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/README.md +98 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +29 -1
- package/dist/index.js +490 -414
- package/dist/style.css +28 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,570 +1,646 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import { createPortal as
|
|
4
|
-
const
|
|
5
|
-
let
|
|
6
|
-
const
|
|
7
|
-
function
|
|
8
|
-
switch (
|
|
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
|
|
10
|
+
return Pe(n.name, n.params);
|
|
11
11
|
case "NAVIGATE": {
|
|
12
|
-
const
|
|
13
|
-
return
|
|
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((
|
|
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),
|
|
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
|
|
25
|
+
const Se = () => {
|
|
26
26
|
if (typeof document > "u") return "light";
|
|
27
|
-
const e = document.documentElement,
|
|
28
|
-
return e.classList.contains("dark") ||
|
|
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
|
|
31
|
-
const
|
|
32
|
-
let
|
|
33
|
-
function
|
|
34
|
-
if (
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
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,
|
|
42
|
+
e || (e = !0, fe = Math.max(0, fe - 1), fe || (we?.(), we = null));
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
const
|
|
46
|
-
function
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
const [
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
const
|
|
55
|
-
for (const
|
|
56
|
-
const
|
|
57
|
-
return
|
|
58
|
-
|
|
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
|
-
}, [
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
if (!
|
|
67
|
-
if (
|
|
68
|
-
|
|
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 (
|
|
72
|
-
const
|
|
73
|
-
if (!
|
|
74
|
-
|
|
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
|
|
78
|
-
|
|
79
|
-
},
|
|
80
|
-
|
|
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",
|
|
83
|
-
document.removeEventListener("keydown",
|
|
84
|
-
const
|
|
85
|
-
if (
|
|
86
|
-
const
|
|
87
|
-
|
|
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
|
|
92
|
-
return
|
|
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:
|
|
96
|
-
className: `pmn-overlay pmn-place-${
|
|
97
|
-
style: { padding:
|
|
98
|
-
onMouseDown: (
|
|
99
|
-
|
|
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__ */
|
|
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":
|
|
109
|
-
"data-modal-theme":
|
|
110
|
-
className: `pmn-dialog ${
|
|
111
|
-
style: { "--pmn-width":
|
|
112
|
-
children:
|
|
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
|
|
119
|
-
return /* @__PURE__ */
|
|
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
|
|
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
|
|
124
|
-
if (
|
|
125
|
-
const
|
|
126
|
-
return /* @__PURE__ */
|
|
127
|
-
e.showBackButton !== !1 &&
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
e.showCloseButton !== !1 && /* @__PURE__ */
|
|
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
|
|
134
|
-
const [
|
|
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
|
|
137
|
-
if (typeof
|
|
138
|
-
if (typeof
|
|
139
|
-
const
|
|
140
|
-
if (!(
|
|
141
|
-
|
|
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
|
|
144
|
-
} catch (
|
|
145
|
-
|
|
143
|
+
await M(A);
|
|
144
|
+
} catch (I) {
|
|
145
|
+
w?.(I, { phase: "footer", route: s });
|
|
146
146
|
} finally {
|
|
147
|
-
|
|
147
|
+
N(!1);
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
};
|
|
151
|
-
return /* @__PURE__ */
|
|
152
|
-
typeof
|
|
153
|
-
typeof
|
|
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
|
|
156
|
+
function Ye({ loading: e, translate: n }) {
|
|
157
157
|
if (!e.visible) return null;
|
|
158
|
-
const
|
|
159
|
-
return /* @__PURE__ */
|
|
160
|
-
/* @__PURE__ */
|
|
161
|
-
/* @__PURE__ */
|
|
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
|
|
164
|
+
class Qe extends qe.Component {
|
|
165
165
|
state = { error: null };
|
|
166
|
-
static getDerivedStateFromError(
|
|
167
|
-
return { error:
|
|
166
|
+
static getDerivedStateFromError(n) {
|
|
167
|
+
return { error: n };
|
|
168
168
|
}
|
|
169
|
-
componentDidCatch(
|
|
170
|
-
this.props.onError?.(
|
|
169
|
+
componentDidCatch(n, r) {
|
|
170
|
+
this.props.onError?.(n, { phase: "render", route: this.props.route, componentStack: r.componentStack });
|
|
171
171
|
}
|
|
172
|
-
componentDidUpdate(
|
|
173
|
-
|
|
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__ */
|
|
177
|
-
/* @__PURE__ */
|
|
178
|
-
/* @__PURE__ */
|
|
179
|
-
/* @__PURE__ */
|
|
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
|
|
184
|
-
const
|
|
185
|
-
isLoading:
|
|
186
|
-
setLoading: (
|
|
187
|
-
showLoading: (
|
|
188
|
-
hideLoading: (
|
|
189
|
-
}), [
|
|
190
|
-
return /* @__PURE__ */
|
|
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
|
|
193
|
-
const [
|
|
194
|
-
|
|
195
|
-
const
|
|
196
|
-
if (
|
|
197
|
-
const
|
|
198
|
-
return
|
|
199
|
-
}, [
|
|
200
|
-
if (
|
|
201
|
-
|
|
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 [
|
|
204
|
-
|
|
205
|
-
}, [
|
|
206
|
-
|
|
207
|
-
}, [
|
|
208
|
-
|
|
209
|
-
}, [
|
|
210
|
-
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
if (
|
|
215
|
-
if (!(
|
|
216
|
-
const
|
|
217
|
-
return delete
|
|
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
|
|
220
|
-
}), []),
|
|
221
|
-
const
|
|
222
|
-
if (!(
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
}, []),
|
|
226
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
227
|
-
}, [
|
|
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(
|
|
230
|
-
} catch (
|
|
231
|
-
|
|
229
|
+
Promise.resolve(r[t]?.(o)).catch((l) => w(l, { phase: t }));
|
|
230
|
+
} catch (l) {
|
|
231
|
+
w(l, { phase: t });
|
|
232
232
|
}
|
|
233
|
-
}, [
|
|
234
|
-
|
|
235
|
-
}, [
|
|
236
|
-
|
|
237
|
-
}, [
|
|
238
|
-
if (!
|
|
239
|
-
|
|
240
|
-
}, []),
|
|
241
|
-
if (
|
|
242
|
-
if (
|
|
243
|
-
const
|
|
244
|
-
|
|
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
|
|
247
|
-
}, [
|
|
248
|
-
return
|
|
249
|
-
|
|
250
|
-
const
|
|
251
|
-
if (!
|
|
252
|
-
const
|
|
253
|
-
(
|
|
254
|
-
}, [
|
|
255
|
-
let
|
|
256
|
-
for (const [
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
const
|
|
260
|
-
for (const
|
|
261
|
-
}, [
|
|
262
|
-
if (
|
|
263
|
-
if (
|
|
264
|
-
const
|
|
265
|
-
|
|
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
|
-
|
|
267
|
+
Z("onFocus", { route: k, stack: p }), H.current = k;
|
|
268
268
|
}
|
|
269
|
-
}, [
|
|
270
|
-
|
|
271
|
-
}, []),
|
|
272
|
-
|
|
273
|
-
}, []), /* @__PURE__ */
|
|
274
|
-
/* @__PURE__ */
|
|
275
|
-
/* @__PURE__ */
|
|
276
|
-
|
|
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:
|
|
279
|
-
screen:
|
|
280
|
-
navigation:
|
|
281
|
-
focused:
|
|
282
|
-
resultEvent:
|
|
283
|
-
bodyClassName:
|
|
284
|
-
setFooter:
|
|
285
|
-
loadingApi:
|
|
286
|
-
notifyError:
|
|
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
|
-
|
|
289
|
+
t.key
|
|
289
290
|
)) }),
|
|
290
|
-
/* @__PURE__ */
|
|
291
|
-
|
|
291
|
+
/* @__PURE__ */ m(
|
|
292
|
+
We,
|
|
292
293
|
{
|
|
293
|
-
screen:
|
|
294
|
-
options:
|
|
295
|
-
override: F[
|
|
296
|
-
route:
|
|
297
|
-
navigation:
|
|
294
|
+
screen: x[k.name],
|
|
295
|
+
options: r,
|
|
296
|
+
override: F[T],
|
|
297
|
+
route: k,
|
|
298
|
+
navigation: i,
|
|
298
299
|
requestClose: re,
|
|
299
|
-
translate:
|
|
300
|
-
onError:
|
|
300
|
+
translate: s,
|
|
301
|
+
onError: w
|
|
301
302
|
},
|
|
302
|
-
|
|
303
|
+
T
|
|
303
304
|
),
|
|
304
|
-
/* @__PURE__ */
|
|
305
|
-
|
|
306
|
-
/* @__PURE__ */
|
|
307
|
-
/* @__PURE__ */
|
|
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
|
|
312
|
-
function
|
|
313
|
-
|
|
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
|
|
317
|
-
if (!
|
|
318
|
-
let
|
|
319
|
-
const
|
|
320
|
-
|
|
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
|
|
323
|
-
|
|
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
|
|
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:
|
|
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
|
|
334
|
-
const { name:
|
|
335
|
-
if (typeof
|
|
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 (
|
|
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:
|
|
340
|
+
return { name: s, params: c, options: { ...v, ...g } };
|
|
340
341
|
}
|
|
341
|
-
const
|
|
342
|
-
function
|
|
343
|
-
|
|
344
|
-
const [
|
|
345
|
-
|
|
346
|
-
const
|
|
347
|
-
|
|
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
|
-
|
|
350
|
-
} catch (
|
|
351
|
-
console.error("[react-modal-navigation] onError failed",
|
|
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
|
-
}, []),
|
|
354
|
-
const
|
|
355
|
-
|
|
356
|
-
}, []),
|
|
357
|
-
|
|
358
|
-
const
|
|
359
|
-
const
|
|
360
|
-
if (!
|
|
361
|
-
|
|
362
|
-
const
|
|
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
|
|
365
|
-
|
|
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
|
|
368
|
-
} catch (
|
|
369
|
-
|
|
381
|
+
await l.onClose?.(L);
|
|
382
|
+
} catch ($) {
|
|
383
|
+
S($, { phase: "onClose", name: o.name });
|
|
370
384
|
}
|
|
371
385
|
return !0;
|
|
372
|
-
} catch (
|
|
373
|
-
return
|
|
386
|
+
} catch ($) {
|
|
387
|
+
return S($, { phase: "onBeforeClose", name: o.name }), !1;
|
|
374
388
|
} finally {
|
|
375
|
-
|
|
389
|
+
j.current === o.id && (j.current = null), M.current = !1, !b.current && x.current && queueMicrotask(() => A.current?.());
|
|
376
390
|
}
|
|
377
|
-
}, [
|
|
378
|
-
const
|
|
379
|
-
if (!
|
|
380
|
-
if (!
|
|
381
|
-
if (!
|
|
382
|
-
|
|
383
|
-
const
|
|
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
|
|
386
|
-
if (
|
|
387
|
-
const
|
|
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
|
|
390
|
-
} catch (
|
|
391
|
-
return
|
|
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 (!
|
|
394
|
-
|
|
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
|
|
397
|
-
} catch (
|
|
398
|
-
|
|
410
|
+
await Ce.onClose?.(ve);
|
|
411
|
+
} catch (xe) {
|
|
412
|
+
S(xe, { phase: "onClose", name: $.name });
|
|
399
413
|
}
|
|
400
|
-
if (!
|
|
414
|
+
if (!x.current || L !== I.current) return null;
|
|
401
415
|
}
|
|
402
|
-
const
|
|
403
|
-
return
|
|
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
|
-
|
|
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
|
-
}, [
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
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
|
-
}, [
|
|
418
|
-
return
|
|
419
|
-
|
|
420
|
-
for (const
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
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:
|
|
428
|
-
params:
|
|
429
|
-
options:
|
|
430
|
-
translate:
|
|
431
|
-
notifyError:
|
|
432
|
-
error:
|
|
433
|
-
clearError: () =>
|
|
434
|
-
registerLoading: (
|
|
435
|
-
|
|
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
|
-
|
|
438
|
-
|
|
492
|
+
registerDirtyGuard: T,
|
|
493
|
+
exiting: P,
|
|
494
|
+
onRequestClose: Q,
|
|
495
|
+
onOpened: (a) => {
|
|
439
496
|
try {
|
|
440
|
-
const
|
|
441
|
-
Promise.resolve(
|
|
442
|
-
} catch (
|
|
443
|
-
|
|
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
|
-
|
|
504
|
+
f.id
|
|
448
505
|
)
|
|
449
506
|
] });
|
|
450
507
|
}
|
|
451
|
-
function
|
|
452
|
-
const e =
|
|
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
|
|
456
|
-
if (!
|
|
457
|
-
return
|
|
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: (...
|
|
461
|
-
replace: (...
|
|
462
|
-
reset: (...
|
|
463
|
-
setParams: (...
|
|
464
|
-
goBack: (...
|
|
465
|
-
close: (...
|
|
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
|
|
524
|
+
return n?.canGoBack ?? !1;
|
|
468
525
|
},
|
|
469
526
|
get stack() {
|
|
470
|
-
return
|
|
527
|
+
return n?.stack ?? [];
|
|
471
528
|
},
|
|
472
529
|
get currentRoute() {
|
|
473
|
-
return
|
|
530
|
+
return n?.currentRoute ?? null;
|
|
474
531
|
}
|
|
475
532
|
} };
|
|
476
|
-
}, [e,
|
|
533
|
+
}, [e, n]);
|
|
477
534
|
}
|
|
478
|
-
function
|
|
479
|
-
const e =
|
|
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
|
|
484
|
-
const e =
|
|
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
|
|
489
|
-
const
|
|
490
|
-
|
|
491
|
-
if (
|
|
545
|
+
function ln(e) {
|
|
546
|
+
const n = Fe();
|
|
547
|
+
O(() => {
|
|
548
|
+
if (n)
|
|
492
549
|
return e();
|
|
493
|
-
}, [
|
|
550
|
+
}, [n, e]);
|
|
494
551
|
}
|
|
495
|
-
function
|
|
496
|
-
const
|
|
497
|
-
if (!
|
|
498
|
-
const
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
}, [e]),
|
|
502
|
-
!
|
|
503
|
-
}, [
|
|
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
|
|
506
|
-
const
|
|
507
|
-
if (!
|
|
508
|
-
const { setFooter:
|
|
509
|
-
|
|
510
|
-
const
|
|
511
|
-
showFooter:
|
|
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:
|
|
514
|
-
doneText:
|
|
515
|
-
cancelText:
|
|
516
|
-
loadingText:
|
|
517
|
-
footerClassName:
|
|
518
|
-
...
|
|
519
|
-
...
|
|
520
|
-
...
|
|
521
|
-
}), [
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
}, [
|
|
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
|
|
527
|
-
const e =
|
|
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
|
|
532
|
-
const e =
|
|
533
|
-
return
|
|
534
|
-
|
|
535
|
-
}), []), { run:
|
|
536
|
-
if (
|
|
537
|
-
if (typeof
|
|
538
|
-
|
|
539
|
-
const p =
|
|
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
|
|
542
|
-
return
|
|
543
|
-
} catch (
|
|
544
|
-
if (
|
|
545
|
-
|
|
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
|
|
548
|
-
} catch (
|
|
549
|
-
console.error("[react-modal-navigation] onError failed",
|
|
604
|
+
await y.onError?.(h);
|
|
605
|
+
} catch (b) {
|
|
606
|
+
console.error("[react-modal-navigation] onError failed", b);
|
|
550
607
|
}
|
|
551
608
|
}
|
|
552
|
-
if (
|
|
553
|
-
return { status: "error", error:
|
|
609
|
+
if (y.throwOnError) throw h;
|
|
610
|
+
return { status: "error", error: h };
|
|
554
611
|
} finally {
|
|
555
|
-
p != null &&
|
|
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
|
-
}, [
|
|
632
|
+
}), [c, g]);
|
|
558
633
|
}
|
|
559
634
|
export {
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
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
|
};
|