dsh-nested-workspaces 0.0.0-stage → 1.3.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/LICENSE +21 -0
- package/README.md +122 -2
- package/client.js +2274 -0
- package/cordis.patch.yml +3 -0
- package/icon.svg +7 -0
- package/index.js +140 -0
- package/locale/en.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +57 -4
package/client.js
ADDED
|
@@ -0,0 +1,2274 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: 'dsh-nested-workspaces',
|
|
3
|
+
factory(require) {
|
|
4
|
+
'use strict'
|
|
5
|
+
|
|
6
|
+
const React = require('react')
|
|
7
|
+
const {
|
|
8
|
+
createElement: h,
|
|
9
|
+
Fragment,
|
|
10
|
+
useCallback,
|
|
11
|
+
useEffect,
|
|
12
|
+
useMemo,
|
|
13
|
+
useRef,
|
|
14
|
+
useState,
|
|
15
|
+
useSyncExternalStore,
|
|
16
|
+
} = React
|
|
17
|
+
const { createPortal } = require('react-dom')
|
|
18
|
+
|
|
19
|
+
const NS = 'nested-workspaces'
|
|
20
|
+
const STYLE_ID = 'dsh-nested-workspaces/sidebar'
|
|
21
|
+
const STORAGE_KEY = 'dsh.nested-workspaces.v1'
|
|
22
|
+
const INDENT_PX = 12
|
|
23
|
+
const UNGROUPED = ''
|
|
24
|
+
|
|
25
|
+
/* ------------------------------------------------------------------ locale */
|
|
26
|
+
|
|
27
|
+
const DICT = {
|
|
28
|
+
zh: {
|
|
29
|
+
'heading.default': '工作区',
|
|
30
|
+
'heading.hint': '双击修改标题,清空可恢复默认',
|
|
31
|
+
'menu.addChild': '添加子工作区',
|
|
32
|
+
'actions.addWorkspace': '添加工作区',
|
|
33
|
+
'actions.newSession': '新建会话',
|
|
34
|
+
'actions.search': '搜索工作区或会话',
|
|
35
|
+
'actions.menu': '更多操作',
|
|
36
|
+
'actions.rename': '重命名',
|
|
37
|
+
'actions.delete': '删除工作区',
|
|
38
|
+
'actions.unarchive': '取消归档',
|
|
39
|
+
'actions.create': '创建',
|
|
40
|
+
'actions.cancel': '取消',
|
|
41
|
+
'actions.confirm': '删除',
|
|
42
|
+
'dialog.rename.title': '重命名工作区',
|
|
43
|
+
'dialog.delete.title': '删除工作区',
|
|
44
|
+
'dialog.delete.description': '将把「{name}」从侧边栏移除,磁盘上的文件不会被删除。',
|
|
45
|
+
'renamed': '已重命名',
|
|
46
|
+
'deleted': '已删除工作区',
|
|
47
|
+
'dialog.addChild.title': '添加子工作区',
|
|
48
|
+
'dialog.addWorkspace.title': '添加工作区',
|
|
49
|
+
'dialog.addChild.description': '将在 {parent} 下创建新的子工作区目录。',
|
|
50
|
+
'dialog.addWorkspace.description': '填写工作区目录的绝对路径;留空则打开目录选择器。',
|
|
51
|
+
'field.name': '子工作区名称',
|
|
52
|
+
'field.path': '工作区路径(留空可选择)',
|
|
53
|
+
'errors.nameRequired': '请输入名称。',
|
|
54
|
+
'errors.nameInvalid': '名称不能包含路径分隔符。',
|
|
55
|
+
'errors.exists': '同名目录已存在。',
|
|
56
|
+
'errors.createFailed': '创建失败:{message}',
|
|
57
|
+
'errors.renameFailed': '重命名失败:{message}',
|
|
58
|
+
'errors.deleteFailed': '删除失败:{message}',
|
|
59
|
+
'actions.moveTo': '移动到',
|
|
60
|
+
'actions.showArchived': '显示已归档会话',
|
|
61
|
+
'actions.hideArchived': '隐藏已归档会话',
|
|
62
|
+
'created': '已创建工作区',
|
|
63
|
+
'createdChild': '已创建子工作区',
|
|
64
|
+
'moved': '已移动会话',
|
|
65
|
+
'rail.search': '搜索',
|
|
66
|
+
'expandGroup': '展开分组',
|
|
67
|
+
'collapseGroup': '收起分组',
|
|
68
|
+
'session.new': '新会话',
|
|
69
|
+
'session.untitled': '未命名会话',
|
|
70
|
+
'ungrouped': '未分组',
|
|
71
|
+
'empty': '暂无会话',
|
|
72
|
+
'search.empty': '没有匹配结果',
|
|
73
|
+
'time.now': '刚刚',
|
|
74
|
+
'time.minutes': '{n}分钟',
|
|
75
|
+
'time.hours': '{n}小时',
|
|
76
|
+
'time.days': '{n}天',
|
|
77
|
+
'time.months': '{n}个月',
|
|
78
|
+
'time.years': '{n}年',
|
|
79
|
+
'time.ago': '{t}前',
|
|
80
|
+
'actions.pin': '置顶',
|
|
81
|
+
'actions.unpin': '取消置顶',
|
|
82
|
+
'row.pinned': '已置顶',
|
|
83
|
+
'errors.pinFailed': '置顶状态更新失败',
|
|
84
|
+
'status.running': '正在工作',
|
|
85
|
+
'status.subagentsRunning': '{n}个子代理正在运行',
|
|
86
|
+
'status.completed': '已完成',
|
|
87
|
+
'status.waitingApproval': '等待批准',
|
|
88
|
+
'status.planReview': '等待确认计划',
|
|
89
|
+
'status.waitingAnswer': '等待回答',
|
|
90
|
+
'errors.reorderFailed': '工作区排序更新失败',
|
|
91
|
+
'errors.invalidParent': 'The parent workspace directory is not usable.',
|
|
92
|
+
'errors.unreadable': 'The new directory could not be read.',
|
|
93
|
+
},
|
|
94
|
+
en: {
|
|
95
|
+
'heading.default': 'Workspaces',
|
|
96
|
+
'heading.hint': 'Double-click to rename; clear it to restore the default',
|
|
97
|
+
'menu.addChild': 'Add child workspace',
|
|
98
|
+
'actions.addWorkspace': 'Add workspace',
|
|
99
|
+
'actions.newSession': 'New session',
|
|
100
|
+
'actions.search': 'Search workspaces or sessions',
|
|
101
|
+
'actions.menu': 'More actions',
|
|
102
|
+
'actions.rename': 'Rename',
|
|
103
|
+
'actions.delete': 'Delete workspace',
|
|
104
|
+
'actions.unarchive': 'Unarchive',
|
|
105
|
+
'actions.create': 'Create',
|
|
106
|
+
'actions.cancel': 'Cancel',
|
|
107
|
+
'actions.confirm': 'Delete',
|
|
108
|
+
'dialog.rename.title': 'Rename workspace',
|
|
109
|
+
'dialog.delete.title': 'Delete workspace',
|
|
110
|
+
'dialog.delete.description': 'This removes "{name}" from the sidebar. Files on disk are kept.',
|
|
111
|
+
'renamed': 'Renamed',
|
|
112
|
+
'deleted': 'Workspace deleted',
|
|
113
|
+
'dialog.addChild.title': 'Add child workspace',
|
|
114
|
+
'dialog.addWorkspace.title': 'Add workspace',
|
|
115
|
+
'dialog.addChild.description': 'A new child workspace directory will be created under {parent}.',
|
|
116
|
+
'dialog.addWorkspace.description': 'Enter the absolute path of the workspace directory, or leave it empty to pick a folder.',
|
|
117
|
+
'field.name': 'Child workspace name',
|
|
118
|
+
'field.path': 'Workspace path (empty to pick)',
|
|
119
|
+
'errors.nameRequired': 'Enter a name.',
|
|
120
|
+
'errors.nameInvalid': 'The name must not contain path separators.',
|
|
121
|
+
'errors.exists': 'A directory with that name already exists.',
|
|
122
|
+
'errors.createFailed': 'Could not create: {message}',
|
|
123
|
+
'errors.renameFailed': 'Could not rename: {message}',
|
|
124
|
+
'errors.deleteFailed': 'Could not delete: {message}',
|
|
125
|
+
'actions.moveTo': 'Move to',
|
|
126
|
+
'actions.showArchived': 'Show archived sessions',
|
|
127
|
+
'actions.hideArchived': 'Hide archived sessions',
|
|
128
|
+
'created': 'Workspace created',
|
|
129
|
+
'createdChild': 'Child workspace created',
|
|
130
|
+
'moved': 'Session moved',
|
|
131
|
+
'rail.search': 'Search',
|
|
132
|
+
'expandGroup': 'Expand group',
|
|
133
|
+
'collapseGroup': 'Collapse group',
|
|
134
|
+
'session.new': 'New session',
|
|
135
|
+
'session.untitled': 'Untitled session',
|
|
136
|
+
'ungrouped': 'Ungrouped',
|
|
137
|
+
'empty': 'No sessions',
|
|
138
|
+
'search.empty': 'No matches',
|
|
139
|
+
'time.now': 'now',
|
|
140
|
+
'time.minutes': '{n}min',
|
|
141
|
+
'time.hours': '{n}h',
|
|
142
|
+
'time.days': '{n}d',
|
|
143
|
+
'time.months': '{n}mo',
|
|
144
|
+
'time.years': '{n}y',
|
|
145
|
+
'time.ago': '{t} ago',
|
|
146
|
+
'actions.pin': 'Pin',
|
|
147
|
+
'actions.unpin': 'Unpin',
|
|
148
|
+
'row.pinned': 'Pinned',
|
|
149
|
+
'errors.pinFailed': 'Could not update the pin',
|
|
150
|
+
'status.running': 'Working',
|
|
151
|
+
'status.subagentsRunning': '{n} subagents running',
|
|
152
|
+
'status.completed': 'Completed',
|
|
153
|
+
'status.waitingApproval': 'Waiting for approval',
|
|
154
|
+
'status.planReview': 'Waiting for plan review',
|
|
155
|
+
'status.waitingAnswer': 'Waiting for an answer',
|
|
156
|
+
'errors.reorderFailed': 'Could not reorder the workspace',
|
|
157
|
+
'errors.invalidParent': 'The parent workspace directory is not usable.',
|
|
158
|
+
'errors.unreadable': 'The new directory could not be read.',
|
|
159
|
+
},
|
|
160
|
+
ja: {
|
|
161
|
+
'heading.default': 'ワークスペース',
|
|
162
|
+
'heading.hint': 'ダブルクリックで名前を変更、空欄で既定に戻す',
|
|
163
|
+
'menu.addChild': '子ワークスペースを追加',
|
|
164
|
+
'actions.addWorkspace': 'ワークスペースを追加',
|
|
165
|
+
'actions.newSession': '新しいセッション',
|
|
166
|
+
'actions.search': '検索',
|
|
167
|
+
'actions.menu': 'その他の操作',
|
|
168
|
+
'actions.rename': '名前を変更',
|
|
169
|
+
'actions.delete': 'ワークスペースを削除',
|
|
170
|
+
'actions.unarchive': 'アーカイブ解除',
|
|
171
|
+
'actions.create': '作成',
|
|
172
|
+
'actions.cancel': 'キャンセル',
|
|
173
|
+
'actions.confirm': '削除',
|
|
174
|
+
'dialog.rename.title': 'ワークスペース名を変更',
|
|
175
|
+
'dialog.delete.title': 'ワークスペースを削除',
|
|
176
|
+
'dialog.delete.description': '「{name}」をサイドバーから削除します。ディスク上のファイルは残ります。',
|
|
177
|
+
'renamed': '名前を変更しました',
|
|
178
|
+
'deleted': 'ワークスペースを削除しました',
|
|
179
|
+
'dialog.addChild.title': '子ワークスペースを追加',
|
|
180
|
+
'dialog.addWorkspace.title': 'ワークスペースを追加',
|
|
181
|
+
'dialog.addChild.description': '{parent} の下に子ワークスペースを作成します。',
|
|
182
|
+
'dialog.addWorkspace.description': 'ワークスペースの絶対パスを入力するか、空欄のままフォルダを選択してください。',
|
|
183
|
+
'field.name': '子ワークスペース名',
|
|
184
|
+
'field.path': 'ワークスペースのパス(空欄で選択)',
|
|
185
|
+
'errors.nameRequired': '名前を入力してください。',
|
|
186
|
+
'errors.nameInvalid': '名前にパス区切り文字は使えません。',
|
|
187
|
+
'errors.exists': '同じ名前のディレクトリが既に存在します。',
|
|
188
|
+
'errors.createFailed': '作成できませんでした: {message}',
|
|
189
|
+
'errors.renameFailed': '名前を変更できませんでした: {message}',
|
|
190
|
+
'errors.deleteFailed': '削除できませんでした: {message}',
|
|
191
|
+
'actions.moveTo': '移動先',
|
|
192
|
+
'actions.showArchived': 'アーカイブ済みを表示',
|
|
193
|
+
'actions.hideArchived': 'アーカイブ済みを隠す',
|
|
194
|
+
'created': 'ワークスペースを作成しました',
|
|
195
|
+
'createdChild': '子ワークスペースを作成しました',
|
|
196
|
+
'moved': 'セッションを移動しました',
|
|
197
|
+
'rail.search': '検索',
|
|
198
|
+
'expandGroup': 'グループを開く',
|
|
199
|
+
'collapseGroup': 'グループを閉じる',
|
|
200
|
+
'session.new': '新しいセッション',
|
|
201
|
+
'session.untitled': '無題のセッション',
|
|
202
|
+
'ungrouped': '未分類',
|
|
203
|
+
'empty': 'セッションはありません',
|
|
204
|
+
'search.empty': '一致する項目はありません',
|
|
205
|
+
'time.now': '今',
|
|
206
|
+
'time.minutes': '{n}分',
|
|
207
|
+
'time.hours': '{n}時間',
|
|
208
|
+
'time.days': '{n}日',
|
|
209
|
+
'time.months': '{n}か月',
|
|
210
|
+
'time.years': '{n}年',
|
|
211
|
+
'time.ago': '{t}前',
|
|
212
|
+
'actions.pin': 'ピン留め',
|
|
213
|
+
'actions.unpin': 'ピン留めを解除',
|
|
214
|
+
'row.pinned': 'ピン留め済み',
|
|
215
|
+
'errors.pinFailed': 'ピン留めを更新できませんでした',
|
|
216
|
+
'status.running': '実行中',
|
|
217
|
+
'status.subagentsRunning': '{n}件のサブエージェントが実行中',
|
|
218
|
+
'status.completed': '完了',
|
|
219
|
+
'status.waitingApproval': '承認待ち',
|
|
220
|
+
'status.planReview': 'プラン確認待ち',
|
|
221
|
+
'status.waitingAnswer': '回答待ち',
|
|
222
|
+
'errors.reorderFailed': 'ワークスペースの並び順を更新できませんでした',
|
|
223
|
+
'errors.invalidParent': '親ワークスペースのディレクトリを使用できません。',
|
|
224
|
+
'errors.unreadable': '作成したディレクトリを読み取れませんでした。',
|
|
225
|
+
},
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/* ------------------------------------------------------------------- styles */
|
|
229
|
+
|
|
230
|
+
const CSS = `
|
|
231
|
+
.dnw-root{display:flex;flex-direction:column;min-height:0;height:100%;color:var(--dsw-alias-label-primary)}
|
|
232
|
+
.dnw-header{flex:none;display:flex;align-items:center;gap:4px;height:36px;padding-left:var(--dsh-sidebar-row-padding,12px);box-sizing:border-box;border-radius:var(--dsw-radius-md);overflow:hidden;color:var(--dsw-alias-label-tertiary)}
|
|
233
|
+
.dnw-label{position:relative;left:-1px;flex:none;max-width:45%;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;line-height:20px;font-size:14px;color:var(--dsw-alias-label-tertiary);user-select:none}
|
|
234
|
+
.dnw-labelEditable{cursor:text;border-radius:var(--dsw-radius-xs);padding:0 2px;margin:0 -2px}
|
|
235
|
+
.dnw-labelEditable:hover{color:var(--dsw-alias-label-secondary)}
|
|
236
|
+
.dnw-headingInput{flex:1;min-width:0;margin:0;padding:0 2px;font:inherit;font-size:14px;line-height:20px;color:var(--dsw-alias-label-primary);background:transparent;border:0.5px solid var(--dsw-alias-border-l4);border-radius:var(--dsw-radius-md);outline:none}
|
|
237
|
+
.dnw-headerActions{display:flex;align-items:center;gap:4px;flex:none;margin-left:auto}
|
|
238
|
+
.dnw-iconButton{display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;padding:0;border:none;border-radius:var(--dsw-radius-sm,6px);background:transparent;color:var(--dsw-alias-label-tertiary);cursor:pointer}
|
|
239
|
+
.dnw-iconButton:hover{background-color:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
|
|
240
|
+
.dnw-iconButtonOn{background-color:var(--dsw-alias-interactive-bg-active);color:var(--dsw-alias-label-primary)}
|
|
241
|
+
.dnw-rowDragging{opacity:0.5}
|
|
242
|
+
.dnw-iconButton:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:1px}
|
|
243
|
+
.dnw-list{flex:1;min-height:0;overflow-y:auto;overflow-x:hidden;padding-bottom:8px;scrollbar-width:thin}
|
|
244
|
+
.dnw-searchRow{padding:0 8px 4px;padding-left:var(--dsh-sidebar-row-padding,12px)}
|
|
245
|
+
.dnw-searchInput{width:100%;box-sizing:border-box;height:32px;padding:0 4px 0 0;font:inherit;font-size:13px;line-height:18px;color:var(--dsw-alias-label-primary);background:transparent;border:0.5px solid var(--dsw-alias-border-l4);border-radius:var(--dsw-radius-md);outline:none}
|
|
246
|
+
.dnw-searchInput:focus{border-color:var(--dsw-alias-state-business-primary)}
|
|
247
|
+
.dnw-row{display:flex;align-items:center;gap:var(--dsh-sidebar-label-gap,6px);height:32px;padding:0 8px;padding-inline-start:calc(var(--dsh-sidebar-row-padding,12px) - var(--dsh-sidebar-paint-inset,3px) + var(--dnw-indent,0px));border-inline:var(--dsh-sidebar-paint-inset,3px) solid transparent;background-clip:padding-box;border-radius:var(--dsw-radius-md);cursor:pointer;user-select:none;position:relative;color:var(--dsw-alias-label-primary)}
|
|
248
|
+
@media (hover:hover){.dnw-row:hover{background-color:var(--dsw-alias-interactive-bg-hover)}}
|
|
249
|
+
.dnw-rowSelected{background-color:var(--dsw-alias-interactive-bg-hover)}
|
|
250
|
+
.dnw-row:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:-2px}
|
|
251
|
+
.dnw-slot{flex:none;display:inline-flex;align-items:center;justify-content:center;width:16px;height:20px;color:var(--dsw-alias-label-tertiary)}
|
|
252
|
+
.dnw-lead{position:relative}
|
|
253
|
+
.dnw-folderIcon{display:inline-flex;align-items:center;justify-content:center;width:16px;height:20px;color:var(--dsw-alias-label-tertiary)}
|
|
254
|
+
.dnw-folderActive{color:var(--dsw-alias-state-business-primary)}
|
|
255
|
+
.dnw-chevron{flex:none;display:none;align-items:center;justify-content:center;width:16px;height:20px;padding:0;border:none;background:transparent;color:var(--dsw-alias-label-caption);cursor:pointer}
|
|
256
|
+
.dnw-workspaceRow:hover .dnw-folderIcon,.dnw-workspaceRow:focus-within .dnw-folderIcon{display:none}
|
|
257
|
+
.dnw-workspaceRow:hover .dnw-chevron,.dnw-workspaceRow:focus-within .dnw-chevron,.dnw-workspaceRow:has(.dnw-chevronOpen) .dnw-chevron{display:inline-flex}
|
|
258
|
+
.dnw-workspaceRow:has(.dnw-chevronOpen) .dnw-folderIcon{display:none}
|
|
259
|
+
@media (hover:none){.dnw-chevron{display:inline-flex}.dnw-folderIcon{display:none}}
|
|
260
|
+
.dnw-arrowInner{display:inline-flex;transition:transform 150ms var(--ds-ease-in-out,ease)}
|
|
261
|
+
.dnw-chevronOpen .dnw-arrowInner{transform:rotate(90deg)}
|
|
262
|
+
.dnw-title{min-width:0;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:14px;line-height:20px}
|
|
263
|
+
.dnw-titleMuted{color:var(--dsw-alias-label-caption)}
|
|
264
|
+
.dnw-rowArchived .dnw-title{color:var(--dsw-alias-label-caption)}
|
|
265
|
+
.dnw-actions{flex:none;display:none;align-items:center;gap:13px}
|
|
266
|
+
.dnw-row:hover .dnw-actions,.dnw-actionsOpen{display:flex}
|
|
267
|
+
.dnw-resting{flex:none;display:inline-flex;align-items:center;gap:6px}
|
|
268
|
+
.dnw-time{flex:none;font-size:10px;line-height:16px;color:var(--dsw-alias-label-tertiary);margin-inline-end:-1px}
|
|
269
|
+
.dnw-pinIndicator{display:inline-flex;flex:none;width:16px;height:20px;align-items:center;justify-content:center;color:var(--dsw-alias-label-caption)}
|
|
270
|
+
@media (hover:hover){.dnw-row:hover .dnw-resting,html[data-input-modality='keyboard'] .dnw-row:focus-within .dnw-resting{display:none}}
|
|
271
|
+
.dnw-row:has(.dnw-actionsOpen) .dnw-resting{display:none}
|
|
272
|
+
@media (hover:none){.dnw-actions{display:flex}.dnw-resting{display:none}}
|
|
273
|
+
.dnw-stateDot{position:relative;display:inline-block;flex:none;border-radius:50%}
|
|
274
|
+
.dnw-stateDot::after{content:"";position:absolute;inset:20%;border-radius:50%;background:currentColor}
|
|
275
|
+
.dnw-stateDot[data-state=done]{color:var(--dsw-alias-state-success-primary)}
|
|
276
|
+
.dnw-stateDot[data-state=warning]{color:var(--dsw-alias-state-warn-primary)}
|
|
277
|
+
.dnw-stateDot[data-state=error]{color:var(--dsw-alias-state-error-primary)}
|
|
278
|
+
.dnw-spinner{flex:none;color:var(--dsw-alias-label-tertiary)}
|
|
279
|
+
.dnw-spinnerMotion{transform-origin:center;animation:dnw-state-dot-spin 1.5s linear infinite}
|
|
280
|
+
.dnw-spinnerTrack,.dnw-spinnerArc{fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round}
|
|
281
|
+
.dnw-spinnerTrack{opacity:.25}
|
|
282
|
+
.dnw-spinnerArc{stroke-dasharray:12 150;animation:dnw-state-dot-dash 1.5s ease-in-out infinite}
|
|
283
|
+
@keyframes dnw-state-dot-spin{to{transform:rotate(360deg)}}
|
|
284
|
+
@keyframes dnw-state-dot-dash{0%{stroke-dasharray:12 150;stroke-dashoffset:0}50%{stroke-dasharray:24 150;stroke-dashoffset:-6}to{stroke-dasharray:12 150;stroke-dashoffset:0}}
|
|
285
|
+
@media (prefers-reduced-motion:reduce){.dnw-spinnerMotion,.dnw-spinnerArc{animation:none}.dnw-spinnerArc{stroke-dasharray:18 150;stroke-dashoffset:-3}}
|
|
286
|
+
.dnw-visuallyHidden{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}
|
|
287
|
+
.dnw-empty{padding:2px 8px 4px;padding-inline-start:calc(var(--dsh-sidebar-row-padding,12px) + 22px + var(--dnw-indent,0px));font-size:13px;line-height:20px;color:var(--dsw-alias-label-caption)}
|
|
288
|
+
.dnw-dropBefore::before,.dnw-dropAfter::after{content:"";position:absolute;left:calc(-1 * var(--dsh-sidebar-paint-inset,3px));right:calc(4px - var(--dsh-sidebar-paint-inset,3px));height:2px;border-radius:1px;background:var(--dsw-alias-state-business-primary)}
|
|
289
|
+
.dnw-dropBefore::before{top:-8px}
|
|
290
|
+
.dnw-dropAfter::after{bottom:-8px}
|
|
291
|
+
.dnw-dropOn{background-color:var(--dsw-alias-interactive-bg-hover);box-shadow:inset 0 0 0 1px var(--dsw-alias-state-business-primary)}
|
|
292
|
+
.dnw-rail{display:flex;flex-direction:column;align-items:center;gap:6px;padding:6px 0}
|
|
293
|
+
.dnw-railButton{display:inline-flex;align-items:center;justify-content:center;width:36px;height:36px;padding:0;border:none;border-radius:var(--dsw-radius-md);background:transparent;color:var(--dsw-alias-label-tertiary);cursor:pointer}
|
|
294
|
+
.dnw-railButton:hover{background-color:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
|
|
295
|
+
.dnw-scrim{position:fixed;inset:0;z-index:2147483000;display:flex;align-items:center;justify-content:center;padding:24px;background:rgba(0,0,0,.32)}
|
|
296
|
+
.dnw-dialog{width:min(420px,100%);display:flex;flex-direction:column;gap:12px;padding:18px;border-radius:var(--dsw-radius-lg,12px);background:var(--dsw-alias-bg-elevated,#fff);color:var(--dsw-alias-label-primary);box-shadow:0 18px 48px rgba(0,0,0,.28);font-size:14px;line-height:20px}
|
|
297
|
+
.dnw-dialogTitle{font-size:15px;font-weight:600;line-height:22px}
|
|
298
|
+
.dnw-dialogText{font-size:13px;line-height:19px;color:var(--dsw-alias-label-secondary);word-break:break-all}
|
|
299
|
+
.dnw-dialogInput{width:100%;box-sizing:border-box;height:44px;padding:0 10px;font:inherit;font-size:14px;line-height:22px;color:var(--dsw-alias-label-primary);background:transparent;border:0.5px solid var(--dsw-alias-border-l4);border-radius:var(--dsw-radius-lg,12px);outline:none}
|
|
300
|
+
.dnw-dialogInput:focus{border-color:var(--dsw-alias-state-business-primary)}
|
|
301
|
+
.dnw-dialogError{font-size:13px;line-height:19px;color:var(--dsw-alias-state-error-primary,#d33)}
|
|
302
|
+
.dnw-dialogFooter{display:flex;justify-content:flex-end;gap:8px;margin-top:2px}
|
|
303
|
+
.dnw-button{height:32px;padding:0 14px;font:inherit;font-size:13px;line-height:30px;border-radius:var(--dsw-radius-md,8px);border:0.5px solid var(--dsw-alias-border-l4);background:transparent;color:var(--dsw-alias-label-primary);cursor:pointer}
|
|
304
|
+
.dnw-button:hover{background-color:var(--dsw-alias-interactive-bg-hover)}
|
|
305
|
+
.dnw-buttonPrimary{border-color:transparent;background:var(--dsw-alias-state-business-primary);color:#fff}
|
|
306
|
+
.dnw-buttonDanger{background:var(--dsw-alias-state-error-primary,#d33)}
|
|
307
|
+
.dnw-button:disabled{opacity:.5;cursor:default}
|
|
308
|
+
.dnw-menu{position:fixed;z-index:2147483001;min-width:184px;padding:4px;display:flex;flex-direction:column;gap:1px;border-radius:var(--dsw-radius-md,8px);background:var(--dsw-alias-bg-elevated,#fff);box-shadow:0 10px 30px rgba(0,0,0,.22),0 0 0 0.5px var(--dsw-alias-border-l4,rgba(0,0,0,.08));font-size:13px;line-height:18px}
|
|
309
|
+
.dnw-menuItem{display:flex;align-items:center;gap:8px;width:100%;padding:6px 8px;border:none;border-radius:var(--dsw-radius-xs);background:transparent;color:var(--dsw-alias-label-primary);font:inherit;text-align:start;cursor:pointer}
|
|
310
|
+
.dnw-menuItem:hover,.dnw-menuItem:focus-visible,.dnw-menuItemActive{background-color:var(--dsw-alias-interactive-bg-hover);outline:none}
|
|
311
|
+
.dnw-menuItemDanger{color:var(--dsw-alias-state-error-primary,#d33)}
|
|
312
|
+
.dnw-menuIcon{flex:none;display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;color:var(--dsw-alias-label-tertiary)}
|
|
313
|
+
.dnw-menuItemDanger .dnw-menuIcon{color:inherit}
|
|
314
|
+
.dnw-menuSeparator{height:1px;margin:4px 6px;background:var(--dsw-alias-border-l4,rgba(0,0,0,.08))}
|
|
315
|
+
@media (prefers-reduced-motion: reduce){.dnw-arrowInner{transition:none}}
|
|
316
|
+
@media (pointer:coarse){.dnw-searchInput,.dnw-headingInput,.dnw-dialogInput{font-size:16px}}
|
|
317
|
+
`
|
|
318
|
+
function ensureStyles() {
|
|
319
|
+
const head = typeof document === 'undefined' || document === null ? null : document.head
|
|
320
|
+
if (head === null) return () => {}
|
|
321
|
+
let element = head.querySelector('style[data-plugin-css="' + STYLE_ID + '"]')
|
|
322
|
+
if (element === null) {
|
|
323
|
+
element = document.createElement('style')
|
|
324
|
+
element.setAttribute('data-plugin-css', STYLE_ID)
|
|
325
|
+
element.textContent = CSS
|
|
326
|
+
head.appendChild(element)
|
|
327
|
+
return () => {
|
|
328
|
+
element.remove()
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
element.textContent = CSS
|
|
332
|
+
return () => {}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/* -------------------------------------------------------------------- icons */
|
|
336
|
+
|
|
337
|
+
const svg = (children, extra) =>
|
|
338
|
+
h(
|
|
339
|
+
'svg',
|
|
340
|
+
Object.assign(
|
|
341
|
+
{
|
|
342
|
+
width: 16,
|
|
343
|
+
height: 16,
|
|
344
|
+
viewBox: '0 0 20 20',
|
|
345
|
+
fill: 'none',
|
|
346
|
+
stroke: 'currentColor',
|
|
347
|
+
strokeWidth: 1.6,
|
|
348
|
+
strokeLinecap: 'round',
|
|
349
|
+
strokeLinejoin: 'round',
|
|
350
|
+
'aria-hidden': 'true',
|
|
351
|
+
focusable: 'false',
|
|
352
|
+
},
|
|
353
|
+
extra || null,
|
|
354
|
+
),
|
|
355
|
+
children,
|
|
356
|
+
)
|
|
357
|
+
|
|
358
|
+
const IconChevron = () => svg(h('path', { key: 'p', d: 'M8 5l4.5 5L8 15' }))
|
|
359
|
+
const IconFolder = () => svg(h('path', { key: 'p', d: 'M3 6.5A1.5 1.5 0 014.5 5h3l1.6 2h6.4A1.5 1.5 0 0117 8.5v6A1.5 1.5 0 0115.5 16h-11A1.5 1.5 0 013 14.5z' }))
|
|
360
|
+
const IconFolderPlus = () =>
|
|
361
|
+
svg([h('path', { key: 'a', d: 'M3 6.5A1.5 1.5 0 014.5 5h3l1.6 2h6.4A1.5 1.5 0 0117 8.5v6A1.5 1.5 0 0115.5 16h-11A1.5 1.5 0 013 14.5z' }), h('path', { key: 'b', d: 'M10 10.5v3M8.5 12h3' })])
|
|
362
|
+
const IconPlus = () => svg(h('path', { key: 'p', d: 'M10 4.5v11M4.5 10h11' }))
|
|
363
|
+
const IconSearch = () => svg([h('circle', { key: 'c', cx: 9, cy: 9, r: 5 }), h('path', { key: 'p', d: 'M12.8 12.8L16.5 16.5' })])
|
|
364
|
+
const IconDots = () => svg([h('circle', { key: 'a', cx: 5, cy: 10, r: 1.2, fill: 'currentColor', stroke: 'none' }), h('circle', { key: 'b', cx: 10, cy: 10, r: 1.2, fill: 'currentColor', stroke: 'none' }), h('circle', { key: 'c', cx: 15, cy: 10, r: 1.2, fill: 'currentColor', stroke: 'none' })])
|
|
365
|
+
const IconEdit = () => svg([h('path', { key: 'a', d: 'M4 16h3l8.2-8.2a1.6 1.6 0 000-2.3l-.7-.7a1.6 1.6 0 00-2.3 0L4 13z' }), h('path', { key: 'b', d: 'M12.4 6.2l1.4 1.4' })])
|
|
366
|
+
const IconTrash = () => svg([h('path', { key: 'a', d: 'M4.5 6.5h11' }), h('path', { key: 'b', d: 'M8 6.5V4.8h4v1.7' }), h('path', { key: 'c', d: 'M6 6.5l.7 9h6.6l.7-9' })])
|
|
367
|
+
const IconClose = () => svg([h('path', { key: 'p', d: 'M6 6l8 8M14 6l-8 8' })])
|
|
368
|
+
const IconArchive = () =>
|
|
369
|
+
svg([h('path', { key: 'a', d: 'M3.5 5.5h13v3h-13z' }), h('path', { key: 'b', d: 'M4.8 8.5v6.2h10.4V8.5' }), h('path', { key: 'c', d: 'M8 11.2h4' })])
|
|
370
|
+
const IconUnarchive = () =>
|
|
371
|
+
svg([
|
|
372
|
+
h('path', { key: 'a', d: 'M3.5 5.5h13v3h-13z' }),
|
|
373
|
+
h('path', { key: 'b', d: 'M4.8 8.5v6.2h10.4V8.5' }),
|
|
374
|
+
h('path', { key: 'c', d: 'M10 13.4V9.9M8.4 11.5L10 9.9l1.6 1.6' }),
|
|
375
|
+
])
|
|
376
|
+
/* A pushed-in pin, drawn solid so it reads at 14px in a 16px cell. */
|
|
377
|
+
const IconPin = () =>
|
|
378
|
+
svg(
|
|
379
|
+
[
|
|
380
|
+
h('path', { key: 'a', d: 'M7.2 3h5.6l-.7 4.1 2.4 2.1-.5 1.3H5.9l-.5-1.3 2.4-2.1z', fill: 'currentColor', stroke: 'none' }),
|
|
381
|
+
h('path', { key: 'b', d: 'M10 10.5V17' }),
|
|
382
|
+
],
|
|
383
|
+
{ strokeWidth: 1.4 },
|
|
384
|
+
)
|
|
385
|
+
const IconPinOutline = () =>
|
|
386
|
+
svg([
|
|
387
|
+
h('path', { key: 'a', d: 'M7.2 3h5.6l-.7 4.1 2.4 2.1-.5 1.3H5.9l-.5-1.3 2.4-2.1z' }),
|
|
388
|
+
h('path', { key: 'b', d: 'M10 10.5V17' }),
|
|
389
|
+
])
|
|
390
|
+
|
|
391
|
+
/* ---------------------------------------------------------------- utilities */
|
|
392
|
+
|
|
393
|
+
const cls = (...parts) => parts.filter(Boolean).join(' ')
|
|
394
|
+
|
|
395
|
+
const MINUTE_MS = 60 * 1000
|
|
396
|
+
const HOUR_MS = 60 * MINUTE_MS
|
|
397
|
+
const DAY_MS = 24 * HOUR_MS
|
|
398
|
+
const MONTH_MS = 30 * DAY_MS
|
|
399
|
+
const YEAR_MS = 365 * DAY_MS
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Coarse age bucket of one timestamp, mirroring the shipped row labels.
|
|
403
|
+
* @returns {{unit: 'now'|'minutes'|'hours'|'days'|'months'|'years', n: number}}
|
|
404
|
+
*/
|
|
405
|
+
function relativeTime(updatedAt, now) {
|
|
406
|
+
/* `updatedAt` is epoch milliseconds on a live SessionSummary; a fixture or
|
|
407
|
+
* a future shape may hand us something else, and a "NaN分钟" label is
|
|
408
|
+
* worse than no label at all. */
|
|
409
|
+
const stamp = typeof updatedAt === 'number' ? updatedAt : typeof updatedAt === 'string' ? Date.parse(updatedAt) : Number(updatedAt)
|
|
410
|
+
if (!Number.isFinite(stamp) || !Number.isFinite(now)) return { unit: 'now', n: 0 }
|
|
411
|
+
const age = Math.max(0, now - stamp)
|
|
412
|
+
if (age < MINUTE_MS) return { unit: 'now', n: 0 }
|
|
413
|
+
if (age < HOUR_MS) return { unit: 'minutes', n: Math.floor(age / MINUTE_MS) }
|
|
414
|
+
if (age < DAY_MS) return { unit: 'hours', n: Math.floor(age / HOUR_MS) }
|
|
415
|
+
if (age < MONTH_MS) return { unit: 'days', n: Math.floor(age / DAY_MS) }
|
|
416
|
+
if (age < YEAR_MS) return { unit: 'months', n: Math.floor(age / MONTH_MS) }
|
|
417
|
+
return { unit: 'years', n: Math.floor(age / YEAR_MS) }
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/** Compact resting label: 刚刚 / 12分钟 / 3小时 / 2天 … */
|
|
421
|
+
function timeLabel(updatedAt, now, t) {
|
|
422
|
+
const { unit, n } = relativeTime(updatedAt, now)
|
|
423
|
+
return unit === 'now' ? t('time.now') : t('time.' + unit, { n })
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/** Full sentence for the tooltip: 刚才 / 12分钟前 … */
|
|
427
|
+
function hoverTimeLabel(updatedAt, now, t) {
|
|
428
|
+
const { unit, n } = relativeTime(updatedAt, now)
|
|
429
|
+
return unit === 'now' ? t('time.now') : t('time.ago', { t: t('time.' + unit, { n }) })
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/** Shipped runningChildCount: sessions in this one's subagent catalog still running. */
|
|
433
|
+
function runningSubagentCount(list, parentId, statuses) {
|
|
434
|
+
const entry = list !== null && list !== undefined && list.projectionsBySession !== undefined ? list.projectionsBySession[parentId] : undefined
|
|
435
|
+
const catalog = entry !== undefined && entry !== null && entry.values !== undefined ? entry.values.subagentCatalog : undefined
|
|
436
|
+
if (!Array.isArray(catalog)) return 0
|
|
437
|
+
let count = 0
|
|
438
|
+
for (const child of catalog) {
|
|
439
|
+
const childStatus = statuses.get(child.id)
|
|
440
|
+
const running = childStatus === undefined ? list.byId[child.id] !== undefined && list.byId[child.id].running === true : childStatus.running === true
|
|
441
|
+
if (running) count += 1
|
|
442
|
+
}
|
|
443
|
+
return count
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/* The shipped browser's working indicator: a 14px stroked arc that spins
|
|
447
|
+
* while the stroke length breathes. Both keyframes and the reduced-motion
|
|
448
|
+
* fallback live in the stylesheet below. */
|
|
449
|
+
function StatusSpinner() {
|
|
450
|
+
return h(
|
|
451
|
+
'svg',
|
|
452
|
+
{
|
|
453
|
+
className: 'dnw-spinner',
|
|
454
|
+
'data-state': 'ongoing',
|
|
455
|
+
width: '14',
|
|
456
|
+
height: '14',
|
|
457
|
+
viewBox: '0 0 24 24',
|
|
458
|
+
'aria-hidden': 'true',
|
|
459
|
+
focusable: 'false',
|
|
460
|
+
},
|
|
461
|
+
h(
|
|
462
|
+
'g',
|
|
463
|
+
{ className: 'dnw-spinnerMotion' },
|
|
464
|
+
h('circle', { className: 'dnw-spinnerTrack', cx: '12', cy: '12', r: '9.5' }),
|
|
465
|
+
h('circle', { className: 'dnw-spinnerArc', cx: '12', cy: '12', r: '9.5' }),
|
|
466
|
+
),
|
|
467
|
+
)
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
function isRecord(value) {
|
|
471
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
function folderPath(path) {
|
|
475
|
+
const windows = /^[A-Za-z]:[/\\]/.test(path) || path.startsWith('\\\\')
|
|
476
|
+
const normalized = windows ? path.replaceAll('\\', '/') : path
|
|
477
|
+
return normalized.replace(/\/+$/, '')
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/** Longest registered ancestor directory of `path`, returned in its original form. */
|
|
481
|
+
function owningParentPath(path, roots) {
|
|
482
|
+
const child = folderPath(path)
|
|
483
|
+
let best = null
|
|
484
|
+
let bestLength = -1
|
|
485
|
+
for (const root of roots) {
|
|
486
|
+
if (root === path) continue
|
|
487
|
+
const parent = folderPath(root)
|
|
488
|
+
if (parent === '' || child === parent) continue
|
|
489
|
+
if (!child.startsWith(parent + '/')) continue
|
|
490
|
+
if (parent.length > bestLength) {
|
|
491
|
+
best = root
|
|
492
|
+
bestLength = parent.length
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return best
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function createSignal(initial) {
|
|
499
|
+
let value = initial
|
|
500
|
+
const listeners = new Set()
|
|
501
|
+
return {
|
|
502
|
+
get: () => value,
|
|
503
|
+
set(next) {
|
|
504
|
+
if (Object.is(next, value)) return
|
|
505
|
+
value = next
|
|
506
|
+
for (const listener of listeners) listener()
|
|
507
|
+
},
|
|
508
|
+
subscribe(listener) {
|
|
509
|
+
listeners.add(listener)
|
|
510
|
+
return () => {
|
|
511
|
+
listeners.delete(listener)
|
|
512
|
+
}
|
|
513
|
+
},
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function createStore() {
|
|
518
|
+
const read = () => {
|
|
519
|
+
const empty = { title: null, assign: {}, order: {}, collapsed: {} }
|
|
520
|
+
if (typeof localStorage === 'undefined') return empty
|
|
521
|
+
try {
|
|
522
|
+
const raw = localStorage.getItem(STORAGE_KEY)
|
|
523
|
+
if (raw === null || raw === '') return empty
|
|
524
|
+
const parsed = JSON.parse(raw)
|
|
525
|
+
if (!isRecord(parsed)) return empty
|
|
526
|
+
return {
|
|
527
|
+
title: typeof parsed.title === 'string' && parsed.title.trim() !== '' ? parsed.title : null,
|
|
528
|
+
assign: isRecord(parsed.assign) ? parsed.assign : {},
|
|
529
|
+
order: isRecord(parsed.order) ? parsed.order : {},
|
|
530
|
+
collapsed: isRecord(parsed.collapsed) ? parsed.collapsed : {},
|
|
531
|
+
}
|
|
532
|
+
} catch {
|
|
533
|
+
return empty
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
let state = read()
|
|
537
|
+
const listeners = new Set()
|
|
538
|
+
const write = () => {
|
|
539
|
+
if (typeof localStorage === 'undefined') return
|
|
540
|
+
try {
|
|
541
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(state))
|
|
542
|
+
} catch {
|
|
543
|
+
/* storage full or blocked: the view still works for this tab */
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
return {
|
|
547
|
+
get: () => state,
|
|
548
|
+
subscribe(listener) {
|
|
549
|
+
listeners.add(listener)
|
|
550
|
+
return () => {
|
|
551
|
+
listeners.delete(listener)
|
|
552
|
+
}
|
|
553
|
+
},
|
|
554
|
+
update(recipe) {
|
|
555
|
+
state = recipe(state)
|
|
556
|
+
write()
|
|
557
|
+
for (const listener of listeners) listener()
|
|
558
|
+
},
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Re-home one session inside the plugin's own grouping. The workspace
|
|
564
|
+
* controller refuses to move a session into a workspace whose path is not
|
|
565
|
+
* the session's recorded cwd, so this is a display assignment: the row is
|
|
566
|
+
* rendered under `groupKey` while its cwd stays untouched.
|
|
567
|
+
*/
|
|
568
|
+
function assignSessionIn(store, items, sessionId, groupKey, beforeSessionId) {
|
|
569
|
+
if (typeof sessionId !== 'string' || sessionId === '') return
|
|
570
|
+
store.update(current => {
|
|
571
|
+
const known = new Set()
|
|
572
|
+
let realOwner = null
|
|
573
|
+
for (const item of items) {
|
|
574
|
+
known.add(item.workspaceId)
|
|
575
|
+
if (realOwner === null && item.sessionIds.includes(sessionId)) realOwner = item.workspaceId
|
|
576
|
+
}
|
|
577
|
+
const assigned = current.assign[sessionId]
|
|
578
|
+
const previousKey =
|
|
579
|
+
typeof assigned === 'string' && known.has(assigned)
|
|
580
|
+
? assigned
|
|
581
|
+
: realOwner === null
|
|
582
|
+
? UNGROUPED
|
|
583
|
+
: realOwner
|
|
584
|
+
|
|
585
|
+
const assign = { ...current.assign }
|
|
586
|
+
if (groupKey === UNGROUPED || groupKey === realOwner) delete assign[sessionId]
|
|
587
|
+
else assign[sessionId] = groupKey
|
|
588
|
+
|
|
589
|
+
const order = { ...current.order }
|
|
590
|
+
const previous = Array.isArray(order[previousKey]) ? order[previousKey] : null
|
|
591
|
+
if (previous !== null) order[previousKey] = previous.filter(id => id !== sessionId)
|
|
592
|
+
const target = Array.isArray(order[groupKey]) ? order[groupKey].slice() : []
|
|
593
|
+
const without = target.filter(id => id !== sessionId)
|
|
594
|
+
const at = beforeSessionId === undefined ? -1 : without.indexOf(beforeSessionId)
|
|
595
|
+
if (at >= 0) without.splice(at, 0, sessionId)
|
|
596
|
+
else without.push(sessionId)
|
|
597
|
+
order[groupKey] = without
|
|
598
|
+
return { ...current, assign, order }
|
|
599
|
+
})
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
return {
|
|
603
|
+
inject: ['slots', 'locale', 'contextMenus', 'workspaces', 'uiWorkspace', 'sessions', 'connection'],
|
|
604
|
+
apply(ctx) {
|
|
605
|
+
const store = createStore()
|
|
606
|
+
const addChildRequest = createSignal(null)
|
|
607
|
+
|
|
608
|
+
ctx.effect(ensureStyles, 'dsh-nested-workspaces: styles')
|
|
609
|
+
|
|
610
|
+
try {
|
|
611
|
+
ctx.locale.register(NS, DICT)
|
|
612
|
+
} catch {
|
|
613
|
+
/* hot reload: this namespace is already installed for this build */
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
const t = ctx.locale.bind(NS)
|
|
617
|
+
const workspaces = ctx.get('workspaces')
|
|
618
|
+
const uiWorkspace = ctx.get('uiWorkspace')
|
|
619
|
+
const sessions = ctx.get('sessions')
|
|
620
|
+
const contextMenus = ctx.get('contextMenus')
|
|
621
|
+
|
|
622
|
+
const notify = (text, success) => {
|
|
623
|
+
try {
|
|
624
|
+
contextMenus.notify(text, success)
|
|
625
|
+
} catch {
|
|
626
|
+
/* no toast surface: the dialog already reported the outcome inline */
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/* --------------------------------------------------- child directories */
|
|
631
|
+
|
|
632
|
+
/* The composed directory picker is a capability union: a Host whose
|
|
633
|
+
* backend is the OS chooser serves only `native`, and `createDirectory`
|
|
634
|
+
* belongs to `browse`, so it answers "needs the browse capability".
|
|
635
|
+
* Making a folder is not really browsing, so this bundle's Host half
|
|
636
|
+
* does the mkdir and answers over Connection; `createDirectory` stays
|
|
637
|
+
* as the fallback for compositions that do serve the browse backend. */
|
|
638
|
+
const CREATE_CHILD_ENDPOINT = 'nested-workspaces'
|
|
639
|
+
|
|
640
|
+
const createChildDirectory = async (parent, name) => {
|
|
641
|
+
const connection = ctx.get('connection')
|
|
642
|
+
const rpc = connection !== null && typeof connection === 'object' ? connection.rpc : null
|
|
643
|
+
if (rpc !== null && typeof rpc === 'object' && typeof rpc.call === 'function') {
|
|
644
|
+
let result = null
|
|
645
|
+
try {
|
|
646
|
+
const controller = typeof AbortController === 'function' ? new AbortController() : null
|
|
647
|
+
result = await rpc.call(
|
|
648
|
+
'/api',
|
|
649
|
+
CREATE_CHILD_ENDPOINT,
|
|
650
|
+
{ action: 'createChild', parent, name },
|
|
651
|
+
controller === null ? undefined : controller.signal,
|
|
652
|
+
)
|
|
653
|
+
} catch {
|
|
654
|
+
/* Transport missing or route unregistered: fall through to the
|
|
655
|
+
* shipped picker endpoint below. */
|
|
656
|
+
result = null
|
|
657
|
+
}
|
|
658
|
+
if (result !== null && typeof result === 'object') {
|
|
659
|
+
if (result.ok === true) {
|
|
660
|
+
const value = result.value !== null && typeof result.value === 'object' ? result.value.path : undefined
|
|
661
|
+
if (typeof value === 'string' && value !== '') return value
|
|
662
|
+
throw new Error('createChild answered without a directory path')
|
|
663
|
+
} else if (result.error !== null && typeof result.error === 'object' && typeof result.error.code === 'string') {
|
|
664
|
+
throw Object.assign(new Error(String(result.error.message || result.error.code)), { code: result.error.code })
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
return uiWorkspace.createDirectory(parent, name)
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/* ------------------------------------------------------- context menus */
|
|
672
|
+
|
|
673
|
+
ctx.effect(
|
|
674
|
+
() =>
|
|
675
|
+
ctx.contextMenus.register({
|
|
676
|
+
id: 'workspace.addChild',
|
|
677
|
+
target: 'workspace',
|
|
678
|
+
order: 150,
|
|
679
|
+
observe: () => [ctx.workspaces.list, ctx.locale],
|
|
680
|
+
resolve: target => [
|
|
681
|
+
{
|
|
682
|
+
id: 'addChild',
|
|
683
|
+
label: ctx.locale.bind(NS)('menu.addChild'),
|
|
684
|
+
icon: { key: 'workspace.addChild' },
|
|
685
|
+
run: () => {
|
|
686
|
+
addChildRequest.set({
|
|
687
|
+
parentId: target.workspaceId,
|
|
688
|
+
parentPath: target.path,
|
|
689
|
+
parentTitle: target.displayTitle,
|
|
690
|
+
})
|
|
691
|
+
},
|
|
692
|
+
},
|
|
693
|
+
],
|
|
694
|
+
}),
|
|
695
|
+
'dsh-nested-workspaces: add-child menu',
|
|
696
|
+
)
|
|
697
|
+
|
|
698
|
+
ctx.effect(
|
|
699
|
+
() =>
|
|
700
|
+
ctx.slots.inject('contextMenu.icon', () =>
|
|
701
|
+
ctx.slots.register({ name: 'contextMenu.icon', key: 'workspace.addChild' }, IconFolderPlus),
|
|
702
|
+
),
|
|
703
|
+
'dsh-nested-workspaces: add-child icon',
|
|
704
|
+
)
|
|
705
|
+
|
|
706
|
+
/*
|
|
707
|
+
* The non-drag half of "manage sessions inside a child workspace": every
|
|
708
|
+
* session menu gains a Move to submenu listing the workspaces this build
|
|
709
|
+
* can see, plus the ungrouped bucket. It writes the same display
|
|
710
|
+
* assignment a drop writes, so both routes land in one place.
|
|
711
|
+
*/
|
|
712
|
+
ctx.effect(
|
|
713
|
+
() =>
|
|
714
|
+
ctx.contextMenus.register({
|
|
715
|
+
id: 'session.nestedMoveTo',
|
|
716
|
+
target: 'session',
|
|
717
|
+
order: 500,
|
|
718
|
+
observe: () => [ctx.workspaces.list, ctx.locale],
|
|
719
|
+
resolve: target => {
|
|
720
|
+
const items = ctx.workspaces.list.getSnapshot().items
|
|
721
|
+
const sessionId = target.sessionId
|
|
722
|
+
const children = items.map(item => ({
|
|
723
|
+
id: 'move:' + item.workspaceId,
|
|
724
|
+
label: item.title || item.path,
|
|
725
|
+
run: () => {
|
|
726
|
+
assignSessionIn(store, items, sessionId, item.workspaceId, undefined)
|
|
727
|
+
notify(ctx.locale.bind(NS)('moved'), true)
|
|
728
|
+
},
|
|
729
|
+
}))
|
|
730
|
+
children.push({
|
|
731
|
+
id: 'move:ungrouped',
|
|
732
|
+
label: ctx.locale.bind(NS)('ungrouped'),
|
|
733
|
+
separatorBefore: true,
|
|
734
|
+
run: () => {
|
|
735
|
+
assignSessionIn(store, items, sessionId, UNGROUPED, undefined)
|
|
736
|
+
notify(ctx.locale.bind(NS)('moved'), true)
|
|
737
|
+
},
|
|
738
|
+
})
|
|
739
|
+
return [
|
|
740
|
+
{
|
|
741
|
+
id: 'moveTo',
|
|
742
|
+
label: ctx.locale.bind(NS)('actions.moveTo'),
|
|
743
|
+
children,
|
|
744
|
+
},
|
|
745
|
+
]
|
|
746
|
+
},
|
|
747
|
+
}),
|
|
748
|
+
'dsh-nested-workspaces: move-to menu',
|
|
749
|
+
)
|
|
750
|
+
|
|
751
|
+
/* Pin/unpin is NOT registered here. ui-workspace already contributes
|
|
752
|
+
* `session.pin` at order 100 (guarding archived rows and the pin/unpin
|
|
753
|
+
* capability), and a second contribution would show the toggle twice in
|
|
754
|
+
* the same menu. The plugin's value-add is the row button below. */
|
|
755
|
+
|
|
756
|
+
/* --------------------------------------------------------------- dialog */
|
|
757
|
+
|
|
758
|
+
function NewWorkspaceDialog(props) {
|
|
759
|
+
const request = props.request
|
|
760
|
+
const isChild = typeof request.parentPath === 'string'
|
|
761
|
+
const [value, setValue] = useState('')
|
|
762
|
+
const [busy, setBusy] = useState(false)
|
|
763
|
+
const [error, setError] = useState(null)
|
|
764
|
+
const inputRef = useRef(null)
|
|
765
|
+
|
|
766
|
+
useEffect(() => {
|
|
767
|
+
const element = inputRef.current
|
|
768
|
+
if (element !== null) {
|
|
769
|
+
element.focus()
|
|
770
|
+
if (!isChild && value !== '') element.select()
|
|
771
|
+
}
|
|
772
|
+
}, [isChild])
|
|
773
|
+
|
|
774
|
+
/* Escape belongs to DialogShell, which ignores it while busy — a second
|
|
775
|
+
* listener here would close the dialog mid-create and orphan the directory. */
|
|
776
|
+
|
|
777
|
+
const describe = failure => {
|
|
778
|
+
const code = failure !== null && typeof failure === 'object' && typeof failure.code === 'string' ? failure.code : ''
|
|
779
|
+
const message = failure && failure.message ? String(failure.message) : String(failure)
|
|
780
|
+
if (code === 'directory-picker/exists' || message.includes('directory-exists') || message.includes('already exists')) {
|
|
781
|
+
return t('errors.exists')
|
|
782
|
+
}
|
|
783
|
+
/* The Host answers these two with a stable code and an English OS
|
|
784
|
+
* string; show the localized wording instead of the raw message. */
|
|
785
|
+
if (code === 'nested-workspaces/invalid-parent') return t('errors.invalidParent')
|
|
786
|
+
if (code === 'directory-picker/unreadable') return t('errors.unreadable')
|
|
787
|
+
return t('errors.createFailed', { message })
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
const submit = async () => {
|
|
791
|
+
if (busy) return
|
|
792
|
+
const trimmed = value.trim()
|
|
793
|
+
if (trimmed === '' && isChild) {
|
|
794
|
+
setError(t('errors.nameRequired'))
|
|
795
|
+
return
|
|
796
|
+
}
|
|
797
|
+
if (isChild && /[\\/]/.test(trimmed)) {
|
|
798
|
+
setError(t('errors.nameInvalid'))
|
|
799
|
+
return
|
|
800
|
+
}
|
|
801
|
+
setBusy(true)
|
|
802
|
+
setError(null)
|
|
803
|
+
try {
|
|
804
|
+
let path = trimmed
|
|
805
|
+
if (isChild) {
|
|
806
|
+
path = await createChildDirectory(request.parentPath, trimmed)
|
|
807
|
+
} else if (path === '') {
|
|
808
|
+
/* No typed path: ask the host's directory picker, which is the
|
|
809
|
+
* same flow the shipped picker uses. */
|
|
810
|
+
const picked = await uiWorkspace.pickDirectory()
|
|
811
|
+
setBusy(false)
|
|
812
|
+
if (picked === null || picked === undefined || picked === '') return
|
|
813
|
+
path = picked
|
|
814
|
+
setValue(picked)
|
|
815
|
+
setBusy(true)
|
|
816
|
+
}
|
|
817
|
+
const created = await workspaces.create({ path })
|
|
818
|
+
if (isChild) {
|
|
819
|
+
store.update(state => ({
|
|
820
|
+
...state,
|
|
821
|
+
collapsed: { ...state.collapsed, [request.parentId]: false },
|
|
822
|
+
}))
|
|
823
|
+
/* Land the new child at the TOP of its siblings instead of below
|
|
824
|
+
* them. The Host appends new registrations after the existing
|
|
825
|
+
* ones, so anchor the new workspace to the first sibling that is
|
|
826
|
+
* already registered under the same parent. */
|
|
827
|
+
const createdId = created && created.workspaceId ? created.workspaceId : null
|
|
828
|
+
if (createdId !== null) {
|
|
829
|
+
const snapshot = workspaces.list.getSnapshot()
|
|
830
|
+
const siblings = snapshot.items
|
|
831
|
+
.filter(item => item.workspaceId !== createdId)
|
|
832
|
+
.filter(item => owningParentPath(item.path, snapshot.items.map(entry => entry.path)) === request.parentPath)
|
|
833
|
+
if (siblings.length > 0) await workspaces.insertBefore(createdId, siblings[0].workspaceId).catch(() => {})
|
|
834
|
+
}
|
|
835
|
+
notify(t('createdChild'), true)
|
|
836
|
+
} else {
|
|
837
|
+
notify(t('created'), true)
|
|
838
|
+
}
|
|
839
|
+
props.onClose()
|
|
840
|
+
} catch (failure) {
|
|
841
|
+
setError(describe(failure))
|
|
842
|
+
} finally {
|
|
843
|
+
setBusy(false)
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
return h(
|
|
848
|
+
DialogShell,
|
|
849
|
+
{
|
|
850
|
+
title: isChild ? t('dialog.addChild.title') : t('dialog.addWorkspace.title'),
|
|
851
|
+
description: isChild
|
|
852
|
+
? t('dialog.addChild.description', { parent: request.parentPath })
|
|
853
|
+
: t('dialog.addWorkspace.description'),
|
|
854
|
+
error,
|
|
855
|
+
busy,
|
|
856
|
+
confirmLabel: t('actions.create'),
|
|
857
|
+
onCancel: () => {
|
|
858
|
+
if (!busy) props.onClose()
|
|
859
|
+
},
|
|
860
|
+
onConfirm: submit,
|
|
861
|
+
confirmDisabled: isChild && value.trim() === '',
|
|
862
|
+
},
|
|
863
|
+
h('input', {
|
|
864
|
+
ref: inputRef,
|
|
865
|
+
className: 'dnw-dialogInput',
|
|
866
|
+
value,
|
|
867
|
+
spellCheck: false,
|
|
868
|
+
autoComplete: 'off',
|
|
869
|
+
'aria-label': isChild ? t('field.name') : t('field.path'),
|
|
870
|
+
placeholder: isChild ? t('field.name') : t('field.path'),
|
|
871
|
+
onChange: event => setValue(event.target.value),
|
|
872
|
+
onKeyDown: event => {
|
|
873
|
+
if (event.key === 'Enter') {
|
|
874
|
+
event.preventDefault()
|
|
875
|
+
submit()
|
|
876
|
+
}
|
|
877
|
+
},
|
|
878
|
+
}),
|
|
879
|
+
)
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
/* ----------------------------------------------------------- popover menu */
|
|
883
|
+
|
|
884
|
+
/**
|
|
885
|
+
* A small anchored menu. The shipped workspace menu rows raise their
|
|
886
|
+
* dialog from inside the browsing region this plugin now owns, so the
|
|
887
|
+
* workspace row carries its own menu instead of borrowing that one.
|
|
888
|
+
*/
|
|
889
|
+
function MenuPopover(props) {
|
|
890
|
+
const { anchor, items, onClose } = props
|
|
891
|
+
const [index, setIndex] = useState(0)
|
|
892
|
+
/* Mirror of `index` for the listener effect: keyboard navigation must not
|
|
893
|
+
* rebind three document listeners on every arrow press. */
|
|
894
|
+
const indexRef = useRef(0)
|
|
895
|
+
indexRef.current = index
|
|
896
|
+
const popoverRef = useRef(null)
|
|
897
|
+
const itemRefs = useRef([])
|
|
898
|
+
const restoreRef = useRef(null)
|
|
899
|
+
|
|
900
|
+
/** First enabled item at or after `from`, wrapping once. */
|
|
901
|
+
const seek = from => {
|
|
902
|
+
for (let step = 0; step < items.length; step += 1) {
|
|
903
|
+
const at = (from + step + items.length) % items.length
|
|
904
|
+
if (items[at] !== undefined && items[at].disabled !== true) return at
|
|
905
|
+
}
|
|
906
|
+
return -1
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
useEffect(() => {
|
|
910
|
+
const onPointerDown = event => {
|
|
911
|
+
const element = popoverRef.current
|
|
912
|
+
if (element !== null && element.contains(event.target)) return
|
|
913
|
+
onClose()
|
|
914
|
+
}
|
|
915
|
+
const onKeyDown = event => {
|
|
916
|
+
if (event.key === 'Escape') {
|
|
917
|
+
event.preventDefault()
|
|
918
|
+
event.stopPropagation()
|
|
919
|
+
onClose()
|
|
920
|
+
return
|
|
921
|
+
}
|
|
922
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp' || event.key === 'Home' || event.key === 'End') {
|
|
923
|
+
event.preventDefault()
|
|
924
|
+
if (items.length === 0) return
|
|
925
|
+
const first = seek(0)
|
|
926
|
+
if (first < 0) return
|
|
927
|
+
if (event.key === 'Home') setIndex(first)
|
|
928
|
+
else if (event.key === 'End') setIndex(seek(Math.max(0, items.length - 1) < 0 ? 0 : items.length - 1))
|
|
929
|
+
else {
|
|
930
|
+
const step = event.key === 'ArrowDown' ? 1 : -1
|
|
931
|
+
setIndex(current => {
|
|
932
|
+
const next = seek(current + step)
|
|
933
|
+
return next < 0 ? current : next
|
|
934
|
+
})
|
|
935
|
+
}
|
|
936
|
+
return
|
|
937
|
+
}
|
|
938
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
939
|
+
const active = document.activeElement
|
|
940
|
+
const position = itemRefs.current.findIndex(node => node === active)
|
|
941
|
+
const chosen = position >= 0 ? items[position] : items[indexRef.current]
|
|
942
|
+
if (chosen === undefined || chosen.disabled === true) return
|
|
943
|
+
event.preventDefault()
|
|
944
|
+
onClose()
|
|
945
|
+
void chosen.onSelect()
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
document.addEventListener('mousedown', onPointerDown, true)
|
|
949
|
+
document.addEventListener('keydown', onKeyDown, true)
|
|
950
|
+
window.addEventListener('resize', onClose)
|
|
951
|
+
return () => {
|
|
952
|
+
document.removeEventListener('mousedown', onPointerDown, true)
|
|
953
|
+
document.removeEventListener('keydown', onKeyDown, true)
|
|
954
|
+
window.removeEventListener('resize', onClose)
|
|
955
|
+
}
|
|
956
|
+
}, [items, onClose])
|
|
957
|
+
|
|
958
|
+
/* Focus the active row, and give focus back to whatever opened the
|
|
959
|
+
* menu when it closes, so keyboard users are never stranded. */
|
|
960
|
+
useEffect(() => {
|
|
961
|
+
restoreRef.current = document.activeElement
|
|
962
|
+
const initial = seek(0)
|
|
963
|
+
if (initial >= 0) setIndex(initial)
|
|
964
|
+
return () => {
|
|
965
|
+
const previous = restoreRef.current
|
|
966
|
+
if (previous !== null && typeof previous.focus === 'function' && document.contains(previous)) previous.focus()
|
|
967
|
+
}
|
|
968
|
+
}, [])
|
|
969
|
+
|
|
970
|
+
useEffect(() => {
|
|
971
|
+
const node = itemRefs.current[index]
|
|
972
|
+
if (node !== undefined && node !== null) node.focus()
|
|
973
|
+
}, [index])
|
|
974
|
+
|
|
975
|
+
const portalTarget = typeof document === 'undefined' ? null : document.body
|
|
976
|
+
if (portalTarget === null) return null
|
|
977
|
+
|
|
978
|
+
/* Keep the menu on screen: flip above the anchor when the space below is
|
|
979
|
+
* too small, then clamp both axes into the viewport. */
|
|
980
|
+
const MENU_WIDTH = 208
|
|
981
|
+
const viewportHeight = window.innerHeight || 0
|
|
982
|
+
const viewportWidth = window.innerWidth || 0
|
|
983
|
+
const estimated = items.length * 34 + 12
|
|
984
|
+
const below = anchor.bottom + 4
|
|
985
|
+
const above = anchor.top - 4 - estimated
|
|
986
|
+
const fitsBelow = viewportHeight === 0 || below + estimated <= viewportHeight
|
|
987
|
+
const top = fitsBelow ? below : Math.max(8, above)
|
|
988
|
+
const style = {
|
|
989
|
+
top: Math.round(Math.max(8, Math.min(top, viewportHeight === 0 ? top : viewportHeight - estimated - 8))) + 'px',
|
|
990
|
+
left: Math.round(Math.max(8, Math.min(anchor.left, (viewportWidth || MENU_WIDTH) - MENU_WIDTH))) + 'px',
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
return createPortal(
|
|
994
|
+
h(
|
|
995
|
+
'div',
|
|
996
|
+
{
|
|
997
|
+
ref: popoverRef,
|
|
998
|
+
className: 'dnw-menu',
|
|
999
|
+
role: 'menu',
|
|
1000
|
+
tabIndex: -1,
|
|
1001
|
+
style,
|
|
1002
|
+
onContextMenu: event => event.preventDefault(),
|
|
1003
|
+
},
|
|
1004
|
+
items.map((item, position) =>
|
|
1005
|
+
h(
|
|
1006
|
+
Fragment,
|
|
1007
|
+
{ key: item.id },
|
|
1008
|
+
item.separatorBefore === true && position > 0 ? h('div', { className: 'dnw-menuSeparator', role: 'separator' }) : null,
|
|
1009
|
+
h(
|
|
1010
|
+
'button',
|
|
1011
|
+
{
|
|
1012
|
+
type: 'button',
|
|
1013
|
+
role: 'menuitem',
|
|
1014
|
+
ref: node => {
|
|
1015
|
+
itemRefs.current[position] = node
|
|
1016
|
+
},
|
|
1017
|
+
tabIndex: position === index ? 0 : -1,
|
|
1018
|
+
className: cls('dnw-menuItem', item.danger === true && 'dnw-menuItemDanger', position === index && 'dnw-menuItemActive'),
|
|
1019
|
+
disabled: item.disabled === true,
|
|
1020
|
+
onMouseEnter: () => setIndex(position),
|
|
1021
|
+
onFocus: () => setIndex(position),
|
|
1022
|
+
onClick: () => {
|
|
1023
|
+
onClose()
|
|
1024
|
+
void item.onSelect()
|
|
1025
|
+
},
|
|
1026
|
+
},
|
|
1027
|
+
item.icon === undefined ? null : h('span', { className: 'dnw-menuIcon' }, h(item.icon, null)),
|
|
1028
|
+
h('span', { className: 'dnw-menuLabel' }, item.label),
|
|
1029
|
+
),
|
|
1030
|
+
),
|
|
1031
|
+
),
|
|
1032
|
+
),
|
|
1033
|
+
portalTarget,
|
|
1034
|
+
)
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
/* ------------------------------------------------------------ dialogs */
|
|
1038
|
+
|
|
1039
|
+
/** Shared modal shell: scrim, Escape, focus trap entry, footer buttons. */
|
|
1040
|
+
function DialogShell(props) {
|
|
1041
|
+
const { title, description, children, error, busy, confirmLabel, danger, onCancel, onConfirm, confirmDisabled } = props
|
|
1042
|
+
const dialogRef = useRef(null)
|
|
1043
|
+
const restoreRef = useRef(null)
|
|
1044
|
+
|
|
1045
|
+
useEffect(() => {
|
|
1046
|
+
const onKeyDown = event => {
|
|
1047
|
+
const element = dialogRef.current
|
|
1048
|
+
if (event.key === 'Escape') {
|
|
1049
|
+
event.preventDefault()
|
|
1050
|
+
event.stopPropagation()
|
|
1051
|
+
if (!busy) onCancel()
|
|
1052
|
+
return
|
|
1053
|
+
}
|
|
1054
|
+
/* Keep Tab inside the dialog: the scrim covers the page, so
|
|
1055
|
+
* focus must not be able to walk out behind it. */
|
|
1056
|
+
if (event.key !== 'Tab' || element === null) return
|
|
1057
|
+
const focusable = element.querySelectorAll(
|
|
1058
|
+
'button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])',
|
|
1059
|
+
)
|
|
1060
|
+
if (focusable.length === 0) return
|
|
1061
|
+
const first = focusable[0]
|
|
1062
|
+
const last = focusable[focusable.length - 1]
|
|
1063
|
+
const active = document.activeElement
|
|
1064
|
+
if (event.shiftKey && (active === first || !element.contains(active))) {
|
|
1065
|
+
event.preventDefault()
|
|
1066
|
+
last.focus()
|
|
1067
|
+
} else if (!event.shiftKey && (active === last || !element.contains(active))) {
|
|
1068
|
+
event.preventDefault()
|
|
1069
|
+
first.focus()
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
document.addEventListener('keydown', onKeyDown, true)
|
|
1073
|
+
return () => document.removeEventListener('keydown', onKeyDown, true)
|
|
1074
|
+
}, [busy, onCancel])
|
|
1075
|
+
|
|
1076
|
+
useEffect(() => {
|
|
1077
|
+
restoreRef.current = document.activeElement
|
|
1078
|
+
return () => {
|
|
1079
|
+
const previous = restoreRef.current
|
|
1080
|
+
if (previous !== null && typeof previous.focus === 'function' && document.contains(previous)) previous.focus()
|
|
1081
|
+
}
|
|
1082
|
+
}, [])
|
|
1083
|
+
|
|
1084
|
+
const portalTarget = typeof document === 'undefined' ? null : document.body
|
|
1085
|
+
if (portalTarget === null) return null
|
|
1086
|
+
|
|
1087
|
+
return createPortal(
|
|
1088
|
+
h(
|
|
1089
|
+
'div',
|
|
1090
|
+
{
|
|
1091
|
+
className: 'dnw-scrim',
|
|
1092
|
+
onMouseDown: event => {
|
|
1093
|
+
if (event.target === event.currentTarget && !busy) onCancel()
|
|
1094
|
+
},
|
|
1095
|
+
},
|
|
1096
|
+
h(
|
|
1097
|
+
'div',
|
|
1098
|
+
{
|
|
1099
|
+
ref: dialogRef,
|
|
1100
|
+
className: 'dnw-dialog',
|
|
1101
|
+
role: 'dialog',
|
|
1102
|
+
'aria-modal': 'true',
|
|
1103
|
+
'aria-label': title,
|
|
1104
|
+
},
|
|
1105
|
+
h('div', { className: 'dnw-dialogTitle' }, title),
|
|
1106
|
+
description === null ? null : h('div', { className: 'dnw-dialogText' }, description),
|
|
1107
|
+
children,
|
|
1108
|
+
error === null ? null : h('div', { className: 'dnw-dialogError', role: 'alert' }, error),
|
|
1109
|
+
h(
|
|
1110
|
+
'div',
|
|
1111
|
+
{ className: 'dnw-dialogFooter' },
|
|
1112
|
+
h(
|
|
1113
|
+
'button',
|
|
1114
|
+
{ type: 'button', className: 'dnw-button', disabled: busy, onClick: onCancel },
|
|
1115
|
+
t('actions.cancel'),
|
|
1116
|
+
),
|
|
1117
|
+
h(
|
|
1118
|
+
'button',
|
|
1119
|
+
{
|
|
1120
|
+
type: 'button',
|
|
1121
|
+
className: cls('dnw-button', 'dnw-buttonPrimary', danger === true && 'dnw-buttonDanger'),
|
|
1122
|
+
disabled: busy || confirmDisabled === true,
|
|
1123
|
+
onClick: onConfirm,
|
|
1124
|
+
},
|
|
1125
|
+
confirmLabel,
|
|
1126
|
+
),
|
|
1127
|
+
),
|
|
1128
|
+
),
|
|
1129
|
+
),
|
|
1130
|
+
portalTarget,
|
|
1131
|
+
)
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
/** Inline rename for one Workspace, mirroring the shipped dialog's guards. */
|
|
1135
|
+
function WorkspaceRenameDialog(props) {
|
|
1136
|
+
const { workspace, onClose } = props
|
|
1137
|
+
const [value, setValue] = useState(workspace.title)
|
|
1138
|
+
const [busy, setBusy] = useState(false)
|
|
1139
|
+
const [error, setError] = useState(null)
|
|
1140
|
+
const inputRef = useRef(null)
|
|
1141
|
+
const trimmed = value.trim()
|
|
1142
|
+
|
|
1143
|
+
useEffect(() => {
|
|
1144
|
+
const element = inputRef.current
|
|
1145
|
+
if (element !== null) {
|
|
1146
|
+
element.focus()
|
|
1147
|
+
element.select()
|
|
1148
|
+
}
|
|
1149
|
+
}, [])
|
|
1150
|
+
|
|
1151
|
+
const submit = async () => {
|
|
1152
|
+
if (busy || trimmed === '' || trimmed === workspace.title) return
|
|
1153
|
+
setBusy(true)
|
|
1154
|
+
setError(null)
|
|
1155
|
+
try {
|
|
1156
|
+
await workspaces.rename(workspace.workspaceId, trimmed)
|
|
1157
|
+
notify(t('renamed'), true)
|
|
1158
|
+
onClose()
|
|
1159
|
+
} catch (failure) {
|
|
1160
|
+
setError(t('errors.renameFailed', { message: failure && failure.message ? String(failure.message) : String(failure) }))
|
|
1161
|
+
} finally {
|
|
1162
|
+
setBusy(false)
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
return h(
|
|
1167
|
+
DialogShell,
|
|
1168
|
+
{
|
|
1169
|
+
title: t('dialog.rename.title'),
|
|
1170
|
+
description: null,
|
|
1171
|
+
error,
|
|
1172
|
+
busy,
|
|
1173
|
+
confirmLabel: t('actions.rename'),
|
|
1174
|
+
onCancel: () => {
|
|
1175
|
+
if (!busy) onClose()
|
|
1176
|
+
},
|
|
1177
|
+
onConfirm: submit,
|
|
1178
|
+
confirmDisabled: trimmed === '' || trimmed === workspace.title,
|
|
1179
|
+
},
|
|
1180
|
+
h('input', {
|
|
1181
|
+
ref: inputRef,
|
|
1182
|
+
className: 'dnw-dialogInput',
|
|
1183
|
+
value,
|
|
1184
|
+
spellCheck: false,
|
|
1185
|
+
autoComplete: 'off',
|
|
1186
|
+
'aria-label': t('dialog.rename.title'),
|
|
1187
|
+
onChange: event => setValue(event.target.value),
|
|
1188
|
+
onKeyDown: event => {
|
|
1189
|
+
if (event.key === 'Enter') {
|
|
1190
|
+
event.preventDefault()
|
|
1191
|
+
void submit()
|
|
1192
|
+
}
|
|
1193
|
+
},
|
|
1194
|
+
}),
|
|
1195
|
+
)
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
/** Remove one Workspace from the list; the directory on disk is untouched. */
|
|
1199
|
+
function WorkspaceDeleteDialog(props) {
|
|
1200
|
+
const { workspace, onClose } = props
|
|
1201
|
+
const [busy, setBusy] = useState(false)
|
|
1202
|
+
const [error, setError] = useState(null)
|
|
1203
|
+
|
|
1204
|
+
const submit = async () => {
|
|
1205
|
+
if (busy) return
|
|
1206
|
+
setBusy(true)
|
|
1207
|
+
setError(null)
|
|
1208
|
+
try {
|
|
1209
|
+
await workspaces.delete(workspace.workspaceId)
|
|
1210
|
+
notify(t('deleted'), true)
|
|
1211
|
+
onClose()
|
|
1212
|
+
} catch (failure) {
|
|
1213
|
+
setError(t('errors.deleteFailed', { message: failure && failure.message ? String(failure.message) : String(failure) }))
|
|
1214
|
+
} finally {
|
|
1215
|
+
setBusy(false)
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
return h(DialogShell, {
|
|
1220
|
+
title: t('dialog.delete.title'),
|
|
1221
|
+
description: t('dialog.delete.description', { name: workspace.title }),
|
|
1222
|
+
error,
|
|
1223
|
+
busy,
|
|
1224
|
+
danger: true,
|
|
1225
|
+
confirmLabel: t('actions.confirm'),
|
|
1226
|
+
onCancel: () => {
|
|
1227
|
+
if (!busy) onClose()
|
|
1228
|
+
},
|
|
1229
|
+
onConfirm: submit,
|
|
1230
|
+
})
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
/* --------------------------------------------------------- row components
|
|
1234
|
+
*
|
|
1235
|
+
* These are components rather than render helpers on purpose: each one calls
|
|
1236
|
+
* React hooks (useSessionAccess / useWorkspaceAccess), so it must own a stable
|
|
1237
|
+
* hook list. Calling them from Sidebar's body made the hook count depend on
|
|
1238
|
+
* collapse state and filters, which breaks the rules of hooks and blanks the
|
|
1239
|
+
* whole sidebar entry. Shared closures arrive in `env`, built once per render.
|
|
1240
|
+
*/
|
|
1241
|
+
function SessionRow(props) {
|
|
1242
|
+
const { session, groupKey, index, bucket, env } = props
|
|
1243
|
+
const { view, statuses, t, uiWorkspace, list, useSessionAccess, openMenu, assignSession, dragIdRef, draggingId, dropTarget, setDropTarget, setDraggingId, now } = env
|
|
1244
|
+
const isArchived = view.archived.has(session.id)
|
|
1245
|
+
const isPinned = view.pinned.has(session.id) && !isArchived
|
|
1246
|
+
const label = session.blank ? (session.id === view.currentId ? t('session.new') : t('session.untitled')) : sessionTitle(session)
|
|
1247
|
+
const title = label === '' ? t('session.untitled') : label
|
|
1248
|
+
const status = statuses.get(session.id)
|
|
1249
|
+
const running = status !== undefined && status.running === true
|
|
1250
|
+
/* Shipped precedence (ui-workspace Rows.tsx sessionStatuses): a pending
|
|
1251
|
+
* interaction wins, then running, then running subagents, then an unread
|
|
1252
|
+
* completion, and otherwise the row is idle and draws no glyph. */
|
|
1253
|
+
const pendingKind = status === undefined ? undefined : status.pendingInteraction === undefined ? undefined : status.pendingInteraction.kind
|
|
1254
|
+
const runningChildren = runningSubagentCount(list, session.id, statuses)
|
|
1255
|
+
const statusState =
|
|
1256
|
+
session.blank || isArchived
|
|
1257
|
+
? 'idle'
|
|
1258
|
+
: pendingKind !== undefined && pendingKind !== null
|
|
1259
|
+
? 'warning'
|
|
1260
|
+
: running
|
|
1261
|
+
? 'ongoing'
|
|
1262
|
+
: runningChildren > 0
|
|
1263
|
+
? 'ongoing'
|
|
1264
|
+
: status !== undefined && status.completionUnread === true
|
|
1265
|
+
? 'done'
|
|
1266
|
+
: 'idle'
|
|
1267
|
+
const statusLabel =
|
|
1268
|
+
statusState === 'idle'
|
|
1269
|
+
? null
|
|
1270
|
+
: statusState === 'warning'
|
|
1271
|
+
? t(pendingKind === 'approval' ? 'status.waitingApproval' : pendingKind === 'plan-review' ? 'status.planReview' : 'status.waitingAnswer')
|
|
1272
|
+
: statusState === 'ongoing'
|
|
1273
|
+
? running
|
|
1274
|
+
? t('status.running')
|
|
1275
|
+
: t('status.subagentsRunning', { n: runningChildren })
|
|
1276
|
+
: t('status.completed')
|
|
1277
|
+
const selected = session.id === view.currentId
|
|
1278
|
+
const canUnarchive = useSessionAccess(session.id, 'workspace/unarchiveSession')
|
|
1279
|
+
const canMove = useSessionAccess(session.id, 'workspace/insertSessionBefore')
|
|
1280
|
+
const canPin = useSessionAccess(session.id, isPinned ? 'workspace/unpinSession' : 'workspace/pinSession')
|
|
1281
|
+
const canDrag = !session.blank && !isArchived && canMove
|
|
1282
|
+
const rowDropPosition = dropTarget !== null && dropTarget.sessionId === session.id ? dropTarget.position : null
|
|
1283
|
+
const actions = []
|
|
1284
|
+
const menuOpen = env.menuOpenSessionId === session.id
|
|
1285
|
+
if (!session.blank && !isArchived && canPin) {
|
|
1286
|
+
actions.push(
|
|
1287
|
+
h(
|
|
1288
|
+
'button',
|
|
1289
|
+
{
|
|
1290
|
+
type: 'button',
|
|
1291
|
+
key: 'pin',
|
|
1292
|
+
className: cls('dnw-iconButton', isPinned && 'dnw-iconButtonOn'),
|
|
1293
|
+
title: t(isPinned ? 'actions.unpin' : 'actions.pin'),
|
|
1294
|
+
'aria-label': t(isPinned ? 'actions.unpin' : 'actions.pin') + ' ' + title,
|
|
1295
|
+
'aria-pressed': isPinned,
|
|
1296
|
+
onClick: event => {
|
|
1297
|
+
event.stopPropagation()
|
|
1298
|
+
const task = isPinned ? uiWorkspace.unpinSession(session.id) : uiWorkspace.pinSession(session.id)
|
|
1299
|
+
if (task !== null && typeof task === 'object' && typeof task.catch === 'function') {
|
|
1300
|
+
task.catch(() => notify(t('errors.pinFailed'), false))
|
|
1301
|
+
}
|
|
1302
|
+
},
|
|
1303
|
+
},
|
|
1304
|
+
h(isPinned ? IconPin : IconPinOutline, null),
|
|
1305
|
+
),
|
|
1306
|
+
)
|
|
1307
|
+
}
|
|
1308
|
+
if (!session.blank && !isArchived) {
|
|
1309
|
+
actions.push(
|
|
1310
|
+
openMenu(
|
|
1311
|
+
{ kind: 'session', value: { sessionId: session.id, displayTitle: title } },
|
|
1312
|
+
t('actions.menu') + ' ' + title,
|
|
1313
|
+
),
|
|
1314
|
+
)
|
|
1315
|
+
}
|
|
1316
|
+
if (isArchived && canUnarchive) {
|
|
1317
|
+
actions.push(
|
|
1318
|
+
h(
|
|
1319
|
+
'button',
|
|
1320
|
+
{
|
|
1321
|
+
type: 'button',
|
|
1322
|
+
key: 'unarchive',
|
|
1323
|
+
className: 'dnw-iconButton',
|
|
1324
|
+
title: t('actions.unarchive'),
|
|
1325
|
+
'aria-label': t('actions.unarchive') + ' ' + title,
|
|
1326
|
+
onClick: event => {
|
|
1327
|
+
event.stopPropagation()
|
|
1328
|
+
uiWorkspace.unarchiveSession(session.id)
|
|
1329
|
+
},
|
|
1330
|
+
},
|
|
1331
|
+
h(IconUnarchive, null),
|
|
1332
|
+
),
|
|
1333
|
+
)
|
|
1334
|
+
}
|
|
1335
|
+
const activate = () => {
|
|
1336
|
+
if (isArchived) return
|
|
1337
|
+
uiWorkspace.openSession(session.id)
|
|
1338
|
+
}
|
|
1339
|
+
/* The next sibling in this bucket is the insertion anchor for an
|
|
1340
|
+
* "after" drop. It skips the row being dragged, otherwise dropping a
|
|
1341
|
+
* row right below the one above it would move it to the group end. */
|
|
1342
|
+
const dropAfter = (() => {
|
|
1343
|
+
if (!Array.isArray(bucket) || typeof index !== 'number') return undefined
|
|
1344
|
+
for (let cursor = index + 1; cursor < bucket.length; cursor += 1) {
|
|
1345
|
+
if (bucket[cursor].id !== draggingId) return bucket[cursor].id
|
|
1346
|
+
}
|
|
1347
|
+
return undefined
|
|
1348
|
+
})()
|
|
1349
|
+
return h(
|
|
1350
|
+
'div',
|
|
1351
|
+
{
|
|
1352
|
+
key: 's:' + session.id,
|
|
1353
|
+
className: cls(
|
|
1354
|
+
'dnw-row',
|
|
1355
|
+
'dnw-sessionRow',
|
|
1356
|
+
selected && 'dnw-rowSelected',
|
|
1357
|
+
isArchived && 'dnw-rowArchived',
|
|
1358
|
+
rowDropPosition === 'before' && 'dnw-dropBefore',
|
|
1359
|
+
rowDropPosition === 'after' && 'dnw-dropAfter',
|
|
1360
|
+
draggingId === session.id && 'dnw-rowDragging',
|
|
1361
|
+
),
|
|
1362
|
+
role: 'treeitem',
|
|
1363
|
+
tabIndex: 0,
|
|
1364
|
+
'aria-selected': selected,
|
|
1365
|
+
'data-row-key': 'nested-session:' + session.id,
|
|
1366
|
+
draggable: canDrag,
|
|
1367
|
+
onKeyDown: event => {
|
|
1368
|
+
if (event.key !== 'Enter' && event.key !== ' ') return
|
|
1369
|
+
event.preventDefault()
|
|
1370
|
+
activate()
|
|
1371
|
+
},
|
|
1372
|
+
onDragStart: event => {
|
|
1373
|
+
dragIdRef.current = session.id
|
|
1374
|
+
setDraggingId(session.id)
|
|
1375
|
+
try {
|
|
1376
|
+
event.dataTransfer.effectAllowed = 'move'
|
|
1377
|
+
event.dataTransfer.setData('text/plain', session.id)
|
|
1378
|
+
} catch {
|
|
1379
|
+
/* some browsers block custom payloads; the ref carries the id */
|
|
1380
|
+
}
|
|
1381
|
+
},
|
|
1382
|
+
onDragEnd: () => {
|
|
1383
|
+
dragIdRef.current = null
|
|
1384
|
+
setDraggingId(null)
|
|
1385
|
+
setDropTarget(null)
|
|
1386
|
+
},
|
|
1387
|
+
onDragOver: event => {
|
|
1388
|
+
const dragging = dragIdRef.current
|
|
1389
|
+
if (dragging === null || dragging === session.id) return
|
|
1390
|
+
event.preventDefault()
|
|
1391
|
+
event.stopPropagation()
|
|
1392
|
+
try {
|
|
1393
|
+
event.dataTransfer.dropEffect = 'move'
|
|
1394
|
+
} catch {
|
|
1395
|
+
/* ignore */
|
|
1396
|
+
}
|
|
1397
|
+
const box = event.currentTarget.getBoundingClientRect()
|
|
1398
|
+
const position = event.clientY < box.top + box.height / 2 ? 'before' : 'after'
|
|
1399
|
+
if (rowDropPosition !== position) setDropTarget({ workspaceId: groupKey, sessionId: session.id, position })
|
|
1400
|
+
},
|
|
1401
|
+
onDragLeave: event => {
|
|
1402
|
+
if (event.currentTarget.contains(event.relatedTarget)) return
|
|
1403
|
+
if (rowDropPosition !== null) setDropTarget(null)
|
|
1404
|
+
},
|
|
1405
|
+
onDrop: event => {
|
|
1406
|
+
const id = dragIdRef.current || event.dataTransfer.getData('text/plain')
|
|
1407
|
+
if (!id || id === session.id) return
|
|
1408
|
+
event.preventDefault()
|
|
1409
|
+
event.stopPropagation()
|
|
1410
|
+
const box = event.currentTarget.getBoundingClientRect()
|
|
1411
|
+
const after = event.clientY >= box.top + box.height / 2
|
|
1412
|
+
setDropTarget(null)
|
|
1413
|
+
dragIdRef.current = null
|
|
1414
|
+
setDraggingId(null)
|
|
1415
|
+
assignSession(id, groupKey, after ? dropAfter : session.id)
|
|
1416
|
+
},
|
|
1417
|
+
onClick: activate,
|
|
1418
|
+
},
|
|
1419
|
+
/* Leading cell, matching the shipped browser: an idle session shows
|
|
1420
|
+
* nothing at all, a running one shows the rotating spinner, and a
|
|
1421
|
+
* pending interaction or unread completion shows a state dot. */
|
|
1422
|
+
h(
|
|
1423
|
+
'span',
|
|
1424
|
+
{ className: 'dnw-slot' },
|
|
1425
|
+
statusState === 'ongoing' ? h(StatusSpinner, null) : null,
|
|
1426
|
+
statusState !== 'ongoing' && statusState !== 'idle'
|
|
1427
|
+
? h('span', { className: 'dnw-stateDot', 'data-state': statusState, style: { width: '10px', height: '10px' }, 'aria-hidden': 'true' })
|
|
1428
|
+
: null,
|
|
1429
|
+
statusLabel === null ? null : h('span', { className: 'dnw-visuallyHidden' }, statusLabel),
|
|
1430
|
+
),
|
|
1431
|
+
h('span', { className: cls('dnw-title', (session.blank || isArchived) && 'dnw-titleMuted') }, title),
|
|
1432
|
+
/* Resting cell: the last-used time and, when pinned, the pin glyph —
|
|
1433
|
+
* the shipped browser swaps this cell for the action buttons on
|
|
1434
|
+
* hover, and so does this one. */
|
|
1435
|
+
session.blank
|
|
1436
|
+
? null
|
|
1437
|
+
: h(
|
|
1438
|
+
'span',
|
|
1439
|
+
{ className: 'dnw-resting' },
|
|
1440
|
+
h(
|
|
1441
|
+
'span',
|
|
1442
|
+
{ className: 'dnw-time', title: hoverTimeLabel(session.updatedAt, now, t) },
|
|
1443
|
+
timeLabel(session.updatedAt, now, t),
|
|
1444
|
+
),
|
|
1445
|
+
isPinned
|
|
1446
|
+
? h(
|
|
1447
|
+
'span',
|
|
1448
|
+
{
|
|
1449
|
+
className: 'dnw-pinIndicator',
|
|
1450
|
+
role: 'img',
|
|
1451
|
+
'aria-label': t('row.pinned'),
|
|
1452
|
+
title: t('row.pinned'),
|
|
1453
|
+
},
|
|
1454
|
+
h(IconPin, null),
|
|
1455
|
+
)
|
|
1456
|
+
: null,
|
|
1457
|
+
),
|
|
1458
|
+
actions.length === 0
|
|
1459
|
+
? null
|
|
1460
|
+
: h('span', { className: cls('dnw-actions', menuOpen && 'dnw-actionsOpen') }, ...actions),
|
|
1461
|
+
)
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
function WorkspaceGroup(props) {
|
|
1465
|
+
const { workspace, depth, env } = props
|
|
1466
|
+
const { view, state, t, uiWorkspace, useWorkspaceAccess, openMenu, openWorkspaceMenu, assignSession, setExpanded, setRenaming, menu, dragIdRef, draggingId, dropTarget, setDropTarget, setDraggingId, workspaceDrag, draggingWorkspaceId, beginWorkspaceDrag, endWorkspaceDrag, hoverWorkspaceDrag, workspaceClickBlockRef } = env
|
|
1467
|
+
const workspaceId = workspace.workspaceId
|
|
1468
|
+
const collapsed = state.collapsed[workspaceId] === true
|
|
1469
|
+
const members = view.members.get(workspaceId) || []
|
|
1470
|
+
const children = view.childrenOf.get(workspaceId) || []
|
|
1471
|
+
const hasSessions = members.length > 0
|
|
1472
|
+
const visible = !collapsed || view.filtering
|
|
1473
|
+
/* Only a header-level hover highlights the group; a hover over one
|
|
1474
|
+
* of its session rows carries a sessionId and must not repaint it. */
|
|
1475
|
+
const isDropTarget =
|
|
1476
|
+
dropTarget !== null && dropTarget.workspaceId === workspaceId && dropTarget.sessionId === undefined
|
|
1477
|
+
const indent = { '--dnw-indent': depth * INDENT_PX + 'px' }
|
|
1478
|
+
const canCreateSession = useWorkspaceAccess(workspaceId, 'session/create')
|
|
1479
|
+
const collapsible = children.length > 0 || hasSessions
|
|
1480
|
+
/* A workspace drag is legal only between rows that share a parent, so a
|
|
1481
|
+
* child can be reordered among its siblings but never leave its root. */
|
|
1482
|
+
const parentId = view.parentOf.get(workspaceId)
|
|
1483
|
+
const workspaceSibling =
|
|
1484
|
+
workspaceDrag !== null &&
|
|
1485
|
+
workspaceDrag.workspaceId !== workspaceId &&
|
|
1486
|
+
view.parentOf.get(workspaceDrag.workspaceId) === parentId
|
|
1487
|
+
const workspaceDropHalf =
|
|
1488
|
+
workspaceSibling && workspaceDrag.over !== null && workspaceDrag.over.id === workspaceId
|
|
1489
|
+
? workspaceDrag.over.half
|
|
1490
|
+
: null
|
|
1491
|
+
const row = h(
|
|
1492
|
+
'div',
|
|
1493
|
+
{
|
|
1494
|
+
key: 'w:' + workspaceId,
|
|
1495
|
+
className: cls(
|
|
1496
|
+
'dnw-row',
|
|
1497
|
+
'dnw-workspaceRow',
|
|
1498
|
+
isDropTarget && 'dnw-dropOn',
|
|
1499
|
+
workspaceDropHalf === 'before' && 'dnw-dropBefore',
|
|
1500
|
+
workspaceDropHalf === 'after' && 'dnw-dropAfter',
|
|
1501
|
+
draggingWorkspaceId === workspaceId && 'dnw-rowDragging',
|
|
1502
|
+
),
|
|
1503
|
+
role: 'treeitem',
|
|
1504
|
+
tabIndex: 0,
|
|
1505
|
+
draggable: true,
|
|
1506
|
+
'aria-expanded': !collapsed,
|
|
1507
|
+
'aria-label': workspace.title + ' — ' + workspace.path,
|
|
1508
|
+
style: indent,
|
|
1509
|
+
onClick: () => {
|
|
1510
|
+
/* A drag ends with a click; expanding on it would undo the drop. */
|
|
1511
|
+
if (draggingWorkspaceId !== null) return
|
|
1512
|
+
if (workspaceClickBlockRef.current) {
|
|
1513
|
+
workspaceClickBlockRef.current = false
|
|
1514
|
+
return
|
|
1515
|
+
}
|
|
1516
|
+
setExpanded(workspaceId, collapsed)
|
|
1517
|
+
},
|
|
1518
|
+
onKeyDown: event => {
|
|
1519
|
+
if (event.target !== event.currentTarget) return
|
|
1520
|
+
if (event.key !== 'Enter' && event.key !== ' ') return
|
|
1521
|
+
event.preventDefault()
|
|
1522
|
+
setExpanded(workspaceId, collapsed)
|
|
1523
|
+
},
|
|
1524
|
+
onContextMenu: event => openWorkspaceMenu(event, workspace),
|
|
1525
|
+
onDragStart: event => {
|
|
1526
|
+
/* `draggable` lives on the row, so the target is normally the row
|
|
1527
|
+
* itself; a drag started on the action buttons must not reorder. */
|
|
1528
|
+
const fromActions =
|
|
1529
|
+
event.target !== event.currentTarget &&
|
|
1530
|
+
typeof Element !== 'undefined' &&
|
|
1531
|
+
event.target instanceof Element &&
|
|
1532
|
+
event.target.closest('.dnw-actions') !== null
|
|
1533
|
+
if (fromActions) {
|
|
1534
|
+
event.preventDefault()
|
|
1535
|
+
return
|
|
1536
|
+
}
|
|
1537
|
+
event.stopPropagation()
|
|
1538
|
+
try {
|
|
1539
|
+
event.dataTransfer.effectAllowed = 'move'
|
|
1540
|
+
event.dataTransfer.setData('text/plain', workspaceId)
|
|
1541
|
+
} catch {
|
|
1542
|
+
/* ignore */
|
|
1543
|
+
}
|
|
1544
|
+
beginWorkspaceDrag(workspaceId)
|
|
1545
|
+
},
|
|
1546
|
+
onDragEnd: () => {
|
|
1547
|
+
endWorkspaceDrag()
|
|
1548
|
+
},
|
|
1549
|
+
onDragOver: event => {
|
|
1550
|
+
if (workspaceDrag !== null) {
|
|
1551
|
+
/* Workspace reorder: sibling rows only, chosen by row midpoint. */
|
|
1552
|
+
if (!workspaceSibling) {
|
|
1553
|
+
/* Keep swallowing the event so the session path below cannot
|
|
1554
|
+
* mistake a workspace drag for a session drop. */
|
|
1555
|
+
return
|
|
1556
|
+
}
|
|
1557
|
+
event.preventDefault()
|
|
1558
|
+
event.stopPropagation()
|
|
1559
|
+
try {
|
|
1560
|
+
event.dataTransfer.dropEffect = 'move'
|
|
1561
|
+
} catch {
|
|
1562
|
+
/* ignore */
|
|
1563
|
+
}
|
|
1564
|
+
const rect = event.currentTarget.getBoundingClientRect()
|
|
1565
|
+
const half = event.clientY < rect.top + rect.height / 2 ? 'before' : 'after'
|
|
1566
|
+
if (workspaceDropHalf !== half) hoverWorkspaceDrag(workspaceId, half)
|
|
1567
|
+
return
|
|
1568
|
+
}
|
|
1569
|
+
if (dragIdRef.current === null) return
|
|
1570
|
+
event.preventDefault()
|
|
1571
|
+
event.stopPropagation()
|
|
1572
|
+
try {
|
|
1573
|
+
event.dataTransfer.dropEffect = 'move'
|
|
1574
|
+
} catch {
|
|
1575
|
+
/* ignore */
|
|
1576
|
+
}
|
|
1577
|
+
if (!isDropTarget) setDropTarget({ workspaceId, mode: 'into' })
|
|
1578
|
+
},
|
|
1579
|
+
onDragLeave: event => {
|
|
1580
|
+
/* Moving onto a child span fires leave on the header; only an
|
|
1581
|
+
* exit from the header itself clears the drop highlight. */
|
|
1582
|
+
if (event.currentTarget.contains(event.relatedTarget)) return
|
|
1583
|
+
if (isDropTarget) setDropTarget(null)
|
|
1584
|
+
},
|
|
1585
|
+
onDrop: event => {
|
|
1586
|
+
event.preventDefault()
|
|
1587
|
+
event.stopPropagation()
|
|
1588
|
+
if (workspaceDrag !== null) return
|
|
1589
|
+
const id = dragIdRef.current || event.dataTransfer.getData('text/plain')
|
|
1590
|
+
setDropTarget(null)
|
|
1591
|
+
setDraggingId(null)
|
|
1592
|
+
dragIdRef.current = null
|
|
1593
|
+
if (id) assignSession(id, workspaceId, undefined)
|
|
1594
|
+
},
|
|
1595
|
+
},
|
|
1596
|
+
h(
|
|
1597
|
+
'span',
|
|
1598
|
+
{ className: 'dnw-slot dnw-lead' },
|
|
1599
|
+
h(
|
|
1600
|
+
'button',
|
|
1601
|
+
{
|
|
1602
|
+
type: 'button',
|
|
1603
|
+
className: cls('dnw-chevron', !collapsed && 'dnw-chevronOpen'),
|
|
1604
|
+
'aria-label': (collapsed ? t('expandGroup') : t('collapseGroup')) + ' ' + workspace.title,
|
|
1605
|
+
'aria-hidden': !collapsible,
|
|
1606
|
+
tabIndex: collapsible ? 0 : -1,
|
|
1607
|
+
onClick: event => {
|
|
1608
|
+
event.stopPropagation()
|
|
1609
|
+
setExpanded(workspaceId, collapsed)
|
|
1610
|
+
},
|
|
1611
|
+
},
|
|
1612
|
+
h('span', { className: 'dnw-arrowInner' }, h(IconChevron, null)),
|
|
1613
|
+
),
|
|
1614
|
+
h('span', { className: cls('dnw-folderIcon', !collapsed && 'dnw-folderActive') }, h(IconFolder, null)),
|
|
1615
|
+
),
|
|
1616
|
+
h(
|
|
1617
|
+
'span',
|
|
1618
|
+
{
|
|
1619
|
+
className: 'dnw-title',
|
|
1620
|
+
title: workspace.path,
|
|
1621
|
+
onDoubleClick: event => {
|
|
1622
|
+
event.preventDefault()
|
|
1623
|
+
event.stopPropagation()
|
|
1624
|
+
setRenaming(workspace)
|
|
1625
|
+
},
|
|
1626
|
+
},
|
|
1627
|
+
workspace.title,
|
|
1628
|
+
),
|
|
1629
|
+
h(
|
|
1630
|
+
'span',
|
|
1631
|
+
{ className: cls('dnw-actions', menu !== null && menu.workspaceId === workspaceId && 'dnw-actionsOpen') },
|
|
1632
|
+
h(
|
|
1633
|
+
'button',
|
|
1634
|
+
{
|
|
1635
|
+
type: 'button',
|
|
1636
|
+
className: 'dnw-iconButton',
|
|
1637
|
+
title: t('actions.menu'),
|
|
1638
|
+
'aria-label': t('actions.menu') + ' ' + workspace.title,
|
|
1639
|
+
'aria-haspopup': 'menu',
|
|
1640
|
+
'aria-expanded': menu !== null && menu.workspaceId === workspaceId,
|
|
1641
|
+
onClick: event => openWorkspaceMenu(event, workspace),
|
|
1642
|
+
},
|
|
1643
|
+
h(IconDots, null),
|
|
1644
|
+
),
|
|
1645
|
+
canCreateSession
|
|
1646
|
+
? h(
|
|
1647
|
+
'button',
|
|
1648
|
+
{
|
|
1649
|
+
type: 'button',
|
|
1650
|
+
className: 'dnw-iconButton',
|
|
1651
|
+
title: t('actions.newSession'),
|
|
1652
|
+
'aria-label': t('actions.newSession') + ' ' + workspace.title,
|
|
1653
|
+
onClick: event => {
|
|
1654
|
+
event.stopPropagation()
|
|
1655
|
+
uiWorkspace.startSession(workspaceId)
|
|
1656
|
+
},
|
|
1657
|
+
},
|
|
1658
|
+
h(IconPlus, null),
|
|
1659
|
+
)
|
|
1660
|
+
: null,
|
|
1661
|
+
),
|
|
1662
|
+
)
|
|
1663
|
+
|
|
1664
|
+
const body = []
|
|
1665
|
+
/* Shipped section order: the workspace header, then its child
|
|
1666
|
+
* workspaces, then the workspace's own session rows. A newly created
|
|
1667
|
+
* child therefore sits directly under its parent instead of at the
|
|
1668
|
+
* bottom of the section. */
|
|
1669
|
+
if (visible) {
|
|
1670
|
+
for (const child of children) body.push(h(WorkspaceGroup, { key: 'grp:' + child.workspaceId, workspace: child, depth: depth + 1, env }))
|
|
1671
|
+
}
|
|
1672
|
+
if (visible && hasSessions) body.push(h('div', { key: 'g:' + workspaceId, role: 'group', style: indent }, members.map((session, index) => h(SessionRow, { key: 's:' + session.id, session, groupKey: workspaceId, index, bucket: members, env }))))
|
|
1673
|
+
return h(Fragment, { key: 'grp:' + workspaceId }, row, ...body)
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1676
|
+
/* ------------------------------------------------------------- sidebar */
|
|
1677
|
+
|
|
1678
|
+
function Sidebar(props) {
|
|
1679
|
+
const { wide, expandSidebar, renderFactorySlot, useSessions, useWorkspaces, useSessionStatus, useSectionScroller } = props
|
|
1680
|
+
const useWorkspaceAccess = typeof props.useWorkspaceAccess === 'function' ? props.useWorkspaceAccess : () => true
|
|
1681
|
+
const useSessionAccess = typeof props.useSessionAccess === 'function' ? props.useSessionAccess : () => true
|
|
1682
|
+
const state = useSyncExternalStore(store.subscribe, store.get, store.get)
|
|
1683
|
+
const request = useSyncExternalStore(addChildRequest.subscribe, addChildRequest.get, addChildRequest.get)
|
|
1684
|
+
/* The shared context menu portals out of the row, so neither :hover nor
|
|
1685
|
+
* :focus-within holds while a row's menu is open. Track the menu's
|
|
1686
|
+
* active target instead, exactly like the shipped `.sessionRow.menuOpen`. */
|
|
1687
|
+
const menuTarget = useSyncExternalStore(
|
|
1688
|
+
contextMenus.active.subscribe,
|
|
1689
|
+
contextMenus.active.getSnapshot,
|
|
1690
|
+
contextMenus.active.getSnapshot,
|
|
1691
|
+
)
|
|
1692
|
+
const menuOpenSessionId =
|
|
1693
|
+
menuTarget !== null && menuTarget !== undefined && menuTarget.kind === 'session'
|
|
1694
|
+
? menuTarget.value.sessionId
|
|
1695
|
+
: null
|
|
1696
|
+
const list = useSessions(snapshot => snapshot)
|
|
1697
|
+
const workspaceSnapshot = useWorkspaces(snapshot => snapshot)
|
|
1698
|
+
const statuses = useSessionStatus(snapshot => snapshot)
|
|
1699
|
+
|
|
1700
|
+
const scroller = typeof useSectionScroller === 'function' ? useSectionScroller() : null
|
|
1701
|
+
const bindScrollerRef = scroller === null ? undefined : scroller.bindScrollerRef
|
|
1702
|
+
|
|
1703
|
+
const [editingTitle, setEditingTitle] = useState(false)
|
|
1704
|
+
const [draftTitle, setDraftTitle] = useState('')
|
|
1705
|
+
const [searchOpen, setSearchOpen] = useState(false)
|
|
1706
|
+
const [query, setQuery] = useState('')
|
|
1707
|
+
const [draggingId, setDraggingId] = useState(null)
|
|
1708
|
+
const [dropTarget, setDropTarget] = useState(null)
|
|
1709
|
+
const [workspaceDrag, setWorkspaceDrag] = useState(null)
|
|
1710
|
+
const workspaceDragRef = useRef(null)
|
|
1711
|
+
/* Some browsers still deliver a click after a drag ends; that click must
|
|
1712
|
+
* not also toggle the group open/closed. */
|
|
1713
|
+
const workspaceClickBlockRef = useRef(false)
|
|
1714
|
+
const [menu, setMenu] = useState(null)
|
|
1715
|
+
const [renaming, setRenaming] = useState(null)
|
|
1716
|
+
const [deleting, setDeleting] = useState(null)
|
|
1717
|
+
const [showArchived, setShowArchived] = useState(false)
|
|
1718
|
+
const dragIdRef = useRef(null)
|
|
1719
|
+
const titleInputRef = useRef(null)
|
|
1720
|
+
const cancelTitleRef = useRef(false)
|
|
1721
|
+
const closeMenu = useCallback(() => setMenu(null), [])
|
|
1722
|
+
|
|
1723
|
+
useEffect(() => {
|
|
1724
|
+
if (editingTitle && titleInputRef.current !== null) {
|
|
1725
|
+
titleInputRef.current.focus()
|
|
1726
|
+
titleInputRef.current.select()
|
|
1727
|
+
}
|
|
1728
|
+
}, [editingTitle])
|
|
1729
|
+
|
|
1730
|
+
const items = workspaceSnapshot.items
|
|
1731
|
+
const view = useMemo(() => {
|
|
1732
|
+
const byId = new Map(items.map(item => [item.workspaceId, item]))
|
|
1733
|
+
const byPath = new Map(items.map(item => [item.path, item.workspaceId]))
|
|
1734
|
+
const paths = items.map(item => item.path)
|
|
1735
|
+
const parentOf = new Map()
|
|
1736
|
+
for (const item of items) {
|
|
1737
|
+
const parentPath = owningParentPath(item.path, paths)
|
|
1738
|
+
if (parentPath === null) continue
|
|
1739
|
+
const parentId = byPath.get(parentPath)
|
|
1740
|
+
if (parentId !== undefined) parentOf.set(item.workspaceId, parentId)
|
|
1741
|
+
}
|
|
1742
|
+
const childrenOf = new Map()
|
|
1743
|
+
const roots = []
|
|
1744
|
+
for (const item of items) {
|
|
1745
|
+
const parentId = parentOf.get(item.workspaceId)
|
|
1746
|
+
if (parentId === undefined) {
|
|
1747
|
+
roots.push(item)
|
|
1748
|
+
continue
|
|
1749
|
+
}
|
|
1750
|
+
const bucket = childrenOf.get(parentId)
|
|
1751
|
+
if (bucket === undefined) childrenOf.set(parentId, [item])
|
|
1752
|
+
else bucket.push(item)
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1755
|
+
const archived = new Set(workspaceSnapshot.archivedSessionIds)
|
|
1756
|
+
const pinned = new Set(workspaceSnapshot.pinnedSessionIds)
|
|
1757
|
+
const realOwner = new Map()
|
|
1758
|
+
for (const item of items) for (const id of item.sessionIds) realOwner.set(id, item.workspaceId)
|
|
1759
|
+
const currentId = list.ids.find(id => ((list.byId[id] && list.byId[id].retainedBy.mainView) || 0) > 0) || null
|
|
1760
|
+
|
|
1761
|
+
const ownerOf = id => {
|
|
1762
|
+
const assigned = state.assign[id]
|
|
1763
|
+
if (typeof assigned === 'string' && byId.has(assigned)) return assigned
|
|
1764
|
+
const real = realOwner.get(id)
|
|
1765
|
+
return real === undefined ? UNGROUPED : real
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1768
|
+
const members = new Map()
|
|
1769
|
+
members.set(UNGROUPED, [])
|
|
1770
|
+
for (const item of items) members.set(item.workspaceId, [])
|
|
1771
|
+
|
|
1772
|
+
const needle = query.trim().toLowerCase()
|
|
1773
|
+
const matches = text => needle === '' || String(text || '').toLowerCase().includes(needle)
|
|
1774
|
+
const workspaceMatches = new Map()
|
|
1775
|
+
for (const item of items) workspaceMatches.set(item.workspaceId, matches(item.title) || matches(item.path))
|
|
1776
|
+
|
|
1777
|
+
for (const id of list.ids) {
|
|
1778
|
+
const session = list.byId[id]
|
|
1779
|
+
if (session === undefined) continue
|
|
1780
|
+
if (session.origin === 'subagent') continue
|
|
1781
|
+
if (session.blank && id !== currentId) continue
|
|
1782
|
+
const isArchived = archived.has(id)
|
|
1783
|
+
if (isArchived && !showArchived) continue
|
|
1784
|
+
const key = ownerOf(id)
|
|
1785
|
+
const bucket = members.get(key)
|
|
1786
|
+
if (bucket === undefined) continue
|
|
1787
|
+
const title = sessionTitle(session)
|
|
1788
|
+
if (needle !== '' && !matches(title) && !workspaceMatches.get(key)) continue
|
|
1789
|
+
bucket.push(session)
|
|
1790
|
+
}
|
|
1791
|
+
|
|
1792
|
+
for (const [key, bucket] of members) {
|
|
1793
|
+
const saved = state.order[key]
|
|
1794
|
+
if (!Array.isArray(saved) || saved.length === 0) {
|
|
1795
|
+
bucket.sort((a, b) => (a.updatedAt < b.updatedAt ? 1 : a.updatedAt > b.updatedAt ? -1 : 0))
|
|
1796
|
+
} else {
|
|
1797
|
+
const rank = new Map()
|
|
1798
|
+
for (let index = 0; index < saved.length; index += 1) rank.set(saved[index], index)
|
|
1799
|
+
const known = []
|
|
1800
|
+
const rest = []
|
|
1801
|
+
for (const session of bucket) {
|
|
1802
|
+
if (rank.has(session.id)) known.push(session)
|
|
1803
|
+
else rest.push(session)
|
|
1804
|
+
}
|
|
1805
|
+
known.sort((a, b) => rank.get(a.id) - rank.get(b.id))
|
|
1806
|
+
rest.sort((a, b) => (a.updatedAt < b.updatedAt ? 1 : a.updatedAt > b.updatedAt ? -1 : 0))
|
|
1807
|
+
bucket.splice(0, bucket.length, ...known, ...rest)
|
|
1808
|
+
}
|
|
1809
|
+
/* Shipped section order: the blank row, then pinned rows, then the
|
|
1810
|
+
* rest. Sorting after the manual order keeps both intact. */
|
|
1811
|
+
const leading = []
|
|
1812
|
+
const pinnedRows = []
|
|
1813
|
+
const trailing = []
|
|
1814
|
+
for (const session of bucket) {
|
|
1815
|
+
if (session.blank) leading.push(session)
|
|
1816
|
+
else if (pinned.has(session.id) && !archived.has(session.id)) pinnedRows.push(session)
|
|
1817
|
+
else trailing.push(session)
|
|
1818
|
+
}
|
|
1819
|
+
bucket.splice(0, bucket.length, ...leading, ...pinnedRows, ...trailing)
|
|
1820
|
+
}
|
|
1821
|
+
|
|
1822
|
+
const filtering = needle !== ''
|
|
1823
|
+
let visibleCount = 0
|
|
1824
|
+
for (const bucket of members.values()) visibleCount += bucket.length
|
|
1825
|
+
|
|
1826
|
+
return { byId, parentOf, childrenOf, roots, members, currentId, ownerOf, realOwner, archived, pinned, filtering, visibleCount }
|
|
1827
|
+
}, [items, list, state.order, state.assign, workspaceSnapshot.archivedSessionIds, workspaceSnapshot.pinnedSessionIds, query, showArchived])
|
|
1828
|
+
|
|
1829
|
+
const setExpanded = useCallback((workspaceId, expanded) => {
|
|
1830
|
+
store.update(current => ({
|
|
1831
|
+
...current,
|
|
1832
|
+
collapsed: { ...current.collapsed, [workspaceId]: !expanded },
|
|
1833
|
+
}))
|
|
1834
|
+
}, [])
|
|
1835
|
+
|
|
1836
|
+
/* Workspace reorder. Mirrors the shipped `commitWorkspaceDrag`: the drop
|
|
1837
|
+
* anchor is the next row after the target, and a move that would leave
|
|
1838
|
+
* the order unchanged is dropped instead of being sent to the Host. */
|
|
1839
|
+
const commitWorkspaceDrag = useCallback(
|
|
1840
|
+
(drag, over) => {
|
|
1841
|
+
if (drag === null || over === null) return
|
|
1842
|
+
const owner = view.parentOf.get(drag.workspaceId)
|
|
1843
|
+
if (over !== null && view.parentOf.get(over.id) !== owner) return
|
|
1844
|
+
const siblings = items.filter(item => view.parentOf.get(item.workspaceId) === owner)
|
|
1845
|
+
const rowIndex = siblings.findIndex(item => item.workspaceId === over.id)
|
|
1846
|
+
if (rowIndex === -1) return
|
|
1847
|
+
const anchor = over.half === 'before' ? over.id : (siblings[rowIndex + 1] || {}).workspaceId
|
|
1848
|
+
if (anchor === drag.workspaceId) return
|
|
1849
|
+
const sourceIndex = siblings.findIndex(item => item.workspaceId === drag.workspaceId)
|
|
1850
|
+
const anchorIndex =
|
|
1851
|
+
anchor === undefined ? siblings.length : siblings.findIndex(item => item.workspaceId === anchor)
|
|
1852
|
+
if (sourceIndex !== -1 && (anchorIndex === sourceIndex || anchorIndex === sourceIndex + 1)) return
|
|
1853
|
+
workspaces.insertBefore(drag.workspaceId, anchor).catch(() => {
|
|
1854
|
+
notify(t('errors.reorderFailed'), false)
|
|
1855
|
+
})
|
|
1856
|
+
},
|
|
1857
|
+
[items, view, workspaces, notify, t],
|
|
1858
|
+
)
|
|
1859
|
+
|
|
1860
|
+
const beginWorkspaceDrag = useCallback(workspaceId => {
|
|
1861
|
+
const next = { workspaceId, over: null }
|
|
1862
|
+
workspaceDragRef.current = next
|
|
1863
|
+
workspaceClickBlockRef.current = true
|
|
1864
|
+
setWorkspaceDrag(next)
|
|
1865
|
+
}, [])
|
|
1866
|
+
|
|
1867
|
+
const hoverWorkspaceDrag = useCallback((id, half) => {
|
|
1868
|
+
const current = workspaceDragRef.current
|
|
1869
|
+
if (current === null) return
|
|
1870
|
+
if (current.over !== null && current.over.id === id && current.over.half === half) return
|
|
1871
|
+
const next = { ...current, over: { id, half } }
|
|
1872
|
+
workspaceDragRef.current = next
|
|
1873
|
+
setWorkspaceDrag(next)
|
|
1874
|
+
}, [])
|
|
1875
|
+
|
|
1876
|
+
const endWorkspaceDrag = useCallback(() => {
|
|
1877
|
+
const current = workspaceDragRef.current
|
|
1878
|
+
workspaceDragRef.current = null
|
|
1879
|
+
setWorkspaceDrag(null)
|
|
1880
|
+
if (current !== null && current.over !== null) commitWorkspaceDrag(current, current.over)
|
|
1881
|
+
/* The click that follows a drop arrives after `dragend`; keep the
|
|
1882
|
+
* block for one task so it is swallowed, then re-arm the row. */
|
|
1883
|
+
window.setTimeout(() => {
|
|
1884
|
+
workspaceClickBlockRef.current = false
|
|
1885
|
+
}, 0)
|
|
1886
|
+
}, [commitWorkspaceDrag])
|
|
1887
|
+
|
|
1888
|
+
const assignSession = useCallback(
|
|
1889
|
+
(sessionId, groupKey, beforeSessionId) => {
|
|
1890
|
+
if (typeof sessionId !== 'string' || sessionId === '') return
|
|
1891
|
+
/* The display bucket is re-partitioned blank → pinned → rest after a
|
|
1892
|
+
* drop index is derived, so a drop that crosses the pinned boundary
|
|
1893
|
+
* would land somewhere other than the marker promised. Refuse it. */
|
|
1894
|
+
if (
|
|
1895
|
+
beforeSessionId !== undefined &&
|
|
1896
|
+
beforeSessionId !== null &&
|
|
1897
|
+
view.pinned.has(sessionId) !== view.pinned.has(beforeSessionId)
|
|
1898
|
+
) {
|
|
1899
|
+
return
|
|
1900
|
+
}
|
|
1901
|
+
store.update(current => {
|
|
1902
|
+
const realOwner = view.realOwner.get(sessionId)
|
|
1903
|
+
const previousKey = view.ownerOf(sessionId)
|
|
1904
|
+
const assign = { ...current.assign }
|
|
1905
|
+
if (groupKey === UNGROUPED || groupKey === realOwner) delete assign[sessionId]
|
|
1906
|
+
else assign[sessionId] = groupKey
|
|
1907
|
+
|
|
1908
|
+
const order = { ...current.order }
|
|
1909
|
+
const previous = Array.isArray(order[previousKey]) ? order[previousKey] : null
|
|
1910
|
+
if (previous !== null) order[previousKey] = previous.filter(id => id !== sessionId)
|
|
1911
|
+
const target = Array.isArray(order[groupKey]) ? order[groupKey].slice() : []
|
|
1912
|
+
const without = target.filter(id => id !== sessionId)
|
|
1913
|
+
const at = beforeSessionId === undefined ? -1 : without.indexOf(beforeSessionId)
|
|
1914
|
+
if (at >= 0) without.splice(at, 0, sessionId)
|
|
1915
|
+
else without.push(sessionId)
|
|
1916
|
+
order[groupKey] = without
|
|
1917
|
+
return { ...current, assign, order }
|
|
1918
|
+
})
|
|
1919
|
+
},
|
|
1920
|
+
[view],
|
|
1921
|
+
)
|
|
1922
|
+
|
|
1923
|
+
const openMenu = (target, label) => {
|
|
1924
|
+
if (typeof renderFactorySlot !== 'function') return null
|
|
1925
|
+
const node = renderFactorySlot('contextMenu.button', { target, label, className: 'dnw-iconButton' })
|
|
1926
|
+
if (node !== null && node !== undefined) return node
|
|
1927
|
+
return h('button', { type: 'button', className: 'dnw-iconButton', 'aria-label': label, title: label, onClick: event => event.stopPropagation() }, h(IconDots, null))
|
|
1928
|
+
}
|
|
1929
|
+
|
|
1930
|
+
const openWorkspaceMenu = (event, workspace) => {
|
|
1931
|
+
event.preventDefault()
|
|
1932
|
+
event.stopPropagation()
|
|
1933
|
+
const rect = event.currentTarget.getBoundingClientRect()
|
|
1934
|
+
const atPointer = event.type === 'contextmenu' && (event.clientX !== 0 || event.clientY !== 0)
|
|
1935
|
+
setMenu({
|
|
1936
|
+
workspaceId: workspace.workspaceId,
|
|
1937
|
+
anchor: atPointer
|
|
1938
|
+
? { top: event.clientY, bottom: event.clientY, left: event.clientX }
|
|
1939
|
+
: { top: rect.top, bottom: rect.bottom, left: rect.left },
|
|
1940
|
+
})
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
const menuWorkspace =
|
|
1944
|
+
menu === null ? null : items.find(item => item.workspaceId === menu.workspaceId) || null
|
|
1945
|
+
|
|
1946
|
+
const menuItems = useMemo(() => {
|
|
1947
|
+
if (menuWorkspace === null) return []
|
|
1948
|
+
return [
|
|
1949
|
+
{
|
|
1950
|
+
id: 'addChild',
|
|
1951
|
+
label: t('menu.addChild'),
|
|
1952
|
+
icon: IconFolderPlus,
|
|
1953
|
+
onSelect: () =>
|
|
1954
|
+
addChildRequest.set({
|
|
1955
|
+
parentId: menuWorkspace.workspaceId,
|
|
1956
|
+
parentPath: menuWorkspace.path,
|
|
1957
|
+
parentTitle: menuWorkspace.title,
|
|
1958
|
+
}),
|
|
1959
|
+
},
|
|
1960
|
+
{
|
|
1961
|
+
id: 'newSession',
|
|
1962
|
+
label: t('actions.newSession'),
|
|
1963
|
+
icon: IconPlus,
|
|
1964
|
+
onSelect: () => uiWorkspace.startSession(menuWorkspace.workspaceId),
|
|
1965
|
+
},
|
|
1966
|
+
{
|
|
1967
|
+
id: 'rename',
|
|
1968
|
+
label: t('actions.rename'),
|
|
1969
|
+
icon: IconEdit,
|
|
1970
|
+
separatorBefore: true,
|
|
1971
|
+
onSelect: () => setRenaming(menuWorkspace),
|
|
1972
|
+
},
|
|
1973
|
+
{
|
|
1974
|
+
id: 'delete',
|
|
1975
|
+
label: t('actions.delete'),
|
|
1976
|
+
icon: IconTrash,
|
|
1977
|
+
danger: true,
|
|
1978
|
+
onSelect: () => setDeleting(menuWorkspace),
|
|
1979
|
+
},
|
|
1980
|
+
]
|
|
1981
|
+
}, [menuWorkspace, t, uiWorkspace])
|
|
1982
|
+
|
|
1983
|
+
const commitTitle = () => {
|
|
1984
|
+
/* Escape sets the cancel flag first; the input then unmounts and its
|
|
1985
|
+
* onBlur fires, which must not turn the abandoned draft into a save. */
|
|
1986
|
+
if (cancelTitleRef.current) {
|
|
1987
|
+
cancelTitleRef.current = false
|
|
1988
|
+
setEditingTitle(false)
|
|
1989
|
+
return
|
|
1990
|
+
}
|
|
1991
|
+
const next = draftTitle.trim()
|
|
1992
|
+
store.update(current => ({ ...current, title: next === '' ? null : next }))
|
|
1993
|
+
setEditingTitle(false)
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1996
|
+
const heading = state.title === null ? t('heading.default') : state.title
|
|
1997
|
+
|
|
1998
|
+
if (!wide) {
|
|
1999
|
+
return h(
|
|
2000
|
+
'div',
|
|
2001
|
+
{ className: 'dnw-root dnw-rail' },
|
|
2002
|
+
h(
|
|
2003
|
+
'button',
|
|
2004
|
+
{
|
|
2005
|
+
type: 'button',
|
|
2006
|
+
className: 'dnw-railButton',
|
|
2007
|
+
title: t('rail.search'),
|
|
2008
|
+
'aria-label': t('rail.search'),
|
|
2009
|
+
onClick: () => {
|
|
2010
|
+
setSearchOpen(true)
|
|
2011
|
+
expandSidebar()
|
|
2012
|
+
},
|
|
2013
|
+
},
|
|
2014
|
+
h(IconSearch, null),
|
|
2015
|
+
),
|
|
2016
|
+
h(
|
|
2017
|
+
'button',
|
|
2018
|
+
{
|
|
2019
|
+
type: 'button',
|
|
2020
|
+
className: 'dnw-railButton',
|
|
2021
|
+
title: t('actions.addWorkspace'),
|
|
2022
|
+
'aria-label': t('actions.addWorkspace'),
|
|
2023
|
+
onClick: () => addChildRequest.set({ parentId: null, parentPath: null, parentTitle: null }),
|
|
2024
|
+
},
|
|
2025
|
+
h(IconFolderPlus, null),
|
|
2026
|
+
),
|
|
2027
|
+
)
|
|
2028
|
+
}
|
|
2029
|
+
|
|
2030
|
+
/* One bag of closures for the row components; rebuilt each render. */
|
|
2031
|
+
const env = {
|
|
2032
|
+
view, state, statuses, t, uiWorkspace, list,
|
|
2033
|
+
useSessionAccess, useWorkspaceAccess,
|
|
2034
|
+
openMenu, openWorkspaceMenu, assignSession, setExpanded, setRenaming,
|
|
2035
|
+
menu, menuOpenSessionId, draggingId, dropTarget, dragIdRef, setDraggingId, setDropTarget,
|
|
2036
|
+
workspaceDrag, draggingWorkspaceId: workspaceDrag === null ? null : workspaceDrag.workspaceId,
|
|
2037
|
+
beginWorkspaceDrag, hoverWorkspaceDrag, endWorkspaceDrag, workspaceClickBlockRef,
|
|
2038
|
+
now: Date.now(),
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
const tree = []
|
|
2042
|
+
for (const root of view.roots) tree.push(h(WorkspaceGroup, { key: 'grp:' + root.workspaceId, workspace: root, depth: 0, env }))
|
|
2043
|
+
|
|
2044
|
+
const ungrouped = view.members.get(UNGROUPED) || []
|
|
2045
|
+
const ungroupedCollapsed = state.collapsed[UNGROUPED] === true
|
|
2046
|
+
const isUngroupedDrop =
|
|
2047
|
+
dropTarget !== null && dropTarget.workspaceId === UNGROUPED && dropTarget.sessionId === undefined
|
|
2048
|
+
if (ungrouped.length > 0) {
|
|
2049
|
+
tree.push(
|
|
2050
|
+
h(
|
|
2051
|
+
'div',
|
|
2052
|
+
{
|
|
2053
|
+
key: 'w:ungrouped',
|
|
2054
|
+
className: cls('dnw-row', 'dnw-workspaceRow'),
|
|
2055
|
+
role: 'treeitem',
|
|
2056
|
+
tabIndex: 0,
|
|
2057
|
+
'aria-expanded': !ungroupedCollapsed,
|
|
2058
|
+
style: { '--dnw-indent': '0px' },
|
|
2059
|
+
onClick: () => setExpanded(UNGROUPED, ungroupedCollapsed),
|
|
2060
|
+
onKeyDown: event => {
|
|
2061
|
+
if (event.target !== event.currentTarget) return
|
|
2062
|
+
if (event.key !== 'Enter' && event.key !== ' ') return
|
|
2063
|
+
event.preventDefault()
|
|
2064
|
+
setExpanded(UNGROUPED, ungroupedCollapsed)
|
|
2065
|
+
},
|
|
2066
|
+
onDragOver: event => {
|
|
2067
|
+
if (workspaceDrag !== null) return
|
|
2068
|
+
if (dragIdRef.current === null) return
|
|
2069
|
+
event.preventDefault()
|
|
2070
|
+
event.stopPropagation()
|
|
2071
|
+
if (!isUngroupedDrop) setDropTarget({ workspaceId: UNGROUPED, mode: 'into' })
|
|
2072
|
+
},
|
|
2073
|
+
onDragLeave: event => {
|
|
2074
|
+
if (event.currentTarget.contains(event.relatedTarget)) return
|
|
2075
|
+
if (isUngroupedDrop) setDropTarget(null)
|
|
2076
|
+
},
|
|
2077
|
+
onDrop: event => {
|
|
2078
|
+
event.preventDefault()
|
|
2079
|
+
event.stopPropagation()
|
|
2080
|
+
/* The ungrouped bucket is not a real workspace: it accepts
|
|
2081
|
+
* sessions but must never take part in a workspace reorder. */
|
|
2082
|
+
if (workspaceDrag !== null) return
|
|
2083
|
+
const id = dragIdRef.current || event.dataTransfer.getData('text/plain')
|
|
2084
|
+
setDropTarget(null)
|
|
2085
|
+
setDraggingId(null)
|
|
2086
|
+
dragIdRef.current = null
|
|
2087
|
+
if (id) assignSession(id, UNGROUPED, undefined)
|
|
2088
|
+
},
|
|
2089
|
+
},
|
|
2090
|
+
h(
|
|
2091
|
+
'span',
|
|
2092
|
+
{ className: 'dnw-slot dnw-lead' },
|
|
2093
|
+
h(
|
|
2094
|
+
'button',
|
|
2095
|
+
{
|
|
2096
|
+
type: 'button',
|
|
2097
|
+
className: cls('dnw-chevron', !ungroupedCollapsed && 'dnw-chevronOpen'),
|
|
2098
|
+
'aria-label': (ungroupedCollapsed ? t('expandGroup') : t('collapseGroup')) + ' ' + t('ungrouped'),
|
|
2099
|
+
onClick: event => {
|
|
2100
|
+
event.stopPropagation()
|
|
2101
|
+
setExpanded(UNGROUPED, ungroupedCollapsed)
|
|
2102
|
+
},
|
|
2103
|
+
},
|
|
2104
|
+
h('span', { className: 'dnw-arrowInner' }, h(IconChevron, null)),
|
|
2105
|
+
),
|
|
2106
|
+
h('span', { className: cls('dnw-folderIcon', !ungroupedCollapsed && 'dnw-folderActive') }, h(IconFolder, null)),
|
|
2107
|
+
),
|
|
2108
|
+
h('span', { className: 'dnw-title dnw-titleMuted' }, t('ungrouped')),
|
|
2109
|
+
),
|
|
2110
|
+
ungroupedCollapsed
|
|
2111
|
+
? null
|
|
2112
|
+
: h('div', { key: 'g:ungrouped', role: 'group' }, ungrouped.map((session, index) => h(SessionRow, { key: 's:' + session.id, session, groupKey: UNGROUPED, index, bucket: ungrouped, env }))),
|
|
2113
|
+
)
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2116
|
+
const empty = view.roots.length === 0 && ungrouped.length === 0 && !view.filtering
|
|
2117
|
+
const noMatches = view.filtering && view.visibleCount === 0
|
|
2118
|
+
|
|
2119
|
+
return h(
|
|
2120
|
+
'div',
|
|
2121
|
+
{ className: 'dnw-root' },
|
|
2122
|
+
h(
|
|
2123
|
+
'div',
|
|
2124
|
+
{ className: 'dnw-header' },
|
|
2125
|
+
editingTitle
|
|
2126
|
+
? h('input', {
|
|
2127
|
+
ref: titleInputRef,
|
|
2128
|
+
className: 'dnw-headingInput',
|
|
2129
|
+
value: draftTitle,
|
|
2130
|
+
'aria-label': t('heading.default'),
|
|
2131
|
+
spellCheck: false,
|
|
2132
|
+
onChange: event => setDraftTitle(event.target.value),
|
|
2133
|
+
onBlur: commitTitle,
|
|
2134
|
+
onKeyDown: event => {
|
|
2135
|
+
if (event.key === 'Enter') {
|
|
2136
|
+
event.preventDefault()
|
|
2137
|
+
commitTitle()
|
|
2138
|
+
} else if (event.key === 'Escape') {
|
|
2139
|
+
event.preventDefault()
|
|
2140
|
+
cancelTitleRef.current = true
|
|
2141
|
+
setEditingTitle(false)
|
|
2142
|
+
}
|
|
2143
|
+
},
|
|
2144
|
+
})
|
|
2145
|
+
: h(
|
|
2146
|
+
'span',
|
|
2147
|
+
{
|
|
2148
|
+
className: 'dnw-label dnw-labelEditable',
|
|
2149
|
+
role: 'button',
|
|
2150
|
+
tabIndex: 0,
|
|
2151
|
+
title: t('heading.hint'),
|
|
2152
|
+
'aria-label': heading,
|
|
2153
|
+
'aria-description': t('heading.hint'),
|
|
2154
|
+
onDoubleClick: event => {
|
|
2155
|
+
event.preventDefault()
|
|
2156
|
+
cancelTitleRef.current = false
|
|
2157
|
+
setDraftTitle(heading)
|
|
2158
|
+
setEditingTitle(true)
|
|
2159
|
+
},
|
|
2160
|
+
onKeyDown: event => {
|
|
2161
|
+
if (event.key === 'Enter' || event.key === 'F2') {
|
|
2162
|
+
event.preventDefault()
|
|
2163
|
+
cancelTitleRef.current = false
|
|
2164
|
+
setDraftTitle(heading)
|
|
2165
|
+
setEditingTitle(true)
|
|
2166
|
+
}
|
|
2167
|
+
},
|
|
2168
|
+
},
|
|
2169
|
+
heading,
|
|
2170
|
+
),
|
|
2171
|
+
h(
|
|
2172
|
+
'div',
|
|
2173
|
+
{ className: 'dnw-headerActions' },
|
|
2174
|
+
h(
|
|
2175
|
+
'button',
|
|
2176
|
+
{
|
|
2177
|
+
type: 'button',
|
|
2178
|
+
className: cls('dnw-iconButton', showArchived && 'dnw-iconButtonOn'),
|
|
2179
|
+
title: showArchived ? t('actions.hideArchived') : t('actions.showArchived'),
|
|
2180
|
+
'aria-label': showArchived ? t('actions.hideArchived') : t('actions.showArchived'),
|
|
2181
|
+
'aria-pressed': showArchived,
|
|
2182
|
+
onClick: () => setShowArchived(current => !current),
|
|
2183
|
+
},
|
|
2184
|
+
h(IconArchive, null),
|
|
2185
|
+
),
|
|
2186
|
+
h(
|
|
2187
|
+
'button',
|
|
2188
|
+
{
|
|
2189
|
+
type: 'button',
|
|
2190
|
+
className: 'dnw-iconButton',
|
|
2191
|
+
title: t('actions.search'),
|
|
2192
|
+
'aria-label': t('actions.search'),
|
|
2193
|
+
onClick: () => {
|
|
2194
|
+
setSearchOpen(open => {
|
|
2195
|
+
if (open) setQuery('')
|
|
2196
|
+
return !open
|
|
2197
|
+
})
|
|
2198
|
+
},
|
|
2199
|
+
},
|
|
2200
|
+
h(IconSearch, null),
|
|
2201
|
+
),
|
|
2202
|
+
h(
|
|
2203
|
+
'button',
|
|
2204
|
+
{
|
|
2205
|
+
type: 'button',
|
|
2206
|
+
className: 'dnw-iconButton',
|
|
2207
|
+
title: t('actions.addWorkspace'),
|
|
2208
|
+
'aria-label': t('actions.addWorkspace'),
|
|
2209
|
+
onClick: () => addChildRequest.set({ parentId: null, parentPath: null, parentTitle: null }),
|
|
2210
|
+
},
|
|
2211
|
+
h(IconFolderPlus, null),
|
|
2212
|
+
),
|
|
2213
|
+
),
|
|
2214
|
+
),
|
|
2215
|
+
searchOpen
|
|
2216
|
+
? h(
|
|
2217
|
+
'div',
|
|
2218
|
+
{ className: 'dnw-searchRow' },
|
|
2219
|
+
h('input', {
|
|
2220
|
+
className: 'dnw-searchInput',
|
|
2221
|
+
value: query,
|
|
2222
|
+
placeholder: t('actions.search'),
|
|
2223
|
+
'aria-label': t('actions.search'),
|
|
2224
|
+
spellCheck: false,
|
|
2225
|
+
autoFocus: true,
|
|
2226
|
+
onChange: event => setQuery(event.target.value),
|
|
2227
|
+
onKeyDown: event => {
|
|
2228
|
+
if (event.key === 'Escape') {
|
|
2229
|
+
event.preventDefault()
|
|
2230
|
+
setQuery('')
|
|
2231
|
+
setSearchOpen(false)
|
|
2232
|
+
}
|
|
2233
|
+
},
|
|
2234
|
+
}),
|
|
2235
|
+
)
|
|
2236
|
+
: null,
|
|
2237
|
+
h(
|
|
2238
|
+
'div',
|
|
2239
|
+
{ className: 'dnw-list', ref: bindScrollerRef, 'data-sidebar-list-area': '', role: 'tree', 'aria-label': heading },
|
|
2240
|
+
empty
|
|
2241
|
+
? h('div', { className: 'dnw-empty' }, t('empty'))
|
|
2242
|
+
: noMatches
|
|
2243
|
+
? h('div', { className: 'dnw-empty' }, t('search.empty'))
|
|
2244
|
+
: tree,
|
|
2245
|
+
),
|
|
2246
|
+
request === null ? null : h(NewWorkspaceDialog, { request, onClose: () => addChildRequest.set(null) }),
|
|
2247
|
+
menuWorkspace === null
|
|
2248
|
+
? null
|
|
2249
|
+
: h(MenuPopover, { anchor: menu.anchor, items: menuItems, onClose: closeMenu }),
|
|
2250
|
+
renaming === null ? null : h(WorkspaceRenameDialog, { workspace: renaming, onClose: () => setRenaming(null) }),
|
|
2251
|
+
deleting === null ? null : h(WorkspaceDeleteDialog, { workspace: deleting, onClose: () => setDeleting(null) }),
|
|
2252
|
+
)
|
|
2253
|
+
}
|
|
2254
|
+
|
|
2255
|
+
ctx.slots.inject('sidebar.workspaces', () =>
|
|
2256
|
+
ctx.slots.register(
|
|
2257
|
+
{
|
|
2258
|
+
name: 'sidebar.workspaces',
|
|
2259
|
+
priority: -1,
|
|
2260
|
+
locale: NS,
|
|
2261
|
+
},
|
|
2262
|
+
Sidebar,
|
|
2263
|
+
),
|
|
2264
|
+
)
|
|
2265
|
+
|
|
2266
|
+
function sessionTitle(session) {
|
|
2267
|
+
if (session.blank) return ''
|
|
2268
|
+
const title = typeof session.title === 'string' ? session.title.trim() : ''
|
|
2269
|
+
return title !== '' ? title : session.displayTitle || ''
|
|
2270
|
+
}
|
|
2271
|
+
},
|
|
2272
|
+
}
|
|
2273
|
+
},
|
|
2274
|
+
})
|