@liuman/react-workspace 1.4.4 → 1.5.0

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