@liuman/react-workspace 1.4.3 → 1.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
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;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),m=require("react"),a=require("antd"),f=require("@ant-design/icons"),c=require("./Workspace-CGO5Pkso.cjs"),{Sider:v}=a.Layout;function w(n){return"type"in n&&n.type==="divider"}function T(n){return n.map((r,t)=>{if(w(r))return{type:"divider",key:r.key??`d-${t}`};const e=r;return{key:e.key,icon:e.icon,label:e.label,disabled:e.disabled,children:e.children?T(e.children):void 0}})}function b(n,r){for(const t of n){if(w(t))continue;const e=t;if(e.key===r)return e;if(e.children){const i=b(e.children,r);if(i)return i}}return null}const y=({menuItems:n,onMenuClick:r,onAction:t,activeWindowType:e,header:i,footer:l,defaultOpenKeys:p=[],siderWidth:h=240,theme:k="light"})=>{const[o,j]=m.useState(!1),x=m.useMemo(()=>{if(!e)return[];const u=c.findMenuKeyByWindowType(n,e);return u?[u]:[]},[e,n]),A=({key:u})=>{const d=b(n,u);!d||d.disabled||(d.windowType?r(d.windowType,d.props):d.action&&t&&t(d.action))};return s.jsxs("div",{className:"rw-workspace-sidebar-wrapper rw-antd-sidebar",children:[s.jsxs(v,{width:h,collapsed:o,collapsedWidth:64,theme:k,className:"rw-antd-sider",children:[i&&s.jsx("div",{className:`rw-workspace-sidebar-header ${o?"collapsed":""}`,children:i}),s.jsx("div",{className:"rw-antd-menu-wrap",children:s.jsx(a.Menu,{mode:"inline",theme:k,selectedKeys:x,defaultOpenKeys:p,items:T(n),onClick:A,inlineCollapsed:o})}),l&&s.jsx("div",{className:`rw-workspace-sidebar-footer ${o?"collapsed":""}`,children:l})]}),s.jsx("button",{type:"button",className:"rw-workspace-collapse-button",style:{left:o?64:h},onClick:()=>j(!o),title:o?"展开":"折叠",children:o?s.jsx(f.MenuUnfoldOutlined,{}):s.jsx(f.MenuFoldOutlined,{})})]})};function W({dark:n=!1,sidebarTheme:r,...t}){const{token:e}=a.theme.useToken(),i=m.useMemo(()=>c.mapAntdTokenToWorkspaceTheme(e),[e]),l=r??(n?"dark":"light");return s.jsx(c.Workspace,{...t,theme:i,themeClassName:n?"rw-theme-dark":void 0,renderSidebar:p=>s.jsx(y,{...p,theme:l})})}const g=({dark:n=!1,sidebarTheme:r,antdTheme:t,...e})=>s.jsx(a.ConfigProvider,{theme:{algorithm:n?a.theme.darkAlgorithm:a.theme.defaultAlgorithm,...t},children:s.jsx(W,{dark:n,sidebarTheme:r,...e})});exports.mapAntdTokenToCssVars=c.mapAntdTokenToCssVars;exports.mapAntdTokenToWorkspaceTheme=c.mapAntdTokenToWorkspaceTheme;exports.AntdWorkspace=g;exports.AntdWorkspaceSidebar=y;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),m=require("react"),a=require("antd"),f=require("@ant-design/icons"),c=require("./Workspace-LroLpOVn.cjs"),{Sider:v}=a.Layout;function w(n){return"type"in n&&n.type==="divider"}function T(n){return n.map((r,t)=>{if(w(r))return{type:"divider",key:r.key??`d-${t}`};const e=r;return{key:e.key,icon:e.icon,label:e.label,disabled:e.disabled,children:e.children?T(e.children):void 0}})}function b(n,r){for(const t of n){if(w(t))continue;const e=t;if(e.key===r)return e;if(e.children){const i=b(e.children,r);if(i)return i}}return null}const y=({menuItems:n,onMenuClick:r,onAction:t,activeWindowType:e,header:i,footer:l,defaultOpenKeys:p=[],siderWidth:h=240,theme:k="light"})=>{const[o,j]=m.useState(!1),x=m.useMemo(()=>{if(!e)return[];const u=c.findMenuKeyByWindowType(n,e);return u?[u]:[]},[e,n]),A=({key:u})=>{const d=b(n,u);!d||d.disabled||(d.windowType?r(d.windowType,d.props):d.action&&t&&t(d.action))};return s.jsxs("div",{className:"rw-workspace-sidebar-wrapper rw-antd-sidebar",children:[s.jsxs(v,{width:h,collapsed:o,collapsedWidth:64,theme:k,className:"rw-antd-sider",children:[i&&s.jsx("div",{className:`rw-workspace-sidebar-header ${o?"collapsed":""}`,children:i}),s.jsx("div",{className:"rw-antd-menu-wrap",children:s.jsx(a.Menu,{mode:"inline",theme:k,selectedKeys:x,defaultOpenKeys:p,items:T(n),onClick:A,inlineCollapsed:o})}),l&&s.jsx("div",{className:`rw-workspace-sidebar-footer ${o?"collapsed":""}`,children:l})]}),s.jsx("button",{type:"button",className:"rw-workspace-collapse-button",style:{left:o?64:h},onClick:()=>j(!o),title:o?"展开":"折叠",children:o?s.jsx(f.MenuUnfoldOutlined,{}):s.jsx(f.MenuFoldOutlined,{})})]})};function W({dark:n=!1,sidebarTheme:r,...t}){const{token:e}=a.theme.useToken(),i=m.useMemo(()=>c.mapAntdTokenToWorkspaceTheme(e),[e]),l=r??(n?"dark":"light");return s.jsx(c.Workspace,{...t,theme:i,themeClassName:n?"rw-theme-dark":void 0,renderSidebar:p=>s.jsx(y,{...p,theme:l})})}const g=({dark:n=!1,sidebarTheme:r,antdTheme:t,...e})=>s.jsx(a.ConfigProvider,{theme:{algorithm:n?a.theme.darkAlgorithm:a.theme.defaultAlgorithm,...t},children:s.jsx(W,{dark:n,sidebarTheme:r,...e})});exports.mapAntdTokenToCssVars=c.mapAntdTokenToCssVars;exports.mapAntdTokenToWorkspaceTheme=c.mapAntdTokenToWorkspaceTheme;exports.AntdWorkspace=g;exports.AntdWorkspaceSidebar=y;
@@ -2,8 +2,8 @@ import { jsxs as u, jsx as t } from "react/jsx-runtime";
2
2
  import { useState as C, useMemo as h } from "react";
3
3
  import { Layout as N, Menu as g, ConfigProvider as A, theme as p } from "antd";
4
4
  import { MenuUnfoldOutlined as M, MenuFoldOutlined as x } from "@ant-design/icons";
5
- import { j as S, o as W, c as j } from "./Workspace-CvNGfg2U.js";
6
- import { n as z } from "./Workspace-CvNGfg2U.js";
5
+ import { j as S, o as W, c as j } from "./Workspace-BJJGfZO9.js";
6
+ import { n as z } from "./Workspace-BJJGfZO9.js";
7
7
  const { Sider: $ } = N;
8
8
  function k(r) {
9
9
  return "type" in r && r.type === "divider";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./Workspace-CGO5Pkso.cjs");exports.FloatingWindow=e.FloatingWindow;exports.WindowContainer=e.WindowContainer;exports.WindowManager=e.WindowManager;exports.WindowTabs=e.WindowTabs;exports.Workspace=e.Workspace;exports.WorkspaceDefault=e.Workspace;exports.WorkspaceProvider=e.WorkspaceProvider;exports.WorkspaceSidebar=e.WorkspaceSidebar;exports.collectParentMenuKeys=e.collectParentMenuKeys;exports.createWindowRenderer=e.createWindowRenderer;exports.findFirstMenuItemWithWindowType=e.findFirstMenuItemWithWindowType;exports.findMenuItem=e.findMenuItem;exports.findMenuKeyByWindowType=e.findMenuKeyByWindowType;exports.fixWindowPosition=e.fixWindowPosition;exports.getAllWindowStatesFromStorage=e.getAllWindowStatesFromStorage;exports.labelToString=e.labelToString;exports.mapAntdTokenToCssVars=e.mapAntdTokenToCssVars;exports.mapAntdTokenToWorkspaceTheme=e.mapAntdTokenToWorkspaceTheme;exports.pickNextActiveWindowId=e.pickNextActiveWindowId;exports.resolveDefaultWindow=e.resolveDefaultWindow;exports.resolveWindowTitle=e.resolveWindowTitle;exports.saveWindowStateToStorage=e.saveWindowStateToStorage;exports.themeToCssVars=e.themeToCssVars;exports.updateTabClickOrder=e.updateTabClickOrder;exports.useWorkspace=e.useWorkspace;exports.useWorkspaceContext=e.useWorkspaceContext;exports.useWorkspaceContextOptional=e.useWorkspaceContextOptional;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./Workspace-LroLpOVn.cjs");exports.FloatingWindow=e.FloatingWindow;exports.WindowContainer=e.WindowContainer;exports.WindowManager=e.WindowManager;exports.WindowTabs=e.WindowTabs;exports.Workspace=e.Workspace;exports.WorkspaceDefault=e.Workspace;exports.WorkspaceProvider=e.WorkspaceProvider;exports.WorkspaceSidebar=e.WorkspaceSidebar;exports.collectParentMenuKeys=e.collectParentMenuKeys;exports.createWindowRenderer=e.createWindowRenderer;exports.findFirstMenuItemWithWindowType=e.findFirstMenuItemWithWindowType;exports.findMenuItem=e.findMenuItem;exports.findMenuKeyByWindowType=e.findMenuKeyByWindowType;exports.fixWindowPosition=e.fixWindowPosition;exports.getAllWindowStatesFromStorage=e.getAllWindowStatesFromStorage;exports.labelToString=e.labelToString;exports.mapAntdTokenToCssVars=e.mapAntdTokenToCssVars;exports.mapAntdTokenToWorkspaceTheme=e.mapAntdTokenToWorkspaceTheme;exports.pickNextActiveWindowId=e.pickNextActiveWindowId;exports.resolveDefaultWindow=e.resolveDefaultWindow;exports.resolveWindowTitle=e.resolveWindowTitle;exports.saveWindowStateToStorage=e.saveWindowStateToStorage;exports.themeToCssVars=e.themeToCssVars;exports.updateTabClickOrder=e.updateTabClickOrder;exports.useWorkspace=e.useWorkspace;exports.useWorkspaceContext=e.useWorkspaceContext;exports.useWorkspaceContextOptional=e.useWorkspaceContextOptional;
@@ -1 +1 @@
1
- .rw-workspace,.rw-floating-window,.rw-window-tabs{--rw-color-primary: #2563eb;--rw-color-primary-hover: #3b82f6;--rw-color-primary-bg: #eff6ff;--rw-color-primary-border: #93c5fd;--rw-color-bg: #ffffff;--rw-color-bg-secondary: #f8fafc;--rw-color-bg-tertiary: #f1f5f9;--rw-color-bg-hover: rgba(15, 23, 42, .045);--rw-color-bg-active: #eff6ff;--rw-color-border: #e8ecf1;--rw-color-border-strong: #cbd5e1;--rw-color-text: #0f172a;--rw-color-text-secondary: #475569;--rw-color-text-muted: #94a3b8;--rw-color-shadow: rgba(15, 23, 42, .16);--rw-color-shadow-light: rgba(15, 23, 42, .06);--rw-shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 1px rgba(15, 23, 42, .04);--rw-shadow-md: 0 2px 8px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .06);--rw-shadow-lg: 0 12px 32px rgba(15, 23, 42, .16), 0 2px 8px rgba(15, 23, 42, .08);--rw-sidebar-width: 240px;--rw-sidebar-collapsed-width: 64px;--rw-sidebar-header-bg: var(--rw-color-bg);--rw-tab-height: 40px;--rw-tab-bg: transparent;--rw-tab-bg-active: var(--rw-color-bg);--rw-tab-radius: 8px;--rw-floating-min-width: 400px;--rw-floating-min-height: 300px;--rw-floating-z-index: 1000;--rw-font-size: 14px;--rw-font-size-sm: 12px;--rw-radius: 6px;--rw-radius-lg: 10px;--rw-transition: .16s cubic-bezier(.4, 0, .2, 1)}.rw-workspace.rw-theme-dark,.rw-floating-window.rw-theme-dark,.rw-window-tabs.rw-theme-dark{--rw-color-primary: #60a5fa;--rw-color-primary-hover: #93c5fd;--rw-color-primary-bg: rgba(96, 165, 250, .16);--rw-color-primary-border: rgba(96, 165, 250, .5);--rw-color-bg: #1a1d23;--rw-color-bg-secondary: #15181d;--rw-color-bg-tertiary: #0f1115;--rw-color-bg-hover: rgba(255, 255, 255, .06);--rw-color-bg-active: rgba(96, 165, 250, .14);--rw-color-border: #2a2f37;--rw-color-border-strong: #3d444e;--rw-color-text: rgba(255, 255, 255, .92);--rw-color-text-secondary: rgba(255, 255, 255, .66);--rw-color-text-muted: rgba(255, 255, 255, .42);--rw-color-shadow: rgba(0, 0, 0, .5);--rw-color-shadow-light: rgba(0, 0, 0, .3);--rw-shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);--rw-shadow-md: 0 2px 8px rgba(0, 0, 0, .36);--rw-shadow-lg: 0 12px 32px rgba(0, 0, 0, .5), 0 2px 8px rgba(0, 0, 0, .3);--rw-sidebar-header-bg: var(--rw-color-bg)}.rw-icon-btn{display:inline-flex;align-items:center;justify-content:center;padding:0 4px;min-width:22px;height:22px;border:none;background:transparent;color:var(--rw-color-text-secondary);border-radius:var(--rw-radius);cursor:pointer;transition:background var(--rw-transition)}.rw-icon-btn:hover{background:var(--rw-color-bg-hover);color:var(--rw-color-text)}.rw-dropdown{position:relative;display:inline-flex}.rw-dropdown-trigger{cursor:pointer;display:inline-flex;align-items:center}.rw-dropdown-menu{position:absolute;top:100%;right:0;margin-top:4px;min-width:140px;background:var(--rw-color-bg);border:1px solid var(--rw-color-border);border-radius:var(--rw-radius-lg);box-shadow:var(--rw-shadow-lg);z-index:2000;padding:4px;max-height:min(70vh,480px);overflow-y:auto;max-width:280px;font-size:var(--rw-font-size);line-height:1.5;text-align:left}.rw-dropdown-item{display:block;width:100%;padding:8px 12px;border:none;background:transparent;text-align:left;font-size:var(--rw-font-size);color:var(--rw-color-text);border-radius:var(--rw-radius);cursor:pointer}.rw-dropdown-item:hover:not(:disabled){background:var(--rw-color-bg-hover)}.rw-dropdown-item:disabled{color:var(--rw-color-text-muted);cursor:not-allowed}.rw-dropdown-divider{height:1px;background:var(--rw-color-border);margin:4px 0}.rw-spinner-wrap{position:relative;height:100%;min-height:0;flex:1;display:flex;flex-direction:column}.rw-spinner-overlay{position:absolute;inset:0;z-index:100;display:flex;flex-direction:column;align-items:center;justify-content:center;background:#ffffffa6;gap:12px}.rw-spinner{width:32px;height:32px;border:3px solid var(--rw-color-border);border-top-color:var(--rw-color-primary);border-radius:50%;animation:rw-spin .8s linear infinite}@keyframes rw-spin{to{transform:rotate(360deg)}}.rw-spinner-tip{color:var(--rw-color-text-secondary);font-size:var(--rw-font-size)}.rw-empty{display:flex;flex-direction:column;align-items:center;justify-content:center;padding:48px 24px;color:var(--rw-color-text-muted)}.rw-empty-icon{color:var(--rw-color-border-strong);margin-bottom:16px}.rw-empty-desc{font-size:var(--rw-font-size)}.rw-dropdown-window{display:flex;align-items:center;gap:8px;min-width:0}.rw-dropdown-window-title{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.rw-dropdown-dot{width:6px;height:6px;border-radius:50%;background:var(--rw-color-border-strong);flex-shrink:0}.rw-dropdown-dot.active{background:var(--rw-color-primary)}.rw-dropdown-tag{margin-left:auto;flex-shrink:0;font-size:var(--rw-font-size-sm);color:var(--rw-color-text-muted)}.rw-workspace{height:100%;min-height:0;overflow:hidden;background:var(--rw-color-bg-tertiary)}.rw-workspace-main{flex:1;height:100%;min-height:0;overflow:hidden;min-width:0;display:flex;flex-direction:column}.rw-workspace-sidebar-wrapper{display:flex;height:100%;position:relative;flex-shrink:0}.rw-workspace-sider{overflow:hidden;height:100%;border-right:1px solid var(--rw-color-border);display:flex;flex-direction:column;background:var(--rw-color-bg);position:relative;transition:width var(--rw-transition)}.rw-workspace-sidebar-header{flex-shrink:0;padding:14px 16px;border-bottom:1px solid var(--rw-color-border);background:var(--rw-sidebar-header-bg);z-index:10}.rw-workspace-sidebar-header.collapsed{padding:12px 8px}.rw-workspace-sidebar-menu{flex:1;overflow-y:auto;overflow-x:hidden;min-height:0;padding:8px 0;scrollbar-width:thin}.rw-workspace-sidebar-footer{flex-shrink:0;padding:10px 12px;border-top:1px solid var(--rw-color-border);background:transparent}.rw-menu-divider{height:1px;background:var(--rw-color-border);margin:4px 12px}.rw-menu-item{position:relative;display:flex;align-items:center;gap:10px;padding:8px 10px;border:none;background:transparent;color:var(--rw-color-text);font-size:var(--rw-font-size);text-align:left;cursor:pointer;border-radius:var(--rw-radius);margin:2px 8px;width:calc(100% - 16px);transition:background var(--rw-transition),color var(--rw-transition)}.rw-menu-item:hover:not(.disabled){background:var(--rw-color-bg-hover);color:var(--rw-color-text)}.rw-menu-item:focus-visible{outline:2px solid var(--rw-color-primary);outline-offset:-2px}.rw-menu-item.selected{background:var(--rw-color-bg-active);color:var(--rw-color-primary);font-weight:500}.rw-menu-item.selected:before{content:"";position:absolute;left:3px;width:3px;height:16px;border-radius:2px;background:var(--rw-color-primary)}.rw-menu-item.disabled{color:var(--rw-color-text-muted);cursor:not-allowed}.rw-menu-icon{display:flex;flex-shrink:0;width:16px;justify-content:center}.rw-menu-label{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.rw-menu-arrow{transition:transform var(--rw-transition);display:flex}.rw-menu-arrow.open{transform:rotate(180deg)}.rw-menu-children{margin-left:4px}.rw-workspace-collapse-button{position:absolute;top:41px;width:24px;height:24px;display:flex;align-items:center;justify-content:center;background:var(--rw-color-bg);border:1px solid var(--rw-color-border);border-radius:6px;cursor:pointer;box-shadow:var(--rw-shadow-md);z-index:100;margin-left:-12px;color:var(--rw-color-text-secondary);transition:all var(--rw-transition)}.rw-workspace-collapse-button:hover{background:var(--rw-color-bg-hover);transform:scale(1.08);color:var(--rw-color-text)}.rw-minimized-floating-badge{margin-left:8px;opacity:.6}.rw-window-tabs{background:var(--rw-color-bg-secondary);border-bottom:1px solid var(--rw-color-border);flex-shrink:0}.rw-window-tabs-container{display:flex;align-items:center;min-height:var(--rw-tab-height);position:relative;min-width:0}.rw-tab-list{display:flex;flex:1;overflow-x:auto;overflow-y:hidden;padding:4px 6px;gap:2px;align-items:center;scrollbar-width:none;min-width:0}.rw-tab-list::-webkit-scrollbar{display:none}.rw-tab-item{display:flex;align-items:center;gap:6px;position:relative;padding:6px 26px 6px 10px;background:var(--rw-tab-bg);border:1px solid transparent;border-radius:var(--rw-tab-radius);cursor:pointer;flex:0 0 auto;max-width:200px;-webkit-user-select:none;user-select:none;color:var(--rw-color-text-secondary);transition:background var(--rw-transition),color var(--rw-transition),box-shadow var(--rw-transition)}.rw-tab-item:hover{background:var(--rw-color-bg-hover);color:var(--rw-color-text)}.rw-tab-item.active{background:var(--rw-tab-bg-active);border-color:var(--rw-color-border);color:var(--rw-color-text);font-weight:500;box-shadow:var(--rw-shadow-sm)}.rw-tab-item:focus-visible{outline:2px solid var(--rw-color-primary);outline-offset:-1px}.rw-tab-title{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:var(--rw-font-size);flex:0 1 auto;min-width:0}.rw-window-tab-close-btn{position:absolute;right:4px;top:50%;transform:translateY(-50%);opacity:0;pointer-events:none;border-radius:4px;transition:opacity var(--rw-transition),background var(--rw-transition)}.rw-window-tab-close-btn:hover{background:var(--rw-color-bg-hover)}.rw-tab-item.active .rw-window-tab-close-btn,.rw-tab-item:hover .rw-window-tab-close-btn{opacity:.55;pointer-events:auto}.rw-tab-item .rw-window-tab-close-btn:hover{opacity:1}.rw-window-tabs-batch-btn{margin:0 6px;flex-shrink:0;align-self:center;border-radius:var(--rw-radius)}.rw-window-tab-insert-indicator{position:absolute;top:6px;bottom:6px;width:2px;background:var(--rw-color-primary);z-index:10;pointer-events:none;border-radius:2px}.rw-tab-preview{display:flex;align-items:center;padding:6px 10px;background:var(--rw-color-primary-bg);border:1px dashed var(--rw-color-primary-border);border-radius:var(--rw-tab-radius);color:var(--rw-color-primary);font-size:var(--rw-font-size);white-space:nowrap;max-width:200px;overflow:hidden;text-overflow:ellipsis;flex:0 0 auto}.rw-window-tabs.rw-tabs-embedded{background:transparent;border-bottom:none;min-width:0;flex:1 1 0;overflow:hidden}.rw-window-manager{height:100%;display:flex;flex-direction:column;overflow:hidden}.rw-window-manager-empty{display:flex;justify-content:center;align-items:center;height:100%;background:var(--rw-color-bg)}.rw-window-content-area{flex:1;overflow:auto;position:relative;background:var(--rw-color-bg);min-height:0}.rw-minimized-windows-bar{display:flex;gap:8px;padding:8px;background:var(--rw-color-bg-secondary);border-top:1px solid var(--rw-color-border);overflow-x:auto;max-height:60px;flex-shrink:0}.rw-minimized-window-item{padding:6px 14px;background:var(--rw-color-bg);border:1px solid var(--rw-color-border);border-radius:999px;font-size:var(--rw-font-size);box-shadow:var(--rw-shadow-sm);cursor:pointer;white-space:nowrap;flex-shrink:0;max-width:200px;overflow:hidden;text-overflow:ellipsis;color:var(--rw-color-text);transition:all var(--rw-transition)}.rw-minimized-window-item:hover{background:var(--rw-color-bg-active);border-color:var(--rw-color-primary-border);color:var(--rw-color-primary)}.rw-window-container{height:100%;overflow:auto;display:flex;flex-direction:column;position:relative}.rw-window-container.active{display:flex}.rw-window-container>div{width:100%;flex:1;overflow:auto;min-height:0}.rw-window-content-padding{padding:16px;width:100%;flex:1;overflow:auto;display:flex;flex-direction:column;box-sizing:border-box;min-height:0}.rw-floating-window{position:fixed;left:0;top:0;background:var(--rw-color-bg);border:1px solid var(--rw-color-border);border-radius:var(--rw-radius-lg);box-shadow:var(--rw-shadow-lg);display:flex;flex-direction:column;z-index:var(--rw-floating-z-index);overflow:hidden}.rw-floating-window-header{display:flex;align-items:center;justify-content:space-between;padding:8px 10px 8px 14px;background:var(--rw-color-bg-secondary);border-bottom:1px solid var(--rw-color-border);cursor:move;-webkit-user-select:none;user-select:none;flex-shrink:0}.rw-floating-window-header:active{cursor:grabbing}.rw-floating-window-title{flex:1;font-weight:500;font-size:var(--rw-font-size);color:var(--rw-color-text);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.rw-floating-window-actions{display:flex;gap:4px;margin-left:12px}.rw-floating-window-content{flex:1;overflow:auto;background:var(--rw-color-bg)}.rw-floating-window-resize-handle{position:absolute;z-index:10}.rw-floating-window-resize-handle:hover{background:transparent}.rw-floating-window-resize-nw{top:0;left:0;width:20px;height:20px;cursor:nwse-resize}.rw-floating-window-resize-ne{top:0;right:0;width:20px;height:20px;cursor:nesw-resize}.rw-floating-window-resize-sw{bottom:0;left:0;width:20px;height:20px;cursor:nesw-resize}.rw-floating-window-resize-se{bottom:0;right:0;width:20px;height:20px;cursor:nwse-resize}.rw-floating-window-resize-n{top:0;left:20px;right:20px;height:4px;cursor:ns-resize}.rw-floating-window-resize-s{bottom:0;left:20px;right:20px;height:4px;cursor:ns-resize}.rw-floating-window-resize-w{left:0;top:20px;bottom:20px;width:4px;cursor:ew-resize}.rw-floating-window-resize-e{right:0;top:20px;bottom:20px;width:4px;cursor:ew-resize}.rw-antd-sidebar .rw-antd-sider{height:100vh!important;display:flex!important;flex-direction:column!important;border-right:1px solid var(--rw-color-border)}.rw-antd-sidebar .rw-antd-menu-wrap{flex:1;overflow-y:auto;overflow-x:hidden;min-height:0}.rw-antd-sidebar .ant-menu{border-inline-end:none!important;background:transparent!important}.rw-antd-sidebar .rw-workspace-sidebar-footer{position:relative;flex-shrink:0}.rw-antd-sidebar .ant-layout-sider-dark .rw-workspace-sidebar-header{background:var(--rw-color-bg-secondary)}.rw-antd-sidebar .ant-layout-sider-dark .rw-workspace-sidebar-footer{background:var(--rw-color-bg)}
1
+ .rw-workspace,.rw-floating-window,.rw-window-tabs,.rw-dropdown-menu{--rw-color-primary: #2563eb;--rw-color-primary-hover: #3b82f6;--rw-color-primary-bg: #eff6ff;--rw-color-primary-border: #93c5fd;--rw-color-bg: #ffffff;--rw-color-bg-secondary: #f8fafc;--rw-color-bg-tertiary: #f1f5f9;--rw-color-bg-hover: rgba(15, 23, 42, .045);--rw-color-bg-active: #eff6ff;--rw-color-border: #e8ecf1;--rw-color-border-strong: #cbd5e1;--rw-color-text: #0f172a;--rw-color-text-secondary: #475569;--rw-color-text-muted: #94a3b8;--rw-color-shadow: rgba(15, 23, 42, .16);--rw-color-shadow-light: rgba(15, 23, 42, .06);--rw-shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 1px rgba(15, 23, 42, .04);--rw-shadow-md: 0 2px 8px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .06);--rw-shadow-lg: 0 12px 32px rgba(15, 23, 42, .16), 0 2px 8px rgba(15, 23, 42, .08);--rw-sidebar-width: 240px;--rw-sidebar-collapsed-width: 64px;--rw-sidebar-header-bg: var(--rw-color-bg);--rw-tab-height: 40px;--rw-tab-bg: transparent;--rw-tab-bg-active: var(--rw-color-bg);--rw-tab-radius: 8px;--rw-floating-min-width: 400px;--rw-floating-min-height: 300px;--rw-floating-z-index: 1000;--rw-font-size: 14px;--rw-font-size-sm: 12px;--rw-radius: 6px;--rw-radius-lg: 10px;--rw-transition: .16s cubic-bezier(.4, 0, .2, 1)}.rw-workspace.rw-theme-dark,.rw-floating-window.rw-theme-dark,.rw-window-tabs.rw-theme-dark,.rw-dropdown-menu.rw-theme-dark{--rw-color-primary: #60a5fa;--rw-color-primary-hover: #93c5fd;--rw-color-primary-bg: rgba(96, 165, 250, .16);--rw-color-primary-border: rgba(96, 165, 250, .5);--rw-color-bg: #1a1d23;--rw-color-bg-secondary: #15181d;--rw-color-bg-tertiary: #0f1115;--rw-color-bg-hover: rgba(255, 255, 255, .06);--rw-color-bg-active: rgba(96, 165, 250, .14);--rw-color-border: #2a2f37;--rw-color-border-strong: #3d444e;--rw-color-text: rgba(255, 255, 255, .92);--rw-color-text-secondary: rgba(255, 255, 255, .66);--rw-color-text-muted: rgba(255, 255, 255, .42);--rw-color-shadow: rgba(0, 0, 0, .5);--rw-color-shadow-light: rgba(0, 0, 0, .3);--rw-shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);--rw-shadow-md: 0 2px 8px rgba(0, 0, 0, .36);--rw-shadow-lg: 0 12px 32px rgba(0, 0, 0, .5), 0 2px 8px rgba(0, 0, 0, .3);--rw-sidebar-header-bg: var(--rw-color-bg)}.rw-icon-btn{display:inline-flex;align-items:center;justify-content:center;padding:0 4px;min-width:22px;height:22px;border:none;background:transparent;color:var(--rw-color-text-secondary);border-radius:var(--rw-radius);cursor:pointer;transition:background var(--rw-transition)}.rw-icon-btn:hover{background:var(--rw-color-bg-hover);color:var(--rw-color-text)}.rw-dropdown{position:relative;display:inline-flex}.rw-dropdown-trigger{cursor:pointer;display:inline-flex;align-items:center}.rw-dropdown-menu{position:fixed;margin:0;min-width:140px;background:var(--rw-color-bg);border:1px solid var(--rw-color-border);border-radius:var(--rw-radius-lg);box-shadow:var(--rw-shadow-lg);z-index:11000;padding:4px;max-height:min(70vh,480px);overflow-y:auto;max-width:280px;font-size:var(--rw-font-size);line-height:1.5;text-align:left}.rw-dropdown-item{display:block;width:100%;padding:8px 12px;border:none;background:transparent;text-align:left;font-size:var(--rw-font-size);color:var(--rw-color-text);border-radius:var(--rw-radius);cursor:pointer}.rw-dropdown-item:hover:not(:disabled){background:var(--rw-color-bg-hover)}.rw-dropdown-item:disabled{color:var(--rw-color-text-muted);cursor:not-allowed}.rw-dropdown-divider{height:1px;background:var(--rw-color-border);margin:4px 0}.rw-spinner-wrap{position:relative;height:100%;min-height:0;flex:1;display:flex;flex-direction:column}.rw-spinner-overlay{position:absolute;inset:0;z-index:100;display:flex;flex-direction:column;align-items:center;justify-content:center;background:#ffffffa6;gap:12px}.rw-spinner{width:32px;height:32px;border:3px solid var(--rw-color-border);border-top-color:var(--rw-color-primary);border-radius:50%;animation:rw-spin .8s linear infinite}@keyframes rw-spin{to{transform:rotate(360deg)}}.rw-spinner-tip{color:var(--rw-color-text-secondary);font-size:var(--rw-font-size)}.rw-empty{display:flex;flex-direction:column;align-items:center;justify-content:center;padding:48px 24px;color:var(--rw-color-text-muted)}.rw-empty-icon{color:var(--rw-color-border-strong);margin-bottom:16px}.rw-empty-desc{font-size:var(--rw-font-size)}.rw-dropdown-window{display:flex;align-items:center;gap:8px;min-width:0}.rw-dropdown-window-title{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.rw-dropdown-dot{width:6px;height:6px;border-radius:50%;background:var(--rw-color-border-strong);flex-shrink:0}.rw-dropdown-dot.active{background:var(--rw-color-primary)}.rw-dropdown-tag{margin-left:auto;flex-shrink:0;font-size:var(--rw-font-size-sm);color:var(--rw-color-text-muted)}.rw-workspace{height:100%;min-height:0;overflow:hidden;background:var(--rw-color-bg-tertiary)}.rw-workspace-main{flex:1;height:100%;min-height:0;overflow:hidden;min-width:0;display:flex;flex-direction:column}.rw-workspace-sidebar-wrapper{display:flex;height:100%;position:relative;flex-shrink:0}.rw-workspace-sider{overflow:hidden;height:100%;border-right:1px solid var(--rw-color-border);display:flex;flex-direction:column;background:var(--rw-color-bg);position:relative;transition:width var(--rw-transition)}.rw-workspace-sidebar-header{flex-shrink:0;padding:14px 16px;border-bottom:1px solid var(--rw-color-border);background:var(--rw-sidebar-header-bg);z-index:10}.rw-workspace-sidebar-header.collapsed{padding:12px 8px}.rw-workspace-sidebar-menu{flex:1;overflow-y:auto;overflow-x:hidden;min-height:0;padding:8px 0;scrollbar-width:thin}.rw-workspace-sidebar-footer{flex-shrink:0;padding:10px 12px;border-top:1px solid var(--rw-color-border);background:transparent}.rw-menu-divider{height:1px;background:var(--rw-color-border);margin:4px 12px}.rw-menu-item{position:relative;display:flex;align-items:center;gap:10px;padding:8px 10px;border:none;background:transparent;color:var(--rw-color-text);font-size:var(--rw-font-size);text-align:left;cursor:pointer;border-radius:var(--rw-radius);margin:2px 8px;width:calc(100% - 16px);transition:background var(--rw-transition),color var(--rw-transition)}.rw-menu-item:hover:not(.disabled){background:var(--rw-color-bg-hover);color:var(--rw-color-text)}.rw-menu-item:focus-visible{outline:2px solid var(--rw-color-primary);outline-offset:-2px}.rw-menu-item.selected{background:var(--rw-color-bg-active);color:var(--rw-color-primary);font-weight:500}.rw-menu-item.selected:before{content:"";position:absolute;left:3px;width:3px;height:16px;border-radius:2px;background:var(--rw-color-primary)}.rw-menu-item.disabled{color:var(--rw-color-text-muted);cursor:not-allowed}.rw-menu-icon{display:flex;flex-shrink:0;width:16px;justify-content:center}.rw-menu-label{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.rw-menu-arrow{transition:transform var(--rw-transition);display:flex}.rw-menu-arrow.open{transform:rotate(180deg)}.rw-menu-children{margin-left:4px}.rw-workspace-collapse-button{position:absolute;top:41px;width:24px;height:24px;display:flex;align-items:center;justify-content:center;background:var(--rw-color-bg);border:1px solid var(--rw-color-border);border-radius:6px;cursor:pointer;box-shadow:var(--rw-shadow-md);z-index:100;margin-left:-12px;color:var(--rw-color-text-secondary);transition:all var(--rw-transition)}.rw-workspace-collapse-button:hover{background:var(--rw-color-bg-hover);transform:scale(1.08);color:var(--rw-color-text)}.rw-minimized-floating-badge{margin-left:8px;opacity:.6}.rw-window-tabs{background:var(--rw-color-bg-secondary);border-bottom:1px solid var(--rw-color-border);flex-shrink:0}.rw-window-tabs-container{display:flex;align-items:center;min-height:var(--rw-tab-height);position:relative;min-width:0}.rw-tab-list{display:flex;flex:1;overflow-x:auto;overflow-y:hidden;padding:4px 6px;gap:2px;align-items:center;scrollbar-width:none;min-width:0}.rw-tab-list::-webkit-scrollbar{display:none}.rw-tab-item{display:flex;align-items:center;gap:6px;position:relative;padding:6px 26px 6px 10px;background:var(--rw-tab-bg);border:1px solid transparent;border-radius:var(--rw-tab-radius);cursor:pointer;flex:0 0 auto;max-width:200px;-webkit-user-select:none;user-select:none;color:var(--rw-color-text-secondary);transition:background var(--rw-transition),color var(--rw-transition),box-shadow var(--rw-transition)}.rw-tab-item:hover{background:var(--rw-color-bg-hover);color:var(--rw-color-text)}.rw-tab-item.active{background:var(--rw-tab-bg-active);border-color:var(--rw-color-border);color:var(--rw-color-text);font-weight:500;box-shadow:var(--rw-shadow-sm)}.rw-tab-item:focus-visible{outline:2px solid var(--rw-color-primary);outline-offset:-1px}.rw-tab-title{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:var(--rw-font-size);flex:0 1 auto;min-width:0}.rw-window-tab-close-btn{position:absolute;right:4px;top:50%;transform:translateY(-50%);opacity:0;pointer-events:none;border-radius:4px;transition:opacity var(--rw-transition),background var(--rw-transition)}.rw-window-tab-close-btn:hover{background:var(--rw-color-bg-hover)}.rw-tab-item.active .rw-window-tab-close-btn,.rw-tab-item:hover .rw-window-tab-close-btn{opacity:.55;pointer-events:auto}.rw-tab-item .rw-window-tab-close-btn:hover{opacity:1}.rw-window-tabs-batch-btn{margin:0 6px;flex-shrink:0;align-self:center;border-radius:var(--rw-radius)}.rw-window-tab-insert-indicator{position:absolute;top:6px;bottom:6px;width:2px;background:var(--rw-color-primary);z-index:10;pointer-events:none;border-radius:2px}.rw-tab-preview{display:flex;align-items:center;padding:6px 10px;background:var(--rw-color-primary-bg);border:1px dashed var(--rw-color-primary-border);border-radius:var(--rw-tab-radius);color:var(--rw-color-primary);font-size:var(--rw-font-size);white-space:nowrap;max-width:200px;overflow:hidden;text-overflow:ellipsis;flex:0 0 auto}.rw-window-tabs.rw-tabs-embedded{background:transparent;border-bottom:none;min-width:0;flex:1 1 0;overflow:hidden}.rw-window-manager{height:100%;display:flex;flex-direction:column;overflow:hidden}.rw-window-manager-empty{display:flex;justify-content:center;align-items:center;height:100%;background:var(--rw-color-bg)}.rw-window-content-area{flex:1;overflow:auto;position:relative;background:var(--rw-color-bg);min-height:0}.rw-minimized-windows-bar{display:flex;gap:8px;padding:8px;background:var(--rw-color-bg-secondary);border-top:1px solid var(--rw-color-border);overflow-x:auto;max-height:60px;flex-shrink:0}.rw-minimized-window-item{padding:6px 14px;background:var(--rw-color-bg);border:1px solid var(--rw-color-border);border-radius:999px;font-size:var(--rw-font-size);box-shadow:var(--rw-shadow-sm);cursor:pointer;white-space:nowrap;flex-shrink:0;max-width:200px;overflow:hidden;text-overflow:ellipsis;color:var(--rw-color-text);transition:all var(--rw-transition)}.rw-minimized-window-item:hover{background:var(--rw-color-bg-active);border-color:var(--rw-color-primary-border);color:var(--rw-color-primary)}.rw-window-container{height:100%;overflow:auto;display:flex;flex-direction:column;position:relative}.rw-window-container.active{display:flex}.rw-window-container>div{width:100%;flex:1;overflow:auto;min-height:0}.rw-window-content-padding{padding:16px;width:100%;flex:1;overflow:auto;display:flex;flex-direction:column;box-sizing:border-box;min-height:0}.rw-floating-window{position:fixed;left:0;top:0;background:var(--rw-color-bg);border:1px solid var(--rw-color-border);border-radius:var(--rw-radius-lg);box-shadow:var(--rw-shadow-lg);display:flex;flex-direction:column;z-index:var(--rw-floating-z-index);overflow:hidden}.rw-floating-window-header{display:flex;align-items:center;justify-content:space-between;padding:8px 10px 8px 14px;background:var(--rw-color-bg-secondary);border-bottom:1px solid var(--rw-color-border);cursor:move;-webkit-user-select:none;user-select:none;flex-shrink:0}.rw-floating-window-header:active{cursor:grabbing}.rw-floating-window-title{flex:1;font-weight:500;font-size:var(--rw-font-size);color:var(--rw-color-text);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.rw-floating-window-actions{display:flex;gap:4px;margin-left:12px}.rw-floating-window-content{flex:1;overflow:auto;background:var(--rw-color-bg)}.rw-floating-window-resize-handle{position:absolute;z-index:10}.rw-floating-window-resize-handle:hover{background:transparent}.rw-floating-window-resize-nw{top:0;left:0;width:20px;height:20px;cursor:nwse-resize}.rw-floating-window-resize-ne{top:0;right:0;width:20px;height:20px;cursor:nesw-resize}.rw-floating-window-resize-sw{bottom:0;left:0;width:20px;height:20px;cursor:nesw-resize}.rw-floating-window-resize-se{bottom:0;right:0;width:20px;height:20px;cursor:nwse-resize}.rw-floating-window-resize-n{top:0;left:20px;right:20px;height:4px;cursor:ns-resize}.rw-floating-window-resize-s{bottom:0;left:20px;right:20px;height:4px;cursor:ns-resize}.rw-floating-window-resize-w{left:0;top:20px;bottom:20px;width:4px;cursor:ew-resize}.rw-floating-window-resize-e{right:0;top:20px;bottom:20px;width:4px;cursor:ew-resize}.rw-antd-sidebar .rw-antd-sider{height:100vh!important;display:flex!important;flex-direction:column!important;border-right:1px solid var(--rw-color-border)}.rw-antd-sidebar .rw-antd-menu-wrap{flex:1;overflow-y:auto;overflow-x:hidden;min-height:0}.rw-antd-sidebar .ant-menu{border-inline-end:none!important;background:transparent!important}.rw-antd-sidebar .rw-workspace-sidebar-footer{position:relative;flex-shrink:0}.rw-antd-sidebar .ant-layout-sider-dark .rw-workspace-sidebar-header{background:var(--rw-color-bg-secondary)}.rw-antd-sidebar .ant-layout-sider-dark .rw-workspace-sidebar-footer{background:var(--rw-color-bg)}
@@ -1,4 +1,4 @@
1
- import { F as s, W as o, a as n, b as t, c as i, c as r, d, e as W, f as p, g as c, h as l, i as w, j as k, k as T, l as u, m, n as f, o as g, p as v, r as x, q as C, s as S, t as b, u as y, v as M, w as h, x as A } from "./Workspace-CvNGfg2U.js";
1
+ import { F as s, W as o, a as n, b as t, c as i, c as r, d, e as W, f as p, g as c, h as l, i as w, j as k, k as T, l as u, m, n as f, o as g, p as v, r as x, q as C, s as S, t as b, u as y, v as M, w as h, x as A } from "./Workspace-BJJGfZO9.js";
2
2
  export {
3
3
  s as FloatingWindow,
4
4
  o as WindowContainer,
@@ -12,6 +12,15 @@ interface DropdownProps {
12
12
  trigger: React.ReactNode;
13
13
  className?: string;
14
14
  }
15
+ /**
16
+ * 下拉菜单。
17
+ *
18
+ * 菜单必须 portal 到 document.body,不能画在触发器旁边。
19
+ * 标签栏被宿主塞进顶栏之后,自己和一路祖先都是 overflow:hidden
20
+ * (.rw-tabs-embedded、antd Header、整页外壳),绝对定位的菜单
21
+ * 会被裁成一条缝 —— 和数、Argus 都撞过。挂到 body 上用 fixed
22
+ * 对着触发器定位,谁裁都裁不到。
23
+ */
15
24
  export declare const Dropdown: React.FC<DropdownProps>;
16
25
  export {};
17
26
  //# sourceMappingURL=Dropdown.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Dropdown.d.ts","sourceRoot":"","sources":["../../src/ui/Dropdown.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAC3D,OAAO,kBAAkB,CAAC;AAE1B,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,UAAU,aAAa;IACrB,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAuC5C,CAAC"}
1
+ {"version":3,"file":"Dropdown.d.ts","sourceRoot":"","sources":["../../src/ui/Dropdown.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoE,MAAM,OAAO,CAAC;AAEzF,OAAO,kBAAkB,CAAC;AAE1B,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,UAAU,aAAa;IACrB,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAYD;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAgG5C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liuman/react-workspace",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "Zero-dependency React IDE-like multi-window workspace with tabs, floating windows, theming, and optional Ant Design integration",
5
5
  "type": "module",
6
6
  "main": "./dist/react-workspace.cjs",
@@ -1 +0,0 @@
1
- "use strict";const n=require("react/jsx-runtime"),l=require("react"),$e=require("react-dom"),Oe=({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})]})]}),xe=100;function Q(e,t){const i=globalThis.window.innerWidth,r=globalThis.window.innerHeight,u=Math.min(t?.minWidth??xe,i),p=Math.min(t?.minHeight??xe,r);let{x:w,y:g,width:m,height:v}=e;return m=Math.min(m,i),v=Math.min(v,r),m=Math.max(m,u),v=Math.max(v,p),w+m>i&&(w=Math.max(0,i-m)),g+v>r&&(g=Math.max(0,r-v)),w<0&&(w=0),g<0&&(g=0),{x:w,y:g,width:m,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 u=JSON.parse(r);if(u&&typeof u=="object"){const p={};return Object.entries(u).forEach(([w,g])=>{if(g&&typeof g=="object"){const m=g,v={};m.position&&typeof m.position.x=="number"&&typeof m.position.y=="number"&&typeof m.position.width=="number"&&typeof m.position.height=="number"&&(v.position=Q(m.position)),typeof m.minimized=="boolean"&&(v.minimized=m.minimized),typeof m.floating=="boolean"&&(v.floating=m.floating),typeof m.floatingZIndex=="number"&&(v.floatingZIndex=m.floatingZIndex),p[w]=v}}),p}}}catch(i){console.warn("[react-workspace] 从 localStorage 读取窗口状态失败:",i)}return{}}function re(e,t,i,r){if(t)try{const u=ne(e,t);u[i]={...u[i],...r},localStorage.setItem(se(e,t),JSON.stringify(u))}catch(u){console.warn("[react-workspace] 保存窗口状态到 localStorage 失败:",u)}}function oe(e,t,i){if(t)try{const r=se(e,t),u=localStorage.getItem(r);let p=u?JSON.parse(u):{};const w=Object.values(p).map(M=>M?.floatingZIndex||0).filter(M=>M>=1e3),g=w.length>0?Math.max(...w):999,m=p[i]||{},v=m.floatingZIndex||0,Y=Math.max(1e3,g+1);v>=1e3?(p[i]={...m,floatingZIndex:Y},Object.keys(p).forEach(M=>{if(M!==i&&p[M]){const $=p[M];$.floatingZIndex!==void 0&&$.floatingZIndex>=1e3&&(p[M]={...$,floatingZIndex:Math.max(1e3,$.floatingZIndex-1)})}})):p[i]={...m,floatingZIndex:Y},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 u=JSON.parse(r);return[...e].sort((w,g)=>{const m=u[w.type]?.floatingZIndex||0,v=u[g.type]?.floatingZIndex||0;return m>=1e3&&v>=1e3?v-m:m>=1e3?-1:v>=1e3?1:0})[0]?.id??e[e.length-1].id}}catch{}return e[e.length-1].id}const Ae="react_workspace_windows_",Be={x:100,y:100,width:800,height:600,minWidth:400,minHeight:300};function we(e){return{...Be,...e}}function Ze(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(u=>{const p=String(u.t??u.type??"");if(!p)throw new Error("窗口缺少类型");const w=u.p??u.props,g=t?.(p,w)??u.n??u.title??p,m={id:typeof u.id=="string"&&u.id?u.id:ce(),type:p,title:String(g),minimized:!1};return w&&typeof w=="object"&&(m.props=w),m})}function ce(){return`window-${Date.now()}-${Math.random().toString(36).slice(2,7)}`}function ye(e){const{workspaceId:t,defaultWindow:i,syncToUrl:r=!1,preserveUrlParams:u=!0,searchParams:p,setSearchParams:w,storageKeyPrefix:g=Ae,floatingDefaults:m,onWindowsChange:v,resolveTitle:Y}=e,M=l.useRef(Y);M.current=Y;const $=l.useRef(i??{type:"home",title:"首页",minimized:!1});$.current=i??$.current;const A=l.useRef(we(m));A.current=we(m);const X=l.useRef(v);X.current=v;const[W,D]=l.useState([]),[C,B]=l.useState(null),y=l.useRef({}),b=l.useCallback((o,s)=>{X.current?.(o,s)},[]),Z=l.useCallback(o=>ne(g,t)[o]||null,[g,t]),H=l.useCallback(o=>Z(o)?.position||null,[Z]),T=l.useCallback((o,s)=>{if(!r||!w)return;const c=u&&p?new URLSearchParams(p):new URLSearchParams;if(o.length>0){c.set("windows",JSON.stringify(o.map(d=>{const I={t:d.type};return d.props&&Object.keys(d.props).length>0&&(I.p=d.props),I})));const f=o.findIndex(d=>d.id===s);f>=0?c.set("active",String(f)):c.delete("active")}else c.delete("windows"),c.delete("active");w(c,{replace:!0})},[r,w,u,p]),h=l.useCallback((o,s)=>{D(o),B(s),T(o,s),b(o,s)},[T,b]),q=l.useCallback(o=>{const s=Z(o.type),c={...o,minimized:s?.minimized??o.minimized??!1,floating:s?.floating??o.floating??!1};if(c.floating){let f=o.floatingPosition||s?.position;f||(f=H(o.type)??void 0),f&&(c.floatingPosition=Q(f)),c.floatingZIndex=s?.floatingZIndex??o.floatingZIndex??1e3}return c},[Z,H]),_=l.useCallback(()=>{const o=$.current,s={id:ce(),type:o.type,title:o.title,minimized:o.minimized??!1};h([s],s.id)},[h]),a=l.useCallback(()=>{if(t)try{localStorage.removeItem(`${g}${t}`)}catch{}delete y.current[t],_()},[t,g,_]);l.useEffect(()=>{if(!t||y.current[t])return;y.current[t]=!0;const o=r?p?.get("windows"):null,s=r?p?.get("active"):null;if(o)try{const c=Ze(o,M.current);if(c.length===0)throw new Error("窗口列表是空的");const f=c.map(q),d=Number(s),I=Number.isInteger(d)&&d>=0&&d<f.length?f[d].id:f.find(O=>O.id===s)?.id??f[0]?.id??null;D(f),B(I),b(f,I)}catch(c){console.error("[react-workspace] 解析窗口配置失败:",c),_()}else _()},[t,p,r,q,_,b]);const x=l.useCallback((o,s)=>{const c=s!==void 0?{...o.props,...s}:o.props,f={...o,props:c},d=W.find(I=>I.type===f.type);if(d){const I=s&&Object.keys(s).length===0?void 0:c,O=q({...d,...f,props:I}),F=W.map(K=>K.id===d.id?O:K);h(F,d.id)}else{const I=q({...f,id:ce(),minimized:f.minimized??!1});h([...W,I],I.id)}},[W,h,q]),k=l.useCallback(o=>{const s=W.find(c=>c.id===o);if(s){if(oe(g,t,s.type),s.floating){const c=ne(g,t)[s.type];if(c?.floatingZIndex){const f=W.map(d=>d.id===o?{...d,minimized:!1,floatingZIndex:c.floatingZIndex}:d);h(f,o);return}}h(W.map(c=>c.id===o?{...c,minimized:!1}:c),o)}},[W,h,g,t]),S=l.useCallback(o=>{const s=W.filter(f=>f.id!==o),c=C===o?ae(s,g,t):C;h(s,c)},[W,C,h,g,t]),z=l.useCallback(o=>{const s=W.map(f=>{if(f.id===o){const d={...f,minimized:!f.minimized};return re(g,t,f.type,{minimized:d.minimized,floating:d.floating}),d}return f}),c=s.find(f=>f.id===o);if(c?.minimized&&C===o&&!c.floating){const f=s.find(d=>!d.minimized&&!d.floating);h(s,f?.id??null)}else c&&!c.minimized&&!c.floating?h(s,o):h(s,C)},[W,C,t,g,h]),P=l.useCallback((o,s)=>{const c=W.find(E=>E.id===o);if(!c||!t||c.floating)return;const f=W.filter(E=>!E.floating&&!E.minimized);if(f.length===1&&f[0].id===o)return;const d=A.current,I={minWidth:d.minWidth,minHeight:d.minHeight};let O=Q({x:d.x,y:d.y,width:d.width,height:d.height},I);if(s)O=Q({x:s.x,y:s.y,width:d.width,height:d.height},I);else if(c.floatingPosition)O=Q(c.floatingPosition,I);else{const E=H(c.type);E&&(O=Q(E,I))}oe(g,t,c.type);const F=ne(g,t)[c.type]?.floatingZIndex??1e3,K=W.map(E=>E.id===o?(re(g,t,E.type,{floating:!0,minimized:!1,position:O,floatingZIndex:F}),{...E,floating:!0,minimized:!1,floatingPosition:O,floatingZIndex:F,pendingDragStart:s}):E);if(C===o){const E=K.filter(G=>!G.floating&&!G.minimized);h(K,E.length>0?ae(E,g,t):null)}else h(K,C)},[W,C,t,g,h,H]),j=l.useCallback((o,s)=>{const c=W.find(G=>G.id===o);if(!c?.floating)return;const{floating:f,floatingPosition:d,floatingZIndex:I,pendingDragStart:O,...F}=c;re(g,t,c.type,{floating:!1,minimized:F.minimized});const K=W.filter(G=>!G.floating);let E;s!==void 0&&s>=0&&s<=K.length?E=[...K.slice(0,s),F,...K.slice(s)]:E=[...K,F],E=[...E,...W.filter(G=>G.floating&&G.id!==o)],h(E,o),setTimeout(()=>{document.querySelector(".rw-window-tabs")?.dispatchEvent(new CustomEvent("clearFloatingWindowPreview"))},0)},[W,h,g,t]),N=l.useCallback((o,s)=>{const c=W.find(d=>d.id===o);if(!c)return;const f=W.map(d=>{if(d.id===o){const{pendingDragStart:I,...O}=d;return{...O,floatingPosition:s}}return d});D(f),c.floating&&re(g,t,c.type,{position:s,floating:!0,minimized:c.minimized,floatingZIndex:c.floatingZIndex})},[W,t,g]),R=l.useCallback(o=>{const s=W.find(f=>f.id===o);if(!s?.floating||!t)return;oe(g,t,s.type);const c=ne(g,t)[s.type];c?.floatingZIndex&&D(f=>f.map(d=>d.id===o&&d.floating?{...d,floatingZIndex:c.floatingZIndex}:d))},[W,t,g]),L=l.useCallback((o,s)=>{D(c=>{const f=c.map(d=>d.id===o?{...d,props:{...d.props,...s}}:d);return b(f,C),f})},[C,b]),V=l.useCallback((o,s)=>{D(c=>{const f=c.map(d=>d.id===o?{...d,title:s}:d);return T(f,C),b(f,C),f})},[C,T,b]),J=l.useCallback(o=>{D(s=>s.map(c=>{if(c.id!==o)return c;const{pendingAction:f,...d}=c;return d}))},[]),ee=l.useCallback(o=>{if(o==="reset-windows"){a();return}if(!C&&!["close-all","minimize-all","restore-all"].includes(o))return;const s=W.filter(I=>!I.floating),c=W.filter(I=>I.floating);let f=[],d=C;switch(o){case"close-left":{const I=s.findIndex(O=>O.id===C);f=s.slice(I);break}case"close-right":{const I=s.findIndex(O=>O.id===C);f=s.slice(0,I+1);break}case"close-others":f=s.filter(I=>I.id===C);break;case"close-all":f=[],d=null;break;case"minimize-all":f=s.map(I=>({...I,minimized:!0})),d=null;break;case"restore-all":f=s.map(I=>({...I,minimized:!1})),d=C??f[0]?.id??null;break;default:f=s}h([...f,...c],d)},[W,C,h,a]),le=l.useCallback((o,s)=>{const c=W.filter(F=>!F.minimized&&!F.floating);if(o<0||o>=c.length||s<0||s>=c.length||o===s)return;const f=[...c],[d]=f.splice(o,1);f.splice(s,0,d);let I=0;const O=W.map(F=>F.minimized||F.floating?F:f[I++]);h(O,C)},[W,C,h]);return{windows:W,activeWindowId:C,openWindow:x,switchWindow:k,closeWindow:S,toggleMinimize:z,floatWindow:P,restoreWindow:j,updateFloatingPosition:N,focusWindow:R,batchManage:ee,updateWindowProps:L,updateWindowTitle:V,clearPendingAction:J,setWindows:D,setActiveWindowId:B,resetWorkspace:a,reorderWindows:le}}const fe=l.createContext(null),be=fe.Provider;function He(){const e=l.useContext(fe);if(!e)throw new Error("[react-workspace] useWorkspaceContext 必须在 Workspace 或 WorkspaceProvider 内使用");return e}function Xe(){return l.useContext(fe)}const te=e=>({width:e,height:e,viewBox:"0 0 24 24",fill:"currentColor"}),ve=({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"})}),Le=({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 We(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 u=We(r.children,t);if(u)return u}}return null}function de(e,t,i){const r=u=>{for(const p of u){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 u=ue(r.children,t);if(u)return u}}return null}function ke(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 ge(e){return typeof e=="string"||typeof e=="number"?String(e):""}function Ve(e){return"type"in e&&e.type==="divider"}const Se=({menuItems:e,onMenuClick:t,onAction:i,activeWindowType:r,header:u,footer:p,defaultOpenKeys:w=[],siderWidth:g=240,onCollapsedChange:m})=>{const[v,Y]=l.useState(!1),[M,$]=l.useState(new Set(w)),A=l.useMemo(()=>r?ue(e,r):null,[r,e]),X=()=>{Y(y=>(m?.(!y),!y))},W=(y,b)=>{b?.stopPropagation(),$(Z=>{const H=new Set(Z);return H.has(y)?H.delete(y):H.add(y),H})},D=y=>{if(!y.disabled){if(y.windowType){t(y.windowType,y.props);return}if(y.action&&i){i(y.action);return}y.children?.length&&W(y.key)}},C=(y,b=0)=>y.map((Z,H)=>{if(Ve(Z))return n.jsx("div",{className:"rw-menu-divider"},Z.key??`div-${H}`);const T=Z,h=!!T.children?.length,q=M.has(T.key),_=T.key===A;return n.jsxs("div",{className:"rw-menu-group",children:[n.jsxs("button",{type:"button",className:`rw-menu-item ${_?"selected":""} ${T.disabled?"disabled":""}`,style:{paddingLeft:v?12:12+b*16},onClick:()=>D(T),disabled:T.disabled,title:v?ge(T.label):void 0,children:[T.icon&&n.jsx("span",{className:"rw-menu-icon",children:T.icon}),!v&&n.jsx("span",{className:"rw-menu-label",children:T.label}),!v&&h&&n.jsx("span",{className:`rw-menu-arrow ${q?"open":""}`,onClick:a=>W(T.key,a),role:"presentation",children:n.jsx(Ue,{size:10})})]}),!v&&h&&q&&n.jsx("div",{className:"rw-menu-children",children:C(T.children,b+1)})]},T.key)}),B=v?64:g;return n.jsxs("div",{className:"rw-workspace-sidebar-wrapper",children:[n.jsxs("aside",{className:"rw-workspace-sider",style:{width:B},children:[u&&n.jsx("div",{className:`rw-workspace-sidebar-header ${v?"collapsed":""}`,children:u}),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:B},onClick:X,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}),Ge=({items:e,trigger:t,className:i})=>{const[r,u]=l.useState(!1),p=l.useRef(null);return l.useEffect(()=>{if(!r)return;const w=g=>{p.current?.contains(g.target)||u(!1)};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[r]),n.jsxs("div",{className:`rw-dropdown ${i||""}`,ref:p,children:[n.jsx("div",{className:"rw-dropdown-trigger",onClick:()=>u(w=>!w),role:"button",tabIndex:0,children:t}),r&&n.jsx("div",{className:"rw-dropdown-menu",children:e.map(w=>w.divider?n.jsx("div",{className:"rw-dropdown-divider"},w.key):n.jsx("button",{type:"button",className:"rw-dropdown-item",disabled:w.disabled,onClick:()=>{w.onClick?.(),u(!1)},children:w.label},w.key))})]})},Ce=({windows:e,activeWindowId:t,onSwitchWindow:i,onCloseWindow:r,onToggleMinimize:u,onBatchManage:p,onFloatWindow:w,onRestoreWindow:g,onReorderWindows:m,embedded:v=!1,themeClassName:Y,allWindows:M=e})=>{const $=e.findIndex(a=>a.id===t),A=l.useRef(null),X=l.useRef(null),[W,D]=l.useState(null),[C,B]=l.useState(null),y=l.useRef({windowId:"",startX:0,startY:0,fromIndex:-1,mode:"none",floated:!1}),b=l.useCallback(a=>{const x=X.current;if(!x)return e.length;const k=x.getBoundingClientRect(),S=a-k.left,z=x.querySelectorAll(".rw-tab-item");if(S<8)return 0;for(let P=0;P<z.length;P++){const j=z[P].getBoundingClientRect(),N=j.left-k.left+j.width/2;if(S<N)return P}return z.length},[e.length]),Z=l.useCallback((a,x,k)=>{if(a.target.closest(".rw-window-tab-close-btn")||a.button!==0)return;y.current={windowId:x,startX:a.clientX,startY:a.clientY,fromIndex:k,mode:"none",floated:!1};const S=j=>{const N=j.clientX-y.current.startX,R=j.clientY-y.current.startY,L=Math.sqrt(N*N+R*R);L<8||(y.current.mode==="none"&&(Math.abs(R)>40&&L>50?y.current.mode="float":Math.abs(N)>12&&Math.abs(N)>Math.abs(R)?y.current.mode="reorder":L>50&&(y.current.mode="float")),y.current.mode==="float"&&y.current.windowId===x?y.current.floated||(y.current.floated=!0,w?.(x,{x:j.clientX,y:j.clientY})):y.current.mode==="reorder"&&D(b(j.clientX)))},z=j=>{if(y.current.mode==="reorder"&&y.current.windowId===x){let R=b(j.clientX);R>y.current.fromIndex&&(R-=1),R!==y.current.fromIndex&&m&&m(y.current.fromIndex,R)}D(null),P()},P=()=>{document.removeEventListener("mousemove",S),document.removeEventListener("mouseup",z),y.current={windowId:"",startX:0,startY:0,fromIndex:-1,mode:"none",floated:!1}};document.addEventListener("mousemove",S),document.addEventListener("mouseup",z)},[w,m,b]);l.useEffect(()=>{if(!t)return;const a=X.current;if(!a)return;const x=e.findIndex(S=>S.id===t);if(x<0)return;a.querySelectorAll(".rw-tab-item")[x]?.scrollIntoView({block:"nearest",inline:"nearest",behavior:"smooth"})},[t,e.length]),l.useEffect(()=>{let a=null;const x=z=>{const{windowTitle:P,clientX:j}=z.detail,N=b(j);a&&cancelAnimationFrame(a),a=requestAnimationFrame(()=>{B({title:P,index:N}),D(N)})},k=()=>{B(null),D(null)},S=A.current;return S?.addEventListener("floatingWindowDragOver",x),S?.addEventListener("clearFloatingWindowPreview",k),()=>{S?.removeEventListener("floatingWindowDragOver",x),S?.removeEventListener("clearFloatingWindowPreview",k),a&&cancelAnimationFrame(a)}},[b]);const H=()=>{const a=e.map((x,k)=>n.jsxs("div",{className:`rw-tab-item ${x.id===t?"active":""}`,onClick:()=>i(x.id),onMouseDown:S=>Z(S,x.id,k),children:[n.jsx("span",{className:"rw-tab-title",children:x.title}),n.jsx("button",{type:"button",title:"关闭",className:"rw-icon-btn rw-window-tab-close-btn",onClick:S=>{S.stopPropagation(),r(x.id)},children:n.jsx(ve,{size:12})})]},x.id));if(C&&W!==null){const x=Math.max(0,Math.min(W,a.length));a.splice(x,0,n.jsx("div",{className:"rw-tab-preview",children:C.title},"rw-preview"))}return a},T=a=>{a.preventDefault();try{const x=sessionStorage.getItem("draggingWindowTitle");x&&B({title:x,index:b(a.clientX)})}catch{}D(b(a.clientX))},h=a=>{a.preventDefault();let x=a.dataTransfer.getData("windowId")||"";if(!x)try{x=sessionStorage.getItem("draggingWindowId")||""}catch{}x&&g&&g(x,W??void 0),B(null),D(null)},_=[...M.length===0?[]:[...M.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:$<=0,onClick:()=>p("close-left")},{key:"close-right",label:"关闭右侧",disabled:$<0||$>=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:!M.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":""} ${Y||""}`,ref:A,onDragOver:T,onDragLeave:()=>{B(null),D(null)},onDrop:h,children:n.jsxs("div",{className:"rw-window-tabs-container",children:[n.jsx("div",{className:"rw-tab-list",ref:X,children:H()}),W!==null&&!C&&n.jsx(Qe,{listRef:X,index:W}),e.length>0&&n.jsx(Ge,{items:_,trigger:n.jsx("button",{type:"button",className:"rw-icon-btn rw-window-tabs-batch-btn",title:"批量管理",children:n.jsx(Ye,{})})})]})})},Qe=({listRef:e,index:t})=>{const[i,r]=l.useState(0);return l.useEffect(()=>{const u=()=>{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 m=w[w.length-1];r(m.offsetLeft+m.offsetWidth+2);return}const g=w[t];r(g.offsetLeft-1)};return u(),window.addEventListener("resize",u),()=>window.removeEventListener("resize",u)},[e,t]),n.jsx("div",{className:"rw-window-tab-insert-indicator",style:{left:`${i}px`}})},et={x:100,y:100,width:800,height:600,minWidth:400,minHeight:300},ze=({window:e,children:t,floatingDefaults:i,onUpdateFloatingPosition:r,onRestoreWindow:u,onCloseWindow:p,onToggleMinimize:w,onFocusWindow:g})=>{const m={...et,...i},v=l.useRef(null),Y=l.useRef(null),[M,$]=l.useState(!1),[A,X]=l.useState(!1),[W,D]=l.useState(!1),C=l.useRef(!1),B=l.useRef(""),y=l.useRef({x:0,y:0,startX:0,startY:0,startWidth:0,startHeight:0}),b=l.useRef({x:0,y:0,width:0,height:0,startX:0,startY:0}),Z=l.useRef(null),H=l.useRef(null),T=l.useRef(null),h=e.floatingPosition||{x:m.x,y:m.y,width:m.width,height:m.height};l.useEffect(()=>{if(!e.pendingDragStart||M||A)return;let a=h.x,x=h.y;if(v.current){const k=v.current.getBoundingClientRect();a=k.left,x=k.top}g?.(e.id),T.current={windowId:e.id,windowTitle:e.title};try{sessionStorage.setItem("draggingWindowId",e.id),sessionStorage.setItem("draggingWindowTitle",e.title)}catch{}$(!0),y.current={x:e.pendingDragStart.x-a,y:e.pendingDragStart.y-x,startX:a,startY:x,startWidth:h.width,startHeight:h.height}},[e.pendingDragStart,e.id,e.title,M,A,h,g]),l.useEffect(()=>{if(M||A||e.pendingDragStart)return;const a={minWidth:m.minWidth,minHeight:m.minHeight},x=Q(h,a);(x.x!==h.x||x.y!==h.y||x.width!==h.width||x.height!==h.height)&&r(e.id,x)},[e.id,e.pendingDragStart]),l.useEffect(()=>{if(!v.current||M||A)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,M,A]);const q=l.useCallback(a=>{const x=a.target;if(x.closest(".rw-floating-window-action-btn")||x.closest(".rw-floating-window-resize-handle")||!Y.current?.contains(x))return;g?.(e.id);let k=h.x,S=h.y;if(v.current){const z=v.current.getBoundingClientRect();k=z.left,S=z.top}T.current={windowId:e.id,windowTitle:e.title};try{sessionStorage.setItem("draggingWindowId",e.id),sessionStorage.setItem("draggingWindowTitle",e.title)}catch{}$(!0),y.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]),_=l.useCallback((a,x)=>{a.stopPropagation(),a.preventDefault(),g?.(e.id);let k=h.x,S=h.y,z=h.width,P=h.height;if(v.current){const j=v.current.getBoundingClientRect();k=j.left,S=j.top,z=j.width,P=j.height}X(!0),B.current=x,b.current={x:a.clientX,y:a.clientY,width:z,height:P,startX:k,startY:S}},[h,e.id,g]);return l.useEffect(()=>{const a=k=>{if(M){k.preventDefault();const S=document.querySelector(".rw-window-tabs");if(S&&T.current){const R=S.getBoundingClientRect(),L=k.clientY>=R.top&&k.clientY<=R.bottom&&k.clientX>=R.left&&k.clientX<=R.right,V=C.current;D(L),C.current=L,L?S.dispatchEvent(new CustomEvent("floatingWindowDragOver",{detail:{...T.current,clientX:k.clientX,clientY:k.clientY}})):V&&S.dispatchEvent(new CustomEvent("clearFloatingWindowPreview"))}const z=y.current.startWidth,P=y.current.startHeight,j=Math.max(0,Math.min(k.clientX-y.current.x,globalThis.window.innerWidth-z)),N=Math.max(0,Math.min(k.clientY-y.current.y,globalThis.window.innerHeight-P));v.current.style.transform=`translate(${j}px, ${N}px)`,H.current={x:j,y:N,width:y.current.startWidth,height:y.current.startHeight}}else if(A){k.preventDefault();const S=B.current,z=b.current;let P=z.startX,j=z.startY,N=z.width,R=z.height;const L=k.clientX-z.x,V=k.clientY-z.y;S.includes("e")&&(N=Math.max(m.minWidth,z.width+L)),S.includes("w")&&(N=Math.max(m.minWidth,z.width-L),P=z.startX+z.width-N),S.includes("s")&&(R=Math.max(m.minHeight,z.height+V)),S.includes("n")&&(R=Math.max(m.minHeight,z.height-V),j=z.startY+z.height-R);const J=v.current;J.style.transform=`translate(${P}px, ${j}px)`,J.style.width=`${N}px`,J.style.height=`${R}px`,H.current={x:P,y:j,width:N,height:R}}},x=k=>{if(k&&T.current){const z=document.querySelector(".rw-window-tabs");if(z){const P=z.getBoundingClientRect();if(k.clientY>=P.top&&k.clientY<=P.bottom&&k.clientX>=P.left&&k.clientX<=P.right){const j=z.querySelector(".rw-tab-list");if(j){let N=j.querySelectorAll(".rw-tab-item").length;const R=j.getBoundingClientRect(),L=k.clientX-R.left;j.querySelectorAll(".rw-tab-item").forEach((V,J)=>{const ee=V.getBoundingClientRect();L<ee.left-R.left+ee.width/2&&(N=Math.min(N,J))}),u(T.current.windowId,N),T.current=null,$(!1),X(!1),D(!1);return}}}}let S=H.current;S&&(S=Q(S,{minWidth:m.minWidth,minHeight:m.minHeight})),S&&r(e.id,S),H.current=null,T.current=null;try{sessionStorage.removeItem("draggingWindowId"),sessionStorage.removeItem("draggingWindowTitle")}catch{}$(!1),X(!1),D(!1),C.current=!1};if(M||A){const k=S=>{Z.current&&cancelAnimationFrame(Z.current),Z.current=requestAnimationFrame(()=>a(S))};return document.addEventListener("mousemove",k,{passive:!1}),document.addEventListener("mouseup",x),document.body.style.userSelect="none",()=>{document.removeEventListener("mousemove",k),document.removeEventListener("mouseup",x),document.body.style.userSelect=""}}},[M,A,e.id,m.minWidth,m.minHeight,r,u]),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:W?.5:1,minWidth:m.minWidth,minHeight:m.minHeight},onClick:a=>{a.target.closest("button, a, input, select, textarea")||g?.(e.id)},children:[n.jsxs("div",{ref:Y,className:"rw-floating-window-header",onMouseDown:q,onDoubleClick:()=>u(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:()=>u(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(Le,{size:12})}),n.jsx("button",{type:"button",title:"关闭",className:"rw-icon-btn rw-floating-window-action-btn",onClick:()=>p(e.id),children:n.jsx(ve,{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:x=>_(x,a)},a))]})},Ie=({windows:e,activeWindowId:t,renderWindow:i,onSwitchWindow:r,onCloseWindow:u,onToggleMinimize:p,onBatchManage:w,onFloatWindow:g,onRestoreWindow:m,onUpdateFloatingPosition:v,onFocusWindow:Y,onReorderWindows:M,emptyDescription:$="从左侧菜单选择功能开始工作",floatingDefaults:A,tabsContainer:X,themeClassName:W})=>{if(e.length===0)return n.jsx("div",{className:"rw-window-manager-empty",children:n.jsx(Je,{description:$})});const D=e.filter(b=>b.minimized),C=e.filter(b=>b.floating&&!b.minimized),B=e.filter(b=>!b.minimized&&!b.floating),y=n.jsx(Ce,{windows:B,activeWindowId:t,onSwitchWindow:r,onCloseWindow:u,onToggleMinimize:p,onBatchManage:w,onFloatWindow:g,onRestoreWindow:m,onReorderWindows:M,allWindows:e,embedded:!!X,themeClassName:W});return n.jsxs("div",{className:"rw-window-manager",children:[X?$e.createPortal(y,X):y,n.jsx("div",{className:"rw-window-content-area",children:B.map(b=>n.jsx(je,{window:b,active:b.id===t,children:i(b,{})},b.id))}),D.length>0&&n.jsx("div",{className:"rw-minimized-windows-bar",children:D.map(b=>n.jsxs("div",{className:"rw-minimized-window-item",onClick:()=>p(b.id),title:b.floating?`${b.title} (浮动窗口)`:b.title,role:"button",tabIndex:0,onKeyDown:Z=>Z.key==="Enter"&&p(b.id),children:[n.jsx("span",{children:b.title}),b.floating&&n.jsx("span",{className:"rw-minimized-floating-badge",children:"🔲"})]},b.id))}),C.map(b=>n.jsx(ze,{window:b,floatingDefaults:A,onUpdateFloatingPosition:v||(()=>{}),onRestoreWindow:m||(()=>{}),onCloseWindow:u,onToggleMinimize:p,onFocusWindow:Y,children:i(b,{})},b.id))]})};function tt(e){return"type"in e&&e.type==="divider"}function me(e){for(const t of e){if(tt(t))continue;const i=t;if(i.windowType)return i;if(i.children){const r=me(i.children);if(r)return r}}return null}function Ne(e,t){if(t)return{minimized:!1,...t};const i=me(e);if(!i?.windowType)return{type:"home",title:"首页",minimized:!1};const r=ge(i.label)||i.key;return{type:i.windowType,title:r,minimized:!1}}function Me(e,t){const{fallback:i}=t??{};return(r,u)=>{const p=e[r.type]??i;return p?l.createElement(p,{window:r,ctx:u}):null}}const nt={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 u=nt[i];t[u]=typeof r=="number"?`${r}px`:r}}),t}function Te(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 it(e){return he(Te(e))}const rt=l.forwardRef(function({workspaceId:t="default",menuItems:i,renderWindow:r,windows:u,sidebarHeader:p,sidebarFooter:w,defaultWindow:g,loading:m=!1,loadingTip:v="加载中...",onAction:Y,activeWindowType:M,emptyDescription:$,syncToUrl:A=!1,preserveUrlParams:X=!0,searchParams:W,setSearchParams:D,floatingDefaults:C,onWindowsChange:B,resolveTitle:y,onReady:b,siderWidth:Z=240,contentBackground:H,themeClassName:T,theme:h,renderSidebar:q,tabsContainer:_,className:a,style:x},k){const S=l.useMemo(()=>Ne(i,g),[i,g]),z=l.useMemo(()=>{if(r)return r;if(u)return Me(u);throw new Error("[react-workspace] 请提供 renderWindow 或 windows")},[r,u]),P=ye({workspaceId:t,defaultWindow:S,syncToUrl:A,preserveUrlParams:X,searchParams:W,setSearchParams:D,floatingDefaults:C,onWindowsChange:B,resolveTitle:(U,ie)=>y?.(U,ie)??de(i,U)}),{windows:j,activeWindowId:N,openWindow:R,switchWindow:L,closeWindow:V,toggleMinimize:J,floatWindow:ee,restoreWindow:le,updateFloatingPosition:o,focusWindow:s,batchManage:c,updateWindowProps:f,clearPendingAction:d,reorderWindows:I}=P,O={workspaceId:t,...P};l.useImperativeHandle(k,()=>O,[t,j,N]),l.useEffect(()=>{b&&j.length>0&&b({workspaceId:t,...P})},[b,t,j.length]);const F=l.useMemo(()=>M!==void 0?M:j.find(U=>U.id===N)?.type,[M,j,N]),K=l.useCallback((U,ie)=>{R({type:U,title:de(i,U),minimized:!1},ie)},[R,i]),E=l.useCallback((U,ie)=>({workspaceId:t,active:ie,activeWindowId:N,windows:j,openWindow:R,switchWindow:L,closeWindow:V,toggleMinimize:J,floatWindow:ee,updateWindowProps:(De,Ee)=>f(De,Ee),clearPendingAction:d}),[t,N,j,R,L,V,J,ee,f,d]),G=l.useMemo(()=>({...O,buildRenderContext:E}),[t,j,N,E]),Re=H??"var(--rw-color-bg-tertiary)",Pe={display:"flex",...h?he(h):void 0,...x},pe={menuItems:i,onMenuClick:K,onAction:Y,activeWindowType:F,header:p,footer:w,defaultOpenKeys:ke(i),siderWidth:Z};return n.jsx(be,{value:G,children:n.jsxs("div",{className:`rw-workspace ${T||""} ${a||""}`.trim(),style:Pe,children:[q?q(pe):n.jsx(Se,{...pe}),n.jsx("main",{className:"rw-workspace-main",style:{background:Re},children:n.jsx(Oe,{spinning:m,tip:v,children:n.jsx(Ie,{workspaceId:t,windows:j,activeWindowId:N,renderWindow:U=>z(U,E(U,U.id===N&&!U.floating)),onSwitchWindow:L,onCloseWindow:V,onToggleMinimize:J,onBatchManage:c,onOpenWindow:R,onFloatWindow:ee,onRestoreWindow:le,onUpdateFloatingPosition:o,onFocusWindow:s,onReorderWindows:I,emptyDescription:$,tabsContainer:_,themeClassName:T,floatingDefaults:C})})})]})})});exports.FloatingWindow=ze;exports.WindowContainer=je;exports.WindowManager=Ie;exports.WindowTabs=Ce;exports.Workspace=rt;exports.WorkspaceProvider=be;exports.WorkspaceSidebar=Se;exports.collectParentMenuKeys=ke;exports.createWindowRenderer=Me;exports.findFirstMenuItemWithWindowType=me;exports.findMenuItem=We;exports.findMenuKeyByWindowType=ue;exports.fixWindowPosition=Q;exports.getAllWindowStatesFromStorage=ne;exports.labelToString=ge;exports.mapAntdTokenToCssVars=it;exports.mapAntdTokenToWorkspaceTheme=Te;exports.pickNextActiveWindowId=ae;exports.resolveDefaultWindow=Ne;exports.resolveWindowTitle=de;exports.saveWindowStateToStorage=re;exports.themeToCssVars=he;exports.updateTabClickOrder=oe;exports.useWorkspace=ye;exports.useWorkspaceContext=He;exports.useWorkspaceContextOptional=Xe;