123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356 |
- /*!
- * 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.82
- */
- 'use strict';
- Object.defineProperty(exports, '__esModule', { value: true });
- const index = require('./index-5c65e149.js');
- const sortable_esm = require('./sortable.esm-0005295a.js');
- const resources = require('./resources-684ec2e5.js');
- const observers = require('./observers-d9fdf006.js');
- const interactive = require('./interactive-e294111f.js');
- const guid = require('./guid-8b6d6cb4.js');
- const dom = require('./dom-9ac0341c.js');
- const conditionalSlot = require('./conditionalSlot-ba5cd797.js');
- require('./array-f1fe66d8.js');
- require('./debounce-94d2834e.js');
- const CSS = {
- container: "container",
- handle: "handle"
- };
- var ICON_TYPES;
- (function (ICON_TYPES) {
- ICON_TYPES["grip"] = "grip";
- })(ICON_TYPES || (ICON_TYPES = {}));
- const valueListCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 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;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{position:relative;-webkit-box-sizing:border-box;box-sizing:border-box;display:-ms-flexbox;display:flex;-ms-flex-negative:0;flex-shrink:0;-ms-flex-positive:0;flex-grow:0;-ms-flex-direction:column;flex-direction:column;-ms-flex-align:stretch;align-items:stretch;background-color:transparent;font-size:var(--calcite-font-size--1);color:var(--calcite-ui-text-2)}:host *{-webkit-box-sizing:border-box;box-sizing:border-box}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}: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;-webkit-box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);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-bottom:0.25rem;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:end;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);-webkit-box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);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:-webkit-sticky;position:sticky;top:0px;z-index:10}calcite-filter{margin-bottom:1px}";
- const ValueList = class {
- constructor(hostRef) {
- index.registerInstance(this, hostRef);
- this.calciteListChange = index.createEvent(this, "calciteListChange", 7);
- this.calciteListOrderChange = index.createEvent(this, "calciteListOrderChange", 7);
- // --------------------------------------------------------------------------
- //
- // Properties
- //
- // --------------------------------------------------------------------------
- /**
- * When true, prevents user interaction. This state shows list items grayed out and with lower opacity.
- */
- this.disabled = false;
- /**
- * When true, list items are sortable via a draggable button.
- */
- this.dragEnabled = false;
- /**
- * When true, an input appears at the top of the list that can be used by end users to filter list items.
- */
- this.filterEnabled = false;
- /**
- * When true, content is waiting to be loaded. This state shows a busy indicator.
- */
- this.loading = false;
- /**
- * Similar to standard radio buttons and checkboxes.
- * When true, a user can select multiple list items at a time.
- * When false, only a single list item can be selected at a time,
- * and selecting a new list item will deselect any other selected list items.
- */
- this.multiple = false;
- /**
- * When true and single-selection is enabled, the selection changes when navigating list items via the 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 = (event) => {
- const handleElement = event
- .composedPath()
- .find((item) => { var _a; return ((_a = item.dataset) === null || _a === void 0 ? void 0 : _a.jsHandle) !== undefined; });
- const item = event
- .composedPath()
- .find((item) => { var _a; return ((_a = item.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === "calcite-value-list-item"; });
- // Only trigger keyboard sorting when the internal drag handle is focused and activated
- if (!handleElement || !item.handleActivated) {
- resources.keyDownHandler.call(this, event);
- return;
- }
- const { items } = this;
- if ((event.key !== "ArrowUp" && event.key !== "ArrowDown") || items.length <= 1) {
- return;
- }
- event.preventDefault();
- const { el } = this;
- const nextIndex = resources.moveItemIndex(this, item, event.key === "ArrowUp" ? "up" : "down");
- if (nextIndex === items.length - 1) {
- el.appendChild(item);
- }
- else {
- const itemAtNextIndex = el.children[nextIndex];
- const insertionReferenceItem = itemAtNextIndex === item.nextElementSibling
- ? itemAtNextIndex.nextElementSibling
- : itemAtNextIndex;
- el.insertBefore(item, insertionReferenceItem);
- }
- this.items = this.getItems();
- this.calciteListOrderChange.emit(this.items.map(({ value }) => value));
- requestAnimationFrame(() => handleElement.focus());
- item.handleActivated = true;
- };
- }
- // --------------------------------------------------------------------------
- //
- // Lifecycle
- //
- // --------------------------------------------------------------------------
- connectedCallback() {
- resources.initialize.call(this);
- resources.initializeObserver.call(this);
- }
- componentDidLoad() {
- this.setUpDragAndDrop();
- }
- componentDidRender() {
- interactive.updateHostInteraction(this);
- }
- disconnectedCallback() {
- resources.cleanUpObserver.call(this);
- this.cleanUpDragAndDrop();
- }
- calciteListFocusOutHandler(event) {
- resources.calciteListFocusOutHandler.call(this, event);
- }
- calciteListItemRemoveHandler(event) {
- resources.removeItem.call(this, event);
- }
- calciteListItemChangeHandler(event) {
- resources.calciteListItemChangeHandler.call(this, event);
- }
- calciteListItemPropsChangeHandler(event) {
- event.stopPropagation();
- this.setUpFilter();
- }
- calciteListItemValueChangeHandler(event) {
- resources.calciteListItemValueChangeHandler.call(this, event);
- }
- // --------------------------------------------------------------------------
- //
- // Private Methods
- //
- // --------------------------------------------------------------------------
- getItems() {
- return Array.from(this.el.querySelectorAll("calcite-value-list-item"));
- }
- setUpItems() {
- resources.setUpItems.call(this, "calcite-value-list-item");
- }
- setUpFilter() {
- if (this.filterEnabled) {
- this.dataForFilter = this.getItemData();
- }
- }
- setUpDragAndDrop() {
- this.cleanUpDragAndDrop();
- if (!this.dragEnabled) {
- return;
- }
- this.sortable = sortable_esm.Sortable.create(this.el, {
- dataIdAttr: "id",
- handle: `.${CSS.handle}`,
- draggable: "calcite-value-list-item",
- group: this.group,
- onSort: () => {
- this.items = Array.from(this.el.querySelectorAll("calcite-value-list-item"));
- const values = this.items.map((item) => item.value);
- this.calciteListOrderChange.emit(values);
- }
- });
- }
- cleanUpDragAndDrop() {
- var _a;
- (_a = this.sortable) === null || _a === void 0 ? void 0 : _a.destroy();
- this.sortable = null;
- }
- // --------------------------------------------------------------------------
- //
- // Public Methods
- //
- // --------------------------------------------------------------------------
- /** Returns the currently selected items */
- async getSelectedItems() {
- return this.selectedValues;
- }
- /** Sets focus on the component. */
- async setFocus(focusId) {
- return resources.setFocus.call(this, focusId);
- }
- // --------------------------------------------------------------------------
- //
- // Render Methods
- //
- // --------------------------------------------------------------------------
- getIconType() {
- let type = null;
- if (this.dragEnabled) {
- type = ICON_TYPES.grip;
- }
- return type;
- }
- render() {
- return index.h(resources.List, { onKeyDown: this.keyDownHandler, props: this });
- }
- get el() { return index.getElement(this); }
- };
- ValueList.style = valueListCss;
- const ICONS = {
- drag: "drag"
- };
- const SLOTS = {
- actionsEnd: "actions-end",
- actionsStart: "actions-start"
- };
- const valueListItemCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 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;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{margin-bottom:1px;-webkit-box-sizing:border-box;box-sizing:border-box;display:-ms-flexbox;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);-webkit-box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);-webkit-transition:background-color var(--calcite-animation-timing), -webkit-box-shadow var(--calcite-animation-timing);transition:background-color var(--calcite-animation-timing), -webkit-box-shadow var(--calcite-animation-timing);transition:background-color var(--calcite-animation-timing), box-shadow var(--calcite-animation-timing);transition:background-color var(--calcite-animation-timing), box-shadow var(--calcite-animation-timing), -webkit-box-shadow var(--calcite-animation-timing)}:host *{-webkit-box-sizing:border-box;box-sizing:border-box}calcite-pick-list-item{position:relative;margin:0px;-ms-flex-positive:1;flex-grow:1;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;-webkit-box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);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);-webkit-box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}.handle{display:-ms-flexbox;display:flex;cursor:move;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;border-style:none;background-color:transparent;padding-top:0px;padding-bottom:0px;padding-left:0.25rem;padding-right:0.25rem;color:var(--calcite-ui-text-1);color:var(--calcite-ui-border-1);outline-offset:0;outline-color:transparent;-webkit-transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out}.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]){pointer-events:none;cursor:default;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}";
- const ValueListItem = class {
- constructor(hostRef) {
- index.registerInstance(this, hostRef);
- this.calciteListItemRemove = index.createEvent(this, "calciteListItemRemove", 7);
- /**
- * When true, the list item cannot be clicked and is visually muted.
- */
- this.disabled = false;
- /**
- * @internal When false, the list item cannot be deselected by user interaction.
- */
- this.disableDeselect = false;
- /**
- * When true, prevents the content of the list item from user interaction.
- */
- this.nonInteractive = false;
- /**
- * @internal - Stores the activated state of the drag handle.
- */
- this.handleActivated = 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, adds an action to remove the list item.
- */
- this.removable = false;
- /**
- * When true, preselects the list item. Toggles when an item is checked/unchecked.
- */
- this.selected = false;
- this.pickListItem = null;
- this.guid = `calcite-value-list-item-${guid.guid()}`;
- // --------------------------------------------------------------------------
- //
- // Private Methods
- //
- // --------------------------------------------------------------------------
- this.getPickListRef = (el) => (this.pickListItem = el);
- this.handleKeyDown = (event) => {
- if (event.key === " ") {
- this.handleActivated = !this.handleActivated;
- }
- };
- this.handleBlur = () => {
- this.handleActivated = false;
- };
- this.handleSelectChange = (event) => {
- this.selected = event.detail.selected;
- };
- }
- // --------------------------------------------------------------------------
- //
- // Lifecycle
- //
- // --------------------------------------------------------------------------
- connectedCallback() {
- conditionalSlot.connectConditionalSlotComponent(this);
- }
- disconnectedCallback() {
- conditionalSlot.disconnectConditionalSlotComponent(this);
- }
- componentDidRender() {
- interactive.updateHostInteraction(this, this.el.closest("calcite-value-list") ? "managed" : false);
- }
- // --------------------------------------------------------------------------
- //
- // Public Methods
- //
- // --------------------------------------------------------------------------
- /**
- * Toggle the selection state. By default this won't trigger an event.
- * The first argument allows the value to be coerced, rather than swapping values.
- */
- async toggleSelected(coerce) {
- this.pickListItem.toggleSelected(coerce);
- }
- /** Set focus on the component. */
- async setFocus() {
- var _a;
- (_a = this.pickListItem) === null || _a === void 0 ? void 0 : _a.setFocus();
- }
- calciteListItemChangeHandler(event) {
- // adjust item payload from wrapped item before bubbling
- event.detail.item = this.el;
- }
- // --------------------------------------------------------------------------
- //
- // Render Methods
- //
- // --------------------------------------------------------------------------
- renderActionsEnd() {
- const { el } = this;
- const hasActionsEnd = dom.getSlotted(el, SLOTS.actionsEnd);
- return hasActionsEnd ? (index.h("slot", { name: SLOTS.actionsEnd, slot: resources.SLOTS.actionsEnd })) : null;
- }
- renderActionsStart() {
- const { el } = this;
- const hasActionsStart = dom.getSlotted(el, SLOTS.actionsStart);
- return hasActionsStart ? (index.h("slot", { name: SLOTS.actionsStart, slot: resources.SLOTS.actionsStart })) : null;
- }
- renderHandle() {
- const { icon } = this;
- if (icon === resources.ICON_TYPES.grip) {
- return (index.h("span", { "aria-pressed": dom.toAriaBoolean(this.handleActivated), class: {
- [resources.CSS.handle]: true,
- [resources.CSS.handleActivated]: this.handleActivated
- }, "data-js-handle": true, onBlur: this.handleBlur, onKeyDown: this.handleKeyDown, role: "button", tabindex: "0" }, index.h("calcite-icon", { icon: ICONS.drag, scale: "s" })));
- }
- }
- render() {
- 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())));
- }
- get el() { return index.getElement(this); }
- };
- ValueListItem.style = valueListItemCss;
- exports.calcite_value_list = ValueList;
- exports.calcite_value_list_item = ValueListItem;
|