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