@tarragon-ui/js 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ajax-form.d.ts +2 -0
- package/dist/components/ajax-form.d.ts.map +1 -0
- package/dist/components/ajax-html.d.ts +2 -0
- package/dist/components/ajax-html.d.ts.map +1 -0
- package/dist/components/dropdown.d.ts +2 -0
- package/dist/components/dropdown.d.ts.map +1 -0
- package/dist/components/exclusive-checkbox.d.ts +2 -0
- package/dist/components/exclusive-checkbox.d.ts.map +1 -0
- package/dist/components/select-all.d.ts +2 -0
- package/dist/components/select-all.d.ts.map +1 -0
- package/dist/components/until-selected.d.ts +2 -0
- package/dist/components/until-selected.d.ts.map +1 -0
- package/dist/components/validate-form.d.ts +2 -0
- package/dist/components/validate-form.d.ts.map +1 -0
- package/dist/constants.d.ts +95 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/emitEvent.d.ts +2 -0
- package/dist/emitEvent.d.ts.map +1 -0
- package/dist/fetch.d.ts +42 -0
- package/dist/fetch.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1176 -0
- package/dist/query-cache.d.ts +57 -0
- package/dist/query-cache.d.ts.map +1 -0
- package/package.json +46 -0
- package/readme.md +3 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1176 @@
|
|
|
1
|
+
const y = "tui-", M = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
2
|
+
var f = /* @__PURE__ */ ((e) => (e.Click = "click", e.DoubleClick = "dblclick", e.MouseUp = "mouseup", e.MouseDown = "mousedown", e.ContextMenu = "contextmenu", e.MouseWheel = "mousewheel", e.DOMMouseScroll = "DOMMouseScroll", e.MouseOver = "mouseover", e.MouseOut = "mouseout", e.MouseMove = "mousemove", e.SelectStart = "selectstart", e.SelectEnd = "selectend", e.KeyDown = "keydown", e.KeyPress = "keypress", e.KeyUp = "keyup", e.OrientationChange = "orientationchange", e.TouchStart = "touchstart", e.TouchMove = "touchmove", e.TouchEnd = "touchend", e.TouchCancel = "touchcancel", e.PointerDown = "pointerdown", e.PointerMove = "pointermove", e.PointerUp = "pointerup", e.PointerLeave = "pointerleave", e.PointerCancel = "pointercancel", e.GestureStart = "gesturestart", e.GestureChange = "gesturechange", e.GestureEnd = "gestureend", e.Focus = "focus", e.Blur = "blur", e.Change = "change", e.Reset = "reset", e.Select = "select", e.Submit = "submit", e.FocusIn = "focusin", e.FocusOut = "focusout", e.Load = "load", e.Unload = "unload", e.BeforeUnload = "beforeunload", e.Resize = "resize", e.Move = "move", e.DOMContentLoaded = "DOMContentLoaded", e.ReadyStateChange = "readystatechange", e.Error = "error", e.Abort = "abort", e.Scroll = "scroll", e.Input = "input", e.Toggle = "toggle", e.Close = "close", e))(f || {});
|
|
3
|
+
const h = {
|
|
4
|
+
AjaxForm: {
|
|
5
|
+
Name: `${y}ajax-form`,
|
|
6
|
+
Event: { Form: "form" }
|
|
7
|
+
},
|
|
8
|
+
AjaxHtml: {
|
|
9
|
+
Name: `${y}ajax-html`
|
|
10
|
+
},
|
|
11
|
+
ExclusiveCheckbox: {
|
|
12
|
+
Name: `${y}exclusive-checkbox`,
|
|
13
|
+
Event: { Toggle: "toggle" }
|
|
14
|
+
},
|
|
15
|
+
Dropdown: { Name: `${y}dropdown` },
|
|
16
|
+
SelectAll: { Name: `${y}select-all`, Event: { Toggle: "toggle" } },
|
|
17
|
+
UntilSelected: { Name: `${y}until-selected` },
|
|
18
|
+
ValidateForm: {
|
|
19
|
+
Name: `${y}validate-form`,
|
|
20
|
+
Event: { Validate: "validate" }
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
function E(e, t, n, s = !1) {
|
|
24
|
+
const a = new Event(`${e}:${t}`, {
|
|
25
|
+
bubbles: !0,
|
|
26
|
+
cancelable: s
|
|
27
|
+
});
|
|
28
|
+
return n.dispatchEvent(a);
|
|
29
|
+
}
|
|
30
|
+
const T = "data-validate-group";
|
|
31
|
+
customElements.define(
|
|
32
|
+
h.ValidateForm.Name,
|
|
33
|
+
class extends HTMLElement {
|
|
34
|
+
form = null;
|
|
35
|
+
groups = void 0;
|
|
36
|
+
connectedCallback() {
|
|
37
|
+
if (this.form = this.querySelector("form"), !this.form) {
|
|
38
|
+
console.warn("No form was found");
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
this.groups = Array.from(this.form.querySelectorAll(`[${T}]`)), this.form.setAttribute("novalidate", ""), this.form.addEventListener("submit", this), this.form.addEventListener("input", this), this.form.addEventListener("blur", this, { capture: !0 }), E(h.ValidateForm.Name, h.ValidateForm.Event.Validate, this), this.setAttribute("is-ready", "");
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Handle events
|
|
45
|
+
* @param {Event} event The event object
|
|
46
|
+
*/
|
|
47
|
+
handleEvent(e) {
|
|
48
|
+
if (e.type === "blur") {
|
|
49
|
+
this.onBlur(e);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (e.type === "input") {
|
|
53
|
+
this.onInput(e);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
this.onSubmit(e);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Handle input events
|
|
60
|
+
* @param {Event} event The event object
|
|
61
|
+
*/
|
|
62
|
+
onInput(e) {
|
|
63
|
+
if (!(e.target instanceof Element)) return;
|
|
64
|
+
const t = e.target.closest("[validate-group]"), n = t ?? e.target;
|
|
65
|
+
if (t?.setAttribute(T, "interacted"), !(!t && n.getAttribute("aria-invalid") !== "true")) {
|
|
66
|
+
if (t) {
|
|
67
|
+
this.isGroupValid(t);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
this.isFieldValid(n);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Handle blur events
|
|
75
|
+
* @param {Event} event The event object
|
|
76
|
+
*/
|
|
77
|
+
onBlur(e) {
|
|
78
|
+
if (!(e.target instanceof Element)) return;
|
|
79
|
+
const t = e.target.closest(`[${T}="interacted"]`);
|
|
80
|
+
if (t) {
|
|
81
|
+
this.isGroupValid(t);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (!e.target.matches(":user-invalid")) {
|
|
85
|
+
this.removeError(e.target);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
this.showError(e.target);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Handle submit events
|
|
92
|
+
* @param {Event} event The event object
|
|
93
|
+
*/
|
|
94
|
+
onSubmit(e) {
|
|
95
|
+
if (!E(
|
|
96
|
+
h.ValidateForm.Name,
|
|
97
|
+
h.ValidateForm.Event.Validate,
|
|
98
|
+
this,
|
|
99
|
+
!0
|
|
100
|
+
)) return;
|
|
101
|
+
const n = this.checkGroupValidity();
|
|
102
|
+
if (this.checkFieldValidity() && n) {
|
|
103
|
+
E(h.ValidateForm.Name, h.ValidateForm.Event.Validate, this);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation(), this.form?.querySelector(
|
|
107
|
+
'input:invalid, [aria-invalid="true"] :is([type="checkbox"], [type="radio"])'
|
|
108
|
+
)?.focus({ focusVisible: !0 }), E(h.ValidateForm.Name, h.ValidateForm.Event.Validate, this);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Check the validity of fields that can be validated with HTMLFormElement.checkValidity().
|
|
112
|
+
* Show error messages for fields that are not.
|
|
113
|
+
*
|
|
114
|
+
* @return {Boolean} If true, all fields are valid
|
|
115
|
+
*/
|
|
116
|
+
checkFieldValidity() {
|
|
117
|
+
if (!this.form || this.form.checkValidity()) return !0;
|
|
118
|
+
const e = this.form.querySelectorAll(":invalid");
|
|
119
|
+
for (const t of e)
|
|
120
|
+
t instanceof HTMLElement && this.showError(t);
|
|
121
|
+
return !1;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Check if an input is valid and show/remove errors
|
|
125
|
+
* @param {Element} field The field to validate
|
|
126
|
+
* @return {Boolean} If true, field is valid
|
|
127
|
+
*/
|
|
128
|
+
isFieldValid(e) {
|
|
129
|
+
return e.matches(":invalid") ? (this.showError(e), !1) : (this.removeError(e), !0);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Check the validity of all input groups
|
|
133
|
+
* @return {Boolean} If true, all groups are valid
|
|
134
|
+
*/
|
|
135
|
+
checkGroupValidity() {
|
|
136
|
+
if (!this.groups) return !0;
|
|
137
|
+
let e = !0;
|
|
138
|
+
for (const t of this.groups)
|
|
139
|
+
t instanceof HTMLElement && (this.isGroupValid(t) || (e = !1));
|
|
140
|
+
return e;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Check if an input group is valid and show/remove errors
|
|
144
|
+
* @param {Element} group The input group
|
|
145
|
+
* @return {Boolean} If true, the group is valid
|
|
146
|
+
*/
|
|
147
|
+
isGroupValid(e) {
|
|
148
|
+
return e.querySelector("input:checked") ? (this.removeError(e), !0) : (this.showError(e, !0), !1);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Show error message on a field
|
|
152
|
+
* @param {Element} field The field or fieldset
|
|
153
|
+
* @param {Boolean} isGroup If true, field is a fieldset input group
|
|
154
|
+
*/
|
|
155
|
+
showError(e, t = !1) {
|
|
156
|
+
const n = this.getMessage(e, t);
|
|
157
|
+
if (!n) return;
|
|
158
|
+
e.setAttribute("aria-invalid", "true");
|
|
159
|
+
const s = document.querySelector(
|
|
160
|
+
"#validation-message-template"
|
|
161
|
+
), a = !!s, c = e.getAttribute("aria-describedby"), l = c ?? `${y}${crypto.randomUUID()}`;
|
|
162
|
+
if (c) {
|
|
163
|
+
const g = this.form?.querySelector(`#${c}`);
|
|
164
|
+
if (g) {
|
|
165
|
+
if (a) {
|
|
166
|
+
const u = g.querySelector(
|
|
167
|
+
'[data-slot="form-message"]'
|
|
168
|
+
);
|
|
169
|
+
u && (u.textContent = n), g.id = l, e.setAttribute("aria-describedby", l);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
g.textContent = n, g.id = l, e.setAttribute("aria-describedby", l);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
let d;
|
|
177
|
+
if (a) {
|
|
178
|
+
d = s.content.cloneNode(!0).firstElementChild, d.id = l;
|
|
179
|
+
const u = d.querySelector('[data-slot="form-message"]');
|
|
180
|
+
u && (u.textContent = n);
|
|
181
|
+
} else
|
|
182
|
+
d = document.createElement("p"), d.textContent = n, d.id = l, d.className = "form-message";
|
|
183
|
+
e.setAttribute("aria-describedby", l), t ? e.append(d) : e.after(d);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Get the error message text
|
|
187
|
+
* @param {Element} field The field or fieldset
|
|
188
|
+
* @param {Boolean} isGroup If true, field is a fieldset input group
|
|
189
|
+
* @return {String} The error message
|
|
190
|
+
*/
|
|
191
|
+
getMessage(e, t = !1) {
|
|
192
|
+
const n = e.getAttribute("data-validate-message");
|
|
193
|
+
if (n) return n;
|
|
194
|
+
if (t) {
|
|
195
|
+
const a = this.getAttribute("checkbox-group-message") ?? "Please select at least one option.", c = this.getAttribute("radio-group-message") ?? "Please select an option.";
|
|
196
|
+
return e.querySelector('[type="checkbox"]') ? a : c;
|
|
197
|
+
}
|
|
198
|
+
return "validationMessage" in e ? e.validationMessage : "";
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Remove the error message from a field
|
|
202
|
+
* @param {Element} field The field or fieldset
|
|
203
|
+
*/
|
|
204
|
+
removeError(e) {
|
|
205
|
+
e.removeAttribute("aria-invalid");
|
|
206
|
+
const t = e.getAttribute("aria-describedby");
|
|
207
|
+
t && this.form?.querySelector(`#${t}`)?.remove();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
);
|
|
211
|
+
class v {
|
|
212
|
+
static instance = void 0;
|
|
213
|
+
baseUrl;
|
|
214
|
+
baseHeaders = void 0;
|
|
215
|
+
constructor(t, n = {}) {
|
|
216
|
+
this.baseUrl = t, this.baseHeaders = n;
|
|
217
|
+
}
|
|
218
|
+
// Singleton pattern with initial configuration.
|
|
219
|
+
// Subsequent calls without arguments will return the existing instance.
|
|
220
|
+
// If arguments are provided, it reconfigures the existing instance or creates a new one.
|
|
221
|
+
static getInstance(t, n) {
|
|
222
|
+
return v.instance ? (t && (v.instance.baseUrl = t), n && (v.instance.baseHeaders = {
|
|
223
|
+
...v.instance.baseHeaders,
|
|
224
|
+
...n
|
|
225
|
+
})) : v.instance = new v(t, n), v.instance;
|
|
226
|
+
}
|
|
227
|
+
isMethod(t) {
|
|
228
|
+
return ["GET", "PUT", "POST", "PATCH", "DELETE"].includes(t.toUpperCase());
|
|
229
|
+
}
|
|
230
|
+
buildQueryString(t) {
|
|
231
|
+
if (!t) return "";
|
|
232
|
+
const n = new URLSearchParams(t).toString();
|
|
233
|
+
return n ? `?${n}` : "";
|
|
234
|
+
}
|
|
235
|
+
buildHeaders(t) {
|
|
236
|
+
return {
|
|
237
|
+
...this.baseHeaders,
|
|
238
|
+
...t
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
async send(t, n, s) {
|
|
242
|
+
try {
|
|
243
|
+
const a = this.buildQueryString(s.queryParameters), c = `${this.baseUrl}${t}${a}`, l = {
|
|
244
|
+
method: n,
|
|
245
|
+
headers: this.buildHeaders(s.headers)
|
|
246
|
+
};
|
|
247
|
+
n !== "GET" && "data" in s && s.data && (l.body = s.data);
|
|
248
|
+
const d = await fetch(c, l);
|
|
249
|
+
if (!d.ok) {
|
|
250
|
+
const u = {
|
|
251
|
+
message: "Request failed",
|
|
252
|
+
status: d.status
|
|
253
|
+
};
|
|
254
|
+
if (d.headers.get("content-type")?.includes("application/json"))
|
|
255
|
+
try {
|
|
256
|
+
const p = await d.json();
|
|
257
|
+
u.message = p.message ?? p.error ?? u.message;
|
|
258
|
+
} catch (p) {
|
|
259
|
+
u.message = `Failed to parse error JSON: ${u.message}`, u.error = p instanceof Error ? p : new Error(String(p));
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
const p = await d.text();
|
|
263
|
+
p && (u.message = `Server responded with an error: ${p.substring(0, 100)}`);
|
|
264
|
+
}
|
|
265
|
+
return [u, void 0];
|
|
266
|
+
}
|
|
267
|
+
const g = d.headers.get("content-type");
|
|
268
|
+
if (g?.includes("application/json"))
|
|
269
|
+
return [void 0, await d.json()];
|
|
270
|
+
if (g?.includes("text/html")) {
|
|
271
|
+
const u = await d.text();
|
|
272
|
+
return [void 0, { type: "html", document: new DOMParser().parseFromString(u, "text/html") }];
|
|
273
|
+
} else if (g?.includes("text/plain"))
|
|
274
|
+
return [void 0, { type: "json", message: await d.text() }];
|
|
275
|
+
return [void 0, { type: "json", message: "Request successful, no content." }];
|
|
276
|
+
} catch (a) {
|
|
277
|
+
return a instanceof Error ? [{ message: "Network error", error: a }, void 0] : [{ message: "An unknown error occurred" }, void 0];
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
get(t, n) {
|
|
281
|
+
return this.send(t, "GET", n ?? {});
|
|
282
|
+
}
|
|
283
|
+
put(t, n) {
|
|
284
|
+
return this.send(t, "PUT", n ?? {});
|
|
285
|
+
}
|
|
286
|
+
post(t, n) {
|
|
287
|
+
return this.send(t, "POST", n ?? {});
|
|
288
|
+
}
|
|
289
|
+
patch(t, n) {
|
|
290
|
+
return this.send(t, "PATCH", n ?? {});
|
|
291
|
+
}
|
|
292
|
+
delete(t, n) {
|
|
293
|
+
return this.send(t, "DELETE", n ?? {});
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
const L = v.getInstance("", {
|
|
297
|
+
"Content-Type": "application/json"
|
|
298
|
+
}), F = {
|
|
299
|
+
staleTime: 0
|
|
300
|
+
};
|
|
301
|
+
class C {
|
|
302
|
+
static instance = void 0;
|
|
303
|
+
cache = /* @__PURE__ */ new Map();
|
|
304
|
+
subscriptions = /* @__PURE__ */ new Map();
|
|
305
|
+
refetchIntervals = /* @__PURE__ */ new Map();
|
|
306
|
+
static getInstance() {
|
|
307
|
+
return C.instance ??= new C(), C.instance;
|
|
308
|
+
}
|
|
309
|
+
// Centralized state update logic
|
|
310
|
+
updateQueryState(t, n, s) {
|
|
311
|
+
const a = this.cache.get(t), c = a ? { ...a } : {
|
|
312
|
+
data: void 0,
|
|
313
|
+
isFetching: !1,
|
|
314
|
+
error: null,
|
|
315
|
+
meta: { ...F }
|
|
316
|
+
};
|
|
317
|
+
s && (c.meta = { ...c.meta, ...s });
|
|
318
|
+
const l = { ...c, ...n };
|
|
319
|
+
l.meta = {
|
|
320
|
+
...F,
|
|
321
|
+
...c.meta
|
|
322
|
+
}, this.cache.set(t, l), this.notifySubscribers(t, l), this.manageRefetchInterval(t, l.meta.staleTime);
|
|
323
|
+
}
|
|
324
|
+
notifySubscribers(t, n) {
|
|
325
|
+
this.subscriptions.get(t)?.forEach((s) => {
|
|
326
|
+
s(n);
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
manageRefetchInterval(t, n) {
|
|
330
|
+
const s = this.refetchIntervals.get(t);
|
|
331
|
+
if (s && (clearInterval(s), this.refetchIntervals.delete(t)), n && n > 0 && this.subscriptions.has(t) && this.subscriptions.get(t).size > 0) {
|
|
332
|
+
const a = window.setInterval(() => {
|
|
333
|
+
this.invalidateQuery(t);
|
|
334
|
+
}, n);
|
|
335
|
+
this.refetchIntervals.set(t, a);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Subscribes to a query key.
|
|
340
|
+
* @param key The query key.
|
|
341
|
+
* @param callback The function to call when the query's data or state updates.
|
|
342
|
+
* @param options Query options that might affect initial state or refetch behavior.
|
|
343
|
+
* @returns An unsubscribe function.
|
|
344
|
+
*/
|
|
345
|
+
subscribe(t, n, s) {
|
|
346
|
+
this.subscriptions.has(t) || this.subscriptions.set(t, /* @__PURE__ */ new Set()), this.subscriptions.get(t).add(n), this.updateQueryState(t, {}, s);
|
|
347
|
+
const c = this.cache.get(t);
|
|
348
|
+
return c && n(c), this.manageRefetchInterval(t, c?.meta.staleTime ?? 0), () => {
|
|
349
|
+
this.subscriptions.get(t)?.delete(n), this.subscriptions.get(t)?.size === 0 && (this.subscriptions.delete(t), this.manageRefetchInterval(t, 0));
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Gets the current state of a query.
|
|
354
|
+
* @param key The query key.
|
|
355
|
+
* @returns The current QueryResult, or undefined if not initialized.
|
|
356
|
+
*/
|
|
357
|
+
get(t) {
|
|
358
|
+
const n = this.cache.get(t);
|
|
359
|
+
if (n)
|
|
360
|
+
return n;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Sets the data for a query key and notifies subscribers.
|
|
364
|
+
* This is used for pushing data without fetching (e.g., from mutations/forms).
|
|
365
|
+
* @param key The query key.
|
|
366
|
+
* @param data The data to set.
|
|
367
|
+
* @param options Options for this query.
|
|
368
|
+
*/
|
|
369
|
+
setQueryData(t, n, s) {
|
|
370
|
+
this.updateQueryState(
|
|
371
|
+
t,
|
|
372
|
+
{
|
|
373
|
+
data: n,
|
|
374
|
+
error: null,
|
|
375
|
+
isFetching: !1
|
|
376
|
+
},
|
|
377
|
+
s
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Fetches data for a query key. This is an internal method called by subscribe/invalidate.
|
|
382
|
+
* It ensures only one fetch is active at a time for a given key.
|
|
383
|
+
*/
|
|
384
|
+
async fetchQuery(t, n) {
|
|
385
|
+
const s = this.cache.get(t);
|
|
386
|
+
if (!s || s.isFetching)
|
|
387
|
+
return;
|
|
388
|
+
this.updateQueryState(t, {
|
|
389
|
+
isFetching: !0,
|
|
390
|
+
// Always true when a fetch is in progress
|
|
391
|
+
error: null
|
|
392
|
+
});
|
|
393
|
+
const [a, c] = await L.get(t);
|
|
394
|
+
if (a) {
|
|
395
|
+
this.updateQueryState(
|
|
396
|
+
t,
|
|
397
|
+
{
|
|
398
|
+
error: a.message,
|
|
399
|
+
isFetching: !1
|
|
400
|
+
},
|
|
401
|
+
n
|
|
402
|
+
);
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
this.updateQueryState(
|
|
406
|
+
t,
|
|
407
|
+
{
|
|
408
|
+
data: c,
|
|
409
|
+
isFetching: !1,
|
|
410
|
+
error: null
|
|
411
|
+
},
|
|
412
|
+
n
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Invalidates a query, triggering an immediate refetch
|
|
417
|
+
* @param key The query key.
|
|
418
|
+
*/
|
|
419
|
+
invalidateQuery(t) {
|
|
420
|
+
const n = this.cache.get(t);
|
|
421
|
+
if (!n) {
|
|
422
|
+
console.warn(`No query exists for key: ${t}`);
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
n.isFetching || this.fetchQuery(t);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
const S = C.getInstance();
|
|
429
|
+
customElements.define(
|
|
430
|
+
h.AjaxForm.Name,
|
|
431
|
+
class extends HTMLElement {
|
|
432
|
+
form = null;
|
|
433
|
+
announce = null;
|
|
434
|
+
announceTitle = null;
|
|
435
|
+
spinner = null;
|
|
436
|
+
messageSubmitting = "Submitting...";
|
|
437
|
+
messageSuccess = "Data submitted successfully";
|
|
438
|
+
messageError = "An error occurred";
|
|
439
|
+
actionOnSuccess = "none";
|
|
440
|
+
keepFields = !1;
|
|
441
|
+
queryKeyToInvalidate = null;
|
|
442
|
+
isSubmittingAttribute = "is-submitting";
|
|
443
|
+
connectedCallback() {
|
|
444
|
+
if (this.form = this.querySelector("form"), !this.form) return;
|
|
445
|
+
const e = this.querySelector('[role="status"]');
|
|
446
|
+
e ? (this.announce = e, this.announceTitle = e.querySelector(".alert-title")) : (this.announce = document.createElement("div"), this.announce.setAttribute("role", "status"), this.announceTitle = document.createElement("p"), this.announceTitle.className = "alert-title", this.announce.append(this.announceTitle), this.append(this.announce)), this.messageSubmitting = this.getAttribute("message-submitting") ?? this.messageSubmitting, this.messageSuccess = this.getAttribute("message-success") ?? this.messageSuccess, this.messageError = this.getAttribute("message-error") ?? this.messageError, this.keepFields = this.hasAttribute("keep-fields"), this.queryKeyToInvalidate = this.getAttribute("query-key");
|
|
447
|
+
const t = this.getAttribute("action-on-success");
|
|
448
|
+
t === "remove-form" ? this.actionOnSuccess = "remove-form" : t === "remove-message" && (this.actionOnSuccess = "remove-message"), this.spinner = document.createElement("div"), this.spinner.className = "loading", this.spinner.innerHTML = '<div class="spinner"></div>', this.append(this.spinner), this.form.addEventListener("submit", this);
|
|
449
|
+
}
|
|
450
|
+
disconnectedCallback() {
|
|
451
|
+
this.form?.removeEventListener("submit", this);
|
|
452
|
+
}
|
|
453
|
+
async handleEvent(e) {
|
|
454
|
+
e.type === "submit" && await this.handleSubmit(e);
|
|
455
|
+
}
|
|
456
|
+
async handleSubmit(e) {
|
|
457
|
+
if (!this.form || (e.preventDefault(), this.isDisabled())) return;
|
|
458
|
+
this.disable(), this.showStatus(this.messageSubmitting, "pending");
|
|
459
|
+
const { action: t, method: n } = this.form;
|
|
460
|
+
if (!L.isMethod(n)) {
|
|
461
|
+
console.error("Method is not a valid value"), this.showStatus(this.messageError, "error");
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
let s = null;
|
|
465
|
+
this.spinner && (s = this.form.querySelector(":focus"));
|
|
466
|
+
const [a, c] = await L.send(t, n, {
|
|
467
|
+
data: this.serialize(),
|
|
468
|
+
headers: {
|
|
469
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
470
|
+
"X-Requested-With": "XMLHttpRequest"
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
if (this.enable(), s?.focus(), a) {
|
|
474
|
+
console.error("An error occurred", a), this.showStatus(this.messageError, "error");
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
if (this.actionOnSuccess === "remove-form" && this.form.remove(), this.keepFields || this.reset(), c.type === "html") {
|
|
478
|
+
if (!this.queryKeyToInvalidate) return;
|
|
479
|
+
S.setQueryData(this.queryKeyToInvalidate, c), this.showStatus(this.messageSuccess, "success");
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
if (this.showStatus(c.message ?? this.messageSuccess, "success"), c.redirectUrl) {
|
|
483
|
+
window.location.href = c.redirectUrl;
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
c.queryKey && S.invalidateQuery(c.queryKey), this.queryKeyToInvalidate && S.invalidateQuery(this.queryKeyToInvalidate), E(h.AjaxForm.Name, h.AjaxForm.Event.Form, this);
|
|
487
|
+
}
|
|
488
|
+
disable() {
|
|
489
|
+
this.setAttribute(this.isSubmittingAttribute, "");
|
|
490
|
+
}
|
|
491
|
+
enable() {
|
|
492
|
+
this.removeAttribute(this.isSubmittingAttribute);
|
|
493
|
+
}
|
|
494
|
+
isDisabled() {
|
|
495
|
+
return this.hasAttribute(this.isSubmittingAttribute);
|
|
496
|
+
}
|
|
497
|
+
showStatus(e, t) {
|
|
498
|
+
if (!(!this.announce || !this.announceTitle))
|
|
499
|
+
switch (this.announceTitle.textContent = e, this.showStatusIcon(t), t) {
|
|
500
|
+
case "success":
|
|
501
|
+
this.announce.className = "alert alert-success", this.actionOnSuccess === "remove-message" && setTimeout(() => {
|
|
502
|
+
!this.announce || !this.announceTitle || (this.announceTitle.textContent = "", this.announce.className = "", this.showStatusIcon("pending"));
|
|
503
|
+
}, 6 * 1e3);
|
|
504
|
+
break;
|
|
505
|
+
case "error":
|
|
506
|
+
this.announce.className = "alert alert-danger";
|
|
507
|
+
break;
|
|
508
|
+
case "pending":
|
|
509
|
+
this.announce.className = "alert visually-hidden";
|
|
510
|
+
break;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
showStatusIcon(e) {
|
|
514
|
+
if (!this.announce) return;
|
|
515
|
+
const t = this.announce.querySelector("[data-announce-success-icon]"), n = this.announce.querySelector("[data-announce-error-icon]");
|
|
516
|
+
switch (e) {
|
|
517
|
+
case "success":
|
|
518
|
+
t?.removeAttribute("hidden"), n?.setAttribute("hidden", "");
|
|
519
|
+
break;
|
|
520
|
+
case "error":
|
|
521
|
+
t?.setAttribute("hidden", ""), n?.removeAttribute("hidden");
|
|
522
|
+
break;
|
|
523
|
+
case "pending":
|
|
524
|
+
t?.setAttribute("hidden", ""), n?.setAttribute("hidden", "");
|
|
525
|
+
break;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
serialize() {
|
|
529
|
+
if (!this.form) return "";
|
|
530
|
+
const e = new FormData(this.form), t = new URLSearchParams();
|
|
531
|
+
for (const [n, s] of e)
|
|
532
|
+
s instanceof File || t.append(n, s);
|
|
533
|
+
return t.toString();
|
|
534
|
+
}
|
|
535
|
+
reset() {
|
|
536
|
+
this.form && this.form.reset();
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
);
|
|
540
|
+
customElements.define(
|
|
541
|
+
h.AjaxHtml.Name,
|
|
542
|
+
class extends HTMLElement {
|
|
543
|
+
queryKey = null;
|
|
544
|
+
unsubscribe = null;
|
|
545
|
+
initialFetchTriggered = !1;
|
|
546
|
+
// To prevent multiple fetch calls
|
|
547
|
+
intersectionObserver = null;
|
|
548
|
+
staleTime;
|
|
549
|
+
connectedCallback() {
|
|
550
|
+
if (this.queryKey = this.getAttribute("query-key"), !this.queryKey) {
|
|
551
|
+
console.warn(`${h.AjaxHtml.Name} requires a "query-key" attribute.`, this);
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
this.staleTime = this.hasAttribute("stale-time") ? (
|
|
555
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
556
|
+
parseInt(this.getAttribute("stale-time"), 10)
|
|
557
|
+
) : void 0, this.unsubscribe = S.subscribe(
|
|
558
|
+
this.queryKey,
|
|
559
|
+
(t) => {
|
|
560
|
+
this.renderContent(t);
|
|
561
|
+
},
|
|
562
|
+
{ staleTime: this.staleTime }
|
|
563
|
+
);
|
|
564
|
+
const e = this.getAttribute("load-strategy");
|
|
565
|
+
if (e)
|
|
566
|
+
switch (e) {
|
|
567
|
+
case "server-side":
|
|
568
|
+
this.initialFetchTriggered = !0;
|
|
569
|
+
break;
|
|
570
|
+
case "initial":
|
|
571
|
+
this.triggerInitialFetch();
|
|
572
|
+
break;
|
|
573
|
+
case "lazy":
|
|
574
|
+
this.intersectionObserver = new IntersectionObserver(
|
|
575
|
+
this.handleIntersection.bind(this),
|
|
576
|
+
{ rootMargin: "0px 0px 100px 0px" }
|
|
577
|
+
), this.intersectionObserver.observe(this);
|
|
578
|
+
break;
|
|
579
|
+
case "defer":
|
|
580
|
+
document.addEventListener(
|
|
581
|
+
"DOMContentLoaded",
|
|
582
|
+
this.handleDomContentLoaded.bind(this),
|
|
583
|
+
{
|
|
584
|
+
once: !0
|
|
585
|
+
}
|
|
586
|
+
);
|
|
587
|
+
break;
|
|
588
|
+
}
|
|
589
|
+
else
|
|
590
|
+
this.initialFetchTriggered = !0;
|
|
591
|
+
}
|
|
592
|
+
disconnectedCallback() {
|
|
593
|
+
this.unsubscribe && this.unsubscribe(), document.removeEventListener("DOMContentLoaded", this.handleDomContentLoaded.bind(this)), this.intersectionObserver && (this.intersectionObserver.unobserve(this), this.intersectionObserver.disconnect(), this.intersectionObserver = null);
|
|
594
|
+
}
|
|
595
|
+
handleDomContentLoaded() {
|
|
596
|
+
this.triggerInitialFetch();
|
|
597
|
+
}
|
|
598
|
+
handleIntersection(e) {
|
|
599
|
+
e.forEach((t) => {
|
|
600
|
+
t.isIntersecting && (this.triggerInitialFetch(), this.intersectionObserver && this.intersectionObserver.unobserve(this));
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
triggerInitialFetch() {
|
|
604
|
+
this.queryKey && (this.initialFetchTriggered || (this.initialFetchTriggered = !0, S.invalidateQuery(this.queryKey)));
|
|
605
|
+
}
|
|
606
|
+
renderContent(e) {
|
|
607
|
+
if (!this.initialFetchTriggered || !e.data || e.data.type !== "html") return;
|
|
608
|
+
const t = e.data.document, n = t.querySelector(`#${this.id}`);
|
|
609
|
+
if (n && n.id === this.id) {
|
|
610
|
+
this.innerHTML = n.innerHTML;
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
if (t.body.innerHTML.trim().length > 0) {
|
|
614
|
+
this.innerHTML = t.body.innerHTML;
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
e.isFetching || (this.innerHTML = "<p>No results found.</p>");
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
);
|
|
621
|
+
customElements.define(
|
|
622
|
+
h.Dropdown.Name,
|
|
623
|
+
class extends HTMLElement {
|
|
624
|
+
dropdown = null;
|
|
625
|
+
trigger = null;
|
|
626
|
+
content = null;
|
|
627
|
+
connectedCallback() {
|
|
628
|
+
this.dropdown = this.querySelector("details"), this.trigger = this.querySelector("summary"), this.content = this.querySelector("ul"), !(!this.dropdown || !this.trigger || !this.content) && (this.trigger.addEventListener(f.Click, this.handleOpen.bind(this)), this.dropdown.addEventListener(f.Toggle, this.handleToggle.bind(this)));
|
|
629
|
+
}
|
|
630
|
+
disconnectedCallback() {
|
|
631
|
+
this.trigger && this.trigger.removeEventListener(f.Click, this.handleOpen.bind(this)), this.dropdown && this.dropdown.removeEventListener(f.Toggle, this.handleToggle.bind(this)), this.removeEvents();
|
|
632
|
+
}
|
|
633
|
+
focusFirstDropdownItem() {
|
|
634
|
+
if (!this.content) return;
|
|
635
|
+
const e = Array.from(
|
|
636
|
+
this.content.querySelectorAll(M)
|
|
637
|
+
);
|
|
638
|
+
if (e.length === 0) {
|
|
639
|
+
this.content.focus();
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
const t = e[0];
|
|
643
|
+
setTimeout(() => {
|
|
644
|
+
t && t.focus();
|
|
645
|
+
}, 1);
|
|
646
|
+
}
|
|
647
|
+
handleTrapFocus(e) {
|
|
648
|
+
if (!this.content || !(e instanceof KeyboardEvent)) return;
|
|
649
|
+
const t = Array.from(
|
|
650
|
+
this.content.querySelectorAll(M)
|
|
651
|
+
);
|
|
652
|
+
if (t.length <= 0) return;
|
|
653
|
+
const n = t[0], s = t[t.length - 1], a = document.activeElement;
|
|
654
|
+
if (!a) return;
|
|
655
|
+
const c = t.indexOf(a);
|
|
656
|
+
if (e.key === "Tab") {
|
|
657
|
+
if (e.shiftKey) {
|
|
658
|
+
if (a === n) {
|
|
659
|
+
if (!s) return;
|
|
660
|
+
s.focus(), e.preventDefault();
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
if (a === s) {
|
|
666
|
+
if (!n) return;
|
|
667
|
+
n.focus(), e.preventDefault();
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
if (e.key === "ArrowUp" || e.key === "ArrowLeft") {
|
|
672
|
+
if (e.preventDefault(), e.altKey) {
|
|
673
|
+
if (!n) return;
|
|
674
|
+
n.focus();
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
if (c === 0 || c === -1) {
|
|
678
|
+
if (!s) return;
|
|
679
|
+
s.focus();
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
t[c - 1]?.focus();
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
if (e.key === "ArrowDown" || e.key === "ArrowRight") {
|
|
686
|
+
if (e.preventDefault(), e.altKey) {
|
|
687
|
+
if (!s) return;
|
|
688
|
+
s.focus();
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
if (c === t.length - 1 || c === -1) {
|
|
692
|
+
if (!n) return;
|
|
693
|
+
n.focus();
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
t[c + 1]?.focus();
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
addEvents() {
|
|
701
|
+
!this.dropdown || !this.content || (document.addEventListener(f.Click, this.handleClickOutside.bind(this)), this.dropdown.addEventListener(f.KeyDown, this.handleEscape.bind(this)), this.content.addEventListener(f.KeyDown, this.handleTrapFocus.bind(this), {
|
|
702
|
+
capture: !0
|
|
703
|
+
}));
|
|
704
|
+
}
|
|
705
|
+
removeEvents() {
|
|
706
|
+
document.removeEventListener(f.Click, this.handleClickOutside.bind(this)), this.dropdown && this.dropdown.removeEventListener(f.KeyDown, this.handleEscape.bind(this)), this.content && this.content.removeEventListener(
|
|
707
|
+
f.KeyDown,
|
|
708
|
+
this.handleTrapFocus.bind(this),
|
|
709
|
+
{
|
|
710
|
+
capture: !0
|
|
711
|
+
}
|
|
712
|
+
);
|
|
713
|
+
}
|
|
714
|
+
handleToggle() {
|
|
715
|
+
this.dropdown && (this.dropdown.open ? (this.focusFirstDropdownItem(), this.addEvents()) : this.removeEvents());
|
|
716
|
+
}
|
|
717
|
+
handleClose() {
|
|
718
|
+
!this.dropdown || !this.trigger || (this.dropdown.removeAttribute("open"), this.trigger.focus(), this.removeEvents());
|
|
719
|
+
}
|
|
720
|
+
handleOpen() {
|
|
721
|
+
this.dropdown?.open || (this.focusFirstDropdownItem(), this.addEvents());
|
|
722
|
+
}
|
|
723
|
+
handleClickOutside(e) {
|
|
724
|
+
this.dropdown && (this.dropdown.contains(e.target) || this.handleClose());
|
|
725
|
+
}
|
|
726
|
+
handleEscape(e) {
|
|
727
|
+
e instanceof KeyboardEvent && e.key === "Escape" && (e.preventDefault(), this.handleClose());
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
);
|
|
731
|
+
customElements.define(
|
|
732
|
+
h.ExclusiveCheckbox.Name,
|
|
733
|
+
class extends HTMLElement {
|
|
734
|
+
targetName = null;
|
|
735
|
+
exclusiveCheckbox = null;
|
|
736
|
+
checkboxes = null;
|
|
737
|
+
connectedCallback() {
|
|
738
|
+
this.targetName = this.getAttribute("target-name"), this.exclusiveCheckbox = this.querySelector("input"), !(!this.targetName || !this.exclusiveCheckbox || !this.parentElement) && (this.checkboxes = [
|
|
739
|
+
...this.parentElement.querySelectorAll(
|
|
740
|
+
`[name="${this.targetName}"]`
|
|
741
|
+
)
|
|
742
|
+
], this.checkboxes.length !== 0 && this.addEvents());
|
|
743
|
+
}
|
|
744
|
+
disconnectedCallback() {
|
|
745
|
+
if (this.exclusiveCheckbox && this.exclusiveCheckbox.removeEventListener(
|
|
746
|
+
f.Change,
|
|
747
|
+
this.handleExclusiveChange.bind(this)
|
|
748
|
+
), this.checkboxes)
|
|
749
|
+
for (const e of this.checkboxes)
|
|
750
|
+
e.removeEventListener(
|
|
751
|
+
f.Change,
|
|
752
|
+
this.handleCheckboxChange.bind(this)
|
|
753
|
+
);
|
|
754
|
+
}
|
|
755
|
+
addEvents() {
|
|
756
|
+
if (!(!this.exclusiveCheckbox || !this.targetName || !this.parentElement || !this.checkboxes)) {
|
|
757
|
+
this.exclusiveCheckbox.addEventListener("change", this.handleExclusiveChange.bind(this));
|
|
758
|
+
for (const e of this.checkboxes)
|
|
759
|
+
e.disabled || e.addEventListener(f.Change, this.handleCheckboxChange.bind(this));
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
handleExclusiveChange() {
|
|
763
|
+
if (!this.exclusiveCheckbox || !this.checkboxes || this.checkboxes.length === 0) return;
|
|
764
|
+
const e = this.exclusiveCheckbox.checked;
|
|
765
|
+
for (const t of this.checkboxes)
|
|
766
|
+
t.disabled || e && (t.checked = !1);
|
|
767
|
+
this.exclusiveCheckbox.indeterminate = !1, E(
|
|
768
|
+
h.ExclusiveCheckbox.Name,
|
|
769
|
+
h.ExclusiveCheckbox.Event.Toggle,
|
|
770
|
+
this.exclusiveCheckbox
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
handleCheckboxChange() {
|
|
774
|
+
if (!this.exclusiveCheckbox || !this.checkboxes || this.checkboxes.length === 0 || !this.exclusiveCheckbox.checked) return;
|
|
775
|
+
const e = this.checkboxes.some(
|
|
776
|
+
(t) => !t.disabled && t.checked
|
|
777
|
+
);
|
|
778
|
+
this.exclusiveCheckbox.checked = !e, E(
|
|
779
|
+
h.ExclusiveCheckbox.Name,
|
|
780
|
+
h.ExclusiveCheckbox.Event.Toggle,
|
|
781
|
+
this.exclusiveCheckbox
|
|
782
|
+
);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
);
|
|
786
|
+
customElements.define(
|
|
787
|
+
h.SelectAll.Name,
|
|
788
|
+
class extends HTMLElement {
|
|
789
|
+
targetName = null;
|
|
790
|
+
selectAllCheckbox = null;
|
|
791
|
+
checkboxes = null;
|
|
792
|
+
connectedCallback() {
|
|
793
|
+
this.targetName = this.getAttribute("target-name"), this.selectAllCheckbox = this.querySelector("input"), !(!this.targetName || !this.selectAllCheckbox || !this.parentElement) && (this.checkboxes = [
|
|
794
|
+
...this.parentElement.querySelectorAll(
|
|
795
|
+
`[name="${this.targetName}"]`
|
|
796
|
+
)
|
|
797
|
+
], this.checkboxes.length !== 0 && (this.ready(), this.addEvents()));
|
|
798
|
+
}
|
|
799
|
+
disconnectedCallback() {
|
|
800
|
+
if (this.selectAllCheckbox && this.selectAllCheckbox.removeEventListener(
|
|
801
|
+
f.Change,
|
|
802
|
+
this.handleSelectAllChange.bind(this)
|
|
803
|
+
), this.checkboxes)
|
|
804
|
+
for (const e of this.checkboxes)
|
|
805
|
+
e.removeEventListener(
|
|
806
|
+
f.Change,
|
|
807
|
+
this.handleCheckboxChange.bind(this)
|
|
808
|
+
);
|
|
809
|
+
}
|
|
810
|
+
ready() {
|
|
811
|
+
this.setAttribute("data-state", "ready");
|
|
812
|
+
}
|
|
813
|
+
addEvents() {
|
|
814
|
+
if (!(!this.selectAllCheckbox || !this.targetName || !this.parentElement || !this.checkboxes)) {
|
|
815
|
+
this.selectAllCheckbox.addEventListener("change", this.handleSelectAllChange.bind(this));
|
|
816
|
+
for (const e of this.checkboxes)
|
|
817
|
+
e.disabled || (e.parentElement?.classList.add("padding-inline-start-lg"), e.addEventListener(f.Change, this.handleCheckboxChange.bind(this)));
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
handleSelectAllChange() {
|
|
821
|
+
if (!this.selectAllCheckbox || !this.checkboxes || this.checkboxes.length === 0) return;
|
|
822
|
+
const e = this.selectAllCheckbox.checked;
|
|
823
|
+
for (const t of this.checkboxes)
|
|
824
|
+
t.disabled || (t.checked = e);
|
|
825
|
+
this.selectAllCheckbox.indeterminate = !1, E(
|
|
826
|
+
h.SelectAll.Name,
|
|
827
|
+
h.SelectAll.Event.Toggle,
|
|
828
|
+
this.selectAllCheckbox
|
|
829
|
+
);
|
|
830
|
+
}
|
|
831
|
+
handleCheckboxChange() {
|
|
832
|
+
if (!this.selectAllCheckbox || !this.checkboxes || this.checkboxes.length === 0) return;
|
|
833
|
+
const e = this.checkboxes.filter(
|
|
834
|
+
(a) => !a.disabled && a.checked
|
|
835
|
+
).length, t = this.checkboxes.length, n = e === t, s = e === 0;
|
|
836
|
+
this.selectAllCheckbox.indeterminate = !n && !s, this.selectAllCheckbox.checked = n, E(
|
|
837
|
+
h.SelectAll.Name,
|
|
838
|
+
h.SelectAll.Event.Toggle,
|
|
839
|
+
this.selectAllCheckbox
|
|
840
|
+
);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
);
|
|
844
|
+
customElements.define(
|
|
845
|
+
h.UntilSelected.Name,
|
|
846
|
+
class extends HTMLElement {
|
|
847
|
+
target = null;
|
|
848
|
+
targetElement = null;
|
|
849
|
+
focusTargetElement = null;
|
|
850
|
+
events = null;
|
|
851
|
+
hideWhenChecked = !1;
|
|
852
|
+
connectedCallback() {
|
|
853
|
+
if (this.target = this.getAttribute("target"), !this.target) return;
|
|
854
|
+
try {
|
|
855
|
+
const s = document.getElementById(this.target);
|
|
856
|
+
if (!(s instanceof HTMLInputElement)) {
|
|
857
|
+
console.warn("Element was not found");
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
this.targetElement = s;
|
|
861
|
+
} catch (s) {
|
|
862
|
+
console.warn("Could not select element", s);
|
|
863
|
+
}
|
|
864
|
+
if (!this.targetElement) return;
|
|
865
|
+
const e = this.getAttribute("focus-target");
|
|
866
|
+
if (e)
|
|
867
|
+
try {
|
|
868
|
+
this.focusTargetElement = document.getElementById(e);
|
|
869
|
+
} catch (s) {
|
|
870
|
+
console.warn("Could not select focus target", s);
|
|
871
|
+
}
|
|
872
|
+
const t = this.getAttribute("events");
|
|
873
|
+
t && (this.events = t.split(",").map((s) => s.trim())), this.hideWhenChecked = this.getAttribute("hide-when-checked") === "true";
|
|
874
|
+
const n = this.targetElement.checked;
|
|
875
|
+
this.toggleAttribute("hidden", this.hideWhenChecked ? n : !n), this.addEvents();
|
|
876
|
+
}
|
|
877
|
+
disconnectedCallback() {
|
|
878
|
+
if (document.removeEventListener(
|
|
879
|
+
`${h.ExclusiveCheckbox.Name}:${h.ExclusiveCheckbox.Event.Toggle}`,
|
|
880
|
+
this.handleTargetChange.bind(this)
|
|
881
|
+
), document.removeEventListener(
|
|
882
|
+
`${h.SelectAll.Name}:${h.ExclusiveCheckbox.Event.Toggle}`,
|
|
883
|
+
this.handleTargetChange.bind(this)
|
|
884
|
+
), this.targetElement && this.targetElement.removeEventListener(
|
|
885
|
+
f.Change,
|
|
886
|
+
this.handleTargetChange.bind(this)
|
|
887
|
+
), this.events && this.events.length > 0)
|
|
888
|
+
for (const e of this.events)
|
|
889
|
+
document.removeEventListener(e, this.handleTargetChange.bind(this));
|
|
890
|
+
}
|
|
891
|
+
addEvents() {
|
|
892
|
+
if (document.addEventListener(
|
|
893
|
+
`${h.ExclusiveCheckbox.Name}:${h.ExclusiveCheckbox.Event.Toggle}`,
|
|
894
|
+
this.handleTargetChange.bind(this)
|
|
895
|
+
), document.addEventListener(
|
|
896
|
+
`${h.SelectAll.Name}:${h.ExclusiveCheckbox.Event.Toggle}`,
|
|
897
|
+
this.handleTargetChange.bind(this)
|
|
898
|
+
), this.targetElement && this.targetElement.addEventListener(
|
|
899
|
+
f.Change,
|
|
900
|
+
this.handleTargetChange.bind(this)
|
|
901
|
+
), this.events && this.events.length > 0)
|
|
902
|
+
for (const e of this.events)
|
|
903
|
+
document.addEventListener(e, this.handleTargetChange.bind(this));
|
|
904
|
+
}
|
|
905
|
+
handleTargetChange() {
|
|
906
|
+
if (!this.targetElement) return;
|
|
907
|
+
const e = this.hideWhenChecked ? this.targetElement.checked : !this.targetElement.checked;
|
|
908
|
+
this.toggleAttribute("hidden", e), e && this.focusTargetElement && this.matches(":focus-within") && this.focusTargetElement.focus();
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
);
|
|
912
|
+
function O() {
|
|
913
|
+
return typeof HTMLButtonElement < "u" && "command" in HTMLButtonElement.prototype && "source" in ((globalThis.CommandEvent || {}).prototype || {});
|
|
914
|
+
}
|
|
915
|
+
function H() {
|
|
916
|
+
document.addEventListener(
|
|
917
|
+
"invoke",
|
|
918
|
+
(i) => {
|
|
919
|
+
i.type == "invoke" && i.isTrusted && (i.stopImmediatePropagation(), i.preventDefault());
|
|
920
|
+
},
|
|
921
|
+
!0
|
|
922
|
+
), document.addEventListener(
|
|
923
|
+
"command",
|
|
924
|
+
(i) => {
|
|
925
|
+
i.type == "command" && i.isTrusted && (i.stopImmediatePropagation(), i.preventDefault());
|
|
926
|
+
},
|
|
927
|
+
!0
|
|
928
|
+
);
|
|
929
|
+
function e(i, o, r = !0) {
|
|
930
|
+
Object.defineProperty(i, o, {
|
|
931
|
+
...Object.getOwnPropertyDescriptor(i, o),
|
|
932
|
+
enumerable: r
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
function t(i) {
|
|
936
|
+
return i && typeof i.getRootNode == "function" ? i.getRootNode() : i && i.parentNode ? t(i.parentNode) : i;
|
|
937
|
+
}
|
|
938
|
+
const n = /* @__PURE__ */ new WeakMap(), s = /* @__PURE__ */ new WeakMap();
|
|
939
|
+
class a extends Event {
|
|
940
|
+
constructor(o, r = {}) {
|
|
941
|
+
super(o, r);
|
|
942
|
+
const { source: m, command: b } = r;
|
|
943
|
+
if (m != null && !(m instanceof Element))
|
|
944
|
+
throw new TypeError("source must be an element");
|
|
945
|
+
n.set(this, m || null), s.set(
|
|
946
|
+
this,
|
|
947
|
+
b !== void 0 ? String(b) : ""
|
|
948
|
+
);
|
|
949
|
+
}
|
|
950
|
+
get [Symbol.toStringTag]() {
|
|
951
|
+
return "CommandEvent";
|
|
952
|
+
}
|
|
953
|
+
get source() {
|
|
954
|
+
if (!n.has(this))
|
|
955
|
+
throw new TypeError("illegal invocation");
|
|
956
|
+
const o = n.get(this);
|
|
957
|
+
if (!(o instanceof Element)) return null;
|
|
958
|
+
const r = t(o);
|
|
959
|
+
return r !== t(this.target || document) ? r.host : o;
|
|
960
|
+
}
|
|
961
|
+
get command() {
|
|
962
|
+
if (!s.has(this))
|
|
963
|
+
throw new TypeError("illegal invocation");
|
|
964
|
+
return s.get(this);
|
|
965
|
+
}
|
|
966
|
+
get action() {
|
|
967
|
+
throw new Error(
|
|
968
|
+
"CommandEvent#action was renamed to CommandEvent#command"
|
|
969
|
+
);
|
|
970
|
+
}
|
|
971
|
+
get invoker() {
|
|
972
|
+
throw new Error(
|
|
973
|
+
"CommandEvent#invoker was renamed to CommandEvent#source"
|
|
974
|
+
);
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
e(a.prototype, "source"), e(a.prototype, "command");
|
|
978
|
+
class c extends Event {
|
|
979
|
+
constructor(o, r = {}) {
|
|
980
|
+
throw super(o, r), new Error(
|
|
981
|
+
"InvokeEvent has been deprecated, it has been renamed to `CommandEvent`"
|
|
982
|
+
);
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
const l = /* @__PURE__ */ new WeakMap();
|
|
986
|
+
function d(i) {
|
|
987
|
+
Object.defineProperties(i.prototype, {
|
|
988
|
+
commandForElement: {
|
|
989
|
+
enumerable: !0,
|
|
990
|
+
configurable: !0,
|
|
991
|
+
set(o) {
|
|
992
|
+
if (this.hasAttribute("invokeaction"))
|
|
993
|
+
throw new TypeError(
|
|
994
|
+
"Element has deprecated `invokeaction` attribute, replace with `command`"
|
|
995
|
+
);
|
|
996
|
+
if (this.hasAttribute("invoketarget"))
|
|
997
|
+
throw new TypeError(
|
|
998
|
+
"Element has deprecated `invoketarget` attribute, replace with `commandfor`"
|
|
999
|
+
);
|
|
1000
|
+
if (o === null)
|
|
1001
|
+
this.removeAttribute("commandfor"), l.delete(this);
|
|
1002
|
+
else if (o instanceof Element) {
|
|
1003
|
+
this.setAttribute("commandfor", "");
|
|
1004
|
+
const r = t(o);
|
|
1005
|
+
t(this) === r || r === this.ownerDocument ? l.set(this, o) : l.delete(this);
|
|
1006
|
+
} else
|
|
1007
|
+
throw new TypeError("commandForElement must be an element or null");
|
|
1008
|
+
},
|
|
1009
|
+
get() {
|
|
1010
|
+
if (this.localName !== "button")
|
|
1011
|
+
return null;
|
|
1012
|
+
if (this.hasAttribute("invokeaction") || this.hasAttribute("invoketarget"))
|
|
1013
|
+
return console.warn(
|
|
1014
|
+
"Element has deprecated `invoketarget` or `invokeaction` attribute, use `commandfor` and `command` instead"
|
|
1015
|
+
), null;
|
|
1016
|
+
if (this.disabled)
|
|
1017
|
+
return null;
|
|
1018
|
+
if (this.form && this.getAttribute("type") !== "button")
|
|
1019
|
+
return console.warn(
|
|
1020
|
+
"Element with `commandFor` is a form participant. It should explicitly set `type=button` in order for `commandFor` to work"
|
|
1021
|
+
), null;
|
|
1022
|
+
const o = l.get(this);
|
|
1023
|
+
if (o)
|
|
1024
|
+
return o.isConnected ? o : (l.delete(this), null);
|
|
1025
|
+
const r = t(this), m = this.getAttribute("commandfor");
|
|
1026
|
+
return (r instanceof Document || r instanceof ShadowRoot) && m && r.getElementById(m) || null;
|
|
1027
|
+
}
|
|
1028
|
+
},
|
|
1029
|
+
command: {
|
|
1030
|
+
enumerable: !0,
|
|
1031
|
+
configurable: !0,
|
|
1032
|
+
get() {
|
|
1033
|
+
const o = this.getAttribute("command") || "";
|
|
1034
|
+
if (o.startsWith("--")) return o;
|
|
1035
|
+
const r = o.toLowerCase();
|
|
1036
|
+
switch (r) {
|
|
1037
|
+
case "show-modal":
|
|
1038
|
+
case "close":
|
|
1039
|
+
case "toggle-popover":
|
|
1040
|
+
case "hide-popover":
|
|
1041
|
+
case "show-popover":
|
|
1042
|
+
return r;
|
|
1043
|
+
}
|
|
1044
|
+
return "";
|
|
1045
|
+
},
|
|
1046
|
+
set(o) {
|
|
1047
|
+
this.setAttribute("command", o);
|
|
1048
|
+
}
|
|
1049
|
+
},
|
|
1050
|
+
invokeAction: {
|
|
1051
|
+
enumerable: !1,
|
|
1052
|
+
configurable: !0,
|
|
1053
|
+
get() {
|
|
1054
|
+
throw new Error(
|
|
1055
|
+
"invokeAction is deprecated. It has been renamed to command"
|
|
1056
|
+
);
|
|
1057
|
+
},
|
|
1058
|
+
set(o) {
|
|
1059
|
+
throw new Error(
|
|
1060
|
+
"invokeAction is deprecated. It has been renamed to command"
|
|
1061
|
+
);
|
|
1062
|
+
}
|
|
1063
|
+
},
|
|
1064
|
+
invokeTargetElement: {
|
|
1065
|
+
enumerable: !1,
|
|
1066
|
+
configurable: !0,
|
|
1067
|
+
get() {
|
|
1068
|
+
throw new Error(
|
|
1069
|
+
"invokeTargetElement is deprecated. It has been renamed to command"
|
|
1070
|
+
);
|
|
1071
|
+
},
|
|
1072
|
+
set(o) {
|
|
1073
|
+
throw new Error(
|
|
1074
|
+
"invokeTargetElement is deprecated. It has been renamed to command"
|
|
1075
|
+
);
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
const g = /* @__PURE__ */ new WeakMap();
|
|
1081
|
+
Object.defineProperties(HTMLElement.prototype, {
|
|
1082
|
+
oncommand: {
|
|
1083
|
+
enumerable: !0,
|
|
1084
|
+
configurable: !0,
|
|
1085
|
+
get() {
|
|
1086
|
+
return x.takeRecords(), g.get(this) || null;
|
|
1087
|
+
},
|
|
1088
|
+
set(i) {
|
|
1089
|
+
const o = g.get(this) || null;
|
|
1090
|
+
o && this.removeEventListener("command", o), g.set(
|
|
1091
|
+
this,
|
|
1092
|
+
typeof i == "object" || typeof i == "function" ? i : null
|
|
1093
|
+
), typeof i == "function" && this.addEventListener("command", i);
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
});
|
|
1097
|
+
function u(i) {
|
|
1098
|
+
for (const o of i)
|
|
1099
|
+
o.oncommand = new Function("event", o.getAttribute("oncommand"));
|
|
1100
|
+
}
|
|
1101
|
+
const x = new MutationObserver((i) => {
|
|
1102
|
+
for (const o of i) {
|
|
1103
|
+
const { target: r } = o;
|
|
1104
|
+
o.type === "childList" ? u(r.querySelectorAll("[oncommand]")) : u([r]);
|
|
1105
|
+
}
|
|
1106
|
+
});
|
|
1107
|
+
x.observe(document, {
|
|
1108
|
+
subtree: !0,
|
|
1109
|
+
childList: !0,
|
|
1110
|
+
attributeFilter: ["oncommand"]
|
|
1111
|
+
}), u(document.querySelectorAll("[oncommand]"));
|
|
1112
|
+
function p(i) {
|
|
1113
|
+
if (i.defaultPrevented || i.type !== "click") return;
|
|
1114
|
+
const o = i.target.closest(
|
|
1115
|
+
"button[invoketarget], button[invokeaction], input[invoketarget], input[invokeaction]"
|
|
1116
|
+
);
|
|
1117
|
+
if (o && (console.warn(
|
|
1118
|
+
"Elements with `invoketarget` or `invokeaction` are deprecated and should be renamed to use `commandfor` and `command` respectively"
|
|
1119
|
+
), o.matches("input")))
|
|
1120
|
+
throw new Error("Input elements no longer support `commandfor`");
|
|
1121
|
+
const r = i.target.closest("button[commandfor], button[command]");
|
|
1122
|
+
if (!r) return;
|
|
1123
|
+
if (r.form && r.getAttribute("type") !== "button")
|
|
1124
|
+
throw i.preventDefault(), new Error(
|
|
1125
|
+
"Element with `commandFor` is a form participant. It should explicitly set `type=button` in order for `commandFor` to work. In order for it to act as a Submit button, it must not have command or commandfor attributes"
|
|
1126
|
+
);
|
|
1127
|
+
if (r.hasAttribute("command") !== r.hasAttribute("commandfor")) {
|
|
1128
|
+
const w = r.hasAttribute("command") ? "command" : "commandfor", A = r.hasAttribute("command") ? "commandfor" : "command";
|
|
1129
|
+
throw new Error(
|
|
1130
|
+
`Element with ${w} attribute must also have a ${A} attribute to function.`
|
|
1131
|
+
);
|
|
1132
|
+
}
|
|
1133
|
+
if (r.command !== "show-popover" && r.command !== "hide-popover" && r.command !== "toggle-popover" && r.command !== "show-modal" && r.command !== "close" && !r.command.startsWith("--")) {
|
|
1134
|
+
console.warn(
|
|
1135
|
+
`"${r.command}" is not a valid command value. Custom commands must begin with --`
|
|
1136
|
+
);
|
|
1137
|
+
return;
|
|
1138
|
+
}
|
|
1139
|
+
const m = r.commandForElement;
|
|
1140
|
+
if (!m) return;
|
|
1141
|
+
const b = new a("command", {
|
|
1142
|
+
command: r.command,
|
|
1143
|
+
source: r,
|
|
1144
|
+
cancelable: !0
|
|
1145
|
+
});
|
|
1146
|
+
if (m.dispatchEvent(b), b.defaultPrevented)
|
|
1147
|
+
return;
|
|
1148
|
+
const k = b.command.toLowerCase();
|
|
1149
|
+
if (m.popover) {
|
|
1150
|
+
const w = !m.matches(":popover-open");
|
|
1151
|
+
w && (k === "toggle-popover" || k === "show-popover") ? m.showPopover({ source: r }) : !w && k === "hide-popover" && m.hidePopover();
|
|
1152
|
+
} else if (m.localName === "dialog") {
|
|
1153
|
+
const w = !m.hasAttribute("open");
|
|
1154
|
+
w && k === "show-modal" ? m.showModal() : !w && k === "close" && m.close();
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
function I(i) {
|
|
1158
|
+
i.addEventListener("click", p, !0);
|
|
1159
|
+
}
|
|
1160
|
+
function q(i, o) {
|
|
1161
|
+
const r = i.prototype.attachShadow;
|
|
1162
|
+
i.prototype.attachShadow = function(b) {
|
|
1163
|
+
const k = r.call(this, b);
|
|
1164
|
+
return o(k), k;
|
|
1165
|
+
};
|
|
1166
|
+
const m = i.prototype.attachInternals;
|
|
1167
|
+
i.prototype.attachInternals = function() {
|
|
1168
|
+
const b = m.call(this);
|
|
1169
|
+
return b.shadowRoot && o(b.shadowRoot), b;
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1172
|
+
d(HTMLButtonElement), q(HTMLElement, (i) => {
|
|
1173
|
+
I(i), x.observe(i, { attributeFilter: ["oncommand"] }), u(i.querySelectorAll("[oncommand]"));
|
|
1174
|
+
}), I(document), Object.assign(globalThis, { CommandEvent: a, InvokeEvent: c });
|
|
1175
|
+
}
|
|
1176
|
+
O() || H();
|