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