calcite-value-list_2.cjs.entry.js 21 KB

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