monobill-mintui 0.6.730 → 0.6.732

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.
@@ -18,7 +18,7 @@ var t = "mint-sortable-placeholder", n = "mint-sortable-dragging", r = class e e
18
18
  ];
19
19
  }
20
20
  constructor() {
21
- 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 = /* @__PURE__ */ new WeakMap(), this._lastPreviewRoot = null, this._lastPreviewIndex = -1, this._keyboardKeydownHandler = (e) => this._onKeyboardReorder(e), this._onListPointerDown = (e) => {
21
+ super(), this._pointerId = null, this._dragEl = null, this._dragOriginalStyle = "", this._placeholder = null, this._listRoot = this, this._startIndex = 0, this._pointerStartX = 0, this._pointerStartY = 0, this._pendingPointerEvent = null, this._moveRaf = null, this._gridSlots = [], this._scrollRaf = null, this._previewResizeRaf = 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 = /* @__PURE__ */ new WeakMap(), this._lastPreviewRoot = null, this._lastPreviewIndex = -1, this._keyboardKeydownHandler = (e) => this._onKeyboardReorder(e), this._onListPointerDown = (e) => {
22
22
  let t = e;
23
23
  if (this._isDisabled() || this._pointerId !== null || t.button !== 0) return;
24
24
  let n = t.target;
@@ -134,7 +134,8 @@ var t = "mint-sortable-placeholder", n = "mint-sortable-dragging", r = class e e
134
134
  }));
135
135
  }
136
136
  getDirection() {
137
- return (this.getAttribute("direction") || "vertical") === "horizontal" ? "horizontal" : "vertical";
137
+ let e = this.getAttribute("direction") || "vertical";
138
+ return e === "horizontal" || e === "grid" ? e : "vertical";
138
139
  }
139
140
  getGap() {
140
141
  let e = this.getAttribute("gap") || "3", t = parseFloat(e);
@@ -189,11 +190,20 @@ var t = "mint-sortable-placeholder", n = "mint-sortable-dragging", r = class e e
189
190
  return null;
190
191
  }
191
192
  _startDrag(e, r) {
192
- 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);
193
+ 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._dragOriginalStyle = r.style.cssText, this._pointerId = e.pointerId, this._startIndex = this._indexOfItem(r), this._gridSlots = this.getDirection() === "grid" ? Array.from(this._listRoot.children).filter((e) => e.nodeType === Node.ELEMENT_NODE && !e.hasAttribute("data-mint-sortable-status")).map((e, t) => ({
194
+ element: e,
195
+ rect: e.getBoundingClientRect(),
196
+ index: t
197
+ })) : [];
193
198
  let i = r.getBoundingClientRect();
194
199
  this._pointerStartX = e.clientX, this._pointerStartY = e.clientY;
195
200
  let a = document.createElement("div");
196
- 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);
201
+ if (a.className = t, this.getDirection() !== "grid") a.style.minHeight = `${i.height}px`, a.style.minWidth = `${i.width}px`;
202
+ else {
203
+ let e = window.getComputedStyle(r);
204
+ e.gridArea === "auto" ? (a.style.gridColumn = e.gridColumn, a.style.gridRow = e.gridRow) : a.style.gridArea = e.gridArea, a.style.alignSelf = e.alignSelf, a.style.justifySelf = e.justifySelf;
205
+ }
206
+ a.setAttribute("aria-hidden", "true"), this._placeholder = a, this._listRoot.insertBefore(a, r), r.classList.add(n), r.style.position = "fixed", r.style.left = `${e.clientX}px`, r.style.top = `${e.clientY}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) translate(-50%, -50%) scale(1.015)", r.style.transformOrigin = "center center", r.style.willChange = "transform", r.setPointerCapture(e.pointerId);
197
207
  let o = this._collectOrderedKeys(), s = {
198
208
  index: this._startIndex,
199
209
  itemId: r.getAttribute(this._getItemKeyAttribute()) || "",
@@ -227,10 +237,16 @@ var t = "mint-sortable-placeholder", n = "mint-sortable-dragging", r = class e e
227
237
  return Array.from(this._listRoot.children).filter((e) => e.nodeType === Node.ELEMENT_NODE && !e.hasAttribute("data-mint-sortable-status"));
228
238
  }
229
239
  _onPointerMove(e) {
230
- if (e.pointerId !== this._pointerId || !this._dragEl || !this._placeholder) return;
231
- e.preventDefault();
240
+ e.pointerId !== this._pointerId || !this._dragEl || !this._placeholder || (e.preventDefault(), this._pendingPointerEvent = e, this._moveRaf === null && (this._moveRaf = requestAnimationFrame(() => {
241
+ this._moveRaf = null;
242
+ let e = this._pendingPointerEvent;
243
+ this._pendingPointerEvent = null, e && e.pointerId === this._pointerId && this._processPointerMove(e);
244
+ })));
245
+ }
246
+ _processPointerMove(e) {
247
+ if (!this._dragEl || !this._placeholder) return;
232
248
  let t = e.clientX - this._pointerStartX, n = e.clientY - this._pointerStartY;
233
- this._dragEl.style.transform = `translate3d(${t}px, ${n}px, 0) scale(1.015)`, this.dispatchEvent(new CustomEvent("mint-sortable-drag", {
249
+ this._dragEl.style.transform = `translate3d(${t}px, ${n}px, 0) translate(-50%, -50%) scale(1.015)`, this.dispatchEvent(new CustomEvent("mint-sortable-drag", {
234
250
  bubbles: !0,
235
251
  composed: !0,
236
252
  detail: {
@@ -278,33 +294,66 @@ var t = "mint-sortable-placeholder", n = "mint-sortable-dragging", r = class e e
278
294
  if (!t || !n) return;
279
295
  let r = this._resolveDropList(e), i = r._resolveListRoot();
280
296
  if (i === n || n.contains(i)) return;
281
- t.parentElement !== i && r._flipAnimate(() => i.appendChild(t)), this._dropList = r;
282
- let a = r.getDirection() === "horizontal", o = a ? e.clientX : e.clientY, s = this.hasAttribute("data-mint-sortable-full-crossing");
297
+ let a = t.parentElement !== i;
298
+ a && r._flipAnimate(() => i.appendChild(t)), this._dropList = r;
299
+ let o = r.getDirection();
300
+ if (o === "grid") {
301
+ this._moveGridPlaceholder(r, i, t, n, e);
302
+ return;
303
+ }
304
+ let s = o === "horizontal", c = s ? e.clientX : e.clientY, l = this.hasAttribute("data-mint-sortable-full-crossing");
283
305
  if (this._dropAtEnd && r !== this) {
284
306
  (t.parentElement !== i || i.lastElementChild !== t) && r._flipAnimate(() => i.appendChild(t)), this._dispatchPreview(r, i, t, n);
285
307
  return;
286
308
  }
287
- let c = Array.from(i.children).filter((e) => e.nodeType === Node.ELEMENT_NODE && e !== n && e !== t), l = null;
288
- for (let e of c) {
289
- let n = e.getBoundingClientRect(), r = a ? n.left : n.top, c = a ? n.left + n.width : n.top + n.height;
290
- if (s) {
291
- if (o < r) {
292
- l = e;
309
+ let u = Array.from(i.children).filter((e) => e.nodeType === Node.ELEMENT_NODE && e !== n && e !== t), d = null;
310
+ for (let e of u) {
311
+ let n = e.getBoundingClientRect(), r = s ? n.left : n.top, a = s ? n.left + n.width : n.top + n.height;
312
+ if (l) {
313
+ if (c < r) {
314
+ d = e;
293
315
  break;
294
316
  }
295
- if (o <= c && Array.prototype.indexOf.call(i.children, t) < Array.prototype.indexOf.call(i.children, e)) {
296
- l = e;
317
+ if (c <= a && Array.prototype.indexOf.call(i.children, t) < Array.prototype.indexOf.call(i.children, e)) {
318
+ d = e;
297
319
  break;
298
320
  }
299
- } else if (o < (a ? n.left + n.width / 2 : n.top + n.height / 2)) {
300
- l = e;
321
+ } else if (c < (s ? n.left + n.width / 2 : n.top + n.height / 2)) {
322
+ d = e;
301
323
  break;
302
324
  }
303
325
  }
304
- let u = Array.from(i.children).filter((e) => e.nodeType === Node.ELEMENT_NODE && e !== n), d = u.length > 0 && u[u.length - 1] === t;
305
- (l ? !(t.nextSibling === l && t.parentNode === i) : !d) && (r._flipAnimate(() => {
306
- l ? i.insertBefore(t, l) : i.appendChild(t);
307
- }), this._dispatchPreview(r, i, t, n));
326
+ let f = Array.from(i.children).filter((e) => e.nodeType === Node.ELEMENT_NODE && e !== n), p = f.length > 0 && f[f.length - 1] === t;
327
+ if (!(d ? !(t.nextSibling === d && t.parentNode === i) : !p)) {
328
+ a && this._dispatchPreview(r, i, t, n);
329
+ return;
330
+ }
331
+ r._flipAnimate(() => {
332
+ d ? i.insertBefore(t, d) : i.appendChild(t);
333
+ }), this._dispatchPreview(r, i, t, n);
334
+ }
335
+ _moveGridPlaceholder(e, t, n, r, i) {
336
+ let a = Array.from(t.children).filter((e) => e.nodeType === Node.ELEMENT_NODE && e !== r && e !== n && !e.hasAttribute("data-mint-sortable-status")), o = t === this._originListRoot ? this._gridSlots.filter((e) => e.element === r || e.element.parentElement === t) : a.map((e, t) => ({
337
+ element: e,
338
+ rect: e.getBoundingClientRect(),
339
+ index: t
340
+ })), s = null, c = Infinity, l = !1;
341
+ for (let e of o) {
342
+ let { rect: t } = e, n = i.clientX >= t.left && i.clientX <= t.right && i.clientY >= t.top && i.clientY <= t.bottom, r = i.clientX - (t.left + t.width / 2), a = i.clientY - (t.top + t.height / 2), o = n ? -1 : r * r + a * a;
343
+ o < c && (s = e, c = o, l = n);
344
+ }
345
+ let u = null;
346
+ if (s) {
347
+ let { rect: e } = s, n = (i.clientX - (e.left + e.width / 2)) / Math.max(e.width, 1), o = (i.clientY - (e.top + e.height / 2)) / Math.max(e.height, 1), c = s.index === 0 && l ? !0 : Math.abs(n) >= Math.abs(o) ? n <= 0 : o <= 0, d = s.index + (c ? 0 : 1);
348
+ t === this._originListRoot && s.element !== r && s.index >= this._startIndex && d--, s.element === r && (d = this._startIndex), d = Math.max(0, Math.min(a.length, d)), u = a[d] ?? null;
349
+ }
350
+ if (!(u ? !(n.nextSibling === u && n.parentNode === t) : !(t.lastElementChild === n && n.parentNode === t))) {
351
+ this._dispatchPreview(e, t, n, r);
352
+ return;
353
+ }
354
+ e._flipAnimate(() => {
355
+ u ? t.insertBefore(n, u) : t.appendChild(n), this._dispatchPreview(e, t, n, r);
356
+ });
308
357
  }
309
358
  _dispatchPreview(e, t, n, r) {
310
359
  let i = Array.from(t.children).filter((e) => e.nodeType === Node.ELEMENT_NODE && e !== r && !e.hasAttribute("data-mint-sortable-status")), a = i.indexOf(n);
@@ -322,34 +371,41 @@ var t = "mint-sortable-placeholder", n = "mint-sortable-dragging", r = class e e
322
371
  bubbles: !0,
323
372
  composed: !0,
324
373
  detail: c
325
- }));
374
+ })), this._resizeDragToPlaceholder(r, n);
375
+ }
376
+ _resizeDragToPlaceholder(e, t) {
377
+ this._previewResizeRaf !== null && cancelAnimationFrame(this._previewResizeRaf), this._previewResizeRaf = requestAnimationFrame(() => {
378
+ if (this._previewResizeRaf = null, this._dragEl !== e || this._placeholder !== t || !t.isConnected) return;
379
+ let n = t.offsetWidth, r = t.offsetHeight;
380
+ !n || !r || (e.style.transition = "width 160ms ease, height 160ms ease", e.style.width = `${n}px`, e.style.height = `${r}px`, e.style.transformOrigin = "center center");
381
+ });
326
382
  }
327
383
  _flipAnimate(e) {
328
384
  let t = this._dragEl, n = this._getAnimationDurationMs(), r = this._getLayoutChildren().filter((e) => e !== t), i = /* @__PURE__ */ new Map();
329
385
  if (r.forEach((e) => {
330
386
  let t = this._flipCleanupTimers.get(e);
331
- t !== void 0 && (window.clearTimeout(t), this._flipCleanupTimers.delete(e)), i.set(e, e.getBoundingClientRect()), e.style.transition = "none", e.style.transform = "";
387
+ t !== void 0 && (window.clearTimeout(t), this._flipCleanupTimers.delete(e)), i.set(e, e.getBoundingClientRect()), e.style.transition = "none", e.style.transform = "", e.style.transformOrigin = "";
332
388
  }), r.length && r[0].offsetHeight, e(), n <= 0 || window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
333
389
  r.forEach((e) => {
334
- e.style.transition = "", e.style.transform = "";
390
+ e.style.transition = "", e.style.transform = "", e.style.transformOrigin = "";
335
391
  });
336
392
  return;
337
393
  }
338
394
  r.forEach((e) => {
339
395
  let t = i.get(e);
340
396
  if (!t) return;
341
- let r = e.getBoundingClientRect(), a = t.left - r.left, o = t.top - r.top;
342
- Math.abs(a) < .5 && Math.abs(o) < .5 || (e.style.transition = "none", e.style.transform = `translate(${a}px, ${o}px)`, requestAnimationFrame(() => {
397
+ let r = e.getBoundingClientRect(), a = t.left - r.left, o = t.top - r.top, s = t.width > 0 && r.width > 0 ? t.width / r.width : 1, c = t.height > 0 && r.height > 0 ? t.height / r.height : 1;
398
+ Math.abs(a) < .5 && Math.abs(o) < .5 && Math.abs(s - 1) < .005 && Math.abs(c - 1) < .005 || (e.style.transition = "none", e.style.transformOrigin = "top left", e.style.transform = `translate(${a}px, ${o}px) scale(${s}, ${c})`, requestAnimationFrame(() => {
343
399
  e.style.transition = `transform ${n}ms cubic-bezier(0.22, 1, 0.36, 1)`, e.style.transform = "";
344
400
  let t = () => {
345
- e.removeEventListener("transitionend", t), e.style.transition = "", e.style.transform = "", this._flipCleanupTimers.delete(e);
401
+ e.removeEventListener("transitionend", t), e.style.transition = "", e.style.transform = "", e.style.transformOrigin = "", this._flipCleanupTimers.delete(e);
346
402
  };
347
403
  e.addEventListener("transitionend", t, { once: !0 }), this._flipCleanupTimers.set(e, window.setTimeout(t, n + 40));
348
404
  }));
349
405
  });
350
406
  }
351
407
  _onPointerUp(e) {
352
- e.pointerId === this._pointerId && (this._maybeMovePlaceholder(e), this._finishDrag(!1));
408
+ e.pointerId === this._pointerId && (this._moveRaf !== null && (cancelAnimationFrame(this._moveRaf), this._moveRaf = null), this._pendingPointerEvent = null, this._processPointerMove(e), this._finishDrag(!1));
353
409
  }
354
410
  _onPointerCancel(e) {
355
411
  e.pointerId === this._pointerId && this._finishDrag(!0);
@@ -360,6 +416,7 @@ var t = "mint-sortable-placeholder", n = "mint-sortable-dragging", r = class e e
360
416
  this._teardownDrag();
361
417
  return;
362
418
  }
419
+ this._previewResizeRaf !== null && (cancelAnimationFrame(this._previewResizeRaf), this._previewResizeRaf = null), this._moveRaf !== null && (cancelAnimationFrame(this._moveRaf), this._moveRaf = null), this._pendingPointerEvent = null;
363
420
  try {
364
421
  t.releasePointerCapture(this._pointerId);
365
422
  } catch {}
@@ -386,9 +443,9 @@ var t = "mint-sortable-placeholder", n = "mint-sortable-dragging", r = class e e
386
443
  let e = this._originListRoot ?? this._listRoot, n = this._originNextSibling ?? this._restoreAfter;
387
444
  n && n.parentNode === e ? e.insertBefore(t, n) : e.appendChild(t);
388
445
  } else r?.parentNode && r.parentNode.insertBefore(t, r);
389
- r?.remove(), this._placeholder = null, t.classList.remove(n), t.style.cssText = "";
446
+ r?.remove(), this._placeholder = null, t.classList.remove(n), t.style.cssText = this._dragOriginalStyle, this._dragOriginalStyle = "";
390
447
  let f = d ? c : i._indexOfItem(t);
391
- this._pointerId = null, this._dragEl = null, this._restoreAfter = null, this._originListRoot = null, this._originNextSibling = null, this._dropList = null, this._dropAtEnd = !1, this._dropRejected = !1, this._lastPreviewRoot = null, this._lastPreviewIndex = -1;
448
+ this._pointerId = null, this._dragEl = null, this._restoreAfter = null, this._originListRoot = null, this._originNextSibling = null, this._dropList = null, this._dropAtEnd = !1, this._dropRejected = !1, this._lastPreviewRoot = null, this._lastPreviewIndex = -1, this._gridSlots = [];
392
449
  let p = this._collectOrderedKeys(), m = i._collectOrderedKeys(), h = !d && (!d && o !== s || f !== c), g = t.getAttribute(this._getItemKeyAttribute()) || "", _ = {
393
450
  oldIndex: c,
394
451
  newIndex: f,
@@ -428,13 +485,13 @@ var t = "mint-sortable-placeholder", n = "mint-sortable-dragging", r = class e e
428
485
  })));
429
486
  }
430
487
  _teardownDrag() {
431
- 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) {
488
+ if (this._previewResizeRaf !== null && (cancelAnimationFrame(this._previewResizeRaf), this._previewResizeRaf = null), this._scrollRaf !== null && (cancelAnimationFrame(this._scrollRaf), this._scrollRaf = null), this._moveRaf !== null && (cancelAnimationFrame(this._moveRaf), this._moveRaf = null), this._pendingPointerEvent = null, window.removeEventListener("pointermove", this._boundPointerMove), window.removeEventListener("pointerup", this._boundPointerUp), window.removeEventListener("pointercancel", this._boundPointerCancel), this._dragEl) {
432
489
  try {
433
490
  this._pointerId !== null && this._dragEl.releasePointerCapture(this._pointerId);
434
491
  } catch {}
435
- this._dragEl.classList.remove(n), this._dragEl.style.cssText = "";
492
+ this._dragEl.classList.remove(n), this._dragEl.style.cssText = this._dragOriginalStyle, this._dragOriginalStyle = "";
436
493
  }
437
- 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, this._lastPreviewRoot = null, this._lastPreviewIndex = -1;
494
+ 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, this._lastPreviewRoot = null, this._lastPreviewIndex = -1, this._gridSlots = [];
438
495
  }
439
496
  };
440
497
  customElements.get("mint-sortable") || e("mint-sortable", r);
@@ -0,0 +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._dragOriginalStyle=``,this._placeholder=null,this._listRoot=this,this._startIndex=0,this._pointerStartX=0,this._pointerStartY=0,this._pendingPointerEvent=null,this._moveRaf=null,this._gridSlots=[],this._scrollRaf=null,this._previewResizeRaf=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._lastPreviewRoot=null,this._lastPreviewIndex=-1,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(){let e=this.getAttribute(`direction`)||`vertical`;return e===`horizontal`||e===`grid`?e:`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._dragOriginalStyle=r.style.cssText,this._pointerId=e.pointerId,this._startIndex=this._indexOfItem(r),this._gridSlots=this.getDirection()===`grid`?Array.from(this._listRoot.children).filter(e=>e.nodeType===Node.ELEMENT_NODE&&!e.hasAttribute(`data-mint-sortable-status`)).map((e,t)=>({element:e,rect:e.getBoundingClientRect(),index:t})):[];let i=r.getBoundingClientRect();this._pointerStartX=e.clientX,this._pointerStartY=e.clientY;let a=document.createElement(`div`);if(a.className=t,this.getDirection()!==`grid`)a.style.minHeight=`${i.height}px`,a.style.minWidth=`${i.width}px`;else{let e=window.getComputedStyle(r);e.gridArea===`auto`?(a.style.gridColumn=e.gridColumn,a.style.gridRow=e.gridRow):a.style.gridArea=e.gridArea,a.style.alignSelf=e.alignSelf,a.style.justifySelf=e.justifySelf}a.setAttribute(`aria-hidden`,`true`),this._placeholder=a,this._listRoot.insertBefore(a,r),r.classList.add(n),r.style.position=`fixed`,r.style.left=`${e.clientX}px`,r.style.top=`${e.clientY}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) translate(-50%, -50%) scale(1.015)`,r.style.transformOrigin=`center center`,r.style.willChange=`transform`,r.setPointerCapture(e.pointerId);let o=this._collectOrderedKeys(),s={index:this._startIndex,itemId:r.getAttribute(this._getItemKeyAttribute())||``,keys:o,sourceContainerId:this.id||null};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){e.pointerId!==this._pointerId||!this._dragEl||!this._placeholder||(e.preventDefault(),this._pendingPointerEvent=e,this._moveRaf===null&&(this._moveRaf=requestAnimationFrame(()=>{this._moveRaf=null;let e=this._pendingPointerEvent;this._pendingPointerEvent=null,e&&e.pointerId===this._pointerId&&this._processPointerMove(e)})))}_processPointerMove(e){if(!this._dragEl||!this._placeholder)return;let t=e.clientX-this._pointerStartX,n=e.clientY-this._pointerStartY;this._dragEl.style.transform=`translate3d(${t}px, ${n}px, 0) translate(-50%, -50%) 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;let a=t.parentElement!==i;a&&r._flipAnimate(()=>i.appendChild(t)),this._dropList=r;let o=r.getDirection();if(o===`grid`){this._moveGridPlaceholder(r,i,t,n,e);return}let s=o===`horizontal`,c=s?e.clientX:e.clientY,l=this.hasAttribute(`data-mint-sortable-full-crossing`);if(this._dropAtEnd&&r!==this){(t.parentElement!==i||i.lastElementChild!==t)&&r._flipAnimate(()=>i.appendChild(t)),this._dispatchPreview(r,i,t,n);return}let u=Array.from(i.children).filter(e=>e.nodeType===Node.ELEMENT_NODE&&e!==n&&e!==t),d=null;for(let e of u){let n=e.getBoundingClientRect(),r=s?n.left:n.top,a=s?n.left+n.width:n.top+n.height;if(l){if(c<r){d=e;break}if(c<=a&&Array.prototype.indexOf.call(i.children,t)<Array.prototype.indexOf.call(i.children,e)){d=e;break}}else if(c<(s?n.left+n.width/2:n.top+n.height/2)){d=e;break}}let f=Array.from(i.children).filter(e=>e.nodeType===Node.ELEMENT_NODE&&e!==n),p=f.length>0&&f[f.length-1]===t;if(!(d?!(t.nextSibling===d&&t.parentNode===i):!p)){a&&this._dispatchPreview(r,i,t,n);return}r._flipAnimate(()=>{d?i.insertBefore(t,d):i.appendChild(t)}),this._dispatchPreview(r,i,t,n)}_moveGridPlaceholder(e,t,n,r,i){let a=Array.from(t.children).filter(e=>e.nodeType===Node.ELEMENT_NODE&&e!==r&&e!==n&&!e.hasAttribute(`data-mint-sortable-status`)),o=t===this._originListRoot?this._gridSlots.filter(e=>e.element===r||e.element.parentElement===t):a.map((e,t)=>({element:e,rect:e.getBoundingClientRect(),index:t})),s=null,c=1/0,l=!1;for(let e of o){let{rect:t}=e,n=i.clientX>=t.left&&i.clientX<=t.right&&i.clientY>=t.top&&i.clientY<=t.bottom,r=i.clientX-(t.left+t.width/2),a=i.clientY-(t.top+t.height/2),o=n?-1:r*r+a*a;o<c&&(s=e,c=o,l=n)}let u=null;if(s){let{rect:e}=s,n=(i.clientX-(e.left+e.width/2))/Math.max(e.width,1),o=(i.clientY-(e.top+e.height/2))/Math.max(e.height,1),c=s.index===0&&l?!0:Math.abs(n)>=Math.abs(o)?n<=0:o<=0,d=s.index+(c?0:1);t===this._originListRoot&&s.element!==r&&s.index>=this._startIndex&&d--,s.element===r&&(d=this._startIndex),d=Math.max(0,Math.min(a.length,d)),u=a[d]??null}if(!(u?!(n.nextSibling===u&&n.parentNode===t):!(t.lastElementChild===n&&n.parentNode===t))){this._dispatchPreview(e,t,n,r);return}e._flipAnimate(()=>{u?t.insertBefore(n,u):t.appendChild(n),this._dispatchPreview(e,t,n,r)})}_dispatchPreview(e,t,n,r){let i=Array.from(t.children).filter(e=>e.nodeType===Node.ELEMENT_NODE&&e!==r&&!e.hasAttribute(`data-mint-sortable-status`)),a=i.indexOf(n);if(a<0||this._lastPreviewRoot===t&&this._lastPreviewIndex===a)return;this._lastPreviewRoot=t,this._lastPreviewIndex=a;let o=this._getItemKeyAttribute(),s=i.map(e=>e===n?r.getAttribute(o)||``:e.getAttribute(o)||``),c={itemId:r.getAttribute(o)||``,oldIndex:this._startIndex,newIndex:a,keys:s,sourceContainerId:this.id||null,destinationContainerId:e.id||null};this.dispatchEvent(new CustomEvent(`mint-sortable-preview`,{bubbles:!0,composed:!0,detail:c})),this._resizeDragToPlaceholder(r,n)}_resizeDragToPlaceholder(e,t){this._previewResizeRaf!==null&&cancelAnimationFrame(this._previewResizeRaf),this._previewResizeRaf=requestAnimationFrame(()=>{if(this._previewResizeRaf=null,this._dragEl!==e||this._placeholder!==t||!t.isConnected)return;let n=t.offsetWidth,r=t.offsetHeight;!n||!r||(e.style.transition=`width 160ms ease, height 160ms ease`,e.style.width=`${n}px`,e.style.height=`${r}px`,e.style.transformOrigin=`center center`)})}_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=``,e.style.transformOrigin=``}),r.length&&r[0].offsetHeight,e(),n<=0||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches){r.forEach(e=>{e.style.transition=``,e.style.transform=``,e.style.transformOrigin=``});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,s=t.width>0&&r.width>0?t.width/r.width:1,c=t.height>0&&r.height>0?t.height/r.height:1;Math.abs(a)<.5&&Math.abs(o)<.5&&Math.abs(s-1)<.005&&Math.abs(c-1)<.005||(e.style.transition=`none`,e.style.transformOrigin=`top left`,e.style.transform=`translate(${a}px, ${o}px) scale(${s}, ${c})`,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=``,e.style.transformOrigin=``,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._moveRaf!==null&&(cancelAnimationFrame(this._moveRaf),this._moveRaf=null),this._pendingPointerEvent=null,this._processPointerMove(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}this._previewResizeRaf!==null&&(cancelAnimationFrame(this._previewResizeRaf),this._previewResizeRaf=null),this._moveRaf!==null&&(cancelAnimationFrame(this._moveRaf),this._moveRaf=null),this._pendingPointerEvent=null;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=this._dragOriginalStyle,this._dragOriginalStyle=``;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,this._lastPreviewRoot=null,this._lastPreviewIndex=-1,this._gridSlots=[];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._previewResizeRaf!==null&&(cancelAnimationFrame(this._previewResizeRaf),this._previewResizeRaf=null),this._scrollRaf!==null&&(cancelAnimationFrame(this._scrollRaf),this._scrollRaf=null),this._moveRaf!==null&&(cancelAnimationFrame(this._moveRaf),this._moveRaf=null),this._pendingPointerEvent=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._dragOriginalStyle,this._dragOriginalStyle=``}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,this._lastPreviewRoot=null,this._lastPreviewIndex=-1,this._gridSlots=[]}};customElements.get(`mint-sortable`)||e.t(`mint-sortable`,r),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return r}});
@@ -1,16 +1,21 @@
1
- type StackDirection = 'horizontal' | 'vertical';
1
+ type StackDirection = 'horizontal' | 'vertical' | 'grid';
2
2
  type TextAlign = 'left' | 'center' | 'right' | 'justify';
3
3
  type StackAlignContent = 'left' | 'right' | 'center';
4
4
  declare class MintSortable extends HTMLElement {
5
5
  static get observedAttributes(): string[];
6
6
  private _pointerId;
7
7
  private _dragEl;
8
+ private _dragOriginalStyle;
8
9
  private _placeholder;
9
10
  private _listRoot;
10
11
  private _startIndex;
11
12
  private _pointerStartX;
12
13
  private _pointerStartY;
14
+ private _pendingPointerEvent;
15
+ private _moveRaf;
16
+ private _gridSlots;
13
17
  private _scrollRaf;
18
+ private _previewResizeRaf;
14
19
  private _boundPointerMove;
15
20
  private _boundPointerUp;
16
21
  private _boundPointerCancel;
@@ -59,11 +64,16 @@ declare class MintSortable extends HTMLElement {
59
64
  private _indexOfItem;
60
65
  private _getLayoutChildren;
61
66
  private _onPointerMove;
67
+ private _processPointerMove;
62
68
  private _resolveDropList;
63
69
  private _autoScroll;
64
70
  private _maybeMovePlaceholder;
71
+ /** Place before/after the nearest item in a two-dimensional grid or mosaic. */
72
+ private _moveGridPlaceholder;
65
73
  /** Emit a serializable snapshot of the proposed order whenever the placeholder changes. */
66
74
  private _dispatchPreview;
75
+ /** Keep the floating preview sized to the slot currently occupied by its placeholder. */
76
+ private _resizeDragToPlaceholder;
67
77
  private _flipAnimate;
68
78
  private _onPointerUp;
69
79
  private _onPointerCancel;
@@ -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,gBAAgB,CAA2B;IACnD,OAAO,CAAC,iBAAiB,CAAK;IAC9B,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;IAmElB,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,cAAc;IAqBtB,OAAO,CAAC,gBAAgB;IA0BxB,OAAO,CAAC,WAAW;IA4BnB,OAAO,CAAC,qBAAqB;IA+E7B,2FAA2F;IAC3F,OAAO,CAAC,gBAAgB;IAsBxB,OAAO,CAAC,YAAY;IAsDpB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,gBAAgB;IAKxB,OAAO,CAAC,WAAW;IA+HnB,OAAO,CAAC,aAAa;CA8BtB;AAMD,eAAe,YAAY,CAAA"}
1
+ {"version":3,"file":"Sortable.d.ts","sourceRoot":"","sources":["../../../src/components/sortable/Sortable.ts"],"names":[],"mappings":"AAIA,KAAK,cAAc,GAAG,YAAY,GAAG,UAAU,GAAG,MAAM,CAAA;AACxD,KAAK,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAA;AACxD,KAAK,iBAAiB,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAA;AAMpD,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,kBAAkB,CAAK;IAC/B,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,oBAAoB,CAA4B;IACxD,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,UAAU,CAAiB;IACnC,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,iBAAiB,CAAsB;IAC/C,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,gBAAgB,CAA2B;IACnD,OAAO,CAAC,iBAAiB,CAAK;IAC9B,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;IA2FlB,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,cAAc;IAiBtB,OAAO,CAAC,mBAAmB;IAoB3B,OAAO,CAAC,gBAAgB;IA0BxB,OAAO,CAAC,WAAW;IA4BnB,OAAO,CAAC,qBAAqB;IAwF7B,+EAA+E;IAC/E,OAAO,CAAC,oBAAoB;IAgE5B,2FAA2F;IAC3F,OAAO,CAAC,gBAAgB;IAuBxB,yFAAyF;IACzF,OAAO,CAAC,wBAAwB;IAmBhC,OAAO,CAAC,YAAY;IA4DpB,OAAO,CAAC,YAAY;IAWpB,OAAO,CAAC,gBAAgB;IAKxB,OAAO,CAAC,WAAW;IA2InB,OAAO,CAAC,aAAa;CAyCtB;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-DdT2ptc5.js";
15
+ import { t as e } from "../chunks/sortable-BpbwI7_Y.js";
16
16
  export { e as default };
@@ -1 +1 @@
1
- const e=require(`../chunks/sortable-Bql13n3L.js`);module.exports=e.t;
1
+ const e=require(`../chunks/sortable-Bxg81mcs.js`);module.exports=e.t;
@@ -1,4 +1,4 @@
1
1
  import '../../theme.css'
2
2
  import '../../sortable.css'
3
- import { t as e } from "../chunks/sortable-DdT2ptc5.js";
3
+ import { t as e } from "../chunks/sortable-BpbwI7_Y.js";
4
4
  export { e as default };
@@ -27,7 +27,7 @@ import "../chunks/spinner-B2sml0AG.js";
27
27
  import "../chunks/button-BTQHrE0x.js";
28
28
  import "../chunks/confirm-action-BW1UwJNu.js";
29
29
  import "../chunks/popover-DPNBidSz.js";
30
- import "../chunks/sortable-DdT2ptc5.js";
30
+ import "../chunks/sortable-BpbwI7_Y.js";
31
31
  //#region src/components/tree/tree-utils.js
32
32
  function t(e = []) {
33
33
  s(e);
@@ -1 +1 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}}),require(`../chunks/icon-B9P0jyS2.js`);const e=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/spinner-CUcCgLKS.js`),require(`../chunks/button-B4BMYTk1.js`),require(`../chunks/confirm-action-sovGys0x.js`),require(`../chunks/popover-CWWKb7L1.js`),require(`../chunks/sortable-Bql13n3L.js`);function t(e=[]){s(e);let t=e=>e.map(e=>({...e,children:Array.isArray(e.children)?t(e.children):[]}));return t(e)}function n(e,t){let r=String(t);for(let t of e){if(String(t.id)===r)return t;let e=n(t.children||[],r);if(e)return e}return null}function r(e,t,n=null){let i=String(t);for(let t of e){if(String(t.id)===i)return{parentId:n,siblings:e,item:t};let a=r(t.children||[],i,String(t.id));if(a)return a}return null}function i(e,t,n=0){let r=String(t);for(let t of e){if(String(t.id)===r)return n;let e=i(t.children||[],r,n+1);if(e>=0)return e}return-1}function a(e){let t=Array.isArray(e?.children)?e.children:[];return t.length?1+Math.max(...t.map(a)):1}function o(e,t){return String(e.id)===String(t)?!0:(e.children||[]).some(e=>o(e,t))}function s(e){let t=new Set,n=e=>{for(let r of e){if(r.id===null||r.id===void 0||String(r.id)===``)throw Error(`Every tree item must have a non-empty identifier.`);let e=String(r.id);if(t.has(e))throw Error(`Tree item identifiers must be unique. Duplicate identifier: ${e}.`);t.add(e),n(r.children||[])}};n(e)}function c(e,s,c,l,u={}){let d=t(e),f=r(d,s);if(!f)throw Error(`Tree item ${s} was not found.`);if(f.item.disabled||f.item.draggable===!1)throw Error(`Disabled tree items cannot be moved.`);let p=c==null||c===``?null:n(d,c);if(c!=null&&c!==``&&!p)throw Error(`Target parent ${c} was not found.`);if(p&&o(f.item,p.id))throw Error(`A tree item cannot be moved inside itself or one of its descendants.`);if(p?.disabled)throw Error(`Disabled tree items cannot contain children.`);if(u.allowNesting===!1&&p)throw Error(`Nesting is disabled for this tree.`);if(p?.canHaveChildren===!1)throw Error(`The target item cannot contain children.`);if(p?.acceptsTypes?.length&&!p.acceptsTypes.includes(f.item.type))throw Error(`The target item does not accept this item type.`);let m=p?p.children:d,h=f.siblings.findIndex(e=>String(e.id)===String(s)),[g]=f.siblings.splice(h,1),_=Math.min(Math.max(0,Number.isFinite(l)?Math.trunc(l):m.length),m.length);m.splice(_,0,g);let v=Number.isFinite(u.maxDepth)?Math.max(1,Math.trunc(u.maxDepth)):1/0;if((p?i(d,p.id)+1:0)+a(g)>v)throw Error(`Moving this branch would exceed the maximum tree depth of ${v}.`);return{items:d,item:g,oldParentId:f.parentId,newParentId:p?String(p.id):null,oldIndex:h,newIndex:_}}var l=0;function u(e,t,n){e.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:n}))}function d(e,t){let n=e.getAttribute(t);return n===``||n===`true`}function f(e){return e==null||e===``?null:String(e)}var p=class extends HTMLElement{constructor(...e){super(...e),this._items=[],this._undoStack=[],this._redoStack=[],this._selectedId=null,this._expandedIds=new Set,this._root=null,this._confirm=null,this._treeId=`mint-tree-${++l}`,this._liveRegion=null,this._dragExpansion=null,this._autoExpandedIds=new Set,this._dragHoverExpandedId=null,this._keyboardFocusRestore=null,this._suppressSelectionClick=!1,this._selectionClickSuppressionTimer=null,this._onClick=e=>{let t=e.target instanceof Element?e.target.closest(`[data-tree-command]`):null;if(!t||!this.contains(t))return;let r=t.getAttribute(`data-tree-command`),i=t.getAttribute(`data-tree-id`);if(r===`create-root`)u(this,`mint-tree-create`,{parentId:null,items:this.items});else if(r===`expand-all`)this._expandedIds=this._defaultExpandedIds(this._items),this._syncExpandedDOM(),u(this,`mint-tree-expand`,{all:!0,expandedIds:this.expandedIds});else if(r===`collapse-all`)this._expandedIds.clear(),this._syncExpandedDOM(),u(this,`mint-tree-collapse`,{all:!0,expandedIds:[]});else if(r===`undo`)this._undo();else if(r===`redo`)this._redo();else if(r===`toggle`&&i){let e=!this._expandedIds.has(i);this._setExpanded(i,e,!0)}else if(r===`select`&&i){if(this.classList.contains(`mint-tree-drag-active`)||this._suppressSelectionClick){e.preventDefault(),this._suppressSelectionClick=!1,this._selectionClickSuppressionTimer!==null&&window.clearTimeout(this._selectionClickSuppressionTimer),this._selectionClickSuppressionTimer=null;return}this._select(i)}else if(r===`create-child`&&i)this._closeItemPopover(t),u(this,`mint-tree-create`,{parentId:i,items:this.items});else if(r===`edit`&&i){this._closeItemPopover(t);let e=n(this._items,i);e&&u(this,`mint-tree-edit`,{item:{...e},itemId:i,items:this.items})}else if(r===`delete`&&i)this._closeItemPopover(t),this._confirmDelete(i);else if([`move-up`,`move-down`,`nest-previous`,`outdent`].includes(r||``)&&i)this._closeItemPopover(t),this._moveByCommand(i,r||``);else if(r===`custom`&&i){this._closeItemPopover(t);let e=n(this._items,i),r=t.getAttribute(`data-tree-action`)||``,a=e?.actions?.find(e=>e.id===r);if(e&&a){let t={item:{...e},itemId:i,action:{...a,onSelect:void 0},items:this.items};u(this,`mint-tree-action`,t),a.onSelect?.({item:{...e},itemId:i,action:a,items:this.items})}}},this._onSortableDrag=e=>{let t=e.detail;if(!t||!Number.isFinite(t.clientX)||!Number.isFinite(t.clientY))return;let r=document.elementFromPoint(t.clientX,t.clientY),i=r?.closest(`[data-mint-tree-row]`),a=t.item?.getAttribute(`data-tree-id`)||``,o=null;if(i&&i.getAttribute(`data-tree-id`)!==a){let e=i.querySelector(`:scope > .mint-tree-row`)?.getBoundingClientRect()||i.getBoundingClientRect(),r=e.height?(t.clientY-e.top)/e.height:0;if(r>.22&&r<.78){let e=i.getAttribute(`data-tree-id`)||``;n(this._items,e)&&this._isValidDrop(a,e)&&(o=e)}}if(!o&&this._dragHoverExpandedId){let e=[...this._root?.querySelectorAll(`[data-tree-id]`)??[]].find(e=>e.getAttribute(`data-tree-id`)===this._dragHoverExpandedId)?.querySelector(`:scope > mint-sortable.mint-tree-children`);r&&e?.contains(r)&&(o=this._dragHoverExpandedId)}if(this._dragHoverExpandedId&&this._dragHoverExpandedId!==o){let e=this._dragHoverExpandedId;this._dragHoverExpandedId=null,this._autoExpandedIds.delete(e),this._expandedIds.delete(e),this._syncNodeExpanded(e);let t=n(this._items,e);t&&u(this,`mint-tree-collapse`,{itemId:e,item:{...t},expandedIds:this.expandedIds,automatic:!0})}if(o){let e=n(this._items,o);e&&!this._expandedIds.has(o)&&(this._expandedIds.add(o),this._autoExpandedIds.add(o),this._dragHoverExpandedId=o,this._syncNodeExpanded(o),u(this,`mint-tree-expand`,{itemId:o,item:{...e},expandedIds:this.expandedIds,automatic:!0}))}},this._onSortableStart=()=>{this.classList.add(`mint-tree-drag-active`),this._dragHoverExpandedId=null,this._dragExpansion?.timer!==null&&this._dragExpansion?.timer!==void 0&&window.clearTimeout(this._dragExpansion.timer),this._dragExpansion=null;let e=this._root?.querySelector(`.mint-sortable-dragging[data-tree-id]`),t=e?.getAttribute(`data-tree-id`)||``,n=e?.querySelector(`:scope > mint-sortable.mint-tree-children`);if(!e||!t||!n||n.hidden||!this._expandedIds.has(t))return;let r=e.querySelector(`:scope > .mint-tree-row`),i=this._root?.querySelector(`.mint-sortable-placeholder`),a=n.getBoundingClientRect().height;n.style.height=`${a}px`,n.style.overflow=`hidden`,e.style.height=`auto`,e.style.overflow=`hidden`,this._dragExpansion={itemId:t,item:e,childList:n,timer:null},this._setTransientExpanded(t,!1),n.offsetHeight,requestAnimationFrame(()=>{this._dragExpansion?.childList===n&&(n.classList.add(`mint-tree-drag-collapse`),n.style.height=`0px`,i&&r&&(i.style.minHeight=`${r.getBoundingClientRect().height}px`))})},this._onSortableEnd=e=>{this.classList.remove(`mint-tree-drag-active`),this._suppressSelectionClick=!0,this._selectionClickSuppressionTimer!==null&&window.clearTimeout(this._selectionClickSuppressionTimer),this._selectionClickSuppressionTimer=window.setTimeout(()=>{this._suppressSelectionClick=!1,this._selectionClickSuppressionTimer=null},300);let t=e.detail,r=t&&!t.cancelled?f(t.newParentId):null;for(let e of this._autoExpandedIds){if(e===r)continue;this._expandedIds.delete(e),this._syncNodeExpanded(e);let t=n(this._items,e);t&&u(this,`mint-tree-collapse`,{itemId:e,item:{...t},expandedIds:this.expandedIds,automatic:!0})}this._autoExpandedIds.clear(),this._dragHoverExpandedId=null;let i=this._dragExpansion;if(!i)return;i.item=[...this._root?.querySelectorAll(`[data-tree-id]`)??[]].find(e=>e.getAttribute(`data-tree-id`)===i.itemId)||i.item,i.childList=i.item.querySelector(`:scope > mint-sortable.mint-tree-children`)||i.childList;let{item:a,childList:o,itemId:s}=i;o.style.height=`0px`,o.style.overflow=`hidden`,o.classList.remove(`mint-tree-drag-collapse`),this._setTransientExpanded(s,!0),o.offsetHeight;let c=o.scrollHeight;requestAnimationFrame(()=>{this._dragExpansion===i&&(o.style.height=`${c}px`)}),i.timer=window.setTimeout(()=>{o.style.height=``,o.style.overflow=``,o.style.opacity=``,this._dragExpansion=null},155)},this._onSortableDragOver=e=>{let t=e,{item:r,target:i}=t.detail||{};if(!r||!i)return;this._root?.querySelectorAll(`.mint-tree-drop-invalid`).forEach(e=>e.classList.remove(`mint-tree-drop-invalid`));let a=this._root?.querySelector(`.mint-sortable-placeholder`),o=r.getAttribute(`data-tree-id`)||``,s=f(i.getAttribute(`data-tree-parent-id`)),c=i===t.detail.source||this._isValidDrop(o,s),l=s?n(this._items,s):null;c&&i!==t.detail.source&&l?a?.setAttribute(`data-drop-label`,`Drop here to nest under ${l.label}`):c&&i===this._root?.querySelector(`:scope > mint-sortable`)?a?.setAttribute(`data-drop-label`,`Drop here to move to the top level`):a?.removeAttribute(`data-drop-label`);let u=(Number.isFinite(t.detail.clientX)&&Number.isFinite(t.detail.clientY)?document.elementFromPoint(t.detail.clientX,t.detail.clientY):null)?.closest(`[data-mint-tree-row]`);u&&u.getAttribute(`data-tree-id`)!==o&&!c&&u.classList.add(`mint-tree-drop-invalid`),c||t.preventDefault()},this._onSortableBeforeDrop=e=>{let t=e,n=t.detail;if(!n?.item||!n.target)return;let r=n.item.getAttribute(`data-tree-id`)||``,i=f(n.target.getAttribute(`data-tree-parent-id`));n.target!==n.source&&!this._isValidDrop(r,i)&&t.preventDefault()},this._onSortableChange=e=>{let t=e.detail;if(!t||t.cancelled)return;let r=t.itemId||``,i=f(t.oldParentId),a=f(t.newParentId),o=this._root?.querySelector(`:scope > mint-sortable`);if(!o)return;let s=n(this._items,r);this._recordHistory(),this._items=this._readItemsFromDOM(o),this._collapseEmptyExpandedNodes();let c=n(this._items,r);if(!c||!s)return;let l={itemId:r,item:{...c},items:this.items,oldParentId:i,newParentId:a,oldIndex:Number(t.oldIndex??-1),newIndex:Number(t.newIndex??-1)};this._clearDropState(),u(this,`mint-tree-change`,{items:l.items,itemId:r}),i===a?u(this,`mint-tree-reorder`,l):u(this,`mint-tree-reparent`,l);let d=`${c.label} moved${a?` into ${n(this._items,a)?.label||`a group`}`:` to the top level`}.`;this._dragExpansion?.itemId===r?window.setTimeout(()=>{this.isConnected&&(this._render(),this._focusRow(r),this._announce(d))},155):(this._render(),this._focusRow(r),this._announce(d))},this._onKeydown=e=>{let t=e.target instanceof Element?e.target.closest(`[data-mint-tree-row]`):null;if(!t)return;if(e.altKey&&[`ArrowUp`,`ArrowDown`].includes(e.key)){e.preventDefault();let n=t.getAttribute(`data-tree-id`)||``;if(n){this._keyboardFocusRestore&&window.clearTimeout(this._keyboardFocusRestore.timer);let e={id:n,x:window.scrollX,y:window.scrollY,timer:0};e.timer=window.setTimeout(()=>{this._keyboardFocusRestore===e&&(this._keyboardFocusRestore=null)},2e3),this._keyboardFocusRestore=e}return}let i=t.getAttribute(`data-tree-id`)||``;if(e.altKey&&e.key===`ArrowRight`){e.preventDefault(),this._keyboardIndent(i);return}if(e.altKey&&e.key===`ArrowLeft`){e.preventDefault(),this._keyboardOutdent(i);return}let a=[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].filter(e=>!e.closest(`mint-sortable[hidden]`)),o=a.indexOf(t);if(e.key===`ArrowDown`)e.preventDefault(),a[o+1]?.focus({preventScroll:!0});else if(e.key===`ArrowUp`)e.preventDefault(),a[o-1]?.focus({preventScroll:!0});else if(e.key===`ArrowRight`)e.preventDefault(),this._expandedIds.has(i)?a[o+1]?.focus({preventScroll:!0}):this._setExpanded(i,!0,!0);else if(e.key===`ArrowLeft`)if(e.preventDefault(),this._expandedIds.has(i))this._setExpanded(i,!1,!0);else{let e=r(this._items,i)?.parentId;e&&[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].find(t=>t.getAttribute(`data-tree-id`)===e)?.focus({preventScroll:!0})}else if(e.key===`Enter`||e.key===` `||e.key===`Spacebar`){let r=e.target instanceof Element?e.target.closest(`[data-tree-command="select"]`):null;(t===e.target||r)&&(e.preventDefault(),n(this._items,i)?.children?.length?this._setExpanded(i,!this._expandedIds.has(i),!0):this._select(i))}}}static get observedAttributes(){return[`selected-id`,`max-depth`,`allow-nesting`,`disabled`,`loading`,`create-label`,`empty-label`,`delete-confirmation`,`expanded-ids`]}connectedCallback(){this._root||(this._selectedId=f(this.getAttribute(`selected-id`)),this._expandedIds=this.hasAttribute(`expanded-ids`)?this._readExpandedIds(this.getAttribute(`expanded-ids`)):this._defaultExpandedIds(this._items),this.addEventListener(`click`,this._onClick),this.addEventListener(`keydown`,this._onKeydown,!0),this.addEventListener(`mint-sortable-start`,this._onSortableStart),this.addEventListener(`mint-sortable-end`,this._onSortableEnd),this.addEventListener(`mint-sortable-drag`,this._onSortableDrag),this.addEventListener(`mint-sortable-drag-over`,this._onSortableDragOver),this.addEventListener(`mint-sortable-before-drop`,this._onSortableBeforeDrop),this.addEventListener(`mint-sortable-change`,this._onSortableChange),this._render())}disconnectedCallback(){this._dragExpansion?.timer!==null&&this._dragExpansion?.timer!==void 0&&window.clearTimeout(this._dragExpansion.timer),this._keyboardFocusRestore&&window.clearTimeout(this._keyboardFocusRestore.timer),this._selectionClickSuppressionTimer!==null&&window.clearTimeout(this._selectionClickSuppressionTimer),this._selectionClickSuppressionTimer=null,this._suppressSelectionClick=!1,this._keyboardFocusRestore=null,this._dragExpansion=null,this._autoExpandedIds.clear(),this._dragHoverExpandedId=null,this.classList.remove(`mint-tree-drag-active`),this.removeEventListener(`click`,this._onClick),this.removeEventListener(`keydown`,this._onKeydown,!0),this.removeEventListener(`mint-sortable-start`,this._onSortableStart),this.removeEventListener(`mint-sortable-end`,this._onSortableEnd),this.removeEventListener(`mint-sortable-drag`,this._onSortableDrag),this.removeEventListener(`mint-sortable-drag-over`,this._onSortableDragOver),this.removeEventListener(`mint-sortable-before-drop`,this._onSortableBeforeDrop),this.removeEventListener(`mint-sortable-change`,this._onSortableChange),this._root=null}attributeChangedCallback(e,t,n){if(!(t===n||!this.isConnected)){if(e===`selected-id`){this._selectedId=f(n),this._syncSelectionDOM();return}e===`expanded-ids`&&(this._expandedIds=this._readExpandedIds(n)),this._render()}}get items(){return t(this._items)}set items(e){this._items=t(Array.isArray(e)?e:[]),this._undoStack=[],this._redoStack=[],this.hasAttribute(`expanded-ids`)?this._collapseEmptyExpandedNodes():this._expandedIds=this._defaultExpandedIds(this._items),this.isConnected&&this._render()}get selectedId(){return this._selectedId}set selectedId(e){this._selectedId=f(e),this._selectedId===null?this.removeAttribute(`selected-id`):this.setAttribute(`selected-id`,this._selectedId)}get expandedIds(){return[...this._expandedIds]}set expandedIds(e){this._expandedIds=new Set((Array.isArray(e)?e:[]).map(String)),this.isConnected&&this._render()}save(){u(this,`mint-tree-save`,{items:this.items})}select(e){this._select(String(e))}expand(e){this._setExpanded(String(e),!0,!0)}collapse(e){this._setExpanded(String(e),!1,!0)}_readExpandedIds(e){if(!e)return this._defaultExpandedIds(this._items);try{let t=JSON.parse(e);return new Set(Array.isArray(t)?t.map(String):[])}catch{return new Set(e.split(`,`).map(e=>e.trim()).filter(Boolean))}}_defaultExpandedIds(e){let t=new Set,n=e=>e.forEach(e=>{e.children?.length&&(t.add(String(e.id)),n(e.children))});return n(e),t}_maxDepth(){let e=Number.parseInt(this.getAttribute(`max-depth`)||``,10);return Number.isFinite(e)&&e>0?e:1/0}_allowNesting(){return!this.hasAttribute(`allow-nesting`)||d(this,`allow-nesting`)}_disabled(){return d(this,`disabled`)}_isLoading(){return d(this,`loading`)}_render(){let e=document.activeElement instanceof HTMLElement?document.activeElement.closest(`[data-mint-tree-row]`):null,t=e&&this.contains(e)?e.getAttribute(`data-tree-id`):null;t&&this._keyboardFocusRestore&&(this._keyboardFocusRestore.id=t);let n=document.createElement(`div`);n.className=`mint-tree-shell`,n.setAttribute(`role`,`tree`),n.setAttribute(`aria-label`,this.getAttribute(`aria-label`)||`Hierarchical items`),n.setAttribute(`aria-busy`,String(this._isLoading()));let r=document.createElement(`div`);r.className=`mint-tree-toolbar`;let i=document.createElement(`span`);i.className=`mint-tree-count`,i.textContent=`${this._countItems()} ${this._countItems()===1?`item`:`items`}`,r.appendChild(i);let a=document.createElement(`div`);a.className=`mint-tree-toolbar-actions`;let o=this._createButton(``,`ghost`,`undo`);o.setAttribute(`icon`,`undo`),o.setAttribute(`aria-label`,`Undo last change`),o.setAttribute(`title`,`Undo`),(!this._undoStack.length||this._disabled())&&o.setAttribute(`disabled`,`true`);let s=this._createButton(``,`ghost`,`redo`);s.setAttribute(`icon`,`redo`),s.setAttribute(`aria-label`,`Redo last undone change`),s.setAttribute(`title`,`Redo`),(!this._redoStack.length||this._disabled())&&s.setAttribute(`disabled`,`true`);let c=this._createButton(``,`ghost`,`expand-all`);c.setAttribute(`icon`,`expand`),c.setAttribute(`aria-label`,`Expand all`),c.setAttribute(`title`,`Expand all`);let l=this._createButton(``,`ghost`,`collapse-all`);if(l.setAttribute(`icon`,`collapse`),l.setAttribute(`aria-label`,`Collapse all`),l.setAttribute(`title`,`Collapse all`),a.append(o,s,c,l),r.appendChild(a),n.appendChild(r),this._isLoading()){let e=document.createElement(`div`);e.className=`mint-tree-loading`,e.setAttribute(`aria-label`,`Loading items`);let t=document.createElement(`mint-spinner`);t.setAttribute(`size`,`small`),e.appendChild(t),n.appendChild(e)}else if(this._items.length)n.appendChild(this._createList(this._items,null,0));else{let e=document.createElement(`div`);e.className=`mint-tree-empty`,e.textContent=this.getAttribute(`empty-label`)||`No items yet.`,n.appendChild(e)}this._liveRegion=document.createElement(`div`),this._liveRegion.className=`mint-tree-live-region`,this._liveRegion.setAttribute(`role`,`status`),this._liveRegion.setAttribute(`aria-live`,`polite`),this._liveRegion.setAttribute(`aria-atomic`,`true`),n.appendChild(this._liveRegion);let u=document.createElement(`mint-confirm-action`);u.className=`mint-tree-confirm`,this._confirm=u,n.appendChild(u),this.replaceChildren(n),this._root=n,this.classList.add(`mint-tree`),this._disabled()?this.setAttribute(`aria-disabled`,`true`):this.removeAttribute(`aria-disabled`);let d=this._keyboardFocusRestore;d&&(this._focusRow(d.id),window.scrollTo({left:d.x,top:d.y,behavior:`instant`}),requestAnimationFrame(()=>{this._keyboardFocusRestore===d&&(this._focusRow(d.id),window.scrollTo({left:d.x,top:d.y,behavior:`instant`}))}))}_countItems(e=this._items){return e.reduce((e,t)=>e+1+this._countItems(t.children||[]),0)}_createButton(e,t,n){let r=document.createElement(`mint-button`);return r.textContent=e,r.setAttribute(`variant`,t),r.setAttribute(`data-tree-command`,n),r}_createList(e,t,n){let r=document.createElement(`mint-sortable`);r.id=`${this._treeId}-list-${t??`root`}`,r.setAttribute(`group`,this._treeId),r.setAttribute(`data-tree-parent-id`,t??``),r.setAttribute(`role`,`group`),r.setAttribute(`data-tree-depth`,String(n)),r.setAttribute(`direction`,`vertical`),r.setAttribute(`gap`,`1`),r.setAttribute(`handle-selector`,`[data-mint-sortable-handle]`),r.setAttribute(`animation-duration`,`320`),r.setAttribute(`item-key-attribute`,`data-tree-id`);let i=document.createElement(`mint-stack`);i.setAttribute(`direction`,`vertical`),i.setAttribute(`gap`,`1`);for(let t of e)i.appendChild(this._createNode(t,n));return r.appendChild(i),r}_createNode(e,t){let n=String(e.id),r=Array.isArray(e.children)?e.children:[],i=e.canHaveChildren!==!1&&this._allowNesting()&&t+a(e)<this._maxDepth(),o=document.createElement(`div`);o.className=`mint-tree-node`,o.setAttribute(`data-tree-id`,n),o.setAttribute(`role`,`treeitem`),o.setAttribute(`data-mint-tree-row`,``),o.setAttribute(`aria-level`,String(t+1)),o.setAttribute(`aria-selected`,String(this._selectedId===n)),o.setAttribute(`tabindex`,this._selectedId===n||this._selectedId===null&&t===0&&this._items[0]?.id===e.id?`0`:`-1`),o.setAttribute(`aria-label`,e.label),r.length&&o.setAttribute(`aria-expanded`,String(this._expandedIds.has(n))),(e.disabled||this._disabled())&&o.setAttribute(`aria-disabled`,`true`),(e.draggable===!1||this._disabled())&&o.setAttribute(`data-sortable-disabled`,``);let s=document.createElement(`div`);s.className=`mint-tree-row`,s.setAttribute(`data-tree-id`,n);let c=document.createElement(`span`);c.className=`mint-tree-drag-handle`,c.setAttribute(`data-mint-sortable-handle`,``),c.setAttribute(`role`,`button`),c.setAttribute(`tabindex`,`-1`),c.setAttribute(`aria-label`,`Drag ${e.label} to move`);let l=document.createElement(`mint-icon`);if(l.setAttribute(`name`,`grip-dots`),l.setAttribute(`aria-hidden`,`true`),c.appendChild(l),s.appendChild(c),r.length){let t=document.createElement(`mint-button`);t.className=`mint-tree-expand`,t.setAttribute(`variant`,`ghost`),t.setAttribute(`icon`,this._expandedIds.has(n)?`caret-up`:`caret-down`),t.setAttribute(`data-tree-command`,`toggle`),t.setAttribute(`data-tree-id`,n),t.setAttribute(`aria-label`,`${this._expandedIds.has(n)?`Collapse`:`Expand`} ${e.label}`),t.setAttribute(`aria-expanded`,String(this._expandedIds.has(n))),(this._disabled()||e.disabled===!0)&&t.setAttribute(`disabled`,`true`),s.appendChild(t)}else{let e=document.createElement(`span`);e.className=`mint-tree-expand-spacer`,e.setAttribute(`aria-hidden`,`true`),s.appendChild(e)}let u=document.createElement(`span`);if(u.className=`mint-tree-label`,u.setAttribute(`data-tree-command`,`select`),u.setAttribute(`data-tree-id`,n),i&&(u.setAttribute(`data-mint-sortable-drop-container`,`${this._treeId}-list-${n}`),u.setAttribute(`data-mint-sortable-drop-end`,``)),e.icon){let t=document.createElement(`mint-icon`);t.setAttribute(`name`,String(e.icon)),t.setAttribute(`aria-hidden`,`true`),u.appendChild(t)}let d=document.createElement(`span`);if(d.className=`mint-tree-label-text`,d.textContent=e.label,u.appendChild(d),s.appendChild(u),e.metadata){let t=document.createElement(`span`);t.className=`mint-tree-metadata`,t.textContent=String(e.metadata),s.appendChild(t)}let f=document.createElement(`span`);f.className=`mint-tree-nest-target`,f.setAttribute(`data-mint-sortable-drop-container`,`${this._treeId}-list-${n}`),f.setAttribute(`data-mint-sortable-drop-end`,``),f.setAttribute(`aria-hidden`,`true`);let p=document.createElement(`mint-icon`);p.setAttribute(`name`,`arrow-right`),p.setAttribute(`aria-hidden`,`true`),f.appendChild(p),i&&s.appendChild(f);let m=this._createActions(e,i);s.appendChild(m),o.appendChild(s);let h=this._createList(r,n,t+1);return h.classList.add(`mint-tree-children`),h.hidden=!this._expandedIds.has(n),o.appendChild(h),o}_createActions(e,t){let i=document.createElement(`div`);i.className=`mint-tree-actions`;let a=`${this._treeId}-actions-trigger-${encodeURIComponent(String(e.id))}`,o=`${a}-popover`,s=document.createElement(`mint-button`);s.id=a,s.setAttribute(`variant`,`ghost`),s.setAttribute(`icon`,`ellipsis`),s.setAttribute(`aria-label`,`Actions for ${e.label}`),s.setAttribute(`aria-haspopup`,`menu`),i.appendChild(s);let c=document.createElement(`mint-popover`);c.id=o,c.setAttribute(`trigger-id`,a),c.setAttribute(`direction`,`down`),c.setAttribute(`trigger-align`,`end`),c.setAttribute(`padding`,`0.3rem`);let l=document.createElement(`div`);l.className=`mint-tree-menu`,l.setAttribute(`role`,`menu`);let u=(t,n,r=!1)=>{let i=document.createElement(`mint-button`);i.textContent=n,i.setAttribute(`variant`,`ghost`),i.setAttribute(`full-width`,`true`),i.setAttribute(`align`,`left`),i.setAttribute(`role`,`menuitem`),i.setAttribute(`data-tree-command`,t),i.setAttribute(`data-tree-id`,String(e.id)),(r||e.disabled===!0||this._disabled())&&i.setAttribute(`disabled`,`true`),l.appendChild(i)},d=Array.isArray(e.actions)?e.actions:null;if(d)for(let t of d){let n=document.createElement(`mint-button`);n.textContent=t.label,n.setAttribute(`variant`,`ghost`),n.setAttribute(`full-width`,`true`),n.setAttribute(`align`,`left`),n.setAttribute(`role`,`menuitem`),n.setAttribute(`data-tree-command`,`custom`),n.setAttribute(`data-tree-id`,String(e.id)),n.setAttribute(`data-tree-action`,t.id),(t.disabled===!0||e.disabled===!0||this._disabled())&&n.setAttribute(`disabled`,`true`),t.icon&&n.setAttribute(`icon`,t.icon),t.tone&&n.setAttribute(`tone`,t.tone),l.appendChild(n)}else{let i=r(this._items,e.id),a=i?.siblings||[],o=a.findIndex(t=>String(t.id)===String(e.id)),s=o>0?a[o-1]:null,c=i?.parentId?n(this._items,i.parentId):null;u(`move-up`,`Move up`,o<=0),u(`move-down`,`Move down`,o<0||o>=a.length-1),u(`nest-previous`,`Nest under previous item`,!s||!this._isValidDrop(String(e.id),String(s.id))),u(`outdent`,`Move to parent level`,!c),u(`create-child`,`Add child`,!t),u(`edit`,`Edit`),u(`delete`,`Delete`)}return c.appendChild(l),i.appendChild(c),i}_closeItemPopover(e){(e.closest(`.mint-tree-menu`)?.closest(`mint-popover`))?.close?.()}async _confirmDelete(e){let t=n(this._items,e);!t||!this._confirm?.showConfirm||await this._confirm.showConfirm({question:this.getAttribute(`delete-confirmation`)||`Delete “${t.label}”?`,tone:`danger`,confirmLabel:`Delete`,cancelLabel:`Cancel`})&&u(this,`mint-tree-delete`,{item:{...t},itemId:e,items:this.items})}_moveByCommand(e,t){let n=r(this._items,e);if(!n)return;let i=n.siblings.findIndex(t=>String(t.id)===e),a=n.parentId,o=i;if(t===`move-up`)o=i-1;else if(t===`move-down`)o=i+1;else if(t===`nest-previous`){let e=n.siblings[i-1];if(!e)return;a=String(e.id),o=(e.children||[]).length}else if(t===`outdent`){if(n.parentId===null)return;let e=r(this._items,n.parentId);if(!e)return;a=e.parentId,o=e.siblings.findIndex(e=>String(e.id)===n.parentId)+1}else return;try{let t=c(this._items,e,a,o,{maxDepth:this._maxDepth(),allowNesting:this._allowNesting()});this._applyMove(t)}catch{}}_applyMove(e){this._recordHistory(),this._items=e.items,this._collapseEmptyExpandedNodes(),e.newParentId&&this._expandedIds.add(e.newParentId),this._render(),this._focusRow(String(e.item.id));let t={itemId:String(e.item.id),item:{...e.item},items:this.items,oldParentId:e.oldParentId,newParentId:e.newParentId,oldIndex:e.oldIndex,newIndex:e.newIndex};u(this,`mint-tree-change`,{items:t.items,itemId:t.itemId}),u(this,t.oldParentId===t.newParentId?`mint-tree-reorder`:`mint-tree-reparent`,t),this._announce(`${t.item.label} moved${t.newParentId?` into ${n(this._items,t.newParentId)?.label||`a group`}`:` to the top level`}.`)}_select(e){if(this.classList.contains(`mint-tree-drag-active`))return;let t=n(this._items,e);!t||t.disabled||this._disabled()||(this._selectedId=e,this.setAttribute(`selected-id`,e),this._syncSelectionDOM(),u(this,`mint-tree-select`,{item:{...t},itemId:e,items:this.items}))}_syncSelectionDOM(){(this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]).forEach(e=>{let t=e.getAttribute(`data-tree-id`)===this._selectedId;e.setAttribute(`aria-selected`,String(t)),e.tabIndex=t?0:-1})}_setExpanded(e,t,r){let i=n(this._items,e);!i||i.disabled||this._disabled()||(t?this._expandedIds.add(e):this._expandedIds.delete(e),this._syncNodeExpanded(e),r&&u(this,t?`mint-tree-expand`:`mint-tree-collapse`,{itemId:e,item:{...i},expandedIds:this.expandedIds}))}_syncExpandedDOM(){this._root?.querySelectorAll(`[data-mint-tree-row]`).forEach(e=>this._syncNodeExpanded(e.getAttribute(`data-tree-id`)||``))}_syncNodeExpanded(e){let t=[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].find(t=>t.getAttribute(`data-tree-id`)===e),r=t?.querySelector(`:scope > mint-sortable.mint-tree-children`);if(!t||!r)return;let i=this._expandedIds.has(e);t.setAttribute(`aria-expanded`,String(i));let a=t.querySelector(`[data-tree-command="toggle"]`);a?.setAttribute(`aria-expanded`,String(i)),a?.setAttribute(`aria-label`,`${i?`Collapse`:`Expand`} ${n(this._items,e)?.label||`item`}`),a?.setAttribute(`icon`,i?`caret-up`:`caret-down`),r.hidden=!i}_setTransientExpanded(e,t){let r=[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].find(t=>t.getAttribute(`data-tree-id`)===e);if(!r)return;r.setAttribute(`aria-expanded`,String(t));let i=r.querySelector(`[data-tree-command="toggle"]`),a=n(this._items,e)?.label||`item`;i?.setAttribute(`aria-expanded`,String(t)),i?.setAttribute(`aria-label`,`${t?`Collapse`:`Expand`} ${a}`),i?.setAttribute(`icon`,t?`caret-up`:`caret-down`)}_isValidDrop(e,t){let r=n(this._items,e);if(!r)return!1;let i=t===null?null:n(this._items,t);return!(t!==null&&!i||i?.disabled||i&&(String(i.id)===e||this._isDescendant(r,i.id))||!this._allowNesting()&&i||i?.canHaveChildren===!1||i?.acceptsTypes?.length&&!i.acceptsTypes.includes(r.type||``)||(i?this._depthOf(String(i.id)):-1)+1+a(r)>this._maxDepth())}_isDescendant(e,t){return(e.children||[]).some(e=>String(e.id)===String(t)||this._isDescendant(e,t))}_depthOf(e){let t=r(this._items,e);return t?this._depthOfParent(t.parentId):-1}_depthOfParent(e){if(e===null)return 0;let t=r(this._items,e);return t?this._depthOfParent(t.parentId)+1:0}_readItemsFromDOM(e){let t=e.querySelector(`:scope > mint-stack`);return t?[...t.children].filter(e=>e instanceof HTMLElement&&e.classList.contains(`mint-tree-node`)).map(e=>{let t=e.getAttribute(`data-tree-id`)||``,r=n(this._items,t),i=e.querySelector(`:scope > mint-sortable.mint-tree-children`);return{...r||{id:t,label:t},children:i?this._readItemsFromDOM(i):[]}}):[]}_clearDropState(){this._root?.querySelectorAll(`.mint-tree-drop-invalid`).forEach(e=>e.classList.remove(`mint-tree-drop-invalid`))}_collapseEmptyExpandedNodes(){for(let e of[...this._expandedIds]){let t=n(this._items,e);!t||t.children?.length||(this._expandedIds.delete(e),this._syncNodeExpanded(e),u(this,`mint-tree-collapse`,{itemId:e,item:{...t},expandedIds:this.expandedIds,automatic:!0,empty:!0}))}}_announce(e){this._liveRegion&&(this._liveRegion.textContent=e)}_recordHistory(){this._undoStack.push(t(this._items)),this._undoStack.length>50&&this._undoStack.shift(),this._redoStack=[]}_undo(){let e=this._undoStack.pop();if(!e)return;let n=this._items;this._redoStack.push(t(this._items)),this._items=e,this._collapseEmptyExpandedNodes(),this._render(),this._emitHistoryChange(n),u(this,`mint-tree-undo`,{items:this.items})}_redo(){let e=this._redoStack.pop();if(!e)return;let n=this._items;this._undoStack.push(t(this._items)),this._items=e,this._collapseEmptyExpandedNodes(),this._render(),this._emitHistoryChange(n),u(this,`mint-tree-redo`,{items:this.items})}_emitHistoryChange(e){let t=this.items,n=e=>{let t=new Map,n=(e,r)=>e.forEach((e,i)=>{let a=String(e.id);t.set(a,{parentId:r,index:i,item:e}),n(e.children||[],a)});return n(e,null),t},r=n(e),i=n(this._items),a=[...new Set([...r.keys(),...i.keys()])].find(e=>{let t=r.get(e),n=i.get(e);return t&&n&&(t.parentId!==n.parentId||t.index!==n.index)});if(u(this,`mint-tree-change`,{items:t,itemId:this._selectedId}),!a)return;let o=r.get(a),s=i.get(a),c={itemId:a,item:{...s.item},items:t,oldParentId:o.parentId,newParentId:s.parentId,oldIndex:o.index,newIndex:s.index};u(this,o.parentId===s.parentId?`mint-tree-reorder`:`mint-tree-reparent`,c)}_keyboardIndent(e){let t=r(this._items,e);if(!t||t.siblings.indexOf(t.item)<=0)return;let n=t.siblings[t.siblings.indexOf(t.item)-1];try{let t=c(this._items,e,n.id,(n.children||[]).length,{maxDepth:this._maxDepth(),allowNesting:this._allowNesting()});this._recordHistory(),this._items=t.items,this._collapseEmptyExpandedNodes(),this._expandedIds.add(String(n.id)),this._render(),this._focusRow(e),u(this,`mint-tree-reparent`,{itemId:e,item:{...t.item},items:this.items,oldParentId:t.oldParentId,newParentId:t.newParentId,oldIndex:t.oldIndex,newIndex:t.newIndex})}catch{}}_keyboardOutdent(e){let t=r(this._items,e);if(!t||t.parentId===null)return;let n=r(this._items,t.parentId);if(!n)return;let i=n.siblings.findIndex(e=>String(e.id)===t.parentId)+1;try{let t=c(this._items,e,n.parentId,i,{maxDepth:this._maxDepth(),allowNesting:this._allowNesting()});this._recordHistory(),this._items=t.items,this._collapseEmptyExpandedNodes(),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-B9P0jyS2.js`);const e=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/spinner-CUcCgLKS.js`),require(`../chunks/button-B4BMYTk1.js`),require(`../chunks/confirm-action-sovGys0x.js`),require(`../chunks/popover-CWWKb7L1.js`),require(`../chunks/sortable-Bxg81mcs.js`);function t(e=[]){s(e);let t=e=>e.map(e=>({...e,children:Array.isArray(e.children)?t(e.children):[]}));return t(e)}function n(e,t){let r=String(t);for(let t of e){if(String(t.id)===r)return t;let e=n(t.children||[],r);if(e)return e}return null}function r(e,t,n=null){let i=String(t);for(let t of e){if(String(t.id)===i)return{parentId:n,siblings:e,item:t};let a=r(t.children||[],i,String(t.id));if(a)return a}return null}function i(e,t,n=0){let r=String(t);for(let t of e){if(String(t.id)===r)return n;let e=i(t.children||[],r,n+1);if(e>=0)return e}return-1}function a(e){let t=Array.isArray(e?.children)?e.children:[];return t.length?1+Math.max(...t.map(a)):1}function o(e,t){return String(e.id)===String(t)?!0:(e.children||[]).some(e=>o(e,t))}function s(e){let t=new Set,n=e=>{for(let r of e){if(r.id===null||r.id===void 0||String(r.id)===``)throw Error(`Every tree item must have a non-empty identifier.`);let e=String(r.id);if(t.has(e))throw Error(`Tree item identifiers must be unique. Duplicate identifier: ${e}.`);t.add(e),n(r.children||[])}};n(e)}function c(e,s,c,l,u={}){let d=t(e),f=r(d,s);if(!f)throw Error(`Tree item ${s} was not found.`);if(f.item.disabled||f.item.draggable===!1)throw Error(`Disabled tree items cannot be moved.`);let p=c==null||c===``?null:n(d,c);if(c!=null&&c!==``&&!p)throw Error(`Target parent ${c} was not found.`);if(p&&o(f.item,p.id))throw Error(`A tree item cannot be moved inside itself or one of its descendants.`);if(p?.disabled)throw Error(`Disabled tree items cannot contain children.`);if(u.allowNesting===!1&&p)throw Error(`Nesting is disabled for this tree.`);if(p?.canHaveChildren===!1)throw Error(`The target item cannot contain children.`);if(p?.acceptsTypes?.length&&!p.acceptsTypes.includes(f.item.type))throw Error(`The target item does not accept this item type.`);let m=p?p.children:d,h=f.siblings.findIndex(e=>String(e.id)===String(s)),[g]=f.siblings.splice(h,1),_=Math.min(Math.max(0,Number.isFinite(l)?Math.trunc(l):m.length),m.length);m.splice(_,0,g);let v=Number.isFinite(u.maxDepth)?Math.max(1,Math.trunc(u.maxDepth)):1/0;if((p?i(d,p.id)+1:0)+a(g)>v)throw Error(`Moving this branch would exceed the maximum tree depth of ${v}.`);return{items:d,item:g,oldParentId:f.parentId,newParentId:p?String(p.id):null,oldIndex:h,newIndex:_}}var l=0;function u(e,t,n){e.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:n}))}function d(e,t){let n=e.getAttribute(t);return n===``||n===`true`}function f(e){return e==null||e===``?null:String(e)}var p=class extends HTMLElement{constructor(...e){super(...e),this._items=[],this._undoStack=[],this._redoStack=[],this._selectedId=null,this._expandedIds=new Set,this._root=null,this._confirm=null,this._treeId=`mint-tree-${++l}`,this._liveRegion=null,this._dragExpansion=null,this._autoExpandedIds=new Set,this._dragHoverExpandedId=null,this._keyboardFocusRestore=null,this._suppressSelectionClick=!1,this._selectionClickSuppressionTimer=null,this._onClick=e=>{let t=e.target instanceof Element?e.target.closest(`[data-tree-command]`):null;if(!t||!this.contains(t))return;let r=t.getAttribute(`data-tree-command`),i=t.getAttribute(`data-tree-id`);if(r===`create-root`)u(this,`mint-tree-create`,{parentId:null,items:this.items});else if(r===`expand-all`)this._expandedIds=this._defaultExpandedIds(this._items),this._syncExpandedDOM(),u(this,`mint-tree-expand`,{all:!0,expandedIds:this.expandedIds});else if(r===`collapse-all`)this._expandedIds.clear(),this._syncExpandedDOM(),u(this,`mint-tree-collapse`,{all:!0,expandedIds:[]});else if(r===`undo`)this._undo();else if(r===`redo`)this._redo();else if(r===`toggle`&&i){let e=!this._expandedIds.has(i);this._setExpanded(i,e,!0)}else if(r===`select`&&i){if(this.classList.contains(`mint-tree-drag-active`)||this._suppressSelectionClick){e.preventDefault(),this._suppressSelectionClick=!1,this._selectionClickSuppressionTimer!==null&&window.clearTimeout(this._selectionClickSuppressionTimer),this._selectionClickSuppressionTimer=null;return}this._select(i)}else if(r===`create-child`&&i)this._closeItemPopover(t),u(this,`mint-tree-create`,{parentId:i,items:this.items});else if(r===`edit`&&i){this._closeItemPopover(t);let e=n(this._items,i);e&&u(this,`mint-tree-edit`,{item:{...e},itemId:i,items:this.items})}else if(r===`delete`&&i)this._closeItemPopover(t),this._confirmDelete(i);else if([`move-up`,`move-down`,`nest-previous`,`outdent`].includes(r||``)&&i)this._closeItemPopover(t),this._moveByCommand(i,r||``);else if(r===`custom`&&i){this._closeItemPopover(t);let e=n(this._items,i),r=t.getAttribute(`data-tree-action`)||``,a=e?.actions?.find(e=>e.id===r);if(e&&a){let t={item:{...e},itemId:i,action:{...a,onSelect:void 0},items:this.items};u(this,`mint-tree-action`,t),a.onSelect?.({item:{...e},itemId:i,action:a,items:this.items})}}},this._onSortableDrag=e=>{let t=e.detail;if(!t||!Number.isFinite(t.clientX)||!Number.isFinite(t.clientY))return;let r=document.elementFromPoint(t.clientX,t.clientY),i=r?.closest(`[data-mint-tree-row]`),a=t.item?.getAttribute(`data-tree-id`)||``,o=null;if(i&&i.getAttribute(`data-tree-id`)!==a){let e=i.querySelector(`:scope > .mint-tree-row`)?.getBoundingClientRect()||i.getBoundingClientRect(),r=e.height?(t.clientY-e.top)/e.height:0;if(r>.22&&r<.78){let e=i.getAttribute(`data-tree-id`)||``;n(this._items,e)&&this._isValidDrop(a,e)&&(o=e)}}if(!o&&this._dragHoverExpandedId){let e=[...this._root?.querySelectorAll(`[data-tree-id]`)??[]].find(e=>e.getAttribute(`data-tree-id`)===this._dragHoverExpandedId)?.querySelector(`:scope > mint-sortable.mint-tree-children`);r&&e?.contains(r)&&(o=this._dragHoverExpandedId)}if(this._dragHoverExpandedId&&this._dragHoverExpandedId!==o){let e=this._dragHoverExpandedId;this._dragHoverExpandedId=null,this._autoExpandedIds.delete(e),this._expandedIds.delete(e),this._syncNodeExpanded(e);let t=n(this._items,e);t&&u(this,`mint-tree-collapse`,{itemId:e,item:{...t},expandedIds:this.expandedIds,automatic:!0})}if(o){let e=n(this._items,o);e&&!this._expandedIds.has(o)&&(this._expandedIds.add(o),this._autoExpandedIds.add(o),this._dragHoverExpandedId=o,this._syncNodeExpanded(o),u(this,`mint-tree-expand`,{itemId:o,item:{...e},expandedIds:this.expandedIds,automatic:!0}))}},this._onSortableStart=()=>{this.classList.add(`mint-tree-drag-active`),this._dragHoverExpandedId=null,this._dragExpansion?.timer!==null&&this._dragExpansion?.timer!==void 0&&window.clearTimeout(this._dragExpansion.timer),this._dragExpansion=null;let e=this._root?.querySelector(`.mint-sortable-dragging[data-tree-id]`),t=e?.getAttribute(`data-tree-id`)||``,n=e?.querySelector(`:scope > mint-sortable.mint-tree-children`);if(!e||!t||!n||n.hidden||!this._expandedIds.has(t))return;let r=e.querySelector(`:scope > .mint-tree-row`),i=this._root?.querySelector(`.mint-sortable-placeholder`),a=n.getBoundingClientRect().height;n.style.height=`${a}px`,n.style.overflow=`hidden`,e.style.height=`auto`,e.style.overflow=`hidden`,this._dragExpansion={itemId:t,item:e,childList:n,timer:null},this._setTransientExpanded(t,!1),n.offsetHeight,requestAnimationFrame(()=>{this._dragExpansion?.childList===n&&(n.classList.add(`mint-tree-drag-collapse`),n.style.height=`0px`,i&&r&&(i.style.minHeight=`${r.getBoundingClientRect().height}px`))})},this._onSortableEnd=e=>{this.classList.remove(`mint-tree-drag-active`),this._suppressSelectionClick=!0,this._selectionClickSuppressionTimer!==null&&window.clearTimeout(this._selectionClickSuppressionTimer),this._selectionClickSuppressionTimer=window.setTimeout(()=>{this._suppressSelectionClick=!1,this._selectionClickSuppressionTimer=null},300);let t=e.detail,r=t&&!t.cancelled?f(t.newParentId):null;for(let e of this._autoExpandedIds){if(e===r)continue;this._expandedIds.delete(e),this._syncNodeExpanded(e);let t=n(this._items,e);t&&u(this,`mint-tree-collapse`,{itemId:e,item:{...t},expandedIds:this.expandedIds,automatic:!0})}this._autoExpandedIds.clear(),this._dragHoverExpandedId=null;let i=this._dragExpansion;if(!i)return;i.item=[...this._root?.querySelectorAll(`[data-tree-id]`)??[]].find(e=>e.getAttribute(`data-tree-id`)===i.itemId)||i.item,i.childList=i.item.querySelector(`:scope > mint-sortable.mint-tree-children`)||i.childList;let{item:a,childList:o,itemId:s}=i;o.style.height=`0px`,o.style.overflow=`hidden`,o.classList.remove(`mint-tree-drag-collapse`),this._setTransientExpanded(s,!0),o.offsetHeight;let c=o.scrollHeight;requestAnimationFrame(()=>{this._dragExpansion===i&&(o.style.height=`${c}px`)}),i.timer=window.setTimeout(()=>{o.style.height=``,o.style.overflow=``,o.style.opacity=``,this._dragExpansion=null},155)},this._onSortableDragOver=e=>{let t=e,{item:r,target:i}=t.detail||{};if(!r||!i)return;this._root?.querySelectorAll(`.mint-tree-drop-invalid`).forEach(e=>e.classList.remove(`mint-tree-drop-invalid`));let a=this._root?.querySelector(`.mint-sortable-placeholder`),o=r.getAttribute(`data-tree-id`)||``,s=f(i.getAttribute(`data-tree-parent-id`)),c=i===t.detail.source||this._isValidDrop(o,s),l=s?n(this._items,s):null;c&&i!==t.detail.source&&l?a?.setAttribute(`data-drop-label`,`Drop here to nest under ${l.label}`):c&&i===this._root?.querySelector(`:scope > mint-sortable`)?a?.setAttribute(`data-drop-label`,`Drop here to move to the top level`):a?.removeAttribute(`data-drop-label`);let u=(Number.isFinite(t.detail.clientX)&&Number.isFinite(t.detail.clientY)?document.elementFromPoint(t.detail.clientX,t.detail.clientY):null)?.closest(`[data-mint-tree-row]`);u&&u.getAttribute(`data-tree-id`)!==o&&!c&&u.classList.add(`mint-tree-drop-invalid`),c||t.preventDefault()},this._onSortableBeforeDrop=e=>{let t=e,n=t.detail;if(!n?.item||!n.target)return;let r=n.item.getAttribute(`data-tree-id`)||``,i=f(n.target.getAttribute(`data-tree-parent-id`));n.target!==n.source&&!this._isValidDrop(r,i)&&t.preventDefault()},this._onSortableChange=e=>{let t=e.detail;if(!t||t.cancelled)return;let r=t.itemId||``,i=f(t.oldParentId),a=f(t.newParentId),o=this._root?.querySelector(`:scope > mint-sortable`);if(!o)return;let s=n(this._items,r);this._recordHistory(),this._items=this._readItemsFromDOM(o),this._collapseEmptyExpandedNodes();let c=n(this._items,r);if(!c||!s)return;let l={itemId:r,item:{...c},items:this.items,oldParentId:i,newParentId:a,oldIndex:Number(t.oldIndex??-1),newIndex:Number(t.newIndex??-1)};this._clearDropState(),u(this,`mint-tree-change`,{items:l.items,itemId:r}),i===a?u(this,`mint-tree-reorder`,l):u(this,`mint-tree-reparent`,l);let d=`${c.label} moved${a?` into ${n(this._items,a)?.label||`a group`}`:` to the top level`}.`;this._dragExpansion?.itemId===r?window.setTimeout(()=>{this.isConnected&&(this._render(),this._focusRow(r),this._announce(d))},155):(this._render(),this._focusRow(r),this._announce(d))},this._onKeydown=e=>{let t=e.target instanceof Element?e.target.closest(`[data-mint-tree-row]`):null;if(!t)return;if(e.altKey&&[`ArrowUp`,`ArrowDown`].includes(e.key)){e.preventDefault();let n=t.getAttribute(`data-tree-id`)||``;if(n){this._keyboardFocusRestore&&window.clearTimeout(this._keyboardFocusRestore.timer);let e={id:n,x:window.scrollX,y:window.scrollY,timer:0};e.timer=window.setTimeout(()=>{this._keyboardFocusRestore===e&&(this._keyboardFocusRestore=null)},2e3),this._keyboardFocusRestore=e}return}let i=t.getAttribute(`data-tree-id`)||``;if(e.altKey&&e.key===`ArrowRight`){e.preventDefault(),this._keyboardIndent(i);return}if(e.altKey&&e.key===`ArrowLeft`){e.preventDefault(),this._keyboardOutdent(i);return}let a=[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].filter(e=>!e.closest(`mint-sortable[hidden]`)),o=a.indexOf(t);if(e.key===`ArrowDown`)e.preventDefault(),a[o+1]?.focus({preventScroll:!0});else if(e.key===`ArrowUp`)e.preventDefault(),a[o-1]?.focus({preventScroll:!0});else if(e.key===`ArrowRight`)e.preventDefault(),this._expandedIds.has(i)?a[o+1]?.focus({preventScroll:!0}):this._setExpanded(i,!0,!0);else if(e.key===`ArrowLeft`)if(e.preventDefault(),this._expandedIds.has(i))this._setExpanded(i,!1,!0);else{let e=r(this._items,i)?.parentId;e&&[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].find(t=>t.getAttribute(`data-tree-id`)===e)?.focus({preventScroll:!0})}else if(e.key===`Enter`||e.key===` `||e.key===`Spacebar`){let r=e.target instanceof Element?e.target.closest(`[data-tree-command="select"]`):null;(t===e.target||r)&&(e.preventDefault(),n(this._items,i)?.children?.length?this._setExpanded(i,!this._expandedIds.has(i),!0):this._select(i))}}}static get observedAttributes(){return[`selected-id`,`max-depth`,`allow-nesting`,`disabled`,`loading`,`create-label`,`empty-label`,`delete-confirmation`,`expanded-ids`]}connectedCallback(){this._root||(this._selectedId=f(this.getAttribute(`selected-id`)),this._expandedIds=this.hasAttribute(`expanded-ids`)?this._readExpandedIds(this.getAttribute(`expanded-ids`)):this._defaultExpandedIds(this._items),this.addEventListener(`click`,this._onClick),this.addEventListener(`keydown`,this._onKeydown,!0),this.addEventListener(`mint-sortable-start`,this._onSortableStart),this.addEventListener(`mint-sortable-end`,this._onSortableEnd),this.addEventListener(`mint-sortable-drag`,this._onSortableDrag),this.addEventListener(`mint-sortable-drag-over`,this._onSortableDragOver),this.addEventListener(`mint-sortable-before-drop`,this._onSortableBeforeDrop),this.addEventListener(`mint-sortable-change`,this._onSortableChange),this._render())}disconnectedCallback(){this._dragExpansion?.timer!==null&&this._dragExpansion?.timer!==void 0&&window.clearTimeout(this._dragExpansion.timer),this._keyboardFocusRestore&&window.clearTimeout(this._keyboardFocusRestore.timer),this._selectionClickSuppressionTimer!==null&&window.clearTimeout(this._selectionClickSuppressionTimer),this._selectionClickSuppressionTimer=null,this._suppressSelectionClick=!1,this._keyboardFocusRestore=null,this._dragExpansion=null,this._autoExpandedIds.clear(),this._dragHoverExpandedId=null,this.classList.remove(`mint-tree-drag-active`),this.removeEventListener(`click`,this._onClick),this.removeEventListener(`keydown`,this._onKeydown,!0),this.removeEventListener(`mint-sortable-start`,this._onSortableStart),this.removeEventListener(`mint-sortable-end`,this._onSortableEnd),this.removeEventListener(`mint-sortable-drag`,this._onSortableDrag),this.removeEventListener(`mint-sortable-drag-over`,this._onSortableDragOver),this.removeEventListener(`mint-sortable-before-drop`,this._onSortableBeforeDrop),this.removeEventListener(`mint-sortable-change`,this._onSortableChange),this._root=null}attributeChangedCallback(e,t,n){if(!(t===n||!this.isConnected)){if(e===`selected-id`){this._selectedId=f(n),this._syncSelectionDOM();return}e===`expanded-ids`&&(this._expandedIds=this._readExpandedIds(n)),this._render()}}get items(){return t(this._items)}set items(e){this._items=t(Array.isArray(e)?e:[]),this._undoStack=[],this._redoStack=[],this.hasAttribute(`expanded-ids`)?this._collapseEmptyExpandedNodes():this._expandedIds=this._defaultExpandedIds(this._items),this.isConnected&&this._render()}get selectedId(){return this._selectedId}set selectedId(e){this._selectedId=f(e),this._selectedId===null?this.removeAttribute(`selected-id`):this.setAttribute(`selected-id`,this._selectedId)}get expandedIds(){return[...this._expandedIds]}set expandedIds(e){this._expandedIds=new Set((Array.isArray(e)?e:[]).map(String)),this.isConnected&&this._render()}save(){u(this,`mint-tree-save`,{items:this.items})}select(e){this._select(String(e))}expand(e){this._setExpanded(String(e),!0,!0)}collapse(e){this._setExpanded(String(e),!1,!0)}_readExpandedIds(e){if(!e)return this._defaultExpandedIds(this._items);try{let t=JSON.parse(e);return new Set(Array.isArray(t)?t.map(String):[])}catch{return new Set(e.split(`,`).map(e=>e.trim()).filter(Boolean))}}_defaultExpandedIds(e){let t=new Set,n=e=>e.forEach(e=>{e.children?.length&&(t.add(String(e.id)),n(e.children))});return n(e),t}_maxDepth(){let e=Number.parseInt(this.getAttribute(`max-depth`)||``,10);return Number.isFinite(e)&&e>0?e:1/0}_allowNesting(){return!this.hasAttribute(`allow-nesting`)||d(this,`allow-nesting`)}_disabled(){return d(this,`disabled`)}_isLoading(){return d(this,`loading`)}_render(){let e=document.activeElement instanceof HTMLElement?document.activeElement.closest(`[data-mint-tree-row]`):null,t=e&&this.contains(e)?e.getAttribute(`data-tree-id`):null;t&&this._keyboardFocusRestore&&(this._keyboardFocusRestore.id=t);let n=document.createElement(`div`);n.className=`mint-tree-shell`,n.setAttribute(`role`,`tree`),n.setAttribute(`aria-label`,this.getAttribute(`aria-label`)||`Hierarchical items`),n.setAttribute(`aria-busy`,String(this._isLoading()));let r=document.createElement(`div`);r.className=`mint-tree-toolbar`;let i=document.createElement(`span`);i.className=`mint-tree-count`,i.textContent=`${this._countItems()} ${this._countItems()===1?`item`:`items`}`,r.appendChild(i);let a=document.createElement(`div`);a.className=`mint-tree-toolbar-actions`;let o=this._createButton(``,`ghost`,`undo`);o.setAttribute(`icon`,`undo`),o.setAttribute(`aria-label`,`Undo last change`),o.setAttribute(`title`,`Undo`),(!this._undoStack.length||this._disabled())&&o.setAttribute(`disabled`,`true`);let s=this._createButton(``,`ghost`,`redo`);s.setAttribute(`icon`,`redo`),s.setAttribute(`aria-label`,`Redo last undone change`),s.setAttribute(`title`,`Redo`),(!this._redoStack.length||this._disabled())&&s.setAttribute(`disabled`,`true`);let c=this._createButton(``,`ghost`,`expand-all`);c.setAttribute(`icon`,`expand`),c.setAttribute(`aria-label`,`Expand all`),c.setAttribute(`title`,`Expand all`);let l=this._createButton(``,`ghost`,`collapse-all`);if(l.setAttribute(`icon`,`collapse`),l.setAttribute(`aria-label`,`Collapse all`),l.setAttribute(`title`,`Collapse all`),a.append(o,s,c,l),r.appendChild(a),n.appendChild(r),this._isLoading()){let e=document.createElement(`div`);e.className=`mint-tree-loading`,e.setAttribute(`aria-label`,`Loading items`);let t=document.createElement(`mint-spinner`);t.setAttribute(`size`,`small`),e.appendChild(t),n.appendChild(e)}else if(this._items.length)n.appendChild(this._createList(this._items,null,0));else{let e=document.createElement(`div`);e.className=`mint-tree-empty`,e.textContent=this.getAttribute(`empty-label`)||`No items yet.`,n.appendChild(e)}this._liveRegion=document.createElement(`div`),this._liveRegion.className=`mint-tree-live-region`,this._liveRegion.setAttribute(`role`,`status`),this._liveRegion.setAttribute(`aria-live`,`polite`),this._liveRegion.setAttribute(`aria-atomic`,`true`),n.appendChild(this._liveRegion);let u=document.createElement(`mint-confirm-action`);u.className=`mint-tree-confirm`,this._confirm=u,n.appendChild(u),this.replaceChildren(n),this._root=n,this.classList.add(`mint-tree`),this._disabled()?this.setAttribute(`aria-disabled`,`true`):this.removeAttribute(`aria-disabled`);let d=this._keyboardFocusRestore;d&&(this._focusRow(d.id),window.scrollTo({left:d.x,top:d.y,behavior:`instant`}),requestAnimationFrame(()=>{this._keyboardFocusRestore===d&&(this._focusRow(d.id),window.scrollTo({left:d.x,top:d.y,behavior:`instant`}))}))}_countItems(e=this._items){return e.reduce((e,t)=>e+1+this._countItems(t.children||[]),0)}_createButton(e,t,n){let r=document.createElement(`mint-button`);return r.textContent=e,r.setAttribute(`variant`,t),r.setAttribute(`data-tree-command`,n),r}_createList(e,t,n){let r=document.createElement(`mint-sortable`);r.id=`${this._treeId}-list-${t??`root`}`,r.setAttribute(`group`,this._treeId),r.setAttribute(`data-tree-parent-id`,t??``),r.setAttribute(`role`,`group`),r.setAttribute(`data-tree-depth`,String(n)),r.setAttribute(`direction`,`vertical`),r.setAttribute(`gap`,`1`),r.setAttribute(`handle-selector`,`[data-mint-sortable-handle]`),r.setAttribute(`animation-duration`,`320`),r.setAttribute(`item-key-attribute`,`data-tree-id`);let i=document.createElement(`mint-stack`);i.setAttribute(`direction`,`vertical`),i.setAttribute(`gap`,`1`);for(let t of e)i.appendChild(this._createNode(t,n));return r.appendChild(i),r}_createNode(e,t){let n=String(e.id),r=Array.isArray(e.children)?e.children:[],i=e.canHaveChildren!==!1&&this._allowNesting()&&t+a(e)<this._maxDepth(),o=document.createElement(`div`);o.className=`mint-tree-node`,o.setAttribute(`data-tree-id`,n),o.setAttribute(`role`,`treeitem`),o.setAttribute(`data-mint-tree-row`,``),o.setAttribute(`aria-level`,String(t+1)),o.setAttribute(`aria-selected`,String(this._selectedId===n)),o.setAttribute(`tabindex`,this._selectedId===n||this._selectedId===null&&t===0&&this._items[0]?.id===e.id?`0`:`-1`),o.setAttribute(`aria-label`,e.label),r.length&&o.setAttribute(`aria-expanded`,String(this._expandedIds.has(n))),(e.disabled||this._disabled())&&o.setAttribute(`aria-disabled`,`true`),(e.draggable===!1||this._disabled())&&o.setAttribute(`data-sortable-disabled`,``);let s=document.createElement(`div`);s.className=`mint-tree-row`,s.setAttribute(`data-tree-id`,n);let c=document.createElement(`span`);c.className=`mint-tree-drag-handle`,c.setAttribute(`data-mint-sortable-handle`,``),c.setAttribute(`role`,`button`),c.setAttribute(`tabindex`,`-1`),c.setAttribute(`aria-label`,`Drag ${e.label} to move`);let l=document.createElement(`mint-icon`);if(l.setAttribute(`name`,`grip-dots`),l.setAttribute(`aria-hidden`,`true`),c.appendChild(l),s.appendChild(c),r.length){let t=document.createElement(`mint-button`);t.className=`mint-tree-expand`,t.setAttribute(`variant`,`ghost`),t.setAttribute(`icon`,this._expandedIds.has(n)?`caret-up`:`caret-down`),t.setAttribute(`data-tree-command`,`toggle`),t.setAttribute(`data-tree-id`,n),t.setAttribute(`aria-label`,`${this._expandedIds.has(n)?`Collapse`:`Expand`} ${e.label}`),t.setAttribute(`aria-expanded`,String(this._expandedIds.has(n))),(this._disabled()||e.disabled===!0)&&t.setAttribute(`disabled`,`true`),s.appendChild(t)}else{let e=document.createElement(`span`);e.className=`mint-tree-expand-spacer`,e.setAttribute(`aria-hidden`,`true`),s.appendChild(e)}let u=document.createElement(`span`);if(u.className=`mint-tree-label`,u.setAttribute(`data-tree-command`,`select`),u.setAttribute(`data-tree-id`,n),i&&(u.setAttribute(`data-mint-sortable-drop-container`,`${this._treeId}-list-${n}`),u.setAttribute(`data-mint-sortable-drop-end`,``)),e.icon){let t=document.createElement(`mint-icon`);t.setAttribute(`name`,String(e.icon)),t.setAttribute(`aria-hidden`,`true`),u.appendChild(t)}let d=document.createElement(`span`);if(d.className=`mint-tree-label-text`,d.textContent=e.label,u.appendChild(d),s.appendChild(u),e.metadata){let t=document.createElement(`span`);t.className=`mint-tree-metadata`,t.textContent=String(e.metadata),s.appendChild(t)}let f=document.createElement(`span`);f.className=`mint-tree-nest-target`,f.setAttribute(`data-mint-sortable-drop-container`,`${this._treeId}-list-${n}`),f.setAttribute(`data-mint-sortable-drop-end`,``),f.setAttribute(`aria-hidden`,`true`);let p=document.createElement(`mint-icon`);p.setAttribute(`name`,`arrow-right`),p.setAttribute(`aria-hidden`,`true`),f.appendChild(p),i&&s.appendChild(f);let m=this._createActions(e,i);s.appendChild(m),o.appendChild(s);let h=this._createList(r,n,t+1);return h.classList.add(`mint-tree-children`),h.hidden=!this._expandedIds.has(n),o.appendChild(h),o}_createActions(e,t){let i=document.createElement(`div`);i.className=`mint-tree-actions`;let a=`${this._treeId}-actions-trigger-${encodeURIComponent(String(e.id))}`,o=`${a}-popover`,s=document.createElement(`mint-button`);s.id=a,s.setAttribute(`variant`,`ghost`),s.setAttribute(`icon`,`ellipsis`),s.setAttribute(`aria-label`,`Actions for ${e.label}`),s.setAttribute(`aria-haspopup`,`menu`),i.appendChild(s);let c=document.createElement(`mint-popover`);c.id=o,c.setAttribute(`trigger-id`,a),c.setAttribute(`direction`,`down`),c.setAttribute(`trigger-align`,`end`),c.setAttribute(`padding`,`0.3rem`);let l=document.createElement(`div`);l.className=`mint-tree-menu`,l.setAttribute(`role`,`menu`);let u=(t,n,r=!1)=>{let i=document.createElement(`mint-button`);i.textContent=n,i.setAttribute(`variant`,`ghost`),i.setAttribute(`full-width`,`true`),i.setAttribute(`align`,`left`),i.setAttribute(`role`,`menuitem`),i.setAttribute(`data-tree-command`,t),i.setAttribute(`data-tree-id`,String(e.id)),(r||e.disabled===!0||this._disabled())&&i.setAttribute(`disabled`,`true`),l.appendChild(i)},d=Array.isArray(e.actions)?e.actions:null;if(d)for(let t of d){let n=document.createElement(`mint-button`);n.textContent=t.label,n.setAttribute(`variant`,`ghost`),n.setAttribute(`full-width`,`true`),n.setAttribute(`align`,`left`),n.setAttribute(`role`,`menuitem`),n.setAttribute(`data-tree-command`,`custom`),n.setAttribute(`data-tree-id`,String(e.id)),n.setAttribute(`data-tree-action`,t.id),(t.disabled===!0||e.disabled===!0||this._disabled())&&n.setAttribute(`disabled`,`true`),t.icon&&n.setAttribute(`icon`,t.icon),t.tone&&n.setAttribute(`tone`,t.tone),l.appendChild(n)}else{let i=r(this._items,e.id),a=i?.siblings||[],o=a.findIndex(t=>String(t.id)===String(e.id)),s=o>0?a[o-1]:null,c=i?.parentId?n(this._items,i.parentId):null;u(`move-up`,`Move up`,o<=0),u(`move-down`,`Move down`,o<0||o>=a.length-1),u(`nest-previous`,`Nest under previous item`,!s||!this._isValidDrop(String(e.id),String(s.id))),u(`outdent`,`Move to parent level`,!c),u(`create-child`,`Add child`,!t),u(`edit`,`Edit`),u(`delete`,`Delete`)}return c.appendChild(l),i.appendChild(c),i}_closeItemPopover(e){(e.closest(`.mint-tree-menu`)?.closest(`mint-popover`))?.close?.()}async _confirmDelete(e){let t=n(this._items,e);!t||!this._confirm?.showConfirm||await this._confirm.showConfirm({question:this.getAttribute(`delete-confirmation`)||`Delete “${t.label}”?`,tone:`danger`,confirmLabel:`Delete`,cancelLabel:`Cancel`})&&u(this,`mint-tree-delete`,{item:{...t},itemId:e,items:this.items})}_moveByCommand(e,t){let n=r(this._items,e);if(!n)return;let i=n.siblings.findIndex(t=>String(t.id)===e),a=n.parentId,o=i;if(t===`move-up`)o=i-1;else if(t===`move-down`)o=i+1;else if(t===`nest-previous`){let e=n.siblings[i-1];if(!e)return;a=String(e.id),o=(e.children||[]).length}else if(t===`outdent`){if(n.parentId===null)return;let e=r(this._items,n.parentId);if(!e)return;a=e.parentId,o=e.siblings.findIndex(e=>String(e.id)===n.parentId)+1}else return;try{let t=c(this._items,e,a,o,{maxDepth:this._maxDepth(),allowNesting:this._allowNesting()});this._applyMove(t)}catch{}}_applyMove(e){this._recordHistory(),this._items=e.items,this._collapseEmptyExpandedNodes(),e.newParentId&&this._expandedIds.add(e.newParentId),this._render(),this._focusRow(String(e.item.id));let t={itemId:String(e.item.id),item:{...e.item},items:this.items,oldParentId:e.oldParentId,newParentId:e.newParentId,oldIndex:e.oldIndex,newIndex:e.newIndex};u(this,`mint-tree-change`,{items:t.items,itemId:t.itemId}),u(this,t.oldParentId===t.newParentId?`mint-tree-reorder`:`mint-tree-reparent`,t),this._announce(`${t.item.label} moved${t.newParentId?` into ${n(this._items,t.newParentId)?.label||`a group`}`:` to the top level`}.`)}_select(e){if(this.classList.contains(`mint-tree-drag-active`))return;let t=n(this._items,e);!t||t.disabled||this._disabled()||(this._selectedId=e,this.setAttribute(`selected-id`,e),this._syncSelectionDOM(),u(this,`mint-tree-select`,{item:{...t},itemId:e,items:this.items}))}_syncSelectionDOM(){(this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]).forEach(e=>{let t=e.getAttribute(`data-tree-id`)===this._selectedId;e.setAttribute(`aria-selected`,String(t)),e.tabIndex=t?0:-1})}_setExpanded(e,t,r){let i=n(this._items,e);!i||i.disabled||this._disabled()||(t?this._expandedIds.add(e):this._expandedIds.delete(e),this._syncNodeExpanded(e),r&&u(this,t?`mint-tree-expand`:`mint-tree-collapse`,{itemId:e,item:{...i},expandedIds:this.expandedIds}))}_syncExpandedDOM(){this._root?.querySelectorAll(`[data-mint-tree-row]`).forEach(e=>this._syncNodeExpanded(e.getAttribute(`data-tree-id`)||``))}_syncNodeExpanded(e){let t=[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].find(t=>t.getAttribute(`data-tree-id`)===e),r=t?.querySelector(`:scope > mint-sortable.mint-tree-children`);if(!t||!r)return;let i=this._expandedIds.has(e);t.setAttribute(`aria-expanded`,String(i));let a=t.querySelector(`[data-tree-command="toggle"]`);a?.setAttribute(`aria-expanded`,String(i)),a?.setAttribute(`aria-label`,`${i?`Collapse`:`Expand`} ${n(this._items,e)?.label||`item`}`),a?.setAttribute(`icon`,i?`caret-up`:`caret-down`),r.hidden=!i}_setTransientExpanded(e,t){let r=[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].find(t=>t.getAttribute(`data-tree-id`)===e);if(!r)return;r.setAttribute(`aria-expanded`,String(t));let i=r.querySelector(`[data-tree-command="toggle"]`),a=n(this._items,e)?.label||`item`;i?.setAttribute(`aria-expanded`,String(t)),i?.setAttribute(`aria-label`,`${t?`Collapse`:`Expand`} ${a}`),i?.setAttribute(`icon`,t?`caret-up`:`caret-down`)}_isValidDrop(e,t){let r=n(this._items,e);if(!r)return!1;let i=t===null?null:n(this._items,t);return!(t!==null&&!i||i?.disabled||i&&(String(i.id)===e||this._isDescendant(r,i.id))||!this._allowNesting()&&i||i?.canHaveChildren===!1||i?.acceptsTypes?.length&&!i.acceptsTypes.includes(r.type||``)||(i?this._depthOf(String(i.id)):-1)+1+a(r)>this._maxDepth())}_isDescendant(e,t){return(e.children||[]).some(e=>String(e.id)===String(t)||this._isDescendant(e,t))}_depthOf(e){let t=r(this._items,e);return t?this._depthOfParent(t.parentId):-1}_depthOfParent(e){if(e===null)return 0;let t=r(this._items,e);return t?this._depthOfParent(t.parentId)+1:0}_readItemsFromDOM(e){let t=e.querySelector(`:scope > mint-stack`);return t?[...t.children].filter(e=>e instanceof HTMLElement&&e.classList.contains(`mint-tree-node`)).map(e=>{let t=e.getAttribute(`data-tree-id`)||``,r=n(this._items,t),i=e.querySelector(`:scope > mint-sortable.mint-tree-children`);return{...r||{id:t,label:t},children:i?this._readItemsFromDOM(i):[]}}):[]}_clearDropState(){this._root?.querySelectorAll(`.mint-tree-drop-invalid`).forEach(e=>e.classList.remove(`mint-tree-drop-invalid`))}_collapseEmptyExpandedNodes(){for(let e of[...this._expandedIds]){let t=n(this._items,e);!t||t.children?.length||(this._expandedIds.delete(e),this._syncNodeExpanded(e),u(this,`mint-tree-collapse`,{itemId:e,item:{...t},expandedIds:this.expandedIds,automatic:!0,empty:!0}))}}_announce(e){this._liveRegion&&(this._liveRegion.textContent=e)}_recordHistory(){this._undoStack.push(t(this._items)),this._undoStack.length>50&&this._undoStack.shift(),this._redoStack=[]}_undo(){let e=this._undoStack.pop();if(!e)return;let n=this._items;this._redoStack.push(t(this._items)),this._items=e,this._collapseEmptyExpandedNodes(),this._render(),this._emitHistoryChange(n),u(this,`mint-tree-undo`,{items:this.items})}_redo(){let e=this._redoStack.pop();if(!e)return;let n=this._items;this._undoStack.push(t(this._items)),this._items=e,this._collapseEmptyExpandedNodes(),this._render(),this._emitHistoryChange(n),u(this,`mint-tree-redo`,{items:this.items})}_emitHistoryChange(e){let t=this.items,n=e=>{let t=new Map,n=(e,r)=>e.forEach((e,i)=>{let a=String(e.id);t.set(a,{parentId:r,index:i,item:e}),n(e.children||[],a)});return n(e,null),t},r=n(e),i=n(this._items),a=[...new Set([...r.keys(),...i.keys()])].find(e=>{let t=r.get(e),n=i.get(e);return t&&n&&(t.parentId!==n.parentId||t.index!==n.index)});if(u(this,`mint-tree-change`,{items:t,itemId:this._selectedId}),!a)return;let o=r.get(a),s=i.get(a),c={itemId:a,item:{...s.item},items:t,oldParentId:o.parentId,newParentId:s.parentId,oldIndex:o.index,newIndex:s.index};u(this,o.parentId===s.parentId?`mint-tree-reorder`:`mint-tree-reparent`,c)}_keyboardIndent(e){let t=r(this._items,e);if(!t||t.siblings.indexOf(t.item)<=0)return;let n=t.siblings[t.siblings.indexOf(t.item)-1];try{let t=c(this._items,e,n.id,(n.children||[]).length,{maxDepth:this._maxDepth(),allowNesting:this._allowNesting()});this._recordHistory(),this._items=t.items,this._collapseEmptyExpandedNodes(),this._expandedIds.add(String(n.id)),this._render(),this._focusRow(e),u(this,`mint-tree-reparent`,{itemId:e,item:{...t.item},items:this.items,oldParentId:t.oldParentId,newParentId:t.newParentId,oldIndex:t.oldIndex,newIndex:t.newIndex})}catch{}}_keyboardOutdent(e){let t=r(this._items,e);if(!t||t.parentId===null)return;let n=r(this._items,t.parentId);if(!n)return;let i=n.siblings.findIndex(e=>String(e.id)===t.parentId)+1;try{let t=c(this._items,e,n.parentId,i,{maxDepth:this._maxDepth(),allowNesting:this._allowNesting()});this._recordHistory(),this._items=t.items,this._collapseEmptyExpandedNodes(),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;
@@ -15,7 +15,7 @@ import "../chunks/spinner-B2sml0AG.js";
15
15
  import "../chunks/button-BTQHrE0x.js";
16
16
  import "../chunks/confirm-action-BW1UwJNu.js";
17
17
  import "../chunks/popover-DPNBidSz.js";
18
- import "../chunks/sortable-DdT2ptc5.js";
18
+ import "../chunks/sortable-BpbwI7_Y.js";
19
19
  //#region src/components/tree/tree-utils.js
20
20
  function t(e = []) {
21
21
  s(e);