calcite-pick-list_3.entry.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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, F as Fragment } from './index-1f9b54dc.js';
  7. import { m as mutationObserverCallback, d as deselectRemovedItems, a as deselectSiblingItems, s as selectSiblings, h as handleFilter, b as getItemData, k as keyDownHandler, i as initialize, e as initializeObserver, f as cleanUpObserver, r as removeItem, l as calciteListItemChangeHandler, n as calciteInternalListItemValueChangeHandler, j as calciteListFocusOutHandler, o as setUpItems, p as setFocus, I as ICON_TYPES, L as List, q as SLOTS, t as CSS, H as HEADING_LEVEL, T as TEXT, u as ICONS, C as CSS$1, S as SLOTS$1 } from './resources-3e3255c7.js';
  8. import { c as createObserver } from './observers-9f44e9b3.js';
  9. import { u as updateHostInteraction } from './interactive-5db230e8.js';
  10. import { g as getSlotted, t as toAriaBoolean } from './dom-8f0a9ff2.js';
  11. import { H as Heading, c as constrainHeadingLevel } from './Heading-e0abf8a2.js';
  12. import { c as connectConditionalSlotComponent, d as disconnectConditionalSlotComponent } from './conditionalSlot-a3e8c63a.js';
  13. import './array-03a17827.js';
  14. import './debounce-d85a6654.js';
  15. import './resources-9c476cb6.js';
  16. import './guid-9f15e57a.js';
  17. const pickListCss = "@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:1;flex-direction:column;align-items:stretch;background-color:transparent;font-size:var(--calcite-font-size--1);line-height:1rem;color:var(--calcite-ui-text-2)}:host *{box-sizing:border-box}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}:host([filter-enabled]) header{margin-block-end:0.25rem;display:flex;align-items:stretch;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:1}calcite-filter{margin-block-end:0px}:host([loading][disabled]){min-block-size:2rem}";
  18. const PickList = class {
  19. constructor(hostRef) {
  20. registerInstance(this, hostRef);
  21. this.calciteListChange = createEvent(this, "calciteListChange", 6);
  22. // --------------------------------------------------------------------------
  23. //
  24. // Properties
  25. //
  26. // --------------------------------------------------------------------------
  27. /**
  28. * When `true`, interaction is prevented and the component is displayed with lower opacity.
  29. */
  30. this.disabled = false;
  31. /**
  32. * When `true`, an input appears at the top of the list that can be used by end users to filter items in the list.
  33. */
  34. this.filterEnabled = false;
  35. /**
  36. * When `true`, a busy indicator is displayed.
  37. */
  38. this.loading = false;
  39. /**
  40. * Similar to standard radio buttons and checkboxes.
  41. * When `true`, a user can select multiple `calcite-pick-list-item`s at a time.
  42. * When `false`, only a single `calcite-pick-list-item` can be selected at a time,
  43. * and a new selection will deselect previous selections.
  44. */
  45. this.multiple = false;
  46. /**
  47. * When `true` and single selection is enabled, the selection changes when navigating `calcite-pick-list-item`s via keyboard.
  48. */
  49. this.selectionFollowsFocus = false;
  50. // --------------------------------------------------------------------------
  51. //
  52. // Private Properties
  53. //
  54. // --------------------------------------------------------------------------
  55. this.selectedValues = new Map();
  56. this.dataForFilter = [];
  57. this.lastSelectedItem = null;
  58. this.mutationObserver = createObserver("mutation", mutationObserverCallback.bind(this));
  59. this.setFilterEl = (el) => {
  60. this.filterEl = el;
  61. };
  62. this.deselectRemovedItems = deselectRemovedItems.bind(this);
  63. this.deselectSiblingItems = deselectSiblingItems.bind(this);
  64. this.selectSiblings = selectSiblings.bind(this);
  65. this.handleFilter = handleFilter.bind(this);
  66. this.getItemData = getItemData.bind(this);
  67. this.keyDownHandler = keyDownHandler.bind(this);
  68. }
  69. // --------------------------------------------------------------------------
  70. //
  71. // Lifecycle
  72. //
  73. // --------------------------------------------------------------------------
  74. connectedCallback() {
  75. initialize.call(this);
  76. initializeObserver.call(this);
  77. }
  78. disconnectedCallback() {
  79. cleanUpObserver.call(this);
  80. }
  81. componentDidRender() {
  82. updateHostInteraction(this);
  83. }
  84. calciteListItemRemoveHandler(event) {
  85. removeItem.call(this, event);
  86. }
  87. calciteListItemChangeHandler(event) {
  88. calciteListItemChangeHandler.call(this, event);
  89. }
  90. calciteInternalListItemPropsChangeHandler(event) {
  91. event.stopPropagation();
  92. this.setUpFilter();
  93. }
  94. calciteInternalListItemValueChangeHandler(event) {
  95. calciteInternalListItemValueChangeHandler.call(this, event);
  96. event.stopPropagation();
  97. }
  98. calciteListFocusOutHandler(event) {
  99. calciteListFocusOutHandler.call(this, event);
  100. }
  101. // --------------------------------------------------------------------------
  102. //
  103. // Private Methods
  104. //
  105. // --------------------------------------------------------------------------
  106. setUpItems() {
  107. setUpItems.call(this, "calcite-pick-list-item");
  108. }
  109. setUpFilter() {
  110. if (this.filterEnabled) {
  111. this.dataForFilter = this.getItemData();
  112. }
  113. }
  114. // --------------------------------------------------------------------------
  115. //
  116. // Public Methods
  117. //
  118. // --------------------------------------------------------------------------
  119. /** Returns the component's selected `calcite-pick-list-item`s. */
  120. async getSelectedItems() {
  121. return this.selectedValues;
  122. }
  123. /**
  124. * Sets focus on the component.
  125. *
  126. * @param focusId
  127. */
  128. async setFocus(focusId) {
  129. return setFocus.call(this, focusId);
  130. }
  131. // --------------------------------------------------------------------------
  132. //
  133. // Render Methods
  134. //
  135. // --------------------------------------------------------------------------
  136. getIconType() {
  137. return this.multiple ? ICON_TYPES.square : ICON_TYPES.circle;
  138. }
  139. render() {
  140. return h(List, { onKeyDown: this.keyDownHandler, props: this });
  141. }
  142. get el() { return getElement(this); }
  143. };
  144. PickList.style = pickListCss;
  145. const pickListGroupCss = "@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{margin-block-end:0.25rem;box-sizing:border-box;display:block;background-color:transparent;font-size:var(--calcite-font-size--1);color:var(--calcite-ui-text-2)}:host *{box-sizing:border-box}:host(:last-child){margin-block-end:0px}.header{margin:0px;display:flex;align-content:space-between;align-items:center;fill:var(--calcite-ui-text-2);color:var(--calcite-ui-text-2)}.heading{margin:0px;padding:0px;font-weight:var(--calcite-font-weight-medium)}.header .heading{flex:1 1 auto;padding:0.5rem}.heading{margin-block:0.5rem;margin-inline:1rem;font-size:var(--calcite-font-size-0);line-height:1.25rem;font-size:var(--calcite-font-size--1);line-height:1.375;color:var(--calcite-ui-text-3)}.container--indented{margin-inline-start:1.5rem}";
  146. const PickListGroup = class {
  147. constructor(hostRef) {
  148. registerInstance(this, hostRef);
  149. }
  150. // --------------------------------------------------------------------------
  151. //
  152. // Lifecycle
  153. //
  154. // --------------------------------------------------------------------------
  155. connectedCallback() {
  156. connectConditionalSlotComponent(this);
  157. }
  158. disconnectedCallback() {
  159. disconnectConditionalSlotComponent(this);
  160. }
  161. // --------------------------------------------------------------------------
  162. //
  163. // Render Methods
  164. //
  165. // --------------------------------------------------------------------------
  166. render() {
  167. var _a;
  168. const { el, groupTitle, headingLevel } = this;
  169. const hasParentItem = getSlotted(el, SLOTS.parentItem) !== null;
  170. const sectionClasses = {
  171. [CSS.container]: true,
  172. [CSS.indented]: hasParentItem
  173. };
  174. const title = groupTitle;
  175. const parentLevel = (_a = el.closest("calcite-pick-list")) === null || _a === void 0 ? void 0 : _a.headingLevel;
  176. const relativeLevel = parentLevel ? constrainHeadingLevel(parentLevel + 1) : null;
  177. const level = headingLevel || relativeLevel || HEADING_LEVEL;
  178. return (h(Fragment, null, title ? (h(Heading, { class: CSS.heading, level: level }, title)) : null, h("slot", { name: SLOTS.parentItem }), h("section", { class: sectionClasses }, h("slot", null))));
  179. }
  180. get el() { return getElement(this); }
  181. };
  182. PickListGroup.style = pickListGroupCss;
  183. const pickListItemCss = "@charset \"UTF-8\";@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:0px;margin-block-end:1px;box-sizing:border-box;display:flex;align-items:stretch;background-color:var(--calcite-ui-foreground-1);font-size:var(--calcite-font-size--1);line-height:1rem;color:var(--calcite-ui-text-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);transition:background-color var(--calcite-animation-timing);animation:calcite-fade-in var(--calcite-animation-timing)}:host *{box-sizing:border-box}.label{display:flex;flex:1 1 auto;cursor:pointer;align-items:center;background-color:transparent;outline-color:transparent}.label:focus{outline:2px solid var(--calcite-ui-brand);outline-offset:-2px}.label:hover{background-color:var(--calcite-ui-foreground-2)}:host([non-interactive]:hover){background-color:var(--calcite-ui-foreground-1)}:host([non-interactive]) .label,:host([non-interactive]) .icon{pointer-events:none}.icon{margin-block:0px;display:flex;cursor:pointer;align-items:center;padding:0.25rem;color:var(--calcite-ui-brand);flex:0 0 auto;line-height:0}.icon:hover{background-color:var(--calcite-ui-foreground-2)}.icon-dot{display:flex;inline-size:1.5rem;align-items:center;padding:0.5rem}.icon-dot:before{opacity:0;content:\"•\"}.icon calcite-icon{opacity:0}:host([selected]) .icon-dot:before,:host([selected]) .icon calcite-icon{transition:opacity var(--calcite-animation-timing);opacity:1}.text-container{pointer-events:none;display:flex;flex-direction:column;flex-wrap:nowrap;overflow:hidden;padding-block:0.5rem;padding-inline:0.75rem;font-size:var(--calcite-font-size--2);line-height:1.375;word-wrap:break-word;word-break:break-word}.title{font-weight:var(--calcite-font-weight-normal);color:var(--calcite-ui-text-1)}.description{margin-block-start:0.125rem;font-weight:var(--calcite-font-weight-normal);color:var(--calcite-ui-text-3)}.actions{margin:0px;display:flex;flex:0 1 auto;align-items:stretch;justify-content:flex-end}.actions--start~.label{padding-inline-start:0.25rem}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}";
  184. const PickListItem = class {
  185. constructor(hostRef) {
  186. registerInstance(this, hostRef);
  187. this.calciteListItemChange = createEvent(this, "calciteListItemChange", 6);
  188. this.calciteListItemRemove = createEvent(this, "calciteListItemRemove", 7);
  189. this.calciteInternalListItemPropsChange = createEvent(this, "calciteInternalListItemPropsChange", 6);
  190. this.calciteInternalListItemValueChange = createEvent(this, "calciteInternalListItemValueChange", 6);
  191. /**
  192. * When `true`, interaction is prevented and the component is displayed with lower opacity.
  193. */
  194. this.disabled = false;
  195. /**
  196. * When `false`, the component cannot be deselected by user interaction.
  197. */
  198. this.disableDeselect = false;
  199. /**
  200. * @internal
  201. */
  202. this.nonInteractive = false;
  203. /**
  204. * Determines the icon SVG symbol that will be shown. Options are `"circle"`, `"square"`, `"grip"` or `null`.
  205. *
  206. * @see [ICON_TYPES](https://github.com/Esri/calcite-components/blob/master/src/components/pick-list/resources.ts#L5)
  207. */
  208. this.icon = null;
  209. /**
  210. * When `true`, displays a remove action that removes the item from the list.
  211. */
  212. this.removable = false;
  213. /**
  214. * When `true`, selects an item. Toggles when an item is checked/unchecked.
  215. */
  216. this.selected = false;
  217. /**
  218. * When `removable` is `true`, the accessible name for the component's remove button.
  219. *
  220. * @default "Remove"
  221. */
  222. this.intlRemove = TEXT.remove;
  223. // --------------------------------------------------------------------------
  224. //
  225. // Private Methods
  226. //
  227. // --------------------------------------------------------------------------
  228. this.pickListClickHandler = (event) => {
  229. if (this.disabled || (this.disableDeselect && this.selected) || this.nonInteractive) {
  230. return;
  231. }
  232. this.shiftPressed = event.shiftKey;
  233. this.selected = !this.selected;
  234. };
  235. this.pickListKeyDownHandler = (event) => {
  236. if (event.key === " ") {
  237. event.preventDefault();
  238. if ((this.disableDeselect && this.selected) || this.nonInteractive) {
  239. return;
  240. }
  241. this.selected = !this.selected;
  242. }
  243. };
  244. this.removeClickHandler = () => {
  245. this.calciteListItemRemove.emit();
  246. };
  247. }
  248. descriptionWatchHandler() {
  249. this.calciteInternalListItemPropsChange.emit();
  250. }
  251. labelWatchHandler() {
  252. this.calciteInternalListItemPropsChange.emit();
  253. }
  254. metadataWatchHandler() {
  255. this.calciteInternalListItemPropsChange.emit();
  256. }
  257. selectedWatchHandler() {
  258. this.calciteListItemChange.emit({
  259. item: this.el,
  260. value: this.value,
  261. selected: this.selected,
  262. shiftPressed: this.shiftPressed
  263. });
  264. this.shiftPressed = false;
  265. }
  266. valueWatchHandler(newValue, oldValue) {
  267. this.calciteInternalListItemValueChange.emit({ oldValue, newValue });
  268. }
  269. // --------------------------------------------------------------------------
  270. //
  271. // Lifecycle
  272. //
  273. // --------------------------------------------------------------------------
  274. connectedCallback() {
  275. connectConditionalSlotComponent(this);
  276. }
  277. disconnectedCallback() {
  278. disconnectConditionalSlotComponent(this);
  279. }
  280. componentDidRender() {
  281. updateHostInteraction(this, this.el.closest("calcite-pick-list") ? "managed" : false);
  282. }
  283. // --------------------------------------------------------------------------
  284. //
  285. // Public Methods
  286. //
  287. // --------------------------------------------------------------------------
  288. /**
  289. * Toggles the selection state. By default this won't trigger an event.
  290. * The first argument allows the value to be coerced, rather than swapping values.
  291. *
  292. * @param coerce
  293. */
  294. async toggleSelected(coerce) {
  295. this.selected = typeof coerce === "boolean" ? coerce : !this.selected;
  296. }
  297. /** Sets focus on the component. */
  298. async setFocus() {
  299. var _a;
  300. (_a = this.focusEl) === null || _a === void 0 ? void 0 : _a.focus();
  301. }
  302. // --------------------------------------------------------------------------
  303. //
  304. // Render Methods
  305. //
  306. // --------------------------------------------------------------------------
  307. renderIcon() {
  308. const { icon } = this;
  309. if (!icon) {
  310. return null;
  311. }
  312. return (h("span", { class: {
  313. [CSS$1.icon]: true,
  314. [CSS$1.iconDot]: icon === ICON_TYPES.circle
  315. }, onClick: this.pickListClickHandler }, icon === ICON_TYPES.square ? h("calcite-icon", { icon: ICONS.checked, scale: "s" }) : null));
  316. }
  317. renderRemoveAction() {
  318. return this.removable ? (h("calcite-action", { class: CSS$1.remove, icon: ICONS.remove, onCalciteActionClick: this.removeClickHandler, slot: SLOTS$1.actionsEnd, text: this.intlRemove })) : null;
  319. }
  320. renderActionsStart() {
  321. const { el } = this;
  322. const hasActionsStart = getSlotted(el, SLOTS$1.actionsStart);
  323. return hasActionsStart ? (h("div", { class: { [CSS$1.actions]: true, [CSS$1.actionsStart]: true } }, h("slot", { name: SLOTS$1.actionsStart }))) : null;
  324. }
  325. renderActionsEnd() {
  326. const { el, removable } = this;
  327. const hasActionsEnd = getSlotted(el, SLOTS$1.actionsEnd);
  328. return hasActionsEnd || removable ? (h("div", { class: { [CSS$1.actions]: true, [CSS$1.actionsEnd]: true } }, h("slot", { name: SLOTS$1.actionsEnd }), this.renderRemoveAction())) : null;
  329. }
  330. render() {
  331. const { description, label } = this;
  332. return (h(Fragment, null, this.renderIcon(), this.renderActionsStart(), h("label", { "aria-label": label, class: CSS$1.label, onClick: this.pickListClickHandler, onKeyDown: this.pickListKeyDownHandler, ref: (focusEl) => (this.focusEl = focusEl), tabIndex: 0 }, h("div", { "aria-checked": toAriaBoolean(this.selected), class: CSS$1.textContainer, role: "menuitemcheckbox" }, h("span", { class: CSS$1.title }, label), description ? h("span", { class: CSS$1.description }, description) : null)), this.renderActionsEnd()));
  333. }
  334. get el() { return getElement(this); }
  335. static get watchers() { return {
  336. "description": ["descriptionWatchHandler"],
  337. "label": ["labelWatchHandler"],
  338. "metadata": ["metadataWatchHandler"],
  339. "selected": ["selectedWatchHandler"],
  340. "value": ["valueWatchHandler"]
  341. }; }
  342. };
  343. PickListItem.style = pickListItemCss;
  344. export { PickList as calcite_pick_list, PickListGroup as calcite_pick_list_group, PickListItem as calcite_pick_list_item };