react-motion-modal 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -1
- package/dist/index.js +338 -243
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -89,7 +89,10 @@ export declare type ModalPosition = (typeof MODAL_POSITIONS)[keyof typeof MODAL_
|
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
91
|
* Renders one modal system into a portal and owns its browser accessibility
|
|
92
|
-
* lifecycle.
|
|
92
|
+
* lifecycle. Providers that share one document coordinate body scroll
|
|
93
|
+
* locking, keyboard ownership and visual layering through a per-document
|
|
94
|
+
* coordinator, so independent systems never unlock, cancel or cover each
|
|
95
|
+
* other accidentally.
|
|
93
96
|
*/
|
|
94
97
|
export declare const ModalProvider: <Registry extends ModalRegistry>({ system, defaultOptions, portalRoot: requestedPortalRoot, }: ModalProviderProps<Registry>) => ReactPortal | null;
|
|
95
98
|
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useReducedMotion as
|
|
3
|
-
import { useState as
|
|
4
|
-
import { createPortal as
|
|
5
|
-
import { useStore as
|
|
6
|
-
import { createStore as
|
|
7
|
-
const
|
|
1
|
+
import { jsxs as Q, jsx as g } from "react/jsx-runtime";
|
|
2
|
+
import { useReducedMotion as Y, useIsPresent as tt, motion as P, AnimatePresence as ot } from "motion/react";
|
|
3
|
+
import { useState as et, useRef as S, useEffect as k } from "react";
|
|
4
|
+
import { createPortal as nt } from "react-dom";
|
|
5
|
+
import { useStore as rt } from "zustand/react";
|
|
6
|
+
import { createStore as it } from "zustand/vanilla";
|
|
7
|
+
const d = {
|
|
8
8
|
TOP: "top",
|
|
9
9
|
TOP_LEFT: "top-left",
|
|
10
10
|
TOP_RIGHT: "top-right",
|
|
@@ -17,212 +17,215 @@ const a = {
|
|
|
17
17
|
BOTTOM_LEFT: "bottom-left",
|
|
18
18
|
BOTTOM_RIGHT: "bottom-right",
|
|
19
19
|
BOTTOM_CENTER: "bottom-center"
|
|
20
|
-
},
|
|
20
|
+
}, R = 1e3, A = {
|
|
21
21
|
duration: 0.24,
|
|
22
22
|
ease: "easeOut"
|
|
23
|
-
},
|
|
23
|
+
}, D = {
|
|
24
24
|
duration: 0.18,
|
|
25
25
|
ease: "easeIn"
|
|
26
|
-
},
|
|
26
|
+
}, U = {
|
|
27
27
|
initial: { opacity: 0 },
|
|
28
28
|
animate: {
|
|
29
29
|
opacity: 1,
|
|
30
|
-
transition:
|
|
30
|
+
transition: A
|
|
31
31
|
},
|
|
32
32
|
exit: {
|
|
33
33
|
opacity: 0,
|
|
34
|
-
transition:
|
|
34
|
+
transition: D
|
|
35
35
|
}
|
|
36
|
-
},
|
|
37
|
-
x:
|
|
38
|
-
y:
|
|
36
|
+
}, G = ({
|
|
37
|
+
x: t = 0,
|
|
38
|
+
y: o = 0
|
|
39
39
|
}) => ({
|
|
40
|
-
backdrop:
|
|
40
|
+
backdrop: U,
|
|
41
41
|
content: {
|
|
42
|
-
initial: { opacity: 0, x:
|
|
42
|
+
initial: { opacity: 0, x: t, y: o },
|
|
43
43
|
animate: {
|
|
44
44
|
opacity: 1,
|
|
45
45
|
x: 0,
|
|
46
46
|
y: 0,
|
|
47
|
-
transition:
|
|
47
|
+
transition: A
|
|
48
48
|
},
|
|
49
49
|
exit: {
|
|
50
50
|
opacity: 0,
|
|
51
|
-
x:
|
|
52
|
-
y:
|
|
53
|
-
transition:
|
|
51
|
+
x: t,
|
|
52
|
+
y: o,
|
|
53
|
+
transition: D
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
}),
|
|
56
|
+
}), Ot = {
|
|
57
57
|
dialog: () => ({
|
|
58
|
-
position:
|
|
58
|
+
position: d.CENTER,
|
|
59
59
|
motion: {
|
|
60
|
-
backdrop:
|
|
60
|
+
backdrop: U,
|
|
61
61
|
content: {
|
|
62
62
|
initial: { opacity: 0, scale: 0.96 },
|
|
63
63
|
animate: {
|
|
64
64
|
opacity: 1,
|
|
65
65
|
scale: 1,
|
|
66
|
-
transition:
|
|
66
|
+
transition: A
|
|
67
67
|
},
|
|
68
68
|
exit: {
|
|
69
69
|
opacity: 0,
|
|
70
70
|
scale: 0.96,
|
|
71
|
-
transition:
|
|
71
|
+
transition: D
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
}),
|
|
76
|
-
drawer: (
|
|
77
|
-
const
|
|
76
|
+
drawer: (t = {}) => {
|
|
77
|
+
const o = t.side ?? "right";
|
|
78
78
|
return {
|
|
79
|
-
position:
|
|
80
|
-
motion:
|
|
81
|
-
x:
|
|
79
|
+
position: o === "left" ? d.LEFT : d.RIGHT,
|
|
80
|
+
motion: G({
|
|
81
|
+
x: o === "left" ? "-100%" : "100%"
|
|
82
82
|
})
|
|
83
83
|
};
|
|
84
84
|
},
|
|
85
|
-
sheet: (
|
|
86
|
-
const
|
|
85
|
+
sheet: (t = {}) => {
|
|
86
|
+
const o = t.edge ?? "bottom";
|
|
87
87
|
return {
|
|
88
|
-
position:
|
|
89
|
-
motion:
|
|
90
|
-
y:
|
|
88
|
+
position: o === "top" ? d.TOP : d.BOTTOM,
|
|
89
|
+
motion: G({
|
|
90
|
+
y: o === "top" ? "-100%" : "100%"
|
|
91
91
|
})
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
|
-
},
|
|
95
|
-
switch (
|
|
96
|
-
case
|
|
94
|
+
}, K = (...t) => t.filter(Boolean).join(" "), V = (t) => {
|
|
95
|
+
switch (t) {
|
|
96
|
+
case d.TOP:
|
|
97
97
|
return "react-motion-modal__body--top";
|
|
98
|
-
case
|
|
98
|
+
case d.TOP_LEFT:
|
|
99
99
|
return "react-motion-modal__body--top-left";
|
|
100
|
-
case
|
|
100
|
+
case d.TOP_RIGHT:
|
|
101
101
|
return "react-motion-modal__body--top-right";
|
|
102
|
-
case
|
|
102
|
+
case d.TOP_CENTER:
|
|
103
103
|
return "react-motion-modal__body--top-center";
|
|
104
|
-
case
|
|
104
|
+
case d.BOTTOM:
|
|
105
105
|
return "react-motion-modal__body--bottom";
|
|
106
|
-
case
|
|
106
|
+
case d.BOTTOM_LEFT:
|
|
107
107
|
return "react-motion-modal__body--bottom-left";
|
|
108
|
-
case
|
|
108
|
+
case d.BOTTOM_RIGHT:
|
|
109
109
|
return "react-motion-modal__body--bottom-right";
|
|
110
|
-
case
|
|
110
|
+
case d.BOTTOM_CENTER:
|
|
111
111
|
return "react-motion-modal__body--bottom-center";
|
|
112
|
-
case
|
|
112
|
+
case d.LEFT:
|
|
113
113
|
return "react-motion-modal__body--left";
|
|
114
|
-
case
|
|
114
|
+
case d.RIGHT:
|
|
115
115
|
return "react-motion-modal__body--right";
|
|
116
|
-
case
|
|
116
|
+
case d.CENTER:
|
|
117
117
|
return "react-motion-modal__body--center";
|
|
118
|
-
case
|
|
118
|
+
case d.CENTER_FULL:
|
|
119
119
|
return "react-motion-modal__body--center-full";
|
|
120
120
|
default:
|
|
121
|
-
return
|
|
121
|
+
return V(d.CENTER);
|
|
122
122
|
}
|
|
123
|
-
},
|
|
124
|
-
if (!(!
|
|
123
|
+
}, j = (t, o) => {
|
|
124
|
+
if (!(!t && !o))
|
|
125
125
|
return {
|
|
126
|
-
...o,
|
|
127
126
|
...t,
|
|
127
|
+
...o,
|
|
128
128
|
style: {
|
|
129
|
-
...
|
|
130
|
-
...
|
|
129
|
+
...t?.style,
|
|
130
|
+
...o?.style
|
|
131
131
|
}
|
|
132
132
|
};
|
|
133
|
-
},
|
|
134
|
-
const
|
|
135
|
-
for (const
|
|
136
|
-
const
|
|
137
|
-
Object.assign(
|
|
133
|
+
}, W = (...t) => {
|
|
134
|
+
const o = {};
|
|
135
|
+
for (const e of t) {
|
|
136
|
+
const s = j(o.backdrop, e?.backdrop), i = j(o.body, e?.body);
|
|
137
|
+
Object.assign(o, e), o.backdrop = s, o.body = i;
|
|
138
138
|
}
|
|
139
|
-
return
|
|
140
|
-
},
|
|
139
|
+
return o;
|
|
140
|
+
}, $ = {
|
|
141
141
|
initial: { opacity: 1 },
|
|
142
142
|
animate: { opacity: 1, transition: { duration: 0 } },
|
|
143
143
|
exit: { opacity: 1, transition: { duration: 0 } }
|
|
144
|
-
},
|
|
145
|
-
const
|
|
146
|
-
component:
|
|
144
|
+
}, st = ({ data: t, index: o, isActive: e, defaultOptions: s }) => {
|
|
145
|
+
const i = Y(), c = tt(), u = e && c, {
|
|
146
|
+
component: p,
|
|
147
147
|
defaultOptions: l,
|
|
148
|
-
preset:
|
|
149
|
-
} =
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
position:
|
|
153
|
-
motion:
|
|
148
|
+
preset: b
|
|
149
|
+
} = t.definition, a = W(
|
|
150
|
+
s,
|
|
151
|
+
b ? {
|
|
152
|
+
position: b.position,
|
|
153
|
+
motion: b.motion
|
|
154
154
|
} : void 0,
|
|
155
155
|
l,
|
|
156
|
-
|
|
157
|
-
),
|
|
158
|
-
return /* @__PURE__ */
|
|
159
|
-
|
|
156
|
+
t.options
|
|
157
|
+
), h = a.position ?? d.CENTER, O = a.closeOnClickOutside ?? !0, v = i ? $ : a.motion?.content, n = i ? $ : a.motion?.backdrop;
|
|
158
|
+
return /* @__PURE__ */ Q(
|
|
159
|
+
P.div,
|
|
160
160
|
{
|
|
161
161
|
className: "react-motion-modal__root",
|
|
162
162
|
initial: !1,
|
|
163
163
|
exit: {},
|
|
164
|
+
inert: !u,
|
|
164
165
|
style: {
|
|
165
|
-
zIndex:
|
|
166
|
-
pointerEvents:
|
|
167
|
-
backdropFilter:
|
|
168
|
-
WebkitBackdropFilter:
|
|
166
|
+
zIndex: R + o,
|
|
167
|
+
pointerEvents: u ? void 0 : "none",
|
|
168
|
+
backdropFilter: a.blur ? "blur(8px)" : void 0,
|
|
169
|
+
WebkitBackdropFilter: a.blur ? "blur(8px)" : void 0
|
|
169
170
|
},
|
|
170
171
|
children: [
|
|
171
|
-
/* @__PURE__ */
|
|
172
|
-
|
|
172
|
+
/* @__PURE__ */ g(
|
|
173
|
+
P.div,
|
|
173
174
|
{
|
|
174
|
-
className:
|
|
175
|
+
className: K(
|
|
175
176
|
"react-motion-modal__backdrop",
|
|
176
|
-
|
|
177
|
-
|
|
177
|
+
u && "react-motion-modal__active",
|
|
178
|
+
a.backdrop?.className
|
|
178
179
|
),
|
|
179
|
-
initial:
|
|
180
|
-
animate:
|
|
181
|
-
exit:
|
|
180
|
+
initial: n?.initial ?? { opacity: 0 },
|
|
181
|
+
animate: n?.animate ?? { opacity: 1 },
|
|
182
|
+
exit: n?.exit ?? { opacity: 0 },
|
|
182
183
|
style: {
|
|
183
|
-
zIndex:
|
|
184
|
-
...
|
|
184
|
+
zIndex: R + o,
|
|
185
|
+
...a.backdrop?.style
|
|
185
186
|
},
|
|
186
187
|
onClick: () => {
|
|
187
|
-
|
|
188
|
+
O && t.cancel("backdrop");
|
|
188
189
|
}
|
|
189
190
|
}
|
|
190
191
|
),
|
|
191
|
-
/* @__PURE__ */
|
|
192
|
+
/* @__PURE__ */ g(
|
|
192
193
|
"div",
|
|
193
194
|
{
|
|
194
195
|
role: "dialog",
|
|
195
|
-
"aria-modal":
|
|
196
|
-
"aria-hidden":
|
|
197
|
-
"aria-label":
|
|
198
|
-
"aria-labelledby":
|
|
199
|
-
"aria-describedby":
|
|
196
|
+
"aria-modal": u ? "true" : void 0,
|
|
197
|
+
"aria-hidden": u ? void 0 : !0,
|
|
198
|
+
"aria-label": a.ariaLabelledBy ? void 0 : a.ariaLabel ?? "Modal",
|
|
199
|
+
"aria-labelledby": a.ariaLabelledBy,
|
|
200
|
+
"aria-describedby": a.ariaDescribedBy,
|
|
200
201
|
tabIndex: -1,
|
|
201
|
-
"data-modal-id":
|
|
202
|
-
className:
|
|
202
|
+
"data-modal-id": t.id,
|
|
203
|
+
className: K(
|
|
203
204
|
"react-motion-modal__body",
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
205
|
+
V(h),
|
|
206
|
+
u && "react-motion-modal__body--active",
|
|
207
|
+
a.body?.className
|
|
207
208
|
),
|
|
208
209
|
style: {
|
|
209
|
-
|
|
210
|
-
|
|
210
|
+
// Keep dialog scrolling from chaining to the locked page.
|
|
211
|
+
overscrollBehavior: "contain",
|
|
212
|
+
...a.body?.style,
|
|
213
|
+
zIndex: R + o + 1
|
|
211
214
|
},
|
|
212
|
-
onClick: (
|
|
213
|
-
children: /* @__PURE__ */
|
|
214
|
-
|
|
215
|
+
onClick: (r) => r.stopPropagation(),
|
|
216
|
+
children: /* @__PURE__ */ g(
|
|
217
|
+
P.div,
|
|
215
218
|
{
|
|
216
219
|
className: "react-motion-modal__content",
|
|
217
|
-
initial:
|
|
218
|
-
animate:
|
|
219
|
-
exit:
|
|
220
|
-
children: /* @__PURE__ */
|
|
221
|
-
|
|
220
|
+
initial: v?.initial,
|
|
221
|
+
animate: v?.animate,
|
|
222
|
+
exit: v?.exit,
|
|
223
|
+
children: /* @__PURE__ */ g(
|
|
224
|
+
p,
|
|
222
225
|
{
|
|
223
|
-
input:
|
|
224
|
-
resolve:
|
|
225
|
-
cancel: (
|
|
226
|
+
input: t.input,
|
|
227
|
+
resolve: t.resolve,
|
|
228
|
+
cancel: (r) => t.cancel(r)
|
|
226
229
|
}
|
|
227
230
|
)
|
|
228
231
|
}
|
|
@@ -232,173 +235,265 @@ const a = {
|
|
|
232
235
|
]
|
|
233
236
|
}
|
|
234
237
|
);
|
|
235
|
-
},
|
|
238
|
+
}, F = /* @__PURE__ */ new WeakMap(), N = (t) => {
|
|
239
|
+
let o = F.get(t);
|
|
240
|
+
return o || (o = { scrollLock: null, keyboardOwners: [], layerEpoch: 0 }, F.set(t, o)), o;
|
|
241
|
+
}, ct = (t, o) => {
|
|
242
|
+
const e = N(t);
|
|
243
|
+
if (!e.scrollLock) {
|
|
244
|
+
e.scrollLock = {
|
|
245
|
+
tokens: /* @__PURE__ */ new Set([o]),
|
|
246
|
+
initialStyles: {
|
|
247
|
+
overflow: t.body.style.overflow,
|
|
248
|
+
overscrollBehavior: t.body.style.overscrollBehavior
|
|
249
|
+
}
|
|
250
|
+
}, t.body.style.overflow = "hidden", t.body.style.overscrollBehavior = "none";
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
e.scrollLock.tokens.add(o);
|
|
254
|
+
}, at = (t, o) => {
|
|
255
|
+
const e = N(t), { scrollLock: s } = e;
|
|
256
|
+
s?.tokens.has(o) && (s.tokens.delete(o), s.tokens.size === 0 && (e.scrollLock = null, t.body.style.overflow = s.initialStyles.overflow, t.body.style.overscrollBehavior = s.initialStyles.overscrollBehavior));
|
|
257
|
+
}, z = (t, o) => {
|
|
258
|
+
const e = N(t), s = e.keyboardOwners, i = s[s.length - 1];
|
|
259
|
+
if (i?.token === o)
|
|
260
|
+
return i.layer;
|
|
261
|
+
const c = ++e.layerEpoch;
|
|
262
|
+
return e.keyboardOwners = [
|
|
263
|
+
...s.filter((u) => u.token !== o),
|
|
264
|
+
{ token: o, layer: c }
|
|
265
|
+
], c;
|
|
266
|
+
}, lt = (t, o) => {
|
|
267
|
+
const e = N(t);
|
|
268
|
+
e.keyboardOwners = e.keyboardOwners.filter(
|
|
269
|
+
(s) => s.token !== o
|
|
270
|
+
), e.keyboardOwners.length === 0 && (e.layerEpoch = 0);
|
|
271
|
+
}, x = (t, o) => F.get(t)?.keyboardOwners.at(-1)?.token === o, dt = [
|
|
236
272
|
"a[href]",
|
|
237
273
|
"button:not([disabled])",
|
|
238
274
|
"textarea:not([disabled])",
|
|
239
|
-
|
|
275
|
+
'input:not([disabled]):not([type="hidden"])',
|
|
240
276
|
"select:not([disabled])",
|
|
241
277
|
'[tabindex]:not([tabindex="-1"])'
|
|
242
|
-
].join(","),
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
278
|
+
].join(","), ut = (t) => t.closest("[inert]") ? !1 : typeof t.checkVisibility == "function" ? t.checkVisibility({
|
|
279
|
+
checkOpacity: !0,
|
|
280
|
+
checkVisibilityCSS: !0
|
|
281
|
+
}) : t.getClientRects().length > 0, C = (t) => t ? Array.from(
|
|
282
|
+
t.querySelectorAll(dt)
|
|
283
|
+
).filter(ut) : [], ft = (t, o) => {
|
|
284
|
+
if (!t || o.key !== "Tab")
|
|
246
285
|
return;
|
|
247
|
-
const
|
|
248
|
-
if (!
|
|
249
|
-
|
|
286
|
+
const e = C(t), s = e[0], i = e[e.length - 1], c = document.activeElement;
|
|
287
|
+
if (!s || !i) {
|
|
288
|
+
o.preventDefault(), t.focus();
|
|
250
289
|
return;
|
|
251
290
|
}
|
|
252
|
-
if (!
|
|
253
|
-
|
|
291
|
+
if (!c || !t.contains(c)) {
|
|
292
|
+
o.preventDefault(), (o.shiftKey ? i : s).focus();
|
|
254
293
|
return;
|
|
255
294
|
}
|
|
256
|
-
|
|
257
|
-
},
|
|
258
|
-
const
|
|
259
|
-
if (!
|
|
295
|
+
o.shiftKey && c === s ? (o.preventDefault(), i.focus()) : !o.shiftKey && c === i && (o.preventDefault(), s.focus());
|
|
296
|
+
}, X = /* @__PURE__ */ new WeakMap(), Z = (t) => {
|
|
297
|
+
const o = X.get(t);
|
|
298
|
+
if (!o)
|
|
260
299
|
throw new Error("Invalid modal system instance.");
|
|
261
|
-
return
|
|
262
|
-
},
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
let
|
|
300
|
+
return o;
|
|
301
|
+
}, mt = (t) => Z(t).store, pt = (t) => {
|
|
302
|
+
const o = Z(t);
|
|
303
|
+
o.providerCount += 1;
|
|
304
|
+
let e = !0;
|
|
266
305
|
return () => {
|
|
267
|
-
|
|
268
|
-
|
|
306
|
+
e && (e = !1, o.providerCount -= 1, queueMicrotask(() => {
|
|
307
|
+
o.providerCount === 0 && t.cancelAll("provider-unmounted");
|
|
269
308
|
}));
|
|
270
309
|
};
|
|
271
|
-
},
|
|
272
|
-
const
|
|
310
|
+
}, _t = (t) => {
|
|
311
|
+
const o = it(() => ({
|
|
273
312
|
activeModals: []
|
|
274
313
|
}));
|
|
275
|
-
let
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
activeModals: l.activeModals.filter((
|
|
314
|
+
let e = 0;
|
|
315
|
+
const s = (p) => {
|
|
316
|
+
o.setState((l) => ({
|
|
317
|
+
activeModals: l.activeModals.filter((b) => b.id !== p)
|
|
279
318
|
}));
|
|
280
|
-
},
|
|
281
|
-
const l =
|
|
282
|
-
l[l.length - 1]?.cancel(
|
|
283
|
-
},
|
|
284
|
-
open(
|
|
285
|
-
const
|
|
286
|
-
if (!
|
|
287
|
-
throw new Error(`Unknown modal "${
|
|
288
|
-
if (
|
|
289
|
-
const
|
|
290
|
-
if (
|
|
291
|
-
return
|
|
319
|
+
}, i = (p = "programmatic") => {
|
|
320
|
+
const l = o.getState().activeModals;
|
|
321
|
+
l[l.length - 1]?.cancel(p);
|
|
322
|
+
}, u = {
|
|
323
|
+
open(p, l, b) {
|
|
324
|
+
const a = t[p];
|
|
325
|
+
if (!a)
|
|
326
|
+
throw new Error(`Unknown modal "${p}".`);
|
|
327
|
+
if (a.policy === "singleton") {
|
|
328
|
+
const m = o.getState().activeModals.find((M) => M.name === p);
|
|
329
|
+
if (m)
|
|
330
|
+
return m.promise;
|
|
292
331
|
}
|
|
293
|
-
|
|
294
|
-
const
|
|
295
|
-
let
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
}),
|
|
299
|
-
|
|
300
|
-
},
|
|
301
|
-
id:
|
|
302
|
-
name:
|
|
332
|
+
a.policy === "replace" && i("replaced");
|
|
333
|
+
const h = `${p}-${++e}`;
|
|
334
|
+
let O = !1, v;
|
|
335
|
+
const n = new Promise((m) => {
|
|
336
|
+
v = m;
|
|
337
|
+
}), r = (m) => {
|
|
338
|
+
O || (O = !0, s(h), v?.(m));
|
|
339
|
+
}, T = {
|
|
340
|
+
id: h,
|
|
341
|
+
name: p,
|
|
303
342
|
input: l,
|
|
304
|
-
definition:
|
|
305
|
-
options:
|
|
306
|
-
promise:
|
|
307
|
-
resolve(
|
|
308
|
-
|
|
343
|
+
definition: a,
|
|
344
|
+
options: b,
|
|
345
|
+
promise: n,
|
|
346
|
+
resolve(m) {
|
|
347
|
+
r({ status: "resolved", value: m });
|
|
309
348
|
},
|
|
310
|
-
cancel(
|
|
311
|
-
|
|
349
|
+
cancel(m = "programmatic") {
|
|
350
|
+
r({ status: "cancelled", reason: m });
|
|
312
351
|
}
|
|
313
352
|
};
|
|
314
|
-
return
|
|
315
|
-
activeModals: [...
|
|
316
|
-
})),
|
|
353
|
+
return o.setState((m) => ({
|
|
354
|
+
activeModals: [...m.activeModals, T]
|
|
355
|
+
})), n;
|
|
317
356
|
},
|
|
318
|
-
cancel:
|
|
319
|
-
cancelAll: (
|
|
320
|
-
const l = [...
|
|
321
|
-
for (const
|
|
322
|
-
|
|
357
|
+
cancel: i,
|
|
358
|
+
cancelAll: (p = "programmatic") => {
|
|
359
|
+
const l = [...o.getState().activeModals].reverse();
|
|
360
|
+
for (const b of l)
|
|
361
|
+
b.cancel(p);
|
|
323
362
|
}
|
|
324
363
|
};
|
|
325
|
-
return
|
|
326
|
-
store:
|
|
364
|
+
return X.set(u, {
|
|
365
|
+
store: o,
|
|
327
366
|
providerCount: 0
|
|
328
|
-
}),
|
|
329
|
-
},
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
367
|
+
}), u;
|
|
368
|
+
}, q = (t, o) => {
|
|
369
|
+
t && (t.style.position = "relative", t.style.zIndex = String(R + o));
|
|
370
|
+
}, kt = ({
|
|
371
|
+
system: t,
|
|
372
|
+
defaultOptions: o,
|
|
373
|
+
portalRoot: e
|
|
333
374
|
}) => {
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
), l =
|
|
337
|
-
return
|
|
338
|
-
|
|
339
|
-
}, [
|
|
340
|
-
const
|
|
341
|
-
return window.addEventListener("popstate",
|
|
342
|
-
}, [
|
|
343
|
-
if (!
|
|
375
|
+
const s = mt(t), i = rt(s, (r) => r.activeModals), c = i[i.length - 1], [u, p] = et(
|
|
376
|
+
e ?? null
|
|
377
|
+
), l = S(null), b = S({}), a = S(null), h = S(/* @__PURE__ */ new Map()), O = S([]), v = i.length > 0, n = u?.ownerDocument ?? null;
|
|
378
|
+
return k(() => {
|
|
379
|
+
p(e ?? document.body);
|
|
380
|
+
}, [e]), k(() => pt(t), [t]), k(() => {
|
|
381
|
+
const r = () => t.cancelAll("programmatic");
|
|
382
|
+
return window.addEventListener("popstate", r), () => window.removeEventListener("popstate", r);
|
|
383
|
+
}, [t]), k(() => {
|
|
384
|
+
if (!n || !v)
|
|
344
385
|
return;
|
|
345
|
-
const
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
386
|
+
const r = b.current;
|
|
387
|
+
return q(l.current, z(n, r)), () => lt(n, r);
|
|
388
|
+
}, [n, v]), k(() => {
|
|
389
|
+
if (!n || !v)
|
|
390
|
+
return;
|
|
391
|
+
const r = b.current, T = n.defaultView;
|
|
392
|
+
if (!T)
|
|
393
|
+
return;
|
|
394
|
+
const M = W(
|
|
395
|
+
o,
|
|
396
|
+
c?.definition.preset ? {
|
|
397
|
+
position: c.definition.preset.position,
|
|
398
|
+
motion: c.definition.preset.motion
|
|
350
399
|
} : void 0,
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
).closeOnPressEsc ?? !0,
|
|
354
|
-
|
|
355
|
-
|
|
400
|
+
c?.definition.defaultOptions,
|
|
401
|
+
c?.options
|
|
402
|
+
).closeOnPressEsc ?? !0, _ = (y) => l.current?.querySelector(
|
|
403
|
+
`[data-modal-id="${y}"]`
|
|
404
|
+
), f = (y) => {
|
|
405
|
+
if (x(n, r)) {
|
|
406
|
+
if (y.key === "Escape" && M) {
|
|
407
|
+
c?.cancel("escape");
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
ft(_(c?.id ?? ""), y);
|
|
411
|
+
}
|
|
412
|
+
}, E = (y) => {
|
|
413
|
+
const L = l.current, I = y.target;
|
|
414
|
+
if (!L)
|
|
415
|
+
return;
|
|
416
|
+
if (I && L.contains(I)) {
|
|
417
|
+
a.current = I instanceof HTMLElement ? I : null;
|
|
356
418
|
return;
|
|
357
419
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
)
|
|
361
|
-
|
|
420
|
+
if (!x(n, r) || !c)
|
|
421
|
+
return;
|
|
422
|
+
const H = _(c.id), J = [
|
|
423
|
+
a.current,
|
|
424
|
+
...C(H)
|
|
425
|
+
];
|
|
426
|
+
for (const B of J)
|
|
427
|
+
if (B?.isConnected && (B.focus(), n.activeElement === B))
|
|
428
|
+
return;
|
|
429
|
+
H?.focus();
|
|
430
|
+
}, w = (y) => {
|
|
431
|
+
if (!x(n, r) || !y.cancelable)
|
|
432
|
+
return;
|
|
433
|
+
const L = l.current;
|
|
434
|
+
L && y.composedPath().includes(L) || y.preventDefault();
|
|
362
435
|
};
|
|
363
|
-
return
|
|
364
|
-
|
|
365
|
-
if (!e)
|
|
366
|
-
return;
|
|
367
|
-
const { body: n } = document, f = n.style.overflow;
|
|
368
|
-
return n.style.overflow = "hidden", () => {
|
|
369
|
-
n.style.overflow = f;
|
|
436
|
+
return T.addEventListener("keydown", f), n.addEventListener("focusin", E), n.addEventListener("touchmove", w, { passive: !1 }), () => {
|
|
437
|
+
T.removeEventListener("keydown", f), n.removeEventListener("focusin", E), n.removeEventListener("touchmove", w);
|
|
370
438
|
};
|
|
371
|
-
}, [
|
|
372
|
-
if (!
|
|
439
|
+
}, [c, o, n, v]), k(() => {
|
|
440
|
+
if (!n || !v)
|
|
373
441
|
return;
|
|
374
|
-
|
|
375
|
-
|
|
442
|
+
const r = b.current;
|
|
443
|
+
return ct(n, r), () => at(n, r);
|
|
444
|
+
}, [n, v]), k(() => {
|
|
445
|
+
if (!n || !u)
|
|
376
446
|
return;
|
|
447
|
+
const r = b.current, T = i.map((f) => f.id), m = O.current, M = T.filter((f) => !m.includes(f)), _ = m.filter((f) => !T.includes(f));
|
|
448
|
+
for (const f of i)
|
|
449
|
+
h.current.has(f.id) || h.current.set(
|
|
450
|
+
f.id,
|
|
451
|
+
n.activeElement ?? null
|
|
452
|
+
);
|
|
453
|
+
if (O.current = T, M.length > 0) {
|
|
454
|
+
q(l.current, z(n, r));
|
|
455
|
+
const f = T[T.length - 1];
|
|
456
|
+
if (f) {
|
|
457
|
+
const E = l.current?.querySelector(
|
|
458
|
+
`[data-modal-id="${f}"]`
|
|
459
|
+
);
|
|
460
|
+
(C(E)[0] ?? E)?.focus();
|
|
461
|
+
}
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
if (_.length > 0) {
|
|
465
|
+
const f = _[_.length - 1], E = f ? h.current.get(f) ?? null : null;
|
|
466
|
+
for (const y of _)
|
|
467
|
+
h.current.delete(y);
|
|
468
|
+
if (E?.isConnected && (E.focus(), n.activeElement === E))
|
|
469
|
+
return;
|
|
470
|
+
const w = i[i.length - 1];
|
|
471
|
+
if (w) {
|
|
472
|
+
const y = l.current?.querySelector(
|
|
473
|
+
`[data-modal-id="${w.id}"]`
|
|
474
|
+
);
|
|
475
|
+
(C(y)[0] ?? y)?.focus();
|
|
476
|
+
}
|
|
377
477
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
) : void 0;
|
|
382
|
-
n && (S(n)[0] ?? n).focus();
|
|
383
|
-
}, [i, e, m]), m ? $(
|
|
384
|
-
/* @__PURE__ */ _("div", { className: "react-motion-modal", ref: l, children: /* @__PURE__ */ _(H, { initial: !0, mode: "sync", children: s.map((n, f) => /* @__PURE__ */ _(
|
|
385
|
-
z,
|
|
478
|
+
}, [i, n, u]), u ? nt(
|
|
479
|
+
/* @__PURE__ */ g("div", { className: "react-motion-modal", ref: l, children: /* @__PURE__ */ g(ot, { initial: !0, mode: "sync", children: i.map((r, T) => /* @__PURE__ */ g(
|
|
480
|
+
st,
|
|
386
481
|
{
|
|
387
|
-
data:
|
|
388
|
-
index:
|
|
389
|
-
isActive:
|
|
390
|
-
defaultOptions:
|
|
482
|
+
data: r,
|
|
483
|
+
index: T,
|
|
484
|
+
isActive: c?.id === r.id,
|
|
485
|
+
defaultOptions: o
|
|
391
486
|
},
|
|
392
|
-
|
|
487
|
+
r.id
|
|
393
488
|
)) }) }),
|
|
394
|
-
|
|
489
|
+
u
|
|
395
490
|
) : null;
|
|
396
|
-
},
|
|
491
|
+
}, gt = (t) => t;
|
|
397
492
|
export {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
493
|
+
d as MODAL_POSITIONS,
|
|
494
|
+
R as MODAL_Z_INDEX,
|
|
495
|
+
kt as ModalProvider,
|
|
496
|
+
_t as createModalSystem,
|
|
497
|
+
gt as defineModal,
|
|
498
|
+
Ot as motionPresets
|
|
404
499
|
};
|