@liuman/react-workspace 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1258 @@
1
+ import { jsxs as j, jsx as s } from "react/jsx-runtime";
2
+ import { useRef as q, useState as ee, useCallback as R, useEffect as ne, createContext as Ne, useContext as we, useMemo as oe, createElement as Me, forwardRef as Pe, useImperativeHandle as Te } from "react";
3
+ import { createPortal as De } from "react-dom";
4
+ const Ee = ({
5
+ tip: e = "加载中...",
6
+ spinning: t = !1,
7
+ children: o
8
+ }) => /* @__PURE__ */ j("div", { className: "rw-spinner-wrap", children: [
9
+ o,
10
+ t && /* @__PURE__ */ j("div", { className: "rw-spinner-overlay", children: [
11
+ /* @__PURE__ */ s("div", { className: "rw-spinner" }),
12
+ e && /* @__PURE__ */ s("span", { className: "rw-spinner-tip", children: e })
13
+ ] })
14
+ ] }), ge = 100;
15
+ function ie(e, t) {
16
+ const o = globalThis.window.innerWidth, r = globalThis.window.innerHeight, g = Math.min(t?.minWidth ?? ge, o), m = Math.min(t?.minHeight ?? ge, r);
17
+ let { x: h, y: d, width: f, height: p } = e;
18
+ return f = Math.min(f, o), p = Math.min(p, r), f = Math.max(f, g), p = Math.max(p, m), h + f > o && (h = Math.max(0, o - f)), d + p > r && (d = Math.max(0, r - p)), h < 0 && (h = 0), d < 0 && (d = 0), { x: h, y: d, width: f, height: p };
19
+ }
20
+ function ae(e, t) {
21
+ return `${e}${t}`;
22
+ }
23
+ function se(e, t) {
24
+ if (!t) return {};
25
+ try {
26
+ const o = ae(e, t), r = localStorage.getItem(o);
27
+ if (r) {
28
+ const g = JSON.parse(r);
29
+ if (g && typeof g == "object") {
30
+ const m = {};
31
+ return Object.entries(g).forEach(([h, d]) => {
32
+ if (d && typeof d == "object") {
33
+ const f = d, p = {};
34
+ f.position && typeof f.position.x == "number" && typeof f.position.y == "number" && typeof f.position.width == "number" && typeof f.position.height == "number" && (p.position = ie(f.position)), typeof f.minimized == "boolean" && (p.minimized = f.minimized), typeof f.floating == "boolean" && (p.floating = f.floating), typeof f.floatingZIndex == "number" && (p.floatingZIndex = f.floatingZIndex), m[h] = p;
35
+ }
36
+ }), m;
37
+ }
38
+ }
39
+ } catch (o) {
40
+ console.warn("[react-workspace] 从 localStorage 读取窗口状态失败:", o);
41
+ }
42
+ return {};
43
+ }
44
+ function le(e, t, o, r) {
45
+ if (t)
46
+ try {
47
+ const g = se(e, t);
48
+ g[o] = { ...g[o], ...r }, localStorage.setItem(ae(e, t), JSON.stringify(g));
49
+ } catch (g) {
50
+ console.warn("[react-workspace] 保存窗口状态到 localStorage 失败:", g);
51
+ }
52
+ }
53
+ function de(e, t, o) {
54
+ if (t)
55
+ try {
56
+ const r = ae(e, t), g = localStorage.getItem(r);
57
+ let m = g ? JSON.parse(g) : {};
58
+ const h = Object.values(m).map((E) => E?.floatingZIndex || 0).filter((E) => E >= 1e3), d = h.length > 0 ? Math.max(...h) : 999, f = m[o] || {}, p = f.floatingZIndex || 0, _ = Math.max(1e3, d + 1);
59
+ p >= 1e3 ? (m[o] = { ...f, floatingZIndex: _ }, Object.keys(m).forEach((E) => {
60
+ if (E !== o && m[E]) {
61
+ const H = m[E];
62
+ H.floatingZIndex !== void 0 && H.floatingZIndex >= 1e3 && (m[E] = {
63
+ ...H,
64
+ floatingZIndex: Math.max(1e3, H.floatingZIndex - 1)
65
+ });
66
+ }
67
+ })) : m[o] = { ...f, floatingZIndex: _ }, localStorage.setItem(r, JSON.stringify(m));
68
+ } catch (r) {
69
+ console.error("[react-workspace] 保存标签点击顺序失败:", r);
70
+ }
71
+ }
72
+ function me(e, t, o) {
73
+ if (e.length === 0) return null;
74
+ try {
75
+ const r = localStorage.getItem(ae(t, o));
76
+ if (r) {
77
+ const g = JSON.parse(r);
78
+ return [...e].sort((h, d) => {
79
+ const f = g[h.type]?.floatingZIndex || 0, p = g[d.type]?.floatingZIndex || 0;
80
+ return f >= 1e3 && p >= 1e3 ? p - f : f >= 1e3 ? -1 : p >= 1e3 ? 1 : 0;
81
+ })[0]?.id ?? e[e.length - 1].id;
82
+ }
83
+ } catch {
84
+ }
85
+ return e[e.length - 1].id;
86
+ }
87
+ const Re = "react_workspace_windows_", Ze = {
88
+ x: 100,
89
+ y: 100,
90
+ width: 800,
91
+ height: 600,
92
+ minWidth: 400,
93
+ minHeight: 300
94
+ };
95
+ function he(e) {
96
+ return { ...Ze, ...e };
97
+ }
98
+ function pe() {
99
+ return `window-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`;
100
+ }
101
+ function $e(e) {
102
+ const {
103
+ workspaceId: t,
104
+ defaultWindow: o,
105
+ syncToUrl: r = !1,
106
+ preserveUrlParams: g = !0,
107
+ searchParams: m,
108
+ setSearchParams: h,
109
+ storageKeyPrefix: d = Re,
110
+ floatingDefaults: f,
111
+ onWindowsChange: p
112
+ } = e, _ = q(
113
+ o ?? { type: "home", title: "首页", minimized: !1 }
114
+ );
115
+ _.current = o ?? _.current;
116
+ const E = q(he(f));
117
+ E.current = he(f);
118
+ const H = q(p);
119
+ H.current = p;
120
+ const [w, Z] = ee([]), [x, U] = ee(null), O = q({}), z = R((n, i) => {
121
+ H.current?.(n, i);
122
+ }, []), a = R(
123
+ (n) => se(d, t)[n] || null,
124
+ [d, t]
125
+ ), L = R(
126
+ (n) => a(n)?.position || null,
127
+ [a]
128
+ ), A = R(
129
+ (n, i) => {
130
+ if (!r || !h) return;
131
+ const l = g && m ? new URLSearchParams(m) : new URLSearchParams();
132
+ n.length > 0 ? l.set("windows", encodeURIComponent(JSON.stringify(
133
+ n.map((c) => ({ id: c.id, type: c.type, title: c.title }))
134
+ ))) : l.delete("windows"), i ? l.set("active", i) : l.delete("active"), h(l, { replace: !0 });
135
+ },
136
+ [r, h, g, m]
137
+ ), k = R(
138
+ (n, i) => {
139
+ Z(n), U(i), A(n, i), z(n, i);
140
+ },
141
+ [A, z]
142
+ ), D = R(
143
+ (n) => {
144
+ const i = a(n.type), l = {
145
+ ...n,
146
+ minimized: i?.minimized ?? n.minimized ?? !1,
147
+ floating: i?.floating ?? n.floating ?? !1
148
+ };
149
+ if (l.floating) {
150
+ let c = n.floatingPosition || i?.position;
151
+ c || (c = L(n.type) ?? void 0), c && (l.floatingPosition = ie(c)), l.floatingZIndex = i?.floatingZIndex ?? n.floatingZIndex ?? 1e3;
152
+ }
153
+ return l;
154
+ },
155
+ [a, L]
156
+ ), y = R(() => {
157
+ const n = _.current, i = {
158
+ id: pe(),
159
+ type: n.type,
160
+ title: n.title,
161
+ minimized: n.minimized ?? !1
162
+ };
163
+ k([i], i.id);
164
+ }, [k]), I = R(() => {
165
+ if (t)
166
+ try {
167
+ localStorage.removeItem(`${d}${t}`);
168
+ } catch {
169
+ }
170
+ delete O.current[t], y();
171
+ }, [t, d, y]);
172
+ ne(() => {
173
+ if (!t || O.current[t]) return;
174
+ O.current[t] = !0;
175
+ const n = r ? m?.get("windows") : null, i = r ? m?.get("active") : null;
176
+ if (n)
177
+ try {
178
+ const c = JSON.parse(decodeURIComponent(n)).map(D), u = i && c.some((T) => T.id === i) ? i : c[0]?.id ?? null;
179
+ Z(c), U(u), z(c, u);
180
+ } catch (l) {
181
+ console.error("[react-workspace] 解析窗口配置失败:", l), y();
182
+ }
183
+ else
184
+ y();
185
+ }, [t, m, r, D, y, z]);
186
+ const M = R(
187
+ (n, i) => {
188
+ const l = i !== void 0 ? { ...n.props, ...i } : n.props, c = { ...n, props: l }, u = w.find((T) => T.type === c.type);
189
+ if (u) {
190
+ const T = i && Object.keys(i).length === 0 ? void 0 : l, F = D({ ...u, ...c, props: T }), Y = w.map((J) => J.id === u.id ? F : J);
191
+ k(Y, u.id);
192
+ } else {
193
+ const T = D({
194
+ ...c,
195
+ id: pe(),
196
+ minimized: c.minimized ?? !1
197
+ });
198
+ k([...w, T], T.id);
199
+ }
200
+ },
201
+ [w, k, D]
202
+ ), W = R(
203
+ (n) => {
204
+ const i = w.find((l) => l.id === n);
205
+ if (i) {
206
+ if (de(d, t, i.type), i.floating) {
207
+ const l = se(d, t)[i.type];
208
+ if (l?.floatingZIndex) {
209
+ const c = w.map(
210
+ (u) => u.id === n ? { ...u, minimized: !1, floatingZIndex: l.floatingZIndex } : u
211
+ );
212
+ k(c, n);
213
+ return;
214
+ }
215
+ }
216
+ k(
217
+ w.map((l) => l.id === n ? { ...l, minimized: !1 } : l),
218
+ n
219
+ );
220
+ }
221
+ },
222
+ [w, k, d, t]
223
+ ), S = R(
224
+ (n) => {
225
+ const i = w.filter((c) => c.id !== n), l = x === n ? me(i, d, t) : x;
226
+ k(i, l);
227
+ },
228
+ [w, x, k, d, t]
229
+ ), v = R(
230
+ (n) => {
231
+ const i = w.map((c) => {
232
+ if (c.id === n) {
233
+ const u = { ...c, minimized: !c.minimized };
234
+ return le(d, t, c.type, {
235
+ minimized: u.minimized,
236
+ floating: u.floating
237
+ }), u;
238
+ }
239
+ return c;
240
+ }), l = i.find((c) => c.id === n);
241
+ if (l?.minimized && x === n && !l.floating) {
242
+ const c = i.find((u) => !u.minimized && !u.floating);
243
+ k(i, c?.id ?? null);
244
+ } else l && !l.minimized && !l.floating ? k(i, n) : k(i, x);
245
+ },
246
+ [w, x, t, d, k]
247
+ ), C = R(
248
+ (n, i) => {
249
+ const l = w.find((B) => B.id === n);
250
+ if (!l || !t || l.floating) return;
251
+ const c = w.filter((B) => !B.floating && !B.minimized);
252
+ if (c.length === 1 && c[0].id === n) return;
253
+ const u = E.current, T = { minWidth: u.minWidth, minHeight: u.minHeight };
254
+ let F = ie(
255
+ { x: u.x, y: u.y, width: u.width, height: u.height },
256
+ T
257
+ );
258
+ if (i)
259
+ F = ie({
260
+ x: i.x,
261
+ y: i.y,
262
+ width: u.width,
263
+ height: u.height
264
+ }, T);
265
+ else if (l.floatingPosition)
266
+ F = ie(l.floatingPosition, T);
267
+ else {
268
+ const B = L(l.type);
269
+ B && (F = ie(B, T));
270
+ }
271
+ de(d, t, l.type);
272
+ const Y = se(d, t)[l.type]?.floatingZIndex ?? 1e3, J = w.map((B) => B.id === n ? (le(d, t, B.type, {
273
+ floating: !0,
274
+ minimized: !1,
275
+ position: F,
276
+ floatingZIndex: Y
277
+ }), {
278
+ ...B,
279
+ floating: !0,
280
+ minimized: !1,
281
+ floatingPosition: F,
282
+ floatingZIndex: Y,
283
+ pendingDragStart: i
284
+ }) : B);
285
+ if (x === n) {
286
+ const B = J.filter((V) => !V.floating && !V.minimized);
287
+ k(J, B.length > 0 ? me(B, d, t) : null);
288
+ } else
289
+ k(J, x);
290
+ },
291
+ [w, x, t, d, k, L]
292
+ ), b = R(
293
+ (n, i) => {
294
+ const l = w.find((V) => V.id === n);
295
+ if (!l?.floating) return;
296
+ const { floating: c, floatingPosition: u, floatingZIndex: T, pendingDragStart: F, ...Y } = l;
297
+ le(d, t, l.type, {
298
+ floating: !1,
299
+ minimized: Y.minimized
300
+ });
301
+ const J = w.filter((V) => !V.floating);
302
+ let B;
303
+ i !== void 0 && i >= 0 && i <= J.length ? B = [...J.slice(0, i), Y, ...J.slice(i)] : B = [...J, Y], B = [...B, ...w.filter((V) => V.floating && V.id !== n)], k(B, n), setTimeout(() => {
304
+ document.querySelector(".rw-window-tabs")?.dispatchEvent(new CustomEvent("clearFloatingWindowPreview"));
305
+ }, 0);
306
+ },
307
+ [w, k, d, t]
308
+ ), P = R(
309
+ (n, i) => {
310
+ const l = w.find((u) => u.id === n);
311
+ if (!l) return;
312
+ const c = w.map((u) => {
313
+ if (u.id === n) {
314
+ const { pendingDragStart: T, ...F } = u;
315
+ return { ...F, floatingPosition: i };
316
+ }
317
+ return u;
318
+ });
319
+ Z(c), l.floating && le(d, t, l.type, {
320
+ position: i,
321
+ floating: !0,
322
+ minimized: l.minimized,
323
+ floatingZIndex: l.floatingZIndex
324
+ });
325
+ },
326
+ [w, t, d]
327
+ ), N = R(
328
+ (n) => {
329
+ const i = w.find((c) => c.id === n);
330
+ if (!i?.floating || !t) return;
331
+ de(d, t, i.type);
332
+ const l = se(d, t)[i.type];
333
+ l?.floatingZIndex && Z(
334
+ (c) => c.map(
335
+ (u) => u.id === n && u.floating ? { ...u, floatingZIndex: l.floatingZIndex } : u
336
+ )
337
+ );
338
+ },
339
+ [w, t, d]
340
+ ), $ = R(
341
+ (n, i) => {
342
+ Z((l) => {
343
+ const c = l.map(
344
+ (u) => u.id === n ? { ...u, props: { ...u.props, ...i } } : u
345
+ );
346
+ return z(c, x), c;
347
+ });
348
+ },
349
+ [x, z]
350
+ ), X = R(
351
+ (n, i) => {
352
+ Z((l) => {
353
+ const c = l.map((u) => u.id === n ? { ...u, title: i } : u);
354
+ return A(c, x), z(c, x), c;
355
+ });
356
+ },
357
+ [x, A, z]
358
+ ), K = R(
359
+ (n) => {
360
+ Z(
361
+ (i) => i.map((l) => {
362
+ if (l.id !== n) return l;
363
+ const { pendingAction: c, ...u } = l;
364
+ return u;
365
+ })
366
+ );
367
+ },
368
+ []
369
+ ), G = R(
370
+ (n) => {
371
+ if (n === "reset-windows") {
372
+ I();
373
+ return;
374
+ }
375
+ if (!x && !["close-all", "minimize-all", "restore-all"].includes(n)) return;
376
+ const i = w.filter((T) => !T.floating), l = w.filter((T) => T.floating);
377
+ let c = [], u = x;
378
+ switch (n) {
379
+ case "close-left": {
380
+ const T = i.findIndex((F) => F.id === x);
381
+ c = i.slice(T);
382
+ break;
383
+ }
384
+ case "close-right": {
385
+ const T = i.findIndex((F) => F.id === x);
386
+ c = i.slice(0, T + 1);
387
+ break;
388
+ }
389
+ case "close-others":
390
+ c = i.filter((T) => T.id === x);
391
+ break;
392
+ case "close-all":
393
+ c = [], u = null;
394
+ break;
395
+ case "minimize-all":
396
+ c = i.map((T) => ({ ...T, minimized: !0 })), u = null;
397
+ break;
398
+ case "restore-all":
399
+ c = i.map((T) => ({ ...T, minimized: !1 })), u = x ?? c[0]?.id ?? null;
400
+ break;
401
+ default:
402
+ c = i;
403
+ }
404
+ k([...c, ...l], u);
405
+ },
406
+ [w, x, k, I]
407
+ ), Q = R(
408
+ (n, i) => {
409
+ const l = w.filter((Y) => !Y.minimized && !Y.floating);
410
+ if (n < 0 || n >= l.length || i < 0 || i >= l.length || n === i) return;
411
+ const c = [...l], [u] = c.splice(n, 1);
412
+ c.splice(i, 0, u);
413
+ let T = 0;
414
+ const F = w.map((Y) => Y.minimized || Y.floating ? Y : c[T++]);
415
+ k(F, x);
416
+ },
417
+ [w, x, k]
418
+ );
419
+ return {
420
+ windows: w,
421
+ activeWindowId: x,
422
+ openWindow: M,
423
+ switchWindow: W,
424
+ closeWindow: S,
425
+ toggleMinimize: v,
426
+ floatWindow: C,
427
+ restoreWindow: b,
428
+ updateFloatingPosition: P,
429
+ focusWindow: N,
430
+ batchManage: G,
431
+ updateWindowProps: $,
432
+ updateWindowTitle: X,
433
+ clearPendingAction: K,
434
+ setWindows: Z,
435
+ setActiveWindowId: U,
436
+ resetWorkspace: I,
437
+ reorderWindows: Q
438
+ };
439
+ }
440
+ const fe = Ne(null), Be = fe.Provider;
441
+ function gt() {
442
+ const e = we(fe);
443
+ if (!e)
444
+ throw new Error("[react-workspace] useWorkspaceContext 必须在 Workspace 或 WorkspaceProvider 内使用");
445
+ return e;
446
+ }
447
+ function mt() {
448
+ return we(fe);
449
+ }
450
+ const re = (e) => ({ width: e, height: e, viewBox: "0 0 24 24", fill: "currentColor" }), ye = ({ size: e = 14, className: t }) => /* @__PURE__ */ s("svg", { ...re(e), className: t, children: /* @__PURE__ */ s("path", { d: "M6 6l12 12M18 6L6 18", stroke: "currentColor", strokeWidth: "2", fill: "none" }) }), Oe = ({ size: e = 14, className: t }) => /* @__PURE__ */ s("svg", { ...re(e), className: t, children: /* @__PURE__ */ s("path", { d: "M5 12h14", stroke: "currentColor", strokeWidth: "2", fill: "none" }) }), He = ({ size: e = 14, className: t }) => /* @__PURE__ */ s("svg", { ...re(e), className: t, children: /* @__PURE__ */ s("rect", { x: "5", y: "5", width: "14", height: "14", rx: "1", stroke: "currentColor", strokeWidth: "2", fill: "none" }) }), Xe = ({ size: e = 16, className: t }) => /* @__PURE__ */ j("svg", { ...re(e), className: t, children: [
451
+ /* @__PURE__ */ s("circle", { cx: "6", cy: "12", r: "1.5" }),
452
+ /* @__PURE__ */ s("circle", { cx: "12", cy: "12", r: "1.5" }),
453
+ /* @__PURE__ */ s("circle", { cx: "18", cy: "12", r: "1.5" })
454
+ ] }), Le = ({ size: e = 12, className: t }) => /* @__PURE__ */ s("svg", { ...re(e), className: t, children: /* @__PURE__ */ s("path", { d: "M9 6l6 6-6 6", stroke: "currentColor", strokeWidth: "2", fill: "none" }) }), Ae = ({ size: e = 12, className: t }) => /* @__PURE__ */ s("svg", { ...re(e), className: t, children: /* @__PURE__ */ s("path", { d: "M15 6l-6 6 6 6", stroke: "currentColor", strokeWidth: "2", fill: "none" }) }), Fe = ({ size: e = 64, className: t }) => /* @__PURE__ */ s("svg", { ...re(e), className: t, fill: "none", stroke: "currentColor", strokeWidth: "1.5", children: /* @__PURE__ */ s("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 }) => /* @__PURE__ */ s("svg", { ...re(e), className: t, children: /* @__PURE__ */ s("path", { d: "M6 9l6 6 6-6", stroke: "currentColor", strokeWidth: "2", fill: "none" }) });
455
+ function _e(e, t) {
456
+ for (const o of e) {
457
+ if ("type" in o && o.type === "divider") continue;
458
+ const r = o;
459
+ if (r.key === t) return r;
460
+ if (r.children) {
461
+ const g = _e(r.children, t);
462
+ if (g) return g;
463
+ }
464
+ }
465
+ return null;
466
+ }
467
+ function Ue(e, t, o) {
468
+ const r = (g) => {
469
+ for (const m of g) {
470
+ if ("type" in m && m.type === "divider") continue;
471
+ const h = m;
472
+ if (h.windowType === t)
473
+ return typeof h.label == "string" ? h.label : h.key;
474
+ if (h.children) {
475
+ const d = r(h.children);
476
+ if (d) return d;
477
+ }
478
+ }
479
+ return null;
480
+ };
481
+ return r(e) ?? o ?? t;
482
+ }
483
+ function ve(e, t) {
484
+ for (const o of e) {
485
+ if ("type" in o && o.type === "divider") continue;
486
+ const r = o;
487
+ if (r.windowType === t) return r.key;
488
+ if (r.children) {
489
+ const g = ve(r.children, t);
490
+ if (g) return g;
491
+ }
492
+ }
493
+ return null;
494
+ }
495
+ function qe(e) {
496
+ const t = [];
497
+ for (const o of e) {
498
+ if ("type" in o && o.type === "divider") continue;
499
+ const r = o;
500
+ r.children?.length && t.push(r.key);
501
+ }
502
+ return t;
503
+ }
504
+ function be(e) {
505
+ return typeof e == "string" || typeof e == "number" ? String(e) : "";
506
+ }
507
+ function je(e) {
508
+ return "type" in e && e.type === "divider";
509
+ }
510
+ const Ke = ({
511
+ menuItems: e,
512
+ onMenuClick: t,
513
+ onAction: o,
514
+ activeWindowType: r,
515
+ header: g,
516
+ footer: m,
517
+ defaultOpenKeys: h = [],
518
+ siderWidth: d = 240,
519
+ onCollapsedChange: f
520
+ }) => {
521
+ const [p, _] = ee(!1), [E, H] = ee(new Set(h)), w = oe(() => r ? ve(e, r) : null, [r, e]), Z = () => {
522
+ _((a) => (f?.(!a), !a));
523
+ }, x = (a, L) => {
524
+ L?.stopPropagation(), H((A) => {
525
+ const k = new Set(A);
526
+ return k.has(a) ? k.delete(a) : k.add(a), k;
527
+ });
528
+ }, U = (a) => {
529
+ if (!a.disabled) {
530
+ if (a.windowType) {
531
+ t(a.windowType, a.props);
532
+ return;
533
+ }
534
+ if (a.action && o) {
535
+ o(a.action);
536
+ return;
537
+ }
538
+ a.children?.length && x(a.key);
539
+ }
540
+ }, O = (a, L = 0) => a.map((A, k) => {
541
+ if (je(A))
542
+ return /* @__PURE__ */ s("div", { className: "rw-menu-divider" }, A.key ?? `div-${k}`);
543
+ const D = A, y = !!D.children?.length, I = E.has(D.key), M = D.key === w;
544
+ return /* @__PURE__ */ j("div", { className: "rw-menu-group", children: [
545
+ /* @__PURE__ */ j(
546
+ "button",
547
+ {
548
+ type: "button",
549
+ className: `rw-menu-item ${M ? "selected" : ""} ${D.disabled ? "disabled" : ""}`,
550
+ style: { paddingLeft: p ? 12 : 12 + L * 16 },
551
+ onClick: () => U(D),
552
+ disabled: D.disabled,
553
+ title: p ? be(D.label) : void 0,
554
+ children: [
555
+ D.icon && /* @__PURE__ */ s("span", { className: "rw-menu-icon", children: D.icon }),
556
+ !p && /* @__PURE__ */ s("span", { className: "rw-menu-label", children: D.label }),
557
+ !p && y && /* @__PURE__ */ s(
558
+ "span",
559
+ {
560
+ className: `rw-menu-arrow ${I ? "open" : ""}`,
561
+ onClick: (W) => x(D.key, W),
562
+ role: "presentation",
563
+ children: /* @__PURE__ */ s(Ye, { size: 10 })
564
+ }
565
+ )
566
+ ]
567
+ }
568
+ ),
569
+ !p && y && I && /* @__PURE__ */ s("div", { className: "rw-menu-children", children: O(D.children, L + 1) })
570
+ ] }, D.key);
571
+ }), z = p ? 64 : d;
572
+ return /* @__PURE__ */ j("div", { className: "rw-workspace-sidebar-wrapper", children: [
573
+ /* @__PURE__ */ j("aside", { className: "rw-workspace-sider", style: { width: z }, children: [
574
+ g && /* @__PURE__ */ s("div", { className: `rw-workspace-sidebar-header ${p ? "collapsed" : ""}`, children: g }),
575
+ /* @__PURE__ */ s("nav", { className: "rw-workspace-sidebar-menu", children: O(e) }),
576
+ m && /* @__PURE__ */ s("div", { className: `rw-workspace-sidebar-footer ${p ? "collapsed" : ""}`, children: m })
577
+ ] }),
578
+ /* @__PURE__ */ s(
579
+ "button",
580
+ {
581
+ type: "button",
582
+ className: "rw-workspace-collapse-button",
583
+ style: { left: z },
584
+ onClick: Z,
585
+ title: p ? "展开导航" : "折叠导航",
586
+ children: p ? /* @__PURE__ */ s(Ae, {}) : /* @__PURE__ */ s(Le, {})
587
+ }
588
+ )
589
+ ] });
590
+ }, Je = ({
591
+ description: e = "暂无内容",
592
+ icon: t
593
+ }) => /* @__PURE__ */ j("div", { className: "rw-empty", children: [
594
+ /* @__PURE__ */ s("div", { className: "rw-empty-icon", children: t ?? /* @__PURE__ */ s(Fe, { size: 64 }) }),
595
+ /* @__PURE__ */ s("div", { className: "rw-empty-desc", children: e })
596
+ ] }), Ve = ({ window: e, active: t, children: o }) => /* @__PURE__ */ s(
597
+ "div",
598
+ {
599
+ className: `rw-window-container ${t ? "active" : ""}`,
600
+ style: { display: t ? "flex" : "none", height: "100%", overflow: "auto", flexDirection: "column" },
601
+ "data-window-type": e.type,
602
+ children: o
603
+ }
604
+ ), Ge = ({ items: e, trigger: t, className: o }) => {
605
+ const [r, g] = ee(!1), m = q(null);
606
+ return ne(() => {
607
+ if (!r) return;
608
+ const h = (d) => {
609
+ m.current?.contains(d.target) || g(!1);
610
+ };
611
+ return document.addEventListener("mousedown", h), () => document.removeEventListener("mousedown", h);
612
+ }, [r]), /* @__PURE__ */ j("div", { className: `rw-dropdown ${o || ""}`, ref: m, children: [
613
+ /* @__PURE__ */ s("div", { className: "rw-dropdown-trigger", onClick: () => g((h) => !h), role: "button", tabIndex: 0, children: t }),
614
+ r && /* @__PURE__ */ s("div", { className: "rw-dropdown-menu", children: e.map(
615
+ (h) => h.divider ? /* @__PURE__ */ s("div", { className: "rw-dropdown-divider" }, h.key) : /* @__PURE__ */ s(
616
+ "button",
617
+ {
618
+ type: "button",
619
+ className: "rw-dropdown-item",
620
+ disabled: h.disabled,
621
+ onClick: () => {
622
+ h.onClick?.(), g(!1);
623
+ },
624
+ children: h.label
625
+ },
626
+ h.key
627
+ )
628
+ ) })
629
+ ] });
630
+ }, Qe = ({
631
+ windows: e,
632
+ activeWindowId: t,
633
+ onSwitchWindow: o,
634
+ onCloseWindow: r,
635
+ onToggleMinimize: g,
636
+ onBatchManage: m,
637
+ onFloatWindow: h,
638
+ onRestoreWindow: d,
639
+ onReorderWindows: f,
640
+ embedded: p = !1,
641
+ allWindows: _ = e
642
+ }) => {
643
+ const E = e.findIndex((I) => I.id === t), H = q(null), w = q(null), [Z, x] = ee(null), [U, O] = ee(null), z = q({ windowId: "", startX: 0, startY: 0, fromIndex: -1, mode: "none", floated: !1 }), a = R((I) => {
644
+ const M = w.current;
645
+ if (!M) return e.length;
646
+ const W = M.getBoundingClientRect(), S = I - W.left, v = M.querySelectorAll(".rw-tab-item");
647
+ if (S < 8) return 0;
648
+ for (let C = 0; C < v.length; C++) {
649
+ const b = v[C].getBoundingClientRect(), P = b.left - W.left + b.width / 2;
650
+ if (S < P) return C;
651
+ }
652
+ return v.length;
653
+ }, [e.length]), L = R(
654
+ (I, M, W) => {
655
+ if (I.target.closest(".rw-window-tab-close-btn") || I.button !== 0) return;
656
+ z.current = { windowId: M, startX: I.clientX, startY: I.clientY, fromIndex: W, mode: "none", floated: !1 };
657
+ const S = (b) => {
658
+ const P = b.clientX - z.current.startX, N = b.clientY - z.current.startY, $ = Math.sqrt(P * P + N * N);
659
+ $ < 8 || (z.current.mode === "none" && (Math.abs(N) > 40 && $ > 50 ? z.current.mode = "float" : Math.abs(P) > 12 && Math.abs(P) > Math.abs(N) ? z.current.mode = "reorder" : $ > 50 && (z.current.mode = "float")), z.current.mode === "float" && z.current.windowId === M ? z.current.floated || (z.current.floated = !0, h?.(M, { x: b.clientX, y: b.clientY })) : z.current.mode === "reorder" && x(a(b.clientX)));
660
+ }, v = (b) => {
661
+ if (z.current.mode === "reorder" && z.current.windowId === M) {
662
+ let N = a(b.clientX);
663
+ N > z.current.fromIndex && (N -= 1), N !== z.current.fromIndex && f && f(z.current.fromIndex, N);
664
+ }
665
+ x(null), C();
666
+ }, C = () => {
667
+ document.removeEventListener("mousemove", S), document.removeEventListener("mouseup", v), z.current = { windowId: "", startX: 0, startY: 0, fromIndex: -1, mode: "none", floated: !1 };
668
+ };
669
+ document.addEventListener("mousemove", S), document.addEventListener("mouseup", v);
670
+ },
671
+ [h, f, a]
672
+ );
673
+ ne(() => {
674
+ let I = null;
675
+ const M = (v) => {
676
+ const { windowTitle: C, clientX: b } = v.detail, P = a(b);
677
+ I && cancelAnimationFrame(I), I = requestAnimationFrame(() => {
678
+ O({ title: C, index: P }), x(P);
679
+ });
680
+ }, W = () => {
681
+ O(null), x(null);
682
+ }, S = H.current;
683
+ return S?.addEventListener("floatingWindowDragOver", M), S?.addEventListener("clearFloatingWindowPreview", W), () => {
684
+ S?.removeEventListener("floatingWindowDragOver", M), S?.removeEventListener("clearFloatingWindowPreview", W), I && cancelAnimationFrame(I);
685
+ };
686
+ }, [a]);
687
+ const A = () => {
688
+ const I = e.map((M, W) => /* @__PURE__ */ j(
689
+ "div",
690
+ {
691
+ className: `rw-tab-item ${M.id === t ? "active" : ""}`,
692
+ onClick: () => o(M.id),
693
+ onMouseDown: (S) => L(S, M.id, W),
694
+ children: [
695
+ /* @__PURE__ */ s("span", { className: "rw-tab-title", children: M.title }),
696
+ /* @__PURE__ */ s(
697
+ "button",
698
+ {
699
+ type: "button",
700
+ title: "关闭",
701
+ className: "rw-icon-btn rw-window-tab-close-btn",
702
+ onClick: (S) => {
703
+ S.stopPropagation(), r(M.id);
704
+ },
705
+ children: /* @__PURE__ */ s(ye, { size: 12 })
706
+ }
707
+ )
708
+ ]
709
+ },
710
+ M.id
711
+ ));
712
+ if (U && Z !== null) {
713
+ const M = Math.max(0, Math.min(Z, I.length));
714
+ I.splice(M, 0, /* @__PURE__ */ s("div", { className: "rw-tab-preview", children: U.title }, "rw-preview"));
715
+ }
716
+ return I;
717
+ }, k = (I) => {
718
+ I.preventDefault();
719
+ try {
720
+ const M = sessionStorage.getItem("draggingWindowTitle");
721
+ M && O({ title: M, index: a(I.clientX) });
722
+ } catch {
723
+ }
724
+ x(a(I.clientX));
725
+ }, D = (I) => {
726
+ I.preventDefault();
727
+ let M = I.dataTransfer.getData("windowId") || "";
728
+ if (!M)
729
+ try {
730
+ M = sessionStorage.getItem("draggingWindowId") || "";
731
+ } catch {
732
+ }
733
+ M && d && d(M, Z ?? void 0), O(null), x(null);
734
+ }, y = [
735
+ { key: "close-others", label: "关闭其他", disabled: e.length <= 1, onClick: () => m("close-others") },
736
+ { key: "close-left", label: "关闭左侧", disabled: E <= 0, onClick: () => m("close-left") },
737
+ { key: "close-right", label: "关闭右侧", disabled: E < 0 || E >= e.length - 1, onClick: () => m("close-right") },
738
+ { key: "d1", label: "", divider: !0 },
739
+ { key: "close-all", label: "关闭全部", disabled: !e.length, onClick: () => m("close-all") },
740
+ { key: "d2", label: "", divider: !0 },
741
+ { key: "minimize-all", label: "最小化全部", disabled: !e.length, onClick: () => m("minimize-all") },
742
+ { key: "restore-all", label: "还原全部", disabled: !_.some((I) => I.minimized), onClick: () => m("restore-all") },
743
+ { key: "d3", label: "", divider: !0 },
744
+ { key: "reset", label: "重置窗口", onClick: () => m("reset-windows") }
745
+ ];
746
+ return /* @__PURE__ */ s(
747
+ "div",
748
+ {
749
+ className: `rw-window-tabs ${p ? "rw-tabs-embedded" : ""}`,
750
+ ref: H,
751
+ onDragOver: k,
752
+ onDragLeave: () => {
753
+ O(null), x(null);
754
+ },
755
+ onDrop: D,
756
+ children: /* @__PURE__ */ j("div", { className: "rw-window-tabs-container", children: [
757
+ /* @__PURE__ */ s("div", { className: "rw-tab-list", ref: w, children: A() }),
758
+ Z !== null && !U && /* @__PURE__ */ s(et, { listRef: w, index: Z }),
759
+ e.length > 0 && /* @__PURE__ */ s(
760
+ Ge,
761
+ {
762
+ items: y,
763
+ trigger: /* @__PURE__ */ s("button", { type: "button", className: "rw-icon-btn rw-window-tabs-batch-btn", title: "批量管理", children: /* @__PURE__ */ s(Xe, {}) })
764
+ }
765
+ )
766
+ ] })
767
+ }
768
+ );
769
+ }, et = ({ listRef: e, index: t }) => {
770
+ const [o, r] = ee(0);
771
+ return ne(() => {
772
+ const g = () => {
773
+ const m = e.current;
774
+ if (!m) return;
775
+ m.getBoundingClientRect();
776
+ const h = m.querySelectorAll(".rw-tab-item:not(.rw-tab-preview)");
777
+ if (t === 0) {
778
+ r(8);
779
+ return;
780
+ }
781
+ if (t >= h.length) {
782
+ const f = h[h.length - 1];
783
+ r(f.offsetLeft + f.offsetWidth + 2);
784
+ return;
785
+ }
786
+ const d = h[t];
787
+ r(d.offsetLeft - 1);
788
+ };
789
+ return g(), window.addEventListener("resize", g), () => window.removeEventListener("resize", g);
790
+ }, [e, t]), /* @__PURE__ */ s("div", { className: "rw-window-tab-insert-indicator", style: { left: `${o}px` } });
791
+ }, tt = {
792
+ x: 100,
793
+ y: 100,
794
+ width: 800,
795
+ height: 600,
796
+ minWidth: 400,
797
+ minHeight: 300
798
+ }, nt = ({
799
+ window: e,
800
+ children: t,
801
+ floatingDefaults: o,
802
+ onUpdateFloatingPosition: r,
803
+ onRestoreWindow: g,
804
+ onCloseWindow: m,
805
+ onToggleMinimize: h,
806
+ onFocusWindow: d
807
+ }) => {
808
+ const f = { ...tt, ...o }, p = q(null), _ = q(null), [E, H] = ee(!1), [w, Z] = ee(!1), [x, U] = ee(!1), O = q(!1), z = q(""), a = q({ x: 0, y: 0, startX: 0, startY: 0, startWidth: 0, startHeight: 0 }), L = q({ x: 0, y: 0, width: 0, height: 0, startX: 0, startY: 0 }), A = q(null), k = q(null), D = q(null), y = e.floatingPosition || { x: f.x, y: f.y, width: f.width, height: f.height };
809
+ ne(() => {
810
+ if (!e.pendingDragStart || E || w) return;
811
+ let W = y.x, S = y.y;
812
+ if (p.current) {
813
+ const v = p.current.getBoundingClientRect();
814
+ W = v.left, S = v.top;
815
+ }
816
+ d?.(e.id), D.current = { windowId: e.id, windowTitle: e.title };
817
+ try {
818
+ sessionStorage.setItem("draggingWindowId", e.id), sessionStorage.setItem("draggingWindowTitle", e.title);
819
+ } catch {
820
+ }
821
+ H(!0), a.current = {
822
+ x: e.pendingDragStart.x - W,
823
+ y: e.pendingDragStart.y - S,
824
+ startX: W,
825
+ startY: S,
826
+ startWidth: y.width,
827
+ startHeight: y.height
828
+ };
829
+ }, [e.pendingDragStart, e.id, e.title, E, w, y, d]), ne(() => {
830
+ if (E || w || e.pendingDragStart) return;
831
+ const W = { minWidth: f.minWidth, minHeight: f.minHeight }, S = ie(y, W);
832
+ (S.x !== y.x || S.y !== y.y || S.width !== y.width || S.height !== y.height) && r(e.id, S);
833
+ }, [e.id, e.pendingDragStart]), ne(() => {
834
+ if (!p.current || E || w) return;
835
+ const W = p.current;
836
+ W.style.transform = `translate(${y.x}px, ${y.y}px)`, W.style.width = `${y.width}px`, W.style.height = `${y.height}px`;
837
+ }, [y.x, y.y, y.width, y.height, E, w]);
838
+ const I = R((W) => {
839
+ const S = W.target;
840
+ if (S.closest(".rw-floating-window-action-btn") || S.closest(".rw-floating-window-resize-handle") || !_.current?.contains(S)) return;
841
+ d?.(e.id);
842
+ let v = y.x, C = y.y;
843
+ if (p.current) {
844
+ const b = p.current.getBoundingClientRect();
845
+ v = b.left, C = b.top;
846
+ }
847
+ D.current = { windowId: e.id, windowTitle: e.title };
848
+ try {
849
+ sessionStorage.setItem("draggingWindowId", e.id), sessionStorage.setItem("draggingWindowTitle", e.title);
850
+ } catch {
851
+ }
852
+ H(!0), a.current = { x: W.clientX - v, y: W.clientY - C, startX: v, startY: C, startWidth: y.width, startHeight: y.height };
853
+ }, [y, e.id, e.title, d]), M = R((W, S) => {
854
+ W.stopPropagation(), W.preventDefault(), d?.(e.id);
855
+ let v = y.x, C = y.y, b = y.width, P = y.height;
856
+ if (p.current) {
857
+ const N = p.current.getBoundingClientRect();
858
+ v = N.left, C = N.top, b = N.width, P = N.height;
859
+ }
860
+ Z(!0), z.current = S, L.current = { x: W.clientX, y: W.clientY, width: b, height: P, startX: v, startY: C };
861
+ }, [y, e.id, d]);
862
+ return ne(() => {
863
+ const W = (v) => {
864
+ if (E) {
865
+ v.preventDefault();
866
+ const C = document.querySelector(".rw-window-tabs");
867
+ if (C && D.current) {
868
+ const X = C.getBoundingClientRect(), K = v.clientY >= X.top && v.clientY <= X.bottom && v.clientX >= X.left && v.clientX <= X.right, G = O.current;
869
+ U(K), O.current = K, K ? C.dispatchEvent(new CustomEvent("floatingWindowDragOver", { detail: { ...D.current, clientX: v.clientX, clientY: v.clientY } })) : G && C.dispatchEvent(new CustomEvent("clearFloatingWindowPreview"));
870
+ }
871
+ const b = a.current.startWidth, P = a.current.startHeight, N = Math.max(0, Math.min(v.clientX - a.current.x, globalThis.window.innerWidth - b)), $ = Math.max(0, Math.min(v.clientY - a.current.y, globalThis.window.innerHeight - P));
872
+ p.current.style.transform = `translate(${N}px, ${$}px)`, k.current = { x: N, y: $, width: a.current.startWidth, height: a.current.startHeight };
873
+ } else if (w) {
874
+ v.preventDefault();
875
+ const C = z.current, b = L.current;
876
+ let P = b.startX, N = b.startY, $ = b.width, X = b.height;
877
+ const K = v.clientX - b.x, G = v.clientY - b.y;
878
+ C.includes("e") && ($ = Math.max(f.minWidth, b.width + K)), C.includes("w") && ($ = Math.max(f.minWidth, b.width - K), P = b.startX + b.width - $), C.includes("s") && (X = Math.max(f.minHeight, b.height + G)), C.includes("n") && (X = Math.max(f.minHeight, b.height - G), N = b.startY + b.height - X);
879
+ const Q = p.current;
880
+ Q.style.transform = `translate(${P}px, ${N}px)`, Q.style.width = `${$}px`, Q.style.height = `${X}px`, k.current = { x: P, y: N, width: $, height: X };
881
+ }
882
+ }, S = (v) => {
883
+ if (v && D.current) {
884
+ const b = document.querySelector(".rw-window-tabs");
885
+ if (b) {
886
+ const P = b.getBoundingClientRect();
887
+ if (v.clientY >= P.top && v.clientY <= P.bottom && v.clientX >= P.left && v.clientX <= P.right) {
888
+ const N = b.querySelector(".rw-tab-list");
889
+ if (N) {
890
+ let $ = N.querySelectorAll(".rw-tab-item").length;
891
+ const X = N.getBoundingClientRect(), K = v.clientX - X.left;
892
+ N.querySelectorAll(".rw-tab-item").forEach((G, Q) => {
893
+ const n = G.getBoundingClientRect();
894
+ K < n.left - X.left + n.width / 2 && ($ = Math.min($, Q));
895
+ }), g(D.current.windowId, $), D.current = null, H(!1), Z(!1), U(!1);
896
+ return;
897
+ }
898
+ }
899
+ }
900
+ }
901
+ let C = k.current;
902
+ C && (C = ie(C, { minWidth: f.minWidth, minHeight: f.minHeight })), C && r(e.id, C), k.current = null, D.current = null;
903
+ try {
904
+ sessionStorage.removeItem("draggingWindowId"), sessionStorage.removeItem("draggingWindowTitle");
905
+ } catch {
906
+ }
907
+ H(!1), Z(!1), U(!1), O.current = !1;
908
+ };
909
+ if (E || w) {
910
+ const v = (C) => {
911
+ A.current && cancelAnimationFrame(A.current), A.current = requestAnimationFrame(() => W(C));
912
+ };
913
+ return document.addEventListener("mousemove", v, { passive: !1 }), document.addEventListener("mouseup", S), document.body.style.userSelect = "none", () => {
914
+ document.removeEventListener("mousemove", v), document.removeEventListener("mouseup", S), document.body.style.userSelect = "";
915
+ };
916
+ }
917
+ }, [E, w, e.id, f.minWidth, f.minHeight, r, g]), /* @__PURE__ */ j(
918
+ "div",
919
+ {
920
+ ref: p,
921
+ className: "rw-floating-window",
922
+ style: {
923
+ transform: `translate(${y.x}px, ${y.y}px)`,
924
+ width: y.width,
925
+ height: y.height,
926
+ zIndex: e.floatingZIndex || 1e3,
927
+ opacity: x ? 0.5 : 1,
928
+ minWidth: f.minWidth,
929
+ minHeight: f.minHeight
930
+ },
931
+ onClick: (W) => {
932
+ W.target.closest("button, a, input, select, textarea") || d?.(e.id);
933
+ },
934
+ children: [
935
+ /* @__PURE__ */ j("div", { ref: _, className: "rw-floating-window-header", onMouseDown: I, onDoubleClick: () => g(e.id), children: [
936
+ /* @__PURE__ */ s("div", { className: "rw-floating-window-title", children: e.title }),
937
+ /* @__PURE__ */ j("div", { className: "rw-floating-window-actions", children: [
938
+ /* @__PURE__ */ s("button", { type: "button", title: "放回", className: "rw-icon-btn rw-floating-window-action-btn", onClick: () => g(e.id), children: /* @__PURE__ */ s(He, { size: 12 }) }),
939
+ /* @__PURE__ */ s("button", { type: "button", title: "最小化", className: "rw-icon-btn rw-floating-window-action-btn", onClick: () => h(e.id), children: /* @__PURE__ */ s(Oe, { size: 12 }) }),
940
+ /* @__PURE__ */ s("button", { type: "button", title: "关闭", className: "rw-icon-btn rw-floating-window-action-btn", onClick: () => m(e.id), children: /* @__PURE__ */ s(ye, { size: 12 }) })
941
+ ] })
942
+ ] }),
943
+ /* @__PURE__ */ s("div", { className: "rw-floating-window-content", children: t }),
944
+ ["nw", "ne", "sw", "se", "n", "s", "w", "e"].map((W) => /* @__PURE__ */ s("div", { className: `rw-floating-window-resize-handle rw-floating-window-resize-${W}`, onMouseDown: (S) => M(S, W) }, W))
945
+ ]
946
+ }
947
+ );
948
+ }, it = ({
949
+ windows: e,
950
+ activeWindowId: t,
951
+ renderWindow: o,
952
+ onSwitchWindow: r,
953
+ onCloseWindow: g,
954
+ onToggleMinimize: m,
955
+ onBatchManage: h,
956
+ onFloatWindow: d,
957
+ onRestoreWindow: f,
958
+ onUpdateFloatingPosition: p,
959
+ onFocusWindow: _,
960
+ onReorderWindows: E,
961
+ emptyDescription: H = "从左侧菜单选择功能开始工作",
962
+ floatingDefaults: w,
963
+ tabsContainer: Z
964
+ }) => {
965
+ if (e.length === 0)
966
+ return /* @__PURE__ */ s("div", { className: "rw-window-manager-empty", children: /* @__PURE__ */ s(Je, { description: H }) });
967
+ const x = e.filter((a) => a.minimized), U = e.filter((a) => a.floating && !a.minimized), O = e.filter((a) => !a.minimized && !a.floating), z = /* @__PURE__ */ s(
968
+ Qe,
969
+ {
970
+ windows: O,
971
+ activeWindowId: t,
972
+ onSwitchWindow: r,
973
+ onCloseWindow: g,
974
+ onToggleMinimize: m,
975
+ onBatchManage: h,
976
+ onFloatWindow: d,
977
+ onRestoreWindow: f,
978
+ onReorderWindows: E,
979
+ allWindows: e,
980
+ embedded: !!Z
981
+ }
982
+ );
983
+ return /* @__PURE__ */ j("div", { className: "rw-window-manager", children: [
984
+ Z ? De(z, Z) : z,
985
+ /* @__PURE__ */ s("div", { className: "rw-window-content-area", children: O.map((a) => /* @__PURE__ */ s(Ve, { window: a, active: a.id === t, children: o(a, {}) }, a.id)) }),
986
+ x.length > 0 && /* @__PURE__ */ s("div", { className: "rw-minimized-windows-bar", children: x.map((a) => /* @__PURE__ */ j(
987
+ "div",
988
+ {
989
+ className: "rw-minimized-window-item",
990
+ onClick: () => m(a.id),
991
+ title: a.floating ? `${a.title} (浮动窗口)` : a.title,
992
+ role: "button",
993
+ tabIndex: 0,
994
+ onKeyDown: (L) => L.key === "Enter" && m(a.id),
995
+ children: [
996
+ /* @__PURE__ */ s("span", { children: a.title }),
997
+ a.floating && /* @__PURE__ */ s("span", { className: "rw-minimized-floating-badge", children: "🔲" })
998
+ ]
999
+ },
1000
+ a.id
1001
+ )) }),
1002
+ U.map((a) => /* @__PURE__ */ s(
1003
+ nt,
1004
+ {
1005
+ window: a,
1006
+ floatingDefaults: w,
1007
+ onUpdateFloatingPosition: p || (() => {
1008
+ }),
1009
+ onRestoreWindow: f || (() => {
1010
+ }),
1011
+ onCloseWindow: g,
1012
+ onToggleMinimize: m,
1013
+ onFocusWindow: _,
1014
+ children: o(a, {})
1015
+ },
1016
+ a.id
1017
+ ))
1018
+ ] });
1019
+ };
1020
+ function rt(e) {
1021
+ return "type" in e && e.type === "divider";
1022
+ }
1023
+ function xe(e) {
1024
+ for (const t of e) {
1025
+ if (rt(t)) continue;
1026
+ const o = t;
1027
+ if (o.windowType) return o;
1028
+ if (o.children) {
1029
+ const r = xe(o.children);
1030
+ if (r) return r;
1031
+ }
1032
+ }
1033
+ return null;
1034
+ }
1035
+ function ot(e, t) {
1036
+ if (t) return { minimized: !1, ...t };
1037
+ const o = xe(e);
1038
+ if (!o?.windowType)
1039
+ return { type: "home", title: "首页", minimized: !1 };
1040
+ const r = be(o.label) || o.key;
1041
+ return { type: o.windowType, title: r, minimized: !1 };
1042
+ }
1043
+ function st(e, t) {
1044
+ const { fallback: o } = t ?? {};
1045
+ return (r, g) => {
1046
+ const m = e[r.type] ?? o;
1047
+ return m ? Me(m, { window: r, ctx: g }) : null;
1048
+ };
1049
+ }
1050
+ const lt = {
1051
+ colorPrimary: "--rw-color-primary",
1052
+ colorPrimaryHover: "--rw-color-primary-hover",
1053
+ colorPrimaryBg: "--rw-color-primary-bg",
1054
+ colorBg: "--rw-color-bg",
1055
+ colorBgSecondary: "--rw-color-bg-secondary",
1056
+ colorBgTertiary: "--rw-color-bg-tertiary",
1057
+ colorBgHover: "--rw-color-bg-hover",
1058
+ colorBgActive: "--rw-color-bg-active",
1059
+ colorBorder: "--rw-color-border",
1060
+ colorBorderStrong: "--rw-color-border-strong",
1061
+ colorText: "--rw-color-text",
1062
+ colorTextSecondary: "--rw-color-text-secondary",
1063
+ colorTextMuted: "--rw-color-text-muted",
1064
+ sidebarWidth: "--rw-sidebar-width",
1065
+ tabHeight: "--rw-tab-height",
1066
+ radius: "--rw-radius",
1067
+ fontSize: "--rw-font-size"
1068
+ };
1069
+ function We(e) {
1070
+ const t = {};
1071
+ return Object.keys(e).forEach((o) => {
1072
+ const r = e[o];
1073
+ if (r !== void 0) {
1074
+ const g = lt[o];
1075
+ t[g] = typeof r == "number" ? `${r}px` : r;
1076
+ }
1077
+ }), t;
1078
+ }
1079
+ function at(e) {
1080
+ return {
1081
+ colorPrimary: e.colorPrimary,
1082
+ colorPrimaryHover: e.colorPrimaryHover,
1083
+ colorPrimaryBg: e.colorPrimaryBg,
1084
+ colorBg: e.colorBgContainer,
1085
+ colorBgSecondary: e.colorFillAlter ?? e.colorBgContainer,
1086
+ colorBgTertiary: e.colorBgLayout,
1087
+ colorBgHover: e.colorBgTextHover,
1088
+ colorBgActive: e.colorPrimaryBg,
1089
+ colorBorder: e.colorBorder,
1090
+ colorBorderStrong: e.colorBorderSecondary ?? e.colorBorder,
1091
+ colorText: e.colorText,
1092
+ colorTextSecondary: e.colorTextSecondary,
1093
+ colorTextMuted: e.colorTextTertiary,
1094
+ radius: e.borderRadius,
1095
+ fontSize: e.fontSize
1096
+ };
1097
+ }
1098
+ function ht(e) {
1099
+ return We(at(e));
1100
+ }
1101
+ const pt = Pe(function({
1102
+ workspaceId: t = "default",
1103
+ menuItems: o,
1104
+ renderWindow: r,
1105
+ windows: g,
1106
+ sidebarHeader: m,
1107
+ sidebarFooter: h,
1108
+ defaultWindow: d,
1109
+ loading: f = !1,
1110
+ loadingTip: p = "加载中...",
1111
+ onAction: _,
1112
+ activeWindowType: E,
1113
+ emptyDescription: H,
1114
+ syncToUrl: w = !1,
1115
+ preserveUrlParams: Z = !0,
1116
+ searchParams: x,
1117
+ setSearchParams: U,
1118
+ floatingDefaults: O,
1119
+ onWindowsChange: z,
1120
+ onReady: a,
1121
+ siderWidth: L = 240,
1122
+ contentBackground: A,
1123
+ themeClassName: k,
1124
+ theme: D,
1125
+ renderSidebar: y,
1126
+ tabsContainer: I,
1127
+ className: M,
1128
+ style: W
1129
+ }, S) {
1130
+ const v = oe(
1131
+ () => ot(o, d),
1132
+ [o, d]
1133
+ ), C = oe(() => {
1134
+ if (r) return r;
1135
+ if (g) return st(g);
1136
+ throw new Error("[react-workspace] 请提供 renderWindow 或 windows");
1137
+ }, [r, g]), b = $e({
1138
+ workspaceId: t,
1139
+ defaultWindow: v,
1140
+ syncToUrl: w,
1141
+ preserveUrlParams: Z,
1142
+ searchParams: x,
1143
+ setSearchParams: U,
1144
+ floatingDefaults: O,
1145
+ onWindowsChange: z
1146
+ }), {
1147
+ windows: P,
1148
+ activeWindowId: N,
1149
+ openWindow: $,
1150
+ switchWindow: X,
1151
+ closeWindow: K,
1152
+ toggleMinimize: G,
1153
+ floatWindow: Q,
1154
+ restoreWindow: n,
1155
+ updateFloatingPosition: i,
1156
+ focusWindow: l,
1157
+ batchManage: c,
1158
+ updateWindowProps: u,
1159
+ clearPendingAction: T,
1160
+ reorderWindows: F
1161
+ } = b, Y = { workspaceId: t, ...b };
1162
+ Te(S, () => Y, [t, P, N]), ne(() => {
1163
+ a && P.length > 0 && a({ workspaceId: t, ...b });
1164
+ }, [a, t, P.length]);
1165
+ const J = oe(() => E !== void 0 ? E : P.find((te) => te.id === N)?.type, [E, P, N]), B = R(
1166
+ (te, ce) => {
1167
+ $({ type: te, title: Ue(o, te), minimized: !1 }, ce);
1168
+ },
1169
+ [$, o]
1170
+ ), V = R(
1171
+ (te, ce) => ({
1172
+ workspaceId: t,
1173
+ active: ce,
1174
+ activeWindowId: N,
1175
+ windows: P,
1176
+ openWindow: $,
1177
+ switchWindow: X,
1178
+ closeWindow: K,
1179
+ toggleMinimize: G,
1180
+ floatWindow: Q,
1181
+ updateWindowProps: (Ie, Ce) => u(Ie, Ce),
1182
+ clearPendingAction: T
1183
+ }),
1184
+ [t, N, P, $, X, K, G, Q, u, T]
1185
+ ), Se = oe(
1186
+ () => ({ ...Y, buildRenderContext: V }),
1187
+ [t, P, N, V]
1188
+ ), ke = A ?? "var(--rw-color-bg-tertiary)", ze = { minHeight: "100vh", height: "100vh", display: "flex", ...D ? We(D) : void 0, ...W }, ue = {
1189
+ menuItems: o,
1190
+ onMenuClick: B,
1191
+ onAction: _,
1192
+ activeWindowType: J,
1193
+ header: m,
1194
+ footer: h,
1195
+ defaultOpenKeys: qe(o),
1196
+ siderWidth: L
1197
+ };
1198
+ return /* @__PURE__ */ s(Be, { value: Se, children: /* @__PURE__ */ j(
1199
+ "div",
1200
+ {
1201
+ className: `rw-workspace ${k || ""} ${M || ""}`.trim(),
1202
+ style: ze,
1203
+ children: [
1204
+ y ? y(ue) : /* @__PURE__ */ s(Ke, { ...ue }),
1205
+ /* @__PURE__ */ s("main", { className: "rw-workspace-main", style: { background: ke }, children: /* @__PURE__ */ s(Ee, { spinning: f, tip: p, children: /* @__PURE__ */ s(
1206
+ it,
1207
+ {
1208
+ workspaceId: t,
1209
+ windows: P,
1210
+ activeWindowId: N,
1211
+ renderWindow: (te) => C(te, V(te, te.id === N && !te.floating)),
1212
+ onSwitchWindow: X,
1213
+ onCloseWindow: K,
1214
+ onToggleMinimize: G,
1215
+ onBatchManage: c,
1216
+ onOpenWindow: $,
1217
+ onFloatWindow: Q,
1218
+ onRestoreWindow: n,
1219
+ onUpdateFloatingPosition: i,
1220
+ onFocusWindow: l,
1221
+ onReorderWindows: F,
1222
+ emptyDescription: H,
1223
+ tabsContainer: I,
1224
+ floatingDefaults: O
1225
+ }
1226
+ ) }) })
1227
+ ]
1228
+ }
1229
+ ) });
1230
+ });
1231
+ export {
1232
+ nt as F,
1233
+ Ve as W,
1234
+ it as a,
1235
+ Qe as b,
1236
+ pt as c,
1237
+ Be as d,
1238
+ Ke as e,
1239
+ qe as f,
1240
+ st as g,
1241
+ xe as h,
1242
+ _e as i,
1243
+ ve as j,
1244
+ ie as k,
1245
+ se as l,
1246
+ be as m,
1247
+ ht as n,
1248
+ at as o,
1249
+ me as p,
1250
+ Ue as q,
1251
+ ot as r,
1252
+ le as s,
1253
+ We as t,
1254
+ de as u,
1255
+ $e as v,
1256
+ gt as w,
1257
+ mt as x
1258
+ };