react-motion-modal 2.0.0 → 2.0.1

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.
Files changed (2) hide show
  1. package/dist/index.js +46 -43
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { jsxs as A, jsx as _ } from "react/jsx-runtime";
1
+ import { jsxs as F, jsx as _ } from "react/jsx-runtime";
2
2
  import { useReducedMotion as D, useIsPresent as G, motion as E, AnimatePresence as H } from "motion/react";
3
3
  import { useState as j, useRef as h, useEffect as v } from "react";
4
4
  import { createPortal as $ } from "react-dom";
@@ -23,7 +23,7 @@ const a = {
23
23
  }, g = {
24
24
  duration: 0.18,
25
25
  ease: "easeIn"
26
- }, I = {
26
+ }, C = {
27
27
  initial: { opacity: 0 },
28
28
  animate: {
29
29
  opacity: 1,
@@ -37,7 +37,7 @@ const a = {
37
37
  x: o = 0,
38
38
  y: t = 0
39
39
  }) => ({
40
- backdrop: I,
40
+ backdrop: C,
41
41
  content: {
42
42
  initial: { opacity: 0, x: o, y: t },
43
43
  animate: {
@@ -57,7 +57,7 @@ const a = {
57
57
  dialog: () => ({
58
58
  position: a.CENTER,
59
59
  motion: {
60
- backdrop: I,
60
+ backdrop: C,
61
61
  content: {
62
62
  initial: { opacity: 0, scale: 0.96 },
63
63
  animate: {
@@ -91,7 +91,7 @@ const a = {
91
91
  })
92
92
  };
93
93
  }
94
- }, N = (...o) => o.filter(Boolean).join(" "), S = (o) => {
94
+ }, N = (...o) => o.filter(Boolean).join(" "), I = (o) => {
95
95
  switch (o) {
96
96
  case a.TOP:
97
97
  return "react-motion-modal__body--top";
@@ -118,7 +118,7 @@ const a = {
118
118
  case a.CENTER_FULL:
119
119
  return "react-motion-modal__body--center-full";
120
120
  default:
121
- return S(a.CENTER);
121
+ return I(a.CENTER);
122
122
  }
123
123
  }, k = (o, t) => {
124
124
  if (!(!o && !t))
@@ -137,12 +137,12 @@ const a = {
137
137
  Object.assign(t, r), t.backdrop = u, t.body = s;
138
138
  }
139
139
  return t;
140
- }, C = {
140
+ }, w = {
141
141
  initial: { opacity: 1 },
142
142
  animate: { opacity: 1, transition: { duration: 0 } },
143
143
  exit: { opacity: 1, transition: { duration: 0 } }
144
144
  }, z = ({ data: o, index: t, isActive: r, defaultOptions: u }) => {
145
- const s = D(), n = G(), m = r && n, {
145
+ const s = D(), i = G(), m = r && i, {
146
146
  component: c,
147
147
  defaultOptions: l,
148
148
  preset: d
@@ -154,8 +154,8 @@ const a = {
154
154
  } : void 0,
155
155
  l,
156
156
  o.options
157
- ), i = e.position ?? a.CENTER, f = e.closeOnClickOutside ?? !0, y = s ? C : e.motion?.content, b = s ? C : e.motion?.backdrop;
158
- return /* @__PURE__ */ A(
157
+ ), n = e.position ?? a.CENTER, f = e.closeOnClickOutside ?? !0, y = s ? w : e.motion?.content, b = s ? w : e.motion?.backdrop;
158
+ return /* @__PURE__ */ F(
159
159
  E.div,
160
160
  {
161
161
  className: "react-motion-modal__root",
@@ -201,7 +201,7 @@ const a = {
201
201
  "data-modal-id": o.id,
202
202
  className: N(
203
203
  "react-motion-modal__body",
204
- S(i),
204
+ I(n),
205
205
  m && "react-motion-modal__body--active",
206
206
  e.body?.className
207
207
  ),
@@ -239,23 +239,23 @@ const a = {
239
239
  "input:not([disabled])",
240
240
  "select:not([disabled])",
241
241
  '[tabindex]:not([tabindex="-1"])'
242
- ].join(","), P = (o) => o ? Array.from(
242
+ ].join(","), S = (o) => o ? Array.from(
243
243
  o.querySelectorAll(q)
244
244
  ).filter((t) => t.getClientRects().length > 0) : [], W = (o, t) => {
245
245
  if (!o || t.key !== "Tab")
246
246
  return;
247
- const r = P(o), u = r[0], s = r[r.length - 1], n = document.activeElement;
247
+ const r = S(o), u = r[0], s = r[r.length - 1], i = document.activeElement;
248
248
  if (!u || !s) {
249
249
  t.preventDefault(), o.focus();
250
250
  return;
251
251
  }
252
- if (!n || !o.contains(n)) {
252
+ if (!i || !o.contains(i)) {
253
253
  t.preventDefault(), (t.shiftKey ? s : u).focus();
254
254
  return;
255
255
  }
256
- t.shiftKey && n === u ? (t.preventDefault(), s.focus()) : !t.shiftKey && n === s && (t.preventDefault(), u.focus());
257
- }, w = /* @__PURE__ */ new WeakMap(), x = (o) => {
258
- const t = w.get(o);
256
+ t.shiftKey && i === u ? (t.preventDefault(), s.focus()) : !t.shiftKey && i === s && (t.preventDefault(), u.focus());
257
+ }, P = /* @__PURE__ */ new WeakMap(), x = (o) => {
258
+ const t = P.get(o);
259
259
  if (!t)
260
260
  throw new Error("Invalid modal system instance.");
261
261
  return t;
@@ -286,19 +286,19 @@ const a = {
286
286
  if (!e)
287
287
  throw new Error(`Unknown modal "${c}".`);
288
288
  if (e.policy === "singleton") {
289
- const p = t.getState().activeModals.find((F) => F.name === c);
289
+ const p = t.getState().activeModals.find((A) => A.name === c);
290
290
  if (p)
291
291
  return p.promise;
292
292
  }
293
293
  e.policy === "replace" && s("replaced");
294
- const i = `${c}-${++r}`;
294
+ const n = `${c}-${++r}`;
295
295
  let f = !1, y;
296
296
  const b = new Promise((p) => {
297
297
  y = p;
298
298
  }), T = (p) => {
299
- f || (f = !0, u(i), y?.(p));
299
+ f || (f = !0, u(n), y?.(p));
300
300
  }, B = {
301
- id: i,
301
+ id: n,
302
302
  name: c,
303
303
  input: l,
304
304
  definition: e,
@@ -322,7 +322,7 @@ const a = {
322
322
  d.cancel(c);
323
323
  }
324
324
  };
325
- return w.set(m, {
325
+ return P.set(m, {
326
326
  store: t,
327
327
  providerCount: 0
328
328
  }), m;
@@ -331,39 +331,42 @@ const a = {
331
331
  defaultOptions: t,
332
332
  portalRoot: r
333
333
  }) => {
334
- const u = X(o), s = K(u, (i) => i.activeModals), n = s[s.length - 1], [m, c] = j(
334
+ const u = X(o), s = K(u, (n) => n.activeModals), i = s[s.length - 1], [m, c] = j(
335
335
  r ?? null
336
336
  ), l = h(null), d = h(null), e = s.length > 0;
337
337
  return v(() => {
338
338
  c(r ?? document.body);
339
339
  }, [r]), v(() => Z(o), [o]), v(() => {
340
+ const n = () => o.cancelAll("programmatic");
341
+ return window.addEventListener("popstate", n), () => window.removeEventListener("popstate", n);
342
+ }, [o]), v(() => {
340
343
  if (!e)
341
344
  return;
342
345
  const f = L(
343
346
  t,
344
- n?.definition.preset ? {
345
- position: n.definition.preset.position,
346
- motion: n.definition.preset.motion
347
+ i?.definition.preset ? {
348
+ position: i.definition.preset.position,
349
+ motion: i.definition.preset.motion
347
350
  } : void 0,
348
- n?.definition.defaultOptions,
349
- n?.options
351
+ i?.definition.defaultOptions,
352
+ i?.options
350
353
  ).closeOnPressEsc ?? !0, y = (b) => {
351
354
  if (b.key === "Escape" && f) {
352
- n?.cancel("escape");
355
+ i?.cancel("escape");
353
356
  return;
354
357
  }
355
- const T = n ? l.current?.querySelector(
356
- `[data-modal-id="${n.id}"]`
358
+ const T = i ? l.current?.querySelector(
359
+ `[data-modal-id="${i.id}"]`
357
360
  ) : void 0;
358
361
  W(T, b);
359
362
  };
360
363
  return window.addEventListener("keydown", y), () => window.removeEventListener("keydown", y);
361
- }, [n, t, e]), v(() => {
364
+ }, [i, t, e]), v(() => {
362
365
  if (!e)
363
366
  return;
364
- const { body: i } = document, f = i.style.overflow;
365
- return i.style.overflow = "hidden", () => {
366
- i.style.overflow = f;
367
+ const { body: n } = document, f = n.style.overflow;
368
+ return n.style.overflow = "hidden", () => {
369
+ n.style.overflow = f;
367
370
  };
368
371
  }, [e]), v(() => {
369
372
  if (!m)
@@ -373,20 +376,20 @@ const a = {
373
376
  return;
374
377
  }
375
378
  d.current === null && (d.current = document.activeElement ?? null);
376
- const i = n ? l.current?.querySelector(
377
- `[data-modal-id="${n.id}"]`
379
+ const n = i ? l.current?.querySelector(
380
+ `[data-modal-id="${i.id}"]`
378
381
  ) : void 0;
379
- i && (P(i)[0] ?? i).focus();
380
- }, [n, e, m]), m ? $(
381
- /* @__PURE__ */ _("div", { className: "react-motion-modal", ref: l, children: /* @__PURE__ */ _(H, { initial: !0, mode: "sync", children: s.map((i, f) => /* @__PURE__ */ _(
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__ */ _(
382
385
  z,
383
386
  {
384
- data: i,
387
+ data: n,
385
388
  index: f,
386
- isActive: n?.id === i.id,
389
+ isActive: i?.id === n.id,
387
390
  defaultOptions: t
388
391
  },
389
- i.id
392
+ n.id
390
393
  )) }) }),
391
394
  m
392
395
  ) : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-motion-modal",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "type": "module",
5
5
  "sideEffects": [
6
6
  "**/*.css"