monobill-mintui 0.6.651 → 0.6.652
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/component-dependencies.json +9 -0
- package/dist/components/chunks/date-picker-BQsCoKaK.js +1282 -0
- package/dist/components/chunks/date-picker-tm5Oc92c.js +1 -0
- package/dist/components/chunks/{input-CdsHKiuL.js → input-DcglGwsR.js} +1 -1
- package/dist/components/chunks/{input-BhptfvVH.js → input-awdYlp-G.js} +1 -1
- package/dist/components/chunks/{popover-BRi53qYL.js → popover-FdMS4yAD.js} +1 -1
- package/dist/components/chunks/{popover-PNIdAt8C.js → popover-wGdggZ-a.js} +1 -1
- package/dist/components/chunks/{table-ty0Sgdpv.js → table-B9e-cnAC.js} +1 -1
- package/dist/components/chunks/{table-odOvGji2.js → table-vjF3q3J5.js} +1 -1
- package/dist/components/chunks/time-picker-Cq3qzkDb.js +1 -0
- package/dist/components/chunks/time-picker-S0bc0BPU.js +360 -0
- package/dist/components/date-picker/DatePicker.d.ts +5 -0
- package/dist/components/date-picker/DatePicker.d.ts.map +1 -1
- package/dist/components/date-picker/browser.js +2 -1270
- package/dist/components/date-picker/index.cjs +1 -1
- package/dist/components/date-picker/index.js +2 -1270
- package/dist/components/datetime-picker/DateTimePicker.d.ts +44 -0
- package/dist/components/datetime-picker/DateTimePicker.d.ts.map +1 -0
- package/dist/components/datetime-picker/browser.js +255 -0
- package/dist/components/datetime-picker/index.cjs +1 -0
- package/dist/components/datetime-picker/index.d.ts +4 -0
- package/dist/components/datetime-picker/index.d.ts.map +1 -0
- package/dist/components/datetime-picker/index.js +243 -0
- package/dist/components/form/Form.d.ts.map +1 -1
- package/dist/components/form/browser.js +9 -8
- package/dist/components/form/index.cjs +1 -1
- package/dist/components/form/index.js +9 -8
- package/dist/components/input/browser.js +1 -1
- package/dist/components/input/index.cjs +1 -1
- package/dist/components/input/index.js +1 -1
- package/dist/components/link/browser.js +1 -1
- package/dist/components/link/index.cjs +1 -1
- package/dist/components/link/index.js +1 -1
- package/dist/components/navigation/browser.js +2 -2
- package/dist/components/navigation/index.cjs +1 -1
- package/dist/components/navigation/index.js +2 -2
- package/dist/components/popover/browser.js +1 -1
- package/dist/components/popover/index.cjs +1 -1
- package/dist/components/popover/index.js +1 -1
- package/dist/components/resource-table/browser.js +6 -6
- package/dist/components/resource-table/index.cjs +1 -1
- package/dist/components/resource-table/index.js +6 -6
- package/dist/components/scroll-fade/browser.js +1 -1
- package/dist/components/scroll-fade/index.cjs +1 -1
- package/dist/components/scroll-fade/index.js +1 -1
- package/dist/components/search/Search.d.ts.map +1 -1
- package/dist/components/search/browser.js +3 -3
- package/dist/components/search/index.cjs +1 -1
- package/dist/components/search/index.js +3 -3
- package/dist/components/select/browser.js +1 -1
- package/dist/components/select/index.cjs +1 -1
- package/dist/components/select/index.js +1 -1
- package/dist/components/side-navigation/browser.js +4 -4
- package/dist/components/side-navigation/index.cjs +1 -1
- package/dist/components/side-navigation/index.js +4 -4
- package/dist/components/sortable/browser.js +1 -1
- package/dist/components/sortable/index.cjs +1 -1
- package/dist/components/sortable/index.js +1 -1
- package/dist/components/table/browser.js +1 -1
- package/dist/components/table/index.cjs +1 -1
- package/dist/components/table/index.js +1 -1
- package/dist/components/tags/browser.js +1 -1
- package/dist/components/tags/index.cjs +1 -1
- package/dist/components/tags/index.js +1 -1
- package/dist/components/time-picker/TimePicker.d.ts +1 -0
- package/dist/components/time-picker/TimePicker.d.ts.map +1 -1
- package/dist/components/time-picker/browser.js +2 -347
- package/dist/components/time-picker/index.cjs +1 -1
- package/dist/components/time-picker/index.js +2 -347
- package/dist/components/tree/browser.js +2 -2
- package/dist/components/tree/index.cjs +1 -1
- package/dist/components/tree/index.js +2 -2
- package/dist/datetime-picker.css +3 -0
- package/dist/index.cjs +3 -3
- package/dist/index.css +10 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +951 -697
- package/dist/navigation-search.json +7 -0
- package/dist/theme.css +5 -0
- package/dist/time-picker.css +1 -1
- package/package.json +10 -1
- /package/dist/components/chunks/{ScrollFade-DIKawLYD.js → ScrollFade-D1FPF6ZS.js} +0 -0
- /package/dist/components/chunks/{ScrollFade-Br6QSd_-.js → ScrollFade-DT2Br2g7.js} +0 -0
- /package/dist/components/chunks/{caret-down-DRrCYUv0.js → caret-down-DGeJj0xv.js} +0 -0
- /package/dist/components/chunks/{caret-down-BU-Ee_JS.js → caret-down-DJvCrCjc.js} +0 -0
- /package/dist/components/chunks/{caret-right-BzeJ0Fw3.js → caret-right-BcZ9bOhS.js} +0 -0
- /package/dist/components/chunks/{caret-right-Bh7uMg-Y.js → caret-right-CgIVfus7.js} +0 -0
- /package/dist/components/chunks/{link-BsC3zT_I.js → link-BjbBJpI6.js} +0 -0
- /package/dist/components/chunks/{link-dTjSvr4E.js → link-CU-gTgir.js} +0 -0
- /package/dist/components/chunks/{search-v06eZL4m.js → search--bcFMYMP.js} +0 -0
- /package/dist/components/chunks/{search-CTAGy5ab.js → search-Cixhf7hA.js} +0 -0
- /package/dist/components/chunks/{sortable-B1nMJBah.js → sortable-CNlF0_gv.js} +0 -0
- /package/dist/components/chunks/{sortable-CXM-7eyL.js → sortable-CVK48xj1.js} +0 -0
|
@@ -5,350 +5,5 @@ import '../../popover.css'
|
|
|
5
5
|
import '../../stack.css'
|
|
6
6
|
import '../../text.css'
|
|
7
7
|
import '../../time-picker.css'
|
|
8
|
-
import "../chunks/
|
|
9
|
-
|
|
10
|
-
import "../chunks/text-Bmfl6CxJ.js";
|
|
11
|
-
import "../chunks/input-CdsHKiuL.js";
|
|
12
|
-
import "../chunks/popover-BRi53qYL.js";
|
|
13
|
-
//#region src/components/time-picker/TimePicker.ts
|
|
14
|
-
var t = class extends HTMLElement {
|
|
15
|
-
constructor(...e) {
|
|
16
|
-
super(...e), this._triggerId = `mint-time-picker-trigger-${Math.random().toString(36).slice(2, 10)}`, this._popover = null, this._popoverObserver = null, this._inputEl = null, this._hiddenInput = null, this._single = {
|
|
17
|
-
hour: 9,
|
|
18
|
-
minute: 0,
|
|
19
|
-
second: 0,
|
|
20
|
-
meridiem: "AM"
|
|
21
|
-
}, this._rangeStart = {
|
|
22
|
-
hour: 9,
|
|
23
|
-
minute: 0,
|
|
24
|
-
second: 0,
|
|
25
|
-
meridiem: "AM"
|
|
26
|
-
}, this._rangeEnd = {
|
|
27
|
-
hour: 5,
|
|
28
|
-
minute: 0,
|
|
29
|
-
second: 0,
|
|
30
|
-
meridiem: "PM"
|
|
31
|
-
}, this._invalidFromInput = !1;
|
|
32
|
-
}
|
|
33
|
-
static get observedAttributes() {
|
|
34
|
-
return [
|
|
35
|
-
"value",
|
|
36
|
-
"label",
|
|
37
|
-
"info",
|
|
38
|
-
"disabled",
|
|
39
|
-
"id",
|
|
40
|
-
"name",
|
|
41
|
-
"required",
|
|
42
|
-
"readonly",
|
|
43
|
-
"range",
|
|
44
|
-
"hours",
|
|
45
|
-
"minutes",
|
|
46
|
-
"seconds",
|
|
47
|
-
"error",
|
|
48
|
-
"error-message"
|
|
49
|
-
];
|
|
50
|
-
}
|
|
51
|
-
connectedCallback() {
|
|
52
|
-
this.classList.add("mint-time-picker-host"), this._parseAndApplyValue(this.getAttribute("value") || ""), this.render();
|
|
53
|
-
}
|
|
54
|
-
disconnectedCallback() {
|
|
55
|
-
this._popoverObserver &&= (this._popoverObserver.disconnect(), null);
|
|
56
|
-
}
|
|
57
|
-
attributeChangedCallback(e, t, n) {
|
|
58
|
-
if (t !== n) {
|
|
59
|
-
if (e === "value") {
|
|
60
|
-
if (this._parseAndApplyValue(n || ""), this._syncHiddenInput(), this._syncInputValue(), this._popover) {
|
|
61
|
-
let e = this._popover.querySelector("[data-mint-time-picker-body=\"true\"]");
|
|
62
|
-
e && this._buildPopoverContent(e);
|
|
63
|
-
}
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
e !== "error" && e !== "error-message" && (this._invalidFromInput = !1), this.render();
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
get value() {
|
|
70
|
-
return this.getValue();
|
|
71
|
-
}
|
|
72
|
-
set value(e) {
|
|
73
|
-
this.setValue(e || "");
|
|
74
|
-
}
|
|
75
|
-
getValue() {
|
|
76
|
-
return this.getAttribute("value") || "";
|
|
77
|
-
}
|
|
78
|
-
setValue(e) {
|
|
79
|
-
e ? this.setAttribute("value", e) : this.removeAttribute("value"), this._parseAndApplyValue(e || ""), this._syncHiddenInput(), this._syncInputValue();
|
|
80
|
-
}
|
|
81
|
-
isRange() {
|
|
82
|
-
return this.getAttribute("range") === "true";
|
|
83
|
-
}
|
|
84
|
-
isHoursEnabled() {
|
|
85
|
-
let e = this.getAttribute("hours");
|
|
86
|
-
return e === null ? !0 : e !== "false";
|
|
87
|
-
}
|
|
88
|
-
isMinutesEnabled() {
|
|
89
|
-
let e = this.getAttribute("minutes");
|
|
90
|
-
return e === null ? !0 : e !== "false";
|
|
91
|
-
}
|
|
92
|
-
isSecondsEnabled() {
|
|
93
|
-
let e = this.getAttribute("seconds");
|
|
94
|
-
return e === null ? !1 : e !== "false";
|
|
95
|
-
}
|
|
96
|
-
isDisabled() {
|
|
97
|
-
return this.getAttribute("disabled") === "true";
|
|
98
|
-
}
|
|
99
|
-
isReadonly() {
|
|
100
|
-
return this.getAttribute("readonly") === "true";
|
|
101
|
-
}
|
|
102
|
-
isRequired() {
|
|
103
|
-
return this.getAttribute("required") === "true";
|
|
104
|
-
}
|
|
105
|
-
hasExternalError() {
|
|
106
|
-
return this.getAttribute("error") === "true";
|
|
107
|
-
}
|
|
108
|
-
getExternalErrorMessage() {
|
|
109
|
-
return this.getAttribute("error-message") || "";
|
|
110
|
-
}
|
|
111
|
-
getLabel() {
|
|
112
|
-
return this.getAttribute("label") || "";
|
|
113
|
-
}
|
|
114
|
-
getInfo() {
|
|
115
|
-
return this.getAttribute("info") || "";
|
|
116
|
-
}
|
|
117
|
-
getName() {
|
|
118
|
-
return this.getAttribute("name") || "";
|
|
119
|
-
}
|
|
120
|
-
_getEffectiveError() {
|
|
121
|
-
return {
|
|
122
|
-
hasError: this.hasExternalError(),
|
|
123
|
-
message: this.getExternalErrorMessage()
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
_formatParts(e) {
|
|
127
|
-
let t = this.isHoursEnabled(), n = this.isMinutesEnabled(), r = this.isSecondsEnabled(), i = [];
|
|
128
|
-
return t && i.push(e.hour.toString()), n && i.push(e.minute.toString().padStart(2, "0")), r && i.push(e.second.toString().padStart(2, "0")), t ? `${i.join(":")} ${e.meridiem.toLowerCase()}` : i.join(":");
|
|
129
|
-
}
|
|
130
|
-
_to24Hour(e) {
|
|
131
|
-
let t = e.hour % 12;
|
|
132
|
-
return e.meridiem === "PM" && (t += 12), {
|
|
133
|
-
hour: t,
|
|
134
|
-
minute: e.minute,
|
|
135
|
-
second: e.second
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
_formatParts24(e) {
|
|
139
|
-
let t = this.isHoursEnabled(), n = this.isMinutesEnabled(), r = this.isSecondsEnabled(), i = this._to24Hour(e), a = [];
|
|
140
|
-
return t && a.push(i.hour.toString().padStart(2, "0")), n && a.push(i.minute.toString().padStart(2, "0")), r && a.push(i.second.toString().padStart(2, "0")), a.join(":");
|
|
141
|
-
}
|
|
142
|
-
_getDisplayValue() {
|
|
143
|
-
return this.isRange() ? `${this._formatParts(this._rangeStart)} - ${this._formatParts(this._rangeEnd)}` : this._formatParts(this._single);
|
|
144
|
-
}
|
|
145
|
-
_getOutputValue() {
|
|
146
|
-
return this.isRange() ? `${this._formatParts24(this._rangeStart)} - ${this._formatParts24(this._rangeEnd)}` : this._formatParts24(this._single);
|
|
147
|
-
}
|
|
148
|
-
_getExpectedFormat() {
|
|
149
|
-
let e = this.isHoursEnabled(), t = this.isMinutesEnabled(), n = this.isSecondsEnabled(), r = [];
|
|
150
|
-
e && r.push("h"), t && r.push("mm"), n && r.push("ss");
|
|
151
|
-
let i = e ? `${r.join(":")} am/pm` : r.join(":");
|
|
152
|
-
return this.isRange() ? `${i} - ${i}` : i;
|
|
153
|
-
}
|
|
154
|
-
_syncHiddenInput() {
|
|
155
|
-
this._hiddenInput && (this._hiddenInput.value = this.getValue() || this._getOutputValue());
|
|
156
|
-
}
|
|
157
|
-
_syncInputValue() {
|
|
158
|
-
this._inputEl && (this._inputEl.value = this._getDisplayValue(), typeof this._inputEl.render == "function" && this._inputEl.render());
|
|
159
|
-
}
|
|
160
|
-
_emitChangeFromPicker() {
|
|
161
|
-
let e = this._getOutputValue();
|
|
162
|
-
this._invalidFromInput = !1, this.setAttribute("value", e), this._syncHiddenInput(), this._syncInputValue(), this.dispatchEvent(new Event("input", {
|
|
163
|
-
bubbles: !0,
|
|
164
|
-
composed: !0
|
|
165
|
-
})), this.dispatchEvent(new Event("change", { bubbles: !0 }));
|
|
166
|
-
}
|
|
167
|
-
_parseSingle(e) {
|
|
168
|
-
let t = this.isHoursEnabled(), n = this.isMinutesEnabled(), r = this.isSecondsEnabled(), i = e.trim();
|
|
169
|
-
if (t) {
|
|
170
|
-
let e = i.match(/^(\d{1,2})(?::(\d{2}))?(?::(\d{2}))?\s*(am|pm)$/i);
|
|
171
|
-
if (!e) return null;
|
|
172
|
-
let t = Number(e[1]), a = Number(e[2] ?? 0), o = Number(e[3] ?? 0), s = e[4].toUpperCase();
|
|
173
|
-
return t < 1 || t > 12 || n && (a < 0 || a > 59) || r && (o < 0 || o > 59) ? null : {
|
|
174
|
-
hour: t,
|
|
175
|
-
minute: a,
|
|
176
|
-
second: o,
|
|
177
|
-
meridiem: s
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
let a = i.match(/^(\d{2})(?::(\d{2}))?$/);
|
|
181
|
-
if (!a) return null;
|
|
182
|
-
let o = Number(a[1]), s = Number(a[2] ?? 0);
|
|
183
|
-
return n && (o < 0 || o > 59) || r && (s < 0 || s > 59) ? null : {
|
|
184
|
-
hour: 12,
|
|
185
|
-
minute: o,
|
|
186
|
-
second: s,
|
|
187
|
-
meridiem: "AM"
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
_parseSingleOutput24(e) {
|
|
191
|
-
let t = this.isHoursEnabled(), n = this.isMinutesEnabled(), r = this.isSecondsEnabled(), i = e.trim();
|
|
192
|
-
if (t) {
|
|
193
|
-
let e = i.match(/^(\d{2})(?::(\d{2}))?(?::(\d{2}))?$/);
|
|
194
|
-
if (!e) return null;
|
|
195
|
-
let t = Number(e[1]), a = Number(e[2] ?? 0), o = Number(e[3] ?? 0);
|
|
196
|
-
if (t < 0 || t > 23 || n && (a < 0 || a > 59) || r && (o < 0 || o > 59)) return null;
|
|
197
|
-
let s = t >= 12 ? "PM" : "AM";
|
|
198
|
-
return {
|
|
199
|
-
hour: t % 12 == 0 ? 12 : t % 12,
|
|
200
|
-
minute: a,
|
|
201
|
-
second: o,
|
|
202
|
-
meridiem: s
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
let a = i.match(/^(\d{2})(?::(\d{2}))?$/);
|
|
206
|
-
if (!a) return null;
|
|
207
|
-
let o = Number(a[1]), s = Number(a[2] ?? 0);
|
|
208
|
-
return n && (o < 0 || o > 59) || r && (s < 0 || s > 59) ? null : {
|
|
209
|
-
hour: 12,
|
|
210
|
-
minute: o,
|
|
211
|
-
second: s,
|
|
212
|
-
meridiem: "AM"
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
_parseAndApplyValue(e) {
|
|
216
|
-
if (!e) return !1;
|
|
217
|
-
if (this.isRange()) {
|
|
218
|
-
let [t, n] = e.split("-").map((e) => e.trim()), r = this._parseSingleOutput24(t || ""), i = this._parseSingleOutput24(n || "");
|
|
219
|
-
return !r || !i ? !1 : (this._rangeStart = r, this._rangeEnd = i, !0);
|
|
220
|
-
}
|
|
221
|
-
let t = this._parseSingleOutput24(e);
|
|
222
|
-
return t ? (this._single = t, !0) : !1;
|
|
223
|
-
}
|
|
224
|
-
_parseAndApplyDisplayValue(e) {
|
|
225
|
-
if (!e) return !1;
|
|
226
|
-
if (this.isRange()) {
|
|
227
|
-
let [t, n] = e.split("-").map((e) => e.trim()), r = this._parseSingle(t || ""), i = this._parseSingle(n || "");
|
|
228
|
-
return !r || !i ? !1 : (this._rangeStart = r, this._rangeEnd = i, !0);
|
|
229
|
-
}
|
|
230
|
-
let t = this._parseSingle(e);
|
|
231
|
-
return t ? (this._single = t, !0) : !1;
|
|
232
|
-
}
|
|
233
|
-
_handleTypedValue(e) {
|
|
234
|
-
let t = e.trim();
|
|
235
|
-
if (!t) {
|
|
236
|
-
this._invalidFromInput = !1, this.removeAttribute("value"), this._syncHiddenInput(), this._syncInputValue();
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
if (!this._parseAndApplyDisplayValue(t)) {
|
|
240
|
-
this._invalidFromInput = !0, this.removeAttribute("value"), this._inputEl && (this._inputEl.value = ""), this._syncHiddenInput(), this.render(), this.dispatchEvent(new Event("input", {
|
|
241
|
-
bubbles: !0,
|
|
242
|
-
composed: !0
|
|
243
|
-
})), this.dispatchEvent(new Event("change", { bubbles: !0 }));
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
this._invalidFromInput = !1;
|
|
247
|
-
let n = this._getOutputValue();
|
|
248
|
-
this.setAttribute("value", n), this._syncHiddenInput(), this._syncInputValue(), this.dispatchEvent(new Event("input", {
|
|
249
|
-
bubbles: !0,
|
|
250
|
-
composed: !0
|
|
251
|
-
})), this.dispatchEvent(new Event("change", { bubbles: !0 }));
|
|
252
|
-
}
|
|
253
|
-
_buildColumn(e, t, n, r = !0, i = "standard", a = "Time") {
|
|
254
|
-
let o = document.createElement("div");
|
|
255
|
-
return o.className = `mint-time-picker-column mint-time-picker-column-${i}${r ? " mint-time-picker-column-divider" : ""}`, o.setAttribute("role", "group"), o.setAttribute("aria-label", a), e.forEach((e) => {
|
|
256
|
-
let r = document.createElement("button");
|
|
257
|
-
r.type = "button";
|
|
258
|
-
let i = e === t;
|
|
259
|
-
r.className = `mint-time-picker-option${i ? " is-selected" : ""}`, r.dataset.selected = i ? "true" : "false", r.setAttribute("aria-pressed", String(i)), r.setAttribute("aria-label", `${a}: ${e}`), r.textContent = e, r.addEventListener("click", () => n(e)), o.appendChild(r);
|
|
260
|
-
}), o;
|
|
261
|
-
}
|
|
262
|
-
_centerSelectedInColumn(e, t = 0) {
|
|
263
|
-
let n = e.querySelector("button[data-selected=\"true\"]");
|
|
264
|
-
if (!n) return;
|
|
265
|
-
let r = n.offsetTop - (e.clientHeight / 2 - n.clientHeight / 2) - t;
|
|
266
|
-
e.scrollTop = Math.max(0, r);
|
|
267
|
-
}
|
|
268
|
-
_centerAllColumnsInPopoverBody() {
|
|
269
|
-
if (!this._popover) return;
|
|
270
|
-
let e = this._popover.querySelector("[data-mint-time-picker-body=\"true\"]");
|
|
271
|
-
if (!e) return;
|
|
272
|
-
let t = Array.from(e.querySelectorAll(".mint-time-picker-column")), n = this.isRange() ? 20 : 0;
|
|
273
|
-
t.forEach((e) => this._centerSelectedInColumn(e, n));
|
|
274
|
-
}
|
|
275
|
-
_setupPopoverOpenObserver() {
|
|
276
|
-
this._popover && (this._popoverObserver &&= (this._popoverObserver.disconnect(), null), this._popoverObserver = new MutationObserver(() => {
|
|
277
|
-
this._popover?.getAttribute("open") === "true" && requestAnimationFrame(() => {
|
|
278
|
-
requestAnimationFrame(() => {
|
|
279
|
-
this._centerAllColumnsInPopoverBody();
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
}), this._popoverObserver.observe(this._popover, {
|
|
283
|
-
attributes: !0,
|
|
284
|
-
attributeFilter: ["open"]
|
|
285
|
-
}));
|
|
286
|
-
}
|
|
287
|
-
_buildPickerSet(e, t, n) {
|
|
288
|
-
let r = this.isHoursEnabled(), i = this.isMinutesEnabled(), a = this.isSecondsEnabled(), o = document.createElement("div"), s = (r ? 1 : 0) + (i ? 1 : 0) + (a ? 1 : 0) + (r ? 1 : 0);
|
|
289
|
-
o.className = "mint-time-picker-wheel", o.style.gridTemplateColumns = `repeat(${Math.max(s, 1)}, minmax(0, 1fr))`;
|
|
290
|
-
let c = Array.from({ length: 12 }, (e, t) => (t + 1).toString().padStart(2, "0")), l = Array.from({ length: 60 }, (e, t) => t.toString().padStart(2, "0")), u = Array.from({ length: 60 }, (e, t) => t.toString().padStart(2, "0")), d = ["AM", "PM"], f = [];
|
|
291
|
-
r && f.push(this._buildColumn(c, t.hour.toString().padStart(2, "0"), (e) => {
|
|
292
|
-
n({
|
|
293
|
-
...t,
|
|
294
|
-
hour: Number(e)
|
|
295
|
-
});
|
|
296
|
-
}, !0, "tall", "Hour")), i && f.push(this._buildColumn(l, t.minute.toString().padStart(2, "0"), (e) => {
|
|
297
|
-
n({
|
|
298
|
-
...t,
|
|
299
|
-
minute: Number(e)
|
|
300
|
-
});
|
|
301
|
-
}, !0, "tall", "Minute")), a && f.push(this._buildColumn(u, t.second.toString().padStart(2, "0"), (e) => {
|
|
302
|
-
n({
|
|
303
|
-
...t,
|
|
304
|
-
second: Number(e)
|
|
305
|
-
});
|
|
306
|
-
}, !0, "tall", "Second")), r && f.push(this._buildColumn(d, t.meridiem, (e) => {
|
|
307
|
-
n({
|
|
308
|
-
...t,
|
|
309
|
-
meridiem: e
|
|
310
|
-
});
|
|
311
|
-
}, !0, "compact", "Meridiem")), f.forEach((e, t) => {
|
|
312
|
-
t === f.length - 1 && e.classList.remove("mint-time-picker-column-divider"), o.appendChild(e);
|
|
313
|
-
}), e.appendChild(o);
|
|
314
|
-
}
|
|
315
|
-
_buildPopoverContent(e) {
|
|
316
|
-
if (e.innerHTML = "", !this.isRange()) {
|
|
317
|
-
this._buildPickerSet(e, this._single, (t) => {
|
|
318
|
-
this._single = t, this._emitChangeFromPicker(), this._buildPopoverContent(e);
|
|
319
|
-
});
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
let t = document.createElement("div");
|
|
323
|
-
t.className = "mint-time-picker-range";
|
|
324
|
-
let n = document.createElement("div"), r = document.createElement("mint-text");
|
|
325
|
-
r.setAttribute("variant", "muted"), r.className = "mint-time-picker-range-label", r.textContent = "Start", n.appendChild(r), this._buildPickerSet(n, this._rangeStart, (t) => {
|
|
326
|
-
this._rangeStart = t, this._emitChangeFromPicker(), this._buildPopoverContent(e);
|
|
327
|
-
});
|
|
328
|
-
let i = document.createElement("div"), a = document.createElement("mint-text");
|
|
329
|
-
a.setAttribute("variant", "muted"), a.className = "mint-time-picker-range-label", a.textContent = "End", i.appendChild(a), this._buildPickerSet(i, this._rangeEnd, (t) => {
|
|
330
|
-
this._rangeEnd = t, this._emitChangeFromPicker(), this._buildPopoverContent(e);
|
|
331
|
-
}), t.appendChild(n), t.appendChild(i), e.appendChild(t), requestAnimationFrame(() => {
|
|
332
|
-
this._centerAllColumnsInPopoverBody();
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
render() {
|
|
336
|
-
let e = this.isDisabled(), t = this.isReadonly(), n = this._getEffectiveError();
|
|
337
|
-
this.innerHTML = "";
|
|
338
|
-
let r = document.createElement("div");
|
|
339
|
-
r.className = "mint-time-picker-control", this._inputEl = document.createElement("mint-input"), this._inputEl.id = this._triggerId, this._inputEl.classList.add("mint-time-picker-trigger"), this._inputEl.setAttribute("type", "text"), this._inputEl.setAttribute("icon", "clock"), this._inputEl.setAttribute("placeholder", this._getExpectedFormat()), this._inputEl.setAttribute("label", this.getLabel()), this._inputEl.setAttribute("info", this.getInfo()), this._inputEl.setAttribute("value", this._getDisplayValue()), this._inputEl.setAttribute("error", n.hasError ? "true" : "false"), this._inputEl.setAttribute("error-message", n.message || ""), e && this._inputEl.setAttribute("disabled", "true"), t && this._inputEl.setAttribute("readonly", "true"), this._inputEl.addEventListener("change", (n) => {
|
|
340
|
-
if (e || t) return;
|
|
341
|
-
let r = n.target;
|
|
342
|
-
this._handleTypedValue((r?.value || "").toString());
|
|
343
|
-
}), this._inputEl.addEventListener("blur", (n) => {
|
|
344
|
-
if (e || t) return;
|
|
345
|
-
let r = n.target;
|
|
346
|
-
this._handleTypedValue((r?.value || "").toString());
|
|
347
|
-
}, !0), r.appendChild(this._inputEl), this._hiddenInput = document.createElement("input"), this._hiddenInput.type = "hidden", this._hiddenInput.name = this.getName(), this._hiddenInput.required = this.isRequired(), r.appendChild(this._hiddenInput), this._syncHiddenInput(), this._popover = document.createElement("mint-popover"), this._popover.setAttribute("trigger-id", this._triggerId), this._popover.setAttribute("direction", "down"), this._popover.setAttribute("padding", "0"), this._popover.setAttribute("distance", "6px"), (e || t) && this._popover.setAttribute("open", "false");
|
|
348
|
-
let i = document.createElement("div");
|
|
349
|
-
i.setAttribute("data-mint-time-picker-body", "true"), i.className = "mint-time-picker-popover", this._buildPopoverContent(i), this._popover.appendChild(i), r.appendChild(this._popover), this._setupPopoverOpenObserver(), this.appendChild(r);
|
|
350
|
-
}
|
|
351
|
-
};
|
|
352
|
-
customElements.get("mint-time-picker") || e("mint-time-picker", t);
|
|
353
|
-
//#endregion
|
|
354
|
-
export { t as default };
|
|
8
|
+
import { t as e } from "../chunks/time-picker-S0bc0BPU.js";
|
|
9
|
+
export { e as default };
|
|
@@ -26,8 +26,8 @@ import { t as e } from "../chunks/register-element-BFYmIynH.js";
|
|
|
26
26
|
import "../chunks/spinner-BjC3nA-C.js";
|
|
27
27
|
import "../chunks/button-CP7K25iD.js";
|
|
28
28
|
import "../chunks/confirm-action-Bf6A7A2j.js";
|
|
29
|
-
import "../chunks/popover-
|
|
30
|
-
import "../chunks/sortable-
|
|
29
|
+
import "../chunks/popover-FdMS4yAD.js";
|
|
30
|
+
import "../chunks/sortable-CNlF0_gv.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-rvYvpQ_h.js`);const e=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/spinner-DfPbEa2d.js`),require(`../chunks/button-B1-XW0BK.js`),require(`../chunks/confirm-action-BvxL3-Xz.js`),require(`../chunks/popover-PNIdAt8C.js`),require(`../chunks/sortable-CXM-7eyL.js`);function t(e=[]){s(e);let t=e=>e.map(e=>({...e,children:Array.isArray(e.children)?t(e.children):[]}));return t(e)}function n(e,t){let r=String(t);for(let t of e){if(String(t.id)===r)return t;let e=n(t.children||[],r);if(e)return e}return null}function r(e,t,n=null){let i=String(t);for(let t of e){if(String(t.id)===i)return{parentId:n,siblings:e,item:t};let a=r(t.children||[],i,String(t.id));if(a)return a}return null}function i(e,t,n=0){let r=String(t);for(let t of e){if(String(t.id)===r)return n;let e=i(t.children||[],r,n+1);if(e>=0)return e}return-1}function a(e){let t=Array.isArray(e?.children)?e.children:[];return t.length?1+Math.max(...t.map(a)):1}function o(e,t){return String(e.id)===String(t)?!0:(e.children||[]).some(e=>o(e,t))}function s(e){let t=new Set,n=e=>{for(let r of e){if(r.id===null||r.id===void 0||String(r.id)===``)throw Error(`Every tree item must have a non-empty identifier.`);let e=String(r.id);if(t.has(e))throw Error(`Tree item identifiers must be unique. Duplicate identifier: ${e}.`);t.add(e),n(r.children||[])}};n(e)}function c(e,s,c,l,u={}){let d=t(e),f=r(d,s);if(!f)throw Error(`Tree item ${s} was not found.`);if(f.item.disabled||f.item.draggable===!1)throw Error(`Disabled tree items cannot be moved.`);let p=c==null||c===``?null:n(d,c);if(c!=null&&c!==``&&!p)throw Error(`Target parent ${c} was not found.`);if(p&&o(f.item,p.id))throw Error(`A tree item cannot be moved inside itself or one of its descendants.`);if(p?.disabled)throw Error(`Disabled tree items cannot contain children.`);if(u.allowNesting===!1&&p)throw Error(`Nesting is disabled for this tree.`);if(p?.canHaveChildren===!1)throw Error(`The target item cannot contain children.`);if(p?.acceptsTypes?.length&&!p.acceptsTypes.includes(f.item.type))throw Error(`The target item does not accept this item type.`);let m=p?p.children:d,h=f.siblings.findIndex(e=>String(e.id)===String(s)),[g]=f.siblings.splice(h,1),_=Math.min(Math.max(0,Number.isFinite(l)?Math.trunc(l):m.length),m.length);m.splice(_,0,g);let v=Number.isFinite(u.maxDepth)?Math.max(1,Math.trunc(u.maxDepth)):1/0;if((p?i(d,p.id)+1:0)+a(g)>v)throw Error(`Moving this branch would exceed the maximum tree depth of ${v}.`);return{items:d,item:g,oldParentId:f.parentId,newParentId:p?String(p.id):null,oldIndex:h,newIndex:_}}var l=0;function u(e,t,n){e.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:n}))}function d(e,t){let n=e.getAttribute(t);return n===``||n===`true`}function f(e){return e==null||e===``?null:String(e)}var p=class extends HTMLElement{constructor(...e){super(...e),this._items=[],this._undoStack=[],this._redoStack=[],this._selectedId=null,this._expandedIds=new Set,this._root=null,this._confirm=null,this._treeId=`mint-tree-${++l}`,this._liveRegion=null,this._dragExpansion=null,this._autoExpandedIds=new Set,this._dragHoverExpandedId=null,this._keyboardFocusRestore=null,this._suppressSelectionClick=!1,this._selectionClickSuppressionTimer=null,this._onClick=e=>{let t=e.target instanceof Element?e.target.closest(`[data-tree-command]`):null;if(!t||!this.contains(t))return;let r=t.getAttribute(`data-tree-command`),i=t.getAttribute(`data-tree-id`);if(r===`create-root`)u(this,`mint-tree-create`,{parentId:null,items:this.items});else if(r===`expand-all`)this._expandedIds=this._defaultExpandedIds(this._items),this._syncExpandedDOM(),u(this,`mint-tree-expand`,{all:!0,expandedIds:this.expandedIds});else if(r===`collapse-all`)this._expandedIds.clear(),this._syncExpandedDOM(),u(this,`mint-tree-collapse`,{all:!0,expandedIds:[]});else if(r===`undo`)this._undo();else if(r===`redo`)this._redo();else if(r===`toggle`&&i){let e=!this._expandedIds.has(i);this._setExpanded(i,e,!0)}else if(r===`select`&&i){if(this.classList.contains(`mint-tree-drag-active`)||this._suppressSelectionClick){e.preventDefault(),this._suppressSelectionClick=!1,this._selectionClickSuppressionTimer!==null&&window.clearTimeout(this._selectionClickSuppressionTimer),this._selectionClickSuppressionTimer=null;return}this._select(i)}else if(r===`create-child`&&i)this._closeItemPopover(t),u(this,`mint-tree-create`,{parentId:i,items:this.items});else if(r===`edit`&&i){this._closeItemPopover(t);let e=n(this._items,i);e&&u(this,`mint-tree-edit`,{item:{...e},itemId:i,items:this.items})}else if(r===`delete`&&i)this._closeItemPopover(t),this._confirmDelete(i);else if([`move-up`,`move-down`,`nest-previous`,`outdent`].includes(r||``)&&i)this._closeItemPopover(t),this._moveByCommand(i,r||``);else if(r===`custom`&&i){this._closeItemPopover(t);let e=n(this._items,i),r=t.getAttribute(`data-tree-action`)||``,a=e?.actions?.find(e=>e.id===r);if(e&&a){let t={item:{...e},itemId:i,action:{...a,onSelect:void 0},items:this.items};u(this,`mint-tree-action`,t),a.onSelect?.({item:{...e},itemId:i,action:a,items:this.items})}}},this._onSortableDrag=e=>{let t=e.detail;if(!t||!Number.isFinite(t.clientX)||!Number.isFinite(t.clientY))return;let r=document.elementFromPoint(t.clientX,t.clientY),i=r?.closest(`[data-mint-tree-row]`),a=t.item?.getAttribute(`data-tree-id`)||``,o=null;if(i&&i.getAttribute(`data-tree-id`)!==a){let e=i.querySelector(`:scope > .mint-tree-row`)?.getBoundingClientRect()||i.getBoundingClientRect(),r=e.height?(t.clientY-e.top)/e.height:0;if(r>.22&&r<.78){let e=i.getAttribute(`data-tree-id`)||``;n(this._items,e)&&this._isValidDrop(a,e)&&(o=e)}}if(!o&&this._dragHoverExpandedId){let e=[...this._root?.querySelectorAll(`[data-tree-id]`)??[]].find(e=>e.getAttribute(`data-tree-id`)===this._dragHoverExpandedId)?.querySelector(`:scope > mint-sortable.mint-tree-children`);r&&e?.contains(r)&&(o=this._dragHoverExpandedId)}if(this._dragHoverExpandedId&&this._dragHoverExpandedId!==o){let e=this._dragHoverExpandedId;this._dragHoverExpandedId=null,this._autoExpandedIds.delete(e),this._expandedIds.delete(e),this._syncNodeExpanded(e);let t=n(this._items,e);t&&u(this,`mint-tree-collapse`,{itemId:e,item:{...t},expandedIds:this.expandedIds,automatic:!0})}if(o){let e=n(this._items,o);e&&!this._expandedIds.has(o)&&(this._expandedIds.add(o),this._autoExpandedIds.add(o),this._dragHoverExpandedId=o,this._syncNodeExpanded(o),u(this,`mint-tree-expand`,{itemId:o,item:{...e},expandedIds:this.expandedIds,automatic:!0}))}},this._onSortableStart=()=>{this.classList.add(`mint-tree-drag-active`),this._dragHoverExpandedId=null,this._dragExpansion?.timer!==null&&this._dragExpansion?.timer!==void 0&&window.clearTimeout(this._dragExpansion.timer),this._dragExpansion=null;let e=this._root?.querySelector(`.mint-sortable-dragging[data-tree-id]`),t=e?.getAttribute(`data-tree-id`)||``,n=e?.querySelector(`:scope > mint-sortable.mint-tree-children`);if(!e||!t||!n||n.hidden||!this._expandedIds.has(t))return;let r=e.querySelector(`:scope > .mint-tree-row`),i=this._root?.querySelector(`.mint-sortable-placeholder`),a=n.getBoundingClientRect().height;n.style.height=`${a}px`,n.style.overflow=`hidden`,e.style.height=`auto`,e.style.overflow=`hidden`,this._dragExpansion={itemId:t,item:e,childList:n,timer:null},this._setTransientExpanded(t,!1),n.offsetHeight,requestAnimationFrame(()=>{this._dragExpansion?.childList===n&&(n.classList.add(`mint-tree-drag-collapse`),n.style.height=`0px`,i&&r&&(i.style.minHeight=`${r.getBoundingClientRect().height}px`))})},this._onSortableEnd=e=>{this.classList.remove(`mint-tree-drag-active`),this._suppressSelectionClick=!0,this._selectionClickSuppressionTimer!==null&&window.clearTimeout(this._selectionClickSuppressionTimer),this._selectionClickSuppressionTimer=window.setTimeout(()=>{this._suppressSelectionClick=!1,this._selectionClickSuppressionTimer=null},300);let t=e.detail,r=t&&!t.cancelled?f(t.newParentId):null;for(let e of this._autoExpandedIds){if(e===r)continue;this._expandedIds.delete(e),this._syncNodeExpanded(e);let t=n(this._items,e);t&&u(this,`mint-tree-collapse`,{itemId:e,item:{...t},expandedIds:this.expandedIds,automatic:!0})}this._autoExpandedIds.clear(),this._dragHoverExpandedId=null;let i=this._dragExpansion;if(!i)return;i.item=[...this._root?.querySelectorAll(`[data-tree-id]`)??[]].find(e=>e.getAttribute(`data-tree-id`)===i.itemId)||i.item,i.childList=i.item.querySelector(`:scope > mint-sortable.mint-tree-children`)||i.childList;let{item:a,childList:o,itemId:s}=i;o.style.height=`0px`,o.style.overflow=`hidden`,o.classList.remove(`mint-tree-drag-collapse`),this._setTransientExpanded(s,!0),o.offsetHeight;let c=o.scrollHeight;requestAnimationFrame(()=>{this._dragExpansion===i&&(o.style.height=`${c}px`)}),i.timer=window.setTimeout(()=>{o.style.height=``,o.style.overflow=``,o.style.opacity=``,this._dragExpansion=null},155)},this._onSortableDragOver=e=>{let t=e,{item:r,target:i}=t.detail||{};if(!r||!i)return;this._root?.querySelectorAll(`.mint-tree-drop-invalid`).forEach(e=>e.classList.remove(`mint-tree-drop-invalid`));let a=this._root?.querySelector(`.mint-sortable-placeholder`),o=r.getAttribute(`data-tree-id`)||``,s=f(i.getAttribute(`data-tree-parent-id`)),c=i===t.detail.source||this._isValidDrop(o,s),l=s?n(this._items,s):null;c&&i!==t.detail.source&&l?a?.setAttribute(`data-drop-label`,`Drop here to nest under ${l.label}`):c&&i===this._root?.querySelector(`:scope > mint-sortable`)?a?.setAttribute(`data-drop-label`,`Drop here to move to the top level`):a?.removeAttribute(`data-drop-label`);let u=(Number.isFinite(t.detail.clientX)&&Number.isFinite(t.detail.clientY)?document.elementFromPoint(t.detail.clientX,t.detail.clientY):null)?.closest(`[data-mint-tree-row]`);u&&u.getAttribute(`data-tree-id`)!==o&&!c&&u.classList.add(`mint-tree-drop-invalid`),c||t.preventDefault()},this._onSortableBeforeDrop=e=>{let t=e,n=t.detail;if(!n?.item||!n.target)return;let r=n.item.getAttribute(`data-tree-id`)||``,i=f(n.target.getAttribute(`data-tree-parent-id`));n.target!==n.source&&!this._isValidDrop(r,i)&&t.preventDefault()},this._onSortableChange=e=>{let t=e.detail;if(!t||t.cancelled)return;let r=t.itemId||``,i=f(t.oldParentId),a=f(t.newParentId),o=this._root?.querySelector(`:scope > mint-sortable`);if(!o)return;let s=n(this._items,r);this._recordHistory(),this._items=this._readItemsFromDOM(o),this._collapseEmptyExpandedNodes();let c=n(this._items,r);if(!c||!s)return;let l={itemId:r,item:{...c},items:this.items,oldParentId:i,newParentId:a,oldIndex:Number(t.oldIndex??-1),newIndex:Number(t.newIndex??-1)};this._clearDropState(),u(this,`mint-tree-change`,{items:l.items,itemId:r}),i===a?u(this,`mint-tree-reorder`,l):u(this,`mint-tree-reparent`,l);let d=`${c.label} moved${a?` into ${n(this._items,a)?.label||`a group`}`:` to the top level`}.`;this._dragExpansion?.itemId===r?window.setTimeout(()=>{this.isConnected&&(this._render(),this._focusRow(r),this._announce(d))},155):(this._render(),this._focusRow(r),this._announce(d))},this._onKeydown=e=>{let t=e.target instanceof Element?e.target.closest(`[data-mint-tree-row]`):null;if(!t)return;if(e.altKey&&[`ArrowUp`,`ArrowDown`].includes(e.key)){e.preventDefault();let n=t.getAttribute(`data-tree-id`)||``;if(n){this._keyboardFocusRestore&&window.clearTimeout(this._keyboardFocusRestore.timer);let e={id:n,x:window.scrollX,y:window.scrollY,timer:0};e.timer=window.setTimeout(()=>{this._keyboardFocusRestore===e&&(this._keyboardFocusRestore=null)},2e3),this._keyboardFocusRestore=e}return}let i=t.getAttribute(`data-tree-id`)||``;if(e.altKey&&e.key===`ArrowRight`){e.preventDefault(),this._keyboardIndent(i);return}if(e.altKey&&e.key===`ArrowLeft`){e.preventDefault(),this._keyboardOutdent(i);return}let a=[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].filter(e=>!e.closest(`mint-sortable[hidden]`)),o=a.indexOf(t);if(e.key===`ArrowDown`)e.preventDefault(),a[o+1]?.focus({preventScroll:!0});else if(e.key===`ArrowUp`)e.preventDefault(),a[o-1]?.focus({preventScroll:!0});else if(e.key===`ArrowRight`)e.preventDefault(),this._expandedIds.has(i)?a[o+1]?.focus({preventScroll:!0}):this._setExpanded(i,!0,!0);else if(e.key===`ArrowLeft`)if(e.preventDefault(),this._expandedIds.has(i))this._setExpanded(i,!1,!0);else{let e=r(this._items,i)?.parentId;e&&[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].find(t=>t.getAttribute(`data-tree-id`)===e)?.focus({preventScroll:!0})}else if(e.key===`Enter`||e.key===` `||e.key===`Spacebar`){let r=e.target instanceof Element?e.target.closest(`[data-tree-command="select"]`):null;(t===e.target||r)&&(e.preventDefault(),n(this._items,i)?.children?.length?this._setExpanded(i,!this._expandedIds.has(i),!0):this._select(i))}}}static get observedAttributes(){return[`selected-id`,`max-depth`,`allow-nesting`,`disabled`,`loading`,`create-label`,`empty-label`,`delete-confirmation`,`expanded-ids`]}connectedCallback(){this._root||(this._selectedId=f(this.getAttribute(`selected-id`)),this._expandedIds=this.hasAttribute(`expanded-ids`)?this._readExpandedIds(this.getAttribute(`expanded-ids`)):this._defaultExpandedIds(this._items),this.addEventListener(`click`,this._onClick),this.addEventListener(`keydown`,this._onKeydown,!0),this.addEventListener(`mint-sortable-start`,this._onSortableStart),this.addEventListener(`mint-sortable-end`,this._onSortableEnd),this.addEventListener(`mint-sortable-drag`,this._onSortableDrag),this.addEventListener(`mint-sortable-drag-over`,this._onSortableDragOver),this.addEventListener(`mint-sortable-before-drop`,this._onSortableBeforeDrop),this.addEventListener(`mint-sortable-change`,this._onSortableChange),this._render())}disconnectedCallback(){this._dragExpansion?.timer!==null&&this._dragExpansion?.timer!==void 0&&window.clearTimeout(this._dragExpansion.timer),this._keyboardFocusRestore&&window.clearTimeout(this._keyboardFocusRestore.timer),this._selectionClickSuppressionTimer!==null&&window.clearTimeout(this._selectionClickSuppressionTimer),this._selectionClickSuppressionTimer=null,this._suppressSelectionClick=!1,this._keyboardFocusRestore=null,this._dragExpansion=null,this._autoExpandedIds.clear(),this._dragHoverExpandedId=null,this.classList.remove(`mint-tree-drag-active`),this.removeEventListener(`click`,this._onClick),this.removeEventListener(`keydown`,this._onKeydown,!0),this.removeEventListener(`mint-sortable-start`,this._onSortableStart),this.removeEventListener(`mint-sortable-end`,this._onSortableEnd),this.removeEventListener(`mint-sortable-drag`,this._onSortableDrag),this.removeEventListener(`mint-sortable-drag-over`,this._onSortableDragOver),this.removeEventListener(`mint-sortable-before-drop`,this._onSortableBeforeDrop),this.removeEventListener(`mint-sortable-change`,this._onSortableChange),this._root=null}attributeChangedCallback(e,t,n){if(!(t===n||!this.isConnected)){if(e===`selected-id`){this._selectedId=f(n),this._syncSelectionDOM();return}e===`expanded-ids`&&(this._expandedIds=this._readExpandedIds(n)),this._render()}}get items(){return t(this._items)}set items(e){this._items=t(Array.isArray(e)?e:[]),this._undoStack=[],this._redoStack=[],this.hasAttribute(`expanded-ids`)||(this._expandedIds=this._defaultExpandedIds(this._items)),this.isConnected&&this._render()}get selectedId(){return this._selectedId}set selectedId(e){this._selectedId=f(e),this._selectedId===null?this.removeAttribute(`selected-id`):this.setAttribute(`selected-id`,this._selectedId)}get expandedIds(){return[...this._expandedIds]}set expandedIds(e){this._expandedIds=new Set((Array.isArray(e)?e:[]).map(String)),this.isConnected&&this._render()}save(){u(this,`mint-tree-save`,{items:this.items})}select(e){this._select(String(e))}expand(e){this._setExpanded(String(e),!0,!0)}collapse(e){this._setExpanded(String(e),!1,!0)}_readExpandedIds(e){if(!e)return this._defaultExpandedIds(this._items);try{let t=JSON.parse(e);return new Set(Array.isArray(t)?t.map(String):[])}catch{return new Set(e.split(`,`).map(e=>e.trim()).filter(Boolean))}}_defaultExpandedIds(e){let t=new Set,n=e=>e.forEach(e=>{e.children?.length&&(t.add(String(e.id)),n(e.children))});return n(e),t}_maxDepth(){let e=Number.parseInt(this.getAttribute(`max-depth`)||``,10);return Number.isFinite(e)&&e>0?e:1/0}_allowNesting(){return!this.hasAttribute(`allow-nesting`)||d(this,`allow-nesting`)}_disabled(){return d(this,`disabled`)}_isLoading(){return d(this,`loading`)}_render(){let e=document.activeElement instanceof HTMLElement?document.activeElement.closest(`[data-mint-tree-row]`):null,t=e&&this.contains(e)?e.getAttribute(`data-tree-id`):null;t&&this._keyboardFocusRestore&&(this._keyboardFocusRestore.id=t);let n=document.createElement(`div`);n.className=`mint-tree-shell`,n.setAttribute(`role`,`tree`),n.setAttribute(`aria-label`,this.getAttribute(`aria-label`)||`Hierarchical items`),n.setAttribute(`aria-busy`,String(this._isLoading()));let r=document.createElement(`div`);r.className=`mint-tree-toolbar`;let i=document.createElement(`span`);i.className=`mint-tree-count`,i.textContent=`${this._countItems()} ${this._countItems()===1?`item`:`items`}`,r.appendChild(i);let a=document.createElement(`div`);a.className=`mint-tree-toolbar-actions`;let o=this._createButton(``,`ghost`,`undo`);o.setAttribute(`icon`,`undo`),o.setAttribute(`aria-label`,`Undo last change`),o.setAttribute(`title`,`Undo`),(!this._undoStack.length||this._disabled())&&o.setAttribute(`disabled`,`true`);let s=this._createButton(``,`ghost`,`redo`);s.setAttribute(`icon`,`redo`),s.setAttribute(`aria-label`,`Redo last undone change`),s.setAttribute(`title`,`Redo`),(!this._redoStack.length||this._disabled())&&s.setAttribute(`disabled`,`true`);let c=this._createButton(``,`ghost`,`expand-all`);c.setAttribute(`icon`,`expand`),c.setAttribute(`aria-label`,`Expand all`),c.setAttribute(`title`,`Expand all`);let l=this._createButton(``,`ghost`,`collapse-all`);if(l.setAttribute(`icon`,`collapse`),l.setAttribute(`aria-label`,`Collapse all`),l.setAttribute(`title`,`Collapse all`),a.append(o,s,c,l),r.appendChild(a),n.appendChild(r),this._isLoading()){let e=document.createElement(`div`);e.className=`mint-tree-loading`,e.setAttribute(`aria-label`,`Loading items`);let t=document.createElement(`mint-spinner`);t.setAttribute(`size`,`small`),e.appendChild(t),n.appendChild(e)}else if(this._items.length)n.appendChild(this._createList(this._items,null,0));else{let e=document.createElement(`div`);e.className=`mint-tree-empty`,e.textContent=this.getAttribute(`empty-label`)||`No items yet.`,n.appendChild(e)}this._liveRegion=document.createElement(`div`),this._liveRegion.className=`mint-tree-live-region`,this._liveRegion.setAttribute(`role`,`status`),this._liveRegion.setAttribute(`aria-live`,`polite`),this._liveRegion.setAttribute(`aria-atomic`,`true`),n.appendChild(this._liveRegion);let u=document.createElement(`mint-confirm-action`);u.className=`mint-tree-confirm`,this._confirm=u,n.appendChild(u),this.replaceChildren(n),this._root=n,this.classList.add(`mint-tree`),this._disabled()?this.setAttribute(`aria-disabled`,`true`):this.removeAttribute(`aria-disabled`);let d=this._keyboardFocusRestore;d&&(this._focusRow(d.id),window.scrollTo({left:d.x,top:d.y,behavior:`instant`}),requestAnimationFrame(()=>{this._keyboardFocusRestore===d&&(this._focusRow(d.id),window.scrollTo({left:d.x,top:d.y,behavior:`instant`}))}))}_countItems(e=this._items){return e.reduce((e,t)=>e+1+this._countItems(t.children||[]),0)}_createButton(e,t,n){let r=document.createElement(`mint-button`);return r.textContent=e,r.setAttribute(`variant`,t),r.setAttribute(`data-tree-command`,n),r}_createList(e,t,n){let r=document.createElement(`mint-sortable`);r.id=`${this._treeId}-list-${t??`root`}`,r.setAttribute(`group`,this._treeId),r.setAttribute(`data-tree-parent-id`,t??``),r.setAttribute(`role`,`group`),r.setAttribute(`data-tree-depth`,String(n)),r.setAttribute(`direction`,`vertical`),r.setAttribute(`gap`,`1`),r.setAttribute(`handle-selector`,`[data-mint-sortable-handle]`),r.setAttribute(`animation-duration`,`320`),r.setAttribute(`item-key-attribute`,`data-tree-id`);let i=document.createElement(`mint-stack`);i.setAttribute(`direction`,`vertical`),i.setAttribute(`gap`,`1`);for(let t of e)i.appendChild(this._createNode(t,n));return r.appendChild(i),r}_createNode(e,t){let n=String(e.id),r=Array.isArray(e.children)?e.children:[],i=e.canHaveChildren!==!1&&this._allowNesting()&&t+a(e)<this._maxDepth(),o=document.createElement(`div`);o.className=`mint-tree-node`,o.setAttribute(`data-tree-id`,n),o.setAttribute(`role`,`treeitem`),o.setAttribute(`data-mint-tree-row`,``),o.setAttribute(`aria-level`,String(t+1)),o.setAttribute(`aria-selected`,String(this._selectedId===n)),o.setAttribute(`tabindex`,this._selectedId===n||this._selectedId===null&&t===0&&this._items[0]?.id===e.id?`0`:`-1`),o.setAttribute(`aria-label`,e.label),r.length&&o.setAttribute(`aria-expanded`,String(this._expandedIds.has(n))),(e.disabled||this._disabled())&&o.setAttribute(`aria-disabled`,`true`),(e.draggable===!1||this._disabled())&&o.setAttribute(`data-sortable-disabled`,``);let s=document.createElement(`div`);s.className=`mint-tree-row`,s.setAttribute(`data-tree-id`,n);let c=document.createElement(`span`);c.className=`mint-tree-drag-handle`,c.setAttribute(`data-mint-sortable-handle`,``),c.setAttribute(`role`,`button`),c.setAttribute(`tabindex`,`-1`),c.setAttribute(`aria-label`,`Drag ${e.label} to move`);let l=document.createElement(`mint-icon`);if(l.setAttribute(`name`,`grip-dots`),l.setAttribute(`aria-hidden`,`true`),c.appendChild(l),s.appendChild(c),r.length){let t=document.createElement(`mint-button`);t.className=`mint-tree-expand`,t.setAttribute(`variant`,`ghost`),t.setAttribute(`icon`,this._expandedIds.has(n)?`caret-up`:`caret-down`),t.setAttribute(`data-tree-command`,`toggle`),t.setAttribute(`data-tree-id`,n),t.setAttribute(`aria-label`,`${this._expandedIds.has(n)?`Collapse`:`Expand`} ${e.label}`),t.setAttribute(`aria-expanded`,String(this._expandedIds.has(n))),(this._disabled()||e.disabled===!0)&&t.setAttribute(`disabled`,`true`),s.appendChild(t)}else{let e=document.createElement(`span`);e.className=`mint-tree-expand-spacer`,e.setAttribute(`aria-hidden`,`true`),s.appendChild(e)}let u=document.createElement(`span`);if(u.className=`mint-tree-label`,u.setAttribute(`data-tree-command`,`select`),u.setAttribute(`data-tree-id`,n),i&&(u.setAttribute(`data-mint-sortable-drop-container`,`${this._treeId}-list-${n}`),u.setAttribute(`data-mint-sortable-drop-end`,``)),e.icon){let t=document.createElement(`mint-icon`);t.setAttribute(`name`,String(e.icon)),t.setAttribute(`aria-hidden`,`true`),u.appendChild(t)}let d=document.createElement(`span`);if(d.className=`mint-tree-label-text`,d.textContent=e.label,u.appendChild(d),s.appendChild(u),e.metadata){let t=document.createElement(`span`);t.className=`mint-tree-metadata`,t.textContent=String(e.metadata),s.appendChild(t)}let f=document.createElement(`span`);f.className=`mint-tree-nest-target`,f.setAttribute(`data-mint-sortable-drop-container`,`${this._treeId}-list-${n}`),f.setAttribute(`data-mint-sortable-drop-end`,``),f.setAttribute(`aria-hidden`,`true`);let p=document.createElement(`mint-icon`);p.setAttribute(`name`,`arrow-right`),p.setAttribute(`aria-hidden`,`true`),f.appendChild(p),i&&s.appendChild(f);let m=this._createActions(e,i);s.appendChild(m),o.appendChild(s);let h=this._createList(r,n,t+1);return h.classList.add(`mint-tree-children`),h.hidden=!this._expandedIds.has(n),o.appendChild(h),o}_createActions(e,t){let i=document.createElement(`div`);i.className=`mint-tree-actions`;let a=`${this._treeId}-actions-trigger-${encodeURIComponent(String(e.id))}`,o=`${a}-popover`,s=document.createElement(`mint-button`);s.id=a,s.setAttribute(`variant`,`ghost`),s.setAttribute(`icon`,`ellipsis`),s.setAttribute(`aria-label`,`Actions for ${e.label}`),s.setAttribute(`aria-haspopup`,`menu`),i.appendChild(s);let c=document.createElement(`mint-popover`);c.id=o,c.setAttribute(`trigger-id`,a),c.setAttribute(`direction`,`down`),c.setAttribute(`trigger-align`,`end`),c.setAttribute(`padding`,`0.3rem`);let l=document.createElement(`div`);l.className=`mint-tree-menu`,l.setAttribute(`role`,`menu`);let u=(t,n,r=!1)=>{let i=document.createElement(`mint-button`);i.textContent=n,i.setAttribute(`variant`,`ghost`),i.setAttribute(`full-width`,`true`),i.setAttribute(`align`,`left`),i.setAttribute(`role`,`menuitem`),i.setAttribute(`data-tree-command`,t),i.setAttribute(`data-tree-id`,String(e.id)),(r||e.disabled===!0||this._disabled())&&i.setAttribute(`disabled`,`true`),l.appendChild(i)},d=Array.isArray(e.actions)?e.actions:null;if(d)for(let t of d){let n=document.createElement(`mint-button`);n.textContent=t.label,n.setAttribute(`variant`,`ghost`),n.setAttribute(`full-width`,`true`),n.setAttribute(`align`,`left`),n.setAttribute(`role`,`menuitem`),n.setAttribute(`data-tree-command`,`custom`),n.setAttribute(`data-tree-id`,String(e.id)),n.setAttribute(`data-tree-action`,t.id),(t.disabled===!0||e.disabled===!0||this._disabled())&&n.setAttribute(`disabled`,`true`),t.icon&&n.setAttribute(`icon`,t.icon),t.tone&&n.setAttribute(`tone`,t.tone),l.appendChild(n)}else{let i=r(this._items,e.id),a=i?.siblings||[],o=a.findIndex(t=>String(t.id)===String(e.id)),s=o>0?a[o-1]:null,c=i?.parentId?n(this._items,i.parentId):null;u(`move-up`,`Move up`,o<=0),u(`move-down`,`Move down`,o<0||o>=a.length-1),u(`nest-previous`,`Nest under previous item`,!s||!this._isValidDrop(String(e.id),String(s.id))),u(`outdent`,`Move to parent level`,!c),u(`create-child`,`Add child`,!t),u(`edit`,`Edit`),u(`delete`,`Delete`)}return c.appendChild(l),i.appendChild(c),i}_closeItemPopover(e){(e.closest(`.mint-tree-menu`)?.closest(`mint-popover`))?.close?.()}async _confirmDelete(e){let t=n(this._items,e);!t||!this._confirm?.showConfirm||await this._confirm.showConfirm({question:this.getAttribute(`delete-confirmation`)||`Delete “${t.label}”?`,tone:`danger`,confirmLabel:`Delete`,cancelLabel:`Cancel`})&&u(this,`mint-tree-delete`,{item:{...t},itemId:e,items:this.items})}_moveByCommand(e,t){let n=r(this._items,e);if(!n)return;let i=n.siblings.findIndex(t=>String(t.id)===e),a=n.parentId,o=i;if(t===`move-up`)o=i-1;else if(t===`move-down`)o=i+1;else if(t===`nest-previous`){let e=n.siblings[i-1];if(!e)return;a=String(e.id),o=(e.children||[]).length}else if(t===`outdent`){if(n.parentId===null)return;let e=r(this._items,n.parentId);if(!e)return;a=e.parentId,o=e.siblings.findIndex(e=>String(e.id)===n.parentId)+1}else return;try{let t=c(this._items,e,a,o,{maxDepth:this._maxDepth(),allowNesting:this._allowNesting()});this._applyMove(t)}catch{}}_applyMove(e){this._recordHistory(),this._items=e.items,this._collapseEmptyExpandedNodes(),e.newParentId&&this._expandedIds.add(e.newParentId),this._render(),this._focusRow(String(e.item.id));let t={itemId:String(e.item.id),item:{...e.item},items:this.items,oldParentId:e.oldParentId,newParentId:e.newParentId,oldIndex:e.oldIndex,newIndex:e.newIndex};u(this,`mint-tree-change`,{items:t.items,itemId:t.itemId}),u(this,t.oldParentId===t.newParentId?`mint-tree-reorder`:`mint-tree-reparent`,t),this._announce(`${t.item.label} moved${t.newParentId?` into ${n(this._items,t.newParentId)?.label||`a group`}`:` to the top level`}.`)}_select(e){if(this.classList.contains(`mint-tree-drag-active`))return;let t=n(this._items,e);!t||t.disabled||this._disabled()||(this._selectedId=e,this.setAttribute(`selected-id`,e),this._syncSelectionDOM(),u(this,`mint-tree-select`,{item:{...t},itemId:e,items:this.items}))}_syncSelectionDOM(){(this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]).forEach(e=>{let t=e.getAttribute(`data-tree-id`)===this._selectedId;e.setAttribute(`aria-selected`,String(t)),e.tabIndex=t?0:-1})}_setExpanded(e,t,r){let i=n(this._items,e);!i||i.disabled||this._disabled()||(t?this._expandedIds.add(e):this._expandedIds.delete(e),this._syncNodeExpanded(e),r&&u(this,t?`mint-tree-expand`:`mint-tree-collapse`,{itemId:e,item:{...i},expandedIds:this.expandedIds}))}_syncExpandedDOM(){this._root?.querySelectorAll(`[data-mint-tree-row]`).forEach(e=>this._syncNodeExpanded(e.getAttribute(`data-tree-id`)||``))}_syncNodeExpanded(e){let t=[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].find(t=>t.getAttribute(`data-tree-id`)===e),r=t?.querySelector(`:scope > mint-sortable.mint-tree-children`);if(!t||!r)return;let i=this._expandedIds.has(e);t.setAttribute(`aria-expanded`,String(i));let a=t.querySelector(`[data-tree-command="toggle"]`);a?.setAttribute(`aria-expanded`,String(i)),a?.setAttribute(`aria-label`,`${i?`Collapse`:`Expand`} ${n(this._items,e)?.label||`item`}`),a?.setAttribute(`icon`,i?`caret-up`:`caret-down`),r.hidden=!i}_setTransientExpanded(e,t){let r=[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].find(t=>t.getAttribute(`data-tree-id`)===e);if(!r)return;r.setAttribute(`aria-expanded`,String(t));let i=r.querySelector(`[data-tree-command="toggle"]`),a=n(this._items,e)?.label||`item`;i?.setAttribute(`aria-expanded`,String(t)),i?.setAttribute(`aria-label`,`${t?`Collapse`:`Expand`} ${a}`),i?.setAttribute(`icon`,t?`caret-up`:`caret-down`)}_isValidDrop(e,t){let r=n(this._items,e);if(!r)return!1;let i=t===null?null:n(this._items,t);return!(t!==null&&!i||i?.disabled||i&&(String(i.id)===e||this._isDescendant(r,i.id))||!this._allowNesting()&&i||i?.canHaveChildren===!1||i?.acceptsTypes?.length&&!i.acceptsTypes.includes(r.type||``)||(i?this._depthOf(String(i.id)):-1)+1+a(r)>this._maxDepth())}_isDescendant(e,t){return(e.children||[]).some(e=>String(e.id)===String(t)||this._isDescendant(e,t))}_depthOf(e){let t=r(this._items,e);return t?this._depthOfParent(t.parentId):-1}_depthOfParent(e){if(e===null)return 0;let t=r(this._items,e);return t?this._depthOfParent(t.parentId)+1:0}_readItemsFromDOM(e){let t=e.querySelector(`:scope > mint-stack`);return t?[...t.children].filter(e=>e instanceof HTMLElement&&e.classList.contains(`mint-tree-node`)).map(e=>{let t=e.getAttribute(`data-tree-id`)||``,r=n(this._items,t),i=e.querySelector(`:scope > mint-sortable.mint-tree-children`);return{...r||{id:t,label:t},children:i?this._readItemsFromDOM(i):[]}}):[]}_clearDropState(){this._root?.querySelectorAll(`.mint-tree-drop-invalid`).forEach(e=>e.classList.remove(`mint-tree-drop-invalid`))}_collapseEmptyExpandedNodes(){for(let e of[...this._expandedIds]){let t=n(this._items,e);!t||t.children?.length||(this._expandedIds.delete(e),this._syncNodeExpanded(e),u(this,`mint-tree-collapse`,{itemId:e,item:{...t},expandedIds:this.expandedIds,automatic:!0,empty:!0}))}}_announce(e){this._liveRegion&&(this._liveRegion.textContent=e)}_recordHistory(){this._undoStack.push(t(this._items)),this._undoStack.length>50&&this._undoStack.shift(),this._redoStack=[]}_undo(){let e=this._undoStack.pop();e&&(this._redoStack.push(t(this._items)),this._items=e,this._render(),u(this,`mint-tree-change`,{items:this.items,itemId:this._selectedId}),u(this,`mint-tree-undo`,{items:this.items}))}_redo(){let e=this._redoStack.pop();e&&(this._undoStack.push(t(this._items)),this._items=e,this._render(),u(this,`mint-tree-change`,{items:this.items,itemId:this._selectedId}),u(this,`mint-tree-redo`,{items:this.items}))}_keyboardIndent(e){let t=r(this._items,e);if(!t||t.siblings.indexOf(t.item)<=0)return;let n=t.siblings[t.siblings.indexOf(t.item)-1];try{let t=c(this._items,e,n.id,(n.children||[]).length,{maxDepth:this._maxDepth(),allowNesting:this._allowNesting()});this._recordHistory(),this._items=t.items,this._expandedIds.add(String(n.id)),this._render(),this._focusRow(e),u(this,`mint-tree-reparent`,{itemId:e,item:{...t.item},items:this.items,oldParentId:t.oldParentId,newParentId:t.newParentId,oldIndex:t.oldIndex,newIndex:t.newIndex})}catch{}}_keyboardOutdent(e){let t=r(this._items,e);if(!t||t.parentId===null)return;let n=r(this._items,t.parentId);if(!n)return;let i=n.siblings.findIndex(e=>String(e.id)===t.parentId)+1;try{let t=c(this._items,e,n.parentId,i,{maxDepth:this._maxDepth(),allowNesting:this._allowNesting()});this._recordHistory(),this._items=t.items,this._render(),this._focusRow(e),u(this,`mint-tree-reparent`,{itemId:e,item:{...t.item},items:this.items,oldParentId:t.oldParentId,newParentId:t.newParentId,oldIndex:t.oldIndex,newIndex:t.newIndex})}catch{}}_focusRow(e){[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].find(t=>t.getAttribute(`data-tree-id`)===e)?.focus({preventScroll:!0})}};customElements.get(`mint-tree`)||e.t(`mint-tree`,p),exports.MintTree=p,exports.default=p;
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}}),require(`../chunks/icon-rvYvpQ_h.js`);const e=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/spinner-DfPbEa2d.js`),require(`../chunks/button-B1-XW0BK.js`),require(`../chunks/confirm-action-BvxL3-Xz.js`),require(`../chunks/popover-wGdggZ-a.js`),require(`../chunks/sortable-CVK48xj1.js`);function t(e=[]){s(e);let t=e=>e.map(e=>({...e,children:Array.isArray(e.children)?t(e.children):[]}));return t(e)}function n(e,t){let r=String(t);for(let t of e){if(String(t.id)===r)return t;let e=n(t.children||[],r);if(e)return e}return null}function r(e,t,n=null){let i=String(t);for(let t of e){if(String(t.id)===i)return{parentId:n,siblings:e,item:t};let a=r(t.children||[],i,String(t.id));if(a)return a}return null}function i(e,t,n=0){let r=String(t);for(let t of e){if(String(t.id)===r)return n;let e=i(t.children||[],r,n+1);if(e>=0)return e}return-1}function a(e){let t=Array.isArray(e?.children)?e.children:[];return t.length?1+Math.max(...t.map(a)):1}function o(e,t){return String(e.id)===String(t)?!0:(e.children||[]).some(e=>o(e,t))}function s(e){let t=new Set,n=e=>{for(let r of e){if(r.id===null||r.id===void 0||String(r.id)===``)throw Error(`Every tree item must have a non-empty identifier.`);let e=String(r.id);if(t.has(e))throw Error(`Tree item identifiers must be unique. Duplicate identifier: ${e}.`);t.add(e),n(r.children||[])}};n(e)}function c(e,s,c,l,u={}){let d=t(e),f=r(d,s);if(!f)throw Error(`Tree item ${s} was not found.`);if(f.item.disabled||f.item.draggable===!1)throw Error(`Disabled tree items cannot be moved.`);let p=c==null||c===``?null:n(d,c);if(c!=null&&c!==``&&!p)throw Error(`Target parent ${c} was not found.`);if(p&&o(f.item,p.id))throw Error(`A tree item cannot be moved inside itself or one of its descendants.`);if(p?.disabled)throw Error(`Disabled tree items cannot contain children.`);if(u.allowNesting===!1&&p)throw Error(`Nesting is disabled for this tree.`);if(p?.canHaveChildren===!1)throw Error(`The target item cannot contain children.`);if(p?.acceptsTypes?.length&&!p.acceptsTypes.includes(f.item.type))throw Error(`The target item does not accept this item type.`);let m=p?p.children:d,h=f.siblings.findIndex(e=>String(e.id)===String(s)),[g]=f.siblings.splice(h,1),_=Math.min(Math.max(0,Number.isFinite(l)?Math.trunc(l):m.length),m.length);m.splice(_,0,g);let v=Number.isFinite(u.maxDepth)?Math.max(1,Math.trunc(u.maxDepth)):1/0;if((p?i(d,p.id)+1:0)+a(g)>v)throw Error(`Moving this branch would exceed the maximum tree depth of ${v}.`);return{items:d,item:g,oldParentId:f.parentId,newParentId:p?String(p.id):null,oldIndex:h,newIndex:_}}var l=0;function u(e,t,n){e.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:n}))}function d(e,t){let n=e.getAttribute(t);return n===``||n===`true`}function f(e){return e==null||e===``?null:String(e)}var p=class extends HTMLElement{constructor(...e){super(...e),this._items=[],this._undoStack=[],this._redoStack=[],this._selectedId=null,this._expandedIds=new Set,this._root=null,this._confirm=null,this._treeId=`mint-tree-${++l}`,this._liveRegion=null,this._dragExpansion=null,this._autoExpandedIds=new Set,this._dragHoverExpandedId=null,this._keyboardFocusRestore=null,this._suppressSelectionClick=!1,this._selectionClickSuppressionTimer=null,this._onClick=e=>{let t=e.target instanceof Element?e.target.closest(`[data-tree-command]`):null;if(!t||!this.contains(t))return;let r=t.getAttribute(`data-tree-command`),i=t.getAttribute(`data-tree-id`);if(r===`create-root`)u(this,`mint-tree-create`,{parentId:null,items:this.items});else if(r===`expand-all`)this._expandedIds=this._defaultExpandedIds(this._items),this._syncExpandedDOM(),u(this,`mint-tree-expand`,{all:!0,expandedIds:this.expandedIds});else if(r===`collapse-all`)this._expandedIds.clear(),this._syncExpandedDOM(),u(this,`mint-tree-collapse`,{all:!0,expandedIds:[]});else if(r===`undo`)this._undo();else if(r===`redo`)this._redo();else if(r===`toggle`&&i){let e=!this._expandedIds.has(i);this._setExpanded(i,e,!0)}else if(r===`select`&&i){if(this.classList.contains(`mint-tree-drag-active`)||this._suppressSelectionClick){e.preventDefault(),this._suppressSelectionClick=!1,this._selectionClickSuppressionTimer!==null&&window.clearTimeout(this._selectionClickSuppressionTimer),this._selectionClickSuppressionTimer=null;return}this._select(i)}else if(r===`create-child`&&i)this._closeItemPopover(t),u(this,`mint-tree-create`,{parentId:i,items:this.items});else if(r===`edit`&&i){this._closeItemPopover(t);let e=n(this._items,i);e&&u(this,`mint-tree-edit`,{item:{...e},itemId:i,items:this.items})}else if(r===`delete`&&i)this._closeItemPopover(t),this._confirmDelete(i);else if([`move-up`,`move-down`,`nest-previous`,`outdent`].includes(r||``)&&i)this._closeItemPopover(t),this._moveByCommand(i,r||``);else if(r===`custom`&&i){this._closeItemPopover(t);let e=n(this._items,i),r=t.getAttribute(`data-tree-action`)||``,a=e?.actions?.find(e=>e.id===r);if(e&&a){let t={item:{...e},itemId:i,action:{...a,onSelect:void 0},items:this.items};u(this,`mint-tree-action`,t),a.onSelect?.({item:{...e},itemId:i,action:a,items:this.items})}}},this._onSortableDrag=e=>{let t=e.detail;if(!t||!Number.isFinite(t.clientX)||!Number.isFinite(t.clientY))return;let r=document.elementFromPoint(t.clientX,t.clientY),i=r?.closest(`[data-mint-tree-row]`),a=t.item?.getAttribute(`data-tree-id`)||``,o=null;if(i&&i.getAttribute(`data-tree-id`)!==a){let e=i.querySelector(`:scope > .mint-tree-row`)?.getBoundingClientRect()||i.getBoundingClientRect(),r=e.height?(t.clientY-e.top)/e.height:0;if(r>.22&&r<.78){let e=i.getAttribute(`data-tree-id`)||``;n(this._items,e)&&this._isValidDrop(a,e)&&(o=e)}}if(!o&&this._dragHoverExpandedId){let e=[...this._root?.querySelectorAll(`[data-tree-id]`)??[]].find(e=>e.getAttribute(`data-tree-id`)===this._dragHoverExpandedId)?.querySelector(`:scope > mint-sortable.mint-tree-children`);r&&e?.contains(r)&&(o=this._dragHoverExpandedId)}if(this._dragHoverExpandedId&&this._dragHoverExpandedId!==o){let e=this._dragHoverExpandedId;this._dragHoverExpandedId=null,this._autoExpandedIds.delete(e),this._expandedIds.delete(e),this._syncNodeExpanded(e);let t=n(this._items,e);t&&u(this,`mint-tree-collapse`,{itemId:e,item:{...t},expandedIds:this.expandedIds,automatic:!0})}if(o){let e=n(this._items,o);e&&!this._expandedIds.has(o)&&(this._expandedIds.add(o),this._autoExpandedIds.add(o),this._dragHoverExpandedId=o,this._syncNodeExpanded(o),u(this,`mint-tree-expand`,{itemId:o,item:{...e},expandedIds:this.expandedIds,automatic:!0}))}},this._onSortableStart=()=>{this.classList.add(`mint-tree-drag-active`),this._dragHoverExpandedId=null,this._dragExpansion?.timer!==null&&this._dragExpansion?.timer!==void 0&&window.clearTimeout(this._dragExpansion.timer),this._dragExpansion=null;let e=this._root?.querySelector(`.mint-sortable-dragging[data-tree-id]`),t=e?.getAttribute(`data-tree-id`)||``,n=e?.querySelector(`:scope > mint-sortable.mint-tree-children`);if(!e||!t||!n||n.hidden||!this._expandedIds.has(t))return;let r=e.querySelector(`:scope > .mint-tree-row`),i=this._root?.querySelector(`.mint-sortable-placeholder`),a=n.getBoundingClientRect().height;n.style.height=`${a}px`,n.style.overflow=`hidden`,e.style.height=`auto`,e.style.overflow=`hidden`,this._dragExpansion={itemId:t,item:e,childList:n,timer:null},this._setTransientExpanded(t,!1),n.offsetHeight,requestAnimationFrame(()=>{this._dragExpansion?.childList===n&&(n.classList.add(`mint-tree-drag-collapse`),n.style.height=`0px`,i&&r&&(i.style.minHeight=`${r.getBoundingClientRect().height}px`))})},this._onSortableEnd=e=>{this.classList.remove(`mint-tree-drag-active`),this._suppressSelectionClick=!0,this._selectionClickSuppressionTimer!==null&&window.clearTimeout(this._selectionClickSuppressionTimer),this._selectionClickSuppressionTimer=window.setTimeout(()=>{this._suppressSelectionClick=!1,this._selectionClickSuppressionTimer=null},300);let t=e.detail,r=t&&!t.cancelled?f(t.newParentId):null;for(let e of this._autoExpandedIds){if(e===r)continue;this._expandedIds.delete(e),this._syncNodeExpanded(e);let t=n(this._items,e);t&&u(this,`mint-tree-collapse`,{itemId:e,item:{...t},expandedIds:this.expandedIds,automatic:!0})}this._autoExpandedIds.clear(),this._dragHoverExpandedId=null;let i=this._dragExpansion;if(!i)return;i.item=[...this._root?.querySelectorAll(`[data-tree-id]`)??[]].find(e=>e.getAttribute(`data-tree-id`)===i.itemId)||i.item,i.childList=i.item.querySelector(`:scope > mint-sortable.mint-tree-children`)||i.childList;let{item:a,childList:o,itemId:s}=i;o.style.height=`0px`,o.style.overflow=`hidden`,o.classList.remove(`mint-tree-drag-collapse`),this._setTransientExpanded(s,!0),o.offsetHeight;let c=o.scrollHeight;requestAnimationFrame(()=>{this._dragExpansion===i&&(o.style.height=`${c}px`)}),i.timer=window.setTimeout(()=>{o.style.height=``,o.style.overflow=``,o.style.opacity=``,this._dragExpansion=null},155)},this._onSortableDragOver=e=>{let t=e,{item:r,target:i}=t.detail||{};if(!r||!i)return;this._root?.querySelectorAll(`.mint-tree-drop-invalid`).forEach(e=>e.classList.remove(`mint-tree-drop-invalid`));let a=this._root?.querySelector(`.mint-sortable-placeholder`),o=r.getAttribute(`data-tree-id`)||``,s=f(i.getAttribute(`data-tree-parent-id`)),c=i===t.detail.source||this._isValidDrop(o,s),l=s?n(this._items,s):null;c&&i!==t.detail.source&&l?a?.setAttribute(`data-drop-label`,`Drop here to nest under ${l.label}`):c&&i===this._root?.querySelector(`:scope > mint-sortable`)?a?.setAttribute(`data-drop-label`,`Drop here to move to the top level`):a?.removeAttribute(`data-drop-label`);let u=(Number.isFinite(t.detail.clientX)&&Number.isFinite(t.detail.clientY)?document.elementFromPoint(t.detail.clientX,t.detail.clientY):null)?.closest(`[data-mint-tree-row]`);u&&u.getAttribute(`data-tree-id`)!==o&&!c&&u.classList.add(`mint-tree-drop-invalid`),c||t.preventDefault()},this._onSortableBeforeDrop=e=>{let t=e,n=t.detail;if(!n?.item||!n.target)return;let r=n.item.getAttribute(`data-tree-id`)||``,i=f(n.target.getAttribute(`data-tree-parent-id`));n.target!==n.source&&!this._isValidDrop(r,i)&&t.preventDefault()},this._onSortableChange=e=>{let t=e.detail;if(!t||t.cancelled)return;let r=t.itemId||``,i=f(t.oldParentId),a=f(t.newParentId),o=this._root?.querySelector(`:scope > mint-sortable`);if(!o)return;let s=n(this._items,r);this._recordHistory(),this._items=this._readItemsFromDOM(o),this._collapseEmptyExpandedNodes();let c=n(this._items,r);if(!c||!s)return;let l={itemId:r,item:{...c},items:this.items,oldParentId:i,newParentId:a,oldIndex:Number(t.oldIndex??-1),newIndex:Number(t.newIndex??-1)};this._clearDropState(),u(this,`mint-tree-change`,{items:l.items,itemId:r}),i===a?u(this,`mint-tree-reorder`,l):u(this,`mint-tree-reparent`,l);let d=`${c.label} moved${a?` into ${n(this._items,a)?.label||`a group`}`:` to the top level`}.`;this._dragExpansion?.itemId===r?window.setTimeout(()=>{this.isConnected&&(this._render(),this._focusRow(r),this._announce(d))},155):(this._render(),this._focusRow(r),this._announce(d))},this._onKeydown=e=>{let t=e.target instanceof Element?e.target.closest(`[data-mint-tree-row]`):null;if(!t)return;if(e.altKey&&[`ArrowUp`,`ArrowDown`].includes(e.key)){e.preventDefault();let n=t.getAttribute(`data-tree-id`)||``;if(n){this._keyboardFocusRestore&&window.clearTimeout(this._keyboardFocusRestore.timer);let e={id:n,x:window.scrollX,y:window.scrollY,timer:0};e.timer=window.setTimeout(()=>{this._keyboardFocusRestore===e&&(this._keyboardFocusRestore=null)},2e3),this._keyboardFocusRestore=e}return}let i=t.getAttribute(`data-tree-id`)||``;if(e.altKey&&e.key===`ArrowRight`){e.preventDefault(),this._keyboardIndent(i);return}if(e.altKey&&e.key===`ArrowLeft`){e.preventDefault(),this._keyboardOutdent(i);return}let a=[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].filter(e=>!e.closest(`mint-sortable[hidden]`)),o=a.indexOf(t);if(e.key===`ArrowDown`)e.preventDefault(),a[o+1]?.focus({preventScroll:!0});else if(e.key===`ArrowUp`)e.preventDefault(),a[o-1]?.focus({preventScroll:!0});else if(e.key===`ArrowRight`)e.preventDefault(),this._expandedIds.has(i)?a[o+1]?.focus({preventScroll:!0}):this._setExpanded(i,!0,!0);else if(e.key===`ArrowLeft`)if(e.preventDefault(),this._expandedIds.has(i))this._setExpanded(i,!1,!0);else{let e=r(this._items,i)?.parentId;e&&[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].find(t=>t.getAttribute(`data-tree-id`)===e)?.focus({preventScroll:!0})}else if(e.key===`Enter`||e.key===` `||e.key===`Spacebar`){let r=e.target instanceof Element?e.target.closest(`[data-tree-command="select"]`):null;(t===e.target||r)&&(e.preventDefault(),n(this._items,i)?.children?.length?this._setExpanded(i,!this._expandedIds.has(i),!0):this._select(i))}}}static get observedAttributes(){return[`selected-id`,`max-depth`,`allow-nesting`,`disabled`,`loading`,`create-label`,`empty-label`,`delete-confirmation`,`expanded-ids`]}connectedCallback(){this._root||(this._selectedId=f(this.getAttribute(`selected-id`)),this._expandedIds=this.hasAttribute(`expanded-ids`)?this._readExpandedIds(this.getAttribute(`expanded-ids`)):this._defaultExpandedIds(this._items),this.addEventListener(`click`,this._onClick),this.addEventListener(`keydown`,this._onKeydown,!0),this.addEventListener(`mint-sortable-start`,this._onSortableStart),this.addEventListener(`mint-sortable-end`,this._onSortableEnd),this.addEventListener(`mint-sortable-drag`,this._onSortableDrag),this.addEventListener(`mint-sortable-drag-over`,this._onSortableDragOver),this.addEventListener(`mint-sortable-before-drop`,this._onSortableBeforeDrop),this.addEventListener(`mint-sortable-change`,this._onSortableChange),this._render())}disconnectedCallback(){this._dragExpansion?.timer!==null&&this._dragExpansion?.timer!==void 0&&window.clearTimeout(this._dragExpansion.timer),this._keyboardFocusRestore&&window.clearTimeout(this._keyboardFocusRestore.timer),this._selectionClickSuppressionTimer!==null&&window.clearTimeout(this._selectionClickSuppressionTimer),this._selectionClickSuppressionTimer=null,this._suppressSelectionClick=!1,this._keyboardFocusRestore=null,this._dragExpansion=null,this._autoExpandedIds.clear(),this._dragHoverExpandedId=null,this.classList.remove(`mint-tree-drag-active`),this.removeEventListener(`click`,this._onClick),this.removeEventListener(`keydown`,this._onKeydown,!0),this.removeEventListener(`mint-sortable-start`,this._onSortableStart),this.removeEventListener(`mint-sortable-end`,this._onSortableEnd),this.removeEventListener(`mint-sortable-drag`,this._onSortableDrag),this.removeEventListener(`mint-sortable-drag-over`,this._onSortableDragOver),this.removeEventListener(`mint-sortable-before-drop`,this._onSortableBeforeDrop),this.removeEventListener(`mint-sortable-change`,this._onSortableChange),this._root=null}attributeChangedCallback(e,t,n){if(!(t===n||!this.isConnected)){if(e===`selected-id`){this._selectedId=f(n),this._syncSelectionDOM();return}e===`expanded-ids`&&(this._expandedIds=this._readExpandedIds(n)),this._render()}}get items(){return t(this._items)}set items(e){this._items=t(Array.isArray(e)?e:[]),this._undoStack=[],this._redoStack=[],this.hasAttribute(`expanded-ids`)||(this._expandedIds=this._defaultExpandedIds(this._items)),this.isConnected&&this._render()}get selectedId(){return this._selectedId}set selectedId(e){this._selectedId=f(e),this._selectedId===null?this.removeAttribute(`selected-id`):this.setAttribute(`selected-id`,this._selectedId)}get expandedIds(){return[...this._expandedIds]}set expandedIds(e){this._expandedIds=new Set((Array.isArray(e)?e:[]).map(String)),this.isConnected&&this._render()}save(){u(this,`mint-tree-save`,{items:this.items})}select(e){this._select(String(e))}expand(e){this._setExpanded(String(e),!0,!0)}collapse(e){this._setExpanded(String(e),!1,!0)}_readExpandedIds(e){if(!e)return this._defaultExpandedIds(this._items);try{let t=JSON.parse(e);return new Set(Array.isArray(t)?t.map(String):[])}catch{return new Set(e.split(`,`).map(e=>e.trim()).filter(Boolean))}}_defaultExpandedIds(e){let t=new Set,n=e=>e.forEach(e=>{e.children?.length&&(t.add(String(e.id)),n(e.children))});return n(e),t}_maxDepth(){let e=Number.parseInt(this.getAttribute(`max-depth`)||``,10);return Number.isFinite(e)&&e>0?e:1/0}_allowNesting(){return!this.hasAttribute(`allow-nesting`)||d(this,`allow-nesting`)}_disabled(){return d(this,`disabled`)}_isLoading(){return d(this,`loading`)}_render(){let e=document.activeElement instanceof HTMLElement?document.activeElement.closest(`[data-mint-tree-row]`):null,t=e&&this.contains(e)?e.getAttribute(`data-tree-id`):null;t&&this._keyboardFocusRestore&&(this._keyboardFocusRestore.id=t);let n=document.createElement(`div`);n.className=`mint-tree-shell`,n.setAttribute(`role`,`tree`),n.setAttribute(`aria-label`,this.getAttribute(`aria-label`)||`Hierarchical items`),n.setAttribute(`aria-busy`,String(this._isLoading()));let r=document.createElement(`div`);r.className=`mint-tree-toolbar`;let i=document.createElement(`span`);i.className=`mint-tree-count`,i.textContent=`${this._countItems()} ${this._countItems()===1?`item`:`items`}`,r.appendChild(i);let a=document.createElement(`div`);a.className=`mint-tree-toolbar-actions`;let o=this._createButton(``,`ghost`,`undo`);o.setAttribute(`icon`,`undo`),o.setAttribute(`aria-label`,`Undo last change`),o.setAttribute(`title`,`Undo`),(!this._undoStack.length||this._disabled())&&o.setAttribute(`disabled`,`true`);let s=this._createButton(``,`ghost`,`redo`);s.setAttribute(`icon`,`redo`),s.setAttribute(`aria-label`,`Redo last undone change`),s.setAttribute(`title`,`Redo`),(!this._redoStack.length||this._disabled())&&s.setAttribute(`disabled`,`true`);let c=this._createButton(``,`ghost`,`expand-all`);c.setAttribute(`icon`,`expand`),c.setAttribute(`aria-label`,`Expand all`),c.setAttribute(`title`,`Expand all`);let l=this._createButton(``,`ghost`,`collapse-all`);if(l.setAttribute(`icon`,`collapse`),l.setAttribute(`aria-label`,`Collapse all`),l.setAttribute(`title`,`Collapse all`),a.append(o,s,c,l),r.appendChild(a),n.appendChild(r),this._isLoading()){let e=document.createElement(`div`);e.className=`mint-tree-loading`,e.setAttribute(`aria-label`,`Loading items`);let t=document.createElement(`mint-spinner`);t.setAttribute(`size`,`small`),e.appendChild(t),n.appendChild(e)}else if(this._items.length)n.appendChild(this._createList(this._items,null,0));else{let e=document.createElement(`div`);e.className=`mint-tree-empty`,e.textContent=this.getAttribute(`empty-label`)||`No items yet.`,n.appendChild(e)}this._liveRegion=document.createElement(`div`),this._liveRegion.className=`mint-tree-live-region`,this._liveRegion.setAttribute(`role`,`status`),this._liveRegion.setAttribute(`aria-live`,`polite`),this._liveRegion.setAttribute(`aria-atomic`,`true`),n.appendChild(this._liveRegion);let u=document.createElement(`mint-confirm-action`);u.className=`mint-tree-confirm`,this._confirm=u,n.appendChild(u),this.replaceChildren(n),this._root=n,this.classList.add(`mint-tree`),this._disabled()?this.setAttribute(`aria-disabled`,`true`):this.removeAttribute(`aria-disabled`);let d=this._keyboardFocusRestore;d&&(this._focusRow(d.id),window.scrollTo({left:d.x,top:d.y,behavior:`instant`}),requestAnimationFrame(()=>{this._keyboardFocusRestore===d&&(this._focusRow(d.id),window.scrollTo({left:d.x,top:d.y,behavior:`instant`}))}))}_countItems(e=this._items){return e.reduce((e,t)=>e+1+this._countItems(t.children||[]),0)}_createButton(e,t,n){let r=document.createElement(`mint-button`);return r.textContent=e,r.setAttribute(`variant`,t),r.setAttribute(`data-tree-command`,n),r}_createList(e,t,n){let r=document.createElement(`mint-sortable`);r.id=`${this._treeId}-list-${t??`root`}`,r.setAttribute(`group`,this._treeId),r.setAttribute(`data-tree-parent-id`,t??``),r.setAttribute(`role`,`group`),r.setAttribute(`data-tree-depth`,String(n)),r.setAttribute(`direction`,`vertical`),r.setAttribute(`gap`,`1`),r.setAttribute(`handle-selector`,`[data-mint-sortable-handle]`),r.setAttribute(`animation-duration`,`320`),r.setAttribute(`item-key-attribute`,`data-tree-id`);let i=document.createElement(`mint-stack`);i.setAttribute(`direction`,`vertical`),i.setAttribute(`gap`,`1`);for(let t of e)i.appendChild(this._createNode(t,n));return r.appendChild(i),r}_createNode(e,t){let n=String(e.id),r=Array.isArray(e.children)?e.children:[],i=e.canHaveChildren!==!1&&this._allowNesting()&&t+a(e)<this._maxDepth(),o=document.createElement(`div`);o.className=`mint-tree-node`,o.setAttribute(`data-tree-id`,n),o.setAttribute(`role`,`treeitem`),o.setAttribute(`data-mint-tree-row`,``),o.setAttribute(`aria-level`,String(t+1)),o.setAttribute(`aria-selected`,String(this._selectedId===n)),o.setAttribute(`tabindex`,this._selectedId===n||this._selectedId===null&&t===0&&this._items[0]?.id===e.id?`0`:`-1`),o.setAttribute(`aria-label`,e.label),r.length&&o.setAttribute(`aria-expanded`,String(this._expandedIds.has(n))),(e.disabled||this._disabled())&&o.setAttribute(`aria-disabled`,`true`),(e.draggable===!1||this._disabled())&&o.setAttribute(`data-sortable-disabled`,``);let s=document.createElement(`div`);s.className=`mint-tree-row`,s.setAttribute(`data-tree-id`,n);let c=document.createElement(`span`);c.className=`mint-tree-drag-handle`,c.setAttribute(`data-mint-sortable-handle`,``),c.setAttribute(`role`,`button`),c.setAttribute(`tabindex`,`-1`),c.setAttribute(`aria-label`,`Drag ${e.label} to move`);let l=document.createElement(`mint-icon`);if(l.setAttribute(`name`,`grip-dots`),l.setAttribute(`aria-hidden`,`true`),c.appendChild(l),s.appendChild(c),r.length){let t=document.createElement(`mint-button`);t.className=`mint-tree-expand`,t.setAttribute(`variant`,`ghost`),t.setAttribute(`icon`,this._expandedIds.has(n)?`caret-up`:`caret-down`),t.setAttribute(`data-tree-command`,`toggle`),t.setAttribute(`data-tree-id`,n),t.setAttribute(`aria-label`,`${this._expandedIds.has(n)?`Collapse`:`Expand`} ${e.label}`),t.setAttribute(`aria-expanded`,String(this._expandedIds.has(n))),(this._disabled()||e.disabled===!0)&&t.setAttribute(`disabled`,`true`),s.appendChild(t)}else{let e=document.createElement(`span`);e.className=`mint-tree-expand-spacer`,e.setAttribute(`aria-hidden`,`true`),s.appendChild(e)}let u=document.createElement(`span`);if(u.className=`mint-tree-label`,u.setAttribute(`data-tree-command`,`select`),u.setAttribute(`data-tree-id`,n),i&&(u.setAttribute(`data-mint-sortable-drop-container`,`${this._treeId}-list-${n}`),u.setAttribute(`data-mint-sortable-drop-end`,``)),e.icon){let t=document.createElement(`mint-icon`);t.setAttribute(`name`,String(e.icon)),t.setAttribute(`aria-hidden`,`true`),u.appendChild(t)}let d=document.createElement(`span`);if(d.className=`mint-tree-label-text`,d.textContent=e.label,u.appendChild(d),s.appendChild(u),e.metadata){let t=document.createElement(`span`);t.className=`mint-tree-metadata`,t.textContent=String(e.metadata),s.appendChild(t)}let f=document.createElement(`span`);f.className=`mint-tree-nest-target`,f.setAttribute(`data-mint-sortable-drop-container`,`${this._treeId}-list-${n}`),f.setAttribute(`data-mint-sortable-drop-end`,``),f.setAttribute(`aria-hidden`,`true`);let p=document.createElement(`mint-icon`);p.setAttribute(`name`,`arrow-right`),p.setAttribute(`aria-hidden`,`true`),f.appendChild(p),i&&s.appendChild(f);let m=this._createActions(e,i);s.appendChild(m),o.appendChild(s);let h=this._createList(r,n,t+1);return h.classList.add(`mint-tree-children`),h.hidden=!this._expandedIds.has(n),o.appendChild(h),o}_createActions(e,t){let i=document.createElement(`div`);i.className=`mint-tree-actions`;let a=`${this._treeId}-actions-trigger-${encodeURIComponent(String(e.id))}`,o=`${a}-popover`,s=document.createElement(`mint-button`);s.id=a,s.setAttribute(`variant`,`ghost`),s.setAttribute(`icon`,`ellipsis`),s.setAttribute(`aria-label`,`Actions for ${e.label}`),s.setAttribute(`aria-haspopup`,`menu`),i.appendChild(s);let c=document.createElement(`mint-popover`);c.id=o,c.setAttribute(`trigger-id`,a),c.setAttribute(`direction`,`down`),c.setAttribute(`trigger-align`,`end`),c.setAttribute(`padding`,`0.3rem`);let l=document.createElement(`div`);l.className=`mint-tree-menu`,l.setAttribute(`role`,`menu`);let u=(t,n,r=!1)=>{let i=document.createElement(`mint-button`);i.textContent=n,i.setAttribute(`variant`,`ghost`),i.setAttribute(`full-width`,`true`),i.setAttribute(`align`,`left`),i.setAttribute(`role`,`menuitem`),i.setAttribute(`data-tree-command`,t),i.setAttribute(`data-tree-id`,String(e.id)),(r||e.disabled===!0||this._disabled())&&i.setAttribute(`disabled`,`true`),l.appendChild(i)},d=Array.isArray(e.actions)?e.actions:null;if(d)for(let t of d){let n=document.createElement(`mint-button`);n.textContent=t.label,n.setAttribute(`variant`,`ghost`),n.setAttribute(`full-width`,`true`),n.setAttribute(`align`,`left`),n.setAttribute(`role`,`menuitem`),n.setAttribute(`data-tree-command`,`custom`),n.setAttribute(`data-tree-id`,String(e.id)),n.setAttribute(`data-tree-action`,t.id),(t.disabled===!0||e.disabled===!0||this._disabled())&&n.setAttribute(`disabled`,`true`),t.icon&&n.setAttribute(`icon`,t.icon),t.tone&&n.setAttribute(`tone`,t.tone),l.appendChild(n)}else{let i=r(this._items,e.id),a=i?.siblings||[],o=a.findIndex(t=>String(t.id)===String(e.id)),s=o>0?a[o-1]:null,c=i?.parentId?n(this._items,i.parentId):null;u(`move-up`,`Move up`,o<=0),u(`move-down`,`Move down`,o<0||o>=a.length-1),u(`nest-previous`,`Nest under previous item`,!s||!this._isValidDrop(String(e.id),String(s.id))),u(`outdent`,`Move to parent level`,!c),u(`create-child`,`Add child`,!t),u(`edit`,`Edit`),u(`delete`,`Delete`)}return c.appendChild(l),i.appendChild(c),i}_closeItemPopover(e){(e.closest(`.mint-tree-menu`)?.closest(`mint-popover`))?.close?.()}async _confirmDelete(e){let t=n(this._items,e);!t||!this._confirm?.showConfirm||await this._confirm.showConfirm({question:this.getAttribute(`delete-confirmation`)||`Delete “${t.label}”?`,tone:`danger`,confirmLabel:`Delete`,cancelLabel:`Cancel`})&&u(this,`mint-tree-delete`,{item:{...t},itemId:e,items:this.items})}_moveByCommand(e,t){let n=r(this._items,e);if(!n)return;let i=n.siblings.findIndex(t=>String(t.id)===e),a=n.parentId,o=i;if(t===`move-up`)o=i-1;else if(t===`move-down`)o=i+1;else if(t===`nest-previous`){let e=n.siblings[i-1];if(!e)return;a=String(e.id),o=(e.children||[]).length}else if(t===`outdent`){if(n.parentId===null)return;let e=r(this._items,n.parentId);if(!e)return;a=e.parentId,o=e.siblings.findIndex(e=>String(e.id)===n.parentId)+1}else return;try{let t=c(this._items,e,a,o,{maxDepth:this._maxDepth(),allowNesting:this._allowNesting()});this._applyMove(t)}catch{}}_applyMove(e){this._recordHistory(),this._items=e.items,this._collapseEmptyExpandedNodes(),e.newParentId&&this._expandedIds.add(e.newParentId),this._render(),this._focusRow(String(e.item.id));let t={itemId:String(e.item.id),item:{...e.item},items:this.items,oldParentId:e.oldParentId,newParentId:e.newParentId,oldIndex:e.oldIndex,newIndex:e.newIndex};u(this,`mint-tree-change`,{items:t.items,itemId:t.itemId}),u(this,t.oldParentId===t.newParentId?`mint-tree-reorder`:`mint-tree-reparent`,t),this._announce(`${t.item.label} moved${t.newParentId?` into ${n(this._items,t.newParentId)?.label||`a group`}`:` to the top level`}.`)}_select(e){if(this.classList.contains(`mint-tree-drag-active`))return;let t=n(this._items,e);!t||t.disabled||this._disabled()||(this._selectedId=e,this.setAttribute(`selected-id`,e),this._syncSelectionDOM(),u(this,`mint-tree-select`,{item:{...t},itemId:e,items:this.items}))}_syncSelectionDOM(){(this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]).forEach(e=>{let t=e.getAttribute(`data-tree-id`)===this._selectedId;e.setAttribute(`aria-selected`,String(t)),e.tabIndex=t?0:-1})}_setExpanded(e,t,r){let i=n(this._items,e);!i||i.disabled||this._disabled()||(t?this._expandedIds.add(e):this._expandedIds.delete(e),this._syncNodeExpanded(e),r&&u(this,t?`mint-tree-expand`:`mint-tree-collapse`,{itemId:e,item:{...i},expandedIds:this.expandedIds}))}_syncExpandedDOM(){this._root?.querySelectorAll(`[data-mint-tree-row]`).forEach(e=>this._syncNodeExpanded(e.getAttribute(`data-tree-id`)||``))}_syncNodeExpanded(e){let t=[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].find(t=>t.getAttribute(`data-tree-id`)===e),r=t?.querySelector(`:scope > mint-sortable.mint-tree-children`);if(!t||!r)return;let i=this._expandedIds.has(e);t.setAttribute(`aria-expanded`,String(i));let a=t.querySelector(`[data-tree-command="toggle"]`);a?.setAttribute(`aria-expanded`,String(i)),a?.setAttribute(`aria-label`,`${i?`Collapse`:`Expand`} ${n(this._items,e)?.label||`item`}`),a?.setAttribute(`icon`,i?`caret-up`:`caret-down`),r.hidden=!i}_setTransientExpanded(e,t){let r=[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].find(t=>t.getAttribute(`data-tree-id`)===e);if(!r)return;r.setAttribute(`aria-expanded`,String(t));let i=r.querySelector(`[data-tree-command="toggle"]`),a=n(this._items,e)?.label||`item`;i?.setAttribute(`aria-expanded`,String(t)),i?.setAttribute(`aria-label`,`${t?`Collapse`:`Expand`} ${a}`),i?.setAttribute(`icon`,t?`caret-up`:`caret-down`)}_isValidDrop(e,t){let r=n(this._items,e);if(!r)return!1;let i=t===null?null:n(this._items,t);return!(t!==null&&!i||i?.disabled||i&&(String(i.id)===e||this._isDescendant(r,i.id))||!this._allowNesting()&&i||i?.canHaveChildren===!1||i?.acceptsTypes?.length&&!i.acceptsTypes.includes(r.type||``)||(i?this._depthOf(String(i.id)):-1)+1+a(r)>this._maxDepth())}_isDescendant(e,t){return(e.children||[]).some(e=>String(e.id)===String(t)||this._isDescendant(e,t))}_depthOf(e){let t=r(this._items,e);return t?this._depthOfParent(t.parentId):-1}_depthOfParent(e){if(e===null)return 0;let t=r(this._items,e);return t?this._depthOfParent(t.parentId)+1:0}_readItemsFromDOM(e){let t=e.querySelector(`:scope > mint-stack`);return t?[...t.children].filter(e=>e instanceof HTMLElement&&e.classList.contains(`mint-tree-node`)).map(e=>{let t=e.getAttribute(`data-tree-id`)||``,r=n(this._items,t),i=e.querySelector(`:scope > mint-sortable.mint-tree-children`);return{...r||{id:t,label:t},children:i?this._readItemsFromDOM(i):[]}}):[]}_clearDropState(){this._root?.querySelectorAll(`.mint-tree-drop-invalid`).forEach(e=>e.classList.remove(`mint-tree-drop-invalid`))}_collapseEmptyExpandedNodes(){for(let e of[...this._expandedIds]){let t=n(this._items,e);!t||t.children?.length||(this._expandedIds.delete(e),this._syncNodeExpanded(e),u(this,`mint-tree-collapse`,{itemId:e,item:{...t},expandedIds:this.expandedIds,automatic:!0,empty:!0}))}}_announce(e){this._liveRegion&&(this._liveRegion.textContent=e)}_recordHistory(){this._undoStack.push(t(this._items)),this._undoStack.length>50&&this._undoStack.shift(),this._redoStack=[]}_undo(){let e=this._undoStack.pop();e&&(this._redoStack.push(t(this._items)),this._items=e,this._render(),u(this,`mint-tree-change`,{items:this.items,itemId:this._selectedId}),u(this,`mint-tree-undo`,{items:this.items}))}_redo(){let e=this._redoStack.pop();e&&(this._undoStack.push(t(this._items)),this._items=e,this._render(),u(this,`mint-tree-change`,{items:this.items,itemId:this._selectedId}),u(this,`mint-tree-redo`,{items:this.items}))}_keyboardIndent(e){let t=r(this._items,e);if(!t||t.siblings.indexOf(t.item)<=0)return;let n=t.siblings[t.siblings.indexOf(t.item)-1];try{let t=c(this._items,e,n.id,(n.children||[]).length,{maxDepth:this._maxDepth(),allowNesting:this._allowNesting()});this._recordHistory(),this._items=t.items,this._expandedIds.add(String(n.id)),this._render(),this._focusRow(e),u(this,`mint-tree-reparent`,{itemId:e,item:{...t.item},items:this.items,oldParentId:t.oldParentId,newParentId:t.newParentId,oldIndex:t.oldIndex,newIndex:t.newIndex})}catch{}}_keyboardOutdent(e){let t=r(this._items,e);if(!t||t.parentId===null)return;let n=r(this._items,t.parentId);if(!n)return;let i=n.siblings.findIndex(e=>String(e.id)===t.parentId)+1;try{let t=c(this._items,e,n.parentId,i,{maxDepth:this._maxDepth(),allowNesting:this._allowNesting()});this._recordHistory(),this._items=t.items,this._render(),this._focusRow(e),u(this,`mint-tree-reparent`,{itemId:e,item:{...t.item},items:this.items,oldParentId:t.oldParentId,newParentId:t.newParentId,oldIndex:t.oldIndex,newIndex:t.newIndex})}catch{}}_focusRow(e){[...this._root?.querySelectorAll(`[data-mint-tree-row]`)??[]].find(t=>t.getAttribute(`data-tree-id`)===e)?.focus({preventScroll:!0})}};customElements.get(`mint-tree`)||e.t(`mint-tree`,p),exports.MintTree=p,exports.default=p;
|
|
@@ -14,8 +14,8 @@ import { t as e } from "../chunks/register-element-BFYmIynH.js";
|
|
|
14
14
|
import "../chunks/spinner-BjC3nA-C.js";
|
|
15
15
|
import "../chunks/button-CP7K25iD.js";
|
|
16
16
|
import "../chunks/confirm-action-Bf6A7A2j.js";
|
|
17
|
-
import "../chunks/popover-
|
|
18
|
-
import "../chunks/sortable-
|
|
17
|
+
import "../chunks/popover-FdMS4yAD.js";
|
|
18
|
+
import "../chunks/sortable-CNlF0_gv.js";
|
|
19
19
|
//#region src/components/tree/tree-utils.js
|
|
20
20
|
function t(e = []) {
|
|
21
21
|
s(e);
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/* mint-ui component style: datetime-picker */
|
|
2
|
+
/*! tailwindcss v4.2.2 | MIT License | https://tailwindcss.com */
|
|
3
|
+
@layer utilities{.visible{visibility:visible}.static{position:static}.hidden{display:none}.inline{display:inline}}mint-datetime-picker{width:100%;min-width:calc(var(--spacing,.25rem) * 0);color:var(--mint-color-text,#28372d);font-family:var(--mint-font-sans,inherit);display:block}mint-datetime-picker .mint-datetime-picker-content{min-width:calc(var(--spacing,.25rem) * 0);gap:calc(var(--spacing,.25rem) * 4);display:grid}mint-datetime-picker .mint-date-picker-inputs{display:none!important}mint-datetime-picker .mint-datetime-picker-panel{box-sizing:border-box;border:1px solid var(--mint-color-border,#dfe6e0);background:var(--mint-color-surface-raised,#fff);min-width:min(18rem,100vw - 2rem);color:var(--mint-color-text,#28372d);border-radius:.8rem;padding:.75rem;box-shadow:0 12px 32px #19281e24}mint-datetime-picker .mint-datetime-picker-time-heading{border:0;border-bottom:1px solid var(--mint-color-border,#dfe6e0);width:100%;color:var(--mint-color-text-secondary,#66736a);font:inherit;text-align:left;text-decoration-line:underline;text-decoration-style:dotted;-webkit-text-decoration-color:var(--mint-color-primary,#315943);-webkit-text-decoration-color:var(--mint-color-primary,#315943);-webkit-text-decoration-color:var(--mint-color-primary,#315943);text-decoration-color:var(--mint-color-primary,#315943);text-underline-offset:.2em;cursor:pointer;background:0 0;margin:0 0 .5rem;padding:.4rem .45rem .65rem;font-weight:600;display:block}mint-datetime-picker .mint-datetime-picker-time-heading:hover{color:var(--mint-color-text,#28372d)}mint-datetime-picker .mint-time-picker-popover{width:100%;min-width:0;max-width:none;box-shadow:none;background:0 0;border:0;border-radius:0;padding:0}mint-datetime-picker .mint-datetime-picker-info{color:var(--mint-color-text-secondary,#66736a)}
|