react-modal-navigation 1.1.6 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -76,3 +76,5 @@
76
76
  - Added a real React 19 `ModalProvider` / `ModalNavigator` profiler integration suite.
77
77
  - Added `npm run test:react` and explicit React testing dependencies.
78
78
  - No Context API redesign in this change; performance refactors await measured results.
79
+
80
+ - Fix: Default Header back button now follows the current render stack depth; per-screen `showBackButton` is respected.
package/README.md CHANGED
@@ -710,3 +710,7 @@ function LoadingIndicator() {
710
710
  声明式 Footer 的按钮配置现在使用逐属性比较,避免 JSON 序列化丢失函数属性或遗漏新增配置字段。异步操作仍需要在业务层使用 `try/finally` 管理自身资源。
711
711
 
712
712
  类型增强:可通过 `TypedModalNavigation<Routes>` 为项目提供路由名及参数的静态检查。
713
+
714
+ ### 返回按钮显示规则(1.1.6 修复)
715
+
716
+ 默认 Header 在导航栈超过一页时自动显示返回按钮。使用 `navigation.navigate('Detail')` 推入页面;`replace` / `reset` 不增加可返回的历史。可通过 `showBackButton: false` 隐藏,页面 `setOptions({ showBackButton: true })` 可覆盖默认设置。如果使用 `renderHeader` 自定义整个 Header,需要自行渲染返回按钮。
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react/jsx-runtime"),e=require("react"),rt=require("react-dom"),We=e.createContext(null),ot=e.createContext(null),Me=e.createContext(null),je=e.createContext(null),Ye=e.createContext(null),_e=e.createContext(null),Fe=e.createContext(null),Oe=e.createContext(null),De=e.createContext(null),at=e.createContext(null),st=e.createContext(null),Ve=e.createContext(null);function ct(t){let n=t;const o=new Set;return{getSnapshot:()=>n,subscribe:r=>(o.add(r),()=>o.delete(r)),publish(r){if(n!==r){n=r;for(const i of[...o])i()}},listenerCount:()=>o.size}}function Pe(t){let n=t;const o=new Set;return{getSnapshot:()=>n,subscribe:r=>(o.add(r),()=>o.delete(r)),publish(r){if(!Object.is(n,r)){n=r;for(const i of[...o])i()}},listenerCount:()=>o.size}}let it=0;const qe=(t,n)=>({key:`modal-route-${++it}`,name:t,params:n??{}}),Qe=(t,n)=>[qe(t,n)];function Ee(t,n){switch(n.type){case"RESET":return Qe(n.name,n.params);case"NAVIGATE":{const o=t.findIndex(r=>r.name===n.name);return o<0?[...t,qe(n.name,n.params)]:t.slice(0,o+1).map((r,i)=>i===o?{...r,params:n.params??{}}:r)}case"SET_OPTIONS":return t.map((o,r)=>r===t.length-1?{...o,options:{...o.options??{},...n.options??{}}}:o);case"SET_PARAMS":return t.map((o,r)=>r===t.length-1?{...o,params:{...o.params??{},...n.params??{}}}:o);case"BACK":return t.length>1?t.slice(0,-1):t;case"REPLACE":return t.length?[...t.slice(0,-1),qe(n.name,n.params)]:t;default:return t}}function ut(t,n,o=1/0){const r=o===1/0?1/0:Math.max(0,Math.floor(Number(o)||0)),i=t.slice(0,-1).filter(l=>n[l.name]?.keepAlive!==!1),g=new Set((r===0?[]:i.slice(-r)).map(l=>l.key));return t.filter((l,f)=>f===t.length-1||g.has(l.key))}const Ke=()=>{if(typeof document>"u")return"light";const t=document.documentElement,n=document.body;return t.classList.contains("dark")||n.classList.contains("dark")||t.dataset.theme==="dark"||n.dataset.theme==="dark"?"dark":t.classList.contains("light")||n.classList.contains("light")||t.dataset.theme==="light"||n.dataset.theme==="light"?"light":window.matchMedia?.("(prefers-color-scheme: dark)").matches?"dark":"light"};let ve=0;const ue=[];let Be=null;function lt(){if(ve++,ve===1){const n=document.documentElement,o=document.body,r={html:n.style.overflow,body:o.style.overflow,padding:o.style.paddingRight,width:o.style.getPropertyValue("--modal-scrollbar-width")},i=Math.max(0,window.innerWidth-n.clientWidth),g=parseFloat(getComputedStyle(o).paddingRight)||0;i&&(o.style.paddingRight=`${g+i}px`),o.style.setProperty("--modal-scrollbar-width",`${i}px`),n.style.overflow="hidden",o.style.overflow="hidden",Be=()=>{n.style.overflow=r.html,o.style.overflow=r.body,o.style.paddingRight=r.padding,r.width?o.style.setProperty("--modal-scrollbar-width",r.width):o.style.removeProperty("--modal-scrollbar-width")}}let t=!1;return()=>{t||(t=!0,ve=Math.max(0,ve-1),ve||(Be?.(),Be=null))}}const dt='a[href],button:not([disabled]),input:not([disabled]),textarea:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])',mt=t=>!t.closest('[inert], [hidden], [aria-hidden="true"]')&&t.getClientRects().length>0&&getComputedStyle(t).visibility!=="hidden"&&getComputedStyle(t).display!=="none";function ft({dialogRef:t,options:n,requestClose:o,children:r,exiting:i=!1}){const g=e.useRef(null),l=e.useRef(null),f=e.useRef(o);f.current=o;const d=e.useRef(n.closeOnEsc);d.current=n.closeOnEsc;const[x,R]=e.useState(Ke),v=n.theme==="light"||n.theme==="dark"?n.theme:x;e.useEffect(()=>{if(n.theme==="light"||n.theme==="dark")return;const b=()=>R(Ke()),M=new MutationObserver(b);for(const F of[document.documentElement,document.body])M.observe(F,{attributes:!0,attributeFilter:["class","data-theme"]});const q=window.matchMedia?.("(prefers-color-scheme: dark)");return q?.addEventListener?.("change",b),b(),()=>{M.disconnect(),q?.removeEventListener?.("change",b)}},[n.theme]),e.useEffect(()=>{l.current=document.activeElement;const b=lt(),M=g.current;ue.push(M),t.current?.focus({preventScroll:!0});const q=j=>{const W=t.current;if(!W||ue.at(-1)!==M)return;if(j.key==="Escape"&&d.current!==!1){j.preventDefault(),f.current("escape");return}if(j.key!=="Tab")return;const N=[...W.querySelectorAll(dt)].filter(mt);if(!N.length){j.preventDefault(),W.focus();return}const Q=N[0],J=N.at(-1);W.contains(document.activeElement)?j.shiftKey&&(document.activeElement===Q||document.activeElement===W)?(j.preventDefault(),J.focus()):!j.shiftKey&&(document.activeElement===J||document.activeElement===W)&&(j.preventDefault(),Q.focus()):(j.preventDefault(),(j.shiftKey?J:Q).focus())},F=j=>{ue.at(-1)===M&&t.current&&!t.current.contains(j.target)&&t.current.focus({preventScroll:!0})};return document.addEventListener("keydown",q),document.addEventListener("focusin",F),()=>{document.removeEventListener("keydown",q),document.removeEventListener("focusin",F);const j=ue.at(-1)===M,W=ue.indexOf(M);if(W!==-1&&ue.splice(W,1),b(),j){const N=l.current;N?.isConnected&&!N.closest("[inert], [hidden]")?N.focus?.({preventScroll:!0}):ue.at(-1)?.querySelector("[role=dialog]")?.focus?.({preventScroll:!0})}}},[t]);const h=n.backgroundColor??n.backgroudColor,m=typeof h=="string"?h:h?.[v],c=typeof m=="string"&&/^(#|rgb\(|rgba\(|hsl\(|hsla\(|oklch\(|color\(|var\()/.test(m.trim())?m:null,L={sm:400,md:560,lg:720,xl:960,full:"100%"},E=["center","left","right","top","bottom"].includes(n.placement)?n.placement:"right",P=b=>typeof b=="number"?`${b}px`:b,B=P(n.width??L[n.size]??460),I=P(n.height),k=P(n.maxHeight),$=P(n.maxWidth),K=Number(n.viewportGap??5),G=Number.isFinite(K)?Math.max(0,K):5,S=typeof n.borderRadius=="number"?`${n.borderRadius}px`:n.borderRadius??"12px";return rt.createPortal(u.jsx("div",{ref:g,className:`pmn-overlay ${i?"pmn-exiting":"pmn-entering"} ${n.animation===!1?"pmn-no-animation":""} pmn-place-${E} ${n.mobileFullscreen?"pmn-mobile-fullscreen":""}`,style:{padding:G,"--pmn-animation-duration":`${Math.min(1e3,Math.max(0,Number(n.animationDuration??220)||0))}ms`},onMouseDown:b=>{b.target===b.currentTarget&&n.closeOnOverlay===!0&&f.current("overlay")},children:u.jsx("section",{ref:t,tabIndex:-1,role:"dialog","aria-modal":"true","aria-label":n.ariaLabel??"Dialog","data-modal-theme":v,className:`pmn-dialog ${v==="dark"?"dark":""} ${!c&&m?m:""} ${n.className??""}`,style:{"--pmn-width":B,"--pmn-gap":`${G}px`,...I!==void 0?{"--pmn-height":I}:{},...k!==void 0?{"--pmn-max-height":k}:{},...$!==void 0?{"--pmn-max-width":$}:{},borderRadius:S,...c?{backgroundColor:c}:{}},children:r})}),document.body)}function Ge({back:t}){return u.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",width:"20",height:"20",fill:"none",stroke:"currentColor",strokeWidth:"2",children:t?u.jsx("path",{d:"m15 18-6-6 6-6"}):u.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})}function pt({options:t,screen:n,route:o,navigation:r,requestClose:i,translate:g}){if(t.showHeader===!1)return null;const l=g??(h=>h),f=n.showTitle??t.showTitle??!0,d=typeof n.title=="function"?n.title({t:l,route:o,navigation:r}):n.title??o.name,x={route:o,navigation:r,close:i,canGoBack:r.canGoBack,title:d,t:l},R=n.renderHeader??t.renderHeader;if(R)return R(x);const v=n.renderHeaderRight??t.renderHeaderRight;return u.jsxs("header",{className:`pmn-header ${n.showHeaderBorder??t.showHeaderBorder?"pmn-border-bottom":""} ${t.headerClassName??""}`,children:[t.showBackButton!==!1&&r.canGoBack&&u.jsx("button",{type:"button",className:"pmn-icon-button","aria-label":l("modal.back"),onClick:()=>r.goBack(),children:u.jsx(Ge,{back:!0})}),f?u.jsx("h2",{children:d}):u.jsx("div",{className:"pmn-header-spacer"}),v?.(x),t.showCloseButton!==!1&&u.jsx("button",{type:"button",className:"pmn-icon-button","aria-label":l("modal.close"),onClick:()=>i("header"),children:u.jsx(Ge,{})})]})}function gt({screen:t,options:n,override:o,route:r,navigation:i,requestClose:g,translate:l,onError:f,loadingApi:d}){const[x,R]=e.useState(null),v=e.useRef(new Set),h=e.useRef(!0);e.useEffect(()=>(h.current=!0,()=>{h.current=!1}),[]);const m=l??(b=>b),c={...n,...t,...o},{showFooter:L,renderFooter:E,done:P,cancel:B,cancle:I}=c,k=B??I,$={route:r,navigation:i,close:g,t:m};if(L===!1)return null;const K=`pmn-footer ${c.showFooterBorder?"pmn-border-top":""} ${c.footerClassName??""}`;if(typeof E=="function")return u.jsx("footer",{className:K,children:E({...$,pending:v.current.size>0})});const G=Array.isArray(c.actions)?c.actions:null;if(!G&&typeof P!="function"&&typeof k!="function")return null;const S=async(b,M,q)=>{if(v.current.has(b)||typeof M!="function")return;v.current.add(b),R(b);const F=d?.begin(r.key,q??c.loadingText??m("modal.processing"));try{await M($)}catch(j){f?.(j,{phase:"footer",action:b,route:r})}finally{d?.end(r.key,F),v.current.delete(b),h.current&&R(j=>j===b?null:j)}};return G?u.jsx("footer",{className:K,children:G.filter(b=>!b.hidden).map(b=>{const M=v.current.has(b.key)||b.loading===!0;return u.jsx("button",{type:"button",disabled:b.disabled===!0||M,className:`pmn-button ${b.variant==="primary"||b.variant==="danger"?"pmn-button-primary":"pmn-button-secondary"} ${b.variant==="danger"?"pmn-button-danger":""}`,onClick:()=>S(b.key,b.onClick,b.loadingText),children:M?b.loadingText??c.loadingText??m("modal.processing"):b.label},b.key)})}):u.jsxs("footer",{className:K,children:[typeof k=="function"&&u.jsx("button",{type:"button",disabled:x!==null,onClick:()=>S("cancel",k),className:"pmn-button pmn-button-secondary",children:c.cancelText??m("modal.cancel")}),typeof P=="function"&&u.jsx("button",{type:"button",disabled:x!==null||c.doneDisabled===!0,onClick:()=>S("done",P),className:"pmn-button pmn-button-primary",children:x==="done"?c.loadingText??m("modal.processing"):c.doneText??m("modal.done")})]})}function ht({loading:t,translate:n}){if(!t.visible)return null;const r=(n??(g=>g))("modal.loading"),i=t.text??(r==="modal.loading"?"加载中...":r);return u.jsx("div",{className:"pmn-loading-overlay",role:"status","aria-live":"polite","aria-busy":"true",children:u.jsxs("div",{className:"pmn-loading-content",children:[u.jsx("span",{className:"pmn-spinner","aria-hidden":"true"}),i&&u.jsx("span",{className:"pmn-loading-text",children:i})]})})}class bt extends e.Component{state={error:null};static getDerivedStateFromError(n){return{error:n}}componentDidCatch(n,o){this.props.onError?.(n,{phase:"render",route:this.props.route,componentStack:o.componentStack})}componentDidUpdate(n){n.route?.key!==this.props.route?.key&&this.state.error&&this.setState({error:null})}render(){return this.state.error?u.jsxs("div",{role:"alert",className:"pmn-error-screen",children:[u.jsx("strong",{children:"页面加载失败"}),u.jsx("p",{children:this.state.error.message}),u.jsx("button",{type:"button",className:"pmn-button pmn-button-secondary",onClick:()=>this.setState({error:null}),children:"重试"})]}):this.props.children}}const xt={success:"✓",error:"×",warning:"!",info:"i"};function yt({items:t,dismiss:n}){return t.length?u.jsx("div",{className:"pmn-toast-region","aria-label":"Notifications",children:t.map(o=>u.jsxs("div",{className:`pmn-toast pmn-toast-${o.type}`,role:o.type==="error"||o.type==="warning"?"alert":"status",children:[u.jsx("span",{className:"pmn-toast-symbol","aria-hidden":"true",children:xt[o.type]}),u.jsx("span",{className:"pmn-toast-message",children:o.message}),o.dismissible&&u.jsx("button",{type:"button",className:"pmn-toast-close","aria-label":"Dismiss notification",onClick:()=>n(o.id),children:"×"})]},o.id))}):null}function vt(t,n){const o=e.useRef(0),r=e.useRef(new Map),i=e.useCallback(f=>{clearTimeout(r.current.get(f)),r.current.delete(f),n.current&&t.current.publish(t.current.getSnapshot().filter(d=>d.id!==f))},[]),g=e.useCallback((f,d={})=>{if(typeof f!="string"||!f.trim())throw new TypeError("[react-modal-navigation] toast message must be a non-empty string");const x=typeof d=="string"?{type:d}:d??{},R=["success","error","warning","info"].includes(x.type)?x.type:"info",v=++o.current,h=Number.isFinite(x.duration)?Math.max(0,x.duration):3e3;if(!n.current)return null;const m=t.current.getSnapshot(),c=m.slice(0,Math.max(0,m.length-4));for(const L of c)clearTimeout(r.current.get(L.id)),r.current.delete(L.id);return t.current.publish([...m.slice(-4),{id:v,message:f,type:R,dismissible:x.dismissible!==!1}]),h>0&&r.current.set(v,setTimeout(()=>i(v),h)),v},[i]),l=e.useMemo(()=>{const f=(d,x)=>g(d,x);for(const d of["success","error","warning","info"])f[d]=(x,R={})=>g(x,{...R,type:d});return f.promise=async(d,x,R={})=>{const v=g(x.loading,{...R,type:"info",duration:0});try{const h=await(typeof d=="function"?d():d);v!=null&&i(v);const m=typeof x.success=="function"?x.success(h):x.success;return m&&g(m,{...R,type:"success"}),h}catch(h){v!=null&&i(v);const m=typeof x.error=="function"?x.error(h):x.error;throw m&&g(m,{...R,type:"error"}),h}},f.dismiss=i,f.clear=()=>{for(const d of r.current.values())clearTimeout(d);r.current.clear(),t.current.publish([])},f},[g,i]);return e.useEffect(()=>()=>{for(const f of r.current.values())clearTimeout(f);r.current.clear()},[]),{toast:l,dismissToast:i}}function wt(t,n,o){const r=e.useRef(new Map),i=e.useRef(0),g=e.useCallback(()=>{if(!n.current)return;const h=[...r.current.values()],m={visible:h.length>0,text:h.at(-1)?.text??null,count:h.length},c=t.current.getSnapshot();(c.visible!==m.visible||c.text!==m.text||c.count!==m.count)&&t.current.publish(m)},[]),l=e.useCallback((h,m)=>{if(!n.current||h!=="global"&&o.current!==h)return null;const c=++i.current;return r.current.set(c,{owner:h,text:m}),g(),c},[g]),f=e.useCallback((h,m)=>{if(m!=null)r.current.get(m)?.owner===h&&r.current.delete(m);else for(const[c,L]of r.current)L.owner===h&&r.current.delete(c);g()},[g]),d=e.useCallback((h,m)=>{h?(f("global"),l("global",m)):f("global")},[l,f]),x=e.useCallback((h,m,c)=>{m?(f(h),l(h,c)):f(h)},[l,f]);return{loadingApi:e.useMemo(()=>({setLoading:d,setScreenLoading:x,begin:l,end:f}),[d,x,l,f]),refreshLoading:g,loadingTasks:r,setLoading:d}}const kt=e.memo(function({store:n,translate:o}){const r=e.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getSnapshot);return u.jsx(ht,{loading:r,translate:o})}),Ct=e.memo(function({store:n,dismiss:o}){const r=e.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getSnapshot);return u.jsx(yt,{items:r,dismiss:o})}),Rt=e.memo(function({store:n,routeKey:o,...r}){const i=e.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getSnapshot);return u.jsx(gt,{...r,override:i[o]})}),Et=e.memo(function({route:n,screen:o,navigation:r,focused:i,resultEvent:g,setFooter:l,loadingApi:f,loadingStore:d,bodyClassName:x,notifyError:R,registerDirtyGuard:v}){const h=o.component,m=e.useMemo(()=>({isFocused:i,resultEvent:g,routeKey:n.key,setFooter:l}),[i,g,n.key,l]),c=e.useMemo(()=>({setLoading:(E,P)=>f.setScreenLoading(n.key,E,P),showLoading:E=>f.begin(n.key,E),hideLoading:E=>f.end(n.key,E)}),[f,n.key]),L=e.useMemo(()=>({routeKey:n.key,registerDirtyGuard:v}),[n.key,v]);return u.jsx(Ve.Provider,{value:n,children:u.jsx(Ye.Provider,{value:L,children:u.jsx(Me.Provider,{value:m,children:u.jsx(je.Provider,{value:c,children:u.jsx(De.Provider,{value:d,children:u.jsx("div",{hidden:!i,inert:!i,"data-modal-route-key":n.key,tabIndex:-1,className:`pmn-body ${x??""}`,children:u.jsx(bt,{route:n,onError:R,children:u.jsx(h,{route:n,navigation:r})})})})})})})})});function Je({config:t,initialScreen:n,params:o,options:r,translate:i,onRequestClose:g,onOpened:l,registerLoading:f,notifyError:d,error:x,clearError:R,registerDirtyGuard:v,canNavigate:h,exiting:m=!1}){const[c,L]=e.useReducer(Ee,null,()=>Qe(n??t.initialRoute,o)),E=e.useRef(null);E.current||(E.current=ct({canGoBack:c.length>1,stack:c,currentRoute:c.at(-1)}));const P=e.useRef(null),B=e.useRef(null),I=e.useRef(null);P.current||(P.current=Pe({visible:!1,text:null,count:0})),B.current||(B.current=Pe({})),I.current||(I.current=Pe([]));const k=e.useRef(!0),$=e.useRef(0),{toast:K,dismissToast:G}=vt(I,k);e.useEffect(()=>(k.current=!0,()=>{k.current=!1,$.current++}),[]);const[S,b]=e.useState({}),M=e.useRef(new Map),q=e.useRef(null),F=e.useRef(null),j=e.useRef(!1),W=e.useRef(!1),N=e.useRef(new Map),Q=e.useRef(0),J=e.useCallback((a,y,T)=>{for(const[D,ne]of N.current)a.includes(ne.key)&&(N.current.delete(D),ne.resolve({status:y,...y==="returned"?{value:T}:{}}))},[]),A=e.useRef(c);A.current=c;const re=e.useRef(h);re.current=h;const X=e.useRef(!1),ge=e.useRef(0),z=c.at(-1),O=z.key,oe=e.useRef(O);oe.current=O;const{loadingApi:he,refreshLoading:be,loadingTasks:le,setLoading:se}=wt(P,k,oe),Z=t.screens,we=P,de=e.useRef(f);de.current=f,e.useEffect(()=>(de.current?.({setLoading:se}),()=>de.current?.(null)),[se]);const ke=e.useCallback((a,y)=>{if(!k.current)return;const T=B.current.getSnapshot();if(y===null){if(!(a in T))return;const D={...T};delete D[a],B.current.publish(D);return}T[a]!==y&&B.current.publish({...T,[a]:y})},[]),xe=e.useCallback(()=>{if(typeof document>"u")return;const a=document.activeElement;if(!(a instanceof HTMLElement)||!q.current?.contains(a))return;const y=a.closest("[data-modal-route-key]");y&&M.current.set(y.dataset.modalRouteKey,a),q.current.focus({preventScroll:!0})},[]),ye=e.useCallback(a=>{if(!Object.prototype.hasOwnProperty.call(Z,a))throw new Error(`[react-modal-navigation] Unknown modal screen: ${a}`)},[Z]),ae=e.useCallback((a,y)=>{try{Promise.resolve(r[a]?.(y)).catch(T=>d(T,{phase:a}))}catch(T){d(T,{phase:a})}},[r,d]),V=e.useCallback(async(a,y,T,D)=>{if(!k.current||W.current)return!1;const ne=$.current,_=A.current,Te=_.at(-1);if(a!=="BACK"&&ye(y),a==="BACK"&&_.length<=1)return!1;const ze=a==="NAVIGATE"?_.findIndex(pe=>pe.name===y):-1,Ne=a==="RESET"?_:a==="BACK"||a==="REPLACE"?[Te]:ze>=0?_.slice(ze+1):[];W.current=!0;try{if(Ne.length&&re.current&&!await re.current(Ne.map(Le=>Le.key),{reason:"navigation",action:a,from:Te,to:a==="BACK"?_.at(-2)?.name:y})||!k.current||ne!==$.current||A.current.at(-1)?.key!==Te.key)return!1;if(a==="BACK"&&D!==void 0){const Re=_.at(-2);b(Le=>({...Le,[Re.key]:{id:++ge.current,data:D}}))}a==="RESET"&&b({}),J(Ne.map(Re=>Re.key),a==="BACK"?"returned":"removed",D),xe();const pe={type:a,name:y,params:T};return A.current=Ee(A.current,pe),L(pe),!0}catch(pe){return k.current&&d(pe,{phase:"navigationGuard",action:a}),!1}finally{W.current=!1}},[ye,xe,d,J]),s=e.useCallback((a,y)=>V("NAVIGATE",a,y),[V]),p=e.useCallback(async(a,y)=>{if(!k.current)return{status:"cancelled"};if(A.current,!await V("NAVIGATE",a,y)||!k.current)return{status:"cancelled"};const D=A.current.at(-1);return!D||D.name!==a?{status:"cancelled"}:new Promise(ne=>{const _=++Q.current;N.current.set(_,{key:D.key,resolve:ne})})},[V]),C=e.useCallback((a,y)=>V("REPLACE",a,y),[V]),w=e.useCallback((a,y)=>V("RESET",a,y),[V]),H=e.useCallback(a=>{if(!a||typeof a!="object"||Array.isArray(a))throw new TypeError("[react-modal-navigation] setParams expects an object");if(!k.current)return;const y={type:"SET_PARAMS",params:a};A.current=Ee(A.current,y),L(y)},[]),U=e.useCallback(a=>{if(!a||typeof a!="object"||Array.isArray(a))throw new TypeError("[react-modal-navigation] setOptions expects an object");if(!k.current)return;const y={type:"SET_OPTIONS",options:a};A.current=Ee(A.current,y),L(y)},[]),Y=e.useCallback(a=>V("BACK",null,void 0,a),[V]),ee=e.useCallback((a,y)=>!k.current||we.current.getSnapshot().visible&&r.lockCloseWhileLoading!==!1?Promise.resolve(!1):g(a,y,{route:z,stack:c}),[r.lockCloseWhileLoading,g,z,c]),te=e.useRef(ee);te.current=ee;const ce=e.useCallback(a=>te.current("api",a),[]),me=e.useMemo(()=>({navigate:s,navigateAsync:p,replace:C,reset:w,setParams:H,setOptions:U,goBack:Y,close:ce,setLoading:se}),[s,p,C,w,H,U,Y,ce,se]),fe=e.useMemo(()=>({canGoBack:c.length>1,stack:c,currentRoute:z}),[c]);e.useLayoutEffect(()=>E.current.publish(fe),[fe]);const ie=e.useRef(null);ie.current||(ie.current=Object.defineProperties({},{canGoBack:{enumerable:!0,get:()=>E.current.getSnapshot().canGoBack},stack:{enumerable:!0,get:()=>E.current.getSnapshot().stack},currentRoute:{enumerable:!0,get:()=>E.current.getSnapshot().currentRoute}}));const Ce=e.useMemo(()=>Object.assign(ie.current,me),[me]);e.useLayoutEffect(()=>{j.current=!1;const a=[...q.current?.querySelectorAll("[data-modal-route-key]")??[]].find(D=>D.dataset.modalRouteKey===O);if(!a)return;const y=M.current.get(O);(y?.isConnected&&a.contains(y)&&!y.matches(":disabled")&&!y.closest("[inert], [hidden]")?y:a).focus({preventScroll:!0})},[O]),e.useEffect(()=>{let a=!1;for(const[T,D]of le.current)D.owner!=="global"&&D.owner!==O&&(le.current.delete(T),a=!0);a&&be();const y=new Set(c.map(T=>T.key));b(T=>{const D=Object.keys(T).filter(_=>!y.has(_));if(!D.length)return T;const ne={...T};return D.forEach(_=>delete ne[_]),ne});for(const T of M.current.keys())y.has(T)||M.current.delete(T)},[O,c,be]),e.useEffect(()=>{if(F.current?.key!==O){if(F.current){const a={from:F.current,to:z,stack:c};ae("onBlur",{route:F.current,...a}),ae("onNavigate",a),ae("onRouteChange",a)}ae("onFocus",{route:z,stack:c}),F.current=z}},[z,O,c,ae]),e.useEffect(()=>()=>{le.current.clear(),M.current.clear();for(const a of N.current.values())a.resolve({status:"dismissed"});N.current.clear()},[]),e.useEffect(()=>{X.current||(X.current=!0,l?.({route:z,stack:c}))},[]);const nt=e.useMemo(()=>ut(c,Z,r.maxCachedScreens),[c,Z,r.maxCachedScreens]),$e=e.useMemo(()=>({...Z[z.name],...z.options??{}}),[Z,z.name,z.options]);return u.jsx(_e.Provider,{value:K,children:u.jsx(st.Provider,{value:I.current,children:u.jsx(at.Provider,{value:B.current,children:u.jsx(ot.Provider,{value:Ce,children:u.jsx(Fe.Provider,{value:me,children:u.jsx(Oe.Provider,{value:E.current,children:u.jsx(je.Provider,{value:he,children:u.jsxs(ft,{dialogRef:q,options:r,requestClose:ee,exiting:m,children:[u.jsx(pt,{options:r,screen:$e,route:z,navigation:Ce,requestClose:ee,translate:i}),u.jsx("main",{className:"pmn-main",children:nt.map(a=>u.jsx(Et,{route:a,screen:Z[a.name],navigation:Ce,focused:a.key===O,resultEvent:S[a.key]??null,bodyClassName:r.bodyClassName,setFooter:ke,loadingApi:he,loadingStore:P.current,notifyError:d,registerDirtyGuard:v},a.key))}),u.jsx(Rt,{store:B.current,routeKey:O,screen:$e,options:r,route:z,navigation:Ce,requestClose:ee,translate:i,onError:d,loadingApi:he},O),u.jsx(kt,{store:P.current,translate:i}),u.jsx(Ct,{store:I.current,dismiss:G}),x&&u.jsxs("div",{className:"pmn-error",role:"alert",children:[u.jsx("span",{children:x.message||String(x)}),u.jsx("button",{type:"button",onClick:R,"aria-label":"Dismiss error",children:"×"})]})]})})})})})})})})}const St=".pmn-overlay,.pmn-dialog,.pmn-dialog *{box-sizing:border-box}.pmn-overlay{position:fixed;inset:0;z-index:1000;display:flex;overscroll-behavior:none;background:#00000073}.pmn-place-right{justify-content:flex-end;align-items:stretch}.pmn-place-left{justify-content:flex-start;align-items:stretch}.pmn-place-center{justify-content:center;align-items:center}.pmn-place-top{justify-content:center;align-items:flex-start}.pmn-place-bottom{justify-content:center;align-items:flex-end}.pmn-dialog{--pmn-surface:#fff;--pmn-body:#fff;--pmn-text:#0f172a;--pmn-muted:#475569;--pmn-border:#e2e8f0;--pmn-hover:#f1f5f9;--pmn-overlay-card:rgba(255,255,255,.92);color-scheme:light;position:relative;display:flex;flex-direction:column;min-height:0;width:100%;max-width:min(calc(100vw - var(--pmn-gap)*2),var(--pmn-max-width, var(--pmn-width)));max-height:min(calc(100dvh - var(--pmn-gap)*2),var(--pmn-max-height, 100dvh));height:var(--pmn-height, 100%);overflow:hidden;outline:none;box-shadow:0 25px 50px -12px #00000040;background:var(--pmn-surface);color:var(--pmn-text)}.pmn-place-left .pmn-dialog,.pmn-place-right .pmn-dialog{height:calc(100dvh - var(--pmn-gap)*2);max-height:calc(100dvh - var(--pmn-gap)*2)}.pmn-place-center .pmn-dialog{height:var(--pmn-height, auto);min-height:150px}.pmn-place-top .pmn-dialog,.pmn-place-bottom .pmn-dialog{height:var(--pmn-height, auto);min-height:0}.pmn-dialog[data-modal-theme=dark]{--pmn-surface:#334155;--pmn-body:#334155;--pmn-text:#f1f5f9;--pmn-muted:#cbd5e1;--pmn-border:#475569;--pmn-hover:#1e293b;--pmn-overlay-card:rgba(51,65,85,.94);color-scheme:dark}.pmn-main{min-height:0;flex:1;overflow:hidden;display:flex;flex-direction:column;background:transparent}.pmn-body{height:100%;min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:16px;flex:1}.pmn-body[hidden]{display:none!important}.pmn-header{display:flex;flex-shrink:0;height:64px;align-items:center;gap:12px;padding:0 20px;background:transparent}.pmn-header h2{font-size:18px;font-weight:600;min-width:0;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin:0}.pmn-header-spacer{flex:1}.pmn-border-bottom{border-bottom:1px solid var(--pmn-border)}.pmn-icon-button{display:inline-flex;align-items:center;justify-content:center;padding:8px;border:0;background:transparent;color:inherit;border-radius:8px;cursor:pointer}.pmn-icon-button:hover{background:var(--pmn-hover)}.pmn-footer{display:flex;flex-shrink:0;align-items:center;justify-content:flex-end;gap:12px;padding:16px 20px;background:transparent}.pmn-border-top{border-top:1px solid var(--pmn-border)}.pmn-button{padding:8px 16px;border-radius:8px;font-size:14px;font-weight:500;cursor:pointer}.pmn-button:disabled{opacity:.5;cursor:not-allowed}.pmn-button-secondary{border:1px solid var(--pmn-border);background:transparent;color:var(--pmn-text)}.pmn-button-secondary:hover:not(:disabled){background:var(--pmn-hover)}.pmn-button-primary{border:1px solid #2563eb;background:#2563eb;color:#fff}.pmn-button-primary:hover:not(:disabled){background:#1d4ed8}.pmn-loading-overlay{position:absolute;inset:0;z-index:50;display:flex;align-items:center;justify-content:center;background:#ffffffb8;backdrop-filter:blur(2px);-webkit-backdrop-filter:blur(2px);cursor:progress}.pmn-dialog[data-modal-theme=dark] .pmn-loading-overlay{background:#0f172ab8}.pmn-loading-content{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:14px;max-width:85%;text-align:center;color:var(--pmn-text);pointer-events:none}.pmn-loading-text{font-size:14px;font-weight:500;line-height:1.5;overflow-wrap:anywhere}.pmn-spinner{width:38px;height:38px;border:3px solid rgba(37,99,235,.2);border-top-color:#2563eb;border-radius:50%;animation:pmn-spin .8s linear infinite}@keyframes pmn-spin{to{transform:rotate(360deg)}}@media(prefers-reduced-motion:reduce){.pmn-spinner{animation-duration:1.8s}}.pmn-error{position:absolute;z-index:60;bottom:8px;left:12px;right:12px;display:flex;justify-content:space-between;gap:12px;padding:12px;border:1px solid #fca5a5;border-radius:8px;background:#fef2f2;color:#991b1b;font-size:13px}.pmn-error button{border:0;background:transparent;font-size:20px;cursor:pointer;color:inherit}.pmn-dialog input:not([type=checkbox]):not([type=radio]),.pmn-dialog textarea,.pmn-dialog select{color:var(--pmn-text);border-color:var(--pmn-border)}.pmn-error-screen{padding:24px;color:var(--pmn-text)}.pmn-error-screen p{color:#dc2626;overflow-wrap:anywhere}@media(max-width:640px){.pmn-overlay.pmn-mobile-fullscreen{padding:0!important}.pmn-mobile-fullscreen .pmn-dialog{max-width:100%;width:100%;height:100dvh;max-height:100dvh;border-radius:0!important}}@media(prefers-reduced-motion:reduce){.pmn-spinner{animation-duration:2s}}@keyframes pmn-fade-in{0%{opacity:0}to{opacity:1}}@keyframes pmn-fade-out{0%{opacity:1}to{opacity:0}}@keyframes pmn-scale-in{0%{opacity:0;transform:translateY(10px) scale(.97)}to{opacity:1;transform:none}}@keyframes pmn-scale-out{0%{opacity:1;transform:none}to{opacity:0;transform:translateY(10px) scale(.97)}}@keyframes pmn-right-in{0%{transform:translate(105%)}to{transform:none}}@keyframes pmn-right-out{0%{transform:none}to{transform:translate(105%)}}@keyframes pmn-left-in{0%{transform:translate(-105%)}to{transform:none}}@keyframes pmn-left-out{0%{transform:none}to{transform:translate(-105%)}}@keyframes pmn-top-in{0%{transform:translateY(-105%)}to{transform:none}}@keyframes pmn-top-out{0%{transform:none}to{transform:translateY(-105%)}}@keyframes pmn-bottom-in{0%{transform:translateY(105%)}to{transform:none}}@keyframes pmn-bottom-out{0%{transform:none}to{transform:translateY(105%)}}.pmn-entering{animation:pmn-fade-in var(--pmn-animation-duration) ease-out both}.pmn-exiting{animation:pmn-fade-out var(--pmn-animation-duration) ease-in both;pointer-events:none}.pmn-entering .pmn-dialog{animation:pmn-scale-in var(--pmn-animation-duration) cubic-bezier(.2,.8,.2,1) both}.pmn-exiting .pmn-dialog{animation:pmn-scale-out var(--pmn-animation-duration) ease-in both}.pmn-entering.pmn-place-right .pmn-dialog{animation-name:pmn-right-in}.pmn-exiting.pmn-place-right .pmn-dialog{animation-name:pmn-right-out}.pmn-entering.pmn-place-left .pmn-dialog{animation-name:pmn-left-in}.pmn-exiting.pmn-place-left .pmn-dialog{animation-name:pmn-left-out}.pmn-entering.pmn-place-top .pmn-dialog{animation-name:pmn-top-in}.pmn-exiting.pmn-place-top .pmn-dialog{animation-name:pmn-top-out}.pmn-entering.pmn-place-bottom .pmn-dialog{animation-name:pmn-bottom-in}.pmn-exiting.pmn-place-bottom .pmn-dialog{animation-name:pmn-bottom-out}.pmn-no-animation,.pmn-no-animation .pmn-dialog{animation:none!important}@media(prefers-reduced-motion:reduce){.pmn-entering,.pmn-exiting,.pmn-entering .pmn-dialog,.pmn-exiting .pmn-dialog{animation:none!important}}.pmn-toast-region{position:absolute;top:56px;left:12px;right:12px;z-index:80;display:flex;flex-direction:column;align-items:center;gap:8px;pointer-events:none;max-height:calc(100% - 72px);overflow:hidden}.pmn-toast{pointer-events:auto;display:flex;align-items:flex-start;gap:10px;width:max-content;max-width:100%;min-width:min(260px,100%);padding:11px 13px;border:1px solid var(--pmn-border);border-radius:9px;background:var(--pmn-surface);color:var(--pmn-text);box-shadow:0 5px 18px #0000001a;font-size:13px;line-height:1.5;overflow-wrap:anywhere}.pmn-toast-symbol{flex:0 0 20px;display:grid;place-items:center;width:20px;height:20px;border-radius:50%;font-size:13px;font-weight:700;background:var(--pmn-hover);color:var(--pmn-muted)}.pmn-toast-success .pmn-toast-symbol{background:#dcfce7;color:#15803d}.pmn-toast-error .pmn-toast-symbol{background:#fee2e2;color:#b91c1c}.pmn-toast-warning .pmn-toast-symbol{background:#fef3c7;color:#b45309}.pmn-toast-info .pmn-toast-symbol{background:#dbeafe;color:#1d4ed8}.pmn-toast-message{flex:1;min-width:0;white-space:pre-wrap}.pmn-toast-close{border:0;background:transparent;color:var(--pmn-muted);cursor:pointer;font-size:19px;line-height:18px;padding:0 1px}.pmn-toast-close:hover{color:var(--pmn-text)}.pmn-button-danger{background:#dc2626!important;color:#fff!important;border-color:#dc2626!important}",He="react-modal-navigation-styles",Ae=new WeakMap;function Mt(){e.useInsertionEffect(()=>{if(typeof document>"u")return;const t=document;let n=Ae.get(t);if(!n){let o=t.getElementById(He);const r=!o;o||(o=t.createElement("style"),o.id=He,o.setAttribute("data-react-modal-navigation",""),o.textContent=St,t.head.appendChild(o)),n={element:o,owned:r,count:0},Ae.set(t,n)}return n.count+=1,()=>{n.count-=1,n.count===0&&(n.owned&&n.element.remove(),Ae.delete(t))}},[])}function Se(t,n,o){if(typeof t=="string"){if(!t.trim())throw new TypeError("[react-modal-navigation] modal name must not be empty");return{name:t,params:n??{},options:o??{}}}if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError("[react-modal-navigation] open expects a modal name or a configuration object");const{name:r,screen:i,params:g={},options:l={},...f}=t;if(typeof r!="string"||!r.trim())throw new TypeError("[react-modal-navigation] open config requires a non-empty string name");if(l===null||typeof l!="object"||Array.isArray(l))throw new TypeError("[react-modal-navigation] open config options must be an object");if(i!==void 0&&(typeof i!="string"||!i.trim()))throw new TypeError("[react-modal-navigation] screen must be a non-empty string");return{name:r,...i===void 0?{}:{screen:i},params:g,options:{...f,...l}}}const jt={placement:"right",showHeader:!0,showBackButton:!0,showCloseButton:!0,viewportGap:5,borderRadius:12,closeOnOverlay:!1,closeOnEsc:!0},Tt=t=>({"modal.loading":"加载中...","modal.processing":"处理中...","modal.back":"返回","modal.close":"关闭","modal.cancel":"取消","modal.done":"完成"})[t]??t;function Nt({registry:t,children:n,defaultOptions:o={},backgroundColor:r,theme:i,translate:g=Tt,onError:l,confirmDiscard:f}){Mt();const[d,x]=e.useState(null),[R,v]=e.useState(null),[h,m]=e.useState(0),c=e.useRef(null),L=e.useRef(new Map),E=e.useRef([]),P=e.useRef(null),B=e.useRef(null),I=e.useRef(0),k=e.useRef(null),$=e.useRef(!1),K=e.useRef(0),G=e.useRef(null),S=e.useRef(new Map),[b,M]=e.useState(!1),q=e.useRef(f);q.current=f;const F=e.useCallback((s,p)=>(S.current.set(s,p),()=>{S.current.get(s)===p&&S.current.delete(s)}),[]),j=e.useCallback(async s=>{for(const p of S.current.values()){if(!p.dirty)continue;if((p.onBeforeDiscard?await p.onBeforeDiscard(s):q.current?await q.current(s):typeof window<"u"&&typeof window.confirm=="function"?window.confirm(p.message||"有未保存的修改,确定放弃吗?"):!1)===!1)return!1}return!0},[]),W=e.useCallback(async(s,p)=>{for(const C of s){const w=S.current.get(C);if(!w?.dirty)continue;if((w.onBeforeDiscard?await w.onBeforeDiscard(p):q.current?await q.current(p):typeof window<"u"&&typeof window.confirm=="function"?window.confirm(w.message||"有未保存的修改,确定放弃吗?"):!1)===!1)return!1}return!0},[]),N=e.useRef(!0),Q=e.useRef(null),J=e.useRef(l);J.current=l;const A=e.useCallback((s,p)=>{N.current&&v(s);try{J.current?J.current(s,p):console.error("[react-modal-navigation]",s)}catch(C){console.error("[react-modal-navigation] onError failed",C)}},[]),re=e.useCallback((s,p)=>{const C=L.current.get(s);L.current.delete(s),C?.(p)},[]),X=e.useCallback(s=>({...jt,...o,...i!==void 0?{theme:i}:{},...r!==void 0?{backgroundColor:r}:{},...s.config.modalOptions,...s.overrides}),[o,i,r]),ge=d?X(d):null,z=e.useRef(null);z.current=ge,Q.current=ge;const O=e.useCallback(async(s="api",p,C={})=>{const w=c.current;if(!w||k.current||$.current)return!1;k.current=w.id,$.current=!0;const H=Q.current??X(w),U={...C,reason:s,result:p,name:w.name};try{if(!await j(U)||await H.onBeforeClose?.(U)===!1||c.current?.id!==w.id||!N.current||(M(!0),await new Promise(Y=>{const ee=H.animation===!1||typeof window<"u"&&window.matchMedia?.("(prefers-reduced-motion: reduce)").matches?0:Math.max(0,Number(H.animationDuration??220)||0);setTimeout(Y,Math.min(ee,1e3))}),!N.current||c.current?.id!==w.id))return!1;c.current=null,G.current=null,x(null),M(!1),S.current.clear(),re(w.id,C.confirmed||p!==void 0?{status:"confirmed",value:p,reason:s}:{status:"dismissed",reason:s});try{await H.onClose?.(U)}catch(Y){A(Y,{phase:"onClose",name:w.name})}return!0}catch(Y){return A(Y,{phase:"onBeforeClose",name:w.name}),!1}finally{k.current===w.id&&(k.current=null),$.current=!1,!c.current&&N.current&&queueMicrotask(()=>B.current?.())}},[X,A,re,j]),oe=e.useCallback(async(s,p={},C={},w,H)=>{const U=t?.[s];if(!U)throw new Error(`[react-modal-navigation] Unknown modal: ${s}`);const Y=H??U.initialRoute;if(!U.screens?.[Y])throw new Error(`[react-modal-navigation] Unknown initial screen '${Y}' in modal '${s}'`);if(!N.current||$.current||k.current)return null;$.current=!0;const ee=K.current;try{const te=c.current;if(te){const me=Q.current??X(te),fe={reason:"replace",name:te.name,nextName:s};try{if(!await j(fe)||await me.onBeforeClose?.(fe)===!1)return null}catch(ie){return A(ie,{phase:"onBeforeClose",name:te.name}),null}if(!N.current||ee!==K.current||c.current?.id!==te.id)return null;c.current=null,G.current=null,x(null),S.current.clear(),re(te.id,{status:"replaced",reason:"replace"});try{await me.onClose?.(fe)}catch(ie){A(ie,{phase:"onClose",name:te.name})}if(!N.current||ee!==K.current)return null}const ce={id:++I.current,name:s,screen:Y,params:p,config:U,overrides:C};return c.current=ce,G.current=null,w&&L.current.set(ce.id,w),v(null),x(ce),ce.id}finally{$.current=!1}},[t,X,A,re,j]);P.current=oe;const he=e.useCallback(async()=>{if(!N.current||c.current||$.current||k.current)return;const s=E.current.shift();if(s){m(E.current.length);try{const p=await P.current(s.args.name,s.args.params,s.args.options,s.resolveResult,s.args.screen);p===null?(s.resolveResult?.({status:"dismissed",reason:"blocked"}),s.resolveId?.(null),queueMicrotask(()=>B.current?.())):s.resolveId?.(p)}catch(p){s.reject?.(p),queueMicrotask(()=>B.current?.())}}},[]);B.current=he;const be=e.useCallback((s,p,C)=>{const w=Se(s,p,C);return t?.[w.name]?new Promise((H,U)=>{E.current.push({args:w,resolveId:H,reject:U}),m(E.current.length),queueMicrotask(()=>B.current?.())}):Promise.reject(new Error(`[react-modal-navigation] Unknown modal: ${w.name}`))},[t]),le=e.useCallback((s,p,C)=>{const w=Se(s,p,C);return t?.[w.name]?new Promise((H,U)=>{E.current.push({args:w,resolveResult:H,reject:U}),m(E.current.length),queueMicrotask(()=>B.current?.())}):Promise.reject(new Error(`[react-modal-navigation] Unknown modal: ${w.name}`))},[t]),se=e.useCallback(s=>{if(!s||typeof s!="object"||Array.isArray(s))throw new TypeError("[react-modal-navigation] update expects an options object");const p=c.current;if(!p||$.current)return!1;const C={...p,overrides:{...p.overrides,...s}};return c.current=C,x(C),Q.current=X(C),!0},[X]),Z=e.useCallback((s="queue-cleared")=>{const p=E.current.splice(0);m(0);for(const C of p)C.resolveId?.(null),C.resolveResult?.({status:"dismissed",reason:s});return p.length},[]),we=e.useCallback((s,p,C)=>{const w=Se(s,p,C);return oe(w.name,w.params,w.options,void 0,w.screen)},[oe]),de=e.useCallback((s,p,C)=>{const w=Se(s,p,C);return new Promise((H,U)=>{oe(w.name,w.params,w.options,H,w.screen).then(Y=>{Y===null&&H({status:"dismissed",reason:"blocked"})},U)})},[oe]),ke=e.useCallback(s=>O("api",s),[O]),xe=e.useCallback((s="api")=>O(s),[O]),ye=e.useCallback(s=>O("confirm",s,{confirmed:!0}),[O]),ae=e.useCallback((s,p)=>G.current?.setLoading(s,p),[]),V=e.useMemo(()=>({open:we,openAsync:de,enqueue:be,enqueueAsync:le,update:se,clearQueue:Z,close:ke,dismiss:xe,confirm:ye,setLoading:ae,queueSize:h,isOpen:!!d,activeName:d?.name??null,error:R,clearError:()=>v(null)}),[we,de,be,le,se,Z,ke,xe,ye,ae,d,R,h]);return e.useEffect(()=>(N.current=!0,()=>{N.current=!1,K.current+=1,c.current=null;for(const p of L.current.values())p({status:"dismissed",reason:"unmount"});L.current.clear(),S.current.clear();const s=E.current.splice(0);for(const p of s)p.resolveId?.(null),p.resolveResult?.({status:"dismissed",reason:"unmount"})}),[]),u.jsxs(We.Provider,{value:V,children:[n,d&&u.jsx(Je,{config:d.config,initialScreen:d.screen,params:d.params,options:ge,translate:g,notifyError:A,error:R,clearError:()=>v(null),registerLoading:s=>{G.current=s},registerDirtyGuard:F,canNavigate:W,exiting:b,onRequestClose:O,onOpened:s=>{try{const p=z.current?.onOpen?.(s);Promise.resolve(p).catch(C=>A(C,{phase:"onOpen"}))}catch(p){A(p,{phase:"onOpen"})}}},d.id)]})}const Lt=Object.freeze({canGoBack:!1,stack:[],currentRoute:null}),Pt=()=>()=>{},Ue=()=>Lt;function Bt(){const t=e.useContext(We),n=e.useContext(Fe),o=e.useContext(Oe),r=e.useSyncExternalStore(o?.subscribe??Pt,o?.getSnapshot??Ue,o?.getSnapshot??Ue);if(!t)throw new Error("[react-modal-navigation] useModal requires <ModalProvider>");const i=e.useMemo(()=>{const g=()=>{if(!n)throw new Error("[react-modal-navigation] navigation requires an active modal screen; use modal.open() outside a modal");return n};return{navigate:(...l)=>g().navigate(...l),replace:(...l)=>g().replace(...l),reset:(...l)=>g().reset(...l),setParams:(...l)=>g().setParams(...l),setOptions:(...l)=>g().setOptions(...l),goBack:(...l)=>g().goBack(...l),close:(...l)=>g().close(...l),setLoading:(...l)=>g().setLoading(...l),canGoBack:r.canGoBack,stack:r.stack,currentRoute:r.currentRoute}},[n,r]);return e.useMemo(()=>({...t,modal:t,navigation:i}),[t,i])}function Xe(){const t=e.useContext(Fe);if(!t)throw new Error("useModalNavigationCommands requires an active modal screen");return t}function Ze(){const t=e.useContext(Oe);if(!t)throw new Error("useModalNavigationState requires an active modal screen");return e.useSyncExternalStore(t.subscribe,t.getSnapshot,t.getSnapshot)}function At(){const t=Xe(),n=Ze();return e.useMemo(()=>({...t,...n}),[t,n])}function Ie(){const t=e.useContext(Me);if(!t)throw new Error("useIsFocused must be called inside a modal screen");return t.isFocused}function qt(t){const n=Ie();e.useEffect(()=>{if(n)return t()},[n,t])}function Ft(t){const n=e.useContext(Me);if(!n)throw new Error("useNavigationResult requires an active modal screen");const o=e.useRef(t),r=e.useRef(null);e.useEffect(()=>{o.current=t},[t]),e.useEffect(()=>{!n.isFocused||!n.resultEvent||r.current!==n.resultEvent.id&&(r.current=n.resultEvent.id,o.current(n.resultEvent.data))},[n.isFocused,n.resultEvent])}function Ot(t={}){const n=e.useContext(Me);if(!n)throw new Error("[react-modal-navigation] useModalFooter requires an active modal screen");const{setFooter:o,routeKey:r}=n,i=e.useRef(t);i.current=t;const g=e.useMemo(()=>(...S)=>i.current.done?.(...S),[]),l=e.useMemo(()=>(...S)=>(i.current.cancel??i.current.cancle)?.(...S),[]),f=e.useMemo(()=>(...S)=>i.current.renderFooter?.(...S),[]),d=typeof t.done=="function",x=typeof(t.cancel??t.cancle)=="function",R=typeof t.renderFooter=="function",{showFooter:v,showFooterBorder:h,doneDisabled:m,doneText:c,cancelText:L,loadingText:E,footerClassName:P}=t,B=e.useRef({source:null,normalized:void 0}),I=Array.isArray(t.actions)?t.actions:null,k=B.current.source;I===k||I&&k&&I.length===k.length&&I.every((S,b)=>{const M=k[b];return[...new Set([...Object.keys(S),...Object.keys(M)])].every(F=>F==="onClick"||Object.is(S[F],M[F]))})||(B.current={source:I?.map(S=>({...S}))??null,normalized:I?.map((S,b)=>({...S,onClick:(...M)=>(i.current.actions?.find(F=>F.key===S.key)??i.current.actions?.[b])?.onClick?.(...M)}))});const K=B.current.normalized,G=e.useMemo(()=>({showFooter:v,showFooterBorder:h,doneDisabled:m,doneText:c,cancelText:L,loadingText:E,footerClassName:P,...K!==void 0?{actions:K}:{},...d?{done:g}:{},...x?{cancel:l}:{},...R?{renderFooter:f}:{}}),[v,h,m,c,L,E,P,K,d,x,R,g,l,f]);e.useEffect(()=>{o(r,G)},[r,o,G]),e.useEffect(()=>()=>o(r,null),[r,o])}function et(){const t=e.useContext(je),n=e.useContext(De);if(!t||!n)throw new Error("[react-modal-navigation] useModalLoading requires an active modal screen");const o=e.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getSnapshot);return e.useMemo(()=>({...t,isLoading:o.visible}),[t,o.visible])}function Dt(){const t=e.useContext(je);if(!t)throw new Error("[react-modal-navigation] useModalLoadingCommands requires an active modal screen");return t}function It(){const t=e.useContext(De);if(!t)throw new Error("[react-modal-navigation] useModalLoadingState requires an active modal screen");return e.useSyncExternalStore(t.subscribe,t.getSnapshot,t.getSnapshot)}function $t(){const t=et(),n=Ie(),o=e.useRef(!0),r=e.useRef(!1),[i,g]=e.useState(!1),[l,f]=e.useState(null),d=e.useRef(t);return d.current=t,e.useEffect(()=>(o.current=!0,()=>{o.current=!1}),[]),{run:e.useCallback(async(R,v={})=>{if(r.current)return{status:"busy"};if(typeof R!="function")throw new TypeError("[react-modal-navigation] run requires a function");r.current=!0,o.current&&(g(!0),f(null));const h=d.current.showLoading(v.loadingText);try{const m=await R();return o.current&&await v.onSuccess?.(m),{status:"success",value:m}}catch(m){if(o.current){f(m);try{await v.onError?.(m)}catch(c){console.error("[react-modal-navigation] onError failed",c)}}if(v.throwOnError)throw m;return{status:"error",error:m}}finally{h!=null&&d.current.hideLoading(h),r.current=!1,o.current&&g(!1)}},[]),pending:i,error:l,clearError:()=>f(null),isFocused:n}}function zt(t,n={}){const o=e.useContext(Ye);if(!o)throw new Error("[react-modal-navigation] useModalUnsavedChanges must be used inside a modal screen");const r=e.useRef({dirty:t,...n});r.current={dirty:t,...n};const{routeKey:i,registerDirtyGuard:g}=o;e.useEffect(()=>g(i,{get dirty(){return!!r.current.dirty},get message(){return r.current.message},get onBeforeDiscard(){return r.current.onBeforeDiscard}}),[i,g])}const Kt=()=>{const t=e.useContext(_e);if(!t)throw new Error("[react-modal-navigation] useToast requires an active modal");return t};function tt(){const t=e.useContext(Ve);if(!t)throw new Error("[react-modal-navigation] useModalRoute requires a modal screen");return t}function Gt(){return tt().params}exports.ModalNavigator=Je;exports.ModalProvider=Nt;exports.useFocusEffect=qt;exports.useIsFocused=Ie;exports.useModal=Bt;exports.useModalFooter=Ot;exports.useModalLoading=et;exports.useModalLoadingCommands=Dt;exports.useModalLoadingState=It;exports.useModalNavigation=At;exports.useModalNavigationCommands=Xe;exports.useModalNavigationState=Ze;exports.useModalParams=Gt;exports.useModalRoute=tt;exports.useModalTask=$t;exports.useModalUnsavedChanges=zt;exports.useNavigationResult=Ft;exports.useToast=Kt;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react/jsx-runtime"),e=require("react"),rt=require("react-dom"),We=e.createContext(null),ot=e.createContext(null),Me=e.createContext(null),je=e.createContext(null),Ye=e.createContext(null),_e=e.createContext(null),Fe=e.createContext(null),Oe=e.createContext(null),De=e.createContext(null),at=e.createContext(null),st=e.createContext(null),Ve=e.createContext(null);function ct(t){let n=t;const o=new Set;return{getSnapshot:()=>n,subscribe:r=>(o.add(r),()=>o.delete(r)),publish(r){if(n!==r){n=r;for(const i of[...o])i()}},listenerCount:()=>o.size}}function Pe(t){let n=t;const o=new Set;return{getSnapshot:()=>n,subscribe:r=>(o.add(r),()=>o.delete(r)),publish(r){if(!Object.is(n,r)){n=r;for(const i of[...o])i()}},listenerCount:()=>o.size}}let it=0;const qe=(t,n)=>({key:`modal-route-${++it}`,name:t,params:n??{}}),Qe=(t,n)=>[qe(t,n)];function Ee(t,n){switch(n.type){case"RESET":return Qe(n.name,n.params);case"NAVIGATE":{const o=t.findIndex(r=>r.name===n.name);return o<0?[...t,qe(n.name,n.params)]:t.slice(0,o+1).map((r,i)=>i===o?{...r,params:n.params??{}}:r)}case"SET_OPTIONS":return t.map((o,r)=>r===t.length-1?{...o,options:{...o.options??{},...n.options??{}}}:o);case"SET_PARAMS":return t.map((o,r)=>r===t.length-1?{...o,params:{...o.params??{},...n.params??{}}}:o);case"BACK":return t.length>1?t.slice(0,-1):t;case"REPLACE":return t.length?[...t.slice(0,-1),qe(n.name,n.params)]:t;default:return t}}function ut(t,n,o=1/0){const r=o===1/0?1/0:Math.max(0,Math.floor(Number(o)||0)),i=t.slice(0,-1).filter(d=>n[d.name]?.keepAlive!==!1),g=new Set((r===0?[]:i.slice(-r)).map(d=>d.key));return t.filter((d,m)=>m===t.length-1||g.has(d.key))}const Ke=()=>{if(typeof document>"u")return"light";const t=document.documentElement,n=document.body;return t.classList.contains("dark")||n.classList.contains("dark")||t.dataset.theme==="dark"||n.dataset.theme==="dark"?"dark":t.classList.contains("light")||n.classList.contains("light")||t.dataset.theme==="light"||n.dataset.theme==="light"?"light":window.matchMedia?.("(prefers-color-scheme: dark)").matches?"dark":"light"};let ve=0;const ue=[];let Be=null;function lt(){if(ve++,ve===1){const n=document.documentElement,o=document.body,r={html:n.style.overflow,body:o.style.overflow,padding:o.style.paddingRight,width:o.style.getPropertyValue("--modal-scrollbar-width")},i=Math.max(0,window.innerWidth-n.clientWidth),g=parseFloat(getComputedStyle(o).paddingRight)||0;i&&(o.style.paddingRight=`${g+i}px`),o.style.setProperty("--modal-scrollbar-width",`${i}px`),n.style.overflow="hidden",o.style.overflow="hidden",Be=()=>{n.style.overflow=r.html,o.style.overflow=r.body,o.style.paddingRight=r.padding,r.width?o.style.setProperty("--modal-scrollbar-width",r.width):o.style.removeProperty("--modal-scrollbar-width")}}let t=!1;return()=>{t||(t=!0,ve=Math.max(0,ve-1),ve||(Be?.(),Be=null))}}const dt='a[href],button:not([disabled]),input:not([disabled]),textarea:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])',mt=t=>!t.closest('[inert], [hidden], [aria-hidden="true"]')&&t.getClientRects().length>0&&getComputedStyle(t).visibility!=="hidden"&&getComputedStyle(t).display!=="none";function ft({dialogRef:t,options:n,requestClose:o,children:r,exiting:i=!1}){const g=e.useRef(null),d=e.useRef(null),m=e.useRef(o);m.current=o;const f=e.useRef(n.closeOnEsc);f.current=n.closeOnEsc;const[x,R]=e.useState(Ke),y=n.theme==="light"||n.theme==="dark"?n.theme:x;e.useEffect(()=>{if(n.theme==="light"||n.theme==="dark")return;const b=()=>R(Ke()),M=new MutationObserver(b);for(const F of[document.documentElement,document.body])M.observe(F,{attributes:!0,attributeFilter:["class","data-theme"]});const q=window.matchMedia?.("(prefers-color-scheme: dark)");return q?.addEventListener?.("change",b),b(),()=>{M.disconnect(),q?.removeEventListener?.("change",b)}},[n.theme]),e.useEffect(()=>{d.current=document.activeElement;const b=lt(),M=g.current;ue.push(M),t.current?.focus({preventScroll:!0});const q=j=>{const W=t.current;if(!W||ue.at(-1)!==M)return;if(j.key==="Escape"&&f.current!==!1){j.preventDefault(),m.current("escape");return}if(j.key!=="Tab")return;const N=[...W.querySelectorAll(dt)].filter(mt);if(!N.length){j.preventDefault(),W.focus();return}const Q=N[0],J=N.at(-1);W.contains(document.activeElement)?j.shiftKey&&(document.activeElement===Q||document.activeElement===W)?(j.preventDefault(),J.focus()):!j.shiftKey&&(document.activeElement===J||document.activeElement===W)&&(j.preventDefault(),Q.focus()):(j.preventDefault(),(j.shiftKey?J:Q).focus())},F=j=>{ue.at(-1)===M&&t.current&&!t.current.contains(j.target)&&t.current.focus({preventScroll:!0})};return document.addEventListener("keydown",q),document.addEventListener("focusin",F),()=>{document.removeEventListener("keydown",q),document.removeEventListener("focusin",F);const j=ue.at(-1)===M,W=ue.indexOf(M);if(W!==-1&&ue.splice(W,1),b(),j){const N=d.current;N?.isConnected&&!N.closest("[inert], [hidden]")?N.focus?.({preventScroll:!0}):ue.at(-1)?.querySelector("[role=dialog]")?.focus?.({preventScroll:!0})}}},[t]);const h=n.backgroundColor??n.backgroudColor,l=typeof h=="string"?h:h?.[y],c=typeof l=="string"&&/^(#|rgb\(|rgba\(|hsl\(|hsla\(|oklch\(|color\(|var\()/.test(l.trim())?l:null,L={sm:400,md:560,lg:720,xl:960,full:"100%"},E=["center","left","right","top","bottom"].includes(n.placement)?n.placement:"right",P=b=>typeof b=="number"?`${b}px`:b,B=P(n.width??L[n.size]??460),I=P(n.height),k=P(n.maxHeight),$=P(n.maxWidth),K=Number(n.viewportGap??5),G=Number.isFinite(K)?Math.max(0,K):5,S=typeof n.borderRadius=="number"?`${n.borderRadius}px`:n.borderRadius??"12px";return rt.createPortal(u.jsx("div",{ref:g,className:`pmn-overlay ${i?"pmn-exiting":"pmn-entering"} ${n.animation===!1?"pmn-no-animation":""} pmn-place-${E} ${n.mobileFullscreen?"pmn-mobile-fullscreen":""}`,style:{padding:G,"--pmn-animation-duration":`${Math.min(1e3,Math.max(0,Number(n.animationDuration??220)||0))}ms`},onMouseDown:b=>{b.target===b.currentTarget&&n.closeOnOverlay===!0&&m.current("overlay")},children:u.jsx("section",{ref:t,tabIndex:-1,role:"dialog","aria-modal":"true","aria-label":n.ariaLabel??"Dialog","data-modal-theme":y,className:`pmn-dialog ${y==="dark"?"dark":""} ${!c&&l?l:""} ${n.className??""}`,style:{"--pmn-width":B,"--pmn-gap":`${G}px`,...I!==void 0?{"--pmn-height":I}:{},...k!==void 0?{"--pmn-max-height":k}:{},...$!==void 0?{"--pmn-max-width":$}:{},borderRadius:S,...c?{backgroundColor:c}:{}},children:r})}),document.body)}function Ge({back:t}){return u.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",width:"20",height:"20",fill:"none",stroke:"currentColor",strokeWidth:"2",children:t?u.jsx("path",{d:"m15 18-6-6 6-6"}):u.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})}function pt({options:t,screen:n,route:o,navigation:r,requestClose:i,translate:g,canGoBack:d}){if(t.showHeader===!1)return null;const m=g??(l=>l),f=n.showTitle??t.showTitle??!0,x=typeof n.title=="function"?n.title({t:m,route:o,navigation:r}):n.title??o.name,R={route:o,navigation:r,close:i,canGoBack:d,title:x,t:m},y=n.renderHeader??t.renderHeader;if(y)return y(R);const h=n.renderHeaderRight??t.renderHeaderRight;return u.jsxs("header",{className:`pmn-header ${n.showHeaderBorder??t.showHeaderBorder?"pmn-border-bottom":""} ${t.headerClassName??""}`,children:[(n.showBackButton??t.showBackButton)!==!1&&d&&u.jsx("button",{type:"button",className:"pmn-icon-button","aria-label":m("modal.back"),onClick:()=>r.goBack(),children:u.jsx(Ge,{back:!0})}),f?u.jsx("h2",{children:x}):u.jsx("div",{className:"pmn-header-spacer"}),h?.(R),t.showCloseButton!==!1&&u.jsx("button",{type:"button",className:"pmn-icon-button","aria-label":m("modal.close"),onClick:()=>i("header"),children:u.jsx(Ge,{})})]})}function gt({screen:t,options:n,override:o,route:r,navigation:i,requestClose:g,translate:d,onError:m,loadingApi:f}){const[x,R]=e.useState(null),y=e.useRef(new Set),h=e.useRef(!0);e.useEffect(()=>(h.current=!0,()=>{h.current=!1}),[]);const l=d??(b=>b),c={...n,...t,...o},{showFooter:L,renderFooter:E,done:P,cancel:B,cancle:I}=c,k=B??I,$={route:r,navigation:i,close:g,t:l};if(L===!1)return null;const K=`pmn-footer ${c.showFooterBorder?"pmn-border-top":""} ${c.footerClassName??""}`;if(typeof E=="function")return u.jsx("footer",{className:K,children:E({...$,pending:y.current.size>0})});const G=Array.isArray(c.actions)?c.actions:null;if(!G&&typeof P!="function"&&typeof k!="function")return null;const S=async(b,M,q)=>{if(y.current.has(b)||typeof M!="function")return;y.current.add(b),R(b);const F=f?.begin(r.key,q??c.loadingText??l("modal.processing"));try{await M($)}catch(j){m?.(j,{phase:"footer",action:b,route:r})}finally{f?.end(r.key,F),y.current.delete(b),h.current&&R(j=>j===b?null:j)}};return G?u.jsx("footer",{className:K,children:G.filter(b=>!b.hidden).map(b=>{const M=y.current.has(b.key)||b.loading===!0;return u.jsx("button",{type:"button",disabled:b.disabled===!0||M,className:`pmn-button ${b.variant==="primary"||b.variant==="danger"?"pmn-button-primary":"pmn-button-secondary"} ${b.variant==="danger"?"pmn-button-danger":""}`,onClick:()=>S(b.key,b.onClick,b.loadingText),children:M?b.loadingText??c.loadingText??l("modal.processing"):b.label},b.key)})}):u.jsxs("footer",{className:K,children:[typeof k=="function"&&u.jsx("button",{type:"button",disabled:x!==null,onClick:()=>S("cancel",k),className:"pmn-button pmn-button-secondary",children:c.cancelText??l("modal.cancel")}),typeof P=="function"&&u.jsx("button",{type:"button",disabled:x!==null||c.doneDisabled===!0,onClick:()=>S("done",P),className:"pmn-button pmn-button-primary",children:x==="done"?c.loadingText??l("modal.processing"):c.doneText??l("modal.done")})]})}function ht({loading:t,translate:n}){if(!t.visible)return null;const r=(n??(g=>g))("modal.loading"),i=t.text??(r==="modal.loading"?"加载中...":r);return u.jsx("div",{className:"pmn-loading-overlay",role:"status","aria-live":"polite","aria-busy":"true",children:u.jsxs("div",{className:"pmn-loading-content",children:[u.jsx("span",{className:"pmn-spinner","aria-hidden":"true"}),i&&u.jsx("span",{className:"pmn-loading-text",children:i})]})})}class bt extends e.Component{state={error:null};static getDerivedStateFromError(n){return{error:n}}componentDidCatch(n,o){this.props.onError?.(n,{phase:"render",route:this.props.route,componentStack:o.componentStack})}componentDidUpdate(n){n.route?.key!==this.props.route?.key&&this.state.error&&this.setState({error:null})}render(){return this.state.error?u.jsxs("div",{role:"alert",className:"pmn-error-screen",children:[u.jsx("strong",{children:"页面加载失败"}),u.jsx("p",{children:this.state.error.message}),u.jsx("button",{type:"button",className:"pmn-button pmn-button-secondary",onClick:()=>this.setState({error:null}),children:"重试"})]}):this.props.children}}const xt={success:"✓",error:"×",warning:"!",info:"i"};function yt({items:t,dismiss:n}){return t.length?u.jsx("div",{className:"pmn-toast-region","aria-label":"Notifications",children:t.map(o=>u.jsxs("div",{className:`pmn-toast pmn-toast-${o.type}`,role:o.type==="error"||o.type==="warning"?"alert":"status",children:[u.jsx("span",{className:"pmn-toast-symbol","aria-hidden":"true",children:xt[o.type]}),u.jsx("span",{className:"pmn-toast-message",children:o.message}),o.dismissible&&u.jsx("button",{type:"button",className:"pmn-toast-close","aria-label":"Dismiss notification",onClick:()=>n(o.id),children:"×"})]},o.id))}):null}function vt(t,n){const o=e.useRef(0),r=e.useRef(new Map),i=e.useCallback(m=>{clearTimeout(r.current.get(m)),r.current.delete(m),n.current&&t.current.publish(t.current.getSnapshot().filter(f=>f.id!==m))},[]),g=e.useCallback((m,f={})=>{if(typeof m!="string"||!m.trim())throw new TypeError("[react-modal-navigation] toast message must be a non-empty string");const x=typeof f=="string"?{type:f}:f??{},R=["success","error","warning","info"].includes(x.type)?x.type:"info",y=++o.current,h=Number.isFinite(x.duration)?Math.max(0,x.duration):3e3;if(!n.current)return null;const l=t.current.getSnapshot(),c=l.slice(0,Math.max(0,l.length-4));for(const L of c)clearTimeout(r.current.get(L.id)),r.current.delete(L.id);return t.current.publish([...l.slice(-4),{id:y,message:m,type:R,dismissible:x.dismissible!==!1}]),h>0&&r.current.set(y,setTimeout(()=>i(y),h)),y},[i]),d=e.useMemo(()=>{const m=(f,x)=>g(f,x);for(const f of["success","error","warning","info"])m[f]=(x,R={})=>g(x,{...R,type:f});return m.promise=async(f,x,R={})=>{const y=g(x.loading,{...R,type:"info",duration:0});try{const h=await(typeof f=="function"?f():f);y!=null&&i(y);const l=typeof x.success=="function"?x.success(h):x.success;return l&&g(l,{...R,type:"success"}),h}catch(h){y!=null&&i(y);const l=typeof x.error=="function"?x.error(h):x.error;throw l&&g(l,{...R,type:"error"}),h}},m.dismiss=i,m.clear=()=>{for(const f of r.current.values())clearTimeout(f);r.current.clear(),t.current.publish([])},m},[g,i]);return e.useEffect(()=>()=>{for(const m of r.current.values())clearTimeout(m);r.current.clear()},[]),{toast:d,dismissToast:i}}function wt(t,n,o){const r=e.useRef(new Map),i=e.useRef(0),g=e.useCallback(()=>{if(!n.current)return;const h=[...r.current.values()],l={visible:h.length>0,text:h.at(-1)?.text??null,count:h.length},c=t.current.getSnapshot();(c.visible!==l.visible||c.text!==l.text||c.count!==l.count)&&t.current.publish(l)},[]),d=e.useCallback((h,l)=>{if(!n.current||h!=="global"&&o.current!==h)return null;const c=++i.current;return r.current.set(c,{owner:h,text:l}),g(),c},[g]),m=e.useCallback((h,l)=>{if(l!=null)r.current.get(l)?.owner===h&&r.current.delete(l);else for(const[c,L]of r.current)L.owner===h&&r.current.delete(c);g()},[g]),f=e.useCallback((h,l)=>{h?(m("global"),d("global",l)):m("global")},[d,m]),x=e.useCallback((h,l,c)=>{l?(m(h),d(h,c)):m(h)},[d,m]);return{loadingApi:e.useMemo(()=>({setLoading:f,setScreenLoading:x,begin:d,end:m}),[f,x,d,m]),refreshLoading:g,loadingTasks:r,setLoading:f}}const kt=e.memo(function({store:n,translate:o}){const r=e.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getSnapshot);return u.jsx(ht,{loading:r,translate:o})}),Ct=e.memo(function({store:n,dismiss:o}){const r=e.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getSnapshot);return u.jsx(yt,{items:r,dismiss:o})}),Rt=e.memo(function({store:n,routeKey:o,...r}){const i=e.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getSnapshot);return u.jsx(gt,{...r,override:i[o]})}),Et=e.memo(function({route:n,screen:o,navigation:r,focused:i,resultEvent:g,setFooter:d,loadingApi:m,loadingStore:f,bodyClassName:x,notifyError:R,registerDirtyGuard:y}){const h=o.component,l=e.useMemo(()=>({isFocused:i,resultEvent:g,routeKey:n.key,setFooter:d}),[i,g,n.key,d]),c=e.useMemo(()=>({setLoading:(E,P)=>m.setScreenLoading(n.key,E,P),showLoading:E=>m.begin(n.key,E),hideLoading:E=>m.end(n.key,E)}),[m,n.key]),L=e.useMemo(()=>({routeKey:n.key,registerDirtyGuard:y}),[n.key,y]);return u.jsx(Ve.Provider,{value:n,children:u.jsx(Ye.Provider,{value:L,children:u.jsx(Me.Provider,{value:l,children:u.jsx(je.Provider,{value:c,children:u.jsx(De.Provider,{value:f,children:u.jsx("div",{hidden:!i,inert:!i,"data-modal-route-key":n.key,tabIndex:-1,className:`pmn-body ${x??""}`,children:u.jsx(bt,{route:n,onError:R,children:u.jsx(h,{route:n,navigation:r})})})})})})})})});function Je({config:t,initialScreen:n,params:o,options:r,translate:i,onRequestClose:g,onOpened:d,registerLoading:m,notifyError:f,error:x,clearError:R,registerDirtyGuard:y,canNavigate:h,exiting:l=!1}){const[c,L]=e.useReducer(Ee,null,()=>Qe(n??t.initialRoute,o)),E=e.useRef(null);E.current||(E.current=ct({canGoBack:c.length>1,stack:c,currentRoute:c.at(-1)}));const P=e.useRef(null),B=e.useRef(null),I=e.useRef(null);P.current||(P.current=Pe({visible:!1,text:null,count:0})),B.current||(B.current=Pe({})),I.current||(I.current=Pe([]));const k=e.useRef(!0),$=e.useRef(0),{toast:K,dismissToast:G}=vt(I,k);e.useEffect(()=>(k.current=!0,()=>{k.current=!1,$.current++}),[]);const[S,b]=e.useState({}),M=e.useRef(new Map),q=e.useRef(null),F=e.useRef(null),j=e.useRef(!1),W=e.useRef(!1),N=e.useRef(new Map),Q=e.useRef(0),J=e.useCallback((a,v,T)=>{for(const[D,ne]of N.current)a.includes(ne.key)&&(N.current.delete(D),ne.resolve({status:v,...v==="returned"?{value:T}:{}}))},[]),A=e.useRef(c);A.current=c;const re=e.useRef(h);re.current=h;const X=e.useRef(!1),ge=e.useRef(0),z=c.at(-1),O=z.key,oe=e.useRef(O);oe.current=O;const{loadingApi:he,refreshLoading:be,loadingTasks:le,setLoading:se}=wt(P,k,oe),Z=t.screens,we=P,de=e.useRef(m);de.current=m,e.useEffect(()=>(de.current?.({setLoading:se}),()=>de.current?.(null)),[se]);const ke=e.useCallback((a,v)=>{if(!k.current)return;const T=B.current.getSnapshot();if(v===null){if(!(a in T))return;const D={...T};delete D[a],B.current.publish(D);return}T[a]!==v&&B.current.publish({...T,[a]:v})},[]),xe=e.useCallback(()=>{if(typeof document>"u")return;const a=document.activeElement;if(!(a instanceof HTMLElement)||!q.current?.contains(a))return;const v=a.closest("[data-modal-route-key]");v&&M.current.set(v.dataset.modalRouteKey,a),q.current.focus({preventScroll:!0})},[]),ye=e.useCallback(a=>{if(!Object.prototype.hasOwnProperty.call(Z,a))throw new Error(`[react-modal-navigation] Unknown modal screen: ${a}`)},[Z]),ae=e.useCallback((a,v)=>{try{Promise.resolve(r[a]?.(v)).catch(T=>f(T,{phase:a}))}catch(T){f(T,{phase:a})}},[r,f]),V=e.useCallback(async(a,v,T,D)=>{if(!k.current||W.current)return!1;const ne=$.current,_=A.current,Te=_.at(-1);if(a!=="BACK"&&ye(v),a==="BACK"&&_.length<=1)return!1;const ze=a==="NAVIGATE"?_.findIndex(pe=>pe.name===v):-1,Ne=a==="RESET"?_:a==="BACK"||a==="REPLACE"?[Te]:ze>=0?_.slice(ze+1):[];W.current=!0;try{if(Ne.length&&re.current&&!await re.current(Ne.map(Le=>Le.key),{reason:"navigation",action:a,from:Te,to:a==="BACK"?_.at(-2)?.name:v})||!k.current||ne!==$.current||A.current.at(-1)?.key!==Te.key)return!1;if(a==="BACK"&&D!==void 0){const Re=_.at(-2);b(Le=>({...Le,[Re.key]:{id:++ge.current,data:D}}))}a==="RESET"&&b({}),J(Ne.map(Re=>Re.key),a==="BACK"?"returned":"removed",D),xe();const pe={type:a,name:v,params:T};return A.current=Ee(A.current,pe),L(pe),!0}catch(pe){return k.current&&f(pe,{phase:"navigationGuard",action:a}),!1}finally{W.current=!1}},[ye,xe,f,J]),s=e.useCallback((a,v)=>V("NAVIGATE",a,v),[V]),p=e.useCallback(async(a,v)=>{if(!k.current)return{status:"cancelled"};if(A.current,!await V("NAVIGATE",a,v)||!k.current)return{status:"cancelled"};const D=A.current.at(-1);return!D||D.name!==a?{status:"cancelled"}:new Promise(ne=>{const _=++Q.current;N.current.set(_,{key:D.key,resolve:ne})})},[V]),C=e.useCallback((a,v)=>V("REPLACE",a,v),[V]),w=e.useCallback((a,v)=>V("RESET",a,v),[V]),H=e.useCallback(a=>{if(!a||typeof a!="object"||Array.isArray(a))throw new TypeError("[react-modal-navigation] setParams expects an object");if(!k.current)return;const v={type:"SET_PARAMS",params:a};A.current=Ee(A.current,v),L(v)},[]),U=e.useCallback(a=>{if(!a||typeof a!="object"||Array.isArray(a))throw new TypeError("[react-modal-navigation] setOptions expects an object");if(!k.current)return;const v={type:"SET_OPTIONS",options:a};A.current=Ee(A.current,v),L(v)},[]),Y=e.useCallback(a=>V("BACK",null,void 0,a),[V]),ee=e.useCallback((a,v)=>!k.current||we.current.getSnapshot().visible&&r.lockCloseWhileLoading!==!1?Promise.resolve(!1):g(a,v,{route:z,stack:c}),[r.lockCloseWhileLoading,g,z,c]),te=e.useRef(ee);te.current=ee;const ce=e.useCallback(a=>te.current("api",a),[]),me=e.useMemo(()=>({navigate:s,navigateAsync:p,replace:C,reset:w,setParams:H,setOptions:U,goBack:Y,close:ce,setLoading:se}),[s,p,C,w,H,U,Y,ce,se]),fe=e.useMemo(()=>({canGoBack:c.length>1,stack:c,currentRoute:z}),[c]);e.useLayoutEffect(()=>E.current.publish(fe),[fe]);const ie=e.useRef(null);ie.current||(ie.current=Object.defineProperties({},{canGoBack:{enumerable:!0,get:()=>E.current.getSnapshot().canGoBack},stack:{enumerable:!0,get:()=>E.current.getSnapshot().stack},currentRoute:{enumerable:!0,get:()=>E.current.getSnapshot().currentRoute}}));const Ce=e.useMemo(()=>Object.assign(ie.current,me),[me]);e.useLayoutEffect(()=>{j.current=!1;const a=[...q.current?.querySelectorAll("[data-modal-route-key]")??[]].find(D=>D.dataset.modalRouteKey===O);if(!a)return;const v=M.current.get(O);(v?.isConnected&&a.contains(v)&&!v.matches(":disabled")&&!v.closest("[inert], [hidden]")?v:a).focus({preventScroll:!0})},[O]),e.useEffect(()=>{let a=!1;for(const[T,D]of le.current)D.owner!=="global"&&D.owner!==O&&(le.current.delete(T),a=!0);a&&be();const v=new Set(c.map(T=>T.key));b(T=>{const D=Object.keys(T).filter(_=>!v.has(_));if(!D.length)return T;const ne={...T};return D.forEach(_=>delete ne[_]),ne});for(const T of M.current.keys())v.has(T)||M.current.delete(T)},[O,c,be]),e.useEffect(()=>{if(F.current?.key!==O){if(F.current){const a={from:F.current,to:z,stack:c};ae("onBlur",{route:F.current,...a}),ae("onNavigate",a),ae("onRouteChange",a)}ae("onFocus",{route:z,stack:c}),F.current=z}},[z,O,c,ae]),e.useEffect(()=>()=>{le.current.clear(),M.current.clear();for(const a of N.current.values())a.resolve({status:"dismissed"});N.current.clear()},[]),e.useEffect(()=>{X.current||(X.current=!0,d?.({route:z,stack:c}))},[]);const nt=e.useMemo(()=>ut(c,Z,r.maxCachedScreens),[c,Z,r.maxCachedScreens]),$e=e.useMemo(()=>({...Z[z.name],...z.options??{}}),[Z,z.name,z.options]);return u.jsx(_e.Provider,{value:K,children:u.jsx(st.Provider,{value:I.current,children:u.jsx(at.Provider,{value:B.current,children:u.jsx(ot.Provider,{value:Ce,children:u.jsx(Fe.Provider,{value:me,children:u.jsx(Oe.Provider,{value:E.current,children:u.jsx(je.Provider,{value:he,children:u.jsxs(ft,{dialogRef:q,options:r,requestClose:ee,exiting:l,children:[u.jsx(pt,{options:r,screen:$e,route:z,navigation:Ce,requestClose:ee,translate:i,canGoBack:c.length>1}),u.jsx("main",{className:"pmn-main",children:nt.map(a=>u.jsx(Et,{route:a,screen:Z[a.name],navigation:Ce,focused:a.key===O,resultEvent:S[a.key]??null,bodyClassName:r.bodyClassName,setFooter:ke,loadingApi:he,loadingStore:P.current,notifyError:f,registerDirtyGuard:y},a.key))}),u.jsx(Rt,{store:B.current,routeKey:O,screen:$e,options:r,route:z,navigation:Ce,requestClose:ee,translate:i,onError:f,loadingApi:he},O),u.jsx(kt,{store:P.current,translate:i}),u.jsx(Ct,{store:I.current,dismiss:G}),x&&u.jsxs("div",{className:"pmn-error",role:"alert",children:[u.jsx("span",{children:x.message||String(x)}),u.jsx("button",{type:"button",onClick:R,"aria-label":"Dismiss error",children:"×"})]})]})})})})})})})})}const St=".pmn-overlay,.pmn-dialog,.pmn-dialog *{box-sizing:border-box}.pmn-overlay{position:fixed;inset:0;z-index:1000;display:flex;overscroll-behavior:none;background:#00000073}.pmn-place-right{justify-content:flex-end;align-items:stretch}.pmn-place-left{justify-content:flex-start;align-items:stretch}.pmn-place-center{justify-content:center;align-items:center}.pmn-place-top{justify-content:center;align-items:flex-start}.pmn-place-bottom{justify-content:center;align-items:flex-end}.pmn-dialog{--pmn-surface:#fff;--pmn-body:#fff;--pmn-text:#0f172a;--pmn-muted:#475569;--pmn-border:#e2e8f0;--pmn-hover:#f1f5f9;--pmn-overlay-card:rgba(255,255,255,.92);color-scheme:light;position:relative;display:flex;flex-direction:column;min-height:0;width:100%;max-width:min(calc(100vw - var(--pmn-gap)*2),var(--pmn-max-width, var(--pmn-width)));max-height:min(calc(100dvh - var(--pmn-gap)*2),var(--pmn-max-height, 100dvh));height:var(--pmn-height, 100%);overflow:hidden;outline:none;box-shadow:0 25px 50px -12px #00000040;background:var(--pmn-surface);color:var(--pmn-text)}.pmn-place-left .pmn-dialog,.pmn-place-right .pmn-dialog{height:calc(100dvh - var(--pmn-gap)*2);max-height:calc(100dvh - var(--pmn-gap)*2)}.pmn-place-center .pmn-dialog{height:var(--pmn-height, auto);min-height:150px}.pmn-place-top .pmn-dialog,.pmn-place-bottom .pmn-dialog{height:var(--pmn-height, auto);min-height:0}.pmn-dialog[data-modal-theme=dark]{--pmn-surface:#334155;--pmn-body:#334155;--pmn-text:#f1f5f9;--pmn-muted:#cbd5e1;--pmn-border:#475569;--pmn-hover:#1e293b;--pmn-overlay-card:rgba(51,65,85,.94);color-scheme:dark}.pmn-main{min-height:0;flex:1;overflow:hidden;display:flex;flex-direction:column;background:transparent}.pmn-body{height:100%;min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:16px;flex:1}.pmn-body[hidden]{display:none!important}.pmn-header{display:flex;flex-shrink:0;height:64px;align-items:center;gap:12px;padding:0 20px;background:transparent}.pmn-header h2{font-size:18px;font-weight:600;min-width:0;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin:0}.pmn-header-spacer{flex:1}.pmn-border-bottom{border-bottom:1px solid var(--pmn-border)}.pmn-icon-button{display:inline-flex;align-items:center;justify-content:center;padding:8px;border:0;background:transparent;color:inherit;border-radius:8px;cursor:pointer}.pmn-icon-button:hover{background:var(--pmn-hover)}.pmn-footer{display:flex;flex-shrink:0;align-items:center;justify-content:flex-end;gap:12px;padding:16px 20px;background:transparent}.pmn-border-top{border-top:1px solid var(--pmn-border)}.pmn-button{padding:8px 16px;border-radius:8px;font-size:14px;font-weight:500;cursor:pointer}.pmn-button:disabled{opacity:.5;cursor:not-allowed}.pmn-button-secondary{border:1px solid var(--pmn-border);background:transparent;color:var(--pmn-text)}.pmn-button-secondary:hover:not(:disabled){background:var(--pmn-hover)}.pmn-button-primary{border:1px solid #2563eb;background:#2563eb;color:#fff}.pmn-button-primary:hover:not(:disabled){background:#1d4ed8}.pmn-loading-overlay{position:absolute;inset:0;z-index:50;display:flex;align-items:center;justify-content:center;background:#ffffffb8;backdrop-filter:blur(2px);-webkit-backdrop-filter:blur(2px);cursor:progress}.pmn-dialog[data-modal-theme=dark] .pmn-loading-overlay{background:#0f172ab8}.pmn-loading-content{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:14px;max-width:85%;text-align:center;color:var(--pmn-text);pointer-events:none}.pmn-loading-text{font-size:14px;font-weight:500;line-height:1.5;overflow-wrap:anywhere}.pmn-spinner{width:38px;height:38px;border:3px solid rgba(37,99,235,.2);border-top-color:#2563eb;border-radius:50%;animation:pmn-spin .8s linear infinite}@keyframes pmn-spin{to{transform:rotate(360deg)}}@media(prefers-reduced-motion:reduce){.pmn-spinner{animation-duration:1.8s}}.pmn-error{position:absolute;z-index:60;bottom:8px;left:12px;right:12px;display:flex;justify-content:space-between;gap:12px;padding:12px;border:1px solid #fca5a5;border-radius:8px;background:#fef2f2;color:#991b1b;font-size:13px}.pmn-error button{border:0;background:transparent;font-size:20px;cursor:pointer;color:inherit}.pmn-dialog input:not([type=checkbox]):not([type=radio]),.pmn-dialog textarea,.pmn-dialog select{color:var(--pmn-text);border-color:var(--pmn-border)}.pmn-error-screen{padding:24px;color:var(--pmn-text)}.pmn-error-screen p{color:#dc2626;overflow-wrap:anywhere}@media(max-width:640px){.pmn-overlay.pmn-mobile-fullscreen{padding:0!important}.pmn-mobile-fullscreen .pmn-dialog{max-width:100%;width:100%;height:100dvh;max-height:100dvh;border-radius:0!important}}@media(prefers-reduced-motion:reduce){.pmn-spinner{animation-duration:2s}}@keyframes pmn-fade-in{0%{opacity:0}to{opacity:1}}@keyframes pmn-fade-out{0%{opacity:1}to{opacity:0}}@keyframes pmn-scale-in{0%{opacity:0;transform:translateY(10px) scale(.97)}to{opacity:1;transform:none}}@keyframes pmn-scale-out{0%{opacity:1;transform:none}to{opacity:0;transform:translateY(10px) scale(.97)}}@keyframes pmn-right-in{0%{transform:translate(105%)}to{transform:none}}@keyframes pmn-right-out{0%{transform:none}to{transform:translate(105%)}}@keyframes pmn-left-in{0%{transform:translate(-105%)}to{transform:none}}@keyframes pmn-left-out{0%{transform:none}to{transform:translate(-105%)}}@keyframes pmn-top-in{0%{transform:translateY(-105%)}to{transform:none}}@keyframes pmn-top-out{0%{transform:none}to{transform:translateY(-105%)}}@keyframes pmn-bottom-in{0%{transform:translateY(105%)}to{transform:none}}@keyframes pmn-bottom-out{0%{transform:none}to{transform:translateY(105%)}}.pmn-entering{animation:pmn-fade-in var(--pmn-animation-duration) ease-out both}.pmn-exiting{animation:pmn-fade-out var(--pmn-animation-duration) ease-in both;pointer-events:none}.pmn-entering .pmn-dialog{animation:pmn-scale-in var(--pmn-animation-duration) cubic-bezier(.2,.8,.2,1) both}.pmn-exiting .pmn-dialog{animation:pmn-scale-out var(--pmn-animation-duration) ease-in both}.pmn-entering.pmn-place-right .pmn-dialog{animation-name:pmn-right-in}.pmn-exiting.pmn-place-right .pmn-dialog{animation-name:pmn-right-out}.pmn-entering.pmn-place-left .pmn-dialog{animation-name:pmn-left-in}.pmn-exiting.pmn-place-left .pmn-dialog{animation-name:pmn-left-out}.pmn-entering.pmn-place-top .pmn-dialog{animation-name:pmn-top-in}.pmn-exiting.pmn-place-top .pmn-dialog{animation-name:pmn-top-out}.pmn-entering.pmn-place-bottom .pmn-dialog{animation-name:pmn-bottom-in}.pmn-exiting.pmn-place-bottom .pmn-dialog{animation-name:pmn-bottom-out}.pmn-no-animation,.pmn-no-animation .pmn-dialog{animation:none!important}@media(prefers-reduced-motion:reduce){.pmn-entering,.pmn-exiting,.pmn-entering .pmn-dialog,.pmn-exiting .pmn-dialog{animation:none!important}}.pmn-toast-region{position:absolute;top:56px;left:12px;right:12px;z-index:80;display:flex;flex-direction:column;align-items:center;gap:8px;pointer-events:none;max-height:calc(100% - 72px);overflow:hidden}.pmn-toast{pointer-events:auto;display:flex;align-items:flex-start;gap:10px;width:max-content;max-width:100%;min-width:min(260px,100%);padding:11px 13px;border:1px solid var(--pmn-border);border-radius:9px;background:var(--pmn-surface);color:var(--pmn-text);box-shadow:0 5px 18px #0000001a;font-size:13px;line-height:1.5;overflow-wrap:anywhere}.pmn-toast-symbol{flex:0 0 20px;display:grid;place-items:center;width:20px;height:20px;border-radius:50%;font-size:13px;font-weight:700;background:var(--pmn-hover);color:var(--pmn-muted)}.pmn-toast-success .pmn-toast-symbol{background:#dcfce7;color:#15803d}.pmn-toast-error .pmn-toast-symbol{background:#fee2e2;color:#b91c1c}.pmn-toast-warning .pmn-toast-symbol{background:#fef3c7;color:#b45309}.pmn-toast-info .pmn-toast-symbol{background:#dbeafe;color:#1d4ed8}.pmn-toast-message{flex:1;min-width:0;white-space:pre-wrap}.pmn-toast-close{border:0;background:transparent;color:var(--pmn-muted);cursor:pointer;font-size:19px;line-height:18px;padding:0 1px}.pmn-toast-close:hover{color:var(--pmn-text)}.pmn-button-danger{background:#dc2626!important;color:#fff!important;border-color:#dc2626!important}",He="react-modal-navigation-styles",Ae=new WeakMap;function Mt(){e.useInsertionEffect(()=>{if(typeof document>"u")return;const t=document;let n=Ae.get(t);if(!n){let o=t.getElementById(He);const r=!o;o||(o=t.createElement("style"),o.id=He,o.setAttribute("data-react-modal-navigation",""),o.textContent=St,t.head.appendChild(o)),n={element:o,owned:r,count:0},Ae.set(t,n)}return n.count+=1,()=>{n.count-=1,n.count===0&&(n.owned&&n.element.remove(),Ae.delete(t))}},[])}function Se(t,n,o){if(typeof t=="string"){if(!t.trim())throw new TypeError("[react-modal-navigation] modal name must not be empty");return{name:t,params:n??{},options:o??{}}}if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError("[react-modal-navigation] open expects a modal name or a configuration object");const{name:r,screen:i,params:g={},options:d={},...m}=t;if(typeof r!="string"||!r.trim())throw new TypeError("[react-modal-navigation] open config requires a non-empty string name");if(d===null||typeof d!="object"||Array.isArray(d))throw new TypeError("[react-modal-navigation] open config options must be an object");if(i!==void 0&&(typeof i!="string"||!i.trim()))throw new TypeError("[react-modal-navigation] screen must be a non-empty string");return{name:r,...i===void 0?{}:{screen:i},params:g,options:{...m,...d}}}const jt={placement:"right",showHeader:!0,showBackButton:!0,showCloseButton:!0,viewportGap:5,borderRadius:12,closeOnOverlay:!1,closeOnEsc:!0},Tt=t=>({"modal.loading":"加载中...","modal.processing":"处理中...","modal.back":"返回","modal.close":"关闭","modal.cancel":"取消","modal.done":"完成"})[t]??t;function Nt({registry:t,children:n,defaultOptions:o={},backgroundColor:r,theme:i,translate:g=Tt,onError:d,confirmDiscard:m}){Mt();const[f,x]=e.useState(null),[R,y]=e.useState(null),[h,l]=e.useState(0),c=e.useRef(null),L=e.useRef(new Map),E=e.useRef([]),P=e.useRef(null),B=e.useRef(null),I=e.useRef(0),k=e.useRef(null),$=e.useRef(!1),K=e.useRef(0),G=e.useRef(null),S=e.useRef(new Map),[b,M]=e.useState(!1),q=e.useRef(m);q.current=m;const F=e.useCallback((s,p)=>(S.current.set(s,p),()=>{S.current.get(s)===p&&S.current.delete(s)}),[]),j=e.useCallback(async s=>{for(const p of S.current.values()){if(!p.dirty)continue;if((p.onBeforeDiscard?await p.onBeforeDiscard(s):q.current?await q.current(s):typeof window<"u"&&typeof window.confirm=="function"?window.confirm(p.message||"有未保存的修改,确定放弃吗?"):!1)===!1)return!1}return!0},[]),W=e.useCallback(async(s,p)=>{for(const C of s){const w=S.current.get(C);if(!w?.dirty)continue;if((w.onBeforeDiscard?await w.onBeforeDiscard(p):q.current?await q.current(p):typeof window<"u"&&typeof window.confirm=="function"?window.confirm(w.message||"有未保存的修改,确定放弃吗?"):!1)===!1)return!1}return!0},[]),N=e.useRef(!0),Q=e.useRef(null),J=e.useRef(d);J.current=d;const A=e.useCallback((s,p)=>{N.current&&y(s);try{J.current?J.current(s,p):console.error("[react-modal-navigation]",s)}catch(C){console.error("[react-modal-navigation] onError failed",C)}},[]),re=e.useCallback((s,p)=>{const C=L.current.get(s);L.current.delete(s),C?.(p)},[]),X=e.useCallback(s=>({...jt,...o,...i!==void 0?{theme:i}:{},...r!==void 0?{backgroundColor:r}:{},...s.config.modalOptions,...s.overrides}),[o,i,r]),ge=f?X(f):null,z=e.useRef(null);z.current=ge,Q.current=ge;const O=e.useCallback(async(s="api",p,C={})=>{const w=c.current;if(!w||k.current||$.current)return!1;k.current=w.id,$.current=!0;const H=Q.current??X(w),U={...C,reason:s,result:p,name:w.name};try{if(!await j(U)||await H.onBeforeClose?.(U)===!1||c.current?.id!==w.id||!N.current||(M(!0),await new Promise(Y=>{const ee=H.animation===!1||typeof window<"u"&&window.matchMedia?.("(prefers-reduced-motion: reduce)").matches?0:Math.max(0,Number(H.animationDuration??220)||0);setTimeout(Y,Math.min(ee,1e3))}),!N.current||c.current?.id!==w.id))return!1;c.current=null,G.current=null,x(null),M(!1),S.current.clear(),re(w.id,C.confirmed||p!==void 0?{status:"confirmed",value:p,reason:s}:{status:"dismissed",reason:s});try{await H.onClose?.(U)}catch(Y){A(Y,{phase:"onClose",name:w.name})}return!0}catch(Y){return A(Y,{phase:"onBeforeClose",name:w.name}),!1}finally{k.current===w.id&&(k.current=null),$.current=!1,!c.current&&N.current&&queueMicrotask(()=>B.current?.())}},[X,A,re,j]),oe=e.useCallback(async(s,p={},C={},w,H)=>{const U=t?.[s];if(!U)throw new Error(`[react-modal-navigation] Unknown modal: ${s}`);const Y=H??U.initialRoute;if(!U.screens?.[Y])throw new Error(`[react-modal-navigation] Unknown initial screen '${Y}' in modal '${s}'`);if(!N.current||$.current||k.current)return null;$.current=!0;const ee=K.current;try{const te=c.current;if(te){const me=Q.current??X(te),fe={reason:"replace",name:te.name,nextName:s};try{if(!await j(fe)||await me.onBeforeClose?.(fe)===!1)return null}catch(ie){return A(ie,{phase:"onBeforeClose",name:te.name}),null}if(!N.current||ee!==K.current||c.current?.id!==te.id)return null;c.current=null,G.current=null,x(null),S.current.clear(),re(te.id,{status:"replaced",reason:"replace"});try{await me.onClose?.(fe)}catch(ie){A(ie,{phase:"onClose",name:te.name})}if(!N.current||ee!==K.current)return null}const ce={id:++I.current,name:s,screen:Y,params:p,config:U,overrides:C};return c.current=ce,G.current=null,w&&L.current.set(ce.id,w),y(null),x(ce),ce.id}finally{$.current=!1}},[t,X,A,re,j]);P.current=oe;const he=e.useCallback(async()=>{if(!N.current||c.current||$.current||k.current)return;const s=E.current.shift();if(s){l(E.current.length);try{const p=await P.current(s.args.name,s.args.params,s.args.options,s.resolveResult,s.args.screen);p===null?(s.resolveResult?.({status:"dismissed",reason:"blocked"}),s.resolveId?.(null),queueMicrotask(()=>B.current?.())):s.resolveId?.(p)}catch(p){s.reject?.(p),queueMicrotask(()=>B.current?.())}}},[]);B.current=he;const be=e.useCallback((s,p,C)=>{const w=Se(s,p,C);return t?.[w.name]?new Promise((H,U)=>{E.current.push({args:w,resolveId:H,reject:U}),l(E.current.length),queueMicrotask(()=>B.current?.())}):Promise.reject(new Error(`[react-modal-navigation] Unknown modal: ${w.name}`))},[t]),le=e.useCallback((s,p,C)=>{const w=Se(s,p,C);return t?.[w.name]?new Promise((H,U)=>{E.current.push({args:w,resolveResult:H,reject:U}),l(E.current.length),queueMicrotask(()=>B.current?.())}):Promise.reject(new Error(`[react-modal-navigation] Unknown modal: ${w.name}`))},[t]),se=e.useCallback(s=>{if(!s||typeof s!="object"||Array.isArray(s))throw new TypeError("[react-modal-navigation] update expects an options object");const p=c.current;if(!p||$.current)return!1;const C={...p,overrides:{...p.overrides,...s}};return c.current=C,x(C),Q.current=X(C),!0},[X]),Z=e.useCallback((s="queue-cleared")=>{const p=E.current.splice(0);l(0);for(const C of p)C.resolveId?.(null),C.resolveResult?.({status:"dismissed",reason:s});return p.length},[]),we=e.useCallback((s,p,C)=>{const w=Se(s,p,C);return oe(w.name,w.params,w.options,void 0,w.screen)},[oe]),de=e.useCallback((s,p,C)=>{const w=Se(s,p,C);return new Promise((H,U)=>{oe(w.name,w.params,w.options,H,w.screen).then(Y=>{Y===null&&H({status:"dismissed",reason:"blocked"})},U)})},[oe]),ke=e.useCallback(s=>O("api",s),[O]),xe=e.useCallback((s="api")=>O(s),[O]),ye=e.useCallback(s=>O("confirm",s,{confirmed:!0}),[O]),ae=e.useCallback((s,p)=>G.current?.setLoading(s,p),[]),V=e.useMemo(()=>({open:we,openAsync:de,enqueue:be,enqueueAsync:le,update:se,clearQueue:Z,close:ke,dismiss:xe,confirm:ye,setLoading:ae,queueSize:h,isOpen:!!f,activeName:f?.name??null,error:R,clearError:()=>y(null)}),[we,de,be,le,se,Z,ke,xe,ye,ae,f,R,h]);return e.useEffect(()=>(N.current=!0,()=>{N.current=!1,K.current+=1,c.current=null;for(const p of L.current.values())p({status:"dismissed",reason:"unmount"});L.current.clear(),S.current.clear();const s=E.current.splice(0);for(const p of s)p.resolveId?.(null),p.resolveResult?.({status:"dismissed",reason:"unmount"})}),[]),u.jsxs(We.Provider,{value:V,children:[n,f&&u.jsx(Je,{config:f.config,initialScreen:f.screen,params:f.params,options:ge,translate:g,notifyError:A,error:R,clearError:()=>y(null),registerLoading:s=>{G.current=s},registerDirtyGuard:F,canNavigate:W,exiting:b,onRequestClose:O,onOpened:s=>{try{const p=z.current?.onOpen?.(s);Promise.resolve(p).catch(C=>A(C,{phase:"onOpen"}))}catch(p){A(p,{phase:"onOpen"})}}},f.id)]})}const Lt=Object.freeze({canGoBack:!1,stack:[],currentRoute:null}),Pt=()=>()=>{},Ue=()=>Lt;function Bt(){const t=e.useContext(We),n=e.useContext(Fe),o=e.useContext(Oe),r=e.useSyncExternalStore(o?.subscribe??Pt,o?.getSnapshot??Ue,o?.getSnapshot??Ue);if(!t)throw new Error("[react-modal-navigation] useModal requires <ModalProvider>");const i=e.useMemo(()=>{const g=()=>{if(!n)throw new Error("[react-modal-navigation] navigation requires an active modal screen; use modal.open() outside a modal");return n};return{navigate:(...d)=>g().navigate(...d),replace:(...d)=>g().replace(...d),reset:(...d)=>g().reset(...d),setParams:(...d)=>g().setParams(...d),setOptions:(...d)=>g().setOptions(...d),goBack:(...d)=>g().goBack(...d),close:(...d)=>g().close(...d),setLoading:(...d)=>g().setLoading(...d),canGoBack:r.canGoBack,stack:r.stack,currentRoute:r.currentRoute}},[n,r]);return e.useMemo(()=>({...t,modal:t,navigation:i}),[t,i])}function Xe(){const t=e.useContext(Fe);if(!t)throw new Error("useModalNavigationCommands requires an active modal screen");return t}function Ze(){const t=e.useContext(Oe);if(!t)throw new Error("useModalNavigationState requires an active modal screen");return e.useSyncExternalStore(t.subscribe,t.getSnapshot,t.getSnapshot)}function At(){const t=Xe(),n=Ze();return e.useMemo(()=>({...t,...n}),[t,n])}function Ie(){const t=e.useContext(Me);if(!t)throw new Error("useIsFocused must be called inside a modal screen");return t.isFocused}function qt(t){const n=Ie();e.useEffect(()=>{if(n)return t()},[n,t])}function Ft(t){const n=e.useContext(Me);if(!n)throw new Error("useNavigationResult requires an active modal screen");const o=e.useRef(t),r=e.useRef(null);e.useEffect(()=>{o.current=t},[t]),e.useEffect(()=>{!n.isFocused||!n.resultEvent||r.current!==n.resultEvent.id&&(r.current=n.resultEvent.id,o.current(n.resultEvent.data))},[n.isFocused,n.resultEvent])}function Ot(t={}){const n=e.useContext(Me);if(!n)throw new Error("[react-modal-navigation] useModalFooter requires an active modal screen");const{setFooter:o,routeKey:r}=n,i=e.useRef(t);i.current=t;const g=e.useMemo(()=>(...S)=>i.current.done?.(...S),[]),d=e.useMemo(()=>(...S)=>(i.current.cancel??i.current.cancle)?.(...S),[]),m=e.useMemo(()=>(...S)=>i.current.renderFooter?.(...S),[]),f=typeof t.done=="function",x=typeof(t.cancel??t.cancle)=="function",R=typeof t.renderFooter=="function",{showFooter:y,showFooterBorder:h,doneDisabled:l,doneText:c,cancelText:L,loadingText:E,footerClassName:P}=t,B=e.useRef({source:null,normalized:void 0}),I=Array.isArray(t.actions)?t.actions:null,k=B.current.source;I===k||I&&k&&I.length===k.length&&I.every((S,b)=>{const M=k[b];return[...new Set([...Object.keys(S),...Object.keys(M)])].every(F=>F==="onClick"||Object.is(S[F],M[F]))})||(B.current={source:I?.map(S=>({...S}))??null,normalized:I?.map((S,b)=>({...S,onClick:(...M)=>(i.current.actions?.find(F=>F.key===S.key)??i.current.actions?.[b])?.onClick?.(...M)}))});const K=B.current.normalized,G=e.useMemo(()=>({showFooter:y,showFooterBorder:h,doneDisabled:l,doneText:c,cancelText:L,loadingText:E,footerClassName:P,...K!==void 0?{actions:K}:{},...f?{done:g}:{},...x?{cancel:d}:{},...R?{renderFooter:m}:{}}),[y,h,l,c,L,E,P,K,f,x,R,g,d,m]);e.useEffect(()=>{o(r,G)},[r,o,G]),e.useEffect(()=>()=>o(r,null),[r,o])}function et(){const t=e.useContext(je),n=e.useContext(De);if(!t||!n)throw new Error("[react-modal-navigation] useModalLoading requires an active modal screen");const o=e.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getSnapshot);return e.useMemo(()=>({...t,isLoading:o.visible}),[t,o.visible])}function Dt(){const t=e.useContext(je);if(!t)throw new Error("[react-modal-navigation] useModalLoadingCommands requires an active modal screen");return t}function It(){const t=e.useContext(De);if(!t)throw new Error("[react-modal-navigation] useModalLoadingState requires an active modal screen");return e.useSyncExternalStore(t.subscribe,t.getSnapshot,t.getSnapshot)}function $t(){const t=et(),n=Ie(),o=e.useRef(!0),r=e.useRef(!1),[i,g]=e.useState(!1),[d,m]=e.useState(null),f=e.useRef(t);return f.current=t,e.useEffect(()=>(o.current=!0,()=>{o.current=!1}),[]),{run:e.useCallback(async(R,y={})=>{if(r.current)return{status:"busy"};if(typeof R!="function")throw new TypeError("[react-modal-navigation] run requires a function");r.current=!0,o.current&&(g(!0),m(null));const h=f.current.showLoading(y.loadingText);try{const l=await R();return o.current&&await y.onSuccess?.(l),{status:"success",value:l}}catch(l){if(o.current){m(l);try{await y.onError?.(l)}catch(c){console.error("[react-modal-navigation] onError failed",c)}}if(y.throwOnError)throw l;return{status:"error",error:l}}finally{h!=null&&f.current.hideLoading(h),r.current=!1,o.current&&g(!1)}},[]),pending:i,error:d,clearError:()=>m(null),isFocused:n}}function zt(t,n={}){const o=e.useContext(Ye);if(!o)throw new Error("[react-modal-navigation] useModalUnsavedChanges must be used inside a modal screen");const r=e.useRef({dirty:t,...n});r.current={dirty:t,...n};const{routeKey:i,registerDirtyGuard:g}=o;e.useEffect(()=>g(i,{get dirty(){return!!r.current.dirty},get message(){return r.current.message},get onBeforeDiscard(){return r.current.onBeforeDiscard}}),[i,g])}const Kt=()=>{const t=e.useContext(_e);if(!t)throw new Error("[react-modal-navigation] useToast requires an active modal");return t};function tt(){const t=e.useContext(Ve);if(!t)throw new Error("[react-modal-navigation] useModalRoute requires a modal screen");return t}function Gt(){return tt().params}exports.ModalNavigator=Je;exports.ModalProvider=Nt;exports.useFocusEffect=qt;exports.useIsFocused=Ie;exports.useModal=Bt;exports.useModalFooter=Ot;exports.useModalLoading=et;exports.useModalLoadingCommands=Dt;exports.useModalLoadingState=It;exports.useModalNavigation=At;exports.useModalNavigationCommands=Xe;exports.useModalNavigationState=Ze;exports.useModalParams=Gt;exports.useModalRoute=tt;exports.useModalTask=$t;exports.useModalUnsavedChanges=zt;exports.useNavigationResult=Ft;exports.useToast=Kt;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx as h, jsxs as me } from "react/jsx-runtime";
2
- import Ne, { createContext as ee, useRef as d, useState as ie, useEffect as H, useCallback as v, useMemo as K, useSyncExternalStore as be, useReducer as ln, useLayoutEffect as Qe, useInsertionEffect as un, useContext as Q } from "react";
2
+ import Ne, { createContext as ee, useRef as m, useState as ie, useEffect as H, useCallback as v, useMemo as K, useSyncExternalStore as be, useReducer as ln, useLayoutEffect as Qe, useInsertionEffect as un, useContext as Q } from "react";
3
3
  import { createPortal as dn } from "react-dom";
4
4
  const nn = ee(null), mn = ee(null), je = ee(null), Fe = ee(null), tn = ee(null), rn = ee(null), Ue = ee(null), We = ee(null), Ye = ee(null), pn = ee(null), fn = ee(null), on = ee(null);
5
5
  function hn(e) {
@@ -55,8 +55,8 @@ function qe(e, n) {
55
55
  }
56
56
  }
57
57
  function bn(e, n, r = 1 / 0) {
58
- const t = r === 1 / 0 ? 1 / 0 : Math.max(0, Math.floor(Number(r) || 0)), c = e.slice(0, -1).filter((i) => n[i.name]?.keepAlive !== !1), f = new Set((t === 0 ? [] : c.slice(-t)).map((i) => i.key));
59
- return e.filter((i, m) => m === e.length - 1 || f.has(i.key));
58
+ const t = r === 1 / 0 ? 1 / 0 : Math.max(0, Math.floor(Number(r) || 0)), c = e.slice(0, -1).filter((l) => n[l.name]?.keepAlive !== !1), f = new Set((t === 0 ? [] : c.slice(-t)).map((l) => l.key));
59
+ return e.filter((l, u) => u === e.length - 1 || f.has(l.key));
60
60
  }
61
61
  const Je = () => {
62
62
  if (typeof document > "u") return "light";
@@ -80,11 +80,11 @@ function yn() {
80
80
  }
81
81
  const vn = 'a[href],button:not([disabled]),input:not([disabled]),textarea:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])', wn = (e) => !e.closest('[inert], [hidden], [aria-hidden="true"]') && e.getClientRects().length > 0 && getComputedStyle(e).visibility !== "hidden" && getComputedStyle(e).display !== "none";
82
82
  function xn({ dialogRef: e, options: n, requestClose: r, children: t, exiting: c = !1 }) {
83
- const f = d(null), i = d(null), m = d(r);
84
- m.current = r;
85
- const l = d(n.closeOnEsc);
86
- l.current = n.closeOnEsc;
87
- const [y, C] = ie(Je), x = n.theme === "light" || n.theme === "dark" ? n.theme : y;
83
+ const f = m(null), l = m(null), u = m(r);
84
+ u.current = r;
85
+ const d = m(n.closeOnEsc);
86
+ d.current = n.closeOnEsc;
87
+ const [y, C] = ie(Je), w = n.theme === "light" || n.theme === "dark" ? n.theme : y;
88
88
  H(() => {
89
89
  if (n.theme === "light" || n.theme === "dark") return;
90
90
  const b = () => C(Je()), T = new MutationObserver(b);
@@ -94,14 +94,14 @@ function xn({ dialogRef: e, options: n, requestClose: r, children: t, exiting: c
94
94
  T.disconnect(), j?.removeEventListener?.("change", b);
95
95
  };
96
96
  }, [n.theme]), H(() => {
97
- i.current = document.activeElement;
97
+ l.current = document.activeElement;
98
98
  const b = yn(), T = f.current;
99
99
  ge.push(T), e.current?.focus({ preventScroll: !0 });
100
100
  const j = (N) => {
101
101
  const V = e.current;
102
102
  if (!V || ge.at(-1) !== T) return;
103
- if (N.key === "Escape" && l.current !== !1) {
104
- N.preventDefault(), m.current("escape");
103
+ if (N.key === "Escape" && d.current !== !1) {
104
+ N.preventDefault(), u.current("escape");
105
105
  return;
106
106
  }
107
107
  if (N.key !== "Tab") return;
@@ -119,12 +119,12 @@ function xn({ dialogRef: e, options: n, requestClose: r, children: t, exiting: c
119
119
  document.removeEventListener("keydown", j), document.removeEventListener("focusin", F);
120
120
  const N = ge.at(-1) === T, V = ge.indexOf(T);
121
121
  if (V !== -1 && ge.splice(V, 1), b(), N) {
122
- const L = i.current;
122
+ const L = l.current;
123
123
  L?.isConnected && !L.closest("[inert], [hidden]") ? L.focus?.({ preventScroll: !0 }) : ge.at(-1)?.querySelector("[role=dialog]")?.focus?.({ preventScroll: !0 });
124
124
  }
125
125
  };
126
126
  }, [e]);
127
- const g = n.backgroundColor ?? n.backgroudColor, u = typeof g == "string" ? g : g?.[x], s = typeof u == "string" && /^(#|rgb\(|rgba\(|hsl\(|hsla\(|oklch\(|color\(|var\()/.test(u.trim()) ? u : null, B = { sm: 400, md: 560, lg: 720, xl: 960, full: "100%" }, R = ["center", "left", "right", "top", "bottom"].includes(n.placement) ? n.placement : "right", A = (b) => typeof b == "number" ? `${b}px` : b, q = A(n.width ?? B[n.size] ?? 460), $ = A(n.height), E = A(n.maxHeight), z = A(n.maxWidth), U = Number(n.viewportGap ?? 5), W = Number.isFinite(U) ? Math.max(0, U) : 5, M = typeof n.borderRadius == "number" ? `${n.borderRadius}px` : n.borderRadius ?? "12px";
127
+ const g = n.backgroundColor ?? n.backgroudColor, i = typeof g == "string" ? g : g?.[w], s = typeof i == "string" && /^(#|rgb\(|rgba\(|hsl\(|hsla\(|oklch\(|color\(|var\()/.test(i.trim()) ? i : null, B = { sm: 400, md: 560, lg: 720, xl: 960, full: "100%" }, R = ["center", "left", "right", "top", "bottom"].includes(n.placement) ? n.placement : "right", A = (b) => typeof b == "number" ? `${b}px` : b, q = A(n.width ?? B[n.size] ?? 460), $ = A(n.height), E = A(n.maxHeight), z = A(n.maxWidth), U = Number(n.viewportGap ?? 5), W = Number.isFinite(U) ? Math.max(0, U) : 5, M = typeof n.borderRadius == "number" ? `${n.borderRadius}px` : n.borderRadius ?? "12px";
128
128
  return dn(/* @__PURE__ */ h(
129
129
  "div",
130
130
  {
@@ -132,7 +132,7 @@ function xn({ dialogRef: e, options: n, requestClose: r, children: t, exiting: c
132
132
  className: `pmn-overlay ${c ? "pmn-exiting" : "pmn-entering"} ${n.animation === !1 ? "pmn-no-animation" : ""} pmn-place-${R} ${n.mobileFullscreen ? "pmn-mobile-fullscreen" : ""}`,
133
133
  style: { padding: W, "--pmn-animation-duration": `${Math.min(1e3, Math.max(0, Number(n.animationDuration ?? 220) || 0))}ms` },
134
134
  onMouseDown: (b) => {
135
- b.target === b.currentTarget && n.closeOnOverlay === !0 && m.current("overlay");
135
+ b.target === b.currentTarget && n.closeOnOverlay === !0 && u.current("overlay");
136
136
  },
137
137
  children: /* @__PURE__ */ h(
138
138
  "section",
@@ -142,8 +142,8 @@ function xn({ dialogRef: e, options: n, requestClose: r, children: t, exiting: c
142
142
  role: "dialog",
143
143
  "aria-modal": "true",
144
144
  "aria-label": n.ariaLabel ?? "Dialog",
145
- "data-modal-theme": x,
146
- className: `pmn-dialog ${x === "dark" ? "dark" : ""} ${!s && u ? u : ""} ${n.className ?? ""}`,
145
+ "data-modal-theme": w,
146
+ className: `pmn-dialog ${w === "dark" ? "dark" : ""} ${!s && i ? i : ""} ${n.className ?? ""}`,
147
147
  style: { "--pmn-width": q, "--pmn-gap": `${W}px`, ...$ !== void 0 ? { "--pmn-height": $ } : {}, ...E !== void 0 ? { "--pmn-max-height": E } : {}, ...z !== void 0 ? { "--pmn-max-width": z } : {}, borderRadius: M, ...s ? { backgroundColor: s } : {} },
148
148
  children: t
149
149
  }
@@ -154,43 +154,43 @@ function xn({ dialogRef: e, options: n, requestClose: r, children: t, exiting: c
154
154
  function Xe({ back: e }) {
155
155
  return /* @__PURE__ */ h("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", width: "20", height: "20", fill: "none", stroke: "currentColor", strokeWidth: "2", children: e ? /* @__PURE__ */ h("path", { d: "m15 18-6-6 6-6" }) : /* @__PURE__ */ h("path", { d: "M18 6 6 18M6 6l12 12" }) });
156
156
  }
157
- function kn({ options: e, screen: n, route: r, navigation: t, requestClose: c, translate: f }) {
157
+ function kn({ options: e, screen: n, route: r, navigation: t, requestClose: c, translate: f, canGoBack: l }) {
158
158
  if (e.showHeader === !1) return null;
159
- const i = f ?? ((g) => g), m = n.showTitle ?? e.showTitle ?? !0, l = typeof n.title == "function" ? n.title({ t: i, route: r, navigation: t }) : n.title ?? r.name, y = { route: r, navigation: t, close: c, canGoBack: t.canGoBack, title: l, t: i }, C = n.renderHeader ?? e.renderHeader;
160
- if (C) return C(y);
161
- const x = n.renderHeaderRight ?? e.renderHeaderRight;
159
+ const u = f ?? ((i) => i), d = n.showTitle ?? e.showTitle ?? !0, y = typeof n.title == "function" ? n.title({ t: u, route: r, navigation: t }) : n.title ?? r.name, C = { route: r, navigation: t, close: c, canGoBack: l, title: y, t: u }, w = n.renderHeader ?? e.renderHeader;
160
+ if (w) return w(C);
161
+ const g = n.renderHeaderRight ?? e.renderHeaderRight;
162
162
  return /* @__PURE__ */ me("header", { className: `pmn-header ${n.showHeaderBorder ?? e.showHeaderBorder ? "pmn-border-bottom" : ""} ${e.headerClassName ?? ""}`, children: [
163
- e.showBackButton !== !1 && t.canGoBack && /* @__PURE__ */ h("button", { type: "button", className: "pmn-icon-button", "aria-label": i("modal.back"), onClick: () => t.goBack(), children: /* @__PURE__ */ h(Xe, { back: !0 }) }),
164
- m ? /* @__PURE__ */ h("h2", { children: l }) : /* @__PURE__ */ h("div", { className: "pmn-header-spacer" }),
165
- x?.(y),
166
- e.showCloseButton !== !1 && /* @__PURE__ */ h("button", { type: "button", className: "pmn-icon-button", "aria-label": i("modal.close"), onClick: () => c("header"), children: /* @__PURE__ */ h(Xe, {}) })
163
+ (n.showBackButton ?? e.showBackButton) !== !1 && l && /* @__PURE__ */ h("button", { type: "button", className: "pmn-icon-button", "aria-label": u("modal.back"), onClick: () => t.goBack(), children: /* @__PURE__ */ h(Xe, { back: !0 }) }),
164
+ d ? /* @__PURE__ */ h("h2", { children: y }) : /* @__PURE__ */ h("div", { className: "pmn-header-spacer" }),
165
+ g?.(C),
166
+ e.showCloseButton !== !1 && /* @__PURE__ */ h("button", { type: "button", className: "pmn-icon-button", "aria-label": u("modal.close"), onClick: () => c("header"), children: /* @__PURE__ */ h(Xe, {}) })
167
167
  ] });
168
168
  }
169
- function En({ screen: e, options: n, override: r, route: t, navigation: c, requestClose: f, translate: i, onError: m, loadingApi: l }) {
170
- const [y, C] = ie(null), x = d(/* @__PURE__ */ new Set()), g = d(!0);
169
+ function En({ screen: e, options: n, override: r, route: t, navigation: c, requestClose: f, translate: l, onError: u, loadingApi: d }) {
170
+ const [y, C] = ie(null), w = m(/* @__PURE__ */ new Set()), g = m(!0);
171
171
  H(() => (g.current = !0, () => {
172
172
  g.current = !1;
173
173
  }), []);
174
- const u = i ?? ((b) => b), s = { ...n, ...e, ...r }, { showFooter: B, renderFooter: R, done: A, cancel: q, cancle: $ } = s, E = q ?? $, z = { route: t, navigation: c, close: f, t: u };
174
+ const i = l ?? ((b) => b), s = { ...n, ...e, ...r }, { showFooter: B, renderFooter: R, done: A, cancel: q, cancle: $ } = s, E = q ?? $, z = { route: t, navigation: c, close: f, t: i };
175
175
  if (B === !1) return null;
176
176
  const U = `pmn-footer ${s.showFooterBorder ? "pmn-border-top" : ""} ${s.footerClassName ?? ""}`;
177
- if (typeof R == "function") return /* @__PURE__ */ h("footer", { className: U, children: R({ ...z, pending: x.current.size > 0 }) });
177
+ if (typeof R == "function") return /* @__PURE__ */ h("footer", { className: U, children: R({ ...z, pending: w.current.size > 0 }) });
178
178
  const W = Array.isArray(s.actions) ? s.actions : null;
179
179
  if (!W && typeof A != "function" && typeof E != "function") return null;
180
180
  const M = async (b, T, j) => {
181
- if (x.current.has(b) || typeof T != "function") return;
182
- x.current.add(b), C(b);
183
- const F = l?.begin(t.key, j ?? s.loadingText ?? u("modal.processing"));
181
+ if (w.current.has(b) || typeof T != "function") return;
182
+ w.current.add(b), C(b);
183
+ const F = d?.begin(t.key, j ?? s.loadingText ?? i("modal.processing"));
184
184
  try {
185
185
  await T(z);
186
186
  } catch (N) {
187
- m?.(N, { phase: "footer", action: b, route: t });
187
+ u?.(N, { phase: "footer", action: b, route: t });
188
188
  } finally {
189
- l?.end(t.key, F), x.current.delete(b), g.current && C((N) => N === b ? null : N);
189
+ d?.end(t.key, F), w.current.delete(b), g.current && C((N) => N === b ? null : N);
190
190
  }
191
191
  };
192
192
  return W ? /* @__PURE__ */ h("footer", { className: U, children: W.filter((b) => !b.hidden).map((b) => {
193
- const T = x.current.has(b.key) || b.loading === !0;
193
+ const T = w.current.has(b.key) || b.loading === !0;
194
194
  return /* @__PURE__ */ h(
195
195
  "button",
196
196
  {
@@ -198,13 +198,13 @@ function En({ screen: e, options: n, override: r, route: t, navigation: c, reque
198
198
  disabled: b.disabled === !0 || T,
199
199
  className: `pmn-button ${b.variant === "primary" || b.variant === "danger" ? "pmn-button-primary" : "pmn-button-secondary"} ${b.variant === "danger" ? "pmn-button-danger" : ""}`,
200
200
  onClick: () => M(b.key, b.onClick, b.loadingText),
201
- children: T ? b.loadingText ?? s.loadingText ?? u("modal.processing") : b.label
201
+ children: T ? b.loadingText ?? s.loadingText ?? i("modal.processing") : b.label
202
202
  },
203
203
  b.key
204
204
  );
205
205
  }) }) : /* @__PURE__ */ me("footer", { className: U, children: [
206
- typeof E == "function" && /* @__PURE__ */ h("button", { type: "button", disabled: y !== null, onClick: () => M("cancel", E), className: "pmn-button pmn-button-secondary", children: s.cancelText ?? u("modal.cancel") }),
207
- typeof A == "function" && /* @__PURE__ */ h("button", { type: "button", disabled: y !== null || s.doneDisabled === !0, onClick: () => M("done", A), className: "pmn-button pmn-button-primary", children: y === "done" ? s.loadingText ?? u("modal.processing") : s.doneText ?? u("modal.done") })
206
+ typeof E == "function" && /* @__PURE__ */ h("button", { type: "button", disabled: y !== null, onClick: () => M("cancel", E), className: "pmn-button pmn-button-secondary", children: s.cancelText ?? i("modal.cancel") }),
207
+ typeof A == "function" && /* @__PURE__ */ h("button", { type: "button", disabled: y !== null || s.doneDisabled === !0, onClick: () => M("done", A), className: "pmn-button pmn-button-primary", children: y === "done" ? s.loadingText ?? i("modal.processing") : s.doneText ?? i("modal.done") })
208
208
  ] });
209
209
  }
210
210
  function Sn({ loading: e, translate: n }) {
@@ -243,62 +243,62 @@ function Mn({ items: e, dismiss: n }) {
243
243
  ] }, r.id)) }) : null;
244
244
  }
245
245
  function Tn(e, n) {
246
- const r = d(0), t = d(/* @__PURE__ */ new Map()), c = v((m) => {
247
- clearTimeout(t.current.get(m)), t.current.delete(m), n.current && e.current.publish(e.current.getSnapshot().filter((l) => l.id !== m));
248
- }, []), f = v((m, l = {}) => {
249
- if (typeof m != "string" || !m.trim()) throw new TypeError("[react-modal-navigation] toast message must be a non-empty string");
250
- const y = typeof l == "string" ? { type: l } : l ?? {}, C = ["success", "error", "warning", "info"].includes(y.type) ? y.type : "info", x = ++r.current, g = Number.isFinite(y.duration) ? Math.max(0, y.duration) : 3e3;
246
+ const r = m(0), t = m(/* @__PURE__ */ new Map()), c = v((u) => {
247
+ clearTimeout(t.current.get(u)), t.current.delete(u), n.current && e.current.publish(e.current.getSnapshot().filter((d) => d.id !== u));
248
+ }, []), f = v((u, d = {}) => {
249
+ if (typeof u != "string" || !u.trim()) throw new TypeError("[react-modal-navigation] toast message must be a non-empty string");
250
+ const y = typeof d == "string" ? { type: d } : d ?? {}, C = ["success", "error", "warning", "info"].includes(y.type) ? y.type : "info", w = ++r.current, g = Number.isFinite(y.duration) ? Math.max(0, y.duration) : 3e3;
251
251
  if (!n.current) return null;
252
- const u = e.current.getSnapshot(), s = u.slice(0, Math.max(0, u.length - 4));
252
+ const i = e.current.getSnapshot(), s = i.slice(0, Math.max(0, i.length - 4));
253
253
  for (const B of s)
254
254
  clearTimeout(t.current.get(B.id)), t.current.delete(B.id);
255
- return e.current.publish([...u.slice(-4), { id: x, message: m, type: C, dismissible: y.dismissible !== !1 }]), g > 0 && t.current.set(x, setTimeout(() => c(x), g)), x;
256
- }, [c]), i = K(() => {
257
- const m = (l, y) => f(l, y);
258
- for (const l of ["success", "error", "warning", "info"]) m[l] = (y, C = {}) => f(y, { ...C, type: l });
259
- return m.promise = async (l, y, C = {}) => {
260
- const x = f(y.loading, { ...C, type: "info", duration: 0 });
255
+ return e.current.publish([...i.slice(-4), { id: w, message: u, type: C, dismissible: y.dismissible !== !1 }]), g > 0 && t.current.set(w, setTimeout(() => c(w), g)), w;
256
+ }, [c]), l = K(() => {
257
+ const u = (d, y) => f(d, y);
258
+ for (const d of ["success", "error", "warning", "info"]) u[d] = (y, C = {}) => f(y, { ...C, type: d });
259
+ return u.promise = async (d, y, C = {}) => {
260
+ const w = f(y.loading, { ...C, type: "info", duration: 0 });
261
261
  try {
262
- const g = await (typeof l == "function" ? l() : l);
263
- x != null && c(x);
264
- const u = typeof y.success == "function" ? y.success(g) : y.success;
265
- return u && f(u, { ...C, type: "success" }), g;
262
+ const g = await (typeof d == "function" ? d() : d);
263
+ w != null && c(w);
264
+ const i = typeof y.success == "function" ? y.success(g) : y.success;
265
+ return i && f(i, { ...C, type: "success" }), g;
266
266
  } catch (g) {
267
- x != null && c(x);
268
- const u = typeof y.error == "function" ? y.error(g) : y.error;
269
- throw u && f(u, { ...C, type: "error" }), g;
267
+ w != null && c(w);
268
+ const i = typeof y.error == "function" ? y.error(g) : y.error;
269
+ throw i && f(i, { ...C, type: "error" }), g;
270
270
  }
271
- }, m.dismiss = c, m.clear = () => {
272
- for (const l of t.current.values()) clearTimeout(l);
271
+ }, u.dismiss = c, u.clear = () => {
272
+ for (const d of t.current.values()) clearTimeout(d);
273
273
  t.current.clear(), e.current.publish([]);
274
- }, m;
274
+ }, u;
275
275
  }, [f, c]);
276
276
  return H(() => () => {
277
- for (const m of t.current.values()) clearTimeout(m);
277
+ for (const u of t.current.values()) clearTimeout(u);
278
278
  t.current.clear();
279
- }, []), { toast: i, dismissToast: c };
279
+ }, []), { toast: l, dismissToast: c };
280
280
  }
281
281
  function Nn(e, n, r) {
282
- const t = d(/* @__PURE__ */ new Map()), c = d(0), f = v(() => {
282
+ const t = m(/* @__PURE__ */ new Map()), c = m(0), f = v(() => {
283
283
  if (!n.current) return;
284
- const g = [...t.current.values()], u = { visible: g.length > 0, text: g.at(-1)?.text ?? null, count: g.length }, s = e.current.getSnapshot();
285
- (s.visible !== u.visible || s.text !== u.text || s.count !== u.count) && e.current.publish(u);
286
- }, []), i = v((g, u) => {
284
+ const g = [...t.current.values()], i = { visible: g.length > 0, text: g.at(-1)?.text ?? null, count: g.length }, s = e.current.getSnapshot();
285
+ (s.visible !== i.visible || s.text !== i.text || s.count !== i.count) && e.current.publish(i);
286
+ }, []), l = v((g, i) => {
287
287
  if (!n.current || g !== "global" && r.current !== g) return null;
288
288
  const s = ++c.current;
289
- return t.current.set(s, { owner: g, text: u }), f(), s;
290
- }, [f]), m = v((g, u) => {
291
- if (u != null)
292
- t.current.get(u)?.owner === g && t.current.delete(u);
289
+ return t.current.set(s, { owner: g, text: i }), f(), s;
290
+ }, [f]), u = v((g, i) => {
291
+ if (i != null)
292
+ t.current.get(i)?.owner === g && t.current.delete(i);
293
293
  else
294
294
  for (const [s, B] of t.current) B.owner === g && t.current.delete(s);
295
295
  f();
296
- }, [f]), l = v((g, u) => {
297
- g ? (m("global"), i("global", u)) : m("global");
298
- }, [i, m]), y = v((g, u, s) => {
299
- u ? (m(g), i(g, s)) : m(g);
300
- }, [i, m]);
301
- return { loadingApi: K(() => ({ setLoading: l, setScreenLoading: y, begin: i, end: m }), [l, y, i, m]), refreshLoading: f, loadingTasks: t, setLoading: l };
296
+ }, [f]), d = v((g, i) => {
297
+ g ? (u("global"), l("global", i)) : u("global");
298
+ }, [l, u]), y = v((g, i, s) => {
299
+ i ? (u(g), l(g, s)) : u(g);
300
+ }, [l, u]);
301
+ return { loadingApi: K(() => ({ setLoading: d, setScreenLoading: y, begin: l, end: u }), [d, y, l, u]), refreshLoading: f, loadingTasks: t, setLoading: d };
302
302
  }
303
303
  const Pn = Ne.memo(function({ store: n, translate: r }) {
304
304
  const t = be(n.subscribe, n.getSnapshot, n.getSnapshot);
@@ -309,106 +309,106 @@ const Pn = Ne.memo(function({ store: n, translate: r }) {
309
309
  }), Bn = Ne.memo(function({ store: n, routeKey: r, ...t }) {
310
310
  const c = be(n.subscribe, n.getSnapshot, n.getSnapshot);
311
311
  return /* @__PURE__ */ h(En, { ...t, override: c[r] });
312
- }), An = Ne.memo(function({ route: n, screen: r, navigation: t, focused: c, resultEvent: f, setFooter: i, loadingApi: m, loadingStore: l, bodyClassName: y, notifyError: C, registerDirtyGuard: x }) {
313
- const g = r.component, u = K(() => ({ isFocused: c, resultEvent: f, routeKey: n.key, setFooter: i }), [c, f, n.key, i]), s = K(() => ({
314
- setLoading: (R, A) => m.setScreenLoading(n.key, R, A),
315
- showLoading: (R) => m.begin(n.key, R),
316
- hideLoading: (R) => m.end(n.key, R)
317
- }), [m, n.key]), B = K(() => ({ routeKey: n.key, registerDirtyGuard: x }), [n.key, x]);
318
- return /* @__PURE__ */ h(on.Provider, { value: n, children: /* @__PURE__ */ h(tn.Provider, { value: B, children: /* @__PURE__ */ h(je.Provider, { value: u, children: /* @__PURE__ */ h(Fe.Provider, { value: s, children: /* @__PURE__ */ h(Ye.Provider, { value: l, children: /* @__PURE__ */ h("div", { hidden: !c, inert: !c, "data-modal-route-key": n.key, tabIndex: -1, className: `pmn-body ${y ?? ""}`, children: /* @__PURE__ */ h(Cn, { route: n, onError: C, children: /* @__PURE__ */ h(g, { route: n, navigation: t }) }) }) }) }) }) }) });
312
+ }), An = Ne.memo(function({ route: n, screen: r, navigation: t, focused: c, resultEvent: f, setFooter: l, loadingApi: u, loadingStore: d, bodyClassName: y, notifyError: C, registerDirtyGuard: w }) {
313
+ const g = r.component, i = K(() => ({ isFocused: c, resultEvent: f, routeKey: n.key, setFooter: l }), [c, f, n.key, l]), s = K(() => ({
314
+ setLoading: (R, A) => u.setScreenLoading(n.key, R, A),
315
+ showLoading: (R) => u.begin(n.key, R),
316
+ hideLoading: (R) => u.end(n.key, R)
317
+ }), [u, n.key]), B = K(() => ({ routeKey: n.key, registerDirtyGuard: w }), [n.key, w]);
318
+ return /* @__PURE__ */ h(on.Provider, { value: n, children: /* @__PURE__ */ h(tn.Provider, { value: B, children: /* @__PURE__ */ h(je.Provider, { value: i, children: /* @__PURE__ */ h(Fe.Provider, { value: s, children: /* @__PURE__ */ h(Ye.Provider, { value: d, children: /* @__PURE__ */ h("div", { hidden: !c, inert: !c, "data-modal-route-key": n.key, tabIndex: -1, className: `pmn-body ${y ?? ""}`, children: /* @__PURE__ */ h(Cn, { route: n, onError: C, children: /* @__PURE__ */ h(g, { route: n, navigation: t }) }) }) }) }) }) }) });
319
319
  });
320
- function qn({ config: e, initialScreen: n, params: r, options: t, translate: c, onRequestClose: f, onOpened: i, registerLoading: m, notifyError: l, error: y, clearError: C, registerDirtyGuard: x, canNavigate: g, exiting: u = !1 }) {
321
- const [s, B] = ln(qe, null, () => an(n ?? e.initialRoute, r)), R = d(null);
320
+ function qn({ config: e, initialScreen: n, params: r, options: t, translate: c, onRequestClose: f, onOpened: l, registerLoading: u, notifyError: d, error: y, clearError: C, registerDirtyGuard: w, canNavigate: g, exiting: i = !1 }) {
321
+ const [s, B] = ln(qe, null, () => an(n ?? e.initialRoute, r)), R = m(null);
322
322
  R.current || (R.current = hn({ canGoBack: s.length > 1, stack: s, currentRoute: s.at(-1) }));
323
- const A = d(null), q = d(null), $ = d(null);
323
+ const A = m(null), q = m(null), $ = m(null);
324
324
  A.current || (A.current = ze({ visible: !1, text: null, count: 0 })), q.current || (q.current = ze({})), $.current || ($.current = ze([]));
325
- const E = d(!0), z = d(0), { toast: U, dismissToast: W } = Tn($, E);
325
+ const E = m(!0), z = m(0), { toast: U, dismissToast: W } = Tn($, E);
326
326
  H(() => (E.current = !0, () => {
327
327
  E.current = !1, z.current++;
328
328
  }), []);
329
- const [M, b] = ie({}), T = d(/* @__PURE__ */ new Map()), j = d(null), F = d(null), N = d(!1), V = d(!1), L = d(/* @__PURE__ */ new Map()), ne = d(0), te = v((o, w, P) => {
329
+ const [M, b] = ie({}), T = m(/* @__PURE__ */ new Map()), j = m(null), F = m(null), N = m(!1), V = m(!1), L = m(/* @__PURE__ */ new Map()), ne = m(0), te = v((o, x, P) => {
330
330
  for (const [I, ce] of L.current)
331
- o.includes(ce.key) && (L.current.delete(I), ce.resolve({ status: w, ...w === "returned" ? { value: P } : {} }));
332
- }, []), O = d(s);
331
+ o.includes(ce.key) && (L.current.delete(I), ce.resolve({ status: x, ...x === "returned" ? { value: P } : {} }));
332
+ }, []), O = m(s);
333
333
  O.current = s;
334
- const le = d(g);
334
+ const le = m(g);
335
335
  le.current = g;
336
- const re = d(!1), Ee = d(0), G = s.at(-1), D = G.key, ue = d(D);
336
+ const re = m(!1), Ee = m(0), G = s.at(-1), D = G.key, ue = m(D);
337
337
  ue.current = D;
338
- const { loadingApi: Se, refreshLoading: Ce, loadingTasks: ye, setLoading: pe } = Nn(A, E, ue), oe = e.screens, Pe = A, ve = d(m);
339
- ve.current = m, H(() => (ve.current?.({ setLoading: pe }), () => ve.current?.(null)), [pe]);
340
- const Le = v((o, w) => {
338
+ const { loadingApi: Se, refreshLoading: Ce, loadingTasks: ye, setLoading: pe } = Nn(A, E, ue), oe = e.screens, Pe = A, ve = m(u);
339
+ ve.current = u, H(() => (ve.current?.({ setLoading: pe }), () => ve.current?.(null)), [pe]);
340
+ const Le = v((o, x) => {
341
341
  if (!E.current) return;
342
342
  const P = q.current.getSnapshot();
343
- if (w === null) {
343
+ if (x === null) {
344
344
  if (!(o in P)) return;
345
345
  const I = { ...P };
346
346
  delete I[o], q.current.publish(I);
347
347
  return;
348
348
  }
349
- P[o] !== w && q.current.publish({ ...P, [o]: w });
349
+ P[o] !== x && q.current.publish({ ...P, [o]: x });
350
350
  }, []), Re = v(() => {
351
351
  if (typeof document > "u") return;
352
352
  const o = document.activeElement;
353
353
  if (!(o instanceof HTMLElement) || !j.current?.contains(o)) return;
354
- const w = o.closest("[data-modal-route-key]");
355
- w && T.current.set(w.dataset.modalRouteKey, o), j.current.focus({ preventScroll: !0 });
354
+ const x = o.closest("[data-modal-route-key]");
355
+ x && T.current.set(x.dataset.modalRouteKey, o), j.current.focus({ preventScroll: !0 });
356
356
  }, []), Me = v((o) => {
357
357
  if (!Object.prototype.hasOwnProperty.call(oe, o)) throw new Error(`[react-modal-navigation] Unknown modal screen: ${o}`);
358
- }, [oe]), de = v((o, w) => {
358
+ }, [oe]), de = v((o, x) => {
359
359
  try {
360
- Promise.resolve(t[o]?.(w)).catch((P) => l(P, { phase: o }));
360
+ Promise.resolve(t[o]?.(x)).catch((P) => d(P, { phase: o }));
361
361
  } catch (P) {
362
- l(P, { phase: o });
362
+ d(P, { phase: o });
363
363
  }
364
- }, [t, l]), Z = v(async (o, w, P, I) => {
364
+ }, [t, d]), Z = v(async (o, x, P, I) => {
365
365
  if (!E.current || V.current) return !1;
366
366
  const ce = z.current, X = O.current, De = X.at(-1);
367
- if (o !== "BACK" && Me(w), o === "BACK" && X.length <= 1) return !1;
368
- const Ve = o === "NAVIGATE" ? X.findIndex((ke) => ke.name === w) : -1, Ie = o === "RESET" ? X : o === "BACK" || o === "REPLACE" ? [De] : Ve >= 0 ? X.slice(Ve + 1) : [];
367
+ if (o !== "BACK" && Me(x), o === "BACK" && X.length <= 1) return !1;
368
+ const Ve = o === "NAVIGATE" ? X.findIndex((ke) => ke.name === x) : -1, Ie = o === "RESET" ? X : o === "BACK" || o === "REPLACE" ? [De] : Ve >= 0 ? X.slice(Ve + 1) : [];
369
369
  V.current = !0;
370
370
  try {
371
371
  if (Ie.length && le.current && !await le.current(Ie.map(($e) => $e.key), {
372
372
  reason: "navigation",
373
373
  action: o,
374
374
  from: De,
375
- to: o === "BACK" ? X.at(-2)?.name : w
375
+ to: o === "BACK" ? X.at(-2)?.name : x
376
376
  }) || !E.current || ce !== z.current || O.current.at(-1)?.key !== De.key) return !1;
377
377
  if (o === "BACK" && I !== void 0) {
378
378
  const Ae = X.at(-2);
379
379
  b(($e) => ({ ...$e, [Ae.key]: { id: ++Ee.current, data: I } }));
380
380
  }
381
381
  o === "RESET" && b({}), te(Ie.map((Ae) => Ae.key), o === "BACK" ? "returned" : "removed", I), Re();
382
- const ke = { type: o, name: w, params: P };
382
+ const ke = { type: o, name: x, params: P };
383
383
  return O.current = qe(O.current, ke), B(ke), !0;
384
384
  } catch (ke) {
385
- return E.current && l(ke, { phase: "navigationGuard", action: o }), !1;
385
+ return E.current && d(ke, { phase: "navigationGuard", action: o }), !1;
386
386
  } finally {
387
387
  V.current = !1;
388
388
  }
389
- }, [Me, Re, l, te]), a = v((o, w) => Z("NAVIGATE", o, w), [Z]), p = v(async (o, w) => {
389
+ }, [Me, Re, d, te]), a = v((o, x) => Z("NAVIGATE", o, x), [Z]), p = v(async (o, x) => {
390
390
  if (!E.current) return { status: "cancelled" };
391
- if (O.current, !await Z("NAVIGATE", o, w) || !E.current) return { status: "cancelled" };
391
+ if (O.current, !await Z("NAVIGATE", o, x) || !E.current) return { status: "cancelled" };
392
392
  const I = O.current.at(-1);
393
393
  return !I || I.name !== o ? { status: "cancelled" } : new Promise((ce) => {
394
394
  const X = ++ne.current;
395
395
  L.current.set(X, { key: I.key, resolve: ce });
396
396
  });
397
- }, [Z]), S = v((o, w) => Z("REPLACE", o, w), [Z]), k = v((o, w) => Z("RESET", o, w), [Z]), Y = v((o) => {
397
+ }, [Z]), S = v((o, x) => Z("REPLACE", o, x), [Z]), k = v((o, x) => Z("RESET", o, x), [Z]), Y = v((o) => {
398
398
  if (!o || typeof o != "object" || Array.isArray(o)) throw new TypeError("[react-modal-navigation] setParams expects an object");
399
399
  if (!E.current) return;
400
- const w = { type: "SET_PARAMS", params: o };
401
- O.current = qe(O.current, w), B(w);
400
+ const x = { type: "SET_PARAMS", params: o };
401
+ O.current = qe(O.current, x), B(x);
402
402
  }, []), _ = v((o) => {
403
403
  if (!o || typeof o != "object" || Array.isArray(o)) throw new TypeError("[react-modal-navigation] setOptions expects an object");
404
404
  if (!E.current) return;
405
- const w = { type: "SET_OPTIONS", options: o };
406
- O.current = qe(O.current, w), B(w);
407
- }, []), J = v((o) => Z("BACK", null, void 0, o), [Z]), ae = v((o, w) => !E.current || Pe.current.getSnapshot().visible && t.lockCloseWhileLoading !== !1 ? Promise.resolve(!1) : f(o, w, { route: G, stack: s }), [t.lockCloseWhileLoading, f, G, s]), se = d(ae);
405
+ const x = { type: "SET_OPTIONS", options: o };
406
+ O.current = qe(O.current, x), B(x);
407
+ }, []), J = v((o) => Z("BACK", null, void 0, o), [Z]), ae = v((o, x) => !E.current || Pe.current.getSnapshot().visible && t.lockCloseWhileLoading !== !1 ? Promise.resolve(!1) : f(o, x, { route: G, stack: s }), [t.lockCloseWhileLoading, f, G, s]), se = m(ae);
408
408
  se.current = ae;
409
409
  const fe = v((o) => se.current("api", o), []), we = K(() => ({ navigate: a, navigateAsync: p, replace: S, reset: k, setParams: Y, setOptions: _, goBack: J, close: fe, setLoading: pe }), [a, p, S, k, Y, _, J, fe, pe]), xe = K(() => ({ canGoBack: s.length > 1, stack: s, currentRoute: G }), [s]);
410
410
  Qe(() => R.current.publish(xe), [xe]);
411
- const he = d(null);
411
+ const he = m(null);
412
412
  he.current || (he.current = Object.defineProperties({}, {
413
413
  canGoBack: { enumerable: !0, get: () => R.current.getSnapshot().canGoBack },
414
414
  stack: { enumerable: !0, get: () => R.current.getSnapshot().stack },
@@ -419,21 +419,21 @@ function qn({ config: e, initialScreen: n, params: r, options: t, translate: c,
419
419
  N.current = !1;
420
420
  const o = [...j.current?.querySelectorAll("[data-modal-route-key]") ?? []].find((I) => I.dataset.modalRouteKey === D);
421
421
  if (!o) return;
422
- const w = T.current.get(D);
423
- (w?.isConnected && o.contains(w) && !w.matches(":disabled") && !w.closest("[inert], [hidden]") ? w : o).focus({ preventScroll: !0 });
422
+ const x = T.current.get(D);
423
+ (x?.isConnected && o.contains(x) && !x.matches(":disabled") && !x.closest("[inert], [hidden]") ? x : o).focus({ preventScroll: !0 });
424
424
  }, [D]), H(() => {
425
425
  let o = !1;
426
426
  for (const [P, I] of ye.current)
427
427
  I.owner !== "global" && I.owner !== D && (ye.current.delete(P), o = !0);
428
428
  o && Ce();
429
- const w = new Set(s.map((P) => P.key));
429
+ const x = new Set(s.map((P) => P.key));
430
430
  b((P) => {
431
- const I = Object.keys(P).filter((X) => !w.has(X));
431
+ const I = Object.keys(P).filter((X) => !x.has(X));
432
432
  if (!I.length) return P;
433
433
  const ce = { ...P };
434
434
  return I.forEach((X) => delete ce[X]), ce;
435
435
  });
436
- for (const P of T.current.keys()) w.has(P) || T.current.delete(P);
436
+ for (const P of T.current.keys()) x.has(P) || T.current.delete(P);
437
437
  }, [D, s, Ce]), H(() => {
438
438
  if (F.current?.key !== D) {
439
439
  if (F.current) {
@@ -447,11 +447,11 @@ function qn({ config: e, initialScreen: n, params: r, options: t, translate: c,
447
447
  for (const o of L.current.values()) o.resolve({ status: "dismissed" });
448
448
  L.current.clear();
449
449
  }, []), H(() => {
450
- re.current || (re.current = !0, i?.({ route: G, stack: s }));
450
+ re.current || (re.current = !0, l?.({ route: G, stack: s }));
451
451
  }, []);
452
452
  const cn = K(() => bn(s, oe, t.maxCachedScreens), [s, oe, t.maxCachedScreens]), _e = K(() => ({ ...oe[G.name], ...G.options ?? {} }), [oe, G.name, G.options]);
453
- return /* @__PURE__ */ h(rn.Provider, { value: U, children: /* @__PURE__ */ h(fn.Provider, { value: $.current, children: /* @__PURE__ */ h(pn.Provider, { value: q.current, children: /* @__PURE__ */ h(mn.Provider, { value: Be, children: /* @__PURE__ */ h(Ue.Provider, { value: we, children: /* @__PURE__ */ h(We.Provider, { value: R.current, children: /* @__PURE__ */ h(Fe.Provider, { value: Se, children: /* @__PURE__ */ me(xn, { dialogRef: j, options: t, requestClose: ae, exiting: u, children: [
454
- /* @__PURE__ */ h(kn, { options: t, screen: _e, route: G, navigation: Be, requestClose: ae, translate: c }),
453
+ return /* @__PURE__ */ h(rn.Provider, { value: U, children: /* @__PURE__ */ h(fn.Provider, { value: $.current, children: /* @__PURE__ */ h(pn.Provider, { value: q.current, children: /* @__PURE__ */ h(mn.Provider, { value: Be, children: /* @__PURE__ */ h(Ue.Provider, { value: we, children: /* @__PURE__ */ h(We.Provider, { value: R.current, children: /* @__PURE__ */ h(Fe.Provider, { value: Se, children: /* @__PURE__ */ me(xn, { dialogRef: j, options: t, requestClose: ae, exiting: i, children: [
454
+ /* @__PURE__ */ h(kn, { options: t, screen: _e, route: G, navigation: Be, requestClose: ae, translate: c, canGoBack: s.length > 1 }),
455
455
  /* @__PURE__ */ h("main", { className: "pmn-main", children: cn.map((o) => /* @__PURE__ */ h(
456
456
  An,
457
457
  {
@@ -464,8 +464,8 @@ function qn({ config: e, initialScreen: n, params: r, options: t, translate: c,
464
464
  setFooter: Le,
465
465
  loadingApi: Se,
466
466
  loadingStore: A.current,
467
- notifyError: l,
468
- registerDirtyGuard: x
467
+ notifyError: d,
468
+ registerDirtyGuard: w
469
469
  },
470
470
  o.key
471
471
  )) }),
@@ -480,7 +480,7 @@ function qn({ config: e, initialScreen: n, params: r, options: t, translate: c,
480
480
  navigation: Be,
481
481
  requestClose: ae,
482
482
  translate: c,
483
- onError: l,
483
+ onError: d,
484
484
  loadingApi: Se
485
485
  },
486
486
  D
@@ -516,20 +516,20 @@ function Oe(e, n, r) {
516
516
  }
517
517
  if (e === null || typeof e != "object" || Array.isArray(e))
518
518
  throw new TypeError("[react-modal-navigation] open expects a modal name or a configuration object");
519
- const { name: t, screen: c, params: f = {}, options: i = {}, ...m } = e;
519
+ const { name: t, screen: c, params: f = {}, options: l = {}, ...u } = e;
520
520
  if (typeof t != "string" || !t.trim())
521
521
  throw new TypeError("[react-modal-navigation] open config requires a non-empty string name");
522
- if (i === null || typeof i != "object" || Array.isArray(i))
522
+ if (l === null || typeof l != "object" || Array.isArray(l))
523
523
  throw new TypeError("[react-modal-navigation] open config options must be an object");
524
524
  if (c !== void 0 && (typeof c != "string" || !c.trim()))
525
525
  throw new TypeError("[react-modal-navigation] screen must be a non-empty string");
526
- return { name: t, ...c === void 0 ? {} : { screen: c }, params: f, options: { ...m, ...i } };
526
+ return { name: t, ...c === void 0 ? {} : { screen: c }, params: f, options: { ...u, ...l } };
527
527
  }
528
528
  const Fn = { placement: "right", showHeader: !0, showBackButton: !0, showCloseButton: !0, viewportGap: 5, borderRadius: 12, closeOnOverlay: !1, closeOnEsc: !0 }, Dn = (e) => ({ "modal.loading": "加载中...", "modal.processing": "处理中...", "modal.back": "返回", "modal.close": "关闭", "modal.cancel": "取消", "modal.done": "完成" })[e] ?? e;
529
- function _n({ registry: e, children: n, defaultOptions: r = {}, backgroundColor: t, theme: c, translate: f = Dn, onError: i, confirmDiscard: m }) {
529
+ function _n({ registry: e, children: n, defaultOptions: r = {}, backgroundColor: t, theme: c, translate: f = Dn, onError: l, confirmDiscard: u }) {
530
530
  jn();
531
- const [l, y] = ie(null), [C, x] = ie(null), [g, u] = ie(0), s = d(null), B = d(/* @__PURE__ */ new Map()), R = d([]), A = d(null), q = d(null), $ = d(0), E = d(null), z = d(!1), U = d(0), W = d(null), M = d(/* @__PURE__ */ new Map()), [b, T] = ie(!1), j = d(m);
532
- j.current = m;
531
+ const [d, y] = ie(null), [C, w] = ie(null), [g, i] = ie(0), s = m(null), B = m(/* @__PURE__ */ new Map()), R = m([]), A = m(null), q = m(null), $ = m(0), E = m(null), z = m(!1), U = m(0), W = m(null), M = m(/* @__PURE__ */ new Map()), [b, T] = ie(!1), j = m(u);
532
+ j.current = u;
533
533
  const F = v((a, p) => (M.current.set(a, p), () => {
534
534
  M.current.get(a) === p && M.current.delete(a);
535
535
  }), []), N = v(async (a) => {
@@ -545,10 +545,10 @@ function _n({ registry: e, children: n, defaultOptions: r = {}, backgroundColor:
545
545
  if ((k.onBeforeDiscard ? await k.onBeforeDiscard(p) : j.current ? await j.current(p) : typeof window < "u" && typeof window.confirm == "function" ? window.confirm(k.message || "有未保存的修改,确定放弃吗?") : !1) === !1) return !1;
546
546
  }
547
547
  return !0;
548
- }, []), L = d(!0), ne = d(null), te = d(i);
549
- te.current = i;
548
+ }, []), L = m(!0), ne = m(null), te = m(l);
549
+ te.current = l;
550
550
  const O = v((a, p) => {
551
- L.current && x(a);
551
+ L.current && w(a);
552
552
  try {
553
553
  te.current ? te.current(a, p) : console.error("[react-modal-navigation]", a);
554
554
  } catch (S) {
@@ -557,7 +557,7 @@ function _n({ registry: e, children: n, defaultOptions: r = {}, backgroundColor:
557
557
  }, []), le = v((a, p) => {
558
558
  const S = B.current.get(a);
559
559
  B.current.delete(a), S?.(p);
560
- }, []), re = v((a) => ({ ...Fn, ...r, ...c !== void 0 ? { theme: c } : {}, ...t !== void 0 ? { backgroundColor: t } : {}, ...a.config.modalOptions, ...a.overrides }), [r, c, t]), Ee = l ? re(l) : null, G = d(null);
560
+ }, []), re = v((a) => ({ ...Fn, ...r, ...c !== void 0 ? { theme: c } : {}, ...t !== void 0 ? { backgroundColor: t } : {}, ...a.config.modalOptions, ...a.overrides }), [r, c, t]), Ee = d ? re(d) : null, G = m(null);
561
561
  G.current = Ee, ne.current = Ee;
562
562
  const D = v(async (a = "api", p, S = {}) => {
563
563
  const k = s.current;
@@ -608,7 +608,7 @@ function _n({ registry: e, children: n, defaultOptions: r = {}, backgroundColor:
608
608
  if (!L.current || ae !== U.current) return null;
609
609
  }
610
610
  const fe = { id: ++$.current, name: a, screen: J, params: p, config: _, overrides: S };
611
- return s.current = fe, W.current = null, k && B.current.set(fe.id, k), x(null), y(fe), fe.id;
611
+ return s.current = fe, W.current = null, k && B.current.set(fe.id, k), w(null), y(fe), fe.id;
612
612
  } finally {
613
613
  z.current = !1;
614
614
  }
@@ -618,7 +618,7 @@ function _n({ registry: e, children: n, defaultOptions: r = {}, backgroundColor:
618
618
  if (!L.current || s.current || z.current || E.current) return;
619
619
  const a = R.current.shift();
620
620
  if (a) {
621
- u(R.current.length);
621
+ i(R.current.length);
622
622
  try {
623
623
  const p = await A.current(a.args.name, a.args.params, a.args.options, a.resolveResult, a.args.screen);
624
624
  p === null ? (a.resolveResult?.({ status: "dismissed", reason: "blocked" }), a.resolveId?.(null), queueMicrotask(() => q.current?.())) : a.resolveId?.(p);
@@ -631,12 +631,12 @@ function _n({ registry: e, children: n, defaultOptions: r = {}, backgroundColor:
631
631
  const Ce = v((a, p, S) => {
632
632
  const k = Oe(a, p, S);
633
633
  return e?.[k.name] ? new Promise((Y, _) => {
634
- R.current.push({ args: k, resolveId: Y, reject: _ }), u(R.current.length), queueMicrotask(() => q.current?.());
634
+ R.current.push({ args: k, resolveId: Y, reject: _ }), i(R.current.length), queueMicrotask(() => q.current?.());
635
635
  }) : Promise.reject(new Error(`[react-modal-navigation] Unknown modal: ${k.name}`));
636
636
  }, [e]), ye = v((a, p, S) => {
637
637
  const k = Oe(a, p, S);
638
638
  return e?.[k.name] ? new Promise((Y, _) => {
639
- R.current.push({ args: k, resolveResult: Y, reject: _ }), u(R.current.length), queueMicrotask(() => q.current?.());
639
+ R.current.push({ args: k, resolveResult: Y, reject: _ }), i(R.current.length), queueMicrotask(() => q.current?.());
640
640
  }) : Promise.reject(new Error(`[react-modal-navigation] Unknown modal: ${k.name}`));
641
641
  }, [e]), pe = v((a) => {
642
642
  if (!a || typeof a != "object" || Array.isArray(a)) throw new TypeError("[react-modal-navigation] update expects an options object");
@@ -646,7 +646,7 @@ function _n({ registry: e, children: n, defaultOptions: r = {}, backgroundColor:
646
646
  return s.current = S, y(S), ne.current = re(S), !0;
647
647
  }, [re]), oe = v((a = "queue-cleared") => {
648
648
  const p = R.current.splice(0);
649
- u(0);
649
+ i(0);
650
650
  for (const S of p)
651
651
  S.resolveId?.(null), S.resolveResult?.({ status: "dismissed", reason: a });
652
652
  return p.length;
@@ -660,7 +660,7 @@ function _n({ registry: e, children: n, defaultOptions: r = {}, backgroundColor:
660
660
  J === null && Y({ status: "dismissed", reason: "blocked" });
661
661
  }, _);
662
662
  });
663
- }, [ue]), Le = v((a) => D("api", a), [D]), Re = v((a = "api") => D(a), [D]), Me = v((a) => D("confirm", a, { confirmed: !0 }), [D]), de = v((a, p) => W.current?.setLoading(a, p), []), Z = K(() => ({ open: Pe, openAsync: ve, enqueue: Ce, enqueueAsync: ye, update: pe, clearQueue: oe, close: Le, dismiss: Re, confirm: Me, setLoading: de, queueSize: g, isOpen: !!l, activeName: l?.name ?? null, error: C, clearError: () => x(null) }), [Pe, ve, Ce, ye, pe, oe, Le, Re, Me, de, l, C, g]);
663
+ }, [ue]), Le = v((a) => D("api", a), [D]), Re = v((a = "api") => D(a), [D]), Me = v((a) => D("confirm", a, { confirmed: !0 }), [D]), de = v((a, p) => W.current?.setLoading(a, p), []), Z = K(() => ({ open: Pe, openAsync: ve, enqueue: Ce, enqueueAsync: ye, update: pe, clearQueue: oe, close: Le, dismiss: Re, confirm: Me, setLoading: de, queueSize: g, isOpen: !!d, activeName: d?.name ?? null, error: C, clearError: () => w(null) }), [Pe, ve, Ce, ye, pe, oe, Le, Re, Me, de, d, C, g]);
664
664
  return H(() => (L.current = !0, () => {
665
665
  L.current = !1, U.current += 1, s.current = null;
666
666
  for (const p of B.current.values()) p({ status: "dismissed", reason: "unmount" });
@@ -670,17 +670,17 @@ function _n({ registry: e, children: n, defaultOptions: r = {}, backgroundColor:
670
670
  p.resolveId?.(null), p.resolveResult?.({ status: "dismissed", reason: "unmount" });
671
671
  }), []), /* @__PURE__ */ me(nn.Provider, { value: Z, children: [
672
672
  n,
673
- l && /* @__PURE__ */ h(
673
+ d && /* @__PURE__ */ h(
674
674
  qn,
675
675
  {
676
- config: l.config,
677
- initialScreen: l.screen,
678
- params: l.params,
676
+ config: d.config,
677
+ initialScreen: d.screen,
678
+ params: d.params,
679
679
  options: Ee,
680
680
  translate: f,
681
681
  notifyError: O,
682
682
  error: C,
683
- clearError: () => x(null),
683
+ clearError: () => w(null),
684
684
  registerLoading: (a) => {
685
685
  W.current = a;
686
686
  },
@@ -697,7 +697,7 @@ function _n({ registry: e, children: n, defaultOptions: r = {}, backgroundColor:
697
697
  }
698
698
  }
699
699
  },
700
- l.id
700
+ d.id
701
701
  )
702
702
  ] });
703
703
  }
@@ -712,14 +712,14 @@ function Vn() {
712
712
  return n;
713
713
  };
714
714
  return {
715
- navigate: (...i) => f().navigate(...i),
716
- replace: (...i) => f().replace(...i),
717
- reset: (...i) => f().reset(...i),
718
- setParams: (...i) => f().setParams(...i),
719
- setOptions: (...i) => f().setOptions(...i),
720
- goBack: (...i) => f().goBack(...i),
721
- close: (...i) => f().close(...i),
722
- setLoading: (...i) => f().setLoading(...i),
715
+ navigate: (...l) => f().navigate(...l),
716
+ replace: (...l) => f().replace(...l),
717
+ reset: (...l) => f().reset(...l),
718
+ setParams: (...l) => f().setParams(...l),
719
+ setOptions: (...l) => f().setOptions(...l),
720
+ goBack: (...l) => f().goBack(...l),
721
+ close: (...l) => f().close(...l),
722
+ setLoading: (...l) => f().setLoading(...l),
723
723
  canGoBack: t.canGoBack,
724
724
  stack: t.stack,
725
725
  currentRoute: t.currentRoute
@@ -756,7 +756,7 @@ function Jn(e) {
756
756
  function Xn(e) {
757
757
  const n = Q(je);
758
758
  if (!n) throw new Error("useNavigationResult requires an active modal screen");
759
- const r = d(e), t = d(null);
759
+ const r = m(e), t = m(null);
760
760
  H(() => {
761
761
  r.current = e;
762
762
  }, [e]), H(() => {
@@ -766,9 +766,9 @@ function Xn(e) {
766
766
  function Zn(e = {}) {
767
767
  const n = Q(je);
768
768
  if (!n) throw new Error("[react-modal-navigation] useModalFooter requires an active modal screen");
769
- const { setFooter: r, routeKey: t } = n, c = d(e);
769
+ const { setFooter: r, routeKey: t } = n, c = m(e);
770
770
  c.current = e;
771
- const f = K(() => (...M) => c.current.done?.(...M), []), i = K(() => (...M) => (c.current.cancel ?? c.current.cancle)?.(...M), []), m = K(() => (...M) => c.current.renderFooter?.(...M), []), l = typeof e.done == "function", y = typeof (e.cancel ?? e.cancle) == "function", C = typeof e.renderFooter == "function", { showFooter: x, showFooterBorder: g, doneDisabled: u, doneText: s, cancelText: B, loadingText: R, footerClassName: A } = e, q = d({ source: null, normalized: void 0 }), $ = Array.isArray(e.actions) ? e.actions : null, E = q.current.source;
771
+ const f = K(() => (...M) => c.current.done?.(...M), []), l = K(() => (...M) => (c.current.cancel ?? c.current.cancle)?.(...M), []), u = K(() => (...M) => c.current.renderFooter?.(...M), []), d = typeof e.done == "function", y = typeof (e.cancel ?? e.cancle) == "function", C = typeof e.renderFooter == "function", { showFooter: w, showFooterBorder: g, doneDisabled: i, doneText: s, cancelText: B, loadingText: R, footerClassName: A } = e, q = m({ source: null, normalized: void 0 }), $ = Array.isArray(e.actions) ? e.actions : null, E = q.current.source;
772
772
  $ === E || $ && E && $.length === E.length && $.every((M, b) => {
773
773
  const T = E[b];
774
774
  return [.../* @__PURE__ */ new Set([...Object.keys(M), ...Object.keys(T)])].every((F) => F === "onClick" || Object.is(M[F], T[F]));
@@ -780,18 +780,18 @@ function Zn(e = {}) {
780
780
  }))
781
781
  });
782
782
  const U = q.current.normalized, W = K(() => ({
783
- showFooter: x,
783
+ showFooter: w,
784
784
  showFooterBorder: g,
785
- doneDisabled: u,
785
+ doneDisabled: i,
786
786
  doneText: s,
787
787
  cancelText: B,
788
788
  loadingText: R,
789
789
  footerClassName: A,
790
790
  ...U !== void 0 ? { actions: U } : {},
791
- ...l ? { done: f } : {},
792
- ...y ? { cancel: i } : {},
793
- ...C ? { renderFooter: m } : {}
794
- }), [x, g, u, s, B, R, A, U, l, y, C, f, i, m]);
791
+ ...d ? { done: f } : {},
792
+ ...y ? { cancel: l } : {},
793
+ ...C ? { renderFooter: u } : {}
794
+ }), [w, g, i, s, B, R, A, U, d, y, C, f, l, u]);
795
795
  H(() => {
796
796
  r(t, W);
797
797
  }, [t, r, W]), H(() => () => r(t, null), [t, r]);
@@ -813,37 +813,37 @@ function nt() {
813
813
  return be(e.subscribe, e.getSnapshot, e.getSnapshot);
814
814
  }
815
815
  function tt() {
816
- const e = Gn(), n = sn(), r = d(!0), t = d(!1), [c, f] = ie(!1), [i, m] = ie(null), l = d(e);
817
- return l.current = e, H(() => (r.current = !0, () => {
816
+ const e = Gn(), n = sn(), r = m(!0), t = m(!1), [c, f] = ie(!1), [l, u] = ie(null), d = m(e);
817
+ return d.current = e, H(() => (r.current = !0, () => {
818
818
  r.current = !1;
819
- }), []), { run: v(async (C, x = {}) => {
819
+ }), []), { run: v(async (C, w = {}) => {
820
820
  if (t.current) return { status: "busy" };
821
821
  if (typeof C != "function") throw new TypeError("[react-modal-navigation] run requires a function");
822
- t.current = !0, r.current && (f(!0), m(null));
823
- const g = l.current.showLoading(x.loadingText);
822
+ t.current = !0, r.current && (f(!0), u(null));
823
+ const g = d.current.showLoading(w.loadingText);
824
824
  try {
825
- const u = await C();
826
- return r.current && await x.onSuccess?.(u), { status: "success", value: u };
827
- } catch (u) {
825
+ const i = await C();
826
+ return r.current && await w.onSuccess?.(i), { status: "success", value: i };
827
+ } catch (i) {
828
828
  if (r.current) {
829
- m(u);
829
+ u(i);
830
830
  try {
831
- await x.onError?.(u);
831
+ await w.onError?.(i);
832
832
  } catch (s) {
833
833
  console.error("[react-modal-navigation] onError failed", s);
834
834
  }
835
835
  }
836
- if (x.throwOnError) throw u;
837
- return { status: "error", error: u };
836
+ if (w.throwOnError) throw i;
837
+ return { status: "error", error: i };
838
838
  } finally {
839
- g != null && l.current.hideLoading(g), t.current = !1, r.current && f(!1);
839
+ g != null && d.current.hideLoading(g), t.current = !1, r.current && f(!1);
840
840
  }
841
- }, []), pending: c, error: i, clearError: () => m(null), isFocused: n };
841
+ }, []), pending: c, error: l, clearError: () => u(null), isFocused: n };
842
842
  }
843
843
  function rt(e, n = {}) {
844
844
  const r = Q(tn);
845
845
  if (!r) throw new Error("[react-modal-navigation] useModalUnsavedChanges must be used inside a modal screen");
846
- const t = d({ dirty: e, ...n });
846
+ const t = m({ dirty: e, ...n });
847
847
  t.current = { dirty: e, ...n };
848
848
  const { routeKey: c, registerDirtyGuard: f } = r;
849
849
  H(() => f(c, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-modal-navigation",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
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",