calcite-value-list_2.entry.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. /*!
  2. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  4. * v1.0.0-beta.97
  5. */
  6. import { r as registerInstance, c as createEvent, h, g as getElement, H as Host } from './index-1f9b54dc.js';
  7. import { S as Sortable } from './sortable.esm-8be1d379.js';
  8. import { g as getItemIndex, m as mutationObserverCallback, d as deselectRemovedItems, a as deselectSiblingItems, s as selectSiblings, h as handleFilter, b as getItemData, k as keyDownHandler, c as moveItemIndex, i as initialize, e as initializeObserver, f as cleanUpObserver, j as calciteListFocusOutHandler, r as removeItem, l as calciteListItemChangeHandler, n as calciteInternalListItemValueChangeHandler, o as setUpItems, p as setFocus, L as List, I as ICON_TYPES$1, C as CSS$1, S as SLOTS$1 } from './resources-3e3255c7.js';
  9. import { c as createObserver } from './observers-9f44e9b3.js';
  10. import { u as updateHostInteraction } from './interactive-5db230e8.js';
  11. import { g as guid } from './guid-9f15e57a.js';
  12. import { g as getSlotted } from './dom-8f0a9ff2.js';
  13. import { c as connectConditionalSlotComponent, d as disconnectConditionalSlotComponent } from './conditionalSlot-a3e8c63a.js';
  14. import './array-03a17827.js';
  15. import './debounce-d85a6654.js';
  16. import './resources-9c476cb6.js';
  17. const CSS = {
  18. container: "container",
  19. handle: "handle"
  20. };
  21. var ICON_TYPES;
  22. (function (ICON_TYPES) {
  23. ICON_TYPES["grip"] = "grip";
  24. })(ICON_TYPES || (ICON_TYPES = {}));
  25. function getScreenReaderText(item, status, valueList) {
  26. const { items, intlDragHandleIdle, intlDragHandleActive, intlDragHandleChange, intlDragHandleCommit } = valueList;
  27. const total = items.length;
  28. const position = getItemIndex(valueList, item) + 1;
  29. if (status === "idle") {
  30. const idleText = intlDragHandleIdle
  31. ? replacePlaceholders(intlDragHandleIdle, item.label, position, total)
  32. : `${item.label}, press space and use arrow keys to reorder content. Current position ${position} of ${total}.`;
  33. return idleText;
  34. }
  35. else if (status === "active") {
  36. const activeText = intlDragHandleActive
  37. ? replacePlaceholders(intlDragHandleActive, item.label, position, total)
  38. : `Reordering ${item.label}, current position ${position} of ${total}.`;
  39. return activeText;
  40. }
  41. else if (status === "change") {
  42. const changeText = intlDragHandleChange
  43. ? replacePlaceholders(intlDragHandleChange, item.label, position, total)
  44. : `${item.label}, new position ${position} of ${total}. Press space to confirm.`;
  45. return changeText;
  46. }
  47. else {
  48. const commitText = intlDragHandleCommit
  49. ? replacePlaceholders(intlDragHandleCommit, item.label, position, total)
  50. : `${item.label}, current position ${position} of ${total}.`;
  51. return commitText;
  52. }
  53. }
  54. function getHandleAndItemElement(event) {
  55. const handle = event
  56. .composedPath()
  57. .find((item) => { var _a; return ((_a = item.dataset) === null || _a === void 0 ? void 0 : _a.jsHandle) !== undefined; });
  58. const item = event
  59. .composedPath()
  60. .find((item) => { var _a; return ((_a = item.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === "calcite-value-list-item"; });
  61. return { handle, item };
  62. }
  63. function replacePlaceholders(text, label, position, total) {
  64. const replacePosition = text.replace("${position}", position.toString());
  65. const replaceLabel = replacePosition.replace("${item.label}", label);
  66. return replaceLabel.replace("${total}", total.toString());
  67. }
  68. const valueListCss = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host{position:relative;box-sizing:border-box;display:flex;flex-shrink:0;flex-grow:0;flex-direction:column;align-items:stretch;background-color:transparent;font-size:var(--calcite-font-size--1);color:var(--calcite-ui-text-2)}:host *{box-sizing:border-box}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}calcite-value-list-item:last-of-type{--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}:host([filter-enabled]) header{margin-block-end:0.25rem;display:flex;align-items:center;justify-content:flex-end;background-color:var(--calcite-ui-foreground-1);--tw-shadow:0 1px 0 var(--calcite-ui-border-3);--tw-shadow-colored:0 1px 0 var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}:host([filter-enabled]) header.sticky-pos{position:sticky;inset-block-start:0px;z-index:300}calcite-filter{margin-block-end:1px}";
  69. const ValueList = class {
  70. constructor(hostRef) {
  71. registerInstance(this, hostRef);
  72. this.calciteListChange = createEvent(this, "calciteListChange", 6);
  73. this.calciteListOrderChange = createEvent(this, "calciteListOrderChange", 6);
  74. // --------------------------------------------------------------------------
  75. //
  76. // Properties
  77. //
  78. // --------------------------------------------------------------------------
  79. /**
  80. * When `true`, interaction is prevented and the component is displayed with lower opacity.
  81. */
  82. this.disabled = false;
  83. /**
  84. * When `true`, `calcite-value-list-item`s are sortable via a draggable button.
  85. */
  86. this.dragEnabled = false;
  87. /**
  88. * When `true`, an input appears at the top of the component that can be used by end users to filter list items.
  89. */
  90. this.filterEnabled = false;
  91. /**
  92. * When `true`, a busy indicator is displayed.
  93. */
  94. this.loading = false;
  95. /**
  96. * Similar to standard radio buttons and checkboxes.
  97. * When `true`, a user can select multiple `calcite-value-list-item`s at a time.
  98. * When `false`, only a single `calcite-value-list-item` can be selected at a time,
  99. * and a new selection will deselect previous selections.
  100. */
  101. this.multiple = false;
  102. /**
  103. * When `true` and single-selection is enabled, the selection changes when navigating `calcite-value-list-item`s via keyboard.
  104. */
  105. this.selectionFollowsFocus = false;
  106. // --------------------------------------------------------------------------
  107. //
  108. // Private Properties
  109. //
  110. // --------------------------------------------------------------------------
  111. this.selectedValues = new Map();
  112. this.dataForFilter = [];
  113. this.lastSelectedItem = null;
  114. this.mutationObserver = createObserver("mutation", mutationObserverCallback.bind(this));
  115. this.setFilterEl = (el) => {
  116. this.filterEl = el;
  117. };
  118. this.deselectRemovedItems = deselectRemovedItems.bind(this);
  119. this.deselectSiblingItems = deselectSiblingItems.bind(this);
  120. this.selectSiblings = selectSiblings.bind(this);
  121. this.handleFilter = handleFilter.bind(this);
  122. this.getItemData = getItemData.bind(this);
  123. this.keyDownHandler = (event) => {
  124. if (event.defaultPrevented) {
  125. return;
  126. }
  127. const { handle, item } = getHandleAndItemElement(event);
  128. if (handle && !item.handleActivated && event.key === " ") {
  129. this.updateScreenReaderText(getScreenReaderText(item, "commit", this));
  130. }
  131. if (!handle || !item.handleActivated) {
  132. keyDownHandler.call(this, event);
  133. return;
  134. }
  135. const { items } = this;
  136. if (event.key === " ") {
  137. this.updateScreenReaderText(getScreenReaderText(item, "active", this));
  138. }
  139. if ((event.key !== "ArrowUp" && event.key !== "ArrowDown") || items.length <= 1) {
  140. return;
  141. }
  142. event.preventDefault();
  143. const { el } = this;
  144. const nextIndex = moveItemIndex(this, item, event.key === "ArrowUp" ? "up" : "down");
  145. if (nextIndex === items.length - 1) {
  146. el.appendChild(item);
  147. }
  148. else {
  149. const itemAtNextIndex = el.children[nextIndex];
  150. const insertionReferenceItem = itemAtNextIndex === item.nextElementSibling
  151. ? itemAtNextIndex.nextElementSibling
  152. : itemAtNextIndex;
  153. el.insertBefore(item, insertionReferenceItem);
  154. }
  155. this.items = this.getItems();
  156. this.calciteListOrderChange.emit(this.items.map(({ value }) => value));
  157. requestAnimationFrame(() => handle === null || handle === void 0 ? void 0 : handle.focus());
  158. item.handleActivated = true;
  159. this.updateHandleAriaLabel(handle, getScreenReaderText(item, "change", this));
  160. };
  161. this.storeAssistiveEl = (el) => {
  162. this.assistiveTextEl = el;
  163. };
  164. this.handleFocusIn = (event) => {
  165. const { handle, item } = getHandleAndItemElement(event);
  166. if (!(item === null || item === void 0 ? void 0 : item.handleActivated) && item && handle) {
  167. this.updateHandleAriaLabel(handle, getScreenReaderText(item, "idle", this));
  168. }
  169. };
  170. }
  171. // --------------------------------------------------------------------------
  172. //
  173. // Lifecycle
  174. //
  175. // --------------------------------------------------------------------------
  176. connectedCallback() {
  177. initialize.call(this);
  178. initializeObserver.call(this);
  179. }
  180. componentDidLoad() {
  181. this.setUpDragAndDrop();
  182. }
  183. componentDidRender() {
  184. updateHostInteraction(this);
  185. }
  186. disconnectedCallback() {
  187. cleanUpObserver.call(this);
  188. this.cleanUpDragAndDrop();
  189. }
  190. calciteListFocusOutHandler(event) {
  191. calciteListFocusOutHandler.call(this, event);
  192. }
  193. calciteListItemRemoveHandler(event) {
  194. removeItem.call(this, event);
  195. }
  196. calciteListItemChangeHandler(event) {
  197. calciteListItemChangeHandler.call(this, event);
  198. }
  199. calciteInternalListItemPropsChangeHandler(event) {
  200. event.stopPropagation();
  201. this.setUpFilter();
  202. }
  203. calciteInternalListItemValueChangeHandler(event) {
  204. calciteInternalListItemValueChangeHandler.call(this, event);
  205. event.stopPropagation();
  206. }
  207. // --------------------------------------------------------------------------
  208. //
  209. // Private Methods
  210. //
  211. // --------------------------------------------------------------------------
  212. getItems() {
  213. return Array.from(this.el.querySelectorAll("calcite-value-list-item"));
  214. }
  215. setUpItems() {
  216. setUpItems.call(this, "calcite-value-list-item");
  217. }
  218. setUpFilter() {
  219. if (this.filterEnabled) {
  220. this.dataForFilter = this.getItemData();
  221. }
  222. }
  223. setUpDragAndDrop() {
  224. this.cleanUpDragAndDrop();
  225. if (!this.dragEnabled) {
  226. return;
  227. }
  228. this.sortable = Sortable.create(this.el, {
  229. dataIdAttr: "id",
  230. handle: `.${CSS.handle}`,
  231. draggable: "calcite-value-list-item",
  232. group: this.group,
  233. onSort: () => {
  234. this.items = Array.from(this.el.querySelectorAll("calcite-value-list-item"));
  235. const values = this.items.map((item) => item.value);
  236. this.calciteListOrderChange.emit(values);
  237. }
  238. });
  239. }
  240. cleanUpDragAndDrop() {
  241. var _a;
  242. (_a = this.sortable) === null || _a === void 0 ? void 0 : _a.destroy();
  243. this.sortable = null;
  244. }
  245. handleBlur() {
  246. if (this.dragEnabled) {
  247. this.updateScreenReaderText("");
  248. }
  249. }
  250. // --------------------------------------------------------------------------
  251. //
  252. // Public Methods
  253. //
  254. // --------------------------------------------------------------------------
  255. /** Returns the currently selected items */
  256. async getSelectedItems() {
  257. return this.selectedValues;
  258. }
  259. /**
  260. * Sets focus on the component.
  261. *
  262. * @param focusId
  263. */
  264. async setFocus(focusId) {
  265. return setFocus.call(this, focusId);
  266. }
  267. // --------------------------------------------------------------------------
  268. //
  269. // Render Methods
  270. //
  271. // --------------------------------------------------------------------------
  272. getIconType() {
  273. let type = null;
  274. if (this.dragEnabled) {
  275. type = ICON_TYPES.grip;
  276. }
  277. return type;
  278. }
  279. updateScreenReaderText(text) {
  280. this.assistiveTextEl.textContent = text;
  281. }
  282. updateHandleAriaLabel(handleElement, text) {
  283. handleElement.ariaLabel = text;
  284. }
  285. render() {
  286. return (h(List, { onBlur: this.handleBlur, onFocusin: this.handleFocusIn, onKeyDown: this.keyDownHandler, props: this }));
  287. }
  288. get el() { return getElement(this); }
  289. };
  290. ValueList.style = valueListCss;
  291. const ICONS = {
  292. drag: "drag"
  293. };
  294. const SLOTS = {
  295. actionsEnd: "actions-end",
  296. actionsStart: "actions-start"
  297. };
  298. const valueListItemCss = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host{margin-block-end:1px;box-sizing:border-box;display:flex;background-color:var(--calcite-ui-foreground-1);font-size:var(--calcite-font-size--1);color:var(--calcite-ui-text-2);--tw-shadow:0 1px 0 var(--calcite-ui-border-3);--tw-shadow-colored:0 1px 0 var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);transition:background-color var(--calcite-animation-timing), box-shadow var(--calcite-animation-timing)}:host *{box-sizing:border-box}calcite-pick-list-item{position:relative;margin:0px;flex-grow:1;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}:host([active]),:host([selected]){--tw-shadow:0 0 0 1px var(--calcite-ui-brand);--tw-shadow-colored:0 0 0 1px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}.handle{display:flex;cursor:move;align-items:center;justify-content:center;border-style:none;background-color:transparent;padding-block:0px;padding-inline:0.25rem;color:var(--calcite-ui-border-input);outline-color:transparent}.handle:hover{background-color:var(--calcite-ui-foreground-2);color:var(--calcite-ui-text-1)}.handle:focus{outline:2px solid var(--calcite-ui-brand);outline-offset:-2px}.handle--activated{background-color:var(--calcite-ui-foreground-3);color:var(--calcite-ui-text-1)}.handle calcite-icon{color:inherit}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}";
  299. const ValueListItem = class {
  300. constructor(hostRef) {
  301. registerInstance(this, hostRef);
  302. this.calciteListItemRemove = createEvent(this, "calciteListItemRemove", 7);
  303. /**
  304. * When `true`, interaction is prevented and the component is displayed with lower opacity.
  305. */
  306. this.disabled = false;
  307. /**
  308. * @internal
  309. */
  310. this.disableDeselect = false;
  311. /**
  312. * When `true`, prevents the content of the component from user interaction.
  313. */
  314. this.nonInteractive = false;
  315. /**
  316. * @internal
  317. */
  318. this.handleActivated = false;
  319. /**
  320. * Determines the icon SVG symbol that will be shown. Options are circle, square, grip or null.
  321. *
  322. * @see [ICON_TYPES](https://github.com/Esri/calcite-components/blob/master/src/components/pick-list/resources.ts#L5)
  323. */
  324. this.icon = null;
  325. /**
  326. * When `true`, adds an action to remove the component.
  327. */
  328. this.removable = false;
  329. /**
  330. * When `true`, the component is selected.
  331. */
  332. this.selected = false;
  333. this.pickListItem = null;
  334. this.guid = `calcite-value-list-item-${guid()}`;
  335. // --------------------------------------------------------------------------
  336. //
  337. // Private Methods
  338. //
  339. // --------------------------------------------------------------------------
  340. this.getPickListRef = (el) => (this.pickListItem = el);
  341. this.handleKeyDown = (event) => {
  342. if (event.key === " ") {
  343. this.handleActivated = !this.handleActivated;
  344. }
  345. };
  346. this.handleBlur = () => {
  347. this.handleActivated = false;
  348. };
  349. this.handleSelectChange = (event) => {
  350. this.selected = event.detail.selected;
  351. };
  352. }
  353. // --------------------------------------------------------------------------
  354. //
  355. // Lifecycle
  356. //
  357. // --------------------------------------------------------------------------
  358. connectedCallback() {
  359. connectConditionalSlotComponent(this);
  360. }
  361. disconnectedCallback() {
  362. disconnectConditionalSlotComponent(this);
  363. }
  364. componentDidRender() {
  365. updateHostInteraction(this, this.el.closest("calcite-value-list") ? "managed" : false);
  366. }
  367. // --------------------------------------------------------------------------
  368. //
  369. // Public Methods
  370. //
  371. // --------------------------------------------------------------------------
  372. /**
  373. * Toggle the selection state. By default this won't trigger an event.
  374. * The first argument allows the value to be coerced, rather than swapping values.
  375. *
  376. * @param coerce
  377. */
  378. async toggleSelected(coerce) {
  379. this.pickListItem.toggleSelected(coerce);
  380. }
  381. /** Set focus on the component. */
  382. async setFocus() {
  383. var _a;
  384. (_a = this.pickListItem) === null || _a === void 0 ? void 0 : _a.setFocus();
  385. }
  386. calciteListItemChangeHandler(event) {
  387. // adjust item payload from wrapped item before bubbling
  388. event.detail.item = this.el;
  389. }
  390. // --------------------------------------------------------------------------
  391. //
  392. // Render Methods
  393. //
  394. // --------------------------------------------------------------------------
  395. renderActionsEnd() {
  396. const { el } = this;
  397. const hasActionsEnd = getSlotted(el, SLOTS.actionsEnd);
  398. return hasActionsEnd ? (h("slot", { name: SLOTS.actionsEnd, slot: SLOTS$1.actionsEnd })) : null;
  399. }
  400. renderActionsStart() {
  401. const { el } = this;
  402. const hasActionsStart = getSlotted(el, SLOTS.actionsStart);
  403. return hasActionsStart ? (h("slot", { name: SLOTS.actionsStart, slot: SLOTS$1.actionsStart })) : null;
  404. }
  405. renderHandle() {
  406. const { icon } = this;
  407. if (icon === ICON_TYPES$1.grip) {
  408. return (h("span", { class: {
  409. [CSS$1.handle]: true,
  410. [CSS$1.handleActivated]: this.handleActivated
  411. }, "data-js-handle": true, onBlur: this.handleBlur, onKeyDown: this.handleKeyDown, role: "button", tabindex: "0" }, h("calcite-icon", { icon: ICONS.drag, scale: "s" })));
  412. }
  413. }
  414. render() {
  415. return (h(Host, { id: this.el.id || this.guid }, this.renderHandle(), h("calcite-pick-list-item", { description: this.description, disableDeselect: this.disableDeselect, disabled: this.disabled, label: this.label, metadata: this.metadata, nonInteractive: this.nonInteractive, onCalciteListItemChange: this.handleSelectChange, ref: this.getPickListRef, removable: this.removable, selected: this.selected, value: this.value }, this.renderActionsStart(), this.renderActionsEnd())));
  416. }
  417. get el() { return getElement(this); }
  418. };
  419. ValueListItem.style = valueListItemCss;
  420. export { ValueList as calcite_value_list, ValueListItem as calcite_value_list_item };