import { tree_item_styles_default } from "./chunk.JLE73CZG.js"; import { SlCheckbox } from "./chunk.3HUDUUUY.js"; import { l } from "./chunk.MB643KRE.js"; import { SlSpinner } from "./chunk.TEPHFVM5.js"; import { getAnimation, setDefaultAnimation } from "./chunk.RCZVQXWP.js"; import { animateTo, shimKeyframesHeightAuto, stopAnimations } from "./chunk.S7GYYU7Z.js"; import { LocalizeController } from "./chunk.NH3SRVOC.js"; import { e } from "./chunk.UZVKBFXH.js"; import { SlIcon } from "./chunk.UZYAV5H6.js"; import { watch } from "./chunk.FA5RT4K4.js"; import { ShoelaceElement, e as e2, n, r } from "./chunk.SEXBCYCU.js"; import { x } from "./chunk.CXZZ2LVK.js"; import { __decorateClass } from "./chunk.KIILAQWQ.js"; // node_modules/lit-html/directives/when.js function n2(n3, r2, t) { return n3 ? r2(n3) : t == null ? void 0 : t(n3); } // src/components/tree-item/tree-item.component.ts var _SlTreeItem = class _SlTreeItem extends ShoelaceElement { constructor() { super(...arguments); this.localize = new LocalizeController(this); this.indeterminate = false; this.isLeaf = false; this.loading = false; this.selectable = false; this.expanded = false; this.selected = false; this.disabled = false; this.lazy = false; } static isTreeItem(node) { return node instanceof Element && node.getAttribute("role") === "treeitem"; } connectedCallback() { super.connectedCallback(); this.setAttribute("role", "treeitem"); this.setAttribute("tabindex", "-1"); if (this.isNestedItem()) { this.slot = "children"; } } firstUpdated() { this.childrenContainer.hidden = !this.expanded; this.childrenContainer.style.height = this.expanded ? "auto" : "0"; this.isLeaf = !this.lazy && this.getChildrenItems().length === 0; this.handleExpandedChange(); } async animateCollapse() { this.emit("sl-collapse"); await stopAnimations(this.childrenContainer); const { keyframes, options } = getAnimation(this, "tree-item.collapse", { dir: this.localize.dir() }); await animateTo( this.childrenContainer, shimKeyframesHeightAuto(keyframes, this.childrenContainer.scrollHeight), options ); this.childrenContainer.hidden = true; this.emit("sl-after-collapse"); } // Checks whether the item is nested into an item isNestedItem() { const parent = this.parentElement; return !!parent && _SlTreeItem.isTreeItem(parent); } handleChildrenSlotChange() { this.loading = false; this.isLeaf = !this.lazy && this.getChildrenItems().length === 0; } willUpdate(changedProperties) { if (changedProperties.has("selected") && !changedProperties.has("indeterminate")) { this.indeterminate = false; } } async animateExpand() { this.emit("sl-expand"); await stopAnimations(this.childrenContainer); this.childrenContainer.hidden = false; const { keyframes, options } = getAnimation(this, "tree-item.expand", { dir: this.localize.dir() }); await animateTo( this.childrenContainer, shimKeyframesHeightAuto(keyframes, this.childrenContainer.scrollHeight), options ); this.childrenContainer.style.height = "auto"; this.emit("sl-after-expand"); } handleLoadingChange() { this.setAttribute("aria-busy", this.loading ? "true" : "false"); if (!this.loading) { this.animateExpand(); } } handleDisabledChange() { this.setAttribute("aria-disabled", this.disabled ? "true" : "false"); } handleSelectedChange() { this.setAttribute("aria-selected", this.selected ? "true" : "false"); } handleExpandedChange() { if (!this.isLeaf) { this.setAttribute("aria-expanded", this.expanded ? "true" : "false"); } else { this.removeAttribute("aria-expanded"); } } handleExpandAnimation() { if (this.expanded) { if (this.lazy) { this.loading = true; this.emit("sl-lazy-load"); } else { this.animateExpand(); } } else { this.animateCollapse(); } } handleLazyChange() { this.emit("sl-lazy-change"); } /** Gets all the nested tree items in this node. */ getChildrenItems({ includeDisabled = true } = {}) { return this.childrenSlot ? [...this.childrenSlot.assignedElements({ flatten: true })].filter( (item) => _SlTreeItem.isTreeItem(item) && (includeDisabled || !item.disabled) ) : []; } render() { const isRtl = this.localize.dir() === "rtl"; const showExpandButton = !this.loading && (!this.isLeaf || this.lazy); return x`