react-modal-navigation 1.1.2 → 1.1.4

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.js CHANGED
@@ -1,104 +1,106 @@
1
- import { jsx as m, jsxs as ae } from "react/jsx-runtime";
2
- import qe, { createContext as he, useRef as u, useState as W, useEffect as O, useReducer as Ae, useCallback as d, useMemo as V, useLayoutEffect as De, useInsertionEffect as $e, useContext as ee } from "react";
3
- import { createPortal as Oe } from "react-dom";
4
- const Te = he(null), Re = he(null), be = he(null), Me = he(null), Be = he(null);
5
- let je = 0;
6
- const Ee = (e, n) => ({ key: `modal-route-${++je}`, name: e, params: n ?? {} }), Pe = (e, n) => [Ee(e, n)];
7
- function Ie(e, n) {
1
+ import { jsx as f, jsxs as oe } from "react/jsx-runtime";
2
+ import Ae, { createContext as he, useRef as d, useState as Q, useEffect as I, useReducer as je, useCallback as m, useMemo as V, useLayoutEffect as De, useInsertionEffect as $e, useContext as ee } from "react";
3
+ import { createPortal as Ie } from "react-dom";
4
+ const Pe = he(null), Ce = he(null), we = he(null), Se = he(null), Fe = he(null);
5
+ let He = 0;
6
+ const Me = (e, n) => ({ key: `modal-route-${++He}`, name: e, params: n ?? {} }), Oe = (e, n) => [Me(e, n)];
7
+ function ze(e, n) {
8
8
  switch (n.type) {
9
9
  case "RESET":
10
- return Pe(n.name, n.params);
10
+ return Oe(n.name, n.params);
11
11
  case "NAVIGATE": {
12
- const r = e.findIndex((s) => s.name === n.name);
13
- return r < 0 ? [...e, Ee(n.name, n.params)] : e.slice(0, r + 1).map((s, c) => c === r ? { ...s, params: n.params ?? {} } : s);
12
+ const r = e.findIndex((o) => o.name === n.name);
13
+ return r < 0 ? [...e, Me(n.name, n.params)] : e.slice(0, r + 1).map((o, s) => s === r ? { ...o, params: n.params ?? {} } : o);
14
14
  }
15
+ case "SET_OPTIONS":
16
+ return e.map((r, o) => o === e.length - 1 ? { ...r, options: { ...r.options ?? {}, ...n.options ?? {} } } : r);
15
17
  case "SET_PARAMS":
16
- return e.map((r, s) => s === e.length - 1 ? { ...r, params: { ...r.params ?? {}, ...n.params ?? {} } } : r);
18
+ return e.map((r, o) => o === e.length - 1 ? { ...r, params: { ...r.params ?? {}, ...n.params ?? {} } } : r);
17
19
  case "BACK":
18
20
  return e.length > 1 ? e.slice(0, -1) : e;
19
21
  case "REPLACE":
20
- return e.length ? [...e.slice(0, -1), Ee(n.name, n.params)] : e;
22
+ return e.length ? [...e.slice(0, -1), Me(n.name, n.params)] : e;
21
23
  default:
22
24
  return e;
23
25
  }
24
26
  }
25
- const Se = () => {
27
+ const Ne = () => {
26
28
  if (typeof document > "u") return "light";
27
29
  const e = document.documentElement, n = document.body;
28
30
  return e.classList.contains("dark") || n.classList.contains("dark") || e.dataset.theme === "dark" || n.dataset.theme === "dark" ? "dark" : e.classList.contains("light") || n.classList.contains("light") || e.dataset.theme === "light" || n.dataset.theme === "light" ? "light" : window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
29
31
  };
30
32
  let fe = 0;
31
- const oe = [];
32
- let we = null;
33
- function He() {
33
+ const re = [];
34
+ let Ee = null;
35
+ function Ge() {
34
36
  if (fe++, fe === 1) {
35
- const n = document.documentElement, r = document.body, s = { html: n.style.overflow, body: r.style.overflow, padding: r.style.paddingRight, width: r.style.getPropertyValue("--modal-scrollbar-width") }, c = Math.max(0, window.innerWidth - n.clientWidth), g = parseFloat(getComputedStyle(r).paddingRight) || 0;
36
- c && (r.style.paddingRight = `${g + c}px`), r.style.setProperty("--modal-scrollbar-width", `${c}px`), n.style.overflow = "hidden", r.style.overflow = "hidden", we = () => {
37
- n.style.overflow = s.html, r.style.overflow = s.body, r.style.paddingRight = s.padding, s.width ? r.style.setProperty("--modal-scrollbar-width", s.width) : r.style.removeProperty("--modal-scrollbar-width");
37
+ const n = document.documentElement, r = document.body, o = { html: n.style.overflow, body: r.style.overflow, padding: r.style.paddingRight, width: r.style.getPropertyValue("--modal-scrollbar-width") }, s = Math.max(0, window.innerWidth - n.clientWidth), v = parseFloat(getComputedStyle(r).paddingRight) || 0;
38
+ s && (r.style.paddingRight = `${v + s}px`), r.style.setProperty("--modal-scrollbar-width", `${s}px`), n.style.overflow = "hidden", r.style.overflow = "hidden", Ee = () => {
39
+ n.style.overflow = o.html, r.style.overflow = o.body, r.style.paddingRight = o.padding, o.width ? r.style.setProperty("--modal-scrollbar-width", o.width) : r.style.removeProperty("--modal-scrollbar-width");
38
40
  };
39
41
  }
40
42
  let e = !1;
41
43
  return () => {
42
- e || (e = !0, fe = Math.max(0, fe - 1), fe || (we?.(), we = null));
44
+ e || (e = !0, fe = Math.max(0, fe - 1), fe || (Ee?.(), Ee = null));
43
45
  };
44
46
  }
45
- const Ge = 'a[href],button:not([disabled]),input:not([disabled]),textarea:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])', ze = (e) => !e.closest('[inert], [hidden], [aria-hidden="true"]') && e.getClientRects().length > 0 && getComputedStyle(e).visibility !== "hidden" && getComputedStyle(e).display !== "none";
46
- function Ke({ dialogRef: e, options: n, requestClose: r, children: s, exiting: c = !1 }) {
47
- const g = u(null), v = u(null), w = u(r);
48
- w.current = r;
49
- const f = u(n.closeOnEsc);
50
- f.current = n.closeOnEsc;
51
- const [N, E] = W(Se), y = n.theme === "light" || n.theme === "dark" ? n.theme : N;
52
- O(() => {
47
+ const Ke = 'a[href],button:not([disabled]),input:not([disabled]),textarea:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])', Ue = (e) => !e.closest('[inert], [hidden], [aria-hidden="true"]') && e.getClientRects().length > 0 && getComputedStyle(e).visibility !== "hidden" && getComputedStyle(e).display !== "none";
48
+ function We({ dialogRef: e, options: n, requestClose: r, children: o, exiting: s = !1 }) {
49
+ const v = d(null), b = d(null), R = d(r);
50
+ R.current = r;
51
+ const h = d(n.closeOnEsc);
52
+ h.current = n.closeOnEsc;
53
+ const [E, T] = Q(Ne), x = n.theme === "light" || n.theme === "dark" ? n.theme : E;
54
+ I(() => {
53
55
  if (n.theme === "light" || n.theme === "dark") return;
54
- const P = () => E(Se()), K = new MutationObserver(P);
55
- for (const T of [document.documentElement, document.body]) K.observe(T, { attributes: !0, attributeFilter: ["class", "data-theme"] });
56
- const k = window.matchMedia?.("(prefers-color-scheme: dark)");
57
- return k?.addEventListener?.("change", P), P(), () => {
58
- K.disconnect(), k?.removeEventListener?.("change", P);
56
+ const L = () => T(Ne()), z = new MutationObserver(L);
57
+ for (const M of [document.documentElement, document.body]) z.observe(M, { attributes: !0, attributeFilter: ["class", "data-theme"] });
58
+ const _ = window.matchMedia?.("(prefers-color-scheme: dark)");
59
+ return _?.addEventListener?.("change", L), L(), () => {
60
+ z.disconnect(), _?.removeEventListener?.("change", L);
59
61
  };
60
- }, [n.theme]), O(() => {
61
- v.current = document.activeElement;
62
- const P = He(), K = g.current;
63
- oe.push(K), e.current?.focus({ preventScroll: !0 });
64
- const k = (C) => {
65
- const x = e.current;
66
- if (!x || oe.at(-1) !== K) return;
67
- if (C.key === "Escape" && f.current !== !1) {
68
- C.preventDefault(), w.current("escape");
62
+ }, [n.theme]), I(() => {
63
+ b.current = document.activeElement;
64
+ const L = Ge(), z = v.current;
65
+ re.push(z), e.current?.focus({ preventScroll: !0 });
66
+ const _ = (y) => {
67
+ const C = e.current;
68
+ if (!C || re.at(-1) !== z) return;
69
+ if (y.key === "Escape" && h.current !== !1) {
70
+ y.preventDefault(), R.current("escape");
69
71
  return;
70
72
  }
71
- if (C.key !== "Tab") return;
72
- const B = [...x.querySelectorAll(Ge)].filter(ze);
73
- if (!B.length) {
74
- C.preventDefault(), x.focus();
73
+ if (y.key !== "Tab") return;
74
+ const F = [...C.querySelectorAll(Ke)].filter(Ue);
75
+ if (!F.length) {
76
+ y.preventDefault(), C.focus();
75
77
  return;
76
78
  }
77
- const G = B[0], S = B.at(-1);
78
- x.contains(document.activeElement) ? C.shiftKey && (document.activeElement === G || document.activeElement === x) ? (C.preventDefault(), S.focus()) : !C.shiftKey && (document.activeElement === S || document.activeElement === x) && (C.preventDefault(), G.focus()) : (C.preventDefault(), (C.shiftKey ? S : G).focus());
79
- }, T = (C) => {
80
- oe.at(-1) === K && e.current && !e.current.contains(C.target) && e.current.focus({ preventScroll: !0 });
79
+ const G = F[0], N = F.at(-1);
80
+ C.contains(document.activeElement) ? y.shiftKey && (document.activeElement === G || document.activeElement === C) ? (y.preventDefault(), N.focus()) : !y.shiftKey && (document.activeElement === N || document.activeElement === C) && (y.preventDefault(), G.focus()) : (y.preventDefault(), (y.shiftKey ? N : G).focus());
81
+ }, M = (y) => {
82
+ re.at(-1) === z && e.current && !e.current.contains(y.target) && e.current.focus({ preventScroll: !0 });
81
83
  };
82
- return document.addEventListener("keydown", k), document.addEventListener("focusin", T), () => {
83
- document.removeEventListener("keydown", k), document.removeEventListener("focusin", T);
84
- const C = oe.at(-1) === K, x = oe.indexOf(K);
85
- if (x !== -1 && oe.splice(x, 1), P(), C) {
86
- const B = v.current;
87
- B?.isConnected && !B.closest("[inert], [hidden]") ? B.focus?.({ preventScroll: !0 }) : oe.at(-1)?.querySelector("[role=dialog]")?.focus?.({ preventScroll: !0 });
84
+ return document.addEventListener("keydown", _), document.addEventListener("focusin", M), () => {
85
+ document.removeEventListener("keydown", _), document.removeEventListener("focusin", M);
86
+ const y = re.at(-1) === z, C = re.indexOf(z);
87
+ if (C !== -1 && re.splice(C, 1), L(), y) {
88
+ const F = b.current;
89
+ F?.isConnected && !F.closest("[inert], [hidden]") ? F.focus?.({ preventScroll: !0 }) : re.at(-1)?.querySelector("[role=dialog]")?.focus?.({ preventScroll: !0 });
88
90
  }
89
91
  };
90
92
  }, [e]);
91
- const p = n.backgroundColor ?? n.backgroudColor, h = typeof p == "string" ? p : p?.[y], b = typeof h == "string" && /^(#|rgb\(|rgba\(|hsl\(|hsla\(|oklch\(|color\(|var\()/.test(h.trim()) ? h : null, D = { sm: 400, md: 560, lg: 720, xl: 960, full: "100%" }, F = ["center", "left", "right", "top", "bottom"].includes(n.placement) ? n.placement : "right", q = (P) => typeof P == "number" ? `${P}px` : P, A = q(n.width ?? D[n.size] ?? 460), R = q(n.height), j = q(n.maxHeight), M = q(n.maxWidth), I = Number(n.viewportGap ?? 5), H = Number.isFinite(I) ? Math.max(0, I) : 5, z = typeof n.borderRadius == "number" ? `${n.borderRadius}px` : n.borderRadius ?? "12px";
92
- return Oe(/* @__PURE__ */ m(
93
+ const k = n.backgroundColor ?? n.backgroudColor, l = typeof k == "string" ? k : k?.[x], g = typeof l == "string" && /^(#|rgb\(|rgba\(|hsl\(|hsla\(|oklch\(|color\(|var\()/.test(l.trim()) ? l : null, A = { sm: 400, md: 560, lg: 720, xl: 960, full: "100%" }, B = ["center", "left", "right", "top", "bottom"].includes(n.placement) ? n.placement : "right", H = (L) => typeof L == "number" ? `${L}px` : L, O = H(n.width ?? A[n.size] ?? 460), D = H(n.height), S = H(n.maxHeight), j = H(n.maxWidth), P = Number(n.viewportGap ?? 5), $ = Number.isFinite(P) ? Math.max(0, P) : 5, q = typeof n.borderRadius == "number" ? `${n.borderRadius}px` : n.borderRadius ?? "12px";
94
+ return Ie(/* @__PURE__ */ f(
93
95
  "div",
94
96
  {
95
- ref: g,
96
- className: `pmn-overlay ${c ? "pmn-exiting" : "pmn-entering"} ${n.animation === !1 ? "pmn-no-animation" : ""} pmn-place-${F} ${n.mobileFullscreen ? "pmn-mobile-fullscreen" : ""}`,
97
- style: { padding: H, "--pmn-animation-duration": `${Math.min(1e3, Math.max(0, Number(n.animationDuration ?? 220) || 0))}ms` },
98
- onMouseDown: (P) => {
99
- P.target === P.currentTarget && n.closeOnOverlay === !0 && w.current("overlay");
97
+ ref: v,
98
+ className: `pmn-overlay ${s ? "pmn-exiting" : "pmn-entering"} ${n.animation === !1 ? "pmn-no-animation" : ""} pmn-place-${B} ${n.mobileFullscreen ? "pmn-mobile-fullscreen" : ""}`,
99
+ style: { padding: $, "--pmn-animation-duration": `${Math.min(1e3, Math.max(0, Number(n.animationDuration ?? 220) || 0))}ms` },
100
+ onMouseDown: (L) => {
101
+ L.target === L.currentTarget && n.closeOnOverlay === !0 && R.current("overlay");
100
102
  },
101
- children: /* @__PURE__ */ m(
103
+ children: /* @__PURE__ */ f(
102
104
  "section",
103
105
  {
104
106
  ref: e,
@@ -106,62 +108,62 @@ function Ke({ dialogRef: e, options: n, requestClose: r, children: s, exiting: c
106
108
  role: "dialog",
107
109
  "aria-modal": "true",
108
110
  "aria-label": n.ariaLabel ?? "Dialog",
109
- "data-modal-theme": y,
110
- className: `pmn-dialog ${y === "dark" ? "dark" : ""} ${!b && h ? h : ""} ${n.className ?? ""}`,
111
- style: { "--pmn-width": A, "--pmn-gap": `${H}px`, ...R !== void 0 ? { "--pmn-height": R } : {}, ...j !== void 0 ? { "--pmn-max-height": j } : {}, ...M !== void 0 ? { "--pmn-max-width": M } : {}, borderRadius: z, ...b ? { backgroundColor: b } : {} },
112
- children: s
111
+ "data-modal-theme": x,
112
+ className: `pmn-dialog ${x === "dark" ? "dark" : ""} ${!g && l ? l : ""} ${n.className ?? ""}`,
113
+ style: { "--pmn-width": O, "--pmn-gap": `${$}px`, ...D !== void 0 ? { "--pmn-height": D } : {}, ...S !== void 0 ? { "--pmn-max-height": S } : {}, ...j !== void 0 ? { "--pmn-max-width": j } : {}, borderRadius: q, ...g ? { backgroundColor: g } : {} },
114
+ children: o
113
115
  }
114
116
  )
115
117
  }
116
118
  ), document.body);
117
119
  }
118
120
  function Le({ back: e }) {
119
- return /* @__PURE__ */ m("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", width: "20", height: "20", fill: "none", stroke: "currentColor", strokeWidth: "2", children: e ? /* @__PURE__ */ m("path", { d: "m15 18-6-6 6-6" }) : /* @__PURE__ */ m("path", { d: "M18 6 6 18M6 6l12 12" }) });
121
+ return /* @__PURE__ */ f("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", width: "20", height: "20", fill: "none", stroke: "currentColor", strokeWidth: "2", children: e ? /* @__PURE__ */ f("path", { d: "m15 18-6-6 6-6" }) : /* @__PURE__ */ f("path", { d: "M18 6 6 18M6 6l12 12" }) });
120
122
  }
121
- function Ue({ options: e, screen: n, route: r, navigation: s, requestClose: c, translate: g }) {
123
+ function Ye({ options: e, screen: n, route: r, navigation: o, requestClose: s, translate: v }) {
122
124
  if (e.showHeader === !1) return null;
123
- const v = g ?? ((p) => p), w = n.showTitle ?? e.showTitle ?? !0, f = typeof n.title == "function" ? n.title({ t: v, route: r, navigation: s }) : n.title ?? r.name, N = { route: r, navigation: s, close: c, canGoBack: s.canGoBack, title: f, t: v }, E = n.renderHeader ?? e.renderHeader;
124
- if (E) return E(N);
125
- const y = n.renderHeaderRight ?? e.renderHeaderRight;
126
- return /* @__PURE__ */ ae("header", { className: `pmn-header ${n.showHeaderBorder ?? e.showHeaderBorder ? "pmn-border-bottom" : ""} ${e.headerClassName ?? ""}`, children: [
127
- e.showBackButton !== !1 && s.canGoBack && /* @__PURE__ */ m("button", { type: "button", className: "pmn-icon-button", "aria-label": v("modal.back"), onClick: () => s.goBack(), children: /* @__PURE__ */ m(Le, { back: !0 }) }),
128
- w ? /* @__PURE__ */ m("h2", { children: f }) : /* @__PURE__ */ m("div", { className: "pmn-header-spacer" }),
129
- y?.(N),
130
- e.showCloseButton !== !1 && /* @__PURE__ */ m("button", { type: "button", className: "pmn-icon-button", "aria-label": v("modal.close"), onClick: () => c("header"), children: /* @__PURE__ */ m(Le, {}) })
125
+ const b = v ?? ((k) => k), R = n.showTitle ?? e.showTitle ?? !0, h = typeof n.title == "function" ? n.title({ t: b, route: r, navigation: o }) : n.title ?? r.name, E = { route: r, navigation: o, close: s, canGoBack: o.canGoBack, title: h, t: b }, T = n.renderHeader ?? e.renderHeader;
126
+ if (T) return T(E);
127
+ const x = n.renderHeaderRight ?? e.renderHeaderRight;
128
+ return /* @__PURE__ */ oe("header", { className: `pmn-header ${n.showHeaderBorder ?? e.showHeaderBorder ? "pmn-border-bottom" : ""} ${e.headerClassName ?? ""}`, children: [
129
+ e.showBackButton !== !1 && o.canGoBack && /* @__PURE__ */ f("button", { type: "button", className: "pmn-icon-button", "aria-label": b("modal.back"), onClick: () => o.goBack(), children: /* @__PURE__ */ f(Le, { back: !0 }) }),
130
+ R ? /* @__PURE__ */ f("h2", { children: h }) : /* @__PURE__ */ f("div", { className: "pmn-header-spacer" }),
131
+ x?.(E),
132
+ e.showCloseButton !== !1 && /* @__PURE__ */ f("button", { type: "button", className: "pmn-icon-button", "aria-label": b("modal.close"), onClick: () => s("header"), children: /* @__PURE__ */ f(Le, {}) })
131
133
  ] });
132
134
  }
133
- function We({ screen: e, options: n, override: r, route: s, navigation: c, requestClose: g, translate: v, onError: w }) {
134
- const [f, N] = W(!1), E = v ?? ((M) => M), y = { ...n, ...e, ...r }, { showFooter: p, renderFooter: h, done: b, cancel: D, cancle: F } = y, q = D ?? F, A = { route: s, navigation: c, close: g, t: E };
135
- if (p === !1) return null;
136
- const R = `pmn-footer ${y.showFooterBorder ? "pmn-border-top" : ""} ${y.footerClassName ?? ""}`;
137
- if (typeof h == "function") return /* @__PURE__ */ m("footer", { className: R, children: h({ ...A, pending: f }) });
138
- if (typeof b != "function" && typeof q != "function") return null;
139
- const j = async (M) => {
140
- if (!(f || typeof M != "function")) {
141
- N(!0);
142
- try {
143
- await M(A);
144
- } catch (I) {
145
- w?.(I, { phase: "footer", route: s });
146
- } finally {
147
- N(!1);
148
- }
135
+ function _e({ screen: e, options: n, override: r, route: o, navigation: s, requestClose: v, translate: b, onError: R, loadingApi: h }) {
136
+ const [E, T] = Q(!1), x = b ?? ((P) => P), k = { ...n, ...e, ...r }, { showFooter: l, renderFooter: g, done: A, cancel: B, cancle: H } = k, O = B ?? H, D = { route: o, navigation: s, close: v, t: x };
137
+ if (l === !1) return null;
138
+ const S = `pmn-footer ${k.showFooterBorder ? "pmn-border-top" : ""} ${k.footerClassName ?? ""}`;
139
+ if (typeof g == "function") return /* @__PURE__ */ f("footer", { className: S, children: g({ ...D, pending: E }) });
140
+ if (typeof A != "function" && typeof O != "function") return null;
141
+ const j = async (P) => {
142
+ if (E || typeof P != "function") return;
143
+ T(!0);
144
+ const $ = h?.begin(o.key, k.loadingText ?? x("modal.processing"));
145
+ try {
146
+ await P(D);
147
+ } catch (q) {
148
+ R?.(q, { phase: "footer", route: o });
149
+ } finally {
150
+ h?.end(o.key, $), T(!1);
149
151
  }
150
152
  };
151
- return /* @__PURE__ */ ae("footer", { className: R, children: [
152
- typeof q == "function" && /* @__PURE__ */ m("button", { type: "button", disabled: f, onClick: () => j(q), className: "pmn-button pmn-button-secondary", children: y.cancelText ?? E("modal.cancel") }),
153
- typeof b == "function" && /* @__PURE__ */ m("button", { type: "button", disabled: f || y.doneDisabled === !0, onClick: () => j(b), className: "pmn-button pmn-button-primary", children: f ? y.loadingText ?? E("modal.processing") : y.doneText ?? E("modal.done") })
153
+ return /* @__PURE__ */ oe("footer", { className: S, children: [
154
+ typeof O == "function" && /* @__PURE__ */ f("button", { type: "button", disabled: E, onClick: () => j(O), className: "pmn-button pmn-button-secondary", children: k.cancelText ?? x("modal.cancel") }),
155
+ typeof A == "function" && /* @__PURE__ */ f("button", { type: "button", disabled: E || k.doneDisabled === !0, onClick: () => j(A), className: "pmn-button pmn-button-primary", children: E ? k.loadingText ?? x("modal.processing") : k.doneText ?? x("modal.done") })
154
156
  ] });
155
157
  }
156
- function Ye({ loading: e, translate: n }) {
158
+ function Qe({ loading: e, translate: n }) {
157
159
  if (!e.visible) return null;
158
- const s = (n ?? ((g) => g))("modal.loading"), c = e.text ?? (s === "modal.loading" ? "加载中..." : s);
159
- return /* @__PURE__ */ m("div", { className: "pmn-loading-overlay", role: "status", "aria-live": "polite", "aria-busy": "true", children: /* @__PURE__ */ ae("div", { className: "pmn-loading-card", children: [
160
- /* @__PURE__ */ m("span", { className: "pmn-spinner", "aria-hidden": "true" }),
161
- /* @__PURE__ */ m("span", { children: c })
160
+ const o = (n ?? ((v) => v))("modal.loading"), s = e.text ?? (o === "modal.loading" ? "加载中..." : o);
161
+ return /* @__PURE__ */ f("div", { className: "pmn-loading-overlay", role: "status", "aria-live": "polite", "aria-busy": "true", children: /* @__PURE__ */ oe("div", { className: "pmn-loading-content", children: [
162
+ /* @__PURE__ */ f("span", { className: "pmn-spinner", "aria-hidden": "true" }),
163
+ s && /* @__PURE__ */ f("span", { className: "pmn-loading-text", children: s })
162
164
  ] }) });
163
165
  }
164
- class Qe extends qe.Component {
166
+ class Ve extends Ae.Component {
165
167
  state = { error: null };
166
168
  static getDerivedStateFromError(n) {
167
169
  return { error: n };
@@ -173,340 +175,348 @@ class Qe extends qe.Component {
173
175
  n.route?.key !== this.props.route?.key && this.state.error && this.setState({ error: null });
174
176
  }
175
177
  render() {
176
- return this.state.error ? /* @__PURE__ */ ae("div", { role: "alert", className: "pmn-error-screen", children: [
177
- /* @__PURE__ */ m("strong", { children: "页面加载失败" }),
178
- /* @__PURE__ */ m("p", { children: this.state.error.message }),
179
- /* @__PURE__ */ m("button", { type: "button", className: "pmn-button pmn-button-secondary", onClick: () => this.setState({ error: null }), children: "重试" })
178
+ return this.state.error ? /* @__PURE__ */ oe("div", { role: "alert", className: "pmn-error-screen", children: [
179
+ /* @__PURE__ */ f("strong", { children: "页面加载失败" }),
180
+ /* @__PURE__ */ f("p", { children: this.state.error.message }),
181
+ /* @__PURE__ */ f("button", { type: "button", className: "pmn-button pmn-button-secondary", onClick: () => this.setState({ error: null }), children: "重试" })
180
182
  ] }) : this.props.children;
181
183
  }
182
184
  }
183
- function Ve({ route: e, screen: n, navigation: r, focused: s, resultEvent: c, setFooter: g, loadingApi: v, bodyClassName: w, notifyError: f, registerDirtyGuard: N }) {
184
- const E = n.component, y = V(() => ({ isFocused: s, resultEvent: c, routeKey: e.key, setFooter: g }), [s, c, e.key, g]), p = V(() => ({
185
- isLoading: s && v.isLoading,
186
- setLoading: (h, b) => v.setScreenLoading(e.key, h, b),
187
- showLoading: (h) => v.begin(e.key, h),
188
- hideLoading: (h) => v.end(e.key, h)
189
- }), [s, v, e.key]);
190
- return /* @__PURE__ */ m(Be.Provider, { value: { routeKey: e.key, registerDirtyGuard: N }, children: /* @__PURE__ */ m(be.Provider, { value: y, children: /* @__PURE__ */ m(Me.Provider, { value: p, children: /* @__PURE__ */ m("div", { hidden: !s, inert: !s, "data-modal-route-key": e.key, tabIndex: -1, className: `pmn-body ${w ?? ""}`, children: /* @__PURE__ */ m(Qe, { route: e, onError: f, children: /* @__PURE__ */ m(E, { route: e, navigation: r }) }) }) }) }) });
185
+ function Je({ route: e, screen: n, navigation: r, focused: o, resultEvent: s, setFooter: v, loadingApi: b, bodyClassName: R, notifyError: h, registerDirtyGuard: E }) {
186
+ const T = n.component, x = V(() => ({ isFocused: o, resultEvent: s, routeKey: e.key, setFooter: v }), [o, s, e.key, v]), k = V(() => ({
187
+ isLoading: o && b.isLoading,
188
+ setLoading: (l, g) => b.setScreenLoading(e.key, l, g),
189
+ showLoading: (l) => b.begin(e.key, l),
190
+ hideLoading: (l) => b.end(e.key, l)
191
+ }), [o, b, e.key]);
192
+ return /* @__PURE__ */ f(Fe.Provider, { value: { routeKey: e.key, registerDirtyGuard: E }, children: /* @__PURE__ */ f(we.Provider, { value: x, children: /* @__PURE__ */ f(Se.Provider, { value: k, children: /* @__PURE__ */ f("div", { hidden: !o, inert: !o, "data-modal-route-key": e.key, tabIndex: -1, className: `pmn-body ${R ?? ""}`, children: /* @__PURE__ */ f(Ve, { route: e, onError: h, children: /* @__PURE__ */ f(T, { route: e, navigation: r }) }) }) }) }) });
191
193
  }
192
- function _e({ config: e, params: n, options: r, translate: s, onRequestClose: c, onOpened: g, registerLoading: v, notifyError: w, error: f, clearError: N, registerDirtyGuard: E, exiting: y = !1 }) {
193
- const [p, h] = Ae(Ie, null, () => Pe(e.initialRoute, n)), [b, D] = W({}), [F, q] = W({}), [, A] = W(0), R = u(/* @__PURE__ */ new Map()), j = u(0), M = u(/* @__PURE__ */ new Map()), I = u(null), H = u(null), z = u(!1), P = u(!1), K = u(0), k = p.at(-1), T = k.key, C = u(T);
194
- C.current = T;
195
- const x = e.screens, B = d(() => A((t) => t + 1), []), G = d((t, o) => {
194
+ function Xe({ config: e, initialScreen: n, params: r, options: o, translate: s, onRequestClose: v, onOpened: b, registerLoading: R, notifyError: h, error: E, clearError: T, registerDirtyGuard: x, exiting: k = !1 }) {
195
+ const [l, g] = je(ze, null, () => Oe(n ?? e.initialRoute, r)), [A, B] = Q({}), [H, O] = Q({}), [, D] = Q(0), S = d(/* @__PURE__ */ new Map()), j = d(0), P = d(/* @__PURE__ */ new Map()), $ = d(null), q = d(null), L = d(!1), z = d(!1), _ = d(0), M = l.at(-1), y = M.key, C = d(y);
196
+ C.current = y;
197
+ const F = e.screens, G = m(() => D((t) => t + 1), []), N = m((t, c) => {
196
198
  if (t !== "global" && C.current !== t) return null;
197
- const l = ++j.current;
198
- return R.current.set(l, { owner: t, text: o }), B(), l;
199
- }, [B]), S = d((t, o) => {
200
- if (o != null)
201
- R.current.get(o)?.owner === t && R.current.delete(o);
199
+ const u = ++j.current;
200
+ return S.current.set(u, { owner: t, text: c }), G(), u;
201
+ }, [G]), W = m((t, c) => {
202
+ if (c != null)
203
+ S.current.get(c)?.owner === t && S.current.delete(c);
202
204
  else
203
- for (const [l, L] of R.current) L.owner === t && R.current.delete(l);
204
- B();
205
- }, [B]), U = d((t, o) => {
206
- t ? (S("global"), G("global", o)) : S("global");
207
- }, [G, S]), Y = d((t, o, l) => {
208
- o ? (S(t), G(t, l)) : S(t);
209
- }, [G, S]), ne = [...R.current.values()], J = { visible: ne.length > 0, text: ne.at(-1)?.text ?? null, count: ne.length }, Q = u(J);
210
- Q.current = J;
211
- const X = V(() => ({ isLoading: J.visible, setLoading: U, setScreenLoading: Y, begin: G, end: S }), [J.visible, U, Y, G, S]), ie = u(v);
212
- ie.current = v, O(() => (ie.current?.({ setLoading: U }), () => ie.current?.(null)), [U]);
213
- const ge = d((t, o) => q((l) => {
214
- if (o === null) {
215
- if (!(t in l)) return l;
216
- const L = { ...l };
217
- return delete L[t], L;
205
+ for (const [u, U] of S.current) U.owner === t && S.current.delete(u);
206
+ G();
207
+ }, [G]), K = m((t, c) => {
208
+ t ? (W("global"), N("global", c)) : W("global");
209
+ }, [N, W]), ae = m((t, c, u) => {
210
+ c ? (W(t), N(t, u)) : W(t);
211
+ }, [N, W]), se = [...S.current.values()], Y = { visible: se.length > 0, text: se.at(-1)?.text ?? null, count: se.length }, X = d(Y);
212
+ X.current = Y;
213
+ const ce = V(() => ({ isLoading: Y.visible, setLoading: K, setScreenLoading: ae, begin: N, end: W }), [Y.visible, K, ae, N, W]), ie = d(R);
214
+ ie.current = R, I(() => (ie.current?.({ setLoading: K }), () => ie.current?.(null)), [K]);
215
+ const ge = m((t, c) => O((u) => {
216
+ if (c === null) {
217
+ if (!(t in u)) return u;
218
+ const U = { ...u };
219
+ return delete U[t], U;
218
220
  }
219
- return l[t] === o ? l : { ...l, [t]: o };
220
- }), []), te = d(() => {
221
+ return u[t] === c ? u : { ...u, [t]: c };
222
+ }), []), ne = m(() => {
221
223
  const t = document.activeElement;
222
- if (!(t instanceof HTMLElement) || !I.current?.contains(t)) return;
223
- const o = t.closest("[data-modal-route-key]");
224
- o && M.current.set(o.dataset.modalRouteKey, t), I.current.focus({ preventScroll: !0 });
225
- }, []), ce = d((t) => {
226
- if (!Object.prototype.hasOwnProperty.call(x, t)) throw new Error(`[react-modal-navigation] Unknown modal screen: ${t}`);
227
- }, [x]), Z = d((t, o) => {
224
+ if (!(t instanceof HTMLElement) || !$.current?.contains(t)) return;
225
+ const c = t.closest("[data-modal-route-key]");
226
+ c && P.current.set(c.dataset.modalRouteKey, t), $.current.focus({ preventScroll: !0 });
227
+ }, []), le = m((t) => {
228
+ if (!Object.prototype.hasOwnProperty.call(F, t)) throw new Error(`[react-modal-navigation] Unknown modal screen: ${t}`);
229
+ }, [F]), Z = m((t, c) => {
228
230
  try {
229
- Promise.resolve(r[t]?.(o)).catch((l) => w(l, { phase: t }));
230
- } catch (l) {
231
- w(l, { phase: t });
231
+ Promise.resolve(o[t]?.(c)).catch((u) => h(u, { phase: t }));
232
+ } catch (u) {
233
+ h(u, { phase: t });
232
234
  }
233
- }, [r, w]), _ = d((t, o, l) => {
234
- ce(o), te(), h({ type: t, name: o, params: l });
235
- }, [ce, te]), le = d((t, o) => _("NAVIGATE", t, o), [_]), ue = d((t, o) => _("REPLACE", t, o), [_]), de = d((t, o) => {
236
- D({}), _("RESET", t, o);
237
- }, [_]), me = d((t) => {
235
+ }, [o, h]), J = m((t, c, u) => {
236
+ le(c), ne(), g({ type: t, name: c, params: u });
237
+ }, [le, ne]), ue = m((t, c) => J("NAVIGATE", t, c), [J]), de = m((t, c) => J("REPLACE", t, c), [J]), me = m((t, c) => {
238
+ B({}), J("RESET", t, c);
239
+ }, [J]), pe = m((t) => {
238
240
  if (!t || typeof t != "object" || Array.isArray(t)) throw new TypeError("[react-modal-navigation] setParams expects an object");
239
- h({ type: "SET_PARAMS", params: t });
240
- }, []), pe = d((t) => {
241
- if (p.length <= 1 || z.current) return !1;
242
- if (z.current = !0, t !== void 0) {
243
- const o = p.at(-2);
244
- D((l) => ({ ...l, [o.key]: { id: ++K.current, data: t } }));
241
+ g({ type: "SET_PARAMS", params: t });
242
+ }, []), ye = m((t) => {
243
+ if (!t || typeof t != "object" || Array.isArray(t)) throw new TypeError("[react-modal-navigation] setOptions expects an object");
244
+ g({ type: "SET_OPTIONS", options: t });
245
+ }, []), a = m((t) => {
246
+ if (l.length <= 1 || L.current) return !1;
247
+ if (L.current = !0, t !== void 0) {
248
+ const c = l.at(-2);
249
+ B((u) => ({ ...u, [c.key]: { id: ++_.current, data: t } }));
245
250
  }
246
- return te(), h({ type: "BACK" }), !0;
247
- }, [p, te]), re = d((t, o) => Q.current.visible && r.lockCloseWhileLoading !== !1 ? Promise.resolve(!1) : c(t, o, { route: k, stack: p }), [r.lockCloseWhileLoading, c, k, p]), a = d((t) => re("api", t), [re]), i = V(() => ({ navigate: le, replace: ue, reset: de, setParams: me, goBack: pe, close: a, setLoading: U, canGoBack: p.length > 1, stack: p, currentRoute: k }), [le, ue, de, me, pe, a, U, p, k]);
251
+ return ne(), g({ type: "BACK" }), !0;
252
+ }, [l, ne]), i = m((t, c) => X.current.visible && o.lockCloseWhileLoading !== !1 ? Promise.resolve(!1) : v(t, c, { route: M, stack: l }), [o.lockCloseWhileLoading, v, M, l]), w = m((t) => i("api", t), [i]), p = V(() => ({ navigate: ue, replace: de, reset: me, setParams: pe, setOptions: ye, goBack: a, close: w, setLoading: K, canGoBack: l.length > 1, stack: l, currentRoute: M }), [ue, de, me, pe, ye, a, w, K, l, M]);
248
253
  return De(() => {
249
- z.current = !1;
250
- const t = [...I.current?.querySelectorAll("[data-modal-route-key]") ?? []].find((L) => L.dataset.modalRouteKey === T);
254
+ L.current = !1;
255
+ const t = [...$.current?.querySelectorAll("[data-modal-route-key]") ?? []].find((U) => U.dataset.modalRouteKey === y);
251
256
  if (!t) return;
252
- const o = M.current.get(T);
253
- (o?.isConnected && t.contains(o) && !o.matches(":disabled") && !o.closest("[inert], [hidden]") ? o : t).focus({ preventScroll: !0 });
254
- }, [T]), O(() => {
257
+ const c = P.current.get(y);
258
+ (c?.isConnected && t.contains(c) && !c.matches(":disabled") && !c.closest("[inert], [hidden]") ? c : t).focus({ preventScroll: !0 });
259
+ }, [y]), I(() => {
255
260
  let t = !1;
256
- for (const [l, L] of R.current)
257
- L.owner !== "global" && L.owner !== T && (R.current.delete(l), t = !0);
258
- t && B();
259
- const o = new Set(p.map((l) => l.key));
260
- for (const l of M.current.keys()) o.has(l) || M.current.delete(l);
261
- }, [T, p, B]), O(() => {
262
- if (H.current?.key !== T) {
263
- if (H.current) {
264
- const t = { from: H.current, to: k, stack: p };
265
- Z("onBlur", { route: H.current, ...t }), Z("onNavigate", t), Z("onRouteChange", t);
261
+ for (const [u, U] of S.current)
262
+ U.owner !== "global" && U.owner !== y && (S.current.delete(u), t = !0);
263
+ t && G();
264
+ const c = new Set(l.map((u) => u.key));
265
+ for (const u of P.current.keys()) c.has(u) || P.current.delete(u);
266
+ }, [y, l, G]), I(() => {
267
+ if (q.current?.key !== y) {
268
+ if (q.current) {
269
+ const t = { from: q.current, to: M, stack: l };
270
+ Z("onBlur", { route: q.current, ...t }), Z("onNavigate", t), Z("onRouteChange", t);
266
271
  }
267
- Z("onFocus", { route: k, stack: p }), H.current = k;
272
+ Z("onFocus", { route: M, stack: l }), q.current = M;
268
273
  }
269
- }, [k, T, p, Z]), O(() => () => {
270
- R.current.clear(), M.current.clear();
271
- }, []), O(() => {
272
- P.current || (P.current = !0, g?.({ route: k, stack: p }));
273
- }, []), /* @__PURE__ */ m(Re.Provider, { value: i, children: /* @__PURE__ */ m(Me.Provider, { value: X, children: /* @__PURE__ */ ae(Ke, { dialogRef: I, options: r, requestClose: re, exiting: y, children: [
274
- /* @__PURE__ */ m(Ue, { options: r, screen: x[k.name], route: k, navigation: i, requestClose: re, translate: s }),
275
- /* @__PURE__ */ m("main", { className: "pmn-main", children: p.map((t) => /* @__PURE__ */ m(
276
- Ve,
274
+ }, [M, y, l, Z]), I(() => () => {
275
+ S.current.clear(), P.current.clear();
276
+ }, []), I(() => {
277
+ z.current || (z.current = !0, b?.({ route: M, stack: l }));
278
+ }, []), /* @__PURE__ */ f(Ce.Provider, { value: p, children: /* @__PURE__ */ f(Se.Provider, { value: ce, children: /* @__PURE__ */ oe(We, { dialogRef: $, options: o, requestClose: i, exiting: k, children: [
279
+ /* @__PURE__ */ f(Ye, { options: o, screen: { ...F[M.name], ...M.options ?? {} }, route: M, navigation: p, requestClose: i, translate: s }),
280
+ /* @__PURE__ */ f("main", { className: "pmn-main", children: l.map((t) => /* @__PURE__ */ f(
281
+ Je,
277
282
  {
278
283
  route: t,
279
- screen: x[t.name],
280
- navigation: i,
281
- focused: t.key === T,
282
- resultEvent: b[t.key] ?? null,
283
- bodyClassName: r.bodyClassName,
284
+ screen: F[t.name],
285
+ navigation: p,
286
+ focused: t.key === y,
287
+ resultEvent: A[t.key] ?? null,
288
+ bodyClassName: o.bodyClassName,
284
289
  setFooter: ge,
285
- loadingApi: X,
286
- notifyError: w,
287
- registerDirtyGuard: E
290
+ loadingApi: ce,
291
+ notifyError: h,
292
+ registerDirtyGuard: x
288
293
  },
289
294
  t.key
290
295
  )) }),
291
- /* @__PURE__ */ m(
292
- We,
296
+ /* @__PURE__ */ f(
297
+ _e,
293
298
  {
294
- screen: x[k.name],
295
- options: r,
296
- override: F[T],
297
- route: k,
298
- navigation: i,
299
- requestClose: re,
299
+ screen: { ...F[M.name], ...M.options ?? {} },
300
+ options: o,
301
+ override: H[y],
302
+ route: M,
303
+ navigation: p,
304
+ requestClose: i,
300
305
  translate: s,
301
- onError: w
306
+ onError: h,
307
+ loadingApi: ce
302
308
  },
303
- T
309
+ y
304
310
  ),
305
- /* @__PURE__ */ m(Ye, { loading: J, translate: s }),
306
- f && /* @__PURE__ */ ae("div", { className: "pmn-error", role: "alert", children: [
307
- /* @__PURE__ */ m("span", { children: f.message || String(f) }),
308
- /* @__PURE__ */ m("button", { type: "button", onClick: N, "aria-label": "Dismiss error", children: "×" })
311
+ /* @__PURE__ */ f(Qe, { loading: Y, translate: s }),
312
+ E && /* @__PURE__ */ oe("div", { className: "pmn-error", role: "alert", children: [
313
+ /* @__PURE__ */ f("span", { children: E.message || String(E) }),
314
+ /* @__PURE__ */ f("button", { type: "button", onClick: T, "aria-label": "Dismiss error", children: "×" })
309
315
  ] })
310
316
  ] }) }) });
311
317
  }
312
- const Je = ".pmn-overlay,.pmn-dialog,.pmn-dialog *{box-sizing:border-box}.pmn-overlay{position:fixed;inset:0;z-index:1000;display:flex;overscroll-behavior:none;background:#00000073}.pmn-place-right{justify-content:flex-end;align-items:stretch}.pmn-place-left{justify-content:flex-start;align-items:stretch}.pmn-place-center{justify-content:center;align-items:center}.pmn-place-top{justify-content:center;align-items:flex-start}.pmn-place-bottom{justify-content:center;align-items:flex-end}.pmn-dialog{--pmn-surface:#fff;--pmn-body:#fff;--pmn-text:#0f172a;--pmn-muted:#475569;--pmn-border:#e2e8f0;--pmn-hover:#f1f5f9;--pmn-overlay-card:rgba(255,255,255,.92);color-scheme:light;position:relative;display:flex;flex-direction:column;min-height:0;width:100%;max-width:min(calc(100vw - var(--pmn-gap)*2),var(--pmn-max-width, var(--pmn-width)));max-height:min(calc(100dvh - var(--pmn-gap)*2),var(--pmn-max-height, 100dvh));height:var(--pmn-height, 100%);overflow:hidden;outline:none;box-shadow:0 25px 50px -12px #00000040;background:var(--pmn-surface);color:var(--pmn-text)}.pmn-place-left .pmn-dialog,.pmn-place-right .pmn-dialog{height:calc(100dvh - var(--pmn-gap)*2);max-height:calc(100dvh - var(--pmn-gap)*2)}.pmn-place-center .pmn-dialog{height:var(--pmn-height, auto);min-height:150px}.pmn-place-top .pmn-dialog,.pmn-place-bottom .pmn-dialog{height:var(--pmn-height, auto);min-height:0}.pmn-dialog[data-modal-theme=dark]{--pmn-surface:#334155;--pmn-body:#334155;--pmn-text:#f1f5f9;--pmn-muted:#cbd5e1;--pmn-border:#475569;--pmn-hover:#1e293b;--pmn-overlay-card:rgba(51,65,85,.94);color-scheme:dark}.pmn-main{min-height:0;flex:1;overflow:hidden;display:flex;flex-direction:column;background:transparent}.pmn-body{height:100%;min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:16px;flex:1}.pmn-body[hidden]{display:none!important}.pmn-header{display:flex;flex-shrink:0;height:64px;align-items:center;gap:12px;padding:0 20px;background:transparent}.pmn-header h2{font-size:18px;font-weight:600;min-width:0;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin:0}.pmn-header-spacer{flex:1}.pmn-border-bottom{border-bottom:1px solid var(--pmn-border)}.pmn-icon-button{display:inline-flex;align-items:center;justify-content:center;padding:8px;border:0;background:transparent;color:inherit;border-radius:8px;cursor:pointer}.pmn-icon-button:hover{background:var(--pmn-hover)}.pmn-footer{display:flex;flex-shrink:0;align-items:center;justify-content:flex-end;gap:12px;padding:16px 20px;background:transparent}.pmn-border-top{border-top:1px solid var(--pmn-border)}.pmn-button{padding:8px 16px;border-radius:8px;font-size:14px;font-weight:500;cursor:pointer}.pmn-button:disabled{opacity:.5;cursor:not-allowed}.pmn-button-secondary{border:1px solid var(--pmn-border);background:transparent;color:var(--pmn-text)}.pmn-button-secondary:hover:not(:disabled){background:var(--pmn-hover)}.pmn-button-primary{border:1px solid #2563eb;background:#2563eb;color:#fff}.pmn-button-primary:hover:not(:disabled){background:#1d4ed8}.pmn-loading-overlay{position:absolute;inset:0;z-index:50;display:flex;align-items:center;justify-content:center;background:var(--pmn-overlay-card);-webkit-backdrop-filter:blur(1px);backdrop-filter:blur(1px)}.pmn-loading-card{display:flex;flex-direction:column;align-items:center;gap:12px;max-width:85%;padding:20px 28px;border-radius:12px;background:var(--pmn-surface);box-shadow:0 10px 20px #00000026}.pmn-spinner{width:36px;height:36px;border:3px solid #2563eb;border-top-color:transparent;border-radius:50%;animation:pmn-spin 1s linear infinite}@keyframes pmn-spin{to{transform:rotate(360deg)}}.pmn-error{position:absolute;z-index:60;bottom:8px;left:12px;right:12px;display:flex;justify-content:space-between;gap:12px;padding:12px;border:1px solid #fca5a5;border-radius:8px;background:#fef2f2;color:#991b1b;font-size:13px}.pmn-error button{border:0;background:transparent;font-size:20px;cursor:pointer;color:inherit}.pmn-dialog input:not([type=checkbox]):not([type=radio]),.pmn-dialog textarea,.pmn-dialog select{color:var(--pmn-text);border-color:var(--pmn-border)}.pmn-error-screen{padding:24px;color:var(--pmn-text)}.pmn-error-screen p{color:#dc2626;overflow-wrap:anywhere}@media(max-width:640px){.pmn-overlay.pmn-mobile-fullscreen{padding:0!important}.pmn-mobile-fullscreen .pmn-dialog{max-width:100%;width:100%;height:100dvh;max-height:100dvh;border-radius:0!important}}@media(prefers-reduced-motion:reduce){.pmn-spinner{animation-duration:2s}}@keyframes pmn-fade-in{0%{opacity:0}to{opacity:1}}@keyframes pmn-fade-out{0%{opacity:1}to{opacity:0}}@keyframes pmn-scale-in{0%{opacity:0;transform:translateY(10px) scale(.97)}to{opacity:1;transform:none}}@keyframes pmn-scale-out{0%{opacity:1;transform:none}to{opacity:0;transform:translateY(10px) scale(.97)}}@keyframes pmn-right-in{0%{transform:translate(105%)}to{transform:none}}@keyframes pmn-right-out{0%{transform:none}to{transform:translate(105%)}}@keyframes pmn-left-in{0%{transform:translate(-105%)}to{transform:none}}@keyframes pmn-left-out{0%{transform:none}to{transform:translate(-105%)}}@keyframes pmn-top-in{0%{transform:translateY(-105%)}to{transform:none}}@keyframes pmn-top-out{0%{transform:none}to{transform:translateY(-105%)}}@keyframes pmn-bottom-in{0%{transform:translateY(105%)}to{transform:none}}@keyframes pmn-bottom-out{0%{transform:none}to{transform:translateY(105%)}}.pmn-entering{animation:pmn-fade-in var(--pmn-animation-duration) ease-out both}.pmn-exiting{animation:pmn-fade-out var(--pmn-animation-duration) ease-in both;pointer-events:none}.pmn-entering .pmn-dialog{animation:pmn-scale-in var(--pmn-animation-duration) cubic-bezier(.2,.8,.2,1) both}.pmn-exiting .pmn-dialog{animation:pmn-scale-out var(--pmn-animation-duration) ease-in both}.pmn-entering.pmn-place-right .pmn-dialog{animation-name:pmn-right-in}.pmn-exiting.pmn-place-right .pmn-dialog{animation-name:pmn-right-out}.pmn-entering.pmn-place-left .pmn-dialog{animation-name:pmn-left-in}.pmn-exiting.pmn-place-left .pmn-dialog{animation-name:pmn-left-out}.pmn-entering.pmn-place-top .pmn-dialog{animation-name:pmn-top-in}.pmn-exiting.pmn-place-top .pmn-dialog{animation-name:pmn-top-out}.pmn-entering.pmn-place-bottom .pmn-dialog{animation-name:pmn-bottom-in}.pmn-exiting.pmn-place-bottom .pmn-dialog{animation-name:pmn-bottom-out}.pmn-no-animation,.pmn-no-animation .pmn-dialog{animation:none!important}@media(prefers-reduced-motion:reduce){.pmn-entering,.pmn-exiting,.pmn-entering .pmn-dialog,.pmn-exiting .pmn-dialog{animation:none!important}}", Ne = "react-modal-navigation-styles", ke = /* @__PURE__ */ new WeakMap();
313
- function Xe() {
318
+ const Ze = ".pmn-overlay,.pmn-dialog,.pmn-dialog *{box-sizing:border-box}.pmn-overlay{position:fixed;inset:0;z-index:1000;display:flex;overscroll-behavior:none;background:#00000073}.pmn-place-right{justify-content:flex-end;align-items:stretch}.pmn-place-left{justify-content:flex-start;align-items:stretch}.pmn-place-center{justify-content:center;align-items:center}.pmn-place-top{justify-content:center;align-items:flex-start}.pmn-place-bottom{justify-content:center;align-items:flex-end}.pmn-dialog{--pmn-surface:#fff;--pmn-body:#fff;--pmn-text:#0f172a;--pmn-muted:#475569;--pmn-border:#e2e8f0;--pmn-hover:#f1f5f9;--pmn-overlay-card:rgba(255,255,255,.92);color-scheme:light;position:relative;display:flex;flex-direction:column;min-height:0;width:100%;max-width:min(calc(100vw - var(--pmn-gap)*2),var(--pmn-max-width, var(--pmn-width)));max-height:min(calc(100dvh - var(--pmn-gap)*2),var(--pmn-max-height, 100dvh));height:var(--pmn-height, 100%);overflow:hidden;outline:none;box-shadow:0 25px 50px -12px #00000040;background:var(--pmn-surface);color:var(--pmn-text)}.pmn-place-left .pmn-dialog,.pmn-place-right .pmn-dialog{height:calc(100dvh - var(--pmn-gap)*2);max-height:calc(100dvh - var(--pmn-gap)*2)}.pmn-place-center .pmn-dialog{height:var(--pmn-height, auto);min-height:150px}.pmn-place-top .pmn-dialog,.pmn-place-bottom .pmn-dialog{height:var(--pmn-height, auto);min-height:0}.pmn-dialog[data-modal-theme=dark]{--pmn-surface:#334155;--pmn-body:#334155;--pmn-text:#f1f5f9;--pmn-muted:#cbd5e1;--pmn-border:#475569;--pmn-hover:#1e293b;--pmn-overlay-card:rgba(51,65,85,.94);color-scheme:dark}.pmn-main{min-height:0;flex:1;overflow:hidden;display:flex;flex-direction:column;background:transparent}.pmn-body{height:100%;min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:16px;flex:1}.pmn-body[hidden]{display:none!important}.pmn-header{display:flex;flex-shrink:0;height:64px;align-items:center;gap:12px;padding:0 20px;background:transparent}.pmn-header h2{font-size:18px;font-weight:600;min-width:0;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin:0}.pmn-header-spacer{flex:1}.pmn-border-bottom{border-bottom:1px solid var(--pmn-border)}.pmn-icon-button{display:inline-flex;align-items:center;justify-content:center;padding:8px;border:0;background:transparent;color:inherit;border-radius:8px;cursor:pointer}.pmn-icon-button:hover{background:var(--pmn-hover)}.pmn-footer{display:flex;flex-shrink:0;align-items:center;justify-content:flex-end;gap:12px;padding:16px 20px;background:transparent}.pmn-border-top{border-top:1px solid var(--pmn-border)}.pmn-button{padding:8px 16px;border-radius:8px;font-size:14px;font-weight:500;cursor:pointer}.pmn-button:disabled{opacity:.5;cursor:not-allowed}.pmn-button-secondary{border:1px solid var(--pmn-border);background:transparent;color:var(--pmn-text)}.pmn-button-secondary:hover:not(:disabled){background:var(--pmn-hover)}.pmn-button-primary{border:1px solid #2563eb;background:#2563eb;color:#fff}.pmn-button-primary:hover:not(:disabled){background:#1d4ed8}.pmn-loading-overlay{position:absolute;inset:0;z-index:50;display:flex;align-items:center;justify-content:center;background:#ffffffb8;backdrop-filter:blur(2px);-webkit-backdrop-filter:blur(2px);cursor:progress}.pmn-dialog[data-modal-theme=dark] .pmn-loading-overlay{background:#0f172ab8}.pmn-loading-content{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:14px;max-width:85%;text-align:center;color:var(--pmn-text);pointer-events:none}.pmn-loading-text{font-size:14px;font-weight:500;line-height:1.5;overflow-wrap:anywhere}.pmn-spinner{width:38px;height:38px;border:3px solid rgba(37,99,235,.2);border-top-color:#2563eb;border-radius:50%;animation:pmn-spin .8s linear infinite}@keyframes pmn-spin{to{transform:rotate(360deg)}}@media(prefers-reduced-motion:reduce){.pmn-spinner{animation-duration:1.8s}}.pmn-error{position:absolute;z-index:60;bottom:8px;left:12px;right:12px;display:flex;justify-content:space-between;gap:12px;padding:12px;border:1px solid #fca5a5;border-radius:8px;background:#fef2f2;color:#991b1b;font-size:13px}.pmn-error button{border:0;background:transparent;font-size:20px;cursor:pointer;color:inherit}.pmn-dialog input:not([type=checkbox]):not([type=radio]),.pmn-dialog textarea,.pmn-dialog select{color:var(--pmn-text);border-color:var(--pmn-border)}.pmn-error-screen{padding:24px;color:var(--pmn-text)}.pmn-error-screen p{color:#dc2626;overflow-wrap:anywhere}@media(max-width:640px){.pmn-overlay.pmn-mobile-fullscreen{padding:0!important}.pmn-mobile-fullscreen .pmn-dialog{max-width:100%;width:100%;height:100dvh;max-height:100dvh;border-radius:0!important}}@media(prefers-reduced-motion:reduce){.pmn-spinner{animation-duration:2s}}@keyframes pmn-fade-in{0%{opacity:0}to{opacity:1}}@keyframes pmn-fade-out{0%{opacity:1}to{opacity:0}}@keyframes pmn-scale-in{0%{opacity:0;transform:translateY(10px) scale(.97)}to{opacity:1;transform:none}}@keyframes pmn-scale-out{0%{opacity:1;transform:none}to{opacity:0;transform:translateY(10px) scale(.97)}}@keyframes pmn-right-in{0%{transform:translate(105%)}to{transform:none}}@keyframes pmn-right-out{0%{transform:none}to{transform:translate(105%)}}@keyframes pmn-left-in{0%{transform:translate(-105%)}to{transform:none}}@keyframes pmn-left-out{0%{transform:none}to{transform:translate(-105%)}}@keyframes pmn-top-in{0%{transform:translateY(-105%)}to{transform:none}}@keyframes pmn-top-out{0%{transform:none}to{transform:translateY(-105%)}}@keyframes pmn-bottom-in{0%{transform:translateY(105%)}to{transform:none}}@keyframes pmn-bottom-out{0%{transform:none}to{transform:translateY(105%)}}.pmn-entering{animation:pmn-fade-in var(--pmn-animation-duration) ease-out both}.pmn-exiting{animation:pmn-fade-out var(--pmn-animation-duration) ease-in both;pointer-events:none}.pmn-entering .pmn-dialog{animation:pmn-scale-in var(--pmn-animation-duration) cubic-bezier(.2,.8,.2,1) both}.pmn-exiting .pmn-dialog{animation:pmn-scale-out var(--pmn-animation-duration) ease-in both}.pmn-entering.pmn-place-right .pmn-dialog{animation-name:pmn-right-in}.pmn-exiting.pmn-place-right .pmn-dialog{animation-name:pmn-right-out}.pmn-entering.pmn-place-left .pmn-dialog{animation-name:pmn-left-in}.pmn-exiting.pmn-place-left .pmn-dialog{animation-name:pmn-left-out}.pmn-entering.pmn-place-top .pmn-dialog{animation-name:pmn-top-in}.pmn-exiting.pmn-place-top .pmn-dialog{animation-name:pmn-top-out}.pmn-entering.pmn-place-bottom .pmn-dialog{animation-name:pmn-bottom-in}.pmn-exiting.pmn-place-bottom .pmn-dialog{animation-name:pmn-bottom-out}.pmn-no-animation,.pmn-no-animation .pmn-dialog{animation:none!important}@media(prefers-reduced-motion:reduce){.pmn-entering,.pmn-exiting,.pmn-entering .pmn-dialog,.pmn-exiting .pmn-dialog{animation:none!important}}", Be = "react-modal-navigation-styles", Re = /* @__PURE__ */ new WeakMap();
319
+ function en() {
314
320
  $e(() => {
315
321
  if (typeof document > "u") return;
316
322
  const e = document;
317
- let n = ke.get(e);
323
+ let n = Re.get(e);
318
324
  if (!n) {
319
- let r = e.getElementById(Ne);
320
- const s = !r;
321
- r || (r = e.createElement("style"), r.id = Ne, r.setAttribute("data-react-modal-navigation", ""), r.textContent = Je, e.head.appendChild(r)), n = { element: r, owned: s, count: 0 }, ke.set(e, n);
325
+ let r = e.getElementById(Be);
326
+ const o = !r;
327
+ r || (r = e.createElement("style"), r.id = Be, r.setAttribute("data-react-modal-navigation", ""), r.textContent = Ze, e.head.appendChild(r)), n = { element: r, owned: o, count: 0 }, Re.set(e, n);
322
328
  }
323
329
  return n.count += 1, () => {
324
- n.count -= 1, n.count === 0 && (n.owned && n.element.remove(), ke.delete(e));
330
+ n.count -= 1, n.count === 0 && (n.owned && n.element.remove(), Re.delete(e));
325
331
  };
326
332
  }, []);
327
333
  }
328
- function ye(e, n, r) {
334
+ function ve(e, n, r) {
329
335
  if (typeof e == "string") {
330
336
  if (!e.trim()) throw new TypeError("[react-modal-navigation] modal name must not be empty");
331
337
  return { name: e, params: n ?? {}, options: r ?? {} };
332
338
  }
333
339
  if (e === null || typeof e != "object" || Array.isArray(e))
334
340
  throw new TypeError("[react-modal-navigation] open expects a modal name or a configuration object");
335
- const { name: s, params: c = {}, options: g = {}, ...v } = e;
336
- if (typeof s != "string" || !s.trim())
341
+ const { name: o, screen: s, params: v = {}, options: b = {}, ...R } = e;
342
+ if (typeof o != "string" || !o.trim())
337
343
  throw new TypeError("[react-modal-navigation] open config requires a non-empty string name");
338
- if (g === null || typeof g != "object" || Array.isArray(g))
344
+ if (b === null || typeof b != "object" || Array.isArray(b))
339
345
  throw new TypeError("[react-modal-navigation] open config options must be an object");
340
- return { name: s, params: c, options: { ...v, ...g } };
346
+ if (s !== void 0 && (typeof s != "string" || !s.trim()))
347
+ throw new TypeError("[react-modal-navigation] screen must be a non-empty string");
348
+ return { name: o, ...s === void 0 ? {} : { screen: s }, params: v, options: { ...R, ...b } };
341
349
  }
342
- const Ze = { placement: "right", showHeader: !0, showBackButton: !0, showCloseButton: !0, viewportGap: 5, borderRadius: 12, closeOnOverlay: !1, closeOnEsc: !0 }, en = (e) => ({ "modal.loading": "加载中...", "modal.processing": "处理中...", "modal.back": "返回", "modal.close": "关闭", "modal.cancel": "取消", "modal.done": "完成" })[e] ?? e;
343
- function an({ registry: e, children: n, defaultOptions: r = {}, backgroundColor: s, theme: c, translate: g = en, onError: v, confirmDiscard: w }) {
344
- Xe();
345
- const [f, N] = W(null), [E, y] = W(null), [p, h] = W(0), b = u(null), D = u(/* @__PURE__ */ new Map()), F = u([]), q = u(null), A = u(null), R = u(0), j = u(null), M = u(!1), I = u(0), H = u(null), z = u(/* @__PURE__ */ new Map()), [P, K] = W(!1), k = u(w);
346
- k.current = w;
347
- const T = d((a, i) => (z.current.set(a, i), () => {
348
- z.current.get(a) === i && z.current.delete(a);
349
- }), []), C = d(async (a) => {
350
- for (const i of z.current.values()) {
350
+ const nn = { placement: "right", showHeader: !0, showBackButton: !0, showCloseButton: !0, viewportGap: 5, borderRadius: 12, closeOnOverlay: !1, closeOnEsc: !0 }, tn = (e) => ({ "modal.loading": "加载中...", "modal.processing": "处理中...", "modal.back": "返回", "modal.close": "关闭", "modal.cancel": "取消", "modal.done": "完成" })[e] ?? e;
351
+ function cn({ registry: e, children: n, defaultOptions: r = {}, backgroundColor: o, theme: s, translate: v = tn, onError: b, confirmDiscard: R }) {
352
+ en();
353
+ const [h, E] = Q(null), [T, x] = Q(null), [k, l] = Q(0), g = d(null), A = d(/* @__PURE__ */ new Map()), B = d([]), H = d(null), O = d(null), D = d(0), S = d(null), j = d(!1), P = d(0), $ = d(null), q = d(/* @__PURE__ */ new Map()), [L, z] = Q(!1), _ = d(R);
354
+ _.current = R;
355
+ const M = m((a, i) => (q.current.set(a, i), () => {
356
+ q.current.get(a) === i && q.current.delete(a);
357
+ }), []), y = m(async (a) => {
358
+ for (const i of q.current.values()) {
351
359
  if (!i.dirty) continue;
352
- if ((i.onBeforeDiscard ? await i.onBeforeDiscard(a) : k.current ? await k.current(a) : typeof window < "u" && typeof window.confirm == "function" ? window.confirm(i.message || "有未保存的修改,确定放弃吗?") : !1) === !1) return !1;
360
+ if ((i.onBeforeDiscard ? await i.onBeforeDiscard(a) : _.current ? await _.current(a) : typeof window < "u" && typeof window.confirm == "function" ? window.confirm(i.message || "有未保存的修改,确定放弃吗?") : !1) === !1) return !1;
353
361
  }
354
362
  return !0;
355
- }, []), x = u(!0), B = u(null), G = u(v);
356
- G.current = v;
357
- const S = d((a, i) => {
358
- x.current && y(a);
363
+ }, []), C = d(!0), F = d(null), G = d(b);
364
+ G.current = b;
365
+ const N = m((a, i) => {
366
+ C.current && x(a);
359
367
  try {
360
368
  G.current ? G.current(a, i) : console.error("[react-modal-navigation]", a);
361
- } catch (t) {
362
- console.error("[react-modal-navigation] onError failed", t);
369
+ } catch (w) {
370
+ console.error("[react-modal-navigation] onError failed", w);
363
371
  }
364
- }, []), U = d((a, i) => {
365
- const t = D.current.get(a);
366
- D.current.delete(a), t?.(i);
367
- }, []), Y = d((a) => ({ ...Ze, ...r, ...c !== void 0 ? { theme: c } : {}, ...s !== void 0 ? { backgroundColor: s } : {}, ...a.config.modalOptions, ...a.overrides }), [r, c, s]), ne = f ? Y(f) : null, J = u(null);
368
- J.current = ne, B.current = ne;
369
- const Q = d(async (a = "api", i, t = {}) => {
370
- const o = b.current;
371
- if (!o || j.current || M.current) return !1;
372
- j.current = o.id, M.current = !0;
373
- const l = B.current ?? Y(o), L = { ...t, reason: a, result: i, name: o.name };
372
+ }, []), W = m((a, i) => {
373
+ const w = A.current.get(a);
374
+ A.current.delete(a), w?.(i);
375
+ }, []), K = m((a) => ({ ...nn, ...r, ...s !== void 0 ? { theme: s } : {}, ...o !== void 0 ? { backgroundColor: o } : {}, ...a.config.modalOptions, ...a.overrides }), [r, s, o]), ae = h ? K(h) : null, se = d(null);
376
+ se.current = ae, F.current = ae;
377
+ const Y = m(async (a = "api", i, w = {}) => {
378
+ const p = g.current;
379
+ if (!p || S.current || j.current) return !1;
380
+ S.current = p.id, j.current = !0;
381
+ const t = F.current ?? K(p), c = { ...w, reason: a, result: i, name: p.name };
374
382
  try {
375
- if (!await C(L) || await l.onBeforeClose?.(L) === !1 || b.current?.id !== o.id || !x.current || (K(!0), await new Promise(($) => {
376
- const se = l.animation === !1 || typeof window < "u" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ? 0 : Math.max(0, Number(l.animationDuration ?? 220) || 0);
377
- setTimeout($, Math.min(se, 1e3));
378
- }), !x.current || b.current?.id !== o.id)) return !1;
379
- b.current = null, H.current = null, N(null), K(!1), z.current.clear(), U(o.id, t.confirmed || i !== void 0 ? { status: "confirmed", value: i, reason: a } : { status: "dismissed", reason: a });
383
+ if (!await y(c) || await t.onBeforeClose?.(c) === !1 || g.current?.id !== p.id || !C.current || (z(!0), await new Promise((u) => {
384
+ const U = t.animation === !1 || typeof window < "u" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ? 0 : Math.max(0, Number(t.animationDuration ?? 220) || 0);
385
+ setTimeout(u, Math.min(U, 1e3));
386
+ }), !C.current || g.current?.id !== p.id)) return !1;
387
+ g.current = null, $.current = null, E(null), z(!1), q.current.clear(), W(p.id, w.confirmed || i !== void 0 ? { status: "confirmed", value: i, reason: a } : { status: "dismissed", reason: a });
380
388
  try {
381
- await l.onClose?.(L);
382
- } catch ($) {
383
- S($, { phase: "onClose", name: o.name });
389
+ await t.onClose?.(c);
390
+ } catch (u) {
391
+ N(u, { phase: "onClose", name: p.name });
384
392
  }
385
393
  return !0;
386
- } catch ($) {
387
- return S($, { phase: "onBeforeClose", name: o.name }), !1;
394
+ } catch (u) {
395
+ return N(u, { phase: "onBeforeClose", name: p.name }), !1;
388
396
  } finally {
389
- j.current === o.id && (j.current = null), M.current = !1, !b.current && x.current && queueMicrotask(() => A.current?.());
397
+ S.current === p.id && (S.current = null), j.current = !1, !g.current && C.current && queueMicrotask(() => O.current?.());
390
398
  }
391
- }, [Y, S, U, C]), X = d(async (a, i = {}, t = {}, o) => {
392
- const l = e?.[a];
393
- if (!l) throw new Error(`[react-modal-navigation] Unknown modal: ${a}`);
394
- if (!l.screens?.[l.initialRoute]) throw new Error(`[react-modal-navigation] Missing initial screen '${l.initialRoute}' in '${a}'`);
395
- if (!x.current || M.current || j.current) return null;
396
- M.current = !0;
397
- const L = I.current;
399
+ }, [K, N, W, y]), X = m(async (a, i = {}, w = {}, p, t) => {
400
+ const c = e?.[a];
401
+ if (!c) throw new Error(`[react-modal-navigation] Unknown modal: ${a}`);
402
+ const u = t ?? c.initialRoute;
403
+ if (!c.screens?.[u]) throw new Error(`[react-modal-navigation] Unknown initial screen '${u}' in modal '${a}'`);
404
+ if (!C.current || j.current || S.current) return null;
405
+ j.current = !0;
406
+ const U = P.current;
398
407
  try {
399
- const $ = b.current;
400
- if ($) {
401
- const Ce = B.current ?? Y($), ve = { reason: "replace", name: $.name, nextName: a };
408
+ const te = g.current;
409
+ if (te) {
410
+ const Te = F.current ?? K(te), xe = { reason: "replace", name: te.name, nextName: a };
402
411
  try {
403
- if (!await C(ve) || await Ce.onBeforeClose?.(ve) === !1) return null;
404
- } catch (xe) {
405
- return S(xe, { phase: "onBeforeClose", name: $.name }), null;
412
+ if (!await y(xe) || await Te.onBeforeClose?.(xe) === !1) return null;
413
+ } catch (ke) {
414
+ return N(ke, { phase: "onBeforeClose", name: te.name }), null;
406
415
  }
407
- if (!x.current || L !== I.current || b.current?.id !== $.id) return null;
408
- b.current = null, H.current = null, N(null), z.current.clear(), U($.id, { status: "replaced", reason: "replace" });
416
+ if (!C.current || U !== P.current || g.current?.id !== te.id) return null;
417
+ g.current = null, $.current = null, E(null), q.current.clear(), W(te.id, { status: "replaced", reason: "replace" });
409
418
  try {
410
- await Ce.onClose?.(ve);
411
- } catch (xe) {
412
- S(xe, { phase: "onClose", name: $.name });
419
+ await Te.onClose?.(xe);
420
+ } catch (ke) {
421
+ N(ke, { phase: "onClose", name: te.name });
413
422
  }
414
- if (!x.current || L !== I.current) return null;
423
+ if (!C.current || U !== P.current) return null;
415
424
  }
416
- const se = { id: ++R.current, name: a, params: i, config: l, overrides: t };
417
- return b.current = se, H.current = null, o && D.current.set(se.id, o), y(null), N(se), se.id;
425
+ const be = { id: ++D.current, name: a, screen: u, params: i, config: c, overrides: w };
426
+ return g.current = be, $.current = null, p && A.current.set(be.id, p), x(null), E(be), be.id;
418
427
  } finally {
419
- M.current = !1;
428
+ j.current = !1;
420
429
  }
421
- }, [e, Y, S, U, C]);
422
- q.current = X;
423
- const ie = d(async () => {
424
- if (!x.current || b.current || M.current || j.current) return;
425
- const a = F.current.shift();
430
+ }, [e, K, N, W, y]);
431
+ H.current = X;
432
+ const ce = m(async () => {
433
+ if (!C.current || g.current || j.current || S.current) return;
434
+ const a = B.current.shift();
426
435
  if (a) {
427
- h(F.current.length);
436
+ l(B.current.length);
428
437
  try {
429
- const i = await q.current(a.args.name, a.args.params, a.args.options, a.resolveResult);
430
- i === null ? (a.resolveResult?.({ status: "dismissed", reason: "blocked" }), a.resolveId?.(null), queueMicrotask(() => A.current?.())) : a.resolveId?.(i);
438
+ const i = await H.current(a.args.name, a.args.params, a.args.options, a.resolveResult, a.args.screen);
439
+ i === null ? (a.resolveResult?.({ status: "dismissed", reason: "blocked" }), a.resolveId?.(null), queueMicrotask(() => O.current?.())) : a.resolveId?.(i);
431
440
  } catch (i) {
432
- a.reject?.(i), queueMicrotask(() => A.current?.());
441
+ a.reject?.(i), queueMicrotask(() => O.current?.());
433
442
  }
434
443
  }
435
444
  }, []);
436
- A.current = ie;
437
- const ge = d((a, i, t) => {
438
- const o = ye(a, i, t);
439
- return e?.[o.name] ? new Promise((l, L) => {
440
- F.current.push({ args: o, resolveId: l, reject: L }), h(F.current.length), queueMicrotask(() => A.current?.());
441
- }) : Promise.reject(new Error(`[react-modal-navigation] Unknown modal: ${o.name}`));
442
- }, [e]), te = d((a, i, t) => {
443
- const o = ye(a, i, t);
444
- return e?.[o.name] ? new Promise((l, L) => {
445
- F.current.push({ args: o, resolveResult: l, reject: L }), h(F.current.length), queueMicrotask(() => A.current?.());
446
- }) : Promise.reject(new Error(`[react-modal-navigation] Unknown modal: ${o.name}`));
447
- }, [e]), ce = d((a) => {
445
+ O.current = ce;
446
+ const ie = m((a, i, w) => {
447
+ const p = ve(a, i, w);
448
+ return e?.[p.name] ? new Promise((t, c) => {
449
+ B.current.push({ args: p, resolveId: t, reject: c }), l(B.current.length), queueMicrotask(() => O.current?.());
450
+ }) : Promise.reject(new Error(`[react-modal-navigation] Unknown modal: ${p.name}`));
451
+ }, [e]), ge = m((a, i, w) => {
452
+ const p = ve(a, i, w);
453
+ return e?.[p.name] ? new Promise((t, c) => {
454
+ B.current.push({ args: p, resolveResult: t, reject: c }), l(B.current.length), queueMicrotask(() => O.current?.());
455
+ }) : Promise.reject(new Error(`[react-modal-navigation] Unknown modal: ${p.name}`));
456
+ }, [e]), ne = m((a) => {
448
457
  if (!a || typeof a != "object" || Array.isArray(a)) throw new TypeError("[react-modal-navigation] update expects an options object");
449
- const i = b.current;
450
- if (!i || M.current) return !1;
451
- const t = { ...i, overrides: { ...i.overrides, ...a } };
452
- return b.current = t, N(t), B.current = Y(t), !0;
453
- }, [Y]), Z = d((a = "queue-cleared") => {
454
- const i = F.current.splice(0);
455
- h(0);
456
- for (const t of i)
457
- t.resolveId?.(null), t.resolveResult?.({ status: "dismissed", reason: a });
458
+ const i = g.current;
459
+ if (!i || j.current) return !1;
460
+ const w = { ...i, overrides: { ...i.overrides, ...a } };
461
+ return g.current = w, E(w), F.current = K(w), !0;
462
+ }, [K]), le = m((a = "queue-cleared") => {
463
+ const i = B.current.splice(0);
464
+ l(0);
465
+ for (const w of i)
466
+ w.resolveId?.(null), w.resolveResult?.({ status: "dismissed", reason: a });
458
467
  return i.length;
459
- }, []), _ = d((a, i, t) => {
460
- const o = ye(a, i, t);
461
- return X(o.name, o.params, o.options);
462
- }, [X]), le = d((a, i, t) => {
463
- const o = ye(a, i, t);
464
- return new Promise((l, L) => {
465
- X(o.name, o.params, o.options, l).then(($) => {
466
- $ === null && l({ status: "dismissed", reason: "blocked" });
467
- }, L);
468
+ }, []), Z = m((a, i, w) => {
469
+ const p = ve(a, i, w);
470
+ return X(p.name, p.params, p.options, void 0, p.screen);
471
+ }, [X]), J = m((a, i, w) => {
472
+ const p = ve(a, i, w);
473
+ return new Promise((t, c) => {
474
+ X(p.name, p.params, p.options, t, p.screen).then((u) => {
475
+ u === null && t({ status: "dismissed", reason: "blocked" });
476
+ }, c);
468
477
  });
469
- }, [X]), ue = d((a) => Q("api", a), [Q]), de = d((a = "api") => Q(a), [Q]), me = d((a) => Q("confirm", a, { confirmed: !0 }), [Q]), pe = d((a, i) => H.current?.setLoading(a, i), []), re = V(() => ({ open: _, openAsync: le, enqueue: ge, enqueueAsync: te, update: ce, clearQueue: Z, close: ue, dismiss: de, confirm: me, setLoading: pe, queueSize: p, isOpen: !!f, activeName: f?.name ?? null, error: E, clearError: () => y(null) }), [_, le, ge, te, ce, Z, ue, de, me, pe, f, E, p]);
470
- return O(() => (x.current = !0, () => {
471
- x.current = !1, I.current += 1, b.current = null;
472
- for (const i of D.current.values()) i({ status: "dismissed", reason: "unmount" });
473
- D.current.clear(), z.current.clear();
474
- const a = F.current.splice(0);
478
+ }, [X]), ue = m((a) => Y("api", a), [Y]), de = m((a = "api") => Y(a), [Y]), me = m((a) => Y("confirm", a, { confirmed: !0 }), [Y]), pe = m((a, i) => $.current?.setLoading(a, i), []), ye = V(() => ({ open: Z, openAsync: J, enqueue: ie, enqueueAsync: ge, update: ne, clearQueue: le, close: ue, dismiss: de, confirm: me, setLoading: pe, queueSize: k, isOpen: !!h, activeName: h?.name ?? null, error: T, clearError: () => x(null) }), [Z, J, ie, ge, ne, le, ue, de, me, pe, h, T, k]);
479
+ return I(() => (C.current = !0, () => {
480
+ C.current = !1, P.current += 1, g.current = null;
481
+ for (const i of A.current.values()) i({ status: "dismissed", reason: "unmount" });
482
+ A.current.clear(), q.current.clear();
483
+ const a = B.current.splice(0);
475
484
  for (const i of a)
476
485
  i.resolveId?.(null), i.resolveResult?.({ status: "dismissed", reason: "unmount" });
477
- }), []), /* @__PURE__ */ ae(Te.Provider, { value: re, children: [
486
+ }), []), /* @__PURE__ */ oe(Pe.Provider, { value: ye, children: [
478
487
  n,
479
- f && /* @__PURE__ */ m(
480
- _e,
488
+ h && /* @__PURE__ */ f(
489
+ Xe,
481
490
  {
482
- config: f.config,
483
- params: f.params,
484
- options: ne,
485
- translate: g,
486
- notifyError: S,
487
- error: E,
488
- clearError: () => y(null),
491
+ config: h.config,
492
+ initialScreen: h.screen,
493
+ params: h.params,
494
+ options: ae,
495
+ translate: v,
496
+ notifyError: N,
497
+ error: T,
498
+ clearError: () => x(null),
489
499
  registerLoading: (a) => {
490
- H.current = a;
500
+ $.current = a;
491
501
  },
492
- registerDirtyGuard: T,
493
- exiting: P,
494
- onRequestClose: Q,
502
+ registerDirtyGuard: M,
503
+ exiting: L,
504
+ onRequestClose: Y,
495
505
  onOpened: (a) => {
496
506
  try {
497
- const i = J.current?.onOpen?.(a);
498
- Promise.resolve(i).catch((t) => S(t, { phase: "onOpen" }));
507
+ const i = se.current?.onOpen?.(a);
508
+ Promise.resolve(i).catch((w) => N(w, { phase: "onOpen" }));
499
509
  } catch (i) {
500
- S(i, { phase: "onOpen" });
510
+ N(i, { phase: "onOpen" });
501
511
  }
502
512
  }
503
513
  },
504
- f.id
514
+ h.id
505
515
  )
506
516
  ] });
507
517
  }
508
- function sn() {
509
- const e = ee(Te), n = ee(Re);
518
+ function ln() {
519
+ const e = ee(Pe), n = ee(Ce);
510
520
  if (!e) throw new Error("[react-modal-navigation] useModal requires <ModalProvider>");
511
521
  return V(() => {
512
522
  const r = () => {
@@ -514,12 +524,13 @@ function sn() {
514
524
  return n;
515
525
  };
516
526
  return { ...e, modal: e, navigation: {
517
- navigate: (...c) => r().navigate(...c),
518
- replace: (...c) => r().replace(...c),
519
- reset: (...c) => r().reset(...c),
520
- setParams: (...c) => r().setParams(...c),
521
- goBack: (...c) => r().goBack(...c),
522
- close: (...c) => r().close(...c),
527
+ navigate: (...s) => r().navigate(...s),
528
+ replace: (...s) => r().replace(...s),
529
+ reset: (...s) => r().reset(...s),
530
+ setParams: (...s) => r().setParams(...s),
531
+ setOptions: (...s) => r().setOptions(...s),
532
+ goBack: (...s) => r().goBack(...s),
533
+ close: (...s) => r().close(...s),
523
534
  get canGoBack() {
524
535
  return n?.canGoBack ?? !1;
525
536
  },
@@ -532,115 +543,115 @@ function sn() {
532
543
  } };
533
544
  }, [e, n]);
534
545
  }
535
- function cn() {
536
- const e = ee(Re);
546
+ function un() {
547
+ const e = ee(Ce);
537
548
  if (!e) throw new Error("useModalNavigation requires an active modal screen");
538
549
  return e;
539
550
  }
540
- function Fe() {
541
- const e = ee(be);
551
+ function qe() {
552
+ const e = ee(we);
542
553
  if (!e) throw new Error("useIsFocused must be called inside a modal screen");
543
554
  return e.isFocused;
544
555
  }
545
- function ln(e) {
546
- const n = Fe();
547
- O(() => {
556
+ function dn(e) {
557
+ const n = qe();
558
+ I(() => {
548
559
  if (n)
549
560
  return e();
550
561
  }, [n, e]);
551
562
  }
552
- function un(e) {
553
- const n = ee(be);
563
+ function mn(e) {
564
+ const n = ee(we);
554
565
  if (!n) throw new Error("useNavigationResult requires an active modal screen");
555
- const r = u(e), s = u(null);
556
- O(() => {
566
+ const r = d(e), o = d(null);
567
+ I(() => {
557
568
  r.current = e;
558
- }, [e]), O(() => {
559
- !n.isFocused || !n.resultEvent || s.current !== n.resultEvent.id && (s.current = n.resultEvent.id, r.current(n.resultEvent.data));
569
+ }, [e]), I(() => {
570
+ !n.isFocused || !n.resultEvent || o.current !== n.resultEvent.id && (o.current = n.resultEvent.id, r.current(n.resultEvent.data));
560
571
  }, [n.isFocused, n.resultEvent]);
561
572
  }
562
- function dn(e = {}) {
563
- const n = ee(be);
573
+ function pn(e = {}) {
574
+ const n = ee(we);
564
575
  if (!n) throw new Error("[react-modal-navigation] useModalFooter requires an active modal screen");
565
- const { setFooter: r, routeKey: s } = n, c = u(e);
566
- c.current = e;
567
- const g = V(() => (...R) => c.current.done?.(...R), []), v = V(() => (...R) => (c.current.cancel ?? c.current.cancle)?.(...R), []), w = V(() => (...R) => c.current.renderFooter?.(...R), []), f = typeof e.done == "function", N = typeof (e.cancel ?? e.cancle) == "function", E = typeof e.renderFooter == "function", { showFooter: y, showFooterBorder: p, doneDisabled: h, doneText: b, cancelText: D, loadingText: F, footerClassName: q } = e, A = V(() => ({
568
- showFooter: y,
569
- showFooterBorder: p,
570
- doneDisabled: h,
571
- doneText: b,
572
- cancelText: D,
573
- loadingText: F,
574
- footerClassName: q,
575
- ...f ? { done: g } : {},
576
- ...N ? { cancel: v } : {},
577
- ...E ? { renderFooter: w } : {}
578
- }), [y, p, h, b, D, F, q, f, N, E, g, v, w]);
579
- O(() => {
580
- r(s, A);
581
- }, [s, r, A]), O(() => () => r(s, null), [s, r]);
576
+ const { setFooter: r, routeKey: o } = n, s = d(e);
577
+ s.current = e;
578
+ const v = V(() => (...D) => s.current.done?.(...D), []), b = V(() => (...D) => (s.current.cancel ?? s.current.cancle)?.(...D), []), R = V(() => (...D) => s.current.renderFooter?.(...D), []), h = typeof e.done == "function", E = typeof (e.cancel ?? e.cancle) == "function", T = typeof e.renderFooter == "function", { showFooter: x, showFooterBorder: k, doneDisabled: l, doneText: g, cancelText: A, loadingText: B, footerClassName: H } = e, O = V(() => ({
579
+ showFooter: x,
580
+ showFooterBorder: k,
581
+ doneDisabled: l,
582
+ doneText: g,
583
+ cancelText: A,
584
+ loadingText: B,
585
+ footerClassName: H,
586
+ ...h ? { done: v } : {},
587
+ ...E ? { cancel: b } : {},
588
+ ...T ? { renderFooter: R } : {}
589
+ }), [x, k, l, g, A, B, H, h, E, T, v, b, R]);
590
+ I(() => {
591
+ r(o, O);
592
+ }, [o, r, O]), I(() => () => r(o, null), [o, r]);
582
593
  }
583
- function nn() {
584
- const e = ee(Me);
594
+ function rn() {
595
+ const e = ee(Se);
585
596
  if (!e) throw new Error("[react-modal-navigation] useModalLoading requires an active modal screen");
586
597
  return e;
587
598
  }
588
- function mn() {
589
- const e = nn(), n = Fe(), r = u(!0), s = u(!1), [c, g] = W(!1), [v, w] = W(null), f = u(e);
590
- return f.current = e, O(() => (r.current = !0, () => {
599
+ function fn() {
600
+ const e = rn(), n = qe(), r = d(!0), o = d(!1), [s, v] = Q(!1), [b, R] = Q(null), h = d(e);
601
+ return h.current = e, I(() => (r.current = !0, () => {
591
602
  r.current = !1;
592
- }), []), { run: d(async (E, y = {}) => {
593
- if (s.current) return { status: "busy" };
594
- if (typeof E != "function") throw new TypeError("[react-modal-navigation] run requires a function");
595
- s.current = !0, r.current && (g(!0), w(null));
596
- const p = f.current.showLoading(y.loadingText);
603
+ }), []), { run: m(async (T, x = {}) => {
604
+ if (o.current) return { status: "busy" };
605
+ if (typeof T != "function") throw new TypeError("[react-modal-navigation] run requires a function");
606
+ o.current = !0, r.current && (v(!0), R(null));
607
+ const k = h.current.showLoading(x.loadingText);
597
608
  try {
598
- const h = await E();
599
- return r.current && await y.onSuccess?.(h), { status: "success", value: h };
600
- } catch (h) {
609
+ const l = await T();
610
+ return r.current && await x.onSuccess?.(l), { status: "success", value: l };
611
+ } catch (l) {
601
612
  if (r.current) {
602
- w(h);
613
+ R(l);
603
614
  try {
604
- await y.onError?.(h);
605
- } catch (b) {
606
- console.error("[react-modal-navigation] onError failed", b);
615
+ await x.onError?.(l);
616
+ } catch (g) {
617
+ console.error("[react-modal-navigation] onError failed", g);
607
618
  }
608
619
  }
609
- if (y.throwOnError) throw h;
610
- return { status: "error", error: h };
620
+ if (x.throwOnError) throw l;
621
+ return { status: "error", error: l };
611
622
  } finally {
612
- p != null && f.current.hideLoading(p), s.current = !1, r.current && g(!1);
623
+ k != null && h.current.hideLoading(k), o.current = !1, r.current && v(!1);
613
624
  }
614
- }, []), pending: c, error: v, clearError: () => w(null), isFocused: n };
625
+ }, []), pending: s, error: b, clearError: () => R(null), isFocused: n };
615
626
  }
616
- function pn(e, n = {}) {
617
- const r = ee(Be);
627
+ function hn(e, n = {}) {
628
+ const r = ee(Fe);
618
629
  if (!r) throw new Error("[react-modal-navigation] useModalUnsavedChanges must be used inside a modal screen");
619
- const s = u({ dirty: e, ...n });
620
- s.current = { dirty: e, ...n };
621
- const { routeKey: c, registerDirtyGuard: g } = r;
622
- O(() => g(c, {
630
+ const o = d({ dirty: e, ...n });
631
+ o.current = { dirty: e, ...n };
632
+ const { routeKey: s, registerDirtyGuard: v } = r;
633
+ I(() => v(s, {
623
634
  get dirty() {
624
- return !!s.current.dirty;
635
+ return !!o.current.dirty;
625
636
  },
626
637
  get message() {
627
- return s.current.message;
638
+ return o.current.message;
628
639
  },
629
640
  get onBeforeDiscard() {
630
- return s.current.onBeforeDiscard;
641
+ return o.current.onBeforeDiscard;
631
642
  }
632
- }), [c, g]);
643
+ }), [s, v]);
633
644
  }
634
645
  export {
635
- _e as ModalNavigator,
636
- an as ModalProvider,
637
- ln as useFocusEffect,
638
- Fe as useIsFocused,
639
- sn as useModal,
640
- dn as useModalFooter,
641
- nn as useModalLoading,
642
- cn as useModalNavigation,
643
- mn as useModalTask,
644
- pn as useModalUnsavedChanges,
645
- un as useNavigationResult
646
+ Xe as ModalNavigator,
647
+ cn as ModalProvider,
648
+ dn as useFocusEffect,
649
+ qe as useIsFocused,
650
+ ln as useModal,
651
+ pn as useModalFooter,
652
+ rn as useModalLoading,
653
+ un as useModalNavigation,
654
+ fn as useModalTask,
655
+ hn as useModalUnsavedChanges,
656
+ mn as useNavigationResult
646
657
  };