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