react-motion-modal 2.0.2 → 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 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%;transform:translate(-50%)}: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%;transform:translate(-50%)}: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%;transform:translate(-50%,-50%)}:where(.react-motion-modal__body--center-full){inset:0;width:100%;height:100%}
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.js CHANGED
@@ -1,10 +1,10 @@
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 = {
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,483 +17,499 @@ const d = {
17
17
  BOTTOM_LEFT: "bottom-left",
18
18
  BOTTOM_RIGHT: "bottom-right",
19
19
  BOTTOM_CENTER: "bottom-center"
20
- }, R = 1e3, A = {
20
+ }, I = 1e3, G = {
21
21
  duration: 0.24,
22
22
  ease: "easeOut"
23
- }, D = {
23
+ }, K = {
24
24
  duration: 0.18,
25
25
  ease: "easeIn"
26
- }, U = {
26
+ }, Z = {
27
27
  initial: { opacity: 0 },
28
28
  animate: {
29
29
  opacity: 1,
30
- transition: A
30
+ transition: G
31
31
  },
32
32
  exit: {
33
33
  opacity: 0,
34
- transition: D
34
+ transition: K
35
35
  }
36
- }, G = ({
36
+ }, j = ({
37
37
  x: t = 0,
38
- y: o = 0
38
+ y: e = 0
39
39
  }) => ({
40
- backdrop: U,
40
+ backdrop: Z,
41
41
  content: {
42
- initial: { opacity: 0, x: t, y: o },
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: A
47
+ transition: G
48
48
  },
49
49
  exit: {
50
50
  opacity: 0,
51
51
  x: t,
52
- y: o,
53
- transition: D
52
+ y: e,
53
+ transition: K
54
54
  }
55
55
  }
56
- }), Ot = {
56
+ }), wt = {
57
57
  dialog: () => ({
58
- position: d.CENTER,
58
+ position: u.CENTER,
59
59
  motion: {
60
- backdrop: U,
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: A
66
+ transition: G
67
67
  },
68
68
  exit: {
69
69
  opacity: 0,
70
70
  scale: 0.96,
71
- transition: D
71
+ transition: K
72
72
  }
73
73
  }
74
74
  }
75
75
  }),
76
76
  drawer: (t = {}) => {
77
- const o = t.side ?? "right";
77
+ const e = t.side ?? "right";
78
78
  return {
79
- position: o === "left" ? d.LEFT : d.RIGHT,
80
- motion: G({
81
- x: o === "left" ? "-100%" : "100%"
79
+ position: e === "left" ? u.LEFT : u.RIGHT,
80
+ motion: j({
81
+ x: e === "left" ? "-100%" : "100%"
82
82
  })
83
83
  };
84
84
  },
85
85
  sheet: (t = {}) => {
86
- const o = t.edge ?? "bottom";
86
+ const e = t.edge ?? "bottom";
87
87
  return {
88
- position: o === "top" ? d.TOP : d.BOTTOM,
89
- motion: G({
90
- y: o === "top" ? "-100%" : "100%"
88
+ position: e === "top" ? u.TOP : u.BOTTOM,
89
+ motion: j({
90
+ y: e === "top" ? "-100%" : "100%"
91
91
  })
92
92
  };
93
93
  }
94
- }, K = (...t) => t.filter(Boolean).join(" "), V = (t) => {
94
+ }, z = (...t) => t.filter(Boolean).join(" "), J = (t) => {
95
95
  switch (t) {
96
- case d.TOP:
96
+ case u.TOP:
97
97
  return "react-motion-modal__body--top";
98
- case d.TOP_LEFT:
98
+ case u.TOP_LEFT:
99
99
  return "react-motion-modal__body--top-left";
100
- case d.TOP_RIGHT:
100
+ case u.TOP_RIGHT:
101
101
  return "react-motion-modal__body--top-right";
102
- case d.TOP_CENTER:
102
+ case u.TOP_CENTER:
103
103
  return "react-motion-modal__body--top-center";
104
- case d.BOTTOM:
104
+ case u.BOTTOM:
105
105
  return "react-motion-modal__body--bottom";
106
- case d.BOTTOM_LEFT:
106
+ case u.BOTTOM_LEFT:
107
107
  return "react-motion-modal__body--bottom-left";
108
- case d.BOTTOM_RIGHT:
108
+ case u.BOTTOM_RIGHT:
109
109
  return "react-motion-modal__body--bottom-right";
110
- case d.BOTTOM_CENTER:
110
+ case u.BOTTOM_CENTER:
111
111
  return "react-motion-modal__body--bottom-center";
112
- case d.LEFT:
112
+ case u.LEFT:
113
113
  return "react-motion-modal__body--left";
114
- case d.RIGHT:
114
+ case u.RIGHT:
115
115
  return "react-motion-modal__body--right";
116
- case d.CENTER:
116
+ case u.CENTER:
117
117
  return "react-motion-modal__body--center";
118
- case d.CENTER_FULL:
118
+ case u.CENTER_FULL:
119
119
  return "react-motion-modal__body--center-full";
120
120
  default:
121
- return V(d.CENTER);
121
+ return J(u.CENTER);
122
122
  }
123
- }, j = (t, o) => {
124
- if (!(!t && !o))
123
+ }, V = (t, e) => {
124
+ if (!(!t && !e))
125
125
  return {
126
126
  ...t,
127
- ...o,
127
+ ...e,
128
128
  style: {
129
129
  ...t?.style,
130
- ...o?.style
130
+ ...e?.style
131
131
  }
132
132
  };
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;
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 o;
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
- }, st = ({ data: t, index: o, isActive: e, defaultOptions: s }) => {
145
- const i = Y(), c = tt(), u = e && c, {
146
- component: p,
147
- defaultOptions: l,
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
148
  preset: b
149
- } = t.definition, a = W(
150
- s,
149
+ } = t.definition, a = Q(
150
+ n,
151
151
  b ? {
152
152
  position: b.position,
153
153
  motion: b.motion
154
154
  } : void 0,
155
- l,
155
+ d,
156
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,
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: !u,
164
+ inert: !l,
165
165
  style: {
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
166
+ zIndex: I + e,
167
+ pointerEvents: l ? void 0 : "none"
170
168
  },
171
169
  children: [
172
- /* @__PURE__ */ g(
173
- P.div,
170
+ /* @__PURE__ */ M(
171
+ A.div,
174
172
  {
175
- className: K(
173
+ className: z(
176
174
  "react-motion-modal__backdrop",
177
- u && "react-motion-modal__active",
175
+ l && "react-motion-modal__active",
178
176
  a.backdrop?.className
179
177
  ),
180
- initial: n?.initial ?? { opacity: 0 },
181
- animate: n?.animate ?? { opacity: 1 },
182
- exit: n?.exit ?? { opacity: 0 },
178
+ initial: i?.initial ?? { opacity: 0 },
179
+ animate: i?.animate ?? { opacity: 1 },
180
+ exit: i?.exit ?? { opacity: 0 },
183
181
  style: {
184
- zIndex: R + o,
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,
185
186
  ...a.backdrop?.style
186
187
  },
187
188
  onClick: () => {
188
- O && t.cancel("backdrop");
189
+ k && t.cancel("backdrop");
189
190
  }
190
191
  }
191
192
  ),
192
- /* @__PURE__ */ g(
193
- "div",
193
+ /* @__PURE__ */ M(
194
+ A.div,
194
195
  {
195
196
  role: "dialog",
196
- "aria-modal": u ? "true" : void 0,
197
- "aria-hidden": u ? void 0 : !0,
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,
198
202
  "aria-label": a.ariaLabelledBy ? void 0 : a.ariaLabel ?? "Modal",
199
203
  "aria-labelledby": a.ariaLabelledBy,
200
204
  "aria-describedby": a.ariaDescribedBy,
201
205
  tabIndex: -1,
202
206
  "data-modal-id": t.id,
203
- className: K(
207
+ className: z(
204
208
  "react-motion-modal__body",
205
- V(h),
206
- u && "react-motion-modal__body--active",
209
+ J(E),
210
+ l && "react-motion-modal__body--active",
207
211
  a.body?.className
208
212
  ),
209
213
  style: {
210
214
  // Keep dialog scrolling from chaining to the locked page.
211
215
  overscrollBehavior: "contain",
212
216
  ...a.body?.style,
213
- zIndex: R + o + 1
217
+ zIndex: I + e + 1
214
218
  },
215
- onClick: (r) => r.stopPropagation(),
216
- children: /* @__PURE__ */ g(
217
- P.div,
219
+ onClick: (g) => g.stopPropagation(),
220
+ children: /* @__PURE__ */ M("div", { className: "react-motion-modal__content", children: /* @__PURE__ */ M(
221
+ m,
218
222
  {
219
- className: "react-motion-modal__content",
220
- initial: v?.initial,
221
- animate: v?.animate,
222
- exit: v?.exit,
223
- children: /* @__PURE__ */ g(
224
- p,
225
- {
226
- input: t.input,
227
- resolve: t.resolve,
228
- cancel: (r) => t.cancel(r)
229
- }
230
- )
223
+ input: t.input,
224
+ resolve: t.resolve,
225
+ cancel: (g) => t.cancel(g)
231
226
  }
232
- )
227
+ ) })
233
228
  }
234
229
  )
235
230
  ]
236
231
  }
237
232
  );
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";
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";
251
256
  return;
252
257
  }
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 = [
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 = [
272
277
  "a[href]",
273
278
  "button:not([disabled])",
274
279
  "textarea:not([disabled])",
275
280
  'input:not([disabled]):not([type="hidden"])',
276
281
  "select:not([disabled])",
277
282
  '[tabindex]:not([tabindex="-1"])'
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")
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")
285
287
  return;
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();
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();
289
291
  return;
290
292
  }
291
- if (!c || !t.contains(c)) {
292
- o.preventDefault(), (o.shiftKey ? i : s).focus();
293
+ if (!s || !t.contains(s)) {
294
+ e.preventDefault(), (e.shiftKey ? r : n).focus();
293
295
  return;
294
296
  }
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)
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)
299
301
  throw new Error("Invalid modal system instance.");
300
- return o;
301
- }, mt = (t) => Z(t).store, pt = (t) => {
302
- const o = Z(t);
303
- o.providerCount += 1;
304
- let e = !0;
302
+ return e;
303
+ }, ht = (t) => tt(t).store, gt = (t) => {
304
+ const e = tt(t);
305
+ e.providerCount += 1;
306
+ let o = !0;
305
307
  return () => {
306
- e && (e = !1, o.providerCount -= 1, queueMicrotask(() => {
307
- o.providerCount === 0 && t.cancelAll("provider-unmounted");
308
+ o && (o = !1, e.providerCount -= 1, queueMicrotask(() => {
309
+ e.providerCount === 0 && t.cancelAll("provider-unmounted");
308
310
  }));
309
311
  };
310
- }, _t = (t) => {
311
- const o = it(() => ({
312
+ }, Lt = (t) => {
313
+ const e = lt(() => ({
312
314
  activeModals: []
313
315
  }));
314
- let e = 0;
315
- const s = (p) => {
316
- o.setState((l) => ({
317
- activeModals: l.activeModals.filter((b) => b.id !== p)
316
+ let o = 0;
317
+ const n = (m) => {
318
+ e.setState((d) => ({
319
+ activeModals: d.activeModals.filter((b) => b.id !== m)
318
320
  }));
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];
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];
325
327
  if (!a)
326
- throw new Error(`Unknown modal "${p}".`);
328
+ throw new Error(`Unknown modal "${m}".`);
327
329
  if (a.policy === "singleton") {
328
- const m = o.getState().activeModals.find((M) => M.name === p);
329
- if (m)
330
- return m.promise;
330
+ const p = e.getState().activeModals.find((c) => c.name === m);
331
+ if (p)
332
+ return p.promise;
331
333
  }
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,
342
- input: l,
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,
343
345
  definition: a,
344
346
  options: b,
345
- promise: n,
346
- resolve(m) {
347
- r({ status: "resolved", value: m });
347
+ promise: i,
348
+ resolve(p) {
349
+ g({ status: "resolved", value: p });
348
350
  },
349
- cancel(m = "programmatic") {
350
- r({ status: "cancelled", reason: m });
351
+ cancel(p = "programmatic") {
352
+ g({ status: "cancelled", reason: p });
351
353
  }
352
354
  };
353
- return o.setState((m) => ({
354
- activeModals: [...m.activeModals, T]
355
- })), n;
355
+ return e.setState((p) => ({
356
+ activeModals: [...p.activeModals, S]
357
+ })), i;
356
358
  },
357
- cancel: i,
358
- cancelAll: (p = "programmatic") => {
359
- const l = [...o.getState().activeModals].reverse();
360
- for (const b of l)
361
- b.cancel(p);
359
+ cancel: r,
360
+ cancelAll: (m = "programmatic") => {
361
+ const d = [...e.getState().activeModals].reverse();
362
+ for (const b of d)
363
+ b.cancel(m);
362
364
  }
363
365
  };
364
- return X.set(u, {
365
- store: o,
366
+ return Y.set(l, {
367
+ store: e,
366
368
  providerCount: 0
367
- }), u;
368
- }, q = (t, o) => {
369
- t && (t.style.position = "relative", t.style.zIndex = String(R + o));
370
- }, kt = ({
369
+ }), l;
370
+ }, X = (t, e) => {
371
+ t && (t.style.position = "relative", t.style.zIndex = String(I + e));
372
+ }, Rt = ({
371
373
  system: t,
372
- defaultOptions: o,
373
- portalRoot: e
374
+ defaultOptions: e,
375
+ portalRoot: o
374
376
  }) => {
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)
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)
385
393
  return;
386
- const r = b.current;
387
- return q(l.current, z(n, r)), () => lt(n, r);
388
- }, [n, v]), k(() => {
389
- if (!n || !v)
394
+ const c = b.current;
395
+ return X(d.current, U(i, c)), () => mt(i, c);
396
+ }, [i, v]), O(() => {
397
+ if (!i || !v)
390
398
  return;
391
- const r = b.current, T = n.defaultView;
392
- if (!T)
399
+ const c = b.current, h = i.defaultView;
400
+ if (!h)
393
401
  return;
394
- const M = W(
395
- o,
396
- c?.definition.preset ? {
397
- position: c.definition.preset.position,
398
- motion: c.definition.preset.motion
402
+ const x = Q(
403
+ e,
404
+ s?.definition.preset ? {
405
+ position: s.definition.preset.position,
406
+ motion: s.definition.preset.motion
399
407
  } : void 0,
400
- c?.definition.defaultOptions,
401
- c?.options
402
- ).closeOnPressEsc ?? !0, _ = (y) => l.current?.querySelector(
408
+ s?.definition.defaultOptions,
409
+ s?.options
410
+ ).closeOnPressEsc ?? !0, _ = (y) => d.current?.querySelector(
403
411
  `[data-modal-id="${y}"]`
404
412
  ), f = (y) => {
405
- if (x(n, r)) {
406
- if (y.key === "Escape" && M) {
407
- c?.cancel("escape");
413
+ if (D(i, c)) {
414
+ if (y.key === "Escape" && x) {
415
+ s?.cancel("escape");
408
416
  return;
409
417
  }
410
- ft(_(c?.id ?? ""), y);
418
+ vt(_(s?.id ?? ""), y);
411
419
  }
412
- }, E = (y) => {
413
- const L = l.current, I = y.target;
420
+ }, T = (y) => {
421
+ const L = d.current, C = y.target;
414
422
  if (!L)
415
423
  return;
416
- if (I && L.contains(I)) {
417
- a.current = I instanceof HTMLElement ? I : null;
424
+ if (C && L.contains(C)) {
425
+ a.current = C instanceof HTMLElement ? C : null;
418
426
  return;
419
427
  }
420
- if (!x(n, r) || !c)
428
+ if (!D(i, c) || !s)
421
429
  return;
422
- const H = _(c.id), J = [
430
+ const W = _(s.id), et = [
423
431
  a.current,
424
- ...C(H)
432
+ ...N(W)
425
433
  ];
426
- for (const B of J)
427
- if (B?.isConnected && (B.focus(), n.activeElement === B))
434
+ for (const F of et)
435
+ if (F?.isConnected && (F.focus(), i.activeElement === F))
428
436
  return;
429
- H?.focus();
437
+ W?.focus();
430
438
  }, w = (y) => {
431
- if (!x(n, r) || !y.cancelable)
439
+ if (!D(i, c) || !y.cancelable)
432
440
  return;
433
- const L = l.current;
441
+ const L = d.current;
434
442
  L && y.composedPath().includes(L) || y.preventDefault();
435
443
  };
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);
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);
438
446
  };
439
- }, [c, o, n, v]), k(() => {
440
- if (!n || !v)
447
+ }, [s, e, i, v]), O(() => {
448
+ if (!i || !g)
441
449
  return;
442
- const r = b.current;
443
- return ct(n, r), () => at(n, r);
444
- }, [n, v]), k(() => {
445
- if (!n || !u)
450
+ const c = b.current;
451
+ return ft(i, c), () => pt(i, c);
452
+ }, [i, g]), O(() => {
453
+ if (!i || !l)
446
454
  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(
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(
450
458
  f.id,
451
- n.activeElement ?? null
459
+ i.activeElement ?? null
452
460
  );
453
- if (O.current = T, M.length > 0) {
454
- q(l.current, z(n, r));
455
- const f = T[T.length - 1];
461
+ if (k.current = h, x.length > 0) {
462
+ X(d.current, U(i, c));
463
+ const f = h[h.length - 1];
456
464
  if (f) {
457
- const E = l.current?.querySelector(
465
+ const T = d.current?.querySelector(
458
466
  `[data-modal-id="${f}"]`
459
467
  );
460
- (C(E)[0] ?? E)?.focus();
468
+ (N(T)[0] ?? T)?.focus();
461
469
  }
462
470
  return;
463
471
  }
464
472
  if (_.length > 0) {
465
- const f = _[_.length - 1], E = f ? h.current.get(f) ?? null : null;
473
+ const f = _[_.length - 1], T = f ? E.current.get(f) ?? null : null;
466
474
  for (const y of _)
467
- h.current.delete(y);
468
- if (E?.isConnected && (E.focus(), n.activeElement === E))
475
+ E.current.delete(y);
476
+ if (T?.isConnected && (T.focus(), i.activeElement === T))
469
477
  return;
470
- const w = i[i.length - 1];
478
+ const w = r[r.length - 1];
471
479
  if (w) {
472
- const y = l.current?.querySelector(
480
+ const y = d.current?.querySelector(
473
481
  `[data-modal-id="${w.id}"]`
474
482
  );
475
- (C(y)[0] ?? y)?.focus();
483
+ (N(y)[0] ?? y)?.focus();
476
484
  }
477
485
  }
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,
486
+ }, [r, i, l]), l ? at(
487
+ /* @__PURE__ */ M("div", { className: "react-motion-modal", ref: d, children: /* @__PURE__ */ M(
488
+ rt,
481
489
  {
482
- data: r,
483
- index: T,
484
- isActive: c?.id === r.id,
485
- defaultOptions: o
486
- },
487
- r.id
488
- )) }) }),
489
- u
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
490
506
  ) : null;
491
- }, gt = (t) => t;
507
+ }, St = (t) => t;
492
508
  export {
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
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
499
515
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-motion-modal",
3
- "version": "2.0.2",
3
+ "version": "2.1.0",
4
4
  "type": "module",
5
5
  "sideEffects": [
6
6
  "**/*.css"