@liuman/react-workspace 1.3.0 → 1.3.2

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