calcite-pick-list_3.cjs.entry.js 21 KB

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