@liuman/react-workspace 1.3.5 → 1.4.0

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