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