@liuman/react-workspace 1.3.1 → 1.3.2

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