@liuman/react-workspace 1.2.1 → 1.3.1
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 +99 -48
- package/dist/Workspace-BBzK2L-Z.cjs +1 -0
- package/dist/Workspace-BD4jIdrk.js +1248 -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 +3 -4
- 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 持久化** — 浮动窗口位置自动保存
|
|
@@ -17,63 +17,104 @@
|
|
|
17
17
|
## 安装
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
|
|
20
|
+
npm install @liuman/react-workspace
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
### Peer Dependencies
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
|
-
|
|
26
|
+
npm install react react-dom
|
|
27
27
|
# URL 同步(可选)
|
|
28
|
-
|
|
28
|
+
npm install react-router-dom
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
## 快速开始
|
|
32
32
|
|
|
33
|
+
### 开箱即用(Ant Design,推荐)
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install @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,17 +142,27 @@ 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
|
|
|
112
164
|
```bash
|
|
113
|
-
|
|
165
|
+
npm install @liuman/react-workspace antd @ant-design/icons
|
|
114
166
|
```
|
|
115
167
|
|
|
116
168
|
#### 1. 主题同步(推荐)
|
|
@@ -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
|
|
@@ -211,8 +255,8 @@ renderWindow={(window) => {
|
|
|
211
255
|
|
|
212
256
|
```bash
|
|
213
257
|
cd packages/react-workspace
|
|
214
|
-
|
|
215
|
-
|
|
258
|
+
npm run dev:demo # 开发
|
|
259
|
+
npm run build:demo # 构建
|
|
216
260
|
```
|
|
217
261
|
|
|
218
262
|
### `useWorkspaceContext`
|
|
@@ -333,9 +377,9 @@ interface SidebarMenuItem {
|
|
|
333
377
|
|
|
334
378
|
```bash
|
|
335
379
|
cd packages/react-workspace
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
380
|
+
npm install
|
|
381
|
+
npm run build
|
|
382
|
+
npm run type-check
|
|
339
383
|
```
|
|
340
384
|
|
|
341
385
|
## 发布到 GitHub
|
|
@@ -437,20 +481,27 @@ npm login
|
|
|
437
481
|
# 2. package.json 包名为 @liuman/react-workspace(react-workspace 已被他人占用)
|
|
438
482
|
|
|
439
483
|
# 3. 发布(需已开启 2FA,并带 OTP)
|
|
440
|
-
|
|
484
|
+
npm run build
|
|
441
485
|
npm publish --access public --otp=你的6位验证码
|
|
442
486
|
```
|
|
443
487
|
|
|
444
488
|
安装方式:
|
|
445
489
|
|
|
446
490
|
```bash
|
|
447
|
-
|
|
491
|
+
npm install @liuman/react-workspace
|
|
448
492
|
```
|
|
449
493
|
|
|
450
494
|
---
|
|
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"),l=require("react"),De=({tip:e="加载中...",spinning:t=!1,children:s})=>n.jsxs("div",{className:"rw-spinner-wrap",children:[s,t&&n.jsxs("div",{className:"rw-spinner-overlay",children:[n.jsx("div",{className:"rw-spinner"}),e&&n.jsx("span",{className:"rw-spinner-tip",children:e})]})]}),ge=100;function Q(e,t){const s=globalThis.window.innerWidth,o=globalThis.window.innerHeight,p=Math.min(t?.minWidth??ge,s),x=Math.min(t?.minHeight??ge,o);let{x:y,y:f,width:u,height:b}=e;return u=Math.min(u,s),b=Math.min(b,o),u=Math.max(u,p),b=Math.max(b,x),y+u>s&&(y=Math.max(0,s-u)),f+b>o&&(f=Math.max(0,o-b)),y<0&&(y=0),f<0&&(f=0),{x:y,y:f,width:u,height:b}}function re(e,t){return`${e}${t}`}function te(e,t){if(!t)return{};try{const s=re(e,t),o=localStorage.getItem(s);if(o){const p=JSON.parse(o);if(p&&typeof p=="object"){const x={};return Object.entries(p).forEach(([y,f])=>{if(f&&typeof f=="object"){const u=f,b={};u.position&&typeof u.position.x=="number"&&typeof u.position.y=="number"&&typeof u.position.width=="number"&&typeof u.position.height=="number"&&(b.position=Q(u.position)),typeof u.minimized=="boolean"&&(b.minimized=u.minimized),typeof u.floating=="boolean"&&(b.floating=u.floating),typeof u.floatingZIndex=="number"&&(b.floatingZIndex=u.floatingZIndex),x[y]=b}}),x}}}catch(s){console.warn("[react-workspace] 从 localStorage 读取窗口状态失败:",s)}return{}}function ne(e,t,s,o){if(t)try{const p=te(e,t);p[s]={...p[s],...o},localStorage.setItem(re(e,t),JSON.stringify(p))}catch(p){console.warn("[react-workspace] 保存窗口状态到 localStorage 失败:",p)}}function ie(e,t,s){if(t)try{const o=re(e,t),p=localStorage.getItem(o);let x=p?JSON.parse(p):{};const y=Object.values(x).map(N=>N?.floatingZIndex||0).filter(N=>N>=1e3),f=y.length>0?Math.max(...y):999,u=x[s]||{},b=u.floatingZIndex||0,$=Math.max(1e3,f+1);b>=1e3?(x[s]={...u,floatingZIndex:$},Object.keys(x).forEach(N=>{if(N!==s&&x[N]){const O=x[N];O.floatingZIndex!==void 0&&O.floatingZIndex>=1e3&&(x[N]={...O,floatingZIndex:Math.max(1e3,O.floatingZIndex-1)})}})):x[s]={...u,floatingZIndex:$},localStorage.setItem(o,JSON.stringify(x))}catch(o){console.error("[react-workspace] 保存标签点击顺序失败:",o)}}function se(e,t,s){if(e.length===0)return null;try{const o=localStorage.getItem(re(t,s));if(o){const p=JSON.parse(o);return[...e].sort((y,f)=>{const u=p[y.type]?.floatingZIndex||0,b=p[f.type]?.floatingZIndex||0;return u>=1e3&&b>=1e3?b-u:u>=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 me(e){return{...Oe,...e}}function he(){return`window-${Date.now()}-${Math.random().toString(36).slice(2,7)}`}function pe(e){const{workspaceId:t,defaultWindow:s,syncToUrl:o=!1,preserveUrlParams:p=!0,searchParams:x,setSearchParams:y,storageKeyPrefix:f=Ee,floatingDefaults:u,onWindowsChange:b}=e,$=l.useRef(s??{type:"home",title:"首页",minimized:!1});$.current=s??$.current;const N=l.useRef(me(u));N.current=me(u);const O=l.useRef(b);O.current=b;const[w,R]=l.useState([]),[j,Z]=l.useState(null),h=l.useRef({}),P=l.useCallback((i,r)=>{O.current?.(i,r)},[]),I=l.useCallback(i=>te(f,t)[i]||null,[f,t]),_=l.useCallback(i=>I(i)?.position||null,[I]),X=l.useCallback((i,r)=>{if(!o||!y)return;const a=p&&x?new URLSearchParams(x):new URLSearchParams;i.length>0?a.set("windows",encodeURIComponent(JSON.stringify(i.map(c=>({id:c.id,type:c.type,title:c.title}))))):a.delete("windows"),r?a.set("active",r):a.delete("active"),y(a,{replace:!0})},[o,y,p,x]),C=l.useCallback((i,r)=>{R(i),Z(r),X(i,r),P(i,r)},[X,P]),g=l.useCallback(i=>{const r=I(i.type),a={...i,minimized:r?.minimized??i.minimized??!1,floating:r?.floating??i.floating??!1};if(a.floating){let c=i.floatingPosition||r?.position;c||(c=_(i.type)??void 0),c&&(a.floatingPosition=Q(c)),a.floatingZIndex=r?.floatingZIndex??i.floatingZIndex??1e3}return a},[I,_]),d=l.useCallback(()=>{const i=$.current,r={id:he(),type:i.type,title:i.title,minimized:i.minimized??!1};C([r],r.id)},[C]),B=l.useCallback(()=>{if(t)try{localStorage.removeItem(`${f}${t}`)}catch{}delete h.current[t],d()},[t,f,d]);l.useEffect(()=>{if(!t||h.current[t])return;h.current[t]=!0;const i=o?x?.get("windows"):null,r=o?x?.get("active"):null;if(i)try{const c=JSON.parse(decodeURIComponent(i)).map(g),m=r&&c.some(M=>M.id===r)?r:c[0]?.id??null;R(c),Z(m),P(c,m)}catch(a){console.error("[react-workspace] 解析窗口配置失败:",a),d()}else d()},[t,x,o,g,d,P]);const L=l.useCallback((i,r)=>{const a=r!==void 0?{...i.props,...r}:i.props,c={...i,props:a},m=w.find(M=>M.type===c.type);if(m){const M=r&&Object.keys(r).length===0?void 0:a,A=g({...m,...c,props:M}),Y=w.map(U=>U.id===m.id?A:U);C(Y,m.id)}else{const M=g({...c,id:he(),minimized:c.minimized??!1});C([...w,M],M.id)}},[w,C,g]),k=l.useCallback(i=>{const r=w.find(a=>a.id===i);if(r){if(ie(f,t,r.type),r.floating){const a=te(f,t)[r.type];if(a?.floatingZIndex){const c=w.map(m=>m.id===i?{...m,minimized:!1,floatingZIndex:a.floatingZIndex}:m);C(c,i);return}}C(w.map(a=>a.id===i?{...a,minimized:!1}:a),i)}},[w,C,f,t]),z=l.useCallback(i=>{const r=w.filter(c=>c.id!==i),a=j===i?se(r,f,t):j;C(r,a)},[w,j,C,f,t]),v=l.useCallback(i=>{const r=w.map(c=>{if(c.id===i){const m={...c,minimized:!c.minimized};return ne(f,t,c.type,{minimized:m.minimized,floating:m.floating}),m}return c}),a=r.find(c=>c.id===i);if(a?.minimized&&j===i&&!a.floating){const c=r.find(m=>!m.minimized&&!m.floating);C(r,c?.id??null)}else a&&!a.minimized&&!a.floating?C(r,i):C(r,j)},[w,j,t,f,C]),S=l.useCallback((i,r)=>{const a=w.find(D=>D.id===i);if(!a||!t||a.floating)return;const c=w.filter(D=>!D.floating&&!D.minimized);if(c.length===1&&c[0].id===i)return;const m=N.current,M={minWidth:m.minWidth,minHeight:m.minHeight};let A=Q({x:m.x,y:m.y,width:m.width,height:m.height},M);if(r)A=Q({x:r.x,y:r.y,width:m.width,height:m.height},M);else if(a.floatingPosition)A=Q(a.floatingPosition,M);else{const D=_(a.type);D&&(A=Q(D,M))}ie(f,t,a.type);const Y=te(f,t)[a.type]?.floatingZIndex??1e3,U=w.map(D=>D.id===i?(ne(f,t,D.type,{floating:!0,minimized:!1,position:A,floatingZIndex:Y}),{...D,floating:!0,minimized:!1,floatingPosition:A,floatingZIndex:Y,pendingDragStart:r}):D);if(j===i){const D=U.filter(V=>!V.floating&&!V.minimized);C(U,D.length>0?se(D,f,t):null)}else C(U,j)},[w,j,t,f,C,_]),W=l.useCallback((i,r)=>{const a=w.find(V=>V.id===i);if(!a?.floating)return;const{floating:c,floatingPosition:m,floatingZIndex:M,pendingDragStart:A,...Y}=a;ne(f,t,a.type,{floating:!1,minimized:Y.minimized});const U=w.filter(V=>!V.floating);let D;r!==void 0&&r>=0&&r<=U.length?D=[...U.slice(0,r),Y,...U.slice(r)]:D=[...U,Y],D=[...D,...w.filter(V=>V.floating&&V.id!==i)],C(D,i),setTimeout(()=>{document.querySelector(".rw-window-tabs")?.dispatchEvent(new CustomEvent("clearFloatingWindowPreview"))},0)},[w,C,f,t]),T=l.useCallback((i,r)=>{const a=w.find(m=>m.id===i);if(!a)return;const c=w.map(m=>{if(m.id===i){const{pendingDragStart:M,...A}=m;return{...A,floatingPosition:r}}return m});R(c),a.floating&&ne(f,t,a.type,{position:r,floating:!0,minimized:a.minimized,floatingZIndex:a.floatingZIndex})},[w,t,f]),E=l.useCallback(i=>{const r=w.find(c=>c.id===i);if(!r?.floating||!t)return;ie(f,t,r.type);const a=te(f,t)[r.type];a?.floatingZIndex&&R(c=>c.map(m=>m.id===i&&m.floating?{...m,floatingZIndex:a.floatingZIndex}:m))},[w,t,f]),F=l.useCallback((i,r)=>{R(a=>{const c=a.map(m=>m.id===i?{...m,props:{...m.props,...r}}:m);return P(c,j),c})},[j,P]),H=l.useCallback((i,r)=>{R(a=>{const c=a.map(m=>m.id===i?{...m,title:r}:m);return X(c,j),P(c,j),c})},[j,X,P]),q=l.useCallback(i=>{R(r=>r.map(a=>{if(a.id!==i)return a;const{pendingAction:c,...m}=a;return m}))},[]),K=l.useCallback(i=>{if(i==="reset-windows"){B();return}if(!j&&!["close-all","minimize-all","restore-all"].includes(i))return;const r=w.filter(M=>!M.floating),a=w.filter(M=>M.floating);let c=[],m=j;switch(i){case"close-left":{const M=r.findIndex(A=>A.id===j);c=r.slice(M);break}case"close-right":{const M=r.findIndex(A=>A.id===j);c=r.slice(0,M+1);break}case"close-others":c=r.filter(M=>M.id===j);break;case"close-all":c=[],m=null;break;case"minimize-all":c=r.map(M=>({...M,minimized:!0})),m=null;break;case"restore-all":c=r.map(M=>({...M,minimized:!1})),m=j??c[0]?.id??null;break;default:c=r}C([...c,...a],m)},[w,j,C,B]),G=l.useCallback((i,r)=>{const a=w.filter(Y=>!Y.minimized&&!Y.floating);if(i<0||i>=a.length||r<0||r>=a.length||i===r)return;const c=[...a],[m]=c.splice(i,1);c.splice(r,0,m);let M=0;const A=w.map(Y=>Y.minimized||Y.floating?Y:c[M++]);C(A,j)},[w,j,C]);return{windows:w,activeWindowId:j,openWindow:L,switchWindow:k,closeWindow:z,toggleMinimize:v,floatWindow:S,restoreWindow:W,updateFloatingPosition:T,focusWindow:E,batchManage:K,updateWindowProps:F,updateWindowTitle:H,clearPendingAction:q,setWindows:R,setActiveWindowId:Z,resetWorkspace:B,reorderWindows:G}}const le=l.createContext(null),xe=le.Provider;function Be(){const e=l.useContext(le);if(!e)throw new Error("[react-workspace] useWorkspaceContext 必须在 Workspace 或 WorkspaceProvider 内使用");return e}function Ze(){return l.useContext(le)}const ee=e=>({width:e,height:e,viewBox:"0 0 24 24",fill:"currentColor"}),we=({size:e=14,className:t})=>n.jsx("svg",{...ee(e),className:t,children:n.jsx("path",{d:"M6 6l12 12M18 6L6 18",stroke:"currentColor",strokeWidth:"2",fill:"none"})}),$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 ye(e,t){for(const s of e){if("type"in s&&s.type==="divider")continue;const o=s;if(o.key===t)return o;if(o.children){const p=ye(o.children,t);if(p)return p}}return null}function be(e,t,s){const o=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 f=o(y.children);if(f)return f}}return null};return o(e)??s??t}function ae(e,t){for(const s of e){if("type"in s&&s.type==="divider")continue;const o=s;if(o.windowType===t)return o.key;if(o.children){const p=ae(o.children,t);if(p)return p}}return null}function ve(e){const t=[];for(const s of e){if("type"in s&&s.type==="divider")continue;const o=s;o.children?.length&&t.push(o.key)}return t}function ce(e){return typeof e=="string"||typeof e=="number"?String(e):""}function _e(e){return"type"in e&&e.type==="divider"}const We=({menuItems:e,onMenuClick:t,onAction:s,activeWindowType:o,header:p,footer:x,defaultOpenKeys:y=[],siderWidth:f=240,onCollapsedChange:u})=>{const[b,$]=l.useState(!1),[N,O]=l.useState(new Set(y)),w=l.useMemo(()=>o?ae(e,o):null,[o,e]),R=()=>{$(I=>(u?.(!I),!I))},j=(I,_)=>{_?.stopPropagation(),O(X=>{const C=new Set(X);return C.has(I)?C.delete(I):C.add(I),C})},Z=I=>{if(!I.disabled){if(I.windowType){t(I.windowType,I.props);return}if(I.action&&s){s(I.action);return}I.children?.length&&j(I.key)}},h=(I,_=0)=>I.map((X,C)=>{if(_e(X))return n.jsx("div",{className:"rw-menu-divider"},X.key??`div-${C}`);const g=X,d=!!g.children?.length,B=N.has(g.key),L=g.key===w;return n.jsxs("div",{className:"rw-menu-group",children:[n.jsxs("button",{type:"button",className:`rw-menu-item ${L?"selected":""} ${g.disabled?"disabled":""}`,style:{paddingLeft:b?12:12+_*16},onClick:()=>Z(g),disabled:g.disabled,title:b?ce(g.label):void 0,children:[g.icon&&n.jsx("span",{className:"rw-menu-icon",children:g.icon}),!b&&n.jsx("span",{className:"rw-menu-label",children:g.label}),!b&&d&&n.jsx("span",{className:`rw-menu-arrow ${B?"open":""}`,onClick:k=>j(g.key,k),role:"presentation",children:n.jsx(Ye,{size:10})})]}),!b&&d&&B&&n.jsx("div",{className:"rw-menu-children",children:h(g.children,_+1)})]},g.key)}),P=b?64:f;return n.jsxs("div",{className:"rw-workspace-sidebar-wrapper",children:[n.jsxs("aside",{className:"rw-workspace-sider",style:{width:P},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:P},onClick:R,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})]}),ke=({window:e,active:t,children:s})=>n.jsx("div",{className:`rw-window-container ${t?"active":""}`,style:{display:t?"flex":"none",height:"100%",overflow:"auto",flexDirection:"column"},"data-window-type":e.type,children:s}),Ue=({items:e,trigger:t,className:s})=>{const[o,p]=l.useState(!1),x=l.useRef(null);return l.useEffect(()=>{if(!o)return;const y=f=>{x.current?.contains(f.target)||p(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[o]),n.jsxs("div",{className:`rw-dropdown ${s||""}`,ref:x,children:[n.jsx("div",{className:"rw-dropdown-trigger",onClick:()=>p(y=>!y),role:"button",tabIndex:0,children:t}),o&&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))})]})},Se=({windows:e,activeWindowId:t,onSwitchWindow:s,onCloseWindow:o,onToggleMinimize:p,onBatchManage:x,onFloatWindow:y,onRestoreWindow:f,onReorderWindows:u,allWindows:b=e})=>{const $=e.findIndex(g=>g.id===t),N=l.useRef(null),O=l.useRef(null),[w,R]=l.useState(null),[j,Z]=l.useState(null),h=l.useRef({windowId:"",startX:0,startY:0,fromIndex:-1,mode:"none",floated:!1}),P=l.useCallback(g=>{const d=O.current;if(!d)return e.length;const B=d.getBoundingClientRect(),L=g-B.left,k=d.querySelectorAll(".rw-tab-item");if(L<8)return 0;for(let z=0;z<k.length;z++){const v=k[z].getBoundingClientRect(),S=v.left-B.left+v.width/2;if(L<S)return z}return k.length},[e.length]),I=l.useCallback((g,d,B)=>{if(g.target.closest(".rw-window-tab-close-btn")||g.button!==0)return;h.current={windowId:d,startX:g.clientX,startY:g.clientY,fromIndex:B,mode:"none",floated:!1};const L=v=>{const S=v.clientX-h.current.startX,W=v.clientY-h.current.startY,T=Math.sqrt(S*S+W*W);T<8||(h.current.mode==="none"&&(Math.abs(W)>40&&T>50?h.current.mode="float":Math.abs(S)>12&&Math.abs(S)>Math.abs(W)?h.current.mode="reorder":T>50&&(h.current.mode="float")),h.current.mode==="float"&&h.current.windowId===d?h.current.floated||(h.current.floated=!0,y?.(d,{x:v.clientX,y:v.clientY})):h.current.mode==="reorder"&&R(P(v.clientX)))},k=v=>{if(h.current.mode==="reorder"&&h.current.windowId===d){let W=P(v.clientX);W>h.current.fromIndex&&(W-=1),W!==h.current.fromIndex&&u&&u(h.current.fromIndex,W)}R(null),z()},z=()=>{document.removeEventListener("mousemove",L),document.removeEventListener("mouseup",k),h.current={windowId:"",startX:0,startY:0,fromIndex:-1,mode:"none",floated:!1}};document.addEventListener("mousemove",L),document.addEventListener("mouseup",k)},[y,u,P]);l.useEffect(()=>{let g=null;const d=k=>{const{windowTitle:z,clientX:v}=k.detail,S=P(v);g&&cancelAnimationFrame(g),g=requestAnimationFrame(()=>{Z({title:z,index:S}),R(S)})},B=()=>{Z(null),R(null)},L=N.current;return L?.addEventListener("floatingWindowDragOver",d),L?.addEventListener("clearFloatingWindowPreview",B),()=>{L?.removeEventListener("floatingWindowDragOver",d),L?.removeEventListener("clearFloatingWindowPreview",B),g&&cancelAnimationFrame(g)}},[P]);const _=g=>{g.preventDefault();try{const d=sessionStorage.getItem("draggingWindowTitle");d&&Z({title:d,index:P(g.clientX)})}catch{}R(P(g.clientX))},X=g=>{g.preventDefault();let d=g.dataTransfer.getData("windowId")||"";if(!d)try{d=sessionStorage.getItem("draggingWindowId")||""}catch{}d&&f&&f(d,w??void 0),Z(null),R(null)},C=[{key:"close-others",label:"关闭其他",disabled:e.length<=1,onClick:()=>x("close-others")},{key:"close-left",label:"关闭左侧",disabled:$<=0,onClick:()=>x("close-left")},{key:"close-right",label:"关闭右侧",disabled:$<0||$>=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(g=>g.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:N,onDragOver:_,onDragLeave:()=>{Z(null),R(null)},onDrop:X,children:n.jsxs("div",{className:"rw-window-tabs-container",children:[n.jsxs("div",{className:"rw-tab-list",ref:O,children:[e.map((g,d)=>n.jsxs("div",{className:`rw-tab-item ${g.id===t?"active":""}`,onClick:()=>s(g.id),onMouseDown:B=>I(B,g.id,d),children:[n.jsx("span",{className:"rw-tab-title",children:g.title}),n.jsx("button",{type:"button",title:"关闭",className:"rw-icon-btn rw-window-tab-close-btn",onClick:B=>{B.stopPropagation(),o(g.id)},children:n.jsx(we,{size:12})})]},g.id)),j&&w!==null&&n.jsx("div",{className:"rw-tab-preview",style:{order:w},children:j.title})]}),w!==null&&!j&&n.jsx(Ke,{listRef:O,index:w}),e.length>0&&n.jsx(Ue,{items:C,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[s,o]=l.useState(0);return l.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){o(8);return}if(t>=y.length){const u=y[y.length-1];o(u.offsetLeft+u.offsetWidth+2);return}const f=y[t];o(f.offsetLeft-1)};return p(),window.addEventListener("resize",p),()=>window.removeEventListener("resize",p)},[e,t]),n.jsx("div",{className:"rw-window-tab-insert-indicator",style:{left:`${s}px`}})},Ve={x:100,y:100,width:800,height:600,minWidth:400,minHeight:300},Ce=({window:e,children:t,floatingDefaults:s,onUpdateFloatingPosition:o,onRestoreWindow:p,onCloseWindow:x,onToggleMinimize:y,onFocusWindow:f})=>{const u={...Ve,...s},b=l.useRef(null),$=l.useRef(null),[N,O]=l.useState(!1),[w,R]=l.useState(!1),[j,Z]=l.useState(!1),h=l.useRef(!1),P=l.useRef(""),I=l.useRef({x:0,y:0,startX:0,startY:0,startWidth:0,startHeight:0}),_=l.useRef({x:0,y:0,width:0,height:0,startX:0,startY:0}),X=l.useRef(null),C=l.useRef(null),g=l.useRef(null),d=e.floatingPosition||{x:u.x,y:u.y,width:u.width,height:u.height};l.useEffect(()=>{if(!e.pendingDragStart||N||w)return;let k=d.x,z=d.y;if(b.current){const v=b.current.getBoundingClientRect();k=v.left,z=v.top}f?.(e.id),g.current={windowId:e.id,windowTitle:e.title};try{sessionStorage.setItem("draggingWindowId",e.id),sessionStorage.setItem("draggingWindowTitle",e.title)}catch{}O(!0),I.current={x:e.pendingDragStart.x-k,y:e.pendingDragStart.y-z,startX:k,startY:z,startWidth:d.width,startHeight:d.height}},[e.pendingDragStart,e.id,e.title,N,w,d,f]),l.useEffect(()=>{if(N||w||e.pendingDragStart)return;const k={minWidth:u.minWidth,minHeight:u.minHeight},z=Q(d,k);(z.x!==d.x||z.y!==d.y||z.width!==d.width||z.height!==d.height)&&o(e.id,z)},[e.id,e.pendingDragStart]),l.useEffect(()=>{if(!b.current||N||w)return;const k=b.current;k.style.transform=`translate(${d.x}px, ${d.y}px)`,k.style.width=`${d.width}px`,k.style.height=`${d.height}px`},[d.x,d.y,d.width,d.height,N,w]);const B=l.useCallback(k=>{const z=k.target;if(z.closest(".rw-floating-window-action-btn")||z.closest(".rw-floating-window-resize-handle")||!$.current?.contains(z))return;f?.(e.id);let v=d.x,S=d.y;if(b.current){const W=b.current.getBoundingClientRect();v=W.left,S=W.top}g.current={windowId:e.id,windowTitle:e.title};try{sessionStorage.setItem("draggingWindowId",e.id),sessionStorage.setItem("draggingWindowTitle",e.title)}catch{}O(!0),I.current={x:k.clientX-v,y:k.clientY-S,startX:v,startY:S,startWidth:d.width,startHeight:d.height}},[d,e.id,e.title,f]),L=l.useCallback((k,z)=>{k.stopPropagation(),k.preventDefault(),f?.(e.id);let v=d.x,S=d.y,W=d.width,T=d.height;if(b.current){const E=b.current.getBoundingClientRect();v=E.left,S=E.top,W=E.width,T=E.height}R(!0),P.current=z,_.current={x:k.clientX,y:k.clientY,width:W,height:T,startX:v,startY:S}},[d,e.id,f]);return l.useEffect(()=>{const k=v=>{if(N){v.preventDefault();const S=document.querySelector(".rw-window-tabs");if(S&&g.current){const H=S.getBoundingClientRect(),q=v.clientY>=H.top&&v.clientY<=H.bottom&&v.clientX>=H.left&&v.clientX<=H.right,K=h.current;Z(q),h.current=q,q?S.dispatchEvent(new CustomEvent("floatingWindowDragOver",{detail:{...g.current,clientX:v.clientX,clientY:v.clientY}})):K&&S.dispatchEvent(new CustomEvent("clearFloatingWindowPreview"))}const W=I.current.startWidth,T=I.current.startHeight,E=Math.max(0,Math.min(v.clientX-I.current.x,globalThis.window.innerWidth-W)),F=Math.max(0,Math.min(v.clientY-I.current.y,globalThis.window.innerHeight-T));b.current.style.transform=`translate(${E}px, ${F}px)`,C.current={x:E,y:F,width:I.current.startWidth,height:I.current.startHeight}}else if(w){v.preventDefault();const S=P.current,W=_.current;let T=W.startX,E=W.startY,F=W.width,H=W.height;const q=v.clientX-W.x,K=v.clientY-W.y;S.includes("e")&&(F=Math.max(u.minWidth,W.width+q)),S.includes("w")&&(F=Math.max(u.minWidth,W.width-q),T=W.startX+W.width-F),S.includes("s")&&(H=Math.max(u.minHeight,W.height+K)),S.includes("n")&&(H=Math.max(u.minHeight,W.height-K),E=W.startY+W.height-H);const G=b.current;G.style.transform=`translate(${T}px, ${E}px)`,G.style.width=`${F}px`,G.style.height=`${H}px`,C.current={x:T,y:E,width:F,height:H}}},z=v=>{if(v&&g.current){const W=document.querySelector(".rw-window-tabs");if(W){const T=W.getBoundingClientRect();if(v.clientY>=T.top&&v.clientY<=T.bottom&&v.clientX>=T.left&&v.clientX<=T.right){const E=W.querySelector(".rw-tab-list");if(E){let F=E.querySelectorAll(".rw-tab-item").length;const H=E.getBoundingClientRect(),q=v.clientX-H.left;E.querySelectorAll(".rw-tab-item").forEach((K,G)=>{const i=K.getBoundingClientRect();q<i.left-H.left+i.width/2&&(F=Math.min(F,G))}),p(g.current.windowId,F),g.current=null,O(!1),R(!1),Z(!1);return}}}}let S=C.current;S&&(S=Q(S,{minWidth:u.minWidth,minHeight:u.minHeight})),S&&o(e.id,S),C.current=null,g.current=null;try{sessionStorage.removeItem("draggingWindowId"),sessionStorage.removeItem("draggingWindowTitle")}catch{}O(!1),R(!1),Z(!1),h.current=!1};if(N||w){const v=S=>{X.current&&cancelAnimationFrame(X.current),X.current=requestAnimationFrame(()=>k(S))};return document.addEventListener("mousemove",v,{passive:!1}),document.addEventListener("mouseup",z),document.body.style.userSelect="none",()=>{document.removeEventListener("mousemove",v),document.removeEventListener("mouseup",z),document.body.style.userSelect=""}}},[N,w,e.id,u.minWidth,u.minHeight,o,p]),n.jsxs("div",{ref:b,className:"rw-floating-window",style:{transform:`translate(${d.x}px, ${d.y}px)`,width:d.width,height:d.height,zIndex:e.floatingZIndex||1e3,opacity:j?.5:1,minWidth:u.minWidth,minHeight:u.minHeight},onClick:k=>{k.target.closest("button, a, input, select, textarea")||f?.(e.id)},children:[n.jsxs("div",{ref:$,className:"rw-floating-window-header",onMouseDown:B,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(we,{size:12})})]})]}),n.jsx("div",{className:"rw-floating-window-content",children:t}),["nw","ne","sw","se","n","s","w","e"].map(k=>n.jsx("div",{className:`rw-floating-window-resize-handle rw-floating-window-resize-${k}`,onMouseDown:z=>L(z,k)},k))]})},je=({windows:e,activeWindowId:t,renderWindow:s,onSwitchWindow:o,onCloseWindow:p,onToggleMinimize:x,onBatchManage:y,onFloatWindow:f,onRestoreWindow:u,onUpdateFloatingPosition:b,onFocusWindow:$,onReorderWindows:N,emptyDescription:O="从左侧菜单选择功能开始工作",floatingDefaults:w})=>{if(e.length===0)return n.jsx("div",{className:"rw-window-manager-empty",children:n.jsx(qe,{description:O})});const R=e.filter(h=>h.minimized),j=e.filter(h=>h.floating&&!h.minimized),Z=e.filter(h=>!h.minimized&&!h.floating);return n.jsxs("div",{className:"rw-window-manager",children:[n.jsx(Se,{windows:Z,activeWindowId:t,onSwitchWindow:o,onCloseWindow:p,onToggleMinimize:x,onBatchManage:y,onFloatWindow:f,onRestoreWindow:u,onReorderWindows:N,allWindows:e}),n.jsx("div",{className:"rw-window-content-area",children:Z.map(h=>n.jsx(ke,{window:h,active:h.id===t,children:s(h,{})},h.id))}),R.length>0&&n.jsx("div",{className:"rw-minimized-windows-bar",children:R.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:P=>P.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(Ce,{window:h,floatingDefaults:w,onUpdateFloatingPosition:b||(()=>{}),onRestoreWindow:u||(()=>{}),onCloseWindow:p,onToggleMinimize:x,onFocusWindow:$,children:s(h,{})},h.id))]})};function Je(e){return"type"in e&&e.type==="divider"}function de(e){for(const t of e){if(Je(t))continue;const s=t;if(s.windowType)return s;if(s.children){const o=de(s.children);if(o)return o}}return null}function Ie(e,t){if(t)return{minimized:!1,...t};const s=de(e);if(!s?.windowType)return{type:"home",title:"首页",minimized:!1};const o=ce(s.label)||s.key;return{type:s.windowType,title:o,minimized:!1}}function ze(e,t){const{fallback:s}=t??{};return(o,p)=>{const x=e[o.type]??s;return x?l.createElement(x,{window:o,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 fe(e){const t={};return Object.keys(e).forEach(s=>{const o=e[s];if(o!==void 0){const p=Ge[s];t[p]=typeof o=="number"?`${o}px`:o}}),t}function Me(e){return{colorPrimary:e.colorPrimary,colorPrimaryHover:e.colorPrimaryHover,colorPrimaryBg:e.colorPrimaryBg,colorBg:e.colorBgContainer,colorBgSecondary:e.colorFillAlter??e.colorBgContainer,colorBgTertiary:e.colorBgLayout,colorBgHover:e.colorBgTextHover,colorBgActive:e.colorPrimaryBg,colorBorder:e.colorBorder,colorBorderStrong:e.colorBorderSecondary??e.colorBorder,colorText:e.colorText,colorTextSecondary:e.colorTextSecondary,colorTextMuted:e.colorTextTertiary,radius:e.borderRadius,fontSize:e.fontSize}}function Qe(e){return fe(Me(e))}const et=l.forwardRef(function({workspaceId:t="default",menuItems:s,renderWindow:o,windows:p,sidebarHeader:x,sidebarFooter:y,defaultWindow:f,loading:u=!1,loadingTip:b="加载中...",onAction:$,activeWindowType:N,emptyDescription:O,syncToUrl:w=!1,preserveUrlParams:R=!0,searchParams:j,setSearchParams:Z,floatingDefaults:h,onWindowsChange:P,onReady:I,siderWidth:_=240,contentBackground:X,themeClassName:C,theme:g,renderSidebar:d,className:B,style:L},k){const z=l.useMemo(()=>Ie(s,f),[s,f]),v=l.useMemo(()=>{if(o)return o;if(p)return ze(p);throw new Error("[react-workspace] 请提供 renderWindow 或 windows")},[o,p]),S=pe({workspaceId:t,defaultWindow:z,syncToUrl:w,preserveUrlParams:R,searchParams:j,setSearchParams:Z,floatingDefaults:h,onWindowsChange:P}),{windows:W,activeWindowId:T,openWindow:E,switchWindow:F,closeWindow:H,toggleMinimize:q,floatWindow:K,restoreWindow:G,updateFloatingPosition:i,focusWindow:r,batchManage:a,updateWindowProps:c,clearPendingAction:m,reorderWindows:M}=S,A={workspaceId:t,...S};l.useImperativeHandle(k,()=>A,[t,W,T]),l.useEffect(()=>{I&&W.length>0&&I({workspaceId:t,...S})},[I,t,W.length]);const Y=l.useMemo(()=>N!==void 0?N:W.find(J=>J.id===T)?.type,[N,W,T]),U=l.useCallback((J,oe)=>{E({type:J,title:be(s,J),minimized:!1},oe)},[E,s]),D=l.useCallback((J,oe)=>({workspaceId:t,active:oe,activeWindowId:T,windows:W,openWindow:E,switchWindow:F,closeWindow:H,toggleMinimize:q,floatWindow:K,updateWindowProps:(Re,Pe)=>c(Re,Pe),clearPendingAction:m}),[t,T,W,E,F,H,q,K,c,m]),V=l.useMemo(()=>({...A,buildRenderContext:D}),[t,W,T,D]),Ne=X??"var(--rw-color-bg-tertiary)",Te={minHeight:"100vh",height:"100vh",display:"flex",...g?fe(g):void 0,...L},ue={menuItems:s,onMenuClick:U,onAction:$,activeWindowType:Y,header:x,footer:y,defaultOpenKeys:ve(s),siderWidth:_};return n.jsx(xe,{value:V,children:n.jsxs("div",{className:`rw-workspace ${C||""} ${B||""}`.trim(),style:Te,children:[d?d(ue):n.jsx(We,{...ue}),n.jsx("main",{className:"rw-workspace-main",style:{background:Ne},children:n.jsx(De,{spinning:u,tip:b,children:n.jsx(je,{workspaceId:t,windows:W,activeWindowId:T,renderWindow:J=>v(J,D(J,J.id===T&&!J.floating)),onSwitchWindow:F,onCloseWindow:H,onToggleMinimize:q,onBatchManage:a,onOpenWindow:E,onFloatWindow:K,onRestoreWindow:G,onUpdateFloatingPosition:i,onFocusWindow:r,onReorderWindows:M,emptyDescription:O,floatingDefaults:h})})})]})})});exports.FloatingWindow=Ce;exports.WindowContainer=ke;exports.WindowManager=je;exports.WindowTabs=Se;exports.Workspace=et;exports.WorkspaceProvider=xe;exports.WorkspaceSidebar=We;exports.collectParentMenuKeys=ve;exports.createWindowRenderer=ze;exports.findFirstMenuItemWithWindowType=de;exports.findMenuItem=ye;exports.findMenuKeyByWindowType=ae;exports.fixWindowPosition=Q;exports.getAllWindowStatesFromStorage=te;exports.labelToString=ce;exports.mapAntdTokenToCssVars=Qe;exports.mapAntdTokenToWorkspaceTheme=Me;exports.pickNextActiveWindowId=se;exports.resolveDefaultWindow=Ie;exports.resolveWindowTitle=be;exports.saveWindowStateToStorage=ne;exports.themeToCssVars=fe;exports.updateTabClickOrder=ie;exports.useWorkspace=pe;exports.useWorkspaceContext=Be;exports.useWorkspaceContextOptional=Ze;
|