@liuman/react-workspace 1.3.4 → 1.3.5

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