monobill-mintui 0.6.638 → 0.6.640
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/chunks/{confirm-action-CholVruh.js → confirm-action-D4U-R6zW.js} +1 -1
- package/dist/components/chunks/{confirm-action-B7vFRCIg.js → confirm-action-DxvkO8OY.js} +1 -1
- package/dist/components/chunks/{modal-C-x5AluM.js → modal-DVbvAPLU.js} +1 -1
- package/dist/components/chunks/{modal-DvjdEuxj.js → modal-DaAORJq2.js} +1 -1
- package/dist/components/chunks/{sortable-BWbidfTB.js → sortable-CparUKN_.js} +5 -7
- package/dist/components/chunks/{sortable-DCa1G1-x.js → sortable-DX2PwFLN.js} +1 -1
- package/dist/components/confirm-action/browser.js +1 -1
- package/dist/components/confirm-action/index.cjs +1 -1
- package/dist/components/confirm-action/index.js +1 -1
- package/dist/components/icon/index.d.ts +1 -0
- package/dist/components/icon/index.d.ts.map +1 -1
- package/dist/components/modal/browser.js +1 -1
- package/dist/components/modal/index.cjs +1 -1
- package/dist/components/modal/index.js +1 -1
- package/dist/components/sortable/Sortable.d.ts.map +1 -1
- package/dist/components/sortable/browser.js +1 -1
- package/dist/components/sortable/index.cjs +1 -1
- package/dist/components/sortable/index.js +1 -1
- package/dist/components/tree/Tree.d.ts.map +1 -1
- package/dist/components/tree/browser.js +9 -8
- package/dist/components/tree/index.cjs +1 -1
- package/dist/components/tree/index.js +9 -8
- package/dist/index.cjs +3 -3
- package/dist/index.css +1 -1
- package/dist/index.js +13 -14
- package/dist/tree.css +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as e } from "./register-element-BFYmIynH.js";
|
|
2
2
|
import "./text-Bmfl6CxJ.js";
|
|
3
3
|
import "./button-M7gi8RMZ.js";
|
|
4
|
-
import "./modal-
|
|
4
|
+
import "./modal-DVbvAPLU.js";
|
|
5
5
|
//#region src/components/confirm-action/ConfirmAction.ts
|
|
6
6
|
var t = class extends HTMLElement {
|
|
7
7
|
constructor(...e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./register-element-tCL_F1YI.js`);require(`./text-Cpl5ljSe.js`),require(`./button-DGuqIeFS.js`),require(`./modal-
|
|
1
|
+
const e=require(`./register-element-tCL_F1YI.js`);require(`./text-Cpl5ljSe.js`),require(`./button-DGuqIeFS.js`),require(`./modal-DaAORJq2.js`);var t=class extends HTMLElement{constructor(...e){super(...e),this._modal=null,this._actionsFooter=null,this._confirmButton=null,this._cancelButton=null,this._pendingResolve=null,this._modalObserver=null,this._lastAction=null,this._onConfirmClick=null,this._onCancelClick=null}connectedCallback(){this._ensureModal(),this._observeModalOpenState()}disconnectedCallback(){this._modalObserver&&=(this._modalObserver.disconnect(),null),this._pendingResolve=null}async showConfirm(e){if(this._ensureModal(),!this._modal||!this._confirmButton||!this._cancelButton)return!1;let t=e.question?.trim()||`Are you sure?`,n=e.tone||`action`,r=e.confirmLabel?.trim()||`Confirm`,i=e.cancelLabel?.trim()||`Cancel`;this._lastAction=null,this._modal.setAttribute(`heading`,t),this._cancelButton.className=`mint-button-core mint-button-ghost mint-button-tone-neutral mint-confirm-action-cancel`,this._confirmButton.className=`mint-button-core mint-button-solid mint-button-tone-${n} mint-confirm-action-confirm`,this._confirmButton.textContent=r,this._cancelButton.textContent=i;let a=new Promise(e=>{this._pendingResolve=e});return requestAnimationFrame(()=>{this._modal.open?.(),this._mountActionsFooter()}),a}_ensureModal(){this._modal||(this._modal=document.createElement(`mint-modal`),this._modal.setAttribute(`heading`,`Are you sure?`),this._modal.setAttribute(`size`,`small`),this._modal.setAttribute(`hide-close-button`,``),this._cancelButton=document.createElement(`button`),this._cancelButton.type=`button`,this._cancelButton.className=`mint-button-core mint-button-ghost mint-button-tone-neutral mint-confirm-action-cancel`,this._cancelButton.textContent=`Cancel`,this._confirmButton=document.createElement(`button`),this._confirmButton.type=`button`,this._confirmButton.className=`mint-button-core mint-button-solid mint-button-tone-action mint-confirm-action-confirm`,this._confirmButton.textContent=`Confirm`,this._actionsFooter=document.createElement(`div`),this._actionsFooter.className=`mint-confirm-action-footer`,this._actionsFooter.append(this._cancelButton,this._confirmButton),this._onCancelClick=()=>{this._lastAction=`cancel`,this._modal?.close?.()},this._onConfirmClick=()=>{this._lastAction=`confirm`,this._modal?.close?.()},this._cancelButton.addEventListener(`click`,this._onCancelClick),this._confirmButton.addEventListener(`click`,this._onConfirmClick),this.appendChild(this._modal))}_mountActionsFooter(){let e=this._modal?.querySelector(`.modal-content`);!e||!this._actionsFooter||(e.querySelectorAll(`:scope > [slot="body"], :scope > [slot="actions"]`).forEach(e=>{!e.textContent?.trim()&&!e.querySelector(`button, mint-button, a, input, select, textarea`)&&e.remove()}),this._actionsFooter.parentElement!==e&&e.appendChild(this._actionsFooter))}_observeModalOpenState(){!this._modal||this._modalObserver||(this._modalObserver=new MutationObserver(()=>{if((this._modal?.hasAttribute(`open`)??!1)||!this._pendingResolve)return;let e=this._pendingResolve;this._pendingResolve=null;let t=this._lastAction===`confirm`;this._lastAction=null,e(t)}),this._modalObserver.observe(this._modal,{attributes:!0,attributeFilter:[`open`]}))}};customElements.get(`mint-confirm-action`)||e.t(`mint-confirm-action`,t);var n=[],r=!1;function i(){return typeof document>`u`||document.body?Promise.resolve():new Promise(e=>{if(typeof window>`u`){e();return}window.addEventListener(`DOMContentLoaded`,()=>e(),{once:!0})})}async function a(){if(await i(),typeof document>`u`)throw Error(`mintui.confirm is only available in browser environments.`);let e=document.querySelector(`mint-confirm-action[data-mint-confirm-action-root="true"]`);if(e)return e;let t=document.createElement(`mint-confirm-action`);return t.setAttribute(`data-mint-confirm-action-root`,`true`),document.body.appendChild(t),t}function o(e){let t=(e||`action`).toString().trim().toLowerCase().replace(/^tone:\s*/,``);return t===`action`||t===`info`||t===`warning`||t===`danger`?t:`action`}async function s(){if(!r){r=!0;try{for(;n.length>0;){let e=n.shift();e&&(await(await a()).showConfirm({question:e.question,tone:o(e.tone),confirmLabel:e.confirmLabel||`Confirm`,cancelLabel:e.cancelLabel||`Cancel`})?e.confirmed?.():e.cancelled?.())}}finally{r=!1}}}function c(e,t,r,i=`action`,a=`Confirm`,o=`Cancel`){typeof window>`u`||(n.push({question:e,confirmed:t,cancelled:r,tone:i,confirmLabel:a,cancelLabel:o}),s())}if(typeof window<`u`){let e=window.mintui||{};e.confirm=c,window.mintui=e}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return c}});
|
|
@@ -86,7 +86,7 @@ var a = class extends HTMLElement {
|
|
|
86
86
|
e.parentElement !== this._bodySlot && this._bodySlot.appendChild(e);
|
|
87
87
|
}), this._actionsSlot || (this._actionsSlot = document.createElement("div"), this._actionsSlot.className = "mint-modal-actions", this._actionsSlot.setAttribute("slot", "actions"), i.appendChild(this._actionsSlot));
|
|
88
88
|
let o = this._actionsSlot.querySelector("mint-stack");
|
|
89
|
-
o || (o = document.createElement("mint-stack"), o.setAttribute("direction", "horizontal"), o.className = "mint-actions-stack", this._actionsSlot.appendChild(o)), Array.from(this.children).filter((e) => e !== this._overlay && e !== this._modal && e !== this._actionsSlot && e.getAttribute("slot") === "actions").forEach((e) => {
|
|
89
|
+
o || (o = document.createElement("mint-stack"), o.setAttribute("direction", "horizontal"), o.setAttribute("align-content", "right"), o.className = "mint-actions-stack", this._actionsSlot.appendChild(o)), Array.from(this.children).filter((e) => e !== this._overlay && e !== this._modal && e !== this._actionsSlot && e.getAttribute("slot") === "actions").forEach((e) => {
|
|
90
90
|
Array.from(e.children).forEach((e) => {
|
|
91
91
|
e.parentElement !== o && o.appendChild(e);
|
|
92
92
|
}), e.parentElement && e.remove();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`./icon-lfkgHbsk.js`);const e=require(`./register-element-tCL_F1YI.js`);require(`./text-Cpl5ljSe.js`),require(`./button-DGuqIeFS.js`),require(`./stack-CpmqyaNX.js`);var t=new Set,n=null;function r(e){if(!t.has(e)){if(t.size===0){let e=document.documentElement;n={scrollY:window.scrollY||window.pageYOffset||0,rootOverflow:e.style.overflow,rootOverscrollBehavior:e.style.overscrollBehavior},e.style.overflow=`hidden`,e.style.overscrollBehavior=`none`}t.add(e)}}function i(e){if(!t.delete(e)||t.size>0||!n)return;let r=n;n=null;let i=document.documentElement;i.style.overflow=r.rootOverflow,i.style.overscrollBehavior=r.rootOverscrollBehavior,window.scrollTo({left:0,top:r.scrollY,behavior:`instant`})}var a=class extends HTMLElement{static get observedAttributes(){return[`id`,`heading`,`open`]}constructor(){super(),this._overlay=null,this._modal=null,this._header=null,this._headingSlot=null,this._bodySlot=null,this._actionsSlot=null,this._closeButton=null,this._triggerElement=null,this._triggerPoint=null,this._renderedOpen=!1,this._lastPointerPoint=null,this._pointerDownHandler=null,this._darkModeObserver=null,this._exitTimer=null,this._backdropTimer=null}connectedCallback(){this.isOpen()||this.classList.add(`mint-hidden`),this.render(),this._observeDarkMode(),this._pointerDownHandler=e=>{this._lastPointerPoint={x:e.clientX,y:e.clientY,target:e.target,time:Date.now()}},document.addEventListener(`pointerdown`,this._pointerDownHandler,!0)}disconnectedCallback(){i(this),this._pointerDownHandler&&=(document.removeEventListener(`pointerdown`,this._pointerDownHandler,!0),null),this._exitTimer&&=(clearTimeout(this._exitTimer),null),this._backdropTimer&&=(clearTimeout(this._backdropTimer),null),this._darkModeObserver&&=(this._darkModeObserver.disconnect(),null)}attributeChangedCallback(e,t,n){t!==n&&(e===`open`&&n!==null&&!this._triggerElement&&(this._triggerElement=this._findTriggerElement(),this._triggerPoint=this._findTriggerPoint(this._triggerElement)),this.render())}getId(){return this.getAttribute(`id`)||``}getHeading(){return this.getAttribute(`heading`)||``}isOpen(){return this.hasAttribute(`open`)}open(e){this._triggerElement=this._findTriggerElement(e),this._triggerPoint=this._findTriggerPoint(this._triggerElement),this.setAttribute(`open`,``)}close(){this.removeAttribute(`open`)}render(){let e=this.getId(),t=this.getHeading(),n=this.isOpen();if(e&&(this.id=e),this._overlay||(this._overlay=document.createElement(`div`),this._overlay.className=`mint-modal-overlay`,this._overlay.addEventListener(`click`,()=>this.close()),this.appendChild(this._overlay)),this._modal||(this._modal=document.createElement(`div`),this._modal.className=`mint-modal-shell`,this.appendChild(this._modal)),n){let e=this._modal.querySelector(`.modal-content`);e||(e=document.createElement(`div`),e.className=`modal-content`,this._modal.appendChild(e)),this._renderedOpen||(this._renderedOpen=!0,r(this),this._animateEnter())}else this._renderedOpen&&(this._renderedOpen=!1,this._animateExit());let i=this._modal.querySelector(`.modal-content`);i||(i=document.createElement(`div`),i.className=`modal-content`,this._modal.appendChild(i)),this._header||(this._header=document.createElement(`div`),this._header.className=`mint-modal-header`,i.appendChild(this._header)),this._headingSlot||(this._headingSlot=document.createElement(`div`),this._headingSlot.className=`mint-modal-heading`,this._headingSlot.setAttribute(`slot`,`heading`),this._header.appendChild(this._headingSlot));let a=this._headingSlot.querySelector(`mint-text`);t?(a||(a=document.createElement(`mint-text`),a.setAttribute(`size`,`sub-heading`),a.setAttribute(`bold`,``),this._headingSlot.appendChild(a)),a.textContent=t):a&&a.remove(),Array.from(this.children).filter(e=>e!==this._overlay&&e!==this._modal&&e!==this._headingSlot&&e.getAttribute(`slot`)===`heading`).forEach(e=>{e.parentElement!==this._headingSlot&&this._headingSlot.appendChild(e)}),this._closeButton||(this._closeButton=document.createElement(`mint-button`),this._closeButton.setAttribute(`variant`,`ghost`),this._closeButton.setAttribute(`icon`,`close`),this._closeButton.addEventListener(`click`,()=>this.close()),this._header.appendChild(this._closeButton)),this._bodySlot||(this._bodySlot=document.createElement(`div`),this._bodySlot.className=`mint-modal-body`,this._bodySlot.setAttribute(`slot`,`body`),i.appendChild(this._bodySlot)),Array.from(this.children).filter(e=>e!==this._overlay&&e!==this._modal&&e!==this._bodySlot&&e.getAttribute(`slot`)===`body`).forEach(e=>{e.parentElement!==this._bodySlot&&this._bodySlot.appendChild(e)}),this._actionsSlot||(this._actionsSlot=document.createElement(`div`),this._actionsSlot.className=`mint-modal-actions`,this._actionsSlot.setAttribute(`slot`,`actions`),i.appendChild(this._actionsSlot));let o=this._actionsSlot.querySelector(`mint-stack`);o||(o=document.createElement(`mint-stack`),o.setAttribute(`direction`,`horizontal`),o.className=`mint-actions-stack`,this._actionsSlot.appendChild(o)),Array.from(this.children).filter(e=>e!==this._overlay&&e!==this._modal&&e!==this._actionsSlot&&e.getAttribute(`slot`)===`actions`).forEach(e=>{Array.from(e.children).forEach(e=>{e.parentElement!==o&&o.appendChild(e)}),e.parentElement&&e.remove()}),Array.from(this.children).forEach(e=>{e!==this._overlay&&e!==this._modal&&e.getAttribute(`slot`)!==`heading`&&e.getAttribute(`slot`)!==`body`&&e.getAttribute(`slot`)!==`actions`&&e!==this._headingSlot&&e!==this._bodySlot&&e!==this._actionsSlot&&e.parentElement!==this._bodySlot&&this._bodySlot.appendChild(e)}),this._updateBackgroundColor()}_updateBackgroundColor(){if(!this._modal)return;document.documentElement?.classList.contains(`dark`)||document.documentElement?.dataset.mintTheme;let e=this._modal.querySelector(`.modal-content`);e&&(e.style.background=`var(--mint-color-surface-raised)`)}_observeDarkMode(){if(!this._darkModeObserver){if(this._darkModeObserver=new MutationObserver(()=>{this._updateBackgroundColor()}),!document.documentElement)return;this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`,`data-mint-theme`]})}}_animateEnter(){let e=this._modal?.querySelector(`.modal-content`);e&&(this._exitTimer&&=(clearTimeout(this._exitTimer),null),this._backdropTimer&&=(clearTimeout(this._backdropTimer),null),this.classList.remove(`mint-modal-closing`),this.classList.remove(`mint-modal-open`),this.classList.add(`mint-modal-open`),this.classList.remove(`mint-hidden`),e.style.transform=`none`,e.style.opacity=`0`,e.style.transition=`none`,requestAnimationFrame(()=>{if(!this.isOpen())return;let t=window.getComputedStyle(e).borderRadius;this._setTransformOrigin(e),e.style.borderRadius=`50%`,e.style.transform=`scale(0.1, 0.2)`,e.style.opacity=`0.9`,e.getBoundingClientRect(),e.style.transition=`opacity 320ms ease-out, transform 360ms cubic-bezier(0.2, 0.8, 0.2, 1), border-radius 360ms cubic-bezier(0.2, 0.8, 0.2, 1)`,requestAnimationFrame(()=>{this.isOpen()&&(e.style.transform=`scale(1)`,e.style.opacity=`1`,e.style.borderRadius=t,window.setTimeout(()=>{this.isOpen()&&(e.style.transition=``,e.style.transform=`none`)},380))})}))}_findTriggerElement(e){if(typeof e==`string`){let t=document.getElementById(e);return t&&!this.contains(t)?t:null}if(e instanceof HTMLElement)return e.isConnected&&!this.contains(e)?e:null;let t=this.getAttribute(`trigger-id`);if(t){let e=document.getElementById(t);if(e&&!this.contains(e))return e}let n=document.activeElement;return n instanceof HTMLElement&&n.isConnected&&n!==document.body&&!this.contains(n)?n:null}_findTriggerPoint(e){if(!e)return null;let t=this._lastPointerPoint;if(!t||Date.now()-t.time>1e3)return null;let n=t.target instanceof Node?t.target:null;return n===e||n&&e.contains(n)?{x:t.x,y:t.y}:null}_setTransformOrigin(e){let t=this._findTriggerElement(this._triggerElement);this._triggerElement=t;let n=this._findTriggerPoint(t);if(n){let t=e.getBoundingClientRect();e.style.transformOrigin=`${n.x-t.left}px ${n.y-t.top}px`,this._triggerPoint=n;return}this._triggerPoint={x:window.innerWidth/2,y:0};let r=e.getBoundingClientRect();e.style.transformOrigin=`${this._triggerPoint.x-r.left}px ${this._triggerPoint.y-r.top}px`}_animateExit(){this.classList.remove(`mint-modal-open`),this._backdropTimer&&=(clearTimeout(this._backdropTimer),null);let e=this._modal?.querySelector(`.modal-content`);if(!e){this.classList.add(`mint-hidden`),this.classList.remove(`mint-modal-closing`),i(this);return}this._exitTimer&&clearTimeout(this._exitTimer),this.classList.add(`mint-modal-closing`),e.style.transition=`opacity 220ms ease-in, transform 260ms cubic-bezier(0.4, 0, 1, 1), border-radius 260ms cubic-bezier(0.4, 0, 1, 1)`,e.style.borderRadius=`50%`,e.style.transform=`scale(0.1, 0.2)`,e.style.opacity=`0.9`,this._exitTimer=setTimeout(()=>{this._exitTimer=null,!this.isOpen()&&(this.classList.add(`mint-hidden`),this.classList.remove(`mint-modal-closing`),e.style.transform=``,e.style.opacity=``,e.style.borderRadius=``,e.style.transition=``,i(this))},280)}};typeof customElements<`u`&&!customElements.get(`mint-modal`)&&e.t(`mint-modal`,a),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return a}});
|
|
1
|
+
require(`./icon-lfkgHbsk.js`);const e=require(`./register-element-tCL_F1YI.js`);require(`./text-Cpl5ljSe.js`),require(`./button-DGuqIeFS.js`),require(`./stack-CpmqyaNX.js`);var t=new Set,n=null;function r(e){if(!t.has(e)){if(t.size===0){let e=document.documentElement;n={scrollY:window.scrollY||window.pageYOffset||0,rootOverflow:e.style.overflow,rootOverscrollBehavior:e.style.overscrollBehavior},e.style.overflow=`hidden`,e.style.overscrollBehavior=`none`}t.add(e)}}function i(e){if(!t.delete(e)||t.size>0||!n)return;let r=n;n=null;let i=document.documentElement;i.style.overflow=r.rootOverflow,i.style.overscrollBehavior=r.rootOverscrollBehavior,window.scrollTo({left:0,top:r.scrollY,behavior:`instant`})}var a=class extends HTMLElement{static get observedAttributes(){return[`id`,`heading`,`open`]}constructor(){super(),this._overlay=null,this._modal=null,this._header=null,this._headingSlot=null,this._bodySlot=null,this._actionsSlot=null,this._closeButton=null,this._triggerElement=null,this._triggerPoint=null,this._renderedOpen=!1,this._lastPointerPoint=null,this._pointerDownHandler=null,this._darkModeObserver=null,this._exitTimer=null,this._backdropTimer=null}connectedCallback(){this.isOpen()||this.classList.add(`mint-hidden`),this.render(),this._observeDarkMode(),this._pointerDownHandler=e=>{this._lastPointerPoint={x:e.clientX,y:e.clientY,target:e.target,time:Date.now()}},document.addEventListener(`pointerdown`,this._pointerDownHandler,!0)}disconnectedCallback(){i(this),this._pointerDownHandler&&=(document.removeEventListener(`pointerdown`,this._pointerDownHandler,!0),null),this._exitTimer&&=(clearTimeout(this._exitTimer),null),this._backdropTimer&&=(clearTimeout(this._backdropTimer),null),this._darkModeObserver&&=(this._darkModeObserver.disconnect(),null)}attributeChangedCallback(e,t,n){t!==n&&(e===`open`&&n!==null&&!this._triggerElement&&(this._triggerElement=this._findTriggerElement(),this._triggerPoint=this._findTriggerPoint(this._triggerElement)),this.render())}getId(){return this.getAttribute(`id`)||``}getHeading(){return this.getAttribute(`heading`)||``}isOpen(){return this.hasAttribute(`open`)}open(e){this._triggerElement=this._findTriggerElement(e),this._triggerPoint=this._findTriggerPoint(this._triggerElement),this.setAttribute(`open`,``)}close(){this.removeAttribute(`open`)}render(){let e=this.getId(),t=this.getHeading(),n=this.isOpen();if(e&&(this.id=e),this._overlay||(this._overlay=document.createElement(`div`),this._overlay.className=`mint-modal-overlay`,this._overlay.addEventListener(`click`,()=>this.close()),this.appendChild(this._overlay)),this._modal||(this._modal=document.createElement(`div`),this._modal.className=`mint-modal-shell`,this.appendChild(this._modal)),n){let e=this._modal.querySelector(`.modal-content`);e||(e=document.createElement(`div`),e.className=`modal-content`,this._modal.appendChild(e)),this._renderedOpen||(this._renderedOpen=!0,r(this),this._animateEnter())}else this._renderedOpen&&(this._renderedOpen=!1,this._animateExit());let i=this._modal.querySelector(`.modal-content`);i||(i=document.createElement(`div`),i.className=`modal-content`,this._modal.appendChild(i)),this._header||(this._header=document.createElement(`div`),this._header.className=`mint-modal-header`,i.appendChild(this._header)),this._headingSlot||(this._headingSlot=document.createElement(`div`),this._headingSlot.className=`mint-modal-heading`,this._headingSlot.setAttribute(`slot`,`heading`),this._header.appendChild(this._headingSlot));let a=this._headingSlot.querySelector(`mint-text`);t?(a||(a=document.createElement(`mint-text`),a.setAttribute(`size`,`sub-heading`),a.setAttribute(`bold`,``),this._headingSlot.appendChild(a)),a.textContent=t):a&&a.remove(),Array.from(this.children).filter(e=>e!==this._overlay&&e!==this._modal&&e!==this._headingSlot&&e.getAttribute(`slot`)===`heading`).forEach(e=>{e.parentElement!==this._headingSlot&&this._headingSlot.appendChild(e)}),this._closeButton||(this._closeButton=document.createElement(`mint-button`),this._closeButton.setAttribute(`variant`,`ghost`),this._closeButton.setAttribute(`icon`,`close`),this._closeButton.addEventListener(`click`,()=>this.close()),this._header.appendChild(this._closeButton)),this._bodySlot||(this._bodySlot=document.createElement(`div`),this._bodySlot.className=`mint-modal-body`,this._bodySlot.setAttribute(`slot`,`body`),i.appendChild(this._bodySlot)),Array.from(this.children).filter(e=>e!==this._overlay&&e!==this._modal&&e!==this._bodySlot&&e.getAttribute(`slot`)===`body`).forEach(e=>{e.parentElement!==this._bodySlot&&this._bodySlot.appendChild(e)}),this._actionsSlot||(this._actionsSlot=document.createElement(`div`),this._actionsSlot.className=`mint-modal-actions`,this._actionsSlot.setAttribute(`slot`,`actions`),i.appendChild(this._actionsSlot));let o=this._actionsSlot.querySelector(`mint-stack`);o||(o=document.createElement(`mint-stack`),o.setAttribute(`direction`,`horizontal`),o.setAttribute(`align-content`,`right`),o.className=`mint-actions-stack`,this._actionsSlot.appendChild(o)),Array.from(this.children).filter(e=>e!==this._overlay&&e!==this._modal&&e!==this._actionsSlot&&e.getAttribute(`slot`)===`actions`).forEach(e=>{Array.from(e.children).forEach(e=>{e.parentElement!==o&&o.appendChild(e)}),e.parentElement&&e.remove()}),Array.from(this.children).forEach(e=>{e!==this._overlay&&e!==this._modal&&e.getAttribute(`slot`)!==`heading`&&e.getAttribute(`slot`)!==`body`&&e.getAttribute(`slot`)!==`actions`&&e!==this._headingSlot&&e!==this._bodySlot&&e!==this._actionsSlot&&e.parentElement!==this._bodySlot&&this._bodySlot.appendChild(e)}),this._updateBackgroundColor()}_updateBackgroundColor(){if(!this._modal)return;document.documentElement?.classList.contains(`dark`)||document.documentElement?.dataset.mintTheme;let e=this._modal.querySelector(`.modal-content`);e&&(e.style.background=`var(--mint-color-surface-raised)`)}_observeDarkMode(){if(!this._darkModeObserver){if(this._darkModeObserver=new MutationObserver(()=>{this._updateBackgroundColor()}),!document.documentElement)return;this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`,`data-mint-theme`]})}}_animateEnter(){let e=this._modal?.querySelector(`.modal-content`);e&&(this._exitTimer&&=(clearTimeout(this._exitTimer),null),this._backdropTimer&&=(clearTimeout(this._backdropTimer),null),this.classList.remove(`mint-modal-closing`),this.classList.remove(`mint-modal-open`),this.classList.add(`mint-modal-open`),this.classList.remove(`mint-hidden`),e.style.transform=`none`,e.style.opacity=`0`,e.style.transition=`none`,requestAnimationFrame(()=>{if(!this.isOpen())return;let t=window.getComputedStyle(e).borderRadius;this._setTransformOrigin(e),e.style.borderRadius=`50%`,e.style.transform=`scale(0.1, 0.2)`,e.style.opacity=`0.9`,e.getBoundingClientRect(),e.style.transition=`opacity 320ms ease-out, transform 360ms cubic-bezier(0.2, 0.8, 0.2, 1), border-radius 360ms cubic-bezier(0.2, 0.8, 0.2, 1)`,requestAnimationFrame(()=>{this.isOpen()&&(e.style.transform=`scale(1)`,e.style.opacity=`1`,e.style.borderRadius=t,window.setTimeout(()=>{this.isOpen()&&(e.style.transition=``,e.style.transform=`none`)},380))})}))}_findTriggerElement(e){if(typeof e==`string`){let t=document.getElementById(e);return t&&!this.contains(t)?t:null}if(e instanceof HTMLElement)return e.isConnected&&!this.contains(e)?e:null;let t=this.getAttribute(`trigger-id`);if(t){let e=document.getElementById(t);if(e&&!this.contains(e))return e}let n=document.activeElement;return n instanceof HTMLElement&&n.isConnected&&n!==document.body&&!this.contains(n)?n:null}_findTriggerPoint(e){if(!e)return null;let t=this._lastPointerPoint;if(!t||Date.now()-t.time>1e3)return null;let n=t.target instanceof Node?t.target:null;return n===e||n&&e.contains(n)?{x:t.x,y:t.y}:null}_setTransformOrigin(e){let t=this._findTriggerElement(this._triggerElement);this._triggerElement=t;let n=this._findTriggerPoint(t);if(n){let t=e.getBoundingClientRect();e.style.transformOrigin=`${n.x-t.left}px ${n.y-t.top}px`,this._triggerPoint=n;return}this._triggerPoint={x:window.innerWidth/2,y:0};let r=e.getBoundingClientRect();e.style.transformOrigin=`${this._triggerPoint.x-r.left}px ${this._triggerPoint.y-r.top}px`}_animateExit(){this.classList.remove(`mint-modal-open`),this._backdropTimer&&=(clearTimeout(this._backdropTimer),null);let e=this._modal?.querySelector(`.modal-content`);if(!e){this.classList.add(`mint-hidden`),this.classList.remove(`mint-modal-closing`),i(this);return}this._exitTimer&&clearTimeout(this._exitTimer),this.classList.add(`mint-modal-closing`),e.style.transition=`opacity 220ms ease-in, transform 260ms cubic-bezier(0.4, 0, 1, 1), border-radius 260ms cubic-bezier(0.4, 0, 1, 1)`,e.style.borderRadius=`50%`,e.style.transform=`scale(0.1, 0.2)`,e.style.opacity=`0.9`,this._exitTimer=setTimeout(()=>{this._exitTimer=null,!this.isOpen()&&(this.classList.add(`mint-hidden`),this.classList.remove(`mint-modal-closing`),e.style.transform=``,e.style.opacity=``,e.style.borderRadius=``,e.style.transition=``,i(this))},280)}};typeof customElements<`u`&&!customElements.get(`mint-modal`)&&e.t(`mint-modal`,a),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return a}});
|
|
@@ -240,23 +240,21 @@ var t = "mint-sortable-placeholder", n = "mint-sortable-dragging", r = class e e
|
|
|
240
240
|
})), this._autoScroll(e), this._maybeMovePlaceholder(e);
|
|
241
241
|
}
|
|
242
242
|
_resolveDropList(t) {
|
|
243
|
-
let n = document.elementFromPoint(t.clientX, t.clientY), r = n?.closest("[data-mint-sortable-drop-container]")
|
|
244
|
-
this._dropAtEnd =
|
|
245
|
-
let
|
|
243
|
+
let n = document.elementFromPoint(t.clientX, t.clientY), r = n?.closest("[data-mint-sortable-drop-container]");
|
|
244
|
+
this._dropAtEnd = !!r?.hasAttribute("data-mint-sortable-drop-end");
|
|
245
|
+
let i = r?.getAttribute("data-mint-sortable-drop-container"), a = i ? document.getElementById(i) : null, o = a?.matches("mint-sortable") ? a : n?.closest("mint-sortable"), s = o instanceof e ? o : this, c = this.getAttribute("group")?.trim(), l = !!(c && s.getAttribute("group")?.trim() === c), u = !!(this._dragEl && (s === this._dragEl || this._dragEl.contains(s))), d = s === this || l && s.isConnected && !u, f = new CustomEvent("mint-sortable-drag-over", {
|
|
246
246
|
bubbles: !0,
|
|
247
247
|
composed: !0,
|
|
248
248
|
cancelable: !0,
|
|
249
249
|
detail: {
|
|
250
250
|
item: this._dragEl,
|
|
251
251
|
source: this,
|
|
252
|
-
target:
|
|
252
|
+
target: s,
|
|
253
253
|
clientX: t.clientX,
|
|
254
254
|
clientY: t.clientY
|
|
255
255
|
}
|
|
256
256
|
});
|
|
257
|
-
this.dispatchEvent(
|
|
258
|
-
let m = this._dropRejected ? this : c;
|
|
259
|
-
return this._dropAtEnd = this._dropAtEnd || !!(m !== this && m.hasAttribute("data-tree-parent-id") && m.getAttribute("data-tree-parent-id")), m;
|
|
257
|
+
return this.dispatchEvent(f), this._dropRejected = !d || f.defaultPrevented, this._dropRejected ? this : s;
|
|
260
258
|
}
|
|
261
259
|
_autoScroll(e) {
|
|
262
260
|
let t = this;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./register-element-tCL_F1YI.js`);var t=`mint-sortable-placeholder`,n=`mint-sortable-dragging`,r=class e extends HTMLElement{static get observedAttributes(){return[`direction`,`gap`,`text-align`,`align-content`,`scroll-max-height`,`disabled`,`handle-selector`,`scroll-sensitivity`,`scroll-speed`,`animation-duration`,`item-key-attribute`,`group`]}constructor(){super(),this._pointerId=null,this._dragEl=null,this._placeholder=null,this._listRoot=this,this._startIndex=0,this._pointerStartX=0,this._pointerStartY=0,this._scrollRaf=null,this._childObserver=null,this._pointerBoundRoot=null,this._restoreAfter=null,this._originListRoot=null,this._originNextSibling=null,this._dropList=null,this._dropAtEnd=!1,this._dropRejected=!1,this._sortStatus=null,this._flipCleanupTimers=new WeakMap,this._keyboardKeydownHandler=e=>this._onKeyboardReorder(e),this._onListPointerDown=e=>{let t=e;if(this._isDisabled()||this._pointerId!==null||t.button!==0)return;let n=t.target;if(!n||!this.contains(n))return;let r=(n instanceof Element?n:n.parentElement)?.closest(`mint-sortable`);if(r&&r!==this)return;let i=this._closestSortableItem(n);if(!i||!this._listRoot.contains(i)||i.hasAttribute(`data-sortable-disabled`))return;let a=this._getHandleSelector();if(a){let e=t.target.closest(a);if(!e||!i.contains(e))return}t.preventDefault(),this._startDrag(t,i)},this._boundPointerMove=this._onPointerMove.bind(this),this._boundPointerUp=this._onPointerUp.bind(this),this._boundPointerCancel=this._onPointerCancel.bind(this)}connectedCallback(){this.classList.add(`mint-sortable`),this._syncInnerStackAttributes(),this._applyHostScrollAndLayout(),this.addEventListener(`keydown`,this._keyboardKeydownHandler),this._observeInnerStack()}disconnectedCallback(){this._unobserveInnerStack(),this.removeEventListener(`keydown`,this._keyboardKeydownHandler),this._teardownDrag(),this._pointerBoundRoot&&=(this._pointerBoundRoot.removeEventListener(`pointerdown`,this._onListPointerDown),null)}attributeChangedCallback(e,t,n){t!==n&&(this._syncInnerStackAttributes(),this._applyHostScrollAndLayout())}_observeInnerStack(){this._childObserver||(this._childObserver=new MutationObserver(()=>{this._pointerId===null&&(this._syncInnerStackAttributes(),this._applyHostScrollAndLayout())}),this._childObserver.observe(this,{childList:!0}))}_unobserveInnerStack(){this._childObserver&&=(this._childObserver.disconnect(),null)}_getInnerStack(){for(let e=0;e<this.children.length;e++){let t=this.children[e];if(t.nodeType===Node.ELEMENT_NODE&&t.tagName===`MINT-STACK`)return t}return null}_resolveListRoot(){return this._getInnerStack()??this}_getItemKeyAttribute(){return this.getAttribute(`item-key-attribute`)?.trim()||`data-sortable-id`}_collectOrderedKeys(){let e=this._resolveListRoot(),n=this._getItemKeyAttribute(),r=[];for(let i=0;i<e.children.length;i++){let a=e.children[i];if(a.nodeType!==Node.ELEMENT_NODE)continue;let o=a;o.classList.contains(t)||o.hasAttribute(`data-mint-sortable-status`)||r.push(o.getAttribute(n)??``)}return r}_syncInnerStackAttributes(){let e=this._getInnerStack();if(!e)return;let t=this.getDirection(),n=this.getGap(),r=this.getTextAlign();e.setAttribute(`direction`,t),e.setAttribute(`gap`,String(n)),r?e.setAttribute(`text-align`,r):e.removeAttribute(`text-align`);let i=this.getAlignContent();i?e.setAttribute(`align-content`,i):e.removeAttribute(`align-content`)}_applyHostScrollAndLayout(){this._listRoot=this._resolveListRoot();let e=this.getAttribute(`scroll-max-height`);e?(this.style.maxHeight=e,this.style.overflowY=`auto`,this.style.overflowX=`hidden`,this.classList.add(`mint-sortable-scrollable`)):(this.style.maxHeight=``,this.style.overflowY=``,this.style.overflowX=``,this.classList.remove(`mint-sortable-scrollable`));let t=this._getInnerStack();this.classList.toggle(`mint-sortable-has-inner-stack`,!!t);let n=this.getDirection(),r=this.getAlignContent(),i=Math.min(12,Math.max(1,Math.round(this.getGap()))),a=this.getTextAlign();this.style.setProperty(`--mint-sortable-direction`,n===`horizontal`?`row`:`column`),this.style.setProperty(`--mint-sortable-gap`,`${i*.25}rem`),this.style.setProperty(`--mint-sortable-text-align`,a||`initial`),this.style.setProperty(`--mint-sortable-button-justify`,a===`left`?`flex-start`:a===`right`?`flex-end`:`center`);let o=r?r===`left`?`flex-start`:r===`right`?`flex-end`:`center`:``,s=n===`vertical`&&o||`stretch`,c=n===`horizontal`&&o||`flex-start`;this.style.setProperty(`--mint-sortable-cross-align`,s),this.style.setProperty(`--mint-sortable-main-align`,c),this._ensureListPointerBinding(),this._syncKeyboardAccessibility()}_syncKeyboardAccessibility(){let e=this._resolveListRoot();e.hasAttribute(`role`)||e.setAttribute(`role`,`list`),this._sortStatus||(this._sortStatus=document.createElement(`div`),this._sortStatus.className=`mint-sortable-status`,this._sortStatus.setAttribute(`role`,`status`),this._sortStatus.setAttribute(`aria-live`,`polite`),this._sortStatus.setAttribute(`aria-atomic`,`true`),this._sortStatus.setAttribute(`data-mint-sortable-status`,``),this.appendChild(this._sortStatus)),this._getLayoutChildren().forEach(e=>{e.classList.contains(t)||(e.hasAttribute(`role`)||e.setAttribute(`role`,`listitem`),e.hasAttribute(`tabindex`)||(e.tabIndex=0),e.setAttribute(`aria-keyshortcuts`,`Alt+ArrowUp Alt+ArrowDown`),e.hasAttribute(`aria-roledescription`)||e.setAttribute(`aria-roledescription`,`sortable item`))})}_onKeyboardReorder(e){if(this._isDisabled()||!e.altKey||![`ArrowUp`,`ArrowDown`].includes(e.key))return;let n=e.target instanceof Element?e.target:null,r=n?.closest(`mint-sortable`);if(r&&r!==this)return;let i=n?this._closestSortableItem(n):null;if(!i||i.hasAttribute(`data-sortable-disabled`))return;let a=this._getLayoutChildren().filter(e=>!e.classList.contains(t)),o=a.indexOf(i),s=o+(e.key===`ArrowUp`?-1:1);if(o<0||s<0||s>=a.length)return;e.preventDefault();let c=a[s];e.key===`ArrowUp`?this._listRoot.insertBefore(i,c):this._listRoot.insertBefore(c,i),i.focus({preventScroll:!0});let l=this._collectOrderedKeys(),u=this._indexOfItem(i),d=i.getAttribute(`aria-label`)||i.textContent?.trim().replace(/\s+/g,` `)||`Item`;this._sortStatus&&(this._sortStatus.textContent=`${d} moved to position ${u+1} of ${a.length}.`);let f=this.getAttribute(`data-tree-parent-id`)||null,p={oldIndex:o,newIndex:u,keys:l,itemId:i.getAttribute(this._getItemKeyAttribute())||``,oldParentId:f,newParentId:f,sourceContainerId:this.id||null,destinationContainerId:this.id||null};this.dispatchEvent(new CustomEvent(`mint-sortable-change`,{bubbles:!0,composed:!0,detail:p})),this.dispatchEvent(new CustomEvent(`mint-sortable-order`,{bubbles:!0,composed:!0,detail:{keys:l}}))}getDirection(){return(this.getAttribute(`direction`)||`vertical`)===`horizontal`?`horizontal`:`vertical`}getGap(){let e=this.getAttribute(`gap`)||`3`,t=parseFloat(e);return Number.isFinite(t)?t:3}getTextAlign(){let e=this.getAttribute(`text-align`)||``;return[`left`,`center`,`right`,`justify`].includes(e)?e:``}getAlignContent(){let e=(this.getAttribute(`align-content`)||``).trim().toLowerCase();return e===`left`||e===`right`||e===`center`?e:``}_isDisabled(){return this.hasAttribute(`disabled`)&&this.getAttribute(`disabled`)!==`false`}_getHandleSelector(){let e=this.getAttribute(`handle-selector`);return e&&e.trim()?e.trim():null}_getScrollSensitivity(){let e=parseFloat(this.getAttribute(`scroll-sensitivity`)||`48`);return Number.isFinite(e)?e:48}_getScrollSpeed(){let e=parseFloat(this.getAttribute(`scroll-speed`)||`12`);return Number.isFinite(e)?e:12}_getAnimationDurationMs(){let e=parseFloat(this.getAttribute(`animation-duration`)||`220`);return Number.isFinite(e)?Math.max(0,e):220}_ensureListPointerBinding(){let e=this._resolveListRoot();this._pointerBoundRoot!==e&&(this._pointerBoundRoot&&this._pointerBoundRoot.removeEventListener(`pointerdown`,this._onListPointerDown),e.addEventListener(`pointerdown`,this._onListPointerDown),this._pointerBoundRoot=e,this._listRoot=e)}_closestSortableItem(e){let r=e;for(;r&&r!==this._listRoot;){if(r.nodeType===Node.ELEMENT_NODE){let e=r;if(e.classList.contains(t)||e.classList.contains(n))return null;if(r.parentElement===this._listRoot)return e}r=r.parentElement}return null}_startDrag(e,r){this._listRoot=this._resolveListRoot(),this._restoreAfter=r.nextElementSibling,this._originListRoot=this._listRoot,this._originNextSibling=r.nextElementSibling,this._dropList=this,this._dropAtEnd=!1,this._dropRejected=!1,this._dragEl=r,this._pointerId=e.pointerId,this._startIndex=this._indexOfItem(r);let i=r.getBoundingClientRect();this._pointerStartX=e.clientX,this._pointerStartY=e.clientY;let a=document.createElement(`div`);a.className=t,a.style.minHeight=`${i.height}px`,a.style.minWidth=`${i.width}px`,a.setAttribute(`aria-hidden`,`true`),this._placeholder=a,this._listRoot.insertBefore(a,r),r.classList.add(n),r.style.position=`fixed`,r.style.left=`${i.left}px`,r.style.top=`${i.top}px`,r.style.width=`${i.width}px`,r.style.height=`${i.height}px`,r.style.margin=`0`,r.style.zIndex=`10000`,r.style.boxSizing=`border-box`,r.style.pointerEvents=`none`,r.style.touchAction=`none`,r.style.transform=`translate3d(0, 0, 0) scale(1.015)`,r.style.transformOrigin=`center center`,r.style.willChange=`transform`,r.setPointerCapture(e.pointerId);let o=this._collectOrderedKeys(),s={index:this._startIndex,keys:o};this.dispatchEvent(new CustomEvent(`mint-sortable-start`,{bubbles:!0,composed:!0,detail:s})),this.dispatchEvent(new CustomEvent(`sort-start`,{bubbles:!0,composed:!0,detail:s})),window.addEventListener(`pointermove`,this._boundPointerMove,{passive:!1}),window.addEventListener(`pointerup`,this._boundPointerUp),window.addEventListener(`pointercancel`,this._boundPointerCancel)}_indexOfItem(e){let n=0;for(let r=0;r<this._listRoot.children.length;r++){let i=this._listRoot.children[r];if(i.nodeType!==Node.ELEMENT_NODE)continue;let a=i;if(!a.classList.contains(t)){if(a===e)return n;n++}}return-1}_getLayoutChildren(){return Array.from(this._listRoot.children).filter(e=>e.nodeType===Node.ELEMENT_NODE&&!e.hasAttribute(`data-mint-sortable-status`))}_onPointerMove(e){if(e.pointerId!==this._pointerId||!this._dragEl||!this._placeholder)return;e.preventDefault();let t=e.clientX-this._pointerStartX,n=e.clientY-this._pointerStartY;this._dragEl.style.transform=`translate3d(${t}px, ${n}px, 0) scale(1.015)`,this.dispatchEvent(new CustomEvent(`mint-sortable-drag`,{bubbles:!0,composed:!0,detail:{item:this._dragEl,source:this,clientX:e.clientX,clientY:e.clientY}})),this._autoScroll(e),this._maybeMovePlaceholder(e)}_resolveDropList(t){let n=document.elementFromPoint(t.clientX,t.clientY),r=n?.closest(`[data-mint-sortable-drop-container]`),i=n?.closest(`[data-mint-sortable-drop-center]`);this._dropAtEnd=!1,i&&(r=i,this._dropAtEnd=!0);let a=r?.getAttribute(`data-mint-sortable-drop-container`),o=a?document.getElementById(a):null,s=o?.matches(`mint-sortable`)?o:n?.closest(`mint-sortable`),c=s instanceof e?s:this,l=this.getAttribute(`group`)?.trim(),u=!!(l&&c.getAttribute(`group`)?.trim()===l),d=!!(this._dragEl&&(c===this._dragEl||this._dragEl.contains(c))),f=c===this||u&&c.isConnected&&!d,p=new CustomEvent(`mint-sortable-drag-over`,{bubbles:!0,composed:!0,cancelable:!0,detail:{item:this._dragEl,source:this,target:c,clientX:t.clientX,clientY:t.clientY}});this.dispatchEvent(p),this._dropRejected=!f||p.defaultPrevented;let m=this._dropRejected?this:c;return this._dropAtEnd=this._dropAtEnd||!!(m!==this&&m.hasAttribute(`data-tree-parent-id`)&&m.getAttribute(`data-tree-parent-id`)),m}_autoScroll(e){let t=this;for(;t&&t!==document.body;){let e=getComputedStyle(t);if(/(auto|scroll)/.test(`${e.overflowY} ${e.overflow}`)&&t.scrollHeight>t.clientHeight||t.style.maxHeight)break;t=t.parentElement}if(!t||t===document.body)return;let n=this._getScrollSensitivity(),r=this._getScrollSpeed(),i=t.getBoundingClientRect();this._scrollRaf!==null&&cancelAnimationFrame(this._scrollRaf),this._scrollRaf=requestAnimationFrame(()=>{this._scrollRaf=null;let a=0;e.clientY<i.top+n?a=-r:e.clientY>i.bottom-n&&(a=r),a!==0&&(t.scrollTop+=a,this._maybeMovePlaceholder(e))})}_maybeMovePlaceholder(e){let t=this._placeholder,n=this._dragEl;if(!t||!n)return;let r=this._resolveDropList(e),i=r._resolveListRoot();if(i===n||n.contains(i))return;t.parentElement!==i&&r._flipAnimate(()=>i.appendChild(t)),this._dropList=r;let a=r.getDirection()===`horizontal`,o=a?e.clientX:e.clientY,s=this.hasAttribute(`data-mint-sortable-full-crossing`);if(this._dropAtEnd&&r!==this){(t.parentElement!==i||i.lastElementChild!==t)&&r._flipAnimate(()=>i.appendChild(t));return}let c=Array.from(i.children).filter(e=>e.nodeType===Node.ELEMENT_NODE&&e!==n&&e!==t),l=null;for(let e of c){let n=e.getBoundingClientRect(),r=a?n.left:n.top,c=a?n.left+n.width:n.top+n.height;if(s){if(o<r){l=e;break}if(o<=c&&Array.prototype.indexOf.call(i.children,t)<Array.prototype.indexOf.call(i.children,e)){l=e;break}}else if(o<(a?n.left+n.width/2:n.top+n.height/2)){l=e;break}}let u=Array.from(i.children).filter(e=>e.nodeType===Node.ELEMENT_NODE&&e!==n),d=u.length>0&&u[u.length-1]===t;(l?!(t.nextSibling===l&&t.parentNode===i):!d)&&r._flipAnimate(()=>{l?i.insertBefore(t,l):i.appendChild(t)})}_flipAnimate(e){let t=this._dragEl,n=this._getAnimationDurationMs(),r=this._getLayoutChildren().filter(e=>e!==t),i=new Map;if(r.forEach(e=>{let t=this._flipCleanupTimers.get(e);t!==void 0&&(window.clearTimeout(t),this._flipCleanupTimers.delete(e)),i.set(e,e.getBoundingClientRect()),e.style.transition=`none`,e.style.transform=``}),r.length&&r[0].offsetHeight,e(),n<=0||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches){r.forEach(e=>{e.style.transition=``,e.style.transform=``});return}r.forEach(e=>{let t=i.get(e);if(!t)return;let r=e.getBoundingClientRect(),a=t.left-r.left,o=t.top-r.top;Math.abs(a)<.5&&Math.abs(o)<.5||(e.style.transition=`none`,e.style.transform=`translate(${a}px, ${o}px)`,requestAnimationFrame(()=>{e.style.transition=`transform ${n}ms cubic-bezier(0.22, 1, 0.36, 1)`,e.style.transform=``;let t=()=>{e.removeEventListener(`transitionend`,t),e.style.transition=``,e.style.transform=``,this._flipCleanupTimers.delete(e)};e.addEventListener(`transitionend`,t,{once:!0}),this._flipCleanupTimers.set(e,window.setTimeout(t,n+40))}))})}_onPointerUp(e){e.pointerId===this._pointerId&&(this._maybeMovePlaceholder(e),this._finishDrag(!1))}_onPointerCancel(e){e.pointerId===this._pointerId&&this._finishDrag(!0)}_finishDrag(e){let t=this._dragEl,r=this._placeholder;if(!t||this._pointerId===null){this._teardownDrag();return}try{t.releasePointerCapture(this._pointerId)}catch{}window.removeEventListener(`pointermove`,this._boundPointerMove),window.removeEventListener(`pointerup`,this._boundPointerUp),window.removeEventListener(`pointercancel`,this._boundPointerCancel);let i=this._dropList??this,a=i._resolveListRoot();!e&&!this._dropRejected&&this._dropAtEnd&&i!==this&&r?.parentNode===a&&a.appendChild(r);let o=this.getAttribute(`data-tree-parent-id`)||null,s=i.getAttribute(`data-tree-parent-id`)||null,c=this._indexOfItem(t),l=r?.parentNode===a?Array.from(a.children).filter(e=>e.nodeType===Node.ELEMENT_NODE&&e!==t&&!e.hasAttribute(`data-mint-sortable-status`)).indexOf(r):c,u=new CustomEvent(`mint-sortable-before-drop`,{bubbles:!0,composed:!0,cancelable:!0,detail:{item:t,source:this,target:i,oldIndex:c,newIndex:l,oldParentId:o,newParentId:s}});e||this.dispatchEvent(u);let d=e||this._dropRejected||u.defaultPrevented;if(d){let e=this._originListRoot??this._listRoot,n=this._originNextSibling??this._restoreAfter;n&&n.parentNode===e?e.insertBefore(t,n):e.appendChild(t)}else r?.parentNode&&r.parentNode.insertBefore(t,r);r?.remove(),this._placeholder=null,t.classList.remove(n),t.style.cssText=``;let f=d?c:i._indexOfItem(t);this._pointerId=null,this._dragEl=null,this._restoreAfter=null,this._originListRoot=null,this._originNextSibling=null,this._dropList=null,this._dropAtEnd=!1,this._dropRejected=!1;let p=this._collectOrderedKeys(),m=i._collectOrderedKeys(),h=!d&&(!d&&o!==s||f!==c),g=t.getAttribute(this._getItemKeyAttribute())||``,_={oldIndex:c,newIndex:f,cancelled:d,keys:p,sourceKeys:p,destinationKeys:m,oldParentId:o,newParentId:s,sourceContainerId:this.id||null,destinationContainerId:i.id||null,itemId:g};this.dispatchEvent(new CustomEvent(`mint-sortable-end`,{bubbles:!0,composed:!0,detail:_})),this.dispatchEvent(new CustomEvent(`sort-stop`,{bubbles:!0,composed:!0,detail:_})),h&&(this.dispatchEvent(new CustomEvent(`mint-sortable-change`,{bubbles:!0,composed:!0,detail:_})),this.dispatchEvent(new CustomEvent(`mint-sortable-order`,{bubbles:!0,composed:!0,detail:{keys:p,sourceKeys:p,destinationKeys:m,oldParentId:o,newParentId:s,itemId:g}})))}_teardownDrag(){if(this._scrollRaf!==null&&(cancelAnimationFrame(this._scrollRaf),this._scrollRaf=null),window.removeEventListener(`pointermove`,this._boundPointerMove),window.removeEventListener(`pointerup`,this._boundPointerUp),window.removeEventListener(`pointercancel`,this._boundPointerCancel),this._dragEl){try{this._pointerId!==null&&this._dragEl.releasePointerCapture(this._pointerId)}catch{}this._dragEl.classList.remove(n),this._dragEl.style.cssText=``}this._placeholder?.remove(),this._placeholder=null,this._dragEl=null,this._pointerId=null,this._restoreAfter=null,this._originListRoot=null,this._originNextSibling=null,this._dropList=null,this._dropRejected=!1}};customElements.get(`mint-sortable`)||e.t(`mint-sortable`,r),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return r}});
|
|
1
|
+
const e=require(`./register-element-tCL_F1YI.js`);var t=`mint-sortable-placeholder`,n=`mint-sortable-dragging`,r=class e extends HTMLElement{static get observedAttributes(){return[`direction`,`gap`,`text-align`,`align-content`,`scroll-max-height`,`disabled`,`handle-selector`,`scroll-sensitivity`,`scroll-speed`,`animation-duration`,`item-key-attribute`,`group`]}constructor(){super(),this._pointerId=null,this._dragEl=null,this._placeholder=null,this._listRoot=this,this._startIndex=0,this._pointerStartX=0,this._pointerStartY=0,this._scrollRaf=null,this._childObserver=null,this._pointerBoundRoot=null,this._restoreAfter=null,this._originListRoot=null,this._originNextSibling=null,this._dropList=null,this._dropAtEnd=!1,this._dropRejected=!1,this._sortStatus=null,this._flipCleanupTimers=new WeakMap,this._keyboardKeydownHandler=e=>this._onKeyboardReorder(e),this._onListPointerDown=e=>{let t=e;if(this._isDisabled()||this._pointerId!==null||t.button!==0)return;let n=t.target;if(!n||!this.contains(n))return;let r=(n instanceof Element?n:n.parentElement)?.closest(`mint-sortable`);if(r&&r!==this)return;let i=this._closestSortableItem(n);if(!i||!this._listRoot.contains(i)||i.hasAttribute(`data-sortable-disabled`))return;let a=this._getHandleSelector();if(a){let e=t.target.closest(a);if(!e||!i.contains(e))return}t.preventDefault(),this._startDrag(t,i)},this._boundPointerMove=this._onPointerMove.bind(this),this._boundPointerUp=this._onPointerUp.bind(this),this._boundPointerCancel=this._onPointerCancel.bind(this)}connectedCallback(){this.classList.add(`mint-sortable`),this._syncInnerStackAttributes(),this._applyHostScrollAndLayout(),this.addEventListener(`keydown`,this._keyboardKeydownHandler),this._observeInnerStack()}disconnectedCallback(){this._unobserveInnerStack(),this.removeEventListener(`keydown`,this._keyboardKeydownHandler),this._teardownDrag(),this._pointerBoundRoot&&=(this._pointerBoundRoot.removeEventListener(`pointerdown`,this._onListPointerDown),null)}attributeChangedCallback(e,t,n){t!==n&&(this._syncInnerStackAttributes(),this._applyHostScrollAndLayout())}_observeInnerStack(){this._childObserver||(this._childObserver=new MutationObserver(()=>{this._pointerId===null&&(this._syncInnerStackAttributes(),this._applyHostScrollAndLayout())}),this._childObserver.observe(this,{childList:!0}))}_unobserveInnerStack(){this._childObserver&&=(this._childObserver.disconnect(),null)}_getInnerStack(){for(let e=0;e<this.children.length;e++){let t=this.children[e];if(t.nodeType===Node.ELEMENT_NODE&&t.tagName===`MINT-STACK`)return t}return null}_resolveListRoot(){return this._getInnerStack()??this}_getItemKeyAttribute(){return this.getAttribute(`item-key-attribute`)?.trim()||`data-sortable-id`}_collectOrderedKeys(){let e=this._resolveListRoot(),n=this._getItemKeyAttribute(),r=[];for(let i=0;i<e.children.length;i++){let a=e.children[i];if(a.nodeType!==Node.ELEMENT_NODE)continue;let o=a;o.classList.contains(t)||o.hasAttribute(`data-mint-sortable-status`)||r.push(o.getAttribute(n)??``)}return r}_syncInnerStackAttributes(){let e=this._getInnerStack();if(!e)return;let t=this.getDirection(),n=this.getGap(),r=this.getTextAlign();e.setAttribute(`direction`,t),e.setAttribute(`gap`,String(n)),r?e.setAttribute(`text-align`,r):e.removeAttribute(`text-align`);let i=this.getAlignContent();i?e.setAttribute(`align-content`,i):e.removeAttribute(`align-content`)}_applyHostScrollAndLayout(){this._listRoot=this._resolveListRoot();let e=this.getAttribute(`scroll-max-height`);e?(this.style.maxHeight=e,this.style.overflowY=`auto`,this.style.overflowX=`hidden`,this.classList.add(`mint-sortable-scrollable`)):(this.style.maxHeight=``,this.style.overflowY=``,this.style.overflowX=``,this.classList.remove(`mint-sortable-scrollable`));let t=this._getInnerStack();this.classList.toggle(`mint-sortable-has-inner-stack`,!!t);let n=this.getDirection(),r=this.getAlignContent(),i=Math.min(12,Math.max(1,Math.round(this.getGap()))),a=this.getTextAlign();this.style.setProperty(`--mint-sortable-direction`,n===`horizontal`?`row`:`column`),this.style.setProperty(`--mint-sortable-gap`,`${i*.25}rem`),this.style.setProperty(`--mint-sortable-text-align`,a||`initial`),this.style.setProperty(`--mint-sortable-button-justify`,a===`left`?`flex-start`:a===`right`?`flex-end`:`center`);let o=r?r===`left`?`flex-start`:r===`right`?`flex-end`:`center`:``,s=n===`vertical`&&o||`stretch`,c=n===`horizontal`&&o||`flex-start`;this.style.setProperty(`--mint-sortable-cross-align`,s),this.style.setProperty(`--mint-sortable-main-align`,c),this._ensureListPointerBinding(),this._syncKeyboardAccessibility()}_syncKeyboardAccessibility(){let e=this._resolveListRoot();e.hasAttribute(`role`)||e.setAttribute(`role`,`list`),this._sortStatus||(this._sortStatus=document.createElement(`div`),this._sortStatus.className=`mint-sortable-status`,this._sortStatus.setAttribute(`role`,`status`),this._sortStatus.setAttribute(`aria-live`,`polite`),this._sortStatus.setAttribute(`aria-atomic`,`true`),this._sortStatus.setAttribute(`data-mint-sortable-status`,``),this.appendChild(this._sortStatus)),this._getLayoutChildren().forEach(e=>{e.classList.contains(t)||(e.hasAttribute(`role`)||e.setAttribute(`role`,`listitem`),e.hasAttribute(`tabindex`)||(e.tabIndex=0),e.setAttribute(`aria-keyshortcuts`,`Alt+ArrowUp Alt+ArrowDown`),e.hasAttribute(`aria-roledescription`)||e.setAttribute(`aria-roledescription`,`sortable item`))})}_onKeyboardReorder(e){if(this._isDisabled()||!e.altKey||![`ArrowUp`,`ArrowDown`].includes(e.key))return;let n=e.target instanceof Element?e.target:null,r=n?.closest(`mint-sortable`);if(r&&r!==this)return;let i=n?this._closestSortableItem(n):null;if(!i||i.hasAttribute(`data-sortable-disabled`))return;let a=this._getLayoutChildren().filter(e=>!e.classList.contains(t)),o=a.indexOf(i),s=o+(e.key===`ArrowUp`?-1:1);if(o<0||s<0||s>=a.length)return;e.preventDefault();let c=a[s];e.key===`ArrowUp`?this._listRoot.insertBefore(i,c):this._listRoot.insertBefore(c,i),i.focus({preventScroll:!0});let l=this._collectOrderedKeys(),u=this._indexOfItem(i),d=i.getAttribute(`aria-label`)||i.textContent?.trim().replace(/\s+/g,` `)||`Item`;this._sortStatus&&(this._sortStatus.textContent=`${d} moved to position ${u+1} of ${a.length}.`);let f=this.getAttribute(`data-tree-parent-id`)||null,p={oldIndex:o,newIndex:u,keys:l,itemId:i.getAttribute(this._getItemKeyAttribute())||``,oldParentId:f,newParentId:f,sourceContainerId:this.id||null,destinationContainerId:this.id||null};this.dispatchEvent(new CustomEvent(`mint-sortable-change`,{bubbles:!0,composed:!0,detail:p})),this.dispatchEvent(new CustomEvent(`mint-sortable-order`,{bubbles:!0,composed:!0,detail:{keys:l}}))}getDirection(){return(this.getAttribute(`direction`)||`vertical`)===`horizontal`?`horizontal`:`vertical`}getGap(){let e=this.getAttribute(`gap`)||`3`,t=parseFloat(e);return Number.isFinite(t)?t:3}getTextAlign(){let e=this.getAttribute(`text-align`)||``;return[`left`,`center`,`right`,`justify`].includes(e)?e:``}getAlignContent(){let e=(this.getAttribute(`align-content`)||``).trim().toLowerCase();return e===`left`||e===`right`||e===`center`?e:``}_isDisabled(){return this.hasAttribute(`disabled`)&&this.getAttribute(`disabled`)!==`false`}_getHandleSelector(){let e=this.getAttribute(`handle-selector`);return e&&e.trim()?e.trim():null}_getScrollSensitivity(){let e=parseFloat(this.getAttribute(`scroll-sensitivity`)||`48`);return Number.isFinite(e)?e:48}_getScrollSpeed(){let e=parseFloat(this.getAttribute(`scroll-speed`)||`12`);return Number.isFinite(e)?e:12}_getAnimationDurationMs(){let e=parseFloat(this.getAttribute(`animation-duration`)||`220`);return Number.isFinite(e)?Math.max(0,e):220}_ensureListPointerBinding(){let e=this._resolveListRoot();this._pointerBoundRoot!==e&&(this._pointerBoundRoot&&this._pointerBoundRoot.removeEventListener(`pointerdown`,this._onListPointerDown),e.addEventListener(`pointerdown`,this._onListPointerDown),this._pointerBoundRoot=e,this._listRoot=e)}_closestSortableItem(e){let r=e;for(;r&&r!==this._listRoot;){if(r.nodeType===Node.ELEMENT_NODE){let e=r;if(e.classList.contains(t)||e.classList.contains(n))return null;if(r.parentElement===this._listRoot)return e}r=r.parentElement}return null}_startDrag(e,r){this._listRoot=this._resolveListRoot(),this._restoreAfter=r.nextElementSibling,this._originListRoot=this._listRoot,this._originNextSibling=r.nextElementSibling,this._dropList=this,this._dropAtEnd=!1,this._dropRejected=!1,this._dragEl=r,this._pointerId=e.pointerId,this._startIndex=this._indexOfItem(r);let i=r.getBoundingClientRect();this._pointerStartX=e.clientX,this._pointerStartY=e.clientY;let a=document.createElement(`div`);a.className=t,a.style.minHeight=`${i.height}px`,a.style.minWidth=`${i.width}px`,a.setAttribute(`aria-hidden`,`true`),this._placeholder=a,this._listRoot.insertBefore(a,r),r.classList.add(n),r.style.position=`fixed`,r.style.left=`${i.left}px`,r.style.top=`${i.top}px`,r.style.width=`${i.width}px`,r.style.height=`${i.height}px`,r.style.margin=`0`,r.style.zIndex=`10000`,r.style.boxSizing=`border-box`,r.style.pointerEvents=`none`,r.style.touchAction=`none`,r.style.transform=`translate3d(0, 0, 0) scale(1.015)`,r.style.transformOrigin=`center center`,r.style.willChange=`transform`,r.setPointerCapture(e.pointerId);let o=this._collectOrderedKeys(),s={index:this._startIndex,keys:o};this.dispatchEvent(new CustomEvent(`mint-sortable-start`,{bubbles:!0,composed:!0,detail:s})),this.dispatchEvent(new CustomEvent(`sort-start`,{bubbles:!0,composed:!0,detail:s})),window.addEventListener(`pointermove`,this._boundPointerMove,{passive:!1}),window.addEventListener(`pointerup`,this._boundPointerUp),window.addEventListener(`pointercancel`,this._boundPointerCancel)}_indexOfItem(e){let n=0;for(let r=0;r<this._listRoot.children.length;r++){let i=this._listRoot.children[r];if(i.nodeType!==Node.ELEMENT_NODE)continue;let a=i;if(!a.classList.contains(t)){if(a===e)return n;n++}}return-1}_getLayoutChildren(){return Array.from(this._listRoot.children).filter(e=>e.nodeType===Node.ELEMENT_NODE&&!e.hasAttribute(`data-mint-sortable-status`))}_onPointerMove(e){if(e.pointerId!==this._pointerId||!this._dragEl||!this._placeholder)return;e.preventDefault();let t=e.clientX-this._pointerStartX,n=e.clientY-this._pointerStartY;this._dragEl.style.transform=`translate3d(${t}px, ${n}px, 0) scale(1.015)`,this.dispatchEvent(new CustomEvent(`mint-sortable-drag`,{bubbles:!0,composed:!0,detail:{item:this._dragEl,source:this,clientX:e.clientX,clientY:e.clientY}})),this._autoScroll(e),this._maybeMovePlaceholder(e)}_resolveDropList(t){let n=document.elementFromPoint(t.clientX,t.clientY),r=n?.closest(`[data-mint-sortable-drop-container]`);this._dropAtEnd=!!r?.hasAttribute(`data-mint-sortable-drop-end`);let i=r?.getAttribute(`data-mint-sortable-drop-container`),a=i?document.getElementById(i):null,o=a?.matches(`mint-sortable`)?a:n?.closest(`mint-sortable`),s=o instanceof e?o:this,c=this.getAttribute(`group`)?.trim(),l=!!(c&&s.getAttribute(`group`)?.trim()===c),u=!!(this._dragEl&&(s===this._dragEl||this._dragEl.contains(s))),d=s===this||l&&s.isConnected&&!u,f=new CustomEvent(`mint-sortable-drag-over`,{bubbles:!0,composed:!0,cancelable:!0,detail:{item:this._dragEl,source:this,target:s,clientX:t.clientX,clientY:t.clientY}});return this.dispatchEvent(f),this._dropRejected=!d||f.defaultPrevented,this._dropRejected?this:s}_autoScroll(e){let t=this;for(;t&&t!==document.body;){let e=getComputedStyle(t);if(/(auto|scroll)/.test(`${e.overflowY} ${e.overflow}`)&&t.scrollHeight>t.clientHeight||t.style.maxHeight)break;t=t.parentElement}if(!t||t===document.body)return;let n=this._getScrollSensitivity(),r=this._getScrollSpeed(),i=t.getBoundingClientRect();this._scrollRaf!==null&&cancelAnimationFrame(this._scrollRaf),this._scrollRaf=requestAnimationFrame(()=>{this._scrollRaf=null;let a=0;e.clientY<i.top+n?a=-r:e.clientY>i.bottom-n&&(a=r),a!==0&&(t.scrollTop+=a,this._maybeMovePlaceholder(e))})}_maybeMovePlaceholder(e){let t=this._placeholder,n=this._dragEl;if(!t||!n)return;let r=this._resolveDropList(e),i=r._resolveListRoot();if(i===n||n.contains(i))return;t.parentElement!==i&&r._flipAnimate(()=>i.appendChild(t)),this._dropList=r;let a=r.getDirection()===`horizontal`,o=a?e.clientX:e.clientY,s=this.hasAttribute(`data-mint-sortable-full-crossing`);if(this._dropAtEnd&&r!==this){(t.parentElement!==i||i.lastElementChild!==t)&&r._flipAnimate(()=>i.appendChild(t));return}let c=Array.from(i.children).filter(e=>e.nodeType===Node.ELEMENT_NODE&&e!==n&&e!==t),l=null;for(let e of c){let n=e.getBoundingClientRect(),r=a?n.left:n.top,c=a?n.left+n.width:n.top+n.height;if(s){if(o<r){l=e;break}if(o<=c&&Array.prototype.indexOf.call(i.children,t)<Array.prototype.indexOf.call(i.children,e)){l=e;break}}else if(o<(a?n.left+n.width/2:n.top+n.height/2)){l=e;break}}let u=Array.from(i.children).filter(e=>e.nodeType===Node.ELEMENT_NODE&&e!==n),d=u.length>0&&u[u.length-1]===t;(l?!(t.nextSibling===l&&t.parentNode===i):!d)&&r._flipAnimate(()=>{l?i.insertBefore(t,l):i.appendChild(t)})}_flipAnimate(e){let t=this._dragEl,n=this._getAnimationDurationMs(),r=this._getLayoutChildren().filter(e=>e!==t),i=new Map;if(r.forEach(e=>{let t=this._flipCleanupTimers.get(e);t!==void 0&&(window.clearTimeout(t),this._flipCleanupTimers.delete(e)),i.set(e,e.getBoundingClientRect()),e.style.transition=`none`,e.style.transform=``}),r.length&&r[0].offsetHeight,e(),n<=0||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches){r.forEach(e=>{e.style.transition=``,e.style.transform=``});return}r.forEach(e=>{let t=i.get(e);if(!t)return;let r=e.getBoundingClientRect(),a=t.left-r.left,o=t.top-r.top;Math.abs(a)<.5&&Math.abs(o)<.5||(e.style.transition=`none`,e.style.transform=`translate(${a}px, ${o}px)`,requestAnimationFrame(()=>{e.style.transition=`transform ${n}ms cubic-bezier(0.22, 1, 0.36, 1)`,e.style.transform=``;let t=()=>{e.removeEventListener(`transitionend`,t),e.style.transition=``,e.style.transform=``,this._flipCleanupTimers.delete(e)};e.addEventListener(`transitionend`,t,{once:!0}),this._flipCleanupTimers.set(e,window.setTimeout(t,n+40))}))})}_onPointerUp(e){e.pointerId===this._pointerId&&(this._maybeMovePlaceholder(e),this._finishDrag(!1))}_onPointerCancel(e){e.pointerId===this._pointerId&&this._finishDrag(!0)}_finishDrag(e){let t=this._dragEl,r=this._placeholder;if(!t||this._pointerId===null){this._teardownDrag();return}try{t.releasePointerCapture(this._pointerId)}catch{}window.removeEventListener(`pointermove`,this._boundPointerMove),window.removeEventListener(`pointerup`,this._boundPointerUp),window.removeEventListener(`pointercancel`,this._boundPointerCancel);let i=this._dropList??this,a=i._resolveListRoot();!e&&!this._dropRejected&&this._dropAtEnd&&i!==this&&r?.parentNode===a&&a.appendChild(r);let o=this.getAttribute(`data-tree-parent-id`)||null,s=i.getAttribute(`data-tree-parent-id`)||null,c=this._indexOfItem(t),l=r?.parentNode===a?Array.from(a.children).filter(e=>e.nodeType===Node.ELEMENT_NODE&&e!==t&&!e.hasAttribute(`data-mint-sortable-status`)).indexOf(r):c,u=new CustomEvent(`mint-sortable-before-drop`,{bubbles:!0,composed:!0,cancelable:!0,detail:{item:t,source:this,target:i,oldIndex:c,newIndex:l,oldParentId:o,newParentId:s}});e||this.dispatchEvent(u);let d=e||this._dropRejected||u.defaultPrevented;if(d){let e=this._originListRoot??this._listRoot,n=this._originNextSibling??this._restoreAfter;n&&n.parentNode===e?e.insertBefore(t,n):e.appendChild(t)}else r?.parentNode&&r.parentNode.insertBefore(t,r);r?.remove(),this._placeholder=null,t.classList.remove(n),t.style.cssText=``;let f=d?c:i._indexOfItem(t);this._pointerId=null,this._dragEl=null,this._restoreAfter=null,this._originListRoot=null,this._originNextSibling=null,this._dropList=null,this._dropAtEnd=!1,this._dropRejected=!1;let p=this._collectOrderedKeys(),m=i._collectOrderedKeys(),h=!d&&(!d&&o!==s||f!==c),g=t.getAttribute(this._getItemKeyAttribute())||``,_={oldIndex:c,newIndex:f,cancelled:d,keys:p,sourceKeys:p,destinationKeys:m,oldParentId:o,newParentId:s,sourceContainerId:this.id||null,destinationContainerId:i.id||null,itemId:g};this.dispatchEvent(new CustomEvent(`mint-sortable-end`,{bubbles:!0,composed:!0,detail:_})),this.dispatchEvent(new CustomEvent(`sort-stop`,{bubbles:!0,composed:!0,detail:_})),h&&(this.dispatchEvent(new CustomEvent(`mint-sortable-change`,{bubbles:!0,composed:!0,detail:_})),this.dispatchEvent(new CustomEvent(`mint-sortable-order`,{bubbles:!0,composed:!0,detail:{keys:p,sourceKeys:p,destinationKeys:m,oldParentId:o,newParentId:s,itemId:g}})))}_teardownDrag(){if(this._scrollRaf!==null&&(cancelAnimationFrame(this._scrollRaf),this._scrollRaf=null),window.removeEventListener(`pointermove`,this._boundPointerMove),window.removeEventListener(`pointerup`,this._boundPointerUp),window.removeEventListener(`pointercancel`,this._boundPointerCancel),this._dragEl){try{this._pointerId!==null&&this._dragEl.releasePointerCapture(this._pointerId)}catch{}this._dragEl.classList.remove(n),this._dragEl.style.cssText=``}this._placeholder?.remove(),this._placeholder=null,this._dragEl=null,this._pointerId=null,this._restoreAfter=null,this._originListRoot=null,this._originNextSibling=null,this._dropList=null,this._dropRejected=!1}};customElements.get(`mint-sortable`)||e.t(`mint-sortable`,r),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return r}});
|
|
@@ -18,5 +18,5 @@ __mintLoadStyle('icon', '../../icon.css')
|
|
|
18
18
|
__mintLoadStyle('text', '../../text.css')
|
|
19
19
|
__mintLoadStyle('stack', '../../stack.css')
|
|
20
20
|
__mintLoadStyle('confirm-action', '../../confirm-action.css')
|
|
21
|
-
import { n as e, t } from "../chunks/confirm-action-
|
|
21
|
+
import { n as e, t } from "../chunks/confirm-action-D4U-R6zW.js";
|
|
22
22
|
export { t as confirm, e as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`../chunks/confirm-action-
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`../chunks/confirm-action-DxvkO8OY.js`);exports.confirm=e.t,exports.default=e.n;
|
|
@@ -6,5 +6,5 @@ import '../../icon.css'
|
|
|
6
6
|
import '../../text.css'
|
|
7
7
|
import '../../stack.css'
|
|
8
8
|
import '../../confirm-action.css'
|
|
9
|
-
import { n as e, t } from "../chunks/confirm-action-
|
|
9
|
+
import { n as e, t } from "../chunks/confirm-action-D4U-R6zW.js";
|
|
10
10
|
export { t as confirm, e as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/icon/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAA;AAErB,OAAO,QAAQ,CAAA;AAEf,OAAO,eAAe,CAAA;AAGtB,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/icon/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAA;AAErB,OAAO,QAAQ,CAAA;AAEf,OAAO,eAAe,CAAA;AAGtB,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -17,5 +17,5 @@ __mintLoadStyle('icon', '../../icon.css')
|
|
|
17
17
|
__mintLoadStyle('text', '../../text.css')
|
|
18
18
|
__mintLoadStyle('stack', '../../stack.css')
|
|
19
19
|
__mintLoadStyle('modal', '../../modal.css')
|
|
20
|
-
import { t as e } from "../chunks/modal-
|
|
20
|
+
import { t as e } from "../chunks/modal-DVbvAPLU.js";
|
|
21
21
|
export { e as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../chunks/modal-
|
|
1
|
+
const e=require(`../chunks/modal-DaAORJq2.js`);module.exports=e.t;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sortable.d.ts","sourceRoot":"","sources":["../../../src/components/sortable/Sortable.ts"],"names":[],"mappings":"AAIA,KAAK,cAAc,GAAG,YAAY,GAAG,UAAU,CAAA;AAC/C,KAAK,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAA;AACxD,KAAK,iBAAiB,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAA;AAKpD,cAAM,YAAa,SAAQ,WAAW;IACpC,MAAM,KAAK,kBAAkB,IAAI,MAAM,EAAE,CAexC;IAED,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,YAAY,CAA2B;IAC/C,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,WAAW,CAAI;IACvB,OAAO,CAAC,cAAc,CAAI;IAC1B,OAAO,CAAC,cAAc,CAAI;IAC1B,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,iBAAiB,CAA2B;IACpD,OAAO,CAAC,eAAe,CAA2B;IAClD,OAAO,CAAC,mBAAmB,CAA2B;IACtD,OAAO,CAAC,cAAc,CAAgC;IACtD,OAAO,CAAC,iBAAiB,CAA2B;IACpD,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,eAAe,CAA2B;IAClD,OAAO,CAAC,kBAAkB,CAAuB;IACjD,OAAO,CAAC,SAAS,CAA4B;IAC7C,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,aAAa,CAAQ;IAC7B,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,kBAAkB,CAAqC;IAC/D,OAAO,CAAC,uBAAuB,CAAiE;;IAShG,iBAAiB,IAAI,IAAI;IAQzB,oBAAoB,IAAI,IAAI;IAU5B,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAM/F,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,oBAAoB;IAO5B,OAAO,CAAC,cAAc;IAUtB,OAAO,CAAC,gBAAgB;IAIxB,wFAAwF;IACxF,OAAO,CAAC,oBAAoB;IAI5B,6EAA6E;IAC7E,OAAO,CAAC,mBAAmB;IAc3B,OAAO,CAAC,yBAAyB;IAejC,OAAO,CAAC,yBAAyB;IAwCjC,OAAO,CAAC,0BAA0B;IAqBlC,OAAO,CAAC,kBAAkB;IAqC1B,YAAY,IAAI,cAAc;IAK9B,MAAM,IAAI,MAAM;IAMhB,YAAY,IAAI,SAAS,GAAG,EAAE;IAM9B,eAAe,IAAI,iBAAiB,GAAG,EAAE;IAQzC,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,kBAAkB;IAK1B,OAAO,CAAC,qBAAqB;IAK7B,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,uBAAuB;IAK/B,OAAO,CAAC,yBAAyB;IAWjC,OAAO,CAAC,kBAAkB,CAuBzB;IAED,OAAO,CAAC,oBAAoB;IAkB5B,OAAO,CAAC,UAAU;IA8DlB,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,cAAc;IAqBtB,OAAO,CAAC,gBAAgB;
|
|
1
|
+
{"version":3,"file":"Sortable.d.ts","sourceRoot":"","sources":["../../../src/components/sortable/Sortable.ts"],"names":[],"mappings":"AAIA,KAAK,cAAc,GAAG,YAAY,GAAG,UAAU,CAAA;AAC/C,KAAK,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAA;AACxD,KAAK,iBAAiB,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAA;AAKpD,cAAM,YAAa,SAAQ,WAAW;IACpC,MAAM,KAAK,kBAAkB,IAAI,MAAM,EAAE,CAexC;IAED,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,YAAY,CAA2B;IAC/C,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,WAAW,CAAI;IACvB,OAAO,CAAC,cAAc,CAAI;IAC1B,OAAO,CAAC,cAAc,CAAI;IAC1B,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,iBAAiB,CAA2B;IACpD,OAAO,CAAC,eAAe,CAA2B;IAClD,OAAO,CAAC,mBAAmB,CAA2B;IACtD,OAAO,CAAC,cAAc,CAAgC;IACtD,OAAO,CAAC,iBAAiB,CAA2B;IACpD,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,eAAe,CAA2B;IAClD,OAAO,CAAC,kBAAkB,CAAuB;IACjD,OAAO,CAAC,SAAS,CAA4B;IAC7C,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,aAAa,CAAQ;IAC7B,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,kBAAkB,CAAqC;IAC/D,OAAO,CAAC,uBAAuB,CAAiE;;IAShG,iBAAiB,IAAI,IAAI;IAQzB,oBAAoB,IAAI,IAAI;IAU5B,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAM/F,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,oBAAoB;IAO5B,OAAO,CAAC,cAAc;IAUtB,OAAO,CAAC,gBAAgB;IAIxB,wFAAwF;IACxF,OAAO,CAAC,oBAAoB;IAI5B,6EAA6E;IAC7E,OAAO,CAAC,mBAAmB;IAc3B,OAAO,CAAC,yBAAyB;IAejC,OAAO,CAAC,yBAAyB;IAwCjC,OAAO,CAAC,0BAA0B;IAqBlC,OAAO,CAAC,kBAAkB;IAqC1B,YAAY,IAAI,cAAc;IAK9B,MAAM,IAAI,MAAM;IAMhB,YAAY,IAAI,SAAS,GAAG,EAAE;IAM9B,eAAe,IAAI,iBAAiB,GAAG,EAAE;IAQzC,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,kBAAkB;IAK1B,OAAO,CAAC,qBAAqB;IAK7B,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,uBAAuB;IAK/B,OAAO,CAAC,yBAAyB;IAWjC,OAAO,CAAC,kBAAkB,CAuBzB;IAED,OAAO,CAAC,oBAAoB;IAkB5B,OAAO,CAAC,UAAU;IA8DlB,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,cAAc;IAqBtB,OAAO,CAAC,gBAAgB;IA0BxB,OAAO,CAAC,WAAW;IA4BnB,OAAO,CAAC,qBAAqB;IA6E7B,OAAO,CAAC,YAAY;IAsDpB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,gBAAgB;IAKxB,OAAO,CAAC,WAAW;IA6HnB,OAAO,CAAC,aAAa;CA4BtB;AAMD,eAAe,YAAY,CAAA"}
|
|
@@ -12,5 +12,5 @@ const __mintLoadStyle = (key, url) => {
|
|
|
12
12
|
}
|
|
13
13
|
__mintLoadStyle('theme', '../../theme.css')
|
|
14
14
|
__mintLoadStyle('sortable', '../../sortable.css')
|
|
15
|
-
import { t as e } from "../chunks/sortable-
|
|
15
|
+
import { t as e } from "../chunks/sortable-CparUKN_.js";
|
|
16
16
|
export { e as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../chunks/sortable-
|
|
1
|
+
const e=require(`../chunks/sortable-DX2PwFLN.js`);module.exports=e.t;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tree.d.ts","sourceRoot":"","sources":["../../../src/components/tree/Tree.ts"],"names":[],"mappings":"AACA,OAAO,iBAAiB,CAAA;AACxB,OAAO,eAAe,CAAA;AACtB,OAAO,0BAA0B,CAAA;AACjC,OAAO,wBAAwB,CAAA;AAC/B,OAAO,wBAAwB,CAAA;AAC/B,OAAO,0BAA0B,CAAA;AACjC,OAAO,yBAAyB,CAAA;AAChC,OAAO,oBAAoB,CAAA;AAC3B,OAAO,oBAAoB,CAAA;AAC3B,OAAO,sBAAsB,CAAA;AAC7B,OAAO,qBAAqB,CAAA;AAC5B,OAAO,sBAAsB,CAAA;AAC7B,OAAO,qBAAqB,CAAA;AAC5B,OAAO,oBAAoB,CAAA;AAC3B,OAAO,4BAA4B,CAAA;AACnC,OAAO,kBAAkB,CAAA;AACzB,OAAO,mBAAmB,CAAA;AAC1B,OAAO,kBAAkB,CAAA;AACzB,OAAO,yBAAyB,CAAA;AAEhC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAkD/C,qBAAa,QAAS,SAAQ,WAAW;IACvC,MAAM,KAAK,kBAAkB,IAAI,MAAM,EAAE,CAExC;IAED,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,WAAW,CAAsB;IACzC,OAAO,CAAC,YAAY,CAAoB;IACxC,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,QAAQ,CAAiK;IACjL,OAAO,CAAC,OAAO,CAAgC;IAC/C,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,cAAc,CAAmG;IACzH,OAAO,CAAC,gBAAgB,CAAoB;IAC5C,OAAO,CAAC,oBAAoB,CAAsB;IAClD,OAAO,CAAC,qBAAqB,CAAmE;IAEhG,iBAAiB,IAAI,IAAI;IAkBzB,oBAAoB,IAAI,IAAI;
|
|
1
|
+
{"version":3,"file":"Tree.d.ts","sourceRoot":"","sources":["../../../src/components/tree/Tree.ts"],"names":[],"mappings":"AACA,OAAO,iBAAiB,CAAA;AACxB,OAAO,eAAe,CAAA;AACtB,OAAO,0BAA0B,CAAA;AACjC,OAAO,wBAAwB,CAAA;AAC/B,OAAO,wBAAwB,CAAA;AAC/B,OAAO,0BAA0B,CAAA;AACjC,OAAO,yBAAyB,CAAA;AAChC,OAAO,oBAAoB,CAAA;AAC3B,OAAO,oBAAoB,CAAA;AAC3B,OAAO,sBAAsB,CAAA;AAC7B,OAAO,qBAAqB,CAAA;AAC5B,OAAO,sBAAsB,CAAA;AAC7B,OAAO,qBAAqB,CAAA;AAC5B,OAAO,oBAAoB,CAAA;AAC3B,OAAO,4BAA4B,CAAA;AACnC,OAAO,kBAAkB,CAAA;AACzB,OAAO,mBAAmB,CAAA;AAC1B,OAAO,kBAAkB,CAAA;AACzB,OAAO,yBAAyB,CAAA;AAEhC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAkD/C,qBAAa,QAAS,SAAQ,WAAW;IACvC,MAAM,KAAK,kBAAkB,IAAI,MAAM,EAAE,CAExC;IAED,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,WAAW,CAAsB;IACzC,OAAO,CAAC,YAAY,CAAoB;IACxC,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,QAAQ,CAAiK;IACjL,OAAO,CAAC,OAAO,CAAgC;IAC/C,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,cAAc,CAAmG;IACzH,OAAO,CAAC,gBAAgB,CAAoB;IAC5C,OAAO,CAAC,oBAAoB,CAAsB;IAClD,OAAO,CAAC,qBAAqB,CAAmE;IAEhG,iBAAiB,IAAI,IAAI;IAkBzB,oBAAoB,IAAI,IAAI;IAmB5B,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAW9F,IAAI,KAAK,IAAI,QAAQ,EAAE,CAAkC;IACzD,IAAI,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,EAI1B;IAED,IAAI,UAAU,IAAI,MAAM,GAAG,IAAI,CAA4B;IAC3D,IAAI,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,EAI3C;IAED,IAAI,WAAW,IAAI,MAAM,EAAE,CAAkC;IAC7D,IAAI,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EAG9B;IAED,yEAAyE;IACzE,IAAI,IAAI,IAAI;IAIZ,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIjC,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IACjC,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAEnC,OAAO,CAAC,gBAAgB;IAUxB,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,SAAS;IAKjB,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,UAAU;IAElB,OAAO,CAAC,OAAO;IA8Ef,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,aAAa;IASrB,OAAO,CAAC,WAAW;IAqBnB,OAAO,CAAC,WAAW;IAoGnB,OAAO,CAAC,cAAc;IAsEtB,OAAO,CAAC,QAAQ,CA4Cf;IAED,OAAO,CAAC,iBAAiB;YAKX,cAAc;IAY5B,OAAO,CAAC,cAAc;IA8BtB,OAAO,CAAC,UAAU;IAoBlB,OAAO,CAAC,OAAO;IASf,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,iBAAiB;IAazB,OAAO,CAAC,eAAe,CAgDtB;IAED,OAAO,CAAC,gBAAgB,CA4BvB;IAED,OAAO,CAAC,cAAc,CAqCrB;IAED,OAAO,CAAC,qBAAqB;IAY7B,OAAO,CAAC,YAAY;IAepB,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,QAAQ;IAKhB,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,mBAAmB,CAuB1B;IAED,OAAO,CAAC,qBAAqB,CAO5B;IAED,OAAO,CAAC,iBAAiB;IAazB,OAAO,CAAC,iBAAiB,CAuCxB;IAED,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,2BAA2B;IAUnC,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,UAAU,CA0DjB;IAED,OAAO,CAAC,eAAe;IAcvB,OAAO,CAAC,gBAAgB;IAexB,OAAO,CAAC,SAAS;CAIlB;AAID,eAAe,QAAQ,CAAA"}
|
|
@@ -25,9 +25,9 @@ import "../chunks/icon-DZP-hLHj.js";
|
|
|
25
25
|
import { t as e } from "../chunks/register-element-BFYmIynH.js";
|
|
26
26
|
import "../chunks/spinner-BsaFHuS6.js";
|
|
27
27
|
import "../chunks/button-M7gi8RMZ.js";
|
|
28
|
-
import "../chunks/confirm-action-
|
|
28
|
+
import "../chunks/confirm-action-D4U-R6zW.js";
|
|
29
29
|
import "../chunks/popover-CV-QCPjW.js";
|
|
30
|
-
import "../chunks/sortable-
|
|
30
|
+
import "../chunks/sortable-CparUKN_.js";
|
|
31
31
|
//#region src/components/tree/tree-utils.js
|
|
32
32
|
function t(e = []) {
|
|
33
33
|
s(e);
|
|
@@ -225,7 +225,7 @@ var p = class extends HTMLElement {
|
|
|
225
225
|
}));
|
|
226
226
|
}
|
|
227
227
|
}, this._onSortableStart = () => {
|
|
228
|
-
this._dragHoverExpandedId = null, this._dragExpansion?.timer !== null && this._dragExpansion?.timer !== void 0 && window.clearTimeout(this._dragExpansion.timer), this._dragExpansion = null;
|
|
228
|
+
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;
|
|
229
229
|
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");
|
|
230
230
|
if (!e || !t || !n || n.hidden || !this._expandedIds.has(t)) return;
|
|
231
231
|
let r = e.querySelector(":scope > .mint-tree-row"), i = this._root?.querySelector(".mint-sortable-placeholder"), a = n.getBoundingClientRect().height;
|
|
@@ -238,6 +238,7 @@ var p = class extends HTMLElement {
|
|
|
238
238
|
this._dragExpansion?.childList === n && (n.classList.add("mint-tree-drag-collapse"), n.style.height = "0px", i && r && (i.style.minHeight = `${r.getBoundingClientRect().height}px`));
|
|
239
239
|
});
|
|
240
240
|
}, this._onSortableEnd = (e) => {
|
|
241
|
+
this.classList.remove("mint-tree-drag-active");
|
|
241
242
|
let t = e.detail, r = t && !t.cancelled ? f(t.newParentId) : null;
|
|
242
243
|
for (let e of this._autoExpandedIds) {
|
|
243
244
|
if (e === r) continue;
|
|
@@ -362,7 +363,7 @@ var p = class extends HTMLElement {
|
|
|
362
363
|
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());
|
|
363
364
|
}
|
|
364
365
|
disconnectedCallback() {
|
|
365
|
-
this._dragExpansion?.timer !== null && this._dragExpansion?.timer !== void 0 && window.clearTimeout(this._dragExpansion.timer), this._keyboardFocusRestore && window.clearTimeout(this._keyboardFocusRestore.timer), this._keyboardFocusRestore = null, this._dragExpansion = null, this._autoExpandedIds.clear(), this._dragHoverExpandedId = null, 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;
|
|
366
|
+
this._dragExpansion?.timer !== null && this._dragExpansion?.timer !== void 0 && window.clearTimeout(this._dragExpansion.timer), this._keyboardFocusRestore && window.clearTimeout(this._keyboardFocusRestore.timer), 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;
|
|
366
367
|
}
|
|
367
368
|
attributeChangedCallback(e, t, n) {
|
|
368
369
|
if (!(t === n || !this.isConnected)) {
|
|
@@ -478,7 +479,7 @@ var p = class extends HTMLElement {
|
|
|
478
479
|
}
|
|
479
480
|
_createList(e, t, n) {
|
|
480
481
|
let r = document.createElement("mint-sortable");
|
|
481
|
-
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")
|
|
482
|
+
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");
|
|
482
483
|
let i = document.createElement("mint-stack");
|
|
483
484
|
i.setAttribute("direction", "vertical"), i.setAttribute("gap", "1");
|
|
484
485
|
for (let t of e) i.appendChild(this._createNode(t, n));
|
|
@@ -488,7 +489,7 @@ var p = class extends HTMLElement {
|
|
|
488
489
|
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");
|
|
489
490
|
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", "");
|
|
490
491
|
let s = document.createElement("div");
|
|
491
|
-
s.className = "mint-tree-row", s.setAttribute("data-tree-id", n)
|
|
492
|
+
s.className = "mint-tree-row", s.setAttribute("data-tree-id", n);
|
|
492
493
|
let c = document.createElement("span");
|
|
493
494
|
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`);
|
|
494
495
|
let l = document.createElement("mint-icon");
|
|
@@ -500,7 +501,7 @@ var p = class extends HTMLElement {
|
|
|
500
501
|
e.className = "mint-tree-expand-spacer", e.setAttribute("aria-hidden", "true"), s.appendChild(e);
|
|
501
502
|
}
|
|
502
503
|
let u = document.createElement("span");
|
|
503
|
-
if (u.className = "mint-tree-label", u.setAttribute("data-tree-command", "select"), u.setAttribute("data-tree-id", n), e.icon) {
|
|
504
|
+
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) {
|
|
504
505
|
let t = document.createElement("mint-icon");
|
|
505
506
|
t.setAttribute("name", String(e.icon)), t.setAttribute("aria-hidden", "true"), u.appendChild(t);
|
|
506
507
|
}
|
|
@@ -510,7 +511,7 @@ var p = class extends HTMLElement {
|
|
|
510
511
|
t.className = "mint-tree-metadata", t.textContent = String(e.metadata), s.appendChild(t);
|
|
511
512
|
}
|
|
512
513
|
let f = document.createElement("span");
|
|
513
|
-
f.className = "mint-tree-nest-target", f.setAttribute("data-mint-sortable-drop-container", `${this._treeId}-list-${n}`), f.setAttribute("aria-hidden", "true");
|
|
514
|
+
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");
|
|
514
515
|
let p = document.createElement("mint-icon");
|
|
515
516
|
p.setAttribute("name", "arrow-right"), p.setAttribute("aria-hidden", "true"), f.appendChild(p), i && s.appendChild(f);
|
|
516
517
|
let m = this._createActions(e, i);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}}),require(`../chunks/icon-lfkgHbsk.js`);const e=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/spinner-DbTohC6i.js`),require(`../chunks/button-DGuqIeFS.js`),require(`../chunks/confirm-action-B7vFRCIg.js`),require(`../chunks/popover-Db9ZGHd9.js`),require(`../chunks/sortable-DCa1G1-x.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._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._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===`toggle`&&i){let e=!this._expandedIds.has(i);this._setExpanded(i,e,!0)}else if(r===`select`&&i)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._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=>{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._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._keyboardFocusRestore=null,this._dragExpansion=null,this._autoExpandedIds.clear(),this._dragHoverExpandedId=null,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.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(`Expand all`,`ghost`,`expand-all`),s=this._createButton(`Collapse all`,`ghost`,`collapse-all`);if(a.append(o,s),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 c=document.createElement(`mint-confirm-action`);c.className=`mint-tree-confirm`,this._confirm=c,n.appendChild(c),this.replaceChildren(n),this._root=n,this.classList.add(`mint-tree`),this._disabled()?this.setAttribute(`aria-disabled`,`true`):this.removeAttribute(`aria-disabled`);let l=this._keyboardFocusRestore;l&&(this._focusRow(l.id),window.scrollTo({left:l.x,top:l.y,behavior:`instant`}),requestAnimationFrame(()=>{this._keyboardFocusRestore===l&&(this._focusRow(l.id),window.scrollTo({left:l.x,top:l.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`),r.setAttribute(`data-mint-sortable-full-crossing`,``);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),s.setAttribute(`data-mint-sortable-drop-container`,`${this._treeId}-list-${n}`),s.setAttribute(`data-mint-sortable-drop-center`,``);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),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(`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._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){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)}_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._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._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-lfkgHbsk.js`);const e=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/spinner-DbTohC6i.js`),require(`../chunks/button-DGuqIeFS.js`),require(`../chunks/confirm-action-DxvkO8OY.js`),require(`../chunks/popover-Db9ZGHd9.js`),require(`../chunks/sortable-DX2PwFLN.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._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._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===`toggle`&&i){let e=!this._expandedIds.has(i);this._setExpanded(i,e,!0)}else if(r===`select`&&i)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`);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._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._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.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(`Expand all`,`ghost`,`expand-all`),s=this._createButton(`Collapse all`,`ghost`,`collapse-all`);if(a.append(o,s),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 c=document.createElement(`mint-confirm-action`);c.className=`mint-tree-confirm`,this._confirm=c,n.appendChild(c),this.replaceChildren(n),this._root=n,this.classList.add(`mint-tree`),this._disabled()?this.setAttribute(`aria-disabled`,`true`):this.removeAttribute(`aria-disabled`);let l=this._keyboardFocusRestore;l&&(this._focusRow(l.id),window.scrollTo({left:l.x,top:l.y,behavior:`instant`}),requestAnimationFrame(()=>{this._keyboardFocusRestore===l&&(this._focusRow(l.id),window.scrollTo({left:l.x,top:l.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._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){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)}_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._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._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;
|