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