@liuman/react-workspace 1.2.1 → 1.3.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/README.md +88 -37
- package/dist/Workspace-D7d8kiGm.cjs +1 -0
- package/dist/Workspace-MEGCvs9U.js +1251 -0
- package/dist/antd.d.ts +193 -0
- package/dist/components/FloatingWindow.d.ts.map +1 -1
- package/dist/components/WindowTabs.d.ts.map +1 -1
- package/dist/components/Workspace.d.ts.map +1 -1
- package/dist/hooks/useWorkspace.d.ts.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/integrations/AntdWorkspace.d.ts +26 -0
- package/dist/integrations/AntdWorkspace.d.ts.map +1 -0
- package/dist/integrations/antd.d.ts +2 -0
- package/dist/integrations/antd.d.ts.map +1 -1
- package/dist/react-workspace-antd.cjs +1 -1
- package/dist/react-workspace-antd.js +74 -42
- package/dist/react-workspace.cjs +1 -1
- package/dist/react-workspace.css +1 -1
- package/dist/react-workspace.js +28 -1140
- package/dist/types.d.ts +21 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/createWindowRenderer.d.ts +15 -0
- package/dist/utils/createWindowRenderer.d.ts.map +1 -0
- package/dist/utils/resolveDefaultWindow.d.ts +6 -0
- package/dist/utils/resolveDefaultWindow.d.ts.map +1 -0
- package/dist/utils/windowStorage.d.ts +6 -2
- package/dist/utils/windowStorage.d.ts.map +1 -1
- package/package.json +2 -3
- package/dist/hooks/useKeyboardShortcuts.d.ts +0 -14
- package/dist/hooks/useKeyboardShortcuts.d.ts.map +0 -1
- package/dist/theme-CzPgEJDm.js +0 -113
- package/dist/theme-DIsh66tX.cjs +0 -1
package/README.md
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
## 特性
|
|
6
6
|
|
|
7
|
+
- **开箱即用** — `AntdWorkspace` + `windows` 映射,最少配置即可运行
|
|
7
8
|
- **零 UI 框架依赖** — 不依赖 antd,仅 React + CSS
|
|
8
9
|
- **多窗口标签页** — 打开、切换、关闭、最小化
|
|
9
10
|
- **标签拖拽排序** — 水平拖动标签调整顺序
|
|
10
11
|
- **浮动窗口** — 拖出为独立窗口,可调整大小,拖回标签栏还原
|
|
11
|
-
- **键盘快捷键** — `Ctrl/Cmd+W` 关闭,`Ctrl/Cmd+Tab` 切换
|
|
12
12
|
- **CSS 主题变量** — 支持亮色/暗色主题定制
|
|
13
13
|
- **URL 状态同步** — 刷新恢复、分享链接
|
|
14
14
|
- **localStorage 持久化** — 浮动窗口位置自动保存
|
|
@@ -30,50 +30,91 @@ yarn add react-router-dom
|
|
|
30
30
|
|
|
31
31
|
## 快速开始
|
|
32
32
|
|
|
33
|
+
### 开箱即用(Ant Design,推荐)
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
yarn add @liuman/react-workspace antd @ant-design/icons
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
import { AntdWorkspace } from '@liuman/react-workspace/antd';
|
|
41
|
+
import '@liuman/react-workspace/style.css';
|
|
42
|
+
|
|
43
|
+
function HomePage() {
|
|
44
|
+
return <div style={{ padding: 24 }}>欢迎!</div>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default function App() {
|
|
48
|
+
return (
|
|
49
|
+
<AntdWorkspace
|
|
50
|
+
menuItems={[
|
|
51
|
+
{ key: 'home', label: '首页', windowType: 'home' },
|
|
52
|
+
]}
|
|
53
|
+
windows={{ home: HomePage }}
|
|
54
|
+
/>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`AntdWorkspace` 已内置:ConfigProvider、Ant Design 侧边栏、主题同步。
|
|
60
|
+
`defaultWindow` 会自动从 `menuItems` 第一项推断,无需手动配置。
|
|
61
|
+
|
|
62
|
+
### 零依赖用法
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
import { Workspace } from '@liuman/react-workspace';
|
|
66
|
+
import '@liuman/react-workspace/style.css';
|
|
67
|
+
|
|
68
|
+
function HomePage() {
|
|
69
|
+
return <div style={{ padding: 24 }}>欢迎!</div>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export default function App() {
|
|
73
|
+
return (
|
|
74
|
+
<Workspace
|
|
75
|
+
menuItems={[
|
|
76
|
+
{ key: 'home', label: '首页', windowType: 'home' },
|
|
77
|
+
]}
|
|
78
|
+
windows={{ home: HomePage }}
|
|
79
|
+
/>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 完整示例(URL 同步 + 自定义区域)
|
|
85
|
+
|
|
33
86
|
```tsx
|
|
34
87
|
import { Workspace } from '@liuman/react-workspace';
|
|
35
88
|
import '@liuman/react-workspace/style.css';
|
|
36
89
|
import { useSearchParams } from 'react-router-dom';
|
|
37
90
|
import { HomeOutlined, SettingOutlined } from '@ant-design/icons';
|
|
38
91
|
|
|
92
|
+
function HomePage() {
|
|
93
|
+
return <div style={{ padding: 24 }}>欢迎!</div>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function SettingsPage() {
|
|
97
|
+
return <div style={{ padding: 24 }}>设置页面</div>;
|
|
98
|
+
}
|
|
99
|
+
|
|
39
100
|
function App() {
|
|
40
101
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
41
102
|
|
|
42
103
|
const menuItems = [
|
|
43
|
-
{
|
|
44
|
-
|
|
45
|
-
icon: <HomeOutlined />,
|
|
46
|
-
label: '首页',
|
|
47
|
-
windowType: 'home',
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
key: 'settings',
|
|
51
|
-
icon: <SettingOutlined />,
|
|
52
|
-
label: '设置',
|
|
53
|
-
windowType: 'settings',
|
|
54
|
-
},
|
|
104
|
+
{ key: 'home', icon: <HomeOutlined />, label: '首页', windowType: 'home' },
|
|
105
|
+
{ key: 'settings', icon: <SettingOutlined />, label: '设置', windowType: 'settings' },
|
|
55
106
|
];
|
|
56
107
|
|
|
57
108
|
return (
|
|
58
109
|
<Workspace
|
|
59
110
|
workspaceId="my-app"
|
|
60
111
|
menuItems={menuItems}
|
|
61
|
-
|
|
112
|
+
windows={{ home: HomePage, settings: SettingsPage }}
|
|
62
113
|
syncToUrl
|
|
63
114
|
searchParams={searchParams}
|
|
64
115
|
setSearchParams={setSearchParams}
|
|
65
116
|
sidebarHeader={<div>我的工作区</div>}
|
|
66
117
|
sidebarFooter={<div>用户信息</div>}
|
|
67
|
-
renderWindow={(window, ctx) => {
|
|
68
|
-
switch (window.type) {
|
|
69
|
-
case 'home':
|
|
70
|
-
return <div style={{ padding: 24 }}>欢迎!</div>;
|
|
71
|
-
case 'settings':
|
|
72
|
-
return <div style={{ padding: 24 }}>设置页面</div>;
|
|
73
|
-
default:
|
|
74
|
-
return <div>未知窗口: {window.type}</div>;
|
|
75
|
-
}
|
|
76
|
-
}}
|
|
77
118
|
/>
|
|
78
119
|
);
|
|
79
120
|
}
|
|
@@ -85,10 +126,11 @@ function App() {
|
|
|
85
126
|
|
|
86
127
|
| 属性 | 类型 | 默认值 | 说明 |
|
|
87
128
|
|------|------|--------|------|
|
|
88
|
-
| `workspaceId` | `string` |
|
|
129
|
+
| `workspaceId` | `string` | `'default'` | 工作区唯一标识,用于 localStorage 隔离 |
|
|
89
130
|
| `menuItems` | `SidebarMenuEntry[]` | 必填 | 侧边栏菜单(支持 `{ type: 'divider' }` 分隔线) |
|
|
90
|
-
| `
|
|
91
|
-
| `
|
|
131
|
+
| `windows` | `Record<string, Component>` | - | 窗口类型 → 组件映射(推荐,与 renderWindow 二选一) |
|
|
132
|
+
| `renderWindow` | `(window, ctx) => ReactNode` | - | 自定义渲染窗口(与 windows 二选一) |
|
|
133
|
+
| `defaultWindow` | `{ type, title }` | 自动从菜单推断 | 默认打开的窗口 |
|
|
92
134
|
| `sidebarHeader` | `ReactNode` | - | 侧边栏顶部区域 |
|
|
93
135
|
| `sidebarFooter` | `ReactNode` | - | 侧边栏底部区域(固定底部) |
|
|
94
136
|
| `loading` | `boolean` | `false` | 加载状态 |
|
|
@@ -100,12 +142,22 @@ function App() {
|
|
|
100
142
|
| `ref` | `WorkspaceRef` | - | 暴露完整工作区 API |
|
|
101
143
|
| `siderWidth` | `number` | `240` | 侧边栏宽度 |
|
|
102
144
|
| `contentBackground` | `string` | `#f0f2f5` | 内容区背景色 |
|
|
103
|
-
| `enableKeyboardShortcuts` | `boolean` | `true` | Ctrl+W / Ctrl+Tab |
|
|
104
145
|
| `themeClassName` | `string` | - | 如 `rw-theme-dark` 启用暗色主题 |
|
|
105
146
|
| `theme` | `WorkspaceTheme` | - | 通过 props 覆盖 CSS 变量(可与 antd token 映射) |
|
|
106
147
|
| `renderSidebar` | `(props) => ReactNode` | - | 自定义侧边栏,例如 Ant Design Menu |
|
|
107
148
|
|
|
108
|
-
###
|
|
149
|
+
### `<AntdWorkspace />`(`@liuman/react-workspace/antd`)
|
|
150
|
+
|
|
151
|
+
在 `Workspace` 基础上内置 ConfigProvider、Ant Design 侧边栏与主题同步。
|
|
152
|
+
Props 与 `Workspace` 相同(除 `renderSidebar` / `theme` / `themeClassName`),额外支持:
|
|
153
|
+
|
|
154
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
155
|
+
|------|------|--------|------|
|
|
156
|
+
| `dark` | `boolean` | `false` | 暗色模式 |
|
|
157
|
+
| `sidebarTheme` | `'light' \| 'dark'` | 跟随 `dark` | 侧边栏主题 |
|
|
158
|
+
| `antdTheme` | `ThemeConfig` | - | 透传给 antd ConfigProvider |
|
|
159
|
+
|
|
160
|
+
### 与 Ant Design 手动集成
|
|
109
161
|
|
|
110
162
|
库核心**零 antd 依赖**,但可无缝配合 Ant Design 使用:
|
|
111
163
|
|
|
@@ -185,14 +237,6 @@ renderWindow={(window) => {
|
|
|
185
237
|
<Workspace className="my-workspace" themeClassName="rw-theme-dark" ... />
|
|
186
238
|
```
|
|
187
239
|
|
|
188
|
-
### 快捷键
|
|
189
|
-
|
|
190
|
-
| 快捷键 | 操作 |
|
|
191
|
-
|--------|------|
|
|
192
|
-
| `Ctrl/Cmd + W` | 关闭当前窗口 |
|
|
193
|
-
| `Ctrl/Cmd + Tab` | 切换到下一个窗口 |
|
|
194
|
-
| `Ctrl/Cmd + Shift + Tab` | 切换到上一个窗口 |
|
|
195
|
-
|
|
196
240
|
### 主题定制
|
|
197
241
|
|
|
198
242
|
```css
|
|
@@ -451,6 +495,13 @@ yarn add @liuman/react-workspace
|
|
|
451
495
|
|
|
452
496
|
## 版本历史
|
|
453
497
|
|
|
498
|
+
### v1.3.0
|
|
499
|
+
- 新增 `AntdWorkspace` 开箱即用组件
|
|
500
|
+
- 新增 `windows` 映射表,简化调用(无需手写 renderWindow switch)
|
|
501
|
+
- `defaultWindow` 自动从菜单推断
|
|
502
|
+
- 移除键盘快捷键;优化标签关闭按钮与暗色主题
|
|
503
|
+
- 修复浮动窗口拖出时超出屏幕问题
|
|
504
|
+
|
|
454
505
|
### v1.2.0
|
|
455
506
|
- 修复侧边栏 footer 遮挡菜单、loading 遮罩覆盖侧边栏等问题
|
|
456
507
|
- 优化默认 UI(标签高亮、菜单选中态)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const n=require("react/jsx-runtime"),a=require("react"),De=({tip:e="加载中...",spinning:t=!1,children:l})=>n.jsxs("div",{className:"rw-spinner-wrap",children:[l,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 l=globalThis.window.innerWidth,s=globalThis.window.innerHeight,p=Math.min(t?.minWidth??me,l),x=Math.min(t?.minHeight??me,s);let{x:y,y:u,width:g,height:b}=e;return g=Math.min(g,l),b=Math.min(b,s),g=Math.max(g,p),b=Math.max(b,x),y+g>l&&(y=Math.max(0,l-g)),u+b>s&&(u=Math.max(0,s-b)),y<0&&(y=0),u<0&&(u=0),{x:y,y:u,width:g,height:b}}function oe(e,t){return`${e}${t}`}function ne(e,t){if(!t)return{};try{const l=oe(e,t),s=localStorage.getItem(l);if(s){const p=JSON.parse(s);if(p&&typeof p=="object"){const x={};return Object.entries(p).forEach(([y,u])=>{if(u&&typeof u=="object"){const g=u,b={};g.position&&typeof g.position.x=="number"&&typeof g.position.y=="number"&&typeof g.position.width=="number"&&typeof g.position.height=="number"&&(b.position=Q(g.position)),typeof g.minimized=="boolean"&&(b.minimized=g.minimized),typeof g.floating=="boolean"&&(b.floating=g.floating),typeof g.floatingZIndex=="number"&&(b.floatingZIndex=g.floatingZIndex),x[y]=b}}),x}}}catch(l){console.warn("[react-workspace] 从 localStorage 读取窗口状态失败:",l)}return{}}function ie(e,t,l,s){if(t)try{const p=ne(e,t);p[l]={...p[l],...s},localStorage.setItem(oe(e,t),JSON.stringify(p))}catch(p){console.warn("[react-workspace] 保存窗口状态到 localStorage 失败:",p)}}function re(e,t,l){if(t)try{const s=oe(e,t),p=localStorage.getItem(s);let x=p?JSON.parse(p):{};const y=Object.values(x).map(M=>M?.floatingZIndex||0).filter(M=>M>=1e3),u=y.length>0?Math.max(...y):999,g=x[l]||{},b=g.floatingZIndex||0,H=Math.max(1e3,u+1);b>=1e3?(x[l]={...g,floatingZIndex:H},Object.keys(x).forEach(M=>{if(M!==l&&x[M]){const E=x[M];E.floatingZIndex!==void 0&&E.floatingZIndex>=1e3&&(x[M]={...E,floatingZIndex:Math.max(1e3,E.floatingZIndex-1)})}})):x[l]={...g,floatingZIndex:H},localStorage.setItem(s,JSON.stringify(x))}catch(s){console.error("[react-workspace] 保存标签点击顺序失败:",s)}}function le(e,t,l){if(e.length===0)return null;try{const s=localStorage.getItem(oe(t,l));if(s){const p=JSON.parse(s);return[...e].sort((y,u)=>{const g=p[y.type]?.floatingZIndex||0,b=p[u.type]?.floatingZIndex||0;return g>=1e3&&b>=1e3?b-g:g>=1e3?-1:b>=1e3?1:0})[0]?.id??e[e.length-1].id}}catch{}return e[e.length-1].id}const Ee="react_workspace_windows_",Oe={x:100,y:100,width:800,height:600,minWidth:400,minHeight:300};function he(e){return{...Oe,...e}}function pe(){return`window-${Date.now()}-${Math.random().toString(36).slice(2,7)}`}function xe(e){const{workspaceId:t,defaultWindow:l,syncToUrl:s=!1,preserveUrlParams:p=!0,searchParams:x,setSearchParams:y,storageKeyPrefix:u=Ee,floatingDefaults:g,onWindowsChange:b}=e,H=a.useRef(l??{type:"home",title:"首页",minimized:!1});H.current=l??H.current;const M=a.useRef(he(g));M.current=he(g);const E=a.useRef(b);E.current=b;const[w,T]=a.useState([]),[j,O]=a.useState(null),[h,B]=a.useState({}),k=a.useCallback((o,i)=>{E.current?.(o,i)},[]),_=a.useCallback(o=>ne(u,t)[o]||null,[u,t]),X=a.useCallback(o=>_(o)?.position||null,[_]),Z=a.useCallback((o,i)=>{if(!s||!y)return;const c=p&&x?new URLSearchParams(x):new URLSearchParams;o.length>0?c.set("windows",encodeURIComponent(JSON.stringify(o.map(d=>({id:d.id,type:d.type,title:d.title}))))):c.delete("windows"),i?c.set("active",i):c.delete("active"),y(c,{replace:!0})},[s,y,p,x]),r=a.useCallback((o,i)=>{T(o),O(i),Z(o,i),k(o,i)},[Z,k]),f=a.useCallback(o=>{const i=_(o.type),c={...o,minimized:i?.minimized??o.minimized??!1,floating:i?.floating??o.floating??!1};if(c.floating){let d=o.floatingPosition||i?.position;d||(d=X(o.type)??void 0),d&&(c.floatingPosition=Q(d)),c.floatingZIndex=i?.floatingZIndex??o.floatingZIndex??1e3}return c},[_,X]),R=a.useCallback(()=>{const o=H.current,i={id:pe(),type:o.type,title:o.title,minimized:o.minimized??!1};r([i],i.id)},[r]),$=a.useCallback(()=>{if(t)try{localStorage.removeItem(`${u}${t}`)}catch{}B(o=>{const i={...o};return delete i[t],i}),R()},[t,u,R]);a.useEffect(()=>{if(!t||h[t])return;const o=s?x?.get("windows"):null,i=s?x?.get("active"):null;if(o)try{const d=JSON.parse(decodeURIComponent(o)).map(f),m=i&&d.some(z=>z.id===i)?i:d[0]?.id??null;T(d),O(m),k(d,m)}catch(c){console.error("[react-workspace] 解析窗口配置失败:",c),R()}else R();B(c=>({...c,[t]:!0}))},[t,x,s,h,f,R,k]);const S=a.useCallback((o,i)=>{const c=i!==void 0?{...o.props,...i}:o.props,d={...o,props:c},m=w.find(z=>z.type===d.type);if(m){const z=i&&Object.keys(i).length===0?void 0:c,F=f({...m,...d,props:z}),Y=w.map(q=>q.id===m.id?F:q);r(Y,m.id)}else{const z=f({...d,id:pe(),minimized:d.minimized??!1});r([...w,z],z.id)}},[w,r,f]),I=a.useCallback(o=>{const i=w.find(c=>c.id===o);if(i){if(re(u,t,i.type),i.floating){const c=ne(u,t)[i.type];if(c?.floatingZIndex){const d=w.map(m=>m.id===o?{...m,minimized:!1,floatingZIndex:c.floatingZIndex}:m);r(d,o);return}}r(w.map(c=>c.id===o?{...c,minimized:!1}:c),o)}},[w,r,u,t]),v=a.useCallback(o=>{const i=w.filter(d=>d.id!==o),c=j===o?le(i,u,t):j;r(i,c)},[w,j,r,u,t]),C=a.useCallback(o=>{const i=w.map(d=>{if(d.id===o){const m={...d,minimized:!d.minimized};return ie(u,t,d.type,{minimized:m.minimized,floating:m.floating}),m}return d}),c=i.find(d=>d.id===o);if(c?.minimized&&j===o&&!c.floating){const d=i.find(m=>!m.minimized&&!m.floating);r(i,d?.id??null)}else c&&!c.minimized&&!c.floating?r(i,o):r(i,j)},[w,j,t,u,r]),W=a.useCallback((o,i)=>{const c=w.find(D=>D.id===o);if(!c||!t||c.floating)return;const d=w.filter(D=>!D.floating&&!D.minimized);if(d.length===1&&d[0].id===o)return;const m=M.current,z={minWidth:m.minWidth,minHeight:m.minHeight};let F=Q({x:m.x,y:m.y,width:m.width,height:m.height},z);if(i)F=Q({x:i.x-m.width/2,y:Math.max(0,i.y-40),width:m.width,height:m.height},z);else if(c.floatingPosition)F=Q(c.floatingPosition,z);else{const D=X(c.type);D&&(F=Q(D,z))}re(u,t,c.type);const Y=ne(u,t)[c.type]?.floatingZIndex??1e3,q=w.map(D=>D.id===o?(ie(u,t,D.type,{floating:!0,minimized:!1,position:F,floatingZIndex:Y}),{...D,floating:!0,minimized:!1,floatingPosition:F,floatingZIndex:Y,pendingDragStart:i}):D);if(j===o){const D=q.filter(V=>!V.floating&&!V.minimized);r(q,D.length>0?le(D,u,t):null)}else r(q,j)},[w,j,t,u,r,X]),N=a.useCallback((o,i)=>{const c=w.find(V=>V.id===o);if(!c?.floating)return;const{floating:d,floatingPosition:m,floatingZIndex:z,pendingDragStart:F,...Y}=c;ie(u,t,c.type,{floating:!1,minimized:Y.minimized});const q=w.filter(V=>!V.floating);let D;i!==void 0&&i>=0&&i<=q.length?D=[...q.slice(0,i),Y,...q.slice(i)]:D=[...q,Y],D=[...D,...w.filter(V=>V.floating&&V.id!==o)],r(D,o),setTimeout(()=>{document.querySelector(".rw-window-tabs")?.dispatchEvent(new CustomEvent("clearFloatingWindowPreview"))},0)},[w,r,u,t]),P=a.useCallback((o,i)=>{const c=w.find(m=>m.id===o);if(!c)return;const d=w.map(m=>{if(m.id===o){const{pendingDragStart:z,...F}=m;return{...F,floatingPosition:i}}return m});T(d),c.floating&&ie(u,t,c.type,{position:i,floating:!0,minimized:c.minimized,floatingZIndex:c.floatingZIndex})},[w,t,u]),L=a.useCallback(o=>{const i=w.find(d=>d.id===o);if(!i?.floating||!t)return;re(u,t,i.type);const c=ne(u,t)[i.type];c?.floatingZIndex&&T(d=>d.map(m=>m.id===o&&m.floating?{...m,floatingZIndex:c.floatingZIndex}:m))},[w,t,u]),A=a.useCallback((o,i)=>{T(c=>{const d=c.map(m=>m.id===o?{...m,props:{...m.props,...i}}:m);return k(d,j),d})},[j,k]),U=a.useCallback((o,i)=>{T(c=>{const d=c.map(m=>m.id===o?{...m,title:i}:m);return Z(d,j),k(d,j),d})},[j,Z,k]),K=a.useCallback(o=>{T(i=>i.map(c=>{if(c.id!==o)return c;const{pendingAction:d,...m}=c;return m}))},[]),G=a.useCallback(o=>{if(o==="reset-windows"){$();return}if(!j&&!["close-all","minimize-all","restore-all"].includes(o))return;const i=w.filter(z=>!z.floating),c=w.filter(z=>z.floating);let d=[],m=j;switch(o){case"close-left":{const z=i.findIndex(F=>F.id===j);d=i.slice(z);break}case"close-right":{const z=i.findIndex(F=>F.id===j);d=i.slice(0,z+1);break}case"close-others":d=i.filter(z=>z.id===j);break;case"close-all":d=[],m=null;break;case"minimize-all":d=i.map(z=>({...z,minimized:!0})),m=null;break;case"restore-all":d=i.map(z=>({...z,minimized:!1})),m=j??d[0]?.id??null;break;default:d=i}r([...d,...c],m)},[w,j,r,$]),te=a.useCallback((o,i)=>{const c=w.filter(Y=>!Y.minimized&&!Y.floating);if(o<0||o>=c.length||i<0||i>=c.length||o===i)return;const d=[...c],[m]=d.splice(o,1);d.splice(i,0,m);let z=0;const F=w.map(Y=>Y.minimized||Y.floating?Y:d[z++]);r(F,j)},[w,j,r]);return{windows:w,activeWindowId:j,openWindow:S,switchWindow:I,closeWindow:v,toggleMinimize:C,floatWindow:W,restoreWindow:N,updateFloatingPosition:P,focusWindow:L,batchManage:G,updateWindowProps:A,updateWindowTitle:U,clearPendingAction:K,setWindows:T,setActiveWindowId:O,resetWorkspace:$,reorderWindows:te}}const ae=a.createContext(null),we=ae.Provider;function Be(){const e=a.useContext(ae);if(!e)throw new Error("[react-workspace] useWorkspaceContext 必须在 Workspace 或 WorkspaceProvider 内使用");return e}function Ze(){return a.useContext(ae)}const ee=e=>({width:e,height:e,viewBox:"0 0 24 24",fill:"currentColor"}),ye=({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"})}),$e=({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"})}),He=({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"})}),Ae=({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"})]}),Xe=({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"})}),Le=({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"})}),Fe=({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"})}),Ye=({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 be(e,t){for(const l of e){if("type"in l&&l.type==="divider")continue;const s=l;if(s.key===t)return s;if(s.children){const p=be(s.children,t);if(p)return p}}return null}function ve(e,t,l){const s=p=>{for(const x of p){if("type"in x&&x.type==="divider")continue;const y=x;if(y.windowType===t)return typeof y.label=="string"?y.label:y.key;if(y.children){const u=s(y.children);if(u)return u}}return null};return s(e)??l??t}function ce(e,t){for(const l of e){if("type"in l&&l.type==="divider")continue;const s=l;if(s.windowType===t)return s.key;if(s.children){const p=ce(s.children,t);if(p)return p}}return null}function We(e){const t=[];for(const l of e){if("type"in l&&l.type==="divider")continue;const s=l;s.children?.length&&t.push(s.key)}return t}function de(e){return typeof e=="string"||typeof e=="number"?String(e):""}function _e(e){return"type"in e&&e.type==="divider"}const ke=({menuItems:e,onMenuClick:t,onAction:l,activeWindowType:s,header:p,footer:x,defaultOpenKeys:y=[],siderWidth:u=240,onCollapsedChange:g})=>{const[b,H]=a.useState(!1),[M,E]=a.useState(new Set(y)),w=a.useMemo(()=>s?ce(e,s):null,[s,e]),T=()=>{H(k=>(g?.(!k),!k))},j=(k,_)=>{_?.stopPropagation(),E(X=>{const Z=new Set(X);return Z.has(k)?Z.delete(k):Z.add(k),Z})},O=k=>{if(!k.disabled){if(k.windowType){t(k.windowType,k.props);return}if(k.action&&l){l(k.action);return}k.children?.length&&j(k.key)}},h=(k,_=0)=>k.map((X,Z)=>{if(_e(X))return n.jsx("div",{className:"rw-menu-divider"},X.key??`div-${Z}`);const r=X,f=!!r.children?.length,R=M.has(r.key),$=r.key===w;return n.jsxs("div",{className:"rw-menu-group",children:[n.jsxs("button",{type:"button",className:`rw-menu-item ${$?"selected":""} ${r.disabled?"disabled":""}`,style:{paddingLeft:b?12:12+_*16},onClick:()=>O(r),disabled:r.disabled,title:b?de(r.label):void 0,children:[r.icon&&n.jsx("span",{className:"rw-menu-icon",children:r.icon}),!b&&n.jsx("span",{className:"rw-menu-label",children:r.label}),!b&&f&&n.jsx("span",{className:`rw-menu-arrow ${R?"open":""}`,onClick:S=>j(r.key,S),role:"presentation",children:n.jsx(Ye,{size:10})})]}),!b&&f&&R&&n.jsx("div",{className:"rw-menu-children",children:h(r.children,_+1)})]},r.key)}),B=b?64:u;return n.jsxs("div",{className:"rw-workspace-sidebar-wrapper",children:[n.jsxs("aside",{className:"rw-workspace-sider",style:{width:B},children:[p&&n.jsx("div",{className:`rw-workspace-sidebar-header ${b?"collapsed":""}`,children:p}),n.jsx("nav",{className:"rw-workspace-sidebar-menu",children:h(e)}),x&&n.jsx("div",{className:`rw-workspace-sidebar-footer ${b?"collapsed":""}`,children:x})]}),n.jsx("button",{type:"button",className:"rw-workspace-collapse-button",style:{left:B},onClick:T,title:b?"展开导航":"折叠导航",children:b?n.jsx(Le,{}):n.jsx(Xe,{})})]})},qe=({description:e="暂无内容",icon:t})=>n.jsxs("div",{className:"rw-empty",children:[n.jsx("div",{className:"rw-empty-icon",children:t??n.jsx(Fe,{size:64})}),n.jsx("div",{className:"rw-empty-desc",children:e})]}),Se=({window:e,active:t,children:l})=>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:l}),Ue=({items:e,trigger:t,className:l})=>{const[s,p]=a.useState(!1),x=a.useRef(null);return a.useEffect(()=>{if(!s)return;const y=u=>{x.current?.contains(u.target)||p(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[s]),n.jsxs("div",{className:`rw-dropdown ${l||""}`,ref:x,children:[n.jsx("div",{className:"rw-dropdown-trigger",onClick:()=>p(y=>!y),role:"button",tabIndex:0,children:t}),s&&n.jsx("div",{className:"rw-dropdown-menu",children:e.map(y=>y.divider?n.jsx("div",{className:"rw-dropdown-divider"},y.key):n.jsx("button",{type:"button",className:"rw-dropdown-item",disabled:y.disabled,onClick:()=>{y.onClick?.(),p(!1)},children:y.label},y.key))})]})},Ce=({windows:e,activeWindowId:t,onSwitchWindow:l,onCloseWindow:s,onToggleMinimize:p,onBatchManage:x,onFloatWindow:y,onRestoreWindow:u,onReorderWindows:g,allWindows:b=e})=>{const H=e.findIndex(r=>r.id===t),M=a.useRef(null),E=a.useRef(null),[w,T]=a.useState(null),[j,O]=a.useState(null),h=a.useRef({windowId:"",startX:0,startY:0,fromIndex:-1,mode:"none",floated:!1}),B=a.useCallback(r=>{const f=E.current;if(!f)return e.length;const R=f.getBoundingClientRect(),$=r-R.left,S=f.querySelectorAll(".rw-tab-item");if($<8)return 0;for(let I=0;I<S.length;I++){const v=S[I].getBoundingClientRect(),C=v.left-R.left+v.width/2;if($<C)return I}return S.length},[e.length]),k=a.useCallback((r,f,R)=>{if(r.target.closest(".rw-window-tab-close-btn")||r.button!==0)return;h.current={windowId:f,startX:r.clientX,startY:r.clientY,fromIndex:R,mode:"none",floated:!1};const $=v=>{const C=v.clientX-h.current.startX,W=v.clientY-h.current.startY,N=Math.sqrt(C*C+W*W);N<8||(h.current.mode==="none"&&(Math.abs(W)>40&&N>50?h.current.mode="float":Math.abs(C)>12&&Math.abs(C)>Math.abs(W)?h.current.mode="reorder":N>50&&(h.current.mode="float")),h.current.mode==="float"&&h.current.windowId===f?h.current.floated||(h.current.floated=!0,y?.(f,{x:v.clientX,y:v.clientY})):h.current.mode==="reorder"&&T(B(v.clientX)))},S=v=>{if(h.current.mode==="reorder"&&h.current.windowId===f){let W=B(v.clientX);W>h.current.fromIndex&&(W-=1),W!==h.current.fromIndex&&g&&g(h.current.fromIndex,W)}T(null),I()},I=()=>{document.removeEventListener("mousemove",$),document.removeEventListener("mouseup",S),h.current={windowId:"",startX:0,startY:0,fromIndex:-1,mode:"none",floated:!1}};document.addEventListener("mousemove",$),document.addEventListener("mouseup",S)},[y,g,B]);a.useEffect(()=>{let r=null;const f=S=>{const{windowTitle:I,clientX:v}=S.detail,C=B(v);r&&cancelAnimationFrame(r),r=requestAnimationFrame(()=>{O({title:I,index:C}),T(C)})},R=()=>{O(null),T(null)},$=M.current;return $?.addEventListener("floatingWindowDragOver",f),$?.addEventListener("clearFloatingWindowPreview",R),()=>{$?.removeEventListener("floatingWindowDragOver",f),$?.removeEventListener("clearFloatingWindowPreview",R),r&&cancelAnimationFrame(r)}},[B]);const _=r=>{r.preventDefault();try{const f=sessionStorage.getItem("draggingWindowTitle");f&&O({title:f,index:B(r.clientX)})}catch{}T(B(r.clientX))},X=r=>{r.preventDefault();let f=r.dataTransfer.getData("windowId")||"";if(!f)try{f=sessionStorage.getItem("draggingWindowId")||""}catch{}f&&u&&u(f,w??void 0),O(null),T(null)},Z=[{key:"close-others",label:"关闭其他",disabled:e.length<=1,onClick:()=>x("close-others")},{key:"close-left",label:"关闭左侧",disabled:H<=0,onClick:()=>x("close-left")},{key:"close-right",label:"关闭右侧",disabled:H<0||H>=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:!b.some(r=>r.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",ref:M,onDragOver:_,onDragLeave:()=>{O(null),T(null)},onDrop:X,children:n.jsxs("div",{className:"rw-window-tabs-container",children:[n.jsxs("div",{className:"rw-tab-list",ref:E,children:[e.map((r,f)=>n.jsxs("div",{className:`rw-tab-item ${r.id===t?"active":""}`,onClick:()=>l(r.id),onMouseDown:R=>k(R,r.id,f),children:[n.jsx("span",{className:"rw-tab-title",children:r.title}),n.jsx("button",{type:"button",title:"关闭",className:"rw-icon-btn rw-window-tab-close-btn",onClick:R=>{R.stopPropagation(),s(r.id)},children:n.jsx(ye,{size:12})})]},r.id)),j&&w!==null&&n.jsx("div",{className:"rw-tab-preview",style:{order:w},children:j.title})]}),w!==null&&!j&&n.jsx(Ke,{listRef:E,index:w}),e.length>0&&n.jsx(Ue,{items:Z,trigger:n.jsx("button",{type:"button",className:"rw-icon-btn rw-window-tabs-batch-btn",title:"批量管理",children:n.jsx(Ae,{})})})]})})},Ke=({listRef:e,index:t})=>{const[l,s]=a.useState(0);return a.useEffect(()=>{const p=()=>{const x=e.current;if(!x)return;x.getBoundingClientRect();const y=x.querySelectorAll(".rw-tab-item:not(.rw-tab-preview)");if(t===0){s(8);return}if(t>=y.length){const g=y[y.length-1];s(g.offsetLeft+g.offsetWidth+2);return}const u=y[t];s(u.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:`${l}px`}})},Ve={x:100,y:100,width:800,height:600,minWidth:400,minHeight:300},je=({window:e,children:t,floatingDefaults:l,onUpdateFloatingPosition:s,onRestoreWindow:p,onCloseWindow:x,onToggleMinimize:y,onFocusWindow:u})=>{const g={...Ve,...l},b=a.useRef(null),H=a.useRef(null),[M,E]=a.useState(!1),[w,T]=a.useState(!1),[j,O]=a.useState(!1),h=a.useRef(!1),B=a.useRef(""),k=a.useRef({x:0,y:0,startX:0,startY:0,startWidth:0,startHeight:0}),_=a.useRef({x:0,y:0,width:0,height:0,startX:0,startY:0}),X=a.useRef(null),Z=a.useRef(null),r=a.useRef(null),f=e.floatingPosition||{x:g.x,y:g.y,width:g.width,height:g.height};a.useEffect(()=>{if(!e.pendingDragStart||M||w)return;let S=f.x,I=f.y;if(b.current){const v=b.current.getBoundingClientRect();S=v.left,I=v.top}u?.(e.id),r.current={windowId:e.id,windowTitle:e.title};try{sessionStorage.setItem("draggingWindowId",e.id),sessionStorage.setItem("draggingWindowTitle",e.title)}catch{}E(!0),k.current={x:e.pendingDragStart.x-S,y:e.pendingDragStart.y-I,startX:S,startY:I,startWidth:f.width,startHeight:f.height}},[e.pendingDragStart,e.id,e.title,M,w,f,u]),a.useEffect(()=>{if(M||w||e.pendingDragStart)return;const S={minWidth:g.minWidth,minHeight:g.minHeight},I=Q(f,S);(I.x!==f.x||I.y!==f.y||I.width!==f.width||I.height!==f.height)&&s(e.id,I)},[e.id,e.pendingDragStart]),a.useEffect(()=>{if(!b.current||M||w)return;const S=b.current;S.style.transform=`translate(${f.x}px, ${f.y}px)`,S.style.width=`${f.width}px`,S.style.height=`${f.height}px`},[f.x,f.y,f.width,f.height,M,w]);const R=a.useCallback(S=>{const I=S.target;if(I.closest(".rw-floating-window-action-btn")||I.closest(".rw-floating-window-resize-handle")||!H.current?.contains(I))return;u?.(e.id);let v=f.x,C=f.y;if(b.current){const W=b.current.getBoundingClientRect();v=W.left,C=W.top}r.current={windowId:e.id,windowTitle:e.title};try{sessionStorage.setItem("draggingWindowId",e.id),sessionStorage.setItem("draggingWindowTitle",e.title)}catch{}E(!0),k.current={x:S.clientX-v,y:S.clientY-C,startX:v,startY:C,startWidth:f.width,startHeight:f.height}},[f,e.id,e.title,u]),$=a.useCallback((S,I)=>{S.stopPropagation(),S.preventDefault(),u?.(e.id);let v=f.x,C=f.y,W=f.width,N=f.height;if(b.current){const P=b.current.getBoundingClientRect();v=P.left,C=P.top,W=P.width,N=P.height}T(!0),B.current=I,_.current={x:S.clientX,y:S.clientY,width:W,height:N,startX:v,startY:C}},[f,e.id,u]);return a.useEffect(()=>{const S=v=>{if(M){v.preventDefault();const C=document.querySelector(".rw-window-tabs");if(C&&r.current){const A=C.getBoundingClientRect(),U=v.clientY>=A.top&&v.clientY<=A.bottom&&v.clientX>=A.left&&v.clientX<=A.right,K=h.current;O(U),h.current=U,U?C.dispatchEvent(new CustomEvent("floatingWindowDragOver",{detail:{...r.current,clientX:v.clientX,clientY:v.clientY}})):K&&C.dispatchEvent(new CustomEvent("clearFloatingWindowPreview"))}const W=k.current.startWidth,N=k.current.startHeight,P=Math.max(0,Math.min(v.clientX-k.current.x,globalThis.window.innerWidth-W)),L=Math.max(0,Math.min(v.clientY-k.current.y,globalThis.window.innerHeight-N));b.current.style.transform=`translate(${P}px, ${L}px)`,Z.current={x:P,y:L,width:k.current.startWidth,height:k.current.startHeight}}else if(w){v.preventDefault();const C=B.current,W=_.current;let N=W.startX,P=W.startY,L=W.width,A=W.height;const U=v.clientX-W.x,K=v.clientY-W.y;C.includes("e")&&(L=Math.max(g.minWidth,W.width+U)),C.includes("w")&&(L=Math.max(g.minWidth,W.width-U),N=W.startX+W.width-L),C.includes("s")&&(A=Math.max(g.minHeight,W.height+K)),C.includes("n")&&(A=Math.max(g.minHeight,W.height-K),P=W.startY+W.height-A);const G=b.current;G.style.transform=`translate(${N}px, ${P}px)`,G.style.width=`${L}px`,G.style.height=`${A}px`,Z.current={x:N,y:P,width:L,height:A}}},I=v=>{if(v&&r.current){const W=document.querySelector(".rw-window-tabs");if(W){const N=W.getBoundingClientRect();if(v.clientY>=N.top&&v.clientY<=N.bottom&&v.clientX>=N.left&&v.clientX<=N.right){const P=W.querySelector(".rw-tab-list");if(P){let L=P.querySelectorAll(".rw-tab-item").length;const A=P.getBoundingClientRect(),U=v.clientX-A.left;P.querySelectorAll(".rw-tab-item").forEach((K,G)=>{const te=K.getBoundingClientRect();U<te.left-A.left+te.width/2&&(L=Math.min(L,G))}),p(r.current.windowId,L),r.current=null,E(!1),T(!1),O(!1);return}}}}let C=Z.current;C&&(C=Q(C,{minWidth:g.minWidth,minHeight:g.minHeight})),C&&s(e.id,C),Z.current=null,r.current=null;try{sessionStorage.removeItem("draggingWindowId"),sessionStorage.removeItem("draggingWindowTitle")}catch{}E(!1),T(!1),O(!1),h.current=!1};if(M||w){const v=C=>{X.current&&cancelAnimationFrame(X.current),X.current=requestAnimationFrame(()=>S(C))};return document.addEventListener("mousemove",v,{passive:!1}),document.addEventListener("mouseup",I),document.body.style.userSelect="none",()=>{document.removeEventListener("mousemove",v),document.removeEventListener("mouseup",I),document.body.style.userSelect=""}}},[M,w,e.id,g.minWidth,g.minHeight,s,p]),n.jsxs("div",{ref:b,className:"rw-floating-window",style:{transform:`translate(${f.x}px, ${f.y}px)`,width:f.width,height:f.height,zIndex:e.floatingZIndex||1e3,opacity:j?.5:1,minWidth:g.minWidth,minHeight:g.minHeight},onClick:S=>{S.target.closest("button, a, input, select, textarea")||u?.(e.id)},children:[n.jsxs("div",{ref:H,className:"rw-floating-window-header",onMouseDown:R,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(He,{size:12})}),n.jsx("button",{type:"button",title:"最小化",className:"rw-icon-btn rw-floating-window-action-btn",onClick:()=>y(e.id),children:n.jsx($e,{size:12})}),n.jsx("button",{type:"button",title:"关闭",className:"rw-icon-btn rw-floating-window-action-btn",onClick:()=>x(e.id),children:n.jsx(ye,{size:12})})]})]}),n.jsx("div",{className:"rw-floating-window-content",children:t}),["nw","ne","sw","se","n","s","w","e"].map(S=>n.jsx("div",{className:`rw-floating-window-resize-handle rw-floating-window-resize-${S}`,onMouseDown:I=>$(I,S)},S))]})},Ie=({windows:e,activeWindowId:t,renderWindow:l,onSwitchWindow:s,onCloseWindow:p,onToggleMinimize:x,onBatchManage:y,onFloatWindow:u,onRestoreWindow:g,onUpdateFloatingPosition:b,onFocusWindow:H,onReorderWindows:M,emptyDescription:E="从左侧菜单选择功能开始工作",floatingDefaults:w})=>{if(e.length===0)return n.jsx("div",{className:"rw-window-manager-empty",children:n.jsx(qe,{description:E})});const T=e.filter(h=>h.minimized),j=e.filter(h=>h.floating&&!h.minimized),O=e.filter(h=>!h.minimized&&!h.floating);return n.jsxs("div",{className:"rw-window-manager",children:[n.jsx(Ce,{windows:O,activeWindowId:t,onSwitchWindow:s,onCloseWindow:p,onToggleMinimize:x,onBatchManage:y,onFloatWindow:u,onRestoreWindow:g,onReorderWindows:M,allWindows:e}),n.jsx("div",{className:"rw-window-content-area",children:O.map(h=>n.jsx(Se,{window:h,active:h.id===t,children:l(h,{})},h.id))}),T.length>0&&n.jsx("div",{className:"rw-minimized-windows-bar",children:T.map(h=>n.jsxs("div",{className:"rw-minimized-window-item",onClick:()=>x(h.id),title:h.floating?`${h.title} (浮动窗口)`:h.title,role:"button",tabIndex:0,onKeyDown:B=>B.key==="Enter"&&x(h.id),children:[n.jsx("span",{children:h.title}),h.floating&&n.jsx("span",{className:"rw-minimized-floating-badge",children:"🔲"})]},h.id))}),j.map(h=>n.jsx(je,{window:h,floatingDefaults:w,onUpdateFloatingPosition:b||(()=>{}),onRestoreWindow:g||(()=>{}),onCloseWindow:p,onToggleMinimize:x,onFocusWindow:H,children:l(h,{})},h.id))]})};function Je(e){return"type"in e&&e.type==="divider"}function fe(e){for(const t of e){if(Je(t))continue;const l=t;if(l.windowType)return l;if(l.children){const s=fe(l.children);if(s)return s}}return null}function ze(e,t){if(t)return{minimized:!1,...t};const l=fe(e);if(!l?.windowType)return{type:"home",title:"首页",minimized:!1};const s=de(l.label)||l.key;return{type:l.windowType,title:s,minimized:!1}}function Me(e,t){const{fallback:l}=t??{};return(s,p)=>{const x=e[s.type]??l;return x?a.createElement(x,{window:s,ctx:p}):null}}const Ge={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 ue(e){const t={};return Object.keys(e).forEach(l=>{const s=e[l];if(s!==void 0){const p=Ge[l];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 Qe(e){return ue(Ne(e))}const et=a.forwardRef(function({workspaceId:t="default",menuItems:l,renderWindow:s,windows:p,sidebarHeader:x,sidebarFooter:y,defaultWindow:u,loading:g=!1,loadingTip:b="加载中...",onAction:H,activeWindowType:M,emptyDescription:E,syncToUrl:w=!1,preserveUrlParams:T=!0,searchParams:j,setSearchParams:O,floatingDefaults:h,onWindowsChange:B,onReady:k,siderWidth:_=240,contentBackground:X,themeClassName:Z,theme:r,renderSidebar:f,className:R,style:$},S){const I=a.useMemo(()=>ze(l,u),[l,u]),v=a.useMemo(()=>{if(s)return s;if(p)return Me(p);throw new Error("[react-workspace] 请提供 renderWindow 或 windows")},[s,p]),C=xe({workspaceId:t,defaultWindow:I,syncToUrl:w,preserveUrlParams:T,searchParams:j,setSearchParams:O,floatingDefaults:h,onWindowsChange:B}),{windows:W,activeWindowId:N,openWindow:P,switchWindow:L,closeWindow:A,toggleMinimize:U,floatWindow:K,restoreWindow:G,updateFloatingPosition:te,focusWindow:o,batchManage:i,updateWindowProps:c,clearPendingAction:d,reorderWindows:m}=C,z={workspaceId:t,...C};a.useImperativeHandle(S,()=>z,[t,W,N]),a.useEffect(()=>{k&&W.length>0&&k({workspaceId:t,...C})},[k,t,W.length]);const F=a.useMemo(()=>M!==void 0?M:W.find(J=>J.id===N)?.type,[M,W,N]),Y=a.useCallback((J,se)=>{P({type:J,title:ve(l,J),minimized:!1},se)},[P,l]),q=a.useCallback((J,se)=>({workspaceId:t,active:se,activeWindowId:N,windows:W,openWindow:P,switchWindow:L,closeWindow:A,toggleMinimize:U,floatWindow:K,updateWindowProps:(Re,Pe)=>c(Re,Pe),clearPendingAction:d}),[t,N,W,P,L,A,U,K,c,d]),D=a.useMemo(()=>({...z,buildRenderContext:q}),[t,W,N,q]),V=X??"var(--rw-color-bg-tertiary)",Te={minHeight:"100vh",height:"100vh",display:"flex",...r?ue(r):void 0,...$},ge={menuItems:l,onMenuClick:Y,onAction:H,activeWindowType:F,header:x,footer:y,defaultOpenKeys:We(l),siderWidth:_};return n.jsx(we,{value:D,children:n.jsxs("div",{className:`rw-workspace ${Z||""} ${R||""}`.trim(),style:Te,children:[f?f(ge):n.jsx(ke,{...ge}),n.jsx("main",{className:"rw-workspace-main",style:{background:V},children:n.jsx(De,{spinning:g,tip:b,children:n.jsx(Ie,{workspaceId:t,windows:W,activeWindowId:N,renderWindow:J=>v(J,q(J,J.id===N&&!J.floating)),onSwitchWindow:L,onCloseWindow:A,onToggleMinimize:U,onBatchManage:i,onOpenWindow:P,onFloatWindow:K,onRestoreWindow:G,onUpdateFloatingPosition:te,onFocusWindow:o,onReorderWindows:m,emptyDescription:E,floatingDefaults:h})})})]})})});exports.FloatingWindow=je;exports.WindowContainer=Se;exports.WindowManager=Ie;exports.WindowTabs=Ce;exports.Workspace=et;exports.WorkspaceProvider=we;exports.WorkspaceSidebar=ke;exports.collectParentMenuKeys=We;exports.createWindowRenderer=Me;exports.findFirstMenuItemWithWindowType=fe;exports.findMenuItem=be;exports.findMenuKeyByWindowType=ce;exports.fixWindowPosition=Q;exports.getAllWindowStatesFromStorage=ne;exports.labelToString=de;exports.mapAntdTokenToCssVars=Qe;exports.mapAntdTokenToWorkspaceTheme=Ne;exports.pickNextActiveWindowId=le;exports.resolveDefaultWindow=ze;exports.resolveWindowTitle=ve;exports.saveWindowStateToStorage=ie;exports.themeToCssVars=ue;exports.updateTabClickOrder=re;exports.useWorkspace=xe;exports.useWorkspaceContext=Be;exports.useWorkspaceContextOptional=Ze;
|