wulf.js 2.1.0 → 2.2.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/README.md +217 -11
- package/changelog.md +60 -0
- package/dist/anchor.esm.js +9 -0
- package/dist/anchor.esm.js.map +7 -0
- package/dist/anchor.global.js +695 -0
- package/dist/anchor.global.js.map +7 -0
- package/dist/anchor.global.min.js +6 -0
- package/dist/anchor.global.min.js.map +7 -0
- package/dist/autosize.css +1 -0
- package/dist/autosize.css.map +7 -0
- package/dist/autosize.esm.js +10 -0
- package/dist/autosize.esm.js.map +7 -0
- package/dist/autosize.global.js +657 -0
- package/dist/autosize.global.js.map +7 -0
- package/dist/autosize.global.min.js +6 -0
- package/dist/autosize.global.min.js.map +7 -0
- package/dist/autosize.layered.css +1 -0
- package/dist/autosize.layered.css.map +7 -0
- package/dist/chunks/chunk-22AIMRD5.js +119 -0
- package/dist/chunks/chunk-22AIMRD5.js.map +7 -0
- package/dist/chunks/chunk-5N2IRGDM.js +766 -0
- package/dist/chunks/chunk-5N2IRGDM.js.map +7 -0
- package/dist/chunks/chunk-72FVCNNZ.js +863 -0
- package/dist/chunks/chunk-72FVCNNZ.js.map +7 -0
- package/dist/chunks/chunk-AXZYYW7H.js +865 -0
- package/dist/chunks/chunk-AXZYYW7H.js.map +7 -0
- package/dist/chunks/chunk-CM3SBIVQ.js +1116 -0
- package/dist/chunks/chunk-CM3SBIVQ.js.map +7 -0
- package/dist/chunks/chunk-H4GRLGQ3.js +578 -0
- package/dist/chunks/chunk-H4GRLGQ3.js.map +7 -0
- package/dist/chunks/chunk-ITRU2RFV.js +1195 -0
- package/dist/chunks/chunk-ITRU2RFV.js.map +7 -0
- package/dist/chunks/chunk-NLUQZEL4.js +1029 -0
- package/dist/chunks/chunk-NLUQZEL4.js.map +7 -0
- package/dist/chunks/chunk-QV46A7FV.js +197 -0
- package/dist/chunks/chunk-QV46A7FV.js.map +7 -0
- package/dist/chunks/chunk-SXLUXN6W.js +612 -0
- package/dist/chunks/chunk-SXLUXN6W.js.map +7 -0
- package/dist/chunks/chunk-T2H4EJCW.js +621 -0
- package/dist/chunks/chunk-T2H4EJCW.js.map +7 -0
- package/dist/chunks/chunk-TILLYEF2.js +6044 -0
- package/dist/chunks/chunk-TILLYEF2.js.map +7 -0
- package/dist/chunks/chunk-VJO22BAT.js +72 -0
- package/dist/chunks/chunk-VJO22BAT.js.map +7 -0
- package/dist/chunks/chunk-ZGUU6DMM.js +77 -0
- package/dist/chunks/chunk-ZGUU6DMM.js.map +7 -0
- package/dist/focus-trap.esm.js +6 -536
- package/dist/focus-trap.esm.js.map +3 -3
- package/dist/focus-trap.global.js +260 -87
- package/dist/focus-trap.global.js.map +3 -3
- package/dist/focus-trap.global.min.js +4 -4
- package/dist/focus-trap.global.min.js.map +4 -4
- package/dist/index.esm.js +79 -10069
- package/dist/index.esm.js.map +4 -4
- package/dist/index.global.js +4192 -355
- package/dist/index.global.js.map +4 -4
- package/dist/index.global.min.js +6 -3
- package/dist/index.global.min.js.map +4 -4
- package/dist/mask.esm.js +16 -6094
- package/dist/mask.esm.js.map +4 -4
- package/dist/mask.global.js +44 -55
- package/dist/mask.global.js.map +3 -3
- package/dist/mask.global.min.js +3 -3
- package/dist/mask.global.min.js.map +4 -4
- package/dist/masonry.esm.js +15 -1067
- package/dist/masonry.esm.js.map +4 -4
- package/dist/masonry.global.js +229 -148
- package/dist/masonry.global.js.map +3 -3
- package/dist/masonry.global.min.js +4 -4
- package/dist/masonry.global.min.js.map +4 -4
- package/dist/scroll.css +1 -1
- package/dist/scroll.css.map +2 -2
- package/dist/scroll.esm.js +14 -1175
- package/dist/scroll.esm.js.map +3 -3
- package/dist/scroll.global.js +171 -88
- package/dist/scroll.global.js.map +3 -3
- package/dist/scroll.global.min.js +3 -3
- package/dist/scroll.global.min.js.map +4 -4
- package/dist/scroll.layered.css +1 -1
- package/dist/scroll.layered.css.map +2 -2
- package/dist/shortcut.esm.js +6 -741
- package/dist/shortcut.esm.js.map +4 -4
- package/dist/shortcut.global.js +225 -58
- package/dist/shortcut.global.js.map +3 -3
- package/dist/shortcut.global.min.js +8 -2
- package/dist/shortcut.global.min.js.map +4 -4
- package/dist/size-report.json +319 -0
- package/dist/sortable.css +1 -0
- package/dist/sortable.css.map +7 -0
- package/dist/sortable.esm.js +22 -0
- package/dist/sortable.esm.js.map +7 -0
- package/dist/sortable.global.js +1477 -0
- package/dist/sortable.global.js.map +7 -0
- package/dist/sortable.global.min.js +6 -0
- package/dist/sortable.global.min.js.map +7 -0
- package/dist/sortable.layered.css +1 -0
- package/dist/sortable.layered.css.map +7 -0
- package/dist/sri-manifest.json +64 -0
- package/dist/toast.css +1 -1
- package/dist/toast.css.map +2 -2
- package/dist/toast.esm.js +19 -1129
- package/dist/toast.esm.js.map +3 -3
- package/dist/toast.global.js +386 -104
- package/dist/toast.global.js.map +3 -3
- package/dist/toast.global.min.js +4 -4
- package/dist/toast.global.min.js.map +4 -4
- package/dist/toast.layered.css +1 -1
- package/dist/toast.layered.css.map +2 -2
- package/dist/types/anchor/Anchor.d.ts +41 -0
- package/dist/types/anchor/index.d.ts +3 -0
- package/dist/types/anchor/types.d.ts +115 -0
- package/dist/types/autosize/Autosize.d.ts +71 -0
- package/dist/types/autosize/index.d.ts +3 -0
- package/dist/types/autosize/types.d.ts +66 -0
- package/dist/types/common/AuditableComponent.d.ts +1 -1
- package/dist/types/common/dom.d.ts +5 -0
- package/dist/types/common/registry.d.ts +40 -0
- package/dist/types/focus-trap/FocusTrap.d.ts +8 -3
- package/dist/types/index.d.ts +13 -1
- package/dist/types/mask/paste.d.ts +2 -5
- package/dist/types/masonry/Masonry.d.ts +2 -0
- package/dist/types/scroll/ScrollBlock.d.ts +2 -0
- package/dist/types/scroll/types.d.ts +6 -0
- package/dist/types/shortcut/ShortcutManager.d.ts +16 -3
- package/dist/types/shortcut/types.d.ts +5 -0
- package/dist/types/sortable/Sortable.d.ts +75 -0
- package/dist/types/sortable/i18n/en.d.ts +2 -0
- package/dist/types/sortable/i18n/fr.d.ts +2 -0
- package/dist/types/sortable/i18n/index.d.ts +9 -0
- package/dist/types/sortable/i18n/types.d.ts +15 -0
- package/dist/types/sortable/index.d.ts +4 -0
- package/dist/types/sortable/types.d.ts +112 -0
- package/dist/types/toast/Toast.d.ts +6 -1
- package/dist/types/toast/ToastInstance.d.ts +7 -0
- package/dist/types/toast/ToastManager.d.ts +4 -2
- package/dist/types/toast/types.d.ts +27 -1
- package/dist/types/undo/UndoManager.d.ts +112 -0
- package/dist/types/undo/i18n/en.d.ts +2 -0
- package/dist/types/undo/i18n/fr.d.ts +2 -0
- package/dist/types/undo/i18n/index.d.ts +9 -0
- package/dist/types/undo/i18n/types.d.ts +6 -0
- package/dist/types/undo/index.d.ts +5 -0
- package/dist/types/undo/types.d.ts +106 -0
- package/dist/undo.esm.js +23 -0
- package/dist/undo.esm.js.map +7 -0
- package/dist/undo.global.js +1029 -0
- package/dist/undo.global.js.map +7 -0
- package/dist/undo.global.min.js +6 -0
- package/dist/undo.global.min.js.map +7 -0
- package/package.json +54 -5
package/dist/toast.global.js
CHANGED
|
@@ -27,58 +27,12 @@ var __WulfIIFE = (() => {
|
|
|
27
27
|
ToastManager: () => ToastManager,
|
|
28
28
|
createI18nManager: () => createI18nManager,
|
|
29
29
|
default: () => index_default,
|
|
30
|
+
isSafeCssValue: () => isSafeCssValue,
|
|
30
31
|
toastEn: () => toastEn,
|
|
31
32
|
toastFr: () => toastFr,
|
|
32
33
|
toastI18n: () => toastI18n
|
|
33
34
|
});
|
|
34
35
|
|
|
35
|
-
// src/common/dom.ts
|
|
36
|
-
function getSafeWulfNamespace() {
|
|
37
|
-
if (typeof window === "undefined") return null;
|
|
38
|
-
const win = window;
|
|
39
|
-
const existing = win.Wulf;
|
|
40
|
-
if (!existing || typeof existing !== "object" || typeof Node !== "undefined" && existing instanceof Node || typeof HTMLCollection !== "undefined" && existing instanceof HTMLCollection) {
|
|
41
|
-
const fresh = {};
|
|
42
|
-
win.Wulf = fresh;
|
|
43
|
-
return fresh;
|
|
44
|
-
}
|
|
45
|
-
return existing;
|
|
46
|
-
}
|
|
47
|
-
function prefersReducedMotion() {
|
|
48
|
-
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
49
|
-
}
|
|
50
|
-
function waitForAnimations(element, fallbackMs, signal) {
|
|
51
|
-
const safeFallback = Number.isFinite(fallbackMs) ? Math.min(fallbackMs, 6e4) : 300;
|
|
52
|
-
if (signal?.aborted || safeFallback <= 0 || prefersReducedMotion()) {
|
|
53
|
-
return Promise.resolve();
|
|
54
|
-
}
|
|
55
|
-
const animations = typeof element.getAnimations === "function" ? element.getAnimations().filter((a) => {
|
|
56
|
-
if (a.playState !== "running") return false;
|
|
57
|
-
const timing = a.effect?.getComputedTiming?.();
|
|
58
|
-
return timing ? Number.isFinite(timing.endTime) : true;
|
|
59
|
-
}) : [];
|
|
60
|
-
if (animations.length === 0) {
|
|
61
|
-
return Promise.resolve();
|
|
62
|
-
}
|
|
63
|
-
return new Promise((resolve) => {
|
|
64
|
-
let settled = false;
|
|
65
|
-
let timerId = null;
|
|
66
|
-
const finish = () => {
|
|
67
|
-
if (settled) return;
|
|
68
|
-
settled = true;
|
|
69
|
-
if (timerId !== null) {
|
|
70
|
-
clearTimeout(timerId);
|
|
71
|
-
timerId = null;
|
|
72
|
-
}
|
|
73
|
-
signal?.removeEventListener("abort", finish);
|
|
74
|
-
resolve();
|
|
75
|
-
};
|
|
76
|
-
signal?.addEventListener("abort", finish, { once: true });
|
|
77
|
-
timerId = setTimeout(finish, safeFallback);
|
|
78
|
-
Promise.allSettled(animations.map((a) => a.finished)).then(finish);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
36
|
// src/common/i18n.ts
|
|
83
37
|
var FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
84
38
|
function isSafeKey(key) {
|
|
@@ -346,20 +300,74 @@ var __WulfIIFE = (() => {
|
|
|
346
300
|
en: toastEn
|
|
347
301
|
});
|
|
348
302
|
|
|
303
|
+
// src/common/dom.ts
|
|
304
|
+
function stripBidiAndInvisibles(raw, maxLength = 4096) {
|
|
305
|
+
const safeLimit = Math.max(0, maxLength);
|
|
306
|
+
return String(raw ?? "").slice(0, safeLimit).replace(/[\u061C\u200B-\u200F\u202A-\u202E\u2066-\u2069\uFEFF]/g, "");
|
|
307
|
+
}
|
|
308
|
+
function getDeepActiveElement(root) {
|
|
309
|
+
if (typeof document === "undefined") return null;
|
|
310
|
+
let active = (root ?? document).activeElement;
|
|
311
|
+
while (active && active.shadowRoot && active.shadowRoot.activeElement) {
|
|
312
|
+
active = active.shadowRoot.activeElement;
|
|
313
|
+
}
|
|
314
|
+
return active && typeof active.focus === "function" ? active : null;
|
|
315
|
+
}
|
|
316
|
+
function isImeComposing(event) {
|
|
317
|
+
return Boolean(
|
|
318
|
+
event.isComposing || event.key === "Process" || event.key === "Enter" && event.keyCode === 229
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
function prefersReducedMotion() {
|
|
322
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
323
|
+
}
|
|
324
|
+
function waitForAnimations(element, fallbackMs, signal) {
|
|
325
|
+
const safeFallback = Number.isFinite(fallbackMs) ? Math.min(fallbackMs, 6e4) : 300;
|
|
326
|
+
if (signal?.aborted || safeFallback <= 0 || prefersReducedMotion()) {
|
|
327
|
+
return Promise.resolve();
|
|
328
|
+
}
|
|
329
|
+
const animations = typeof element.getAnimations === "function" ? element.getAnimations().filter((a) => {
|
|
330
|
+
if (a.playState !== "running") return false;
|
|
331
|
+
const timing = a.effect?.getComputedTiming?.();
|
|
332
|
+
return timing ? Number.isFinite(timing.endTime) : true;
|
|
333
|
+
}) : [];
|
|
334
|
+
if (animations.length === 0) {
|
|
335
|
+
return Promise.resolve();
|
|
336
|
+
}
|
|
337
|
+
return new Promise((resolve) => {
|
|
338
|
+
let settled = false;
|
|
339
|
+
let timerId = null;
|
|
340
|
+
const finish = () => {
|
|
341
|
+
if (settled) return;
|
|
342
|
+
settled = true;
|
|
343
|
+
if (timerId !== null) {
|
|
344
|
+
clearTimeout(timerId);
|
|
345
|
+
timerId = null;
|
|
346
|
+
}
|
|
347
|
+
signal?.removeEventListener("abort", finish);
|
|
348
|
+
resolve();
|
|
349
|
+
};
|
|
350
|
+
signal?.addEventListener("abort", finish, { once: true });
|
|
351
|
+
timerId = setTimeout(finish, safeFallback);
|
|
352
|
+
Promise.allSettled(animations.map((a) => a.finished)).then(finish);
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
|
|
349
356
|
// src/toast/ToastInstance.ts
|
|
350
357
|
var nextToastId = 1;
|
|
351
358
|
var DEFAULT_TOAST_DURATION = 5e3;
|
|
359
|
+
var SAFE_COLOR_FALLBACK_RE = /^(?:#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})|(?:rgb|rgba|hsl|hsla|oklch|oklab|lch|lab)\(\s*(?:[+-]?(?:\d+\.?\d*|\.\d+)(?:%|deg|rad|grad|turn)?|none)(?:\s*[,/\s]\s*(?:[+-]?(?:\d+\.?\d*|\.\d+)(?:%|deg|rad|grad|turn)?|none)){2,3}\s*\)|[a-z]{3,20})$/i;
|
|
352
360
|
function isSafeCssValue(val) {
|
|
353
361
|
if (!val || typeof val !== "string" || val.length > 128) return false;
|
|
354
362
|
const trimmed = val.trim();
|
|
355
363
|
if (!trimmed) return false;
|
|
356
|
-
if (/[\u0000-\u001F\u007F;{}<>\\]|(?:url|image-set|-webkit-image-set|image|src|expression|attr|env)\s*\(/i.test(trimmed)) {
|
|
364
|
+
if (/[\u0000-\u001F\u007F;{}<>\\]|(?:url|image-set|-webkit-image-set|image|src|expression|attr|env|var)\s*\(/i.test(trimmed)) {
|
|
357
365
|
return false;
|
|
358
366
|
}
|
|
359
367
|
if (typeof CSS !== "undefined" && typeof CSS.supports === "function") {
|
|
360
368
|
return CSS.supports("color", trimmed) || CSS.supports("background-color", trimmed);
|
|
361
369
|
}
|
|
362
|
-
return
|
|
370
|
+
return SAFE_COLOR_FALLBACK_RE.test(trimmed);
|
|
363
371
|
}
|
|
364
372
|
function sanitizeIconClasses(icon) {
|
|
365
373
|
return icon.slice(0, 128).trim().split(/\s+/).filter((token) => /^[a-zA-Z0-9_-]+$/.test(token) && !token.startsWith("wulf-toast")).slice(0, 8).join(" ");
|
|
@@ -379,16 +387,20 @@ var __WulfIIFE = (() => {
|
|
|
379
387
|
isPausedByFocus = false;
|
|
380
388
|
isPausedByVisibility = false;
|
|
381
389
|
isPendingFocusDismiss = false;
|
|
390
|
+
actionPending = false;
|
|
382
391
|
previousActiveElement = null;
|
|
383
392
|
eventsAbortController = new AbortController();
|
|
384
393
|
disposeAbortController = new AbortController();
|
|
385
394
|
onDismissCallback;
|
|
386
395
|
constructor(options, onDismiss) {
|
|
387
396
|
super();
|
|
397
|
+
if (typeof document === "undefined") {
|
|
398
|
+
throw new Error("[Wulf.Toast] Impossible d'instancier une notification Toast sans environnement DOM (document).");
|
|
399
|
+
}
|
|
388
400
|
this.id = `wulf-toast-${nextToastId++}`;
|
|
389
401
|
this.options = Object.freeze({ ...options });
|
|
390
402
|
this.onDismissCallback = onDismiss;
|
|
391
|
-
this.previousActiveElement =
|
|
403
|
+
this.previousActiveElement = getDeepActiveElement();
|
|
392
404
|
const duration = options.duration === void 0 ? DEFAULT_TOAST_DURATION : options.duration;
|
|
393
405
|
if (typeof duration === "number" && Number.isFinite(duration) && duration > 0) {
|
|
394
406
|
this.remainingTime = Math.min(duration, 2147483647);
|
|
@@ -433,6 +445,14 @@ var __WulfIIFE = (() => {
|
|
|
433
445
|
"Notification persistante impossible \xE0 fermer au clavier : activez closable: true lorsque duration est d\xE9sactiv\xE9 (WCAG 2.1.1)."
|
|
434
446
|
);
|
|
435
447
|
}
|
|
448
|
+
if (this.options.action) {
|
|
449
|
+
const safeActionLabel = stripBidiAndInvisibles(String(this.options.action.label ?? ""), 128).trim();
|
|
450
|
+
if (!safeActionLabel) {
|
|
451
|
+
warnings.push(
|
|
452
|
+
"Bouton d'action invalide : action.label doit contenir un texte non vide (WCAG 4.1.2)."
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
436
456
|
return warnings;
|
|
437
457
|
}
|
|
438
458
|
getAuditPrefix() {
|
|
@@ -475,7 +495,30 @@ var __WulfIIFE = (() => {
|
|
|
475
495
|
}
|
|
476
496
|
}
|
|
477
497
|
const content = document.createElement("div");
|
|
478
|
-
|
|
498
|
+
const isInteractiveContent = Boolean(this.options.onClick || this.options.closeOnClick);
|
|
499
|
+
content.className = isInteractiveContent ? "wulf-toast-content wulf-toast-content--interactive" : "wulf-toast-content";
|
|
500
|
+
if (isInteractiveContent) {
|
|
501
|
+
content.setAttribute("role", "button");
|
|
502
|
+
content.setAttribute("tabindex", "0");
|
|
503
|
+
content.addEventListener("keydown", (e) => {
|
|
504
|
+
if (isImeComposing(e)) return;
|
|
505
|
+
if (e.key === "Enter") {
|
|
506
|
+
e.preventDefault();
|
|
507
|
+
e.stopPropagation();
|
|
508
|
+
content.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true }));
|
|
509
|
+
} else if (e.key === " ") {
|
|
510
|
+
e.preventDefault();
|
|
511
|
+
e.stopPropagation();
|
|
512
|
+
}
|
|
513
|
+
}, { signal: this.eventsAbortController.signal });
|
|
514
|
+
content.addEventListener("keyup", (e) => {
|
|
515
|
+
if (e.key === " ") {
|
|
516
|
+
e.preventDefault();
|
|
517
|
+
e.stopPropagation();
|
|
518
|
+
content.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true }));
|
|
519
|
+
}
|
|
520
|
+
}, { signal: this.eventsAbortController.signal });
|
|
521
|
+
}
|
|
479
522
|
if (this.options.title && this.options.title.trim() !== "") {
|
|
480
523
|
const titleEl = document.createElement("div");
|
|
481
524
|
titleEl.className = "wulf-toast-title";
|
|
@@ -489,6 +532,63 @@ var __WulfIIFE = (() => {
|
|
|
489
532
|
content.appendChild(messageEl);
|
|
490
533
|
}
|
|
491
534
|
el.appendChild(content);
|
|
535
|
+
const actionDef = this.options.action;
|
|
536
|
+
if (actionDef && typeof actionDef.onClick === "function") {
|
|
537
|
+
const safeLabel = stripBidiAndInvisibles(String(actionDef.label ?? ""), 128).trim();
|
|
538
|
+
if (safeLabel) {
|
|
539
|
+
const actionBtn = document.createElement("button");
|
|
540
|
+
actionBtn.type = "button";
|
|
541
|
+
actionBtn.className = "wulf-toast-action";
|
|
542
|
+
actionBtn.textContent = safeLabel;
|
|
543
|
+
if (typeof actionDef.ariaLabel === "string") {
|
|
544
|
+
const safeAriaLabel = stripBidiAndInvisibles(actionDef.ariaLabel, 256).trim();
|
|
545
|
+
if (safeAriaLabel) {
|
|
546
|
+
actionBtn.setAttribute("aria-label", safeAriaLabel);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
const resetActionState = () => {
|
|
550
|
+
this.actionPending = false;
|
|
551
|
+
if (!this._isClosed) {
|
|
552
|
+
actionBtn.disabled = false;
|
|
553
|
+
actionBtn.removeAttribute("aria-busy");
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
actionBtn.addEventListener("click", (e) => {
|
|
557
|
+
e.stopPropagation();
|
|
558
|
+
if (this._isClosed || this.actionPending) return;
|
|
559
|
+
this.actionPending = true;
|
|
560
|
+
actionBtn.disabled = true;
|
|
561
|
+
actionBtn.setAttribute("aria-busy", "true");
|
|
562
|
+
const shouldClose = actionDef.closeOnClick !== false;
|
|
563
|
+
try {
|
|
564
|
+
const result = actionDef.onClick(this, e);
|
|
565
|
+
if (result && typeof result.then === "function") {
|
|
566
|
+
result.then(
|
|
567
|
+
() => {
|
|
568
|
+
if (shouldClose && !this._isClosed) {
|
|
569
|
+
this.close("action");
|
|
570
|
+
} else {
|
|
571
|
+
resetActionState();
|
|
572
|
+
}
|
|
573
|
+
},
|
|
574
|
+
(err) => {
|
|
575
|
+
console.error("[Wulf.Toast] Erreur dans action.onClick:", err);
|
|
576
|
+
resetActionState();
|
|
577
|
+
}
|
|
578
|
+
);
|
|
579
|
+
} else if (shouldClose && !this._isClosed) {
|
|
580
|
+
this.close("action");
|
|
581
|
+
} else {
|
|
582
|
+
resetActionState();
|
|
583
|
+
}
|
|
584
|
+
} catch (err) {
|
|
585
|
+
console.error("[Wulf.Toast] Erreur dans action.onClick:", err);
|
|
586
|
+
resetActionState();
|
|
587
|
+
}
|
|
588
|
+
}, { signal: this.eventsAbortController.signal });
|
|
589
|
+
el.appendChild(actionBtn);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
492
592
|
const closable = this.options.closable ?? true;
|
|
493
593
|
if (closable) {
|
|
494
594
|
const closeBtn = document.createElement("button");
|
|
@@ -519,7 +619,7 @@ var __WulfIIFE = (() => {
|
|
|
519
619
|
* Injection de texte sécurisée gérant nativement les retours à la ligne (\n et \r\n).
|
|
520
620
|
*/
|
|
521
621
|
appendTextWithLineBreaks(container, text) {
|
|
522
|
-
const safeText = String(text ?? "")
|
|
622
|
+
const safeText = stripBidiAndInvisibles(String(text ?? ""), 4096);
|
|
523
623
|
const lines = safeText.split(/\r\n|\r|\n/).slice(0, 100);
|
|
524
624
|
lines.forEach((line, index) => {
|
|
525
625
|
if (index > 0) {
|
|
@@ -535,7 +635,11 @@ var __WulfIIFE = (() => {
|
|
|
535
635
|
const { signal } = this.eventsAbortController;
|
|
536
636
|
this.element.addEventListener("click", (e) => {
|
|
537
637
|
if (this.options.onClick) {
|
|
538
|
-
|
|
638
|
+
try {
|
|
639
|
+
this.options.onClick(this, e);
|
|
640
|
+
} catch (err) {
|
|
641
|
+
console.error("[Wulf.Toast] Erreur dans le callback onClick:", err);
|
|
642
|
+
}
|
|
539
643
|
}
|
|
540
644
|
if (this.options.closeOnClick) {
|
|
541
645
|
this.close("toast-click");
|
|
@@ -558,6 +662,7 @@ var __WulfIIFE = (() => {
|
|
|
558
662
|
}, { signal });
|
|
559
663
|
this.element.addEventListener("keydown", (e) => {
|
|
560
664
|
if (e.key === "Escape" && (this.options.closable ?? true)) {
|
|
665
|
+
if (isImeComposing(e)) return;
|
|
561
666
|
e.stopPropagation();
|
|
562
667
|
this.close("close-button");
|
|
563
668
|
}
|
|
@@ -586,13 +691,15 @@ var __WulfIIFE = (() => {
|
|
|
586
691
|
return;
|
|
587
692
|
}
|
|
588
693
|
if (this.timerId !== null) {
|
|
589
|
-
window.clearTimeout(this.timerId);
|
|
694
|
+
if (typeof window !== "undefined") window.clearTimeout(this.timerId);
|
|
590
695
|
this.timerId = null;
|
|
591
696
|
}
|
|
592
|
-
|
|
697
|
+
if (typeof window === "undefined") return;
|
|
698
|
+
this.timerStartTime = typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
593
699
|
this.timerId = window.setTimeout(() => {
|
|
594
700
|
this.timerId = null;
|
|
595
|
-
|
|
701
|
+
const active = getDeepActiveElement();
|
|
702
|
+
if (active && this.element.contains(active)) {
|
|
596
703
|
this.isPendingFocusDismiss = true;
|
|
597
704
|
return;
|
|
598
705
|
}
|
|
@@ -614,9 +721,10 @@ var __WulfIIFE = (() => {
|
|
|
614
721
|
}
|
|
615
722
|
if (wasPaused) return;
|
|
616
723
|
if (this.timerId !== null) {
|
|
617
|
-
window.clearTimeout(this.timerId);
|
|
724
|
+
if (typeof window !== "undefined") window.clearTimeout(this.timerId);
|
|
618
725
|
this.timerId = null;
|
|
619
|
-
const
|
|
726
|
+
const now = typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
727
|
+
const elapsed = now - this.timerStartTime;
|
|
620
728
|
this.remainingTime = Math.max(0, this.remainingTime - elapsed);
|
|
621
729
|
}
|
|
622
730
|
this.element.classList.add("is-paused");
|
|
@@ -632,7 +740,8 @@ var __WulfIIFE = (() => {
|
|
|
632
740
|
this.isPausedByFocus = false;
|
|
633
741
|
} else if (source === "hover") {
|
|
634
742
|
this.isPausedByHover = false;
|
|
635
|
-
|
|
743
|
+
const active = getDeepActiveElement();
|
|
744
|
+
if (active && this.element.contains(active)) {
|
|
636
745
|
this.isPausedByFocus = true;
|
|
637
746
|
}
|
|
638
747
|
} else {
|
|
@@ -658,7 +767,11 @@ var __WulfIIFE = (() => {
|
|
|
658
767
|
this.element.parentNode.removeChild(this.element);
|
|
659
768
|
}
|
|
660
769
|
if (this.options.onClose) {
|
|
661
|
-
|
|
770
|
+
try {
|
|
771
|
+
this.options.onClose(this, reason);
|
|
772
|
+
} catch (err) {
|
|
773
|
+
console.error("[Wulf.Toast] Erreur dans le callback onClose:", err);
|
|
774
|
+
}
|
|
662
775
|
}
|
|
663
776
|
}
|
|
664
777
|
/**
|
|
@@ -667,7 +780,7 @@ var __WulfIIFE = (() => {
|
|
|
667
780
|
destroyImmediate(reason = "replace") {
|
|
668
781
|
this._isClosed = true;
|
|
669
782
|
if (this.timerId !== null) {
|
|
670
|
-
window.clearTimeout(this.timerId);
|
|
783
|
+
if (typeof window !== "undefined") window.clearTimeout(this.timerId);
|
|
671
784
|
this.timerId = null;
|
|
672
785
|
}
|
|
673
786
|
this.disposeAbortController.abort();
|
|
@@ -683,7 +796,7 @@ var __WulfIIFE = (() => {
|
|
|
683
796
|
}
|
|
684
797
|
this._isClosed = true;
|
|
685
798
|
if (this.timerId !== null) {
|
|
686
|
-
window.clearTimeout(this.timerId);
|
|
799
|
+
if (typeof window !== "undefined") window.clearTimeout(this.timerId);
|
|
687
800
|
this.timerId = null;
|
|
688
801
|
}
|
|
689
802
|
this.eventsAbortController.abort();
|
|
@@ -702,6 +815,49 @@ var __WulfIIFE = (() => {
|
|
|
702
815
|
}
|
|
703
816
|
};
|
|
704
817
|
|
|
818
|
+
// src/common/registry.ts
|
|
819
|
+
var WULF_TRAP_STACK_SYMBOL = Symbol.for("wulf.focusTrap.stack.v1");
|
|
820
|
+
var WULF_TOAST_MANAGER_SYMBOL = Symbol.for("wulf.toast.manager.v1");
|
|
821
|
+
var WULF_TOAST_CONTAINERS_SYMBOL = Symbol.for("wulf.toast.containers.v1");
|
|
822
|
+
var WULF_TOAST_ANNOUNCERS_SYMBOL = Symbol.for("wulf.toast.announcers.v1");
|
|
823
|
+
function getGlobalRegistry() {
|
|
824
|
+
if (typeof globalThis === "undefined") return null;
|
|
825
|
+
return globalThis;
|
|
826
|
+
}
|
|
827
|
+
function getSharedToastManager() {
|
|
828
|
+
const reg = getGlobalRegistry();
|
|
829
|
+
if (!reg) return null;
|
|
830
|
+
return reg[WULF_TOAST_MANAGER_SYMBOL] ?? null;
|
|
831
|
+
}
|
|
832
|
+
function setSharedToastManager(instance) {
|
|
833
|
+
const reg = getGlobalRegistry();
|
|
834
|
+
if (!reg) return;
|
|
835
|
+
reg[WULF_TOAST_MANAGER_SYMBOL] = instance;
|
|
836
|
+
}
|
|
837
|
+
function getWeakSetRegistry(sym) {
|
|
838
|
+
if (typeof WeakSet === "undefined") return null;
|
|
839
|
+
const reg = getGlobalRegistry();
|
|
840
|
+
if (!reg) return null;
|
|
841
|
+
let set = reg[sym];
|
|
842
|
+
if (!(set instanceof WeakSet)) {
|
|
843
|
+
set = /* @__PURE__ */ new WeakSet();
|
|
844
|
+
reg[sym] = set;
|
|
845
|
+
}
|
|
846
|
+
return set;
|
|
847
|
+
}
|
|
848
|
+
function registerToastContainer(el) {
|
|
849
|
+
getWeakSetRegistry(WULF_TOAST_CONTAINERS_SYMBOL)?.add(el);
|
|
850
|
+
}
|
|
851
|
+
function unregisterToastContainer(el) {
|
|
852
|
+
getWeakSetRegistry(WULF_TOAST_CONTAINERS_SYMBOL)?.delete(el);
|
|
853
|
+
}
|
|
854
|
+
function registerToastAnnouncer(el) {
|
|
855
|
+
getWeakSetRegistry(WULF_TOAST_ANNOUNCERS_SYMBOL)?.add(el);
|
|
856
|
+
}
|
|
857
|
+
function unregisterToastAnnouncer(el) {
|
|
858
|
+
getWeakSetRegistry(WULF_TOAST_ANNOUNCERS_SYMBOL)?.delete(el);
|
|
859
|
+
}
|
|
860
|
+
|
|
705
861
|
// src/toast/ToastManager.ts
|
|
706
862
|
var VALID_POSITIONS = /* @__PURE__ */ new Set([
|
|
707
863
|
"top-left",
|
|
@@ -716,8 +872,8 @@ var __WulfIIFE = (() => {
|
|
|
716
872
|
}
|
|
717
873
|
var FOCUSABLE_IN_TOAST = 'button:not([disabled]), [href], [tabindex]:not([tabindex="-1"])';
|
|
718
874
|
var ToastManager = class _ToastManager {
|
|
719
|
-
static instance = null;
|
|
720
875
|
containers = /* @__PURE__ */ new Map();
|
|
876
|
+
containerBaseLabels = /* @__PURE__ */ new WeakMap();
|
|
721
877
|
activeToasts = /* @__PURE__ */ new Map();
|
|
722
878
|
announcerEl = null;
|
|
723
879
|
politeRegion = null;
|
|
@@ -745,15 +901,21 @@ var __WulfIIFE = (() => {
|
|
|
745
901
|
constructor() {
|
|
746
902
|
}
|
|
747
903
|
static getInstance() {
|
|
748
|
-
|
|
749
|
-
|
|
904
|
+
let instance = getSharedToastManager();
|
|
905
|
+
if (!instance) {
|
|
906
|
+
instance = new _ToastManager();
|
|
907
|
+
setSharedToastManager(instance);
|
|
750
908
|
}
|
|
751
|
-
return
|
|
909
|
+
return instance;
|
|
910
|
+
}
|
|
911
|
+
getContainerKey(position, useTopLayer) {
|
|
912
|
+
return `${position}:${useTopLayer ? "top" : "fixed"}`;
|
|
752
913
|
}
|
|
753
914
|
/**
|
|
754
915
|
* Ajoute et affiche une notification Toast.
|
|
755
916
|
*/
|
|
756
917
|
add(toast) {
|
|
918
|
+
if (typeof document === "undefined" || typeof window === "undefined") return;
|
|
757
919
|
const position = normalizePosition(toast.options.position);
|
|
758
920
|
let list = this.activeToasts.get(position);
|
|
759
921
|
if (!list) {
|
|
@@ -795,7 +957,7 @@ var __WulfIIFE = (() => {
|
|
|
795
957
|
* Insère l'élément toast dans le conteneur Top Layer, annonce le message et démarre le minuteur.
|
|
796
958
|
*/
|
|
797
959
|
mountToast(toast, position, maxToasts = 5) {
|
|
798
|
-
if (toast.isClosed) return;
|
|
960
|
+
if (toast.isClosed || typeof document === "undefined") return;
|
|
799
961
|
const useTopLayer = toast.options.useTopLayer ?? true;
|
|
800
962
|
const container = this.getOrCreateContainer(position, toast, useTopLayer);
|
|
801
963
|
let list = this.activeToasts.get(position);
|
|
@@ -839,7 +1001,8 @@ var __WulfIIFE = (() => {
|
|
|
839
1001
|
* Annonce la notification sur un canal unique pour éviter les doubles lectures AT.
|
|
840
1002
|
*/
|
|
841
1003
|
announce(toast) {
|
|
842
|
-
|
|
1004
|
+
if (typeof document === "undefined" || typeof window === "undefined") return;
|
|
1005
|
+
const parts = [toast.options.title, toast.options.message].filter((val) => typeof val === "string" && val.trim().length > 0).map((val) => stripBidiAndInvisibles(val, 512).trim()).filter(Boolean);
|
|
843
1006
|
if (parts.length === 0) return;
|
|
844
1007
|
const rawText = parts.join(". ");
|
|
845
1008
|
const text = rawText.length > 512 ? `${rawText.slice(0, 509)}...` : rawText;
|
|
@@ -926,12 +1089,14 @@ var __WulfIIFE = (() => {
|
|
|
926
1089
|
* Crée ou reconnecte le conteneur persistant des annonces ARIA hors du popover.
|
|
927
1090
|
*/
|
|
928
1091
|
ensureAnnouncer() {
|
|
1092
|
+
if (typeof document === "undefined" || !document.body) return;
|
|
929
1093
|
if (this.announcerEl && document.body.contains(this.announcerEl)) {
|
|
930
1094
|
return;
|
|
931
1095
|
}
|
|
932
1096
|
const wrapper = document.createElement("div");
|
|
933
1097
|
wrapper.className = "wulf-toast-announcer";
|
|
934
1098
|
wrapper.setAttribute("data-wulf-toast-announcer", "true");
|
|
1099
|
+
registerToastAnnouncer(wrapper);
|
|
935
1100
|
const polite = document.createElement("div");
|
|
936
1101
|
polite.setAttribute("role", "status");
|
|
937
1102
|
polite.setAttribute("aria-live", "polite");
|
|
@@ -951,7 +1116,8 @@ var __WulfIIFE = (() => {
|
|
|
951
1116
|
* Transfère le focus avant de retirer un toast focalisé pour éviter que le focus ne retombe sur <body>.
|
|
952
1117
|
*/
|
|
953
1118
|
handleFocusHandoff(toast, list) {
|
|
954
|
-
|
|
1119
|
+
const active = getDeepActiveElement();
|
|
1120
|
+
if (!active || !toast.element.contains(active)) {
|
|
955
1121
|
return;
|
|
956
1122
|
}
|
|
957
1123
|
for (let i = list.length - 1; i >= 0; i--) {
|
|
@@ -964,7 +1130,15 @@ var __WulfIIFE = (() => {
|
|
|
964
1130
|
}
|
|
965
1131
|
}
|
|
966
1132
|
const prev = toast.getPreviousActiveElement();
|
|
967
|
-
if (prev && prev.isConnected && typeof prev.focus === "function" && !prev.disabled && !prev.closest("[inert]") && prev.getAttribute("aria-hidden") !== "true") {
|
|
1133
|
+
if (prev && prev.isConnected && typeof prev.focus === "function" && !prev.disabled && !prev.hidden && !prev.closest("[hidden]") && !prev.closest("[inert]") && prev.getAttribute("aria-hidden") !== "true" && (prev.tabIndex >= 0 || prev.getAttribute("tabindex") !== null)) {
|
|
1134
|
+
const prevWithCheck = prev;
|
|
1135
|
+
if (typeof prevWithCheck.checkVisibility === "function" && !prevWithCheck.checkVisibility({
|
|
1136
|
+
checkOpacity: false,
|
|
1137
|
+
checkVisibilityCSS: true,
|
|
1138
|
+
visibilityProperty: true
|
|
1139
|
+
})) {
|
|
1140
|
+
return;
|
|
1141
|
+
}
|
|
968
1142
|
try {
|
|
969
1143
|
prev.focus();
|
|
970
1144
|
} catch {
|
|
@@ -977,6 +1151,9 @@ var __WulfIIFE = (() => {
|
|
|
977
1151
|
remove(toast, _reason) {
|
|
978
1152
|
const position = normalizePosition(toast.options.position);
|
|
979
1153
|
const list = this.activeToasts.get(position);
|
|
1154
|
+
const useTopLayer = toast.options.useTopLayer ?? true;
|
|
1155
|
+
const containerKey = this.getContainerKey(position, useTopLayer);
|
|
1156
|
+
const parentContainer = toast.element.parentElement;
|
|
980
1157
|
if (list) {
|
|
981
1158
|
const index = list.indexOf(toast);
|
|
982
1159
|
if (index !== -1) {
|
|
@@ -986,19 +1163,34 @@ var __WulfIIFE = (() => {
|
|
|
986
1163
|
if (toast.element.parentNode) {
|
|
987
1164
|
toast.element.parentNode.removeChild(toast.element);
|
|
988
1165
|
}
|
|
1166
|
+
const targetContainer = this.containers.get(containerKey) || (parentContainer instanceof HTMLElement ? parentContainer : void 0);
|
|
1167
|
+
if (targetContainer && (!targetContainer.firstChild || targetContainer.children.length === 0)) {
|
|
1168
|
+
for (const [k, c] of Array.from(this.containers.entries())) {
|
|
1169
|
+
if (c === targetContainer) {
|
|
1170
|
+
this.containers.delete(k);
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
this.disposeContainer(targetContainer);
|
|
1174
|
+
this.syncContainerRegionLabels();
|
|
1175
|
+
}
|
|
989
1176
|
if (list.length === 0 && !this.pendingReplacements.has(position)) {
|
|
990
|
-
const
|
|
991
|
-
|
|
992
|
-
this.
|
|
993
|
-
|
|
994
|
-
|
|
1177
|
+
for (const mode of [true, false]) {
|
|
1178
|
+
const k = this.getContainerKey(position, mode);
|
|
1179
|
+
const container = this.containers.get(k);
|
|
1180
|
+
if (container && (!container.firstChild || container.children.length === 0)) {
|
|
1181
|
+
this.disposeContainer(container);
|
|
1182
|
+
this.containers.delete(k);
|
|
1183
|
+
}
|
|
995
1184
|
}
|
|
1185
|
+
this.activeToasts.delete(position);
|
|
1186
|
+
this.syncContainerRegionLabels();
|
|
996
1187
|
}
|
|
997
1188
|
} else if (toast.element.parentNode) {
|
|
998
1189
|
toast.element.parentNode.removeChild(toast.element);
|
|
999
1190
|
}
|
|
1000
1191
|
}
|
|
1001
1192
|
disposeContainer(container) {
|
|
1193
|
+
unregisterToastContainer(container);
|
|
1002
1194
|
try {
|
|
1003
1195
|
const popoverEl = container;
|
|
1004
1196
|
if (typeof popoverEl.hidePopover === "function" && this.isPopoverOpen(container)) {
|
|
@@ -1014,6 +1206,9 @@ var __WulfIIFE = (() => {
|
|
|
1014
1206
|
* Ferme l'ensemble des toasts actifs (sur une position ou partout) et attend leur retrait complet.
|
|
1015
1207
|
*/
|
|
1016
1208
|
clearAll(position) {
|
|
1209
|
+
if (typeof document === "undefined" || typeof window === "undefined") {
|
|
1210
|
+
return Promise.resolve();
|
|
1211
|
+
}
|
|
1017
1212
|
const promises = [];
|
|
1018
1213
|
if (position) {
|
|
1019
1214
|
this.replaceTokens.set(position, (this.replaceTokens.get(position) || 0) + 1);
|
|
@@ -1025,11 +1220,19 @@ var __WulfIIFE = (() => {
|
|
|
1025
1220
|
promises.push(t.close("programmatic"));
|
|
1026
1221
|
}
|
|
1027
1222
|
} else {
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
this.
|
|
1031
|
-
this.containers.
|
|
1032
|
-
|
|
1223
|
+
let removedAny = false;
|
|
1224
|
+
for (const mode of [true, false]) {
|
|
1225
|
+
const k = this.getContainerKey(position, mode);
|
|
1226
|
+
const container = this.containers.get(k);
|
|
1227
|
+
if (container && (!container.firstChild || container.children.length === 0)) {
|
|
1228
|
+
this.disposeContainer(container);
|
|
1229
|
+
this.containers.delete(k);
|
|
1230
|
+
removedAny = true;
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
this.activeToasts.delete(position);
|
|
1234
|
+
if (removedAny) {
|
|
1235
|
+
this.syncContainerRegionLabels();
|
|
1033
1236
|
}
|
|
1034
1237
|
}
|
|
1035
1238
|
} else {
|
|
@@ -1045,23 +1248,27 @@ var __WulfIIFE = (() => {
|
|
|
1045
1248
|
this.assertiveAnnounceTimerId = null;
|
|
1046
1249
|
this.politeClearTimerId = null;
|
|
1047
1250
|
this.assertiveClearTimerId = null;
|
|
1048
|
-
const
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1251
|
+
const positionSet = new Set(Array.from(this.activeToasts.keys()));
|
|
1252
|
+
for (const key of this.containers.keys()) {
|
|
1253
|
+
const pos = key.slice(0, key.lastIndexOf(":"));
|
|
1254
|
+
if (VALID_POSITIONS.has(pos)) {
|
|
1255
|
+
positionSet.add(pos);
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
for (const pos of positionSet) {
|
|
1053
1259
|
promises.push(this.clearAll(pos));
|
|
1054
1260
|
}
|
|
1055
1261
|
}
|
|
1056
1262
|
return Promise.all(promises).then(() => {
|
|
1057
1263
|
if (!position) {
|
|
1058
|
-
for (const [
|
|
1264
|
+
for (const [key, container] of Array.from(this.containers.entries())) {
|
|
1059
1265
|
if (!container.firstChild || container.children.length === 0) {
|
|
1060
1266
|
this.disposeContainer(container);
|
|
1061
|
-
this.containers.delete(
|
|
1062
|
-
this.activeToasts.delete(pos);
|
|
1267
|
+
this.containers.delete(key);
|
|
1063
1268
|
}
|
|
1064
1269
|
}
|
|
1270
|
+
this.activeToasts.clear();
|
|
1271
|
+
this.syncContainerRegionLabels();
|
|
1065
1272
|
}
|
|
1066
1273
|
});
|
|
1067
1274
|
}
|
|
@@ -1069,10 +1276,16 @@ var __WulfIIFE = (() => {
|
|
|
1069
1276
|
* Détruit immédiatement tous les toasts, conteneurs, annonceurs ARIA et temporisations en cours.
|
|
1070
1277
|
*/
|
|
1071
1278
|
destroy() {
|
|
1072
|
-
|
|
1073
|
-
|
|
1279
|
+
if (typeof window !== "undefined") {
|
|
1280
|
+
for (const timerId of this.announceTimers) {
|
|
1281
|
+
window.clearTimeout(timerId);
|
|
1282
|
+
}
|
|
1074
1283
|
}
|
|
1075
1284
|
this.announceTimers = [];
|
|
1285
|
+
this.politeAnnounceTimerId = null;
|
|
1286
|
+
this.assertiveAnnounceTimerId = null;
|
|
1287
|
+
this.politeClearTimerId = null;
|
|
1288
|
+
this.assertiveClearTimerId = null;
|
|
1076
1289
|
for (const list of Array.from(this.activeToasts.values())) {
|
|
1077
1290
|
for (const toast of [...list]) {
|
|
1078
1291
|
toast.destroyImmediate("programmatic");
|
|
@@ -1086,35 +1299,52 @@ var __WulfIIFE = (() => {
|
|
|
1086
1299
|
this.replaceTokens.clear();
|
|
1087
1300
|
this.pendingReplacements.clear();
|
|
1088
1301
|
if (this.announcerEl) {
|
|
1302
|
+
unregisterToastAnnouncer(this.announcerEl);
|
|
1089
1303
|
this.announcerEl.remove();
|
|
1090
1304
|
this.announcerEl = null;
|
|
1091
1305
|
this.politeRegion = null;
|
|
1092
1306
|
this.assertiveRegion = null;
|
|
1093
1307
|
}
|
|
1094
|
-
|
|
1308
|
+
setSharedToastManager(null);
|
|
1309
|
+
}
|
|
1310
|
+
syncContainerRegionLabels() {
|
|
1311
|
+
const useSuffix = this.containers.size > 1;
|
|
1312
|
+
for (const [key, container] of this.containers.entries()) {
|
|
1313
|
+
const baseLabel = this.containerBaseLabels.get(container) || toastI18n.t("notificationsRegion");
|
|
1314
|
+
const pos = key.slice(0, key.lastIndexOf(":"));
|
|
1315
|
+
container.setAttribute("aria-label", useSuffix ? `${baseLabel} (${pos})` : baseLabel);
|
|
1316
|
+
}
|
|
1095
1317
|
}
|
|
1096
1318
|
/**
|
|
1097
|
-
* Récupère ou crée le conteneur DOM pour une position
|
|
1319
|
+
* Récupère ou crée le conteneur DOM pour une position et un mode Top Layer donnés.
|
|
1098
1320
|
*/
|
|
1099
1321
|
getOrCreateContainer(position, toast, useTopLayer) {
|
|
1100
|
-
|
|
1322
|
+
const key = this.getContainerKey(position, useTopLayer);
|
|
1323
|
+
let container = this.containers.get(key);
|
|
1101
1324
|
if (!container || !document.body.contains(container)) {
|
|
1325
|
+
if (container) {
|
|
1326
|
+
unregisterToastContainer(container);
|
|
1327
|
+
}
|
|
1102
1328
|
container = document.createElement("div");
|
|
1103
1329
|
container.className = `wulf-toast-container wulf-toast-${position}`;
|
|
1104
1330
|
container.setAttribute("role", "region");
|
|
1105
|
-
|
|
1331
|
+
const baseLabel = toastI18n.t("notificationsRegion", toast.options.i18n);
|
|
1332
|
+
this.containerBaseLabels.set(container, baseLabel);
|
|
1333
|
+
container.setAttribute("aria-label", baseLabel);
|
|
1106
1334
|
if (useTopLayer && typeof container.showPopover === "function") {
|
|
1107
1335
|
container.setAttribute("popover", "manual");
|
|
1108
1336
|
}
|
|
1337
|
+
registerToastContainer(container);
|
|
1109
1338
|
document.body.appendChild(container);
|
|
1110
|
-
this.containers.set(
|
|
1339
|
+
this.containers.set(key, container);
|
|
1340
|
+
this.syncContainerRegionLabels();
|
|
1111
1341
|
}
|
|
1112
1342
|
return container;
|
|
1113
1343
|
}
|
|
1114
1344
|
};
|
|
1115
1345
|
|
|
1116
1346
|
// src/toast/Toast.ts
|
|
1117
|
-
var Toast = class extends LocalizedComponent {
|
|
1347
|
+
var Toast = class _Toast extends LocalizedComponent {
|
|
1118
1348
|
static _i18n = toastI18n;
|
|
1119
1349
|
static i18n = toastI18n;
|
|
1120
1350
|
audit() {
|
|
@@ -1137,6 +1367,65 @@ var __WulfIIFE = (() => {
|
|
|
1137
1367
|
manager.add(instance);
|
|
1138
1368
|
return instance;
|
|
1139
1369
|
}
|
|
1370
|
+
/**
|
|
1371
|
+
* Accompagne une promesse asynchrone avec une notification de chargement puis un résultat succès ou erreur.
|
|
1372
|
+
* Seul le toast de chargement est fermé à la résolution/rejet ; tout rejet est toujours repropagé.
|
|
1373
|
+
*/
|
|
1374
|
+
static async promise(promiseOrFactory, options) {
|
|
1375
|
+
const resolveMessage = (spec, arg) => {
|
|
1376
|
+
let resolved;
|
|
1377
|
+
if (typeof spec === "function") {
|
|
1378
|
+
try {
|
|
1379
|
+
resolved = spec(arg);
|
|
1380
|
+
} catch (err) {
|
|
1381
|
+
console.error("[Wulf.Toast] Erreur lors de la r\xE9solution du message Toast.promise:", err);
|
|
1382
|
+
return {};
|
|
1383
|
+
}
|
|
1384
|
+
} else {
|
|
1385
|
+
resolved = spec;
|
|
1386
|
+
}
|
|
1387
|
+
if (typeof resolved === "string") {
|
|
1388
|
+
return { message: resolved };
|
|
1389
|
+
}
|
|
1390
|
+
if (resolved && typeof resolved === "object") {
|
|
1391
|
+
return { ...resolved };
|
|
1392
|
+
}
|
|
1393
|
+
return {};
|
|
1394
|
+
};
|
|
1395
|
+
const baseOpts = options.baseOptions ? { ...options.baseOptions } : {};
|
|
1396
|
+
const loadingOpts = resolveMessage(options.loading, void 0);
|
|
1397
|
+
const loadingToast = _Toast.show({
|
|
1398
|
+
...baseOpts,
|
|
1399
|
+
duration: false,
|
|
1400
|
+
closable: true,
|
|
1401
|
+
role: "status",
|
|
1402
|
+
...loadingOpts,
|
|
1403
|
+
replace: false
|
|
1404
|
+
});
|
|
1405
|
+
const targetPromise = typeof promiseOrFactory === "function" ? Promise.resolve().then(() => promiseOrFactory()) : Promise.resolve(promiseOrFactory);
|
|
1406
|
+
try {
|
|
1407
|
+
const data = await targetPromise;
|
|
1408
|
+
await loadingToast.close("replace", true);
|
|
1409
|
+
const successOpts = resolveMessage(options.success, data);
|
|
1410
|
+
_Toast.show({
|
|
1411
|
+
...baseOpts,
|
|
1412
|
+
role: "status",
|
|
1413
|
+
...successOpts,
|
|
1414
|
+
replace: false
|
|
1415
|
+
});
|
|
1416
|
+
return data;
|
|
1417
|
+
} catch (err) {
|
|
1418
|
+
await loadingToast.close("replace", true);
|
|
1419
|
+
const errorOpts = resolveMessage(options.error, err);
|
|
1420
|
+
_Toast.show({
|
|
1421
|
+
...baseOpts,
|
|
1422
|
+
role: "alert",
|
|
1423
|
+
...errorOpts,
|
|
1424
|
+
replace: false
|
|
1425
|
+
});
|
|
1426
|
+
throw err;
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1140
1429
|
/**
|
|
1141
1430
|
* Ferme immédiatement l'ensemble des toasts actifs (globalement ou par position) et attend leur retrait complet.
|
|
1142
1431
|
*/
|
|
@@ -1153,14 +1442,7 @@ var __WulfIIFE = (() => {
|
|
|
1153
1442
|
|
|
1154
1443
|
// src/toast/index.ts
|
|
1155
1444
|
var index_default = Toast;
|
|
1156
|
-
var wulfNamespace = getSafeWulfNamespace();
|
|
1157
|
-
if (wulfNamespace) {
|
|
1158
|
-
wulfNamespace.Toast = Object.assign(Toast, {
|
|
1159
|
-
Toast,
|
|
1160
|
-
i18n: toastI18n
|
|
1161
|
-
});
|
|
1162
|
-
}
|
|
1163
1445
|
return __toCommonJS(index_exports);
|
|
1164
1446
|
})();
|
|
1165
|
-
if (typeof window !== "undefined") { var __w = window.Wulf; if (!__w || typeof __w !== "object" || (typeof Node !== "undefined" && __w instanceof Node) || (typeof HTMLCollection !== "undefined" && __w instanceof HTMLCollection)) { __w = {}; window.Wulf = __w; } if (typeof __WulfIIFE !== "undefined" && __WulfIIFE) { for (var k in
|
|
1447
|
+
if (typeof window !== "undefined") { var __w = window.Wulf; if (!__w || typeof __w !== "object" || (typeof Node !== "undefined" && __w instanceof Node) || (typeof HTMLCollection !== "undefined" && __w instanceof HTMLCollection)) { __w = {}; window.Wulf = __w; } var __set = function(obj, key, val) { try { Object.defineProperty(obj, key, { value: val, writable: true, configurable: true, enumerable: true }); } catch (_) { try { obj[key] = val; } catch (__) {} } }; if (typeof __WulfIIFE !== "undefined" && __WulfIIFE) { var __e = __WulfIIFE; var __skip = ["__proto__","constructor","prototype"]; for (var k in __e) { if (Object.hasOwn(__e, k) && __skip.indexOf(k) === -1 && __w[k] === undefined) { __set(__w, k, __e[k]); } } if (__e.Toast) __set(__w, "Toast", Object.assign(__e.Toast, { Toast: __e.Toast, ToastInstance: __e.ToastInstance, ToastManager: __e.ToastManager, i18n: __e.toastI18n })); }}
|
|
1166
1448
|
//# sourceMappingURL=toast.global.js.map
|