@liuman/react-workspace 1.4.2 → 1.4.3
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-DsDjnfmH.cjs → Workspace-CGO5Pkso.cjs} +1 -1
- package/dist/{Workspace-BVDjjAYv.js → Workspace-CvNGfg2U.js} +45 -45
- package/dist/components/Workspace.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
|
@@ -1 +1 @@
|
|
|
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={minHeight:"100vh",height:"100vh",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;
|
|
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;
|
|
@@ -119,7 +119,7 @@ function Be(e, t) {
|
|
|
119
119
|
function ge() {
|
|
120
120
|
return `window-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`;
|
|
121
121
|
}
|
|
122
|
-
function
|
|
122
|
+
function Ae(e) {
|
|
123
123
|
const {
|
|
124
124
|
workspaceId: t,
|
|
125
125
|
defaultWindow: n,
|
|
@@ -141,14 +141,14 @@ function He(e) {
|
|
|
141
141
|
B.current = ye(g);
|
|
142
142
|
const L = Y(v);
|
|
143
143
|
L.current = v;
|
|
144
|
-
const [x, E] = te([]), [z,
|
|
144
|
+
const [x, E] = te([]), [z, A] = te(null), y = Y({}), b = R((r, o) => {
|
|
145
145
|
L.current?.(r, o);
|
|
146
|
-
}, []),
|
|
146
|
+
}, []), H = R(
|
|
147
147
|
(r) => ae(u, t)[r] || null,
|
|
148
148
|
[u, t]
|
|
149
149
|
), X = R(
|
|
150
|
-
(r) =>
|
|
151
|
-
[
|
|
150
|
+
(r) => H(r)?.position || null,
|
|
151
|
+
[H]
|
|
152
152
|
), T = R(
|
|
153
153
|
(r, o) => {
|
|
154
154
|
if (!i || !w) return;
|
|
@@ -167,12 +167,12 @@ function He(e) {
|
|
|
167
167
|
[i, w, f, h]
|
|
168
168
|
), m = R(
|
|
169
169
|
(r, o) => {
|
|
170
|
-
E(r),
|
|
170
|
+
E(r), A(o), T(r, o), b(r, o);
|
|
171
171
|
},
|
|
172
172
|
[T, b]
|
|
173
173
|
), U = R(
|
|
174
174
|
(r) => {
|
|
175
|
-
const o =
|
|
175
|
+
const o = H(r.type), a = {
|
|
176
176
|
...r,
|
|
177
177
|
minimized: o?.minimized ?? r.minimized ?? !1,
|
|
178
178
|
floating: o?.floating ?? r.floating ?? !1
|
|
@@ -183,7 +183,7 @@ function He(e) {
|
|
|
183
183
|
}
|
|
184
184
|
return a;
|
|
185
185
|
},
|
|
186
|
-
[
|
|
186
|
+
[H, X]
|
|
187
187
|
), K = R(() => {
|
|
188
188
|
const r = O.current, o = {
|
|
189
189
|
id: ge(),
|
|
@@ -209,7 +209,7 @@ function He(e) {
|
|
|
209
209
|
const a = Be(r, M.current);
|
|
210
210
|
if (a.length === 0) throw new Error("窗口列表是空的");
|
|
211
211
|
const d = a.map(U), c = Number(o), N = Number.isInteger(c) && c >= 0 && c < d.length ? d[c].id : d.find((Z) => Z.id === o)?.id ?? d[0]?.id ?? null;
|
|
212
|
-
E(d),
|
|
212
|
+
E(d), A(N), b(d, N);
|
|
213
213
|
} catch (a) {
|
|
214
214
|
console.error("[react-workspace] 解析窗口配置失败:", a), K();
|
|
215
215
|
}
|
|
@@ -465,12 +465,12 @@ function He(e) {
|
|
|
465
465
|
updateWindowTitle: G,
|
|
466
466
|
clearPendingAction: Q,
|
|
467
467
|
setWindows: E,
|
|
468
|
-
setActiveWindowId:
|
|
468
|
+
setActiveWindowId: A,
|
|
469
469
|
resetWorkspace: l,
|
|
470
470
|
reorderWindows: fe
|
|
471
471
|
};
|
|
472
472
|
}
|
|
473
|
-
const me = Te(null),
|
|
473
|
+
const me = Te(null), He = me.Provider;
|
|
474
474
|
function ht() {
|
|
475
475
|
const e = ve(me);
|
|
476
476
|
if (!e)
|
|
@@ -554,8 +554,8 @@ const Ve = ({
|
|
|
554
554
|
const [v, j] = te(!1), [M, O] = te(new Set(w)), B = le(() => i ? We(e, i) : null, [i, e]), L = () => {
|
|
555
555
|
j((y) => (g?.(!y), !y));
|
|
556
556
|
}, x = (y, b) => {
|
|
557
|
-
b?.stopPropagation(), O((
|
|
558
|
-
const X = new Set(
|
|
557
|
+
b?.stopPropagation(), O((H) => {
|
|
558
|
+
const X = new Set(H);
|
|
559
559
|
return X.has(y) ? X.delete(y) : X.add(y), X;
|
|
560
560
|
});
|
|
561
561
|
}, E = (y) => {
|
|
@@ -570,10 +570,10 @@ const Ve = ({
|
|
|
570
570
|
}
|
|
571
571
|
y.children?.length && x(y.key);
|
|
572
572
|
}
|
|
573
|
-
}, z = (y, b = 0) => y.map((
|
|
574
|
-
if (Je(
|
|
575
|
-
return /* @__PURE__ */ s("div", { className: "rw-menu-divider" },
|
|
576
|
-
const T =
|
|
573
|
+
}, z = (y, b = 0) => y.map((H, X) => {
|
|
574
|
+
if (Je(H))
|
|
575
|
+
return /* @__PURE__ */ s("div", { className: "rw-menu-divider" }, H.key ?? `div-${X}`);
|
|
576
|
+
const T = H, m = !!T.children?.length, U = M.has(T.key), K = T.key === B;
|
|
577
577
|
return /* @__PURE__ */ _("div", { className: "rw-menu-group", children: [
|
|
578
578
|
/* @__PURE__ */ _(
|
|
579
579
|
"button",
|
|
@@ -601,9 +601,9 @@ const Ve = ({
|
|
|
601
601
|
),
|
|
602
602
|
!v && m && U && /* @__PURE__ */ s("div", { className: "rw-menu-children", children: z(T.children, b + 1) })
|
|
603
603
|
] }, T.key);
|
|
604
|
-
}),
|
|
604
|
+
}), A = v ? 64 : u;
|
|
605
605
|
return /* @__PURE__ */ _("div", { className: "rw-workspace-sidebar-wrapper", children: [
|
|
606
|
-
/* @__PURE__ */ _("aside", { className: "rw-workspace-sider", style: { width:
|
|
606
|
+
/* @__PURE__ */ _("aside", { className: "rw-workspace-sider", style: { width: A }, children: [
|
|
607
607
|
f && /* @__PURE__ */ s("div", { className: `rw-workspace-sidebar-header ${v ? "collapsed" : ""}`, children: f }),
|
|
608
608
|
/* @__PURE__ */ s("nav", { className: "rw-workspace-sidebar-menu", children: z(e) }),
|
|
609
609
|
h && /* @__PURE__ */ s("div", { className: `rw-workspace-sidebar-footer ${v ? "collapsed" : ""}`, children: h })
|
|
@@ -613,7 +613,7 @@ const Ve = ({
|
|
|
613
613
|
{
|
|
614
614
|
type: "button",
|
|
615
615
|
className: "rw-workspace-collapse-button",
|
|
616
|
-
style: { left:
|
|
616
|
+
style: { left: A },
|
|
617
617
|
onClick: L,
|
|
618
618
|
title: v ? "展开导航" : "折叠导航",
|
|
619
619
|
children: v ? /* @__PURE__ */ s(_e, {}) : /* @__PURE__ */ s(Ye, {})
|
|
@@ -674,7 +674,7 @@ const Ve = ({
|
|
|
674
674
|
themeClassName: j,
|
|
675
675
|
allWindows: M = e
|
|
676
676
|
}) => {
|
|
677
|
-
const O = e.findIndex((l) => l.id === t), B = Y(null), L = Y(null), [x, E] = te(null), [z,
|
|
677
|
+
const O = e.findIndex((l) => l.id === t), B = Y(null), L = Y(null), [x, E] = te(null), [z, A] = te(null), y = Y({ windowId: "", startX: 0, startY: 0, fromIndex: -1, mode: "none", floated: !1 }), b = R((l) => {
|
|
678
678
|
const p = L.current;
|
|
679
679
|
if (!p) return e.length;
|
|
680
680
|
const W = p.getBoundingClientRect(), S = l - W.left, I = p.querySelectorAll(".rw-tab-item");
|
|
@@ -684,7 +684,7 @@ const Ve = ({
|
|
|
684
684
|
if (S < C) return D;
|
|
685
685
|
}
|
|
686
686
|
return I.length;
|
|
687
|
-
}, [e.length]),
|
|
687
|
+
}, [e.length]), H = R(
|
|
688
688
|
(l, p, W) => {
|
|
689
689
|
if (l.target.closest(".rw-window-tab-close-btn") || l.button !== 0) return;
|
|
690
690
|
y.current = { windowId: p, startX: l.clientX, startY: l.clientY, fromIndex: W, mode: "none", floated: !1 };
|
|
@@ -716,10 +716,10 @@ const Ve = ({
|
|
|
716
716
|
const p = (I) => {
|
|
717
717
|
const { windowTitle: D, clientX: k } = I.detail, C = b(k);
|
|
718
718
|
l && cancelAnimationFrame(l), l = requestAnimationFrame(() => {
|
|
719
|
-
|
|
719
|
+
A({ title: D, index: C }), E(C);
|
|
720
720
|
});
|
|
721
721
|
}, W = () => {
|
|
722
|
-
|
|
722
|
+
A(null), E(null);
|
|
723
723
|
}, S = B.current;
|
|
724
724
|
return S?.addEventListener("floatingWindowDragOver", p), S?.addEventListener("clearFloatingWindowPreview", W), () => {
|
|
725
725
|
S?.removeEventListener("floatingWindowDragOver", p), S?.removeEventListener("clearFloatingWindowPreview", W), l && cancelAnimationFrame(l);
|
|
@@ -731,7 +731,7 @@ const Ve = ({
|
|
|
731
731
|
{
|
|
732
732
|
className: `rw-tab-item ${p.id === t ? "active" : ""}`,
|
|
733
733
|
onClick: () => n(p.id),
|
|
734
|
-
onMouseDown: (S) =>
|
|
734
|
+
onMouseDown: (S) => H(S, p.id, W),
|
|
735
735
|
children: [
|
|
736
736
|
/* @__PURE__ */ s("span", { className: "rw-tab-title", children: p.title }),
|
|
737
737
|
/* @__PURE__ */ s(
|
|
@@ -759,7 +759,7 @@ const Ve = ({
|
|
|
759
759
|
l.preventDefault();
|
|
760
760
|
try {
|
|
761
761
|
const p = sessionStorage.getItem("draggingWindowTitle");
|
|
762
|
-
p &&
|
|
762
|
+
p && A({ title: p, index: b(l.clientX) });
|
|
763
763
|
} catch {
|
|
764
764
|
}
|
|
765
765
|
E(b(l.clientX));
|
|
@@ -771,7 +771,7 @@ const Ve = ({
|
|
|
771
771
|
p = sessionStorage.getItem("draggingWindowId") || "";
|
|
772
772
|
} catch {
|
|
773
773
|
}
|
|
774
|
-
p && u && u(p, x ?? void 0),
|
|
774
|
+
p && u && u(p, x ?? void 0), A(null), E(null);
|
|
775
775
|
}, K = [
|
|
776
776
|
...M.length === 0 ? [] : [
|
|
777
777
|
...M.map((l) => ({
|
|
@@ -806,7 +806,7 @@ const Ve = ({
|
|
|
806
806
|
ref: B,
|
|
807
807
|
onDragOver: T,
|
|
808
808
|
onDragLeave: () => {
|
|
809
|
-
|
|
809
|
+
A(null), E(null);
|
|
810
810
|
},
|
|
811
811
|
onDrop: m,
|
|
812
812
|
children: /* @__PURE__ */ _("div", { className: "rw-window-tabs-container", children: [
|
|
@@ -861,7 +861,7 @@ const Ve = ({
|
|
|
861
861
|
onToggleMinimize: w,
|
|
862
862
|
onFocusWindow: u
|
|
863
863
|
}) => {
|
|
864
|
-
const g = { ...it, ...n }, v = Y(null), j = Y(null), [M, O] = te(!1), [B, L] = te(!1), [x, E] = te(!1), z = Y(!1),
|
|
864
|
+
const g = { ...it, ...n }, v = Y(null), j = Y(null), [M, O] = te(!1), [B, L] = te(!1), [x, E] = te(!1), z = Y(!1), A = Y(""), y = Y({ x: 0, y: 0, startX: 0, startY: 0, startWidth: 0, startHeight: 0 }), b = Y({ x: 0, y: 0, width: 0, height: 0, startX: 0, startY: 0 }), H = Y(null), X = Y(null), T = Y(null), m = e.floatingPosition || { x: g.x, y: g.y, width: g.width, height: g.height };
|
|
865
865
|
ne(() => {
|
|
866
866
|
if (!e.pendingDragStart || M || B) return;
|
|
867
867
|
let l = m.x, p = m.y;
|
|
@@ -913,7 +913,7 @@ const Ve = ({
|
|
|
913
913
|
const k = v.current.getBoundingClientRect();
|
|
914
914
|
W = k.left, S = k.top, I = k.width, D = k.height;
|
|
915
915
|
}
|
|
916
|
-
L(!0),
|
|
916
|
+
L(!0), A.current = p, b.current = { x: l.clientX, y: l.clientY, width: I, height: D, startX: W, startY: S };
|
|
917
917
|
}, [m, e.id, u]);
|
|
918
918
|
return ne(() => {
|
|
919
919
|
const l = (W) => {
|
|
@@ -928,7 +928,7 @@ const Ve = ({
|
|
|
928
928
|
v.current.style.transform = `translate(${k}px, ${C}px)`, X.current = { x: k, y: C, width: y.current.startWidth, height: y.current.startHeight };
|
|
929
929
|
} else if (B) {
|
|
930
930
|
W.preventDefault();
|
|
931
|
-
const S =
|
|
931
|
+
const S = A.current, I = b.current;
|
|
932
932
|
let D = I.startX, k = I.startY, C = I.width, P = I.height;
|
|
933
933
|
const F = W.clientX - I.x, G = W.clientY - I.y;
|
|
934
934
|
S.includes("e") && (C = Math.max(g.minWidth, I.width + F)), S.includes("w") && (C = Math.max(g.minWidth, I.width - F), D = I.startX + I.width - C), S.includes("s") && (P = Math.max(g.minHeight, I.height + G)), S.includes("n") && (P = Math.max(g.minHeight, I.height - G), k = I.startY + I.height - P);
|
|
@@ -964,7 +964,7 @@ const Ve = ({
|
|
|
964
964
|
};
|
|
965
965
|
if (M || B) {
|
|
966
966
|
const W = (S) => {
|
|
967
|
-
|
|
967
|
+
H.current && cancelAnimationFrame(H.current), H.current = requestAnimationFrame(() => l(S));
|
|
968
968
|
};
|
|
969
969
|
return document.addEventListener("mousemove", W, { passive: !1 }), document.addEventListener("mouseup", p), document.body.style.userSelect = "none", () => {
|
|
970
970
|
document.removeEventListener("mousemove", W), document.removeEventListener("mouseup", p), document.body.style.userSelect = "";
|
|
@@ -1021,10 +1021,10 @@ const Ve = ({
|
|
|
1021
1021
|
}) => {
|
|
1022
1022
|
if (e.length === 0)
|
|
1023
1023
|
return /* @__PURE__ */ s("div", { className: "rw-window-manager-empty", children: /* @__PURE__ */ s(Ge, { description: O }) });
|
|
1024
|
-
const E = e.filter((b) => b.minimized), z = e.filter((b) => b.floating && !b.minimized),
|
|
1024
|
+
const E = e.filter((b) => b.minimized), z = e.filter((b) => b.floating && !b.minimized), A = e.filter((b) => !b.minimized && !b.floating), y = /* @__PURE__ */ s(
|
|
1025
1025
|
tt,
|
|
1026
1026
|
{
|
|
1027
|
-
windows:
|
|
1027
|
+
windows: A,
|
|
1028
1028
|
activeWindowId: t,
|
|
1029
1029
|
onSwitchWindow: i,
|
|
1030
1030
|
onCloseWindow: f,
|
|
@@ -1040,7 +1040,7 @@ const Ve = ({
|
|
|
1040
1040
|
);
|
|
1041
1041
|
return /* @__PURE__ */ _("div", { className: "rw-window-manager", children: [
|
|
1042
1042
|
L ? Re(y, L) : y,
|
|
1043
|
-
/* @__PURE__ */ s("div", { className: "rw-window-content-area", children:
|
|
1043
|
+
/* @__PURE__ */ s("div", { className: "rw-window-content-area", children: A.map((b) => /* @__PURE__ */ s(Qe, { window: b, active: b.id === t, children: n(b, {}) }, b.id)) }),
|
|
1044
1044
|
E.length > 0 && /* @__PURE__ */ s("div", { className: "rw-minimized-windows-bar", children: E.map((b) => /* @__PURE__ */ _(
|
|
1045
1045
|
"div",
|
|
1046
1046
|
{
|
|
@@ -1049,7 +1049,7 @@ const Ve = ({
|
|
|
1049
1049
|
title: b.floating ? `${b.title} (浮动窗口)` : b.title,
|
|
1050
1050
|
role: "button",
|
|
1051
1051
|
tabIndex: 0,
|
|
1052
|
-
onKeyDown: (
|
|
1052
|
+
onKeyDown: (H) => H.key === "Enter" && h(b.id),
|
|
1053
1053
|
children: [
|
|
1054
1054
|
/* @__PURE__ */ s("span", { children: b.title }),
|
|
1055
1055
|
b.floating && /* @__PURE__ */ s("span", { className: "rw-minimized-floating-badge", children: "🔲" })
|
|
@@ -1174,10 +1174,10 @@ const yt = De(function({
|
|
|
1174
1174
|
searchParams: x,
|
|
1175
1175
|
setSearchParams: E,
|
|
1176
1176
|
floatingDefaults: z,
|
|
1177
|
-
onWindowsChange:
|
|
1177
|
+
onWindowsChange: A,
|
|
1178
1178
|
resolveTitle: y,
|
|
1179
1179
|
onReady: b,
|
|
1180
|
-
siderWidth:
|
|
1180
|
+
siderWidth: H = 240,
|
|
1181
1181
|
contentBackground: X,
|
|
1182
1182
|
themeClassName: T,
|
|
1183
1183
|
theme: m,
|
|
@@ -1193,7 +1193,7 @@ const yt = De(function({
|
|
|
1193
1193
|
if (i) return i;
|
|
1194
1194
|
if (f) return at(f);
|
|
1195
1195
|
throw new Error("[react-workspace] 请提供 renderWindow 或 windows");
|
|
1196
|
-
}, [i, f]), D =
|
|
1196
|
+
}, [i, f]), D = Ae({
|
|
1197
1197
|
workspaceId: t,
|
|
1198
1198
|
defaultWindow: S,
|
|
1199
1199
|
syncToUrl: B,
|
|
@@ -1201,7 +1201,7 @@ const yt = De(function({
|
|
|
1201
1201
|
searchParams: x,
|
|
1202
1202
|
setSearchParams: E,
|
|
1203
1203
|
floatingDefaults: z,
|
|
1204
|
-
onWindowsChange:
|
|
1204
|
+
onWindowsChange: A,
|
|
1205
1205
|
// 恢复窗口标题:使用者给的优先(详情类窗口要按参数拼),
|
|
1206
1206
|
// 其次按类型去菜单里查,都查不到就退回类型本身。
|
|
1207
1207
|
resolveTitle: (V, se) => y?.(V, se) ?? be(n, V)
|
|
@@ -1247,7 +1247,7 @@ const yt = De(function({
|
|
|
1247
1247
|
), ee = le(
|
|
1248
1248
|
() => ({ ...Z, buildRenderContext: $ }),
|
|
1249
1249
|
[t, k, C, $]
|
|
1250
|
-
), Ie = X ?? "var(--rw-color-bg-tertiary)", Ne = {
|
|
1250
|
+
), Ie = X ?? "var(--rw-color-bg-tertiary)", Ne = { display: "flex", ...m ? ze(m) : void 0, ...p }, he = {
|
|
1251
1251
|
menuItems: n,
|
|
1252
1252
|
onMenuClick: J,
|
|
1253
1253
|
onAction: j,
|
|
@@ -1255,9 +1255,9 @@ const yt = De(function({
|
|
|
1255
1255
|
header: h,
|
|
1256
1256
|
footer: w,
|
|
1257
1257
|
defaultOpenKeys: Ke(n),
|
|
1258
|
-
siderWidth:
|
|
1258
|
+
siderWidth: H
|
|
1259
1259
|
};
|
|
1260
|
-
return /* @__PURE__ */ s(
|
|
1260
|
+
return /* @__PURE__ */ s(He, { value: ee, children: /* @__PURE__ */ _(
|
|
1261
1261
|
"div",
|
|
1262
1262
|
{
|
|
1263
1263
|
className: `rw-workspace ${T || ""} ${l || ""}`.trim(),
|
|
@@ -1297,7 +1297,7 @@ export {
|
|
|
1297
1297
|
ot as a,
|
|
1298
1298
|
tt as b,
|
|
1299
1299
|
yt as c,
|
|
1300
|
-
|
|
1300
|
+
He as d,
|
|
1301
1301
|
Ve as e,
|
|
1302
1302
|
Ke as f,
|
|
1303
1303
|
at as g,
|
|
@@ -1315,7 +1315,7 @@ export {
|
|
|
1315
1315
|
ce as s,
|
|
1316
1316
|
ze as t,
|
|
1317
1317
|
ue as u,
|
|
1318
|
-
|
|
1318
|
+
Ae as v,
|
|
1319
1319
|
ht as w,
|
|
1320
1320
|
pt as x
|
|
1321
1321
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Workspace.d.ts","sourceRoot":"","sources":["../../src/components/Workspace.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAA2E,MAAM,OAAO,CAAC;AAUhG,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAkE,MAAM,UAAU,CAAC;AAC7H,OAAO,qBAAqB,CAAC;AAC7B,OAAO,yBAAyB,CAAC;AAEjC,eAAO,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"Workspace.d.ts","sourceRoot":"","sources":["../../src/components/Workspace.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAA2E,MAAM,OAAO,CAAC;AAUhG,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAkE,MAAM,UAAU,CAAC;AAC7H,OAAO,qBAAqB,CAAC;AAC7B,OAAO,yBAAyB,CAAC;AAEjC,eAAO,MAAM,SAAS,kGAgLpB,CAAC;AAEH,eAAe,SAAS,CAAC"}
|
|
@@ -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-
|
|
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;
|
|
@@ -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-
|
|
6
|
-
import { n as z } from "./Workspace-
|
|
5
|
+
import { j as S, o as W, c as j } from "./Workspace-CvNGfg2U.js";
|
|
6
|
+
import { n as z } from "./Workspace-CvNGfg2U.js";
|
|
7
7
|
const { Sider: $ } = N;
|
|
8
8
|
function k(r) {
|
|
9
9
|
return "type" in r && r.type === "divider";
|
package/dist/react-workspace.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./Workspace-
|
|
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;
|
package/dist/react-workspace.js
CHANGED
|
@@ -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-
|
|
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";
|
|
2
2
|
export {
|
|
3
3
|
s as FloatingWindow,
|
|
4
4
|
o as WindowContainer,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liuman/react-workspace",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3",
|
|
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",
|