/*! * All material copyright ESRI, All Rights Reserved, unless otherwise specified. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details. * v1.0.0-beta.97 */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const index = require('./index-a0010f96.js'); const resources = require('./resources-8b3ba64a.js'); const observers = require('./observers-5706326b.js'); const interactive = require('./interactive-32293bca.js'); const dom = require('./dom-2ec8c9ed.js'); const Heading = require('./Heading-1e87a15f.js'); const conditionalSlot = require('./conditionalSlot-ef852d9d.js'); require('./array-e708c699.js'); require('./debounce-2c8b61fb.js'); require('./resources-b5a5f8a7.js'); require('./guid-f4f03a7a.js'); 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}"; const PickList = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.calciteListChange = index.createEvent(this, "calciteListChange", 6); // -------------------------------------------------------------------------- // // Properties // // -------------------------------------------------------------------------- /** * When `true`, interaction is prevented and the component is displayed with lower opacity. */ this.disabled = false; /** * When `true`, an input appears at the top of the list that can be used by end users to filter items in the list. */ this.filterEnabled = false; /** * When `true`, a busy indicator is displayed. */ this.loading = false; /** * Similar to standard radio buttons and checkboxes. * When `true`, a user can select multiple `calcite-pick-list-item`s at a time. * When `false`, only a single `calcite-pick-list-item` can be selected at a time, * and a new selection will deselect previous selections. */ this.multiple = false; /** * When `true` and single selection is enabled, the selection changes when navigating `calcite-pick-list-item`s via keyboard. */ this.selectionFollowsFocus = false; // -------------------------------------------------------------------------- // // Private Properties // // -------------------------------------------------------------------------- this.selectedValues = new Map(); this.dataForFilter = []; this.lastSelectedItem = null; this.mutationObserver = observers.createObserver("mutation", resources.mutationObserverCallback.bind(this)); this.setFilterEl = (el) => { this.filterEl = el; }; this.deselectRemovedItems = resources.deselectRemovedItems.bind(this); this.deselectSiblingItems = resources.deselectSiblingItems.bind(this); this.selectSiblings = resources.selectSiblings.bind(this); this.handleFilter = resources.handleFilter.bind(this); this.getItemData = resources.getItemData.bind(this); this.keyDownHandler = resources.keyDownHandler.bind(this); } // -------------------------------------------------------------------------- // // Lifecycle // // -------------------------------------------------------------------------- connectedCallback() { resources.initialize.call(this); resources.initializeObserver.call(this); } disconnectedCallback() { resources.cleanUpObserver.call(this); } componentDidRender() { interactive.updateHostInteraction(this); } calciteListItemRemoveHandler(event) { resources.removeItem.call(this, event); } calciteListItemChangeHandler(event) { resources.calciteListItemChangeHandler.call(this, event); } calciteInternalListItemPropsChangeHandler(event) { event.stopPropagation(); this.setUpFilter(); } calciteInternalListItemValueChangeHandler(event) { resources.calciteInternalListItemValueChangeHandler.call(this, event); event.stopPropagation(); } calciteListFocusOutHandler(event) { resources.calciteListFocusOutHandler.call(this, event); } // -------------------------------------------------------------------------- // // Private Methods // // -------------------------------------------------------------------------- setUpItems() { resources.setUpItems.call(this, "calcite-pick-list-item"); } setUpFilter() { if (this.filterEnabled) { this.dataForFilter = this.getItemData(); } } // -------------------------------------------------------------------------- // // Public Methods // // -------------------------------------------------------------------------- /** Returns the component's selected `calcite-pick-list-item`s. */ async getSelectedItems() { return this.selectedValues; } /** * Sets focus on the component. * * @param focusId */ async setFocus(focusId) { return resources.setFocus.call(this, focusId); } // -------------------------------------------------------------------------- // // Render Methods // // -------------------------------------------------------------------------- getIconType() { return this.multiple ? resources.ICON_TYPES.square : resources.ICON_TYPES.circle; } render() { return index.h(resources.List, { onKeyDown: this.keyDownHandler, props: this }); } get el() { return index.getElement(this); } }; PickList.style = pickListCss; 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}"; const PickListGroup = class { constructor(hostRef) { index.registerInstance(this, hostRef); } // -------------------------------------------------------------------------- // // Lifecycle // // -------------------------------------------------------------------------- connectedCallback() { conditionalSlot.connectConditionalSlotComponent(this); } disconnectedCallback() { conditionalSlot.disconnectConditionalSlotComponent(this); } // -------------------------------------------------------------------------- // // Render Methods // // -------------------------------------------------------------------------- render() { var _a; const { el, groupTitle, headingLevel } = this; const hasParentItem = dom.getSlotted(el, resources.SLOTS$1.parentItem) !== null; const sectionClasses = { [resources.CSS$1.container]: true, [resources.CSS$1.indented]: hasParentItem }; const title = groupTitle; const parentLevel = (_a = el.closest("calcite-pick-list")) === null || _a === void 0 ? void 0 : _a.headingLevel; const relativeLevel = parentLevel ? Heading.constrainHeadingLevel(parentLevel + 1) : null; const level = headingLevel || relativeLevel || resources.HEADING_LEVEL; 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)))); } get el() { return index.getElement(this); } }; PickListGroup.style = pickListGroupCss; 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}"; const PickListItem = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.calciteListItemChange = index.createEvent(this, "calciteListItemChange", 6); this.calciteListItemRemove = index.createEvent(this, "calciteListItemRemove", 7); this.calciteInternalListItemPropsChange = index.createEvent(this, "calciteInternalListItemPropsChange", 6); this.calciteInternalListItemValueChange = index.createEvent(this, "calciteInternalListItemValueChange", 6); /** * When `true`, interaction is prevented and the component is displayed with lower opacity. */ this.disabled = false; /** * When `false`, the component cannot be deselected by user interaction. */ this.disableDeselect = false; /** * @internal */ this.nonInteractive = false; /** * Determines the icon SVG symbol that will be shown. Options are `"circle"`, `"square"`, `"grip"` or `null`. * * @see [ICON_TYPES](https://github.com/Esri/calcite-components/blob/master/src/components/pick-list/resources.ts#L5) */ this.icon = null; /** * When `true`, displays a remove action that removes the item from the list. */ this.removable = false; /** * When `true`, selects an item. Toggles when an item is checked/unchecked. */ this.selected = false; /** * When `removable` is `true`, the accessible name for the component's remove button. * * @default "Remove" */ this.intlRemove = resources.TEXT.remove; // -------------------------------------------------------------------------- // // Private Methods // // -------------------------------------------------------------------------- this.pickListClickHandler = (event) => { if (this.disabled || (this.disableDeselect && this.selected) || this.nonInteractive) { return; } this.shiftPressed = event.shiftKey; this.selected = !this.selected; }; this.pickListKeyDownHandler = (event) => { if (event.key === " ") { event.preventDefault(); if ((this.disableDeselect && this.selected) || this.nonInteractive) { return; } this.selected = !this.selected; } }; this.removeClickHandler = () => { this.calciteListItemRemove.emit(); }; } descriptionWatchHandler() { this.calciteInternalListItemPropsChange.emit(); } labelWatchHandler() { this.calciteInternalListItemPropsChange.emit(); } metadataWatchHandler() { this.calciteInternalListItemPropsChange.emit(); } selectedWatchHandler() { this.calciteListItemChange.emit({ item: this.el, value: this.value, selected: this.selected, shiftPressed: this.shiftPressed }); this.shiftPressed = false; } valueWatchHandler(newValue, oldValue) { this.calciteInternalListItemValueChange.emit({ oldValue, newValue }); } // -------------------------------------------------------------------------- // // Lifecycle // // -------------------------------------------------------------------------- connectedCallback() { conditionalSlot.connectConditionalSlotComponent(this); } disconnectedCallback() { conditionalSlot.disconnectConditionalSlotComponent(this); } componentDidRender() { interactive.updateHostInteraction(this, this.el.closest("calcite-pick-list") ? "managed" : false); } // -------------------------------------------------------------------------- // // Public Methods // // -------------------------------------------------------------------------- /** * Toggles the selection state. By default this won't trigger an event. * The first argument allows the value to be coerced, rather than swapping values. * * @param coerce */ async toggleSelected(coerce) { this.selected = typeof coerce === "boolean" ? coerce : !this.selected; } /** Sets focus on the component. */ async setFocus() { var _a; (_a = this.focusEl) === null || _a === void 0 ? void 0 : _a.focus(); } // -------------------------------------------------------------------------- // // Render Methods // // -------------------------------------------------------------------------- renderIcon() { const { icon } = this; if (!icon) { return null; } return (index.h("span", { class: { [resources.CSS.icon]: true, [resources.CSS.iconDot]: icon === resources.ICON_TYPES.circle }, onClick: this.pickListClickHandler }, icon === resources.ICON_TYPES.square ? index.h("calcite-icon", { icon: resources.ICONS.checked, scale: "s" }) : null)); } renderRemoveAction() { 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; } renderActionsStart() { const { el } = this; const hasActionsStart = dom.getSlotted(el, resources.SLOTS.actionsStart); return hasActionsStart ? (index.h("div", { class: { [resources.CSS.actions]: true, [resources.CSS.actionsStart]: true } }, index.h("slot", { name: resources.SLOTS.actionsStart }))) : null; } renderActionsEnd() { const { el, removable } = this; const hasActionsEnd = dom.getSlotted(el, resources.SLOTS.actionsEnd); 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; } render() { const { description, label } = this; 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())); } get el() { return index.getElement(this); } static get watchers() { return { "description": ["descriptionWatchHandler"], "label": ["labelWatchHandler"], "metadata": ["metadataWatchHandler"], "selected": ["selectedWatchHandler"], "value": ["valueWatchHandler"] }; } }; PickListItem.style = pickListItemCss; exports.calcite_pick_list = PickList; exports.calcite_pick_list_group = PickListGroup; exports.calcite_pick_list_item = PickListItem;