@tarragon-ui/js 0.2.0 → 0.7.1
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/tarragon-ui.js +541 -423
- package/package.json +53 -43
package/dist/tarragon-ui.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const y = "tui-",
|
|
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
|
|
1
|
+
const y = "tui-", V = `data-${y}`, h = (e) => V + e, A = (e, t) => `[${h(e)}${t ? `="${t}"` : ""}]`, v = "hidden", R = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])', K = 1e3;
|
|
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.BeforeToggle = "beforetoggle", 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 a = {
|
|
4
4
|
AjaxForm: {
|
|
5
5
|
Name: `${y}ajax-form`,
|
|
6
6
|
Event: { Form: "form" }
|
|
@@ -8,28 +8,31 @@ const h = {
|
|
|
8
8
|
AjaxHtml: {
|
|
9
9
|
Name: `${y}ajax-html`
|
|
10
10
|
},
|
|
11
|
+
Dropdown: {
|
|
12
|
+
Name: `${y}dropdown`
|
|
13
|
+
},
|
|
11
14
|
ExclusiveCheckbox: {
|
|
12
15
|
Name: `${y}exclusive-checkbox`,
|
|
13
16
|
Event: { Toggle: "toggle" }
|
|
14
17
|
},
|
|
15
|
-
Dropdown: { Name: `${y}dropdown` },
|
|
16
18
|
SelectAll: { Name: `${y}select-all`, Event: { Toggle: "toggle" } },
|
|
19
|
+
SearchFilter: { Name: `${y}search-filter` },
|
|
17
20
|
UntilSelected: { Name: `${y}until-selected` },
|
|
18
21
|
ValidateForm: {
|
|
19
22
|
Name: `${y}validate-form`,
|
|
20
23
|
Event: { Validate: "validate" }
|
|
21
24
|
}
|
|
22
25
|
};
|
|
23
|
-
function
|
|
24
|
-
const
|
|
26
|
+
function w(e, t, n, s = !1) {
|
|
27
|
+
const c = new Event(`${e}:${t}`, {
|
|
25
28
|
bubbles: !0,
|
|
26
29
|
cancelable: s
|
|
27
30
|
});
|
|
28
|
-
return n.dispatchEvent(
|
|
31
|
+
return n.dispatchEvent(c);
|
|
29
32
|
}
|
|
30
|
-
const
|
|
33
|
+
const O = "validate-group";
|
|
31
34
|
customElements.define(
|
|
32
|
-
|
|
35
|
+
a.ValidateForm.Name,
|
|
33
36
|
class extends HTMLElement {
|
|
34
37
|
form = null;
|
|
35
38
|
groups = void 0;
|
|
@@ -38,45 +41,35 @@ customElements.define(
|
|
|
38
41
|
console.warn("No form was found");
|
|
39
42
|
return;
|
|
40
43
|
}
|
|
41
|
-
this.groups = Array.from(
|
|
44
|
+
this.groups = Array.from(
|
|
45
|
+
this.form.querySelectorAll(A(O))
|
|
46
|
+
), this.form.setAttribute("novalidate", ""), this.form.addEventListener("submit", this.onSubmit), this.form.addEventListener("input", this.onInput), this.form.addEventListener("blur", this.onBlur, { capture: !0 }), w(a.ValidateForm.Name, a.ValidateForm.Event.Validate, this), this.setAttribute(h("is-ready"), "");
|
|
42
47
|
}
|
|
43
|
-
|
|
44
|
-
|
|
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);
|
|
48
|
+
disconnectedCallback() {
|
|
49
|
+
this.form && (this.form.removeEventListener("submit", this.onSubmit), this.form.removeEventListener("input", this.onInput), this.form.removeEventListener("blur", this.onBlur, { capture: !0 }));
|
|
57
50
|
}
|
|
58
51
|
/**
|
|
59
52
|
* Handle input events
|
|
60
53
|
* @param {Event} event The event object
|
|
61
54
|
*/
|
|
62
|
-
onInput(e) {
|
|
55
|
+
onInput = (e) => {
|
|
63
56
|
if (!(e.target instanceof Element)) return;
|
|
64
|
-
const t = e.target.closest(
|
|
65
|
-
if (t?.setAttribute(
|
|
57
|
+
const t = e.target.closest(A(O)), n = t ?? e.target;
|
|
58
|
+
if (t?.setAttribute(h(O), "interacted"), !(!t && n.getAttribute("aria-invalid") !== "true")) {
|
|
66
59
|
if (t) {
|
|
67
60
|
this.isGroupValid(t);
|
|
68
61
|
return;
|
|
69
62
|
}
|
|
70
63
|
this.isFieldValid(n);
|
|
71
64
|
}
|
|
72
|
-
}
|
|
65
|
+
};
|
|
73
66
|
/**
|
|
74
67
|
* Handle blur events
|
|
75
68
|
* @param {Event} event The event object
|
|
76
69
|
*/
|
|
77
|
-
onBlur(e) {
|
|
70
|
+
onBlur = (e) => {
|
|
78
71
|
if (!(e.target instanceof Element)) return;
|
|
79
|
-
const t = e.target.closest(`[${
|
|
72
|
+
const t = e.target.closest(`[${O}="interacted"]`);
|
|
80
73
|
if (t) {
|
|
81
74
|
this.isGroupValid(t);
|
|
82
75
|
return;
|
|
@@ -86,27 +79,27 @@ customElements.define(
|
|
|
86
79
|
return;
|
|
87
80
|
}
|
|
88
81
|
this.showError(e.target);
|
|
89
|
-
}
|
|
82
|
+
};
|
|
90
83
|
/**
|
|
91
84
|
* Handle submit events
|
|
92
85
|
* @param {Event} event The event object
|
|
93
86
|
*/
|
|
94
|
-
onSubmit(e) {
|
|
95
|
-
if (!
|
|
96
|
-
|
|
97
|
-
|
|
87
|
+
onSubmit = (e) => {
|
|
88
|
+
if (!w(
|
|
89
|
+
a.ValidateForm.Name,
|
|
90
|
+
a.ValidateForm.Event.Validate,
|
|
98
91
|
this,
|
|
99
92
|
!0
|
|
100
93
|
)) return;
|
|
101
94
|
const n = this.checkGroupValidity();
|
|
102
95
|
if (this.checkFieldValidity() && n) {
|
|
103
|
-
|
|
96
|
+
w(a.ValidateForm.Name, a.ValidateForm.Event.Validate, this);
|
|
104
97
|
return;
|
|
105
98
|
}
|
|
106
99
|
e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation(), this.form?.querySelector(
|
|
107
100
|
'input:invalid, [aria-invalid="true"] :is([type="checkbox"], [type="radio"])'
|
|
108
|
-
)?.focus({ focusVisible: !0 }),
|
|
109
|
-
}
|
|
101
|
+
)?.focus({ focusVisible: !0 }), w(a.ValidateForm.Name, a.ValidateForm.Event.Validate, this);
|
|
102
|
+
};
|
|
110
103
|
/**
|
|
111
104
|
* Check the validity of fields that can be validated with HTMLFormElement.checkValidity().
|
|
112
105
|
* Show error messages for fields that are not.
|
|
@@ -156,31 +149,33 @@ customElements.define(
|
|
|
156
149
|
const n = this.getMessage(e, t);
|
|
157
150
|
if (!n) return;
|
|
158
151
|
e.setAttribute("aria-invalid", "true");
|
|
159
|
-
const s =
|
|
160
|
-
"
|
|
161
|
-
),
|
|
162
|
-
if (
|
|
163
|
-
const
|
|
164
|
-
if (
|
|
165
|
-
if (
|
|
166
|
-
const
|
|
167
|
-
|
|
152
|
+
const s = this.querySelector(
|
|
153
|
+
A("validation-message-template")
|
|
154
|
+
), c = !!s, l = e.getAttribute("aria-describedby"), u = l ?? `${y}${crypto.randomUUID()}`;
|
|
155
|
+
if (l) {
|
|
156
|
+
const m = this.form?.querySelector(`#${l}`);
|
|
157
|
+
if (m) {
|
|
158
|
+
if (c) {
|
|
159
|
+
const p = m.querySelector(
|
|
160
|
+
A("slot", "form-message")
|
|
168
161
|
);
|
|
169
|
-
|
|
162
|
+
p && (p.textContent = n), m.id = u, e.setAttribute("aria-describedby", u);
|
|
170
163
|
return;
|
|
171
164
|
}
|
|
172
|
-
|
|
165
|
+
m.textContent = n, m.id = u, e.setAttribute("aria-describedby", u);
|
|
173
166
|
return;
|
|
174
167
|
}
|
|
175
168
|
}
|
|
176
|
-
let
|
|
177
|
-
if (
|
|
178
|
-
|
|
179
|
-
const
|
|
180
|
-
|
|
169
|
+
let b;
|
|
170
|
+
if (c) {
|
|
171
|
+
b = s.content.cloneNode(!0).firstElementChild, b.id = u;
|
|
172
|
+
const p = b.querySelector(
|
|
173
|
+
A("slot", "form-message")
|
|
174
|
+
);
|
|
175
|
+
p && (p.textContent = n);
|
|
181
176
|
} else
|
|
182
|
-
|
|
183
|
-
e.setAttribute("aria-describedby",
|
|
177
|
+
b = document.createElement("p"), b.textContent = n, b.id = u, b.className = "form-message";
|
|
178
|
+
e.setAttribute("aria-describedby", u), t ? e.append(b) : e.after(b);
|
|
184
179
|
}
|
|
185
180
|
/**
|
|
186
181
|
* Get the error message text
|
|
@@ -189,11 +184,11 @@ customElements.define(
|
|
|
189
184
|
* @return {String} The error message
|
|
190
185
|
*/
|
|
191
186
|
getMessage(e, t = !1) {
|
|
192
|
-
const n = e.getAttribute("
|
|
187
|
+
const n = e.getAttribute(h("validate-message"));
|
|
193
188
|
if (n) return n;
|
|
194
189
|
if (t) {
|
|
195
|
-
const
|
|
196
|
-
return e.querySelector('[type="checkbox"]') ?
|
|
190
|
+
const c = this.getAttribute(h("checkbox-group-message")) ?? "Please select at least one option.", l = this.getAttribute(h("radio-group-message")) ?? "Please select an option.";
|
|
191
|
+
return e.querySelector('[type="checkbox"]') ? c : l;
|
|
197
192
|
}
|
|
198
193
|
return "validationMessage" in e ? e.validationMessage : "";
|
|
199
194
|
}
|
|
@@ -208,21 +203,20 @@ customElements.define(
|
|
|
208
203
|
}
|
|
209
204
|
}
|
|
210
205
|
);
|
|
211
|
-
class
|
|
206
|
+
class S {
|
|
212
207
|
static instance = void 0;
|
|
213
|
-
baseUrl;
|
|
214
208
|
baseHeaders = void 0;
|
|
215
|
-
constructor(t
|
|
216
|
-
this.
|
|
209
|
+
constructor(t = {}) {
|
|
210
|
+
this.baseHeaders = t;
|
|
217
211
|
}
|
|
218
212
|
// Singleton pattern with initial configuration.
|
|
219
213
|
// Subsequent calls without arguments will return the existing instance.
|
|
220
214
|
// If arguments are provided, it reconfigures the existing instance or creates a new one.
|
|
221
|
-
static getInstance(t
|
|
222
|
-
return
|
|
223
|
-
...
|
|
224
|
-
...
|
|
225
|
-
})
|
|
215
|
+
static getInstance(t) {
|
|
216
|
+
return S.instance ? t && (S.instance.baseHeaders = {
|
|
217
|
+
...S.instance.baseHeaders,
|
|
218
|
+
...t
|
|
219
|
+
}) : S.instance = new S(t), S.instance;
|
|
226
220
|
}
|
|
227
221
|
isMethod(t) {
|
|
228
222
|
return ["GET", "PUT", "POST", "PATCH", "DELETE"].includes(t.toUpperCase());
|
|
@@ -240,41 +234,41 @@ class v {
|
|
|
240
234
|
}
|
|
241
235
|
async send(t, n, s) {
|
|
242
236
|
try {
|
|
243
|
-
const
|
|
244
|
-
method:
|
|
237
|
+
const c = n.toUpperCase(), l = this.buildQueryString(s.queryParameters), u = `${t}${l}`, b = {
|
|
238
|
+
method: c,
|
|
245
239
|
headers: this.buildHeaders(s.headers)
|
|
246
240
|
};
|
|
247
|
-
|
|
248
|
-
const
|
|
249
|
-
if (!
|
|
250
|
-
const
|
|
241
|
+
c !== "GET" && "data" in s && s.data && (b.body = s.data);
|
|
242
|
+
const m = await fetch(u, b);
|
|
243
|
+
if (!m.ok) {
|
|
244
|
+
const g = {
|
|
251
245
|
message: "Request failed",
|
|
252
|
-
status:
|
|
246
|
+
status: m.status
|
|
253
247
|
};
|
|
254
|
-
if (
|
|
248
|
+
if (m.headers.get("content-type")?.includes("application/json"))
|
|
255
249
|
try {
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
} catch (
|
|
259
|
-
|
|
250
|
+
const k = await m.json();
|
|
251
|
+
g.message = k.message ?? k.error ?? g.message;
|
|
252
|
+
} catch (k) {
|
|
253
|
+
g.message = `Failed to parse error JSON: ${g.message}`, g.error = k instanceof Error ? k : new Error(String(k));
|
|
260
254
|
}
|
|
261
255
|
else {
|
|
262
|
-
const
|
|
263
|
-
|
|
256
|
+
const k = await m.text();
|
|
257
|
+
k && (g.message = `Server responded with an error: ${k.substring(0, 100)}`);
|
|
264
258
|
}
|
|
265
|
-
return [
|
|
259
|
+
return [g, void 0];
|
|
266
260
|
}
|
|
267
|
-
const
|
|
268
|
-
if (
|
|
269
|
-
return [void 0, await
|
|
270
|
-
if (
|
|
271
|
-
const
|
|
272
|
-
return [void 0, { type: "html", document: new DOMParser().parseFromString(
|
|
273
|
-
} else if (
|
|
274
|
-
return [void 0, { type: "json", message: await
|
|
261
|
+
const p = m.headers.get("content-type");
|
|
262
|
+
if (p?.includes("application/json"))
|
|
263
|
+
return [void 0, await m.json()];
|
|
264
|
+
if (p?.includes("text/html")) {
|
|
265
|
+
const g = await m.text();
|
|
266
|
+
return [void 0, { type: "html", document: new DOMParser().parseFromString(g, "text/html") }];
|
|
267
|
+
} else if (p?.includes("text/plain"))
|
|
268
|
+
return [void 0, { type: "json", message: await m.text() }];
|
|
275
269
|
return [void 0, { type: "json", message: "Request successful, no content." }];
|
|
276
|
-
} catch (
|
|
277
|
-
return
|
|
270
|
+
} catch (c) {
|
|
271
|
+
return c instanceof Error ? [{ message: "Network error", error: c }, void 0] : [{ message: "An unknown error occurred" }, void 0];
|
|
278
272
|
}
|
|
279
273
|
}
|
|
280
274
|
get(t, n) {
|
|
@@ -293,33 +287,33 @@ class v {
|
|
|
293
287
|
return this.send(t, "DELETE", n ?? {});
|
|
294
288
|
}
|
|
295
289
|
}
|
|
296
|
-
const
|
|
290
|
+
const F = S.getInstance({
|
|
297
291
|
"Content-Type": "application/json"
|
|
298
|
-
}),
|
|
292
|
+
}), H = {
|
|
299
293
|
staleTime: 0
|
|
300
294
|
};
|
|
301
|
-
class
|
|
295
|
+
class L {
|
|
302
296
|
static instance = void 0;
|
|
303
297
|
cache = /* @__PURE__ */ new Map();
|
|
304
298
|
subscriptions = /* @__PURE__ */ new Map();
|
|
305
299
|
refetchIntervals = /* @__PURE__ */ new Map();
|
|
306
300
|
static getInstance() {
|
|
307
|
-
return
|
|
301
|
+
return L.instance ??= new L(), L.instance;
|
|
308
302
|
}
|
|
309
303
|
// Centralized state update logic
|
|
310
304
|
updateQueryState(t, n, s) {
|
|
311
|
-
const
|
|
305
|
+
const c = this.cache.get(t), l = c ? { ...c } : {
|
|
312
306
|
data: void 0,
|
|
313
307
|
isFetching: !1,
|
|
314
308
|
error: null,
|
|
315
|
-
meta: { ...
|
|
309
|
+
meta: { ...H }
|
|
316
310
|
};
|
|
317
|
-
s && (
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
...
|
|
321
|
-
...
|
|
322
|
-
}, this.cache.set(t,
|
|
311
|
+
s && (l.meta = { ...l.meta, ...s });
|
|
312
|
+
const u = { ...l, ...n };
|
|
313
|
+
u.meta = {
|
|
314
|
+
...H,
|
|
315
|
+
...l.meta
|
|
316
|
+
}, this.cache.set(t, u), this.notifySubscribers(t, u), this.manageRefetchInterval(t, u.meta.staleTime);
|
|
323
317
|
}
|
|
324
318
|
notifySubscribers(t, n) {
|
|
325
319
|
this.subscriptions.get(t)?.forEach((s) => {
|
|
@@ -329,10 +323,10 @@ class C {
|
|
|
329
323
|
manageRefetchInterval(t, n) {
|
|
330
324
|
const s = this.refetchIntervals.get(t);
|
|
331
325
|
if (s && (clearInterval(s), this.refetchIntervals.delete(t)), n && n > 0 && this.subscriptions.has(t) && this.subscriptions.get(t).size > 0) {
|
|
332
|
-
const
|
|
326
|
+
const c = window.setInterval(() => {
|
|
333
327
|
this.invalidateQuery(t);
|
|
334
328
|
}, n);
|
|
335
|
-
this.refetchIntervals.set(t,
|
|
329
|
+
this.refetchIntervals.set(t, c);
|
|
336
330
|
}
|
|
337
331
|
}
|
|
338
332
|
/**
|
|
@@ -344,8 +338,8 @@ class C {
|
|
|
344
338
|
*/
|
|
345
339
|
subscribe(t, n, s) {
|
|
346
340
|
this.subscriptions.has(t) || this.subscriptions.set(t, /* @__PURE__ */ new Set()), this.subscriptions.get(t).add(n), this.updateQueryState(t, {}, s);
|
|
347
|
-
const
|
|
348
|
-
return
|
|
341
|
+
const l = this.cache.get(t);
|
|
342
|
+
return l && n(l), this.manageRefetchInterval(t, l?.meta.staleTime ?? 0), () => {
|
|
349
343
|
this.subscriptions.get(t)?.delete(n), this.subscriptions.get(t)?.size === 0 && (this.subscriptions.delete(t), this.manageRefetchInterval(t, 0));
|
|
350
344
|
};
|
|
351
345
|
}
|
|
@@ -390,12 +384,12 @@ class C {
|
|
|
390
384
|
// Always true when a fetch is in progress
|
|
391
385
|
error: null
|
|
392
386
|
});
|
|
393
|
-
const [
|
|
394
|
-
if (
|
|
387
|
+
const [c, l] = await F.get(t);
|
|
388
|
+
if (c) {
|
|
395
389
|
this.updateQueryState(
|
|
396
390
|
t,
|
|
397
391
|
{
|
|
398
|
-
error:
|
|
392
|
+
error: c.message,
|
|
399
393
|
isFetching: !1
|
|
400
394
|
},
|
|
401
395
|
n
|
|
@@ -405,7 +399,7 @@ class C {
|
|
|
405
399
|
this.updateQueryState(
|
|
406
400
|
t,
|
|
407
401
|
{
|
|
408
|
-
data:
|
|
402
|
+
data: l,
|
|
409
403
|
isFetching: !1,
|
|
410
404
|
error: null
|
|
411
405
|
},
|
|
@@ -425,9 +419,9 @@ class C {
|
|
|
425
419
|
n.isFetching || this.fetchQuery(t);
|
|
426
420
|
}
|
|
427
421
|
}
|
|
428
|
-
const
|
|
422
|
+
const M = L.getInstance();
|
|
429
423
|
customElements.define(
|
|
430
|
-
|
|
424
|
+
a.AjaxForm.Name,
|
|
431
425
|
class extends HTMLElement {
|
|
432
426
|
form = null;
|
|
433
427
|
announce = null;
|
|
@@ -443,8 +437,8 @@ customElements.define(
|
|
|
443
437
|
connectedCallback() {
|
|
444
438
|
if (this.form = this.querySelector("form"), !this.form) return;
|
|
445
439
|
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");
|
|
440
|
+
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(h("message-submitting")) ?? this.messageSubmitting, this.messageSuccess = this.getAttribute(h("message-success")) ?? this.messageSuccess, this.messageError = this.getAttribute(h("message-error")) ?? this.messageError, this.keepFields = this.hasAttribute(h("keep-fields")), this.queryKeyToInvalidate = this.getAttribute(h("query-key"));
|
|
441
|
+
const t = this.getAttribute(h("action-on-success"));
|
|
448
442
|
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
443
|
}
|
|
450
444
|
disconnectedCallback() {
|
|
@@ -457,53 +451,53 @@ customElements.define(
|
|
|
457
451
|
if (!this.form || (e.preventDefault(), this.isDisabled())) return;
|
|
458
452
|
this.disable(), this.showStatus(this.messageSubmitting, "pending");
|
|
459
453
|
const { action: t, method: n } = this.form;
|
|
460
|
-
if (!
|
|
454
|
+
if (!F.isMethod(n)) {
|
|
461
455
|
console.error("Method is not a valid value"), this.showStatus(this.messageError, "error");
|
|
462
456
|
return;
|
|
463
457
|
}
|
|
464
458
|
let s = null;
|
|
465
459
|
this.spinner && (s = this.form.querySelector(":focus"));
|
|
466
|
-
const [
|
|
460
|
+
const [c, l] = await F.send(t, n, {
|
|
467
461
|
data: this.serialize(),
|
|
468
462
|
headers: {
|
|
469
463
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
470
464
|
"X-Requested-With": "XMLHttpRequest"
|
|
471
465
|
}
|
|
472
466
|
});
|
|
473
|
-
if (this.enable(), s?.focus(),
|
|
474
|
-
console.error("An error occurred",
|
|
467
|
+
if (this.enable(), s?.focus(), c) {
|
|
468
|
+
console.error("An error occurred", c), this.showStatus(this.messageError, "error");
|
|
475
469
|
return;
|
|
476
470
|
}
|
|
477
|
-
if (this.actionOnSuccess === "remove-form" && this.form.remove(), this.keepFields || this.reset(),
|
|
471
|
+
if (this.actionOnSuccess === "remove-form" && this.form.remove(), this.keepFields || this.reset(), l.type === "html") {
|
|
478
472
|
if (!this.queryKeyToInvalidate) return;
|
|
479
|
-
|
|
473
|
+
M.setQueryData(this.queryKeyToInvalidate, l), this.showStatus(this.messageSuccess, "success");
|
|
480
474
|
return;
|
|
481
475
|
}
|
|
482
|
-
if (this.showStatus(
|
|
483
|
-
window.location.href =
|
|
476
|
+
if (this.showStatus(l.message ?? this.messageSuccess, "success"), l.redirectUrl) {
|
|
477
|
+
window.location.href = l.redirectUrl;
|
|
484
478
|
return;
|
|
485
479
|
}
|
|
486
|
-
|
|
480
|
+
l.queryKey && M.invalidateQuery(l.queryKey), this.queryKeyToInvalidate && M.invalidateQuery(this.queryKeyToInvalidate), w(a.AjaxForm.Name, a.AjaxForm.Event.Form, this);
|
|
487
481
|
}
|
|
488
482
|
disable() {
|
|
489
|
-
this.setAttribute(this.isSubmittingAttribute, "");
|
|
483
|
+
this.setAttribute(h(this.isSubmittingAttribute), "");
|
|
490
484
|
}
|
|
491
485
|
enable() {
|
|
492
|
-
this.removeAttribute(this.isSubmittingAttribute);
|
|
486
|
+
this.removeAttribute(h(this.isSubmittingAttribute));
|
|
493
487
|
}
|
|
494
488
|
isDisabled() {
|
|
495
|
-
return this.hasAttribute(this.isSubmittingAttribute);
|
|
489
|
+
return this.hasAttribute(h(this.isSubmittingAttribute));
|
|
496
490
|
}
|
|
497
491
|
showStatus(e, t) {
|
|
498
492
|
if (!(!this.announce || !this.announceTitle))
|
|
499
493
|
switch (this.announceTitle.textContent = e, this.showStatusIcon(t), t) {
|
|
500
494
|
case "success":
|
|
501
|
-
this.announce.className = "alert
|
|
495
|
+
this.announce.className = "alert success", this.actionOnSuccess === "remove-message" && setTimeout(() => {
|
|
502
496
|
!this.announce || !this.announceTitle || (this.announceTitle.textContent = "", this.announce.className = "", this.showStatusIcon("pending"));
|
|
503
|
-
}, 6 *
|
|
497
|
+
}, 6 * K);
|
|
504
498
|
break;
|
|
505
499
|
case "error":
|
|
506
|
-
this.announce.className = "alert
|
|
500
|
+
this.announce.className = "alert danger";
|
|
507
501
|
break;
|
|
508
502
|
case "pending":
|
|
509
503
|
this.announce.className = "alert visually-hidden";
|
|
@@ -512,16 +506,20 @@ customElements.define(
|
|
|
512
506
|
}
|
|
513
507
|
showStatusIcon(e) {
|
|
514
508
|
if (!this.announce) return;
|
|
515
|
-
const t = this.announce.querySelector(
|
|
509
|
+
const t = this.announce.querySelector(
|
|
510
|
+
A("announce-success-icon")
|
|
511
|
+
), n = this.announce.querySelector(
|
|
512
|
+
A("announce-error-icon")
|
|
513
|
+
);
|
|
516
514
|
switch (e) {
|
|
517
515
|
case "success":
|
|
518
|
-
t?.removeAttribute(
|
|
516
|
+
t?.removeAttribute(v), n?.setAttribute(v, "");
|
|
519
517
|
break;
|
|
520
518
|
case "error":
|
|
521
|
-
t?.setAttribute(
|
|
519
|
+
t?.setAttribute(v, ""), n?.removeAttribute(v);
|
|
522
520
|
break;
|
|
523
521
|
case "pending":
|
|
524
|
-
t?.setAttribute(
|
|
522
|
+
t?.setAttribute(v, ""), n?.setAttribute(v, "");
|
|
525
523
|
break;
|
|
526
524
|
}
|
|
527
525
|
}
|
|
@@ -538,7 +536,7 @@ customElements.define(
|
|
|
538
536
|
}
|
|
539
537
|
);
|
|
540
538
|
customElements.define(
|
|
541
|
-
|
|
539
|
+
a.AjaxHtml.Name,
|
|
542
540
|
class extends HTMLElement {
|
|
543
541
|
queryKey = null;
|
|
544
542
|
unsubscribe = null;
|
|
@@ -547,21 +545,25 @@ customElements.define(
|
|
|
547
545
|
intersectionObserver = null;
|
|
548
546
|
staleTime;
|
|
549
547
|
connectedCallback() {
|
|
550
|
-
if (
|
|
551
|
-
console.warn(`${
|
|
548
|
+
if (!this.id) {
|
|
549
|
+
console.warn(`${a.AjaxHtml.Name} requires a "id" attribute.`, this);
|
|
552
550
|
return;
|
|
553
551
|
}
|
|
554
|
-
this.
|
|
552
|
+
if (this.queryKey = this.getAttribute(h("query-key")), !this.queryKey) {
|
|
553
|
+
console.warn(`${a.AjaxHtml.Name} requires a "query-key" attribute.`, this);
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
this.staleTime = this.hasAttribute(h("stale-time")) ? (
|
|
555
557
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
556
|
-
parseInt(this.getAttribute("stale-time"), 10)
|
|
557
|
-
) : void 0, this.unsubscribe =
|
|
558
|
+
parseInt(this.getAttribute(h("stale-time")), 10)
|
|
559
|
+
) : void 0, this.unsubscribe = M.subscribe(
|
|
558
560
|
this.queryKey,
|
|
559
561
|
(t) => {
|
|
560
562
|
this.renderContent(t);
|
|
561
563
|
},
|
|
562
564
|
{ staleTime: this.staleTime }
|
|
563
565
|
);
|
|
564
|
-
const e = this.getAttribute("load-strategy");
|
|
566
|
+
const e = this.getAttribute(h("load-strategy"));
|
|
565
567
|
if (e)
|
|
566
568
|
switch (e) {
|
|
567
569
|
case "server-side":
|
|
@@ -572,36 +574,32 @@ customElements.define(
|
|
|
572
574
|
break;
|
|
573
575
|
case "lazy":
|
|
574
576
|
this.intersectionObserver = new IntersectionObserver(
|
|
575
|
-
this.handleIntersection
|
|
577
|
+
this.handleIntersection,
|
|
576
578
|
{ rootMargin: "0px 0px 100px 0px" }
|
|
577
579
|
), this.intersectionObserver.observe(this);
|
|
578
580
|
break;
|
|
579
581
|
case "defer":
|
|
580
|
-
document.addEventListener(
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
{
|
|
584
|
-
once: !0
|
|
585
|
-
}
|
|
586
|
-
);
|
|
582
|
+
document.addEventListener("DOMContentLoaded", this.handleDomContentLoaded, {
|
|
583
|
+
once: !0
|
|
584
|
+
});
|
|
587
585
|
break;
|
|
588
586
|
}
|
|
589
587
|
else
|
|
590
588
|
this.initialFetchTriggered = !0;
|
|
591
589
|
}
|
|
592
590
|
disconnectedCallback() {
|
|
593
|
-
this.unsubscribe && this.unsubscribe(), document.removeEventListener("DOMContentLoaded", this.handleDomContentLoaded
|
|
591
|
+
this.unsubscribe && this.unsubscribe(), document.removeEventListener("DOMContentLoaded", this.handleDomContentLoaded), this.intersectionObserver && (this.intersectionObserver.unobserve(this), this.intersectionObserver.disconnect(), this.intersectionObserver = null);
|
|
594
592
|
}
|
|
595
|
-
handleDomContentLoaded() {
|
|
593
|
+
handleDomContentLoaded = () => {
|
|
596
594
|
this.triggerInitialFetch();
|
|
597
|
-
}
|
|
598
|
-
handleIntersection(e) {
|
|
595
|
+
};
|
|
596
|
+
handleIntersection = (e) => {
|
|
599
597
|
e.forEach((t) => {
|
|
600
598
|
t.isIntersecting && (this.triggerInitialFetch(), this.intersectionObserver && this.intersectionObserver.unobserve(this));
|
|
601
599
|
});
|
|
602
|
-
}
|
|
600
|
+
};
|
|
603
601
|
triggerInitialFetch() {
|
|
604
|
-
this.queryKey && (this.initialFetchTriggered || (this.initialFetchTriggered = !0,
|
|
602
|
+
this.queryKey && (this.initialFetchTriggered || (this.initialFetchTriggered = !0, M.invalidateQuery(this.queryKey)));
|
|
605
603
|
}
|
|
606
604
|
renderContent(e) {
|
|
607
605
|
if (!this.initialFetchTriggered || !e.data || e.data.type !== "html") return;
|
|
@@ -618,124 +616,165 @@ customElements.define(
|
|
|
618
616
|
}
|
|
619
617
|
}
|
|
620
618
|
);
|
|
619
|
+
const $ = "[popover]", P = (e) => `[popovertarget="${e}"]`, q = {
|
|
620
|
+
open: "open",
|
|
621
|
+
closed: "closed"
|
|
622
|
+
};
|
|
621
623
|
customElements.define(
|
|
622
|
-
|
|
624
|
+
a.Dropdown.Name,
|
|
623
625
|
class extends HTMLElement {
|
|
624
|
-
|
|
626
|
+
popoverElement = null;
|
|
625
627
|
trigger = null;
|
|
626
|
-
|
|
628
|
+
focusableElements = [];
|
|
629
|
+
searchString = "";
|
|
630
|
+
searchTimeout = -1;
|
|
627
631
|
connectedCallback() {
|
|
628
|
-
|
|
632
|
+
const e = this.querySelector($);
|
|
633
|
+
if (!e) {
|
|
634
|
+
console.error(
|
|
635
|
+
`${a.Dropdown.Name} component: Missing element with selector "${$}"`
|
|
636
|
+
);
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
this.popoverElement = e;
|
|
640
|
+
const t = this.querySelector(
|
|
641
|
+
P(this.popoverElement.id)
|
|
642
|
+
);
|
|
643
|
+
if (!t) {
|
|
644
|
+
console.error(
|
|
645
|
+
`${a.Dropdown.Name} component: Missing element with selector "${P(this.popoverElement.id)}"`
|
|
646
|
+
);
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
this.trigger = t, this.focusableElements = this.getFocusableElementsForTrap(), this.popoverElement.setAttribute(h("state"), q.closed), this.addEventListener(f.KeyDown, this.handleKeydown), this.popoverElement.addEventListener(f.Toggle, this.handleToggle), this.setAttribute(h("state"), "ready");
|
|
629
650
|
}
|
|
630
651
|
disconnectedCallback() {
|
|
631
|
-
this.
|
|
652
|
+
this.removeEventListener(f.KeyDown, this.handleKeydown), this.popoverElement?.removeEventListener(f.Toggle, this.handleToggle);
|
|
632
653
|
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
654
|
+
getFocusableElementsForTrap() {
|
|
655
|
+
return this.popoverElement ? [...Array.from(
|
|
656
|
+
this.popoverElement.querySelectorAll(R)
|
|
657
|
+
)].filter(Boolean) : [];
|
|
658
|
+
}
|
|
659
|
+
handleToggle = (e) => {
|
|
660
|
+
if (e.newState === "open") {
|
|
661
|
+
this.onPopoverOpen();
|
|
640
662
|
return;
|
|
641
663
|
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
664
|
+
this.onPopoverClose();
|
|
665
|
+
};
|
|
666
|
+
onPopoverOpen() {
|
|
667
|
+
this.popoverElement && this.popoverElement.setAttribute(h("state"), q.open);
|
|
646
668
|
}
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
);
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
if (
|
|
655
|
-
|
|
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();
|
|
669
|
+
onPopoverClose() {
|
|
670
|
+
this.popoverElement && this.popoverElement.setAttribute(h("state"), q.closed);
|
|
671
|
+
}
|
|
672
|
+
isOpen() {
|
|
673
|
+
return this.popoverElement ? this.popoverElement.getAttribute(h("state")) === q.open : !1;
|
|
674
|
+
}
|
|
675
|
+
handleKeydown = (e) => {
|
|
676
|
+
if (this.isOpen()) {
|
|
677
|
+
this.handleKeyboardWhenOpen(e);
|
|
683
678
|
return;
|
|
684
679
|
}
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
680
|
+
this.handleKeyboardWhenClosed(e);
|
|
681
|
+
};
|
|
682
|
+
handleKeyboardWhenClosed = (e) => {
|
|
683
|
+
if (!this.isOpen())
|
|
684
|
+
switch (e.key) {
|
|
685
|
+
case "Enter":
|
|
686
|
+
case " ":
|
|
687
|
+
case "ArrowDown":
|
|
688
|
+
e.preventDefault(), this.openPopover(), this.focusOptionByIndex(0);
|
|
689
|
+
break;
|
|
690
|
+
case "ArrowUp":
|
|
691
|
+
e.preventDefault(), this.openPopover(), this.focusOptionByIndex(this.focusableElements.length - 1);
|
|
692
|
+
break;
|
|
693
|
+
default:
|
|
694
|
+
/^[a-zA-Z0-9]$/.test(e.key) && (e.preventDefault(), this.openPopover(), this.handleSearchString(e.key));
|
|
695
|
+
break;
|
|
690
696
|
}
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
697
|
+
};
|
|
698
|
+
handleKeyboardWhenOpen = (e) => {
|
|
699
|
+
if (this.isOpen())
|
|
700
|
+
switch (e.key) {
|
|
701
|
+
case " ":
|
|
702
|
+
e.preventDefault(), this.triggerAction(e);
|
|
703
|
+
break;
|
|
704
|
+
case "Tab":
|
|
705
|
+
this.closePopover(), e.shiftKey && (e.preventDefault(), this.trigger?.focus());
|
|
706
|
+
break;
|
|
707
|
+
case "ArrowDown":
|
|
708
|
+
e.target && (e.target instanceof HTMLAnchorElement || e.target instanceof HTMLButtonElement) && this.focusOptionByStep(e.target, 1, e);
|
|
709
|
+
break;
|
|
710
|
+
case "ArrowUp":
|
|
711
|
+
e.target && (e.target instanceof HTMLAnchorElement || e.target instanceof HTMLButtonElement) && this.focusOptionByStep(e.target, -1, e);
|
|
712
|
+
break;
|
|
713
|
+
case "Home":
|
|
714
|
+
e.preventDefault(), this.focusOptionByIndex(0);
|
|
715
|
+
break;
|
|
716
|
+
case "End":
|
|
717
|
+
e.preventDefault(), this.focusOptionByIndex(this.focusableElements.length - 1);
|
|
718
|
+
break;
|
|
719
|
+
default:
|
|
720
|
+
/^[a-zA-Z0-9]$/.test(e.key) && (e.preventDefault(), this.handleSearchString(e.key));
|
|
721
|
+
break;
|
|
695
722
|
}
|
|
696
|
-
|
|
723
|
+
};
|
|
724
|
+
openPopover = () => {
|
|
725
|
+
this.trigger && (this.isOpen() || this.trigger.click());
|
|
726
|
+
};
|
|
727
|
+
closePopover = () => {
|
|
728
|
+
this.popoverElement && this.isOpen() && this.popoverElement.hidePopover();
|
|
729
|
+
};
|
|
730
|
+
triggerAction = (e) => {
|
|
731
|
+
e.target instanceof HTMLAnchorElement && e.target.click();
|
|
732
|
+
};
|
|
733
|
+
focusOptionByStep = (e, t, n) => {
|
|
734
|
+
const s = this.focusableElements;
|
|
735
|
+
if (!s.length) return;
|
|
736
|
+
const c = e, l = s.indexOf(c);
|
|
737
|
+
if (n.preventDefault(), l === -1) {
|
|
738
|
+
s[0]?.focus();
|
|
697
739
|
return;
|
|
698
740
|
}
|
|
741
|
+
const u = (l + t + s.length) % s.length;
|
|
742
|
+
u >= s.length || u < 0 || s[u]?.focus();
|
|
743
|
+
};
|
|
744
|
+
focusOptionByIndex(e) {
|
|
745
|
+
if (!this.focusableElements.length) return;
|
|
746
|
+
const t = Math.max(0, Math.min(e, this.focusableElements.length - 1));
|
|
747
|
+
this.focusableElements[t]?.focus();
|
|
748
|
+
}
|
|
749
|
+
handleSearchString(e) {
|
|
750
|
+
if (clearTimeout(this.searchTimeout), this.searchString += e.toLowerCase(), !this.focusableElements.length) return;
|
|
751
|
+
const t = this.getActiveOption(), n = this.searchString.length === 1 && t ? this.focusableElements.indexOf(t) + 1 : 0, s = this.findOptionBySearchString(this.focusableElements, n) ?? this.findOptionBySearchString(this.focusableElements, 0);
|
|
752
|
+
s && s.focus(), this.searchTimeout = window.setTimeout(() => {
|
|
753
|
+
this.searchString = "";
|
|
754
|
+
}, 500);
|
|
755
|
+
}
|
|
756
|
+
findOptionBySearchString(e, t) {
|
|
757
|
+
for (let n = 0; n < e.length; n++) {
|
|
758
|
+
const s = (t + n) % e.length;
|
|
759
|
+
if (e[s]?.textContent.trim().toLowerCase()?.startsWith(this.searchString))
|
|
760
|
+
return e[s] ?? null;
|
|
761
|
+
}
|
|
762
|
+
return null;
|
|
699
763
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
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());
|
|
764
|
+
getActiveOption() {
|
|
765
|
+
const e = document.activeElement;
|
|
766
|
+
return !e || !(e instanceof HTMLAnchorElement) || !(e instanceof HTMLButtonElement) ? null : this.focusableElements.find((t) => t === e) ?? null;
|
|
728
767
|
}
|
|
729
768
|
}
|
|
730
769
|
);
|
|
731
770
|
customElements.define(
|
|
732
|
-
|
|
771
|
+
a.ExclusiveCheckbox.Name,
|
|
733
772
|
class extends HTMLElement {
|
|
734
773
|
targetName = null;
|
|
735
774
|
exclusiveCheckbox = null;
|
|
736
775
|
checkboxes = null;
|
|
737
776
|
connectedCallback() {
|
|
738
|
-
this.targetName = this.getAttribute("target-name"), this.exclusiveCheckbox = this.querySelector("input"), !(!this.targetName || !this.exclusiveCheckbox || !this.parentElement) && (this.checkboxes = [
|
|
777
|
+
this.targetName = this.getAttribute(h("target-name")), this.exclusiveCheckbox = this.querySelector("input"), !(!this.targetName || !this.exclusiveCheckbox || !this.parentElement) && (this.checkboxes = [
|
|
739
778
|
...this.parentElement.querySelectorAll(
|
|
740
779
|
`[name="${this.targetName}"]`
|
|
741
780
|
)
|
|
@@ -744,53 +783,50 @@ customElements.define(
|
|
|
744
783
|
disconnectedCallback() {
|
|
745
784
|
if (this.exclusiveCheckbox && this.exclusiveCheckbox.removeEventListener(
|
|
746
785
|
f.Change,
|
|
747
|
-
this.handleExclusiveChange
|
|
786
|
+
this.handleExclusiveChange
|
|
748
787
|
), this.checkboxes)
|
|
749
788
|
for (const e of this.checkboxes)
|
|
750
|
-
e.removeEventListener(
|
|
751
|
-
f.Change,
|
|
752
|
-
this.handleCheckboxChange.bind(this)
|
|
753
|
-
);
|
|
789
|
+
e.removeEventListener(f.Change, this.handleCheckboxChange);
|
|
754
790
|
}
|
|
755
791
|
addEvents() {
|
|
756
792
|
if (!(!this.exclusiveCheckbox || !this.targetName || !this.parentElement || !this.checkboxes)) {
|
|
757
|
-
this.exclusiveCheckbox.addEventListener("change", this.handleExclusiveChange
|
|
793
|
+
this.exclusiveCheckbox.addEventListener("change", this.handleExclusiveChange);
|
|
758
794
|
for (const e of this.checkboxes)
|
|
759
|
-
e.disabled || e.addEventListener(f.Change, this.handleCheckboxChange
|
|
795
|
+
e.disabled || e.addEventListener(f.Change, this.handleCheckboxChange);
|
|
760
796
|
}
|
|
761
797
|
}
|
|
762
|
-
handleExclusiveChange() {
|
|
798
|
+
handleExclusiveChange = () => {
|
|
763
799
|
if (!this.exclusiveCheckbox || !this.checkboxes || this.checkboxes.length === 0) return;
|
|
764
800
|
const e = this.exclusiveCheckbox.checked;
|
|
765
801
|
for (const t of this.checkboxes)
|
|
766
802
|
t.disabled || e && (t.checked = !1);
|
|
767
|
-
this.exclusiveCheckbox.indeterminate = !1,
|
|
768
|
-
|
|
769
|
-
|
|
803
|
+
this.exclusiveCheckbox.indeterminate = !1, w(
|
|
804
|
+
a.ExclusiveCheckbox.Name,
|
|
805
|
+
a.ExclusiveCheckbox.Event.Toggle,
|
|
770
806
|
this.exclusiveCheckbox
|
|
771
807
|
);
|
|
772
|
-
}
|
|
773
|
-
handleCheckboxChange() {
|
|
808
|
+
};
|
|
809
|
+
handleCheckboxChange = () => {
|
|
774
810
|
if (!this.exclusiveCheckbox || !this.checkboxes || this.checkboxes.length === 0 || !this.exclusiveCheckbox.checked) return;
|
|
775
811
|
const e = this.checkboxes.some(
|
|
776
812
|
(t) => !t.disabled && t.checked
|
|
777
813
|
);
|
|
778
|
-
this.exclusiveCheckbox.checked = !e,
|
|
779
|
-
|
|
780
|
-
|
|
814
|
+
this.exclusiveCheckbox.checked = !e, w(
|
|
815
|
+
a.ExclusiveCheckbox.Name,
|
|
816
|
+
a.ExclusiveCheckbox.Event.Toggle,
|
|
781
817
|
this.exclusiveCheckbox
|
|
782
818
|
);
|
|
783
|
-
}
|
|
819
|
+
};
|
|
784
820
|
}
|
|
785
821
|
);
|
|
786
822
|
customElements.define(
|
|
787
|
-
|
|
823
|
+
a.SelectAll.Name,
|
|
788
824
|
class extends HTMLElement {
|
|
789
825
|
targetName = null;
|
|
790
826
|
selectAllCheckbox = null;
|
|
791
827
|
checkboxes = null;
|
|
792
828
|
connectedCallback() {
|
|
793
|
-
this.targetName = this.getAttribute("target-name"), this.selectAllCheckbox = this.querySelector("input"), !(!this.targetName || !this.selectAllCheckbox || !this.parentElement) && (this.checkboxes = [
|
|
829
|
+
this.targetName = this.getAttribute(h("target-name")), this.selectAllCheckbox = this.querySelector("input"), !(!this.targetName || !this.selectAllCheckbox || !this.parentElement) && (this.checkboxes = [
|
|
794
830
|
...this.parentElement.querySelectorAll(
|
|
795
831
|
`[name="${this.targetName}"]`
|
|
796
832
|
)
|
|
@@ -799,58 +835,55 @@ customElements.define(
|
|
|
799
835
|
disconnectedCallback() {
|
|
800
836
|
if (this.selectAllCheckbox && this.selectAllCheckbox.removeEventListener(
|
|
801
837
|
f.Change,
|
|
802
|
-
this.handleSelectAllChange
|
|
838
|
+
this.handleSelectAllChange
|
|
803
839
|
), this.checkboxes)
|
|
804
840
|
for (const e of this.checkboxes)
|
|
805
|
-
e.removeEventListener(
|
|
806
|
-
f.Change,
|
|
807
|
-
this.handleCheckboxChange.bind(this)
|
|
808
|
-
);
|
|
841
|
+
e.removeEventListener(f.Change, this.handleCheckboxChange);
|
|
809
842
|
}
|
|
810
843
|
ready() {
|
|
811
|
-
this.setAttribute("
|
|
844
|
+
this.setAttribute(h("state"), "ready");
|
|
812
845
|
}
|
|
813
846
|
addEvents() {
|
|
814
847
|
if (!(!this.selectAllCheckbox || !this.targetName || !this.parentElement || !this.checkboxes)) {
|
|
815
|
-
this.selectAllCheckbox.addEventListener("change", this.handleSelectAllChange
|
|
848
|
+
this.selectAllCheckbox.addEventListener("change", this.handleSelectAllChange);
|
|
816
849
|
for (const e of this.checkboxes)
|
|
817
|
-
e.disabled || (e.parentElement?.classList.add("padding-inline-start-lg"), e.addEventListener(f.Change, this.handleCheckboxChange
|
|
850
|
+
e.disabled || (e.parentElement?.classList.add("padding-inline-start-lg"), e.addEventListener(f.Change, this.handleCheckboxChange));
|
|
818
851
|
}
|
|
819
852
|
}
|
|
820
|
-
handleSelectAllChange() {
|
|
853
|
+
handleSelectAllChange = () => {
|
|
821
854
|
if (!this.selectAllCheckbox || !this.checkboxes || this.checkboxes.length === 0) return;
|
|
822
855
|
const e = this.selectAllCheckbox.checked;
|
|
823
856
|
for (const t of this.checkboxes)
|
|
824
857
|
t.disabled || (t.checked = e);
|
|
825
|
-
this.selectAllCheckbox.indeterminate = !1,
|
|
826
|
-
|
|
827
|
-
|
|
858
|
+
this.selectAllCheckbox.indeterminate = !1, w(
|
|
859
|
+
a.SelectAll.Name,
|
|
860
|
+
a.SelectAll.Event.Toggle,
|
|
828
861
|
this.selectAllCheckbox
|
|
829
862
|
);
|
|
830
|
-
}
|
|
831
|
-
handleCheckboxChange() {
|
|
863
|
+
};
|
|
864
|
+
handleCheckboxChange = () => {
|
|
832
865
|
if (!this.selectAllCheckbox || !this.checkboxes || this.checkboxes.length === 0) return;
|
|
833
866
|
const e = this.checkboxes.filter(
|
|
834
|
-
(
|
|
867
|
+
(c) => !c.disabled && c.checked
|
|
835
868
|
).length, t = this.checkboxes.length, n = e === t, s = e === 0;
|
|
836
|
-
this.selectAllCheckbox.indeterminate = !n && !s, this.selectAllCheckbox.checked = n,
|
|
837
|
-
|
|
838
|
-
|
|
869
|
+
this.selectAllCheckbox.indeterminate = !n && !s, this.selectAllCheckbox.checked = n, w(
|
|
870
|
+
a.SelectAll.Name,
|
|
871
|
+
a.SelectAll.Event.Toggle,
|
|
839
872
|
this.selectAllCheckbox
|
|
840
873
|
);
|
|
841
|
-
}
|
|
874
|
+
};
|
|
842
875
|
}
|
|
843
876
|
);
|
|
844
877
|
customElements.define(
|
|
845
|
-
|
|
878
|
+
a.UntilSelected.Name,
|
|
846
879
|
class extends HTMLElement {
|
|
847
880
|
target = null;
|
|
848
881
|
targetElement = null;
|
|
849
882
|
focusTargetElement = null;
|
|
850
883
|
events = null;
|
|
851
|
-
|
|
884
|
+
showWhen = "checked";
|
|
852
885
|
connectedCallback() {
|
|
853
|
-
if (this.target = this.getAttribute("target"), !this.target) return;
|
|
886
|
+
if (this.target = this.getAttribute(h("target")), !this.target) return;
|
|
854
887
|
try {
|
|
855
888
|
const s = document.getElementById(this.target);
|
|
856
889
|
if (!(s instanceof HTMLInputElement)) {
|
|
@@ -862,89 +895,169 @@ customElements.define(
|
|
|
862
895
|
console.warn("Could not select element", s);
|
|
863
896
|
}
|
|
864
897
|
if (!this.targetElement) return;
|
|
865
|
-
const e = this.getAttribute("focus-target");
|
|
898
|
+
const e = this.getAttribute(h("focus-target"));
|
|
866
899
|
if (e)
|
|
867
900
|
try {
|
|
868
901
|
this.focusTargetElement = document.getElementById(e);
|
|
869
902
|
} catch (s) {
|
|
870
903
|
console.warn("Could not select focus target", s);
|
|
871
904
|
}
|
|
872
|
-
const t = this.getAttribute("events");
|
|
873
|
-
t && (this.events = t.split(",").map((s) => s.trim())), this.
|
|
905
|
+
const t = this.getAttribute(h("events"));
|
|
906
|
+
t && (this.events = t.split(",").map((s) => s.trim())), this.showWhen = this.getAttribute(h("show-when")) === "not-checked" ? "not-checked" : "checked";
|
|
874
907
|
const n = this.targetElement.checked;
|
|
875
|
-
this.toggleAttribute(
|
|
908
|
+
this.toggleAttribute(
|
|
909
|
+
v,
|
|
910
|
+
this.showWhen === "checked" ? !n : n
|
|
911
|
+
), this.addEvents();
|
|
876
912
|
}
|
|
877
913
|
disconnectedCallback() {
|
|
878
914
|
if (document.removeEventListener(
|
|
879
|
-
`${
|
|
880
|
-
this.handleTargetChange
|
|
915
|
+
`${a.ExclusiveCheckbox.Name}:${a.ExclusiveCheckbox.Event.Toggle}`,
|
|
916
|
+
this.handleTargetChange
|
|
881
917
|
), document.removeEventListener(
|
|
882
|
-
`${
|
|
883
|
-
this.handleTargetChange
|
|
884
|
-
), this.targetElement && this.targetElement.removeEventListener(
|
|
885
|
-
f.Change,
|
|
886
|
-
this.handleTargetChange.bind(this)
|
|
887
|
-
), this.events && this.events.length > 0)
|
|
918
|
+
`${a.SelectAll.Name}:${a.ExclusiveCheckbox.Event.Toggle}`,
|
|
919
|
+
this.handleTargetChange
|
|
920
|
+
), this.targetElement && this.targetElement.removeEventListener(f.Change, this.handleTargetChange), this.events && this.events.length > 0)
|
|
888
921
|
for (const e of this.events)
|
|
889
|
-
document.removeEventListener(e, this.handleTargetChange
|
|
922
|
+
document.removeEventListener(e, this.handleTargetChange);
|
|
890
923
|
}
|
|
891
924
|
addEvents() {
|
|
892
925
|
if (document.addEventListener(
|
|
893
|
-
`${
|
|
894
|
-
this.handleTargetChange
|
|
926
|
+
`${a.ExclusiveCheckbox.Name}:${a.ExclusiveCheckbox.Event.Toggle}`,
|
|
927
|
+
this.handleTargetChange
|
|
895
928
|
), document.addEventListener(
|
|
896
|
-
`${
|
|
897
|
-
this.handleTargetChange
|
|
898
|
-
), this.targetElement && this.targetElement.addEventListener(
|
|
899
|
-
f.Change,
|
|
900
|
-
this.handleTargetChange.bind(this)
|
|
901
|
-
), this.events && this.events.length > 0)
|
|
929
|
+
`${a.SelectAll.Name}:${a.ExclusiveCheckbox.Event.Toggle}`,
|
|
930
|
+
this.handleTargetChange
|
|
931
|
+
), this.targetElement && this.targetElement.addEventListener(f.Change, this.handleTargetChange), this.events && this.events.length > 0)
|
|
902
932
|
for (const e of this.events)
|
|
903
|
-
document.addEventListener(e, this.handleTargetChange
|
|
933
|
+
document.addEventListener(e, this.handleTargetChange);
|
|
904
934
|
}
|
|
905
|
-
handleTargetChange() {
|
|
935
|
+
handleTargetChange = () => {
|
|
906
936
|
if (!this.targetElement) return;
|
|
907
|
-
const e = this.
|
|
908
|
-
this.toggleAttribute(
|
|
937
|
+
const e = this.showWhen === "checked" ? !this.targetElement.checked : this.targetElement.checked;
|
|
938
|
+
this.toggleAttribute(v, e), e && this.focusTargetElement && this.matches(":focus-within") && this.focusTargetElement.focus();
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
);
|
|
942
|
+
function j(e, t) {
|
|
943
|
+
let n;
|
|
944
|
+
return function(...s) {
|
|
945
|
+
clearTimeout(n), n = setTimeout(() => {
|
|
946
|
+
e.apply(this, s);
|
|
947
|
+
}, t);
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
customElements.define(
|
|
951
|
+
a.SearchFilter.Name,
|
|
952
|
+
class extends HTMLElement {
|
|
953
|
+
// TODO Add an aria-live region to announce number of results found
|
|
954
|
+
// TODO handle focus management for accessibility
|
|
955
|
+
inputElement = null;
|
|
956
|
+
searchButton = null;
|
|
957
|
+
collections = [];
|
|
958
|
+
debouncedFilterTargets;
|
|
959
|
+
constructor() {
|
|
960
|
+
super(), this.debouncedFilterTargets = j(this.filterTargets, 300);
|
|
909
961
|
}
|
|
962
|
+
connectedCallback() {
|
|
963
|
+
if (this.inputElement = this.querySelector('input[type="search"]'), this.searchButton = this.querySelector('button[type="submit"]'), !this.inputElement || !this.searchButton) return;
|
|
964
|
+
const e = this.getAttribute(h("collection-selector"));
|
|
965
|
+
if (!e) {
|
|
966
|
+
console.warn(
|
|
967
|
+
`${a.SearchFilter.Name} requires a "collection-selector" attribute.`,
|
|
968
|
+
this
|
|
969
|
+
);
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
const t = this.getAttribute(h("target-selector"));
|
|
973
|
+
if (!t) {
|
|
974
|
+
console.warn(
|
|
975
|
+
`${a.SearchFilter.Name} requires a "target-selector" attribute.`,
|
|
976
|
+
this
|
|
977
|
+
);
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
const n = Array.from(
|
|
981
|
+
document.querySelectorAll(e)
|
|
982
|
+
);
|
|
983
|
+
if (n.length !== 0) {
|
|
984
|
+
for (const s of n) {
|
|
985
|
+
const c = Array.from(
|
|
986
|
+
s.querySelectorAll(t)
|
|
987
|
+
);
|
|
988
|
+
this.collections.push({
|
|
989
|
+
element: s,
|
|
990
|
+
targetElements: c.map((l) => ({
|
|
991
|
+
element: l,
|
|
992
|
+
text: l.textContent.toLocaleLowerCase()
|
|
993
|
+
}))
|
|
994
|
+
});
|
|
995
|
+
}
|
|
996
|
+
this.collections.length !== 0 && (this.inputElement.addEventListener(f.Input, this.debouncedFilterTargets), this.searchButton.addEventListener(f.Click, this.onSearchClick));
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
disconnectedCallback() {
|
|
1000
|
+
this.inputElement?.removeEventListener(f.Input, this.debouncedFilterTargets), this.searchButton?.removeEventListener(f.Click, this.onSearchClick);
|
|
1001
|
+
}
|
|
1002
|
+
onSearchClick = (e) => {
|
|
1003
|
+
e.preventDefault(), this.filterTargets();
|
|
1004
|
+
};
|
|
1005
|
+
filterTargets = () => {
|
|
1006
|
+
if (!this.inputElement) return;
|
|
1007
|
+
const e = this.inputElement.value.toLocaleLowerCase();
|
|
1008
|
+
if (!e) {
|
|
1009
|
+
for (const t of this.collections) {
|
|
1010
|
+
t.element.removeAttribute(v);
|
|
1011
|
+
for (const n of t.targetElements)
|
|
1012
|
+
n.element.removeAttribute(v);
|
|
1013
|
+
}
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
this.collections.forEach((t) => {
|
|
1017
|
+
let n = !1;
|
|
1018
|
+
for (const s of t.targetElements)
|
|
1019
|
+
s.text.includes(e) ? (s.element.removeAttribute(v), n = !0) : s.element.setAttribute(v, "");
|
|
1020
|
+
n ? t.element.removeAttribute(v) : t.element.setAttribute(v, "");
|
|
1021
|
+
});
|
|
1022
|
+
};
|
|
910
1023
|
}
|
|
911
1024
|
);
|
|
912
|
-
function
|
|
1025
|
+
function N() {
|
|
913
1026
|
return typeof HTMLButtonElement < "u" && "command" in HTMLButtonElement.prototype && "source" in ((globalThis.CommandEvent || {}).prototype || {});
|
|
914
1027
|
}
|
|
915
|
-
function
|
|
1028
|
+
function U() {
|
|
916
1029
|
document.addEventListener(
|
|
917
1030
|
"invoke",
|
|
918
|
-
(
|
|
919
|
-
|
|
1031
|
+
(r) => {
|
|
1032
|
+
r.type == "invoke" && r.isTrusted && (r.stopImmediatePropagation(), r.preventDefault());
|
|
920
1033
|
},
|
|
921
1034
|
!0
|
|
922
1035
|
), document.addEventListener(
|
|
923
1036
|
"command",
|
|
924
|
-
(
|
|
925
|
-
|
|
1037
|
+
(r) => {
|
|
1038
|
+
r.type == "command" && r.isTrusted && (r.stopImmediatePropagation(), r.preventDefault());
|
|
926
1039
|
},
|
|
927
1040
|
!0
|
|
928
1041
|
);
|
|
929
|
-
function e(i, o
|
|
930
|
-
Object.defineProperty(
|
|
931
|
-
...Object.getOwnPropertyDescriptor(
|
|
932
|
-
enumerable:
|
|
1042
|
+
function e(r, i, o = !0) {
|
|
1043
|
+
Object.defineProperty(r, i, {
|
|
1044
|
+
...Object.getOwnPropertyDescriptor(r, i),
|
|
1045
|
+
enumerable: o
|
|
933
1046
|
});
|
|
934
1047
|
}
|
|
935
|
-
function t(
|
|
936
|
-
return
|
|
1048
|
+
function t(r) {
|
|
1049
|
+
return r && typeof r.getRootNode == "function" ? r.getRootNode() : r && r.parentNode ? t(r.parentNode) : r;
|
|
937
1050
|
}
|
|
938
1051
|
const n = /* @__PURE__ */ new WeakMap(), s = /* @__PURE__ */ new WeakMap();
|
|
939
|
-
class
|
|
940
|
-
constructor(
|
|
941
|
-
super(
|
|
942
|
-
const { source:
|
|
943
|
-
if (
|
|
1052
|
+
class c extends Event {
|
|
1053
|
+
constructor(i, o = {}) {
|
|
1054
|
+
super(i, o);
|
|
1055
|
+
const { source: d, command: E } = o;
|
|
1056
|
+
if (d != null && !(d instanceof Element))
|
|
944
1057
|
throw new TypeError("source must be an element");
|
|
945
|
-
n.set(this,
|
|
1058
|
+
n.set(this, d || null), s.set(
|
|
946
1059
|
this,
|
|
947
|
-
|
|
1060
|
+
E !== void 0 ? String(E) : ""
|
|
948
1061
|
);
|
|
949
1062
|
}
|
|
950
1063
|
get [Symbol.toStringTag]() {
|
|
@@ -953,10 +1066,10 @@ function H() {
|
|
|
953
1066
|
get source() {
|
|
954
1067
|
if (!n.has(this))
|
|
955
1068
|
throw new TypeError("illegal invocation");
|
|
956
|
-
const
|
|
957
|
-
if (!(
|
|
958
|
-
const
|
|
959
|
-
return
|
|
1069
|
+
const i = n.get(this);
|
|
1070
|
+
if (!(i instanceof Element)) return null;
|
|
1071
|
+
const o = t(i);
|
|
1072
|
+
return o !== t(this.target || document) ? o.host : i;
|
|
960
1073
|
}
|
|
961
1074
|
get command() {
|
|
962
1075
|
if (!s.has(this))
|
|
@@ -974,21 +1087,21 @@ function H() {
|
|
|
974
1087
|
);
|
|
975
1088
|
}
|
|
976
1089
|
}
|
|
977
|
-
e(
|
|
978
|
-
class
|
|
979
|
-
constructor(
|
|
980
|
-
throw super(
|
|
1090
|
+
e(c.prototype, "source"), e(c.prototype, "command");
|
|
1091
|
+
class l extends Event {
|
|
1092
|
+
constructor(i, o = {}) {
|
|
1093
|
+
throw super(i, o), new Error(
|
|
981
1094
|
"InvokeEvent has been deprecated, it has been renamed to `CommandEvent`"
|
|
982
1095
|
);
|
|
983
1096
|
}
|
|
984
1097
|
}
|
|
985
|
-
const
|
|
986
|
-
function
|
|
987
|
-
Object.defineProperties(
|
|
1098
|
+
const u = /* @__PURE__ */ new WeakMap();
|
|
1099
|
+
function b(r) {
|
|
1100
|
+
Object.defineProperties(r.prototype, {
|
|
988
1101
|
commandForElement: {
|
|
989
1102
|
enumerable: !0,
|
|
990
1103
|
configurable: !0,
|
|
991
|
-
set(
|
|
1104
|
+
set(i) {
|
|
992
1105
|
if (this.hasAttribute("invokeaction"))
|
|
993
1106
|
throw new TypeError(
|
|
994
1107
|
"Element has deprecated `invokeaction` attribute, replace with `command`"
|
|
@@ -997,12 +1110,12 @@ function H() {
|
|
|
997
1110
|
throw new TypeError(
|
|
998
1111
|
"Element has deprecated `invoketarget` attribute, replace with `commandfor`"
|
|
999
1112
|
);
|
|
1000
|
-
if (
|
|
1001
|
-
this.removeAttribute("commandfor"),
|
|
1002
|
-
else if (
|
|
1113
|
+
if (i === null)
|
|
1114
|
+
this.removeAttribute("commandfor"), u.delete(this);
|
|
1115
|
+
else if (i instanceof Element) {
|
|
1003
1116
|
this.setAttribute("commandfor", "");
|
|
1004
|
-
const
|
|
1005
|
-
t(this) ===
|
|
1117
|
+
const o = t(i);
|
|
1118
|
+
t(this) === o || o === this.ownerDocument ? u.set(this, i) : u.delete(this);
|
|
1006
1119
|
} else
|
|
1007
1120
|
throw new TypeError("commandForElement must be an element or null");
|
|
1008
1121
|
},
|
|
@@ -1019,32 +1132,33 @@ function H() {
|
|
|
1019
1132
|
return console.warn(
|
|
1020
1133
|
"Element with `commandFor` is a form participant. It should explicitly set `type=button` in order for `commandFor` to work"
|
|
1021
1134
|
), null;
|
|
1022
|
-
const
|
|
1023
|
-
if (
|
|
1024
|
-
return
|
|
1025
|
-
const
|
|
1026
|
-
return (
|
|
1135
|
+
const i = u.get(this);
|
|
1136
|
+
if (i)
|
|
1137
|
+
return i.isConnected ? i : (u.delete(this), null);
|
|
1138
|
+
const o = t(this), d = this.getAttribute("commandfor");
|
|
1139
|
+
return (o instanceof Document || o instanceof ShadowRoot) && d && o.getElementById(d) || null;
|
|
1027
1140
|
}
|
|
1028
1141
|
},
|
|
1029
1142
|
command: {
|
|
1030
1143
|
enumerable: !0,
|
|
1031
1144
|
configurable: !0,
|
|
1032
1145
|
get() {
|
|
1033
|
-
const
|
|
1034
|
-
if (
|
|
1035
|
-
const
|
|
1036
|
-
switch (
|
|
1146
|
+
const i = this.getAttribute("command") || "";
|
|
1147
|
+
if (i.startsWith("--")) return i;
|
|
1148
|
+
const o = i.toLowerCase();
|
|
1149
|
+
switch (o) {
|
|
1037
1150
|
case "show-modal":
|
|
1151
|
+
case "request-close":
|
|
1038
1152
|
case "close":
|
|
1039
1153
|
case "toggle-popover":
|
|
1040
1154
|
case "hide-popover":
|
|
1041
1155
|
case "show-popover":
|
|
1042
|
-
return
|
|
1156
|
+
return o;
|
|
1043
1157
|
}
|
|
1044
1158
|
return "";
|
|
1045
1159
|
},
|
|
1046
|
-
set(
|
|
1047
|
-
this.setAttribute("command",
|
|
1160
|
+
set(i) {
|
|
1161
|
+
this.setAttribute("command", i);
|
|
1048
1162
|
}
|
|
1049
1163
|
},
|
|
1050
1164
|
invokeAction: {
|
|
@@ -1055,7 +1169,7 @@ function H() {
|
|
|
1055
1169
|
"invokeAction is deprecated. It has been renamed to command"
|
|
1056
1170
|
);
|
|
1057
1171
|
},
|
|
1058
|
-
set(
|
|
1172
|
+
set(i) {
|
|
1059
1173
|
throw new Error(
|
|
1060
1174
|
"invokeAction is deprecated. It has been renamed to command"
|
|
1061
1175
|
);
|
|
@@ -1069,7 +1183,7 @@ function H() {
|
|
|
1069
1183
|
"invokeTargetElement is deprecated. It has been renamed to command"
|
|
1070
1184
|
);
|
|
1071
1185
|
},
|
|
1072
|
-
set(
|
|
1186
|
+
set(i) {
|
|
1073
1187
|
throw new Error(
|
|
1074
1188
|
"invokeTargetElement is deprecated. It has been renamed to command"
|
|
1075
1189
|
);
|
|
@@ -1077,100 +1191,104 @@ function H() {
|
|
|
1077
1191
|
}
|
|
1078
1192
|
});
|
|
1079
1193
|
}
|
|
1080
|
-
const
|
|
1194
|
+
const m = /* @__PURE__ */ new WeakMap();
|
|
1081
1195
|
Object.defineProperties(HTMLElement.prototype, {
|
|
1082
1196
|
oncommand: {
|
|
1083
1197
|
enumerable: !0,
|
|
1084
1198
|
configurable: !0,
|
|
1085
1199
|
get() {
|
|
1086
|
-
return
|
|
1200
|
+
return g.takeRecords(), m.get(this) || null;
|
|
1087
1201
|
},
|
|
1088
|
-
set(
|
|
1089
|
-
const
|
|
1090
|
-
|
|
1202
|
+
set(r) {
|
|
1203
|
+
const i = m.get(this) || null;
|
|
1204
|
+
i && this.removeEventListener("command", i), m.set(
|
|
1091
1205
|
this,
|
|
1092
|
-
typeof
|
|
1093
|
-
), typeof
|
|
1206
|
+
typeof r == "object" || typeof r == "function" ? r : null
|
|
1207
|
+
), typeof r == "function" && this.addEventListener("command", r);
|
|
1094
1208
|
}
|
|
1095
1209
|
}
|
|
1096
1210
|
});
|
|
1097
|
-
function
|
|
1098
|
-
for (const
|
|
1099
|
-
|
|
1211
|
+
function p(r) {
|
|
1212
|
+
for (const i of r)
|
|
1213
|
+
i.oncommand = new Function("event", i.getAttribute("oncommand"));
|
|
1100
1214
|
}
|
|
1101
|
-
const
|
|
1102
|
-
for (const
|
|
1103
|
-
const { target:
|
|
1104
|
-
|
|
1215
|
+
const g = new MutationObserver((r) => {
|
|
1216
|
+
for (const i of r) {
|
|
1217
|
+
const { target: o } = i;
|
|
1218
|
+
i.type === "childList" ? p(o.querySelectorAll("[oncommand]")) : p([o]);
|
|
1105
1219
|
}
|
|
1106
1220
|
});
|
|
1107
|
-
|
|
1221
|
+
g.observe(document, {
|
|
1108
1222
|
subtree: !0,
|
|
1109
1223
|
childList: !0,
|
|
1110
1224
|
attributeFilter: ["oncommand"]
|
|
1111
|
-
}),
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1225
|
+
}), p(document.querySelectorAll("[oncommand]"));
|
|
1226
|
+
const I = /* @__PURE__ */ new WeakSet();
|
|
1227
|
+
function k(r) {
|
|
1228
|
+
if (I.has(r) || (I.add(r), r.defaultPrevented) || r.type !== "click") return;
|
|
1229
|
+
const i = r.target.closest(
|
|
1115
1230
|
"button[invoketarget], button[invokeaction], input[invoketarget], input[invokeaction]"
|
|
1116
1231
|
);
|
|
1117
|
-
if (
|
|
1232
|
+
if (i && (console.warn(
|
|
1118
1233
|
"Elements with `invoketarget` or `invokeaction` are deprecated and should be renamed to use `commandfor` and `command` respectively"
|
|
1119
|
-
),
|
|
1234
|
+
), i.matches("input")))
|
|
1120
1235
|
throw new Error("Input elements no longer support `commandfor`");
|
|
1121
|
-
const
|
|
1122
|
-
if (!
|
|
1123
|
-
if (
|
|
1124
|
-
throw
|
|
1236
|
+
const o = r.target.closest("button[commandfor], button[command]");
|
|
1237
|
+
if (!o) return;
|
|
1238
|
+
if (o.form && o.getAttribute("type") !== "button")
|
|
1239
|
+
throw r.preventDefault(), new Error(
|
|
1125
1240
|
"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
1241
|
);
|
|
1127
|
-
if (
|
|
1128
|
-
const
|
|
1242
|
+
if (o.hasAttribute("command") !== o.hasAttribute("commandfor")) {
|
|
1243
|
+
const C = o.hasAttribute("command") ? "command" : "commandfor", T = o.hasAttribute("command") ? "commandfor" : "command";
|
|
1129
1244
|
throw new Error(
|
|
1130
|
-
`Element with ${
|
|
1245
|
+
`Element with ${C} attribute must also have a ${T} attribute to function.`
|
|
1131
1246
|
);
|
|
1132
1247
|
}
|
|
1133
|
-
if (
|
|
1248
|
+
if (o.command !== "show-popover" && o.command !== "hide-popover" && o.command !== "toggle-popover" && o.command !== "show-modal" && o.command !== "request-close" && o.command !== "close" && !o.command.startsWith("--")) {
|
|
1134
1249
|
console.warn(
|
|
1135
|
-
`"${
|
|
1250
|
+
`"${o.command}" is not a valid command value. Custom commands must begin with --`
|
|
1136
1251
|
);
|
|
1137
1252
|
return;
|
|
1138
1253
|
}
|
|
1139
|
-
const
|
|
1140
|
-
if (!
|
|
1141
|
-
const
|
|
1142
|
-
command:
|
|
1143
|
-
source:
|
|
1254
|
+
const d = o.commandForElement;
|
|
1255
|
+
if (!d) return;
|
|
1256
|
+
const E = new c("command", {
|
|
1257
|
+
command: o.command,
|
|
1258
|
+
source: o,
|
|
1144
1259
|
cancelable: !0
|
|
1145
1260
|
});
|
|
1146
|
-
if (
|
|
1261
|
+
if (d.dispatchEvent(E), E.defaultPrevented)
|
|
1147
1262
|
return;
|
|
1148
|
-
const
|
|
1149
|
-
if (
|
|
1150
|
-
const
|
|
1151
|
-
|
|
1152
|
-
} else if (
|
|
1153
|
-
const
|
|
1154
|
-
|
|
1263
|
+
const x = E.command.toLowerCase();
|
|
1264
|
+
if (d.popover) {
|
|
1265
|
+
const C = !d.matches(":popover-open");
|
|
1266
|
+
C && (x === "toggle-popover" || x === "show-popover") ? d.showPopover({ source: o }) : !C && x === "hide-popover" && d.hidePopover();
|
|
1267
|
+
} else if (d.localName === "dialog") {
|
|
1268
|
+
const C = !d.hasAttribute("open");
|
|
1269
|
+
C && x == "show-modal" ? d.showModal() : !C && x == "close" ? d.close(o.value ? o.value : void 0) : !C && x == "request-close" && (HTMLDialogElement.prototype.requestClose || (HTMLDialogElement.prototype.requestClose = function() {
|
|
1270
|
+
const T = new Event("cancel", { cancelable: !0 });
|
|
1271
|
+
this.dispatchEvent(T), T.defaultPrevented || this.close();
|
|
1272
|
+
}), d.requestClose(o.value ? o.value : void 0));
|
|
1155
1273
|
}
|
|
1156
1274
|
}
|
|
1157
|
-
function
|
|
1158
|
-
|
|
1275
|
+
function D(r) {
|
|
1276
|
+
r.addEventListener("click", k, !0);
|
|
1159
1277
|
}
|
|
1160
|
-
function
|
|
1161
|
-
const
|
|
1162
|
-
|
|
1163
|
-
const
|
|
1164
|
-
return
|
|
1278
|
+
function B(r, i) {
|
|
1279
|
+
const o = r.prototype.attachShadow;
|
|
1280
|
+
r.prototype.attachShadow = function(E) {
|
|
1281
|
+
const x = o.call(this, E);
|
|
1282
|
+
return i(x), x;
|
|
1165
1283
|
};
|
|
1166
|
-
const
|
|
1167
|
-
|
|
1168
|
-
const
|
|
1169
|
-
return
|
|
1284
|
+
const d = r.prototype.attachInternals;
|
|
1285
|
+
r.prototype.attachInternals = function() {
|
|
1286
|
+
const E = d.call(this);
|
|
1287
|
+
return E.shadowRoot && i(E.shadowRoot), E;
|
|
1170
1288
|
};
|
|
1171
1289
|
}
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
}),
|
|
1290
|
+
b(HTMLButtonElement), B(HTMLElement, (r) => {
|
|
1291
|
+
D(r), g.observe(r, { attributeFilter: ["oncommand"] }), p(r.querySelectorAll("[oncommand]"));
|
|
1292
|
+
}), D(document), Object.assign(globalThis, { CommandEvent: c, InvokeEvent: l });
|
|
1175
1293
|
}
|
|
1176
|
-
|
|
1294
|
+
N() || U();
|