react-modal-navigation 1.1.3 → 1.1.4

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
@@ -1,3 +1,4 @@
1
+ - Footer 异步 Done/Cancel 操作自动触发覆盖整个弹窗的 Loading,支持 loadingText 国际化。
1
2
  # Changelog
2
3
 
3
4
  ## 1.0.0
@@ -18,3 +19,5 @@
18
19
  - 提供 TypeScript 类型声明和中文 API 参考文档。
19
20
 
20
21
  - 支持通过 `modal.open({ name, screen, params })` 指定初始页面,兼容异步与队列调用。
22
+
23
+ - 支持 `navigation.setOptions()` 动态更新当前页面标题、Header 和 Footer 配置,并完善路由参数文档。
package/README.md CHANGED
@@ -459,3 +459,63 @@ const result = await modal.openAsync({
459
459
  - 未注册的页面会抛出错误,不会静默回退。
460
460
  - 传统字符串调用 `modal.open('userModal', params, options)` 保持不变。
461
461
  - `screen` 只在打开时生效,打开后切换页面请使用 `navigation.navigate()`。
462
+
463
+
464
+ ## 动态页面标题与路由参数
465
+
466
+ 每个弹窗页面均可通过 `useModal()` 取得 `navigation.currentRoute`,或者直接读取页面组件的 `route` 属性。`params` 是打开或跳转页面时传入的参数。
467
+
468
+ ```jsx
469
+ import { useEffect } from 'react';
470
+ import { useModal } from 'react-modal-navigation';
471
+
472
+ function UserDetail({ route }) {
473
+ const { navigation } = useModal();
474
+ const userId = route.params?.userId;
475
+
476
+ useEffect(() => {
477
+ navigation.setOptions({ title: `用户详情 #${userId}` });
478
+ }, [navigation.setOptions, userId]);
479
+
480
+ return <div>用户 ID:{userId}</div>;
481
+ }
482
+
483
+ // 打开时指定页面和参数
484
+ modal.open({ name: 'userModal', screen: 'UserDetail', params: { userId: 1001 } });
485
+
486
+ // 弹窗内导航时传参
487
+ navigation.navigate('UserDetail', { userId: 1002 });
488
+ ```
489
+
490
+ `navigation.setOptions(options)` 更新**当前路由实例**的页面配置(例如 `title`、`renderHeaderRight`、`showBackButton`),不会修改 Registry,也不会重置页面栈。`navigation.setParams({ userId: 1003 })` 则合并当前页面参数。详情见 [API 文档](docs/API.md)。
491
+
492
+
493
+ ### Footer 异步操作的整窗 Loading
494
+
495
+ 点击默认 Footer 的 Done/Cancel 按钮后,组件会在异步操作期间自动显示覆盖整个弹窗的 Loading 蒙层,完成或失败后自动移除。无需手动管理加载状态。`loadingText` 优先于 `translate('modal.processing')`,可按业务分别设置。
496
+
497
+ ```jsx
498
+ function EditUser() {
499
+ const { t } = useTranslation();
500
+ useModalFooter({
501
+ doneText: t('common.save'),
502
+ loadingText: t('common.saving'),
503
+ done: async () => { await saveUser(); },
504
+ });
505
+ return <UserForm />;
506
+ }
507
+ ```
508
+
509
+ 如果需要手动控制整个弹窗的加载,可继续使用 `useModalLoading()` 的 `setLoading(true, t('...'))` / `setLoading(false)`,或者 `modal.setLoading(...)`。
510
+
511
+
512
+ ### 整窗 Loading 蒙层
513
+
514
+ `useModalLoading()` / `modal.setLoading()` 触发的 Loading 覆盖整个弹窗(Header、页面内容和 Footer),居中展示无卡片、无阴影的旋转圆圈及可国际化文案。背景使用半透明蒙层,弹窗内的操作在加载期间被遮挡。
515
+
516
+ ```jsx
517
+ modal.setLoading(true, { text: t("common.loading") });
518
+ // 请求结束后
519
+ modal.setLoading(false);
520
+ ```
521
+
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react/jsx-runtime"),t=require("react"),Te=require("react-dom"),Me=t.createContext(null),xe=t.createContext(null),fe=t.createContext(null),ve=t.createContext(null),je=t.createContext(null);let Be=0;const ye=(e,n)=>({key:`modal-route-${++Be}`,name:e,params:n??{}}),Se=(e,n)=>[ye(e,n)];function Pe(e,n){switch(n.type){case"RESET":return Se(n.name,n.params);case"NAVIGATE":{const o=e.findIndex(s=>s.name===n.name);return o<0?[...e,ye(n.name,n.params)]:e.slice(0,o+1).map((s,c)=>c===o?{...s,params:n.params??{}}:s)}case"SET_PARAMS":return e.map((o,s)=>s===e.length-1?{...o,params:{...o.params??{},...n.params??{}}}:o);case"BACK":return e.length>1?e.slice(0,-1):e;case"REPLACE":return e.length?[...e.slice(0,-1),ye(n.name,n.params)]:e;default:return e}}const Ce=()=>{if(typeof document>"u")return"light";const e=document.documentElement,n=document.body;return e.classList.contains("dark")||n.classList.contains("dark")||e.dataset.theme==="dark"||n.dataset.theme==="dark"?"dark":e.classList.contains("light")||n.classList.contains("light")||e.dataset.theme==="light"||n.dataset.theme==="light"?"light":window.matchMedia?.("(prefers-color-scheme: dark)").matches?"dark":"light"};let se=0;const J=[];let ge=null;function Fe(){if(se++,se===1){const n=document.documentElement,o=document.body,s={html:n.style.overflow,body:o.style.overflow,padding:o.style.paddingRight,width:o.style.getPropertyValue("--modal-scrollbar-width")},c=Math.max(0,window.innerWidth-n.clientWidth),x=parseFloat(getComputedStyle(o).paddingRight)||0;c&&(o.style.paddingRight=`${x+c}px`),o.style.setProperty("--modal-scrollbar-width",`${c}px`),n.style.overflow="hidden",o.style.overflow="hidden",ge=()=>{n.style.overflow=s.html,o.style.overflow=s.body,o.style.paddingRight=s.padding,s.width?o.style.setProperty("--modal-scrollbar-width",s.width):o.style.removeProperty("--modal-scrollbar-width")}}let e=!1;return()=>{e||(e=!0,se=Math.max(0,se-1),se||(ge?.(),ge=null))}}const qe='a[href],button:not([disabled]),input:not([disabled]),textarea:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])',De=e=>!e.closest('[inert], [hidden], [aria-hidden="true"]')&&e.getClientRects().length>0&&getComputedStyle(e).visibility!=="hidden"&&getComputedStyle(e).display!=="none";function Ae({dialogRef:e,options:n,requestClose:o,children:s,exiting:c=!1}){const x=t.useRef(null),g=t.useRef(null),v=t.useRef(o);v.current=o;const f=t.useRef(n.closeOnEsc);f.current=n.closeOnEsc;const[C,w]=t.useState(Ce),y=n.theme==="light"||n.theme==="dark"?n.theme:C;t.useEffect(()=>{if(n.theme==="light"||n.theme==="dark")return;const N=()=>w(Ce()),$=new MutationObserver(N);for(const R of[document.documentElement,document.body])$.observe(R,{attributes:!0,attributeFilter:["class","data-theme"]});const U=window.matchMedia?.("(prefers-color-scheme: dark)");return U?.addEventListener?.("change",N),N(),()=>{$.disconnect(),U?.removeEventListener?.("change",N)}},[n.theme]),t.useEffect(()=>{g.current=document.activeElement;const N=Fe(),$=x.current;J.push($),e.current?.focus({preventScroll:!0});const U=h=>{const k=e.current;if(!k||J.at(-1)!==$)return;if(h.key==="Escape"&&f.current!==!1){h.preventDefault(),v.current("escape");return}if(h.key!=="Tab")return;const B=[...k.querySelectorAll(qe)].filter(De);if(!B.length){h.preventDefault(),k.focus();return}const I=B[0],S=B.at(-1);k.contains(document.activeElement)?h.shiftKey&&(document.activeElement===I||document.activeElement===k)?(h.preventDefault(),S.focus()):!h.shiftKey&&(document.activeElement===S||document.activeElement===k)&&(h.preventDefault(),I.focus()):(h.preventDefault(),(h.shiftKey?S:I).focus())},R=h=>{J.at(-1)===$&&e.current&&!e.current.contains(h.target)&&e.current.focus({preventScroll:!0})};return document.addEventListener("keydown",U),document.addEventListener("focusin",R),()=>{document.removeEventListener("keydown",U),document.removeEventListener("focusin",R);const h=J.at(-1)===$,k=J.indexOf($);if(k!==-1&&J.splice(k,1),N(),h){const B=g.current;B?.isConnected&&!B.closest("[inert], [hidden]")?B.focus?.({preventScroll:!0}):J.at(-1)?.querySelector("[role=dialog]")?.focus?.({preventScroll:!0})}}},[e]);const j=n.backgroundColor??n.backgroudColor,u=typeof j=="string"?j:j?.[y],p=typeof u=="string"&&/^(#|rgb\(|rgba\(|hsl\(|hsla\(|oklch\(|color\(|var\()/.test(u.trim())?u:null,O={sm:400,md:560,lg:720,xl:960,full:"100%"},L=["center","left","right","top","bottom"].includes(n.placement)?n.placement:"right",P=N=>typeof N=="number"?`${N}px`:N,F=P(n.width??O[n.size]??460),q=P(n.height),E=P(n.maxHeight),T=P(n.maxWidth),D=Number(n.viewportGap??5),G=Number.isFinite(D)?Math.max(0,D):5,A=typeof n.borderRadius=="number"?`${n.borderRadius}px`:n.borderRadius??"12px";return Te.createPortal(m.jsx("div",{ref:x,className:`pmn-overlay ${c?"pmn-exiting":"pmn-entering"} ${n.animation===!1?"pmn-no-animation":""} pmn-place-${L} ${n.mobileFullscreen?"pmn-mobile-fullscreen":""}`,style:{padding:G,"--pmn-animation-duration":`${Math.min(1e3,Math.max(0,Number(n.animationDuration??220)||0))}ms`},onMouseDown:N=>{N.target===N.currentTarget&&n.closeOnOverlay===!0&&v.current("overlay")},children:m.jsx("section",{ref:e,tabIndex:-1,role:"dialog","aria-modal":"true","aria-label":n.ariaLabel??"Dialog","data-modal-theme":y,className:`pmn-dialog ${y==="dark"?"dark":""} ${!p&&u?u:""} ${n.className??""}`,style:{"--pmn-width":F,"--pmn-gap":`${G}px`,...q!==void 0?{"--pmn-height":q}:{},...E!==void 0?{"--pmn-max-height":E}:{},...T!==void 0?{"--pmn-max-width":T}:{},borderRadius:A,...p?{backgroundColor:p}:{}},children:s})}),document.body)}function Ee({back:e}){return m.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",width:"20",height:"20",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e?m.jsx("path",{d:"m15 18-6-6 6-6"}):m.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})}function Oe({options:e,screen:n,route:o,navigation:s,requestClose:c,translate:x}){if(e.showHeader===!1)return null;const g=x??(j=>j),v=n.showTitle??e.showTitle??!0,f=typeof n.title=="function"?n.title({t:g,route:o,navigation:s}):n.title??o.name,C={route:o,navigation:s,close:c,canGoBack:s.canGoBack,title:f,t:g},w=n.renderHeader??e.renderHeader;if(w)return w(C);const y=n.renderHeaderRight??e.renderHeaderRight;return m.jsxs("header",{className:`pmn-header ${n.showHeaderBorder??e.showHeaderBorder?"pmn-border-bottom":""} ${e.headerClassName??""}`,children:[e.showBackButton!==!1&&s.canGoBack&&m.jsx("button",{type:"button",className:"pmn-icon-button","aria-label":g("modal.back"),onClick:()=>s.goBack(),children:m.jsx(Ee,{back:!0})}),v?m.jsx("h2",{children:f}):m.jsx("div",{className:"pmn-header-spacer"}),y?.(C),e.showCloseButton!==!1&&m.jsx("button",{type:"button",className:"pmn-icon-button","aria-label":g("modal.close"),onClick:()=>c("header"),children:m.jsx(Ee,{})})]})}function $e({screen:e,options:n,override:o,route:s,navigation:c,requestClose:x,translate:g,onError:v}){const[f,C]=t.useState(!1),w=g??(T=>T),y={...n,...e,...o},{showFooter:j,renderFooter:u,done:p,cancel:O,cancle:L}=y,P=O??L,F={route:s,navigation:c,close:x,t:w};if(j===!1)return null;const q=`pmn-footer ${y.showFooterBorder?"pmn-border-top":""} ${y.footerClassName??""}`;if(typeof u=="function")return m.jsx("footer",{className:q,children:u({...F,pending:f})});if(typeof p!="function"&&typeof P!="function")return null;const E=async T=>{if(!(f||typeof T!="function")){C(!0);try{await T(F)}catch(D){v?.(D,{phase:"footer",route:s})}finally{C(!1)}}};return m.jsxs("footer",{className:q,children:[typeof P=="function"&&m.jsx("button",{type:"button",disabled:f,onClick:()=>E(P),className:"pmn-button pmn-button-secondary",children:y.cancelText??w("modal.cancel")}),typeof p=="function"&&m.jsx("button",{type:"button",disabled:f||y.doneDisabled===!0,onClick:()=>E(p),className:"pmn-button pmn-button-primary",children:f?y.loadingText??w("modal.processing"):y.doneText??w("modal.done")})]})}function Ie({loading:e,translate:n}){if(!e.visible)return null;const s=(n??(x=>x))("modal.loading"),c=e.text??(s==="modal.loading"?"加载中...":s);return m.jsx("div",{className:"pmn-loading-overlay",role:"status","aria-live":"polite","aria-busy":"true",children:m.jsxs("div",{className:"pmn-loading-card",children:[m.jsx("span",{className:"pmn-spinner","aria-hidden":"true"}),m.jsx("span",{children:c})]})})}class He extends t.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?m.jsxs("div",{role:"alert",className:"pmn-error-screen",children:[m.jsx("strong",{children:"页面加载失败"}),m.jsx("p",{children:this.state.error.message}),m.jsx("button",{type:"button",className:"pmn-button pmn-button-secondary",onClick:()=>this.setState({error:null}),children:"重试"})]}):this.props.children}}function Ge({route:e,screen:n,navigation:o,focused:s,resultEvent:c,setFooter:x,loadingApi:g,bodyClassName:v,notifyError:f,registerDirtyGuard:C}){const w=n.component,y=t.useMemo(()=>({isFocused:s,resultEvent:c,routeKey:e.key,setFooter:x}),[s,c,e.key,x]),j=t.useMemo(()=>({isLoading:s&&g.isLoading,setLoading:(u,p)=>g.setScreenLoading(e.key,u,p),showLoading:u=>g.begin(e.key,u),hideLoading:u=>g.end(e.key,u)}),[s,g,e.key]);return m.jsx(je.Provider,{value:{routeKey:e.key,registerDirtyGuard:C},children:m.jsx(fe.Provider,{value:y,children:m.jsx(ve.Provider,{value:j,children:m.jsx("div",{hidden:!s,inert:!s,"data-modal-route-key":e.key,tabIndex:-1,className:`pmn-body ${v??""}`,children:m.jsx(He,{route:e,onError:f,children:m.jsx(w,{route:e,navigation:o})})})})})})}function Ne({config:e,initialScreen:n,params:o,options:s,translate:c,onRequestClose:x,onOpened:g,registerLoading:v,notifyError:f,error:C,clearError:w,registerDirtyGuard:y,exiting:j=!1}){const[u,p]=t.useReducer(Pe,null,()=>Se(n??e.initialRoute,o)),[O,L]=t.useState({}),[P,F]=t.useState({}),[,q]=t.useState(0),E=t.useRef(new Map),T=t.useRef(0),D=t.useRef(new Map),G=t.useRef(null),A=t.useRef(null),N=t.useRef(!1),$=t.useRef(!1),U=t.useRef(0),R=u.at(-1),h=R.key,k=t.useRef(h);k.current=h;const B=e.screens,I=t.useCallback(()=>q(r=>r+1),[]),S=t.useCallback((r,i)=>{if(r!=="global"&&k.current!==r)return null;const d=++T.current;return E.current.set(d,{owner:r,text:i}),I(),d},[I]),z=t.useCallback((r,i)=>{if(i!=null)E.current.get(i)?.owner===r&&E.current.delete(i);else for(const[d,M]of E.current)M.owner===r&&E.current.delete(d);I()},[I]),H=t.useCallback((r,i)=>{r?(z("global"),S("global",i)):z("global")},[S,z]),X=t.useCallback((r,i,d)=>{i?(z(r),S(r,d)):z(r)},[S,z]),Z=[...E.current.values()],K={visible:Z.length>0,text:Z.at(-1)?.text??null,count:Z.length},Y=t.useRef(K);Y.current=K;const ce=t.useMemo(()=>({isLoading:K.visible,setLoading:H,setScreenLoading:X,begin:S,end:z}),[K.visible,H,X,S,z]),ee=t.useRef(v);ee.current=v,t.useEffect(()=>(ee.current?.({setLoading:H}),()=>ee.current?.(null)),[H]);const ie=t.useCallback((r,i)=>F(d=>{if(i===null){if(!(r in d))return d;const M={...d};return delete M[r],M}return d[r]===i?d:{...d,[r]:i}}),[]),V=t.useCallback(()=>{const r=document.activeElement;if(!(r instanceof HTMLElement)||!G.current?.contains(r))return;const i=r.closest("[data-modal-route-key]");i&&D.current.set(i.dataset.modalRouteKey,r),G.current.focus({preventScroll:!0})},[]),te=t.useCallback(r=>{if(!Object.prototype.hasOwnProperty.call(B,r))throw new Error(`[react-modal-navigation] Unknown modal screen: ${r}`)},[B]),Q=t.useCallback((r,i)=>{try{Promise.resolve(s[r]?.(i)).catch(d=>f(d,{phase:r}))}catch(d){f(d,{phase:r})}},[s,f]),W=t.useCallback((r,i,d)=>{te(i),V(),p({type:r,name:i,params:d})},[te,V]),ne=t.useCallback((r,i)=>W("NAVIGATE",r,i),[W]),re=t.useCallback((r,i)=>W("REPLACE",r,i),[W]),oe=t.useCallback((r,i)=>{L({}),W("RESET",r,i)},[W]),ae=t.useCallback(r=>{if(!r||typeof r!="object"||Array.isArray(r))throw new TypeError("[react-modal-navigation] setParams expects an object");p({type:"SET_PARAMS",params:r})},[]),le=t.useCallback(r=>{if(u.length<=1||N.current)return!1;if(N.current=!0,r!==void 0){const i=u.at(-2);L(d=>({...d,[i.key]:{id:++U.current,data:r}}))}return V(),p({type:"BACK"}),!0},[u,V]),a=t.useCallback((r,i)=>Y.current.visible&&s.lockCloseWhileLoading!==!1?Promise.resolve(!1):x(r,i,{route:R,stack:u}),[s.lockCloseWhileLoading,x,R,u]),l=t.useCallback(r=>a("api",r),[a]),b=t.useMemo(()=>({navigate:ne,replace:re,reset:oe,setParams:ae,goBack:le,close:l,setLoading:H,canGoBack:u.length>1,stack:u,currentRoute:R}),[ne,re,oe,ae,le,l,H,u,R]);return t.useLayoutEffect(()=>{N.current=!1;const r=[...G.current?.querySelectorAll("[data-modal-route-key]")??[]].find(M=>M.dataset.modalRouteKey===h);if(!r)return;const i=D.current.get(h);(i?.isConnected&&r.contains(i)&&!i.matches(":disabled")&&!i.closest("[inert], [hidden]")?i:r).focus({preventScroll:!0})},[h]),t.useEffect(()=>{let r=!1;for(const[d,M]of E.current)M.owner!=="global"&&M.owner!==h&&(E.current.delete(d),r=!0);r&&I();const i=new Set(u.map(d=>d.key));for(const d of D.current.keys())i.has(d)||D.current.delete(d)},[h,u,I]),t.useEffect(()=>{if(A.current?.key!==h){if(A.current){const r={from:A.current,to:R,stack:u};Q("onBlur",{route:A.current,...r}),Q("onNavigate",r),Q("onRouteChange",r)}Q("onFocus",{route:R,stack:u}),A.current=R}},[R,h,u,Q]),t.useEffect(()=>()=>{E.current.clear(),D.current.clear()},[]),t.useEffect(()=>{$.current||($.current=!0,g?.({route:R,stack:u}))},[]),m.jsx(xe.Provider,{value:b,children:m.jsx(ve.Provider,{value:ce,children:m.jsxs(Ae,{dialogRef:G,options:s,requestClose:a,exiting:j,children:[m.jsx(Oe,{options:s,screen:B[R.name],route:R,navigation:b,requestClose:a,translate:c}),m.jsx("main",{className:"pmn-main",children:u.map(r=>m.jsx(Ge,{route:r,screen:B[r.name],navigation:b,focused:r.key===h,resultEvent:O[r.key]??null,bodyClassName:s.bodyClassName,setFooter:ie,loadingApi:ce,notifyError:f,registerDirtyGuard:y},r.key))}),m.jsx($e,{screen:B[R.name],options:s,override:P[h],route:R,navigation:b,requestClose:a,translate:c,onError:f},h),m.jsx(Ie,{loading:K,translate:c}),C&&m.jsxs("div",{className:"pmn-error",role:"alert",children:[m.jsx("span",{children:C.message||String(C)}),m.jsx("button",{type:"button",onClick:w,"aria-label":"Dismiss error",children:"×"})]})]})})})}const ze=".pmn-overlay,.pmn-dialog,.pmn-dialog *{box-sizing:border-box}.pmn-overlay{position:fixed;inset:0;z-index:1000;display:flex;overscroll-behavior:none;background:#00000073}.pmn-place-right{justify-content:flex-end;align-items:stretch}.pmn-place-left{justify-content:flex-start;align-items:stretch}.pmn-place-center{justify-content:center;align-items:center}.pmn-place-top{justify-content:center;align-items:flex-start}.pmn-place-bottom{justify-content:center;align-items:flex-end}.pmn-dialog{--pmn-surface:#fff;--pmn-body:#fff;--pmn-text:#0f172a;--pmn-muted:#475569;--pmn-border:#e2e8f0;--pmn-hover:#f1f5f9;--pmn-overlay-card:rgba(255,255,255,.92);color-scheme:light;position:relative;display:flex;flex-direction:column;min-height:0;width:100%;max-width:min(calc(100vw - var(--pmn-gap)*2),var(--pmn-max-width, var(--pmn-width)));max-height:min(calc(100dvh - var(--pmn-gap)*2),var(--pmn-max-height, 100dvh));height:var(--pmn-height, 100%);overflow:hidden;outline:none;box-shadow:0 25px 50px -12px #00000040;background:var(--pmn-surface);color:var(--pmn-text)}.pmn-place-left .pmn-dialog,.pmn-place-right .pmn-dialog{height:calc(100dvh - var(--pmn-gap)*2);max-height:calc(100dvh - var(--pmn-gap)*2)}.pmn-place-center .pmn-dialog{height:var(--pmn-height, auto);min-height:150px}.pmn-place-top .pmn-dialog,.pmn-place-bottom .pmn-dialog{height:var(--pmn-height, auto);min-height:0}.pmn-dialog[data-modal-theme=dark]{--pmn-surface:#334155;--pmn-body:#334155;--pmn-text:#f1f5f9;--pmn-muted:#cbd5e1;--pmn-border:#475569;--pmn-hover:#1e293b;--pmn-overlay-card:rgba(51,65,85,.94);color-scheme:dark}.pmn-main{min-height:0;flex:1;overflow:hidden;display:flex;flex-direction:column;background:transparent}.pmn-body{height:100%;min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:16px;flex:1}.pmn-body[hidden]{display:none!important}.pmn-header{display:flex;flex-shrink:0;height:64px;align-items:center;gap:12px;padding:0 20px;background:transparent}.pmn-header h2{font-size:18px;font-weight:600;min-width:0;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin:0}.pmn-header-spacer{flex:1}.pmn-border-bottom{border-bottom:1px solid var(--pmn-border)}.pmn-icon-button{display:inline-flex;align-items:center;justify-content:center;padding:8px;border:0;background:transparent;color:inherit;border-radius:8px;cursor:pointer}.pmn-icon-button:hover{background:var(--pmn-hover)}.pmn-footer{display:flex;flex-shrink:0;align-items:center;justify-content:flex-end;gap:12px;padding:16px 20px;background:transparent}.pmn-border-top{border-top:1px solid var(--pmn-border)}.pmn-button{padding:8px 16px;border-radius:8px;font-size:14px;font-weight:500;cursor:pointer}.pmn-button:disabled{opacity:.5;cursor:not-allowed}.pmn-button-secondary{border:1px solid var(--pmn-border);background:transparent;color:var(--pmn-text)}.pmn-button-secondary:hover:not(:disabled){background:var(--pmn-hover)}.pmn-button-primary{border:1px solid #2563eb;background:#2563eb;color:#fff}.pmn-button-primary:hover:not(:disabled){background:#1d4ed8}.pmn-loading-overlay{position:absolute;inset:0;z-index:50;display:flex;align-items:center;justify-content:center;background:var(--pmn-overlay-card);-webkit-backdrop-filter:blur(1px);backdrop-filter:blur(1px)}.pmn-loading-card{display:flex;flex-direction:column;align-items:center;gap:12px;max-width:85%;padding:20px 28px;border-radius:12px;background:var(--pmn-surface);box-shadow:0 10px 20px #00000026}.pmn-spinner{width:36px;height:36px;border:3px solid #2563eb;border-top-color:transparent;border-radius:50%;animation:pmn-spin 1s linear infinite}@keyframes pmn-spin{to{transform:rotate(360deg)}}.pmn-error{position:absolute;z-index:60;bottom:8px;left:12px;right:12px;display:flex;justify-content:space-between;gap:12px;padding:12px;border:1px solid #fca5a5;border-radius:8px;background:#fef2f2;color:#991b1b;font-size:13px}.pmn-error button{border:0;background:transparent;font-size:20px;cursor:pointer;color:inherit}.pmn-dialog input:not([type=checkbox]):not([type=radio]),.pmn-dialog textarea,.pmn-dialog select{color:var(--pmn-text);border-color:var(--pmn-border)}.pmn-error-screen{padding:24px;color:var(--pmn-text)}.pmn-error-screen p{color:#dc2626;overflow-wrap:anywhere}@media(max-width:640px){.pmn-overlay.pmn-mobile-fullscreen{padding:0!important}.pmn-mobile-fullscreen .pmn-dialog{max-width:100%;width:100%;height:100dvh;max-height:100dvh;border-radius:0!important}}@media(prefers-reduced-motion:reduce){.pmn-spinner{animation-duration:2s}}@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}}",Re="react-modal-navigation-styles",be=new WeakMap;function Ke(){t.useInsertionEffect(()=>{if(typeof document>"u")return;const e=document;let n=be.get(e);if(!n){let o=e.getElementById(Re);const s=!o;o||(o=e.createElement("style"),o.id=Re,o.setAttribute("data-react-modal-navigation",""),o.textContent=ze,e.head.appendChild(o)),n={element:o,owned:s,count:0},be.set(e,n)}return n.count+=1,()=>{n.count-=1,n.count===0&&(n.owned&&n.element.remove(),be.delete(e))}},[])}function me(e,n,o){if(typeof e=="string"){if(!e.trim())throw new TypeError("[react-modal-navigation] modal name must not be empty");return{name:e,params:n??{},options:o??{}}}if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError("[react-modal-navigation] open expects a modal name or a configuration object");const{name:s,screen:c,params:x={},options:g={},...v}=e;if(typeof s!="string"||!s.trim())throw new TypeError("[react-modal-navigation] open config requires a non-empty string name");if(g===null||typeof g!="object"||Array.isArray(g))throw new TypeError("[react-modal-navigation] open config options must be an object");if(c!==void 0&&(typeof c!="string"||!c.trim()))throw new TypeError("[react-modal-navigation] screen must be a non-empty string");return{name:s,...c===void 0?{}:{screen:c},params:x,options:{...v,...g}}}const Ue={placement:"right",showHeader:!0,showBackButton:!0,showCloseButton:!0,viewportGap:5,borderRadius:12,closeOnOverlay:!1,closeOnEsc:!0},We=e=>({"modal.loading":"加载中...","modal.processing":"处理中...","modal.back":"返回","modal.close":"关闭","modal.cancel":"取消","modal.done":"完成"})[e]??e;function Ye({registry:e,children:n,defaultOptions:o={},backgroundColor:s,theme:c,translate:x=We,onError:g,confirmDiscard:v}){Ke();const[f,C]=t.useState(null),[w,y]=t.useState(null),[j,u]=t.useState(0),p=t.useRef(null),O=t.useRef(new Map),L=t.useRef([]),P=t.useRef(null),F=t.useRef(null),q=t.useRef(0),E=t.useRef(null),T=t.useRef(!1),D=t.useRef(0),G=t.useRef(null),A=t.useRef(new Map),[N,$]=t.useState(!1),U=t.useRef(v);U.current=v;const R=t.useCallback((a,l)=>(A.current.set(a,l),()=>{A.current.get(a)===l&&A.current.delete(a)}),[]),h=t.useCallback(async a=>{for(const l of A.current.values()){if(!l.dirty)continue;if((l.onBeforeDiscard?await l.onBeforeDiscard(a):U.current?await U.current(a):typeof window<"u"&&typeof window.confirm=="function"?window.confirm(l.message||"有未保存的修改,确定放弃吗?"):!1)===!1)return!1}return!0},[]),k=t.useRef(!0),B=t.useRef(null),I=t.useRef(g);I.current=g;const S=t.useCallback((a,l)=>{k.current&&y(a);try{I.current?I.current(a,l):console.error("[react-modal-navigation]",a)}catch(b){console.error("[react-modal-navigation] onError failed",b)}},[]),z=t.useCallback((a,l)=>{const b=O.current.get(a);O.current.delete(a),b?.(l)},[]),H=t.useCallback(a=>({...Ue,...o,...c!==void 0?{theme:c}:{},...s!==void 0?{backgroundColor:s}:{},...a.config.modalOptions,...a.overrides}),[o,c,s]),X=f?H(f):null,Z=t.useRef(null);Z.current=X,B.current=X;const K=t.useCallback(async(a="api",l,b={})=>{const r=p.current;if(!r||E.current||T.current)return!1;E.current=r.id,T.current=!0;const i=B.current??H(r),d={...b,reason:a,result:l,name:r.name};try{if(!await h(d)||await i.onBeforeClose?.(d)===!1||p.current?.id!==r.id||!k.current||($(!0),await new Promise(M=>{const ue=i.animation===!1||typeof window<"u"&&window.matchMedia?.("(prefers-reduced-motion: reduce)").matches?0:Math.max(0,Number(i.animationDuration??220)||0);setTimeout(M,Math.min(ue,1e3))}),!k.current||p.current?.id!==r.id))return!1;p.current=null,G.current=null,C(null),$(!1),A.current.clear(),z(r.id,b.confirmed||l!==void 0?{status:"confirmed",value:l,reason:a}:{status:"dismissed",reason:a});try{await i.onClose?.(d)}catch(M){S(M,{phase:"onClose",name:r.name})}return!0}catch(M){return S(M,{phase:"onBeforeClose",name:r.name}),!1}finally{E.current===r.id&&(E.current=null),T.current=!1,!p.current&&k.current&&queueMicrotask(()=>F.current?.())}},[H,S,z,h]),Y=t.useCallback(async(a,l={},b={},r,i)=>{const d=e?.[a];if(!d)throw new Error(`[react-modal-navigation] Unknown modal: ${a}`);const M=i??d.initialRoute;if(!d.screens?.[M])throw new Error(`[react-modal-navigation] Unknown initial screen '${M}' in modal '${a}'`);if(!k.current||T.current||E.current)return null;T.current=!0;const ue=D.current;try{const _=p.current;if(_){const ke=B.current??H(_),pe={reason:"replace",name:_.name,nextName:a};try{if(!await h(pe)||await ke.onBeforeClose?.(pe)===!1)return null}catch(he){return S(he,{phase:"onBeforeClose",name:_.name}),null}if(!k.current||ue!==D.current||p.current?.id!==_.id)return null;p.current=null,G.current=null,C(null),A.current.clear(),z(_.id,{status:"replaced",reason:"replace"});try{await ke.onClose?.(pe)}catch(he){S(he,{phase:"onClose",name:_.name})}if(!k.current||ue!==D.current)return null}const de={id:++q.current,name:a,screen:M,params:l,config:d,overrides:b};return p.current=de,G.current=null,r&&O.current.set(de.id,r),y(null),C(de),de.id}finally{T.current=!1}},[e,H,S,z,h]);P.current=Y;const ce=t.useCallback(async()=>{if(!k.current||p.current||T.current||E.current)return;const a=L.current.shift();if(a){u(L.current.length);try{const l=await P.current(a.args.name,a.args.params,a.args.options,a.resolveResult,a.args.screen);l===null?(a.resolveResult?.({status:"dismissed",reason:"blocked"}),a.resolveId?.(null),queueMicrotask(()=>F.current?.())):a.resolveId?.(l)}catch(l){a.reject?.(l),queueMicrotask(()=>F.current?.())}}},[]);F.current=ce;const ee=t.useCallback((a,l,b)=>{const r=me(a,l,b);return e?.[r.name]?new Promise((i,d)=>{L.current.push({args:r,resolveId:i,reject:d}),u(L.current.length),queueMicrotask(()=>F.current?.())}):Promise.reject(new Error(`[react-modal-navigation] Unknown modal: ${r.name}`))},[e]),ie=t.useCallback((a,l,b)=>{const r=me(a,l,b);return e?.[r.name]?new Promise((i,d)=>{L.current.push({args:r,resolveResult:i,reject:d}),u(L.current.length),queueMicrotask(()=>F.current?.())}):Promise.reject(new Error(`[react-modal-navigation] Unknown modal: ${r.name}`))},[e]),V=t.useCallback(a=>{if(!a||typeof a!="object"||Array.isArray(a))throw new TypeError("[react-modal-navigation] update expects an options object");const l=p.current;if(!l||T.current)return!1;const b={...l,overrides:{...l.overrides,...a}};return p.current=b,C(b),B.current=H(b),!0},[H]),te=t.useCallback((a="queue-cleared")=>{const l=L.current.splice(0);u(0);for(const b of l)b.resolveId?.(null),b.resolveResult?.({status:"dismissed",reason:a});return l.length},[]),Q=t.useCallback((a,l,b)=>{const r=me(a,l,b);return Y(r.name,r.params,r.options,void 0,r.screen)},[Y]),W=t.useCallback((a,l,b)=>{const r=me(a,l,b);return new Promise((i,d)=>{Y(r.name,r.params,r.options,i,r.screen).then(M=>{M===null&&i({status:"dismissed",reason:"blocked"})},d)})},[Y]),ne=t.useCallback(a=>K("api",a),[K]),re=t.useCallback((a="api")=>K(a),[K]),oe=t.useCallback(a=>K("confirm",a,{confirmed:!0}),[K]),ae=t.useCallback((a,l)=>G.current?.setLoading(a,l),[]),le=t.useMemo(()=>({open:Q,openAsync:W,enqueue:ee,enqueueAsync:ie,update:V,clearQueue:te,close:ne,dismiss:re,confirm:oe,setLoading:ae,queueSize:j,isOpen:!!f,activeName:f?.name??null,error:w,clearError:()=>y(null)}),[Q,W,ee,ie,V,te,ne,re,oe,ae,f,w,j]);return t.useEffect(()=>(k.current=!0,()=>{k.current=!1,D.current+=1,p.current=null;for(const l of O.current.values())l({status:"dismissed",reason:"unmount"});O.current.clear(),A.current.clear();const a=L.current.splice(0);for(const l of a)l.resolveId?.(null),l.resolveResult?.({status:"dismissed",reason:"unmount"})}),[]),m.jsxs(Me.Provider,{value:le,children:[n,f&&m.jsx(Ne,{config:f.config,initialScreen:f.screen,params:f.params,options:X,translate:x,notifyError:S,error:w,clearError:()=>y(null),registerLoading:a=>{G.current=a},registerDirtyGuard:R,exiting:N,onRequestClose:K,onOpened:a=>{try{const l=Z.current?.onOpen?.(a);Promise.resolve(l).catch(b=>S(b,{phase:"onOpen"}))}catch(l){S(l,{phase:"onOpen"})}}},f.id)]})}function Qe(){const e=t.useContext(Me),n=t.useContext(xe);if(!e)throw new Error("[react-modal-navigation] useModal requires <ModalProvider>");return t.useMemo(()=>{const o=()=>{if(!n)throw new Error("[react-modal-navigation] navigation requires an active modal screen; use modal.open() outside a modal");return n};return{...e,modal:e,navigation:{navigate:(...c)=>o().navigate(...c),replace:(...c)=>o().replace(...c),reset:(...c)=>o().reset(...c),setParams:(...c)=>o().setParams(...c),goBack:(...c)=>o().goBack(...c),close:(...c)=>o().close(...c),get canGoBack(){return n?.canGoBack??!1},get stack(){return n?.stack??[]},get currentRoute(){return n?.currentRoute??null}}}},[e,n])}function Ve(){const e=t.useContext(xe);if(!e)throw new Error("useModalNavigation requires an active modal screen");return e}function we(){const e=t.useContext(fe);if(!e)throw new Error("useIsFocused must be called inside a modal screen");return e.isFocused}function _e(e){const n=we();t.useEffect(()=>{if(n)return e()},[n,e])}function Je(e){const n=t.useContext(fe);if(!n)throw new Error("useNavigationResult requires an active modal screen");const o=t.useRef(e),s=t.useRef(null);t.useEffect(()=>{o.current=e},[e]),t.useEffect(()=>{!n.isFocused||!n.resultEvent||s.current!==n.resultEvent.id&&(s.current=n.resultEvent.id,o.current(n.resultEvent.data))},[n.isFocused,n.resultEvent])}function Xe(e={}){const n=t.useContext(fe);if(!n)throw new Error("[react-modal-navigation] useModalFooter requires an active modal screen");const{setFooter:o,routeKey:s}=n,c=t.useRef(e);c.current=e;const x=t.useMemo(()=>(...q)=>c.current.done?.(...q),[]),g=t.useMemo(()=>(...q)=>(c.current.cancel??c.current.cancle)?.(...q),[]),v=t.useMemo(()=>(...q)=>c.current.renderFooter?.(...q),[]),f=typeof e.done=="function",C=typeof(e.cancel??e.cancle)=="function",w=typeof e.renderFooter=="function",{showFooter:y,showFooterBorder:j,doneDisabled:u,doneText:p,cancelText:O,loadingText:L,footerClassName:P}=e,F=t.useMemo(()=>({showFooter:y,showFooterBorder:j,doneDisabled:u,doneText:p,cancelText:O,loadingText:L,footerClassName:P,...f?{done:x}:{},...C?{cancel:g}:{},...w?{renderFooter:v}:{}}),[y,j,u,p,O,L,P,f,C,w,x,g,v]);t.useEffect(()=>{o(s,F)},[s,o,F]),t.useEffect(()=>()=>o(s,null),[s,o])}function Le(){const e=t.useContext(ve);if(!e)throw new Error("[react-modal-navigation] useModalLoading requires an active modal screen");return e}function Ze(){const e=Le(),n=we(),o=t.useRef(!0),s=t.useRef(!1),[c,x]=t.useState(!1),[g,v]=t.useState(null),f=t.useRef(e);return f.current=e,t.useEffect(()=>(o.current=!0,()=>{o.current=!1}),[]),{run:t.useCallback(async(w,y={})=>{if(s.current)return{status:"busy"};if(typeof w!="function")throw new TypeError("[react-modal-navigation] run requires a function");s.current=!0,o.current&&(x(!0),v(null));const j=f.current.showLoading(y.loadingText);try{const u=await w();return o.current&&await y.onSuccess?.(u),{status:"success",value:u}}catch(u){if(o.current){v(u);try{await y.onError?.(u)}catch(p){console.error("[react-modal-navigation] onError failed",p)}}if(y.throwOnError)throw u;return{status:"error",error:u}}finally{j!=null&&f.current.hideLoading(j),s.current=!1,o.current&&x(!1)}},[]),pending:c,error:g,clearError:()=>v(null),isFocused:n}}function et(e,n={}){const o=t.useContext(je);if(!o)throw new Error("[react-modal-navigation] useModalUnsavedChanges must be used inside a modal screen");const s=t.useRef({dirty:e,...n});s.current={dirty:e,...n};const{routeKey:c,registerDirtyGuard:x}=o;t.useEffect(()=>x(c,{get dirty(){return!!s.current.dirty},get message(){return s.current.message},get onBeforeDiscard(){return s.current.onBeforeDiscard}}),[c,x])}exports.ModalNavigator=Ne;exports.ModalProvider=Ye;exports.useFocusEffect=_e;exports.useIsFocused=we;exports.useModal=Qe;exports.useModalFooter=Xe;exports.useModalLoading=Le;exports.useModalNavigation=Ve;exports.useModalTask=Ze;exports.useModalUnsavedChanges=et;exports.useNavigationResult=Je;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime"),t=require("react"),Le=require("react-dom"),Me=t.createContext(null),ve=t.createContext(null),fe=t.createContext(null),xe=t.createContext(null),je=t.createContext(null);let Pe=0;const ye=(e,n)=>({key:`modal-route-${++Pe}`,name:e,params:n??{}}),Se=(e,n)=>[ye(e,n)];function Be(e,n){switch(n.type){case"RESET":return Se(n.name,n.params);case"NAVIGATE":{const o=e.findIndex(a=>a.name===n.name);return o<0?[...e,ye(n.name,n.params)]:e.slice(0,o+1).map((a,c)=>c===o?{...a,params:n.params??{}}:a)}case"SET_OPTIONS":return e.map((o,a)=>a===e.length-1?{...o,options:{...o.options??{},...n.options??{}}}:o);case"SET_PARAMS":return e.map((o,a)=>a===e.length-1?{...o,params:{...o.params??{},...n.params??{}}}:o);case"BACK":return e.length>1?e.slice(0,-1):e;case"REPLACE":return e.length?[...e.slice(0,-1),ye(n.name,n.params)]:e;default:return e}}const Ee=()=>{if(typeof document>"u")return"light";const e=document.documentElement,n=document.body;return e.classList.contains("dark")||n.classList.contains("dark")||e.dataset.theme==="dark"||n.dataset.theme==="dark"?"dark":e.classList.contains("light")||n.classList.contains("light")||e.dataset.theme==="light"||n.dataset.theme==="light"?"light":window.matchMedia?.("(prefers-color-scheme: dark)").matches?"dark":"light"};let ie=0;const X=[];let ge=null;function Fe(){if(ie++,ie===1){const n=document.documentElement,o=document.body,a={html:n.style.overflow,body:o.style.overflow,padding:o.style.paddingRight,width:o.style.getPropertyValue("--modal-scrollbar-width")},c=Math.max(0,window.innerWidth-n.clientWidth),y=parseFloat(getComputedStyle(o).paddingRight)||0;c&&(o.style.paddingRight=`${y+c}px`),o.style.setProperty("--modal-scrollbar-width",`${c}px`),n.style.overflow="hidden",o.style.overflow="hidden",ge=()=>{n.style.overflow=a.html,o.style.overflow=a.body,o.style.paddingRight=a.padding,a.width?o.style.setProperty("--modal-scrollbar-width",a.width):o.style.removeProperty("--modal-scrollbar-width")}}let e=!1;return()=>{e||(e=!0,ie=Math.max(0,ie-1),ie||(ge?.(),ge=null))}}const qe='a[href],button:not([disabled]),input:not([disabled]),textarea:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])',Oe=e=>!e.closest('[inert], [hidden], [aria-hidden="true"]')&&e.getClientRects().length>0&&getComputedStyle(e).visibility!=="hidden"&&getComputedStyle(e).display!=="none";function Ae({dialogRef:e,options:n,requestClose:o,children:a,exiting:c=!1}){const y=t.useRef(null),b=t.useRef(null),E=t.useRef(o);E.current=o;const p=t.useRef(n.closeOnEsc);p.current=n.closeOnEsc;const[k,j]=t.useState(Ee),x=n.theme==="light"||n.theme==="dark"?n.theme:k;t.useEffect(()=>{if(n.theme==="light"||n.theme==="dark")return;const T=()=>j(Ee()),I=new MutationObserver(T);for(const C of[document.documentElement,document.body])I.observe(C,{attributes:!0,attributeFilter:["class","data-theme"]});const W=window.matchMedia?.("(prefers-color-scheme: dark)");return W?.addEventListener?.("change",T),T(),()=>{I.disconnect(),W?.removeEventListener?.("change",T)}},[n.theme]),t.useEffect(()=>{b.current=document.activeElement;const T=Fe(),I=y.current;X.push(I),e.current?.focus({preventScroll:!0});const W=g=>{const R=e.current;if(!R||X.at(-1)!==I)return;if(g.key==="Escape"&&p.current!==!1){g.preventDefault(),E.current("escape");return}if(g.key!=="Tab")return;const P=[...R.querySelectorAll(qe)].filter(Oe);if(!P.length){g.preventDefault(),R.focus();return}const H=P[0],S=P.at(-1);R.contains(document.activeElement)?g.shiftKey&&(document.activeElement===H||document.activeElement===R)?(g.preventDefault(),S.focus()):!g.shiftKey&&(document.activeElement===S||document.activeElement===R)&&(g.preventDefault(),H.focus()):(g.preventDefault(),(g.shiftKey?S:H).focus())},C=g=>{X.at(-1)===I&&e.current&&!e.current.contains(g.target)&&e.current.focus({preventScroll:!0})};return document.addEventListener("keydown",W),document.addEventListener("focusin",C),()=>{document.removeEventListener("keydown",W),document.removeEventListener("focusin",C);const g=X.at(-1)===I,R=X.indexOf(I);if(R!==-1&&X.splice(R,1),T(),g){const P=b.current;P?.isConnected&&!P.closest("[inert], [hidden]")?P.focus?.({preventScroll:!0}):X.at(-1)?.querySelector("[role=dialog]")?.focus?.({preventScroll:!0})}}},[e]);const w=n.backgroundColor??n.backgroudColor,u=typeof w=="string"?w:w?.[x],h=typeof u=="string"&&/^(#|rgb\(|rgba\(|hsl\(|hsla\(|oklch\(|color\(|var\()/.test(u.trim())?u:null,q={sm:400,md:560,lg:720,xl:960,full:"100%"},N=["center","left","right","top","bottom"].includes(n.placement)?n.placement:"right",$=T=>typeof T=="number"?`${T}px`:T,B=$(n.width??q[n.size]??460),A=$(n.height),M=$(n.maxHeight),O=$(n.maxWidth),L=Number(n.viewportGap??5),D=Number.isFinite(L)?Math.max(0,L):5,F=typeof n.borderRadius=="number"?`${n.borderRadius}px`:n.borderRadius??"12px";return Le.createPortal(d.jsx("div",{ref:y,className:`pmn-overlay ${c?"pmn-exiting":"pmn-entering"} ${n.animation===!1?"pmn-no-animation":""} pmn-place-${N} ${n.mobileFullscreen?"pmn-mobile-fullscreen":""}`,style:{padding:D,"--pmn-animation-duration":`${Math.min(1e3,Math.max(0,Number(n.animationDuration??220)||0))}ms`},onMouseDown:T=>{T.target===T.currentTarget&&n.closeOnOverlay===!0&&E.current("overlay")},children:d.jsx("section",{ref:e,tabIndex:-1,role:"dialog","aria-modal":"true","aria-label":n.ariaLabel??"Dialog","data-modal-theme":x,className:`pmn-dialog ${x==="dark"?"dark":""} ${!h&&u?u:""} ${n.className??""}`,style:{"--pmn-width":B,"--pmn-gap":`${D}px`,...A!==void 0?{"--pmn-height":A}:{},...M!==void 0?{"--pmn-max-height":M}:{},...O!==void 0?{"--pmn-max-width":O}:{},borderRadius:F,...h?{backgroundColor:h}:{}},children:a})}),document.body)}function Ce({back:e}){return d.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",width:"20",height:"20",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e?d.jsx("path",{d:"m15 18-6-6 6-6"}):d.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})}function De({options:e,screen:n,route:o,navigation:a,requestClose:c,translate:y}){if(e.showHeader===!1)return null;const b=y??(w=>w),E=n.showTitle??e.showTitle??!0,p=typeof n.title=="function"?n.title({t:b,route:o,navigation:a}):n.title??o.name,k={route:o,navigation:a,close:c,canGoBack:a.canGoBack,title:p,t:b},j=n.renderHeader??e.renderHeader;if(j)return j(k);const x=n.renderHeaderRight??e.renderHeaderRight;return d.jsxs("header",{className:`pmn-header ${n.showHeaderBorder??e.showHeaderBorder?"pmn-border-bottom":""} ${e.headerClassName??""}`,children:[e.showBackButton!==!1&&a.canGoBack&&d.jsx("button",{type:"button",className:"pmn-icon-button","aria-label":b("modal.back"),onClick:()=>a.goBack(),children:d.jsx(Ce,{back:!0})}),E?d.jsx("h2",{children:p}):d.jsx("div",{className:"pmn-header-spacer"}),x?.(k),e.showCloseButton!==!1&&d.jsx("button",{type:"button",className:"pmn-icon-button","aria-label":b("modal.close"),onClick:()=>c("header"),children:d.jsx(Ce,{})})]})}function $e({screen:e,options:n,override:o,route:a,navigation:c,requestClose:y,translate:b,onError:E,loadingApi:p}){const[k,j]=t.useState(!1),x=b??(L=>L),w={...n,...e,...o},{showFooter:u,renderFooter:h,done:q,cancel:N,cancle:$}=w,B=N??$,A={route:a,navigation:c,close:y,t:x};if(u===!1)return null;const M=`pmn-footer ${w.showFooterBorder?"pmn-border-top":""} ${w.footerClassName??""}`;if(typeof h=="function")return d.jsx("footer",{className:M,children:h({...A,pending:k})});if(typeof q!="function"&&typeof B!="function")return null;const O=async L=>{if(k||typeof L!="function")return;j(!0);const D=p?.begin(a.key,w.loadingText??x("modal.processing"));try{await L(A)}catch(F){E?.(F,{phase:"footer",route:a})}finally{p?.end(a.key,D),j(!1)}};return d.jsxs("footer",{className:M,children:[typeof B=="function"&&d.jsx("button",{type:"button",disabled:k,onClick:()=>O(B),className:"pmn-button pmn-button-secondary",children:w.cancelText??x("modal.cancel")}),typeof q=="function"&&d.jsx("button",{type:"button",disabled:k||w.doneDisabled===!0,onClick:()=>O(q),className:"pmn-button pmn-button-primary",children:k?w.loadingText??x("modal.processing"):w.doneText??x("modal.done")})]})}function Ie({loading:e,translate:n}){if(!e.visible)return null;const a=(n??(y=>y))("modal.loading"),c=e.text??(a==="modal.loading"?"加载中...":a);return d.jsx("div",{className:"pmn-loading-overlay",role:"status","aria-live":"polite","aria-busy":"true",children:d.jsxs("div",{className:"pmn-loading-content",children:[d.jsx("span",{className:"pmn-spinner","aria-hidden":"true"}),c&&d.jsx("span",{className:"pmn-loading-text",children:c})]})})}class He extends t.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?d.jsxs("div",{role:"alert",className:"pmn-error-screen",children:[d.jsx("strong",{children:"页面加载失败"}),d.jsx("p",{children:this.state.error.message}),d.jsx("button",{type:"button",className:"pmn-button pmn-button-secondary",onClick:()=>this.setState({error:null}),children:"重试"})]}):this.props.children}}function ze({route:e,screen:n,navigation:o,focused:a,resultEvent:c,setFooter:y,loadingApi:b,bodyClassName:E,notifyError:p,registerDirtyGuard:k}){const j=n.component,x=t.useMemo(()=>({isFocused:a,resultEvent:c,routeKey:e.key,setFooter:y}),[a,c,e.key,y]),w=t.useMemo(()=>({isLoading:a&&b.isLoading,setLoading:(u,h)=>b.setScreenLoading(e.key,u,h),showLoading:u=>b.begin(e.key,u),hideLoading:u=>b.end(e.key,u)}),[a,b,e.key]);return d.jsx(je.Provider,{value:{routeKey:e.key,registerDirtyGuard:k},children:d.jsx(fe.Provider,{value:x,children:d.jsx(xe.Provider,{value:w,children:d.jsx("div",{hidden:!a,inert:!a,"data-modal-route-key":e.key,tabIndex:-1,className:`pmn-body ${E??""}`,children:d.jsx(He,{route:e,onError:p,children:d.jsx(j,{route:e,navigation:o})})})})})})}function Te({config:e,initialScreen:n,params:o,options:a,translate:c,onRequestClose:y,onOpened:b,registerLoading:E,notifyError:p,error:k,clearError:j,registerDirtyGuard:x,exiting:w=!1}){const[u,h]=t.useReducer(Be,null,()=>Se(n??e.initialRoute,o)),[q,N]=t.useState({}),[$,B]=t.useState({}),[,A]=t.useState(0),M=t.useRef(new Map),O=t.useRef(0),L=t.useRef(new Map),D=t.useRef(null),F=t.useRef(null),T=t.useRef(!1),I=t.useRef(!1),W=t.useRef(0),C=u.at(-1),g=C.key,R=t.useRef(g);R.current=g;const P=e.screens,H=t.useCallback(()=>A(r=>r+1),[]),S=t.useCallback((r,l)=>{if(r!=="global"&&R.current!==r)return null;const m=++O.current;return M.current.set(m,{owner:r,text:l}),H(),m},[H]),K=t.useCallback((r,l)=>{if(l!=null)M.current.get(l)?.owner===r&&M.current.delete(l);else for(const[m,G]of M.current)G.owner===r&&M.current.delete(m);H()},[H]),z=t.useCallback((r,l)=>{r?(K("global"),S("global",l)):K("global")},[S,K]),Z=t.useCallback((r,l,m)=>{l?(K(r),S(r,m)):K(r)},[S,K]),ee=[...M.current.values()],U={visible:ee.length>0,text:ee.at(-1)?.text??null,count:ee.length},_=t.useRef(U);_.current=U;const ne=t.useMemo(()=>({isLoading:U.visible,setLoading:z,setScreenLoading:Z,begin:S,end:K}),[U.visible,z,Z,S,K]),te=t.useRef(E);te.current=E,t.useEffect(()=>(te.current?.({setLoading:z}),()=>te.current?.(null)),[z]);const le=t.useCallback((r,l)=>B(m=>{if(l===null){if(!(r in m))return m;const G={...m};return delete G[r],G}return m[r]===l?m:{...m,[r]:l}}),[]),V=t.useCallback(()=>{const r=document.activeElement;if(!(r instanceof HTMLElement)||!D.current?.contains(r))return;const l=r.closest("[data-modal-route-key]");l&&L.current.set(l.dataset.modalRouteKey,r),D.current.focus({preventScroll:!0})},[]),re=t.useCallback(r=>{if(!Object.prototype.hasOwnProperty.call(P,r))throw new Error(`[react-modal-navigation] Unknown modal screen: ${r}`)},[P]),Q=t.useCallback((r,l)=>{try{Promise.resolve(a[r]?.(l)).catch(m=>p(m,{phase:r}))}catch(m){p(m,{phase:r})}},[a,p]),Y=t.useCallback((r,l,m)=>{re(l),V(),h({type:r,name:l,params:m})},[re,V]),oe=t.useCallback((r,l)=>Y("NAVIGATE",r,l),[Y]),ae=t.useCallback((r,l)=>Y("REPLACE",r,l),[Y]),se=t.useCallback((r,l)=>{N({}),Y("RESET",r,l)},[Y]),ce=t.useCallback(r=>{if(!r||typeof r!="object"||Array.isArray(r))throw new TypeError("[react-modal-navigation] setParams expects an object");h({type:"SET_PARAMS",params:r})},[]),ue=t.useCallback(r=>{if(!r||typeof r!="object"||Array.isArray(r))throw new TypeError("[react-modal-navigation] setOptions expects an object");h({type:"SET_OPTIONS",options:r})},[]),s=t.useCallback(r=>{if(u.length<=1||T.current)return!1;if(T.current=!0,r!==void 0){const l=u.at(-2);N(m=>({...m,[l.key]:{id:++W.current,data:r}}))}return V(),h({type:"BACK"}),!0},[u,V]),i=t.useCallback((r,l)=>_.current.visible&&a.lockCloseWhileLoading!==!1?Promise.resolve(!1):y(r,l,{route:C,stack:u}),[a.lockCloseWhileLoading,y,C,u]),v=t.useCallback(r=>i("api",r),[i]),f=t.useMemo(()=>({navigate:oe,replace:ae,reset:se,setParams:ce,setOptions:ue,goBack:s,close:v,setLoading:z,canGoBack:u.length>1,stack:u,currentRoute:C}),[oe,ae,se,ce,ue,s,v,z,u,C]);return t.useLayoutEffect(()=>{T.current=!1;const r=[...D.current?.querySelectorAll("[data-modal-route-key]")??[]].find(G=>G.dataset.modalRouteKey===g);if(!r)return;const l=L.current.get(g);(l?.isConnected&&r.contains(l)&&!l.matches(":disabled")&&!l.closest("[inert], [hidden]")?l:r).focus({preventScroll:!0})},[g]),t.useEffect(()=>{let r=!1;for(const[m,G]of M.current)G.owner!=="global"&&G.owner!==g&&(M.current.delete(m),r=!0);r&&H();const l=new Set(u.map(m=>m.key));for(const m of L.current.keys())l.has(m)||L.current.delete(m)},[g,u,H]),t.useEffect(()=>{if(F.current?.key!==g){if(F.current){const r={from:F.current,to:C,stack:u};Q("onBlur",{route:F.current,...r}),Q("onNavigate",r),Q("onRouteChange",r)}Q("onFocus",{route:C,stack:u}),F.current=C}},[C,g,u,Q]),t.useEffect(()=>()=>{M.current.clear(),L.current.clear()},[]),t.useEffect(()=>{I.current||(I.current=!0,b?.({route:C,stack:u}))},[]),d.jsx(ve.Provider,{value:f,children:d.jsx(xe.Provider,{value:ne,children:d.jsxs(Ae,{dialogRef:D,options:a,requestClose:i,exiting:w,children:[d.jsx(De,{options:a,screen:{...P[C.name],...C.options??{}},route:C,navigation:f,requestClose:i,translate:c}),d.jsx("main",{className:"pmn-main",children:u.map(r=>d.jsx(ze,{route:r,screen:P[r.name],navigation:f,focused:r.key===g,resultEvent:q[r.key]??null,bodyClassName:a.bodyClassName,setFooter:le,loadingApi:ne,notifyError:p,registerDirtyGuard:x},r.key))}),d.jsx($e,{screen:{...P[C.name],...C.options??{}},options:a,override:$[g],route:C,navigation:f,requestClose:i,translate:c,onError:p,loadingApi:ne},g),d.jsx(Ie,{loading:U,translate:c}),k&&d.jsxs("div",{className:"pmn-error",role:"alert",children:[d.jsx("span",{children:k.message||String(k)}),d.jsx("button",{type:"button",onClick:j,"aria-label":"Dismiss error",children:"×"})]})]})})})}const Ge=".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}}",Re="react-modal-navigation-styles",be=new WeakMap;function Ke(){t.useInsertionEffect(()=>{if(typeof document>"u")return;const e=document;let n=be.get(e);if(!n){let o=e.getElementById(Re);const a=!o;o||(o=e.createElement("style"),o.id=Re,o.setAttribute("data-react-modal-navigation",""),o.textContent=Ge,e.head.appendChild(o)),n={element:o,owned:a,count:0},be.set(e,n)}return n.count+=1,()=>{n.count-=1,n.count===0&&(n.owned&&n.element.remove(),be.delete(e))}},[])}function me(e,n,o){if(typeof e=="string"){if(!e.trim())throw new TypeError("[react-modal-navigation] modal name must not be empty");return{name:e,params:n??{},options:o??{}}}if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError("[react-modal-navigation] open expects a modal name or a configuration object");const{name:a,screen:c,params:y={},options:b={},...E}=e;if(typeof a!="string"||!a.trim())throw new TypeError("[react-modal-navigation] open config requires a non-empty string name");if(b===null||typeof b!="object"||Array.isArray(b))throw new TypeError("[react-modal-navigation] open config options must be an object");if(c!==void 0&&(typeof c!="string"||!c.trim()))throw new TypeError("[react-modal-navigation] screen must be a non-empty string");return{name:a,...c===void 0?{}:{screen:c},params:y,options:{...E,...b}}}const Ue={placement:"right",showHeader:!0,showBackButton:!0,showCloseButton:!0,viewportGap:5,borderRadius:12,closeOnOverlay:!1,closeOnEsc:!0},We=e=>({"modal.loading":"加载中...","modal.processing":"处理中...","modal.back":"返回","modal.close":"关闭","modal.cancel":"取消","modal.done":"完成"})[e]??e;function Ye({registry:e,children:n,defaultOptions:o={},backgroundColor:a,theme:c,translate:y=We,onError:b,confirmDiscard:E}){Ke();const[p,k]=t.useState(null),[j,x]=t.useState(null),[w,u]=t.useState(0),h=t.useRef(null),q=t.useRef(new Map),N=t.useRef([]),$=t.useRef(null),B=t.useRef(null),A=t.useRef(0),M=t.useRef(null),O=t.useRef(!1),L=t.useRef(0),D=t.useRef(null),F=t.useRef(new Map),[T,I]=t.useState(!1),W=t.useRef(E);W.current=E;const C=t.useCallback((s,i)=>(F.current.set(s,i),()=>{F.current.get(s)===i&&F.current.delete(s)}),[]),g=t.useCallback(async s=>{for(const i of F.current.values()){if(!i.dirty)continue;if((i.onBeforeDiscard?await i.onBeforeDiscard(s):W.current?await W.current(s):typeof window<"u"&&typeof window.confirm=="function"?window.confirm(i.message||"有未保存的修改,确定放弃吗?"):!1)===!1)return!1}return!0},[]),R=t.useRef(!0),P=t.useRef(null),H=t.useRef(b);H.current=b;const S=t.useCallback((s,i)=>{R.current&&x(s);try{H.current?H.current(s,i):console.error("[react-modal-navigation]",s)}catch(v){console.error("[react-modal-navigation] onError failed",v)}},[]),K=t.useCallback((s,i)=>{const v=q.current.get(s);q.current.delete(s),v?.(i)},[]),z=t.useCallback(s=>({...Ue,...o,...c!==void 0?{theme:c}:{},...a!==void 0?{backgroundColor:a}:{},...s.config.modalOptions,...s.overrides}),[o,c,a]),Z=p?z(p):null,ee=t.useRef(null);ee.current=Z,P.current=Z;const U=t.useCallback(async(s="api",i,v={})=>{const f=h.current;if(!f||M.current||O.current)return!1;M.current=f.id,O.current=!0;const r=P.current??z(f),l={...v,reason:s,result:i,name:f.name};try{if(!await g(l)||await r.onBeforeClose?.(l)===!1||h.current?.id!==f.id||!R.current||(I(!0),await new Promise(m=>{const G=r.animation===!1||typeof window<"u"&&window.matchMedia?.("(prefers-reduced-motion: reduce)").matches?0:Math.max(0,Number(r.animationDuration??220)||0);setTimeout(m,Math.min(G,1e3))}),!R.current||h.current?.id!==f.id))return!1;h.current=null,D.current=null,k(null),I(!1),F.current.clear(),K(f.id,v.confirmed||i!==void 0?{status:"confirmed",value:i,reason:s}:{status:"dismissed",reason:s});try{await r.onClose?.(l)}catch(m){S(m,{phase:"onClose",name:f.name})}return!0}catch(m){return S(m,{phase:"onBeforeClose",name:f.name}),!1}finally{M.current===f.id&&(M.current=null),O.current=!1,!h.current&&R.current&&queueMicrotask(()=>B.current?.())}},[z,S,K,g]),_=t.useCallback(async(s,i={},v={},f,r)=>{const l=e?.[s];if(!l)throw new Error(`[react-modal-navigation] Unknown modal: ${s}`);const m=r??l.initialRoute;if(!l.screens?.[m])throw new Error(`[react-modal-navigation] Unknown initial screen '${m}' in modal '${s}'`);if(!R.current||O.current||M.current)return null;O.current=!0;const G=L.current;try{const J=h.current;if(J){const ke=P.current??z(J),pe={reason:"replace",name:J.name,nextName:s};try{if(!await g(pe)||await ke.onBeforeClose?.(pe)===!1)return null}catch(he){return S(he,{phase:"onBeforeClose",name:J.name}),null}if(!R.current||G!==L.current||h.current?.id!==J.id)return null;h.current=null,D.current=null,k(null),F.current.clear(),K(J.id,{status:"replaced",reason:"replace"});try{await ke.onClose?.(pe)}catch(he){S(he,{phase:"onClose",name:J.name})}if(!R.current||G!==L.current)return null}const de={id:++A.current,name:s,screen:m,params:i,config:l,overrides:v};return h.current=de,D.current=null,f&&q.current.set(de.id,f),x(null),k(de),de.id}finally{O.current=!1}},[e,z,S,K,g]);$.current=_;const ne=t.useCallback(async()=>{if(!R.current||h.current||O.current||M.current)return;const s=N.current.shift();if(s){u(N.current.length);try{const i=await $.current(s.args.name,s.args.params,s.args.options,s.resolveResult,s.args.screen);i===null?(s.resolveResult?.({status:"dismissed",reason:"blocked"}),s.resolveId?.(null),queueMicrotask(()=>B.current?.())):s.resolveId?.(i)}catch(i){s.reject?.(i),queueMicrotask(()=>B.current?.())}}},[]);B.current=ne;const te=t.useCallback((s,i,v)=>{const f=me(s,i,v);return e?.[f.name]?new Promise((r,l)=>{N.current.push({args:f,resolveId:r,reject:l}),u(N.current.length),queueMicrotask(()=>B.current?.())}):Promise.reject(new Error(`[react-modal-navigation] Unknown modal: ${f.name}`))},[e]),le=t.useCallback((s,i,v)=>{const f=me(s,i,v);return e?.[f.name]?new Promise((r,l)=>{N.current.push({args:f,resolveResult:r,reject:l}),u(N.current.length),queueMicrotask(()=>B.current?.())}):Promise.reject(new Error(`[react-modal-navigation] Unknown modal: ${f.name}`))},[e]),V=t.useCallback(s=>{if(!s||typeof s!="object"||Array.isArray(s))throw new TypeError("[react-modal-navigation] update expects an options object");const i=h.current;if(!i||O.current)return!1;const v={...i,overrides:{...i.overrides,...s}};return h.current=v,k(v),P.current=z(v),!0},[z]),re=t.useCallback((s="queue-cleared")=>{const i=N.current.splice(0);u(0);for(const v of i)v.resolveId?.(null),v.resolveResult?.({status:"dismissed",reason:s});return i.length},[]),Q=t.useCallback((s,i,v)=>{const f=me(s,i,v);return _(f.name,f.params,f.options,void 0,f.screen)},[_]),Y=t.useCallback((s,i,v)=>{const f=me(s,i,v);return new Promise((r,l)=>{_(f.name,f.params,f.options,r,f.screen).then(m=>{m===null&&r({status:"dismissed",reason:"blocked"})},l)})},[_]),oe=t.useCallback(s=>U("api",s),[U]),ae=t.useCallback((s="api")=>U(s),[U]),se=t.useCallback(s=>U("confirm",s,{confirmed:!0}),[U]),ce=t.useCallback((s,i)=>D.current?.setLoading(s,i),[]),ue=t.useMemo(()=>({open:Q,openAsync:Y,enqueue:te,enqueueAsync:le,update:V,clearQueue:re,close:oe,dismiss:ae,confirm:se,setLoading:ce,queueSize:w,isOpen:!!p,activeName:p?.name??null,error:j,clearError:()=>x(null)}),[Q,Y,te,le,V,re,oe,ae,se,ce,p,j,w]);return t.useEffect(()=>(R.current=!0,()=>{R.current=!1,L.current+=1,h.current=null;for(const i of q.current.values())i({status:"dismissed",reason:"unmount"});q.current.clear(),F.current.clear();const s=N.current.splice(0);for(const i of s)i.resolveId?.(null),i.resolveResult?.({status:"dismissed",reason:"unmount"})}),[]),d.jsxs(Me.Provider,{value:ue,children:[n,p&&d.jsx(Te,{config:p.config,initialScreen:p.screen,params:p.params,options:Z,translate:y,notifyError:S,error:j,clearError:()=>x(null),registerLoading:s=>{D.current=s},registerDirtyGuard:C,exiting:T,onRequestClose:U,onOpened:s=>{try{const i=ee.current?.onOpen?.(s);Promise.resolve(i).catch(v=>S(v,{phase:"onOpen"}))}catch(i){S(i,{phase:"onOpen"})}}},p.id)]})}function _e(){const e=t.useContext(Me),n=t.useContext(ve);if(!e)throw new Error("[react-modal-navigation] useModal requires <ModalProvider>");return t.useMemo(()=>{const o=()=>{if(!n)throw new Error("[react-modal-navigation] navigation requires an active modal screen; use modal.open() outside a modal");return n};return{...e,modal:e,navigation:{navigate:(...c)=>o().navigate(...c),replace:(...c)=>o().replace(...c),reset:(...c)=>o().reset(...c),setParams:(...c)=>o().setParams(...c),setOptions:(...c)=>o().setOptions(...c),goBack:(...c)=>o().goBack(...c),close:(...c)=>o().close(...c),get canGoBack(){return n?.canGoBack??!1},get stack(){return n?.stack??[]},get currentRoute(){return n?.currentRoute??null}}}},[e,n])}function Qe(){const e=t.useContext(ve);if(!e)throw new Error("useModalNavigation requires an active modal screen");return e}function we(){const e=t.useContext(fe);if(!e)throw new Error("useIsFocused must be called inside a modal screen");return e.isFocused}function Ve(e){const n=we();t.useEffect(()=>{if(n)return e()},[n,e])}function Je(e){const n=t.useContext(fe);if(!n)throw new Error("useNavigationResult requires an active modal screen");const o=t.useRef(e),a=t.useRef(null);t.useEffect(()=>{o.current=e},[e]),t.useEffect(()=>{!n.isFocused||!n.resultEvent||a.current!==n.resultEvent.id&&(a.current=n.resultEvent.id,o.current(n.resultEvent.data))},[n.isFocused,n.resultEvent])}function Xe(e={}){const n=t.useContext(fe);if(!n)throw new Error("[react-modal-navigation] useModalFooter requires an active modal screen");const{setFooter:o,routeKey:a}=n,c=t.useRef(e);c.current=e;const y=t.useMemo(()=>(...A)=>c.current.done?.(...A),[]),b=t.useMemo(()=>(...A)=>(c.current.cancel??c.current.cancle)?.(...A),[]),E=t.useMemo(()=>(...A)=>c.current.renderFooter?.(...A),[]),p=typeof e.done=="function",k=typeof(e.cancel??e.cancle)=="function",j=typeof e.renderFooter=="function",{showFooter:x,showFooterBorder:w,doneDisabled:u,doneText:h,cancelText:q,loadingText:N,footerClassName:$}=e,B=t.useMemo(()=>({showFooter:x,showFooterBorder:w,doneDisabled:u,doneText:h,cancelText:q,loadingText:N,footerClassName:$,...p?{done:y}:{},...k?{cancel:b}:{},...j?{renderFooter:E}:{}}),[x,w,u,h,q,N,$,p,k,j,y,b,E]);t.useEffect(()=>{o(a,B)},[a,o,B]),t.useEffect(()=>()=>o(a,null),[a,o])}function Ne(){const e=t.useContext(xe);if(!e)throw new Error("[react-modal-navigation] useModalLoading requires an active modal screen");return e}function Ze(){const e=Ne(),n=we(),o=t.useRef(!0),a=t.useRef(!1),[c,y]=t.useState(!1),[b,E]=t.useState(null),p=t.useRef(e);return p.current=e,t.useEffect(()=>(o.current=!0,()=>{o.current=!1}),[]),{run:t.useCallback(async(j,x={})=>{if(a.current)return{status:"busy"};if(typeof j!="function")throw new TypeError("[react-modal-navigation] run requires a function");a.current=!0,o.current&&(y(!0),E(null));const w=p.current.showLoading(x.loadingText);try{const u=await j();return o.current&&await x.onSuccess?.(u),{status:"success",value:u}}catch(u){if(o.current){E(u);try{await x.onError?.(u)}catch(h){console.error("[react-modal-navigation] onError failed",h)}}if(x.throwOnError)throw u;return{status:"error",error:u}}finally{w!=null&&p.current.hideLoading(w),a.current=!1,o.current&&y(!1)}},[]),pending:c,error:b,clearError:()=>E(null),isFocused:n}}function et(e,n={}){const o=t.useContext(je);if(!o)throw new Error("[react-modal-navigation] useModalUnsavedChanges must be used inside a modal screen");const a=t.useRef({dirty:e,...n});a.current={dirty:e,...n};const{routeKey:c,registerDirtyGuard:y}=o;t.useEffect(()=>y(c,{get dirty(){return!!a.current.dirty},get message(){return a.current.message},get onBeforeDiscard(){return a.current.onBeforeDiscard}}),[c,y])}exports.ModalNavigator=Te;exports.ModalProvider=Ye;exports.useFocusEffect=Ve;exports.useIsFocused=we;exports.useModal=_e;exports.useModalFooter=Xe;exports.useModalLoading=Ne;exports.useModalNavigation=Qe;exports.useModalTask=Ze;exports.useModalUnsavedChanges=et;exports.useNavigationResult=Je;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { ComponentType, ReactNode } from 'react';
2
2
  export type ModalTheme = 'auto' | 'light' | 'dark';
3
3
  export type ModalBackground = string | { light?: string; dark?: string };
4
- export interface ModalRoute<P = unknown> { key: string; name: string; params: P }
4
+ export interface ModalRoute<P = unknown> { key: string; name: string; params: P; options?: ModalScreenOptions }
5
5
  export type ModalResult<T = unknown> = { status: 'confirmed'; value: T; reason: string } | { status: 'dismissed' | 'replaced'; reason: string };
6
6
  export interface ModalEventContext<T = unknown> { route?: ModalRoute; stack?: ModalRoute[]; from?: ModalRoute; to?: ModalRoute; reason?: string; result?: T; name?: string }
7
7
  export interface ModalNavigation {
@@ -9,6 +9,8 @@ export interface ModalNavigation {
9
9
  replace(name: string, params?: unknown): void;
10
10
  reset(name: string, params?: unknown): void;
11
11
  setParams(params: Record<string, unknown>): void;
12
+ /** Update options of the active screen without navigating. Changes are scoped to this route instance. */
13
+ setOptions(options: ModalScreenOptions): void;
12
14
  goBack(result?: unknown): boolean;
13
15
  close(result?: unknown): Promise<boolean>;
14
16
  setLoading(value: boolean, text?: string): void;
@@ -76,6 +78,9 @@ export interface ModalOptions {
76
78
  renderHeaderRight?: (context: ModalActionContext) => ReactNode;
77
79
  }
78
80
  export interface ModalActionContext { route: ModalRoute; navigation: ModalNavigation; close: (reason?: string, result?: unknown) => Promise<boolean>; t: (key: string) => string }
81
+ export interface ModalScreenOptions extends Omit<Partial<ModalOptions>, 'title'> {
82
+ title?: string | ReactNode | ((context: { t: (key: string) => string; route: ModalRoute; navigation: ModalNavigation }) => ReactNode);
83
+ }
79
84
  export interface ModalScreen extends ModalOptions {
80
85
  component: ComponentType<any>;
81
86
  title?: string | ((context: { t: (key: string) => string; route: ModalRoute; navigation: ModalNavigation }) => ReactNode);