react-modal-navigation 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,8 @@ React 19 多页面弹窗导航组件库。支持 **Modal / Drawer / Sheet**、
7
7
  ## 目录
8
8
 
9
9
  1. [安装和快速开始](#安装和快速开始)
10
- 2. [弹窗位置与尺寸](#弹窗位置与尺寸)
10
+ 2. [对象形式打开弹窗](#推荐对象形式打开弹窗)
11
+ 3. [弹窗位置与尺寸](#弹窗位置与尺寸)
11
12
  3. [配置优先级与响应式](#配置优先级与响应式)
12
13
  4. [页面导航与传参](#页面导航与传参)
13
14
  5. [Promise 结果与关闭守卫](#promise-结果与关闭守卫)
@@ -69,7 +70,48 @@ export default function App() {
69
70
  }
70
71
  ```
71
72
 
72
- **不需要** `import 'react-modal-navigation/style.css'`,Provider 会自动注入组件样式;业务页面可以使用任意 CSS 方案。
73
+ ## 推荐:对象形式打开弹窗
74
+
75
+ `modal.open()` 和 `modal.openAsync()` 现在都支持**字符串位置参数**及**对象参数**两种写法,原有代码不需要修改。推荐新项目采用对象形式,避免为了设置位置而传入无意义的 `{}`。
76
+
77
+ ```jsx
78
+ const { modal } = useModal();
79
+
80
+ // 推荐:只有名称和布局配置,不需要空的 params
81
+ await modal.open({
82
+ name: 'editUser',
83
+ options: { placement: 'bottom', width: '100%', height: '55dvh' },
84
+ });
85
+
86
+ // 带页面参数
87
+ await modal.open({
88
+ name: 'editUser',
89
+ params: { userId: 1001 },
90
+ options: { placement: 'center', width: 640 },
91
+ });
92
+
93
+ // Promise 弹窗也支持同样的对象形式
94
+ const result = await modal.openAsync({
95
+ name: 'editUser',
96
+ params: { userId: 1001 },
97
+ options: { placement: 'right', width: 520 },
98
+ });
99
+
100
+ // 旧 API 保持兼容
101
+ await modal.open('editUser');
102
+ await modal.open('editUser', { userId: 1001 });
103
+ await modal.open('editUser', {}, { placement: 'bottom', height: '55dvh' });
104
+ ```
105
+
106
+ 对象字段说明:
107
+
108
+ | 字段 | 类型 | 必填 | 说明 |
109
+ | --- | --- | --- | --- |
110
+ | `name` | `string` | 是 | registry 中注册的弹窗名称 |
111
+ | `params` | `unknown` | 否 | 传给初始 Screen 的页面参数,默认 `{}` |
112
+ | `options` | `ModalOptions` | 否 | 本次打开覆盖的布局、尺寸、主题和事件配置 |
113
+
114
+ **兼容规则:** 第一个参数是字符串时继续使用 `open(name, params?, overrides?)`;第一个参数是对象时使用 `open({ name, params?, options? })`。对象形式不需要再传第二、第三个参数。配置优先级仍为 `defaultOptions → modalOptions → options`。`openAsync` 的结果结构不变。
73
115
 
74
116
  ## 弹窗位置与尺寸
75
117
 
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react/jsx-runtime"),n=require("react"),ye=require("react-dom"),ge=n.createContext(null),oe=n.createContext(null),ee=n.createContext(null),ae=n.createContext(null);let ke=0;const re=(e,t)=>({key:`modal-route-${++ke}`,name:e,params:t??{}}),be=(e,t)=>[re(e,t)];function we(e,t){switch(t.type){case"RESET":return be(t.name,t.params);case"NAVIGATE":{const r=e.findIndex(a=>a.name===t.name);return r<0?[...e,re(t.name,t.params)]:e.slice(0,r+1).map((a,s)=>s===r?{...a,params:t.params??{}}:a)}case"SET_PARAMS":return e.map((r,a)=>a===e.length-1?{...r,params:{...r.params??{},...t.params??{}}}:r);case"BACK":return e.length>1?e.slice(0,-1):e;case"REPLACE":return e.length?[...e.slice(0,-1),re(t.name,t.params)]:e;default:return e}}const fe=()=>{if(typeof document>"u")return"light";const e=document.documentElement,t=document.body;return e.classList.contains("dark")||t.classList.contains("dark")||e.dataset.theme==="dark"||t.dataset.theme==="dark"?"dark":e.classList.contains("light")||t.classList.contains("light")||e.dataset.theme==="light"||t.dataset.theme==="light"?"light":window.matchMedia?.("(prefers-color-scheme: dark)").matches?"dark":"light"};let X=0;const Y=[];let te=null;function Ce(){if(X++,X===1){const t=document.documentElement,r=document.body,a={html:t.style.overflow,body:r.style.overflow,padding:r.style.paddingRight,width:r.style.getPropertyValue("--modal-scrollbar-width")},s=Math.max(0,window.innerWidth-t.clientWidth),y=parseFloat(getComputedStyle(r).paddingRight)||0;s&&(r.style.paddingRight=`${y+s}px`),r.style.setProperty("--modal-scrollbar-width",`${s}px`),t.style.overflow="hidden",r.style.overflow="hidden",te=()=>{t.style.overflow=a.html,r.style.overflow=a.body,r.style.paddingRight=a.padding,a.width?r.style.setProperty("--modal-scrollbar-width",a.width):r.style.removeProperty("--modal-scrollbar-width")}}let e=!1;return()=>{e||(e=!0,X=Math.max(0,X-1),X||(te?.(),te=null))}}const Ee='a[href],button:not([disabled]),input:not([disabled]),textarea:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])',Re=e=>!e.closest('[inert], [hidden], [aria-hidden="true"]')&&e.getClientRects().length>0&&getComputedStyle(e).visibility!=="hidden"&&getComputedStyle(e).display!=="none";function Me({dialogRef:e,options:t,requestClose:r,children:a}){const s=n.useRef(null),y=n.useRef(null),h=n.useRef(r);h.current=r;const m=n.useRef(t.closeOnEsc);m.current=t.closeOnEsc;const[g,M]=n.useState(fe),l=t.theme==="light"||t.theme==="dark"?t.theme:g;n.useEffect(()=>{if(t.theme==="light"||t.theme==="dark")return;const j=()=>M(fe()),b=new MutationObserver(j);for(const H of[document.documentElement,document.body])b.observe(H,{attributes:!0,attributeFilter:["class","data-theme"]});const E=window.matchMedia?.("(prefers-color-scheme: dark)");return E?.addEventListener?.("change",j),j(),()=>{b.disconnect(),E?.removeEventListener?.("change",j)}},[t.theme]),n.useEffect(()=>{y.current=document.activeElement;const j=Ce(),b=s.current;Y.push(b),e.current?.focus({preventScroll:!0});const E=w=>{const S=e.current;if(!S||Y.at(-1)!==b)return;if(w.key==="Escape"&&m.current!==!1){w.preventDefault(),h.current("escape");return}if(w.key!=="Tab")return;const B=[...S.querySelectorAll(Ee)].filter(Re);if(!B.length){w.preventDefault(),S.focus();return}const $=B[0],K=B.at(-1);S.contains(document.activeElement)?w.shiftKey&&(document.activeElement===$||document.activeElement===S)?(w.preventDefault(),K.focus()):!w.shiftKey&&(document.activeElement===K||document.activeElement===S)&&(w.preventDefault(),$.focus()):(w.preventDefault(),(w.shiftKey?K:$).focus())},H=w=>{Y.at(-1)===b&&e.current&&!e.current.contains(w.target)&&e.current.focus({preventScroll:!0})};return document.addEventListener("keydown",E),document.addEventListener("focusin",H),()=>{document.removeEventListener("keydown",E),document.removeEventListener("focusin",H);const w=Y.at(-1)===b,S=Y.indexOf(b);if(S!==-1&&Y.splice(S,1),j(),w){const B=y.current;B?.isConnected&&!B.closest("[inert], [hidden]")?B.focus?.({preventScroll:!0}):Y.at(-1)?.querySelector("[role=dialog]")?.focus?.({preventScroll:!0})}}},[e]);const u=t.backgroundColor??t.backgroudColor,f=typeof u=="string"?u:u?.[l],x=typeof f=="string"&&/^(#|rgb\(|rgba\(|hsl\(|hsla\(|oklch\(|color\(|var\()/.test(f.trim())?f:null,N={sm:400,md:560,lg:720,xl:960,full:"100%"},O=["center","left","right","top","bottom"].includes(t.placement)?t.placement:"right",P=j=>typeof j=="number"?`${j}px`:j,v=P(t.width??N[t.size]??460),T=P(t.height),R=P(t.maxHeight),q=P(t.maxWidth),k=Number(t.viewportGap??5),A=Number.isFinite(k)?Math.max(0,k):5,z=typeof t.borderRadius=="number"?`${t.borderRadius}px`:t.borderRadius??"12px";return ye.createPortal(c.jsx("div",{ref:s,className:`pmn-overlay pmn-place-${O} ${t.mobileFullscreen?"pmn-mobile-fullscreen":""}`,style:{padding:A},onMouseDown:j=>{j.target===j.currentTarget&&t.closeOnOverlay===!0&&h.current("overlay")},children:c.jsx("section",{ref:e,tabIndex:-1,role:"dialog","aria-modal":"true","aria-label":t.ariaLabel??"Dialog","data-modal-theme":l,className:`pmn-dialog ${l==="dark"?"dark":""} ${!x&&f?f:""} ${t.className??""}`,style:{"--pmn-width":v,"--pmn-gap":`${A}px`,...T!==void 0?{"--pmn-height":T}:{},...R!==void 0?{"--pmn-max-height":R}:{},...q!==void 0?{"--pmn-max-width":q}:{},borderRadius:z,...x?{backgroundColor:x}:{}},children:a})}),document.body)}function pe({back:e}){return c.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",width:"20",height:"20",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e?c.jsx("path",{d:"m15 18-6-6 6-6"}):c.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})}function je({options:e,screen:t,route:r,navigation:a,requestClose:s,translate:y}){if(e.showHeader===!1)return null;const h=y??(f=>f),m=t.showTitle??e.showTitle??!0,g=typeof t.title=="function"?t.title({t:h,route:r,navigation:a}):t.title??r.name,M={route:r,navigation:a,close:s,canGoBack:a.canGoBack,title:g,t:h},l=t.renderHeader??e.renderHeader;if(l)return l(M);const u=t.renderHeaderRight??e.renderHeaderRight;return c.jsxs("header",{className:`pmn-header ${t.showHeaderBorder??e.showHeaderBorder?"pmn-border-bottom":""} ${e.headerClassName??""}`,children:[e.showBackButton!==!1&&a.canGoBack&&c.jsx("button",{type:"button",className:"pmn-icon-button","aria-label":h("modal.back"),onClick:()=>a.goBack(),children:c.jsx(pe,{back:!0})}),m?c.jsx("h2",{children:g}):c.jsx("div",{className:"pmn-header-spacer"}),u?.(M),e.showCloseButton!==!1&&c.jsx("button",{type:"button",className:"pmn-icon-button","aria-label":h("modal.close"),onClick:()=>s("header"),children:c.jsx(pe,{})})]})}function Se({screen:e,options:t,override:r,route:a,navigation:s,requestClose:y,translate:h,onError:m}){const[g,M]=n.useState(!1),l=h??(k=>k),u={...t,...e,...r},{showFooter:f,renderFooter:x,done:N,cancel:O,cancle:P}=u,v=O??P,T={route:a,navigation:s,close:y,t:l};if(f===!1)return null;const R=`pmn-footer ${u.showFooterBorder?"pmn-border-top":""} ${u.footerClassName??""}`;if(typeof x=="function")return c.jsx("footer",{className:R,children:x({...T,pending:g})});if(typeof N!="function"&&typeof v!="function")return null;const q=async k=>{if(!(g||typeof k!="function")){M(!0);try{await k(T)}catch(A){m?.(A,{phase:"footer",route:a})}finally{M(!1)}}};return c.jsxs("footer",{className:R,children:[typeof v=="function"&&c.jsx("button",{type:"button",disabled:g,onClick:()=>q(v),className:"pmn-button pmn-button-secondary",children:u.cancelText??l("modal.cancel")}),typeof N=="function"&&c.jsx("button",{type:"button",disabled:g||u.doneDisabled===!0,onClick:()=>q(N),className:"pmn-button pmn-button-primary",children:g?u.loadingText??l("modal.processing"):u.doneText??l("modal.done")})]})}function Le({loading:e,translate:t}){if(!e.visible)return null;const a=(t??(y=>y))("modal.loading"),s=e.text??(a==="modal.loading"?"加载中...":a);return c.jsx("div",{className:"pmn-loading-overlay",role:"status","aria-live":"polite","aria-busy":"true",children:c.jsxs("div",{className:"pmn-loading-card",children:[c.jsx("span",{className:"pmn-spinner","aria-hidden":"true"}),c.jsx("span",{children:s})]})})}class Ne extends n.Component{state={error:null};static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t,r){this.props.onError?.(t,{phase:"render",route:this.props.route,componentStack:r.componentStack})}componentDidUpdate(t){t.route?.key!==this.props.route?.key&&this.state.error&&this.setState({error:null})}render(){return this.state.error?c.jsxs("div",{role:"alert",className:"pmn-error-screen",children:[c.jsx("strong",{children:"页面加载失败"}),c.jsx("p",{children:this.state.error.message}),c.jsx("button",{type:"button",className:"pmn-button pmn-button-secondary",onClick:()=>this.setState({error:null}),children:"重试"})]}):this.props.children}}function Te({route:e,screen:t,navigation:r,focused:a,resultEvent:s,setFooter:y,loadingApi:h,bodyClassName:m,notifyError:g}){const M=t.component,l=n.useMemo(()=>({isFocused:a,resultEvent:s,routeKey:e.key,setFooter:y}),[a,s,e.key,y]),u=n.useMemo(()=>({isLoading:a&&h.isLoading,setLoading:(f,x)=>h.setScreenLoading(e.key,f,x),showLoading:f=>h.begin(e.key,f),hideLoading:f=>h.end(e.key,f)}),[a,h,e.key]);return c.jsx(ee.Provider,{value:l,children:c.jsx(ae.Provider,{value:u,children:c.jsx("div",{hidden:!a,inert:!a,"data-modal-route-key":e.key,tabIndex:-1,className:`pmn-body ${m??""}`,children:c.jsx(Ne,{route:e,onError:g,children:c.jsx(M,{route:e,navigation:r})})})})})}function xe({config:e,params:t,options:r,translate:a,onRequestClose:s,onOpened:y,registerLoading:h,notifyError:m,error:g,clearError:M}){const[l,u]=n.useReducer(we,null,()=>be(e.initialRoute,t)),[f,x]=n.useState({}),[N,O]=n.useState({}),[,P]=n.useState(0),v=n.useRef(new Map),T=n.useRef(0),R=n.useRef(new Map),q=n.useRef(null),k=n.useRef(null),A=n.useRef(!1),z=n.useRef(!1),j=n.useRef(0),b=l.at(-1),E=b.key,H=n.useRef(E);H.current=E;const w=e.screens,S=n.useCallback(()=>P(o=>o+1),[]),B=n.useCallback((o,i)=>{if(o!=="global"&&H.current!==o)return null;const p=++T.current;return v.current.set(p,{owner:o,text:i}),S(),p},[S]),$=n.useCallback((o,i)=>{if(i!=null)v.current.get(i)?.owner===o&&v.current.delete(i);else for(const[p,V]of v.current)V.owner===o&&v.current.delete(p);S()},[S]),K=n.useCallback((o,i)=>{o?($("global"),B("global",i)):$("global")},[B,$]),d=n.useCallback((o,i,p)=>{i?($(o),B(o,p)):$(o)},[B,$]),C=[...v.current.values()],L={visible:C.length>0,text:C.at(-1)?.text??null,count:C.length},F=n.useRef(L);F.current=L;const D=n.useMemo(()=>({isLoading:L.visible,setLoading:K,setScreenLoading:d,begin:B,end:$}),[L.visible,K,d,B,$]),G=n.useRef(h);G.current=h,n.useEffect(()=>(G.current?.({setLoading:K}),()=>G.current?.(null)),[K]);const I=n.useCallback((o,i)=>O(p=>{if(i===null){if(!(o in p))return p;const V={...p};return delete V[o],V}return p[o]===i?p:{...p,[o]:i}}),[]),U=n.useCallback(()=>{const o=document.activeElement;if(!(o instanceof HTMLElement)||!q.current?.contains(o))return;const i=o.closest("[data-modal-route-key]");i&&R.current.set(i.dataset.modalRouteKey,o),q.current.focus({preventScroll:!0})},[]),J=n.useCallback(o=>{if(!Object.prototype.hasOwnProperty.call(w,o))throw new Error(`[react-modal-navigation] Unknown modal screen: ${o}`)},[w]),_=n.useCallback((o,i)=>{try{Promise.resolve(r[o]?.(i)).catch(p=>m(p,{phase:o}))}catch(p){m(p,{phase:o})}},[r,m]),W=n.useCallback((o,i,p)=>{J(i),U(),u({type:o,name:i,params:p})},[J,U]),ce=n.useCallback((o,i)=>W("NAVIGATE",o,i),[W]),le=n.useCallback((o,i)=>W("REPLACE",o,i),[W]),ie=n.useCallback((o,i)=>{x({}),W("RESET",o,i)},[W]),ue=n.useCallback(o=>{if(!o||typeof o!="object"||Array.isArray(o))throw new TypeError("[react-modal-navigation] setParams expects an object");u({type:"SET_PARAMS",params:o})},[]),de=n.useCallback(o=>{if(l.length<=1||A.current)return!1;if(A.current=!0,o!==void 0){const i=l.at(-2);x(p=>({...p,[i.key]:{id:++j.current,data:o}}))}return U(),u({type:"BACK"}),!0},[l,U]),Q=n.useCallback((o,i)=>F.current.visible&&r.lockCloseWhileLoading!==!1?Promise.resolve(!1):s(o,i,{route:b,stack:l}),[r.lockCloseWhileLoading,s,b,l]),me=n.useCallback(o=>Q("api",o),[Q]),Z=n.useMemo(()=>({navigate:ce,replace:le,reset:ie,setParams:ue,goBack:de,close:me,setLoading:K,canGoBack:l.length>1,stack:l,currentRoute:b}),[ce,le,ie,ue,de,me,K,l,b]);return n.useLayoutEffect(()=>{A.current=!1;const o=[...q.current?.querySelectorAll("[data-modal-route-key]")??[]].find(V=>V.dataset.modalRouteKey===E);if(!o)return;const i=R.current.get(E);(i?.isConnected&&o.contains(i)&&!i.matches(":disabled")&&!i.closest("[inert], [hidden]")?i:o).focus({preventScroll:!0})},[E]),n.useEffect(()=>{let o=!1;for(const[p,V]of v.current)V.owner!=="global"&&V.owner!==E&&(v.current.delete(p),o=!0);o&&S();const i=new Set(l.map(p=>p.key));for(const p of R.current.keys())i.has(p)||R.current.delete(p)},[E,l,S]),n.useEffect(()=>{if(k.current?.key!==E){if(k.current){const o={from:k.current,to:b,stack:l};_("onBlur",{route:k.current,...o}),_("onNavigate",o),_("onRouteChange",o)}_("onFocus",{route:b,stack:l}),k.current=b}},[b,E,l,_]),n.useEffect(()=>()=>{v.current.clear(),R.current.clear()},[]),n.useEffect(()=>{z.current||(z.current=!0,y?.({route:b,stack:l}))},[]),c.jsx(oe.Provider,{value:Z,children:c.jsx(ae.Provider,{value:D,children:c.jsxs(Me,{dialogRef:q,options:r,requestClose:Q,children:[c.jsx(je,{options:r,screen:w[b.name],route:b,navigation:Z,requestClose:Q,translate:a}),c.jsx("main",{className:"pmn-main",children:l.map(o=>c.jsx(Te,{route:o,screen:w[o.name],navigation:Z,focused:o.key===E,resultEvent:f[o.key]??null,bodyClassName:r.bodyClassName,setFooter:I,loadingApi:D,notifyError:m},o.key))}),c.jsx(Se,{screen:w[b.name],options:r,override:N[E],route:b,navigation:Z,requestClose:Q,translate:a,onError:m},E),c.jsx(Le,{loading:L,translate:a}),g&&c.jsxs("div",{className:"pmn-error",role:"alert",children:[c.jsx("span",{children:g.message||String(g)}),c.jsx("button",{type:"button",onClick:M,"aria-label":"Dismiss error",children:"×"})]})]})})})}const Fe=".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}}",he="react-modal-navigation-styles",ne=new WeakMap;function Be(){n.useInsertionEffect(()=>{if(typeof document>"u")return;const e=document;let t=ne.get(e);if(!t){let r=e.getElementById(he);const a=!r;r||(r=e.createElement("style"),r.id=he,r.setAttribute("data-react-modal-navigation",""),r.textContent=Fe,e.head.appendChild(r)),t={element:r,owned:a,count:0},ne.set(e,t)}return t.count+=1,()=>{t.count-=1,t.count===0&&(t.owned&&t.element.remove(),ne.delete(e))}},[])}const Pe={placement:"right",showHeader:!0,showBackButton:!0,showCloseButton:!0,viewportGap:5,borderRadius:12,closeOnOverlay:!1,closeOnEsc:!0},Oe=e=>({"modal.loading":"加载中...","modal.processing":"处理中...","modal.back":"返回","modal.close":"关闭","modal.cancel":"取消","modal.done":"完成"})[e]??e;function $e({registry:e,children:t,defaultOptions:r={},backgroundColor:a,theme:s,translate:y=Oe,onError:h}){Be();const[m,g]=n.useState(null),[M,l]=n.useState(null),u=n.useRef(null),f=n.useRef(new Map),x=n.useRef(0),N=n.useRef(null),O=n.useRef(!1),P=n.useRef(0),v=n.useRef(null),T=n.useRef(!0),R=n.useRef(null),q=n.useRef(h);q.current=h;const k=n.useCallback((d,C)=>{T.current&&l(d);try{q.current?q.current(d,C):console.error("[react-modal-navigation]",d)}catch(L){console.error("[react-modal-navigation] onError failed",L)}},[]),A=n.useCallback((d,C)=>{const L=f.current.get(d);f.current.delete(d),L?.(C)},[]),z=n.useCallback(d=>({...Pe,...r,...s!==void 0?{theme:s}:{},...a!==void 0?{backgroundColor:a}:{},...d.config.modalOptions,...d.overrides}),[r,s,a]),j=m?z(m):null,b=n.useRef(null);b.current=j,R.current=j;const E=n.useCallback(async(d="api",C,L={})=>{const F=u.current;if(!F||N.current||O.current)return!1;N.current=F.id,O.current=!0;const D=R.current??z(F),G={...L,reason:d,result:C,name:F.name};try{if(await D.onBeforeClose?.(G)===!1||u.current?.id!==F.id||!T.current)return!1;u.current=null,v.current=null,g(null),A(F.id,C===void 0?{status:"dismissed",reason:d}:{status:"confirmed",value:C,reason:d});try{await D.onClose?.(G)}catch(I){k(I,{phase:"onClose",name:F.name})}return!0}catch(I){return k(I,{phase:"onBeforeClose",name:F.name}),!1}finally{N.current===F.id&&(N.current=null),O.current=!1}},[z,k,A]),H=n.useCallback(async(d,C={},L={},F)=>{const D=e?.[d];if(!D)throw new Error(`[react-modal-navigation] Unknown modal: ${d}`);if(!D.screens?.[D.initialRoute])throw new Error(`[react-modal-navigation] Missing initial screen '${D.initialRoute}' in '${d}'`);if(!T.current||O.current||N.current)return null;O.current=!0;const G=P.current;try{const I=u.current;if(I){const J=R.current??z(I),_={reason:"replace",name:I.name,nextName:d};try{if(await J.onBeforeClose?.(_)===!1)return null}catch(W){return k(W,{phase:"onBeforeClose",name:I.name}),null}if(!T.current||G!==P.current||u.current?.id!==I.id)return null;u.current=null,v.current=null,g(null),A(I.id,{status:"replaced",reason:"replace"});try{await J.onClose?.(_)}catch(W){k(W,{phase:"onClose",name:I.name})}if(!T.current||G!==P.current)return null}const U={id:++x.current,name:d,params:C,config:D,overrides:L};return u.current=U,v.current=null,F&&f.current.set(U.id,F),l(null),g(U),U.id}finally{O.current=!1}},[e,z,k,A]),w=n.useCallback((d,C,L)=>H(d,C,L),[H]),S=n.useCallback((d,C,L)=>new Promise((F,D)=>{H(d,C,L,F).then(G=>{G===null&&F({status:"dismissed",reason:"blocked"})},D)}),[H]),B=n.useCallback(d=>E("api",d),[E]),$=n.useCallback((d,C)=>v.current?.setLoading(d,C),[]),K=n.useMemo(()=>({open:w,openAsync:S,close:B,setLoading:$,isOpen:!!m,activeName:m?.name??null,error:M,clearError:()=>l(null)}),[w,S,B,$,m,M]);return n.useEffect(()=>(T.current=!0,()=>{T.current=!1,P.current+=1,u.current=null;for(const d of f.current.values())d({status:"dismissed",reason:"unmount"});f.current.clear()}),[]),c.jsxs(ge.Provider,{value:K,children:[t,m&&c.jsx(xe,{config:m.config,params:m.params,options:j,translate:y,notifyError:k,error:M,clearError:()=>l(null),registerLoading:d=>{v.current=d},onRequestClose:E,onOpened:d=>{try{const C=b.current?.onOpen?.(d);Promise.resolve(C).catch(L=>k(L,{phase:"onOpen"}))}catch(C){k(C,{phase:"onOpen"})}}},m.id)]})}function qe(){const e=n.useContext(ge),t=n.useContext(oe);if(!e)throw new Error("[react-modal-navigation] useModal requires <ModalProvider>");return n.useMemo(()=>{const r=()=>{if(!t)throw new Error("[react-modal-navigation] navigation requires an active modal screen; use modal.open() outside a modal");return t};return{...e,modal:e,navigation:{navigate:(...s)=>r().navigate(...s),replace:(...s)=>r().replace(...s),reset:(...s)=>r().reset(...s),setParams:(...s)=>r().setParams(...s),goBack:(...s)=>r().goBack(...s),close:(...s)=>r().close(...s),get canGoBack(){return t?.canGoBack??!1},get stack(){return t?.stack??[]},get currentRoute(){return t?.currentRoute??null}}}},[e,t])}function Ae(){const e=n.useContext(oe);if(!e)throw new Error("useModalNavigation requires an active modal screen");return e}function se(){const e=n.useContext(ee);if(!e)throw new Error("useIsFocused must be called inside a modal screen");return e.isFocused}function De(e){const t=se();n.useEffect(()=>{if(t)return e()},[t,e])}function Ie(e){const t=n.useContext(ee);if(!t)throw new Error("useNavigationResult requires an active modal screen");const r=n.useRef(e),a=n.useRef(null);n.useEffect(()=>{r.current=e},[e]),n.useEffect(()=>{!t.isFocused||!t.resultEvent||a.current!==t.resultEvent.id&&(a.current=t.resultEvent.id,r.current(t.resultEvent.data))},[t.isFocused,t.resultEvent])}function He(e={}){const t=n.useContext(ee);if(!t)throw new Error("[react-modal-navigation] useModalFooter requires an active modal screen");const{setFooter:r,routeKey:a}=t,s=n.useRef(e);s.current=e;const y=n.useMemo(()=>(...R)=>s.current.done?.(...R),[]),h=n.useMemo(()=>(...R)=>(s.current.cancel??s.current.cancle)?.(...R),[]),m=n.useMemo(()=>(...R)=>s.current.renderFooter?.(...R),[]),g=typeof e.done=="function",M=typeof(e.cancel??e.cancle)=="function",l=typeof e.renderFooter=="function",{showFooter:u,showFooterBorder:f,doneDisabled:x,doneText:N,cancelText:O,loadingText:P,footerClassName:v}=e,T=n.useMemo(()=>({showFooter:u,showFooterBorder:f,doneDisabled:x,doneText:N,cancelText:O,loadingText:P,footerClassName:v,...g?{done:y}:{},...M?{cancel:h}:{},...l?{renderFooter:m}:{}}),[u,f,x,N,O,P,v,g,M,l,y,h,m]);n.useEffect(()=>{r(a,T)},[a,r,T]),n.useEffect(()=>()=>r(a,null),[a,r])}function ve(){const e=n.useContext(ae);if(!e)throw new Error("[react-modal-navigation] useModalLoading requires an active modal screen");return e}function Ke(){const e=ve(),t=se(),r=n.useRef(!0),a=n.useRef(!1),[s,y]=n.useState(!1),[h,m]=n.useState(null),g=n.useRef(e);return g.current=e,n.useEffect(()=>(r.current=!0,()=>{r.current=!1}),[]),{run:n.useCallback(async(l,u={})=>{if(a.current)return{status:"busy"};if(typeof l!="function")throw new TypeError("[react-modal-navigation] run requires a function");a.current=!0,r.current&&(y(!0),m(null));const f=g.current.showLoading(u.loadingText);try{const x=await l();return r.current&&await u.onSuccess?.(x),{status:"success",value:x}}catch(x){if(r.current){m(x);try{await u.onError?.(x)}catch(N){console.error("[react-modal-navigation] onError failed",N)}}if(u.throwOnError)throw x;return{status:"error",error:x}}finally{f!=null&&g.current.hideLoading(f),a.current=!1,r.current&&y(!1)}},[]),pending:s,error:h,clearError:()=>m(null),isFocused:t}}exports.ModalNavigator=xe;exports.ModalProvider=$e;exports.useFocusEffect=De;exports.useIsFocused=se;exports.useModal=qe;exports.useModalFooter=He;exports.useModalLoading=ve;exports.useModalNavigation=Ae;exports.useModalTask=Ke;exports.useNavigationResult=Ie;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react/jsx-runtime"),n=require("react"),we=require("react-dom"),be=n.createContext(null),oe=n.createContext(null),ee=n.createContext(null),ae=n.createContext(null);let ke=0;const re=(e,t)=>({key:`modal-route-${++ke}`,name:e,params:t??{}}),xe=(e,t)=>[re(e,t)];function Ee(e,t){switch(t.type){case"RESET":return xe(t.name,t.params);case"NAVIGATE":{const r=e.findIndex(a=>a.name===t.name);return r<0?[...e,re(t.name,t.params)]:e.slice(0,r+1).map((a,s)=>s===r?{...a,params:t.params??{}}:a)}case"SET_PARAMS":return e.map((r,a)=>a===e.length-1?{...r,params:{...r.params??{},...t.params??{}}}:r);case"BACK":return e.length>1?e.slice(0,-1):e;case"REPLACE":return e.length?[...e.slice(0,-1),re(t.name,t.params)]:e;default:return e}}const fe=()=>{if(typeof document>"u")return"light";const e=document.documentElement,t=document.body;return e.classList.contains("dark")||t.classList.contains("dark")||e.dataset.theme==="dark"||t.dataset.theme==="dark"?"dark":e.classList.contains("light")||t.classList.contains("light")||e.dataset.theme==="light"||t.dataset.theme==="light"?"light":window.matchMedia?.("(prefers-color-scheme: dark)").matches?"dark":"light"};let X=0;const Y=[];let te=null;function Ce(){if(X++,X===1){const t=document.documentElement,r=document.body,a={html:t.style.overflow,body:r.style.overflow,padding:r.style.paddingRight,width:r.style.getPropertyValue("--modal-scrollbar-width")},s=Math.max(0,window.innerWidth-t.clientWidth),h=parseFloat(getComputedStyle(r).paddingRight)||0;s&&(r.style.paddingRight=`${h+s}px`),r.style.setProperty("--modal-scrollbar-width",`${s}px`),t.style.overflow="hidden",r.style.overflow="hidden",te=()=>{t.style.overflow=a.html,r.style.overflow=a.body,r.style.paddingRight=a.padding,a.width?r.style.setProperty("--modal-scrollbar-width",a.width):r.style.removeProperty("--modal-scrollbar-width")}}let e=!1;return()=>{e||(e=!0,X=Math.max(0,X-1),X||(te?.(),te=null))}}const Re='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";function Me({dialogRef:e,options:t,requestClose:r,children:a}){const s=n.useRef(null),h=n.useRef(null),g=n.useRef(r);g.current=r;const m=n.useRef(t.closeOnEsc);m.current=t.closeOnEsc;const[b,M]=n.useState(fe),l=t.theme==="light"||t.theme==="dark"?t.theme:b;n.useEffect(()=>{if(t.theme==="light"||t.theme==="dark")return;const S=()=>M(fe()),x=new MutationObserver(S);for(const H of[document.documentElement,document.body])x.observe(H,{attributes:!0,attributeFilter:["class","data-theme"]});const R=window.matchMedia?.("(prefers-color-scheme: dark)");return R?.addEventListener?.("change",S),S(),()=>{x.disconnect(),R?.removeEventListener?.("change",S)}},[t.theme]),n.useEffect(()=>{h.current=document.activeElement;const S=Ce(),x=s.current;Y.push(x),e.current?.focus({preventScroll:!0});const R=k=>{const L=e.current;if(!L||Y.at(-1)!==x)return;if(k.key==="Escape"&&m.current!==!1){k.preventDefault(),g.current("escape");return}if(k.key!=="Tab")return;const B=[...L.querySelectorAll(Re)].filter(je);if(!B.length){k.preventDefault(),L.focus();return}const O=B[0],K=B.at(-1);L.contains(document.activeElement)?k.shiftKey&&(document.activeElement===O||document.activeElement===L)?(k.preventDefault(),K.focus()):!k.shiftKey&&(document.activeElement===K||document.activeElement===L)&&(k.preventDefault(),O.focus()):(k.preventDefault(),(k.shiftKey?K:O).focus())},H=k=>{Y.at(-1)===x&&e.current&&!e.current.contains(k.target)&&e.current.focus({preventScroll:!0})};return document.addEventListener("keydown",R),document.addEventListener("focusin",H),()=>{document.removeEventListener("keydown",R),document.removeEventListener("focusin",H);const k=Y.at(-1)===x,L=Y.indexOf(x);if(L!==-1&&Y.splice(L,1),S(),k){const B=h.current;B?.isConnected&&!B.closest("[inert], [hidden]")?B.focus?.({preventScroll:!0}):Y.at(-1)?.querySelector("[role=dialog]")?.focus?.({preventScroll:!0})}}},[e]);const u=t.backgroundColor??t.backgroudColor,f=typeof u=="string"?u:u?.[l],y=typeof f=="string"&&/^(#|rgb\(|rgba\(|hsl\(|hsla\(|oklch\(|color\(|var\()/.test(f.trim())?f:null,T={sm:400,md:560,lg:720,xl:960,full:"100%"},A=["center","left","right","top","bottom"].includes(t.placement)?t.placement:"right",P=S=>typeof S=="number"?`${S}px`:S,v=P(t.width??T[t.size]??460),F=P(t.height),j=P(t.maxHeight),q=P(t.maxWidth),w=Number(t.viewportGap??5),I=Number.isFinite(w)?Math.max(0,w):5,G=typeof t.borderRadius=="number"?`${t.borderRadius}px`:t.borderRadius??"12px";return we.createPortal(c.jsx("div",{ref:s,className:`pmn-overlay pmn-place-${A} ${t.mobileFullscreen?"pmn-mobile-fullscreen":""}`,style:{padding:I},onMouseDown:S=>{S.target===S.currentTarget&&t.closeOnOverlay===!0&&g.current("overlay")},children:c.jsx("section",{ref:e,tabIndex:-1,role:"dialog","aria-modal":"true","aria-label":t.ariaLabel??"Dialog","data-modal-theme":l,className:`pmn-dialog ${l==="dark"?"dark":""} ${!y&&f?f:""} ${t.className??""}`,style:{"--pmn-width":v,"--pmn-gap":`${I}px`,...F!==void 0?{"--pmn-height":F}:{},...j!==void 0?{"--pmn-max-height":j}:{},...q!==void 0?{"--pmn-max-width":q}:{},borderRadius:G,...y?{backgroundColor:y}:{}},children:a})}),document.body)}function pe({back:e}){return c.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",width:"20",height:"20",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e?c.jsx("path",{d:"m15 18-6-6 6-6"}):c.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})}function Se({options:e,screen:t,route:r,navigation:a,requestClose:s,translate:h}){if(e.showHeader===!1)return null;const g=h??(f=>f),m=t.showTitle??e.showTitle??!0,b=typeof t.title=="function"?t.title({t:g,route:r,navigation:a}):t.title??r.name,M={route:r,navigation:a,close:s,canGoBack:a.canGoBack,title:b,t:g},l=t.renderHeader??e.renderHeader;if(l)return l(M);const u=t.renderHeaderRight??e.renderHeaderRight;return c.jsxs("header",{className:`pmn-header ${t.showHeaderBorder??e.showHeaderBorder?"pmn-border-bottom":""} ${e.headerClassName??""}`,children:[e.showBackButton!==!1&&a.canGoBack&&c.jsx("button",{type:"button",className:"pmn-icon-button","aria-label":g("modal.back"),onClick:()=>a.goBack(),children:c.jsx(pe,{back:!0})}),m?c.jsx("h2",{children:b}):c.jsx("div",{className:"pmn-header-spacer"}),u?.(M),e.showCloseButton!==!1&&c.jsx("button",{type:"button",className:"pmn-icon-button","aria-label":g("modal.close"),onClick:()=>s("header"),children:c.jsx(pe,{})})]})}function Le({screen:e,options:t,override:r,route:a,navigation:s,requestClose:h,translate:g,onError:m}){const[b,M]=n.useState(!1),l=g??(w=>w),u={...t,...e,...r},{showFooter:f,renderFooter:y,done:T,cancel:A,cancle:P}=u,v=A??P,F={route:a,navigation:s,close:h,t:l};if(f===!1)return null;const j=`pmn-footer ${u.showFooterBorder?"pmn-border-top":""} ${u.footerClassName??""}`;if(typeof y=="function")return c.jsx("footer",{className:j,children:y({...F,pending:b})});if(typeof T!="function"&&typeof v!="function")return null;const q=async w=>{if(!(b||typeof w!="function")){M(!0);try{await w(F)}catch(I){m?.(I,{phase:"footer",route:a})}finally{M(!1)}}};return c.jsxs("footer",{className:j,children:[typeof v=="function"&&c.jsx("button",{type:"button",disabled:b,onClick:()=>q(v),className:"pmn-button pmn-button-secondary",children:u.cancelText??l("modal.cancel")}),typeof T=="function"&&c.jsx("button",{type:"button",disabled:b||u.doneDisabled===!0,onClick:()=>q(T),className:"pmn-button pmn-button-primary",children:b?u.loadingText??l("modal.processing"):u.doneText??l("modal.done")})]})}function Ne({loading:e,translate:t}){if(!e.visible)return null;const a=(t??(h=>h))("modal.loading"),s=e.text??(a==="modal.loading"?"加载中...":a);return c.jsx("div",{className:"pmn-loading-overlay",role:"status","aria-live":"polite","aria-busy":"true",children:c.jsxs("div",{className:"pmn-loading-card",children:[c.jsx("span",{className:"pmn-spinner","aria-hidden":"true"}),c.jsx("span",{children:s})]})})}class Te extends n.Component{state={error:null};static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t,r){this.props.onError?.(t,{phase:"render",route:this.props.route,componentStack:r.componentStack})}componentDidUpdate(t){t.route?.key!==this.props.route?.key&&this.state.error&&this.setState({error:null})}render(){return this.state.error?c.jsxs("div",{role:"alert",className:"pmn-error-screen",children:[c.jsx("strong",{children:"页面加载失败"}),c.jsx("p",{children:this.state.error.message}),c.jsx("button",{type:"button",className:"pmn-button pmn-button-secondary",onClick:()=>this.setState({error:null}),children:"重试"})]}):this.props.children}}function Fe({route:e,screen:t,navigation:r,focused:a,resultEvent:s,setFooter:h,loadingApi:g,bodyClassName:m,notifyError:b}){const M=t.component,l=n.useMemo(()=>({isFocused:a,resultEvent:s,routeKey:e.key,setFooter:h}),[a,s,e.key,h]),u=n.useMemo(()=>({isLoading:a&&g.isLoading,setLoading:(f,y)=>g.setScreenLoading(e.key,f,y),showLoading:f=>g.begin(e.key,f),hideLoading:f=>g.end(e.key,f)}),[a,g,e.key]);return c.jsx(ee.Provider,{value:l,children:c.jsx(ae.Provider,{value:u,children:c.jsx("div",{hidden:!a,inert:!a,"data-modal-route-key":e.key,tabIndex:-1,className:`pmn-body ${m??""}`,children:c.jsx(Te,{route:e,onError:b,children:c.jsx(M,{route:e,navigation:r})})})})})}function ye({config:e,params:t,options:r,translate:a,onRequestClose:s,onOpened:h,registerLoading:g,notifyError:m,error:b,clearError:M}){const[l,u]=n.useReducer(Ee,null,()=>xe(e.initialRoute,t)),[f,y]=n.useState({}),[T,A]=n.useState({}),[,P]=n.useState(0),v=n.useRef(new Map),F=n.useRef(0),j=n.useRef(new Map),q=n.useRef(null),w=n.useRef(null),I=n.useRef(!1),G=n.useRef(!1),S=n.useRef(0),x=l.at(-1),R=x.key,H=n.useRef(R);H.current=R;const k=e.screens,L=n.useCallback(()=>P(o=>o+1),[]),B=n.useCallback((o,i)=>{if(o!=="global"&&H.current!==o)return null;const p=++F.current;return v.current.set(p,{owner:o,text:i}),L(),p},[L]),O=n.useCallback((o,i)=>{if(i!=null)v.current.get(i)?.owner===o&&v.current.delete(i);else for(const[p,V]of v.current)V.owner===o&&v.current.delete(p);L()},[L]),K=n.useCallback((o,i)=>{o?(O("global"),B("global",i)):O("global")},[B,O]),d=n.useCallback((o,i,p)=>{i?(O(o),B(o,p)):O(o)},[B,O]),E=[...v.current.values()],N={visible:E.length>0,text:E.at(-1)?.text??null,count:E.length},C=n.useRef(N);C.current=N;const D=n.useMemo(()=>({isLoading:N.visible,setLoading:K,setScreenLoading:d,begin:B,end:O}),[N.visible,K,d,B,O]),z=n.useRef(g);z.current=g,n.useEffect(()=>(z.current?.({setLoading:K}),()=>z.current?.(null)),[K]);const $=n.useCallback((o,i)=>A(p=>{if(i===null){if(!(o in p))return p;const V={...p};return delete V[o],V}return p[o]===i?p:{...p,[o]:i}}),[]),U=n.useCallback(()=>{const o=document.activeElement;if(!(o instanceof HTMLElement)||!q.current?.contains(o))return;const i=o.closest("[data-modal-route-key]");i&&j.current.set(i.dataset.modalRouteKey,o),q.current.focus({preventScroll:!0})},[]),J=n.useCallback(o=>{if(!Object.prototype.hasOwnProperty.call(k,o))throw new Error(`[react-modal-navigation] Unknown modal screen: ${o}`)},[k]),_=n.useCallback((o,i)=>{try{Promise.resolve(r[o]?.(i)).catch(p=>m(p,{phase:o}))}catch(p){m(p,{phase:o})}},[r,m]),W=n.useCallback((o,i,p)=>{J(i),U(),u({type:o,name:i,params:p})},[J,U]),ce=n.useCallback((o,i)=>W("NAVIGATE",o,i),[W]),le=n.useCallback((o,i)=>W("REPLACE",o,i),[W]),ie=n.useCallback((o,i)=>{y({}),W("RESET",o,i)},[W]),ue=n.useCallback(o=>{if(!o||typeof o!="object"||Array.isArray(o))throw new TypeError("[react-modal-navigation] setParams expects an object");u({type:"SET_PARAMS",params:o})},[]),de=n.useCallback(o=>{if(l.length<=1||I.current)return!1;if(I.current=!0,o!==void 0){const i=l.at(-2);y(p=>({...p,[i.key]:{id:++S.current,data:o}}))}return U(),u({type:"BACK"}),!0},[l,U]),Q=n.useCallback((o,i)=>C.current.visible&&r.lockCloseWhileLoading!==!1?Promise.resolve(!1):s(o,i,{route:x,stack:l}),[r.lockCloseWhileLoading,s,x,l]),me=n.useCallback(o=>Q("api",o),[Q]),Z=n.useMemo(()=>({navigate:ce,replace:le,reset:ie,setParams:ue,goBack:de,close:me,setLoading:K,canGoBack:l.length>1,stack:l,currentRoute:x}),[ce,le,ie,ue,de,me,K,l,x]);return n.useLayoutEffect(()=>{I.current=!1;const o=[...q.current?.querySelectorAll("[data-modal-route-key]")??[]].find(V=>V.dataset.modalRouteKey===R);if(!o)return;const i=j.current.get(R);(i?.isConnected&&o.contains(i)&&!i.matches(":disabled")&&!i.closest("[inert], [hidden]")?i:o).focus({preventScroll:!0})},[R]),n.useEffect(()=>{let o=!1;for(const[p,V]of v.current)V.owner!=="global"&&V.owner!==R&&(v.current.delete(p),o=!0);o&&L();const i=new Set(l.map(p=>p.key));for(const p of j.current.keys())i.has(p)||j.current.delete(p)},[R,l,L]),n.useEffect(()=>{if(w.current?.key!==R){if(w.current){const o={from:w.current,to:x,stack:l};_("onBlur",{route:w.current,...o}),_("onNavigate",o),_("onRouteChange",o)}_("onFocus",{route:x,stack:l}),w.current=x}},[x,R,l,_]),n.useEffect(()=>()=>{v.current.clear(),j.current.clear()},[]),n.useEffect(()=>{G.current||(G.current=!0,h?.({route:x,stack:l}))},[]),c.jsx(oe.Provider,{value:Z,children:c.jsx(ae.Provider,{value:D,children:c.jsxs(Me,{dialogRef:q,options:r,requestClose:Q,children:[c.jsx(Se,{options:r,screen:k[x.name],route:x,navigation:Z,requestClose:Q,translate:a}),c.jsx("main",{className:"pmn-main",children:l.map(o=>c.jsx(Fe,{route:o,screen:k[o.name],navigation:Z,focused:o.key===R,resultEvent:f[o.key]??null,bodyClassName:r.bodyClassName,setFooter:$,loadingApi:D,notifyError:m},o.key))}),c.jsx(Le,{screen:k[x.name],options:r,override:T[R],route:x,navigation:Z,requestClose:Q,translate:a,onError:m},R),c.jsx(Ne,{loading:N,translate:a}),b&&c.jsxs("div",{className:"pmn-error",role:"alert",children:[c.jsx("span",{children:b.message||String(b)}),c.jsx("button",{type:"button",onClick:M,"aria-label":"Dismiss error",children:"×"})]})]})})})}const Be=".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}}",he="react-modal-navigation-styles",ne=new WeakMap;function Pe(){n.useInsertionEffect(()=>{if(typeof document>"u")return;const e=document;let t=ne.get(e);if(!t){let r=e.getElementById(he);const a=!r;r||(r=e.createElement("style"),r.id=he,r.setAttribute("data-react-modal-navigation",""),r.textContent=Be,e.head.appendChild(r)),t={element:r,owned:a,count:0},ne.set(e,t)}return t.count+=1,()=>{t.count-=1,t.count===0&&(t.owned&&t.element.remove(),ne.delete(e))}},[])}function ge(e,t,r){if(typeof e=="string"){if(!e.trim())throw new TypeError("[react-modal-navigation] modal name must not be empty");return{name:e,params:t??{},options:r??{}}}if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError("[react-modal-navigation] open expects a modal name or { name, params?, options? }");const{name:a,params:s={},options:h={}}=e;if(typeof a!="string"||!a.trim())throw new TypeError("[react-modal-navigation] open config requires a non-empty string name");if(h===null||typeof h!="object"||Array.isArray(h))throw new TypeError("[react-modal-navigation] open config options must be an object");return{name:a,params:s,options:h}}const Ae={placement:"right",showHeader:!0,showBackButton:!0,showCloseButton:!0,viewportGap:5,borderRadius:12,closeOnOverlay:!1,closeOnEsc:!0},Oe=e=>({"modal.loading":"加载中...","modal.processing":"处理中...","modal.back":"返回","modal.close":"关闭","modal.cancel":"取消","modal.done":"完成"})[e]??e;function $e({registry:e,children:t,defaultOptions:r={},backgroundColor:a,theme:s,translate:h=Oe,onError:g}){Pe();const[m,b]=n.useState(null),[M,l]=n.useState(null),u=n.useRef(null),f=n.useRef(new Map),y=n.useRef(0),T=n.useRef(null),A=n.useRef(!1),P=n.useRef(0),v=n.useRef(null),F=n.useRef(!0),j=n.useRef(null),q=n.useRef(g);q.current=g;const w=n.useCallback((d,E)=>{F.current&&l(d);try{q.current?q.current(d,E):console.error("[react-modal-navigation]",d)}catch(N){console.error("[react-modal-navigation] onError failed",N)}},[]),I=n.useCallback((d,E)=>{const N=f.current.get(d);f.current.delete(d),N?.(E)},[]),G=n.useCallback(d=>({...Ae,...r,...s!==void 0?{theme:s}:{},...a!==void 0?{backgroundColor:a}:{},...d.config.modalOptions,...d.overrides}),[r,s,a]),S=m?G(m):null,x=n.useRef(null);x.current=S,j.current=S;const R=n.useCallback(async(d="api",E,N={})=>{const C=u.current;if(!C||T.current||A.current)return!1;T.current=C.id,A.current=!0;const D=j.current??G(C),z={...N,reason:d,result:E,name:C.name};try{if(await D.onBeforeClose?.(z)===!1||u.current?.id!==C.id||!F.current)return!1;u.current=null,v.current=null,b(null),I(C.id,E===void 0?{status:"dismissed",reason:d}:{status:"confirmed",value:E,reason:d});try{await D.onClose?.(z)}catch($){w($,{phase:"onClose",name:C.name})}return!0}catch($){return w($,{phase:"onBeforeClose",name:C.name}),!1}finally{T.current===C.id&&(T.current=null),A.current=!1}},[G,w,I]),H=n.useCallback(async(d,E={},N={},C)=>{const D=e?.[d];if(!D)throw new Error(`[react-modal-navigation] Unknown modal: ${d}`);if(!D.screens?.[D.initialRoute])throw new Error(`[react-modal-navigation] Missing initial screen '${D.initialRoute}' in '${d}'`);if(!F.current||A.current||T.current)return null;A.current=!0;const z=P.current;try{const $=u.current;if($){const J=j.current??G($),_={reason:"replace",name:$.name,nextName:d};try{if(await J.onBeforeClose?.(_)===!1)return null}catch(W){return w(W,{phase:"onBeforeClose",name:$.name}),null}if(!F.current||z!==P.current||u.current?.id!==$.id)return null;u.current=null,v.current=null,b(null),I($.id,{status:"replaced",reason:"replace"});try{await J.onClose?.(_)}catch(W){w(W,{phase:"onClose",name:$.name})}if(!F.current||z!==P.current)return null}const U={id:++y.current,name:d,params:E,config:D,overrides:N};return u.current=U,v.current=null,C&&f.current.set(U.id,C),l(null),b(U),U.id}finally{A.current=!1}},[e,G,w,I]),k=n.useCallback((d,E,N)=>{const C=ge(d,E,N);return H(C.name,C.params,C.options)},[H]),L=n.useCallback((d,E,N)=>{const C=ge(d,E,N);return new Promise((D,z)=>{H(C.name,C.params,C.options,D).then($=>{$===null&&D({status:"dismissed",reason:"blocked"})},z)})},[H]),B=n.useCallback(d=>R("api",d),[R]),O=n.useCallback((d,E)=>v.current?.setLoading(d,E),[]),K=n.useMemo(()=>({open:k,openAsync:L,close:B,setLoading:O,isOpen:!!m,activeName:m?.name??null,error:M,clearError:()=>l(null)}),[k,L,B,O,m,M]);return n.useEffect(()=>(F.current=!0,()=>{F.current=!1,P.current+=1,u.current=null;for(const d of f.current.values())d({status:"dismissed",reason:"unmount"});f.current.clear()}),[]),c.jsxs(be.Provider,{value:K,children:[t,m&&c.jsx(ye,{config:m.config,params:m.params,options:S,translate:h,notifyError:w,error:M,clearError:()=>l(null),registerLoading:d=>{v.current=d},onRequestClose:R,onOpened:d=>{try{const E=x.current?.onOpen?.(d);Promise.resolve(E).catch(N=>w(N,{phase:"onOpen"}))}catch(E){w(E,{phase:"onOpen"})}}},m.id)]})}function qe(){const e=n.useContext(be),t=n.useContext(oe);if(!e)throw new Error("[react-modal-navigation] useModal requires <ModalProvider>");return n.useMemo(()=>{const r=()=>{if(!t)throw new Error("[react-modal-navigation] navigation requires an active modal screen; use modal.open() outside a modal");return t};return{...e,modal:e,navigation:{navigate:(...s)=>r().navigate(...s),replace:(...s)=>r().replace(...s),reset:(...s)=>r().reset(...s),setParams:(...s)=>r().setParams(...s),goBack:(...s)=>r().goBack(...s),close:(...s)=>r().close(...s),get canGoBack(){return t?.canGoBack??!1},get stack(){return t?.stack??[]},get currentRoute(){return t?.currentRoute??null}}}},[e,t])}function De(){const e=n.useContext(oe);if(!e)throw new Error("useModalNavigation requires an active modal screen");return e}function se(){const e=n.useContext(ee);if(!e)throw new Error("useIsFocused must be called inside a modal screen");return e.isFocused}function Ie(e){const t=se();n.useEffect(()=>{if(t)return e()},[t,e])}function He(e){const t=n.useContext(ee);if(!t)throw new Error("useNavigationResult requires an active modal screen");const r=n.useRef(e),a=n.useRef(null);n.useEffect(()=>{r.current=e},[e]),n.useEffect(()=>{!t.isFocused||!t.resultEvent||a.current!==t.resultEvent.id&&(a.current=t.resultEvent.id,r.current(t.resultEvent.data))},[t.isFocused,t.resultEvent])}function Ke(e={}){const t=n.useContext(ee);if(!t)throw new Error("[react-modal-navigation] useModalFooter requires an active modal screen");const{setFooter:r,routeKey:a}=t,s=n.useRef(e);s.current=e;const h=n.useMemo(()=>(...j)=>s.current.done?.(...j),[]),g=n.useMemo(()=>(...j)=>(s.current.cancel??s.current.cancle)?.(...j),[]),m=n.useMemo(()=>(...j)=>s.current.renderFooter?.(...j),[]),b=typeof e.done=="function",M=typeof(e.cancel??e.cancle)=="function",l=typeof e.renderFooter=="function",{showFooter:u,showFooterBorder:f,doneDisabled:y,doneText:T,cancelText:A,loadingText:P,footerClassName:v}=e,F=n.useMemo(()=>({showFooter:u,showFooterBorder:f,doneDisabled:y,doneText:T,cancelText:A,loadingText:P,footerClassName:v,...b?{done:h}:{},...M?{cancel:g}:{},...l?{renderFooter:m}:{}}),[u,f,y,T,A,P,v,b,M,l,h,g,m]);n.useEffect(()=>{r(a,F)},[a,r,F]),n.useEffect(()=>()=>r(a,null),[a,r])}function ve(){const e=n.useContext(ae);if(!e)throw new Error("[react-modal-navigation] useModalLoading requires an active modal screen");return e}function ze(){const e=ve(),t=se(),r=n.useRef(!0),a=n.useRef(!1),[s,h]=n.useState(!1),[g,m]=n.useState(null),b=n.useRef(e);return b.current=e,n.useEffect(()=>(r.current=!0,()=>{r.current=!1}),[]),{run:n.useCallback(async(l,u={})=>{if(a.current)return{status:"busy"};if(typeof l!="function")throw new TypeError("[react-modal-navigation] run requires a function");a.current=!0,r.current&&(h(!0),m(null));const f=b.current.showLoading(u.loadingText);try{const y=await l();return r.current&&await u.onSuccess?.(y),{status:"success",value:y}}catch(y){if(r.current){m(y);try{await u.onError?.(y)}catch(T){console.error("[react-modal-navigation] onError failed",T)}}if(u.throwOnError)throw y;return{status:"error",error:y}}finally{f!=null&&b.current.hideLoading(f),a.current=!1,r.current&&h(!1)}},[]),pending:s,error:g,clearError:()=>m(null),isFocused:t}}exports.ModalNavigator=ye;exports.ModalProvider=$e;exports.useFocusEffect=Ie;exports.useIsFocused=se;exports.useModal=qe;exports.useModalFooter=Ke;exports.useModalLoading=ve;exports.useModalNavigation=De;exports.useModalTask=ze;exports.useNavigationResult=He;
package/dist/index.d.ts CHANGED
@@ -87,9 +87,19 @@ export interface ModalProviderProps {
87
87
  translate?: (key: string) => string;
88
88
  onError?: (error: unknown, context: { phase: string; [key: string]: unknown }) => void;
89
89
  }
90
+ /** Named-object form for opening a modal without positional placeholders. */
91
+ export interface ModalOpenConfig<P = unknown> {
92
+ name: string;
93
+ params?: P;
94
+ options?: ModalOptions;
95
+ }
90
96
  export interface ModalActions {
97
+ /** Legacy positional call; preserved for backwards compatibility. */
91
98
  open(name: string, params?: unknown, overrides?: ModalOptions): Promise<number | null>;
99
+ /** Recommended object call. */
100
+ open(config: ModalOpenConfig): Promise<number | null>;
92
101
  openAsync<T = unknown>(name: string, params?: unknown, overrides?: ModalOptions): Promise<ModalResult<T>>;
102
+ openAsync<T = unknown>(config: ModalOpenConfig): Promise<ModalResult<T>>;
93
103
  close(result?: unknown): Promise<boolean>;
94
104
  setLoading(value: boolean, text?: string): void;
95
105
  readonly isOpen: boolean;
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { jsx as d, jsxs as ee } from "react/jsx-runtime";
2
- import Re, { createContext as ce, useRef as u, useState as Q, useEffect as I, useReducer as Se, useCallback as b, useMemo as _, useLayoutEffect as Le, useInsertionEffect as Me, useContext as te } from "react";
3
- import { createPortal as Ne } from "react-dom";
4
- const ke = ce(null), ue = ce(null), se = ce(null), me = ce(null);
2
+ import Se, { createContext as ce, useRef as u, useState as Q, useEffect as I, useReducer as Le, useCallback as y, useMemo as _, useLayoutEffect as Me, useInsertionEffect as Ne, useContext as te } from "react";
3
+ import { createPortal as Te } from "react-dom";
4
+ const Ee = ce(null), ue = ce(null), se = ce(null), me = ce(null);
5
5
  let Be = 0;
6
- const de = (e, t) => ({ key: `modal-route-${++Be}`, name: e, params: t ?? {} }), Ee = (e, t) => [de(e, t)];
7
- function Te(e, t) {
6
+ const de = (e, t) => ({ key: `modal-route-${++Be}`, name: e, params: t ?? {} }), Re = (e, t) => [de(e, t)];
7
+ function Fe(e, t) {
8
8
  switch (t.type) {
9
9
  case "RESET":
10
- return Ee(t.name, t.params);
10
+ return Re(t.name, t.params);
11
11
  case "NAVIGATE": {
12
12
  const n = e.findIndex((o) => o.name === t.name);
13
13
  return n < 0 ? [...e, de(t.name, t.params)] : e.slice(0, n + 1).map((o, a) => a === n ? { ...o, params: t.params ?? {} } : o);
@@ -22,81 +22,81 @@ function Te(e, t) {
22
22
  return e;
23
23
  }
24
24
  }
25
- const ye = () => {
25
+ const ve = () => {
26
26
  if (typeof document > "u") return "light";
27
27
  const e = document.documentElement, t = document.body;
28
28
  return e.classList.contains("dark") || t.classList.contains("dark") || e.dataset.theme === "dark" || t.dataset.theme === "dark" ? "dark" : e.classList.contains("light") || t.classList.contains("light") || e.dataset.theme === "light" || t.dataset.theme === "light" ? "light" : window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
29
29
  };
30
30
  let oe = 0;
31
31
  const Z = [];
32
- let le = null;
33
- function Fe() {
32
+ let ie = null;
33
+ function Pe() {
34
34
  if (oe++, oe === 1) {
35
- const t = document.documentElement, n = document.body, o = { html: t.style.overflow, body: n.style.overflow, padding: n.style.paddingRight, width: n.style.getPropertyValue("--modal-scrollbar-width") }, a = Math.max(0, window.innerWidth - t.clientWidth), w = parseFloat(getComputedStyle(n).paddingRight) || 0;
36
- a && (n.style.paddingRight = `${w + a}px`), n.style.setProperty("--modal-scrollbar-width", `${a}px`), t.style.overflow = "hidden", n.style.overflow = "hidden", le = () => {
35
+ const t = document.documentElement, n = document.body, o = { html: t.style.overflow, body: n.style.overflow, padding: n.style.paddingRight, width: n.style.getPropertyValue("--modal-scrollbar-width") }, a = Math.max(0, window.innerWidth - t.clientWidth), h = parseFloat(getComputedStyle(n).paddingRight) || 0;
36
+ a && (n.style.paddingRight = `${h + a}px`), n.style.setProperty("--modal-scrollbar-width", `${a}px`), t.style.overflow = "hidden", n.style.overflow = "hidden", ie = () => {
37
37
  t.style.overflow = o.html, n.style.overflow = o.body, n.style.paddingRight = o.padding, o.width ? n.style.setProperty("--modal-scrollbar-width", o.width) : n.style.removeProperty("--modal-scrollbar-width");
38
38
  };
39
39
  }
40
40
  let e = !1;
41
41
  return () => {
42
- e || (e = !0, oe = Math.max(0, oe - 1), oe || (le?.(), le = null));
42
+ e || (e = !0, oe = Math.max(0, oe - 1), oe || (ie?.(), ie = null));
43
43
  };
44
44
  }
45
- const Pe = 'a[href],button:not([disabled]),input:not([disabled]),textarea:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])', Oe = (e) => !e.closest('[inert], [hidden], [aria-hidden="true"]') && e.getClientRects().length > 0 && getComputedStyle(e).visibility !== "hidden" && getComputedStyle(e).display !== "none";
45
+ const Ae = 'a[href],button:not([disabled]),input:not([disabled]),textarea:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])', Oe = (e) => !e.closest('[inert], [hidden], [aria-hidden="true"]') && e.getClientRects().length > 0 && getComputedStyle(e).visibility !== "hidden" && getComputedStyle(e).display !== "none";
46
46
  function $e({ dialogRef: e, options: t, requestClose: n, children: o }) {
47
- const a = u(null), w = u(null), h = u(n);
48
- h.current = n;
47
+ const a = u(null), h = u(null), g = u(n);
48
+ g.current = n;
49
49
  const m = u(t.closeOnEsc);
50
50
  m.current = t.closeOnEsc;
51
- const [g, L] = Q(ye), c = t.theme === "light" || t.theme === "dark" ? t.theme : g;
51
+ const [b, M] = Q(ve), c = t.theme === "light" || t.theme === "dark" ? t.theme : b;
52
52
  I(() => {
53
53
  if (t.theme === "light" || t.theme === "dark") return;
54
- const M = () => L(ye()), v = new MutationObserver(M);
55
- for (const G of [document.documentElement, document.body]) v.observe(G, { attributes: !0, attributeFilter: ["class", "data-theme"] });
56
- const R = window.matchMedia?.("(prefers-color-scheme: dark)");
57
- return R?.addEventListener?.("change", M), M(), () => {
58
- v.disconnect(), R?.removeEventListener?.("change", M);
54
+ const N = () => M(ve()), v = new MutationObserver(N);
55
+ for (const z of [document.documentElement, document.body]) v.observe(z, { attributes: !0, attributeFilter: ["class", "data-theme"] });
56
+ const S = window.matchMedia?.("(prefers-color-scheme: dark)");
57
+ return S?.addEventListener?.("change", N), N(), () => {
58
+ v.disconnect(), S?.removeEventListener?.("change", N);
59
59
  };
60
60
  }, [t.theme]), I(() => {
61
- w.current = document.activeElement;
62
- const M = Fe(), v = a.current;
61
+ h.current = document.activeElement;
62
+ const N = Pe(), v = a.current;
63
63
  Z.push(v), e.current?.focus({ preventScroll: !0 });
64
- const R = (E) => {
65
- const N = e.current;
66
- if (!N || Z.at(-1) !== v) return;
64
+ const S = (E) => {
65
+ const T = e.current;
66
+ if (!T || Z.at(-1) !== v) return;
67
67
  if (E.key === "Escape" && m.current !== !1) {
68
- E.preventDefault(), h.current("escape");
68
+ E.preventDefault(), g.current("escape");
69
69
  return;
70
70
  }
71
71
  if (E.key !== "Tab") return;
72
- const O = [...N.querySelectorAll(Pe)].filter(Oe);
73
- if (!O.length) {
74
- E.preventDefault(), N.focus();
72
+ const A = [...T.querySelectorAll(Ae)].filter(Oe);
73
+ if (!A.length) {
74
+ E.preventDefault(), T.focus();
75
75
  return;
76
76
  }
77
- const D = O[0], z = O.at(-1);
78
- N.contains(document.activeElement) ? E.shiftKey && (document.activeElement === D || document.activeElement === N) ? (E.preventDefault(), z.focus()) : !E.shiftKey && (document.activeElement === z || document.activeElement === N) && (E.preventDefault(), D.focus()) : (E.preventDefault(), (E.shiftKey ? z : D).focus());
79
- }, G = (E) => {
77
+ const j = A[0], G = A.at(-1);
78
+ T.contains(document.activeElement) ? E.shiftKey && (document.activeElement === j || document.activeElement === T) ? (E.preventDefault(), G.focus()) : !E.shiftKey && (document.activeElement === G || document.activeElement === T) && (E.preventDefault(), j.focus()) : (E.preventDefault(), (E.shiftKey ? G : j).focus());
79
+ }, z = (E) => {
80
80
  Z.at(-1) === v && e.current && !e.current.contains(E.target) && e.current.focus({ preventScroll: !0 });
81
81
  };
82
- return document.addEventListener("keydown", R), document.addEventListener("focusin", G), () => {
83
- document.removeEventListener("keydown", R), document.removeEventListener("focusin", G);
84
- const E = Z.at(-1) === v, N = Z.indexOf(v);
85
- if (N !== -1 && Z.splice(N, 1), M(), E) {
86
- const O = w.current;
87
- O?.isConnected && !O.closest("[inert], [hidden]") ? O.focus?.({ preventScroll: !0 }) : Z.at(-1)?.querySelector("[role=dialog]")?.focus?.({ preventScroll: !0 });
82
+ return document.addEventListener("keydown", S), document.addEventListener("focusin", z), () => {
83
+ document.removeEventListener("keydown", S), document.removeEventListener("focusin", z);
84
+ const E = Z.at(-1) === v, T = Z.indexOf(v);
85
+ if (T !== -1 && Z.splice(T, 1), N(), E) {
86
+ const A = h.current;
87
+ A?.isConnected && !A.closest("[inert], [hidden]") ? A.focus?.({ preventScroll: !0 }) : Z.at(-1)?.querySelector("[role=dialog]")?.focus?.({ preventScroll: !0 });
88
88
  }
89
89
  };
90
90
  }, [e]);
91
- const l = t.backgroundColor ?? t.backgroudColor, p = typeof l == "string" ? l : l?.[c], y = typeof p == "string" && /^(#|rgb\(|rgba\(|hsl\(|hsla\(|oklch\(|color\(|var\()/.test(p.trim()) ? p : null, T = { sm: 400, md: 560, lg: 720, xl: 960, full: "100%" }, A = ["center", "left", "right", "top", "bottom"].includes(t.placement) ? t.placement : "right", $ = (M) => typeof M == "number" ? `${M}px` : M, x = $(t.width ?? T[t.size] ?? 460), F = $(t.height), S = $(t.maxHeight), H = $(t.maxWidth), k = Number(t.viewportGap ?? 5), q = Number.isFinite(k) ? Math.max(0, k) : 5, U = typeof t.borderRadius == "number" ? `${t.borderRadius}px` : t.borderRadius ?? "12px";
92
- return Ne(/* @__PURE__ */ d(
91
+ const i = t.backgroundColor ?? t.backgroudColor, p = typeof i == "string" ? i : i?.[c], x = typeof p == "string" && /^(#|rgb\(|rgba\(|hsl\(|hsla\(|oklch\(|color\(|var\()/.test(p.trim()) ? p : null, F = { sm: 400, md: 560, lg: 720, xl: 960, full: "100%" }, $ = ["center", "left", "right", "top", "bottom"].includes(t.placement) ? t.placement : "right", O = (N) => typeof N == "number" ? `${N}px` : N, w = O(t.width ?? F[t.size] ?? 460), P = O(t.height), L = O(t.maxHeight), q = O(t.maxWidth), k = Number(t.viewportGap ?? 5), K = Number.isFinite(k) ? Math.max(0, k) : 5, U = typeof t.borderRadius == "number" ? `${t.borderRadius}px` : t.borderRadius ?? "12px";
92
+ return Te(/* @__PURE__ */ d(
93
93
  "div",
94
94
  {
95
95
  ref: a,
96
- className: `pmn-overlay pmn-place-${A} ${t.mobileFullscreen ? "pmn-mobile-fullscreen" : ""}`,
97
- style: { padding: q },
98
- onMouseDown: (M) => {
99
- M.target === M.currentTarget && t.closeOnOverlay === !0 && h.current("overlay");
96
+ className: `pmn-overlay pmn-place-${$} ${t.mobileFullscreen ? "pmn-mobile-fullscreen" : ""}`,
97
+ style: { padding: K },
98
+ onMouseDown: (N) => {
99
+ N.target === N.currentTarget && t.closeOnOverlay === !0 && g.current("overlay");
100
100
  },
101
101
  children: /* @__PURE__ */ d(
102
102
  "section",
@@ -107,8 +107,8 @@ function $e({ dialogRef: e, options: t, requestClose: n, children: o }) {
107
107
  "aria-modal": "true",
108
108
  "aria-label": t.ariaLabel ?? "Dialog",
109
109
  "data-modal-theme": c,
110
- className: `pmn-dialog ${c === "dark" ? "dark" : ""} ${!y && p ? p : ""} ${t.className ?? ""}`,
111
- style: { "--pmn-width": x, "--pmn-gap": `${q}px`, ...F !== void 0 ? { "--pmn-height": F } : {}, ...S !== void 0 ? { "--pmn-max-height": S } : {}, ...H !== void 0 ? { "--pmn-max-width": H } : {}, borderRadius: U, ...y ? { backgroundColor: y } : {} },
110
+ className: `pmn-dialog ${c === "dark" ? "dark" : ""} ${!x && p ? p : ""} ${t.className ?? ""}`,
111
+ style: { "--pmn-width": w, "--pmn-gap": `${K}px`, ...P !== void 0 ? { "--pmn-height": P } : {}, ...L !== void 0 ? { "--pmn-max-height": L } : {}, ...q !== void 0 ? { "--pmn-max-width": q } : {}, borderRadius: U, ...x ? { backgroundColor: x } : {} },
112
112
  children: o
113
113
  }
114
114
  )
@@ -118,50 +118,50 @@ function $e({ dialogRef: e, options: t, requestClose: n, children: o }) {
118
118
  function xe({ back: e }) {
119
119
  return /* @__PURE__ */ d("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", width: "20", height: "20", fill: "none", stroke: "currentColor", strokeWidth: "2", children: e ? /* @__PURE__ */ d("path", { d: "m15 18-6-6 6-6" }) : /* @__PURE__ */ d("path", { d: "M18 6 6 18M6 6l12 12" }) });
120
120
  }
121
- function Ae({ options: e, screen: t, route: n, navigation: o, requestClose: a, translate: w }) {
121
+ function je({ options: e, screen: t, route: n, navigation: o, requestClose: a, translate: h }) {
122
122
  if (e.showHeader === !1) return null;
123
- const h = w ?? ((p) => p), m = t.showTitle ?? e.showTitle ?? !0, g = typeof t.title == "function" ? t.title({ t: h, route: n, navigation: o }) : t.title ?? n.name, L = { route: n, navigation: o, close: a, canGoBack: o.canGoBack, title: g, t: h }, c = t.renderHeader ?? e.renderHeader;
124
- if (c) return c(L);
125
- const l = t.renderHeaderRight ?? e.renderHeaderRight;
123
+ const g = h ?? ((p) => p), m = t.showTitle ?? e.showTitle ?? !0, b = typeof t.title == "function" ? t.title({ t: g, route: n, navigation: o }) : t.title ?? n.name, M = { route: n, navigation: o, close: a, canGoBack: o.canGoBack, title: b, t: g }, c = t.renderHeader ?? e.renderHeader;
124
+ if (c) return c(M);
125
+ const i = t.renderHeaderRight ?? e.renderHeaderRight;
126
126
  return /* @__PURE__ */ ee("header", { className: `pmn-header ${t.showHeaderBorder ?? e.showHeaderBorder ? "pmn-border-bottom" : ""} ${e.headerClassName ?? ""}`, children: [
127
- e.showBackButton !== !1 && o.canGoBack && /* @__PURE__ */ d("button", { type: "button", className: "pmn-icon-button", "aria-label": h("modal.back"), onClick: () => o.goBack(), children: /* @__PURE__ */ d(xe, { back: !0 }) }),
128
- m ? /* @__PURE__ */ d("h2", { children: g }) : /* @__PURE__ */ d("div", { className: "pmn-header-spacer" }),
129
- l?.(L),
130
- e.showCloseButton !== !1 && /* @__PURE__ */ d("button", { type: "button", className: "pmn-icon-button", "aria-label": h("modal.close"), onClick: () => a("header"), children: /* @__PURE__ */ d(xe, {}) })
127
+ e.showBackButton !== !1 && o.canGoBack && /* @__PURE__ */ d("button", { type: "button", className: "pmn-icon-button", "aria-label": g("modal.back"), onClick: () => o.goBack(), children: /* @__PURE__ */ d(xe, { back: !0 }) }),
128
+ m ? /* @__PURE__ */ d("h2", { children: b }) : /* @__PURE__ */ d("div", { className: "pmn-header-spacer" }),
129
+ i?.(M),
130
+ e.showCloseButton !== !1 && /* @__PURE__ */ d("button", { type: "button", className: "pmn-icon-button", "aria-label": g("modal.close"), onClick: () => a("header"), children: /* @__PURE__ */ d(xe, {}) })
131
131
  ] });
132
132
  }
133
- function De({ screen: e, options: t, override: n, route: o, navigation: a, requestClose: w, translate: h, onError: m }) {
134
- const [g, L] = Q(!1), c = h ?? ((k) => k), l = { ...t, ...e, ...n }, { showFooter: p, renderFooter: y, done: T, cancel: A, cancle: $ } = l, x = A ?? $, F = { route: o, navigation: a, close: w, t: c };
133
+ function De({ screen: e, options: t, override: n, route: o, navigation: a, requestClose: h, translate: g, onError: m }) {
134
+ const [b, M] = Q(!1), c = g ?? ((k) => k), i = { ...t, ...e, ...n }, { showFooter: p, renderFooter: x, done: F, cancel: $, cancle: O } = i, w = $ ?? O, P = { route: o, navigation: a, close: h, t: c };
135
135
  if (p === !1) return null;
136
- const S = `pmn-footer ${l.showFooterBorder ? "pmn-border-top" : ""} ${l.footerClassName ?? ""}`;
137
- if (typeof y == "function") return /* @__PURE__ */ d("footer", { className: S, children: y({ ...F, pending: g }) });
138
- if (typeof T != "function" && typeof x != "function") return null;
139
- const H = async (k) => {
140
- if (!(g || typeof k != "function")) {
141
- L(!0);
136
+ const L = `pmn-footer ${i.showFooterBorder ? "pmn-border-top" : ""} ${i.footerClassName ?? ""}`;
137
+ if (typeof x == "function") return /* @__PURE__ */ d("footer", { className: L, children: x({ ...P, pending: b }) });
138
+ if (typeof F != "function" && typeof w != "function") return null;
139
+ const q = async (k) => {
140
+ if (!(b || typeof k != "function")) {
141
+ M(!0);
142
142
  try {
143
- await k(F);
144
- } catch (q) {
145
- m?.(q, { phase: "footer", route: o });
143
+ await k(P);
144
+ } catch (K) {
145
+ m?.(K, { phase: "footer", route: o });
146
146
  } finally {
147
- L(!1);
147
+ M(!1);
148
148
  }
149
149
  }
150
150
  };
151
- return /* @__PURE__ */ ee("footer", { className: S, children: [
152
- typeof x == "function" && /* @__PURE__ */ d("button", { type: "button", disabled: g, onClick: () => H(x), className: "pmn-button pmn-button-secondary", children: l.cancelText ?? c("modal.cancel") }),
153
- typeof T == "function" && /* @__PURE__ */ d("button", { type: "button", disabled: g || l.doneDisabled === !0, onClick: () => H(T), className: "pmn-button pmn-button-primary", children: g ? l.loadingText ?? c("modal.processing") : l.doneText ?? c("modal.done") })
151
+ return /* @__PURE__ */ ee("footer", { className: L, children: [
152
+ typeof w == "function" && /* @__PURE__ */ d("button", { type: "button", disabled: b, onClick: () => q(w), className: "pmn-button pmn-button-secondary", children: i.cancelText ?? c("modal.cancel") }),
153
+ typeof F == "function" && /* @__PURE__ */ d("button", { type: "button", disabled: b || i.doneDisabled === !0, onClick: () => q(F), className: "pmn-button pmn-button-primary", children: b ? i.loadingText ?? c("modal.processing") : i.doneText ?? c("modal.done") })
154
154
  ] });
155
155
  }
156
- function He({ loading: e, translate: t }) {
156
+ function qe({ loading: e, translate: t }) {
157
157
  if (!e.visible) return null;
158
- const o = (t ?? ((w) => w))("modal.loading"), a = e.text ?? (o === "modal.loading" ? "加载中..." : o);
158
+ const o = (t ?? ((h) => h))("modal.loading"), a = e.text ?? (o === "modal.loading" ? "加载中..." : o);
159
159
  return /* @__PURE__ */ d("div", { className: "pmn-loading-overlay", role: "status", "aria-live": "polite", "aria-busy": "true", children: /* @__PURE__ */ ee("div", { className: "pmn-loading-card", children: [
160
160
  /* @__PURE__ */ d("span", { className: "pmn-spinner", "aria-hidden": "true" }),
161
161
  /* @__PURE__ */ d("span", { children: a })
162
162
  ] }) });
163
163
  }
164
- class Ie extends Re.Component {
164
+ class He extends Se.Component {
165
165
  state = { error: null };
166
166
  static getDerivedStateFromError(t) {
167
167
  return { error: t };
@@ -180,109 +180,109 @@ class Ie extends Re.Component {
180
180
  ] }) : this.props.children;
181
181
  }
182
182
  }
183
- function qe({ route: e, screen: t, navigation: n, focused: o, resultEvent: a, setFooter: w, loadingApi: h, bodyClassName: m, notifyError: g }) {
184
- const L = t.component, c = _(() => ({ isFocused: o, resultEvent: a, routeKey: e.key, setFooter: w }), [o, a, e.key, w]), l = _(() => ({
185
- isLoading: o && h.isLoading,
186
- setLoading: (p, y) => h.setScreenLoading(e.key, p, y),
187
- showLoading: (p) => h.begin(e.key, p),
188
- hideLoading: (p) => h.end(e.key, p)
189
- }), [o, h, e.key]);
190
- return /* @__PURE__ */ d(se.Provider, { value: c, children: /* @__PURE__ */ d(me.Provider, { value: l, children: /* @__PURE__ */ d("div", { hidden: !o, inert: !o, "data-modal-route-key": e.key, tabIndex: -1, className: `pmn-body ${m ?? ""}`, children: /* @__PURE__ */ d(Ie, { route: e, onError: g, children: /* @__PURE__ */ d(L, { route: e, navigation: n }) }) }) }) });
183
+ function Ie({ route: e, screen: t, navigation: n, focused: o, resultEvent: a, setFooter: h, loadingApi: g, bodyClassName: m, notifyError: b }) {
184
+ const M = t.component, c = _(() => ({ isFocused: o, resultEvent: a, routeKey: e.key, setFooter: h }), [o, a, e.key, h]), i = _(() => ({
185
+ isLoading: o && g.isLoading,
186
+ setLoading: (p, x) => g.setScreenLoading(e.key, p, x),
187
+ showLoading: (p) => g.begin(e.key, p),
188
+ hideLoading: (p) => g.end(e.key, p)
189
+ }), [o, g, e.key]);
190
+ return /* @__PURE__ */ d(se.Provider, { value: c, children: /* @__PURE__ */ d(me.Provider, { value: i, children: /* @__PURE__ */ d("div", { hidden: !o, inert: !o, "data-modal-route-key": e.key, tabIndex: -1, className: `pmn-body ${m ?? ""}`, children: /* @__PURE__ */ d(He, { route: e, onError: b, children: /* @__PURE__ */ d(M, { route: e, navigation: n }) }) }) }) });
191
191
  }
192
- function je({ config: e, params: t, options: n, translate: o, onRequestClose: a, onOpened: w, registerLoading: h, notifyError: m, error: g, clearError: L }) {
193
- const [c, l] = Se(Te, null, () => Ee(e.initialRoute, t)), [p, y] = Q({}), [T, A] = Q({}), [, $] = Q(0), x = u(/* @__PURE__ */ new Map()), F = u(0), S = u(/* @__PURE__ */ new Map()), H = u(null), k = u(null), q = u(!1), U = u(!1), M = u(0), v = c.at(-1), R = v.key, G = u(R);
194
- G.current = R;
195
- const E = e.screens, N = b(() => $((r) => r + 1), []), O = b((r, s) => {
196
- if (r !== "global" && G.current !== r) return null;
197
- const f = ++F.current;
198
- return x.current.set(f, { owner: r, text: s }), N(), f;
199
- }, [N]), D = b((r, s) => {
192
+ function Ke({ config: e, params: t, options: n, translate: o, onRequestClose: a, onOpened: h, registerLoading: g, notifyError: m, error: b, clearError: M }) {
193
+ const [c, i] = Le(Fe, null, () => Re(e.initialRoute, t)), [p, x] = Q({}), [F, $] = Q({}), [, O] = Q(0), w = u(/* @__PURE__ */ new Map()), P = u(0), L = u(/* @__PURE__ */ new Map()), q = u(null), k = u(null), K = u(!1), U = u(!1), N = u(0), v = c.at(-1), S = v.key, z = u(S);
194
+ z.current = S;
195
+ const E = e.screens, T = y(() => O((r) => r + 1), []), A = y((r, s) => {
196
+ if (r !== "global" && z.current !== r) return null;
197
+ const f = ++P.current;
198
+ return w.current.set(f, { owner: r, text: s }), T(), f;
199
+ }, [T]), j = y((r, s) => {
200
200
  if (s != null)
201
- x.current.get(s)?.owner === r && x.current.delete(s);
201
+ w.current.get(s)?.owner === r && w.current.delete(s);
202
202
  else
203
- for (const [f, J] of x.current) J.owner === r && x.current.delete(f);
204
- N();
205
- }, [N]), z = b((r, s) => {
206
- r ? (D("global"), O("global", s)) : D("global");
207
- }, [O, D]), i = b((r, s, f) => {
208
- s ? (D(r), O(r, f)) : D(r);
209
- }, [O, D]), C = [...x.current.values()], B = { visible: C.length > 0, text: C.at(-1)?.text ?? null, count: C.length }, P = u(B);
210
- P.current = B;
211
- const j = _(() => ({ isLoading: B.visible, setLoading: z, setScreenLoading: i, begin: O, end: D }), [B.visible, z, i, O, D]), W = u(h);
212
- W.current = h, I(() => (W.current?.({ setLoading: z }), () => W.current?.(null)), [z]);
213
- const K = b((r, s) => A((f) => {
203
+ for (const [f, J] of w.current) J.owner === r && w.current.delete(f);
204
+ T();
205
+ }, [T]), G = y((r, s) => {
206
+ r ? (j("global"), A("global", s)) : j("global");
207
+ }, [A, j]), l = y((r, s, f) => {
208
+ s ? (j(r), A(r, f)) : j(r);
209
+ }, [A, j]), R = [...w.current.values()], B = { visible: R.length > 0, text: R.at(-1)?.text ?? null, count: R.length }, C = u(B);
210
+ C.current = B;
211
+ const H = _(() => ({ isLoading: B.visible, setLoading: G, setScreenLoading: l, begin: A, end: j }), [B.visible, G, l, A, j]), W = u(g);
212
+ W.current = g, I(() => (W.current?.({ setLoading: G }), () => W.current?.(null)), [G]);
213
+ const D = y((r, s) => $((f) => {
214
214
  if (s === null) {
215
215
  if (!(r in f)) return f;
216
216
  const J = { ...f };
217
217
  return delete J[r], J;
218
218
  }
219
219
  return f[r] === s ? f : { ...f, [r]: s };
220
- }), []), Y = b(() => {
220
+ }), []), Y = y(() => {
221
221
  const r = document.activeElement;
222
- if (!(r instanceof HTMLElement) || !H.current?.contains(r)) return;
222
+ if (!(r instanceof HTMLElement) || !q.current?.contains(r)) return;
223
223
  const s = r.closest("[data-modal-route-key]");
224
- s && S.current.set(s.dataset.modalRouteKey, r), H.current.focus({ preventScroll: !0 });
225
- }, []), ne = b((r) => {
224
+ s && L.current.set(s.dataset.modalRouteKey, r), q.current.focus({ preventScroll: !0 });
225
+ }, []), ne = y((r) => {
226
226
  if (!Object.prototype.hasOwnProperty.call(E, r)) throw new Error(`[react-modal-navigation] Unknown modal screen: ${r}`);
227
- }, [E]), X = b((r, s) => {
227
+ }, [E]), X = y((r, s) => {
228
228
  try {
229
229
  Promise.resolve(n[r]?.(s)).catch((f) => m(f, { phase: r }));
230
230
  } catch (f) {
231
231
  m(f, { phase: r });
232
232
  }
233
- }, [n, m]), V = b((r, s, f) => {
234
- ne(s), Y(), l({ type: r, name: s, params: f });
235
- }, [ne, Y]), pe = b((r, s) => V("NAVIGATE", r, s), [V]), fe = b((r, s) => V("REPLACE", r, s), [V]), he = b((r, s) => {
236
- y({}), V("RESET", r, s);
237
- }, [V]), ge = b((r) => {
233
+ }, [n, m]), V = y((r, s, f) => {
234
+ ne(s), Y(), i({ type: r, name: s, params: f });
235
+ }, [ne, Y]), pe = y((r, s) => V("NAVIGATE", r, s), [V]), fe = y((r, s) => V("REPLACE", r, s), [V]), he = y((r, s) => {
236
+ x({}), V("RESET", r, s);
237
+ }, [V]), ge = y((r) => {
238
238
  if (!r || typeof r != "object" || Array.isArray(r)) throw new TypeError("[react-modal-navigation] setParams expects an object");
239
- l({ type: "SET_PARAMS", params: r });
240
- }, []), be = b((r) => {
241
- if (c.length <= 1 || q.current) return !1;
242
- if (q.current = !0, r !== void 0) {
239
+ i({ type: "SET_PARAMS", params: r });
240
+ }, []), be = y((r) => {
241
+ if (c.length <= 1 || K.current) return !1;
242
+ if (K.current = !0, r !== void 0) {
243
243
  const s = c.at(-2);
244
- y((f) => ({ ...f, [s.key]: { id: ++M.current, data: r } }));
244
+ x((f) => ({ ...f, [s.key]: { id: ++N.current, data: r } }));
245
245
  }
246
- return Y(), l({ type: "BACK" }), !0;
247
- }, [c, Y]), re = b((r, s) => P.current.visible && n.lockCloseWhileLoading !== !1 ? Promise.resolve(!1) : a(r, s, { route: v, stack: c }), [n.lockCloseWhileLoading, a, v, c]), ve = b((r) => re("api", r), [re]), ae = _(() => ({ navigate: pe, replace: fe, reset: he, setParams: ge, goBack: be, close: ve, setLoading: z, canGoBack: c.length > 1, stack: c, currentRoute: v }), [pe, fe, he, ge, be, ve, z, c, v]);
248
- return Le(() => {
249
- q.current = !1;
250
- const r = [...H.current?.querySelectorAll("[data-modal-route-key]") ?? []].find((J) => J.dataset.modalRouteKey === R);
246
+ return Y(), i({ type: "BACK" }), !0;
247
+ }, [c, Y]), re = y((r, s) => C.current.visible && n.lockCloseWhileLoading !== !1 ? Promise.resolve(!1) : a(r, s, { route: v, stack: c }), [n.lockCloseWhileLoading, a, v, c]), ye = y((r) => re("api", r), [re]), ae = _(() => ({ navigate: pe, replace: fe, reset: he, setParams: ge, goBack: be, close: ye, setLoading: G, canGoBack: c.length > 1, stack: c, currentRoute: v }), [pe, fe, he, ge, be, ye, G, c, v]);
248
+ return Me(() => {
249
+ K.current = !1;
250
+ const r = [...q.current?.querySelectorAll("[data-modal-route-key]") ?? []].find((J) => J.dataset.modalRouteKey === S);
251
251
  if (!r) return;
252
- const s = S.current.get(R);
252
+ const s = L.current.get(S);
253
253
  (s?.isConnected && r.contains(s) && !s.matches(":disabled") && !s.closest("[inert], [hidden]") ? s : r).focus({ preventScroll: !0 });
254
- }, [R]), I(() => {
254
+ }, [S]), I(() => {
255
255
  let r = !1;
256
- for (const [f, J] of x.current)
257
- J.owner !== "global" && J.owner !== R && (x.current.delete(f), r = !0);
258
- r && N();
256
+ for (const [f, J] of w.current)
257
+ J.owner !== "global" && J.owner !== S && (w.current.delete(f), r = !0);
258
+ r && T();
259
259
  const s = new Set(c.map((f) => f.key));
260
- for (const f of S.current.keys()) s.has(f) || S.current.delete(f);
261
- }, [R, c, N]), I(() => {
262
- if (k.current?.key !== R) {
260
+ for (const f of L.current.keys()) s.has(f) || L.current.delete(f);
261
+ }, [S, c, T]), I(() => {
262
+ if (k.current?.key !== S) {
263
263
  if (k.current) {
264
264
  const r = { from: k.current, to: v, stack: c };
265
265
  X("onBlur", { route: k.current, ...r }), X("onNavigate", r), X("onRouteChange", r);
266
266
  }
267
267
  X("onFocus", { route: v, stack: c }), k.current = v;
268
268
  }
269
- }, [v, R, c, X]), I(() => () => {
270
- x.current.clear(), S.current.clear();
269
+ }, [v, S, c, X]), I(() => () => {
270
+ w.current.clear(), L.current.clear();
271
271
  }, []), I(() => {
272
- U.current || (U.current = !0, w?.({ route: v, stack: c }));
273
- }, []), /* @__PURE__ */ d(ue.Provider, { value: ae, children: /* @__PURE__ */ d(me.Provider, { value: j, children: /* @__PURE__ */ ee($e, { dialogRef: H, options: n, requestClose: re, children: [
274
- /* @__PURE__ */ d(Ae, { options: n, screen: E[v.name], route: v, navigation: ae, requestClose: re, translate: o }),
272
+ U.current || (U.current = !0, h?.({ route: v, stack: c }));
273
+ }, []), /* @__PURE__ */ d(ue.Provider, { value: ae, children: /* @__PURE__ */ d(me.Provider, { value: H, children: /* @__PURE__ */ ee($e, { dialogRef: q, options: n, requestClose: re, children: [
274
+ /* @__PURE__ */ d(je, { options: n, screen: E[v.name], route: v, navigation: ae, requestClose: re, translate: o }),
275
275
  /* @__PURE__ */ d("main", { className: "pmn-main", children: c.map((r) => /* @__PURE__ */ d(
276
- qe,
276
+ Ie,
277
277
  {
278
278
  route: r,
279
279
  screen: E[r.name],
280
280
  navigation: ae,
281
- focused: r.key === R,
281
+ focused: r.key === S,
282
282
  resultEvent: p[r.key] ?? null,
283
283
  bodyClassName: n.bodyClassName,
284
- setFooter: K,
285
- loadingApi: j,
284
+ setFooter: D,
285
+ loadingApi: H,
286
286
  notifyError: m
287
287
  },
288
288
  r.key
@@ -292,135 +292,155 @@ function je({ config: e, params: t, options: n, translate: o, onRequestClose: a,
292
292
  {
293
293
  screen: E[v.name],
294
294
  options: n,
295
- override: T[R],
295
+ override: F[S],
296
296
  route: v,
297
297
  navigation: ae,
298
298
  requestClose: re,
299
299
  translate: o,
300
300
  onError: m
301
301
  },
302
- R
302
+ S
303
303
  ),
304
- /* @__PURE__ */ d(He, { loading: B, translate: o }),
305
- g && /* @__PURE__ */ ee("div", { className: "pmn-error", role: "alert", children: [
306
- /* @__PURE__ */ d("span", { children: g.message || String(g) }),
307
- /* @__PURE__ */ d("button", { type: "button", onClick: L, "aria-label": "Dismiss error", children: "×" })
304
+ /* @__PURE__ */ d(qe, { loading: B, translate: o }),
305
+ b && /* @__PURE__ */ ee("div", { className: "pmn-error", role: "alert", children: [
306
+ /* @__PURE__ */ d("span", { children: b.message || String(b) }),
307
+ /* @__PURE__ */ d("button", { type: "button", onClick: M, "aria-label": "Dismiss error", children: "×" })
308
308
  ] })
309
309
  ] }) }) });
310
310
  }
311
- const Ke = ".pmn-overlay,.pmn-dialog,.pmn-dialog *{box-sizing:border-box}.pmn-overlay{position:fixed;inset:0;z-index:1000;display:flex;overscroll-behavior:none;background:#00000073}.pmn-place-right{justify-content:flex-end;align-items:stretch}.pmn-place-left{justify-content:flex-start;align-items:stretch}.pmn-place-center{justify-content:center;align-items:center}.pmn-place-top{justify-content:center;align-items:flex-start}.pmn-place-bottom{justify-content:center;align-items:flex-end}.pmn-dialog{--pmn-surface:#fff;--pmn-body:#fff;--pmn-text:#0f172a;--pmn-muted:#475569;--pmn-border:#e2e8f0;--pmn-hover:#f1f5f9;--pmn-overlay-card:rgba(255,255,255,.92);color-scheme:light;position:relative;display:flex;flex-direction:column;min-height:0;width:100%;max-width:min(calc(100vw - var(--pmn-gap)*2),var(--pmn-max-width, var(--pmn-width)));max-height:min(calc(100dvh - var(--pmn-gap)*2),var(--pmn-max-height, 100dvh));height:var(--pmn-height, 100%);overflow:hidden;outline:none;box-shadow:0 25px 50px -12px #00000040;background:var(--pmn-surface);color:var(--pmn-text)}.pmn-place-left .pmn-dialog,.pmn-place-right .pmn-dialog{height:calc(100dvh - var(--pmn-gap)*2);max-height:calc(100dvh - var(--pmn-gap)*2)}.pmn-place-center .pmn-dialog{height:var(--pmn-height, auto);min-height:150px}.pmn-place-top .pmn-dialog,.pmn-place-bottom .pmn-dialog{height:var(--pmn-height, auto);min-height:0}.pmn-dialog[data-modal-theme=dark]{--pmn-surface:#334155;--pmn-body:#334155;--pmn-text:#f1f5f9;--pmn-muted:#cbd5e1;--pmn-border:#475569;--pmn-hover:#1e293b;--pmn-overlay-card:rgba(51,65,85,.94);color-scheme:dark}.pmn-main{min-height:0;flex:1;overflow:hidden;display:flex;flex-direction:column;background:transparent}.pmn-body{height:100%;min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:16px;flex:1}.pmn-body[hidden]{display:none!important}.pmn-header{display:flex;flex-shrink:0;height:64px;align-items:center;gap:12px;padding:0 20px;background:transparent}.pmn-header h2{font-size:18px;font-weight:600;min-width:0;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin:0}.pmn-header-spacer{flex:1}.pmn-border-bottom{border-bottom:1px solid var(--pmn-border)}.pmn-icon-button{display:inline-flex;align-items:center;justify-content:center;padding:8px;border:0;background:transparent;color:inherit;border-radius:8px;cursor:pointer}.pmn-icon-button:hover{background:var(--pmn-hover)}.pmn-footer{display:flex;flex-shrink:0;align-items:center;justify-content:flex-end;gap:12px;padding:16px 20px;background:transparent}.pmn-border-top{border-top:1px solid var(--pmn-border)}.pmn-button{padding:8px 16px;border-radius:8px;font-size:14px;font-weight:500;cursor:pointer}.pmn-button:disabled{opacity:.5;cursor:not-allowed}.pmn-button-secondary{border:1px solid var(--pmn-border);background:transparent;color:var(--pmn-text)}.pmn-button-secondary:hover:not(:disabled){background:var(--pmn-hover)}.pmn-button-primary{border:1px solid #2563eb;background:#2563eb;color:#fff}.pmn-button-primary:hover:not(:disabled){background:#1d4ed8}.pmn-loading-overlay{position:absolute;inset:0;z-index:50;display:flex;align-items:center;justify-content:center;background:var(--pmn-overlay-card);-webkit-backdrop-filter:blur(1px);backdrop-filter:blur(1px)}.pmn-loading-card{display:flex;flex-direction:column;align-items:center;gap:12px;max-width:85%;padding:20px 28px;border-radius:12px;background:var(--pmn-surface);box-shadow:0 10px 20px #00000026}.pmn-spinner{width:36px;height:36px;border:3px solid #2563eb;border-top-color:transparent;border-radius:50%;animation:pmn-spin 1s linear infinite}@keyframes pmn-spin{to{transform:rotate(360deg)}}.pmn-error{position:absolute;z-index:60;bottom:8px;left:12px;right:12px;display:flex;justify-content:space-between;gap:12px;padding:12px;border:1px solid #fca5a5;border-radius:8px;background:#fef2f2;color:#991b1b;font-size:13px}.pmn-error button{border:0;background:transparent;font-size:20px;cursor:pointer;color:inherit}.pmn-dialog input:not([type=checkbox]):not([type=radio]),.pmn-dialog textarea,.pmn-dialog select{color:var(--pmn-text);border-color:var(--pmn-border)}.pmn-error-screen{padding:24px;color:var(--pmn-text)}.pmn-error-screen p{color:#dc2626;overflow-wrap:anywhere}@media(max-width:640px){.pmn-overlay.pmn-mobile-fullscreen{padding:0!important}.pmn-mobile-fullscreen .pmn-dialog{max-width:100%;width:100%;height:100dvh;max-height:100dvh;border-radius:0!important}}@media(prefers-reduced-motion:reduce){.pmn-spinner{animation-duration:2s}}", we = "react-modal-navigation-styles", ie = /* @__PURE__ */ new WeakMap();
311
+ const ze = ".pmn-overlay,.pmn-dialog,.pmn-dialog *{box-sizing:border-box}.pmn-overlay{position:fixed;inset:0;z-index:1000;display:flex;overscroll-behavior:none;background:#00000073}.pmn-place-right{justify-content:flex-end;align-items:stretch}.pmn-place-left{justify-content:flex-start;align-items:stretch}.pmn-place-center{justify-content:center;align-items:center}.pmn-place-top{justify-content:center;align-items:flex-start}.pmn-place-bottom{justify-content:center;align-items:flex-end}.pmn-dialog{--pmn-surface:#fff;--pmn-body:#fff;--pmn-text:#0f172a;--pmn-muted:#475569;--pmn-border:#e2e8f0;--pmn-hover:#f1f5f9;--pmn-overlay-card:rgba(255,255,255,.92);color-scheme:light;position:relative;display:flex;flex-direction:column;min-height:0;width:100%;max-width:min(calc(100vw - var(--pmn-gap)*2),var(--pmn-max-width, var(--pmn-width)));max-height:min(calc(100dvh - var(--pmn-gap)*2),var(--pmn-max-height, 100dvh));height:var(--pmn-height, 100%);overflow:hidden;outline:none;box-shadow:0 25px 50px -12px #00000040;background:var(--pmn-surface);color:var(--pmn-text)}.pmn-place-left .pmn-dialog,.pmn-place-right .pmn-dialog{height:calc(100dvh - var(--pmn-gap)*2);max-height:calc(100dvh - var(--pmn-gap)*2)}.pmn-place-center .pmn-dialog{height:var(--pmn-height, auto);min-height:150px}.pmn-place-top .pmn-dialog,.pmn-place-bottom .pmn-dialog{height:var(--pmn-height, auto);min-height:0}.pmn-dialog[data-modal-theme=dark]{--pmn-surface:#334155;--pmn-body:#334155;--pmn-text:#f1f5f9;--pmn-muted:#cbd5e1;--pmn-border:#475569;--pmn-hover:#1e293b;--pmn-overlay-card:rgba(51,65,85,.94);color-scheme:dark}.pmn-main{min-height:0;flex:1;overflow:hidden;display:flex;flex-direction:column;background:transparent}.pmn-body{height:100%;min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:16px;flex:1}.pmn-body[hidden]{display:none!important}.pmn-header{display:flex;flex-shrink:0;height:64px;align-items:center;gap:12px;padding:0 20px;background:transparent}.pmn-header h2{font-size:18px;font-weight:600;min-width:0;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin:0}.pmn-header-spacer{flex:1}.pmn-border-bottom{border-bottom:1px solid var(--pmn-border)}.pmn-icon-button{display:inline-flex;align-items:center;justify-content:center;padding:8px;border:0;background:transparent;color:inherit;border-radius:8px;cursor:pointer}.pmn-icon-button:hover{background:var(--pmn-hover)}.pmn-footer{display:flex;flex-shrink:0;align-items:center;justify-content:flex-end;gap:12px;padding:16px 20px;background:transparent}.pmn-border-top{border-top:1px solid var(--pmn-border)}.pmn-button{padding:8px 16px;border-radius:8px;font-size:14px;font-weight:500;cursor:pointer}.pmn-button:disabled{opacity:.5;cursor:not-allowed}.pmn-button-secondary{border:1px solid var(--pmn-border);background:transparent;color:var(--pmn-text)}.pmn-button-secondary:hover:not(:disabled){background:var(--pmn-hover)}.pmn-button-primary{border:1px solid #2563eb;background:#2563eb;color:#fff}.pmn-button-primary:hover:not(:disabled){background:#1d4ed8}.pmn-loading-overlay{position:absolute;inset:0;z-index:50;display:flex;align-items:center;justify-content:center;background:var(--pmn-overlay-card);-webkit-backdrop-filter:blur(1px);backdrop-filter:blur(1px)}.pmn-loading-card{display:flex;flex-direction:column;align-items:center;gap:12px;max-width:85%;padding:20px 28px;border-radius:12px;background:var(--pmn-surface);box-shadow:0 10px 20px #00000026}.pmn-spinner{width:36px;height:36px;border:3px solid #2563eb;border-top-color:transparent;border-radius:50%;animation:pmn-spin 1s linear infinite}@keyframes pmn-spin{to{transform:rotate(360deg)}}.pmn-error{position:absolute;z-index:60;bottom:8px;left:12px;right:12px;display:flex;justify-content:space-between;gap:12px;padding:12px;border:1px solid #fca5a5;border-radius:8px;background:#fef2f2;color:#991b1b;font-size:13px}.pmn-error button{border:0;background:transparent;font-size:20px;cursor:pointer;color:inherit}.pmn-dialog input:not([type=checkbox]):not([type=radio]),.pmn-dialog textarea,.pmn-dialog select{color:var(--pmn-text);border-color:var(--pmn-border)}.pmn-error-screen{padding:24px;color:var(--pmn-text)}.pmn-error-screen p{color:#dc2626;overflow-wrap:anywhere}@media(max-width:640px){.pmn-overlay.pmn-mobile-fullscreen{padding:0!important}.pmn-mobile-fullscreen .pmn-dialog{max-width:100%;width:100%;height:100dvh;max-height:100dvh;border-radius:0!important}}@media(prefers-reduced-motion:reduce){.pmn-spinner{animation-duration:2s}}", we = "react-modal-navigation-styles", le = /* @__PURE__ */ new WeakMap();
312
312
  function Ge() {
313
- Me(() => {
313
+ Ne(() => {
314
314
  if (typeof document > "u") return;
315
315
  const e = document;
316
- let t = ie.get(e);
316
+ let t = le.get(e);
317
317
  if (!t) {
318
318
  let n = e.getElementById(we);
319
319
  const o = !n;
320
- n || (n = e.createElement("style"), n.id = we, n.setAttribute("data-react-modal-navigation", ""), n.textContent = Ke, e.head.appendChild(n)), t = { element: n, owned: o, count: 0 }, ie.set(e, t);
320
+ n || (n = e.createElement("style"), n.id = we, n.setAttribute("data-react-modal-navigation", ""), n.textContent = ze, e.head.appendChild(n)), t = { element: n, owned: o, count: 0 }, le.set(e, t);
321
321
  }
322
322
  return t.count += 1, () => {
323
- t.count -= 1, t.count === 0 && (t.owned && t.element.remove(), ie.delete(e));
323
+ t.count -= 1, t.count === 0 && (t.owned && t.element.remove(), le.delete(e));
324
324
  };
325
325
  }, []);
326
326
  }
327
- const ze = { placement: "right", showHeader: !0, showBackButton: !0, showCloseButton: !0, viewportGap: 5, borderRadius: 12, closeOnOverlay: !1, closeOnEsc: !0 }, We = (e) => ({ "modal.loading": "加载中...", "modal.processing": "处理中...", "modal.back": "返回", "modal.close": "关闭", "modal.cancel": "取消", "modal.done": "完成" })[e] ?? e;
328
- function Je({ registry: e, children: t, defaultOptions: n = {}, backgroundColor: o, theme: a, translate: w = We, onError: h }) {
327
+ function ke(e, t, n) {
328
+ if (typeof e == "string") {
329
+ if (!e.trim()) throw new TypeError("[react-modal-navigation] modal name must not be empty");
330
+ return { name: e, params: t ?? {}, options: n ?? {} };
331
+ }
332
+ if (e === null || typeof e != "object" || Array.isArray(e))
333
+ throw new TypeError("[react-modal-navigation] open expects a modal name or { name, params?, options? }");
334
+ const { name: o, params: a = {}, options: h = {} } = e;
335
+ if (typeof o != "string" || !o.trim())
336
+ throw new TypeError("[react-modal-navigation] open config requires a non-empty string name");
337
+ if (h === null || typeof h != "object" || Array.isArray(h))
338
+ throw new TypeError("[react-modal-navigation] open config options must be an object");
339
+ return { name: o, params: a, options: h };
340
+ }
341
+ const We = { placement: "right", showHeader: !0, showBackButton: !0, showCloseButton: !0, viewportGap: 5, borderRadius: 12, closeOnOverlay: !1, closeOnEsc: !0 }, Ue = (e) => ({ "modal.loading": "加载中...", "modal.processing": "处理中...", "modal.back": "返回", "modal.close": "关闭", "modal.cancel": "取消", "modal.done": "完成" })[e] ?? e;
342
+ function Qe({ registry: e, children: t, defaultOptions: n = {}, backgroundColor: o, theme: a, translate: h = Ue, onError: g }) {
329
343
  Ge();
330
- const [m, g] = Q(null), [L, c] = Q(null), l = u(null), p = u(/* @__PURE__ */ new Map()), y = u(0), T = u(null), A = u(!1), $ = u(0), x = u(null), F = u(!0), S = u(null), H = u(h);
331
- H.current = h;
332
- const k = b((i, C) => {
333
- F.current && c(i);
344
+ const [m, b] = Q(null), [M, c] = Q(null), i = u(null), p = u(/* @__PURE__ */ new Map()), x = u(0), F = u(null), $ = u(!1), O = u(0), w = u(null), P = u(!0), L = u(null), q = u(g);
345
+ q.current = g;
346
+ const k = y((l, R) => {
347
+ P.current && c(l);
334
348
  try {
335
- H.current ? H.current(i, C) : console.error("[react-modal-navigation]", i);
349
+ q.current ? q.current(l, R) : console.error("[react-modal-navigation]", l);
336
350
  } catch (B) {
337
351
  console.error("[react-modal-navigation] onError failed", B);
338
352
  }
339
- }, []), q = b((i, C) => {
340
- const B = p.current.get(i);
341
- p.current.delete(i), B?.(C);
342
- }, []), U = b((i) => ({ ...ze, ...n, ...a !== void 0 ? { theme: a } : {}, ...o !== void 0 ? { backgroundColor: o } : {}, ...i.config.modalOptions, ...i.overrides }), [n, a, o]), M = m ? U(m) : null, v = u(null);
343
- v.current = M, S.current = M;
344
- const R = b(async (i = "api", C, B = {}) => {
345
- const P = l.current;
346
- if (!P || T.current || A.current) return !1;
347
- T.current = P.id, A.current = !0;
348
- const j = S.current ?? U(P), W = { ...B, reason: i, result: C, name: P.name };
353
+ }, []), K = y((l, R) => {
354
+ const B = p.current.get(l);
355
+ p.current.delete(l), B?.(R);
356
+ }, []), U = y((l) => ({ ...We, ...n, ...a !== void 0 ? { theme: a } : {}, ...o !== void 0 ? { backgroundColor: o } : {}, ...l.config.modalOptions, ...l.overrides }), [n, a, o]), N = m ? U(m) : null, v = u(null);
357
+ v.current = N, L.current = N;
358
+ const S = y(async (l = "api", R, B = {}) => {
359
+ const C = i.current;
360
+ if (!C || F.current || $.current) return !1;
361
+ F.current = C.id, $.current = !0;
362
+ const H = L.current ?? U(C), W = { ...B, reason: l, result: R, name: C.name };
349
363
  try {
350
- if (await j.onBeforeClose?.(W) === !1 || l.current?.id !== P.id || !F.current) return !1;
351
- l.current = null, x.current = null, g(null), q(P.id, C === void 0 ? { status: "dismissed", reason: i } : { status: "confirmed", value: C, reason: i });
364
+ if (await H.onBeforeClose?.(W) === !1 || i.current?.id !== C.id || !P.current) return !1;
365
+ i.current = null, w.current = null, b(null), K(C.id, R === void 0 ? { status: "dismissed", reason: l } : { status: "confirmed", value: R, reason: l });
352
366
  try {
353
- await j.onClose?.(W);
354
- } catch (K) {
355
- k(K, { phase: "onClose", name: P.name });
367
+ await H.onClose?.(W);
368
+ } catch (D) {
369
+ k(D, { phase: "onClose", name: C.name });
356
370
  }
357
371
  return !0;
358
- } catch (K) {
359
- return k(K, { phase: "onBeforeClose", name: P.name }), !1;
372
+ } catch (D) {
373
+ return k(D, { phase: "onBeforeClose", name: C.name }), !1;
360
374
  } finally {
361
- T.current === P.id && (T.current = null), A.current = !1;
375
+ F.current === C.id && (F.current = null), $.current = !1;
362
376
  }
363
- }, [U, k, q]), G = b(async (i, C = {}, B = {}, P) => {
364
- const j = e?.[i];
365
- if (!j) throw new Error(`[react-modal-navigation] Unknown modal: ${i}`);
366
- if (!j.screens?.[j.initialRoute]) throw new Error(`[react-modal-navigation] Missing initial screen '${j.initialRoute}' in '${i}'`);
367
- if (!F.current || A.current || T.current) return null;
368
- A.current = !0;
369
- const W = $.current;
377
+ }, [U, k, K]), z = y(async (l, R = {}, B = {}, C) => {
378
+ const H = e?.[l];
379
+ if (!H) throw new Error(`[react-modal-navigation] Unknown modal: ${l}`);
380
+ if (!H.screens?.[H.initialRoute]) throw new Error(`[react-modal-navigation] Missing initial screen '${H.initialRoute}' in '${l}'`);
381
+ if (!P.current || $.current || F.current) return null;
382
+ $.current = !0;
383
+ const W = O.current;
370
384
  try {
371
- const K = l.current;
372
- if (K) {
373
- const ne = S.current ?? U(K), X = { reason: "replace", name: K.name, nextName: i };
385
+ const D = i.current;
386
+ if (D) {
387
+ const ne = L.current ?? U(D), X = { reason: "replace", name: D.name, nextName: l };
374
388
  try {
375
389
  if (await ne.onBeforeClose?.(X) === !1) return null;
376
390
  } catch (V) {
377
- return k(V, { phase: "onBeforeClose", name: K.name }), null;
391
+ return k(V, { phase: "onBeforeClose", name: D.name }), null;
378
392
  }
379
- if (!F.current || W !== $.current || l.current?.id !== K.id) return null;
380
- l.current = null, x.current = null, g(null), q(K.id, { status: "replaced", reason: "replace" });
393
+ if (!P.current || W !== O.current || i.current?.id !== D.id) return null;
394
+ i.current = null, w.current = null, b(null), K(D.id, { status: "replaced", reason: "replace" });
381
395
  try {
382
396
  await ne.onClose?.(X);
383
397
  } catch (V) {
384
- k(V, { phase: "onClose", name: K.name });
398
+ k(V, { phase: "onClose", name: D.name });
385
399
  }
386
- if (!F.current || W !== $.current) return null;
400
+ if (!P.current || W !== O.current) return null;
387
401
  }
388
- const Y = { id: ++y.current, name: i, params: C, config: j, overrides: B };
389
- return l.current = Y, x.current = null, P && p.current.set(Y.id, P), c(null), g(Y), Y.id;
402
+ const Y = { id: ++x.current, name: l, params: R, config: H, overrides: B };
403
+ return i.current = Y, w.current = null, C && p.current.set(Y.id, C), c(null), b(Y), Y.id;
390
404
  } finally {
391
- A.current = !1;
405
+ $.current = !1;
392
406
  }
393
- }, [e, U, k, q]), E = b((i, C, B) => G(i, C, B), [G]), N = b((i, C, B) => new Promise((P, j) => {
394
- G(i, C, B, P).then((W) => {
395
- W === null && P({ status: "dismissed", reason: "blocked" });
396
- }, j);
397
- }), [G]), O = b((i) => R("api", i), [R]), D = b((i, C) => x.current?.setLoading(i, C), []), z = _(() => ({ open: E, openAsync: N, close: O, setLoading: D, isOpen: !!m, activeName: m?.name ?? null, error: L, clearError: () => c(null) }), [E, N, O, D, m, L]);
398
- return I(() => (F.current = !0, () => {
399
- F.current = !1, $.current += 1, l.current = null;
400
- for (const i of p.current.values()) i({ status: "dismissed", reason: "unmount" });
407
+ }, [e, U, k, K]), E = y((l, R, B) => {
408
+ const C = ke(l, R, B);
409
+ return z(C.name, C.params, C.options);
410
+ }, [z]), T = y((l, R, B) => {
411
+ const C = ke(l, R, B);
412
+ return new Promise((H, W) => {
413
+ z(C.name, C.params, C.options, H).then((D) => {
414
+ D === null && H({ status: "dismissed", reason: "blocked" });
415
+ }, W);
416
+ });
417
+ }, [z]), A = y((l) => S("api", l), [S]), j = y((l, R) => w.current?.setLoading(l, R), []), G = _(() => ({ open: E, openAsync: T, close: A, setLoading: j, isOpen: !!m, activeName: m?.name ?? null, error: M, clearError: () => c(null) }), [E, T, A, j, m, M]);
418
+ return I(() => (P.current = !0, () => {
419
+ P.current = !1, O.current += 1, i.current = null;
420
+ for (const l of p.current.values()) l({ status: "dismissed", reason: "unmount" });
401
421
  p.current.clear();
402
- }), []), /* @__PURE__ */ ee(ke.Provider, { value: z, children: [
422
+ }), []), /* @__PURE__ */ ee(Ee.Provider, { value: G, children: [
403
423
  t,
404
424
  m && /* @__PURE__ */ d(
405
- je,
425
+ Ke,
406
426
  {
407
427
  config: m.config,
408
428
  params: m.params,
409
- options: M,
410
- translate: w,
429
+ options: N,
430
+ translate: h,
411
431
  notifyError: k,
412
- error: L,
432
+ error: M,
413
433
  clearError: () => c(null),
414
- registerLoading: (i) => {
415
- x.current = i;
434
+ registerLoading: (l) => {
435
+ w.current = l;
416
436
  },
417
- onRequestClose: R,
418
- onOpened: (i) => {
437
+ onRequestClose: S,
438
+ onOpened: (l) => {
419
439
  try {
420
- const C = v.current?.onOpen?.(i);
421
- Promise.resolve(C).catch((B) => k(B, { phase: "onOpen" }));
422
- } catch (C) {
423
- k(C, { phase: "onOpen" });
440
+ const R = v.current?.onOpen?.(l);
441
+ Promise.resolve(R).catch((B) => k(B, { phase: "onOpen" }));
442
+ } catch (R) {
443
+ k(R, { phase: "onOpen" });
424
444
  }
425
445
  }
426
446
  },
@@ -428,8 +448,8 @@ function Je({ registry: e, children: t, defaultOptions: n = {}, backgroundColor:
428
448
  )
429
449
  ] });
430
450
  }
431
- function Qe() {
432
- const e = te(ke), t = te(ue);
451
+ function Xe() {
452
+ const e = te(Ee), t = te(ue);
433
453
  if (!e) throw new Error("[react-modal-navigation] useModal requires <ModalProvider>");
434
454
  return _(() => {
435
455
  const n = () => {
@@ -455,7 +475,7 @@ function Qe() {
455
475
  } };
456
476
  }, [e, t]);
457
477
  }
458
- function Xe() {
478
+ function Ze() {
459
479
  const e = te(ue);
460
480
  if (!e) throw new Error("useModalNavigation requires an active modal screen");
461
481
  return e;
@@ -465,14 +485,14 @@ function Ce() {
465
485
  if (!e) throw new Error("useIsFocused must be called inside a modal screen");
466
486
  return e.isFocused;
467
487
  }
468
- function Ze(e) {
488
+ function et(e) {
469
489
  const t = Ce();
470
490
  I(() => {
471
491
  if (t)
472
492
  return e();
473
493
  }, [t, e]);
474
494
  }
475
- function et(e) {
495
+ function tt(e) {
476
496
  const t = te(se);
477
497
  if (!t) throw new Error("useNavigationResult requires an active modal screen");
478
498
  const n = u(e), o = u(null);
@@ -482,69 +502,69 @@ function et(e) {
482
502
  !t.isFocused || !t.resultEvent || o.current !== t.resultEvent.id && (o.current = t.resultEvent.id, n.current(t.resultEvent.data));
483
503
  }, [t.isFocused, t.resultEvent]);
484
504
  }
485
- function tt(e = {}) {
505
+ function nt(e = {}) {
486
506
  const t = te(se);
487
507
  if (!t) throw new Error("[react-modal-navigation] useModalFooter requires an active modal screen");
488
508
  const { setFooter: n, routeKey: o } = t, a = u(e);
489
509
  a.current = e;
490
- const w = _(() => (...S) => a.current.done?.(...S), []), h = _(() => (...S) => (a.current.cancel ?? a.current.cancle)?.(...S), []), m = _(() => (...S) => a.current.renderFooter?.(...S), []), g = typeof e.done == "function", L = typeof (e.cancel ?? e.cancle) == "function", c = typeof e.renderFooter == "function", { showFooter: l, showFooterBorder: p, doneDisabled: y, doneText: T, cancelText: A, loadingText: $, footerClassName: x } = e, F = _(() => ({
491
- showFooter: l,
510
+ const h = _(() => (...L) => a.current.done?.(...L), []), g = _(() => (...L) => (a.current.cancel ?? a.current.cancle)?.(...L), []), m = _(() => (...L) => a.current.renderFooter?.(...L), []), b = typeof e.done == "function", M = typeof (e.cancel ?? e.cancle) == "function", c = typeof e.renderFooter == "function", { showFooter: i, showFooterBorder: p, doneDisabled: x, doneText: F, cancelText: $, loadingText: O, footerClassName: w } = e, P = _(() => ({
511
+ showFooter: i,
492
512
  showFooterBorder: p,
493
- doneDisabled: y,
494
- doneText: T,
495
- cancelText: A,
496
- loadingText: $,
497
- footerClassName: x,
498
- ...g ? { done: w } : {},
499
- ...L ? { cancel: h } : {},
513
+ doneDisabled: x,
514
+ doneText: F,
515
+ cancelText: $,
516
+ loadingText: O,
517
+ footerClassName: w,
518
+ ...b ? { done: h } : {},
519
+ ...M ? { cancel: g } : {},
500
520
  ...c ? { renderFooter: m } : {}
501
- }), [l, p, y, T, A, $, x, g, L, c, w, h, m]);
521
+ }), [i, p, x, F, $, O, w, b, M, c, h, g, m]);
502
522
  I(() => {
503
- n(o, F);
504
- }, [o, n, F]), I(() => () => n(o, null), [o, n]);
523
+ n(o, P);
524
+ }, [o, n, P]), I(() => () => n(o, null), [o, n]);
505
525
  }
506
- function Ue() {
526
+ function Ve() {
507
527
  const e = te(me);
508
528
  if (!e) throw new Error("[react-modal-navigation] useModalLoading requires an active modal screen");
509
529
  return e;
510
530
  }
511
- function nt() {
512
- const e = Ue(), t = Ce(), n = u(!0), o = u(!1), [a, w] = Q(!1), [h, m] = Q(null), g = u(e);
513
- return g.current = e, I(() => (n.current = !0, () => {
531
+ function rt() {
532
+ const e = Ve(), t = Ce(), n = u(!0), o = u(!1), [a, h] = Q(!1), [g, m] = Q(null), b = u(e);
533
+ return b.current = e, I(() => (n.current = !0, () => {
514
534
  n.current = !1;
515
- }), []), { run: b(async (c, l = {}) => {
535
+ }), []), { run: y(async (c, i = {}) => {
516
536
  if (o.current) return { status: "busy" };
517
537
  if (typeof c != "function") throw new TypeError("[react-modal-navigation] run requires a function");
518
- o.current = !0, n.current && (w(!0), m(null));
519
- const p = g.current.showLoading(l.loadingText);
538
+ o.current = !0, n.current && (h(!0), m(null));
539
+ const p = b.current.showLoading(i.loadingText);
520
540
  try {
521
- const y = await c();
522
- return n.current && await l.onSuccess?.(y), { status: "success", value: y };
523
- } catch (y) {
541
+ const x = await c();
542
+ return n.current && await i.onSuccess?.(x), { status: "success", value: x };
543
+ } catch (x) {
524
544
  if (n.current) {
525
- m(y);
545
+ m(x);
526
546
  try {
527
- await l.onError?.(y);
528
- } catch (T) {
529
- console.error("[react-modal-navigation] onError failed", T);
547
+ await i.onError?.(x);
548
+ } catch (F) {
549
+ console.error("[react-modal-navigation] onError failed", F);
530
550
  }
531
551
  }
532
- if (l.throwOnError) throw y;
533
- return { status: "error", error: y };
552
+ if (i.throwOnError) throw x;
553
+ return { status: "error", error: x };
534
554
  } finally {
535
- p != null && g.current.hideLoading(p), o.current = !1, n.current && w(!1);
555
+ p != null && b.current.hideLoading(p), o.current = !1, n.current && h(!1);
536
556
  }
537
- }, []), pending: a, error: h, clearError: () => m(null), isFocused: t };
557
+ }, []), pending: a, error: g, clearError: () => m(null), isFocused: t };
538
558
  }
539
559
  export {
540
- je as ModalNavigator,
541
- Je as ModalProvider,
542
- Ze as useFocusEffect,
560
+ Ke as ModalNavigator,
561
+ Qe as ModalProvider,
562
+ et as useFocusEffect,
543
563
  Ce as useIsFocused,
544
- Qe as useModal,
545
- tt as useModalFooter,
546
- Ue as useModalLoading,
547
- Xe as useModalNavigation,
548
- nt as useModalTask,
549
- et as useNavigationResult
564
+ Xe as useModal,
565
+ nt as useModalFooter,
566
+ Ve as useModalLoading,
567
+ Ze as useModalNavigation,
568
+ rt as useModalTask,
569
+ tt as useNavigationResult
550
570
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-modal-navigation",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "React 19 modal navigation with automatic built-in CSS, Promise results and typed hooks",
5
5
  "type": "module",
6
6
  "license": "MIT",