@mortenbrudvik/waveui 0.11.0 → 0.12.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 +97 -2
- package/dist/components/button/Link.cjs +1 -1
- package/dist/components/button/Link.cjs.map +1 -1
- package/dist/components/button/Link.mjs +4 -4
- package/dist/components/data-display/AvatarGroup.cjs +1 -1
- package/dist/components/data-display/AvatarGroup.cjs.map +1 -1
- package/dist/components/data-display/AvatarGroup.mjs +10 -10
- package/dist/components/data-display/InfoButton.cjs +1 -1
- package/dist/components/data-display/InfoButton.cjs.map +1 -1
- package/dist/components/data-display/InfoButton.mjs +12 -12
- package/dist/components/feedback/Toaster.cjs +1 -1
- package/dist/components/feedback/Toaster.cjs.map +1 -1
- package/dist/components/feedback/Toaster.mjs +235 -235
- package/dist/components/feedback/Toaster.mjs.map +1 -1
- package/dist/components/input/Combobox.cjs +1 -1
- package/dist/components/input/Combobox.cjs.map +1 -1
- package/dist/components/input/Combobox.mjs +176 -175
- package/dist/components/input/Combobox.mjs.map +1 -1
- package/dist/components/input/DatePicker.cjs +1 -1
- package/dist/components/input/DatePicker.cjs.map +1 -1
- package/dist/components/input/DatePicker.mjs +188 -187
- package/dist/components/input/DatePicker.mjs.map +1 -1
- package/dist/components/input/Dropdown.cjs +1 -1
- package/dist/components/input/Dropdown.cjs.map +1 -1
- package/dist/components/input/Dropdown.mjs +41 -40
- package/dist/components/input/Dropdown.mjs.map +1 -1
- package/dist/components/input/Option.cjs +1 -1
- package/dist/components/input/Option.cjs.map +1 -1
- package/dist/components/input/Option.mjs +89 -87
- package/dist/components/input/Option.mjs.map +1 -1
- package/dist/components/input/TagPicker.root.cjs +1 -1
- package/dist/components/input/TagPicker.root.cjs.map +1 -1
- package/dist/components/input/TagPicker.root.mjs +136 -135
- package/dist/components/input/TagPicker.root.mjs.map +1 -1
- package/dist/components/input/TimePicker.cjs +1 -1
- package/dist/components/input/TimePicker.cjs.map +1 -1
- package/dist/components/input/TimePicker.mjs +156 -154
- package/dist/components/input/TimePicker.mjs.map +1 -1
- package/dist/components/navigation/Menu.popover.cjs +1 -1
- package/dist/components/navigation/Menu.popover.cjs.map +1 -1
- package/dist/components/navigation/Menu.popover.mjs +137 -127
- package/dist/components/navigation/Menu.popover.mjs.map +1 -1
- package/dist/components/navigation/Menu.root.cjs +1 -1
- package/dist/components/navigation/Menu.root.cjs.map +1 -1
- package/dist/components/navigation/Menu.root.mjs +4 -4
- package/dist/components/overlays/Dialog.cjs +1 -1
- package/dist/components/overlays/Dialog.cjs.map +1 -1
- package/dist/components/overlays/Dialog.mjs +123 -123
- package/dist/components/overlays/Dialog.mjs.map +1 -1
- package/dist/components/overlays/Drawer.panel.cjs +1 -1
- package/dist/components/overlays/Drawer.panel.cjs.map +1 -1
- package/dist/components/overlays/Drawer.panel.mjs +12 -12
- package/dist/components/overlays/Drawer.panel.mjs.map +1 -1
- package/dist/components/overlays/Popover.cjs +1 -1
- package/dist/components/overlays/Popover.cjs.map +1 -1
- package/dist/components/overlays/Popover.mjs +173 -162
- package/dist/components/overlays/Popover.mjs.map +1 -1
- package/dist/components/overlays/TeachingPopover.cjs +1 -1
- package/dist/components/overlays/TeachingPopover.cjs.map +1 -1
- package/dist/components/overlays/TeachingPopover.mjs +96 -91
- package/dist/components/overlays/TeachingPopover.mjs.map +1 -1
- package/dist/components/overlays/Tooltip.cjs +1 -1
- package/dist/components/overlays/Tooltip.cjs.map +1 -1
- package/dist/components/overlays/Tooltip.mjs +47 -47
- package/dist/components/overlays/Tooltip.mjs.map +1 -1
- package/dist/components/portal/Portal.cjs +1 -1
- package/dist/components/portal/Portal.cjs.map +1 -1
- package/dist/components/portal/Portal.mjs +5 -5
- package/dist/components/table/DataGrid.cjs +1 -1
- package/dist/components/table/DataGrid.cjs.map +1 -1
- package/dist/components/table/DataGrid.mjs +1 -1
- package/dist/hooks/useDismiss.cjs.map +1 -1
- package/dist/hooks/useDismiss.mjs.map +1 -1
- package/dist/hooks/useFocusTrap.cjs.map +1 -1
- package/dist/hooks/useFocusTrap.mjs.map +1 -1
- package/dist/hooks/useFocusVisible.cjs +2 -0
- package/dist/hooks/useFocusVisible.cjs.map +1 -0
- package/dist/hooks/useFocusVisible.mjs +49 -0
- package/dist/hooks/useFocusVisible.mjs.map +1 -0
- package/dist/hooks/useFocusableGroup.cjs +2 -0
- package/dist/hooks/useFocusableGroup.cjs.map +1 -0
- package/dist/hooks/useFocusableGroup.mjs +70 -0
- package/dist/hooks/useFocusableGroup.mjs.map +1 -0
- package/dist/hooks/useModalLayer.cjs +1 -1
- package/dist/hooks/useModalLayer.cjs.map +1 -1
- package/dist/hooks/useModalLayer.mjs +4 -4
- package/dist/hooks/useModalOpen.cjs +2 -0
- package/dist/hooks/useModalOpen.cjs.map +1 -0
- package/dist/hooks/useModalOpen.mjs +14 -0
- package/dist/hooks/useModalOpen.mjs.map +1 -0
- package/dist/hooks/usePopupPosition.cjs +1 -1
- package/dist/hooks/usePopupPosition.cjs.map +1 -1
- package/dist/hooks/usePopupPosition.mjs +82 -53
- package/dist/hooks/usePopupPosition.mjs.map +1 -1
- package/dist/hooks/useResolvedTarget.cjs +2 -0
- package/dist/hooks/useResolvedTarget.cjs.map +1 -0
- package/dist/hooks/useResolvedTarget.mjs +37 -0
- package/dist/hooks/useResolvedTarget.mjs.map +1 -0
- package/dist/hooks/useRovingGrid.cjs +1 -1
- package/dist/hooks/useRovingGrid.cjs.map +1 -1
- package/dist/hooks/useRovingGrid.mjs +8 -57
- package/dist/hooks/useRovingGrid.mjs.map +1 -1
- package/dist/hooks/useRovingTabIndex.cjs +1 -1
- package/dist/hooks/useRovingTabIndex.cjs.map +1 -1
- package/dist/hooks/useRovingTabIndex.mjs +142 -107
- package/dist/hooks/useRovingTabIndex.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +814 -18
- package/dist/index.d.ts +814 -18
- package/dist/index.mjs +120 -108
- package/dist/lib/layers.cjs +1 -1
- package/dist/lib/layers.cjs.map +1 -1
- package/dist/lib/layers.mjs +112 -109
- package/dist/lib/layers.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/dist/lib/layers.mjs
CHANGED
|
@@ -4,8 +4,8 @@ var t = {
|
|
|
4
4
|
overlay: "var(--wave-z-overlay, 1000)",
|
|
5
5
|
toast: "var(--wave-z-toast, 1100)",
|
|
6
6
|
tooltip: "var(--wave-z-tooltip, 1200)"
|
|
7
|
-
}, n = "[data-wave-focus-trap-allow]";
|
|
8
|
-
function
|
|
7
|
+
}, n = "[data-wave-focus-trap-allow]", r = { "data-wave-focus-trap-allow": "" };
|
|
8
|
+
function i() {
|
|
9
9
|
let t = e("layers", () => ({
|
|
10
10
|
stack: [],
|
|
11
11
|
elements: /* @__PURE__ */ new Map(),
|
|
@@ -17,214 +17,217 @@ function r() {
|
|
|
17
17
|
}));
|
|
18
18
|
return t.subscribers ??= /* @__PURE__ */ new Set(), t.isolated ??= /* @__PURE__ */ new Map(), t;
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function a(e) {
|
|
21
21
|
for (let t of Array.from(e.subscribers)) t();
|
|
22
22
|
}
|
|
23
|
-
var
|
|
24
|
-
function
|
|
23
|
+
var o = 1;
|
|
24
|
+
function s(e, t) {
|
|
25
25
|
if (t !== null) return e.stack.find((e) => e.id === t);
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function c(e, t, n) {
|
|
28
28
|
let r = /* @__PURE__ */ new Set([t.id]), i = t.parentId;
|
|
29
29
|
for (; i !== null && !r.has(i);) {
|
|
30
30
|
if (i === n) return !0;
|
|
31
|
-
r.add(i), i =
|
|
31
|
+
r.add(i), i = s(e, i)?.parentId ?? null;
|
|
32
32
|
}
|
|
33
33
|
return !1;
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function l(e, t) {
|
|
36
36
|
return !!e && e.contains(t);
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function u(e, t, n, r) {
|
|
39
39
|
if (r.has(t)) return !1;
|
|
40
40
|
r.add(t);
|
|
41
|
-
let i =
|
|
42
|
-
if (i && i.getElements().some((e) =>
|
|
41
|
+
let i = s(e, t);
|
|
42
|
+
if (i && i.getElements().some((e) => l(e, n))) return !0;
|
|
43
43
|
let a = e.elements.get(t);
|
|
44
44
|
if (a) {
|
|
45
|
-
for (let e of a) if (
|
|
45
|
+
for (let e of a) if (l(e, n)) return !0;
|
|
46
46
|
}
|
|
47
|
-
for (let i of e.stack) if (i.parentId === t &&
|
|
47
|
+
for (let i of e.stack) if (i.parentId === t && u(e, i.id, n, r)) return !0;
|
|
48
48
|
return !1;
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
let t = e.nodeType ===
|
|
50
|
+
function d(e) {
|
|
51
|
+
let t = e.nodeType === o ? e : e.parentElement;
|
|
52
52
|
return !!t && t.closest("[data-wave-focus-trap-allow]") !== null;
|
|
53
53
|
}
|
|
54
|
-
function d(e, t) {
|
|
55
|
-
return u(t) ? !0 : l(r(), e, t, /* @__PURE__ */ new Set());
|
|
56
|
-
}
|
|
57
54
|
function f(e, t) {
|
|
55
|
+
return d(t) ? !0 : u(i(), e, t, /* @__PURE__ */ new Set());
|
|
56
|
+
}
|
|
57
|
+
function p(e, t) {
|
|
58
58
|
if (e === t || e.id === t.id) return 0;
|
|
59
|
-
let n =
|
|
60
|
-
if (
|
|
61
|
-
if (
|
|
62
|
-
let
|
|
63
|
-
return
|
|
64
|
-
}
|
|
65
|
-
function
|
|
66
|
-
let { stack: t } =
|
|
59
|
+
let n = i();
|
|
60
|
+
if (c(n, e, t.id)) return 1;
|
|
61
|
+
if (c(n, t, e.id)) return -1;
|
|
62
|
+
let r = n.stack.indexOf(e), a = n.stack.indexOf(t);
|
|
63
|
+
return r !== -1 && a !== -1 ? r - a : e.order - t.order;
|
|
64
|
+
}
|
|
65
|
+
function m(e) {
|
|
66
|
+
let { stack: t } = i();
|
|
67
67
|
for (let n = t.length - 1; n >= 0; n--) {
|
|
68
68
|
let r = t[n];
|
|
69
69
|
if (!e || e(r)) return r;
|
|
70
70
|
}
|
|
71
71
|
return null;
|
|
72
72
|
}
|
|
73
|
-
function
|
|
74
|
-
let t =
|
|
75
|
-
n.set(e,
|
|
73
|
+
function h(e) {
|
|
74
|
+
let t = i(), { isolated: n } = t, r = n.get(e) ?? 0;
|
|
75
|
+
n.set(e, r + 1), r === 0 && a(t);
|
|
76
76
|
let o = !0;
|
|
77
77
|
return () => {
|
|
78
78
|
if (!o) return;
|
|
79
79
|
o = !1;
|
|
80
80
|
let r = (n.get(e) ?? 1) - 1;
|
|
81
|
-
r > 0 ? n.set(e, r) : n.delete(e) &&
|
|
81
|
+
r > 0 ? n.set(e, r) : n.delete(e) && a(t);
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
|
-
function h(e) {
|
|
85
|
-
return e.isolated.size === 0 ? null : p((t) => e.isolated.has(t.id));
|
|
86
|
-
}
|
|
87
84
|
function g(e) {
|
|
88
|
-
|
|
85
|
+
return e.isolated.size === 0 ? null : m((t) => e.isolated.has(t.id));
|
|
86
|
+
}
|
|
87
|
+
function _(e) {
|
|
88
|
+
let t = i();
|
|
89
89
|
if (t.isolated.size === 0) return !1;
|
|
90
|
-
let n =
|
|
91
|
-
return t.stack.some((r) => r.id !== e && t.isolated.has(r.id) && !
|
|
90
|
+
let n = s(t, e);
|
|
91
|
+
return t.stack.some((r) => r.id !== e && t.isolated.has(r.id) && !c(t, r, e) && (!n || p(n, r) > 0));
|
|
92
92
|
}
|
|
93
|
-
function
|
|
94
|
-
return !!t && t !== e &&
|
|
93
|
+
function v(e, t) {
|
|
94
|
+
return !!t && t !== e && p(t, e) > 0;
|
|
95
95
|
}
|
|
96
|
-
function
|
|
97
|
-
let { subscribers: t } =
|
|
96
|
+
function y(e) {
|
|
97
|
+
let { subscribers: t } = i();
|
|
98
98
|
return t.add(e), () => {
|
|
99
99
|
t.delete(e);
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
|
-
function
|
|
103
|
-
return
|
|
102
|
+
function b() {
|
|
103
|
+
return i().stack.some((e) => e.kind === "modal");
|
|
104
|
+
}
|
|
105
|
+
function x() {
|
|
106
|
+
return [...i().stack];
|
|
104
107
|
}
|
|
105
|
-
function
|
|
106
|
-
return
|
|
108
|
+
function S(e) {
|
|
109
|
+
return s(i(), e) ?? null;
|
|
107
110
|
}
|
|
108
|
-
function
|
|
109
|
-
let n =
|
|
110
|
-
return !!
|
|
111
|
+
function C(e, t) {
|
|
112
|
+
let n = i(), r = s(n, e);
|
|
113
|
+
return !!r && c(n, r, t);
|
|
111
114
|
}
|
|
112
|
-
function
|
|
113
|
-
let n =
|
|
114
|
-
if (
|
|
115
|
-
|
|
116
|
-
let c =
|
|
117
|
-
if (c && (a || t !== e)) for (let e of c.getElements()) e && !
|
|
118
|
-
for (let e of n.elements.get(t) ?? [])
|
|
119
|
-
for (let e of n.stack) e.parentId === t &&
|
|
115
|
+
function w(e, t) {
|
|
116
|
+
let n = i(), r = [], a = t?.includeOwnElements ?? !0, o = (t, i) => {
|
|
117
|
+
if (i.has(t)) return;
|
|
118
|
+
i.add(t);
|
|
119
|
+
let c = s(n, t);
|
|
120
|
+
if (c && (a || t !== e)) for (let e of c.getElements()) e && !r.includes(e) && r.push(e);
|
|
121
|
+
for (let e of n.elements.get(t) ?? []) r.includes(e) || r.push(e);
|
|
122
|
+
for (let e of n.stack) e.parentId === t && o(e.id, i);
|
|
120
123
|
};
|
|
121
|
-
return
|
|
124
|
+
return o(e, /* @__PURE__ */ new Set()), r;
|
|
122
125
|
}
|
|
123
|
-
function
|
|
124
|
-
let n =
|
|
126
|
+
function T(e, t) {
|
|
127
|
+
let n = i();
|
|
125
128
|
for (let r = n.stack.length - 1; r >= 0; r--) {
|
|
126
129
|
let i = n.stack[r];
|
|
127
|
-
if (i.kind === "modal" && (t === void 0 || i.id !== t && !
|
|
130
|
+
if (i.kind === "modal" && (t === void 0 || i.id !== t && !c(n, i, t))) return !f(i.id, e);
|
|
128
131
|
}
|
|
129
132
|
return !1;
|
|
130
133
|
}
|
|
131
|
-
function
|
|
132
|
-
let n =
|
|
133
|
-
return
|
|
134
|
+
function E(e, t) {
|
|
135
|
+
let n = i(), r = n.elements.get(e);
|
|
136
|
+
return r || (r = /* @__PURE__ */ new Set(), n.elements.set(e, r)), r.add(t), () => {
|
|
134
137
|
let r = n.elements.get(e);
|
|
135
138
|
r && (r.delete(t), r.size === 0 && n.elements.delete(e));
|
|
136
139
|
};
|
|
137
140
|
}
|
|
138
|
-
function
|
|
139
|
-
let t =
|
|
141
|
+
function D(e) {
|
|
142
|
+
let t = i();
|
|
140
143
|
t.counter += 1, e.order = t.counter;
|
|
141
|
-
let n = t.stack.findIndex((n) =>
|
|
142
|
-
n === -1 ? t.stack.push(e) : t.stack.splice(n, 0, e),
|
|
143
|
-
let
|
|
144
|
+
let n = t.stack.findIndex((n) => c(t, n, e.id));
|
|
145
|
+
n === -1 ? t.stack.push(e) : t.stack.splice(n, 0, e), B(t), a(t);
|
|
146
|
+
let r = !0;
|
|
144
147
|
return () => {
|
|
145
|
-
if (!
|
|
146
|
-
|
|
148
|
+
if (!r) return;
|
|
149
|
+
r = !1;
|
|
147
150
|
let n = t.stack.indexOf(e);
|
|
148
|
-
n !== -1 && t.stack.splice(n, 1), t.press && (t.press.layers = t.press.layers.filter((t) => t !== e)), t.stack.length === 0 &&
|
|
151
|
+
n !== -1 && t.stack.splice(n, 1), t.press && (t.press.layers = t.press.layers.filter((t) => t !== e)), t.stack.length === 0 && V(t), a(t);
|
|
149
152
|
};
|
|
150
153
|
}
|
|
151
|
-
function
|
|
154
|
+
function O(e) {
|
|
152
155
|
let t = e.target;
|
|
153
156
|
return t && typeof t.nodeType == "number" ? t : null;
|
|
154
157
|
}
|
|
155
|
-
function
|
|
156
|
-
return [...e].sort((e, t) =>
|
|
158
|
+
function k(e) {
|
|
159
|
+
return [...e].sort((e, t) => p(t, e));
|
|
157
160
|
}
|
|
158
|
-
function
|
|
159
|
-
let r =
|
|
160
|
-
return (o ?
|
|
161
|
+
function A(e, t, n) {
|
|
162
|
+
let r = g(e), i = (e) => !!t && f(e.id, t) || !!n && f(e.id, n), a = (e) => (e.escape === !0 || e.escape === "inside" && i(e)) && !v(e, r), o = m(i);
|
|
163
|
+
return (o ? m((t) => a(t) && (t === o || c(e, t, o.id))) ?? m((e) => a(e) && i(e)) : null) ?? m(a);
|
|
161
164
|
}
|
|
162
|
-
function
|
|
165
|
+
function j(e) {
|
|
163
166
|
return e === "Enter" || e === " " || e === "Spacebar";
|
|
164
167
|
}
|
|
165
|
-
function
|
|
166
|
-
let t =
|
|
168
|
+
function M(e) {
|
|
169
|
+
let t = i();
|
|
167
170
|
if (e.key === "Escape" || e.key === "Esc") {
|
|
168
171
|
if (e.defaultPrevented || e.isComposing) return;
|
|
169
|
-
let n =
|
|
172
|
+
let n = A(t, O(e), document.activeElement);
|
|
170
173
|
if (!n) return;
|
|
171
174
|
e.preventDefault(), n.onDismiss("escape", e);
|
|
172
175
|
return;
|
|
173
176
|
}
|
|
174
|
-
|
|
177
|
+
j(e.key) && (t.press = null);
|
|
175
178
|
}
|
|
176
|
-
function
|
|
177
|
-
let t =
|
|
179
|
+
function N(e) {
|
|
180
|
+
let t = i(), n = O(e);
|
|
178
181
|
if (!n || e.button !== 0) {
|
|
179
182
|
t.press = null;
|
|
180
183
|
return;
|
|
181
184
|
}
|
|
182
|
-
let
|
|
185
|
+
let r = g(t);
|
|
183
186
|
t.press = { layers: t.stack.filter((t) => {
|
|
184
|
-
let { outsidePress:
|
|
185
|
-
return !
|
|
187
|
+
let { outsidePress: i } = t;
|
|
188
|
+
return !i || v(t, r) || f(t.id, n) ? !1 : typeof i != "function" || i(e) !== !1;
|
|
186
189
|
}) };
|
|
187
190
|
}
|
|
188
|
-
var
|
|
189
|
-
function
|
|
190
|
-
let t =
|
|
191
|
+
var P = 1e3;
|
|
192
|
+
function F(e) {
|
|
193
|
+
let t = i().press;
|
|
191
194
|
if (!t) return;
|
|
192
|
-
let n = e.pointerType === "mouse" ? 0 :
|
|
195
|
+
let n = e.pointerType === "mouse" ? 0 : P;
|
|
193
196
|
setTimeout(() => {
|
|
194
|
-
let e =
|
|
197
|
+
let e = i();
|
|
195
198
|
e.press === t && (e.press = null);
|
|
196
199
|
}, n);
|
|
197
200
|
}
|
|
198
|
-
function
|
|
199
|
-
|
|
201
|
+
function I() {
|
|
202
|
+
i().press = null;
|
|
200
203
|
}
|
|
201
|
-
function
|
|
202
|
-
let t =
|
|
204
|
+
function L(e) {
|
|
205
|
+
let t = i(), n = t.press;
|
|
203
206
|
if (t.press = null, !n) return;
|
|
204
|
-
let
|
|
205
|
-
for (let n of
|
|
207
|
+
let r = O(e), a = n.layers.filter((e) => !(r && f(e.id, r)));
|
|
208
|
+
for (let n of k(a)) t.stack.includes(n) && n.onDismiss("outside-press", e);
|
|
206
209
|
}
|
|
207
|
-
function
|
|
208
|
-
let t =
|
|
210
|
+
function R(e) {
|
|
211
|
+
let t = O(e);
|
|
209
212
|
if (!t) return;
|
|
210
|
-
let n =
|
|
211
|
-
n.length !== 0 && queueMicrotask(() =>
|
|
213
|
+
let n = i().stack.filter((e) => e.focusOutside && !f(e.id, t));
|
|
214
|
+
n.length !== 0 && queueMicrotask(() => z(n, t, e));
|
|
212
215
|
}
|
|
213
|
-
function
|
|
214
|
-
let
|
|
215
|
-
for (let e of
|
|
216
|
+
function z(e, t, n) {
|
|
217
|
+
let r = i(), a = (t.ownerDocument ?? document).activeElement, o = e.filter((e) => r.stack.includes(e) && !f(e.id, t) && !(a && f(e.id, a)));
|
|
218
|
+
for (let e of k(o)) r.stack.includes(e) && e.onDismiss("focus-outside", n);
|
|
216
219
|
}
|
|
217
|
-
function
|
|
220
|
+
function B(e) {
|
|
218
221
|
if (e.listeners || typeof document > "u") return;
|
|
219
222
|
let t = document;
|
|
220
|
-
t.addEventListener("keydown",
|
|
221
|
-
t.removeEventListener("keydown",
|
|
223
|
+
t.addEventListener("keydown", M), t.addEventListener("pointerdown", N, !0), t.addEventListener("pointerup", F, !0), t.addEventListener("pointercancel", I, !0), t.addEventListener("contextmenu", I, !0), t.addEventListener("click", L), t.addEventListener("focusin", R, !0), e.listeners = { remove() {
|
|
224
|
+
t.removeEventListener("keydown", M), t.removeEventListener("pointerdown", N, !0), t.removeEventListener("pointerup", F, !0), t.removeEventListener("pointercancel", I, !0), t.removeEventListener("contextmenu", I, !0), t.removeEventListener("click", L), t.removeEventListener("focusin", R, !0);
|
|
222
225
|
} };
|
|
223
226
|
}
|
|
224
|
-
function
|
|
227
|
+
function V(e) {
|
|
225
228
|
e.listeners?.remove(), e.listeners = null, e.press = null;
|
|
226
229
|
}
|
|
227
230
|
//#endregion
|
|
228
|
-
export { n as ALLOW_OUTSIDE_SELECTOR, t as Z_INDEX,
|
|
231
|
+
export { n as ALLOW_OUTSIDE_SELECTOR, t as Z_INDEX, p as compareLayers, S as getLayer, w as getLayerTreeElements, x as getOpenLayers, m as getTopmostLayer, _ as hasIsolatingModalBelow, b as hasOpenModal, C as isDescendantLayer, f as isInsideLayerTree, T as isInsideOtherOpenModal, r as modalAllowProps, D as registerLayer, E as registerLayerElement, h as registerLayerIsolation, y as subscribeLayers };
|
|
229
232
|
|
|
230
233
|
//# sourceMappingURL=layers.mjs.map
|
package/dist/lib/layers.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layers.mjs","names":["Z_INDEX","ALLOW_OUTSIDE_SELECTOR","getState","state","getGlobalRegistry","notifySubscribers","subscriber","ELEMENT_NODE","findLayer","id","layer","isDescendantOf","visited","parentId","ancestorId","containsNode","container","target","isInsideTreeWithoutAllowList","layerId","record","el","registered","isInsideAllowList","isInsideLayerTree","compareLayers","a","b","indexA","indexB","getTopmostLayer","i","stack","predicate","registerLayerIsolation","previous","isolated","count","getIsolationBarrier","hasIsolatingModalBelow","self","isBelowBarrier","barrier","subscribeLayers","subscribers","listener","getOpenLayers","getLayer","isDescendantLayer","getLayerTreeElements","result","includeOwn","options","visit","isInsideOtherOpenModal","exceptLayerId","registerLayerElement","set","current","registerLayer","firstDescendant","ensureListeners","index","removeListeners","getEventTargetNode","event","sortTopmostFirst","layers","findEscapeHandler","contains","active","isCandidate","scope","isClickActivationKey","key","handleKeyDown","handler","handlePointerDown","outsidePress","GESTURE_CLICK_TIMEOUT_MS","handlePointerUp","press","timeout","forgetPress","handleClick","toDismiss","handleFocusIn","candidates","dismissFocusOutside","doc"],"sources":["../../src/lib/layers.ts"],"sourcesContent":["import { getGlobalRegistry } from './globalRegistry';\n\n/**\n * The shared stack of open dismissable layers (dialogs, drawers, popovers, menus, listboxes,\n * tooltips) and the document listeners that route Escape, outside presses and focus changes to\n * them. `useDismiss` registers layers; focus traps, modal isolation and focus restore read the\n * stack. It lives in `getGlobalRegistry('layers')`, so an app that loads both the ESM and the CJS\n * build still has one stack and one set of listeners.\n */\n\n/**\n * z-index of each portal layer. `Portal` adds its nesting depth, so a surface opened from inside\n * another overlay always stacks above it. The values fall back to the defaults of `tokens.css`.\n */\nexport const Z_INDEX = {\n overlay: 'var(--wave-z-overlay, 1000)',\n toast: 'var(--wave-z-toast, 1100)',\n tooltip: 'var(--wave-z-tooltip, 1200)',\n} as const;\n\n/**\n * What kind of surface a layer is. `modal` marks dialog-like surfaces (focus-restore validation and\n * modal isolation look for them); a modal blocks presses and Escape for the layers below it only\n * while its page isolation is active ({@link registerLayerIsolation}). `dialog` marks a non-modal\n * Dialog or Drawer: it shields nothing (no isolation), takes Escape only from inside its tree\n * (`escape: 'inside'`), and the Toaster moves out of its way; focus-restore validation and modal\n * isolation do not count it.\n */\nexport type LayerKind = 'modal' | 'dialog' | 'popover' | 'menu' | 'listbox' | 'tooltip' | 'toast';\n\n/** Why a popup layer is dismissed: Escape, a press outside it, or focus moving outside it. */\nexport type DismissReason = 'escape' | 'outside-press' | 'focus-outside';\n\n/** A registered layer. Getters are allowed, so fields can read the latest options. */\nexport interface LayerRecord {\n /** Unique id; children name it as their `parentId` (through `DismissLayerContext`). */\n id: string;\n /** The enclosing layer (React parentage, which survives portals), or `null`. */\n parentId: string | null;\n kind: LayerKind;\n /** Global open-order counter, assigned by {@link registerLayer} (the passed value is replaced). */\n order: number;\n /** The elements that belong to the layer: its surface, its trigger, extra ignore targets. */\n getElements(): Array<HTMLElement | null>;\n /** The element the layer is anchored to (its trigger); focus traps leave the layer through it. */\n getAnchor(): HTMLElement | null;\n /**\n * Whether Escape dismisses the layer: always (`true`), never (`false`), or only while the key's\n * target or the focused element is in the layer's tree (`'inside'`).\n */\n escape: boolean | 'inside';\n /** Whether a press outside the layer's tree dismisses it; a predicate returning `false` opts out. */\n outsidePress: boolean | ((event: PointerEvent | MouseEvent) => boolean);\n /** Whether focus moving outside the layer's tree dismisses it. */\n focusOutside: boolean;\n /** Called when the layer should close. */\n onDismiss(reason: DismissReason, event: Event): void;\n}\n\n/**\n * Regions (the Toaster viewport) whose content counts as inside **every** layer and whose\n * tabbables join every focus trap's Tab cycle. Modal isolation never makes them inert.\n */\nexport const ALLOW_OUTSIDE_SELECTOR = '[data-wave-focus-trap-allow]';\n\ninterface PressSnapshot {\n /**\n * Layers with outside press enabled whose tree did not contain the pointerdown target. Only these\n * can be dismissed by the click: a layer registered later (opened by that press, or closed and\n * reopened, which registers a new record) is not in it, and a layer that unregisters is removed.\n */\n layers: LayerRecord[];\n}\n\ninterface InstalledListeners {\n remove(): void;\n}\n\ninterface LayerState {\n /** Open layers from bottom to top. A parent always precedes its descendants. */\n stack: LayerRecord[];\n /** Elements registered per layer id (portal wrappers of the layer's descendants). */\n elements: Map<string, Set<HTMLElement>>;\n counter: number;\n press: PressSnapshot | null;\n listeners: InstalledListeners | null;\n /**\n * Called after a layer registers or unregisters (modal isolation re-plans), and after the\n * isolated set changes (the dim-once snapshot).\n */\n subscribers: Set<() => void>;\n /** Ids of layers whose modal isolation currently makes the page inert, with a use count. */\n isolated: Map<string, number>;\n}\n\nfunction getState(): LayerState {\n const state = getGlobalRegistry<LayerState>('layers', () => ({\n stack: [],\n elements: new Map(),\n counter: 0,\n press: null,\n listeners: null,\n subscribers: new Set(),\n isolated: new Map(),\n }));\n // A registry created by an earlier copy of this module (hot reload) may predate these fields.\n state.subscribers ??= new Set();\n state.isolated ??= new Map();\n return state;\n}\n\nfunction notifySubscribers(state: LayerState): void {\n for (const subscriber of Array.from(state.subscribers)) subscriber();\n}\n\nconst ELEMENT_NODE = 1;\n\nfunction findLayer(state: LayerState, id: string | null): LayerRecord | undefined {\n if (id === null) return undefined;\n return state.stack.find((layer) => layer.id === id);\n}\n\n/** Whether `layer` is a (possibly indirect) descendant of the layer `ancestorId`. */\nfunction isDescendantOf(state: LayerState, layer: LayerRecord, ancestorId: string): boolean {\n const visited = new Set<string>([layer.id]);\n let parentId = layer.parentId;\n while (parentId !== null && !visited.has(parentId)) {\n if (parentId === ancestorId) return true;\n visited.add(parentId);\n parentId = findLayer(state, parentId)?.parentId ?? null;\n }\n return false;\n}\n\nfunction containsNode(container: Node | null | undefined, target: Node): boolean {\n return !!container && container.contains(target);\n}\n\nfunction isInsideTreeWithoutAllowList(\n state: LayerState,\n layerId: string,\n target: Node,\n visited: Set<string>,\n): boolean {\n if (visited.has(layerId)) return false;\n visited.add(layerId);\n\n const record = findLayer(state, layerId);\n if (record && record.getElements().some((el) => containsNode(el, target))) return true;\n\n const registered = state.elements.get(layerId);\n if (registered) {\n for (const el of registered) {\n if (containsNode(el, target)) return true;\n }\n }\n\n for (const layer of state.stack) {\n if (\n layer.parentId === layerId &&\n isInsideTreeWithoutAllowList(state, layer.id, target, visited)\n ) {\n return true;\n }\n }\n return false;\n}\n\nfunction isInsideAllowList(target: Node): boolean {\n const el = target.nodeType === ELEMENT_NODE ? (target as Element) : target.parentElement;\n return !!el && el.closest(ALLOW_OUTSIDE_SELECTOR) !== null;\n}\n\n/**\n * Whether `target` belongs to the tree of the layer `layerId`:\n * - the layer's own elements (`getElements()`),\n * - elements registered for it with {@link registerLayerElement} (portal wrappers of overlays\n * rendered inside it — React parentage survives portals, the DOM does not),\n * - every descendant layer's tree, and\n * - regions matching {@link ALLOW_OUTSIDE_SELECTOR} (the Toaster viewport), which count as inside\n * every layer.\n */\nexport function isInsideLayerTree(layerId: string, target: Node): boolean {\n if (isInsideAllowList(target)) return true;\n return isInsideTreeWithoutAllowList(getState(), layerId, target, new Set());\n}\n\n/**\n * Compares two layers for stacking: `> 0` when `a` is above `b`. A descendant layer is above its\n * ancestor; otherwise the layer whose tree opened later is above. (A parent that registers after\n * its descendants — effects run child-first when both open in one commit — takes the place of its\n * earliest descendant.)\n */\nexport function compareLayers(a: LayerRecord, b: LayerRecord): number {\n if (a === b || a.id === b.id) return 0;\n const state = getState();\n if (isDescendantOf(state, a, b.id)) return 1;\n if (isDescendantOf(state, b, a.id)) return -1;\n const indexA = state.stack.indexOf(a);\n const indexB = state.stack.indexOf(b);\n if (indexA !== -1 && indexB !== -1) return indexA - indexB;\n return a.order - b.order;\n}\n\n/** The topmost open layer (optionally the topmost one matching `predicate`), or `null`. */\nexport function getTopmostLayer(predicate?: (layer: LayerRecord) => boolean): LayerRecord | null {\n const { stack } = getState();\n for (let i = stack.length - 1; i >= 0; i--) {\n const layer = stack[i];\n if (!predicate || predicate(layer)) return layer;\n }\n return null;\n}\n\n/**\n * Marks the layer `layerId` as isolating the page: `useModalIsolation` made everything outside its\n * tree inert (Dialog, Drawer). While it is open, the topmost isolating layer is a barrier — layers\n * stacked below it (its ancestors and older siblings) are never dismissed by outside presses and\n * never receive Escape, the way a modal blocks the page behind it. Layers above it (its\n * descendants, or a modal opened later) are unaffected. A `kind: 'modal'` layer without isolation\n * (a transient popup such as the DatePicker calendar, whose page stays interactive) is no barrier.\n * Returns the unregister function; registrations are counted, so the layer stays marked until\n * every registration is removed.\n */\nexport function registerLayerIsolation(layerId: string): () => void {\n const state = getState();\n const { isolated } = state;\n const previous = isolated.get(layerId) ?? 0;\n isolated.set(layerId, previous + 1);\n // Subscribers (the dim-once snapshot of Dialog and Drawer) read isolation, which changes without\n // a layer registering: notify when the isolated set gains the layer, and again when it loses it.\n if (previous === 0) notifySubscribers(state);\n let registered = true;\n return () => {\n if (!registered) return;\n registered = false;\n const count = (isolated.get(layerId) ?? 1) - 1;\n if (count > 0) isolated.set(layerId, count);\n else if (isolated.delete(layerId)) notifySubscribers(state);\n };\n}\n\n/** The topmost open layer whose modal isolation is active, or `null`. */\nfunction getIsolationBarrier(state: LayerState): LayerRecord | null {\n if (state.isolated.size === 0) return null;\n return getTopmostLayer((layer) => state.isolated.has(layer.id));\n}\n\n/**\n * Whether an open layer whose modal isolation is active ({@link registerLayerIsolation}) is\n * stacked below the layer `layerId` (`compareLayers(self, other) > 0`). A `layerId` that is not\n * registered yet (the render that opens it) counts as the topmost layer, so every isolating open\n * layer counts. The layer itself and its descendants never count. Read during render through\n * `useSyncExternalStore(subscribeLayers, …)` (the dim-once rule of Dialog and Drawer).\n */\nexport function hasIsolatingModalBelow(layerId: string): boolean {\n const state = getState();\n if (state.isolated.size === 0) return false;\n const self = findLayer(state, layerId);\n return state.stack.some(\n (layer) =>\n layer.id !== layerId &&\n state.isolated.has(layer.id) &&\n !isDescendantOf(state, layer, layerId) &&\n (!self || compareLayers(self, layer) > 0),\n );\n}\n\n/** Whether `layer` is stacked below `barrier` (neither the barrier itself nor above it). */\nfunction isBelowBarrier(layer: LayerRecord, barrier: LayerRecord | null): boolean {\n return !!barrier && barrier !== layer && compareLayers(barrier, layer) > 0;\n}\n\n/**\n * Whether `layer` is stacked below the topmost open **isolating** modal (see\n * {@link registerLayerIsolation}). Such a layer is behind the modal and inert: outside presses\n * never dismiss it and Escape never reaches it. The modal's descendants are above it and stay\n * reachable; a modal-kind layer without isolation shields nothing.\n */\nexport function isBehindIsolatingModal(layer: LayerRecord): boolean {\n return isBelowBarrier(layer, getIsolationBarrier(getState()));\n}\n\n/**\n * Calls `listener` synchronously after any layer registers or unregisters (in the committing\n * component's layout effect, so a modal can re-plan its isolation before a newly opened modal\n * moves focus), and after a layer's modal isolation starts or ends ({@link registerLayerIsolation}).\n * Returns the unsubscribe function.\n */\nexport function subscribeLayers(listener: () => void): () => void {\n const { subscribers } = getState();\n subscribers.add(listener);\n return () => {\n subscribers.delete(listener);\n };\n}\n\n/** The open layers from bottom to top (a copy; a parent always precedes its descendants). */\nexport function getOpenLayers(): LayerRecord[] {\n return [...getState().stack];\n}\n\n/** The open layer with this id, or `null`. */\nexport function getLayer(layerId: string): LayerRecord | null {\n return findLayer(getState(), layerId) ?? null;\n}\n\n/** Whether the open layer `layerId` is a (possibly indirect) descendant of `ancestorId`. */\nexport function isDescendantLayer(layerId: string, ancestorId: string): boolean {\n const state = getState();\n const layer = findLayer(state, layerId);\n return !!layer && isDescendantOf(state, layer, ancestorId);\n}\n\n/**\n * Every element that makes up the tree of `layerId`: the layer's own elements, the elements\n * registered for it and the same for each descendant layer (the allow-list is not included).\n * With `includeOwnElements: false` the layer's own `getElements()` are left out (its descendants'\n * are still included).\n */\nexport function getLayerTreeElements(\n layerId: string,\n options?: { includeOwnElements?: boolean },\n): HTMLElement[] {\n const state = getState();\n const result: HTMLElement[] = [];\n const includeOwn = options?.includeOwnElements ?? true;\n const visit = (id: string, visited: Set<string>) => {\n if (visited.has(id)) return;\n visited.add(id);\n const record = findLayer(state, id);\n if (record && (includeOwn || id !== layerId)) {\n for (const el of record.getElements()) {\n if (el && !result.includes(el)) result.push(el);\n }\n }\n for (const el of state.elements.get(id) ?? []) {\n if (!result.includes(el)) result.push(el);\n }\n for (const layer of state.stack) {\n if (layer.parentId === id) visit(layer.id, visited);\n }\n };\n visit(layerId, new Set());\n return result;\n}\n\n/**\n * Whether focusing `el` would send focus behind another open modal layer: the topmost open modal\n * layer other than `exceptLayerId` (and its descendants, which close with it) does not contain\n * `el` in its tree. An element inside that modal's tree (for example an opener inside a parent\n * dialog) is reachable and returns `false`. Used to validate focus-restore targets.\n */\nexport function isInsideOtherOpenModal(el: Element, exceptLayerId?: string): boolean {\n const state = getState();\n for (let i = state.stack.length - 1; i >= 0; i--) {\n const layer = state.stack[i];\n if (layer.kind !== 'modal') continue;\n if (exceptLayerId !== undefined) {\n if (layer.id === exceptLayerId || isDescendantOf(state, layer, exceptLayerId)) continue;\n }\n return !isInsideLayerTree(layer.id, el);\n }\n return false;\n}\n\n/**\n * Registers an element (a portal wrapper) as part of the layer `layerId`, so presses and focus\n * inside it count as inside that layer and its ancestors. Returns the unregister function (usable\n * as a React 19 ref-callback cleanup). The layer does not need to be registered yet.\n */\nexport function registerLayerElement(layerId: string, el: HTMLElement): () => void {\n const state = getState();\n let set = state.elements.get(layerId);\n if (!set) {\n set = new Set();\n state.elements.set(layerId, set);\n }\n set.add(el);\n return () => {\n const current = state.elements.get(layerId);\n if (!current) return;\n current.delete(el);\n if (current.size === 0) state.elements.delete(layerId);\n };\n}\n\n/**\n * Registers an open layer and returns its unregister function. `record.order` is set to the next\n * value of the global open-order counter. The layer is placed on top of the stack — or, when some\n * of its descendants registered first (same commit), directly below the earliest of them.\n */\nexport function registerLayer(record: LayerRecord): () => void {\n const state = getState();\n state.counter += 1;\n record.order = state.counter;\n\n const firstDescendant = state.stack.findIndex((layer) => isDescendantOf(state, layer, record.id));\n if (firstDescendant === -1) state.stack.push(record);\n else state.stack.splice(firstDescendant, 0, record);\n\n ensureListeners(state);\n notifySubscribers(state);\n\n let registered = true;\n return () => {\n if (!registered) return;\n registered = false;\n const index = state.stack.indexOf(record);\n if (index !== -1) state.stack.splice(index, 1);\n if (state.press) {\n state.press.layers = state.press.layers.filter((layer) => layer !== record);\n }\n if (state.stack.length === 0) removeListeners(state);\n notifySubscribers(state);\n };\n}\n\n// ---------------------------------------------------------------------------\n// Document listeners\n// ---------------------------------------------------------------------------\n\nfunction getEventTargetNode(event: Event): Node | null {\n const target = event.target as { nodeType?: unknown } | null;\n return target && typeof target.nodeType === 'number' ? (target as Node) : null;\n}\n\n/** Topmost first: descendants before their ancestors. */\nfunction sortTopmostFirst(layers: LayerRecord[]): LayerRecord[] {\n return [...layers].sort((a, b) => compareLayers(b, a));\n}\n\n/**\n * The layer that handles an Escape whose target / focused element is `target` / `active`.\n * Candidates are the escape-enabled layers that are not stacked below the topmost isolating modal\n * (a modal that ignores Escape never lets the key close something inert behind it — its ancestor\n * dialog as much as an older sibling); a layer with `escape: 'inside'` is a candidate only while\n * its tree contains them (the toast region counts as inside every layer):\n * 1. the innermost layer whose tree contains them (the topmost such layer) is the focus scope;\n * 2. the topmost candidate of that scope's subtree handles it — the scope itself or an open\n * descendant above it (a tooltip or popover opened from the focused dialog closes first, while\n * a sibling of the focused layer is not in its subtree);\n * 3. else the topmost candidate whose tree contains them (an ancestor);\n * 4. else — no layer contains them, or none of the containing layers takes Escape — the global\n * topmost candidate.\n */\nfunction findEscapeHandler(\n state: LayerState,\n target: Node | null,\n active: Element | null,\n): LayerRecord | null {\n const barrier = getIsolationBarrier(state);\n const contains = (layer: LayerRecord) =>\n (!!target && isInsideLayerTree(layer.id, target)) ||\n (!!active && isInsideLayerTree(layer.id, active));\n const isCandidate = (layer: LayerRecord) =>\n (layer.escape === true || (layer.escape === 'inside' && contains(layer))) &&\n !isBelowBarrier(layer, barrier);\n const scope = getTopmostLayer(contains);\n const handler = scope\n ? (getTopmostLayer(\n (layer) =>\n isCandidate(layer) && (layer === scope || isDescendantOf(state, layer, scope.id)),\n ) ?? getTopmostLayer((layer) => isCandidate(layer) && contains(layer)))\n : null;\n return handler ?? getTopmostLayer(isCandidate);\n}\n\n/** Keys that activate the focused control with a synthetic click. */\nfunction isClickActivationKey(key: string): boolean {\n return key === 'Enter' || key === ' ' || key === 'Spacebar';\n}\n\nfunction handleKeyDown(event: KeyboardEvent): void {\n const state = getState();\n if (event.key === 'Escape' || event.key === 'Esc') {\n if (event.defaultPrevented || event.isComposing) return;\n const handler = findEscapeHandler(state, getEventTargetNode(event), document.activeElement);\n if (!handler) return;\n event.preventDefault();\n handler.onDismiss('escape', event);\n return;\n }\n // A keyboard-activated click (Enter/Space) must not dismiss layers recorded by an unrelated\n // earlier pointerdown. Other keys keep the pending press: modifiers held for a Shift/Ctrl+click\n // auto-repeat their keydown while the pointer is down.\n if (isClickActivationKey(event.key)) state.press = null;\n}\n\nfunction handlePointerDown(event: PointerEvent): void {\n const state = getState();\n const target = getEventTargetNode(event);\n // Only a primary press is followed by a click (right/middle buttons fire contextmenu/auxclick).\n if (!target || event.button !== 0) {\n state.press = null;\n return;\n }\n const barrier = getIsolationBarrier(state);\n const layers = state.stack.filter((layer) => {\n const { outsidePress } = layer;\n if (!outsidePress) return false;\n // A layer behind an open isolating modal (its parent dialog, or a dialog below a sibling\n // modal opened from inside it) is inert and not reachable: presses inside that modal, or on\n // its backdrop, are not \"outside\" presses for it.\n if (isBelowBarrier(layer, barrier)) return false;\n if (isInsideLayerTree(layer.id, target)) return false;\n return typeof outsidePress !== 'function' || outsidePress(event) !== false;\n });\n state.press = { layers };\n}\n\n/**\n * How long (ms) a touch, pen or unknown-device press waits for its click after the pointerup. A\n * tap's click follows within about 350 ms (at most the double-tap delay); a press that gets no\n * click (a long press that opened the context menu, a tap on a non-clickable area) is forgotten\n * after this, so a later programmatic `click()` cannot complete it.\n */\nconst GESTURE_CLICK_TIMEOUT_MS = 1000;\n\n/**\n * A mouse click is dispatched right after its pointerup, in the same task. When none follows (the\n * pointer was released over another window or element tree), a mouse press is forgotten on the\n * next macrotask, so a later programmatic `click()` cannot complete it. Touch and stylus taps are\n * turned into a click by a separate gesture event in a later task (Apple Pencil on iPadOS and\n * Android styluses report `pointerType: 'pen'`, and an unknown device type `''` may behave the\n * same way), so every other pointer type keeps its press for {@link GESTURE_CLICK_TIMEOUT_MS}.\n * The next pointerdown, pointercancel, contextmenu or Enter/Space forgets a press earlier.\n */\nfunction handlePointerUp(event: PointerEvent): void {\n const press = getState().press;\n if (!press) return;\n const timeout = event.pointerType === 'mouse' ? 0 : GESTURE_CLICK_TIMEOUT_MS;\n setTimeout(() => {\n const current = getState();\n if (current.press === press) current.press = null;\n }, timeout);\n}\n\n/** A cancelled pointer stream, or a context menu (a long press, a Mac Ctrl+click), gets no click. */\nfunction forgetPress(): void {\n getState().press = null;\n}\n\nfunction handleClick(event: MouseEvent): void {\n const state = getState();\n const press = state.press;\n state.press = null;\n if (!press) return;\n const target = getEventTargetNode(event);\n const toDismiss = press.layers.filter(\n (layer) => !(target && isInsideLayerTree(layer.id, target)),\n );\n for (const layer of sortTopmostFirst(toDismiss)) {\n // An earlier layer's onDismiss may already have unregistered this one.\n if (state.stack.includes(layer)) layer.onDismiss('outside-press', event);\n }\n}\n\nfunction handleFocusIn(event: FocusEvent): void {\n const target = getEventTargetNode(event);\n if (!target) return;\n const candidates = getState().stack.filter(\n (layer) => layer.focusOutside && !isInsideLayerTree(layer.id, target),\n );\n if (candidates.length === 0) return;\n // Not in this dispatch: React applies `autoFocus` in the layout phase of the commit that mounts\n // a surface, before that surface's portal wrapper and dismiss layer register. A field focused\n // as a popover or dialog opens inside the layer is inside its tree once that commit has run.\n queueMicrotask(() => dismissFocusOutside(candidates, target, event));\n}\n\n/**\n * Dismisses each of `candidates` that is still open and whose tree still contains neither the\n * focusin `target` nor the element focused now (focus that came back inside keeps it open; focus\n * lost to `<body>` after leaving does not).\n */\nfunction dismissFocusOutside(candidates: LayerRecord[], target: Node, event: FocusEvent): void {\n const state = getState();\n const active = (target.ownerDocument ?? document).activeElement;\n const toDismiss = candidates.filter(\n (layer) =>\n state.stack.includes(layer) &&\n !isInsideLayerTree(layer.id, target) &&\n !(active && isInsideLayerTree(layer.id, active)),\n );\n for (const layer of sortTopmostFirst(toDismiss)) {\n // An earlier layer's onDismiss may already have unregistered this one.\n if (state.stack.includes(layer)) layer.onDismiss('focus-outside', event);\n }\n}\n\nfunction ensureListeners(state: LayerState): void {\n if (state.listeners || typeof document === 'undefined') return;\n const doc = document;\n doc.addEventListener('keydown', handleKeyDown);\n doc.addEventListener('pointerdown', handlePointerDown, true);\n doc.addEventListener('pointerup', handlePointerUp, true);\n doc.addEventListener('pointercancel', forgetPress, true);\n doc.addEventListener('contextmenu', forgetPress, true);\n doc.addEventListener('click', handleClick);\n doc.addEventListener('focusin', handleFocusIn, true);\n state.listeners = {\n remove() {\n doc.removeEventListener('keydown', handleKeyDown);\n doc.removeEventListener('pointerdown', handlePointerDown, true);\n doc.removeEventListener('pointerup', handlePointerUp, true);\n doc.removeEventListener('pointercancel', forgetPress, true);\n doc.removeEventListener('contextmenu', forgetPress, true);\n doc.removeEventListener('click', handleClick);\n doc.removeEventListener('focusin', handleFocusIn, true);\n },\n };\n}\n\nfunction removeListeners(state: LayerState): void {\n state.listeners?.remove();\n state.listeners = null;\n state.press = null;\n}\n"],"mappings":";;AAcA,IAAaA,IAAU;CACrB,SAAS;CACT,OAAO;CACP,SAAS;AACX,GA6CaC,IAAyB;AAgCtC,SAASC,IAAuB;CAC9B,IAAMC,IAAQC,EAA8B,iBAAiB;EAC3D,OAAO,CAAC;EACR,0BAAU,IAAI,IAAI;EAClB,SAAS;EACT,OAAO;EACP,WAAW;EACX,6BAAa,IAAI,IAAI;EACrB,0BAAU,IAAI,IAAI;CACpB,EAAE;CAIF,OAFA,EAAM,gCAAgB,IAAI,IAAI,GAC9B,EAAM,6BAAa,IAAI,IAAI,GACpBD;AACT;AAEA,SAASE,EAAkB,GAAyB;CAClD,KAAK,IAAMC,KAAc,MAAM,KAAKH,EAAM,WAAW,GAAG,EAAW;AACrE;AAEA,IAAMI,IAAe;AAErB,SAASC,EAAU,GAAmB,GAA4C;CAChF,IAAIC,MAAO,MACX,OAAON,EAAM,MAAM,MAAM,MAAUO,EAAM,OAAOD,CAAE;AACpD;AAGA,SAASE,EAAe,GAAmB,GAAoB,GAA6B;CAC1F,IAAMC,oBAAU,IAAI,IAAY,CAACF,EAAM,EAAE,CAAC,GACtCG,IAAWH,EAAM;CACrB,OAAOG,MAAa,QAAQ,CAACD,EAAQ,IAAIC,CAAQ,IAAG;EAClD,IAAIA,MAAaC,GAAY,OAAO;EAEpC,AADAF,EAAQ,IAAIC,CAAQ,GACpB,IAAWL,EAAUL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iBAAiB,eAAeN,GAAa,EAAI,GACrDM,EAAI,iBAAiB,SAASL,CAAW,GACzCK,EAAI,iBAAiB,WAAWH,GAAe,EAAI,GACnD,EAAM,YAAY,EAChB,SAAS;EAOP,AANAG,EAAI,oBAAoB,WAAWd,CAAa,GAChDc,EAAI,oBAAoB,eAAeZ,GAAmB,EAAI,GAC9DY,EAAI,oBAAoB,aAAaT,GAAiB,EAAI,GAC1DS,EAAI,oBAAoB,iBAAiBN,GAAa,EAAI,GAC1DM,EAAI,oBAAoB,eAAeN,GAAa,EAAI,GACxDM,EAAI,oBAAoB,SAASL,CAAW,GAC5CK,EAAI,oBAAoB,WAAWH,GAAe,EAAI;CACxD,EACF;AACF;AAEA,SAASvB,EAAgB,GAAyB;CAGhD,AAFA5D,EAAM,WAAW,OAAO,GACxB,EAAM,YAAY,MAClB,EAAM,QAAQ;AAChB"}
|
|
1
|
+
{"version":3,"file":"layers.mjs","names":["Z_INDEX","ALLOW_OUTSIDE_SELECTOR","modalAllowProps","getState","state","getGlobalRegistry","notifySubscribers","subscriber","ELEMENT_NODE","findLayer","id","layer","isDescendantOf","visited","parentId","ancestorId","containsNode","container","target","isInsideTreeWithoutAllowList","layerId","record","el","registered","isInsideAllowList","isInsideLayerTree","compareLayers","a","b","indexA","indexB","getTopmostLayer","i","stack","predicate","registerLayerIsolation","previous","isolated","count","getIsolationBarrier","hasIsolatingModalBelow","self","isBelowBarrier","barrier","subscribeLayers","subscribers","listener","hasOpenModal","getOpenLayers","getLayer","isDescendantLayer","getLayerTreeElements","result","includeOwn","options","visit","isInsideOtherOpenModal","exceptLayerId","registerLayerElement","set","current","registerLayer","firstDescendant","ensureListeners","index","removeListeners","getEventTargetNode","event","sortTopmostFirst","layers","findEscapeHandler","contains","active","isCandidate","scope","isClickActivationKey","key","handleKeyDown","handler","handlePointerDown","outsidePress","GESTURE_CLICK_TIMEOUT_MS","handlePointerUp","press","timeout","forgetPress","handleClick","toDismiss","handleFocusIn","candidates","dismissFocusOutside","doc"],"sources":["../../src/lib/layers.ts"],"sourcesContent":["import { getGlobalRegistry } from './globalRegistry';\n\n/**\n * The shared stack of open dismissable layers (dialogs, drawers, popovers, menus, listboxes,\n * tooltips) and the document listeners that route Escape, outside presses and focus changes to\n * them. `useDismiss` registers layers; focus traps, modal isolation and focus restore read the\n * stack. It lives in `getGlobalRegistry('layers')`, so an app that loads both the ESM and the CJS\n * build still has one stack and one set of listeners.\n */\n\n/**\n * z-index of each portal layer. `Portal` adds its nesting depth, so a surface opened from inside\n * another overlay always stacks above it. The values fall back to the defaults of `tokens.css`.\n */\nexport const Z_INDEX = {\n overlay: 'var(--wave-z-overlay, 1000)',\n toast: 'var(--wave-z-toast, 1100)',\n tooltip: 'var(--wave-z-tooltip, 1200)',\n} as const;\n\n/**\n * What kind of surface a layer is. `modal` marks dialog-like surfaces (focus-restore validation and\n * modal isolation look for them); a modal blocks presses and Escape for the layers below it only\n * while its page isolation is active ({@link registerLayerIsolation}). `dialog` marks a non-modal\n * Dialog or Drawer: it shields nothing (no isolation), takes Escape only from inside its tree\n * (`escape: 'inside'`), and the Toaster moves out of its way; focus-restore validation and modal\n * isolation do not count it.\n */\nexport type LayerKind = 'modal' | 'dialog' | 'popover' | 'menu' | 'listbox' | 'tooltip' | 'toast';\n\n/** Why a popup layer is dismissed: Escape, a press outside it, or focus moving outside it. */\nexport type DismissReason = 'escape' | 'outside-press' | 'focus-outside';\n\n/** A registered layer. Getters are allowed, so fields can read the latest options. */\nexport interface LayerRecord {\n /** Unique id; children name it as their `parentId` (through `DismissLayerContext`). */\n id: string;\n /** The enclosing layer (React parentage, which survives portals), or `null`. */\n parentId: string | null;\n kind: LayerKind;\n /** Global open-order counter, assigned by {@link registerLayer} (the passed value is replaced). */\n order: number;\n /** The elements that belong to the layer: its surface, its trigger, extra ignore targets. */\n getElements(): Array<HTMLElement | null>;\n /** The element the layer is anchored to (its trigger); focus traps leave the layer through it. */\n getAnchor(): HTMLElement | null;\n /**\n * Whether Escape dismisses the layer: always (`true`), never (`false`), or only while the key's\n * target or the focused element is in the layer's tree (`'inside'`).\n */\n escape: boolean | 'inside';\n /** Whether a press outside the layer's tree dismisses it; a predicate returning `false` opts out. */\n outsidePress: boolean | ((event: PointerEvent | MouseEvent) => boolean);\n /** Whether focus moving outside the layer's tree dismisses it. */\n focusOutside: boolean;\n /** Called when the layer should close. */\n onDismiss(reason: DismissReason, event: Event): void;\n}\n\n/**\n * Regions (the Toaster viewport) whose content counts as inside **every** layer and whose\n * tabbables join every focus trap's Tab cycle. Modal isolation never makes them inert.\n */\nexport const ALLOW_OUTSIDE_SELECTOR = '[data-wave-focus-trap-allow]';\n\n/**\n * Props that mark an app-owned region (a notification area, a live status bar) so that WaveUI's\n * modal surfaces leave it usable. Spread them on the region's element: `<div {...modalAllowProps}>`.\n * Over an open Dialog or Drawer the region\n *\n * - counts as inside every dismiss layer, so a press in it closes nothing;\n * - has its tabbable elements in the Tab cycle of every focus trap;\n * - is never made `inert` by the modal's page isolation.\n *\n * The attribute it sets, `data-wave-focus-trap-allow`, is the one the Toaster's own region\n * carries, and it is a stable contract.\n */\nexport const modalAllowProps = { 'data-wave-focus-trap-allow': '' } as const;\n\ninterface PressSnapshot {\n /**\n * Layers with outside press enabled whose tree did not contain the pointerdown target. Only these\n * can be dismissed by the click: a layer registered later (opened by that press, or closed and\n * reopened, which registers a new record) is not in it, and a layer that unregisters is removed.\n */\n layers: LayerRecord[];\n}\n\ninterface InstalledListeners {\n remove(): void;\n}\n\ninterface LayerState {\n /** Open layers from bottom to top. A parent always precedes its descendants. */\n stack: LayerRecord[];\n /** Elements registered per layer id (portal wrappers of the layer's descendants). */\n elements: Map<string, Set<HTMLElement>>;\n counter: number;\n press: PressSnapshot | null;\n listeners: InstalledListeners | null;\n /**\n * Called after a layer registers or unregisters (modal isolation re-plans), and after the\n * isolated set changes (the dim-once snapshot).\n */\n subscribers: Set<() => void>;\n /** Ids of layers whose modal isolation currently makes the page inert, with a use count. */\n isolated: Map<string, number>;\n}\n\nfunction getState(): LayerState {\n const state = getGlobalRegistry<LayerState>('layers', () => ({\n stack: [],\n elements: new Map(),\n counter: 0,\n press: null,\n listeners: null,\n subscribers: new Set(),\n isolated: new Map(),\n }));\n // A registry created by an earlier copy of this module (hot reload) may predate these fields.\n state.subscribers ??= new Set();\n state.isolated ??= new Map();\n return state;\n}\n\nfunction notifySubscribers(state: LayerState): void {\n for (const subscriber of Array.from(state.subscribers)) subscriber();\n}\n\nconst ELEMENT_NODE = 1;\n\nfunction findLayer(state: LayerState, id: string | null): LayerRecord | undefined {\n if (id === null) return undefined;\n return state.stack.find((layer) => layer.id === id);\n}\n\n/** Whether `layer` is a (possibly indirect) descendant of the layer `ancestorId`. */\nfunction isDescendantOf(state: LayerState, layer: LayerRecord, ancestorId: string): boolean {\n const visited = new Set<string>([layer.id]);\n let parentId = layer.parentId;\n while (parentId !== null && !visited.has(parentId)) {\n if (parentId === ancestorId) return true;\n visited.add(parentId);\n parentId = findLayer(state, parentId)?.parentId ?? null;\n }\n return false;\n}\n\nfunction containsNode(container: Node | null | undefined, target: Node): boolean {\n return !!container && container.contains(target);\n}\n\nfunction isInsideTreeWithoutAllowList(\n state: LayerState,\n layerId: string,\n target: Node,\n visited: Set<string>,\n): boolean {\n if (visited.has(layerId)) return false;\n visited.add(layerId);\n\n const record = findLayer(state, layerId);\n if (record && record.getElements().some((el) => containsNode(el, target))) return true;\n\n const registered = state.elements.get(layerId);\n if (registered) {\n for (const el of registered) {\n if (containsNode(el, target)) return true;\n }\n }\n\n for (const layer of state.stack) {\n if (\n layer.parentId === layerId &&\n isInsideTreeWithoutAllowList(state, layer.id, target, visited)\n ) {\n return true;\n }\n }\n return false;\n}\n\nfunction isInsideAllowList(target: Node): boolean {\n const el = target.nodeType === ELEMENT_NODE ? (target as Element) : target.parentElement;\n return !!el && el.closest(ALLOW_OUTSIDE_SELECTOR) !== null;\n}\n\n/**\n * Whether `target` belongs to the tree of the layer `layerId`:\n * - the layer's own elements (`getElements()`),\n * - elements registered for it with {@link registerLayerElement} (portal wrappers of overlays\n * rendered inside it — React parentage survives portals, the DOM does not),\n * - every descendant layer's tree, and\n * - regions matching {@link ALLOW_OUTSIDE_SELECTOR} (the Toaster viewport), which count as inside\n * every layer.\n */\nexport function isInsideLayerTree(layerId: string, target: Node): boolean {\n if (isInsideAllowList(target)) return true;\n return isInsideTreeWithoutAllowList(getState(), layerId, target, new Set());\n}\n\n/**\n * Compares two layers for stacking: `> 0` when `a` is above `b`. A descendant layer is above its\n * ancestor; otherwise the layer whose tree opened later is above. (A parent that registers after\n * its descendants — effects run child-first when both open in one commit — takes the place of its\n * earliest descendant.)\n */\nexport function compareLayers(a: LayerRecord, b: LayerRecord): number {\n if (a === b || a.id === b.id) return 0;\n const state = getState();\n if (isDescendantOf(state, a, b.id)) return 1;\n if (isDescendantOf(state, b, a.id)) return -1;\n const indexA = state.stack.indexOf(a);\n const indexB = state.stack.indexOf(b);\n if (indexA !== -1 && indexB !== -1) return indexA - indexB;\n return a.order - b.order;\n}\n\n/** The topmost open layer (optionally the topmost one matching `predicate`), or `null`. */\nexport function getTopmostLayer(predicate?: (layer: LayerRecord) => boolean): LayerRecord | null {\n const { stack } = getState();\n for (let i = stack.length - 1; i >= 0; i--) {\n const layer = stack[i];\n if (!predicate || predicate(layer)) return layer;\n }\n return null;\n}\n\n/**\n * Marks the layer `layerId` as isolating the page: `useModalIsolation` made everything outside its\n * tree inert (Dialog, Drawer). While it is open, the topmost isolating layer is a barrier — layers\n * stacked below it (its ancestors and older siblings) are never dismissed by outside presses and\n * never receive Escape, the way a modal blocks the page behind it. Layers above it (its\n * descendants, or a modal opened later) are unaffected. A `kind: 'modal'` layer without isolation\n * (a transient popup such as the DatePicker calendar, whose page stays interactive) is no barrier.\n * Returns the unregister function; registrations are counted, so the layer stays marked until\n * every registration is removed.\n */\nexport function registerLayerIsolation(layerId: string): () => void {\n const state = getState();\n const { isolated } = state;\n const previous = isolated.get(layerId) ?? 0;\n isolated.set(layerId, previous + 1);\n // Subscribers (the dim-once snapshot of Dialog and Drawer) read isolation, which changes without\n // a layer registering: notify when the isolated set gains the layer, and again when it loses it.\n if (previous === 0) notifySubscribers(state);\n let registered = true;\n return () => {\n if (!registered) return;\n registered = false;\n const count = (isolated.get(layerId) ?? 1) - 1;\n if (count > 0) isolated.set(layerId, count);\n else if (isolated.delete(layerId)) notifySubscribers(state);\n };\n}\n\n/** The topmost open layer whose modal isolation is active, or `null`. */\nfunction getIsolationBarrier(state: LayerState): LayerRecord | null {\n if (state.isolated.size === 0) return null;\n return getTopmostLayer((layer) => state.isolated.has(layer.id));\n}\n\n/**\n * Whether an open layer whose modal isolation is active ({@link registerLayerIsolation}) is\n * stacked below the layer `layerId` (`compareLayers(self, other) > 0`). A `layerId` that is not\n * registered yet (the render that opens it) counts as the topmost layer, so every isolating open\n * layer counts. The layer itself and its descendants never count. Read during render through\n * `useSyncExternalStore(subscribeLayers, …)` (the dim-once rule of Dialog and Drawer).\n */\nexport function hasIsolatingModalBelow(layerId: string): boolean {\n const state = getState();\n if (state.isolated.size === 0) return false;\n const self = findLayer(state, layerId);\n return state.stack.some(\n (layer) =>\n layer.id !== layerId &&\n state.isolated.has(layer.id) &&\n !isDescendantOf(state, layer, layerId) &&\n (!self || compareLayers(self, layer) > 0),\n );\n}\n\n/** Whether `layer` is stacked below `barrier` (neither the barrier itself nor above it). */\nfunction isBelowBarrier(layer: LayerRecord, barrier: LayerRecord | null): boolean {\n return !!barrier && barrier !== layer && compareLayers(barrier, layer) > 0;\n}\n\n/**\n * Whether `layer` is stacked below the topmost open **isolating** modal (see\n * {@link registerLayerIsolation}). Such a layer is behind the modal and inert: outside presses\n * never dismiss it and Escape never reaches it. The modal's descendants are above it and stay\n * reachable; a modal-kind layer without isolation shields nothing.\n */\nexport function isBehindIsolatingModal(layer: LayerRecord): boolean {\n return isBelowBarrier(layer, getIsolationBarrier(getState()));\n}\n\n/**\n * Calls `listener` synchronously after any layer registers or unregisters (in the committing\n * component's layout effect, so a modal can re-plan its isolation before a newly opened modal\n * moves focus), and after a layer's modal isolation starts or ends ({@link registerLayerIsolation}).\n * Returns the unsubscribe function.\n */\nexport function subscribeLayers(listener: () => void): () => void {\n const { subscribers } = getState();\n subscribers.add(listener);\n return () => {\n subscribers.delete(listener);\n };\n}\n\n/**\n * Whether a modal surface is open now: a layer of kind `'modal'` (a Dialog, an overlay Drawer, an\n * alert, the DatePicker's calendar, or your own `useDismiss({ kind: 'modal' })`). A non-modal\n * surface is no modal. Server-safe: `false` when no layer is registered, as on the server.\n */\nexport function hasOpenModal(): boolean {\n return getState().stack.some((layer) => layer.kind === 'modal');\n}\n\n/** The open layers from bottom to top (a copy; a parent always precedes its descendants). */\nexport function getOpenLayers(): LayerRecord[] {\n return [...getState().stack];\n}\n\n/** The open layer with this id, or `null`. */\nexport function getLayer(layerId: string): LayerRecord | null {\n return findLayer(getState(), layerId) ?? null;\n}\n\n/** Whether the open layer `layerId` is a (possibly indirect) descendant of `ancestorId`. */\nexport function isDescendantLayer(layerId: string, ancestorId: string): boolean {\n const state = getState();\n const layer = findLayer(state, layerId);\n return !!layer && isDescendantOf(state, layer, ancestorId);\n}\n\n/**\n * Every element that makes up the tree of `layerId`: the layer's own elements, the elements\n * registered for it and the same for each descendant layer (the allow-list is not included).\n * With `includeOwnElements: false` the layer's own `getElements()` are left out (its descendants'\n * are still included).\n */\nexport function getLayerTreeElements(\n layerId: string,\n options?: { includeOwnElements?: boolean },\n): HTMLElement[] {\n const state = getState();\n const result: HTMLElement[] = [];\n const includeOwn = options?.includeOwnElements ?? true;\n const visit = (id: string, visited: Set<string>) => {\n if (visited.has(id)) return;\n visited.add(id);\n const record = findLayer(state, id);\n if (record && (includeOwn || id !== layerId)) {\n for (const el of record.getElements()) {\n if (el && !result.includes(el)) result.push(el);\n }\n }\n for (const el of state.elements.get(id) ?? []) {\n if (!result.includes(el)) result.push(el);\n }\n for (const layer of state.stack) {\n if (layer.parentId === id) visit(layer.id, visited);\n }\n };\n visit(layerId, new Set());\n return result;\n}\n\n/**\n * Whether focusing `el` would send focus behind another open modal layer: the topmost open modal\n * layer other than `exceptLayerId` (and its descendants, which close with it) does not contain\n * `el` in its tree. An element inside that modal's tree (for example an opener inside a parent\n * dialog) is reachable and returns `false`. Used to validate focus-restore targets.\n */\nexport function isInsideOtherOpenModal(el: Element, exceptLayerId?: string): boolean {\n const state = getState();\n for (let i = state.stack.length - 1; i >= 0; i--) {\n const layer = state.stack[i];\n if (layer.kind !== 'modal') continue;\n if (exceptLayerId !== undefined) {\n if (layer.id === exceptLayerId || isDescendantOf(state, layer, exceptLayerId)) continue;\n }\n return !isInsideLayerTree(layer.id, el);\n }\n return false;\n}\n\n/**\n * Registers an element (a portal wrapper) as part of the layer `layerId`, so presses and focus\n * inside it count as inside that layer and its ancestors. Returns the unregister function (usable\n * as a React 19 ref-callback cleanup). The layer does not need to be registered yet.\n */\nexport function registerLayerElement(layerId: string, el: HTMLElement): () => void {\n const state = getState();\n let set = state.elements.get(layerId);\n if (!set) {\n set = new Set();\n state.elements.set(layerId, set);\n }\n set.add(el);\n return () => {\n const current = state.elements.get(layerId);\n if (!current) return;\n current.delete(el);\n if (current.size === 0) state.elements.delete(layerId);\n };\n}\n\n/**\n * Registers an open layer and returns its unregister function. `record.order` is set to the next\n * value of the global open-order counter. The layer is placed on top of the stack — or, when some\n * of its descendants registered first (same commit), directly below the earliest of them.\n */\nexport function registerLayer(record: LayerRecord): () => void {\n const state = getState();\n state.counter += 1;\n record.order = state.counter;\n\n const firstDescendant = state.stack.findIndex((layer) => isDescendantOf(state, layer, record.id));\n if (firstDescendant === -1) state.stack.push(record);\n else state.stack.splice(firstDescendant, 0, record);\n\n ensureListeners(state);\n notifySubscribers(state);\n\n let registered = true;\n return () => {\n if (!registered) return;\n registered = false;\n const index = state.stack.indexOf(record);\n if (index !== -1) state.stack.splice(index, 1);\n if (state.press) {\n state.press.layers = state.press.layers.filter((layer) => layer !== record);\n }\n if (state.stack.length === 0) removeListeners(state);\n notifySubscribers(state);\n };\n}\n\n// ---------------------------------------------------------------------------\n// Document listeners\n// ---------------------------------------------------------------------------\n\nfunction getEventTargetNode(event: Event): Node | null {\n const target = event.target as { nodeType?: unknown } | null;\n return target && typeof target.nodeType === 'number' ? (target as Node) : null;\n}\n\n/** Topmost first: descendants before their ancestors. */\nfunction sortTopmostFirst(layers: LayerRecord[]): LayerRecord[] {\n return [...layers].sort((a, b) => compareLayers(b, a));\n}\n\n/**\n * The layer that handles an Escape whose target / focused element is `target` / `active`.\n * Candidates are the escape-enabled layers that are not stacked below the topmost isolating modal\n * (a modal that ignores Escape never lets the key close something inert behind it — its ancestor\n * dialog as much as an older sibling); a layer with `escape: 'inside'` is a candidate only while\n * its tree contains them (the toast region counts as inside every layer):\n * 1. the innermost layer whose tree contains them (the topmost such layer) is the focus scope;\n * 2. the topmost candidate of that scope's subtree handles it — the scope itself or an open\n * descendant above it (a tooltip or popover opened from the focused dialog closes first, while\n * a sibling of the focused layer is not in its subtree);\n * 3. else the topmost candidate whose tree contains them (an ancestor);\n * 4. else — no layer contains them, or none of the containing layers takes Escape — the global\n * topmost candidate.\n */\nfunction findEscapeHandler(\n state: LayerState,\n target: Node | null,\n active: Element | null,\n): LayerRecord | null {\n const barrier = getIsolationBarrier(state);\n const contains = (layer: LayerRecord) =>\n (!!target && isInsideLayerTree(layer.id, target)) ||\n (!!active && isInsideLayerTree(layer.id, active));\n const isCandidate = (layer: LayerRecord) =>\n (layer.escape === true || (layer.escape === 'inside' && contains(layer))) &&\n !isBelowBarrier(layer, barrier);\n const scope = getTopmostLayer(contains);\n const handler = scope\n ? (getTopmostLayer(\n (layer) =>\n isCandidate(layer) && (layer === scope || isDescendantOf(state, layer, scope.id)),\n ) ?? getTopmostLayer((layer) => isCandidate(layer) && contains(layer)))\n : null;\n return handler ?? getTopmostLayer(isCandidate);\n}\n\n/** Keys that activate the focused control with a synthetic click. */\nfunction isClickActivationKey(key: string): boolean {\n return key === 'Enter' || key === ' ' || key === 'Spacebar';\n}\n\nfunction handleKeyDown(event: KeyboardEvent): void {\n const state = getState();\n if (event.key === 'Escape' || event.key === 'Esc') {\n if (event.defaultPrevented || event.isComposing) return;\n const handler = findEscapeHandler(state, getEventTargetNode(event), document.activeElement);\n if (!handler) return;\n event.preventDefault();\n handler.onDismiss('escape', event);\n return;\n }\n // A keyboard-activated click (Enter/Space) must not dismiss layers recorded by an unrelated\n // earlier pointerdown. Other keys keep the pending press: modifiers held for a Shift/Ctrl+click\n // auto-repeat their keydown while the pointer is down.\n if (isClickActivationKey(event.key)) state.press = null;\n}\n\nfunction handlePointerDown(event: PointerEvent): void {\n const state = getState();\n const target = getEventTargetNode(event);\n // Only a primary press is followed by a click (right/middle buttons fire contextmenu/auxclick).\n if (!target || event.button !== 0) {\n state.press = null;\n return;\n }\n const barrier = getIsolationBarrier(state);\n const layers = state.stack.filter((layer) => {\n const { outsidePress } = layer;\n if (!outsidePress) return false;\n // A layer behind an open isolating modal (its parent dialog, or a dialog below a sibling\n // modal opened from inside it) is inert and not reachable: presses inside that modal, or on\n // its backdrop, are not \"outside\" presses for it.\n if (isBelowBarrier(layer, barrier)) return false;\n if (isInsideLayerTree(layer.id, target)) return false;\n return typeof outsidePress !== 'function' || outsidePress(event) !== false;\n });\n state.press = { layers };\n}\n\n/**\n * How long (ms) a touch, pen or unknown-device press waits for its click after the pointerup. A\n * tap's click follows within about 350 ms (at most the double-tap delay); a press that gets no\n * click (a long press that opened the context menu, a tap on a non-clickable area) is forgotten\n * after this, so a later programmatic `click()` cannot complete it.\n */\nconst GESTURE_CLICK_TIMEOUT_MS = 1000;\n\n/**\n * A mouse click is dispatched right after its pointerup, in the same task. When none follows (the\n * pointer was released over another window or element tree), a mouse press is forgotten on the\n * next macrotask, so a later programmatic `click()` cannot complete it. Touch and stylus taps are\n * turned into a click by a separate gesture event in a later task (Apple Pencil on iPadOS and\n * Android styluses report `pointerType: 'pen'`, and an unknown device type `''` may behave the\n * same way), so every other pointer type keeps its press for {@link GESTURE_CLICK_TIMEOUT_MS}.\n * The next pointerdown, pointercancel, contextmenu or Enter/Space forgets a press earlier.\n */\nfunction handlePointerUp(event: PointerEvent): void {\n const press = getState().press;\n if (!press) return;\n const timeout = event.pointerType === 'mouse' ? 0 : GESTURE_CLICK_TIMEOUT_MS;\n setTimeout(() => {\n const current = getState();\n if (current.press === press) current.press = null;\n }, timeout);\n}\n\n/** A cancelled pointer stream, or a context menu (a long press, a Mac Ctrl+click), gets no click. */\nfunction forgetPress(): void {\n getState().press = null;\n}\n\nfunction handleClick(event: MouseEvent): void {\n const state = getState();\n const press = state.press;\n state.press = null;\n if (!press) return;\n const target = getEventTargetNode(event);\n const toDismiss = press.layers.filter(\n (layer) => !(target && isInsideLayerTree(layer.id, target)),\n );\n for (const layer of sortTopmostFirst(toDismiss)) {\n // An earlier layer's onDismiss may already have unregistered this one.\n if (state.stack.includes(layer)) layer.onDismiss('outside-press', event);\n }\n}\n\nfunction handleFocusIn(event: FocusEvent): void {\n const target = getEventTargetNode(event);\n if (!target) return;\n const candidates = getState().stack.filter(\n (layer) => layer.focusOutside && !isInsideLayerTree(layer.id, target),\n );\n if (candidates.length === 0) return;\n // Not in this dispatch: React applies `autoFocus` in the layout phase of the commit that mounts\n // a surface, before that surface's portal wrapper and dismiss layer register. A field focused\n // as a popover or dialog opens inside the layer is inside its tree once that commit has run.\n queueMicrotask(() => dismissFocusOutside(candidates, target, event));\n}\n\n/**\n * Dismisses each of `candidates` that is still open and whose tree still contains neither the\n * focusin `target` nor the element focused now (focus that came back inside keeps it open; focus\n * lost to `<body>` after leaving does not).\n */\nfunction dismissFocusOutside(candidates: LayerRecord[], target: Node, event: FocusEvent): void {\n const state = getState();\n const active = (target.ownerDocument ?? document).activeElement;\n const toDismiss = candidates.filter(\n (layer) =>\n state.stack.includes(layer) &&\n !isInsideLayerTree(layer.id, target) &&\n !(active && isInsideLayerTree(layer.id, active)),\n );\n for (const layer of sortTopmostFirst(toDismiss)) {\n // An earlier layer's onDismiss may already have unregistered this one.\n if (state.stack.includes(layer)) layer.onDismiss('focus-outside', event);\n }\n}\n\nfunction ensureListeners(state: LayerState): void {\n if (state.listeners || typeof document === 'undefined') return;\n const doc = document;\n doc.addEventListener('keydown', handleKeyDown);\n doc.addEventListener('pointerdown', handlePointerDown, true);\n doc.addEventListener('pointerup', handlePointerUp, true);\n doc.addEventListener('pointercancel', forgetPress, true);\n doc.addEventListener('contextmenu', forgetPress, true);\n doc.addEventListener('click', handleClick);\n doc.addEventListener('focusin', handleFocusIn, true);\n state.listeners = {\n remove() {\n doc.removeEventListener('keydown', handleKeyDown);\n doc.removeEventListener('pointerdown', handlePointerDown, true);\n doc.removeEventListener('pointerup', handlePointerUp, true);\n doc.removeEventListener('pointercancel', forgetPress, true);\n doc.removeEventListener('contextmenu', forgetPress, true);\n doc.removeEventListener('click', handleClick);\n doc.removeEventListener('focusin', handleFocusIn, true);\n },\n };\n}\n\nfunction removeListeners(state: LayerState): void {\n state.listeners?.remove();\n state.listeners = null;\n state.press = null;\n}\n"],"mappings":";;AAcA,IAAaA,IAAU;CACrB,SAAS;CACT,OAAO;CACP,SAAS;AACX,GA6CaC,IAAyB,gCAczBC,IAAkB,EAAE,8BAA8B,GAAG;AAgClE,SAASC,IAAuB;CAC9B,IAAMC,IAAQC,EAA8B,iBAAiB;EAC3D,OAAO,CAAC;EACR,0BAAU,IAAI,IAAI;EAClB,SAAS;EACT,OAAO;EACP,WAAW;EACX,6BAAa,IAAI,IAAI;EACrB,0BAAU,IAAI,IAAI;CACpB,EAAE;CAIF,OAFA,EAAM,gCAAgB,IAAI,IAAI,GAC9B,EAAM,6BAAa,IAAI,IAAI,GACpBD;AACT;AAEA,SAASE,EAAkB,GAAyB;CAClD,KAAK,IAAMC,KAAc,MAAM,KAAKH,EAAM,WAAW,GAAG,EAAW;AACrE;AAEA,IAAMI,IAAe;AAErB,SAASC,EAAU,GAAmB,GAA4C;CAChF,IAAIC,MAAO,MACX,OAAON,EAAM,MAAM,MAAM,MAAUO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