@liuman/react-workspace 1.4.4 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- "use strict";const n=require("react/jsx-runtime"),o=require("react"),ye=require("react-dom"),$e=({tip:e="加载中...",spinning:t=!1,children:i})=>n.jsxs("div",{className:"rw-spinner-wrap",children:[i,t&&n.jsxs("div",{className:"rw-spinner-overlay",children:[n.jsx("div",{className:"rw-spinner"}),e&&n.jsx("span",{className:"rw-spinner-tip",children:e})]})]}),we=100;function Q(e,t){const i=globalThis.window.innerWidth,r=globalThis.window.innerHeight,m=Math.min(t?.minWidth??we,i),p=Math.min(t?.minHeight??we,r);let{x:W,y:g,width:f,height:v}=e;return f=Math.min(f,i),v=Math.min(v,r),f=Math.max(f,m),v=Math.max(v,p),W+f>i&&(W=Math.max(0,i-f)),g+v>r&&(g=Math.max(0,r-v)),W<0&&(W=0),g<0&&(g=0),{x:W,y:g,width:f,height:v}}function se(e,t){return`${e}${t}`}function ne(e,t){if(!t)return{};try{const i=se(e,t),r=localStorage.getItem(i);if(r){const m=JSON.parse(r);if(m&&typeof m=="object"){const p={};return Object.entries(m).forEach(([W,g])=>{if(g&&typeof g=="object"){const f=g,v={};f.position&&typeof f.position.x=="number"&&typeof f.position.y=="number"&&typeof f.position.width=="number"&&typeof f.position.height=="number"&&(v.position=Q(f.position)),typeof f.minimized=="boolean"&&(v.minimized=f.minimized),typeof f.floating=="boolean"&&(v.floating=f.floating),typeof f.floatingZIndex=="number"&&(v.floatingZIndex=f.floatingZIndex),p[W]=v}}),p}}}catch(i){console.warn("[react-workspace] 从 localStorage 读取窗口状态失败:",i)}return{}}function re(e,t,i,r){if(t)try{const m=ne(e,t);m[i]={...m[i],...r},localStorage.setItem(se(e,t),JSON.stringify(m))}catch(m){console.warn("[react-workspace] 保存窗口状态到 localStorage 失败:",m)}}function oe(e,t,i){if(t)try{const r=se(e,t),m=localStorage.getItem(r);let p=m?JSON.parse(m):{};const W=Object.values(p).map(z=>z?.floatingZIndex||0).filter(z=>z>=1e3),g=W.length>0?Math.max(...W):999,f=p[i]||{},v=f.floatingZIndex||0,X=Math.max(1e3,g+1);v>=1e3?(p[i]={...f,floatingZIndex:X},Object.keys(p).forEach(z=>{if(z!==i&&p[z]){const N=p[z];N.floatingZIndex!==void 0&&N.floatingZIndex>=1e3&&(p[z]={...N,floatingZIndex:Math.max(1e3,N.floatingZIndex-1)})}})):p[i]={...f,floatingZIndex:X},localStorage.setItem(r,JSON.stringify(p))}catch(r){console.error("[react-workspace] 保存标签点击顺序失败:",r)}}function ae(e,t,i){if(e.length===0)return null;try{const r=localStorage.getItem(se(t,i));if(r){const m=JSON.parse(r);return[...e].sort((W,g)=>{const f=m[W.type]?.floatingZIndex||0,v=m[g.type]?.floatingZIndex||0;return f>=1e3&&v>=1e3?v-f:f>=1e3?-1:v>=1e3?1:0})[0]?.id??e[e.length-1].id}}catch{}return e[e.length-1].id}const Oe="react_workspace_windows_",Ae={x:100,y:100,width:800,height:600,minWidth:400,minHeight:300};function xe(e){return{...Ae,...e}}function Be(e,t){let i=e;if(i.trim().startsWith("%"))try{i=decodeURIComponent(i)}catch{}const r=JSON.parse(i);if(!Array.isArray(r))throw new Error("窗口列表不是数组");return r.map(m=>{const p=String(m.t??m.type??"");if(!p)throw new Error("窗口缺少类型");const W=m.p??m.props,g=t?.(p,W)??m.n??m.title??p,f={id:typeof m.id=="string"&&m.id?m.id:ce(),type:p,title:String(g),minimized:!1};return W&&typeof W=="object"&&(f.props=W),f})}function ce(){return`window-${Date.now()}-${Math.random().toString(36).slice(2,7)}`}function be(e){const{workspaceId:t,defaultWindow:i,syncToUrl:r=!1,preserveUrlParams:m=!0,searchParams:p,setSearchParams:W,storageKeyPrefix:g=Oe,floatingDefaults:f,onWindowsChange:v,resolveTitle:X}=e,z=o.useRef(X);z.current=X;const N=o.useRef(i??{type:"home",title:"首页",minimized:!1});N.current=i??N.current;const O=o.useRef(xe(f));O.current=xe(f);const D=o.useRef(v);D.current=v;const[b,R]=o.useState([]),[C,L]=o.useState(null),x=o.useRef({}),w=o.useCallback((s,l)=>{D.current?.(s,l)},[]),Z=o.useCallback(s=>ne(g,t)[s]||null,[g,t]),H=o.useCallback(s=>Z(s)?.position||null,[Z]),E=o.useCallback((s,l)=>{if(!r||!W)return;const c=m&&p?new URLSearchParams(p):new URLSearchParams;if(s.length>0){c.set("windows",JSON.stringify(s.map(d=>{const M={t:d.type};return d.props&&Object.keys(d.props).length>0&&(M.p=d.props),M})));const u=s.findIndex(d=>d.id===l);u>=0?c.set("active",String(u)):c.delete("active")}else c.delete("windows"),c.delete("active");W(c,{replace:!0})},[r,W,m,p]),h=o.useCallback((s,l)=>{R(s),L(l),E(s,l),w(s,l)},[E,w]),q=o.useCallback(s=>{const l=Z(s.type),c={...s,minimized:l?.minimized??s.minimized??!1,floating:l?.floating??s.floating??!1};if(c.floating){let u=s.floatingPosition||l?.position;u||(u=H(s.type)??void 0),u&&(c.floatingPosition=Q(u)),c.floatingZIndex=l?.floatingZIndex??s.floatingZIndex??1e3}return c},[Z,H]),_=o.useCallback(()=>{const s=N.current,l={id:ce(),type:s.type,title:s.title,minimized:s.minimized??!1};h([l],l.id)},[h]),a=o.useCallback(()=>{if(t)try{localStorage.removeItem(`${g}${t}`)}catch{}delete x.current[t],_()},[t,g,_]);o.useEffect(()=>{if(!t||x.current[t])return;x.current[t]=!0;const s=r?p?.get("windows"):null,l=r?p?.get("active"):null;if(s)try{const c=Be(s,z.current);if(c.length===0)throw new Error("窗口列表是空的");const u=c.map(q),d=Number(l),M=Number.isInteger(d)&&d>=0&&d<u.length?u[d].id:u.find(B=>B.id===l)?.id??u[0]?.id??null;R(u),L(M),w(u,M)}catch(c){console.error("[react-workspace] 解析窗口配置失败:",c),_()}else _()},[t,p,r,q,_,w]);const y=o.useCallback((s,l)=>{const c=l!==void 0?{...s.props,...l}:s.props,u={...s,props:c},d=b.find(M=>M.type===u.type);if(d){const M=l&&Object.keys(l).length===0?void 0:c,B=q({...d,...u,props:M}),Y=b.map(K=>K.id===d.id?B:K);h(Y,d.id)}else{const M=q({...u,id:ce(),minimized:u.minimized??!1});h([...b,M],M.id)}},[b,h,q]),k=o.useCallback(s=>{const l=b.find(c=>c.id===s);if(l){if(oe(g,t,l.type),l.floating){const c=ne(g,t)[l.type];if(c?.floatingZIndex){const u=b.map(d=>d.id===s?{...d,minimized:!1,floatingZIndex:c.floatingZIndex}:d);h(u,s);return}}h(b.map(c=>c.id===s?{...c,minimized:!1}:c),s)}},[b,h,g,t]),S=o.useCallback(s=>{const l=b.filter(u=>u.id!==s),c=C===s?ae(l,g,t):C;h(l,c)},[b,C,h,g,t]),I=o.useCallback(s=>{const l=b.map(u=>{if(u.id===s){const d={...u,minimized:!u.minimized};return re(g,t,u.type,{minimized:d.minimized,floating:d.floating}),d}return u}),c=l.find(u=>u.id===s);if(c?.minimized&&C===s&&!c.floating){const u=l.find(d=>!d.minimized&&!d.floating);h(l,u?.id??null)}else c&&!c.minimized&&!c.floating?h(l,s):h(l,C)},[b,C,t,g,h]),$=o.useCallback((s,l)=>{const c=b.find(A=>A.id===s);if(!c||!t||c.floating)return;const u=b.filter(A=>!A.floating&&!A.minimized);if(u.length===1&&u[0].id===s)return;const d=O.current,M={minWidth:d.minWidth,minHeight:d.minHeight};let B=Q({x:d.x,y:d.y,width:d.width,height:d.height},M);if(l)B=Q({x:l.x,y:l.y,width:d.width,height:d.height},M);else if(c.floatingPosition)B=Q(c.floatingPosition,M);else{const A=H(c.type);A&&(B=Q(A,M))}oe(g,t,c.type);const Y=ne(g,t)[c.type]?.floatingZIndex??1e3,K=b.map(A=>A.id===s?(re(g,t,A.type,{floating:!0,minimized:!1,position:B,floatingZIndex:Y}),{...A,floating:!0,minimized:!1,floatingPosition:B,floatingZIndex:Y,pendingDragStart:l}):A);if(C===s){const A=K.filter(G=>!G.floating&&!G.minimized);h(K,A.length>0?ae(A,g,t):null)}else h(K,C)},[b,C,t,g,h,H]),j=o.useCallback((s,l)=>{const c=b.find(G=>G.id===s);if(!c?.floating)return;const{floating:u,floatingPosition:d,floatingZIndex:M,pendingDragStart:B,...Y}=c;re(g,t,c.type,{floating:!1,minimized:Y.minimized});const K=b.filter(G=>!G.floating);let A;l!==void 0&&l>=0&&l<=K.length?A=[...K.slice(0,l),Y,...K.slice(l)]:A=[...K,Y],A=[...A,...b.filter(G=>G.floating&&G.id!==s)],h(A,s),setTimeout(()=>{document.querySelector(".rw-window-tabs")?.dispatchEvent(new CustomEvent("clearFloatingWindowPreview"))},0)},[b,h,g,t]),T=o.useCallback((s,l)=>{const c=b.find(d=>d.id===s);if(!c)return;const u=b.map(d=>{if(d.id===s){const{pendingDragStart:M,...B}=d;return{...B,floatingPosition:l}}return d});R(u),c.floating&&re(g,t,c.type,{position:l,floating:!0,minimized:c.minimized,floatingZIndex:c.floatingZIndex})},[b,t,g]),P=o.useCallback(s=>{const l=b.find(u=>u.id===s);if(!l?.floating||!t)return;oe(g,t,l.type);const c=ne(g,t)[l.type];c?.floatingZIndex&&R(u=>u.map(d=>d.id===s&&d.floating?{...d,floatingZIndex:c.floatingZIndex}:d))},[b,t,g]),F=o.useCallback((s,l)=>{R(c=>{const u=c.map(d=>d.id===s?{...d,props:{...d.props,...l}}:d);return w(u,C),u})},[C,w]),V=o.useCallback((s,l)=>{R(c=>{const u=c.map(d=>d.id===s?{...d,title:l}:d);return E(u,C),w(u,C),u})},[C,E,w]),J=o.useCallback(s=>{R(l=>l.map(c=>{if(c.id!==s)return c;const{pendingAction:u,...d}=c;return d}))},[]),ee=o.useCallback(s=>{if(s==="reset-windows"){a();return}if(!C&&!["close-all","minimize-all","restore-all"].includes(s))return;const l=b.filter(M=>!M.floating),c=b.filter(M=>M.floating);let u=[],d=C;switch(s){case"close-left":{const M=l.findIndex(B=>B.id===C);u=l.slice(M);break}case"close-right":{const M=l.findIndex(B=>B.id===C);u=l.slice(0,M+1);break}case"close-others":u=l.filter(M=>M.id===C);break;case"close-all":u=[],d=null;break;case"minimize-all":u=l.map(M=>({...M,minimized:!0})),d=null;break;case"restore-all":u=l.map(M=>({...M,minimized:!1})),d=C??u[0]?.id??null;break;default:u=l}h([...u,...c],d)},[b,C,h,a]),le=o.useCallback((s,l)=>{const c=b.filter(Y=>!Y.minimized&&!Y.floating);if(s<0||s>=c.length||l<0||l>=c.length||s===l)return;const u=[...c],[d]=u.splice(s,1);u.splice(l,0,d);let M=0;const B=b.map(Y=>Y.minimized||Y.floating?Y:u[M++]);h(B,C)},[b,C,h]);return{windows:b,activeWindowId:C,openWindow:y,switchWindow:k,closeWindow:S,toggleMinimize:I,floatWindow:$,restoreWindow:j,updateFloatingPosition:T,focusWindow:P,batchManage:ee,updateWindowProps:F,updateWindowTitle:V,clearPendingAction:J,setWindows:R,setActiveWindowId:L,resetWorkspace:a,reorderWindows:le}}const fe=o.createContext(null),ve=fe.Provider;function Ze(){const e=o.useContext(fe);if(!e)throw new Error("[react-workspace] useWorkspaceContext 必须在 Workspace 或 WorkspaceProvider 内使用");return e}function He(){return o.useContext(fe)}const te=e=>({width:e,height:e,viewBox:"0 0 24 24",fill:"currentColor"}),We=({size:e=14,className:t})=>n.jsx("svg",{...te(e),className:t,children:n.jsx("path",{d:"M6 6l12 12M18 6L6 18",stroke:"currentColor",strokeWidth:"2",fill:"none"})}),Xe=({size:e=14,className:t})=>n.jsx("svg",{...te(e),className:t,children:n.jsx("path",{d:"M5 12h14",stroke:"currentColor",strokeWidth:"2",fill:"none"})}),Fe=({size:e=14,className:t})=>n.jsx("svg",{...te(e),className:t,children:n.jsx("rect",{x:"5",y:"5",width:"14",height:"14",rx:"1",stroke:"currentColor",strokeWidth:"2",fill:"none"})}),Ye=({size:e=16,className:t})=>n.jsxs("svg",{...te(e),className:t,children:[n.jsx("circle",{cx:"6",cy:"12",r:"1.5"}),n.jsx("circle",{cx:"12",cy:"12",r:"1.5"}),n.jsx("circle",{cx:"18",cy:"12",r:"1.5"})]}),qe=({size:e=12,className:t})=>n.jsx("svg",{...te(e),className:t,children:n.jsx("path",{d:"M9 6l6 6-6 6",stroke:"currentColor",strokeWidth:"2",fill:"none"})}),_e=({size:e=12,className:t})=>n.jsx("svg",{...te(e),className:t,children:n.jsx("path",{d:"M15 6l-6 6 6 6",stroke:"currentColor",strokeWidth:"2",fill:"none"})}),Ke=({size:e=64,className:t})=>n.jsx("svg",{...te(e),className:t,fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:n.jsx("path",{d:"M3 7a2 2 0 012-2h5l2 2h9a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2V7z"})}),Ue=({size:e=12,className:t})=>n.jsx("svg",{...te(e),className:t,children:n.jsx("path",{d:"M6 9l6 6 6-6",stroke:"currentColor",strokeWidth:"2",fill:"none"})});function ke(e,t){for(const i of e){if("type"in i&&i.type==="divider")continue;const r=i;if(r.key===t)return r;if(r.children){const m=ke(r.children,t);if(m)return m}}return null}function de(e,t,i){const r=m=>{for(const p of m){if("type"in p&&p.type==="divider")continue;const W=p;if(W.windowType===t)return typeof W.label=="string"?W.label:W.key;if(W.children){const g=r(W.children);if(g)return g}}return null};return r(e)??i??t}function ue(e,t){for(const i of e){if("type"in i&&i.type==="divider")continue;const r=i;if(r.windowType===t)return r.key;if(r.children){const m=ue(r.children,t);if(m)return m}}return null}function Se(e){const t=[];for(const i of e){if("type"in i&&i.type==="divider")continue;const r=i;r.children?.length&&t.push(r.key)}return t}function me(e){return typeof e=="string"||typeof e=="number"?String(e):""}function Ve(e){return"type"in e&&e.type==="divider"}const Ce=({menuItems:e,onMenuClick:t,onAction:i,activeWindowType:r,header:m,footer:p,defaultOpenKeys:W=[],siderWidth:g=240,onCollapsedChange:f})=>{const[v,X]=o.useState(!1),[z,N]=o.useState(new Set(W)),O=o.useMemo(()=>r?ue(e,r):null,[r,e]),D=()=>{X(x=>(f?.(!x),!x))},b=(x,w)=>{w?.stopPropagation(),N(Z=>{const H=new Set(Z);return H.has(x)?H.delete(x):H.add(x),H})},R=x=>{if(!x.disabled){if(x.windowType){t(x.windowType,x.props);return}if(x.action&&i){i(x.action);return}x.children?.length&&b(x.key)}},C=(x,w=0)=>x.map((Z,H)=>{if(Ve(Z))return n.jsx("div",{className:"rw-menu-divider"},Z.key??`div-${H}`);const E=Z,h=!!E.children?.length,q=z.has(E.key),_=E.key===O;return n.jsxs("div",{className:"rw-menu-group",children:[n.jsxs("button",{type:"button",className:`rw-menu-item ${_?"selected":""} ${E.disabled?"disabled":""}`,style:{paddingLeft:v?12:12+w*16},onClick:()=>R(E),disabled:E.disabled,title:v?me(E.label):void 0,children:[E.icon&&n.jsx("span",{className:"rw-menu-icon",children:E.icon}),!v&&n.jsx("span",{className:"rw-menu-label",children:E.label}),!v&&h&&n.jsx("span",{className:`rw-menu-arrow ${q?"open":""}`,onClick:a=>b(E.key,a),role:"presentation",children:n.jsx(Ue,{size:10})})]}),!v&&h&&q&&n.jsx("div",{className:"rw-menu-children",children:C(E.children,w+1)})]},E.key)}),L=v?64:g;return n.jsxs("div",{className:"rw-workspace-sidebar-wrapper",children:[n.jsxs("aside",{className:"rw-workspace-sider",style:{width:L},children:[m&&n.jsx("div",{className:`rw-workspace-sidebar-header ${v?"collapsed":""}`,children:m}),n.jsx("nav",{className:"rw-workspace-sidebar-menu",children:C(e)}),p&&n.jsx("div",{className:`rw-workspace-sidebar-footer ${v?"collapsed":""}`,children:p})]}),n.jsx("button",{type:"button",className:"rw-workspace-collapse-button",style:{left:L},onClick:D,title:v?"展开导航":"折叠导航",children:v?n.jsx(_e,{}):n.jsx(qe,{})})]})},Je=({description:e="暂无内容",icon:t})=>n.jsxs("div",{className:"rw-empty",children:[n.jsx("div",{className:"rw-empty-icon",children:t??n.jsx(Ke,{size:64})}),n.jsx("div",{className:"rw-empty-desc",children:e})]}),je=({window:e,active:t,children:i})=>n.jsx("div",{className:`rw-window-container ${t?"active":""}`,style:{display:t?"flex":"none",height:"100%",overflow:"auto",flexDirection:"column"},"data-window-type":e.type,children:i});function Ge(e){let t=e;for(;t;){const i=[...t.classList].find(r=>r.startsWith("rw-theme-"));if(i)return i;t=t.parentElement}return""}const Qe=({items:e,trigger:t,className:i})=>{const[r,m]=o.useState(!1),p=o.useRef(null),W=o.useRef(null),[g,f]=o.useState(null),[v,X]=o.useState(""),z=o.useCallback(()=>{const N=p.current?.querySelector(".rw-dropdown-trigger"),O=W.current;if(!N||!O)return;const D=N.getBoundingClientRect(),b=O.offsetWidth,R=O.offsetHeight,C=4,L=8;let x=D.bottom+C;x+R>window.innerHeight-L&&D.top-C-R>L&&(x=D.top-C-R);let w=D.right-b;w<L&&(w=L),w+b>window.innerWidth-L&&(w=Math.max(L,window.innerWidth-L-b)),f({top:x,left:w})},[]);return o.useLayoutEffect(()=>{if(!r){f(null);return}return X(Ge(p.current)),z(),window.addEventListener("resize",z),window.addEventListener("scroll",z,!0),()=>{window.removeEventListener("resize",z),window.removeEventListener("scroll",z,!0)}},[r,z,e.length]),o.useEffect(()=>{if(!r)return;const N=D=>{const b=D.target;p.current?.contains(b)||W.current?.contains(b)||m(!1)},O=D=>{D.key==="Escape"&&m(!1)};return document.addEventListener("mousedown",N),document.addEventListener("keydown",O),()=>{document.removeEventListener("mousedown",N),document.removeEventListener("keydown",O)}},[r]),n.jsxs("div",{className:`rw-dropdown ${i||""}`,ref:p,children:[n.jsx("div",{className:"rw-dropdown-trigger",onClick:()=>m(N=>!N),role:"button",tabIndex:0,children:t}),r&&ye.createPortal(n.jsx("div",{ref:W,className:`rw-dropdown-menu ${v}`,style:g?{top:g.top,left:g.left}:{visibility:"hidden",top:0,left:0},children:e.map(N=>N.divider?n.jsx("div",{className:"rw-dropdown-divider"},N.key):n.jsx("button",{type:"button",className:"rw-dropdown-item",disabled:N.disabled,onClick:()=>{N.onClick?.(),m(!1)},children:N.label},N.key))}),document.body)]})},ze=({windows:e,activeWindowId:t,onSwitchWindow:i,onCloseWindow:r,onToggleMinimize:m,onBatchManage:p,onFloatWindow:W,onRestoreWindow:g,onReorderWindows:f,embedded:v=!1,themeClassName:X,allWindows:z=e})=>{const N=e.findIndex(a=>a.id===t),O=o.useRef(null),D=o.useRef(null),[b,R]=o.useState(null),[C,L]=o.useState(null),x=o.useRef({windowId:"",startX:0,startY:0,fromIndex:-1,mode:"none",floated:!1}),w=o.useCallback(a=>{const y=D.current;if(!y)return e.length;const k=y.getBoundingClientRect(),S=a-k.left,I=y.querySelectorAll(".rw-tab-item");if(S<8)return 0;for(let $=0;$<I.length;$++){const j=I[$].getBoundingClientRect(),T=j.left-k.left+j.width/2;if(S<T)return $}return I.length},[e.length]),Z=o.useCallback((a,y,k)=>{if(a.target.closest(".rw-window-tab-close-btn")||a.button!==0)return;x.current={windowId:y,startX:a.clientX,startY:a.clientY,fromIndex:k,mode:"none",floated:!1};const S=j=>{const T=j.clientX-x.current.startX,P=j.clientY-x.current.startY,F=Math.sqrt(T*T+P*P);F<8||(x.current.mode==="none"&&(Math.abs(P)>40&&F>50?x.current.mode="float":Math.abs(T)>12&&Math.abs(T)>Math.abs(P)?x.current.mode="reorder":F>50&&(x.current.mode="float")),x.current.mode==="float"&&x.current.windowId===y?x.current.floated||(x.current.floated=!0,W?.(y,{x:j.clientX,y:j.clientY})):x.current.mode==="reorder"&&R(w(j.clientX)))},I=j=>{if(x.current.mode==="reorder"&&x.current.windowId===y){let P=w(j.clientX);P>x.current.fromIndex&&(P-=1),P!==x.current.fromIndex&&f&&f(x.current.fromIndex,P)}R(null),$()},$=()=>{document.removeEventListener("mousemove",S),document.removeEventListener("mouseup",I),x.current={windowId:"",startX:0,startY:0,fromIndex:-1,mode:"none",floated:!1}};document.addEventListener("mousemove",S),document.addEventListener("mouseup",I)},[W,f,w]);o.useEffect(()=>{if(!t)return;const a=D.current;if(!a)return;const y=e.findIndex(S=>S.id===t);if(y<0)return;a.querySelectorAll(".rw-tab-item")[y]?.scrollIntoView({block:"nearest",inline:"nearest",behavior:"smooth"})},[t,e.length]),o.useEffect(()=>{let a=null;const y=I=>{const{windowTitle:$,clientX:j}=I.detail,T=w(j);a&&cancelAnimationFrame(a),a=requestAnimationFrame(()=>{L({title:$,index:T}),R(T)})},k=()=>{L(null),R(null)},S=O.current;return S?.addEventListener("floatingWindowDragOver",y),S?.addEventListener("clearFloatingWindowPreview",k),()=>{S?.removeEventListener("floatingWindowDragOver",y),S?.removeEventListener("clearFloatingWindowPreview",k),a&&cancelAnimationFrame(a)}},[w]);const H=()=>{const a=e.map((y,k)=>n.jsxs("div",{className:`rw-tab-item ${y.id===t?"active":""}`,onClick:()=>i(y.id),onMouseDown:S=>Z(S,y.id,k),children:[n.jsx("span",{className:"rw-tab-title",children:y.title}),n.jsx("button",{type:"button",title:"关闭",className:"rw-icon-btn rw-window-tab-close-btn",onClick:S=>{S.stopPropagation(),r(y.id)},children:n.jsx(We,{size:12})})]},y.id));if(C&&b!==null){const y=Math.max(0,Math.min(b,a.length));a.splice(y,0,n.jsx("div",{className:"rw-tab-preview",children:C.title},"rw-preview"))}return a},E=a=>{a.preventDefault();try{const y=sessionStorage.getItem("draggingWindowTitle");y&&L({title:y,index:w(a.clientX)})}catch{}R(w(a.clientX))},h=a=>{a.preventDefault();let y=a.dataTransfer.getData("windowId")||"";if(!y)try{y=sessionStorage.getItem("draggingWindowId")||""}catch{}y&&g&&g(y,b??void 0),L(null),R(null)},_=[...z.length===0?[]:[...z.map(a=>({key:`win-${a.id}`,label:n.jsxs("span",{className:"rw-dropdown-window",children:[n.jsx("span",{className:`rw-dropdown-dot ${a.id===t?"active":""}`}),n.jsx("span",{className:"rw-dropdown-window-title",children:a.title}),a.minimized&&n.jsx("span",{className:"rw-dropdown-tag",children:"已最小化"}),a.floating&&!a.minimized&&n.jsx("span",{className:"rw-dropdown-tag",children:"浮动"})]}),onClick:()=>{a.minimized&&g?.(a.id),i(a.id)}})),{key:"d0",label:"",divider:!0}],{key:"close-others",label:"关闭其他",disabled:e.length<=1,onClick:()=>p("close-others")},{key:"close-left",label:"关闭左侧",disabled:N<=0,onClick:()=>p("close-left")},{key:"close-right",label:"关闭右侧",disabled:N<0||N>=e.length-1,onClick:()=>p("close-right")},{key:"d1",label:"",divider:!0},{key:"close-all",label:"关闭全部",disabled:!e.length,onClick:()=>p("close-all")},{key:"d2",label:"",divider:!0},{key:"minimize-all",label:"最小化全部",disabled:!e.length,onClick:()=>p("minimize-all")},{key:"restore-all",label:"还原全部",disabled:!z.some(a=>a.minimized),onClick:()=>p("restore-all")},{key:"d3",label:"",divider:!0},{key:"reset",label:"重置窗口",onClick:()=>p("reset-windows")}];return n.jsx("div",{className:`rw-window-tabs ${v?"rw-tabs-embedded":""} ${X||""}`,ref:O,onDragOver:E,onDragLeave:()=>{L(null),R(null)},onDrop:h,children:n.jsxs("div",{className:"rw-window-tabs-container",children:[n.jsx("div",{className:"rw-tab-list",ref:D,children:H()}),b!==null&&!C&&n.jsx(et,{listRef:D,index:b}),e.length>0&&n.jsx(Qe,{items:_,trigger:n.jsx("button",{type:"button",className:"rw-icon-btn rw-window-tabs-batch-btn",title:"批量管理",children:n.jsx(Ye,{})})})]})})},et=({listRef:e,index:t})=>{const[i,r]=o.useState(0);return o.useEffect(()=>{const m=()=>{const p=e.current;if(!p)return;p.getBoundingClientRect();const W=p.querySelectorAll(".rw-tab-item:not(.rw-tab-preview)");if(t===0){r(8);return}if(t>=W.length){const f=W[W.length-1];r(f.offsetLeft+f.offsetWidth+2);return}const g=W[t];r(g.offsetLeft-1)};return m(),window.addEventListener("resize",m),()=>window.removeEventListener("resize",m)},[e,t]),n.jsx("div",{className:"rw-window-tab-insert-indicator",style:{left:`${i}px`}})},tt={x:100,y:100,width:800,height:600,minWidth:400,minHeight:300},Ie=({window:e,children:t,floatingDefaults:i,onUpdateFloatingPosition:r,onRestoreWindow:m,onCloseWindow:p,onToggleMinimize:W,onFocusWindow:g})=>{const f={...tt,...i},v=o.useRef(null),X=o.useRef(null),[z,N]=o.useState(!1),[O,D]=o.useState(!1),[b,R]=o.useState(!1),C=o.useRef(!1),L=o.useRef(""),x=o.useRef({x:0,y:0,startX:0,startY:0,startWidth:0,startHeight:0}),w=o.useRef({x:0,y:0,width:0,height:0,startX:0,startY:0}),Z=o.useRef(null),H=o.useRef(null),E=o.useRef(null),h=e.floatingPosition||{x:f.x,y:f.y,width:f.width,height:f.height};o.useEffect(()=>{if(!e.pendingDragStart||z||O)return;let a=h.x,y=h.y;if(v.current){const k=v.current.getBoundingClientRect();a=k.left,y=k.top}g?.(e.id),E.current={windowId:e.id,windowTitle:e.title};try{sessionStorage.setItem("draggingWindowId",e.id),sessionStorage.setItem("draggingWindowTitle",e.title)}catch{}N(!0),x.current={x:e.pendingDragStart.x-a,y:e.pendingDragStart.y-y,startX:a,startY:y,startWidth:h.width,startHeight:h.height}},[e.pendingDragStart,e.id,e.title,z,O,h,g]),o.useEffect(()=>{if(z||O||e.pendingDragStart)return;const a={minWidth:f.minWidth,minHeight:f.minHeight},y=Q(h,a);(y.x!==h.x||y.y!==h.y||y.width!==h.width||y.height!==h.height)&&r(e.id,y)},[e.id,e.pendingDragStart]),o.useEffect(()=>{if(!v.current||z||O)return;const a=v.current;a.style.transform=`translate(${h.x}px, ${h.y}px)`,a.style.width=`${h.width}px`,a.style.height=`${h.height}px`},[h.x,h.y,h.width,h.height,z,O]);const q=o.useCallback(a=>{const y=a.target;if(y.closest(".rw-floating-window-action-btn")||y.closest(".rw-floating-window-resize-handle")||!X.current?.contains(y))return;g?.(e.id);let k=h.x,S=h.y;if(v.current){const I=v.current.getBoundingClientRect();k=I.left,S=I.top}E.current={windowId:e.id,windowTitle:e.title};try{sessionStorage.setItem("draggingWindowId",e.id),sessionStorage.setItem("draggingWindowTitle",e.title)}catch{}N(!0),x.current={x:a.clientX-k,y:a.clientY-S,startX:k,startY:S,startWidth:h.width,startHeight:h.height}},[h,e.id,e.title,g]),_=o.useCallback((a,y)=>{a.stopPropagation(),a.preventDefault(),g?.(e.id);let k=h.x,S=h.y,I=h.width,$=h.height;if(v.current){const j=v.current.getBoundingClientRect();k=j.left,S=j.top,I=j.width,$=j.height}D(!0),L.current=y,w.current={x:a.clientX,y:a.clientY,width:I,height:$,startX:k,startY:S}},[h,e.id,g]);return o.useEffect(()=>{const a=k=>{if(z){k.preventDefault();const S=document.querySelector(".rw-window-tabs");if(S&&E.current){const P=S.getBoundingClientRect(),F=k.clientY>=P.top&&k.clientY<=P.bottom&&k.clientX>=P.left&&k.clientX<=P.right,V=C.current;R(F),C.current=F,F?S.dispatchEvent(new CustomEvent("floatingWindowDragOver",{detail:{...E.current,clientX:k.clientX,clientY:k.clientY}})):V&&S.dispatchEvent(new CustomEvent("clearFloatingWindowPreview"))}const I=x.current.startWidth,$=x.current.startHeight,j=Math.max(0,Math.min(k.clientX-x.current.x,globalThis.window.innerWidth-I)),T=Math.max(0,Math.min(k.clientY-x.current.y,globalThis.window.innerHeight-$));v.current.style.transform=`translate(${j}px, ${T}px)`,H.current={x:j,y:T,width:x.current.startWidth,height:x.current.startHeight}}else if(O){k.preventDefault();const S=L.current,I=w.current;let $=I.startX,j=I.startY,T=I.width,P=I.height;const F=k.clientX-I.x,V=k.clientY-I.y;S.includes("e")&&(T=Math.max(f.minWidth,I.width+F)),S.includes("w")&&(T=Math.max(f.minWidth,I.width-F),$=I.startX+I.width-T),S.includes("s")&&(P=Math.max(f.minHeight,I.height+V)),S.includes("n")&&(P=Math.max(f.minHeight,I.height-V),j=I.startY+I.height-P);const J=v.current;J.style.transform=`translate(${$}px, ${j}px)`,J.style.width=`${T}px`,J.style.height=`${P}px`,H.current={x:$,y:j,width:T,height:P}}},y=k=>{if(k&&E.current){const I=document.querySelector(".rw-window-tabs");if(I){const $=I.getBoundingClientRect();if(k.clientY>=$.top&&k.clientY<=$.bottom&&k.clientX>=$.left&&k.clientX<=$.right){const j=I.querySelector(".rw-tab-list");if(j){let T=j.querySelectorAll(".rw-tab-item").length;const P=j.getBoundingClientRect(),F=k.clientX-P.left;j.querySelectorAll(".rw-tab-item").forEach((V,J)=>{const ee=V.getBoundingClientRect();F<ee.left-P.left+ee.width/2&&(T=Math.min(T,J))}),m(E.current.windowId,T),E.current=null,N(!1),D(!1),R(!1);return}}}}let S=H.current;S&&(S=Q(S,{minWidth:f.minWidth,minHeight:f.minHeight})),S&&r(e.id,S),H.current=null,E.current=null;try{sessionStorage.removeItem("draggingWindowId"),sessionStorage.removeItem("draggingWindowTitle")}catch{}N(!1),D(!1),R(!1),C.current=!1};if(z||O){const k=S=>{Z.current&&cancelAnimationFrame(Z.current),Z.current=requestAnimationFrame(()=>a(S))};return document.addEventListener("mousemove",k,{passive:!1}),document.addEventListener("mouseup",y),document.body.style.userSelect="none",()=>{document.removeEventListener("mousemove",k),document.removeEventListener("mouseup",y),document.body.style.userSelect=""}}},[z,O,e.id,f.minWidth,f.minHeight,r,m]),n.jsxs("div",{ref:v,className:"rw-floating-window",style:{transform:`translate(${h.x}px, ${h.y}px)`,width:h.width,height:h.height,zIndex:e.floatingZIndex||1e3,opacity:b?.5:1,minWidth:f.minWidth,minHeight:f.minHeight},onClick:a=>{a.target.closest("button, a, input, select, textarea")||g?.(e.id)},children:[n.jsxs("div",{ref:X,className:"rw-floating-window-header",onMouseDown:q,onDoubleClick:()=>m(e.id),children:[n.jsx("div",{className:"rw-floating-window-title",children:e.title}),n.jsxs("div",{className:"rw-floating-window-actions",children:[n.jsx("button",{type:"button",title:"放回",className:"rw-icon-btn rw-floating-window-action-btn",onClick:()=>m(e.id),children:n.jsx(Fe,{size:12})}),n.jsx("button",{type:"button",title:"最小化",className:"rw-icon-btn rw-floating-window-action-btn",onClick:()=>W(e.id),children:n.jsx(Xe,{size:12})}),n.jsx("button",{type:"button",title:"关闭",className:"rw-icon-btn rw-floating-window-action-btn",onClick:()=>p(e.id),children:n.jsx(We,{size:12})})]})]}),n.jsx("div",{className:"rw-floating-window-content",children:t}),["nw","ne","sw","se","n","s","w","e"].map(a=>n.jsx("div",{className:`rw-floating-window-resize-handle rw-floating-window-resize-${a}`,onMouseDown:y=>_(y,a)},a))]})},Ne=({windows:e,activeWindowId:t,renderWindow:i,onSwitchWindow:r,onCloseWindow:m,onToggleMinimize:p,onBatchManage:W,onFloatWindow:g,onRestoreWindow:f,onUpdateFloatingPosition:v,onFocusWindow:X,onReorderWindows:z,emptyDescription:N="从左侧菜单选择功能开始工作",floatingDefaults:O,tabsContainer:D,themeClassName:b})=>{if(e.length===0)return n.jsx("div",{className:"rw-window-manager-empty",children:n.jsx(Je,{description:N})});const R=e.filter(w=>w.minimized),C=e.filter(w=>w.floating&&!w.minimized),L=e.filter(w=>!w.minimized&&!w.floating),x=n.jsx(ze,{windows:L,activeWindowId:t,onSwitchWindow:r,onCloseWindow:m,onToggleMinimize:p,onBatchManage:W,onFloatWindow:g,onRestoreWindow:f,onReorderWindows:z,allWindows:e,embedded:!!D,themeClassName:b});return n.jsxs("div",{className:"rw-window-manager",children:[D?ye.createPortal(x,D):x,n.jsx("div",{className:"rw-window-content-area",children:L.map(w=>n.jsx(je,{window:w,active:w.id===t,children:i(w,{})},w.id))}),R.length>0&&n.jsx("div",{className:"rw-minimized-windows-bar",children:R.map(w=>n.jsxs("div",{className:"rw-minimized-window-item",onClick:()=>p(w.id),title:w.floating?`${w.title} (浮动窗口)`:w.title,role:"button",tabIndex:0,onKeyDown:Z=>Z.key==="Enter"&&p(w.id),children:[n.jsx("span",{children:w.title}),w.floating&&n.jsx("span",{className:"rw-minimized-floating-badge",children:"🔲"})]},w.id))}),C.map(w=>n.jsx(Ie,{window:w,floatingDefaults:O,onUpdateFloatingPosition:v||(()=>{}),onRestoreWindow:f||(()=>{}),onCloseWindow:m,onToggleMinimize:p,onFocusWindow:X,children:i(w,{})},w.id))]})};function nt(e){return"type"in e&&e.type==="divider"}function ge(e){for(const t of e){if(nt(t))continue;const i=t;if(i.windowType)return i;if(i.children){const r=ge(i.children);if(r)return r}}return null}function Me(e,t){if(t)return{minimized:!1,...t};const i=ge(e);if(!i?.windowType)return{type:"home",title:"首页",minimized:!1};const r=me(i.label)||i.key;return{type:i.windowType,title:r,minimized:!1}}function Te(e,t){const{fallback:i}=t??{};return(r,m)=>{const p=e[r.type]??i;return p?o.createElement(p,{window:r,ctx:m}):null}}const it={colorPrimary:"--rw-color-primary",colorPrimaryHover:"--rw-color-primary-hover",colorPrimaryBg:"--rw-color-primary-bg",colorBg:"--rw-color-bg",colorBgSecondary:"--rw-color-bg-secondary",colorBgTertiary:"--rw-color-bg-tertiary",colorBgHover:"--rw-color-bg-hover",colorBgActive:"--rw-color-bg-active",colorBorder:"--rw-color-border",colorBorderStrong:"--rw-color-border-strong",colorText:"--rw-color-text",colorTextSecondary:"--rw-color-text-secondary",colorTextMuted:"--rw-color-text-muted",sidebarWidth:"--rw-sidebar-width",tabHeight:"--rw-tab-height",radius:"--rw-radius",fontSize:"--rw-font-size"};function he(e){const t={};return Object.keys(e).forEach(i=>{const r=e[i];if(r!==void 0){const m=it[i];t[m]=typeof r=="number"?`${r}px`:r}}),t}function Ee(e){return{colorPrimary:e.colorPrimary,colorPrimaryHover:e.colorPrimaryHover,colorPrimaryBg:e.colorPrimaryBg,colorBg:e.colorBgContainer,colorBgSecondary:e.colorFillAlter??e.colorBgContainer,colorBgTertiary:e.colorBgLayout,colorBgHover:e.colorBgTextHover,colorBgActive:e.colorPrimaryBg,colorBorder:e.colorBorder,colorBorderStrong:e.colorBorderSecondary??e.colorBorder,colorText:e.colorText,colorTextSecondary:e.colorTextSecondary,colorTextMuted:e.colorTextTertiary,radius:e.borderRadius,fontSize:e.fontSize}}function rt(e){return he(Ee(e))}const ot=o.forwardRef(function({workspaceId:t="default",menuItems:i,renderWindow:r,windows:m,sidebarHeader:p,sidebarFooter:W,defaultWindow:g,loading:f=!1,loadingTip:v="加载中...",onAction:X,activeWindowType:z,emptyDescription:N,syncToUrl:O=!1,preserveUrlParams:D=!0,searchParams:b,setSearchParams:R,floatingDefaults:C,onWindowsChange:L,resolveTitle:x,onReady:w,siderWidth:Z=240,contentBackground:H,themeClassName:E,theme:h,renderSidebar:q,tabsContainer:_,className:a,style:y},k){const S=o.useMemo(()=>Me(i,g),[i,g]),I=o.useMemo(()=>{if(r)return r;if(m)return Te(m);throw new Error("[react-workspace] 请提供 renderWindow 或 windows")},[r,m]),$=be({workspaceId:t,defaultWindow:S,syncToUrl:O,preserveUrlParams:D,searchParams:b,setSearchParams:R,floatingDefaults:C,onWindowsChange:L,resolveTitle:(U,ie)=>x?.(U,ie)??de(i,U)}),{windows:j,activeWindowId:T,openWindow:P,switchWindow:F,closeWindow:V,toggleMinimize:J,floatWindow:ee,restoreWindow:le,updateFloatingPosition:s,focusWindow:l,batchManage:c,updateWindowProps:u,clearPendingAction:d,reorderWindows:M}=$,B={workspaceId:t,...$};o.useImperativeHandle(k,()=>B,[t,j,T]),o.useEffect(()=>{w&&j.length>0&&w({workspaceId:t,...$})},[w,t,j.length]);const Y=o.useMemo(()=>z!==void 0?z:j.find(U=>U.id===T)?.type,[z,j,T]),K=o.useCallback((U,ie)=>{P({type:U,title:de(i,U),minimized:!1},ie)},[P,i]),A=o.useCallback((U,ie)=>({workspaceId:t,active:ie,activeWindowId:T,windows:j,openWindow:P,switchWindow:F,closeWindow:V,toggleMinimize:J,floatWindow:ee,updateWindowProps:(De,Le)=>u(De,Le),clearPendingAction:d}),[t,T,j,P,F,V,J,ee,u,d]),G=o.useMemo(()=>({...B,buildRenderContext:A}),[t,j,T,A]),Re=H??"var(--rw-color-bg-tertiary)",Pe={display:"flex",...h?he(h):void 0,...y},pe={menuItems:i,onMenuClick:K,onAction:X,activeWindowType:Y,header:p,footer:W,defaultOpenKeys:Se(i),siderWidth:Z};return n.jsx(ve,{value:G,children:n.jsxs("div",{className:`rw-workspace ${E||""} ${a||""}`.trim(),style:Pe,children:[q?q(pe):n.jsx(Ce,{...pe}),n.jsx("main",{className:"rw-workspace-main",style:{background:Re},children:n.jsx($e,{spinning:f,tip:v,children:n.jsx(Ne,{workspaceId:t,windows:j,activeWindowId:T,renderWindow:U=>I(U,A(U,U.id===T&&!U.floating)),onSwitchWindow:F,onCloseWindow:V,onToggleMinimize:J,onBatchManage:c,onOpenWindow:P,onFloatWindow:ee,onRestoreWindow:le,onUpdateFloatingPosition:s,onFocusWindow:l,onReorderWindows:M,emptyDescription:N,tabsContainer:_,themeClassName:E,floatingDefaults:C})})})]})})});exports.FloatingWindow=Ie;exports.WindowContainer=je;exports.WindowManager=Ne;exports.WindowTabs=ze;exports.Workspace=ot;exports.WorkspaceProvider=ve;exports.WorkspaceSidebar=Ce;exports.collectParentMenuKeys=Se;exports.createWindowRenderer=Te;exports.findFirstMenuItemWithWindowType=ge;exports.findMenuItem=ke;exports.findMenuKeyByWindowType=ue;exports.fixWindowPosition=Q;exports.getAllWindowStatesFromStorage=ne;exports.labelToString=me;exports.mapAntdTokenToCssVars=rt;exports.mapAntdTokenToWorkspaceTheme=Ee;exports.pickNextActiveWindowId=ae;exports.resolveDefaultWindow=Me;exports.resolveWindowTitle=de;exports.saveWindowStateToStorage=re;exports.themeToCssVars=he;exports.updateTabClickOrder=oe;exports.useWorkspace=be;exports.useWorkspaceContext=Ze;exports.useWorkspaceContextOptional=He;