monobill-mintui 0.6.678 → 0.6.680
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/page/browser.js +4 -0
- package/dist/components/page/index.cjs +1 -1
- package/dist/components/page/index.js +4 -0
- package/dist/components/tree/Tree.d.ts +1 -0
- package/dist/components/tree/Tree.d.ts.map +1 -1
- package/dist/components/tree/browser.js +35 -7
- package/dist/components/tree/index.cjs +1 -1
- package/dist/components/tree/index.js +35 -7
- package/dist/index.cjs +2 -2
- package/dist/index.js +39 -7
- package/package.json +1 -1
|
@@ -79,6 +79,10 @@ var t = class extends HTMLElement {
|
|
|
79
79
|
this._actionsTrigger.hidden = !0, this._actionsPopover.style.display = "none", this._actionsWrapper.hidden = !0, this._groupingActions = !1;
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
|
+
if (e.length === 1) {
|
|
83
|
+
this._setActionSlot(e[0], "actions"), this._syncOverflowButtonWidths([]), this._actionsTrigger.hidden = !0, this._actionsPopover.style.display = "none", this._groupingActions = !1;
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
82
86
|
e.forEach((e) => this._setActionSlot(e, "actions")), this._syncOverflowButtonWidths([]), this._actionsPopover.style.display = "", this._actionsTrigger.hidden = !0;
|
|
83
87
|
let t = this._root.querySelector(".mint-page-actions-primary"), n = this._root.querySelector(".mint-page-header"), r = this._root.querySelector(".mint-page-heading");
|
|
84
88
|
this._actionsResizeObserver?.observe(t), e.forEach((e) => this._actionsResizeObserver?.observe(e));
|
|
@@ -97,4 +97,4 @@ require(`../chunks/icon-CGXHKbMq.js`);const e=require(`../chunks/register-elemen
|
|
|
97
97
|
</header>
|
|
98
98
|
<main part="body" class="mint-page-body"><slot></slot></main>
|
|
99
99
|
</div>
|
|
100
|
-
`,this._headingElement=this._root.querySelector(`.mint-page-heading`),this._backButton=this._root.querySelector(`.mint-page-back`),this._actionsSlot=this._root.querySelector(`slot[name="actions"]`),this._overflowActionsSlot=this._root.querySelector(`slot[name="overflow-actions"]`),this._actionsWrapper=this._root.querySelector(`.mint-page-actions`),this._actionsTrigger=this._root.querySelector(`#mint-page-actions-trigger`),this._actionsPopover=this._root.querySelector(`#mint-page-actions-popover`),this._actionsSlot.addEventListener(`slotchange`,()=>this._scheduleActionGrouping()),this._overflowActionsSlot.addEventListener(`slotchange`,()=>this._scheduleActionGrouping()),this._backButton.addEventListener(`click`,e=>this._handleBack(e),!0)}connectedCallback(){this.render(),this._actionsResizeObserver=new ResizeObserver(()=>this._scheduleActionGrouping()),this._actionsResizeObserver.observe(this._root.querySelector(`.mint-page-header`)),this._actionsMutationObserver=new MutationObserver(e=>{e.some(e=>e.type===`childList`||e.attributeName===`importance`||e.attributeName===`slot`&&![`actions`,`overflow-actions`].includes(e.target.getAttribute(`slot`)||``))&&this._scheduleActionGrouping()}),this._actionsMutationObserver.observe(this,{childList:!0,attributes:!0,attributeFilter:[`slot`,`importance`]}),this._scheduleActionGrouping()}disconnectedCallback(){this._actionsResizeObserver?.disconnect(),this._actionsMutationObserver?.disconnect(),this._actionsFrame!==null&&cancelAnimationFrame(this._actionsFrame),this._actionsFrame=null}attributeChangedCallback(e,t,n){t!==n&&this.isConnected&&this.render()}getHeading(){return this.getAttribute(`heading`)||``}getFallbackHref(){return this.getAttribute(`fallback-href`)||`/`}shouldShowBackButton(){return this.getAttribute(`show-back-button`)===`true`}isContainered(){return this.hasAttribute(`containered`)&&this.getAttribute(`containered`)!==`false`}render(){this._headingElement.textContent=this.getHeading(),this._backButton.setAttribute(`fallback-href`,this.getFallbackHref()),this._backButton.hidden=!this.shouldShowBackButton()}_scheduleActionGrouping(){this._actionsFrame!==null||!this.isConnected||(this._actionsFrame=requestAnimationFrame(()=>{this._actionsFrame=null,this._groupActions()}))}_groupActions(){if(this._groupingActions)return;this._groupingActions=!0;let e=Array.from(this.children).filter(e=>e instanceof HTMLElement&&(e.getAttribute(`slot`)===`actions`||e.getAttribute(`slot`)===`overflow-actions`));if(this._actionsWrapper.hidden=e.length===0,!e.length){this._actionsTrigger.hidden=!0,this._actionsPopover.style.display=`none`,this._actionsWrapper.hidden=!0,this._groupingActions=!1;return}e.forEach(e=>this._setActionSlot(e,`actions`)),this._syncOverflowButtonWidths([]),this._actionsPopover.style.display=``,this._actionsTrigger.hidden=!0;let t=this._root.querySelector(`.mint-page-actions-primary`),n=this._root.querySelector(`.mint-page-header`),r=this._root.querySelector(`.mint-page-heading`);this._actionsResizeObserver?.observe(t),e.forEach(e=>this._actionsResizeObserver?.observe(e));let i=n.clientWidth<=767,a=e.reduce((e,t,n)=>e+t.getBoundingClientRect().width+(n?8:0),0),o=this._backButton.hidden?0:this._backButton.getBoundingClientRect().width+16,s=Math.min(n.clientWidth,r.scrollWidth+o),c=Math.max(0,n.clientWidth-s-16),l=[],u=e=>{let t=e.getAttribute(`importance`),n=e.querySelector(`[importance]`)?.getAttribute(`importance`),r=Number(t??n??1);return Number.isFinite(r)&&r>0?r:1};!i&&a>c&&(c=Math.max(0,c-48));let d=a;for(;i?e.length>l.length:d>c&&l.length<e.length;){let t=e.filter(e=>!l.includes(e));t.sort((t,n)=>u(n)-u(t)||e.indexOf(n)-e.indexOf(t));let n=t[0];if(!n)break;l.push(n),d-=n.getBoundingClientRect().width+(l.length<e.length?8:0)}let f=new Set(l);e.forEach(e=>this._setActionSlot(e,f.has(e)?`overflow-actions`:`actions`)),this._actionsTrigger.hidden=l.length===0,this._actionsPopover.style.display=l.length===0?`none`:``,this._syncOverflowButtonWidths(l),this._actionsResizeObserver?.observe(this._actionsTrigger),this._groupingActions=!1}_setActionSlot(e,t){e.getAttribute(`slot`)!==t&&e.setAttribute(`slot`,t)}_syncOverflowButtonWidths(e){let t=new Set;e.forEach(e=>{e.matches(`mint-button`)&&t.add(e),e.querySelectorAll(`mint-button`).forEach(e=>t.add(e))}),Array.from(this.querySelectorAll(`mint-button[slot="actions"], mint-button[slot="overflow-actions"], [slot="actions"] mint-button, [slot="overflow-actions"] mint-button`)).forEach(e=>{if(t.has(e))this._actionFullWidthOriginal.has(e)||this._actionFullWidthOriginal.set(e,e.getAttribute(`full-width`)),e.setAttribute(`full-width`,`true`);else if(this._actionFullWidthOriginal.has(e)){let t=this._actionFullWidthOriginal.get(e);t===null?e.removeAttribute(`full-width`):t!==void 0&&e.setAttribute(`full-width`,t),this._actionFullWidthOriginal.delete(e)}})}_handleBack(e){e.preventDefault(),e.stopPropagation();let t=document.referrer,n=!!(t&&(()=>{try{return new URL(t).origin===window.location.origin}catch{return!1}})()),r={url:n?t:this.getFallbackHref(),isFromReferrer:n,referrer:t||null,fallbackHref:this.getFallbackHref()},i=new CustomEvent(`back`,{detail:r,bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(i)&&(n&&window.history.length>1?window.history.back():window.location.href=this.getFallbackHref())}};typeof customElements<`u`&&!customElements.get(`mint-page`)&&e.t(`mint-page`,t),module.exports=t;
|
|
100
|
+
`,this._headingElement=this._root.querySelector(`.mint-page-heading`),this._backButton=this._root.querySelector(`.mint-page-back`),this._actionsSlot=this._root.querySelector(`slot[name="actions"]`),this._overflowActionsSlot=this._root.querySelector(`slot[name="overflow-actions"]`),this._actionsWrapper=this._root.querySelector(`.mint-page-actions`),this._actionsTrigger=this._root.querySelector(`#mint-page-actions-trigger`),this._actionsPopover=this._root.querySelector(`#mint-page-actions-popover`),this._actionsSlot.addEventListener(`slotchange`,()=>this._scheduleActionGrouping()),this._overflowActionsSlot.addEventListener(`slotchange`,()=>this._scheduleActionGrouping()),this._backButton.addEventListener(`click`,e=>this._handleBack(e),!0)}connectedCallback(){this.render(),this._actionsResizeObserver=new ResizeObserver(()=>this._scheduleActionGrouping()),this._actionsResizeObserver.observe(this._root.querySelector(`.mint-page-header`)),this._actionsMutationObserver=new MutationObserver(e=>{e.some(e=>e.type===`childList`||e.attributeName===`importance`||e.attributeName===`slot`&&![`actions`,`overflow-actions`].includes(e.target.getAttribute(`slot`)||``))&&this._scheduleActionGrouping()}),this._actionsMutationObserver.observe(this,{childList:!0,attributes:!0,attributeFilter:[`slot`,`importance`]}),this._scheduleActionGrouping()}disconnectedCallback(){this._actionsResizeObserver?.disconnect(),this._actionsMutationObserver?.disconnect(),this._actionsFrame!==null&&cancelAnimationFrame(this._actionsFrame),this._actionsFrame=null}attributeChangedCallback(e,t,n){t!==n&&this.isConnected&&this.render()}getHeading(){return this.getAttribute(`heading`)||``}getFallbackHref(){return this.getAttribute(`fallback-href`)||`/`}shouldShowBackButton(){return this.getAttribute(`show-back-button`)===`true`}isContainered(){return this.hasAttribute(`containered`)&&this.getAttribute(`containered`)!==`false`}render(){this._headingElement.textContent=this.getHeading(),this._backButton.setAttribute(`fallback-href`,this.getFallbackHref()),this._backButton.hidden=!this.shouldShowBackButton()}_scheduleActionGrouping(){this._actionsFrame!==null||!this.isConnected||(this._actionsFrame=requestAnimationFrame(()=>{this._actionsFrame=null,this._groupActions()}))}_groupActions(){if(this._groupingActions)return;this._groupingActions=!0;let e=Array.from(this.children).filter(e=>e instanceof HTMLElement&&(e.getAttribute(`slot`)===`actions`||e.getAttribute(`slot`)===`overflow-actions`));if(this._actionsWrapper.hidden=e.length===0,!e.length){this._actionsTrigger.hidden=!0,this._actionsPopover.style.display=`none`,this._actionsWrapper.hidden=!0,this._groupingActions=!1;return}if(e.length===1){this._setActionSlot(e[0],`actions`),this._syncOverflowButtonWidths([]),this._actionsTrigger.hidden=!0,this._actionsPopover.style.display=`none`,this._groupingActions=!1;return}e.forEach(e=>this._setActionSlot(e,`actions`)),this._syncOverflowButtonWidths([]),this._actionsPopover.style.display=``,this._actionsTrigger.hidden=!0;let t=this._root.querySelector(`.mint-page-actions-primary`),n=this._root.querySelector(`.mint-page-header`),r=this._root.querySelector(`.mint-page-heading`);this._actionsResizeObserver?.observe(t),e.forEach(e=>this._actionsResizeObserver?.observe(e));let i=n.clientWidth<=767,a=e.reduce((e,t,n)=>e+t.getBoundingClientRect().width+(n?8:0),0),o=this._backButton.hidden?0:this._backButton.getBoundingClientRect().width+16,s=Math.min(n.clientWidth,r.scrollWidth+o),c=Math.max(0,n.clientWidth-s-16),l=[],u=e=>{let t=e.getAttribute(`importance`),n=e.querySelector(`[importance]`)?.getAttribute(`importance`),r=Number(t??n??1);return Number.isFinite(r)&&r>0?r:1};!i&&a>c&&(c=Math.max(0,c-48));let d=a;for(;i?e.length>l.length:d>c&&l.length<e.length;){let t=e.filter(e=>!l.includes(e));t.sort((t,n)=>u(n)-u(t)||e.indexOf(n)-e.indexOf(t));let n=t[0];if(!n)break;l.push(n),d-=n.getBoundingClientRect().width+(l.length<e.length?8:0)}let f=new Set(l);e.forEach(e=>this._setActionSlot(e,f.has(e)?`overflow-actions`:`actions`)),this._actionsTrigger.hidden=l.length===0,this._actionsPopover.style.display=l.length===0?`none`:``,this._syncOverflowButtonWidths(l),this._actionsResizeObserver?.observe(this._actionsTrigger),this._groupingActions=!1}_setActionSlot(e,t){e.getAttribute(`slot`)!==t&&e.setAttribute(`slot`,t)}_syncOverflowButtonWidths(e){let t=new Set;e.forEach(e=>{e.matches(`mint-button`)&&t.add(e),e.querySelectorAll(`mint-button`).forEach(e=>t.add(e))}),Array.from(this.querySelectorAll(`mint-button[slot="actions"], mint-button[slot="overflow-actions"], [slot="actions"] mint-button, [slot="overflow-actions"] mint-button`)).forEach(e=>{if(t.has(e))this._actionFullWidthOriginal.has(e)||this._actionFullWidthOriginal.set(e,e.getAttribute(`full-width`)),e.setAttribute(`full-width`,`true`);else if(this._actionFullWidthOriginal.has(e)){let t=this._actionFullWidthOriginal.get(e);t===null?e.removeAttribute(`full-width`):t!==void 0&&e.setAttribute(`full-width`,t),this._actionFullWidthOriginal.delete(e)}})}_handleBack(e){e.preventDefault(),e.stopPropagation();let t=document.referrer,n=!!(t&&(()=>{try{return new URL(t).origin===window.location.origin}catch{return!1}})()),r={url:n?t:this.getFallbackHref(),isFromReferrer:n,referrer:t||null,fallbackHref:this.getFallbackHref()},i=new CustomEvent(`back`,{detail:r,bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(i)&&(n&&window.history.length>1?window.history.back():window.location.href=this.getFallbackHref())}};typeof customElements<`u`&&!customElements.get(`mint-page`)&&e.t(`mint-page`,t),module.exports=t;
|
|
@@ -67,6 +67,10 @@ var t = class extends HTMLElement {
|
|
|
67
67
|
this._actionsTrigger.hidden = !0, this._actionsPopover.style.display = "none", this._actionsWrapper.hidden = !0, this._groupingActions = !1;
|
|
68
68
|
return;
|
|
69
69
|
}
|
|
70
|
+
if (e.length === 1) {
|
|
71
|
+
this._setActionSlot(e[0], "actions"), this._syncOverflowButtonWidths([]), this._actionsTrigger.hidden = !0, this._actionsPopover.style.display = "none", this._groupingActions = !1;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
70
74
|
e.forEach((e) => this._setActionSlot(e, "actions")), this._syncOverflowButtonWidths([]), this._actionsPopover.style.display = "", this._actionsTrigger.hidden = !0;
|
|
71
75
|
let t = this._root.querySelector(".mint-page-actions-primary"), n = this._root.querySelector(".mint-page-header"), r = this._root.querySelector(".mint-page-heading");
|
|
72
76
|
this._actionsResizeObserver?.observe(t), e.forEach((e) => this._actionsResizeObserver?.observe(e));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tree.d.ts","sourceRoot":"","sources":["../../../src/components/tree/Tree.ts"],"names":[],"mappings":"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
|
|
1
|
+
{"version":3,"file":"Tree.d.ts","sourceRoot":"","sources":["../../../src/components/tree/Tree.ts"],"names":[],"mappings":"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"}
|
|
@@ -708,17 +708,45 @@ var p = class extends HTMLElement {
|
|
|
708
708
|
}
|
|
709
709
|
_undo() {
|
|
710
710
|
let e = this._undoStack.pop();
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
}), u(this, "mint-tree-undo", { items: this.items }));
|
|
711
|
+
if (!e) return;
|
|
712
|
+
let n = this._items;
|
|
713
|
+
this._redoStack.push(t(this._items)), this._items = e, this._render(), this._emitHistoryChange(n), u(this, "mint-tree-undo", { items: this.items });
|
|
715
714
|
}
|
|
716
715
|
_redo() {
|
|
717
716
|
let e = this._redoStack.pop();
|
|
718
|
-
|
|
719
|
-
|
|
717
|
+
if (!e) return;
|
|
718
|
+
let n = this._items;
|
|
719
|
+
this._undoStack.push(t(this._items)), this._items = e, this._render(), this._emitHistoryChange(n), u(this, "mint-tree-redo", { items: this.items });
|
|
720
|
+
}
|
|
721
|
+
_emitHistoryChange(e) {
|
|
722
|
+
let t = this.items, n = (e) => {
|
|
723
|
+
let t = /* @__PURE__ */ new Map(), n = (e, r) => e.forEach((e, i) => {
|
|
724
|
+
let a = String(e.id);
|
|
725
|
+
t.set(a, {
|
|
726
|
+
parentId: r,
|
|
727
|
+
index: i,
|
|
728
|
+
item: e
|
|
729
|
+
}), n(e.children || [], a);
|
|
730
|
+
});
|
|
731
|
+
return n(e, null), t;
|
|
732
|
+
}, r = n(e), i = n(this._items), a = [...new Set([...r.keys(), ...i.keys()])].find((e) => {
|
|
733
|
+
let t = r.get(e), n = i.get(e);
|
|
734
|
+
return t && n && (t.parentId !== n.parentId || t.index !== n.index);
|
|
735
|
+
});
|
|
736
|
+
if (u(this, "mint-tree-change", {
|
|
737
|
+
items: t,
|
|
720
738
|
itemId: this._selectedId
|
|
721
|
-
}),
|
|
739
|
+
}), !a) return;
|
|
740
|
+
let o = r.get(a), s = i.get(a), c = {
|
|
741
|
+
itemId: a,
|
|
742
|
+
item: { ...s.item },
|
|
743
|
+
items: t,
|
|
744
|
+
oldParentId: o.parentId,
|
|
745
|
+
newParentId: s.parentId,
|
|
746
|
+
oldIndex: o.index,
|
|
747
|
+
newIndex: s.index
|
|
748
|
+
};
|
|
749
|
+
u(this, o.parentId === s.parentId ? "mint-tree-reorder" : "mint-tree-reparent", c);
|
|
722
750
|
}
|
|
723
751
|
_keyboardIndent(e) {
|
|
724
752
|
let t = r(this._items, e);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}}),require(`../chunks/icon-CGXHKbMq.js`);const e=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/spinner-DfPbEa2d.js`),require(`../chunks/button-WCO2Tpah.js`),require(`../chunks/confirm-action-BMb31P5R.js`),require(`../chunks/popover-eTECdkG7.js`),require(`../chunks/sortable-BmObFEEn.js`);function t(e=[]){s(e);let t=e=>e.map(e=>({...e,children:Array.isArray(e.children)?t(e.children):[]}));return t(e)}function n(e,t){let r=String(t);for(let t of e){if(String(t.id)===r)return t;let e=n(t.children||[],r);if(e)return e}return null}function r(e,t,n=null){let i=String(t);for(let t of e){if(String(t.id)===i)return{parentId:n,siblings:e,item:t};let a=r(t.children||[],i,String(t.id));if(a)return a}return null}function i(e,t,n=0){let r=String(t);for(let t of e){if(String(t.id)===r)return n;let e=i(t.children||[],r,n+1);if(e>=0)return e}return-1}function a(e){let t=Array.isArray(e?.children)?e.children:[];return t.length?1+Math.max(...t.map(a)):1}function o(e,t){return String(e.id)===String(t)?!0:(e.children||[]).some(e=>o(e,t))}function s(e){let t=new Set,n=e=>{for(let r of e){if(r.id===null||r.id===void 0||String(r.id)===``)throw Error(`Every tree item must have a non-empty identifier.`);let e=String(r.id);if(t.has(e))throw Error(`Tree item identifiers must be unique. Duplicate identifier: ${e}.`);t.add(e),n(r.children||[])}};n(e)}function c(e,s,c,l,u={}){let d=t(e),f=r(d,s);if(!f)throw Error(`Tree item ${s} was not found.`);if(f.item.disabled||f.item.draggable===!1)throw Error(`Disabled tree items cannot be moved.`);let p=c==null||c===``?null:n(d,c);if(c!=null&&c!==``&&!p)throw Error(`Target parent ${c} was not found.`);if(p&&o(f.item,p.id))throw Error(`A tree item cannot be moved inside itself or one of its descendants.`);if(p?.disabled)throw Error(`Disabled tree items cannot contain children.`);if(u.allowNesting===!1&&p)throw Error(`Nesting is disabled for this tree.`);if(p?.canHaveChildren===!1)throw Error(`The target item cannot contain children.`);if(p?.acceptsTypes?.length&&!p.acceptsTypes.includes(f.item.type))throw Error(`The target item does not accept this item type.`);let m=p?p.children:d,h=f.siblings.findIndex(e=>String(e.id)===String(s)),[g]=f.siblings.splice(h,1),_=Math.min(Math.max(0,Number.isFinite(l)?Math.trunc(l):m.length),m.length);m.splice(_,0,g);let v=Number.isFinite(u.maxDepth)?Math.max(1,Math.trunc(u.maxDepth)):1/0;if((p?i(d,p.id)+1:0)+a(g)>v)throw Error(`Moving this branch would exceed the maximum tree depth of ${v}.`);return{items:d,item:g,oldParentId:f.parentId,newParentId:p?String(p.id):null,oldIndex:h,newIndex:_}}var l=0;function u(e,t,n){e.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:n}))}function d(e,t){let n=e.getAttribute(t);return n===``||n===`true`}function f(e){return e==null||e===``?null:String(e)}var p=class extends HTMLElement{constructor(...e){super(...e),this._items=[],this._undoStack=[],this._redoStack=[],this._selectedId=null,this._expandedIds=new Set,this._root=null,this._confirm=null,this._treeId=`mint-tree-${++l}`,this._liveRegion=null,this._dragExpansion=null,this._autoExpandedIds=new Set,this._dragHoverExpandedId=null,this._keyboardFocusRestore=null,this._suppressSelectionClick=!1,this._selectionClickSuppressionTimer=null,this._onClick=e=>{let t=e.target instanceof Element?e.target.closest(`[data-tree-command]`):null;if(!t||!this.contains(t))return;let r=t.getAttribute(`data-tree-command`),i=t.getAttribute(`data-tree-id`);if(r===`create-root`)u(this,`mint-tree-create`,{parentId:null,items:this.items});else if(r===`expand-all`)this._expandedIds=this._defaultExpandedIds(this._items),this._syncExpandedDOM(),u(this,`mint-tree-expand`,{all:!0,expandedIds:this.expandedIds});else if(r===`collapse-all`)this._expandedIds.clear(),this._syncExpandedDOM(),u(this,`mint-tree-collapse`,{all:!0,expandedIds:[]});else if(r===`undo`)this._undo();else if(r===`redo`)this._redo();else if(r===`toggle`&&i){let e=!this._expandedIds.has(i);this._setExpanded(i,e,!0)}else if(r===`select`&&i){if(this.classList.contains(`mint-tree-drag-active`)||this._suppressSelectionClick){e.preventDefault(),this._suppressSelectionClick=!1,this._selectionClickSuppressionTimer!==null&&window.clearTimeout(this._selectionClickSuppressionTimer),this._selectionClickSuppressionTimer=null;return}this._select(i)}else if(r===`create-child`&&i)this._closeItemPopover(t),u(this,`mint-tree-create`,{parentId:i,items:this.items});else if(r===`edit`&&i){this._closeItemPopover(t);let e=n(this._items,i);e&&u(this,`mint-tree-edit`,{item:{...e},itemId:i,items:this.items})}else if(r===`delete`&&i)this._closeItemPopover(t),this._confirmDelete(i);else if([`move-up`,`move-down`,`nest-previous`,`outdent`].includes(r||``)&&i)this._closeItemPopover(t),this._moveByCommand(i,r||``);else if(r===`custom`&&i){this._closeItemPopover(t);let e=n(this._items,i),r=t.getAttribute(`data-tree-action`)||``,a=e?.actions?.find(e=>e.id===r);if(e&&a){let t={item:{...e},itemId:i,action:{...a,onSelect:void 0},items:this.items};u(this,`mint-tree-action`,t),a.onSelect?.({item:{...e},itemId:i,action:a,items:this.items})}}},this._onSortableDrag=e=>{let t=e.detail;if(!t||!Number.isFinite(t.clientX)||!Number.isFinite(t.clientY))return;let r=document.elementFromPoint(t.clientX,t.clientY),i=r?.closest(`[data-mint-tree-row]`),a=t.item?.getAttribute(`data-tree-id`)||``,o=null;if(i&&i.getAttribute(`data-tree-id`)!==a){let e=i.querySelector(`:scope > .mint-tree-row`)?.getBoundingClientRect()||i.getBoundingClientRect(),r=e.height?(t.clientY-e.top)/e.height:0;if(r>.22&&r<.78){let e=i.getAttribute(`data-tree-id`)||``;n(this._items,e)&&this._isValidDrop(a,e)&&(o=e)}}if(!o&&this._dragHoverExpandedId){let e=[...this._root?.querySelectorAll(`[data-tree-id]`)??[]].find(e=>e.getAttribute(`data-tree-id`)===this._dragHoverExpandedId)?.querySelector(`:scope > mint-sortable.mint-tree-children`);r&&e?.contains(r)&&(o=this._dragHoverExpandedId)}if(this._dragHoverExpandedId&&this._dragHoverExpandedId!==o){let e=this._dragHoverExpandedId;this._dragHoverExpandedId=null,this._autoExpandedIds.delete(e),this._expandedIds.delete(e),this._syncNodeExpanded(e);let t=n(this._items,e);t&&u(this,`mint-tree-collapse`,{itemId:e,item:{...t},expandedIds:this.expandedIds,automatic:!0})}if(o){let e=n(this._items,o);e&&!this._expandedIds.has(o)&&(this._expandedIds.add(o),this._autoExpandedIds.add(o),this._dragHoverExpandedId=o,this._syncNodeExpanded(o),u(this,`mint-tree-expand`,{itemId:o,item:{...e},expandedIds:this.expandedIds,automatic:!0}))}},this._onSortableStart=()=>{this.classList.add(`mint-tree-drag-active`),this._dragHoverExpandedId=null,this._dragExpansion?.timer!==null&&this._dragExpansion?.timer!==void 0&&window.clearTimeout(this._dragExpansion.timer),this._dragExpansion=null;let e=this._root?.querySelector(`.mint-sortable-dragging[data-tree-id]`),t=e?.getAttribute(`data-tree-id`)||``,n=e?.querySelector(`:scope > mint-sortable.mint-tree-children`);if(!e||!t||!n||n.hidden||!this._expandedIds.has(t))return;let r=e.querySelector(`:scope > .mint-tree-row`),i=this._root?.querySelector(`.mint-sortable-placeholder`),a=n.getBoundingClientRect().height;n.style.height=`${a}px`,n.style.overflow=`hidden`,e.style.height=`auto`,e.style.overflow=`hidden`,this._dragExpansion={itemId:t,item:e,childList:n,timer:null},this._setTransientExpanded(t,!1),n.offsetHeight,requestAnimationFrame(()=>{this._dragExpansion?.childList===n&&(n.classList.add(`mint-tree-drag-collapse`),n.style.height=`0px`,i&&r&&(i.style.minHeight=`${r.getBoundingClientRect().height}px`))})},this._onSortableEnd=e=>{this.classList.remove(`mint-tree-drag-active`),this._suppressSelectionClick=!0,this._selectionClickSuppressionTimer!==null&&window.clearTimeout(this._selectionClickSuppressionTimer),this._selectionClickSuppressionTimer=window.setTimeout(()=>{this._suppressSelectionClick=!1,this._selectionClickSuppressionTimer=null},300);let t=e.detail,r=t&&!t.cancelled?f(t.newParentId):null;for(let e of this._autoExpandedIds){if(e===r)continue;this._expandedIds.delete(e),this._syncNodeExpanded(e);let t=n(this._items,e);t&&u(this,`mint-tree-collapse`,{itemId:e,item:{...t},expandedIds:this.expandedIds,automatic:!0})}this._autoExpandedIds.clear(),this._dragHoverExpandedId=null;let i=this._dragExpansion;if(!i)return;i.item=[...this._root?.querySelectorAll(`[data-tree-id]`)??[]].find(e=>e.getAttribute(`data-tree-id`)===i.itemId)||i.item,i.childList=i.item.querySelector(`:scope > mint-sortable.mint-tree-children`)||i.childList;let{item:a,childList:o,itemId:s}=i;o.style.height=`0px`,o.style.overflow=`hidden`,o.classList.remove(`mint-tree-drag-collapse`),this._setTransientExpanded(s,!0),o.offsetHeight;let c=o.scrollHeight;requestAnimationFrame(()=>{this._dragExpansion===i&&(o.style.height=`${c}px`)}),i.timer=window.setTimeout(()=>{o.style.height=``,o.style.overflow=``,o.style.opacity=``,this._dragExpansion=null},155)},this._onSortableDragOver=e=>{let t=e,{item:r,target:i}=t.detail||{};if(!r||!i)return;this._root?.querySelectorAll(`.mint-tree-drop-invalid`).forEach(e=>e.classList.remove(`mint-tree-drop-invalid`));let a=this._root?.querySelector(`.mint-sortable-placeholder`),o=r.getAttribute(`data-tree-id`)||``,s=f(i.getAttribute(`data-tree-parent-id`)),c=i===t.detail.source||this._isValidDrop(o,s),l=s?n(this._items,s):null;c&&i!==t.detail.source&&l?a?.setAttribute(`data-drop-label`,`Drop here to nest under ${l.label}`):c&&i===this._root?.querySelector(`:scope > mint-sortable`)?a?.setAttribute(`data-drop-label`,`Drop here to move to the top level`):a?.removeAttribute(`data-drop-label`);let u=(Number.isFinite(t.detail.clientX)&&Number.isFinite(t.detail.clientY)?document.elementFromPoint(t.detail.clientX,t.detail.clientY):null)?.closest(`[data-mint-tree-row]`);u&&u.getAttribute(`data-tree-id`)!==o&&!c&&u.classList.add(`mint-tree-drop-invalid`),c||t.preventDefault()},this._onSortableBeforeDrop=e=>{let t=e,n=t.detail;if(!n?.item||!n.target)return;let r=n.item.getAttribute(`data-tree-id`)||``,i=f(n.target.getAttribute(`data-tree-parent-id`));n.target!==n.source&&!this._isValidDrop(r,i)&&t.preventDefault()},this._onSortableChange=e=>{let t=e.detail;if(!t||t.cancelled)return;let r=t.itemId||``,i=f(t.oldParentId),a=f(t.newParentId),o=this._root?.querySelector(`:scope > mint-sortable`);if(!o)return;let s=n(this._items,r);this._recordHistory(),this._items=this._readItemsFromDOM(o),this._collapseEmptyExpandedNodes();let c=n(this._items,r);if(!c||!s)return;let l={itemId:r,item:{...c},items:this.items,oldParentId:i,newParentId:a,oldIndex:Number(t.oldIndex??-1),newIndex:Number(t.newIndex??-1)};this._clearDropState(),u(this,`mint-tree-change`,{items:l.items,itemId:r}),i===a?u(this,`mint-tree-reorder`,l):u(this,`mint-tree-reparent`,l);let d=`${c.label} moved${a?` into ${n(this._items,a)?.label||`a group`}`:` to the top level`}.`;this._dragExpansion?.itemId===r?window.setTimeout(()=>{this.isConnected&&(this._render(),this._focusRow(r),this._announce(d))},155):(this._render(),this._focusRow(r),this._announce(d))},this._onKeydown=e=>{let t=e.target instanceof Element?e.target.closest(`[data-mint-tree-row]`):null;if(!t)return;if(e.altKey&&[`ArrowUp`,`ArrowDown`].includes(e.key)){e.preventDefault();let n=t.getAttribute(`data-tree-id`)||``;if(n){this._keyboardFocusRestore&&window.clearTimeout(this._keyboardFocusRestore.timer);let e={id:n,x:window.scrollX,y:window.scrollY,timer:0};e.timer=window.setTimeout(()=>{this._keyboardFocusRestore===e&&(this._keyboardFocusRestore=null)},2e3),this._keyboardFocusRestore=e}return}let i=t.getAttribute(`data-tree-id`)||``;if(e.altKey&&e.key===`ArrowRight`){e.preventDefault(),this._keyboardIndent(i);return}if(e.altKey&&e.key===`ArrowLeft`){e.preventDefault(),this._keyboardOutdent(i);return}let a=[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].filter(e=>!e.closest(`mint-sortable[hidden]`)),o=a.indexOf(t);if(e.key===`ArrowDown`)e.preventDefault(),a[o+1]?.focus({preventScroll:!0});else if(e.key===`ArrowUp`)e.preventDefault(),a[o-1]?.focus({preventScroll:!0});else if(e.key===`ArrowRight`)e.preventDefault(),this._expandedIds.has(i)?a[o+1]?.focus({preventScroll:!0}):this._setExpanded(i,!0,!0);else if(e.key===`ArrowLeft`)if(e.preventDefault(),this._expandedIds.has(i))this._setExpanded(i,!1,!0);else{let e=r(this._items,i)?.parentId;e&&[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].find(t=>t.getAttribute(`data-tree-id`)===e)?.focus({preventScroll:!0})}else if(e.key===`Enter`||e.key===` `||e.key===`Spacebar`){let r=e.target instanceof Element?e.target.closest(`[data-tree-command="select"]`):null;(t===e.target||r)&&(e.preventDefault(),n(this._items,i)?.children?.length?this._setExpanded(i,!this._expandedIds.has(i),!0):this._select(i))}}}static get observedAttributes(){return[`selected-id`,`max-depth`,`allow-nesting`,`disabled`,`loading`,`create-label`,`empty-label`,`delete-confirmation`,`expanded-ids`]}connectedCallback(){this._root||(this._selectedId=f(this.getAttribute(`selected-id`)),this._expandedIds=this.hasAttribute(`expanded-ids`)?this._readExpandedIds(this.getAttribute(`expanded-ids`)):this._defaultExpandedIds(this._items),this.addEventListener(`click`,this._onClick),this.addEventListener(`keydown`,this._onKeydown,!0),this.addEventListener(`mint-sortable-start`,this._onSortableStart),this.addEventListener(`mint-sortable-end`,this._onSortableEnd),this.addEventListener(`mint-sortable-drag`,this._onSortableDrag),this.addEventListener(`mint-sortable-drag-over`,this._onSortableDragOver),this.addEventListener(`mint-sortable-before-drop`,this._onSortableBeforeDrop),this.addEventListener(`mint-sortable-change`,this._onSortableChange),this._render())}disconnectedCallback(){this._dragExpansion?.timer!==null&&this._dragExpansion?.timer!==void 0&&window.clearTimeout(this._dragExpansion.timer),this._keyboardFocusRestore&&window.clearTimeout(this._keyboardFocusRestore.timer),this._selectionClickSuppressionTimer!==null&&window.clearTimeout(this._selectionClickSuppressionTimer),this._selectionClickSuppressionTimer=null,this._suppressSelectionClick=!1,this._keyboardFocusRestore=null,this._dragExpansion=null,this._autoExpandedIds.clear(),this._dragHoverExpandedId=null,this.classList.remove(`mint-tree-drag-active`),this.removeEventListener(`click`,this._onClick),this.removeEventListener(`keydown`,this._onKeydown,!0),this.removeEventListener(`mint-sortable-start`,this._onSortableStart),this.removeEventListener(`mint-sortable-end`,this._onSortableEnd),this.removeEventListener(`mint-sortable-drag`,this._onSortableDrag),this.removeEventListener(`mint-sortable-drag-over`,this._onSortableDragOver),this.removeEventListener(`mint-sortable-before-drop`,this._onSortableBeforeDrop),this.removeEventListener(`mint-sortable-change`,this._onSortableChange),this._root=null}attributeChangedCallback(e,t,n){if(!(t===n||!this.isConnected)){if(e===`selected-id`){this._selectedId=f(n),this._syncSelectionDOM();return}e===`expanded-ids`&&(this._expandedIds=this._readExpandedIds(n)),this._render()}}get items(){return t(this._items)}set items(e){this._items=t(Array.isArray(e)?e:[]),this._undoStack=[],this._redoStack=[],this.hasAttribute(`expanded-ids`)||(this._expandedIds=this._defaultExpandedIds(this._items)),this.isConnected&&this._render()}get selectedId(){return this._selectedId}set selectedId(e){this._selectedId=f(e),this._selectedId===null?this.removeAttribute(`selected-id`):this.setAttribute(`selected-id`,this._selectedId)}get expandedIds(){return[...this._expandedIds]}set expandedIds(e){this._expandedIds=new Set((Array.isArray(e)?e:[]).map(String)),this.isConnected&&this._render()}save(){u(this,`mint-tree-save`,{items:this.items})}select(e){this._select(String(e))}expand(e){this._setExpanded(String(e),!0,!0)}collapse(e){this._setExpanded(String(e),!1,!0)}_readExpandedIds(e){if(!e)return this._defaultExpandedIds(this._items);try{let t=JSON.parse(e);return new Set(Array.isArray(t)?t.map(String):[])}catch{return new Set(e.split(`,`).map(e=>e.trim()).filter(Boolean))}}_defaultExpandedIds(e){let t=new Set,n=e=>e.forEach(e=>{e.children?.length&&(t.add(String(e.id)),n(e.children))});return n(e),t}_maxDepth(){let e=Number.parseInt(this.getAttribute(`max-depth`)||``,10);return Number.isFinite(e)&&e>0?e:1/0}_allowNesting(){return!this.hasAttribute(`allow-nesting`)||d(this,`allow-nesting`)}_disabled(){return d(this,`disabled`)}_isLoading(){return d(this,`loading`)}_render(){let e=document.activeElement instanceof HTMLElement?document.activeElement.closest(`[data-mint-tree-row]`):null,t=e&&this.contains(e)?e.getAttribute(`data-tree-id`):null;t&&this._keyboardFocusRestore&&(this._keyboardFocusRestore.id=t);let n=document.createElement(`div`);n.className=`mint-tree-shell`,n.setAttribute(`role`,`tree`),n.setAttribute(`aria-label`,this.getAttribute(`aria-label`)||`Hierarchical items`),n.setAttribute(`aria-busy`,String(this._isLoading()));let r=document.createElement(`div`);r.className=`mint-tree-toolbar`;let i=document.createElement(`span`);i.className=`mint-tree-count`,i.textContent=`${this._countItems()} ${this._countItems()===1?`item`:`items`}`,r.appendChild(i);let a=document.createElement(`div`);a.className=`mint-tree-toolbar-actions`;let o=this._createButton(``,`ghost`,`undo`);o.setAttribute(`icon`,`undo`),o.setAttribute(`aria-label`,`Undo last change`),o.setAttribute(`title`,`Undo`),(!this._undoStack.length||this._disabled())&&o.setAttribute(`disabled`,`true`);let s=this._createButton(``,`ghost`,`redo`);s.setAttribute(`icon`,`redo`),s.setAttribute(`aria-label`,`Redo last undone change`),s.setAttribute(`title`,`Redo`),(!this._redoStack.length||this._disabled())&&s.setAttribute(`disabled`,`true`);let c=this._createButton(``,`ghost`,`expand-all`);c.setAttribute(`icon`,`expand`),c.setAttribute(`aria-label`,`Expand all`),c.setAttribute(`title`,`Expand all`);let l=this._createButton(``,`ghost`,`collapse-all`);if(l.setAttribute(`icon`,`collapse`),l.setAttribute(`aria-label`,`Collapse all`),l.setAttribute(`title`,`Collapse all`),a.append(o,s,c,l),r.appendChild(a),n.appendChild(r),this._isLoading()){let e=document.createElement(`div`);e.className=`mint-tree-loading`,e.setAttribute(`aria-label`,`Loading items`);let t=document.createElement(`mint-spinner`);t.setAttribute(`size`,`small`),e.appendChild(t),n.appendChild(e)}else if(this._items.length)n.appendChild(this._createList(this._items,null,0));else{let e=document.createElement(`div`);e.className=`mint-tree-empty`,e.textContent=this.getAttribute(`empty-label`)||`No items yet.`,n.appendChild(e)}this._liveRegion=document.createElement(`div`),this._liveRegion.className=`mint-tree-live-region`,this._liveRegion.setAttribute(`role`,`status`),this._liveRegion.setAttribute(`aria-live`,`polite`),this._liveRegion.setAttribute(`aria-atomic`,`true`),n.appendChild(this._liveRegion);let u=document.createElement(`mint-confirm-action`);u.className=`mint-tree-confirm`,this._confirm=u,n.appendChild(u),this.replaceChildren(n),this._root=n,this.classList.add(`mint-tree`),this._disabled()?this.setAttribute(`aria-disabled`,`true`):this.removeAttribute(`aria-disabled`);let d=this._keyboardFocusRestore;d&&(this._focusRow(d.id),window.scrollTo({left:d.x,top:d.y,behavior:`instant`}),requestAnimationFrame(()=>{this._keyboardFocusRestore===d&&(this._focusRow(d.id),window.scrollTo({left:d.x,top:d.y,behavior:`instant`}))}))}_countItems(e=this._items){return e.reduce((e,t)=>e+1+this._countItems(t.children||[]),0)}_createButton(e,t,n){let r=document.createElement(`mint-button`);return r.textContent=e,r.setAttribute(`variant`,t),r.setAttribute(`data-tree-command`,n),r}_createList(e,t,n){let r=document.createElement(`mint-sortable`);r.id=`${this._treeId}-list-${t??`root`}`,r.setAttribute(`group`,this._treeId),r.setAttribute(`data-tree-parent-id`,t??``),r.setAttribute(`role`,`group`),r.setAttribute(`data-tree-depth`,String(n)),r.setAttribute(`direction`,`vertical`),r.setAttribute(`gap`,`1`),r.setAttribute(`handle-selector`,`[data-mint-sortable-handle]`),r.setAttribute(`animation-duration`,`320`),r.setAttribute(`item-key-attribute`,`data-tree-id`);let i=document.createElement(`mint-stack`);i.setAttribute(`direction`,`vertical`),i.setAttribute(`gap`,`1`);for(let t of e)i.appendChild(this._createNode(t,n));return r.appendChild(i),r}_createNode(e,t){let n=String(e.id),r=Array.isArray(e.children)?e.children:[],i=e.canHaveChildren!==!1&&this._allowNesting()&&t+a(e)<this._maxDepth(),o=document.createElement(`div`);o.className=`mint-tree-node`,o.setAttribute(`data-tree-id`,n),o.setAttribute(`role`,`treeitem`),o.setAttribute(`data-mint-tree-row`,``),o.setAttribute(`aria-level`,String(t+1)),o.setAttribute(`aria-selected`,String(this._selectedId===n)),o.setAttribute(`tabindex`,this._selectedId===n||this._selectedId===null&&t===0&&this._items[0]?.id===e.id?`0`:`-1`),o.setAttribute(`aria-label`,e.label),r.length&&o.setAttribute(`aria-expanded`,String(this._expandedIds.has(n))),(e.disabled||this._disabled())&&o.setAttribute(`aria-disabled`,`true`),(e.draggable===!1||this._disabled())&&o.setAttribute(`data-sortable-disabled`,``);let s=document.createElement(`div`);s.className=`mint-tree-row`,s.setAttribute(`data-tree-id`,n);let c=document.createElement(`span`);c.className=`mint-tree-drag-handle`,c.setAttribute(`data-mint-sortable-handle`,``),c.setAttribute(`role`,`button`),c.setAttribute(`tabindex`,`-1`),c.setAttribute(`aria-label`,`Drag ${e.label} to move`);let l=document.createElement(`mint-icon`);if(l.setAttribute(`name`,`grip-dots`),l.setAttribute(`aria-hidden`,`true`),c.appendChild(l),s.appendChild(c),r.length){let t=document.createElement(`mint-button`);t.className=`mint-tree-expand`,t.setAttribute(`variant`,`ghost`),t.setAttribute(`icon`,this._expandedIds.has(n)?`caret-up`:`caret-down`),t.setAttribute(`data-tree-command`,`toggle`),t.setAttribute(`data-tree-id`,n),t.setAttribute(`aria-label`,`${this._expandedIds.has(n)?`Collapse`:`Expand`} ${e.label}`),t.setAttribute(`aria-expanded`,String(this._expandedIds.has(n))),(this._disabled()||e.disabled===!0)&&t.setAttribute(`disabled`,`true`),s.appendChild(t)}else{let e=document.createElement(`span`);e.className=`mint-tree-expand-spacer`,e.setAttribute(`aria-hidden`,`true`),s.appendChild(e)}let u=document.createElement(`span`);if(u.className=`mint-tree-label`,u.setAttribute(`data-tree-command`,`select`),u.setAttribute(`data-tree-id`,n),i&&(u.setAttribute(`data-mint-sortable-drop-container`,`${this._treeId}-list-${n}`),u.setAttribute(`data-mint-sortable-drop-end`,``)),e.icon){let t=document.createElement(`mint-icon`);t.setAttribute(`name`,String(e.icon)),t.setAttribute(`aria-hidden`,`true`),u.appendChild(t)}let d=document.createElement(`span`);if(d.className=`mint-tree-label-text`,d.textContent=e.label,u.appendChild(d),s.appendChild(u),e.metadata){let t=document.createElement(`span`);t.className=`mint-tree-metadata`,t.textContent=String(e.metadata),s.appendChild(t)}let f=document.createElement(`span`);f.className=`mint-tree-nest-target`,f.setAttribute(`data-mint-sortable-drop-container`,`${this._treeId}-list-${n}`),f.setAttribute(`data-mint-sortable-drop-end`,``),f.setAttribute(`aria-hidden`,`true`);let p=document.createElement(`mint-icon`);p.setAttribute(`name`,`arrow-right`),p.setAttribute(`aria-hidden`,`true`),f.appendChild(p),i&&s.appendChild(f);let m=this._createActions(e,i);s.appendChild(m),o.appendChild(s);let h=this._createList(r,n,t+1);return h.classList.add(`mint-tree-children`),h.hidden=!this._expandedIds.has(n),o.appendChild(h),o}_createActions(e,t){let i=document.createElement(`div`);i.className=`mint-tree-actions`;let a=`${this._treeId}-actions-trigger-${encodeURIComponent(String(e.id))}`,o=`${a}-popover`,s=document.createElement(`mint-button`);s.id=a,s.setAttribute(`variant`,`ghost`),s.setAttribute(`icon`,`ellipsis`),s.setAttribute(`aria-label`,`Actions for ${e.label}`),s.setAttribute(`aria-haspopup`,`menu`),i.appendChild(s);let c=document.createElement(`mint-popover`);c.id=o,c.setAttribute(`trigger-id`,a),c.setAttribute(`direction`,`down`),c.setAttribute(`trigger-align`,`end`),c.setAttribute(`padding`,`0.3rem`);let l=document.createElement(`div`);l.className=`mint-tree-menu`,l.setAttribute(`role`,`menu`);let u=(t,n,r=!1)=>{let i=document.createElement(`mint-button`);i.textContent=n,i.setAttribute(`variant`,`ghost`),i.setAttribute(`full-width`,`true`),i.setAttribute(`align`,`left`),i.setAttribute(`role`,`menuitem`),i.setAttribute(`data-tree-command`,t),i.setAttribute(`data-tree-id`,String(e.id)),(r||e.disabled===!0||this._disabled())&&i.setAttribute(`disabled`,`true`),l.appendChild(i)},d=Array.isArray(e.actions)?e.actions:null;if(d)for(let t of d){let n=document.createElement(`mint-button`);n.textContent=t.label,n.setAttribute(`variant`,`ghost`),n.setAttribute(`full-width`,`true`),n.setAttribute(`align`,`left`),n.setAttribute(`role`,`menuitem`),n.setAttribute(`data-tree-command`,`custom`),n.setAttribute(`data-tree-id`,String(e.id)),n.setAttribute(`data-tree-action`,t.id),(t.disabled===!0||e.disabled===!0||this._disabled())&&n.setAttribute(`disabled`,`true`),t.icon&&n.setAttribute(`icon`,t.icon),t.tone&&n.setAttribute(`tone`,t.tone),l.appendChild(n)}else{let i=r(this._items,e.id),a=i?.siblings||[],o=a.findIndex(t=>String(t.id)===String(e.id)),s=o>0?a[o-1]:null,c=i?.parentId?n(this._items,i.parentId):null;u(`move-up`,`Move up`,o<=0),u(`move-down`,`Move down`,o<0||o>=a.length-1),u(`nest-previous`,`Nest under previous item`,!s||!this._isValidDrop(String(e.id),String(s.id))),u(`outdent`,`Move to parent level`,!c),u(`create-child`,`Add child`,!t),u(`edit`,`Edit`),u(`delete`,`Delete`)}return c.appendChild(l),i.appendChild(c),i}_closeItemPopover(e){(e.closest(`.mint-tree-menu`)?.closest(`mint-popover`))?.close?.()}async _confirmDelete(e){let t=n(this._items,e);!t||!this._confirm?.showConfirm||await this._confirm.showConfirm({question:this.getAttribute(`delete-confirmation`)||`Delete “${t.label}”?`,tone:`danger`,confirmLabel:`Delete`,cancelLabel:`Cancel`})&&u(this,`mint-tree-delete`,{item:{...t},itemId:e,items:this.items})}_moveByCommand(e,t){let n=r(this._items,e);if(!n)return;let i=n.siblings.findIndex(t=>String(t.id)===e),a=n.parentId,o=i;if(t===`move-up`)o=i-1;else if(t===`move-down`)o=i+1;else if(t===`nest-previous`){let e=n.siblings[i-1];if(!e)return;a=String(e.id),o=(e.children||[]).length}else if(t===`outdent`){if(n.parentId===null)return;let e=r(this._items,n.parentId);if(!e)return;a=e.parentId,o=e.siblings.findIndex(e=>String(e.id)===n.parentId)+1}else return;try{let t=c(this._items,e,a,o,{maxDepth:this._maxDepth(),allowNesting:this._allowNesting()});this._applyMove(t)}catch{}}_applyMove(e){this._recordHistory(),this._items=e.items,this._collapseEmptyExpandedNodes(),e.newParentId&&this._expandedIds.add(e.newParentId),this._render(),this._focusRow(String(e.item.id));let t={itemId:String(e.item.id),item:{...e.item},items:this.items,oldParentId:e.oldParentId,newParentId:e.newParentId,oldIndex:e.oldIndex,newIndex:e.newIndex};u(this,`mint-tree-change`,{items:t.items,itemId:t.itemId}),u(this,t.oldParentId===t.newParentId?`mint-tree-reorder`:`mint-tree-reparent`,t),this._announce(`${t.item.label} moved${t.newParentId?` into ${n(this._items,t.newParentId)?.label||`a group`}`:` to the top level`}.`)}_select(e){if(this.classList.contains(`mint-tree-drag-active`))return;let t=n(this._items,e);!t||t.disabled||this._disabled()||(this._selectedId=e,this.setAttribute(`selected-id`,e),this._syncSelectionDOM(),u(this,`mint-tree-select`,{item:{...t},itemId:e,items:this.items}))}_syncSelectionDOM(){(this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]).forEach(e=>{let t=e.getAttribute(`data-tree-id`)===this._selectedId;e.setAttribute(`aria-selected`,String(t)),e.tabIndex=t?0:-1})}_setExpanded(e,t,r){let i=n(this._items,e);!i||i.disabled||this._disabled()||(t?this._expandedIds.add(e):this._expandedIds.delete(e),this._syncNodeExpanded(e),r&&u(this,t?`mint-tree-expand`:`mint-tree-collapse`,{itemId:e,item:{...i},expandedIds:this.expandedIds}))}_syncExpandedDOM(){this._root?.querySelectorAll(`[data-mint-tree-row]`).forEach(e=>this._syncNodeExpanded(e.getAttribute(`data-tree-id`)||``))}_syncNodeExpanded(e){let t=[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].find(t=>t.getAttribute(`data-tree-id`)===e),r=t?.querySelector(`:scope > mint-sortable.mint-tree-children`);if(!t||!r)return;let i=this._expandedIds.has(e);t.setAttribute(`aria-expanded`,String(i));let a=t.querySelector(`[data-tree-command="toggle"]`);a?.setAttribute(`aria-expanded`,String(i)),a?.setAttribute(`aria-label`,`${i?`Collapse`:`Expand`} ${n(this._items,e)?.label||`item`}`),a?.setAttribute(`icon`,i?`caret-up`:`caret-down`),r.hidden=!i}_setTransientExpanded(e,t){let r=[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].find(t=>t.getAttribute(`data-tree-id`)===e);if(!r)return;r.setAttribute(`aria-expanded`,String(t));let i=r.querySelector(`[data-tree-command="toggle"]`),a=n(this._items,e)?.label||`item`;i?.setAttribute(`aria-expanded`,String(t)),i?.setAttribute(`aria-label`,`${t?`Collapse`:`Expand`} ${a}`),i?.setAttribute(`icon`,t?`caret-up`:`caret-down`)}_isValidDrop(e,t){let r=n(this._items,e);if(!r)return!1;let i=t===null?null:n(this._items,t);return!(t!==null&&!i||i?.disabled||i&&(String(i.id)===e||this._isDescendant(r,i.id))||!this._allowNesting()&&i||i?.canHaveChildren===!1||i?.acceptsTypes?.length&&!i.acceptsTypes.includes(r.type||``)||(i?this._depthOf(String(i.id)):-1)+1+a(r)>this._maxDepth())}_isDescendant(e,t){return(e.children||[]).some(e=>String(e.id)===String(t)||this._isDescendant(e,t))}_depthOf(e){let t=r(this._items,e);return t?this._depthOfParent(t.parentId):-1}_depthOfParent(e){if(e===null)return 0;let t=r(this._items,e);return t?this._depthOfParent(t.parentId)+1:0}_readItemsFromDOM(e){let t=e.querySelector(`:scope > mint-stack`);return t?[...t.children].filter(e=>e instanceof HTMLElement&&e.classList.contains(`mint-tree-node`)).map(e=>{let t=e.getAttribute(`data-tree-id`)||``,r=n(this._items,t),i=e.querySelector(`:scope > mint-sortable.mint-tree-children`);return{...r||{id:t,label:t},children:i?this._readItemsFromDOM(i):[]}}):[]}_clearDropState(){this._root?.querySelectorAll(`.mint-tree-drop-invalid`).forEach(e=>e.classList.remove(`mint-tree-drop-invalid`))}_collapseEmptyExpandedNodes(){for(let e of[...this._expandedIds]){let t=n(this._items,e);!t||t.children?.length||(this._expandedIds.delete(e),this._syncNodeExpanded(e),u(this,`mint-tree-collapse`,{itemId:e,item:{...t},expandedIds:this.expandedIds,automatic:!0,empty:!0}))}}_announce(e){this._liveRegion&&(this._liveRegion.textContent=e)}_recordHistory(){this._undoStack.push(t(this._items)),this._undoStack.length>50&&this._undoStack.shift(),this._redoStack=[]}_undo(){let e=this._undoStack.pop();e&&(this._redoStack.push(t(this._items)),this._items=e,this._render(),u(this,`mint-tree-change`,{items:this.items,itemId:this._selectedId}),u(this,`mint-tree-undo`,{items:this.items}))}_redo(){let e=this._redoStack.pop();e&&(this._undoStack.push(t(this._items)),this._items=e,this._render(),u(this,`mint-tree-change`,{items:this.items,itemId:this._selectedId}),u(this,`mint-tree-redo`,{items:this.items}))}_keyboardIndent(e){let t=r(this._items,e);if(!t||t.siblings.indexOf(t.item)<=0)return;let n=t.siblings[t.siblings.indexOf(t.item)-1];try{let t=c(this._items,e,n.id,(n.children||[]).length,{maxDepth:this._maxDepth(),allowNesting:this._allowNesting()});this._recordHistory(),this._items=t.items,this._expandedIds.add(String(n.id)),this._render(),this._focusRow(e),u(this,`mint-tree-reparent`,{itemId:e,item:{...t.item},items:this.items,oldParentId:t.oldParentId,newParentId:t.newParentId,oldIndex:t.oldIndex,newIndex:t.newIndex})}catch{}}_keyboardOutdent(e){let t=r(this._items,e);if(!t||t.parentId===null)return;let n=r(this._items,t.parentId);if(!n)return;let i=n.siblings.findIndex(e=>String(e.id)===t.parentId)+1;try{let t=c(this._items,e,n.parentId,i,{maxDepth:this._maxDepth(),allowNesting:this._allowNesting()});this._recordHistory(),this._items=t.items,this._render(),this._focusRow(e),u(this,`mint-tree-reparent`,{itemId:e,item:{...t.item},items:this.items,oldParentId:t.oldParentId,newParentId:t.newParentId,oldIndex:t.oldIndex,newIndex:t.newIndex})}catch{}}_focusRow(e){[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].find(t=>t.getAttribute(`data-tree-id`)===e)?.focus({preventScroll:!0})}};customElements.get(`mint-tree`)||e.t(`mint-tree`,p),exports.MintTree=p,exports.default=p;
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}}),require(`../chunks/icon-CGXHKbMq.js`);const e=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/spinner-DfPbEa2d.js`),require(`../chunks/button-WCO2Tpah.js`),require(`../chunks/confirm-action-BMb31P5R.js`),require(`../chunks/popover-eTECdkG7.js`),require(`../chunks/sortable-BmObFEEn.js`);function t(e=[]){s(e);let t=e=>e.map(e=>({...e,children:Array.isArray(e.children)?t(e.children):[]}));return t(e)}function n(e,t){let r=String(t);for(let t of e){if(String(t.id)===r)return t;let e=n(t.children||[],r);if(e)return e}return null}function r(e,t,n=null){let i=String(t);for(let t of e){if(String(t.id)===i)return{parentId:n,siblings:e,item:t};let a=r(t.children||[],i,String(t.id));if(a)return a}return null}function i(e,t,n=0){let r=String(t);for(let t of e){if(String(t.id)===r)return n;let e=i(t.children||[],r,n+1);if(e>=0)return e}return-1}function a(e){let t=Array.isArray(e?.children)?e.children:[];return t.length?1+Math.max(...t.map(a)):1}function o(e,t){return String(e.id)===String(t)?!0:(e.children||[]).some(e=>o(e,t))}function s(e){let t=new Set,n=e=>{for(let r of e){if(r.id===null||r.id===void 0||String(r.id)===``)throw Error(`Every tree item must have a non-empty identifier.`);let e=String(r.id);if(t.has(e))throw Error(`Tree item identifiers must be unique. Duplicate identifier: ${e}.`);t.add(e),n(r.children||[])}};n(e)}function c(e,s,c,l,u={}){let d=t(e),f=r(d,s);if(!f)throw Error(`Tree item ${s} was not found.`);if(f.item.disabled||f.item.draggable===!1)throw Error(`Disabled tree items cannot be moved.`);let p=c==null||c===``?null:n(d,c);if(c!=null&&c!==``&&!p)throw Error(`Target parent ${c} was not found.`);if(p&&o(f.item,p.id))throw Error(`A tree item cannot be moved inside itself or one of its descendants.`);if(p?.disabled)throw Error(`Disabled tree items cannot contain children.`);if(u.allowNesting===!1&&p)throw Error(`Nesting is disabled for this tree.`);if(p?.canHaveChildren===!1)throw Error(`The target item cannot contain children.`);if(p?.acceptsTypes?.length&&!p.acceptsTypes.includes(f.item.type))throw Error(`The target item does not accept this item type.`);let m=p?p.children:d,h=f.siblings.findIndex(e=>String(e.id)===String(s)),[g]=f.siblings.splice(h,1),_=Math.min(Math.max(0,Number.isFinite(l)?Math.trunc(l):m.length),m.length);m.splice(_,0,g);let v=Number.isFinite(u.maxDepth)?Math.max(1,Math.trunc(u.maxDepth)):1/0;if((p?i(d,p.id)+1:0)+a(g)>v)throw Error(`Moving this branch would exceed the maximum tree depth of ${v}.`);return{items:d,item:g,oldParentId:f.parentId,newParentId:p?String(p.id):null,oldIndex:h,newIndex:_}}var l=0;function u(e,t,n){e.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:n}))}function d(e,t){let n=e.getAttribute(t);return n===``||n===`true`}function f(e){return e==null||e===``?null:String(e)}var p=class extends HTMLElement{constructor(...e){super(...e),this._items=[],this._undoStack=[],this._redoStack=[],this._selectedId=null,this._expandedIds=new Set,this._root=null,this._confirm=null,this._treeId=`mint-tree-${++l}`,this._liveRegion=null,this._dragExpansion=null,this._autoExpandedIds=new Set,this._dragHoverExpandedId=null,this._keyboardFocusRestore=null,this._suppressSelectionClick=!1,this._selectionClickSuppressionTimer=null,this._onClick=e=>{let t=e.target instanceof Element?e.target.closest(`[data-tree-command]`):null;if(!t||!this.contains(t))return;let r=t.getAttribute(`data-tree-command`),i=t.getAttribute(`data-tree-id`);if(r===`create-root`)u(this,`mint-tree-create`,{parentId:null,items:this.items});else if(r===`expand-all`)this._expandedIds=this._defaultExpandedIds(this._items),this._syncExpandedDOM(),u(this,`mint-tree-expand`,{all:!0,expandedIds:this.expandedIds});else if(r===`collapse-all`)this._expandedIds.clear(),this._syncExpandedDOM(),u(this,`mint-tree-collapse`,{all:!0,expandedIds:[]});else if(r===`undo`)this._undo();else if(r===`redo`)this._redo();else if(r===`toggle`&&i){let e=!this._expandedIds.has(i);this._setExpanded(i,e,!0)}else if(r===`select`&&i){if(this.classList.contains(`mint-tree-drag-active`)||this._suppressSelectionClick){e.preventDefault(),this._suppressSelectionClick=!1,this._selectionClickSuppressionTimer!==null&&window.clearTimeout(this._selectionClickSuppressionTimer),this._selectionClickSuppressionTimer=null;return}this._select(i)}else if(r===`create-child`&&i)this._closeItemPopover(t),u(this,`mint-tree-create`,{parentId:i,items:this.items});else if(r===`edit`&&i){this._closeItemPopover(t);let e=n(this._items,i);e&&u(this,`mint-tree-edit`,{item:{...e},itemId:i,items:this.items})}else if(r===`delete`&&i)this._closeItemPopover(t),this._confirmDelete(i);else if([`move-up`,`move-down`,`nest-previous`,`outdent`].includes(r||``)&&i)this._closeItemPopover(t),this._moveByCommand(i,r||``);else if(r===`custom`&&i){this._closeItemPopover(t);let e=n(this._items,i),r=t.getAttribute(`data-tree-action`)||``,a=e?.actions?.find(e=>e.id===r);if(e&&a){let t={item:{...e},itemId:i,action:{...a,onSelect:void 0},items:this.items};u(this,`mint-tree-action`,t),a.onSelect?.({item:{...e},itemId:i,action:a,items:this.items})}}},this._onSortableDrag=e=>{let t=e.detail;if(!t||!Number.isFinite(t.clientX)||!Number.isFinite(t.clientY))return;let r=document.elementFromPoint(t.clientX,t.clientY),i=r?.closest(`[data-mint-tree-row]`),a=t.item?.getAttribute(`data-tree-id`)||``,o=null;if(i&&i.getAttribute(`data-tree-id`)!==a){let e=i.querySelector(`:scope > .mint-tree-row`)?.getBoundingClientRect()||i.getBoundingClientRect(),r=e.height?(t.clientY-e.top)/e.height:0;if(r>.22&&r<.78){let e=i.getAttribute(`data-tree-id`)||``;n(this._items,e)&&this._isValidDrop(a,e)&&(o=e)}}if(!o&&this._dragHoverExpandedId){let e=[...this._root?.querySelectorAll(`[data-tree-id]`)??[]].find(e=>e.getAttribute(`data-tree-id`)===this._dragHoverExpandedId)?.querySelector(`:scope > mint-sortable.mint-tree-children`);r&&e?.contains(r)&&(o=this._dragHoverExpandedId)}if(this._dragHoverExpandedId&&this._dragHoverExpandedId!==o){let e=this._dragHoverExpandedId;this._dragHoverExpandedId=null,this._autoExpandedIds.delete(e),this._expandedIds.delete(e),this._syncNodeExpanded(e);let t=n(this._items,e);t&&u(this,`mint-tree-collapse`,{itemId:e,item:{...t},expandedIds:this.expandedIds,automatic:!0})}if(o){let e=n(this._items,o);e&&!this._expandedIds.has(o)&&(this._expandedIds.add(o),this._autoExpandedIds.add(o),this._dragHoverExpandedId=o,this._syncNodeExpanded(o),u(this,`mint-tree-expand`,{itemId:o,item:{...e},expandedIds:this.expandedIds,automatic:!0}))}},this._onSortableStart=()=>{this.classList.add(`mint-tree-drag-active`),this._dragHoverExpandedId=null,this._dragExpansion?.timer!==null&&this._dragExpansion?.timer!==void 0&&window.clearTimeout(this._dragExpansion.timer),this._dragExpansion=null;let e=this._root?.querySelector(`.mint-sortable-dragging[data-tree-id]`),t=e?.getAttribute(`data-tree-id`)||``,n=e?.querySelector(`:scope > mint-sortable.mint-tree-children`);if(!e||!t||!n||n.hidden||!this._expandedIds.has(t))return;let r=e.querySelector(`:scope > .mint-tree-row`),i=this._root?.querySelector(`.mint-sortable-placeholder`),a=n.getBoundingClientRect().height;n.style.height=`${a}px`,n.style.overflow=`hidden`,e.style.height=`auto`,e.style.overflow=`hidden`,this._dragExpansion={itemId:t,item:e,childList:n,timer:null},this._setTransientExpanded(t,!1),n.offsetHeight,requestAnimationFrame(()=>{this._dragExpansion?.childList===n&&(n.classList.add(`mint-tree-drag-collapse`),n.style.height=`0px`,i&&r&&(i.style.minHeight=`${r.getBoundingClientRect().height}px`))})},this._onSortableEnd=e=>{this.classList.remove(`mint-tree-drag-active`),this._suppressSelectionClick=!0,this._selectionClickSuppressionTimer!==null&&window.clearTimeout(this._selectionClickSuppressionTimer),this._selectionClickSuppressionTimer=window.setTimeout(()=>{this._suppressSelectionClick=!1,this._selectionClickSuppressionTimer=null},300);let t=e.detail,r=t&&!t.cancelled?f(t.newParentId):null;for(let e of this._autoExpandedIds){if(e===r)continue;this._expandedIds.delete(e),this._syncNodeExpanded(e);let t=n(this._items,e);t&&u(this,`mint-tree-collapse`,{itemId:e,item:{...t},expandedIds:this.expandedIds,automatic:!0})}this._autoExpandedIds.clear(),this._dragHoverExpandedId=null;let i=this._dragExpansion;if(!i)return;i.item=[...this._root?.querySelectorAll(`[data-tree-id]`)??[]].find(e=>e.getAttribute(`data-tree-id`)===i.itemId)||i.item,i.childList=i.item.querySelector(`:scope > mint-sortable.mint-tree-children`)||i.childList;let{item:a,childList:o,itemId:s}=i;o.style.height=`0px`,o.style.overflow=`hidden`,o.classList.remove(`mint-tree-drag-collapse`),this._setTransientExpanded(s,!0),o.offsetHeight;let c=o.scrollHeight;requestAnimationFrame(()=>{this._dragExpansion===i&&(o.style.height=`${c}px`)}),i.timer=window.setTimeout(()=>{o.style.height=``,o.style.overflow=``,o.style.opacity=``,this._dragExpansion=null},155)},this._onSortableDragOver=e=>{let t=e,{item:r,target:i}=t.detail||{};if(!r||!i)return;this._root?.querySelectorAll(`.mint-tree-drop-invalid`).forEach(e=>e.classList.remove(`mint-tree-drop-invalid`));let a=this._root?.querySelector(`.mint-sortable-placeholder`),o=r.getAttribute(`data-tree-id`)||``,s=f(i.getAttribute(`data-tree-parent-id`)),c=i===t.detail.source||this._isValidDrop(o,s),l=s?n(this._items,s):null;c&&i!==t.detail.source&&l?a?.setAttribute(`data-drop-label`,`Drop here to nest under ${l.label}`):c&&i===this._root?.querySelector(`:scope > mint-sortable`)?a?.setAttribute(`data-drop-label`,`Drop here to move to the top level`):a?.removeAttribute(`data-drop-label`);let u=(Number.isFinite(t.detail.clientX)&&Number.isFinite(t.detail.clientY)?document.elementFromPoint(t.detail.clientX,t.detail.clientY):null)?.closest(`[data-mint-tree-row]`);u&&u.getAttribute(`data-tree-id`)!==o&&!c&&u.classList.add(`mint-tree-drop-invalid`),c||t.preventDefault()},this._onSortableBeforeDrop=e=>{let t=e,n=t.detail;if(!n?.item||!n.target)return;let r=n.item.getAttribute(`data-tree-id`)||``,i=f(n.target.getAttribute(`data-tree-parent-id`));n.target!==n.source&&!this._isValidDrop(r,i)&&t.preventDefault()},this._onSortableChange=e=>{let t=e.detail;if(!t||t.cancelled)return;let r=t.itemId||``,i=f(t.oldParentId),a=f(t.newParentId),o=this._root?.querySelector(`:scope > mint-sortable`);if(!o)return;let s=n(this._items,r);this._recordHistory(),this._items=this._readItemsFromDOM(o),this._collapseEmptyExpandedNodes();let c=n(this._items,r);if(!c||!s)return;let l={itemId:r,item:{...c},items:this.items,oldParentId:i,newParentId:a,oldIndex:Number(t.oldIndex??-1),newIndex:Number(t.newIndex??-1)};this._clearDropState(),u(this,`mint-tree-change`,{items:l.items,itemId:r}),i===a?u(this,`mint-tree-reorder`,l):u(this,`mint-tree-reparent`,l);let d=`${c.label} moved${a?` into ${n(this._items,a)?.label||`a group`}`:` to the top level`}.`;this._dragExpansion?.itemId===r?window.setTimeout(()=>{this.isConnected&&(this._render(),this._focusRow(r),this._announce(d))},155):(this._render(),this._focusRow(r),this._announce(d))},this._onKeydown=e=>{let t=e.target instanceof Element?e.target.closest(`[data-mint-tree-row]`):null;if(!t)return;if(e.altKey&&[`ArrowUp`,`ArrowDown`].includes(e.key)){e.preventDefault();let n=t.getAttribute(`data-tree-id`)||``;if(n){this._keyboardFocusRestore&&window.clearTimeout(this._keyboardFocusRestore.timer);let e={id:n,x:window.scrollX,y:window.scrollY,timer:0};e.timer=window.setTimeout(()=>{this._keyboardFocusRestore===e&&(this._keyboardFocusRestore=null)},2e3),this._keyboardFocusRestore=e}return}let i=t.getAttribute(`data-tree-id`)||``;if(e.altKey&&e.key===`ArrowRight`){e.preventDefault(),this._keyboardIndent(i);return}if(e.altKey&&e.key===`ArrowLeft`){e.preventDefault(),this._keyboardOutdent(i);return}let a=[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].filter(e=>!e.closest(`mint-sortable[hidden]`)),o=a.indexOf(t);if(e.key===`ArrowDown`)e.preventDefault(),a[o+1]?.focus({preventScroll:!0});else if(e.key===`ArrowUp`)e.preventDefault(),a[o-1]?.focus({preventScroll:!0});else if(e.key===`ArrowRight`)e.preventDefault(),this._expandedIds.has(i)?a[o+1]?.focus({preventScroll:!0}):this._setExpanded(i,!0,!0);else if(e.key===`ArrowLeft`)if(e.preventDefault(),this._expandedIds.has(i))this._setExpanded(i,!1,!0);else{let e=r(this._items,i)?.parentId;e&&[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].find(t=>t.getAttribute(`data-tree-id`)===e)?.focus({preventScroll:!0})}else if(e.key===`Enter`||e.key===` `||e.key===`Spacebar`){let r=e.target instanceof Element?e.target.closest(`[data-tree-command="select"]`):null;(t===e.target||r)&&(e.preventDefault(),n(this._items,i)?.children?.length?this._setExpanded(i,!this._expandedIds.has(i),!0):this._select(i))}}}static get observedAttributes(){return[`selected-id`,`max-depth`,`allow-nesting`,`disabled`,`loading`,`create-label`,`empty-label`,`delete-confirmation`,`expanded-ids`]}connectedCallback(){this._root||(this._selectedId=f(this.getAttribute(`selected-id`)),this._expandedIds=this.hasAttribute(`expanded-ids`)?this._readExpandedIds(this.getAttribute(`expanded-ids`)):this._defaultExpandedIds(this._items),this.addEventListener(`click`,this._onClick),this.addEventListener(`keydown`,this._onKeydown,!0),this.addEventListener(`mint-sortable-start`,this._onSortableStart),this.addEventListener(`mint-sortable-end`,this._onSortableEnd),this.addEventListener(`mint-sortable-drag`,this._onSortableDrag),this.addEventListener(`mint-sortable-drag-over`,this._onSortableDragOver),this.addEventListener(`mint-sortable-before-drop`,this._onSortableBeforeDrop),this.addEventListener(`mint-sortable-change`,this._onSortableChange),this._render())}disconnectedCallback(){this._dragExpansion?.timer!==null&&this._dragExpansion?.timer!==void 0&&window.clearTimeout(this._dragExpansion.timer),this._keyboardFocusRestore&&window.clearTimeout(this._keyboardFocusRestore.timer),this._selectionClickSuppressionTimer!==null&&window.clearTimeout(this._selectionClickSuppressionTimer),this._selectionClickSuppressionTimer=null,this._suppressSelectionClick=!1,this._keyboardFocusRestore=null,this._dragExpansion=null,this._autoExpandedIds.clear(),this._dragHoverExpandedId=null,this.classList.remove(`mint-tree-drag-active`),this.removeEventListener(`click`,this._onClick),this.removeEventListener(`keydown`,this._onKeydown,!0),this.removeEventListener(`mint-sortable-start`,this._onSortableStart),this.removeEventListener(`mint-sortable-end`,this._onSortableEnd),this.removeEventListener(`mint-sortable-drag`,this._onSortableDrag),this.removeEventListener(`mint-sortable-drag-over`,this._onSortableDragOver),this.removeEventListener(`mint-sortable-before-drop`,this._onSortableBeforeDrop),this.removeEventListener(`mint-sortable-change`,this._onSortableChange),this._root=null}attributeChangedCallback(e,t,n){if(!(t===n||!this.isConnected)){if(e===`selected-id`){this._selectedId=f(n),this._syncSelectionDOM();return}e===`expanded-ids`&&(this._expandedIds=this._readExpandedIds(n)),this._render()}}get items(){return t(this._items)}set items(e){this._items=t(Array.isArray(e)?e:[]),this._undoStack=[],this._redoStack=[],this.hasAttribute(`expanded-ids`)||(this._expandedIds=this._defaultExpandedIds(this._items)),this.isConnected&&this._render()}get selectedId(){return this._selectedId}set selectedId(e){this._selectedId=f(e),this._selectedId===null?this.removeAttribute(`selected-id`):this.setAttribute(`selected-id`,this._selectedId)}get expandedIds(){return[...this._expandedIds]}set expandedIds(e){this._expandedIds=new Set((Array.isArray(e)?e:[]).map(String)),this.isConnected&&this._render()}save(){u(this,`mint-tree-save`,{items:this.items})}select(e){this._select(String(e))}expand(e){this._setExpanded(String(e),!0,!0)}collapse(e){this._setExpanded(String(e),!1,!0)}_readExpandedIds(e){if(!e)return this._defaultExpandedIds(this._items);try{let t=JSON.parse(e);return new Set(Array.isArray(t)?t.map(String):[])}catch{return new Set(e.split(`,`).map(e=>e.trim()).filter(Boolean))}}_defaultExpandedIds(e){let t=new Set,n=e=>e.forEach(e=>{e.children?.length&&(t.add(String(e.id)),n(e.children))});return n(e),t}_maxDepth(){let e=Number.parseInt(this.getAttribute(`max-depth`)||``,10);return Number.isFinite(e)&&e>0?e:1/0}_allowNesting(){return!this.hasAttribute(`allow-nesting`)||d(this,`allow-nesting`)}_disabled(){return d(this,`disabled`)}_isLoading(){return d(this,`loading`)}_render(){let e=document.activeElement instanceof HTMLElement?document.activeElement.closest(`[data-mint-tree-row]`):null,t=e&&this.contains(e)?e.getAttribute(`data-tree-id`):null;t&&this._keyboardFocusRestore&&(this._keyboardFocusRestore.id=t);let n=document.createElement(`div`);n.className=`mint-tree-shell`,n.setAttribute(`role`,`tree`),n.setAttribute(`aria-label`,this.getAttribute(`aria-label`)||`Hierarchical items`),n.setAttribute(`aria-busy`,String(this._isLoading()));let r=document.createElement(`div`);r.className=`mint-tree-toolbar`;let i=document.createElement(`span`);i.className=`mint-tree-count`,i.textContent=`${this._countItems()} ${this._countItems()===1?`item`:`items`}`,r.appendChild(i);let a=document.createElement(`div`);a.className=`mint-tree-toolbar-actions`;let o=this._createButton(``,`ghost`,`undo`);o.setAttribute(`icon`,`undo`),o.setAttribute(`aria-label`,`Undo last change`),o.setAttribute(`title`,`Undo`),(!this._undoStack.length||this._disabled())&&o.setAttribute(`disabled`,`true`);let s=this._createButton(``,`ghost`,`redo`);s.setAttribute(`icon`,`redo`),s.setAttribute(`aria-label`,`Redo last undone change`),s.setAttribute(`title`,`Redo`),(!this._redoStack.length||this._disabled())&&s.setAttribute(`disabled`,`true`);let c=this._createButton(``,`ghost`,`expand-all`);c.setAttribute(`icon`,`expand`),c.setAttribute(`aria-label`,`Expand all`),c.setAttribute(`title`,`Expand all`);let l=this._createButton(``,`ghost`,`collapse-all`);if(l.setAttribute(`icon`,`collapse`),l.setAttribute(`aria-label`,`Collapse all`),l.setAttribute(`title`,`Collapse all`),a.append(o,s,c,l),r.appendChild(a),n.appendChild(r),this._isLoading()){let e=document.createElement(`div`);e.className=`mint-tree-loading`,e.setAttribute(`aria-label`,`Loading items`);let t=document.createElement(`mint-spinner`);t.setAttribute(`size`,`small`),e.appendChild(t),n.appendChild(e)}else if(this._items.length)n.appendChild(this._createList(this._items,null,0));else{let e=document.createElement(`div`);e.className=`mint-tree-empty`,e.textContent=this.getAttribute(`empty-label`)||`No items yet.`,n.appendChild(e)}this._liveRegion=document.createElement(`div`),this._liveRegion.className=`mint-tree-live-region`,this._liveRegion.setAttribute(`role`,`status`),this._liveRegion.setAttribute(`aria-live`,`polite`),this._liveRegion.setAttribute(`aria-atomic`,`true`),n.appendChild(this._liveRegion);let u=document.createElement(`mint-confirm-action`);u.className=`mint-tree-confirm`,this._confirm=u,n.appendChild(u),this.replaceChildren(n),this._root=n,this.classList.add(`mint-tree`),this._disabled()?this.setAttribute(`aria-disabled`,`true`):this.removeAttribute(`aria-disabled`);let d=this._keyboardFocusRestore;d&&(this._focusRow(d.id),window.scrollTo({left:d.x,top:d.y,behavior:`instant`}),requestAnimationFrame(()=>{this._keyboardFocusRestore===d&&(this._focusRow(d.id),window.scrollTo({left:d.x,top:d.y,behavior:`instant`}))}))}_countItems(e=this._items){return e.reduce((e,t)=>e+1+this._countItems(t.children||[]),0)}_createButton(e,t,n){let r=document.createElement(`mint-button`);return r.textContent=e,r.setAttribute(`variant`,t),r.setAttribute(`data-tree-command`,n),r}_createList(e,t,n){let r=document.createElement(`mint-sortable`);r.id=`${this._treeId}-list-${t??`root`}`,r.setAttribute(`group`,this._treeId),r.setAttribute(`data-tree-parent-id`,t??``),r.setAttribute(`role`,`group`),r.setAttribute(`data-tree-depth`,String(n)),r.setAttribute(`direction`,`vertical`),r.setAttribute(`gap`,`1`),r.setAttribute(`handle-selector`,`[data-mint-sortable-handle]`),r.setAttribute(`animation-duration`,`320`),r.setAttribute(`item-key-attribute`,`data-tree-id`);let i=document.createElement(`mint-stack`);i.setAttribute(`direction`,`vertical`),i.setAttribute(`gap`,`1`);for(let t of e)i.appendChild(this._createNode(t,n));return r.appendChild(i),r}_createNode(e,t){let n=String(e.id),r=Array.isArray(e.children)?e.children:[],i=e.canHaveChildren!==!1&&this._allowNesting()&&t+a(e)<this._maxDepth(),o=document.createElement(`div`);o.className=`mint-tree-node`,o.setAttribute(`data-tree-id`,n),o.setAttribute(`role`,`treeitem`),o.setAttribute(`data-mint-tree-row`,``),o.setAttribute(`aria-level`,String(t+1)),o.setAttribute(`aria-selected`,String(this._selectedId===n)),o.setAttribute(`tabindex`,this._selectedId===n||this._selectedId===null&&t===0&&this._items[0]?.id===e.id?`0`:`-1`),o.setAttribute(`aria-label`,e.label),r.length&&o.setAttribute(`aria-expanded`,String(this._expandedIds.has(n))),(e.disabled||this._disabled())&&o.setAttribute(`aria-disabled`,`true`),(e.draggable===!1||this._disabled())&&o.setAttribute(`data-sortable-disabled`,``);let s=document.createElement(`div`);s.className=`mint-tree-row`,s.setAttribute(`data-tree-id`,n);let c=document.createElement(`span`);c.className=`mint-tree-drag-handle`,c.setAttribute(`data-mint-sortable-handle`,``),c.setAttribute(`role`,`button`),c.setAttribute(`tabindex`,`-1`),c.setAttribute(`aria-label`,`Drag ${e.label} to move`);let l=document.createElement(`mint-icon`);if(l.setAttribute(`name`,`grip-dots`),l.setAttribute(`aria-hidden`,`true`),c.appendChild(l),s.appendChild(c),r.length){let t=document.createElement(`mint-button`);t.className=`mint-tree-expand`,t.setAttribute(`variant`,`ghost`),t.setAttribute(`icon`,this._expandedIds.has(n)?`caret-up`:`caret-down`),t.setAttribute(`data-tree-command`,`toggle`),t.setAttribute(`data-tree-id`,n),t.setAttribute(`aria-label`,`${this._expandedIds.has(n)?`Collapse`:`Expand`} ${e.label}`),t.setAttribute(`aria-expanded`,String(this._expandedIds.has(n))),(this._disabled()||e.disabled===!0)&&t.setAttribute(`disabled`,`true`),s.appendChild(t)}else{let e=document.createElement(`span`);e.className=`mint-tree-expand-spacer`,e.setAttribute(`aria-hidden`,`true`),s.appendChild(e)}let u=document.createElement(`span`);if(u.className=`mint-tree-label`,u.setAttribute(`data-tree-command`,`select`),u.setAttribute(`data-tree-id`,n),i&&(u.setAttribute(`data-mint-sortable-drop-container`,`${this._treeId}-list-${n}`),u.setAttribute(`data-mint-sortable-drop-end`,``)),e.icon){let t=document.createElement(`mint-icon`);t.setAttribute(`name`,String(e.icon)),t.setAttribute(`aria-hidden`,`true`),u.appendChild(t)}let d=document.createElement(`span`);if(d.className=`mint-tree-label-text`,d.textContent=e.label,u.appendChild(d),s.appendChild(u),e.metadata){let t=document.createElement(`span`);t.className=`mint-tree-metadata`,t.textContent=String(e.metadata),s.appendChild(t)}let f=document.createElement(`span`);f.className=`mint-tree-nest-target`,f.setAttribute(`data-mint-sortable-drop-container`,`${this._treeId}-list-${n}`),f.setAttribute(`data-mint-sortable-drop-end`,``),f.setAttribute(`aria-hidden`,`true`);let p=document.createElement(`mint-icon`);p.setAttribute(`name`,`arrow-right`),p.setAttribute(`aria-hidden`,`true`),f.appendChild(p),i&&s.appendChild(f);let m=this._createActions(e,i);s.appendChild(m),o.appendChild(s);let h=this._createList(r,n,t+1);return h.classList.add(`mint-tree-children`),h.hidden=!this._expandedIds.has(n),o.appendChild(h),o}_createActions(e,t){let i=document.createElement(`div`);i.className=`mint-tree-actions`;let a=`${this._treeId}-actions-trigger-${encodeURIComponent(String(e.id))}`,o=`${a}-popover`,s=document.createElement(`mint-button`);s.id=a,s.setAttribute(`variant`,`ghost`),s.setAttribute(`icon`,`ellipsis`),s.setAttribute(`aria-label`,`Actions for ${e.label}`),s.setAttribute(`aria-haspopup`,`menu`),i.appendChild(s);let c=document.createElement(`mint-popover`);c.id=o,c.setAttribute(`trigger-id`,a),c.setAttribute(`direction`,`down`),c.setAttribute(`trigger-align`,`end`),c.setAttribute(`padding`,`0.3rem`);let l=document.createElement(`div`);l.className=`mint-tree-menu`,l.setAttribute(`role`,`menu`);let u=(t,n,r=!1)=>{let i=document.createElement(`mint-button`);i.textContent=n,i.setAttribute(`variant`,`ghost`),i.setAttribute(`full-width`,`true`),i.setAttribute(`align`,`left`),i.setAttribute(`role`,`menuitem`),i.setAttribute(`data-tree-command`,t),i.setAttribute(`data-tree-id`,String(e.id)),(r||e.disabled===!0||this._disabled())&&i.setAttribute(`disabled`,`true`),l.appendChild(i)},d=Array.isArray(e.actions)?e.actions:null;if(d)for(let t of d){let n=document.createElement(`mint-button`);n.textContent=t.label,n.setAttribute(`variant`,`ghost`),n.setAttribute(`full-width`,`true`),n.setAttribute(`align`,`left`),n.setAttribute(`role`,`menuitem`),n.setAttribute(`data-tree-command`,`custom`),n.setAttribute(`data-tree-id`,String(e.id)),n.setAttribute(`data-tree-action`,t.id),(t.disabled===!0||e.disabled===!0||this._disabled())&&n.setAttribute(`disabled`,`true`),t.icon&&n.setAttribute(`icon`,t.icon),t.tone&&n.setAttribute(`tone`,t.tone),l.appendChild(n)}else{let i=r(this._items,e.id),a=i?.siblings||[],o=a.findIndex(t=>String(t.id)===String(e.id)),s=o>0?a[o-1]:null,c=i?.parentId?n(this._items,i.parentId):null;u(`move-up`,`Move up`,o<=0),u(`move-down`,`Move down`,o<0||o>=a.length-1),u(`nest-previous`,`Nest under previous item`,!s||!this._isValidDrop(String(e.id),String(s.id))),u(`outdent`,`Move to parent level`,!c),u(`create-child`,`Add child`,!t),u(`edit`,`Edit`),u(`delete`,`Delete`)}return c.appendChild(l),i.appendChild(c),i}_closeItemPopover(e){(e.closest(`.mint-tree-menu`)?.closest(`mint-popover`))?.close?.()}async _confirmDelete(e){let t=n(this._items,e);!t||!this._confirm?.showConfirm||await this._confirm.showConfirm({question:this.getAttribute(`delete-confirmation`)||`Delete “${t.label}”?`,tone:`danger`,confirmLabel:`Delete`,cancelLabel:`Cancel`})&&u(this,`mint-tree-delete`,{item:{...t},itemId:e,items:this.items})}_moveByCommand(e,t){let n=r(this._items,e);if(!n)return;let i=n.siblings.findIndex(t=>String(t.id)===e),a=n.parentId,o=i;if(t===`move-up`)o=i-1;else if(t===`move-down`)o=i+1;else if(t===`nest-previous`){let e=n.siblings[i-1];if(!e)return;a=String(e.id),o=(e.children||[]).length}else if(t===`outdent`){if(n.parentId===null)return;let e=r(this._items,n.parentId);if(!e)return;a=e.parentId,o=e.siblings.findIndex(e=>String(e.id)===n.parentId)+1}else return;try{let t=c(this._items,e,a,o,{maxDepth:this._maxDepth(),allowNesting:this._allowNesting()});this._applyMove(t)}catch{}}_applyMove(e){this._recordHistory(),this._items=e.items,this._collapseEmptyExpandedNodes(),e.newParentId&&this._expandedIds.add(e.newParentId),this._render(),this._focusRow(String(e.item.id));let t={itemId:String(e.item.id),item:{...e.item},items:this.items,oldParentId:e.oldParentId,newParentId:e.newParentId,oldIndex:e.oldIndex,newIndex:e.newIndex};u(this,`mint-tree-change`,{items:t.items,itemId:t.itemId}),u(this,t.oldParentId===t.newParentId?`mint-tree-reorder`:`mint-tree-reparent`,t),this._announce(`${t.item.label} moved${t.newParentId?` into ${n(this._items,t.newParentId)?.label||`a group`}`:` to the top level`}.`)}_select(e){if(this.classList.contains(`mint-tree-drag-active`))return;let t=n(this._items,e);!t||t.disabled||this._disabled()||(this._selectedId=e,this.setAttribute(`selected-id`,e),this._syncSelectionDOM(),u(this,`mint-tree-select`,{item:{...t},itemId:e,items:this.items}))}_syncSelectionDOM(){(this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]).forEach(e=>{let t=e.getAttribute(`data-tree-id`)===this._selectedId;e.setAttribute(`aria-selected`,String(t)),e.tabIndex=t?0:-1})}_setExpanded(e,t,r){let i=n(this._items,e);!i||i.disabled||this._disabled()||(t?this._expandedIds.add(e):this._expandedIds.delete(e),this._syncNodeExpanded(e),r&&u(this,t?`mint-tree-expand`:`mint-tree-collapse`,{itemId:e,item:{...i},expandedIds:this.expandedIds}))}_syncExpandedDOM(){this._root?.querySelectorAll(`[data-mint-tree-row]`).forEach(e=>this._syncNodeExpanded(e.getAttribute(`data-tree-id`)||``))}_syncNodeExpanded(e){let t=[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].find(t=>t.getAttribute(`data-tree-id`)===e),r=t?.querySelector(`:scope > mint-sortable.mint-tree-children`);if(!t||!r)return;let i=this._expandedIds.has(e);t.setAttribute(`aria-expanded`,String(i));let a=t.querySelector(`[data-tree-command="toggle"]`);a?.setAttribute(`aria-expanded`,String(i)),a?.setAttribute(`aria-label`,`${i?`Collapse`:`Expand`} ${n(this._items,e)?.label||`item`}`),a?.setAttribute(`icon`,i?`caret-up`:`caret-down`),r.hidden=!i}_setTransientExpanded(e,t){let r=[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].find(t=>t.getAttribute(`data-tree-id`)===e);if(!r)return;r.setAttribute(`aria-expanded`,String(t));let i=r.querySelector(`[data-tree-command="toggle"]`),a=n(this._items,e)?.label||`item`;i?.setAttribute(`aria-expanded`,String(t)),i?.setAttribute(`aria-label`,`${t?`Collapse`:`Expand`} ${a}`),i?.setAttribute(`icon`,t?`caret-up`:`caret-down`)}_isValidDrop(e,t){let r=n(this._items,e);if(!r)return!1;let i=t===null?null:n(this._items,t);return!(t!==null&&!i||i?.disabled||i&&(String(i.id)===e||this._isDescendant(r,i.id))||!this._allowNesting()&&i||i?.canHaveChildren===!1||i?.acceptsTypes?.length&&!i.acceptsTypes.includes(r.type||``)||(i?this._depthOf(String(i.id)):-1)+1+a(r)>this._maxDepth())}_isDescendant(e,t){return(e.children||[]).some(e=>String(e.id)===String(t)||this._isDescendant(e,t))}_depthOf(e){let t=r(this._items,e);return t?this._depthOfParent(t.parentId):-1}_depthOfParent(e){if(e===null)return 0;let t=r(this._items,e);return t?this._depthOfParent(t.parentId)+1:0}_readItemsFromDOM(e){let t=e.querySelector(`:scope > mint-stack`);return t?[...t.children].filter(e=>e instanceof HTMLElement&&e.classList.contains(`mint-tree-node`)).map(e=>{let t=e.getAttribute(`data-tree-id`)||``,r=n(this._items,t),i=e.querySelector(`:scope > mint-sortable.mint-tree-children`);return{...r||{id:t,label:t},children:i?this._readItemsFromDOM(i):[]}}):[]}_clearDropState(){this._root?.querySelectorAll(`.mint-tree-drop-invalid`).forEach(e=>e.classList.remove(`mint-tree-drop-invalid`))}_collapseEmptyExpandedNodes(){for(let e of[...this._expandedIds]){let t=n(this._items,e);!t||t.children?.length||(this._expandedIds.delete(e),this._syncNodeExpanded(e),u(this,`mint-tree-collapse`,{itemId:e,item:{...t},expandedIds:this.expandedIds,automatic:!0,empty:!0}))}}_announce(e){this._liveRegion&&(this._liveRegion.textContent=e)}_recordHistory(){this._undoStack.push(t(this._items)),this._undoStack.length>50&&this._undoStack.shift(),this._redoStack=[]}_undo(){let e=this._undoStack.pop();if(!e)return;let n=this._items;this._redoStack.push(t(this._items)),this._items=e,this._render(),this._emitHistoryChange(n),u(this,`mint-tree-undo`,{items:this.items})}_redo(){let e=this._redoStack.pop();if(!e)return;let n=this._items;this._undoStack.push(t(this._items)),this._items=e,this._render(),this._emitHistoryChange(n),u(this,`mint-tree-redo`,{items:this.items})}_emitHistoryChange(e){let t=this.items,n=e=>{let t=new Map,n=(e,r)=>e.forEach((e,i)=>{let a=String(e.id);t.set(a,{parentId:r,index:i,item:e}),n(e.children||[],a)});return n(e,null),t},r=n(e),i=n(this._items),a=[...new Set([...r.keys(),...i.keys()])].find(e=>{let t=r.get(e),n=i.get(e);return t&&n&&(t.parentId!==n.parentId||t.index!==n.index)});if(u(this,`mint-tree-change`,{items:t,itemId:this._selectedId}),!a)return;let o=r.get(a),s=i.get(a),c={itemId:a,item:{...s.item},items:t,oldParentId:o.parentId,newParentId:s.parentId,oldIndex:o.index,newIndex:s.index};u(this,o.parentId===s.parentId?`mint-tree-reorder`:`mint-tree-reparent`,c)}_keyboardIndent(e){let t=r(this._items,e);if(!t||t.siblings.indexOf(t.item)<=0)return;let n=t.siblings[t.siblings.indexOf(t.item)-1];try{let t=c(this._items,e,n.id,(n.children||[]).length,{maxDepth:this._maxDepth(),allowNesting:this._allowNesting()});this._recordHistory(),this._items=t.items,this._expandedIds.add(String(n.id)),this._render(),this._focusRow(e),u(this,`mint-tree-reparent`,{itemId:e,item:{...t.item},items:this.items,oldParentId:t.oldParentId,newParentId:t.newParentId,oldIndex:t.oldIndex,newIndex:t.newIndex})}catch{}}_keyboardOutdent(e){let t=r(this._items,e);if(!t||t.parentId===null)return;let n=r(this._items,t.parentId);if(!n)return;let i=n.siblings.findIndex(e=>String(e.id)===t.parentId)+1;try{let t=c(this._items,e,n.parentId,i,{maxDepth:this._maxDepth(),allowNesting:this._allowNesting()});this._recordHistory(),this._items=t.items,this._render(),this._focusRow(e),u(this,`mint-tree-reparent`,{itemId:e,item:{...t.item},items:this.items,oldParentId:t.oldParentId,newParentId:t.newParentId,oldIndex:t.oldIndex,newIndex:t.newIndex})}catch{}}_focusRow(e){[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].find(t=>t.getAttribute(`data-tree-id`)===e)?.focus({preventScroll:!0})}};customElements.get(`mint-tree`)||e.t(`mint-tree`,p),exports.MintTree=p,exports.default=p;
|
|
@@ -696,17 +696,45 @@ var p = class extends HTMLElement {
|
|
|
696
696
|
}
|
|
697
697
|
_undo() {
|
|
698
698
|
let e = this._undoStack.pop();
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
}), u(this, "mint-tree-undo", { items: this.items }));
|
|
699
|
+
if (!e) return;
|
|
700
|
+
let n = this._items;
|
|
701
|
+
this._redoStack.push(t(this._items)), this._items = e, this._render(), this._emitHistoryChange(n), u(this, "mint-tree-undo", { items: this.items });
|
|
703
702
|
}
|
|
704
703
|
_redo() {
|
|
705
704
|
let e = this._redoStack.pop();
|
|
706
|
-
|
|
707
|
-
|
|
705
|
+
if (!e) return;
|
|
706
|
+
let n = this._items;
|
|
707
|
+
this._undoStack.push(t(this._items)), this._items = e, this._render(), this._emitHistoryChange(n), u(this, "mint-tree-redo", { items: this.items });
|
|
708
|
+
}
|
|
709
|
+
_emitHistoryChange(e) {
|
|
710
|
+
let t = this.items, n = (e) => {
|
|
711
|
+
let t = /* @__PURE__ */ new Map(), n = (e, r) => e.forEach((e, i) => {
|
|
712
|
+
let a = String(e.id);
|
|
713
|
+
t.set(a, {
|
|
714
|
+
parentId: r,
|
|
715
|
+
index: i,
|
|
716
|
+
item: e
|
|
717
|
+
}), n(e.children || [], a);
|
|
718
|
+
});
|
|
719
|
+
return n(e, null), t;
|
|
720
|
+
}, r = n(e), i = n(this._items), a = [...new Set([...r.keys(), ...i.keys()])].find((e) => {
|
|
721
|
+
let t = r.get(e), n = i.get(e);
|
|
722
|
+
return t && n && (t.parentId !== n.parentId || t.index !== n.index);
|
|
723
|
+
});
|
|
724
|
+
if (u(this, "mint-tree-change", {
|
|
725
|
+
items: t,
|
|
708
726
|
itemId: this._selectedId
|
|
709
|
-
}),
|
|
727
|
+
}), !a) return;
|
|
728
|
+
let o = r.get(a), s = i.get(a), c = {
|
|
729
|
+
itemId: a,
|
|
730
|
+
item: { ...s.item },
|
|
731
|
+
items: t,
|
|
732
|
+
oldParentId: o.parentId,
|
|
733
|
+
newParentId: s.parentId,
|
|
734
|
+
oldIndex: o.index,
|
|
735
|
+
newIndex: s.index
|
|
736
|
+
};
|
|
737
|
+
u(this, o.parentId === s.parentId ? "mint-tree-reorder" : "mint-tree-reparent", c);
|
|
710
738
|
}
|
|
711
739
|
_keyboardIndent(e) {
|
|
712
740
|
let t = r(this._items, e);
|