dsh-sidebar-sessions 0.1.3 → 0.1.5
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.
- package/README.md +10 -4
- package/lib/client.js +996 -817
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -1,817 +1,996 @@
|
|
|
1
|
-
/* dsh-sidebar-sessions client bundle — plain ESM, no build step.
|
|
2
|
-
*
|
|
3
|
-
* sidebar.workspaces implementation:
|
|
4
|
-
* - recent-first session list, user groups, archive bucket
|
|
5
|
-
* - workspace node styled like a group, marked as a workspace: expanding it
|
|
6
|
-
* lists the workspaces (not sessions), each with its own fold state
|
|
7
|
-
* - drag-to-reorder: a drop moves the dragged row before the row it lands
|
|
8
|
-
* on. The workspace tree writes host order (insertSessionBefore); the
|
|
9
|
-
* recency sections (最近/置顶/分组/未分组/已归档) keep a local manual order,
|
|
10
|
-
* because re-sorting them by updatedAt would erase every drop
|
|
11
|
-
* - hidden entirely when the sidebar collapses to a narrow rail (CSS container
|
|
12
|
-
* query — no JS measurement, so no flicker)
|
|
13
|
-
*/
|
|
14
|
-
window.__ModuleLoader__.load({
|
|
15
|
-
id: "dsh-sidebar-sessions",
|
|
16
|
-
factory: (require) => {
|
|
17
|
-
const React = require("react");
|
|
18
|
-
const h = React.createElement;
|
|
19
|
-
const { memo, useCallback, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } = React;
|
|
20
|
-
const inject = ["slots", "sessions", "workspaces", "uiWorkspace", "uiSession", "remote", "remote.schedule"];
|
|
21
|
-
|
|
22
|
-
const STORE_KEY = "dsh-session-groups.v1";
|
|
23
|
-
const RECENT_LIMIT = 20;
|
|
24
|
-
|
|
25
|
-
const CSS = `
|
|
26
|
-
.dsg-root{container-type:inline-size;display:flex;flex-direction:column;gap:1px;padding:4px 6px 8px}
|
|
27
|
-
@container (max-width:150px){.dsg-root > *{display:none}}
|
|
28
|
-
.dsg-head{position:sticky;top:0;z-index:2;display:flex;align-items:center;height:32px;padding:0 8px;box-sizing:border-box;color:var(--dsw-alias-label-secondary,#6b7280);font-size:12px;font-weight:600;cursor:pointer;user-select:none;background:var(--dsw-alias-bg-base,transparent)}
|
|
29
|
-
.dsg-head:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
30
|
-
.dsg-caret{width:14px;flex:none;color:var(--dsw-alias-label-tertiary,#9ca3af);font-size:10px}
|
|
31
|
-
.dsg-head-label{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
32
|
-
.dsg-count{font-size:10px;color:var(--dsw-alias-label-tertiary,#9ca3af);flex:none;margin-left:6px}
|
|
33
|
-
.dsg-row{position:relative;display:flex;align-items:center;box-sizing:border-box;width:100%;height:32px;padding:0 4px 0 10px;border-radius:var(--dsw-radius-md,12px);color:var(--dsw-alias-label-primary,#111827);cursor:pointer;user-select:none}
|
|
34
|
-
.dsg-row:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
35
|
-
.dsg-row:focus-visible{outline:2px solid var(--dsw-alias-focus-ring,#4d6bfe);outline-offset:-2px}
|
|
36
|
-
.dsg-row[data-over="before"]{box-shadow:inset 0 2px 0 0 var(--dsw-alias-state-business-primary,#4d6bfe)}
|
|
37
|
-
.dsg-row[data-over="after"]{box-shadow:inset 0 -2px 0 0 var(--dsw-alias-state-business-primary,#4d6bfe)}
|
|
38
|
-
.dsg-row[data-dragging="true"]{opacity:.45}
|
|
39
|
-
.dsg-dot{flex:none;width:8px;height:8px;border-radius:50%;margin-right:8px;background:var(--dsw-alias-label-tertiary,#9ca3af);box-sizing:border-box}
|
|
40
|
-
.dsg-dot[data-state="running"]{background:transparent;border:1.5px solid var(--dsw-alias-state-business-primary,#4d6bfe);border-top-color:transparent;animation:dsg-spin .8s linear infinite}
|
|
41
|
-
.dsg-dot[data-state="pending"]{background:var(--dsw-alias-state-warning-primary,#f7ad31)}
|
|
42
|
-
.dsg-dot[data-state="unread"]{background:var(--dsw-alias-state-success-primary,#22c55e)}
|
|
43
|
-
@keyframes dsg-spin{to{transform:rotate(360deg)}}
|
|
44
|
-
.dsg-title{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:14px;line-height:20px;margin:0 4px 0 0;text-align:left}
|
|
45
|
-
.dsg-time{flex:0 0 4.5em;width:4.5em;margin-left:6px;text-align:right;white-space:nowrap;font-size:10px;line-height:16px;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-tertiary,#9ca3af)}
|
|
46
|
-
.dsg-actions{display:flex;flex:none;gap:2px;opacity:0;margin-left:4px}
|
|
47
|
-
.dsg-row:hover .dsg-actions,.dsg-row:focus-within .dsg-actions{opacity:1}
|
|
48
|
-
.dsg-icon{display:inline-flex;align-items:center;justify-content:center;box-sizing:border-box;width:22px;height:22px;border:none;background:transparent;color:var(--dsw-alias-label-secondary,#6b7280);cursor:pointer;font-size:13px;line-height:1;padding:0;border-radius:var(--dsw-radius-s,8px)}
|
|
49
|
-
.dsg-icon:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary,#111827)}
|
|
50
|
-
.dsg-pin{flex:none;color:var(--dsw-alias-state-business-primary,#4d6bfe);font-size:11px;margin-right:4px}
|
|
51
|
-
.dsg-dot-clock{flex:none;display:inline-flex;align-items:center;justify-content:center;width:12px;height:12px;margin-right:6px;color:var(--dsw-alias-label-tertiary,#9ca3af)}
|
|
52
|
-
.dsg-menu{position:fixed;z-index:9999;min-width:190px;padding:4px;background:var(--dsw-alias-bg-layer-2,#24272c);border:1px solid var(--dsw-alias-border-l4,rgba(127,127,127,.3));border-radius:var(--dsw-radius-md,12px);box-shadow:0 8px 24px rgba(0,0,0,.28)}
|
|
53
|
-
.dsg-menu-item{display:flex;align-items:center;gap:8px;height:30px;padding:0 10px;font-size:13px;color:var(--dsw-alias-label-primary,#111827);cursor:pointer;border-radius:var(--dsw-radius-s,8px);white-space:nowrap}
|
|
54
|
-
.dsg-menu-item:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
55
|
-
.dsg-menu-sep{height:1px;margin:4px 6px;background:var(--dsw-alias-border-l2,rgba(127,127,127,.2))}
|
|
56
|
-
.dsg-menu-label{display:flex;align-items:center;height:24px;padding:0 10px;font-size:11px;color:var(--dsw-alias-label-tertiary,#9ca3af);cursor:default}
|
|
57
|
-
.dsg-dot-sm{color:var(--dsw-alias-state-business-primary,#4d6bfe);font-size:10px}
|
|
58
|
-
.dsg-search{display:flex;align-items:center;gap:6px;margin:0 2px 8px;padding:0 10px;height:34px;box-sizing:border-box;border-radius:var(--dsw-radius-sm,8px);background:var(--dsw-alias-bg-layer-1,#1a1d21);border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.15))}
|
|
59
|
-
.dsg-search input{flex:1;min-width:0;height:32px;line-height:32px;background:transparent;border:none;outline:none;color:var(--dsw-alias-label-primary,#e5e7eb);font-size:13px}
|
|
60
|
-
.dsg-search input::placeholder{color:var(--dsw-alias-label-tertiary,#9ca3af)}
|
|
61
|
-
.dsg-empty{padding:6px 10px;font-size:12px;color:var(--dsw-alias-label-tertiary,#9ca3af);line-height:18px}
|
|
62
|
-
.dsg-
|
|
63
|
-
.dsg-
|
|
64
|
-
.dsg-
|
|
65
|
-
.dsg-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return () =>
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
function
|
|
206
|
-
if (
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
if (
|
|
218
|
-
if (
|
|
219
|
-
if (
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
return
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
"
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
const
|
|
355
|
-
const
|
|
356
|
-
const
|
|
357
|
-
const
|
|
358
|
-
const
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
const
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
);
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
);
|
|
376
|
-
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
const
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
const
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
const
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
const
|
|
434
|
-
const
|
|
435
|
-
|
|
436
|
-
const
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
const
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
const
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
)
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
const
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
{
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
const
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
}),
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
1
|
+
/* dsh-sidebar-sessions client bundle — plain ESM, no build step.
|
|
2
|
+
*
|
|
3
|
+
* sidebar.workspaces implementation:
|
|
4
|
+
* - recent-first session list, user groups, archive bucket
|
|
5
|
+
* - workspace node styled like a group, marked as a workspace: expanding it
|
|
6
|
+
* lists the workspaces (not sessions), each with its own fold state
|
|
7
|
+
* - drag-to-reorder: a drop moves the dragged row before the row it lands
|
|
8
|
+
* on. The workspace tree writes host order (insertSessionBefore); the
|
|
9
|
+
* recency sections (最近/置顶/分组/未分组/已归档) keep a local manual order,
|
|
10
|
+
* because re-sorting them by updatedAt would erase every drop
|
|
11
|
+
* - hidden entirely when the sidebar collapses to a narrow rail (CSS container
|
|
12
|
+
* query — no JS measurement, so no flicker)
|
|
13
|
+
*/
|
|
14
|
+
window.__ModuleLoader__.load({
|
|
15
|
+
id: "dsh-sidebar-sessions",
|
|
16
|
+
factory: (require) => {
|
|
17
|
+
const React = require("react");
|
|
18
|
+
const h = React.createElement;
|
|
19
|
+
const { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } = React;
|
|
20
|
+
const inject = ["slots", "sessions", "workspaces", "uiWorkspace", "uiSession", "remote", "remote.schedule"];
|
|
21
|
+
|
|
22
|
+
const STORE_KEY = "dsh-session-groups.v1";
|
|
23
|
+
const RECENT_LIMIT = 20;
|
|
24
|
+
|
|
25
|
+
const CSS = `
|
|
26
|
+
.dsg-root{container-type:inline-size;display:flex;flex-direction:column;gap:1px;padding:4px 6px 8px;flex:1 1 auto;min-height:0;overflow-y:auto;overflow-x:hidden;overscroll-behavior:contain}
|
|
27
|
+
@container (max-width:150px){.dsg-root > *{display:none}}
|
|
28
|
+
.dsg-head{position:sticky;top:0;z-index:2;display:flex;align-items:center;height:32px;padding:0 8px;box-sizing:border-box;color:var(--dsw-alias-label-secondary,#6b7280);font-size:12px;font-weight:600;cursor:pointer;user-select:none;background:var(--dsw-alias-bg-base,transparent)}
|
|
29
|
+
.dsg-head:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
30
|
+
.dsg-caret{width:14px;flex:none;color:var(--dsw-alias-label-tertiary,#9ca3af);font-size:10px}
|
|
31
|
+
.dsg-head-label{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
32
|
+
.dsg-count{font-size:10px;color:var(--dsw-alias-label-tertiary,#9ca3af);flex:none;margin-left:6px}
|
|
33
|
+
.dsg-row{position:relative;display:flex;align-items:center;box-sizing:border-box;width:100%;height:32px;padding:0 4px 0 10px;border-radius:var(--dsw-radius-md,12px);color:var(--dsw-alias-label-primary,#111827);cursor:pointer;user-select:none}
|
|
34
|
+
.dsg-row:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
35
|
+
.dsg-row:focus-visible{outline:2px solid var(--dsw-alias-focus-ring,#4d6bfe);outline-offset:-2px}
|
|
36
|
+
.dsg-row[data-over="before"]{box-shadow:inset 0 2px 0 0 var(--dsw-alias-state-business-primary,#4d6bfe)}
|
|
37
|
+
.dsg-row[data-over="after"]{box-shadow:inset 0 -2px 0 0 var(--dsw-alias-state-business-primary,#4d6bfe)}
|
|
38
|
+
.dsg-row[data-dragging="true"]{opacity:.45}
|
|
39
|
+
.dsg-dot{flex:none;width:8px;height:8px;border-radius:50%;margin-right:8px;background:var(--dsw-alias-label-tertiary,#9ca3af);box-sizing:border-box}
|
|
40
|
+
.dsg-dot[data-state="running"]{background:transparent;border:1.5px solid var(--dsw-alias-state-business-primary,#4d6bfe);border-top-color:transparent;animation:dsg-spin .8s linear infinite}
|
|
41
|
+
.dsg-dot[data-state="pending"]{background:var(--dsw-alias-state-warning-primary,#f7ad31)}
|
|
42
|
+
.dsg-dot[data-state="unread"]{background:var(--dsw-alias-state-success-primary,#22c55e)}
|
|
43
|
+
@keyframes dsg-spin{to{transform:rotate(360deg)}}
|
|
44
|
+
.dsg-title{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:14px;line-height:20px;margin:0 4px 0 0;text-align:left}
|
|
45
|
+
.dsg-time{flex:0 0 4.5em;width:4.5em;margin-left:6px;text-align:right;white-space:nowrap;font-size:10px;line-height:16px;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-tertiary,#9ca3af)}
|
|
46
|
+
.dsg-actions{display:flex;flex:none;gap:2px;opacity:0;margin-left:4px}
|
|
47
|
+
.dsg-row:hover .dsg-actions,.dsg-row:focus-within .dsg-actions{opacity:1}
|
|
48
|
+
.dsg-icon{display:inline-flex;align-items:center;justify-content:center;box-sizing:border-box;width:22px;height:22px;border:none;background:transparent;color:var(--dsw-alias-label-secondary,#6b7280);cursor:pointer;font-size:13px;line-height:1;padding:0;border-radius:var(--dsw-radius-s,8px)}
|
|
49
|
+
.dsg-icon:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary,#111827)}
|
|
50
|
+
.dsg-pin{flex:none;color:var(--dsw-alias-state-business-primary,#4d6bfe);font-size:11px;margin-right:4px}
|
|
51
|
+
.dsg-dot-clock{flex:none;display:inline-flex;align-items:center;justify-content:center;width:12px;height:12px;margin-right:6px;color:var(--dsw-alias-label-tertiary,#9ca3af)}
|
|
52
|
+
.dsg-menu{position:fixed;z-index:9999;min-width:190px;padding:4px;background:var(--dsw-alias-bg-layer-2,#24272c);border:1px solid var(--dsw-alias-border-l4,rgba(127,127,127,.3));border-radius:var(--dsw-radius-md,12px);box-shadow:0 8px 24px rgba(0,0,0,.28)}
|
|
53
|
+
.dsg-menu-item{display:flex;align-items:center;gap:8px;height:30px;padding:0 10px;font-size:13px;color:var(--dsw-alias-label-primary,#111827);cursor:pointer;border-radius:var(--dsw-radius-s,8px);white-space:nowrap}
|
|
54
|
+
.dsg-menu-item:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
55
|
+
.dsg-menu-sep{height:1px;margin:4px 6px;background:var(--dsw-alias-border-l2,rgba(127,127,127,.2))}
|
|
56
|
+
.dsg-menu-label{display:flex;align-items:center;height:24px;padding:0 10px;font-size:11px;color:var(--dsw-alias-label-tertiary,#9ca3af);cursor:default}
|
|
57
|
+
.dsg-dot-sm{color:var(--dsw-alias-state-business-primary,#4d6bfe);font-size:10px}
|
|
58
|
+
.dsg-search{display:flex;align-items:center;gap:6px;margin:0 2px 8px;padding:0 10px;height:34px;box-sizing:border-box;border-radius:var(--dsw-radius-sm,8px);background:var(--dsw-alias-bg-layer-1,#1a1d21);border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.15))}
|
|
59
|
+
.dsg-search input{flex:1;min-width:0;height:32px;line-height:32px;background:transparent;border:none;outline:none;color:var(--dsw-alias-label-primary,#e5e7eb);font-size:13px}
|
|
60
|
+
.dsg-search input::placeholder{color:var(--dsw-alias-label-tertiary,#9ca3af)}
|
|
61
|
+
.dsg-empty{padding:6px 10px;font-size:12px;color:var(--dsw-alias-label-tertiary,#9ca3af);line-height:18px}
|
|
62
|
+
.dsg-more{display:flex;align-items:center;justify-content:center;height:30px;margin:2px 2px 4px;border-radius:var(--dsw-radius-s,8px);color:var(--dsw-alias-label-tertiary,#9ca3af);font-size:12px;line-height:1;cursor:pointer;user-select:none}
|
|
63
|
+
.dsg-more:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-secondary,#6b7280)}
|
|
64
|
+
.dsg-more:focus-visible{outline:2px solid var(--dsw-alias-focus-ring,#4d6bfe);outline-offset:-2px}
|
|
65
|
+
.dsg-more-end{cursor:default;font-size:11px}
|
|
66
|
+
.dsg-more-end:hover{background:transparent;color:var(--dsw-alias-label-tertiary,#9ca3af)}
|
|
67
|
+
.dsg-ws{display:flex;align-items:center;gap:4px;padding:2px 8px 8px}
|
|
68
|
+
.dsg-ws-btn{flex:1;display:flex;align-items:center;justify-content:center;height:34px;box-sizing:border-box;border:1px dashed var(--dsw-alias-border-l2,rgba(127,127,127,.25));background:transparent;color:var(--dsw-alias-label-secondary,#6b7280);font-size:13px;line-height:1;border-radius:var(--dsw-radius-sm,8px);cursor:pointer}
|
|
69
|
+
.dsg-ws-btn:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
|
|
70
|
+
.dsg-ws-row{display:flex;align-items:center;height:28px;padding:0 8px;font-size:12px;color:var(--dsw-alias-label-tertiary,#9ca3af)}
|
|
71
|
+
`;
|
|
72
|
+
|
|
73
|
+
function injectStyles() {
|
|
74
|
+
const id = "dsh-sidebar-sessions-style";
|
|
75
|
+
if (document.getElementById(id)) return () => {};
|
|
76
|
+
const style = document.createElement("style");
|
|
77
|
+
style.id = id;
|
|
78
|
+
style.textContent = CSS;
|
|
79
|
+
document.head.appendChild(style);
|
|
80
|
+
return () => style.remove();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const EMPTY = { groups: [], assign: {}, collapsed: {}, hiddenWorkspaces: [], activeWorkspace: null, order: {} };
|
|
84
|
+
|
|
85
|
+
function readStore() {
|
|
86
|
+
try {
|
|
87
|
+
const raw = window.localStorage.getItem(STORE_KEY);
|
|
88
|
+
if (!raw) return { ...EMPTY };
|
|
89
|
+
const parsed = JSON.parse(raw);
|
|
90
|
+
return {
|
|
91
|
+
groups: Array.isArray(parsed.groups) ? parsed.groups : [],
|
|
92
|
+
assign: parsed.assign && typeof parsed.assign === "object" ? parsed.assign : {},
|
|
93
|
+
collapsed: parsed.collapsed && typeof parsed.collapsed === "object" ? parsed.collapsed : {},
|
|
94
|
+
hiddenWorkspaces: Array.isArray(parsed.hiddenWorkspaces) ? parsed.hiddenWorkspaces : [],
|
|
95
|
+
activeWorkspace: typeof parsed.activeWorkspace === "string" ? parsed.activeWorkspace : null,
|
|
96
|
+
order: parsed.order && typeof parsed.order === "object" ? parsed.order : {},
|
|
97
|
+
};
|
|
98
|
+
} catch {
|
|
99
|
+
return { ...EMPTY };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function writeStore(next) {
|
|
104
|
+
try {
|
|
105
|
+
window.localStorage.setItem(STORE_KEY, JSON.stringify(next));
|
|
106
|
+
} catch {}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const store = (() => {
|
|
110
|
+
let state = readStore();
|
|
111
|
+
const listeners = new Set();
|
|
112
|
+
const emit = () => {
|
|
113
|
+
for (const fn of listeners) fn();
|
|
114
|
+
};
|
|
115
|
+
return {
|
|
116
|
+
get: () => state,
|
|
117
|
+
set(next) {
|
|
118
|
+
state = next;
|
|
119
|
+
writeStore(state);
|
|
120
|
+
emit();
|
|
121
|
+
},
|
|
122
|
+
subscribe(fn) {
|
|
123
|
+
listeners.add(fn);
|
|
124
|
+
return () => listeners.delete(fn);
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
})();
|
|
128
|
+
|
|
129
|
+
function useGroups() {
|
|
130
|
+
return useSyncExternalStore(store.subscribe, store.get, store.get);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function newGroupId() {
|
|
134
|
+
return "g_" + Math.random().toString(36).slice(2, 9);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function titleOf(row, id) {
|
|
138
|
+
return String(row?.displayTitle || row?.title || id);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function updatedAt(row) {
|
|
142
|
+
const n = Number(row?.updatedAt);
|
|
143
|
+
return Number.isFinite(n) ? n : 0;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function sortRecent(ids, byId) {
|
|
147
|
+
return [...ids].sort((a, b) => {
|
|
148
|
+
const d = updatedAt(byId[b]) - updatedAt(byId[a]);
|
|
149
|
+
if (d !== 0) return d;
|
|
150
|
+
return String(a).localeCompare(String(b));
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Layer a section's saved manual order over its base order. Ids the saved
|
|
156
|
+
* order never saw (a new session, or one that just entered the section)
|
|
157
|
+
* come first, newest first, so fresh activity stays on top; the ids it did
|
|
158
|
+
* see keep the order the user dragged them into. Only display order: the
|
|
159
|
+
* caller still decides what belongs in the section.
|
|
160
|
+
*/
|
|
161
|
+
function applyManualOrder(ids, saved) {
|
|
162
|
+
if (!Array.isArray(saved) || saved.length === 0) return ids;
|
|
163
|
+
const present = new Set(ids);
|
|
164
|
+
const kept = saved.filter((id) => present.has(id));
|
|
165
|
+
if (kept.length === 0) return ids;
|
|
166
|
+
const keptSet = new Set(kept);
|
|
167
|
+
const fresh = ids.filter((id) => !keptSet.has(id));
|
|
168
|
+
return fresh.concat(kept);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Move `src` to the dropped row: `half` is the pointer's half of that row,
|
|
173
|
+
* so dropping on the lower half lands the row after the target and the
|
|
174
|
+
* upper half lands it before. A move that changes nothing returns undefined.
|
|
175
|
+
*/
|
|
176
|
+
function moveTo(ids, src, targetId, half) {
|
|
177
|
+
if (src === targetId) return undefined;
|
|
178
|
+
if (!ids.includes(src) || !ids.includes(targetId)) return undefined;
|
|
179
|
+
const without = ids.filter((id) => id !== src);
|
|
180
|
+
const at = without.indexOf(targetId);
|
|
181
|
+
const insertAt = half === "after" ? at + 1 : at;
|
|
182
|
+
const next = without.slice(0, insertAt).concat([src], without.slice(insertAt));
|
|
183
|
+
return next.every((id, index) => id === ids[index]) ? undefined : next;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Anchor for host `insertSessionBefore`: the id that must follow `src`. */
|
|
187
|
+
function anchorAfter(ids, src, targetId) {
|
|
188
|
+
const without = ids.filter((id) => id !== src);
|
|
189
|
+
return without[without.indexOf(targetId) + 1];
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Which half of the row the pointer is in: "before" (top) or "after". */
|
|
193
|
+
function rowHalf(event) {
|
|
194
|
+
const el = event.currentTarget;
|
|
195
|
+
const rect = el && el.getBoundingClientRect ? el.getBoundingClientRect() : null;
|
|
196
|
+
if (!rect) return "before";
|
|
197
|
+
return event.clientY - rect.top > rect.height / 2 ? "after" : "before";
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Viewport-relative bottom of the list's scrolling ancestor (or the window
|
|
202
|
+
* when the page itself scrolls): paging measures against the box the user
|
|
203
|
+
* actually sees, so a short sidebar loads one screen at a time.
|
|
204
|
+
*/
|
|
205
|
+
function scrollBottom(el) {
|
|
206
|
+
if (!el || typeof getComputedStyle !== "function") return (window.innerHeight || 0);
|
|
207
|
+
for (let node = el.parentElement; node; node = node.parentElement) {
|
|
208
|
+
const style = getComputedStyle(node);
|
|
209
|
+
if (!/(auto|scroll|overlay)/.test(style.overflowY || "")) continue;
|
|
210
|
+
if (node.scrollHeight > node.clientHeight) return node.getBoundingClientRect().bottom;
|
|
211
|
+
}
|
|
212
|
+
return (window.innerHeight || 0);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Whether one schedule catalog row targets or involves this session. */
|
|
216
|
+
function taskInvolvesSession(row, id) {
|
|
217
|
+
if (!row) return false;
|
|
218
|
+
if (row.sessionId === id) return true;
|
|
219
|
+
if (Array.isArray(row.involvedSessionIds) && row.involvedSessionIds.indexOf(id) !== -1) return true;
|
|
220
|
+
const target = row.target;
|
|
221
|
+
if (!target) return false;
|
|
222
|
+
if (target.kind === "new") return row.lastDelivery?.targetSessionId === id;
|
|
223
|
+
return target.sessionId === id;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function isSubagent(row) {
|
|
227
|
+
return row?.origin === "subagent";
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function pendingKind(value) {
|
|
231
|
+
if (value === undefined || value === null) return undefined;
|
|
232
|
+
if (typeof value === "string") return value;
|
|
233
|
+
return value.kind || "pending";
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function dotState(status) {
|
|
237
|
+
if (pendingKind(status?.pendingInteraction) !== undefined) return "pending";
|
|
238
|
+
if (status?.running === true) return "running";
|
|
239
|
+
if (status?.completionUnread === true) return "unread";
|
|
240
|
+
return "idle";
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function fmtTime(ms) {
|
|
244
|
+
if (!ms) return "";
|
|
245
|
+
const now = Date.now();
|
|
246
|
+
const diff = now - ms;
|
|
247
|
+
if (diff < 60_000) return "刚刚";
|
|
248
|
+
if (diff < 3_600_000) return Math.floor(diff / 60_000) + " 分";
|
|
249
|
+
if (diff < 86_400_000) return Math.floor(diff / 3_600_000) + " 时";
|
|
250
|
+
if (diff < 7 * 86_400_000) return Math.floor(diff / 86_400_000) + " 天";
|
|
251
|
+
const d = new Date(ms);
|
|
252
|
+
return d.getMonth() + 1 + "/" + d.getDate();
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const Row = memo(function Row(props) {
|
|
256
|
+
const { id, section, row, pinned, archived, status, scheduled, dragging, over, onOpen, onMenu, onDragStart, onDragOver, onDrop } = props;
|
|
257
|
+
const label = titleOf(row, id);
|
|
258
|
+
return h(
|
|
259
|
+
"div",
|
|
260
|
+
{
|
|
261
|
+
className: "dsg-row",
|
|
262
|
+
"data-section": section || "recent",
|
|
263
|
+
"data-dragging": dragging ? "true" : undefined,
|
|
264
|
+
"data-over": over || undefined,
|
|
265
|
+
draggable: true,
|
|
266
|
+
onClick: () => onOpen(id),
|
|
267
|
+
title: label,
|
|
268
|
+
onDragStart: (e) => {
|
|
269
|
+
try { e.dataTransfer.setData("text/plain", id); e.dataTransfer.effectAllowed = "move"; } catch {}
|
|
270
|
+
onDragStart(id);
|
|
271
|
+
},
|
|
272
|
+
onDragOver: (e) => {
|
|
273
|
+
e.preventDefault();
|
|
274
|
+
try { e.dataTransfer.dropEffect = "move"; } catch {}
|
|
275
|
+
onDragOver(section || "recent", id, rowHalf(e));
|
|
276
|
+
},
|
|
277
|
+
onDragLeave: () => onDragOver(null, null, null),
|
|
278
|
+
onDrop: (e) => {
|
|
279
|
+
e.preventDefault();
|
|
280
|
+
onDrop(section || "recent", id, rowHalf(e));
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
scheduled && dotState(status) === "idle"
|
|
284
|
+
? h("span", { className: "dsg-dot-clock", title: "已设置定时任务", "aria-label": "已设置定时任务" },
|
|
285
|
+
h("svg", { width: 12, height: 12, viewBox: "0 0 16 16", fill: "none" },
|
|
286
|
+
h("circle", { cx: 8, cy: 8, r: 6.25, stroke: "currentColor", strokeWidth: 1.5 }),
|
|
287
|
+
h("path", { d: "M8 4.5V8l2.5 1.5", stroke: "currentColor", strokeWidth: 1.5, strokeLinecap: "round", strokeLinejoin: "round" })))
|
|
288
|
+
: h("span", { className: "dsg-dot", "data-state": dotState(status) }),
|
|
289
|
+
h("span", { className: "dsg-title" }, label),
|
|
290
|
+
pinned ? h("span", { className: "dsg-pin" }, "★") : null,
|
|
291
|
+
h("span", { className: "dsg-time" }, fmtTime(updatedAt(row))),
|
|
292
|
+
h(
|
|
293
|
+
"span",
|
|
294
|
+
{ className: "dsg-actions" },
|
|
295
|
+
h("button", {
|
|
296
|
+
className: "dsg-icon",
|
|
297
|
+
title: "更多操作",
|
|
298
|
+
onClick: (e) => {
|
|
299
|
+
e.stopPropagation();
|
|
300
|
+
onMenu(id, e.currentTarget);
|
|
301
|
+
},
|
|
302
|
+
}, "⋯")
|
|
303
|
+
)
|
|
304
|
+
);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
class RegionBoundary extends React.Component {
|
|
308
|
+
constructor(props) {
|
|
309
|
+
super(props);
|
|
310
|
+
this.state = { error: null };
|
|
311
|
+
}
|
|
312
|
+
static getDerivedStateFromError(error) {
|
|
313
|
+
return { error };
|
|
314
|
+
}
|
|
315
|
+
componentDidCatch(error) {
|
|
316
|
+
try {
|
|
317
|
+
console.error("[dsh-sidebar-sessions] region failed", error);
|
|
318
|
+
} catch {}
|
|
319
|
+
}
|
|
320
|
+
render() {
|
|
321
|
+
if (this.state.error) {
|
|
322
|
+
return h("div", { className: "dsg-empty" }, "会话分组暂不可用(", String(this.state.error?.message || this.state.error), ")");
|
|
323
|
+
}
|
|
324
|
+
return this.props.children;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function GuardedRegion(props) {
|
|
329
|
+
return h(RegionBoundary, null, h(Region, props));
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function Region(props) {
|
|
333
|
+
const {
|
|
334
|
+
useSessions, useWorkspaces, useSessionStatus, useScheduleCatalog, open,
|
|
335
|
+
pinSession, unpinSession, archiveSession, unarchiveSession,
|
|
336
|
+
renameSession, forkSession, createWorkspace, pickDirectory, insertSessionBefore, openWorkspace,
|
|
337
|
+
} = props;
|
|
338
|
+
const list = useSessions((s) => s);
|
|
339
|
+
const ws = useWorkspaces((s) => s);
|
|
340
|
+
const useStatus = typeof useSessionStatus === "function" ? useSessionStatus : () => ({});
|
|
341
|
+
const statuses = useStatus((s) => s);
|
|
342
|
+
const useSchedules = typeof useScheduleCatalog === "function" ? useScheduleCatalog : () => [];
|
|
343
|
+
const schedules = useSchedules();
|
|
344
|
+
/* A scheduler row belongs to a session when it targets it (the target
|
|
345
|
+
* session, or the reserved `new_once` id / last delivered id for a `new`
|
|
346
|
+
* target) or lists it among the involved sessions. Older Host builds put
|
|
347
|
+
* a bare `sessionId` on the row, so that shape is honoured too. */
|
|
348
|
+
const scheduledOf = useCallback((id) => {
|
|
349
|
+
if (!Array.isArray(schedules)) return false;
|
|
350
|
+
return schedules.some((row) => row && row.status === "active" && taskInvolvesSession(row, id));
|
|
351
|
+
}, [schedules]);
|
|
352
|
+
const groups = useGroups();
|
|
353
|
+
const [showArchived, setShowArchived] = useState(false);
|
|
354
|
+
const [showHidden, setShowHidden] = useState(false);
|
|
355
|
+
const [menu, setMenu] = useState(null);
|
|
356
|
+
const [query, setQuery] = useState("");
|
|
357
|
+
const [dragId, setDragId] = useState(null);
|
|
358
|
+
const [dragOver, setDragOver] = useState(null);
|
|
359
|
+
const [compact, setCompact] = useState(false);
|
|
360
|
+
const rootRef = useRef(null);
|
|
361
|
+
/* Current rendered order per section key, read by the drop handler. */
|
|
362
|
+
const sectionIdsRef = useRef({});
|
|
363
|
+
|
|
364
|
+
/* Paging: the 最近 list and the search results grow one screen at a time. */
|
|
365
|
+
const [recentLimit, setRecentLimit] = useState(RECENT_LIMIT);
|
|
366
|
+
const [searchLimit, setSearchLimit] = useState(RECENT_LIMIT);
|
|
367
|
+
const [loadingMore, setLoadingMore] = useState(null);
|
|
368
|
+
const moreRef = useRef(null);
|
|
369
|
+
const searchMoreRef = useRef(null);
|
|
370
|
+
const loadGuard = useRef(false);
|
|
371
|
+
const loadTimer = useRef(null);
|
|
372
|
+
/* One automatic batch per scroll burst: appending rows makes the browser
|
|
373
|
+
* anchor the scroll position, which would otherwise keep the footer in
|
|
374
|
+
* range and quietly load the whole history in one gesture. */
|
|
375
|
+
const autoPagerAt = useRef(0);
|
|
376
|
+
const liveSortedRef = useRef([]);
|
|
377
|
+
const recentLimitRef = useRef(RECENT_LIMIT);
|
|
378
|
+
|
|
379
|
+
useLayoutEffect(() => {
|
|
380
|
+
const el = rootRef.current;
|
|
381
|
+
if (!el) return undefined;
|
|
382
|
+
const measure = () => {
|
|
383
|
+
const w = el.getBoundingClientRect().width;
|
|
384
|
+
setCompact(w > 0 && w < 150);
|
|
385
|
+
};
|
|
386
|
+
measure();
|
|
387
|
+
const ro = typeof ResizeObserver !== "undefined" ? new ResizeObserver(measure) : undefined;
|
|
388
|
+
if (ro) ro.observe(el);
|
|
389
|
+
else window.addEventListener("resize", measure);
|
|
390
|
+
return () => {
|
|
391
|
+
if (ro) ro.disconnect();
|
|
392
|
+
else window.removeEventListener("resize", measure);
|
|
393
|
+
};
|
|
394
|
+
}, []);
|
|
395
|
+
const searching = query.trim().length > 0;
|
|
396
|
+
|
|
397
|
+
const byId = list?.byId || {};
|
|
398
|
+
const pinnedSet = useMemo(() => new Set(ws?.pinnedSessionIds || []), [ws]);
|
|
399
|
+
const archivedSet = useMemo(() => new Set(ws?.archivedSessionIds || []), [ws]);
|
|
400
|
+
const assign = groups.assign || {};
|
|
401
|
+
const collapsed = groups.collapsed || {};
|
|
402
|
+
const orders = groups.order || {};
|
|
403
|
+
const hidden = store.get().hiddenWorkspaces || [];
|
|
404
|
+
|
|
405
|
+
const ids = useMemo(() => (list?.ids || []).filter((id) => byId[id] && !isSubagent(byId[id])), [list, byId]);
|
|
406
|
+
const archived = useMemo(() => ids.filter((id) => archivedSet.has(id)), [ids, archivedSet]);
|
|
407
|
+
const live = useMemo(() => ids.filter((id) => !archivedSet.has(id)), [ids, archivedSet]);
|
|
408
|
+
const archivedOrdered = useMemo(() => applyManualOrder(archived, orders["archived"]), [archived, orders]);
|
|
409
|
+
const liveSorted = useMemo(() => sortRecent(live, byId), [live, byId]);
|
|
410
|
+
const recentBase = useMemo(() => liveSorted.slice(0, recentLimit), [liveSorted, recentLimit]);
|
|
411
|
+
const recent = useMemo(() => applyManualOrder(recentBase, orders.recent), [recentBase, orders]);
|
|
412
|
+
const remainingRecent = Math.max(0, live.length - recent.length);
|
|
413
|
+
liveSortedRef.current = liveSorted;
|
|
414
|
+
recentLimitRef.current = recentLimit;
|
|
415
|
+
const pinned = useMemo(() => applyManualOrder(sortRecent(live.filter((id) => pinnedSet.has(id)), byId), orders.pinned), [live, byId, pinnedSet, orders]);
|
|
416
|
+
|
|
417
|
+
const accountOf = useCallback((id) => {
|
|
418
|
+
for (const item of ws?.items || []) {
|
|
419
|
+
if ((item.sessionIds || []).includes(id)) return item.workspaceId;
|
|
420
|
+
}
|
|
421
|
+
return undefined;
|
|
422
|
+
}, [ws]);
|
|
423
|
+
|
|
424
|
+
const visibleWorkspaces = useMemo(
|
|
425
|
+
() => (ws?.items || []).filter((it) => !hidden.includes(String(it.workspaceId))),
|
|
426
|
+
[ws, hidden]
|
|
427
|
+
);
|
|
428
|
+
const hiddenWorkspaces = useMemo(
|
|
429
|
+
() => (ws?.items || []).filter((it) => hidden.includes(String(it.workspaceId))),
|
|
430
|
+
[ws, hidden]
|
|
431
|
+
);
|
|
432
|
+
|
|
433
|
+
const groupRows = useMemo(() => {
|
|
434
|
+
const byGroup = new Map();
|
|
435
|
+
for (const g of groups.groups) byGroup.set(g.id, []);
|
|
436
|
+
const rest = [];
|
|
437
|
+
const shownInWorkspaces = new Set();
|
|
438
|
+
for (const item of visibleWorkspaces) for (const id of item.sessionIds || []) shownInWorkspaces.add(id);
|
|
439
|
+
for (const id of live) {
|
|
440
|
+
if (pinnedSet.has(id)) continue;
|
|
441
|
+
if (shownInWorkspaces.has(id)) continue;
|
|
442
|
+
const gid = assign[id];
|
|
443
|
+
if (gid && byGroup.has(gid)) byGroup.get(gid).push(id);
|
|
444
|
+
else rest.push(id);
|
|
445
|
+
}
|
|
446
|
+
for (const [gid, arr] of byGroup) byGroup.set(gid, applyManualOrder(sortRecent(arr, byId), orders["g:" + gid]));
|
|
447
|
+
return { byGroup, rest: applyManualOrder(sortRecent(rest, byId), orders.ungrouped) };
|
|
448
|
+
}, [live, byId, groups.groups, assign, pinnedSet, visibleWorkspaces, orders]);
|
|
449
|
+
|
|
450
|
+
const filteredAll = useMemo(() => {
|
|
451
|
+
const needle = query.trim().toLowerCase();
|
|
452
|
+
if (!needle) return null;
|
|
453
|
+
return sortRecent(ids.filter((id) => titleOf(byId[id], id).toLowerCase().includes(needle)), byId);
|
|
454
|
+
}, [query, ids, byId]);
|
|
455
|
+
const filtered = useMemo(() => (filteredAll ? filteredAll.slice(0, searchLimit) : null), [filteredAll, searchLimit]);
|
|
456
|
+
const remainingSearch = filteredAll ? Math.max(0, filteredAll.length - (filtered ? filtered.length : 0)) : 0;
|
|
457
|
+
|
|
458
|
+
/* Grow one batch; a drag suppresses it so a list never reflows under the
|
|
459
|
+
* pointer. The 140ms window is the "加载中…" state, not a wait. */
|
|
460
|
+
const growRecent = useCallback(() => {
|
|
461
|
+
if (loadGuard.current || dragId) return;
|
|
462
|
+
loadGuard.current = true;
|
|
463
|
+
setLoadingMore("recent");
|
|
464
|
+
loadTimer.current = setTimeout(() => {
|
|
465
|
+
loadGuard.current = false;
|
|
466
|
+
setLoadingMore(null);
|
|
467
|
+
const limit = recentLimitRef.current;
|
|
468
|
+
const next = limit + RECENT_LIMIT;
|
|
469
|
+
/* A manual order must absorb the newly revealed rows, or the ones it
|
|
470
|
+
* never saw would jump above it (fresh rows render first). */
|
|
471
|
+
const cur = store.get();
|
|
472
|
+
const saved = cur.order && cur.order.recent;
|
|
473
|
+
if (Array.isArray(saved) && saved.length > 0) {
|
|
474
|
+
const seen = new Set(saved);
|
|
475
|
+
const revealed = liveSortedRef.current.slice(limit, next).filter((id) => !seen.has(id));
|
|
476
|
+
if (revealed.length > 0) store.set({ ...cur, order: { ...cur.order, recent: saved.concat(revealed) } });
|
|
477
|
+
}
|
|
478
|
+
setRecentLimit(next);
|
|
479
|
+
}, 140);
|
|
480
|
+
}, [dragId]);
|
|
481
|
+
|
|
482
|
+
const growSearch = useCallback(() => {
|
|
483
|
+
if (loadGuard.current || dragId) return;
|
|
484
|
+
loadGuard.current = true;
|
|
485
|
+
setLoadingMore("search");
|
|
486
|
+
loadTimer.current = setTimeout(() => {
|
|
487
|
+
loadGuard.current = false;
|
|
488
|
+
setLoadingMore(null);
|
|
489
|
+
setSearchLimit((n) => n + RECENT_LIMIT);
|
|
490
|
+
}, 140);
|
|
491
|
+
}, [dragId]);
|
|
492
|
+
|
|
493
|
+
useEffect(() => () => { if (loadTimer.current) clearTimeout(loadTimer.current); }, []);
|
|
494
|
+
useEffect(() => { setSearchLimit(RECENT_LIMIT); }, [query]);
|
|
495
|
+
|
|
496
|
+
/* Auto-grow when the footer nears the bottom of the visible box; clicking
|
|
497
|
+
* it does the same, so a fast scroll and a deliberate click agree. */
|
|
498
|
+
useEffect(() => {
|
|
499
|
+
const el = moreRef.current;
|
|
500
|
+
if (!el || remainingRecent <= 0) return undefined;
|
|
501
|
+
let ticking = false;
|
|
502
|
+
const check = () => {
|
|
503
|
+
ticking = false;
|
|
504
|
+
if (Date.now() - autoPagerAt.current < 900) return;
|
|
505
|
+
if (el.getBoundingClientRect().top < scrollBottom(el) + 240) {
|
|
506
|
+
autoPagerAt.current = Date.now();
|
|
507
|
+
growRecent();
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
const onScroll = () => { if (!ticking) { ticking = true; requestAnimationFrame(check); } };
|
|
511
|
+
check();
|
|
512
|
+
window.addEventListener("scroll", onScroll, true);
|
|
513
|
+
window.addEventListener("resize", onScroll);
|
|
514
|
+
return () => {
|
|
515
|
+
window.removeEventListener("scroll", onScroll, true);
|
|
516
|
+
window.removeEventListener("resize", onScroll);
|
|
517
|
+
};
|
|
518
|
+
}, [remainingRecent, recentLimit, growRecent, searching]);
|
|
519
|
+
|
|
520
|
+
useEffect(() => {
|
|
521
|
+
const el = searchMoreRef.current;
|
|
522
|
+
if (!el || remainingSearch <= 0) return undefined;
|
|
523
|
+
let ticking = false;
|
|
524
|
+
const check = () => {
|
|
525
|
+
ticking = false;
|
|
526
|
+
if (Date.now() - autoPagerAt.current < 900) return;
|
|
527
|
+
if (el.getBoundingClientRect().top < scrollBottom(el) + 240) {
|
|
528
|
+
autoPagerAt.current = Date.now();
|
|
529
|
+
growSearch();
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
const onScroll = () => { if (!ticking) { ticking = true; requestAnimationFrame(check); } };
|
|
533
|
+
check();
|
|
534
|
+
window.addEventListener("scroll", onScroll, true);
|
|
535
|
+
window.addEventListener("resize", onScroll);
|
|
536
|
+
return () => {
|
|
537
|
+
window.removeEventListener("scroll", onScroll, true);
|
|
538
|
+
window.removeEventListener("resize", onScroll);
|
|
539
|
+
};
|
|
540
|
+
}, [remainingSearch, searchLimit, growSearch]);
|
|
541
|
+
|
|
542
|
+
/* Default workspace = the one holding the most recent live session. */
|
|
543
|
+
const currentWsId = useMemo(() => {
|
|
544
|
+
if (groups.activeWorkspace) return groups.activeWorkspace;
|
|
545
|
+
for (const id of recent) {
|
|
546
|
+
const found = (ws?.items || []).find((it) => (it.sessionIds || []).includes(id));
|
|
547
|
+
if (found) return found.workspaceId;
|
|
548
|
+
}
|
|
549
|
+
return visibleWorkspaces[0]?.workspaceId;
|
|
550
|
+
}, [groups.activeWorkspace, recent, ws, visibleWorkspaces]);
|
|
551
|
+
|
|
552
|
+
const toggle = useCallback((key) => {
|
|
553
|
+
const cur = store.get();
|
|
554
|
+
store.set({ ...cur, collapsed: { ...cur.collapsed, [key]: !(cur.collapsed || {})[key] } });
|
|
555
|
+
}, []);
|
|
556
|
+
|
|
557
|
+
const assignTo = useCallback((id, gid) => {
|
|
558
|
+
const cur = store.get();
|
|
559
|
+
const nextAssign = { ...cur.assign };
|
|
560
|
+
if (gid) nextAssign[id] = gid;
|
|
561
|
+
else delete nextAssign[id];
|
|
562
|
+
store.set({ ...cur, assign: nextAssign });
|
|
563
|
+
}, []);
|
|
564
|
+
|
|
565
|
+
const createGroup = useCallback((sessionId) => {
|
|
566
|
+
const name = window.prompt("新分组名称");
|
|
567
|
+
if (!name || !name.trim()) return;
|
|
568
|
+
const g = { id: newGroupId(), name: name.trim().slice(0, 20) };
|
|
569
|
+
const cur = store.get();
|
|
570
|
+
const next = { ...cur, groups: [...cur.groups, g] };
|
|
571
|
+
if (sessionId) next.assign = { ...cur.assign, [sessionId]: g.id };
|
|
572
|
+
store.set(next);
|
|
573
|
+
}, []);
|
|
574
|
+
|
|
575
|
+
const renameGroup = useCallback((g) => {
|
|
576
|
+
const name = window.prompt("分组名称", g.name);
|
|
577
|
+
if (!name || !name.trim()) return;
|
|
578
|
+
const cur = store.get();
|
|
579
|
+
store.set({ ...cur, groups: cur.groups.map((x) => (x.id === g.id ? { ...x, name: name.trim().slice(0, 20) } : x)) });
|
|
580
|
+
}, []);
|
|
581
|
+
|
|
582
|
+
const deleteGroup = useCallback((g) => {
|
|
583
|
+
if (!window.confirm(`删除分组「${g.name}」?组内会话会回到未分组。`)) return;
|
|
584
|
+
const cur = store.get();
|
|
585
|
+
const nextAssign = { ...cur.assign };
|
|
586
|
+
for (const [sid, gid] of Object.entries(nextAssign)) if (gid === g.id) delete nextAssign[sid];
|
|
587
|
+
store.set({ ...cur, groups: cur.groups.filter((x) => x.id !== g.id), assign: nextAssign });
|
|
588
|
+
}, []);
|
|
589
|
+
|
|
590
|
+
const switchWorkspace = useCallback((item) => {
|
|
591
|
+
const cur = store.get();
|
|
592
|
+
store.set({ ...cur, activeWorkspace: String(item.workspaceId) });
|
|
593
|
+
try {
|
|
594
|
+
if (openWorkspace) Promise.resolve(openWorkspace(item.workspaceId)).catch((err) => console.error("[dsh-sidebar-sessions] switch workspace failed", err));
|
|
595
|
+
} catch (err) {
|
|
596
|
+
console.error("[dsh-sidebar-sessions] switch workspace failed", err);
|
|
597
|
+
}
|
|
598
|
+
}, [openWorkspace]);
|
|
599
|
+
|
|
600
|
+
const hideWorkspace = useCallback((item) => {
|
|
601
|
+
const cur = store.get();
|
|
602
|
+
const id = String(item.workspaceId);
|
|
603
|
+
store.set({ ...cur, hiddenWorkspaces: [...new Set([...(cur.hiddenWorkspaces || []), id])] });
|
|
604
|
+
}, []);
|
|
605
|
+
|
|
606
|
+
const unhideWorkspace = useCallback((item) => {
|
|
607
|
+
const cur = store.get();
|
|
608
|
+
const id = String(item.workspaceId);
|
|
609
|
+
store.set({ ...cur, hiddenWorkspaces: (cur.hiddenWorkspaces || []).filter((x) => x !== id) });
|
|
610
|
+
}, []);
|
|
611
|
+
|
|
612
|
+
const closeMenu = useCallback(() => setMenu(null), []);
|
|
613
|
+
const openMenu = useCallback((id, el) => {
|
|
614
|
+
const r = el.getBoundingClientRect();
|
|
615
|
+
setMenu({ id, x: Math.min(r.right - 190, Math.max(8, window.innerWidth - 210)), y: Math.min(r.bottom + 2, window.innerHeight - 280) });
|
|
616
|
+
}, []);
|
|
617
|
+
|
|
618
|
+
const renameRow = useCallback(async (id) => {
|
|
619
|
+
const name = window.prompt("重命名对话", titleOf(byId[id], id));
|
|
620
|
+
if (!name || !name.trim() || !renameSession) return;
|
|
621
|
+
try {
|
|
622
|
+
await renameSession(id, name.trim());
|
|
623
|
+
} catch (err) {
|
|
624
|
+
console.error("[dsh-sidebar-sessions] rename failed", err);
|
|
625
|
+
}
|
|
626
|
+
}, [byId, renameSession]);
|
|
627
|
+
|
|
628
|
+
const copy = useCallback((text) => {
|
|
629
|
+
try {
|
|
630
|
+
if (navigator.clipboard?.writeText) navigator.clipboard.writeText(text);
|
|
631
|
+
} catch {}
|
|
632
|
+
}, []);
|
|
633
|
+
|
|
634
|
+
const commitSectionOrder = useCallback((sectionKey, next) => {
|
|
635
|
+
if (!next || sectionKey === "search") return;
|
|
636
|
+
const cur = store.get();
|
|
637
|
+
store.set({ ...cur, order: { ...(cur.order || {}), [sectionKey]: next } });
|
|
638
|
+
}, []);
|
|
639
|
+
|
|
640
|
+
const clearSectionOrder = useCallback((sectionKey) => {
|
|
641
|
+
const cur = store.get();
|
|
642
|
+
const order = { ...(cur.order || {}) };
|
|
643
|
+
if (!(sectionKey in order)) return;
|
|
644
|
+
delete order[sectionKey];
|
|
645
|
+
store.set({ ...cur, order });
|
|
646
|
+
}, []);
|
|
647
|
+
|
|
648
|
+
const handleDragOver = useCallback((section, id, half) => {
|
|
649
|
+
if (!id) {
|
|
650
|
+
setDragOver(null);
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
/* No marker when the dragged row is not part of that list: a drop there
|
|
654
|
+
* cannot move anything, so promising a landing line would lie. */
|
|
655
|
+
const ids = sectionIdsRef.current[section];
|
|
656
|
+
if (!dragId || !ids || !ids.includes(dragId)) {
|
|
657
|
+
setDragOver(null);
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
setDragOver({ section, id, half: half || "before" });
|
|
661
|
+
}, [dragId]);
|
|
662
|
+
|
|
663
|
+
/** End of any drag: no row may stay in its "being dragged" state. */
|
|
664
|
+
const handleDragEnd = useCallback(() => {
|
|
665
|
+
setDragId(null);
|
|
666
|
+
setDragOver(null);
|
|
667
|
+
}, []);
|
|
668
|
+
|
|
669
|
+
const onDropRow = useCallback((sectionKey, targetId, half) => {
|
|
670
|
+
const src = dragId;
|
|
671
|
+
setDragId(null);
|
|
672
|
+
setDragOver(null);
|
|
673
|
+
if (!src || src === targetId) return;
|
|
674
|
+
const ids = sectionIdsRef.current[sectionKey] || [];
|
|
675
|
+
const next = moveTo(ids, src, targetId, half);
|
|
676
|
+
/* Workspace tree: the host owns the order, so write it durably and
|
|
677
|
+
* fall back to the local view order only when the host refuses. */
|
|
678
|
+
if (typeof sectionKey === "string" && sectionKey.indexOf("ws:") === 0) {
|
|
679
|
+
if (!next) return;
|
|
680
|
+
const a = accountOf(src);
|
|
681
|
+
const b = accountOf(targetId);
|
|
682
|
+
if (a === undefined || a !== b) return;
|
|
683
|
+
/* A local order means the view already overrides the host; keep it local. */
|
|
684
|
+
if (orders[sectionKey]) {
|
|
685
|
+
commitSectionOrder(sectionKey, next);
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
/* insertSessionBefore takes the id that must FOLLOW the moved row. */
|
|
689
|
+
const anchor = half === "after" ? anchorAfter(ids, src, targetId) : targetId;
|
|
690
|
+
if (anchor === src) return;
|
|
691
|
+
const keepLocal = () => commitSectionOrder(sectionKey, next);
|
|
692
|
+
if (!insertSessionBefore) return;
|
|
693
|
+
try {
|
|
694
|
+
Promise.resolve(insertSessionBefore(a, src, anchor))
|
|
695
|
+
.then((result) => {
|
|
696
|
+
if (result && result.ok === false) {
|
|
697
|
+
console.error("[dsh-sidebar-sessions] reorder rejected, keeping view order", result.error);
|
|
698
|
+
keepLocal();
|
|
699
|
+
} else clearSectionOrder(sectionKey);
|
|
700
|
+
})
|
|
701
|
+
.catch((err) => {
|
|
702
|
+
console.error("[dsh-sidebar-sessions] reorder failed", err);
|
|
703
|
+
keepLocal();
|
|
704
|
+
});
|
|
705
|
+
} catch (err) {
|
|
706
|
+
console.error("[dsh-sidebar-sessions] reorder failed", err);
|
|
707
|
+
keepLocal();
|
|
708
|
+
}
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
/* Every other list is view order: keep it locally, or the recency
|
|
712
|
+
* sort would put the row straight back where it was. */
|
|
713
|
+
commitSectionOrder(sectionKey, next);
|
|
714
|
+
}, [dragId, accountOf, insertSessionBefore, commitSectionOrder, clearSectionOrder, orders]);
|
|
715
|
+
|
|
716
|
+
const sections = { recent, pinned, archived: archivedOrdered, search: filtered || [], ungrouped: groupRows.rest };
|
|
717
|
+
for (const g of groups.groups) sections["g:" + g.id] = groupRows.byGroup.get(g.id) || [];
|
|
718
|
+
for (const item of visibleWorkspaces) sections["ws:" + String(item.workspaceId)] = applyManualOrder((item.sessionIds || []).filter((id) => byId[id] && !archivedSet.has(id)), orders["ws:" + String(item.workspaceId)]);
|
|
719
|
+
sectionIdsRef.current = sections;
|
|
720
|
+
|
|
721
|
+
const renderRow = useCallback(
|
|
722
|
+
(id, opts) =>
|
|
723
|
+
h(Row, {
|
|
724
|
+
key: id,
|
|
725
|
+
id,
|
|
726
|
+
section: (opts && opts.section) || "recent",
|
|
727
|
+
row: byId[id],
|
|
728
|
+
pinned: pinnedSet.has(id),
|
|
729
|
+
archived: archivedSet.has(id),
|
|
730
|
+
status: statuses?.get?.(id),
|
|
731
|
+
scheduled: scheduledOf(id),
|
|
732
|
+
dragging: dragId === id,
|
|
733
|
+
over: dragOver !== null && dragOver.id === id && dragOver.section === ((opts && opts.section) || "recent") && dragId !== null && dragId !== id ? dragOver.half : null,
|
|
734
|
+
onOpen: open,
|
|
735
|
+
onMenu: openMenu,
|
|
736
|
+
onDragStart: setDragId,
|
|
737
|
+
onDragOver: handleDragOver,
|
|
738
|
+
onDrop: onDropRow,
|
|
739
|
+
...(opts || {}),
|
|
740
|
+
}),
|
|
741
|
+
[byId, pinnedSet, archivedSet, statuses, scheduledOf, dragId, dragOver, open, openMenu, onDropRow, handleDragOver]
|
|
742
|
+
);
|
|
743
|
+
|
|
744
|
+
const head = (label, count, onToggle, caret, extra) =>
|
|
745
|
+
h(
|
|
746
|
+
"div",
|
|
747
|
+
{ className: "dsg-head", onClick: onToggle },
|
|
748
|
+
h("span", { className: "dsg-caret" }, caret),
|
|
749
|
+
h("span", { className: "dsg-head-label" }, label),
|
|
750
|
+
h("span", { className: "dsg-count" }, String(count)),
|
|
751
|
+
extra || null
|
|
752
|
+
);
|
|
753
|
+
|
|
754
|
+
const section = (key, label, count, body, extra) =>
|
|
755
|
+
h(
|
|
756
|
+
"div",
|
|
757
|
+
{ key },
|
|
758
|
+
head(label, count, () => toggle(key), collapsed[key] ? "▸" : "▾", extra),
|
|
759
|
+
collapsed[key] ? null : body
|
|
760
|
+
);
|
|
761
|
+
|
|
762
|
+
/* Footer of a paged list: 还能翻 / 加载中 / 到底了. */
|
|
763
|
+
const moreButton = (onClick) => ({
|
|
764
|
+
role: "button",
|
|
765
|
+
tabIndex: 0,
|
|
766
|
+
onClick,
|
|
767
|
+
onKeyDown: (ev) => {
|
|
768
|
+
if (ev.key !== "Enter" && ev.key !== " ") return;
|
|
769
|
+
ev.preventDefault();
|
|
770
|
+
onClick();
|
|
771
|
+
},
|
|
772
|
+
});
|
|
773
|
+
|
|
774
|
+
const recentFooter = (() => {
|
|
775
|
+
if (loadingMore === "recent") return h("div", { className: "dsg-more", "data-pager": "recent", ref: moreRef }, "加载中…");
|
|
776
|
+
if (remainingRecent > 0) {
|
|
777
|
+
return h("div", { ...moreButton(growRecent), ref: moreRef, className: "dsg-more", "data-pager": "recent", title: "加载更多对话" },
|
|
778
|
+
`显示更多(还有 ${remainingRecent} 条)`);
|
|
779
|
+
}
|
|
780
|
+
if (live.length > RECENT_LIMIT) {
|
|
781
|
+
return h("div", { className: "dsg-more dsg-more-end", "data-pager": "recent" }, `已经是最早的对话了 · 共 ${live.length} 条`);
|
|
782
|
+
}
|
|
783
|
+
return null;
|
|
784
|
+
})();
|
|
785
|
+
|
|
786
|
+
const searchFooter = (() => {
|
|
787
|
+
if (!filteredAll || filteredAll.length === 0) return null;
|
|
788
|
+
if (loadingMore === "search") return h("div", { className: "dsg-more", "data-pager": "search", ref: searchMoreRef }, "加载中…");
|
|
789
|
+
if (remainingSearch > 0) {
|
|
790
|
+
return h("div", { ...moreButton(growSearch), ref: searchMoreRef, className: "dsg-more", "data-pager": "search", title: "加载更多匹配" },
|
|
791
|
+
`还有 ${remainingSearch} 条匹配`);
|
|
792
|
+
}
|
|
793
|
+
if (filteredAll.length > RECENT_LIMIT) {
|
|
794
|
+
return h("div", { className: "dsg-more dsg-more-end", "data-pager": "search" }, `全部 ${filteredAll.length} 条匹配都在这了`);
|
|
795
|
+
}
|
|
796
|
+
return null;
|
|
797
|
+
})();
|
|
798
|
+
const menuEl = menu
|
|
799
|
+
? h(
|
|
800
|
+
"div",
|
|
801
|
+
{ className: "dsg-menu", style: { left: menu.x, top: menu.y }, onMouseLeave: closeMenu },
|
|
802
|
+
h("div", { className: "dsg-menu-item", onClick: () => { pinnedSet.has(menu.id) ? unpinSession(menu.id) : pinSession(menu.id); closeMenu(); } },
|
|
803
|
+
pinnedSet.has(menu.id) ? "取消置顶" : "置顶"),
|
|
804
|
+
h("div", { className: "dsg-menu-item", onClick: () => { renameRow(menu.id); closeMenu(); } }, "重命名"),
|
|
805
|
+
h("div", { className: "dsg-menu-item", onClick: () => { if (forkSession) forkSession(menu.id); closeMenu(); } }, "分叉会话"),
|
|
806
|
+
h("div", { className: "dsg-menu-item", onClick: () => { copy(menu.id); closeMenu(); } }, "复制 Session ID"),
|
|
807
|
+
h("div", { className: "dsg-menu-item", onClick: () => { const item = (ws?.items || []).find((x) => (x.sessionIds || []).includes(menu.id)); if (item?.path) copy(item.path); closeMenu(); } }, "复制工作目录"),
|
|
808
|
+
h("div", { className: "dsg-menu-sep" }),
|
|
809
|
+
h("div", { className: "dsg-menu-label" }, "移动到分组"),
|
|
810
|
+
h("div", { className: "dsg-menu-item", onClick: () => { assignTo(menu.id, null); closeMenu(); } }, "未分组"),
|
|
811
|
+
groups.groups.map((g) =>
|
|
812
|
+
h("div", { key: g.id, className: "dsg-menu-item", onClick: () => { assignTo(menu.id, g.id); closeMenu(); } },
|
|
813
|
+
h("span", { className: "dsg-dot-sm" }, "●"), g.name)
|
|
814
|
+
),
|
|
815
|
+
h("div", { className: "dsg-menu-item", onClick: () => { createGroup(menu.id); closeMenu(); } }, "+ 新建分组…"),
|
|
816
|
+
h("div", { className: "dsg-menu-sep" }),
|
|
817
|
+
h("div", { className: "dsg-menu-item", onClick: () => { archivedSet.has(menu.id) ? unarchiveSession(menu.id) : archiveSession(menu.id); closeMenu(); } },
|
|
818
|
+
archivedSet.has(menu.id) ? "取消归档" : "归档")
|
|
819
|
+
)
|
|
820
|
+
: null;
|
|
821
|
+
|
|
822
|
+
return h(
|
|
823
|
+
"div",
|
|
824
|
+
{
|
|
825
|
+
className: "dsg-root",
|
|
826
|
+
ref: rootRef,
|
|
827
|
+
onClick: menu ? closeMenu : undefined,
|
|
828
|
+
/* A drag can end without a drop on a row (released on a header, the
|
|
829
|
+
* gap between sections, or cancelled with Esc); dragend is the only
|
|
830
|
+
* event that always fires, and without it that row keeps the 45%
|
|
831
|
+
* "being dragged" dimming until the next drop or a reload. */
|
|
832
|
+
onDragEnd: handleDragEnd,
|
|
833
|
+
onDrop: (e) => { e.preventDefault(); handleDragEnd(); },
|
|
834
|
+
},
|
|
835
|
+
compact ? null : h(React.Fragment, null,
|
|
836
|
+
h("div", { className: "dsg-ws" },
|
|
837
|
+
h("button", { className: "dsg-ws-btn", onClick: async () => {
|
|
838
|
+
try {
|
|
839
|
+
if (pickDirectory && createWorkspace) {
|
|
840
|
+
const dir = await pickDirectory();
|
|
841
|
+
if (dir) await createWorkspace(dir);
|
|
842
|
+
}
|
|
843
|
+
} catch (err) {
|
|
844
|
+
console.error("[dsh-sidebar-sessions] create workspace failed", err);
|
|
845
|
+
}
|
|
846
|
+
} }, "+ 新建工作区")),
|
|
847
|
+
h("div", { className: "dsg-search" },
|
|
848
|
+
h("input", {
|
|
849
|
+
value: query,
|
|
850
|
+
placeholder: "搜索对话",
|
|
851
|
+
onChange: (e) => setQuery(e.target.value),
|
|
852
|
+
onKeyDown: (e) => { if (e.key === "Escape") setQuery(""); },
|
|
853
|
+
}),
|
|
854
|
+
query ? h("button", { className: "dsg-icon", title: "清除", onClick: () => setQuery("") }, "✕") : null),
|
|
855
|
+
searching
|
|
856
|
+
? h("div", null,
|
|
857
|
+
head("搜索结果", (filtered || []).length, () => {}, "▾"),
|
|
858
|
+
(filtered || []).length
|
|
859
|
+
? h("div", null, filtered.map((id) => renderRow(id, { section: "search" })), searchFooter)
|
|
860
|
+
: h("div", { className: "dsg-empty" }, "没有匹配的对话"))
|
|
861
|
+
: h(React.Fragment, null,
|
|
862
|
+
pinned.length ? section("pinned", "置顶", pinned.length, h("div", null, pinned.map((id) => renderRow(id, { section: "pinned" })))) : null,
|
|
863
|
+
section("recent", "最近", recent.length, h("div", null, recent.map((id) => renderRow(id, { section: "recent" })), recentFooter),
|
|
864
|
+
Array.isArray(orders.recent) && orders.recent.length
|
|
865
|
+
? h("button", { className: "dsg-icon", style: { width: 18, height: 18, fontSize: 11, flex: "none" }, title: "恢复最近排序", onClick: (e) => { e.stopPropagation(); clearSectionOrder("recent"); } }, "↺")
|
|
866
|
+
: null),
|
|
867
|
+
groups.groups.map((g) => {
|
|
868
|
+
const rows = groupRows.byGroup.get(g.id) || [];
|
|
869
|
+
return h("div", { key: g.id },
|
|
870
|
+
h("div", { className: "dsg-head", onClick: () => toggle("g:" + g.id) },
|
|
871
|
+
h("span", { className: "dsg-caret" }, collapsed["g:" + g.id] ? "▸" : "▾"),
|
|
872
|
+
h("span", { className: "dsg-head-label" }, g.name),
|
|
873
|
+
h("span", { className: "dsg-count" }, String(rows.length)),
|
|
874
|
+
h("span", { style: { display: "flex", gap: 2, flex: "none" }, onClick: (e) => e.stopPropagation() },
|
|
875
|
+
h("button", { className: "dsg-icon", style: { width: 18, height: 18, fontSize: 11 }, title: "重命名", onClick: () => renameGroup(g) }, "✎"),
|
|
876
|
+
h("button", { className: "dsg-icon", style: { width: 18, height: 18, fontSize: 11 }, title: "删除分组", onClick: () => deleteGroup(g) }, "✕"))),
|
|
877
|
+
collapsed["g:" + g.id] ? null : h("div", null, rows.map((id) => renderRow(id, { section: "g:" + g.id }))));
|
|
878
|
+
}),
|
|
879
|
+
section("ungrouped", "未分组", groupRows.rest.length, h("div", null, groupRows.rest.map((id) => renderRow(id, { section: "ungrouped" })))),
|
|
880
|
+
archivedOrdered.length
|
|
881
|
+
? h("div", { key: "archived" },
|
|
882
|
+
head("已归档", archivedOrdered.length, () => setShowArchived((v) => !v), showArchived ? "▾" : "▸"),
|
|
883
|
+
showArchived ? h("div", null, archivedOrdered.map((id) => renderRow(id, { archived: true, section: "archived" }))) : null)
|
|
884
|
+
: null,
|
|
885
|
+
/* Workspace block: same shape as a group, marked as a workspace. */
|
|
886
|
+
h("div", { key: "wsroot" },
|
|
887
|
+
h("div", { className: "dsg-head", onClick: () => toggle("ws:root") },
|
|
888
|
+
h("span", { className: "dsg-caret" }, collapsed["ws:root"] ? "▸" : "▾"),
|
|
889
|
+
h("span", { className: "dsg-head-label" }, "📁 工作区"),
|
|
890
|
+
h("span", { className: "dsg-count" }, String(visibleWorkspaces.length))),
|
|
891
|
+
collapsed["ws:root"] ? null : h("div", null,
|
|
892
|
+
visibleWorkspaces.length === 0
|
|
893
|
+
? h("div", { className: "dsg-empty" }, "还没有工作区,点上方「+ 新建工作区」")
|
|
894
|
+
: visibleWorkspaces.map((item) => {
|
|
895
|
+
const key = "ws:" + String(item.workspaceId);
|
|
896
|
+
const members = applyManualOrder((item.sessionIds || []).filter((id) => byId[id] && !archivedSet.has(id)), orders[key]);
|
|
897
|
+
const isCurrent = String(currentWsId) === String(item.workspaceId);
|
|
898
|
+
const label = item.title || item.path || String(item.workspaceId);
|
|
899
|
+
return h("div", { key },
|
|
900
|
+
h("div", { className: "dsg-head", onClick: () => { switchWorkspace(item); if (collapsed[key]) toggle(key); } },
|
|
901
|
+
h("span", { className: "dsg-caret", onClick: (e) => { e.stopPropagation(); toggle(key); } }, collapsed[key] ? "▸" : "▾"),
|
|
902
|
+
h("span", { className: "dsg-head-label" }, (isCurrent ? "📌 " : "📁 ") + label),
|
|
903
|
+
h("span", { className: "dsg-count" }, String(members.length)),
|
|
904
|
+
h("button", { className: "dsg-icon", style: { width: 18, height: 18, fontSize: 11 }, title: "隐藏工作区", onClick: (e) => { e.stopPropagation(); hideWorkspace(item); } }, "✕")),
|
|
905
|
+
collapsed[key] ? null : h("div", null, members.map((id) => renderRow(id, { section: key }))));
|
|
906
|
+
}))),
|
|
907
|
+
hiddenWorkspaces.length
|
|
908
|
+
? h("div", { key: "hiddenws" },
|
|
909
|
+
head("已隐藏的工作区", hiddenWorkspaces.length, () => setShowHidden((v) => !v), showHidden ? "▾" : "▸"),
|
|
910
|
+
showHidden
|
|
911
|
+
? h("div", null, hiddenWorkspaces.map((item) =>
|
|
912
|
+
h("div", { key: String(item.workspaceId), className: "dsg-ws-row" },
|
|
913
|
+
h("span", { style: { flex: 1, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" } }, item.title || item.path || String(item.workspaceId)),
|
|
914
|
+
h("button", { className: "dsg-icon", style: { width: 18, height: 18, fontSize: 11 }, title: "恢复显示", onClick: () => unhideWorkspace(item) }, "↩"))))
|
|
915
|
+
: null)
|
|
916
|
+
: null),
|
|
917
|
+
),
|
|
918
|
+
menuEl
|
|
919
|
+
);
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
function apply(ctx) {
|
|
923
|
+
ctx.effect(() => injectStyles(), "dsh-sidebar-sessions: styles");
|
|
924
|
+
|
|
925
|
+
/* Schedule catalog: active (not yet fired) reminders, refreshed on change. */
|
|
926
|
+
const scheduleStore = (() => {
|
|
927
|
+
let state = [];
|
|
928
|
+
const listeners = new Set();
|
|
929
|
+
return {
|
|
930
|
+
get: () => state,
|
|
931
|
+
set(next) {
|
|
932
|
+
state = next;
|
|
933
|
+
for (const fn of listeners) fn();
|
|
934
|
+
},
|
|
935
|
+
subscribe(fn) {
|
|
936
|
+
listeners.add(fn);
|
|
937
|
+
return () => listeners.delete(fn);
|
|
938
|
+
},
|
|
939
|
+
};
|
|
940
|
+
})();
|
|
941
|
+
|
|
942
|
+
const reloadSchedules = () => {
|
|
943
|
+
try {
|
|
944
|
+
const remote = ctx.remote && ctx.remote.schedule;
|
|
945
|
+
if (!remote || typeof remote.catalog !== "function") return;
|
|
946
|
+
Promise.resolve(remote.catalog())
|
|
947
|
+
.then((result) => {
|
|
948
|
+
const rows = Array.isArray(result) ? result : (result && Array.isArray(result.value) ? result.value : []);
|
|
949
|
+
scheduleStore.set(rows);
|
|
950
|
+
})
|
|
951
|
+
.catch((err) => console.error("[dsh-sidebar-sessions] schedule catalog failed", err));
|
|
952
|
+
} catch {}
|
|
953
|
+
};
|
|
954
|
+
|
|
955
|
+
ctx.effect(() => {
|
|
956
|
+
reloadSchedules();
|
|
957
|
+
const off = typeof ctx.on === "function" ? ctx.on("schedule/changed", reloadSchedules) : undefined;
|
|
958
|
+
return () => {
|
|
959
|
+
if (typeof off === "function") off();
|
|
960
|
+
};
|
|
961
|
+
}, "dsh-sidebar-sessions: schedules");
|
|
962
|
+
ctx.slots.inject("sidebar.workspaces", () =>
|
|
963
|
+
ctx.slots.register(
|
|
964
|
+
{
|
|
965
|
+
name: "sidebar.workspaces",
|
|
966
|
+
id: "dsh-sidebar-sessions",
|
|
967
|
+
priority: -2,
|
|
968
|
+
registrant: "dsh-sidebar-sessions",
|
|
969
|
+
inject: () => ({
|
|
970
|
+
open: (sessionId) => ctx.uiWorkspace.openSession(sessionId),
|
|
971
|
+
pinSession: (sessionId) => ctx.uiWorkspace.pinSession(sessionId),
|
|
972
|
+
unpinSession: (sessionId) => ctx.uiWorkspace.unpinSession(sessionId),
|
|
973
|
+
archiveSession: (sessionId) => ctx.uiWorkspace.archiveSession(sessionId),
|
|
974
|
+
unarchiveSession: (sessionId) => ctx.uiWorkspace.unarchiveSession(sessionId),
|
|
975
|
+
forkSession: (sessionId) => ctx.uiWorkspace.forkSession(sessionId),
|
|
976
|
+
pickDirectory: () => ctx.uiWorkspace.pickDirectory(),
|
|
977
|
+
openWorkspace: (workspaceId) => ctx.uiWorkspace.openWorkspace(workspaceId),
|
|
978
|
+
createWorkspace: (input) => ctx.workspaces.create(input),
|
|
979
|
+
insertSessionBefore: (accountId, sessionId, anchor) => ctx.workspaces.insertSessionBefore(accountId, sessionId, anchor),
|
|
980
|
+
useScheduleCatalog: () => useSyncExternalStore(scheduleStore.subscribe, scheduleStore.get, scheduleStore.get),
|
|
981
|
+
renameSession: (sessionId, title) =>
|
|
982
|
+
ctx.sessions.using(sessionId, { source: "workspaceOperation" }, (ref) =>
|
|
983
|
+
ref.binding.session.rename(title)
|
|
984
|
+
).then((result) => {
|
|
985
|
+
if (result?.ok === false) throw new Error(result.error?.message || "rename failed");
|
|
986
|
+
}),
|
|
987
|
+
}),
|
|
988
|
+
},
|
|
989
|
+
GuardedRegion
|
|
990
|
+
)
|
|
991
|
+
);
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
return { inject, apply };
|
|
995
|
+
},
|
|
996
|
+
});
|