dsh-session-relocate 0.2.6 → 0.2.8
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 +12 -0
- package/docs/DESIGN.md +11 -0
- package/docs/shared-footer-bar.md +4 -0
- package/lib/client.js +266 -2
- package/package.json +1 -1
- package/src/plugin.js +65 -1
package/README.md
CHANGED
|
@@ -58,9 +58,15 @@ curl http://127.0.0.1:3080/api/dsh-session-relocate/status
|
|
|
58
58
|
- 拖到目标工作区的**文件夹行**上 —— 可以;
|
|
59
59
|
- 拖到它下面**任意一条会话行**上 —— 也可以;
|
|
60
60
|
- 拖到分组里的空隙、或「展开其余 N 个会话」上 —— 一样可以。
|
|
61
|
+
- **拖到列表上下边缘会自动滚动**(越靠边滚得越快),长侧栏也能拖到看不见的工作区。
|
|
61
62
|
|
|
62
63
|
松手前,整块目标分组会亮起蓝框。
|
|
63
64
|
|
|
65
|
+
**移出工作区(回到「未分组」)**:把会话拖到侧栏的「未分组」分组上,松手即移出 ——
|
|
66
|
+
**只改归属**,会话日志、header 里的 cwd、写句柄全都不动,所以正在跑的会话也能安全移出,
|
|
67
|
+
之后随时可以再拖(或「移动到」)回原工作区。也可以用该会话「…」菜单里的
|
|
68
|
+
**移出工作区(未分组)**(侧栏还没有「未分组」分组时,这是唯一的入口)。
|
|
69
|
+
|
|
64
70
|
**多选也能拖。** 在多选模式里勾好几条后,抓住其中任意一条拖到目标工作区,松手就是整批搬(逐条文件事务 + 最后一次性写归属),进度显示「正在移动 x/N…」;拖的如果是一条**没被勾中**的行,就只搬它自己。
|
|
65
71
|
|
|
66
72
|
**组内上下拖动仍然是官方的排序功能,插件一点不抢。** 判断依据是"指针落在哪个分组里":
|
|
@@ -237,6 +243,7 @@ POSIX 上才是会话目录里的 `session.lock`(flock)。两种情况下锁
|
|
|
237
243
|
| --- | --- | --- |
|
|
238
244
|
| POST | `<prefix>/describe` | `{ sessionId? }` → 工作区列表;带 sessionId 时额外给出 `currentWorkspaceId`、`live`、`willHandoff`(正在跑,会就地接管)、`willRelease`(空闲,会先释放)、`activity`、`canMove`、`reason`。 |
|
|
239
245
|
| POST | `<prefix>/move` | `{ sessionId, targetWorkspaceId }` 或 `{ sessionId, targetPath }` → 迁移回执(`applied: 'live' \| 'pending'`、`released`、`releaseAttempts`、`handedOff`、`verification: 'full' \| 'sampled'`)。带 `deferRegistry: true` 时只做文件事务、保留迁移日志。 |
|
|
246
|
+
| POST | `<prefix>/move-out` | `{ sessionId }` → 把会话从当前工作区摘出去(回到「未分组」)。**只改注册表**,不动日志 / header / 写句柄;本来就不在分组里时返回 `code: "already-ungrouped"`。 |
|
|
240
247
|
| POST | `<prefix>/move-commit` | `{ sessionIds }` → 把一批 defer 过的迁移的归属一次性写进注册表(每个目标/源工作区各一次 mutate),返回逐条结果。 |
|
|
241
248
|
| GET | `<prefix>/status` | 版本/配置(含 `moveLive`/`releaseLive`/`verify`/`bulkDefer`)/待收尾的迁移列表;调用时会顺带尝试恢复。 |
|
|
242
249
|
| POST | `<prefix>/__selftest/create-live` | 仅 `selftest: true` 时存在。造一个「已打开 + 持有写租约」的会话(`{ workspacePath, pressure? }`)。 |
|
|
@@ -267,6 +274,11 @@ node --test
|
|
|
267
274
|
|
|
268
275
|
## 已知限制
|
|
269
276
|
|
|
277
|
+
- **「未分组」分组只在已有未分组会话时才出现**(官方 `groupByWorkspace` 里是 `if (stray.length > 0)`)。
|
|
278
|
+
侧栏还没有这个分组时,拖拽没有投放目标 —— 用「…」菜单里的 **移出工作区(未分组)**。
|
|
279
|
+
- **自动滚动依赖「找得到滚动容器」**:从拖拽行向上找 `overflow-y: auto|scroll|overlay` 且内容确实超出的祖先。
|
|
280
|
+
原生拖拽期间浏览器自己不滚,所以这块是我们手动做的;找不到容器时就是「不滚」,不影响搬移本身。
|
|
281
|
+
|
|
270
282
|
- **拖动搬移依赖官方的 DOM 约定**:行属性(`data-row-key="session:<id>"` / `"workspace:<workspaceId>"`)
|
|
271
283
|
加上**分组结构**(官方 `renderGroup` 把每个工作区渲染成一个「恰好只含一个工作区行」的容器)。
|
|
272
284
|
它读的是官方渲染出来的东西,不是未公开的拖拽载荷;DSH 若改掉这些,拖动会**分级退化**:
|
package/docs/DESIGN.md
CHANGED
|
@@ -218,6 +218,17 @@ header 是冻的,所以**那一轮的工具仍然用旧目录**;下次打开
|
|
|
218
218
|
槽位组件常驻,靠返回 `null` 表示「不存在」。老宿主没有这个槽时回退自绘浮动卡片(`.dshsm-bar-float`)。
|
|
219
219
|
文案一律自己插值,不把参数交给宿主 `t`。
|
|
220
220
|
|
|
221
|
+
**边缘自动滚动**:拖拽期间用 rAF 自己滚(HTML5 拖拽时浏览器不帮滚)。滚动容器从拖拽行向上找
|
|
222
|
+
`overflow-y: auto|scroll|overlay` 且 `scrollHeight > clientHeight + 4` 的祖先(不依赖 class 名);
|
|
223
|
+
指针进入距上下边缘 84px 时开滚,速度按比例平方曲线 2~22px/帧;指针越出滚动容器 40px 以上就停;
|
|
224
|
+
滚不动(到底/到顶)就停止排帧。每滚一步用 `document.elementFromPoint` 重算一次投放目标 ——
|
|
225
|
+
否则内容动了但不会再有 `dragover`,高亮会停在上一个分组上。
|
|
226
|
+
|
|
227
|
+
**移出工作区(未分组)**:投放目标是「未分组」分组 —— 它的工作区行 `data-row-key` 恰好是
|
|
228
|
+
`workspace:`(官方 `UNGROUPED_KEY = ''`)。松手后走 `POST /move-out`:**只改注册表**,
|
|
229
|
+
日志 / `header.cwd` / 写句柄一律不碰,所以正在跑的会话也能移出,且随时能再搬回来。
|
|
230
|
+
侧栏没有「未分组」分组时(没有 stray 会话)另有菜单入口「移出工作区(未分组)」,走同一条接口。
|
|
231
|
+
|
|
221
232
|
**多选拖动**:dragstart 时读当前选中集合 —— 本插件的多选读 `bulkState`;`dsh-delete-session`
|
|
222
233
|
的多选读它给选中行挂的 `.dsdel-check-on`(只读它的 DOM,不动它的状态)。拖的会话在选中集合里且
|
|
223
234
|
不止一条时,投放走 `runBulkMove`(逐条 defer + 一次 commit),完成后发一个 `Escape` 让宿主收起
|
|
@@ -92,6 +92,10 @@ body.dshsm-selecting [class*="_footArea"] > *:not([class*="_footerActions"]){dis
|
|
|
92
92
|
/* 别家插件的页脚按钮让位 */
|
|
93
93
|
body.dshsm-selecting [data-slot="sidebar.footer.action"] > [data-dsh-plugin]{display:none}
|
|
94
94
|
|
|
95
|
+
/* 按钮型入口一律让位(.dhns-footer-btn 这类没带 data-dsh-plugin 的)
|
|
96
|
+
槽入口无包装层,'> button' 精确命中按钮型入口;:not([role="toolbar"]) 保证藏不到底栏自己 */
|
|
97
|
+
body.dshsm-selecting [data-slot="sidebar.footer.action"] > button:not([role="toolbar"]){display:none}
|
|
98
|
+
|
|
95
99
|
/* entryRow 那个容器不带 data-dsh-plugin,单独点名 */
|
|
96
100
|
body.dshsm-selecting [data-slot="sidebar.footer.action"] > [class*="_entryRow"]{display:none}
|
|
97
101
|
```
|
package/lib/client.js
CHANGED
|
@@ -57,6 +57,12 @@ window.__ModuleLoader__.load({
|
|
|
57
57
|
'body.dshsm-selecting [class*="_footArea"] > *:not([class*="_footerActions"]){display:none}',
|
|
58
58
|
'body.dshsm-selecting [data-slot="sidebar.footer.action"] > [data-dsh-plugin]{display:none}',
|
|
59
59
|
'body.dshsm-selecting [data-slot="sidebar.footer.action"] > [class*="_entryRow"]{display:none}',
|
|
60
|
+
// 页脚里的「按钮型」入口也要让位。槽入口是**无包装层**的直接子节点
|
|
61
|
+
// (renderer 的 SlotOutlet 是 <div data-slot style="display:contents">,入口组件直接挂成子节点),
|
|
62
|
+
// 所以 '> button' 精确命中按钮型入口 —— 例如 dsh-sidebar-declutter 的 .dhns-footer-btn,
|
|
63
|
+
// 它没带 data-dsh-plugin,上面两条规则都漏了它,多选时会和底栏挤在同一行。
|
|
64
|
+
// :not([role="toolbar"]) 保证永远藏不到底栏自己(两家底栏都是 div + role="toolbar")。
|
|
65
|
+
'body.dshsm-selecting [data-slot="sidebar.footer.action"] > button:not([role="toolbar"]){display:none}',
|
|
60
66
|
'.dshsm-picker-backdrop{position:fixed;inset:0;z-index:2147483602;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,.42)}',
|
|
61
67
|
'.dshsm-picker{width:min(440px,92vw);max-height:70vh;overflow:auto;display:flex;flex-direction:column;gap:10px;padding:16px;border-radius:14px;border:1px solid transparent;box-shadow:0 18px 48px rgba(0,0,0,.36)}',
|
|
62
68
|
'.dshsm-picker.dshsm-dark{background:#1f232b;color:#f2f3f5;border-color:rgba(255,255,255,.18);color-scheme:dark}',
|
|
@@ -222,6 +228,12 @@ window.__ModuleLoader__.load({
|
|
|
222
228
|
failed: '移动失败',
|
|
223
229
|
needsReload: '(刷新页面后生效)',
|
|
224
230
|
dragMoved: '已移动到「{ws}」',
|
|
231
|
+
dragDetached: '已从「{ws}」移出,现在是未分组',
|
|
232
|
+
dragDetachedNoWs: '已移出工作区,现在是未分组',
|
|
233
|
+
bulkDetached: '已移出 {ok} 个',
|
|
234
|
+
ungroupAction: '移出工作区(未分组)',
|
|
235
|
+
ungroupAlready: '这个对话本来就不在任何工作区里',
|
|
236
|
+
ungroupDone: '已移出「{ws}」',
|
|
225
237
|
dragFailed: '移动失败:',
|
|
226
238
|
bulk: '多选',
|
|
227
239
|
bulkMove: '移动',
|
|
@@ -268,6 +280,12 @@ window.__ModuleLoader__.load({
|
|
|
268
280
|
failed: 'Move failed',
|
|
269
281
|
needsReload: ' (reload the page to apply)',
|
|
270
282
|
dragMoved: 'Moved to “{ws}”',
|
|
283
|
+
dragDetached: 'Removed from “{ws}” — now ungrouped',
|
|
284
|
+
dragDetachedNoWs: 'Removed from its workspace — now ungrouped',
|
|
285
|
+
bulkDetached: 'Removed {ok}',
|
|
286
|
+
ungroupAction: 'Remove from workspace (ungroup)',
|
|
287
|
+
ungroupAlready: 'This conversation is not in any workspace',
|
|
288
|
+
ungroupDone: 'Removed from “{ws}”',
|
|
271
289
|
dragFailed: 'Move failed: ',
|
|
272
290
|
bulk: 'Select multiple',
|
|
273
291
|
bulkMove: 'Move',
|
|
@@ -685,6 +703,10 @@ window.__ModuleLoader__.load({
|
|
|
685
703
|
sourceWorkspaceId: null,
|
|
686
704
|
targetSection: null,
|
|
687
705
|
hostSelected: false,
|
|
706
|
+
// 自动滚动:拖动源所在的滚动容器、当前指针、rAF 句柄
|
|
707
|
+
scrollEl: null,
|
|
708
|
+
scrollRaf: null,
|
|
709
|
+
pointer: null,
|
|
688
710
|
};
|
|
689
711
|
var dragInstallRefs = 0;
|
|
690
712
|
var toastNode = null;
|
|
@@ -744,6 +766,29 @@ window.__ModuleLoader__.load({
|
|
|
744
766
|
return id.length > 0 ? id : null;
|
|
745
767
|
}
|
|
746
768
|
|
|
769
|
+
/**
|
|
770
|
+
* 「未分组」那个分组:它的工作区行 data-row-key 恰好是 "workspace:"(id 为空)。
|
|
771
|
+
* 拖到它上面 = 移出工作区(只改归属,文件与 header 都不动)。
|
|
772
|
+
*/
|
|
773
|
+
function ungroupedGroupOf(target) {
|
|
774
|
+
var node = target;
|
|
775
|
+
for (var depth = 0; depth < ROW_WALK_LIMIT && node !== null && node !== undefined; depth += 1) {
|
|
776
|
+
if (typeof node.getAttribute === 'function' && node.getAttribute('role') === 'tree') break;
|
|
777
|
+
if (typeof node.querySelectorAll === 'function') {
|
|
778
|
+
var rows = node.querySelectorAll(WORKSPACE_ROW_SELECTOR);
|
|
779
|
+
if (rows !== null && rows !== undefined && typeof rows.length === 'number') {
|
|
780
|
+
if (rows.length > 1) break;
|
|
781
|
+
if (rows.length === 1) {
|
|
782
|
+
var key = typeof rows[0].getAttribute === 'function' ? rows[0].getAttribute(ROW_KEY_ATTR) : null;
|
|
783
|
+
if (key === WORKSPACE_PREFIX) return { section: node, row: rows[0], workspaceId: '' };
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
node = node.parentElement;
|
|
788
|
+
}
|
|
789
|
+
return null;
|
|
790
|
+
}
|
|
791
|
+
|
|
747
792
|
function toggleDropClass(row, on) {
|
|
748
793
|
if (row === null || row === undefined) return;
|
|
749
794
|
var list = row.classList;
|
|
@@ -765,7 +810,97 @@ window.__ModuleLoader__.load({
|
|
|
765
810
|
dragState.targetSection = null;
|
|
766
811
|
}
|
|
767
812
|
|
|
813
|
+
// ── 拖到侧栏上下边缘自动滚动 ────────────────────────────────────────────
|
|
814
|
+
//
|
|
815
|
+
// 侧栏很长时,「能拖到」和「看得见」是两件事:不滚就只能拖到眼前那几个工作区。
|
|
816
|
+
// 这里用 rAF 自己滚(HTML5 拖拽时浏览器不会帮你滚),并且不依赖任何 class 名:
|
|
817
|
+
// 向上找第一个 overflow-y 可滚且内容确实超出的祖先,官方/第三方侧栏都适用。
|
|
818
|
+
var SCROLL_EDGE = 84; // 指针进入距边缘这么多像素就开滚
|
|
819
|
+
var SCROLL_MAX_STEP = 22; // 每帧最多滚多少像素
|
|
820
|
+
var SCROLL_TAIL = 40; // 指针越出滚动区这么多以内继续(避免边缘抖动)
|
|
821
|
+
|
|
822
|
+
/** 从元素向上找真正的滚动容器;找不到返回 null。 */
|
|
823
|
+
function findScrollableAncestor(element) {
|
|
824
|
+
if (typeof document === 'undefined') return null;
|
|
825
|
+
var node = element;
|
|
826
|
+
while (node !== null && node !== undefined && node !== document.body && node !== document.documentElement) {
|
|
827
|
+
var style = null;
|
|
828
|
+
try {
|
|
829
|
+
style = typeof globalThis.getComputedStyle === 'function' ? globalThis.getComputedStyle(node) : null;
|
|
830
|
+
} catch (error) {
|
|
831
|
+
style = null;
|
|
832
|
+
}
|
|
833
|
+
var overflowY = style !== null && style !== undefined ? String(style.overflowY || '') : '';
|
|
834
|
+
if ((overflowY === 'auto' || overflowY === 'scroll' || overflowY === 'overlay')
|
|
835
|
+
&& typeof node.scrollHeight === 'number' && typeof node.clientHeight === 'number'
|
|
836
|
+
&& node.scrollHeight > node.clientHeight + 4) return node;
|
|
837
|
+
node = node.parentElement;
|
|
838
|
+
}
|
|
839
|
+
return null;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
/** 离边缘越近每帧滚得越多:比例平方曲线,2~22px。 */
|
|
843
|
+
function scrollStepFor(distance) {
|
|
844
|
+
var ratio = Math.min(1, Math.max(0, Number(distance) / SCROLL_EDGE));
|
|
845
|
+
return Math.max(2, Math.round(ratio * ratio * SCROLL_MAX_STEP));
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
function stopAutoScroll() {
|
|
849
|
+
if (dragState.scrollRaf !== null) {
|
|
850
|
+
try {
|
|
851
|
+
if (typeof globalThis.cancelAnimationFrame === 'function') globalThis.cancelAnimationFrame(dragState.scrollRaf);
|
|
852
|
+
else clearTimeout(dragState.scrollRaf);
|
|
853
|
+
} catch (error) { /* ignore */ }
|
|
854
|
+
dragState.scrollRaf = null;
|
|
855
|
+
}
|
|
856
|
+
dragState.scrollEl = null;
|
|
857
|
+
dragState.pointer = null;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
function ensureAutoScroll() {
|
|
861
|
+
if (dragState.scrollRaf !== null) return;
|
|
862
|
+
if (dragState.scrollEl === null || dragState.scrollEl === undefined) return;
|
|
863
|
+
if (typeof globalThis.requestAnimationFrame !== 'function') return;
|
|
864
|
+
dragState.scrollRaf = globalThis.requestAnimationFrame(autoScrollTick);
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
function autoScrollTick() {
|
|
868
|
+
dragState.scrollRaf = null;
|
|
869
|
+
var element = dragState.scrollEl;
|
|
870
|
+
var pointer = dragState.pointer;
|
|
871
|
+
if (element === null || element === undefined || pointer === null || dragState.sessionId === null) return;
|
|
872
|
+
var rect = null;
|
|
873
|
+
try { rect = element.getBoundingClientRect(); } catch (error) { rect = null; }
|
|
874
|
+
if (rect === null || rect === undefined || !(rect.height > 0)) return;
|
|
875
|
+
// 指针甩到侧栏外面(比如拖去聊天区)就别滚了
|
|
876
|
+
if (pointer.x < rect.left - SCROLL_TAIL || pointer.x > rect.right + SCROLL_TAIL) return;
|
|
877
|
+
if (pointer.y < rect.top - SCROLL_TAIL || pointer.y > rect.bottom + SCROLL_TAIL) return;
|
|
878
|
+
var delta = 0;
|
|
879
|
+
if (pointer.y < rect.top + SCROLL_EDGE) delta = -scrollStepFor(rect.top + SCROLL_EDGE - pointer.y);
|
|
880
|
+
else if (pointer.y > rect.bottom - SCROLL_EDGE) delta = scrollStepFor(pointer.y - (rect.bottom - SCROLL_EDGE));
|
|
881
|
+
if (delta === 0) return;
|
|
882
|
+
var before = element.scrollTop;
|
|
883
|
+
element.scrollTop = before + delta;
|
|
884
|
+
// 到底 / 到顶:滚不动了,等下一次 dragover 再说,别空转烧 rAF
|
|
885
|
+
if (element.scrollTop === before) return;
|
|
886
|
+
// 内容滚了但不会再收到 dragover:按指针位置重算一次投放目标,高亮才跟得上
|
|
887
|
+
hoverAtPoint(pointer.x, pointer.y);
|
|
888
|
+
ensureAutoScroll();
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/** 自动滚动后按指针重算高亮(等价于一次没有事件的 dragover)。 */
|
|
892
|
+
function hoverAtPoint(x, y) {
|
|
893
|
+
if (typeof document === 'undefined' || typeof document.elementFromPoint !== 'function') return;
|
|
894
|
+
var node = null;
|
|
895
|
+
try { node = document.elementFromPoint(x, y); } catch (error) { node = null; }
|
|
896
|
+
if (node === null || node === undefined) { clearHighlight(); return; }
|
|
897
|
+
var drop = resolveDrop({ target: node });
|
|
898
|
+
if (drop === null) { clearHighlight(); return; }
|
|
899
|
+
highlightGroup(drop.section);
|
|
900
|
+
}
|
|
901
|
+
|
|
768
902
|
function resetDrag() {
|
|
903
|
+
stopAutoScroll();
|
|
769
904
|
clearHighlight();
|
|
770
905
|
dragState.sessionId = null;
|
|
771
906
|
dragState.sessionIds = null;
|
|
@@ -777,6 +912,12 @@ window.__ModuleLoader__.load({
|
|
|
777
912
|
function resolveDrop(event) {
|
|
778
913
|
if (dragState.sessionId === null) return null;
|
|
779
914
|
var target = event !== null && event !== undefined ? event.target : null;
|
|
915
|
+
// 「未分组」组 = 移出工作区。本来就在未分组时不接管(无事可做,让官方排序照旧)。
|
|
916
|
+
var ungrouped = ungroupedGroupOf(target);
|
|
917
|
+
if (ungrouped !== null) {
|
|
918
|
+
if (dragState.sourceWorkspaceId === null || dragState.sourceWorkspaceId === undefined || dragState.sourceWorkspaceId === '') return null;
|
|
919
|
+
return { sessionId: dragState.sessionId, kind: 'ungrouped', targetWorkspaceId: null, section: ungrouped.section };
|
|
920
|
+
}
|
|
780
921
|
var group = workspaceGroupOf(target);
|
|
781
922
|
if (group === null) {
|
|
782
923
|
// 退化路径:读不到分组结构(老版本 DSH / 结构变了)时,回到「只认工作区行」的老行为,
|
|
@@ -785,11 +926,11 @@ window.__ModuleLoader__.load({
|
|
|
785
926
|
var fallbackId = row === null ? null : workspaceIdOf(row);
|
|
786
927
|
if (fallbackId === null) return null;
|
|
787
928
|
if (dragState.sourceWorkspaceId !== null && dragState.sourceWorkspaceId === fallbackId) return null;
|
|
788
|
-
return { sessionId: dragState.sessionId, targetWorkspaceId: fallbackId, section: row };
|
|
929
|
+
return { sessionId: dragState.sessionId, kind: 'workspace', targetWorkspaceId: fallbackId, section: row };
|
|
789
930
|
}
|
|
790
931
|
// 落在**它自己所在的那个分组**里 = 官方的工作区内排序区,让路(官方照旧重排)。
|
|
791
932
|
if (dragState.sourceWorkspaceId !== null && dragState.sourceWorkspaceId === group.workspaceId) return null;
|
|
792
|
-
return { sessionId: dragState.sessionId, targetWorkspaceId: group.workspaceId, section: group.section };
|
|
933
|
+
return { sessionId: dragState.sessionId, kind: 'workspace', targetWorkspaceId: group.workspaceId, section: group.section };
|
|
793
934
|
}
|
|
794
935
|
|
|
795
936
|
/**
|
|
@@ -821,6 +962,7 @@ window.__ModuleLoader__.load({
|
|
|
821
962
|
if (sessionId.length === 0) return;
|
|
822
963
|
resetDrag();
|
|
823
964
|
dragState.sessionId = sessionId;
|
|
965
|
+
dragState.scrollEl = findScrollableAncestor(row);
|
|
824
966
|
// 多选拖动:宿主底栏(或我们自己的多选)里选中的整批一起搬。
|
|
825
967
|
var selectedIds = selectedIdsForDrag();
|
|
826
968
|
var multi = selectedIds.length > 1 && selectedIds.indexOf(sessionId) >= 0;
|
|
@@ -843,6 +985,11 @@ window.__ModuleLoader__.load({
|
|
|
843
985
|
|
|
844
986
|
function onDragOver(event) {
|
|
845
987
|
if (dragState.sessionId === null) return;
|
|
988
|
+
// 记下指针位置并驱动自动滚动(HTML5 拖拽时浏览器自己不滚)
|
|
989
|
+
if (event !== null && event !== undefined && typeof event.clientX === 'number' && typeof event.clientY === 'number') {
|
|
990
|
+
dragState.pointer = { x: event.clientX, y: event.clientY };
|
|
991
|
+
ensureAutoScroll();
|
|
992
|
+
}
|
|
846
993
|
var drop = resolveDrop(event);
|
|
847
994
|
if (drop === null) {
|
|
848
995
|
clearHighlight();
|
|
@@ -872,7 +1019,13 @@ window.__ModuleLoader__.load({
|
|
|
872
1019
|
var targetWorkspaceId = drop.targetWorkspaceId;
|
|
873
1020
|
var ids = dragState.sessionIds !== null && dragState.sessionIds.length > 1 ? dragState.sessionIds : [sessionId];
|
|
874
1021
|
var hostSelected = dragState.hostSelected === true;
|
|
1022
|
+
var kind = drop.kind === 'ungrouped' ? 'ungrouped' : 'workspace';
|
|
875
1023
|
resetDrag();
|
|
1024
|
+
if (kind === 'ungrouped') {
|
|
1025
|
+
if (ids.length > 1) detachManyByDrag(ids, hostSelected);
|
|
1026
|
+
else detachByDrag(sessionId, hostSelected);
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
876
1029
|
if (ids.length > 1) moveManyByDrag(ids, targetWorkspaceId, hostSelected);
|
|
877
1030
|
else moveByDrag(sessionId, targetWorkspaceId, hostSelected);
|
|
878
1031
|
}
|
|
@@ -918,6 +1071,59 @@ window.__ModuleLoader__.load({
|
|
|
918
1071
|
});
|
|
919
1072
|
}
|
|
920
1073
|
|
|
1074
|
+
/** 拖到「未分组」组上:只把归属摘掉 —— 会话日志、header 的 cwd、写句柄全都不动。 */
|
|
1075
|
+
function detachByDrag(sessionId, hostSelected) {
|
|
1076
|
+
var strings = text();
|
|
1077
|
+
toast(strings.moving);
|
|
1078
|
+
post('/move-out', { sessionId: sessionId }).then(function (result) {
|
|
1079
|
+
if (result !== null && result !== undefined && result.ok === true) {
|
|
1080
|
+
var from = result.detachedFrom !== null && result.detachedFrom !== undefined && typeof result.detachedFrom.title === 'string'
|
|
1081
|
+
? result.detachedFrom.title
|
|
1082
|
+
: '';
|
|
1083
|
+
toast(from.length > 0 ? strings.dragDetached.replace('{ws}', from) : strings.dragDetachedNoWs);
|
|
1084
|
+
if (bulkState.selecting === true) exitBulk();
|
|
1085
|
+
else if (hostSelected === true) dismissHostSelection();
|
|
1086
|
+
refreshSidebar();
|
|
1087
|
+
return;
|
|
1088
|
+
}
|
|
1089
|
+
var message = result !== null && result !== undefined && typeof result.message === 'string' ? result.message : '';
|
|
1090
|
+
toast(strings.dragFailed + message);
|
|
1091
|
+
}, function (error) {
|
|
1092
|
+
toast(strings.dragFailed + errorText(error));
|
|
1093
|
+
});
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
/** 多选时整批移出工作区:逐条摘归属(只改注册表,很快),失败按条隔离。 */
|
|
1097
|
+
function detachManyByDrag(ids, hostSelected) {
|
|
1098
|
+
var strings = text();
|
|
1099
|
+
toast(strings.moving);
|
|
1100
|
+
var done = 0;
|
|
1101
|
+
var failed = 0;
|
|
1102
|
+
var chain = Promise.resolve();
|
|
1103
|
+
for (var i = 0; i < ids.length; i += 1) {
|
|
1104
|
+
(function (id) {
|
|
1105
|
+
chain = chain.then(function () {
|
|
1106
|
+
return post('/move-out', { sessionId: id }).then(function (result) {
|
|
1107
|
+
if (result !== null && result !== undefined && result.ok === true) done += 1;
|
|
1108
|
+
else failed += 1;
|
|
1109
|
+
toast(strings.bulkProgress.replace('{d}', String(done + failed)).replace('{t}', String(ids.length)));
|
|
1110
|
+
}, function () {
|
|
1111
|
+
failed += 1;
|
|
1112
|
+
});
|
|
1113
|
+
});
|
|
1114
|
+
})(ids[i]);
|
|
1115
|
+
}
|
|
1116
|
+
chain.then(function () {
|
|
1117
|
+
var summary = failed === 0
|
|
1118
|
+
? strings.bulkDetached.replace('{ok}', String(done))
|
|
1119
|
+
: strings.bulkPartial.replace('{ok}', String(done)).replace('{fail}', String(failed));
|
|
1120
|
+
toast(summary);
|
|
1121
|
+
if (bulkState.selecting === true) exitBulk();
|
|
1122
|
+
else if (hostSelected === true) dismissHostSelection();
|
|
1123
|
+
refreshSidebar();
|
|
1124
|
+
});
|
|
1125
|
+
}
|
|
1126
|
+
|
|
921
1127
|
/** 多选拖动:整批搬到同一个目标(目标就是松手的分组,不再弹选择面板)。 */
|
|
922
1128
|
function moveManyByDrag(ids, targetWorkspaceId, hostSelected) {
|
|
923
1129
|
var strings = text();
|
|
@@ -2087,6 +2293,53 @@ window.__ModuleLoader__.load({
|
|
|
2087
2293
|
]);
|
|
2088
2294
|
}
|
|
2089
2295
|
|
|
2296
|
+
/**
|
|
2297
|
+
* 菜单里的「移出工作区」:只摘归属(/move-out),文件与 header 都不动。
|
|
2298
|
+
*
|
|
2299
|
+
* 为什么除了拖动还要一个菜单入口:「未分组」那个分组只有在**已经有未分组会话**时才渲染
|
|
2300
|
+
* (官方 groupByWorkspace 里是 if (stray.length > 0)),没有它就没有投放目标。
|
|
2301
|
+
*/
|
|
2302
|
+
function UngroupEntry(props) {
|
|
2303
|
+
var useMenuOpenState = props !== null && props !== undefined ? props.useMenuOpenState : null;
|
|
2304
|
+
var strings = text();
|
|
2305
|
+
function closeMenu() {
|
|
2306
|
+
if (typeof useMenuOpenState !== 'function') return;
|
|
2307
|
+
var state = null;
|
|
2308
|
+
try { state = useMenuOpenState(); } catch (error) { state = null; }
|
|
2309
|
+
if (state !== null && Array.isArray(state) && typeof state[1] === 'function') {
|
|
2310
|
+
try { state[1](false); } catch (error) { /* ignore */ }
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
function run() {
|
|
2314
|
+
closeMenu();
|
|
2315
|
+
var sessionId = props !== null && props !== undefined ? props.sessionId : null;
|
|
2316
|
+
if (typeof sessionId !== 'string' || sessionId.length === 0) return;
|
|
2317
|
+
toast(strings.moving);
|
|
2318
|
+
post('/move-out', { sessionId: sessionId }).then(function (result) {
|
|
2319
|
+
if (result !== null && result !== undefined && result.ok === true) {
|
|
2320
|
+
var from = result.detachedFrom !== null && result.detachedFrom !== undefined && typeof result.detachedFrom.title === 'string'
|
|
2321
|
+
? result.detachedFrom.title
|
|
2322
|
+
: '';
|
|
2323
|
+
toast(from.length > 0 ? strings.ungroupDone.replace('{ws}', from) : strings.dragDetachedNoWs);
|
|
2324
|
+
refreshSidebar();
|
|
2325
|
+
return;
|
|
2326
|
+
}
|
|
2327
|
+
if (result !== null && result !== undefined && result.code === 'already-ungrouped') {
|
|
2328
|
+
toast(strings.ungroupAlready);
|
|
2329
|
+
return;
|
|
2330
|
+
}
|
|
2331
|
+
var message = result !== null && result !== undefined && typeof result.message === 'string' ? result.message : '';
|
|
2332
|
+
toast(strings.dragFailed + message);
|
|
2333
|
+
}, function (error) {
|
|
2334
|
+
toast(strings.dragFailed + errorText(error));
|
|
2335
|
+
});
|
|
2336
|
+
}
|
|
2337
|
+
return button('ungroup', [rowIcon(), react.createElement('span', { className: 'dshsm-rowLabel', key: 'label' }, strings.ungroupAction)], {
|
|
2338
|
+
className: 'dshsm-item dshsm-row',
|
|
2339
|
+
onClick: run,
|
|
2340
|
+
});
|
|
2341
|
+
}
|
|
2342
|
+
|
|
2090
2343
|
/** 菜单里的「多选」入口:宿主支持批量动作时让位给它那根底栏。 */
|
|
2091
2344
|
function BulkEntry(props) {
|
|
2092
2345
|
var useMenuOpenState = props !== null && props !== undefined ? props.useMenuOpenState : null;
|
|
@@ -2206,6 +2459,11 @@ window.__ModuleLoader__.load({
|
|
|
2206
2459
|
{ name: 'sidebar.workspaces.session.menu.item', id: 'session-relocate', order: 350 },
|
|
2207
2460
|
Entry,
|
|
2208
2461
|
));
|
|
2462
|
+
// 「移出工作区」:拖到「未分组」组的等价入口(那个分组只在已有未分组会话时才渲染)。
|
|
2463
|
+
items.push(ctx.slots.register(
|
|
2464
|
+
{ name: 'sidebar.workspaces.session.menu.item', id: 'session-relocate-ungroup', order: 349 },
|
|
2465
|
+
UngroupEntry,
|
|
2466
|
+
));
|
|
2209
2467
|
return function () {
|
|
2210
2468
|
for (var i = 0; i < items.length; i += 1) {
|
|
2211
2469
|
if (typeof items[i] === 'function') {
|
|
@@ -2235,6 +2493,7 @@ window.__ModuleLoader__.load({
|
|
|
2235
2493
|
exports.inject = inject;
|
|
2236
2494
|
exports.__entry = Entry;
|
|
2237
2495
|
exports.__bulkEntry = BulkEntry;
|
|
2496
|
+
exports.__ungroupEntry = UngroupEntry;
|
|
2238
2497
|
// 给测试用的内部入口(浏览器里没人用)。
|
|
2239
2498
|
exports.__bulk = {
|
|
2240
2499
|
moveSelection: moveSelection,
|
|
@@ -2267,7 +2526,12 @@ window.__ModuleLoader__.load({
|
|
|
2267
2526
|
reset: resetDrag,
|
|
2268
2527
|
nearestRow: nearestRow,
|
|
2269
2528
|
workspaceGroupOf: workspaceGroupOf,
|
|
2529
|
+
ungroupedGroupOf: ungroupedGroupOf,
|
|
2270
2530
|
workspaceIdOf: workspaceIdOf,
|
|
2531
|
+
scrollStepFor: scrollStepFor,
|
|
2532
|
+
findScrollableAncestor: findScrollableAncestor,
|
|
2533
|
+
autoScrollTick: autoScrollTick,
|
|
2534
|
+
detachByDrag: detachByDrag,
|
|
2271
2535
|
};
|
|
2272
2536
|
return module.exports;
|
|
2273
2537
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-relocate",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "跨工作区移动 DSH 对话:把某个 Session 的日志文件与工作区归属整体搬到另一个工作区(可自动注册新工作区)。带日志级崩溃恢复的安全事务,并且会先安全释放「已打开但空闲」的会话 —— 所以正在打开的对话也能直接搬,不需要重启 DSH。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/plugin.js",
|
package/src/plugin.js
CHANGED
|
@@ -289,6 +289,14 @@ export function apply(ctx, config) {
|
|
|
289
289
|
return previous;
|
|
290
290
|
}
|
|
291
291
|
|
|
292
|
+
/** 删掉这个会话的投影缓存文件(归属变了要让侧栏重算)。尽力而为,失败不影响结果。 */
|
|
293
|
+
async function invalidateProjectionFile(sessionId) {
|
|
294
|
+
const file = join(home, 'storages', 'session_projcache', 'sessions', sessionId + '.json');
|
|
295
|
+
await rm(file, { force: true }).catch((error) => {
|
|
296
|
+
log('warn', '清理投影缓存失败(不影响结果):' + String(error && error.message));
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
292
300
|
function buildHost() {
|
|
293
301
|
const registry = ctx.workspaceRegistry;
|
|
294
302
|
return {
|
|
@@ -521,6 +529,35 @@ export function apply(ctx, config) {
|
|
|
521
529
|
return { applied: false, reason: '批量摘除源归属失败:' + String(error && error.message) };
|
|
522
530
|
}
|
|
523
531
|
},
|
|
532
|
+
/**
|
|
533
|
+
* 把会话从它当前所在的工作区里摘出去(= 回到「未分组」)。
|
|
534
|
+
*
|
|
535
|
+
* 只改注册表:会话日志、header 的 cwd、投影缓存全都不动 —— 因为 cwd 没变,
|
|
536
|
+
* 随时可以再拖回原工作区(那时走 attachExisting / already-there 那条路)。
|
|
537
|
+
* 这也是 DSH 自己的模型允许的最低风险操作:未分组 = 没有任何工作区记录包含它。
|
|
538
|
+
*/
|
|
539
|
+
async detachFromWorkspace(sessionId) {
|
|
540
|
+
const registry = ctx.workspaceRegistry;
|
|
541
|
+
let entities = [];
|
|
542
|
+
try {
|
|
543
|
+
entities = typeof registry.list === 'function' ? registry.list() : [];
|
|
544
|
+
} catch (error) {
|
|
545
|
+
entities = [];
|
|
546
|
+
}
|
|
547
|
+
const owner = entities.find((entity) => Array.isArray(entity.sessionIds) && entity.sessionIds.indexOf(sessionId) >= 0);
|
|
548
|
+
if (owner === undefined) return { detached: false, reason: 'already-ungrouped' };
|
|
549
|
+
if (typeof owner.mutate !== 'function') return { detached: false, reason: 'no-mutate' };
|
|
550
|
+
try {
|
|
551
|
+
await owner.mutate((record) => (Array.isArray(record.sessionIds) && record.sessionIds.includes(sessionId)
|
|
552
|
+
? { ...record, sessionIds: record.sessionIds.filter((entry) => entry !== sessionId) }
|
|
553
|
+
: record));
|
|
554
|
+
} catch (error) {
|
|
555
|
+
return { detached: false, reason: 'mutate-failed: ' + String(error && error.message) };
|
|
556
|
+
}
|
|
557
|
+
// 归属变了:失效一次投影缓存,让侧栏按新的分组关系重算(和搬移时同一个做法)。
|
|
558
|
+
await invalidateProjectionFile(sessionId);
|
|
559
|
+
return { detached: true, from: { id: owner.id, title: owner.title } };
|
|
560
|
+
},
|
|
524
561
|
async releaseSession(sessionId) {
|
|
525
562
|
const sessions = ctx.get('sessions');
|
|
526
563
|
if (sessions === undefined || typeof sessions.get !== 'function') {
|
|
@@ -743,6 +780,32 @@ export function apply(ctx, config) {
|
|
|
743
780
|
}
|
|
744
781
|
}
|
|
745
782
|
|
|
783
|
+
/**
|
|
784
|
+
* 把会话移出它当前所在的工作区(回到「未分组」)。
|
|
785
|
+
*
|
|
786
|
+
* 只改注册表:不动会话日志、不动 header 里的 cwd、不碰写句柄 —— 所以
|
|
787
|
+
* **正在跑的会话也能安全移出**(文件根本没动),而且随时能再拖回原工作区。
|
|
788
|
+
*/
|
|
789
|
+
async function moveOut(body) {
|
|
790
|
+
const sessionId = typeof body.sessionId === "string" ? body.sessionId.trim() : "";
|
|
791
|
+
if (sessionId.length === 0) return { ok: false, code: "bad-request", message: "缺少 sessionId" };
|
|
792
|
+
try {
|
|
793
|
+
const host = buildHost();
|
|
794
|
+
const result = await host.detachFromWorkspace(sessionId);
|
|
795
|
+
if (result === undefined || result.detached !== true) {
|
|
796
|
+
const reason = result !== undefined && typeof result.reason === "string" ? result.reason : "";
|
|
797
|
+
if (reason === "already-ungrouped") {
|
|
798
|
+
return { ok: false, code: "already-ungrouped", message: "这个对话本来就不在任何工作区里" };
|
|
799
|
+
}
|
|
800
|
+
return { ok: false, code: "detach-failed", message: "移出工作区失败:" + reason };
|
|
801
|
+
}
|
|
802
|
+
return { ok: true, sessionId, detachedFrom: { id: result.from.id, title: result.from.title } };
|
|
803
|
+
} catch (error) {
|
|
804
|
+
log("warn", "移出工作区失败:" + String(error && error.message));
|
|
805
|
+
return failure(error);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
|
|
746
809
|
/**
|
|
747
810
|
* 把父会话的全部后代(子代理会话)搬到同一个目标。
|
|
748
811
|
* 每个子会话走完整事务(文件 + 归属);失败按条隔离,父会话的成功回执不受影响。
|
|
@@ -1017,7 +1080,8 @@ export function apply(ctx, config) {
|
|
|
1017
1080
|
const routes = [
|
|
1018
1081
|
route(prefix + '/describe', ['POST'], describe),
|
|
1019
1082
|
route(prefix + '/move', ['POST'], move),
|
|
1020
|
-
route(prefix + '/move-
|
|
1083
|
+
route(prefix + '/move-out', ['POST'], moveOut),
|
|
1084
|
+
route(prefix + '/move-commit', ['POST'], moveCommit),
|
|
1021
1085
|
route(prefix + '/status', ['GET', 'POST'], status),
|
|
1022
1086
|
];
|
|
1023
1087
|
if (selftest) {
|