dsh-session-relocate 0.1.0 → 0.2.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.
- package/README.md +17 -3
- package/docs/DESIGN.md +5 -0
- package/lib/client.js +659 -21
- package/package.json +1 -1
- package/src/plugin.js +91 -9
- package/src/relocate.js +256 -31
package/lib/client.js
CHANGED
|
@@ -27,6 +27,26 @@ window.__ModuleLoader__.load({
|
|
|
27
27
|
'.dshsm-bad{color:#ff453a}',
|
|
28
28
|
// 拖动时给工作区行加的高亮(官方行本身没有 drop 语义,所以这个类只由本插件加)
|
|
29
29
|
'.dshsm-drop{outline:2px solid #4c8dff;outline-offset:-2px;border-radius:6px}',
|
|
30
|
+
// 多选模式:行首勾选圈 + 底部操作条 + 目标工作区面板
|
|
31
|
+
'.dshsm-check{display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;margin-right:6px;border-radius:50%;border:1.5px solid var(--dsw-alias-border-l3,rgba(128,128,128,.5));background:0 0;flex:none}',
|
|
32
|
+
'.dshsm-check-on{border-color:#4c8dff;background:#4c8dff;box-shadow:inset 0 0 0 3px var(--dsw-alias-fill-elevated,#fff)}',
|
|
33
|
+
'.dshsm-bar{position:fixed;left:12px;bottom:12px;z-index:2147483600;display:flex;align-items:center;gap:10px;padding:10px 12px;border-radius:12px;border:1px solid var(--dsw-alias-border-l3,rgba(128,128,128,.3));background:var(--dsw-alias-fill-elevated,#1f232b);color:var(--dsw-alias-label-primary,#fff);box-shadow:0 8px 28px rgba(0,0,0,.28)}',
|
|
34
|
+
'.dshsm-bar-count{font-size:13px;white-space:nowrap}',
|
|
35
|
+
'.dshsm-bar-btn{appearance:none;min-height:30px;padding:0 12px;border-radius:8px;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.4));background:0 0;color:inherit;font:inherit;font-size:13px;cursor:pointer}',
|
|
36
|
+
'.dshsm-bar-btn:hover:not(:disabled){background:var(--dsw-alias-fill-secondary,rgba(127,127,127,.16))}',
|
|
37
|
+
'.dshsm-bar-btn:disabled{opacity:.5;cursor:default}',
|
|
38
|
+
'.dshsm-bar-primary{border-color:#4c8dff;background:#4c8dff;color:#fff}',
|
|
39
|
+
'.dshsm-picker-backdrop{position:fixed;inset:0;z-index:2147483602;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,.28)}',
|
|
40
|
+
'.dshsm-picker{width:min(440px,92vw);max-height:70vh;overflow:auto;display:flex;flex-direction:column;gap:10px;padding:16px;border-radius:14px;background:var(--dsw-alias-fill-elevated,#1f232b);color:var(--dsw-alias-label-primary,#fff);border:1px solid var(--dsw-alias-border-l3,rgba(128,128,128,.3));box-shadow:0 18px 48px rgba(0,0,0,.36)}',
|
|
41
|
+
'.dshsm-picker-title{font-size:14px;font-weight:600}',
|
|
42
|
+
'.dshsm-picker-list{display:flex;flex-direction:column;gap:6px}',
|
|
43
|
+
'.dshsm-picker-item{display:flex;flex-direction:column;gap:2px;width:100%;text-align:left;padding:8px 10px;border-radius:8px;border:1px solid transparent;background:0 0;color:inherit;font:inherit;font-size:13px;cursor:pointer}',
|
|
44
|
+
'.dshsm-picker-item:hover{background:var(--dsw-alias-fill-secondary,rgba(127,127,127,.16))}',
|
|
45
|
+
'.dshsm-picker-name{font-weight:500}',
|
|
46
|
+
'.dshsm-picker-path{font-size:11px;color:var(--dsw-alias-label-caption,#8b8b8b);overflow-wrap:anywhere}',
|
|
47
|
+
'.dshsm-picker-empty{font-size:12px;color:var(--dsw-alias-label-caption,#8b8b8b)}',
|
|
48
|
+
'.dshsm-picker-actions{display:flex;justify-content:flex-end}',
|
|
49
|
+
'.dshsm-picker-btn{appearance:none;min-height:30px;padding:0 12px;border-radius:8px;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.4));background:0 0;color:inherit;font:inherit;font-size:13px;cursor:pointer}',
|
|
30
50
|
].join('');
|
|
31
51
|
|
|
32
52
|
function ensureStyles() {
|
|
@@ -82,6 +102,18 @@ window.__ModuleLoader__.load({
|
|
|
82
102
|
needsReload: '(刷新页面后生效)',
|
|
83
103
|
dragMoved: '已移动到「{ws}」',
|
|
84
104
|
dragFailed: '移动失败:',
|
|
105
|
+
bulk: '多选',
|
|
106
|
+
bulkMove: '移动',
|
|
107
|
+
bulkCancel: '取消',
|
|
108
|
+
bulkSelected: '已选 {n} 个',
|
|
109
|
+
bulkPicking: '移动 {n} 个对话到:',
|
|
110
|
+
bulkProgress: '正在移动 {d}/{t}…',
|
|
111
|
+
bulkDone: '已移动 {ok} 个',
|
|
112
|
+
bulkPartial: '已移动 {ok} 个,{fail} 个失败',
|
|
113
|
+
bulkSkipped: '({n} 个本来就在目标工作区)',
|
|
114
|
+
bulkFailed: '批量移动失败:',
|
|
115
|
+
noteReleaseRetries: '(释放重试 {n} 次)',
|
|
116
|
+
noteSampled: '(大会话:抽样校验)',
|
|
85
117
|
};
|
|
86
118
|
var EN = {
|
|
87
119
|
open: 'Move to',
|
|
@@ -98,6 +130,18 @@ window.__ModuleLoader__.load({
|
|
|
98
130
|
needsReload: ' (reload the page to apply)',
|
|
99
131
|
dragMoved: 'Moved to “{ws}”',
|
|
100
132
|
dragFailed: 'Move failed: ',
|
|
133
|
+
bulk: 'Select multiple',
|
|
134
|
+
bulkMove: 'Move',
|
|
135
|
+
bulkCancel: 'Cancel',
|
|
136
|
+
bulkSelected: '{n} selected',
|
|
137
|
+
bulkPicking: 'Move {n} conversations to:',
|
|
138
|
+
bulkProgress: 'Moving {d}/{t}…',
|
|
139
|
+
bulkDone: 'Moved {ok}',
|
|
140
|
+
bulkPartial: 'Moved {ok}, {fail} failed',
|
|
141
|
+
bulkSkipped: ' ({n} already there)',
|
|
142
|
+
bulkFailed: 'Bulk move failed: ',
|
|
143
|
+
noteReleaseRetries: ' (release retried {n}×)',
|
|
144
|
+
noteSampled: ' (large session: sampled verify)',
|
|
101
145
|
};
|
|
102
146
|
|
|
103
147
|
function text() {
|
|
@@ -120,6 +164,21 @@ window.__ModuleLoader__.load({
|
|
|
120
164
|
return String(error);
|
|
121
165
|
}
|
|
122
166
|
|
|
167
|
+
/**
|
|
168
|
+
* 把回执里值得说一句的信息拼成后缀:释放重试了几次、大会话是不是只做了抽样校验。
|
|
169
|
+
* 没有要说的就返回空串。
|
|
170
|
+
*/
|
|
171
|
+
function receiptNotes(result) {
|
|
172
|
+
if (result === null || typeof result !== 'object') return '';
|
|
173
|
+
var strings = text();
|
|
174
|
+
var notes = [];
|
|
175
|
+
if (Number.isSafeInteger(result.releaseAttempts) && result.releaseAttempts > 1) {
|
|
176
|
+
notes.push(strings.noteReleaseRetries.replace('{n}', String(result.releaseAttempts)));
|
|
177
|
+
}
|
|
178
|
+
if (result.verification === 'sampled') notes.push(strings.noteSampled);
|
|
179
|
+
return notes.length === 0 ? '' : notes.join('');
|
|
180
|
+
}
|
|
181
|
+
|
|
123
182
|
/** 渲染一个菜单按钮。 */
|
|
124
183
|
function button(key, label, options) {
|
|
125
184
|
var props = Object.assign({ key: key, type: 'button', role: 'menuitem', className: 'dshsm-item' }, options || {});
|
|
@@ -182,7 +241,12 @@ window.__ModuleLoader__.load({
|
|
|
182
241
|
setState({ phase: 'error', message: (result !== null && typeof result === 'object' && result.message !== undefined) ? result.message : strings.failed });
|
|
183
242
|
return;
|
|
184
243
|
}
|
|
185
|
-
setState({
|
|
244
|
+
setState({
|
|
245
|
+
phase: 'done',
|
|
246
|
+
title: result.targetTitle !== undefined ? result.targetTitle : result.to,
|
|
247
|
+
applied: result.applied,
|
|
248
|
+
note: receiptNotes(result),
|
|
249
|
+
});
|
|
186
250
|
// 成功后排这一行会被工作区列表刷新带走;这里顺手关掉菜单更干净。
|
|
187
251
|
if (setMenuOpen !== null) setMenuOpen(false);
|
|
188
252
|
}, function (error) {
|
|
@@ -213,7 +277,8 @@ window.__ModuleLoader__.load({
|
|
|
213
277
|
}
|
|
214
278
|
if (state.phase === 'done') {
|
|
215
279
|
var suffix = state.applied === 'pending' ? strings.pending : (state.applied === 'live' ? '' : strings.needsReload);
|
|
216
|
-
|
|
280
|
+
var note = typeof state.note === 'string' ? state.note : '';
|
|
281
|
+
return button('done', strings.done + ' ' + String(state.title) + note + (suffix.length > 0 ? ';' + suffix : ''), { disabled: true });
|
|
217
282
|
}
|
|
218
283
|
// picking
|
|
219
284
|
var nodes = [button('caption', strings.pick + (state.targets.length === 0 ? ' ' + strings.noTargets : ''), { disabled: true })];
|
|
@@ -256,10 +321,12 @@ window.__ModuleLoader__.load({
|
|
|
256
321
|
|
|
257
322
|
var dragState = {
|
|
258
323
|
sessionId: null,
|
|
324
|
+
sessionIds: null,
|
|
259
325
|
sourceWorkspaceId: null,
|
|
260
326
|
targetSection: null,
|
|
261
|
-
|
|
327
|
+
hostSelected: false,
|
|
262
328
|
};
|
|
329
|
+
var dragInstallRefs = 0;
|
|
263
330
|
var toastNode = null;
|
|
264
331
|
var toastTimer = null;
|
|
265
332
|
|
|
@@ -341,7 +408,9 @@ window.__ModuleLoader__.load({
|
|
|
341
408
|
function resetDrag() {
|
|
342
409
|
clearHighlight();
|
|
343
410
|
dragState.sessionId = null;
|
|
411
|
+
dragState.sessionIds = null;
|
|
344
412
|
dragState.sourceWorkspaceId = null;
|
|
413
|
+
dragState.hostSelected = false;
|
|
345
414
|
}
|
|
346
415
|
|
|
347
416
|
/** 解析投放目标:没有正在拖的会话、或指针不在任何工作区分组里,就返回 null。 */
|
|
@@ -363,6 +432,26 @@ window.__ModuleLoader__.load({
|
|
|
363
432
|
return { sessionId: dragState.sessionId, targetWorkspaceId: group.workspaceId, section: group.section };
|
|
364
433
|
}
|
|
365
434
|
|
|
435
|
+
/**
|
|
436
|
+
* 当前多选中的会话 id。两个来源:
|
|
437
|
+
* - 我们自己的多选模式(bulkState);
|
|
438
|
+
* - dsh-delete-session 的多选底栏:它给选中行的复选框挂 `.dsdel-check-on`
|
|
439
|
+
* (那是它的 DOM 契约,我们只读、不改)。
|
|
440
|
+
* 没有多选时返回空数组。
|
|
441
|
+
*/
|
|
442
|
+
function selectedIdsForDrag() {
|
|
443
|
+
if (bulkState.selecting === true) return bulkSelectedIds();
|
|
444
|
+
if (typeof document === 'undefined' || typeof document.querySelectorAll !== 'function') return [];
|
|
445
|
+
var marks = document.querySelectorAll('.dsdel-check-on');
|
|
446
|
+
var ids = [];
|
|
447
|
+
for (var i = 0; marks !== null && marks !== undefined && i < marks.length; i += 1) {
|
|
448
|
+
var row = nearestRow(marks[i]);
|
|
449
|
+
var id = row === null ? null : sessionIdFromRow(row);
|
|
450
|
+
if (id !== null && ids.indexOf(id) < 0) ids.push(id);
|
|
451
|
+
}
|
|
452
|
+
return ids;
|
|
453
|
+
}
|
|
454
|
+
|
|
366
455
|
function onDragStart(event) {
|
|
367
456
|
var row = nearestRow(event !== null && event !== undefined ? event.target : null);
|
|
368
457
|
if (row === null || typeof row.getAttribute !== 'function') return;
|
|
@@ -372,22 +461,22 @@ window.__ModuleLoader__.load({
|
|
|
372
461
|
if (sessionId.length === 0) return;
|
|
373
462
|
resetDrag();
|
|
374
463
|
dragState.sessionId = sessionId;
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
464
|
+
// 多选拖动:宿主底栏(或我们自己的多选)里选中的整批一起搬。
|
|
465
|
+
var selectedIds = selectedIdsForDrag();
|
|
466
|
+
var multi = selectedIds.length > 1 && selectedIds.indexOf(sessionId) >= 0;
|
|
467
|
+
dragState.sessionIds = multi ? selectedIds : [sessionId];
|
|
468
|
+
dragState.hostSelected = bulkState.selecting !== true && selectedIds.indexOf(sessionId) >= 0;
|
|
469
|
+
// 源工作区**每次**从 DOM 现读(同步、稳):拖起来的那一行就在它自己的分组里。
|
|
470
|
+
// 不能跨拖动缓存 —— 会话可能刚被搬走,旧分组已经不是它的家了。
|
|
380
471
|
// 读不到再问主机;还是拿不到也无所谓 —— 服务端会用 already-there 兜住。
|
|
381
472
|
var own = workspaceGroupOf(row);
|
|
382
473
|
if (own !== null) {
|
|
383
|
-
dragState.sourceBySession[sessionId] = own.workspaceId;
|
|
384
474
|
dragState.sourceWorkspaceId = own.workspaceId;
|
|
385
475
|
return;
|
|
386
476
|
}
|
|
387
477
|
post('/describe', { sessionId: sessionId }).then(function (result) {
|
|
388
478
|
var session = result !== null && result !== undefined ? result.session : null;
|
|
389
479
|
if (session === null || session === undefined) return;
|
|
390
|
-
dragState.sourceBySession[sessionId] = session.currentWorkspaceId;
|
|
391
480
|
if (dragState.sessionId === sessionId) dragState.sourceWorkspaceId = session.currentWorkspaceId;
|
|
392
481
|
}, function () { /* 探测失败就让服务端兜 */ });
|
|
393
482
|
}
|
|
@@ -421,8 +510,11 @@ window.__ModuleLoader__.load({
|
|
|
421
510
|
if (typeof event.preventDefault === 'function') event.preventDefault();
|
|
422
511
|
var sessionId = drop.sessionId;
|
|
423
512
|
var targetWorkspaceId = drop.targetWorkspaceId;
|
|
513
|
+
var ids = dragState.sessionIds !== null && dragState.sessionIds.length > 1 ? dragState.sessionIds : [sessionId];
|
|
514
|
+
var hostSelected = dragState.hostSelected === true;
|
|
424
515
|
resetDrag();
|
|
425
|
-
|
|
516
|
+
if (ids.length > 1) moveManyByDrag(ids, targetWorkspaceId, hostSelected);
|
|
517
|
+
else moveByDrag(sessionId, targetWorkspaceId, hostSelected);
|
|
426
518
|
}
|
|
427
519
|
|
|
428
520
|
function onDragEnd() {
|
|
@@ -442,14 +534,16 @@ window.__ModuleLoader__.load({
|
|
|
442
534
|
}
|
|
443
535
|
|
|
444
536
|
/** 拖完立刻搬(不再问一次;搬错了再拖回去就行)。 */
|
|
445
|
-
function moveByDrag(sessionId, targetWorkspaceId) {
|
|
537
|
+
function moveByDrag(sessionId, targetWorkspaceId, hostSelected) {
|
|
446
538
|
var strings = text();
|
|
447
539
|
toast(strings.moving);
|
|
448
540
|
post('/move', { sessionId: sessionId, targetWorkspaceId: targetWorkspaceId }).then(function (result) {
|
|
449
541
|
if (result !== null && result !== undefined && result.ok === true) {
|
|
450
542
|
var title = result.targetTitle;
|
|
451
543
|
var label = typeof title === 'string' && title.length > 0 ? title : targetWorkspaceId;
|
|
452
|
-
toast(strings.dragMoved.replace('{ws}', label));
|
|
544
|
+
toast(strings.dragMoved.replace('{ws}', label) + receiptNotes(result));
|
|
545
|
+
if (bulkState.selecting === true) exitBulk();
|
|
546
|
+
else if (hostSelected === true) dismissHostSelection();
|
|
453
547
|
return;
|
|
454
548
|
}
|
|
455
549
|
var message = result !== null && result !== undefined && typeof result.message === 'string' ? result.message : '';
|
|
@@ -459,6 +553,41 @@ window.__ModuleLoader__.load({
|
|
|
459
553
|
});
|
|
460
554
|
}
|
|
461
555
|
|
|
556
|
+
/** 多选拖动:整批搬到同一个目标(目标就是松手的分组,不再弹选择面板)。 */
|
|
557
|
+
function moveManyByDrag(ids, targetWorkspaceId, hostSelected) {
|
|
558
|
+
var strings = text();
|
|
559
|
+
toast(strings.moving);
|
|
560
|
+
runBulkMove(ids, targetWorkspaceId, {
|
|
561
|
+
onProgress: function (done, total) {
|
|
562
|
+
toast(strings.bulkProgress.replace('{d}', String(done)).replace('{t}', String(total)));
|
|
563
|
+
},
|
|
564
|
+
}).then(function (result) {
|
|
565
|
+
var summary = result.failed === 0
|
|
566
|
+
? strings.bulkDone.replace('{ok}', String(result.moved))
|
|
567
|
+
: strings.bulkPartial.replace('{ok}', String(result.moved)).replace('{fail}', String(result.failed));
|
|
568
|
+
if (result.skipped > 0) summary += strings.bulkSkipped.replace('{n}', String(result.skipped));
|
|
569
|
+
summary += receiptNotes(result);
|
|
570
|
+
toast(summary);
|
|
571
|
+
if (bulkState.selecting === true) exitBulk();
|
|
572
|
+
else if (hostSelected === true) dismissHostSelection();
|
|
573
|
+
refreshSidebar();
|
|
574
|
+
}, function (error) {
|
|
575
|
+
toast(strings.bulkFailed + errorText(error));
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* 收起宿主(dsh-delete-session)的多选态:它监听 document 的 Escape(capture),
|
|
581
|
+
* 我们只发一个 Escape,不碰它的内部状态。
|
|
582
|
+
*/
|
|
583
|
+
function dismissHostSelection() {
|
|
584
|
+
if (typeof document === 'undefined' || typeof document.dispatchEvent !== 'function') return;
|
|
585
|
+
var event = typeof KeyboardEvent === 'function'
|
|
586
|
+
? new KeyboardEvent('keydown', { key: 'Escape', bubbles: true })
|
|
587
|
+
: { type: 'keydown', key: 'Escape', bubbles: true, stopPropagation: function () {}, preventDefault: function () {} };
|
|
588
|
+
try { document.dispatchEvent(event); } catch (error) { /* ignore */ }
|
|
589
|
+
}
|
|
590
|
+
|
|
462
591
|
/** 自绘 toast(不依赖官方是否暴露通知服务)。 */
|
|
463
592
|
function toast(message) {
|
|
464
593
|
if (typeof document === 'undefined' || document.body === undefined || document.body === null) return;
|
|
@@ -487,18 +616,32 @@ window.__ModuleLoader__.load({
|
|
|
487
616
|
return true;
|
|
488
617
|
}
|
|
489
618
|
|
|
490
|
-
/**
|
|
619
|
+
/**
|
|
620
|
+
* 挂上拖动搬移,返回卸载函数。环境没有 document 就整个不启用。
|
|
621
|
+
*
|
|
622
|
+
* 引用计数:客户端可能被重复 apply(热重载 / 换 fiber)。DOM 里同一个监听函数
|
|
623
|
+
* 重复 add 是 no-op,但 remove 一次就真删掉了 —— 不计数的话,旧的 disposer 一跑
|
|
624
|
+
* 就会把还在用的监听整套撤掉(菜单还在、拖动却全没了)。
|
|
625
|
+
*/
|
|
491
626
|
function installDrag() {
|
|
492
627
|
if (typeof document === 'undefined' || typeof document.addEventListener !== 'function') {
|
|
493
628
|
return function () {};
|
|
494
629
|
}
|
|
495
630
|
var capture = true; // 捕获阶段先于官方(React)的处理
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
631
|
+
if (dragInstallRefs === 0) {
|
|
632
|
+
document.addEventListener('dragstart', onDragStart, capture);
|
|
633
|
+
document.addEventListener('dragover', onDragOver, capture);
|
|
634
|
+
document.addEventListener('drop', onDrop, capture);
|
|
635
|
+
document.addEventListener('dragend', onDragEnd, capture);
|
|
636
|
+
document.addEventListener('dragleave', onDragLeave, capture);
|
|
637
|
+
}
|
|
638
|
+
dragInstallRefs += 1;
|
|
639
|
+
var disposed = false;
|
|
501
640
|
return function () {
|
|
641
|
+
if (disposed) return;
|
|
642
|
+
disposed = true;
|
|
643
|
+
dragInstallRefs -= 1;
|
|
644
|
+
if (dragInstallRefs > 0) return;
|
|
502
645
|
document.removeEventListener('dragstart', onDragStart, capture);
|
|
503
646
|
document.removeEventListener('dragover', onDragOver, capture);
|
|
504
647
|
document.removeEventListener('drop', onDrop, capture);
|
|
@@ -508,11 +651,480 @@ window.__ModuleLoader__.load({
|
|
|
508
651
|
};
|
|
509
652
|
}
|
|
510
653
|
|
|
654
|
+
// ── 批量搬移(多选)───────────────────────────────────────────────────────
|
|
655
|
+
//
|
|
656
|
+
// 两条路,靠 dsh-delete-session 显式暴露的能力位决定走哪条:
|
|
657
|
+
// A. 它装了且支持批量动作(window.__DSH_DELETE_SESSION__.supportsBulkMove)→ 它那根
|
|
658
|
+
// 底栏上出现「移动」,它调我们暴露的 window.__DSH_SESSION_RELOCATE__.moveSelection(ids, hooks)。
|
|
659
|
+
// B. 只有我们 → 菜单里多一项「多选」,自己画勾选圈 + 底栏(已选 N / 取消 / 移动)。
|
|
660
|
+
// 判断只认能力位、不猜 DOM:它没给能力位就按 B 走(宁可多一个入口,也不静默丢功能)。
|
|
661
|
+
var CHECK_CLASS = 'dshsm-check';
|
|
662
|
+
var CHECK_ON_CLASS = 'dshsm-check-on';
|
|
663
|
+
var bulkState = { selecting: false, selected: {}, bar: null, countNode: null, moveNode: null, raf: null, moveSelectionFn: null };
|
|
664
|
+
|
|
665
|
+
/** 宿主(dsh-delete-session)是否支持把「移动」放进它那根底栏。 */
|
|
666
|
+
function hostSupportsBulkMove() {
|
|
667
|
+
var host = globalThis.__DSH_DELETE_SESSION__;
|
|
668
|
+
return host !== null && typeof host === 'object' && host.supportsBulkMove === true;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/** 搬完让侧边栏重新取一次(官方一般会因会话事件自己刷新,这里补一次兜底)。 */
|
|
672
|
+
function refreshSidebar() {
|
|
673
|
+
try { globalThis.dispatchEvent(new Event('resize')); } catch (error) { /* 没有 Event 的环境就算了 */ }
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* 纯逻辑:串行把一批会话搬到同一个目标工作区。不碰 DOM,方便单测。
|
|
678
|
+
*
|
|
679
|
+
* 两段式:先逐条 `/move` + `deferRegistry`(每条只做文件事务,进度能实时显示),
|
|
680
|
+
* 最后一次性 `/move-commit` 把整批归属写进注册表 —— N 条会话只付 2 次注册表写,
|
|
681
|
+
* 而不是 2N 次(实测这是单条搬移里最贵的部分)。
|
|
682
|
+
*/
|
|
683
|
+
function runBulkMove(sessionIds, targetWorkspaceId, hooks) {
|
|
684
|
+
var ids = Array.isArray(sessionIds) ? sessionIds.filter(function (id) { return typeof id === 'string' && id.length > 0; }) : [];
|
|
685
|
+
if (ids.length === 0) return Promise.resolve({ canceled: false, moved: 0, failed: 0, skipped: 0, total: 0, results: [] });
|
|
686
|
+
// 主机支不支持两段式,问一次 /status 并缓存:不支持就退回逐条单发(老主机照常能用)。
|
|
687
|
+
return hostSupportsDefer().then(function (twoPhase) {
|
|
688
|
+
return runBulkMoveInner(ids, targetWorkspaceId, hooks, twoPhase);
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
var bulkCapability = null;
|
|
693
|
+
function hostSupportsDefer() {
|
|
694
|
+
if (bulkCapability !== null) return Promise.resolve(bulkCapability);
|
|
695
|
+
return post('/status').then(function (result) {
|
|
696
|
+
bulkCapability = result !== null && typeof result === 'object' && result.bulkDefer === true;
|
|
697
|
+
return bulkCapability;
|
|
698
|
+
}, function () {
|
|
699
|
+
bulkCapability = false;
|
|
700
|
+
return false;
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
function runBulkMoveInner(ids, targetWorkspaceId, hooks, twoPhase) {
|
|
705
|
+
var byId = {};
|
|
706
|
+
var deferred = [];
|
|
707
|
+
var moved = 0;
|
|
708
|
+
var failed = 0;
|
|
709
|
+
var skipped = 0;
|
|
710
|
+
var sampled = false;
|
|
711
|
+
var releaseRetries = 0;
|
|
712
|
+
function record(entry) {
|
|
713
|
+
byId[entry.sessionId] = entry;
|
|
714
|
+
}
|
|
715
|
+
function finish() {
|
|
716
|
+
// results 按传入顺序输出(commit 会把成功项推到后面,这里统一回填)。
|
|
717
|
+
var ordered = [];
|
|
718
|
+
for (var i = 0; i < ids.length; i += 1) if (byId[ids[i]] !== undefined) ordered.push(byId[ids[i]]);
|
|
719
|
+
return {
|
|
720
|
+
canceled: false,
|
|
721
|
+
moved: moved,
|
|
722
|
+
failed: failed,
|
|
723
|
+
skipped: skipped,
|
|
724
|
+
total: ids.length,
|
|
725
|
+
results: ordered,
|
|
726
|
+
verification: sampled ? 'sampled' : 'full',
|
|
727
|
+
releaseAttempts: releaseRetries,
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
/** 第二段:一次提交,把 defer 过的归属一次性写进注册表。 */
|
|
731
|
+
function commit(pending) {
|
|
732
|
+
return post('/move-commit', { sessionIds: pending }).then(function (result) {
|
|
733
|
+
var okCommit = result !== null && typeof result === 'object' && result.ok === true;
|
|
734
|
+
var committed = result !== null && typeof result === 'object' && Array.isArray(result.results) ? result.results : [];
|
|
735
|
+
var byId = {};
|
|
736
|
+
for (var i = 0; i < committed.length; i += 1) {
|
|
737
|
+
var entry = committed[i];
|
|
738
|
+
if (entry !== null && typeof entry === 'object' && typeof entry.sessionId === 'string') byId[entry.sessionId] = entry;
|
|
739
|
+
}
|
|
740
|
+
for (var j = 0; j < pending.length; j += 1) {
|
|
741
|
+
var id = pending[j];
|
|
742
|
+
var one = byId[id];
|
|
743
|
+
if (okCommit && one !== undefined && one.status === 'moved') {
|
|
744
|
+
moved += 1;
|
|
745
|
+
record({ sessionId: id, status: 'moved', targetWorkspaceId: targetWorkspaceId });
|
|
746
|
+
} else {
|
|
747
|
+
failed += 1;
|
|
748
|
+
record({
|
|
749
|
+
sessionId: id,
|
|
750
|
+
status: 'failed',
|
|
751
|
+
code: one !== undefined && typeof one.status === 'string' ? one.status : 'commit-failed',
|
|
752
|
+
message: one !== undefined && typeof one.message === 'string'
|
|
753
|
+
? one.message
|
|
754
|
+
: (result !== null && typeof result === 'object' && typeof result.message === 'string' ? result.message : ''),
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
return finish();
|
|
759
|
+
}, function (error) {
|
|
760
|
+
for (var k = 0; k < pending.length; k += 1) {
|
|
761
|
+
failed += 1;
|
|
762
|
+
record({ sessionId: pending[k], status: 'failed', code: 'commit-failed', message: errorText(error) });
|
|
763
|
+
}
|
|
764
|
+
return finish();
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
function step(index) {
|
|
768
|
+
if (index >= ids.length) return twoPhase && deferred.length > 0 ? commit(deferred) : Promise.resolve(finish());
|
|
769
|
+
var sessionId = ids[index];
|
|
770
|
+
var done = post('/move', { sessionId: sessionId, targetWorkspaceId: targetWorkspaceId, deferRegistry: twoPhase }).then(function (result) {
|
|
771
|
+
if (result !== null && typeof result === 'object' && result.ok === true) {
|
|
772
|
+
if (result.verification === 'sampled') sampled = true;
|
|
773
|
+
if (Number.isSafeInteger(result.releaseAttempts) && result.releaseAttempts > releaseRetries) releaseRetries = result.releaseAttempts;
|
|
774
|
+
if (twoPhase) deferred.push(sessionId);
|
|
775
|
+
else {
|
|
776
|
+
moved += 1;
|
|
777
|
+
record({ sessionId: sessionId, status: 'moved', targetWorkspaceId: targetWorkspaceId });
|
|
778
|
+
}
|
|
779
|
+
} else if (result !== null && typeof result === 'object' && result.code === 'already-there') {
|
|
780
|
+
skipped += 1;
|
|
781
|
+
record({ sessionId: sessionId, status: 'skipped', code: 'already-there', message: typeof result.message === 'string' ? result.message : '' });
|
|
782
|
+
} else {
|
|
783
|
+
failed += 1;
|
|
784
|
+
record({
|
|
785
|
+
sessionId: sessionId,
|
|
786
|
+
status: 'failed',
|
|
787
|
+
code: result !== null && typeof result === 'object' && typeof result.code === 'string' ? result.code : 'failed',
|
|
788
|
+
message: result !== null && typeof result === 'object' && typeof result.message === 'string' ? result.message : '',
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
}, function (error) {
|
|
792
|
+
failed += 1;
|
|
793
|
+
record({ sessionId: sessionId, status: 'failed', code: 'network', message: errorText(error) });
|
|
794
|
+
});
|
|
795
|
+
return done.then(function () {
|
|
796
|
+
if (hooks !== null && hooks !== undefined && typeof hooks.onProgress === 'function') {
|
|
797
|
+
try { hooks.onProgress(index + 1, ids.length); } catch (error) { /* 回调抛错不能打断批量 */ }
|
|
798
|
+
}
|
|
799
|
+
return step(index + 1);
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
return step(0);
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
/** 弹一个居中的目标工作区面板;取消返回 { canceled: true }。 */
|
|
806
|
+
function pickBulkTarget(count) {
|
|
807
|
+
return new Promise(function (resolve) {
|
|
808
|
+
var strings = text();
|
|
809
|
+
var backdrop = document.createElement('div');
|
|
810
|
+
backdrop.className = 'dshsm-picker-backdrop';
|
|
811
|
+
var panel = document.createElement('div');
|
|
812
|
+
panel.className = 'dshsm-picker';
|
|
813
|
+
panel.setAttribute('role', 'dialog');
|
|
814
|
+
var title = document.createElement('div');
|
|
815
|
+
title.className = 'dshsm-picker-title';
|
|
816
|
+
title.textContent = strings.bulkPicking.replace('{n}', String(count));
|
|
817
|
+
panel.appendChild(title);
|
|
818
|
+
var list = document.createElement('div');
|
|
819
|
+
list.className = 'dshsm-picker-list';
|
|
820
|
+
panel.appendChild(list);
|
|
821
|
+
var actions = document.createElement('div');
|
|
822
|
+
actions.className = 'dshsm-picker-actions';
|
|
823
|
+
var cancel = document.createElement('button');
|
|
824
|
+
cancel.type = 'button';
|
|
825
|
+
cancel.className = 'dshsm-picker-btn';
|
|
826
|
+
cancel.textContent = strings.bulkCancel;
|
|
827
|
+
actions.appendChild(cancel);
|
|
828
|
+
panel.appendChild(actions);
|
|
829
|
+
backdrop.appendChild(panel);
|
|
830
|
+
document.body.appendChild(backdrop);
|
|
831
|
+
|
|
832
|
+
var settled = false;
|
|
833
|
+
function done(value) {
|
|
834
|
+
if (settled) return;
|
|
835
|
+
settled = true;
|
|
836
|
+
if (typeof backdrop.remove === 'function') backdrop.remove();
|
|
837
|
+
document.removeEventListener('keydown', onKey, true);
|
|
838
|
+
resolve(value);
|
|
839
|
+
}
|
|
840
|
+
function onKey(event) {
|
|
841
|
+
if (event.key !== 'Escape') return;
|
|
842
|
+
event.stopPropagation();
|
|
843
|
+
done({ canceled: true });
|
|
844
|
+
}
|
|
845
|
+
cancel.addEventListener('click', function () { done({ canceled: true }); });
|
|
846
|
+
backdrop.addEventListener('mousedown', function (event) { if (event.target === backdrop) done({ canceled: true }); });
|
|
847
|
+
document.addEventListener('keydown', onKey, true);
|
|
848
|
+
|
|
849
|
+
var loading = document.createElement('div');
|
|
850
|
+
loading.className = 'dshsm-picker-empty';
|
|
851
|
+
loading.textContent = strings.loading;
|
|
852
|
+
list.appendChild(loading);
|
|
853
|
+
|
|
854
|
+
post('/describe', {}).then(function (result) {
|
|
855
|
+
if (settled) return;
|
|
856
|
+
if (typeof list.removeChild === 'function') list.removeChild(loading);
|
|
857
|
+
var spaces = result !== null && typeof result === 'object' && Array.isArray(result.workspaces) ? result.workspaces : [];
|
|
858
|
+
if (spaces.length === 0) {
|
|
859
|
+
var empty = document.createElement('div');
|
|
860
|
+
empty.className = 'dshsm-picker-empty';
|
|
861
|
+
empty.textContent = strings.noTargets;
|
|
862
|
+
list.appendChild(empty);
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
for (var i = 0; i < spaces.length; i += 1) {
|
|
866
|
+
(function (workspace) {
|
|
867
|
+
var item = document.createElement('button');
|
|
868
|
+
item.type = 'button';
|
|
869
|
+
item.className = 'dshsm-picker-item';
|
|
870
|
+
var name = document.createElement('span');
|
|
871
|
+
name.className = 'dshsm-picker-name';
|
|
872
|
+
name.textContent = workspace.title;
|
|
873
|
+
item.appendChild(name);
|
|
874
|
+
if (typeof workspace.path === 'string' && workspace.path.length > 0) {
|
|
875
|
+
var path = document.createElement('span');
|
|
876
|
+
path.className = 'dshsm-picker-path';
|
|
877
|
+
path.textContent = workspace.path;
|
|
878
|
+
item.appendChild(path);
|
|
879
|
+
}
|
|
880
|
+
item.addEventListener('click', function () { done({ workspace: workspace }); });
|
|
881
|
+
list.appendChild(item);
|
|
882
|
+
})(spaces[i]);
|
|
883
|
+
}
|
|
884
|
+
}, function (error) {
|
|
885
|
+
if (settled) return;
|
|
886
|
+
if (typeof list.removeChild === 'function') list.removeChild(loading);
|
|
887
|
+
var failedNode = document.createElement('div');
|
|
888
|
+
failedNode.className = 'dshsm-picker-empty dshsm-bad';
|
|
889
|
+
failedNode.textContent = strings.failed + ':' + errorText(error);
|
|
890
|
+
list.appendChild(failedNode);
|
|
891
|
+
});
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
/**
|
|
896
|
+
* 对外契约(dsh-delete-session 会用):选目标 → 串行搬 → 汇总。
|
|
897
|
+
* 返回 { canceled?, moved, failed, skipped, total, results[] };
|
|
898
|
+
* hooks.onProgress(done, total) 的 done = 已处理条数(成功 + 失败 + 跳过)。
|
|
899
|
+
*/
|
|
900
|
+
function moveSelection(sessionIds, hooks) {
|
|
901
|
+
var ids = Array.isArray(sessionIds) ? sessionIds.filter(function (id) { return typeof id === 'string' && id.length > 0; }) : [];
|
|
902
|
+
if (ids.length === 0) {
|
|
903
|
+
return Promise.resolve({ canceled: false, moved: 0, failed: 0, skipped: 0, total: 0, results: [] });
|
|
904
|
+
}
|
|
905
|
+
return pickBulkTarget(ids.length).then(function (picked) {
|
|
906
|
+
if (picked === null || picked === undefined || picked.workspace === undefined) {
|
|
907
|
+
return { canceled: true, moved: 0, failed: 0, skipped: 0, total: ids.length, results: [] };
|
|
908
|
+
}
|
|
909
|
+
return runBulkMove(ids, picked.workspace.id, hooks);
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
/** 行 → 会话 id(只认会话行;工作区行不是会话)。 */
|
|
914
|
+
function sessionIdFromRow(row) {
|
|
915
|
+
var node = row;
|
|
916
|
+
for (var depth = 0; depth < ROW_WALK_LIMIT && node !== null && node !== undefined; depth += 1) {
|
|
917
|
+
if (typeof node.getAttribute === 'function') {
|
|
918
|
+
var key = node.getAttribute(ROW_KEY_ATTR);
|
|
919
|
+
if (typeof key === 'string' && key.indexOf(SESSION_PREFIX) === 0 && key.length > SESSION_PREFIX.length) {
|
|
920
|
+
return key.slice(SESSION_PREFIX.length);
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
node = node.parentElement;
|
|
924
|
+
}
|
|
925
|
+
return null;
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
function bulkDecorate() {
|
|
929
|
+
bulkState.raf = null;
|
|
930
|
+
if (typeof document === 'undefined' || typeof document.querySelectorAll !== 'function') return;
|
|
931
|
+
var rows = Array.prototype.slice.call(document.querySelectorAll('[role="treeitem"]'));
|
|
932
|
+
for (var i = 0; i < rows.length; i += 1) {
|
|
933
|
+
var row = rows[i];
|
|
934
|
+
var id = sessionIdFromRow(row);
|
|
935
|
+
if (id === null) continue;
|
|
936
|
+
var check = typeof row.querySelector === 'function' ? row.querySelector(':scope > .' + CHECK_CLASS) : null;
|
|
937
|
+
if (bulkState.selecting !== true) {
|
|
938
|
+
if (check !== null && typeof check.remove === 'function') check.remove();
|
|
939
|
+
continue;
|
|
940
|
+
}
|
|
941
|
+
if (check === null) {
|
|
942
|
+
check = document.createElement('span');
|
|
943
|
+
check.className = CHECK_CLASS;
|
|
944
|
+
check.setAttribute('aria-hidden', 'true');
|
|
945
|
+
row.insertBefore(check, row.firstChild);
|
|
946
|
+
}
|
|
947
|
+
if (bulkState.selected[id] === true) check.classList.add(CHECK_ON_CLASS);
|
|
948
|
+
else check.classList.remove(CHECK_ON_CLASS);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
function scheduleBulkDecorate() {
|
|
953
|
+
if (bulkState.raf !== null) return;
|
|
954
|
+
bulkState.raf = typeof globalThis.requestAnimationFrame === 'function'
|
|
955
|
+
? globalThis.requestAnimationFrame(bulkDecorate)
|
|
956
|
+
: setTimeout(bulkDecorate, 16);
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
function bulkSelectedIds() {
|
|
960
|
+
var ids = [];
|
|
961
|
+
for (var key in bulkState.selected) if (bulkState.selected[key] === true) ids.push(key);
|
|
962
|
+
return ids;
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
function bulkUpdateBar() {
|
|
966
|
+
var count = bulkSelectedIds().length;
|
|
967
|
+
if (bulkState.countNode !== null) bulkState.countNode.textContent = text().bulkSelected.replace('{n}', String(count));
|
|
968
|
+
if (bulkState.moveNode !== null) bulkState.moveNode.disabled = count === 0;
|
|
969
|
+
return count;
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
function buildBulkBar() {
|
|
973
|
+
var strings = text();
|
|
974
|
+
var bar = document.createElement('div');
|
|
975
|
+
bar.className = 'dshsm-bar';
|
|
976
|
+
bar.setAttribute('role', 'toolbar');
|
|
977
|
+
var count = document.createElement('span');
|
|
978
|
+
count.className = 'dshsm-bar-count';
|
|
979
|
+
var cancel = document.createElement('button');
|
|
980
|
+
cancel.type = 'button';
|
|
981
|
+
cancel.className = 'dshsm-bar-btn';
|
|
982
|
+
cancel.textContent = strings.bulkCancel;
|
|
983
|
+
cancel.addEventListener('click', function (event) { if (event) event.stopPropagation(); exitBulk(); });
|
|
984
|
+
var move = document.createElement('button');
|
|
985
|
+
move.type = 'button';
|
|
986
|
+
move.className = 'dshsm-bar-btn dshsm-bar-primary';
|
|
987
|
+
move.textContent = strings.bulkMove;
|
|
988
|
+
move.disabled = true;
|
|
989
|
+
move.addEventListener('click', function (event) {
|
|
990
|
+
if (event) event.stopPropagation();
|
|
991
|
+
bulkMoveSelected();
|
|
992
|
+
});
|
|
993
|
+
bar.appendChild(count);
|
|
994
|
+
bar.appendChild(cancel);
|
|
995
|
+
bar.appendChild(move);
|
|
996
|
+
document.body.appendChild(bar);
|
|
997
|
+
bulkState.bar = bar;
|
|
998
|
+
bulkState.countNode = count;
|
|
999
|
+
bulkState.moveNode = move;
|
|
1000
|
+
bulkUpdateBar();
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
function bulkMoveSelected() {
|
|
1004
|
+
var strings = text();
|
|
1005
|
+
var ids = bulkSelectedIds();
|
|
1006
|
+
if (ids.length === 0) return;
|
|
1007
|
+
if (bulkState.moveNode !== null) bulkState.moveNode.disabled = true;
|
|
1008
|
+
var run = typeof bulkState.moveSelectionFn === 'function' ? bulkState.moveSelectionFn : moveSelection;
|
|
1009
|
+
run(ids, {
|
|
1010
|
+
onProgress: function (done, total) {
|
|
1011
|
+
if (bulkState.countNode !== null) {
|
|
1012
|
+
bulkState.countNode.textContent = strings.bulkProgress.replace('{d}', String(done)).replace('{t}', String(total));
|
|
1013
|
+
}
|
|
1014
|
+
},
|
|
1015
|
+
}).then(function (result) {
|
|
1016
|
+
if (result.canceled === true) { bulkUpdateBar(); return; }
|
|
1017
|
+
var summary = result.failed === 0
|
|
1018
|
+
? strings.bulkDone.replace('{ok}', String(result.moved))
|
|
1019
|
+
: strings.bulkPartial.replace('{ok}', String(result.moved)).replace('{fail}', String(result.failed));
|
|
1020
|
+
if (result.skipped > 0) summary += strings.bulkSkipped.replace('{n}', String(result.skipped));
|
|
1021
|
+
summary += receiptNotes(result);
|
|
1022
|
+
toast(summary);
|
|
1023
|
+
exitBulk();
|
|
1024
|
+
refreshSidebar();
|
|
1025
|
+
}, function (error) {
|
|
1026
|
+
toast(strings.bulkFailed + errorText(error));
|
|
1027
|
+
bulkUpdateBar();
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
function onBulkRowClick(event) {
|
|
1032
|
+
if (bulkState.selecting !== true) return;
|
|
1033
|
+
var target = event !== null && event !== undefined ? event.target : null;
|
|
1034
|
+
var row = target !== null && target !== undefined && typeof target.closest === 'function' ? target.closest('[role="treeitem"]') : null;
|
|
1035
|
+
if (row === null || row === undefined) return;
|
|
1036
|
+
var id = sessionIdFromRow(row);
|
|
1037
|
+
if (id === null) return;
|
|
1038
|
+
if (typeof event.preventDefault === 'function') event.preventDefault();
|
|
1039
|
+
if (typeof event.stopPropagation === 'function') event.stopPropagation();
|
|
1040
|
+
if (bulkState.selected[id] === true) delete bulkState.selected[id];
|
|
1041
|
+
else bulkState.selected[id] = true;
|
|
1042
|
+
scheduleBulkDecorate();
|
|
1043
|
+
bulkUpdateBar();
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
function onBulkKeydown(event) {
|
|
1047
|
+
if (bulkState.selecting !== true) return;
|
|
1048
|
+
if (event.key !== 'Escape') return;
|
|
1049
|
+
event.stopPropagation();
|
|
1050
|
+
exitBulk();
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
function enterBulk() {
|
|
1054
|
+
if (typeof document === 'undefined' || document.body === undefined || document.body === null) return;
|
|
1055
|
+
if (bulkState.selecting === true) return;
|
|
1056
|
+
bulkState.selecting = true;
|
|
1057
|
+
bulkState.selected = {};
|
|
1058
|
+
buildBulkBar();
|
|
1059
|
+
document.addEventListener('click', onBulkRowClick, true);
|
|
1060
|
+
document.addEventListener('keydown', onBulkKeydown, true);
|
|
1061
|
+
scheduleBulkDecorate();
|
|
1062
|
+
// 关掉菜单(和官方一样:在别处点一下)
|
|
1063
|
+
try { document.dispatchEvent(new MouseEvent('mousedown', { bubbles: true })); } catch (error) { /* ignore */ }
|
|
1064
|
+
try { document.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true })); } catch (error) { /* ignore */ }
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
function exitBulk() {
|
|
1068
|
+
if (bulkState.selecting !== true) return;
|
|
1069
|
+
bulkState.selecting = false;
|
|
1070
|
+
bulkState.selected = {};
|
|
1071
|
+
if (bulkState.raf !== null) {
|
|
1072
|
+
try {
|
|
1073
|
+
if (typeof globalThis.cancelAnimationFrame === 'function') globalThis.cancelAnimationFrame(bulkState.raf);
|
|
1074
|
+
else clearTimeout(bulkState.raf);
|
|
1075
|
+
} catch (error) { /* ignore */ }
|
|
1076
|
+
bulkState.raf = null;
|
|
1077
|
+
}
|
|
1078
|
+
if (typeof document !== 'undefined') {
|
|
1079
|
+
document.removeEventListener('click', onBulkRowClick, true);
|
|
1080
|
+
document.removeEventListener('keydown', onBulkKeydown, true);
|
|
1081
|
+
}
|
|
1082
|
+
if (bulkState.bar !== null) {
|
|
1083
|
+
if (typeof bulkState.bar.remove === 'function') bulkState.bar.remove();
|
|
1084
|
+
bulkState.bar = null;
|
|
1085
|
+
bulkState.countNode = null;
|
|
1086
|
+
bulkState.moveNode = null;
|
|
1087
|
+
}
|
|
1088
|
+
bulkDecorate();
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
/** 菜单里的「多选」入口:宿主支持批量动作时让位给它那根底栏。 */
|
|
1092
|
+
function BulkEntry(props) {
|
|
1093
|
+
var useMenuOpenState = props !== null && props !== undefined ? props.useMenuOpenState : null;
|
|
1094
|
+
var menuState = null;
|
|
1095
|
+
if (typeof useMenuOpenState === 'function') {
|
|
1096
|
+
try { menuState = useMenuOpenState(); } catch (error) { menuState = null; }
|
|
1097
|
+
}
|
|
1098
|
+
if (hostSupportsBulkMove()) return null;
|
|
1099
|
+
return button('bulk', text().bulk, {
|
|
1100
|
+
onClick: function () {
|
|
1101
|
+
if (menuState !== null && Array.isArray(menuState) && typeof menuState[1] === 'function') {
|
|
1102
|
+
try { menuState[1](false); } catch (error) { /* ignore */ }
|
|
1103
|
+
}
|
|
1104
|
+
enterBulk();
|
|
1105
|
+
},
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
|
|
511
1109
|
/** 需要 slots 服务。 */
|
|
512
1110
|
var inject = ['slots'];
|
|
513
1111
|
|
|
514
1112
|
function apply(ctx) {
|
|
515
1113
|
ensureStyles();
|
|
1114
|
+
// 对外契约:dsh-delete-session 会检测这个全局,把「移动」放进它那根底栏。
|
|
1115
|
+
var boot = bootGlobal();
|
|
1116
|
+
var version = boot !== null && typeof boot === 'object' && typeof boot.version === 'string' ? boot.version : '0.0.0';
|
|
1117
|
+
// 注意:这个全局**同时**是主机注入的引导信息(prefix / version / drag)和客户端对外契约,
|
|
1118
|
+
// 所以只能合并、不能整个覆盖 —— 覆盖掉 prefix 会让桥接请求打到一个不存在的地址。
|
|
1119
|
+
var contract = globalThis.__DSH_SESSION_RELOCATE__;
|
|
1120
|
+
if (contract === null || typeof contract !== 'object') contract = {};
|
|
1121
|
+
contract.version = version;
|
|
1122
|
+
contract.supportsBulkMove = true;
|
|
1123
|
+
contract.moveSelection = moveSelection;
|
|
1124
|
+
globalThis.__DSH_SESSION_RELOCATE__ = contract;
|
|
1125
|
+
try {
|
|
1126
|
+
document.dispatchEvent(new CustomEvent('dsh-session-relocate:ready', { detail: { version: version } }));
|
|
1127
|
+
} catch (error) { /* 没有 CustomEvent 的环境就算了 */ }
|
|
516
1128
|
// 拖动搬移:与菜单那条路并存(拖不动就点菜单)。
|
|
517
1129
|
if (!dragEnabled()) {
|
|
518
1130
|
// 主机侧关掉了:什么都不挂。
|
|
@@ -522,17 +1134,43 @@ window.__ModuleLoader__.load({
|
|
|
522
1134
|
installDrag();
|
|
523
1135
|
}
|
|
524
1136
|
return ctx.slots.inject('sidebar.workspaces.session.menu.item', function () {
|
|
525
|
-
|
|
1137
|
+
var disposers = [];
|
|
1138
|
+
// 「多选」入口:dsh-delete-session 支持批量动作时该组件渲染 null(入口交给它那根底栏)。
|
|
1139
|
+
disposers.push(ctx.slots.register(
|
|
1140
|
+
{ name: 'sidebar.workspaces.session.menu.item', id: 'session-relocate-bulk', order: 351 },
|
|
1141
|
+
BulkEntry,
|
|
1142
|
+
));
|
|
1143
|
+
disposers.push(ctx.slots.register(
|
|
526
1144
|
{ name: 'sidebar.workspaces.session.menu.item', id: 'session-relocate', order: 350 },
|
|
527
1145
|
Entry,
|
|
528
|
-
);
|
|
1146
|
+
));
|
|
1147
|
+
return function () {
|
|
1148
|
+
for (var i = 0; i < disposers.length; i += 1) {
|
|
1149
|
+
if (typeof disposers[i] === 'function') {
|
|
1150
|
+
try { disposers[i](); } catch (error) { /* ignore */ }
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
};
|
|
529
1154
|
});
|
|
530
1155
|
}
|
|
531
1156
|
|
|
532
1157
|
exports.apply = apply;
|
|
533
1158
|
exports.inject = inject;
|
|
534
1159
|
exports.__entry = Entry;
|
|
1160
|
+
exports.__bulkEntry = BulkEntry;
|
|
535
1161
|
// 给测试用的内部入口(浏览器里没人用)。
|
|
1162
|
+
exports.__bulk = {
|
|
1163
|
+
moveSelection: moveSelection,
|
|
1164
|
+
runBulkMove: runBulkMove,
|
|
1165
|
+
pickBulkTarget: pickBulkTarget,
|
|
1166
|
+
hostSupportsBulkMove: hostSupportsBulkMove,
|
|
1167
|
+
enterBulk: enterBulk,
|
|
1168
|
+
exitBulk: exitBulk,
|
|
1169
|
+
bulkDecorate: bulkDecorate,
|
|
1170
|
+
bulkMoveSelected: bulkMoveSelected,
|
|
1171
|
+
state: bulkState,
|
|
1172
|
+
sessionIdFromRow: sessionIdFromRow,
|
|
1173
|
+
};
|
|
536
1174
|
exports.__drag = {
|
|
537
1175
|
installDrag: installDrag,
|
|
538
1176
|
onDragStart: onDragStart,
|