@esri/calcite-components
Version:
Web Components for Esri's Calcite Design System.
730 lines (718 loc) • 38.9 kB
JavaScript
/*!
* All material copyright ESRI, All Rights Reserved, unless otherwise specified.
* See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
* v1.5.0-next.4
*/
import { r as registerInstance, c as createEvent, h, a as getElement, H as Host } from './index-c8875db5.js';
import { t as toAriaBoolean, d as slotChangeHasAssignedElement, b as getElementDir } from './dom-4f5d1224.js';
import { c as connectInteractive, d as disconnectInteractive, u as updateHostInteraction } from './interactive-cff0a7ea.js';
import { c as createObserver } from './observers-d19b0d93.js';
import { s as setUpLoadableComponent, a as setComponentLoaded, c as componentLoaded } from './loadable-8d606217.js';
import { d as debounce } from './debounce-ca1bd093.js';
import { c as connectLocalized, d as disconnectLocalized } from './locale-0c018cdb.js';
import { u as updateMessages, c as connectMessages, s as setUpMessages, d as disconnectMessages } from './t9n-f819e5a2.js';
import './guid-bdb80778.js';
import './resources-35f23920.js';
import './browser-4be2add2.js';
import './key-582cee8f.js';
const CSS$2 = {
container: "container",
containerBorderSelected: "container--border-selected",
containerBorderUnselected: "container--border-unselected",
contentContainer: "content-container",
contentContainerSelectable: "content-container--selectable",
contentContainerHasCenterContent: "content-container--has-center-content",
nestedContainer: "nested-container",
nestedContainerHidden: "nested-container--hidden",
content: "content",
customContent: "custom-content",
actionsStart: "actions-start",
contentStart: "content-start",
label: "label",
description: "description",
contentEnd: "content-end",
actionsEnd: "actions-end",
selectionContainer: "selection-container",
openContainer: "open-container"
};
const SLOTS = {
actionsStart: "actions-start",
contentStart: "content-start",
content: "content",
contentEnd: "content-end",
actionsEnd: "actions-end"
};
const MAX_COLUMNS = 5;
const ICONS = {
selectedMultiple: "check-circle-f",
selectedSingle: "circle-f",
unselected: "blank",
closedLTR: "caret-right",
closedRTL: "caret-left",
open: "caret-down",
blank: "blank",
close: "x"
};
const listItemGroupSelector = "calcite-list-item-group";
const listItemSelector$1 = "calcite-list-item";
function getListItemChildren(event) {
const assignedElements = event.target.assignedElements({ flatten: true });
const listItemGroupChildren = assignedElements.filter((el) => el?.matches(listItemGroupSelector))
.map((group) => Array.from(group.querySelectorAll(listItemSelector$1)))
.reduce((previousValue, currentValue) => [...previousValue, ...currentValue], []);
const listItemChildren = assignedElements.filter((el) => el?.matches(listItemSelector$1));
return [...listItemGroupChildren, ...listItemChildren];
}
function updateListItemChildren(listItemChildren) {
listItemChildren.forEach((listItem) => {
listItem.setPosition = listItemChildren.indexOf(listItem) + 1;
listItem.setSize = listItemChildren.length;
});
}
function getDepth(element, includeGroup = false) {
const expression = includeGroup
? "ancestor::calcite-list-item | ancestor::calcite-list-item-group"
: "ancestor::calcite-list-item";
const result = document.evaluate(expression, element, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
return result.snapshotLength;
}
const CSS$1 = {
container: "container",
table: "table",
scrim: "scrim",
tableContainer: "table-container",
sticky: "sticky-pos"
};
const debounceTimeout = 0;
const listCss = "@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-right{0%{opacity:0;transform:translate3D(-5px, 0, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-left{0%{opacity:0;transform:translate3D(5px, 0, 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-right{animation-name:in-right}.calcite-animate__in-left{animation-name:in-left}.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);--calcite-floating-ui-z-index:var(--calcite-app-z-index-dropdown)}:host([hidden]){display:none}:host([disabled]){cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host([disabled]) *,:host([disabled]) ::slotted(*){pointer-events:none}:host{display:block}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}.container{position:relative}.table-container{position:relative;z-index:var(--calcite-app-z-index);box-sizing:border-box;display:flex;inline-size:100%;flex-direction:column;background-color:transparent}.table-container *{box-sizing:border-box}.table{inline-size:100%;border-collapse:collapse}::slotted(calcite-list-item){margin-block-end:1px;--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)}::slotted(calcite-list-item:last-child){--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)}.sticky-pos{position:sticky;inset-block-start:0px;z-index:var(--calcite-app-z-index-sticky)}.sticky-pos th{padding:0px}calcite-filter{margin-block-end:1px}";
const listItemSelector = "calcite-list-item";
const parentSelector = "calcite-list-item-group, calcite-list-item";
const List = class {
constructor(hostRef) {
registerInstance(this, hostRef);
this.calciteListChange = createEvent(this, "calciteListChange", 6);
this.calciteListFilter = createEvent(this, "calciteListFilter", 6);
this.listItems = [];
this.enabledListItems = [];
this.mutationObserver = createObserver("mutation", () => this.updateListItems());
// --------------------------------------------------------------------------
//
// Private Methods
//
// --------------------------------------------------------------------------
this.handleDefaultSlotChange = (event) => {
updateListItemChildren(getListItemChildren(event));
};
this.setActiveListItem = () => {
const { enabledListItems } = this;
if (!enabledListItems.some((item) => item.active)) {
if (enabledListItems[0]) {
enabledListItems[0].active = true;
}
}
};
this.updateSelectedItems = (emit = false) => {
this.selectedItems = this.enabledListItems.filter((item) => item.selected);
if (emit) {
this.calciteListChange.emit();
}
};
this.updateFilteredItems = (emit = false) => {
const { listItems, filteredData, filterText } = this;
const values = filteredData.map((item) => item.value);
const lastDescendantItems = listItems?.filter((listItem) => listItems.every((li) => li === listItem || !listItem.contains(li)));
const filteredItems = listItems.filter((item) => !filterText || values.includes(item.value)) || [];
const visibleParents = new WeakSet();
lastDescendantItems.forEach((listItem) => this.filterElements({ el: listItem, filteredItems, visibleParents }));
this.filteredItems = filteredItems;
if (emit) {
this.calciteListFilter.emit();
}
};
this.handleFilter = (event) => {
event.stopPropagation();
const { filteredItems, value } = event.currentTarget;
this.filteredData = filteredItems;
this.filterText = value;
this.updateListItems(true);
};
this.getItemData = () => {
return this.listItems.map((item) => ({
label: item.label,
description: item.description,
metadata: item.metadata,
value: item.value
}));
};
this.updateListItems = debounce((emit = false) => {
const { selectionAppearance, selectionMode } = this;
const items = this.queryListItems();
items.forEach((item) => {
item.selectionAppearance = selectionAppearance;
item.selectionMode = selectionMode;
});
this.listItems = items;
if (this.filterEnabled) {
this.dataForFilter = this.getItemData();
if (this.filterEl) {
this.filterEl.items = this.dataForFilter;
}
}
this.updateFilteredItems(emit);
this.enabledListItems = items.filter((item) => !item.disabled && !item.closed);
this.setActiveListItem();
this.updateSelectedItems(emit);
}, debounceTimeout);
this.queryListItems = () => {
return Array.from(this.el.querySelectorAll(listItemSelector));
};
this.focusRow = (focusEl) => {
const { enabledListItems } = this;
if (!focusEl) {
return;
}
enabledListItems.forEach((listItem) => (listItem.active = listItem === focusEl));
focusEl.setFocus();
};
this.isNavigable = (listItem) => {
const parentListItemEl = listItem.parentElement?.closest(listItemSelector);
if (!parentListItemEl) {
return true;
}
return parentListItemEl.open && this.isNavigable(parentListItemEl);
};
this.handleListKeydown = (event) => {
if (event.defaultPrevented) {
return;
}
const { key } = event;
const filteredItems = this.enabledListItems.filter((listItem) => this.isNavigable(listItem));
const currentIndex = filteredItems.findIndex((listItem) => listItem.active);
if (key === "ArrowDown") {
event.preventDefault();
const nextIndex = currentIndex + 1;
if (filteredItems[nextIndex]) {
this.focusRow(filteredItems[nextIndex]);
}
}
else if (key === "ArrowUp") {
event.preventDefault();
const prevIndex = currentIndex - 1;
if (filteredItems[prevIndex]) {
this.focusRow(filteredItems[prevIndex]);
}
}
else if (key === "Home") {
event.preventDefault();
const homeItem = filteredItems[0];
if (homeItem) {
this.focusRow(homeItem);
}
}
else if (key === "End") {
event.preventDefault();
const endItem = filteredItems[filteredItems.length - 1];
if (endItem) {
this.focusRow(endItem);
}
}
};
this.disabled = false;
this.filterEnabled = false;
this.filteredItems = [];
this.filteredData = [];
this.filterPlaceholder = undefined;
this.filterText = undefined;
this.label = undefined;
this.loading = false;
this.openable = false;
this.selectedItems = [];
this.selectionMode = "none";
this.selectionAppearance = "icon";
this.dataForFilter = [];
}
handleFilterEnabledChange() {
this.updateListItems();
}
handleSelectionAppearanceChange() {
this.updateListItems();
}
handleCalciteInternalFocusPreviousItem(event) {
event.stopPropagation();
const { enabledListItems } = this;
const currentIndex = enabledListItems.findIndex((listItem) => listItem.active);
const prevIndex = currentIndex - 1;
if (enabledListItems[prevIndex]) {
this.focusRow(enabledListItems[prevIndex]);
}
}
handleCalciteInternalListItemActive(event) {
const target = event.target;
const { listItems } = this;
listItems.forEach((listItem) => {
listItem.active = listItem === target;
});
}
handleCalciteListItemSelect() {
this.updateSelectedItems(true);
}
handleCalciteInternalListItemSelect(event) {
const target = event.target;
const { listItems, selectionMode } = this;
if (target.selected && (selectionMode === "single" || selectionMode === "single-persist")) {
listItems.forEach((listItem) => (listItem.selected = listItem === target));
}
this.updateSelectedItems();
}
handleCalciteListItemClose() {
this.updateListItems(true);
}
//--------------------------------------------------------------------------
//
// Lifecycle
//
//--------------------------------------------------------------------------
connectedCallback() {
this.mutationObserver?.observe(this.el, { childList: true, subtree: true });
this.updateListItems();
connectInteractive(this);
}
disconnectedCallback() {
this.mutationObserver?.disconnect();
disconnectInteractive(this);
}
componentWillLoad() {
setUpLoadableComponent(this);
}
componentDidRender() {
updateHostInteraction(this);
}
componentDidLoad() {
setComponentLoaded(this);
const { filterEl } = this;
const filteredItems = filterEl?.filteredItems;
if (filteredItems) {
this.filteredData = filteredItems;
}
this.updateListItems();
}
// --------------------------------------------------------------------------
//
// Public Methods
//
// --------------------------------------------------------------------------
/** Sets focus on the component's first focusable element. */
async setFocus() {
await componentLoaded(this);
this.enabledListItems.find((listItem) => listItem.active)?.setFocus();
}
// --------------------------------------------------------------------------
//
// Render Methods
//
// --------------------------------------------------------------------------
render() {
const { loading, label, disabled, dataForFilter, filterEnabled, filterPlaceholder, filterText } = this;
return (h("div", { class: CSS$1.container }, loading ? h("calcite-scrim", { class: CSS$1.scrim, loading: loading }) : null, h("table", { "aria-busy": toAriaBoolean(loading), "aria-label": label || "", class: CSS$1.table, onKeyDown: this.handleListKeydown, role: "treegrid" }, filterEnabled ? (h("thead", null, h("tr", { class: { [CSS$1.sticky]: true } }, h("th", { colSpan: MAX_COLUMNS }, h("calcite-filter", { "aria-label": filterPlaceholder, disabled: loading || disabled, items: dataForFilter, onCalciteFilterChange: this.handleFilter, placeholder: filterPlaceholder, value: filterText,
// eslint-disable-next-line react/jsx-sort-props
ref: (el) => (this.filterEl = el) }))))) : null, h("tbody", { class: CSS$1.tableContainer }, h("slot", { onSlotchange: this.handleDefaultSlotChange })))));
}
filterElements({ el, filteredItems, visibleParents }) {
const hidden = !visibleParents.has(el) && !filteredItems.includes(el);
el.hidden = hidden;
const closestParent = el.parentElement.closest(parentSelector);
if (!closestParent) {
return;
}
if (!hidden) {
visibleParents.add(closestParent);
}
this.filterElements({
el: closestParent,
filteredItems,
visibleParents
});
}
get el() { return getElement(this); }
static get watchers() { return {
"filterEnabled": ["handleFilterEnabledChange"],
"selectionMode": ["handleSelectionAppearanceChange"],
"selectionAppearance": ["handleSelectionAppearanceChange"]
}; }
};
List.style = listCss;
const listItemCss = "@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-right{0%{opacity:0;transform:translate3D(-5px, 0, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-left{0%{opacity:0;transform:translate3D(5px, 0, 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-right{animation-name:in-right}.calcite-animate__in-left{animation-name:in-left}.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);--calcite-floating-ui-z-index:var(--calcite-app-z-index-dropdown)}:host([hidden]){display:none}:host([disabled]){cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host([disabled]) *,:host([disabled]) ::slotted(*){pointer-events:none}:host{display:flex;flex-direction:column;--calcite-list-item-icon-color:var(--calcite-ui-brand);--calcite-list-item-spacing-indent:1rem}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}.container{box-sizing:border-box;display:flex;flex:1 1 0%;background-color:var(--calcite-ui-foreground-1);font-family:var(--calcite-sans-family);padding-inline-start:calc(var(--calcite-list-item-spacing-indent) * var(--calcite-list-item-spacing-indent-multiplier))}.container *{box-sizing:border-box}.container:hover{cursor:pointer;background-color:var(--calcite-ui-foreground-2)}.container--border-selected{border-inline-start:4px solid var(--calcite-ui-brand)}.container--border-unselected{border-inline-start:4px solid transparent}.nested-container{display:flex;flex-direction:column;background-color:var(--calcite-ui-foreground-1)}.nested-container--hidden{display:none}.content-container{display:flex;flex:1 1 auto;align-items:stretch;padding:0px;font-family:var(--calcite-sans-family);font-weight:var(--calcite-font-weight-normal);color:var(--calcite-ui-text-2)}tr,td{outline-color:transparent}tr:focus,td:focus{z-index:var(--calcite-app-z-index-sticky);outline:2px solid var(--calcite-ui-focus-color, var(--calcite-ui-brand));outline-offset:calc(\n -2px *\n calc(\n 1 -\n 2 * clamp(\n 0,\n var(--calcite-ui-focus-offset-invert),\n 1\n )\n )\n )}.content,.custom-content{display:flex;flex:1 1 auto;flex-direction:column;justify-content:center;padding-inline:0.75rem;padding-block:0.5rem;font-size:var(--calcite-font-size--2);line-height:1.375}.label,.description{font-family:var(--calcite-sans-family);font-size:var(--calcite-font-size--2);font-weight:var(--calcite-font-weight-normal);word-wrap:break-word;word-break:break-word}.label:only-child,.description:only-child{margin:0px;padding-block:0.25rem}.label{color:var(--calcite-ui-text-1)}.description{margin-block-start:0.125rem;color:var(--calcite-ui-text-3)}.content-start{justify-content:flex-start}.content-end{justify-content:flex-end}.content-start,.content-end{flex:1 1 auto}.content-container--has-center-content .content-start,.content-container--has-center-content .content-end{flex:0 1 auto}.selection-container{display:flex;padding-inline:0.75rem;color:var(--calcite-list-item-icon-color)}.actions-start,.actions-end,.content-start,.content-end,.selection-container,.open-container{display:flex;align-items:center}.open-container,.selection-container{cursor:pointer}.content-start ::slotted(calcite-icon),.content-end ::slotted(calcite-icon){margin-inline:0.75rem;align-self:center}.actions-start ::slotted(calcite-action),.actions-end ::slotted(calcite-action){align-self:stretch;color:inherit}::slotted(calcite-list-item){border-width:0px;border-block-start-width:1px;border-style:solid;border-color:var(--calcite-ui-border-3)}[hidden]{display:none}";
const focusMap = new Map();
const listSelector = "calcite-list";
const ListItem = class {
constructor(hostRef) {
registerInstance(this, hostRef);
this.calciteListItemSelect = createEvent(this, "calciteListItemSelect", 6);
this.calciteListItemClose = createEvent(this, "calciteListItemClose", 6);
this.calciteInternalListItemSelect = createEvent(this, "calciteInternalListItemSelect", 6);
this.calciteInternalListItemActive = createEvent(this, "calciteInternalListItemActive", 6);
this.calciteInternalFocusPreviousItem = createEvent(this, "calciteInternalFocusPreviousItem", 6);
// --------------------------------------------------------------------------
//
// Private Methods
//
// --------------------------------------------------------------------------
this.closeClickHandler = () => {
this.closed = true;
this.calciteListItemClose.emit();
};
this.handleContentSlotChange = (event) => {
this.hasCustomContent = slotChangeHasAssignedElement(event);
};
this.handleActionsStartSlotChange = (event) => {
this.hasActionsStart = slotChangeHasAssignedElement(event);
};
this.handleActionsEndSlotChange = (event) => {
this.hasActionsEnd = slotChangeHasAssignedElement(event);
};
this.handleContentStartSlotChange = (event) => {
this.hasContentStart = slotChangeHasAssignedElement(event);
};
this.handleContentEndSlotChange = (event) => {
this.hasContentEnd = slotChangeHasAssignedElement(event);
};
this.handleDefaultSlotChange = (event) => {
const { parentListEl } = this;
const listItemChildren = getListItemChildren(event);
updateListItemChildren(listItemChildren);
const openable = !!listItemChildren.length;
if (openable && parentListEl && !parentListEl.openable) {
parentListEl.openable = true;
}
this.openable = openable;
if (!openable) {
this.open = false;
}
};
this.toggleOpen = () => {
this.open = !this.open;
};
this.itemClicked = (event) => {
if (event.defaultPrevented) {
return;
}
this.toggleSelected();
this.calciteInternalListItemActive.emit();
};
this.toggleSelected = () => {
const { selectionMode, selected } = this;
if (this.disabled) {
return;
}
if (selectionMode === "multiple" || selectionMode === "single") {
this.selected = !selected;
}
else if (selectionMode === "single-persist") {
this.selected = true;
}
this.calciteListItemSelect.emit();
};
this.handleItemKeyDown = (event) => {
if (event.defaultPrevented) {
return;
}
const { key } = event;
const composedPath = event.composedPath();
const { containerEl, contentEl, actionsStartEl, actionsEndEl, open, openable } = this;
const cells = [actionsStartEl, contentEl, actionsEndEl].filter(Boolean);
const currentIndex = cells.findIndex((cell) => composedPath.includes(cell));
if (key === "Enter") {
event.preventDefault();
this.toggleSelected();
}
else if (key === "ArrowRight") {
event.preventDefault();
const nextIndex = currentIndex + 1;
if (currentIndex === -1) {
if (!open && openable) {
this.open = true;
this.focusCell(null);
}
else if (cells[0]) {
this.focusCell(cells[0]);
}
}
else if (cells[currentIndex] && cells[nextIndex]) {
this.focusCell(cells[nextIndex]);
}
}
else if (key === "ArrowLeft") {
event.preventDefault();
const prevIndex = currentIndex - 1;
if (currentIndex === -1) {
this.focusCell(null);
if (open && openable) {
this.open = false;
}
else {
this.calciteInternalFocusPreviousItem.emit();
}
}
else if (currentIndex === 0) {
this.focusCell(null);
containerEl.focus();
}
else if (cells[currentIndex] && cells[prevIndex]) {
this.focusCell(cells[prevIndex]);
}
}
};
this.focusCellNull = () => {
this.focusCell(null);
};
this.focusCell = (focusEl, saveFocusIndex = true) => {
const { contentEl, actionsStartEl, actionsEndEl, parentListEl } = this;
if (saveFocusIndex) {
focusMap.set(parentListEl, null);
}
[actionsStartEl, contentEl, actionsEndEl].filter(Boolean).forEach((tableCell, cellIndex) => {
const tabIndexAttr = "tabindex";
if (tableCell === focusEl) {
tableCell.setAttribute(tabIndexAttr, "0");
saveFocusIndex && focusMap.set(parentListEl, cellIndex);
}
else {
tableCell.removeAttribute(tabIndexAttr);
}
});
focusEl?.focus();
};
this.active = false;
this.closable = false;
this.closed = false;
this.description = undefined;
this.disabled = false;
this.label = undefined;
this.metadata = undefined;
this.open = false;
this.setSize = null;
this.setPosition = null;
this.selected = false;
this.value = undefined;
this.selectionMode = null;
this.selectionAppearance = null;
this.messageOverrides = undefined;
this.messages = undefined;
this.effectiveLocale = "";
this.defaultMessages = undefined;
this.level = null;
this.visualLevel = null;
this.parentListEl = undefined;
this.openable = false;
this.hasActionsStart = false;
this.hasActionsEnd = false;
this.hasCustomContent = false;
this.hasContentStart = false;
this.hasContentEnd = false;
}
activeHandler(active) {
if (!active) {
this.focusCell(null, false);
}
}
handleSelectedChange() {
this.calciteInternalListItemSelect.emit();
}
onMessagesChange() {
/* wired up by t9n util */
}
effectiveLocaleChange() {
updateMessages(this, this.effectiveLocale);
}
connectedCallback() {
connectInteractive(this);
connectLocalized(this);
connectMessages(this);
const { el } = this;
this.parentListEl = el.closest(listSelector);
this.level = getDepth(el) + 1;
this.visualLevel = getDepth(el, true);
this.setSelectionDefaults();
}
async componentWillLoad() {
setUpLoadableComponent(this);
await setUpMessages(this);
}
componentDidLoad() {
setComponentLoaded(this);
}
componentDidRender() {
updateHostInteraction(this, "managed");
}
disconnectedCallback() {
disconnectInteractive(this);
disconnectLocalized(this);
disconnectMessages(this);
}
// --------------------------------------------------------------------------
//
// Public Methods
//
// --------------------------------------------------------------------------
/** Sets focus on the component. */
async setFocus() {
await componentLoaded(this);
const { containerEl, contentEl, actionsStartEl, actionsEndEl, parentListEl } = this;
const focusIndex = focusMap.get(parentListEl);
if (typeof focusIndex === "number") {
const cells = [actionsStartEl, contentEl, actionsEndEl].filter(Boolean);
if (cells[focusIndex]) {
this.focusCell(cells[focusIndex]);
}
else {
containerEl?.focus();
}
return;
}
containerEl?.focus();
}
// --------------------------------------------------------------------------
//
// Render Methods
//
// --------------------------------------------------------------------------
renderSelected() {
const { selected, selectionMode, selectionAppearance } = this;
if (selectionMode === "none" || selectionAppearance === "border") {
return null;
}
return (h("td", { class: CSS$2.selectionContainer, key: "selection-container", onClick: this.itemClicked }, h("calcite-icon", { icon: selected
? selectionMode === "multiple"
? ICONS.selectedMultiple
: ICONS.selectedSingle
: ICONS.unselected, scale: "s" })));
}
renderOpen() {
const { el, open, openable, parentListEl } = this;
const dir = getElementDir(el);
return openable ? (h("td", { class: CSS$2.openContainer, key: "open-container", onClick: this.toggleOpen }, h("calcite-icon", { icon: open ? ICONS.open : dir === "rtl" ? ICONS.closedRTL : ICONS.closedLTR, scale: "s" }))) : parentListEl?.openable ? (h("td", { class: CSS$2.openContainer, key: "open-container", onClick: this.itemClicked }, h("calcite-icon", { icon: ICONS.blank, scale: "s" }))) : null;
}
renderActionsStart() {
const { label, hasActionsStart } = this;
return (h("td", { "aria-label": label, class: CSS$2.actionsStart, hidden: !hasActionsStart, key: "actions-start-container", role: "gridcell",
// eslint-disable-next-line react/jsx-sort-props
ref: (el) => (this.actionsStartEl = el) }, h("slot", { name: SLOTS.actionsStart, onSlotchange: this.handleActionsStartSlotChange })));
}
renderActionsEnd() {
const { label, hasActionsEnd, closable, messages } = this;
return (h("td", { "aria-label": label, class: CSS$2.actionsEnd, hidden: !(hasActionsEnd || closable), key: "actions-end-container", role: "gridcell",
// eslint-disable-next-line react/jsx-sort-props
ref: (el) => (this.actionsEndEl = el) }, h("slot", { name: SLOTS.actionsEnd, onSlotchange: this.handleActionsEndSlotChange }), closable ? (h("calcite-action", { appearance: "transparent", icon: ICONS.close, key: "close-action", label: messages.close, onClick: this.closeClickHandler, text: messages.close })) : null));
}
renderContentStart() {
const { hasContentStart } = this;
return (h("div", { class: CSS$2.contentStart, hidden: !hasContentStart }, h("slot", { name: SLOTS.contentStart, onSlotchange: this.handleContentStartSlotChange })));
}
renderCustomContent() {
const { hasCustomContent } = this;
return (h("div", { class: CSS$2.customContent, hidden: !hasCustomContent }, h("slot", { name: SLOTS.content, onSlotchange: this.handleContentSlotChange })));
}
renderContentEnd() {
const { hasContentEnd } = this;
return (h("div", { class: CSS$2.contentEnd, hidden: !hasContentEnd }, h("slot", { name: SLOTS.contentEnd, onSlotchange: this.handleContentEndSlotChange })));
}
renderContentProperties() {
const { label, description, hasCustomContent } = this;
return !hasCustomContent && (!!label || !!description) ? (h("div", { class: CSS$2.content, key: "content" }, label ? (h("div", { class: CSS$2.label, key: "label" }, label)) : null, description ? (h("div", { class: CSS$2.description, key: "description" }, description)) : null)) : null;
}
renderContentContainer() {
const { description, label, selectionMode, hasCustomContent } = this;
const hasCenterContent = hasCustomContent || !!label || !!description;
const content = [
this.renderContentStart(),
this.renderCustomContent(),
this.renderContentProperties(),
this.renderContentEnd()
];
return (h("td", { "aria-label": label, class: {
[CSS$2.contentContainer]: true,
[CSS$2.contentContainerSelectable]: selectionMode !== "none",
[CSS$2.contentContainerHasCenterContent]: hasCenterContent
}, key: "content-container", onClick: this.itemClicked, role: "gridcell",
// eslint-disable-next-line react/jsx-sort-props
ref: (el) => (this.contentEl = el) }, content));
}
render() {
const { openable, open, level, setPosition, setSize, active, label, selected, selectionAppearance, selectionMode, closed } = this;
const showBorder = selectionMode !== "none" && selectionAppearance === "border";
const borderSelected = showBorder && selected;
const borderUnselected = showBorder && !selected;
return (h(Host, null, h("tr", { "aria-expanded": openable ? toAriaBoolean(open) : null, "aria-label": label, "aria-level": level, "aria-posinset": setPosition, "aria-selected": toAriaBoolean(selected), "aria-setsize": setSize, class: {
[CSS$2.container]: true,
[CSS$2.containerBorderSelected]: borderSelected,
[CSS$2.containerBorderUnselected]: borderUnselected
}, hidden: closed, onFocus: this.focusCellNull, onKeyDown: this.handleItemKeyDown, role: "row", style: { "--calcite-list-item-spacing-indent-multiplier": `${this.visualLevel}` }, tabIndex: active ? 0 : -1,
// eslint-disable-next-line react/jsx-sort-props
ref: (el) => (this.containerEl = el) }, this.renderSelected(), this.renderOpen(), this.renderActionsStart(), this.renderContentContainer(), this.renderActionsEnd()), h("div", { class: {
[CSS$2.nestedContainer]: true,
[CSS$2.nestedContainerHidden]: openable && !open
} }, h("slot", { onSlotchange: this.handleDefaultSlotChange }))));
}
setSelectionDefaults() {
const { parentListEl, selectionMode, selectionAppearance } = this;
if (!parentListEl) {
return;
}
if (!selectionMode) {
this.selectionMode = parentListEl.selectionMode;
}
if (!selectionAppearance) {
this.selectionAppearance = parentListEl.selectionAppearance;
}
}
static get assetsDirs() { return ["assets"]; }
get el() { return getElement(this); }
static get watchers() { return {
"active": ["activeHandler"],
"selected": ["handleSelectedChange"],
"messageOverrides": ["onMessagesChange"],
"effectiveLocale": ["effectiveLocaleChange"]
}; }
};
ListItem.style = listItemCss;
const CSS = {
container: "container",
heading: "heading"
};
const listItemGroupCss = "@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-right{0%{opacity:0;transform:translate3D(-5px, 0, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-left{0%{opacity:0;transform:translate3D(5px, 0, 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-right{animation-name:in-right}.calcite-animate__in-left{animation-name:in-left}.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);--calcite-floating-ui-z-index:var(--calcite-app-z-index-dropdown)}:host([hidden]){display:none}:host([disabled]){cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host([disabled]) *,:host([disabled]) ::slotted(*){pointer-events:none}:host{display:flex;flex-direction:column;background-color:var(--calcite-ui-foreground-1);--calcite-list-item-spacing-indent:1rem}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}.container{margin:0px;display:flex;flex:1 1 0%;background-color:var(--calcite-ui-foreground-2);padding:0.75rem;font-family:var(--calcite-sans-family);font-size:var(--calcite-font-size--1);font-weight:var(--calcite-font-weight-bold);color:var(--calcite-ui-text-2)}.heading{padding-inline-start:calc(var(--calcite-list-item-spacing-indent) * var(--calcite-list-item-spacing-indent-multiplier))}::slotted(calcite-list-item){margin-block-end:1px;--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)}::slotted(calcite-list-item:last-child){--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)}[hidden]{display:none}";
const ListItemGroup = class {
constructor(hostRef) {
registerInstance(this, hostRef);
this.disabled = false;
this.heading = undefined;
this.visualLevel = null;
}
// --------------------------------------------------------------------------
//
// Lifecycle
//
// --------------------------------------------------------------------------
connectedCallback() {
const { el } = this;
this.visualLevel = getDepth(el, true);
connectInteractive(this);
}
componentDidRender() {
updateHostInteraction(this);
}
disconnectedCallback() {
disconnectInteractive(this);
}
// --------------------------------------------------------------------------
//
// Render Methods
//
// --------------------------------------------------------------------------
render() {
const { heading, visualLevel } = this;
return (h(Host, null, h("tr", { class: CSS.container, style: { "--calcite-list-item-spacing-indent-multiplier": `${visualLevel}` } }, h("td", { class: CSS.heading, colSpan: MAX_COLUMNS }, heading)), h("slot", null)));
}
get el() { return getElement(this); }
};
ListItemGroup.style = listItemGroupCss;
export { List as calcite_list, ListItem as calcite_list_item, ListItemGroup as calcite_list_item_group };