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