dsh-nested-workspaces 0.0.0-stage → 1.0.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 +92 -2
- package/client.js +1785 -0
- package/cordis.patch.yml +3 -0
- package/icon.svg +7 -0
- package/index.js +8 -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,1785 @@
|
|
|
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
|
+
},
|
|
74
|
+
en: {
|
|
75
|
+
'heading.default': 'Workspaces',
|
|
76
|
+
'heading.hint': 'Double-click to rename; clear it to restore the default',
|
|
77
|
+
'menu.addChild': 'Add child workspace',
|
|
78
|
+
'actions.addWorkspace': 'Add workspace',
|
|
79
|
+
'actions.newSession': 'New session',
|
|
80
|
+
'actions.search': 'Search workspaces or sessions',
|
|
81
|
+
'actions.menu': 'More actions',
|
|
82
|
+
'actions.rename': 'Rename',
|
|
83
|
+
'actions.delete': 'Delete workspace',
|
|
84
|
+
'actions.unarchive': 'Unarchive',
|
|
85
|
+
'actions.create': 'Create',
|
|
86
|
+
'actions.cancel': 'Cancel',
|
|
87
|
+
'actions.confirm': 'Delete',
|
|
88
|
+
'dialog.rename.title': 'Rename workspace',
|
|
89
|
+
'dialog.delete.title': 'Delete workspace',
|
|
90
|
+
'dialog.delete.description': 'This removes "{name}" from the sidebar. Files on disk are kept.',
|
|
91
|
+
'renamed': 'Renamed',
|
|
92
|
+
'deleted': 'Workspace deleted',
|
|
93
|
+
'dialog.addChild.title': 'Add child workspace',
|
|
94
|
+
'dialog.addWorkspace.title': 'Add workspace',
|
|
95
|
+
'dialog.addChild.description': 'A new child workspace directory will be created under {parent}.',
|
|
96
|
+
'dialog.addWorkspace.description': 'Enter the absolute path of the workspace directory, or leave it empty to pick a folder.',
|
|
97
|
+
'field.name': 'Child workspace name',
|
|
98
|
+
'field.path': 'Workspace path (empty to pick)',
|
|
99
|
+
'errors.nameRequired': 'Enter a name.',
|
|
100
|
+
'errors.nameInvalid': 'The name must not contain path separators.',
|
|
101
|
+
'errors.exists': 'A directory with that name already exists.',
|
|
102
|
+
'errors.createFailed': 'Could not create: {message}',
|
|
103
|
+
'errors.renameFailed': 'Could not rename: {message}',
|
|
104
|
+
'errors.deleteFailed': 'Could not delete: {message}',
|
|
105
|
+
'actions.moveTo': 'Move to',
|
|
106
|
+
'actions.showArchived': 'Show archived sessions',
|
|
107
|
+
'actions.hideArchived': 'Hide archived sessions',
|
|
108
|
+
'created': 'Workspace created',
|
|
109
|
+
'createdChild': 'Child workspace created',
|
|
110
|
+
'moved': 'Session moved',
|
|
111
|
+
'rail.search': 'Search',
|
|
112
|
+
'expandGroup': 'Expand group',
|
|
113
|
+
'collapseGroup': 'Collapse group',
|
|
114
|
+
'session.new': 'New session',
|
|
115
|
+
'session.untitled': 'Untitled session',
|
|
116
|
+
'ungrouped': 'Ungrouped',
|
|
117
|
+
'empty': 'No sessions',
|
|
118
|
+
'search.empty': 'No matches',
|
|
119
|
+
},
|
|
120
|
+
ja: {
|
|
121
|
+
'heading.default': 'ワークスペース',
|
|
122
|
+
'heading.hint': 'ダブルクリックで名前を変更、空欄で既定に戻す',
|
|
123
|
+
'menu.addChild': '子ワークスペースを追加',
|
|
124
|
+
'actions.addWorkspace': 'ワークスペースを追加',
|
|
125
|
+
'actions.newSession': '新しいセッション',
|
|
126
|
+
'actions.search': '検索',
|
|
127
|
+
'actions.menu': 'その他の操作',
|
|
128
|
+
'actions.rename': '名前を変更',
|
|
129
|
+
'actions.delete': 'ワークスペースを削除',
|
|
130
|
+
'actions.unarchive': 'アーカイブ解除',
|
|
131
|
+
'actions.create': '作成',
|
|
132
|
+
'actions.cancel': 'キャンセル',
|
|
133
|
+
'actions.confirm': '削除',
|
|
134
|
+
'dialog.rename.title': 'ワークスペース名を変更',
|
|
135
|
+
'dialog.delete.title': 'ワークスペースを削除',
|
|
136
|
+
'dialog.delete.description': '「{name}」をサイドバーから削除します。ディスク上のファイルは残ります。',
|
|
137
|
+
'renamed': '名前を変更しました',
|
|
138
|
+
'deleted': 'ワークスペースを削除しました',
|
|
139
|
+
'dialog.addChild.title': '子ワークスペースを追加',
|
|
140
|
+
'dialog.addWorkspace.title': 'ワークスペースを追加',
|
|
141
|
+
'dialog.addChild.description': '{parent} の下に子ワークスペースを作成します。',
|
|
142
|
+
'dialog.addWorkspace.description': 'ワークスペースの絶対パスを入力するか、空欄のままフォルダを選択してください。',
|
|
143
|
+
'field.name': '子ワークスペース名',
|
|
144
|
+
'field.path': 'ワークスペースのパス(空欄で選択)',
|
|
145
|
+
'errors.nameRequired': '名前を入力してください。',
|
|
146
|
+
'errors.nameInvalid': '名前にパス区切り文字は使えません。',
|
|
147
|
+
'errors.exists': '同じ名前のディレクトリが既に存在します。',
|
|
148
|
+
'errors.createFailed': '作成できませんでした: {message}',
|
|
149
|
+
'errors.renameFailed': '名前を変更できませんでした: {message}',
|
|
150
|
+
'errors.deleteFailed': '削除できませんでした: {message}',
|
|
151
|
+
'actions.moveTo': '移動先',
|
|
152
|
+
'actions.showArchived': 'アーカイブ済みを表示',
|
|
153
|
+
'actions.hideArchived': 'アーカイブ済みを隠す',
|
|
154
|
+
'created': 'ワークスペースを作成しました',
|
|
155
|
+
'createdChild': '子ワークスペースを作成しました',
|
|
156
|
+
'moved': 'セッションを移動しました',
|
|
157
|
+
'rail.search': '検索',
|
|
158
|
+
'expandGroup': 'グループを開く',
|
|
159
|
+
'collapseGroup': 'グループを閉じる',
|
|
160
|
+
'session.new': '新しいセッション',
|
|
161
|
+
'session.untitled': '無題のセッション',
|
|
162
|
+
'ungrouped': '未分類',
|
|
163
|
+
'empty': 'セッションはありません',
|
|
164
|
+
'search.empty': '一致する項目はありません',
|
|
165
|
+
},
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/* ------------------------------------------------------------------- styles */
|
|
169
|
+
|
|
170
|
+
const CSS = `
|
|
171
|
+
.dnw-root{display:flex;flex-direction:column;min-height:0;height:100%;color:var(--dsw-alias-label-primary)}
|
|
172
|
+
.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)}
|
|
173
|
+
.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}
|
|
174
|
+
.dnw-labelEditable{cursor:text;border-radius:var(--dsw-radius-xs);padding:0 2px;margin:0 -2px}
|
|
175
|
+
.dnw-labelEditable:hover{color:var(--dsw-alias-label-secondary)}
|
|
176
|
+
.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}
|
|
177
|
+
.dnw-headerActions{display:flex;align-items:center;gap:4px;flex:none;margin-left:auto}
|
|
178
|
+
.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}
|
|
179
|
+
.dnw-iconButton:hover{background-color:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
|
|
180
|
+
.dnw-iconButtonOn{background-color:var(--dsw-alias-interactive-bg-active);color:var(--dsw-alias-label-primary)}
|
|
181
|
+
.dnw-rowDragging{opacity:0.5}
|
|
182
|
+
.dnw-iconButton:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:1px}
|
|
183
|
+
.dnw-list{flex:1;min-height:0;overflow-y:auto;overflow-x:hidden;padding-bottom:8px;scrollbar-width:thin}
|
|
184
|
+
.dnw-searchRow{padding:0 8px 4px;padding-left:var(--dsh-sidebar-row-padding,12px)}
|
|
185
|
+
.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}
|
|
186
|
+
.dnw-searchInput:focus{border-color:var(--dsw-alias-state-business-primary)}
|
|
187
|
+
.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)}
|
|
188
|
+
@media (hover:hover){.dnw-row:hover{background-color:var(--dsw-alias-interactive-bg-hover)}}
|
|
189
|
+
.dnw-rowSelected{background-color:var(--dsw-alias-interactive-bg-hover)}
|
|
190
|
+
.dnw-row:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:-2px}
|
|
191
|
+
.dnw-slot{flex:none;display:inline-flex;align-items:center;justify-content:center;width:16px;height:20px;color:var(--dsw-alias-label-tertiary)}
|
|
192
|
+
.dnw-lead{position:relative}
|
|
193
|
+
.dnw-folderIcon{display:inline-flex;align-items:center;justify-content:center;width:16px;height:20px;color:var(--dsw-alias-label-tertiary)}
|
|
194
|
+
.dnw-folderActive{color:var(--dsw-alias-state-business-primary)}
|
|
195
|
+
.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}
|
|
196
|
+
.dnw-workspaceRow:hover .dnw-folderIcon,.dnw-workspaceRow:focus-within .dnw-folderIcon{display:none}
|
|
197
|
+
.dnw-workspaceRow:hover .dnw-chevron,.dnw-workspaceRow:focus-within .dnw-chevron,.dnw-workspaceRow:has(.dnw-chevronOpen) .dnw-chevron{display:inline-flex}
|
|
198
|
+
.dnw-workspaceRow:has(.dnw-chevronOpen) .dnw-folderIcon{display:none}
|
|
199
|
+
@media (hover:none){.dnw-chevron{display:inline-flex}.dnw-folderIcon{display:none}}
|
|
200
|
+
.dnw-arrowInner{display:inline-flex;transition:transform 150ms var(--ds-ease-in-out,ease)}
|
|
201
|
+
.dnw-chevronOpen .dnw-arrowInner{transform:rotate(90deg)}
|
|
202
|
+
.dnw-title{min-width:0;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:14px;line-height:20px}
|
|
203
|
+
.dnw-titleMuted{color:var(--dsw-alias-label-caption)}
|
|
204
|
+
.dnw-rowArchived .dnw-title{color:var(--dsw-alias-label-caption)}
|
|
205
|
+
.dnw-actions{flex:none;display:none;align-items:center;gap:13px}
|
|
206
|
+
.dnw-row:hover .dnw-actions,.dnw-actionsOpen{display:flex}
|
|
207
|
+
@media (hover:none){.dnw-actions{display:flex}}
|
|
208
|
+
.dnw-dot{width:6px;height:6px;border-radius:50%;background:var(--dsw-alias-state-business-primary);flex:none}
|
|
209
|
+
.dnw-dotIdle{background:var(--dsw-alias-label-caption);opacity:.5}
|
|
210
|
+
.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)}
|
|
211
|
+
.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)}
|
|
212
|
+
.dnw-dropBefore::before{top:-8px}
|
|
213
|
+
.dnw-dropAfter::after{bottom:-8px}
|
|
214
|
+
.dnw-dropOn{background-color:var(--dsw-alias-interactive-bg-hover);box-shadow:inset 0 0 0 1px var(--dsw-alias-state-business-primary)}
|
|
215
|
+
.dnw-rail{display:flex;flex-direction:column;align-items:center;gap:6px;padding:6px 0}
|
|
216
|
+
.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}
|
|
217
|
+
.dnw-railButton:hover{background-color:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
|
|
218
|
+
.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)}
|
|
219
|
+
.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}
|
|
220
|
+
.dnw-dialogTitle{font-size:15px;font-weight:600;line-height:22px}
|
|
221
|
+
.dnw-dialogText{font-size:13px;line-height:19px;color:var(--dsw-alias-label-secondary);word-break:break-all}
|
|
222
|
+
.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}
|
|
223
|
+
.dnw-dialogInput:focus{border-color:var(--dsw-alias-state-business-primary)}
|
|
224
|
+
.dnw-dialogError{font-size:13px;line-height:19px;color:var(--dsw-alias-state-error-primary,#d33)}
|
|
225
|
+
.dnw-dialogFooter{display:flex;justify-content:flex-end;gap:8px;margin-top:2px}
|
|
226
|
+
.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}
|
|
227
|
+
.dnw-button:hover{background-color:var(--dsw-alias-interactive-bg-hover)}
|
|
228
|
+
.dnw-buttonPrimary{border-color:transparent;background:var(--dsw-alias-state-business-primary);color:#fff}
|
|
229
|
+
.dnw-buttonDanger{background:var(--dsw-alias-state-error-primary,#d33)}
|
|
230
|
+
.dnw-button:disabled{opacity:.5;cursor:default}
|
|
231
|
+
.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}
|
|
232
|
+
.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}
|
|
233
|
+
.dnw-menuItem:hover,.dnw-menuItem:focus-visible,.dnw-menuItemActive{background-color:var(--dsw-alias-interactive-bg-hover);outline:none}
|
|
234
|
+
.dnw-menuItemDanger{color:var(--dsw-alias-state-error-primary,#d33)}
|
|
235
|
+
.dnw-menuIcon{flex:none;display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;color:var(--dsw-alias-label-tertiary)}
|
|
236
|
+
.dnw-menuItemDanger .dnw-menuIcon{color:inherit}
|
|
237
|
+
.dnw-menuSeparator{height:1px;margin:4px 6px;background:var(--dsw-alias-border-l4,rgba(0,0,0,.08))}
|
|
238
|
+
@media (prefers-reduced-motion: reduce){.dnw-arrowInner{transition:none}}
|
|
239
|
+
@media (pointer:coarse){.dnw-searchInput,.dnw-headingInput,.dnw-dialogInput{font-size:16px}}
|
|
240
|
+
`
|
|
241
|
+
function ensureStyles() {
|
|
242
|
+
const head = typeof document === 'undefined' || document === null ? null : document.head
|
|
243
|
+
if (head === null) return () => {}
|
|
244
|
+
let element = head.querySelector('style[data-plugin-css="' + STYLE_ID + '"]')
|
|
245
|
+
if (element === null) {
|
|
246
|
+
element = document.createElement('style')
|
|
247
|
+
element.setAttribute('data-plugin-css', STYLE_ID)
|
|
248
|
+
element.textContent = CSS
|
|
249
|
+
head.appendChild(element)
|
|
250
|
+
return () => {
|
|
251
|
+
element.remove()
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
element.textContent = CSS
|
|
255
|
+
return () => {}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/* -------------------------------------------------------------------- icons */
|
|
259
|
+
|
|
260
|
+
const svg = (children, extra) =>
|
|
261
|
+
h(
|
|
262
|
+
'svg',
|
|
263
|
+
Object.assign(
|
|
264
|
+
{
|
|
265
|
+
width: 16,
|
|
266
|
+
height: 16,
|
|
267
|
+
viewBox: '0 0 20 20',
|
|
268
|
+
fill: 'none',
|
|
269
|
+
stroke: 'currentColor',
|
|
270
|
+
strokeWidth: 1.6,
|
|
271
|
+
strokeLinecap: 'round',
|
|
272
|
+
strokeLinejoin: 'round',
|
|
273
|
+
'aria-hidden': 'true',
|
|
274
|
+
focusable: 'false',
|
|
275
|
+
},
|
|
276
|
+
extra || null,
|
|
277
|
+
),
|
|
278
|
+
children,
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
const IconChevron = () => svg(h('path', { key: 'p', d: 'M8 5l4.5 5L8 15' }))
|
|
282
|
+
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' }))
|
|
283
|
+
const IconFolderPlus = () =>
|
|
284
|
+
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' })])
|
|
285
|
+
const IconPlus = () => svg(h('path', { key: 'p', d: 'M10 4.5v11M4.5 10h11' }))
|
|
286
|
+
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' })])
|
|
287
|
+
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' })])
|
|
288
|
+
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' })])
|
|
289
|
+
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' })])
|
|
290
|
+
const IconClose = () => svg([h('path', { key: 'p', d: 'M6 6l8 8M14 6l-8 8' })])
|
|
291
|
+
const IconArchive = () =>
|
|
292
|
+
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' })])
|
|
293
|
+
const IconUnarchive = () =>
|
|
294
|
+
svg([
|
|
295
|
+
h('path', { key: 'a', d: 'M3.5 5.5h13v3h-13z' }),
|
|
296
|
+
h('path', { key: 'b', d: 'M4.8 8.5v6.2h10.4V8.5' }),
|
|
297
|
+
h('path', { key: 'c', d: 'M10 13.4V9.9M8.4 11.5L10 9.9l1.6 1.6' }),
|
|
298
|
+
])
|
|
299
|
+
|
|
300
|
+
/* ---------------------------------------------------------------- utilities */
|
|
301
|
+
|
|
302
|
+
const cls = (...parts) => parts.filter(Boolean).join(' ')
|
|
303
|
+
|
|
304
|
+
function isRecord(value) {
|
|
305
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function folderPath(path) {
|
|
309
|
+
const windows = /^[A-Za-z]:[/\\]/.test(path) || path.startsWith('\\\\')
|
|
310
|
+
const normalized = windows ? path.replaceAll('\\', '/') : path
|
|
311
|
+
return normalized.replace(/\/+$/, '')
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** Longest registered ancestor directory of `path`, returned in its original form. */
|
|
315
|
+
function owningParentPath(path, roots) {
|
|
316
|
+
const child = folderPath(path)
|
|
317
|
+
let best = null
|
|
318
|
+
let bestLength = -1
|
|
319
|
+
for (const root of roots) {
|
|
320
|
+
if (root === path) continue
|
|
321
|
+
const parent = folderPath(root)
|
|
322
|
+
if (parent === '' || child === parent) continue
|
|
323
|
+
if (!child.startsWith(parent + '/')) continue
|
|
324
|
+
if (parent.length > bestLength) {
|
|
325
|
+
best = root
|
|
326
|
+
bestLength = parent.length
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return best
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function createSignal(initial) {
|
|
333
|
+
let value = initial
|
|
334
|
+
const listeners = new Set()
|
|
335
|
+
return {
|
|
336
|
+
get: () => value,
|
|
337
|
+
set(next) {
|
|
338
|
+
if (Object.is(next, value)) return
|
|
339
|
+
value = next
|
|
340
|
+
for (const listener of listeners) listener()
|
|
341
|
+
},
|
|
342
|
+
subscribe(listener) {
|
|
343
|
+
listeners.add(listener)
|
|
344
|
+
return () => {
|
|
345
|
+
listeners.delete(listener)
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function createStore() {
|
|
352
|
+
const read = () => {
|
|
353
|
+
const empty = { title: null, assign: {}, order: {}, collapsed: {} }
|
|
354
|
+
if (typeof localStorage === 'undefined') return empty
|
|
355
|
+
try {
|
|
356
|
+
const raw = localStorage.getItem(STORAGE_KEY)
|
|
357
|
+
if (raw === null || raw === '') return empty
|
|
358
|
+
const parsed = JSON.parse(raw)
|
|
359
|
+
if (!isRecord(parsed)) return empty
|
|
360
|
+
return {
|
|
361
|
+
title: typeof parsed.title === 'string' && parsed.title.trim() !== '' ? parsed.title : null,
|
|
362
|
+
assign: isRecord(parsed.assign) ? parsed.assign : {},
|
|
363
|
+
order: isRecord(parsed.order) ? parsed.order : {},
|
|
364
|
+
collapsed: isRecord(parsed.collapsed) ? parsed.collapsed : {},
|
|
365
|
+
}
|
|
366
|
+
} catch {
|
|
367
|
+
return empty
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
let state = read()
|
|
371
|
+
const listeners = new Set()
|
|
372
|
+
const write = () => {
|
|
373
|
+
if (typeof localStorage === 'undefined') return
|
|
374
|
+
try {
|
|
375
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(state))
|
|
376
|
+
} catch {
|
|
377
|
+
/* storage full or blocked: the view still works for this tab */
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return {
|
|
381
|
+
get: () => state,
|
|
382
|
+
subscribe(listener) {
|
|
383
|
+
listeners.add(listener)
|
|
384
|
+
return () => {
|
|
385
|
+
listeners.delete(listener)
|
|
386
|
+
}
|
|
387
|
+
},
|
|
388
|
+
update(recipe) {
|
|
389
|
+
state = recipe(state)
|
|
390
|
+
write()
|
|
391
|
+
for (const listener of listeners) listener()
|
|
392
|
+
},
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Re-home one session inside the plugin's own grouping. The workspace
|
|
398
|
+
* controller refuses to move a session into a workspace whose path is not
|
|
399
|
+
* the session's recorded cwd, so this is a display assignment: the row is
|
|
400
|
+
* rendered under `groupKey` while its cwd stays untouched.
|
|
401
|
+
*/
|
|
402
|
+
function assignSessionIn(store, items, sessionId, groupKey, beforeSessionId) {
|
|
403
|
+
if (typeof sessionId !== 'string' || sessionId === '') return
|
|
404
|
+
store.update(current => {
|
|
405
|
+
const known = new Set()
|
|
406
|
+
let realOwner = null
|
|
407
|
+
for (const item of items) {
|
|
408
|
+
known.add(item.workspaceId)
|
|
409
|
+
if (realOwner === null && item.sessionIds.includes(sessionId)) realOwner = item.workspaceId
|
|
410
|
+
}
|
|
411
|
+
const assigned = current.assign[sessionId]
|
|
412
|
+
const previousKey =
|
|
413
|
+
typeof assigned === 'string' && known.has(assigned)
|
|
414
|
+
? assigned
|
|
415
|
+
: realOwner === null
|
|
416
|
+
? UNGROUPED
|
|
417
|
+
: realOwner
|
|
418
|
+
|
|
419
|
+
const assign = { ...current.assign }
|
|
420
|
+
if (groupKey === UNGROUPED || groupKey === realOwner) delete assign[sessionId]
|
|
421
|
+
else assign[sessionId] = groupKey
|
|
422
|
+
|
|
423
|
+
const order = { ...current.order }
|
|
424
|
+
const previous = Array.isArray(order[previousKey]) ? order[previousKey] : null
|
|
425
|
+
if (previous !== null) order[previousKey] = previous.filter(id => id !== sessionId)
|
|
426
|
+
const target = Array.isArray(order[groupKey]) ? order[groupKey].slice() : []
|
|
427
|
+
const without = target.filter(id => id !== sessionId)
|
|
428
|
+
const at = beforeSessionId === undefined ? -1 : without.indexOf(beforeSessionId)
|
|
429
|
+
if (at >= 0) without.splice(at, 0, sessionId)
|
|
430
|
+
else without.push(sessionId)
|
|
431
|
+
order[groupKey] = without
|
|
432
|
+
return { ...current, assign, order }
|
|
433
|
+
})
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
return {
|
|
437
|
+
inject: ['slots', 'locale', 'contextMenus', 'workspaces', 'uiWorkspace', 'sessions'],
|
|
438
|
+
apply(ctx) {
|
|
439
|
+
const store = createStore()
|
|
440
|
+
const addChildRequest = createSignal(null)
|
|
441
|
+
|
|
442
|
+
ctx.effect(ensureStyles, 'dsh-nested-workspaces: styles')
|
|
443
|
+
|
|
444
|
+
try {
|
|
445
|
+
ctx.locale.register(NS, DICT)
|
|
446
|
+
} catch {
|
|
447
|
+
/* hot reload: this namespace is already installed for this build */
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
const t = ctx.locale.bind(NS)
|
|
451
|
+
const workspaces = ctx.get('workspaces')
|
|
452
|
+
const uiWorkspace = ctx.get('uiWorkspace')
|
|
453
|
+
const sessions = ctx.get('sessions')
|
|
454
|
+
const contextMenus = ctx.get('contextMenus')
|
|
455
|
+
|
|
456
|
+
const notify = (text, success) => {
|
|
457
|
+
try {
|
|
458
|
+
contextMenus.notify(text, success)
|
|
459
|
+
} catch {
|
|
460
|
+
/* no toast surface: the dialog already reported the outcome inline */
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/* ------------------------------------------------------- context menus */
|
|
465
|
+
|
|
466
|
+
ctx.effect(
|
|
467
|
+
() =>
|
|
468
|
+
ctx.contextMenus.register({
|
|
469
|
+
id: 'workspace.addChild',
|
|
470
|
+
target: 'workspace',
|
|
471
|
+
order: 150,
|
|
472
|
+
observe: () => [ctx.workspaces.list, ctx.locale],
|
|
473
|
+
resolve: target => [
|
|
474
|
+
{
|
|
475
|
+
id: 'addChild',
|
|
476
|
+
label: ctx.locale.bind(NS)('menu.addChild'),
|
|
477
|
+
icon: { key: 'workspace.addChild' },
|
|
478
|
+
run: () => {
|
|
479
|
+
addChildRequest.set({
|
|
480
|
+
parentId: target.workspaceId,
|
|
481
|
+
parentPath: target.path,
|
|
482
|
+
parentTitle: target.displayTitle,
|
|
483
|
+
})
|
|
484
|
+
},
|
|
485
|
+
},
|
|
486
|
+
],
|
|
487
|
+
}),
|
|
488
|
+
'dsh-nested-workspaces: add-child menu',
|
|
489
|
+
)
|
|
490
|
+
|
|
491
|
+
ctx.effect(
|
|
492
|
+
() =>
|
|
493
|
+
ctx.slots.inject('contextMenu.icon', () =>
|
|
494
|
+
ctx.slots.register({ name: 'contextMenu.icon', key: 'workspace.addChild' }, IconFolderPlus),
|
|
495
|
+
),
|
|
496
|
+
'dsh-nested-workspaces: add-child icon',
|
|
497
|
+
)
|
|
498
|
+
|
|
499
|
+
/*
|
|
500
|
+
* The non-drag half of "manage sessions inside a child workspace": every
|
|
501
|
+
* session menu gains a Move to submenu listing the workspaces this build
|
|
502
|
+
* can see, plus the ungrouped bucket. It writes the same display
|
|
503
|
+
* assignment a drop writes, so both routes land in one place.
|
|
504
|
+
*/
|
|
505
|
+
ctx.effect(
|
|
506
|
+
() =>
|
|
507
|
+
ctx.contextMenus.register({
|
|
508
|
+
id: 'session.nestedMoveTo',
|
|
509
|
+
target: 'session',
|
|
510
|
+
order: 500,
|
|
511
|
+
observe: () => [ctx.workspaces.list, ctx.locale],
|
|
512
|
+
resolve: target => {
|
|
513
|
+
const items = ctx.workspaces.list.getSnapshot().items
|
|
514
|
+
const sessionId = target.sessionId
|
|
515
|
+
const children = items.map(item => ({
|
|
516
|
+
id: 'move:' + item.workspaceId,
|
|
517
|
+
label: item.title || item.path,
|
|
518
|
+
run: () => {
|
|
519
|
+
assignSessionIn(store, items, sessionId, item.workspaceId, undefined)
|
|
520
|
+
notify(ctx.locale.bind(NS)('moved'), true)
|
|
521
|
+
},
|
|
522
|
+
}))
|
|
523
|
+
children.push({
|
|
524
|
+
id: 'move:ungrouped',
|
|
525
|
+
label: ctx.locale.bind(NS)('ungrouped'),
|
|
526
|
+
separatorBefore: true,
|
|
527
|
+
run: () => {
|
|
528
|
+
assignSessionIn(store, items, sessionId, UNGROUPED, undefined)
|
|
529
|
+
notify(ctx.locale.bind(NS)('moved'), true)
|
|
530
|
+
},
|
|
531
|
+
})
|
|
532
|
+
return [
|
|
533
|
+
{
|
|
534
|
+
id: 'moveTo',
|
|
535
|
+
label: ctx.locale.bind(NS)('actions.moveTo'),
|
|
536
|
+
children,
|
|
537
|
+
},
|
|
538
|
+
]
|
|
539
|
+
},
|
|
540
|
+
}),
|
|
541
|
+
'dsh-nested-workspaces: move-to menu',
|
|
542
|
+
)
|
|
543
|
+
|
|
544
|
+
/* --------------------------------------------------------------- dialog */
|
|
545
|
+
|
|
546
|
+
function NewWorkspaceDialog(props) {
|
|
547
|
+
const request = props.request
|
|
548
|
+
const isChild = typeof request.parentPath === 'string'
|
|
549
|
+
const [value, setValue] = useState('')
|
|
550
|
+
const [busy, setBusy] = useState(false)
|
|
551
|
+
const [error, setError] = useState(null)
|
|
552
|
+
const inputRef = useRef(null)
|
|
553
|
+
|
|
554
|
+
useEffect(() => {
|
|
555
|
+
const element = inputRef.current
|
|
556
|
+
if (element !== null) {
|
|
557
|
+
element.focus()
|
|
558
|
+
if (!isChild && value !== '') element.select()
|
|
559
|
+
}
|
|
560
|
+
}, [isChild])
|
|
561
|
+
|
|
562
|
+
/* Escape belongs to DialogShell, which ignores it while busy — a second
|
|
563
|
+
* listener here would close the dialog mid-create and orphan the directory. */
|
|
564
|
+
|
|
565
|
+
const describe = failure => {
|
|
566
|
+
const code = failure !== null && typeof failure === 'object' && typeof failure.code === 'string' ? failure.code : ''
|
|
567
|
+
const message = failure && failure.message ? String(failure.message) : String(failure)
|
|
568
|
+
if (code === 'directory-picker/exists' || message.includes('directory-exists') || message.includes('already exists')) {
|
|
569
|
+
return t('errors.exists')
|
|
570
|
+
}
|
|
571
|
+
return t('errors.createFailed', { message })
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
const submit = async () => {
|
|
575
|
+
if (busy) return
|
|
576
|
+
const trimmed = value.trim()
|
|
577
|
+
if (trimmed === '' && isChild) {
|
|
578
|
+
setError(t('errors.nameRequired'))
|
|
579
|
+
return
|
|
580
|
+
}
|
|
581
|
+
if (isChild && /[\\/]/.test(trimmed)) {
|
|
582
|
+
setError(t('errors.nameInvalid'))
|
|
583
|
+
return
|
|
584
|
+
}
|
|
585
|
+
setBusy(true)
|
|
586
|
+
setError(null)
|
|
587
|
+
try {
|
|
588
|
+
let path = trimmed
|
|
589
|
+
if (isChild) {
|
|
590
|
+
path = await uiWorkspace.createDirectory(request.parentPath, trimmed)
|
|
591
|
+
} else if (path === '') {
|
|
592
|
+
/* No typed path: ask the host's directory picker, which is the
|
|
593
|
+
* same flow the shipped picker uses. */
|
|
594
|
+
const picked = await uiWorkspace.pickDirectory()
|
|
595
|
+
setBusy(false)
|
|
596
|
+
if (picked === null || picked === undefined || picked === '') return
|
|
597
|
+
path = picked
|
|
598
|
+
setValue(picked)
|
|
599
|
+
setBusy(true)
|
|
600
|
+
}
|
|
601
|
+
await workspaces.create({ path })
|
|
602
|
+
if (isChild) {
|
|
603
|
+
store.update(state => ({
|
|
604
|
+
...state,
|
|
605
|
+
collapsed: { ...state.collapsed, [request.parentId]: false },
|
|
606
|
+
}))
|
|
607
|
+
notify(t('createdChild'), true)
|
|
608
|
+
} else {
|
|
609
|
+
notify(t('created'), true)
|
|
610
|
+
}
|
|
611
|
+
props.onClose()
|
|
612
|
+
} catch (failure) {
|
|
613
|
+
setError(describe(failure))
|
|
614
|
+
} finally {
|
|
615
|
+
setBusy(false)
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
return h(
|
|
620
|
+
DialogShell,
|
|
621
|
+
{
|
|
622
|
+
title: isChild ? t('dialog.addChild.title') : t('dialog.addWorkspace.title'),
|
|
623
|
+
description: isChild
|
|
624
|
+
? t('dialog.addChild.description', { parent: request.parentPath })
|
|
625
|
+
: t('dialog.addWorkspace.description'),
|
|
626
|
+
error,
|
|
627
|
+
busy,
|
|
628
|
+
confirmLabel: t('actions.create'),
|
|
629
|
+
onCancel: () => {
|
|
630
|
+
if (!busy) props.onClose()
|
|
631
|
+
},
|
|
632
|
+
onConfirm: submit,
|
|
633
|
+
confirmDisabled: isChild && value.trim() === '',
|
|
634
|
+
},
|
|
635
|
+
h('input', {
|
|
636
|
+
ref: inputRef,
|
|
637
|
+
className: 'dnw-dialogInput',
|
|
638
|
+
value,
|
|
639
|
+
spellCheck: false,
|
|
640
|
+
autoComplete: 'off',
|
|
641
|
+
'aria-label': isChild ? t('field.name') : t('field.path'),
|
|
642
|
+
placeholder: isChild ? t('field.name') : t('field.path'),
|
|
643
|
+
onChange: event => setValue(event.target.value),
|
|
644
|
+
onKeyDown: event => {
|
|
645
|
+
if (event.key === 'Enter') {
|
|
646
|
+
event.preventDefault()
|
|
647
|
+
submit()
|
|
648
|
+
}
|
|
649
|
+
},
|
|
650
|
+
}),
|
|
651
|
+
)
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/* ----------------------------------------------------------- popover menu */
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* A small anchored menu. The shipped workspace menu rows raise their
|
|
658
|
+
* dialog from inside the browsing region this plugin now owns, so the
|
|
659
|
+
* workspace row carries its own menu instead of borrowing that one.
|
|
660
|
+
*/
|
|
661
|
+
function MenuPopover(props) {
|
|
662
|
+
const { anchor, items, onClose } = props
|
|
663
|
+
const [index, setIndex] = useState(0)
|
|
664
|
+
/* Mirror of `index` for the listener effect: keyboard navigation must not
|
|
665
|
+
* rebind three document listeners on every arrow press. */
|
|
666
|
+
const indexRef = useRef(0)
|
|
667
|
+
indexRef.current = index
|
|
668
|
+
const popoverRef = useRef(null)
|
|
669
|
+
const itemRefs = useRef([])
|
|
670
|
+
const restoreRef = useRef(null)
|
|
671
|
+
|
|
672
|
+
/** First enabled item at or after `from`, wrapping once. */
|
|
673
|
+
const seek = from => {
|
|
674
|
+
for (let step = 0; step < items.length; step += 1) {
|
|
675
|
+
const at = (from + step + items.length) % items.length
|
|
676
|
+
if (items[at] !== undefined && items[at].disabled !== true) return at
|
|
677
|
+
}
|
|
678
|
+
return -1
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
useEffect(() => {
|
|
682
|
+
const onPointerDown = event => {
|
|
683
|
+
const element = popoverRef.current
|
|
684
|
+
if (element !== null && element.contains(event.target)) return
|
|
685
|
+
onClose()
|
|
686
|
+
}
|
|
687
|
+
const onKeyDown = event => {
|
|
688
|
+
if (event.key === 'Escape') {
|
|
689
|
+
event.preventDefault()
|
|
690
|
+
event.stopPropagation()
|
|
691
|
+
onClose()
|
|
692
|
+
return
|
|
693
|
+
}
|
|
694
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp' || event.key === 'Home' || event.key === 'End') {
|
|
695
|
+
event.preventDefault()
|
|
696
|
+
if (items.length === 0) return
|
|
697
|
+
const first = seek(0)
|
|
698
|
+
if (first < 0) return
|
|
699
|
+
if (event.key === 'Home') setIndex(first)
|
|
700
|
+
else if (event.key === 'End') setIndex(seek(Math.max(0, items.length - 1) < 0 ? 0 : items.length - 1))
|
|
701
|
+
else {
|
|
702
|
+
const step = event.key === 'ArrowDown' ? 1 : -1
|
|
703
|
+
setIndex(current => {
|
|
704
|
+
const next = seek(current + step)
|
|
705
|
+
return next < 0 ? current : next
|
|
706
|
+
})
|
|
707
|
+
}
|
|
708
|
+
return
|
|
709
|
+
}
|
|
710
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
711
|
+
const active = document.activeElement
|
|
712
|
+
const position = itemRefs.current.findIndex(node => node === active)
|
|
713
|
+
const chosen = position >= 0 ? items[position] : items[indexRef.current]
|
|
714
|
+
if (chosen === undefined || chosen.disabled === true) return
|
|
715
|
+
event.preventDefault()
|
|
716
|
+
onClose()
|
|
717
|
+
void chosen.onSelect()
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
document.addEventListener('mousedown', onPointerDown, true)
|
|
721
|
+
document.addEventListener('keydown', onKeyDown, true)
|
|
722
|
+
window.addEventListener('resize', onClose)
|
|
723
|
+
return () => {
|
|
724
|
+
document.removeEventListener('mousedown', onPointerDown, true)
|
|
725
|
+
document.removeEventListener('keydown', onKeyDown, true)
|
|
726
|
+
window.removeEventListener('resize', onClose)
|
|
727
|
+
}
|
|
728
|
+
}, [items, onClose])
|
|
729
|
+
|
|
730
|
+
/* Focus the active row, and give focus back to whatever opened the
|
|
731
|
+
* menu when it closes, so keyboard users are never stranded. */
|
|
732
|
+
useEffect(() => {
|
|
733
|
+
restoreRef.current = document.activeElement
|
|
734
|
+
const initial = seek(0)
|
|
735
|
+
if (initial >= 0) setIndex(initial)
|
|
736
|
+
return () => {
|
|
737
|
+
const previous = restoreRef.current
|
|
738
|
+
if (previous !== null && typeof previous.focus === 'function' && document.contains(previous)) previous.focus()
|
|
739
|
+
}
|
|
740
|
+
}, [])
|
|
741
|
+
|
|
742
|
+
useEffect(() => {
|
|
743
|
+
const node = itemRefs.current[index]
|
|
744
|
+
if (node !== undefined && node !== null) node.focus()
|
|
745
|
+
}, [index])
|
|
746
|
+
|
|
747
|
+
const portalTarget = typeof document === 'undefined' ? null : document.body
|
|
748
|
+
if (portalTarget === null) return null
|
|
749
|
+
|
|
750
|
+
/* Keep the menu on screen: flip above the anchor when the space below is
|
|
751
|
+
* too small, then clamp both axes into the viewport. */
|
|
752
|
+
const MENU_WIDTH = 208
|
|
753
|
+
const viewportHeight = window.innerHeight || 0
|
|
754
|
+
const viewportWidth = window.innerWidth || 0
|
|
755
|
+
const estimated = items.length * 34 + 12
|
|
756
|
+
const below = anchor.bottom + 4
|
|
757
|
+
const above = anchor.top - 4 - estimated
|
|
758
|
+
const fitsBelow = viewportHeight === 0 || below + estimated <= viewportHeight
|
|
759
|
+
const top = fitsBelow ? below : Math.max(8, above)
|
|
760
|
+
const style = {
|
|
761
|
+
top: Math.round(Math.max(8, Math.min(top, viewportHeight === 0 ? top : viewportHeight - estimated - 8))) + 'px',
|
|
762
|
+
left: Math.round(Math.max(8, Math.min(anchor.left, (viewportWidth || MENU_WIDTH) - MENU_WIDTH))) + 'px',
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
return createPortal(
|
|
766
|
+
h(
|
|
767
|
+
'div',
|
|
768
|
+
{
|
|
769
|
+
ref: popoverRef,
|
|
770
|
+
className: 'dnw-menu',
|
|
771
|
+
role: 'menu',
|
|
772
|
+
tabIndex: -1,
|
|
773
|
+
style,
|
|
774
|
+
onContextMenu: event => event.preventDefault(),
|
|
775
|
+
},
|
|
776
|
+
items.map((item, position) =>
|
|
777
|
+
h(
|
|
778
|
+
Fragment,
|
|
779
|
+
{ key: item.id },
|
|
780
|
+
item.separatorBefore === true && position > 0 ? h('div', { className: 'dnw-menuSeparator', role: 'separator' }) : null,
|
|
781
|
+
h(
|
|
782
|
+
'button',
|
|
783
|
+
{
|
|
784
|
+
type: 'button',
|
|
785
|
+
role: 'menuitem',
|
|
786
|
+
ref: node => {
|
|
787
|
+
itemRefs.current[position] = node
|
|
788
|
+
},
|
|
789
|
+
tabIndex: position === index ? 0 : -1,
|
|
790
|
+
className: cls('dnw-menuItem', item.danger === true && 'dnw-menuItemDanger', position === index && 'dnw-menuItemActive'),
|
|
791
|
+
disabled: item.disabled === true,
|
|
792
|
+
onMouseEnter: () => setIndex(position),
|
|
793
|
+
onFocus: () => setIndex(position),
|
|
794
|
+
onClick: () => {
|
|
795
|
+
onClose()
|
|
796
|
+
void item.onSelect()
|
|
797
|
+
},
|
|
798
|
+
},
|
|
799
|
+
item.icon === undefined ? null : h('span', { className: 'dnw-menuIcon' }, h(item.icon, null)),
|
|
800
|
+
h('span', { className: 'dnw-menuLabel' }, item.label),
|
|
801
|
+
),
|
|
802
|
+
),
|
|
803
|
+
),
|
|
804
|
+
),
|
|
805
|
+
portalTarget,
|
|
806
|
+
)
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
/* ------------------------------------------------------------ dialogs */
|
|
810
|
+
|
|
811
|
+
/** Shared modal shell: scrim, Escape, focus trap entry, footer buttons. */
|
|
812
|
+
function DialogShell(props) {
|
|
813
|
+
const { title, description, children, error, busy, confirmLabel, danger, onCancel, onConfirm, confirmDisabled } = props
|
|
814
|
+
const dialogRef = useRef(null)
|
|
815
|
+
const restoreRef = useRef(null)
|
|
816
|
+
|
|
817
|
+
useEffect(() => {
|
|
818
|
+
const onKeyDown = event => {
|
|
819
|
+
const element = dialogRef.current
|
|
820
|
+
if (event.key === 'Escape') {
|
|
821
|
+
event.preventDefault()
|
|
822
|
+
event.stopPropagation()
|
|
823
|
+
if (!busy) onCancel()
|
|
824
|
+
return
|
|
825
|
+
}
|
|
826
|
+
/* Keep Tab inside the dialog: the scrim covers the page, so
|
|
827
|
+
* focus must not be able to walk out behind it. */
|
|
828
|
+
if (event.key !== 'Tab' || element === null) return
|
|
829
|
+
const focusable = element.querySelectorAll(
|
|
830
|
+
'button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])',
|
|
831
|
+
)
|
|
832
|
+
if (focusable.length === 0) return
|
|
833
|
+
const first = focusable[0]
|
|
834
|
+
const last = focusable[focusable.length - 1]
|
|
835
|
+
const active = document.activeElement
|
|
836
|
+
if (event.shiftKey && (active === first || !element.contains(active))) {
|
|
837
|
+
event.preventDefault()
|
|
838
|
+
last.focus()
|
|
839
|
+
} else if (!event.shiftKey && (active === last || !element.contains(active))) {
|
|
840
|
+
event.preventDefault()
|
|
841
|
+
first.focus()
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
document.addEventListener('keydown', onKeyDown, true)
|
|
845
|
+
return () => document.removeEventListener('keydown', onKeyDown, true)
|
|
846
|
+
}, [busy, onCancel])
|
|
847
|
+
|
|
848
|
+
useEffect(() => {
|
|
849
|
+
restoreRef.current = document.activeElement
|
|
850
|
+
return () => {
|
|
851
|
+
const previous = restoreRef.current
|
|
852
|
+
if (previous !== null && typeof previous.focus === 'function' && document.contains(previous)) previous.focus()
|
|
853
|
+
}
|
|
854
|
+
}, [])
|
|
855
|
+
|
|
856
|
+
const portalTarget = typeof document === 'undefined' ? null : document.body
|
|
857
|
+
if (portalTarget === null) return null
|
|
858
|
+
|
|
859
|
+
return createPortal(
|
|
860
|
+
h(
|
|
861
|
+
'div',
|
|
862
|
+
{
|
|
863
|
+
className: 'dnw-scrim',
|
|
864
|
+
onMouseDown: event => {
|
|
865
|
+
if (event.target === event.currentTarget && !busy) onCancel()
|
|
866
|
+
},
|
|
867
|
+
},
|
|
868
|
+
h(
|
|
869
|
+
'div',
|
|
870
|
+
{
|
|
871
|
+
ref: dialogRef,
|
|
872
|
+
className: 'dnw-dialog',
|
|
873
|
+
role: 'dialog',
|
|
874
|
+
'aria-modal': 'true',
|
|
875
|
+
'aria-label': title,
|
|
876
|
+
},
|
|
877
|
+
h('div', { className: 'dnw-dialogTitle' }, title),
|
|
878
|
+
description === null ? null : h('div', { className: 'dnw-dialogText' }, description),
|
|
879
|
+
children,
|
|
880
|
+
error === null ? null : h('div', { className: 'dnw-dialogError', role: 'alert' }, error),
|
|
881
|
+
h(
|
|
882
|
+
'div',
|
|
883
|
+
{ className: 'dnw-dialogFooter' },
|
|
884
|
+
h(
|
|
885
|
+
'button',
|
|
886
|
+
{ type: 'button', className: 'dnw-button', disabled: busy, onClick: onCancel },
|
|
887
|
+
t('actions.cancel'),
|
|
888
|
+
),
|
|
889
|
+
h(
|
|
890
|
+
'button',
|
|
891
|
+
{
|
|
892
|
+
type: 'button',
|
|
893
|
+
className: cls('dnw-button', 'dnw-buttonPrimary', danger === true && 'dnw-buttonDanger'),
|
|
894
|
+
disabled: busy || confirmDisabled === true,
|
|
895
|
+
onClick: onConfirm,
|
|
896
|
+
},
|
|
897
|
+
confirmLabel,
|
|
898
|
+
),
|
|
899
|
+
),
|
|
900
|
+
),
|
|
901
|
+
),
|
|
902
|
+
portalTarget,
|
|
903
|
+
)
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
/** Inline rename for one Workspace, mirroring the shipped dialog's guards. */
|
|
907
|
+
function WorkspaceRenameDialog(props) {
|
|
908
|
+
const { workspace, onClose } = props
|
|
909
|
+
const [value, setValue] = useState(workspace.title)
|
|
910
|
+
const [busy, setBusy] = useState(false)
|
|
911
|
+
const [error, setError] = useState(null)
|
|
912
|
+
const inputRef = useRef(null)
|
|
913
|
+
const trimmed = value.trim()
|
|
914
|
+
|
|
915
|
+
useEffect(() => {
|
|
916
|
+
const element = inputRef.current
|
|
917
|
+
if (element !== null) {
|
|
918
|
+
element.focus()
|
|
919
|
+
element.select()
|
|
920
|
+
}
|
|
921
|
+
}, [])
|
|
922
|
+
|
|
923
|
+
const submit = async () => {
|
|
924
|
+
if (busy || trimmed === '' || trimmed === workspace.title) return
|
|
925
|
+
setBusy(true)
|
|
926
|
+
setError(null)
|
|
927
|
+
try {
|
|
928
|
+
await workspaces.rename(workspace.workspaceId, trimmed)
|
|
929
|
+
notify(t('renamed'), true)
|
|
930
|
+
onClose()
|
|
931
|
+
} catch (failure) {
|
|
932
|
+
setError(t('errors.renameFailed', { message: failure && failure.message ? String(failure.message) : String(failure) }))
|
|
933
|
+
} finally {
|
|
934
|
+
setBusy(false)
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
return h(
|
|
939
|
+
DialogShell,
|
|
940
|
+
{
|
|
941
|
+
title: t('dialog.rename.title'),
|
|
942
|
+
description: null,
|
|
943
|
+
error,
|
|
944
|
+
busy,
|
|
945
|
+
confirmLabel: t('actions.rename'),
|
|
946
|
+
onCancel: () => {
|
|
947
|
+
if (!busy) onClose()
|
|
948
|
+
},
|
|
949
|
+
onConfirm: submit,
|
|
950
|
+
confirmDisabled: trimmed === '' || trimmed === workspace.title,
|
|
951
|
+
},
|
|
952
|
+
h('input', {
|
|
953
|
+
ref: inputRef,
|
|
954
|
+
className: 'dnw-dialogInput',
|
|
955
|
+
value,
|
|
956
|
+
spellCheck: false,
|
|
957
|
+
autoComplete: 'off',
|
|
958
|
+
'aria-label': t('dialog.rename.title'),
|
|
959
|
+
onChange: event => setValue(event.target.value),
|
|
960
|
+
onKeyDown: event => {
|
|
961
|
+
if (event.key === 'Enter') {
|
|
962
|
+
event.preventDefault()
|
|
963
|
+
void submit()
|
|
964
|
+
}
|
|
965
|
+
},
|
|
966
|
+
}),
|
|
967
|
+
)
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
/** Remove one Workspace from the list; the directory on disk is untouched. */
|
|
971
|
+
function WorkspaceDeleteDialog(props) {
|
|
972
|
+
const { workspace, onClose } = props
|
|
973
|
+
const [busy, setBusy] = useState(false)
|
|
974
|
+
const [error, setError] = useState(null)
|
|
975
|
+
|
|
976
|
+
const submit = async () => {
|
|
977
|
+
if (busy) return
|
|
978
|
+
setBusy(true)
|
|
979
|
+
setError(null)
|
|
980
|
+
try {
|
|
981
|
+
await workspaces.delete(workspace.workspaceId)
|
|
982
|
+
notify(t('deleted'), true)
|
|
983
|
+
onClose()
|
|
984
|
+
} catch (failure) {
|
|
985
|
+
setError(t('errors.deleteFailed', { message: failure && failure.message ? String(failure.message) : String(failure) }))
|
|
986
|
+
} finally {
|
|
987
|
+
setBusy(false)
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
return h(DialogShell, {
|
|
992
|
+
title: t('dialog.delete.title'),
|
|
993
|
+
description: t('dialog.delete.description', { name: workspace.title }),
|
|
994
|
+
error,
|
|
995
|
+
busy,
|
|
996
|
+
danger: true,
|
|
997
|
+
confirmLabel: t('actions.confirm'),
|
|
998
|
+
onCancel: () => {
|
|
999
|
+
if (!busy) onClose()
|
|
1000
|
+
},
|
|
1001
|
+
onConfirm: submit,
|
|
1002
|
+
})
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
/* --------------------------------------------------------- row components
|
|
1006
|
+
*
|
|
1007
|
+
* These are components rather than render helpers on purpose: each one calls
|
|
1008
|
+
* React hooks (useSessionAccess / useWorkspaceAccess), so it must own a stable
|
|
1009
|
+
* hook list. Calling them from Sidebar's body made the hook count depend on
|
|
1010
|
+
* collapse state and filters, which breaks the rules of hooks and blanks the
|
|
1011
|
+
* whole sidebar entry. Shared closures arrive in `env`, built once per render.
|
|
1012
|
+
*/
|
|
1013
|
+
function SessionRow(props) {
|
|
1014
|
+
const { session, groupKey, index, bucket, env } = props
|
|
1015
|
+
const { view, statuses, t, uiWorkspace, useSessionAccess, openMenu, assignSession, dragIdRef, draggingId, dropTarget, setDropTarget, setDraggingId } = env
|
|
1016
|
+
const isArchived = view.archived.has(session.id)
|
|
1017
|
+
const label = session.blank ? (session.id === view.currentId ? t('session.new') : t('session.untitled')) : sessionTitle(session)
|
|
1018
|
+
const title = label === '' ? t('session.untitled') : label
|
|
1019
|
+
const status = statuses.get(session.id)
|
|
1020
|
+
const running = status !== undefined && status.running === true
|
|
1021
|
+
const selected = session.id === view.currentId
|
|
1022
|
+
const canUnarchive = useSessionAccess(session.id, 'workspace/unarchiveSession')
|
|
1023
|
+
const canMove = useSessionAccess(session.id, 'workspace/insertSessionBefore')
|
|
1024
|
+
const canDrag = !session.blank && !isArchived && canMove
|
|
1025
|
+
const rowDropPosition = dropTarget !== null && dropTarget.sessionId === session.id ? dropTarget.position : null
|
|
1026
|
+
const actions = []
|
|
1027
|
+
if (!session.blank && !isArchived) {
|
|
1028
|
+
actions.push(
|
|
1029
|
+
openMenu(
|
|
1030
|
+
{ kind: 'session', value: { sessionId: session.id, displayTitle: title } },
|
|
1031
|
+
t('actions.menu') + ' ' + title,
|
|
1032
|
+
),
|
|
1033
|
+
)
|
|
1034
|
+
}
|
|
1035
|
+
if (isArchived && canUnarchive) {
|
|
1036
|
+
actions.push(
|
|
1037
|
+
h(
|
|
1038
|
+
'button',
|
|
1039
|
+
{
|
|
1040
|
+
type: 'button',
|
|
1041
|
+
key: 'unarchive',
|
|
1042
|
+
className: 'dnw-iconButton',
|
|
1043
|
+
title: t('actions.unarchive'),
|
|
1044
|
+
'aria-label': t('actions.unarchive') + ' ' + title,
|
|
1045
|
+
onClick: event => {
|
|
1046
|
+
event.stopPropagation()
|
|
1047
|
+
uiWorkspace.unarchiveSession(session.id)
|
|
1048
|
+
},
|
|
1049
|
+
},
|
|
1050
|
+
h(IconUnarchive, null),
|
|
1051
|
+
),
|
|
1052
|
+
)
|
|
1053
|
+
}
|
|
1054
|
+
const activate = () => {
|
|
1055
|
+
if (isArchived) return
|
|
1056
|
+
uiWorkspace.openSession(session.id)
|
|
1057
|
+
}
|
|
1058
|
+
/* The next sibling in this bucket is the insertion anchor for an
|
|
1059
|
+
* "after" drop. It skips the row being dragged, otherwise dropping a
|
|
1060
|
+
* row right below the one above it would move it to the group end. */
|
|
1061
|
+
const dropAfter = (() => {
|
|
1062
|
+
if (!Array.isArray(bucket) || typeof index !== 'number') return undefined
|
|
1063
|
+
for (let cursor = index + 1; cursor < bucket.length; cursor += 1) {
|
|
1064
|
+
if (bucket[cursor].id !== draggingId) return bucket[cursor].id
|
|
1065
|
+
}
|
|
1066
|
+
return undefined
|
|
1067
|
+
})()
|
|
1068
|
+
return h(
|
|
1069
|
+
'div',
|
|
1070
|
+
{
|
|
1071
|
+
key: 's:' + session.id,
|
|
1072
|
+
className: cls(
|
|
1073
|
+
'dnw-row',
|
|
1074
|
+
'dnw-sessionRow',
|
|
1075
|
+
selected && 'dnw-rowSelected',
|
|
1076
|
+
isArchived && 'dnw-rowArchived',
|
|
1077
|
+
rowDropPosition === 'before' && 'dnw-dropBefore',
|
|
1078
|
+
rowDropPosition === 'after' && 'dnw-dropAfter',
|
|
1079
|
+
draggingId === session.id && 'dnw-rowDragging',
|
|
1080
|
+
),
|
|
1081
|
+
role: 'treeitem',
|
|
1082
|
+
tabIndex: 0,
|
|
1083
|
+
'aria-selected': selected,
|
|
1084
|
+
'data-row-key': 'nested-session:' + session.id,
|
|
1085
|
+
draggable: canDrag,
|
|
1086
|
+
onKeyDown: event => {
|
|
1087
|
+
if (event.key !== 'Enter' && event.key !== ' ') return
|
|
1088
|
+
event.preventDefault()
|
|
1089
|
+
activate()
|
|
1090
|
+
},
|
|
1091
|
+
onDragStart: event => {
|
|
1092
|
+
dragIdRef.current = session.id
|
|
1093
|
+
setDraggingId(session.id)
|
|
1094
|
+
try {
|
|
1095
|
+
event.dataTransfer.effectAllowed = 'move'
|
|
1096
|
+
event.dataTransfer.setData('text/plain', session.id)
|
|
1097
|
+
} catch {
|
|
1098
|
+
/* some browsers block custom payloads; the ref carries the id */
|
|
1099
|
+
}
|
|
1100
|
+
},
|
|
1101
|
+
onDragEnd: () => {
|
|
1102
|
+
dragIdRef.current = null
|
|
1103
|
+
setDraggingId(null)
|
|
1104
|
+
setDropTarget(null)
|
|
1105
|
+
},
|
|
1106
|
+
onDragOver: event => {
|
|
1107
|
+
const dragging = dragIdRef.current
|
|
1108
|
+
if (dragging === null || dragging === session.id) return
|
|
1109
|
+
event.preventDefault()
|
|
1110
|
+
event.stopPropagation()
|
|
1111
|
+
try {
|
|
1112
|
+
event.dataTransfer.dropEffect = 'move'
|
|
1113
|
+
} catch {
|
|
1114
|
+
/* ignore */
|
|
1115
|
+
}
|
|
1116
|
+
const box = event.currentTarget.getBoundingClientRect()
|
|
1117
|
+
const position = event.clientY < box.top + box.height / 2 ? 'before' : 'after'
|
|
1118
|
+
if (rowDropPosition !== position) setDropTarget({ workspaceId: groupKey, sessionId: session.id, position })
|
|
1119
|
+
},
|
|
1120
|
+
onDragLeave: event => {
|
|
1121
|
+
if (event.currentTarget.contains(event.relatedTarget)) return
|
|
1122
|
+
if (rowDropPosition !== null) setDropTarget(null)
|
|
1123
|
+
},
|
|
1124
|
+
onDrop: event => {
|
|
1125
|
+
const id = dragIdRef.current || event.dataTransfer.getData('text/plain')
|
|
1126
|
+
if (!id || id === session.id) return
|
|
1127
|
+
event.preventDefault()
|
|
1128
|
+
event.stopPropagation()
|
|
1129
|
+
const box = event.currentTarget.getBoundingClientRect()
|
|
1130
|
+
const after = event.clientY >= box.top + box.height / 2
|
|
1131
|
+
setDropTarget(null)
|
|
1132
|
+
dragIdRef.current = null
|
|
1133
|
+
setDraggingId(null)
|
|
1134
|
+
assignSession(id, groupKey, after ? dropAfter : session.id)
|
|
1135
|
+
},
|
|
1136
|
+
onClick: activate,
|
|
1137
|
+
},
|
|
1138
|
+
h(
|
|
1139
|
+
'span',
|
|
1140
|
+
{ className: 'dnw-slot' },
|
|
1141
|
+
running ? h('span', { className: 'dnw-dot' }) : h('span', { className: cls('dnw-dot', 'dnw-dotIdle') }),
|
|
1142
|
+
),
|
|
1143
|
+
h('span', { className: cls('dnw-title', (session.blank || isArchived) && 'dnw-titleMuted') }, title),
|
|
1144
|
+
actions.length === 0 ? null : h('span', { className: 'dnw-actions' }, ...actions),
|
|
1145
|
+
)
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
function WorkspaceGroup(props) {
|
|
1149
|
+
const { workspace, depth, env } = props
|
|
1150
|
+
const { view, state, t, uiWorkspace, useWorkspaceAccess, openMenu, openWorkspaceMenu, assignSession, setExpanded, setRenaming, menu, dragIdRef, draggingId, dropTarget, setDropTarget, setDraggingId } = env
|
|
1151
|
+
const workspaceId = workspace.workspaceId
|
|
1152
|
+
const collapsed = state.collapsed[workspaceId] === true
|
|
1153
|
+
const members = view.members.get(workspaceId) || []
|
|
1154
|
+
const children = view.childrenOf.get(workspaceId) || []
|
|
1155
|
+
const hasSessions = members.length > 0
|
|
1156
|
+
const visible = !collapsed || view.filtering
|
|
1157
|
+
/* Only a header-level hover highlights the group; a hover over one
|
|
1158
|
+
* of its session rows carries a sessionId and must not repaint it. */
|
|
1159
|
+
const isDropTarget =
|
|
1160
|
+
dropTarget !== null && dropTarget.workspaceId === workspaceId && dropTarget.sessionId === undefined
|
|
1161
|
+
const indent = { '--dnw-indent': depth * INDENT_PX + 'px' }
|
|
1162
|
+
const canCreateSession = useWorkspaceAccess(workspaceId, 'session/create')
|
|
1163
|
+
const collapsible = children.length > 0 || hasSessions
|
|
1164
|
+
const row = h(
|
|
1165
|
+
'div',
|
|
1166
|
+
{
|
|
1167
|
+
key: 'w:' + workspaceId,
|
|
1168
|
+
className: cls('dnw-row', 'dnw-workspaceRow', isDropTarget && 'dnw-dropOn'),
|
|
1169
|
+
role: 'treeitem',
|
|
1170
|
+
tabIndex: 0,
|
|
1171
|
+
'aria-expanded': !collapsed,
|
|
1172
|
+
'aria-label': workspace.title + ' — ' + workspace.path,
|
|
1173
|
+
style: indent,
|
|
1174
|
+
onClick: () => setExpanded(workspaceId, collapsed),
|
|
1175
|
+
onKeyDown: event => {
|
|
1176
|
+
if (event.target !== event.currentTarget) return
|
|
1177
|
+
if (event.key !== 'Enter' && event.key !== ' ') return
|
|
1178
|
+
event.preventDefault()
|
|
1179
|
+
setExpanded(workspaceId, collapsed)
|
|
1180
|
+
},
|
|
1181
|
+
onContextMenu: event => openWorkspaceMenu(event, workspace),
|
|
1182
|
+
onDragOver: event => {
|
|
1183
|
+
if (dragIdRef.current === null) return
|
|
1184
|
+
event.preventDefault()
|
|
1185
|
+
event.stopPropagation()
|
|
1186
|
+
try {
|
|
1187
|
+
event.dataTransfer.dropEffect = 'move'
|
|
1188
|
+
} catch {
|
|
1189
|
+
/* ignore */
|
|
1190
|
+
}
|
|
1191
|
+
if (!isDropTarget) setDropTarget({ workspaceId, mode: 'into' })
|
|
1192
|
+
},
|
|
1193
|
+
onDragLeave: event => {
|
|
1194
|
+
/* Moving onto a child span fires leave on the header; only an
|
|
1195
|
+
* exit from the header itself clears the drop highlight. */
|
|
1196
|
+
if (event.currentTarget.contains(event.relatedTarget)) return
|
|
1197
|
+
if (isDropTarget) setDropTarget(null)
|
|
1198
|
+
},
|
|
1199
|
+
onDrop: event => {
|
|
1200
|
+
const id = dragIdRef.current || event.dataTransfer.getData('text/plain')
|
|
1201
|
+
event.preventDefault()
|
|
1202
|
+
event.stopPropagation()
|
|
1203
|
+
setDropTarget(null)
|
|
1204
|
+
setDraggingId(null)
|
|
1205
|
+
dragIdRef.current = null
|
|
1206
|
+
if (id) assignSession(id, workspaceId, undefined)
|
|
1207
|
+
},
|
|
1208
|
+
},
|
|
1209
|
+
h(
|
|
1210
|
+
'span',
|
|
1211
|
+
{ className: 'dnw-slot dnw-lead' },
|
|
1212
|
+
h(
|
|
1213
|
+
'button',
|
|
1214
|
+
{
|
|
1215
|
+
type: 'button',
|
|
1216
|
+
className: cls('dnw-chevron', !collapsed && 'dnw-chevronOpen'),
|
|
1217
|
+
'aria-label': (collapsed ? t('expandGroup') : t('collapseGroup')) + ' ' + workspace.title,
|
|
1218
|
+
'aria-hidden': !collapsible,
|
|
1219
|
+
tabIndex: collapsible ? 0 : -1,
|
|
1220
|
+
onClick: event => {
|
|
1221
|
+
event.stopPropagation()
|
|
1222
|
+
setExpanded(workspaceId, collapsed)
|
|
1223
|
+
},
|
|
1224
|
+
},
|
|
1225
|
+
h('span', { className: 'dnw-arrowInner' }, h(IconChevron, null)),
|
|
1226
|
+
),
|
|
1227
|
+
h('span', { className: cls('dnw-folderIcon', !collapsed && 'dnw-folderActive') }, h(IconFolder, null)),
|
|
1228
|
+
),
|
|
1229
|
+
h(
|
|
1230
|
+
'span',
|
|
1231
|
+
{
|
|
1232
|
+
className: 'dnw-title',
|
|
1233
|
+
title: workspace.path,
|
|
1234
|
+
onDoubleClick: event => {
|
|
1235
|
+
event.preventDefault()
|
|
1236
|
+
event.stopPropagation()
|
|
1237
|
+
setRenaming(workspace)
|
|
1238
|
+
},
|
|
1239
|
+
},
|
|
1240
|
+
workspace.title,
|
|
1241
|
+
),
|
|
1242
|
+
h(
|
|
1243
|
+
'span',
|
|
1244
|
+
{ className: cls('dnw-actions', menu !== null && menu.workspaceId === workspaceId && 'dnw-actionsOpen') },
|
|
1245
|
+
h(
|
|
1246
|
+
'button',
|
|
1247
|
+
{
|
|
1248
|
+
type: 'button',
|
|
1249
|
+
className: 'dnw-iconButton',
|
|
1250
|
+
title: t('actions.menu'),
|
|
1251
|
+
'aria-label': t('actions.menu') + ' ' + workspace.title,
|
|
1252
|
+
'aria-haspopup': 'menu',
|
|
1253
|
+
'aria-expanded': menu !== null && menu.workspaceId === workspaceId,
|
|
1254
|
+
onClick: event => openWorkspaceMenu(event, workspace),
|
|
1255
|
+
},
|
|
1256
|
+
h(IconDots, null),
|
|
1257
|
+
),
|
|
1258
|
+
canCreateSession
|
|
1259
|
+
? h(
|
|
1260
|
+
'button',
|
|
1261
|
+
{
|
|
1262
|
+
type: 'button',
|
|
1263
|
+
className: 'dnw-iconButton',
|
|
1264
|
+
title: t('actions.newSession'),
|
|
1265
|
+
'aria-label': t('actions.newSession') + ' ' + workspace.title,
|
|
1266
|
+
onClick: event => {
|
|
1267
|
+
event.stopPropagation()
|
|
1268
|
+
uiWorkspace.startSession(workspaceId)
|
|
1269
|
+
},
|
|
1270
|
+
},
|
|
1271
|
+
h(IconPlus, null),
|
|
1272
|
+
)
|
|
1273
|
+
: null,
|
|
1274
|
+
),
|
|
1275
|
+
)
|
|
1276
|
+
|
|
1277
|
+
const body = []
|
|
1278
|
+
if (visible && hasSessions) body.push(h('div', { key: 'g:' + workspaceId, role: 'group' }, members.map((session, index) => h(SessionRow, { key: 's:' + session.id, session, groupKey: workspaceId, index, bucket: members, env }))))
|
|
1279
|
+
if (visible) {
|
|
1280
|
+
for (const child of children) body.push(h(WorkspaceGroup, { key: 'grp:' + child.workspaceId, workspace: child, depth: depth + 1, env }))
|
|
1281
|
+
}
|
|
1282
|
+
return h(Fragment, { key: 'grp:' + workspaceId }, row, ...body)
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
/* ------------------------------------------------------------- sidebar */
|
|
1286
|
+
|
|
1287
|
+
function Sidebar(props) {
|
|
1288
|
+
const { wide, expandSidebar, renderFactorySlot, useSessions, useWorkspaces, useSessionStatus, useSectionScroller } = props
|
|
1289
|
+
const useWorkspaceAccess = typeof props.useWorkspaceAccess === 'function' ? props.useWorkspaceAccess : () => true
|
|
1290
|
+
const useSessionAccess = typeof props.useSessionAccess === 'function' ? props.useSessionAccess : () => true
|
|
1291
|
+
const state = useSyncExternalStore(store.subscribe, store.get, store.get)
|
|
1292
|
+
const request = useSyncExternalStore(addChildRequest.subscribe, addChildRequest.get, addChildRequest.get)
|
|
1293
|
+
const list = useSessions(snapshot => snapshot)
|
|
1294
|
+
const workspaceSnapshot = useWorkspaces(snapshot => snapshot)
|
|
1295
|
+
const statuses = useSessionStatus(snapshot => snapshot)
|
|
1296
|
+
|
|
1297
|
+
const scroller = typeof useSectionScroller === 'function' ? useSectionScroller() : null
|
|
1298
|
+
const bindScrollerRef = scroller === null ? undefined : scroller.bindScrollerRef
|
|
1299
|
+
|
|
1300
|
+
const [editingTitle, setEditingTitle] = useState(false)
|
|
1301
|
+
const [draftTitle, setDraftTitle] = useState('')
|
|
1302
|
+
const [searchOpen, setSearchOpen] = useState(false)
|
|
1303
|
+
const [query, setQuery] = useState('')
|
|
1304
|
+
const [draggingId, setDraggingId] = useState(null)
|
|
1305
|
+
const [dropTarget, setDropTarget] = useState(null)
|
|
1306
|
+
const [menu, setMenu] = useState(null)
|
|
1307
|
+
const [renaming, setRenaming] = useState(null)
|
|
1308
|
+
const [deleting, setDeleting] = useState(null)
|
|
1309
|
+
const [showArchived, setShowArchived] = useState(false)
|
|
1310
|
+
const dragIdRef = useRef(null)
|
|
1311
|
+
const titleInputRef = useRef(null)
|
|
1312
|
+
const cancelTitleRef = useRef(false)
|
|
1313
|
+
const closeMenu = useCallback(() => setMenu(null), [])
|
|
1314
|
+
|
|
1315
|
+
useEffect(() => {
|
|
1316
|
+
if (editingTitle && titleInputRef.current !== null) {
|
|
1317
|
+
titleInputRef.current.focus()
|
|
1318
|
+
titleInputRef.current.select()
|
|
1319
|
+
}
|
|
1320
|
+
}, [editingTitle])
|
|
1321
|
+
|
|
1322
|
+
const items = workspaceSnapshot.items
|
|
1323
|
+
const view = useMemo(() => {
|
|
1324
|
+
const byId = new Map(items.map(item => [item.workspaceId, item]))
|
|
1325
|
+
const byPath = new Map(items.map(item => [item.path, item.workspaceId]))
|
|
1326
|
+
const paths = items.map(item => item.path)
|
|
1327
|
+
const parentOf = new Map()
|
|
1328
|
+
for (const item of items) {
|
|
1329
|
+
const parentPath = owningParentPath(item.path, paths)
|
|
1330
|
+
if (parentPath === null) continue
|
|
1331
|
+
const parentId = byPath.get(parentPath)
|
|
1332
|
+
if (parentId !== undefined) parentOf.set(item.workspaceId, parentId)
|
|
1333
|
+
}
|
|
1334
|
+
const childrenOf = new Map()
|
|
1335
|
+
const roots = []
|
|
1336
|
+
for (const item of items) {
|
|
1337
|
+
const parentId = parentOf.get(item.workspaceId)
|
|
1338
|
+
if (parentId === undefined) {
|
|
1339
|
+
roots.push(item)
|
|
1340
|
+
continue
|
|
1341
|
+
}
|
|
1342
|
+
const bucket = childrenOf.get(parentId)
|
|
1343
|
+
if (bucket === undefined) childrenOf.set(parentId, [item])
|
|
1344
|
+
else bucket.push(item)
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
const archived = new Set(workspaceSnapshot.archivedSessionIds)
|
|
1348
|
+
const realOwner = new Map()
|
|
1349
|
+
for (const item of items) for (const id of item.sessionIds) realOwner.set(id, item.workspaceId)
|
|
1350
|
+
const currentId = list.ids.find(id => ((list.byId[id] && list.byId[id].retainedBy.mainView) || 0) > 0) || null
|
|
1351
|
+
|
|
1352
|
+
const ownerOf = id => {
|
|
1353
|
+
const assigned = state.assign[id]
|
|
1354
|
+
if (typeof assigned === 'string' && byId.has(assigned)) return assigned
|
|
1355
|
+
const real = realOwner.get(id)
|
|
1356
|
+
return real === undefined ? UNGROUPED : real
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
const members = new Map()
|
|
1360
|
+
members.set(UNGROUPED, [])
|
|
1361
|
+
for (const item of items) members.set(item.workspaceId, [])
|
|
1362
|
+
|
|
1363
|
+
const needle = query.trim().toLowerCase()
|
|
1364
|
+
const matches = text => needle === '' || String(text || '').toLowerCase().includes(needle)
|
|
1365
|
+
const workspaceMatches = new Map()
|
|
1366
|
+
for (const item of items) workspaceMatches.set(item.workspaceId, matches(item.title) || matches(item.path))
|
|
1367
|
+
|
|
1368
|
+
for (const id of list.ids) {
|
|
1369
|
+
const session = list.byId[id]
|
|
1370
|
+
if (session === undefined) continue
|
|
1371
|
+
if (session.origin === 'subagent') continue
|
|
1372
|
+
if (session.blank && id !== currentId) continue
|
|
1373
|
+
const isArchived = archived.has(id)
|
|
1374
|
+
if (isArchived && !showArchived) continue
|
|
1375
|
+
const key = ownerOf(id)
|
|
1376
|
+
const bucket = members.get(key)
|
|
1377
|
+
if (bucket === undefined) continue
|
|
1378
|
+
const title = sessionTitle(session)
|
|
1379
|
+
if (needle !== '' && !matches(title) && !workspaceMatches.get(key)) continue
|
|
1380
|
+
bucket.push(session)
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
for (const [key, bucket] of members) {
|
|
1384
|
+
const saved = state.order[key]
|
|
1385
|
+
if (!Array.isArray(saved) || saved.length === 0) {
|
|
1386
|
+
bucket.sort((a, b) => (a.updatedAt < b.updatedAt ? 1 : a.updatedAt > b.updatedAt ? -1 : 0))
|
|
1387
|
+
continue
|
|
1388
|
+
}
|
|
1389
|
+
const rank = new Map()
|
|
1390
|
+
for (let index = 0; index < saved.length; index += 1) rank.set(saved[index], index)
|
|
1391
|
+
const known = []
|
|
1392
|
+
const rest = []
|
|
1393
|
+
for (const session of bucket) {
|
|
1394
|
+
if (rank.has(session.id)) known.push(session)
|
|
1395
|
+
else rest.push(session)
|
|
1396
|
+
}
|
|
1397
|
+
known.sort((a, b) => rank.get(a.id) - rank.get(b.id))
|
|
1398
|
+
rest.sort((a, b) => (a.updatedAt < b.updatedAt ? 1 : a.updatedAt > b.updatedAt ? -1 : 0))
|
|
1399
|
+
members.set(key, known.concat(rest))
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
const filtering = needle !== ''
|
|
1403
|
+
let visibleCount = 0
|
|
1404
|
+
for (const bucket of members.values()) visibleCount += bucket.length
|
|
1405
|
+
|
|
1406
|
+
return { byId, parentOf, childrenOf, roots, members, currentId, ownerOf, realOwner, archived, filtering, visibleCount }
|
|
1407
|
+
}, [items, list, state.order, state.assign, workspaceSnapshot.archivedSessionIds, query, showArchived])
|
|
1408
|
+
|
|
1409
|
+
const setExpanded = useCallback((workspaceId, expanded) => {
|
|
1410
|
+
store.update(current => ({
|
|
1411
|
+
...current,
|
|
1412
|
+
collapsed: { ...current.collapsed, [workspaceId]: !expanded },
|
|
1413
|
+
}))
|
|
1414
|
+
}, [])
|
|
1415
|
+
|
|
1416
|
+
const assignSession = useCallback(
|
|
1417
|
+
(sessionId, groupKey, beforeSessionId) => {
|
|
1418
|
+
if (typeof sessionId !== 'string' || sessionId === '') return
|
|
1419
|
+
store.update(current => {
|
|
1420
|
+
const realOwner = view.realOwner.get(sessionId)
|
|
1421
|
+
const previousKey = view.ownerOf(sessionId)
|
|
1422
|
+
const assign = { ...current.assign }
|
|
1423
|
+
if (groupKey === UNGROUPED || groupKey === realOwner) delete assign[sessionId]
|
|
1424
|
+
else assign[sessionId] = groupKey
|
|
1425
|
+
|
|
1426
|
+
const order = { ...current.order }
|
|
1427
|
+
const previous = Array.isArray(order[previousKey]) ? order[previousKey] : null
|
|
1428
|
+
if (previous !== null) order[previousKey] = previous.filter(id => id !== sessionId)
|
|
1429
|
+
const target = Array.isArray(order[groupKey]) ? order[groupKey].slice() : []
|
|
1430
|
+
const without = target.filter(id => id !== sessionId)
|
|
1431
|
+
const at = beforeSessionId === undefined ? -1 : without.indexOf(beforeSessionId)
|
|
1432
|
+
if (at >= 0) without.splice(at, 0, sessionId)
|
|
1433
|
+
else without.push(sessionId)
|
|
1434
|
+
order[groupKey] = without
|
|
1435
|
+
return { ...current, assign, order }
|
|
1436
|
+
})
|
|
1437
|
+
},
|
|
1438
|
+
[view],
|
|
1439
|
+
)
|
|
1440
|
+
|
|
1441
|
+
const openMenu = (target, label) => {
|
|
1442
|
+
if (typeof renderFactorySlot !== 'function') return null
|
|
1443
|
+
const node = renderFactorySlot('contextMenu.button', { target, label, className: 'dnw-iconButton' })
|
|
1444
|
+
if (node !== null && node !== undefined) return node
|
|
1445
|
+
return h('button', { type: 'button', className: 'dnw-iconButton', 'aria-label': label, title: label, onClick: event => event.stopPropagation() }, h(IconDots, null))
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
const openWorkspaceMenu = (event, workspace) => {
|
|
1449
|
+
event.preventDefault()
|
|
1450
|
+
event.stopPropagation()
|
|
1451
|
+
const rect = event.currentTarget.getBoundingClientRect()
|
|
1452
|
+
const atPointer = event.type === 'contextmenu' && (event.clientX !== 0 || event.clientY !== 0)
|
|
1453
|
+
setMenu({
|
|
1454
|
+
workspaceId: workspace.workspaceId,
|
|
1455
|
+
anchor: atPointer
|
|
1456
|
+
? { top: event.clientY, bottom: event.clientY, left: event.clientX }
|
|
1457
|
+
: { top: rect.top, bottom: rect.bottom, left: rect.left },
|
|
1458
|
+
})
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
const menuWorkspace =
|
|
1462
|
+
menu === null ? null : items.find(item => item.workspaceId === menu.workspaceId) || null
|
|
1463
|
+
|
|
1464
|
+
const menuItems = useMemo(() => {
|
|
1465
|
+
if (menuWorkspace === null) return []
|
|
1466
|
+
return [
|
|
1467
|
+
{
|
|
1468
|
+
id: 'addChild',
|
|
1469
|
+
label: t('menu.addChild'),
|
|
1470
|
+
icon: IconFolderPlus,
|
|
1471
|
+
onSelect: () =>
|
|
1472
|
+
addChildRequest.set({
|
|
1473
|
+
parentId: menuWorkspace.workspaceId,
|
|
1474
|
+
parentPath: menuWorkspace.path,
|
|
1475
|
+
parentTitle: menuWorkspace.title,
|
|
1476
|
+
}),
|
|
1477
|
+
},
|
|
1478
|
+
{
|
|
1479
|
+
id: 'newSession',
|
|
1480
|
+
label: t('actions.newSession'),
|
|
1481
|
+
icon: IconPlus,
|
|
1482
|
+
onSelect: () => uiWorkspace.startSession(menuWorkspace.workspaceId),
|
|
1483
|
+
},
|
|
1484
|
+
{
|
|
1485
|
+
id: 'rename',
|
|
1486
|
+
label: t('actions.rename'),
|
|
1487
|
+
icon: IconEdit,
|
|
1488
|
+
separatorBefore: true,
|
|
1489
|
+
onSelect: () => setRenaming(menuWorkspace),
|
|
1490
|
+
},
|
|
1491
|
+
{
|
|
1492
|
+
id: 'delete',
|
|
1493
|
+
label: t('actions.delete'),
|
|
1494
|
+
icon: IconTrash,
|
|
1495
|
+
danger: true,
|
|
1496
|
+
onSelect: () => setDeleting(menuWorkspace),
|
|
1497
|
+
},
|
|
1498
|
+
]
|
|
1499
|
+
}, [menuWorkspace, t, uiWorkspace])
|
|
1500
|
+
|
|
1501
|
+
const commitTitle = () => {
|
|
1502
|
+
/* Escape sets the cancel flag first; the input then unmounts and its
|
|
1503
|
+
* onBlur fires, which must not turn the abandoned draft into a save. */
|
|
1504
|
+
if (cancelTitleRef.current) {
|
|
1505
|
+
cancelTitleRef.current = false
|
|
1506
|
+
setEditingTitle(false)
|
|
1507
|
+
return
|
|
1508
|
+
}
|
|
1509
|
+
const next = draftTitle.trim()
|
|
1510
|
+
store.update(current => ({ ...current, title: next === '' ? null : next }))
|
|
1511
|
+
setEditingTitle(false)
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
const heading = state.title === null ? t('heading.default') : state.title
|
|
1515
|
+
|
|
1516
|
+
if (!wide) {
|
|
1517
|
+
return h(
|
|
1518
|
+
'div',
|
|
1519
|
+
{ className: 'dnw-root dnw-rail' },
|
|
1520
|
+
h(
|
|
1521
|
+
'button',
|
|
1522
|
+
{
|
|
1523
|
+
type: 'button',
|
|
1524
|
+
className: 'dnw-railButton',
|
|
1525
|
+
title: t('rail.search'),
|
|
1526
|
+
'aria-label': t('rail.search'),
|
|
1527
|
+
onClick: () => {
|
|
1528
|
+
setSearchOpen(true)
|
|
1529
|
+
expandSidebar()
|
|
1530
|
+
},
|
|
1531
|
+
},
|
|
1532
|
+
h(IconSearch, null),
|
|
1533
|
+
),
|
|
1534
|
+
h(
|
|
1535
|
+
'button',
|
|
1536
|
+
{
|
|
1537
|
+
type: 'button',
|
|
1538
|
+
className: 'dnw-railButton',
|
|
1539
|
+
title: t('actions.addWorkspace'),
|
|
1540
|
+
'aria-label': t('actions.addWorkspace'),
|
|
1541
|
+
onClick: () => addChildRequest.set({ parentId: null, parentPath: null, parentTitle: null }),
|
|
1542
|
+
},
|
|
1543
|
+
h(IconFolderPlus, null),
|
|
1544
|
+
),
|
|
1545
|
+
)
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
/* One bag of closures for the row components; rebuilt each render. */
|
|
1549
|
+
const env = {
|
|
1550
|
+
view, state, statuses, t, uiWorkspace,
|
|
1551
|
+
useSessionAccess, useWorkspaceAccess,
|
|
1552
|
+
openMenu, openWorkspaceMenu, assignSession, setExpanded, setRenaming,
|
|
1553
|
+
menu, draggingId, dropTarget, dragIdRef, setDraggingId, setDropTarget,
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
const tree = []
|
|
1557
|
+
for (const root of view.roots) tree.push(h(WorkspaceGroup, { key: 'grp:' + root.workspaceId, workspace: root, depth: 0, env }))
|
|
1558
|
+
|
|
1559
|
+
const ungrouped = view.members.get(UNGROUPED) || []
|
|
1560
|
+
const ungroupedCollapsed = state.collapsed[UNGROUPED] === true
|
|
1561
|
+
const isUngroupedDrop =
|
|
1562
|
+
dropTarget !== null && dropTarget.workspaceId === UNGROUPED && dropTarget.sessionId === undefined
|
|
1563
|
+
if (ungrouped.length > 0) {
|
|
1564
|
+
tree.push(
|
|
1565
|
+
h(
|
|
1566
|
+
'div',
|
|
1567
|
+
{
|
|
1568
|
+
key: 'w:ungrouped',
|
|
1569
|
+
className: cls('dnw-row', 'dnw-workspaceRow'),
|
|
1570
|
+
role: 'treeitem',
|
|
1571
|
+
tabIndex: 0,
|
|
1572
|
+
'aria-expanded': !ungroupedCollapsed,
|
|
1573
|
+
style: { '--dnw-indent': '0px' },
|
|
1574
|
+
onClick: () => setExpanded(UNGROUPED, ungroupedCollapsed),
|
|
1575
|
+
onKeyDown: event => {
|
|
1576
|
+
if (event.target !== event.currentTarget) return
|
|
1577
|
+
if (event.key !== 'Enter' && event.key !== ' ') return
|
|
1578
|
+
event.preventDefault()
|
|
1579
|
+
setExpanded(UNGROUPED, ungroupedCollapsed)
|
|
1580
|
+
},
|
|
1581
|
+
onDragOver: event => {
|
|
1582
|
+
if (dragIdRef.current === null) return
|
|
1583
|
+
event.preventDefault()
|
|
1584
|
+
event.stopPropagation()
|
|
1585
|
+
if (!isUngroupedDrop) setDropTarget({ workspaceId: UNGROUPED, mode: 'into' })
|
|
1586
|
+
},
|
|
1587
|
+
onDragLeave: event => {
|
|
1588
|
+
if (event.currentTarget.contains(event.relatedTarget)) return
|
|
1589
|
+
if (isUngroupedDrop) setDropTarget(null)
|
|
1590
|
+
},
|
|
1591
|
+
onDrop: event => {
|
|
1592
|
+
const id = dragIdRef.current || event.dataTransfer.getData('text/plain')
|
|
1593
|
+
event.preventDefault()
|
|
1594
|
+
event.stopPropagation()
|
|
1595
|
+
setDropTarget(null)
|
|
1596
|
+
setDraggingId(null)
|
|
1597
|
+
dragIdRef.current = null
|
|
1598
|
+
if (id) assignSession(id, UNGROUPED, undefined)
|
|
1599
|
+
},
|
|
1600
|
+
},
|
|
1601
|
+
h(
|
|
1602
|
+
'span',
|
|
1603
|
+
{ className: 'dnw-slot dnw-lead' },
|
|
1604
|
+
h(
|
|
1605
|
+
'button',
|
|
1606
|
+
{
|
|
1607
|
+
type: 'button',
|
|
1608
|
+
className: cls('dnw-chevron', !ungroupedCollapsed && 'dnw-chevronOpen'),
|
|
1609
|
+
'aria-label': (ungroupedCollapsed ? t('expandGroup') : t('collapseGroup')) + ' ' + t('ungrouped'),
|
|
1610
|
+
onClick: event => {
|
|
1611
|
+
event.stopPropagation()
|
|
1612
|
+
setExpanded(UNGROUPED, ungroupedCollapsed)
|
|
1613
|
+
},
|
|
1614
|
+
},
|
|
1615
|
+
h('span', { className: 'dnw-arrowInner' }, h(IconChevron, null)),
|
|
1616
|
+
),
|
|
1617
|
+
h('span', { className: cls('dnw-folderIcon', !ungroupedCollapsed && 'dnw-folderActive') }, h(IconFolder, null)),
|
|
1618
|
+
),
|
|
1619
|
+
h('span', { className: 'dnw-title dnw-titleMuted' }, t('ungrouped')),
|
|
1620
|
+
),
|
|
1621
|
+
ungroupedCollapsed
|
|
1622
|
+
? null
|
|
1623
|
+
: h('div', { key: 'g:ungrouped', role: 'group' }, ungrouped.map((session, index) => h(SessionRow, { key: 's:' + session.id, session, groupKey: UNGROUPED, index, bucket: ungrouped, env }))),
|
|
1624
|
+
)
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
const empty = view.roots.length === 0 && ungrouped.length === 0 && !view.filtering
|
|
1628
|
+
const noMatches = view.filtering && view.visibleCount === 0
|
|
1629
|
+
|
|
1630
|
+
return h(
|
|
1631
|
+
'div',
|
|
1632
|
+
{ className: 'dnw-root' },
|
|
1633
|
+
h(
|
|
1634
|
+
'div',
|
|
1635
|
+
{ className: 'dnw-header' },
|
|
1636
|
+
editingTitle
|
|
1637
|
+
? h('input', {
|
|
1638
|
+
ref: titleInputRef,
|
|
1639
|
+
className: 'dnw-headingInput',
|
|
1640
|
+
value: draftTitle,
|
|
1641
|
+
'aria-label': t('heading.default'),
|
|
1642
|
+
spellCheck: false,
|
|
1643
|
+
onChange: event => setDraftTitle(event.target.value),
|
|
1644
|
+
onBlur: commitTitle,
|
|
1645
|
+
onKeyDown: event => {
|
|
1646
|
+
if (event.key === 'Enter') {
|
|
1647
|
+
event.preventDefault()
|
|
1648
|
+
commitTitle()
|
|
1649
|
+
} else if (event.key === 'Escape') {
|
|
1650
|
+
event.preventDefault()
|
|
1651
|
+
cancelTitleRef.current = true
|
|
1652
|
+
setEditingTitle(false)
|
|
1653
|
+
}
|
|
1654
|
+
},
|
|
1655
|
+
})
|
|
1656
|
+
: h(
|
|
1657
|
+
'span',
|
|
1658
|
+
{
|
|
1659
|
+
className: 'dnw-label dnw-labelEditable',
|
|
1660
|
+
role: 'button',
|
|
1661
|
+
tabIndex: 0,
|
|
1662
|
+
title: t('heading.hint'),
|
|
1663
|
+
'aria-label': heading,
|
|
1664
|
+
'aria-description': t('heading.hint'),
|
|
1665
|
+
onDoubleClick: event => {
|
|
1666
|
+
event.preventDefault()
|
|
1667
|
+
cancelTitleRef.current = false
|
|
1668
|
+
setDraftTitle(heading)
|
|
1669
|
+
setEditingTitle(true)
|
|
1670
|
+
},
|
|
1671
|
+
onKeyDown: event => {
|
|
1672
|
+
if (event.key === 'Enter' || event.key === 'F2') {
|
|
1673
|
+
event.preventDefault()
|
|
1674
|
+
cancelTitleRef.current = false
|
|
1675
|
+
setDraftTitle(heading)
|
|
1676
|
+
setEditingTitle(true)
|
|
1677
|
+
}
|
|
1678
|
+
},
|
|
1679
|
+
},
|
|
1680
|
+
heading,
|
|
1681
|
+
),
|
|
1682
|
+
h(
|
|
1683
|
+
'div',
|
|
1684
|
+
{ className: 'dnw-headerActions' },
|
|
1685
|
+
h(
|
|
1686
|
+
'button',
|
|
1687
|
+
{
|
|
1688
|
+
type: 'button',
|
|
1689
|
+
className: cls('dnw-iconButton', showArchived && 'dnw-iconButtonOn'),
|
|
1690
|
+
title: showArchived ? t('actions.hideArchived') : t('actions.showArchived'),
|
|
1691
|
+
'aria-label': showArchived ? t('actions.hideArchived') : t('actions.showArchived'),
|
|
1692
|
+
'aria-pressed': showArchived,
|
|
1693
|
+
onClick: () => setShowArchived(current => !current),
|
|
1694
|
+
},
|
|
1695
|
+
h(IconArchive, null),
|
|
1696
|
+
),
|
|
1697
|
+
h(
|
|
1698
|
+
'button',
|
|
1699
|
+
{
|
|
1700
|
+
type: 'button',
|
|
1701
|
+
className: 'dnw-iconButton',
|
|
1702
|
+
title: t('actions.search'),
|
|
1703
|
+
'aria-label': t('actions.search'),
|
|
1704
|
+
onClick: () => {
|
|
1705
|
+
setSearchOpen(open => {
|
|
1706
|
+
if (open) setQuery('')
|
|
1707
|
+
return !open
|
|
1708
|
+
})
|
|
1709
|
+
},
|
|
1710
|
+
},
|
|
1711
|
+
h(IconSearch, null),
|
|
1712
|
+
),
|
|
1713
|
+
h(
|
|
1714
|
+
'button',
|
|
1715
|
+
{
|
|
1716
|
+
type: 'button',
|
|
1717
|
+
className: 'dnw-iconButton',
|
|
1718
|
+
title: t('actions.addWorkspace'),
|
|
1719
|
+
'aria-label': t('actions.addWorkspace'),
|
|
1720
|
+
onClick: () => addChildRequest.set({ parentId: null, parentPath: null, parentTitle: null }),
|
|
1721
|
+
},
|
|
1722
|
+
h(IconFolderPlus, null),
|
|
1723
|
+
),
|
|
1724
|
+
),
|
|
1725
|
+
),
|
|
1726
|
+
searchOpen
|
|
1727
|
+
? h(
|
|
1728
|
+
'div',
|
|
1729
|
+
{ className: 'dnw-searchRow' },
|
|
1730
|
+
h('input', {
|
|
1731
|
+
className: 'dnw-searchInput',
|
|
1732
|
+
value: query,
|
|
1733
|
+
placeholder: t('actions.search'),
|
|
1734
|
+
'aria-label': t('actions.search'),
|
|
1735
|
+
spellCheck: false,
|
|
1736
|
+
autoFocus: true,
|
|
1737
|
+
onChange: event => setQuery(event.target.value),
|
|
1738
|
+
onKeyDown: event => {
|
|
1739
|
+
if (event.key === 'Escape') {
|
|
1740
|
+
event.preventDefault()
|
|
1741
|
+
setQuery('')
|
|
1742
|
+
setSearchOpen(false)
|
|
1743
|
+
}
|
|
1744
|
+
},
|
|
1745
|
+
}),
|
|
1746
|
+
)
|
|
1747
|
+
: null,
|
|
1748
|
+
h(
|
|
1749
|
+
'div',
|
|
1750
|
+
{ className: 'dnw-list', ref: bindScrollerRef, 'data-sidebar-list-area': '', role: 'tree', 'aria-label': heading },
|
|
1751
|
+
empty
|
|
1752
|
+
? h('div', { className: 'dnw-empty' }, t('empty'))
|
|
1753
|
+
: noMatches
|
|
1754
|
+
? h('div', { className: 'dnw-empty' }, t('search.empty'))
|
|
1755
|
+
: tree,
|
|
1756
|
+
),
|
|
1757
|
+
request === null ? null : h(NewWorkspaceDialog, { request, onClose: () => addChildRequest.set(null) }),
|
|
1758
|
+
menuWorkspace === null
|
|
1759
|
+
? null
|
|
1760
|
+
: h(MenuPopover, { anchor: menu.anchor, items: menuItems, onClose: closeMenu }),
|
|
1761
|
+
renaming === null ? null : h(WorkspaceRenameDialog, { workspace: renaming, onClose: () => setRenaming(null) }),
|
|
1762
|
+
deleting === null ? null : h(WorkspaceDeleteDialog, { workspace: deleting, onClose: () => setDeleting(null) }),
|
|
1763
|
+
)
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
ctx.slots.inject('sidebar.workspaces', () =>
|
|
1767
|
+
ctx.slots.register(
|
|
1768
|
+
{
|
|
1769
|
+
name: 'sidebar.workspaces',
|
|
1770
|
+
priority: -1,
|
|
1771
|
+
locale: NS,
|
|
1772
|
+
},
|
|
1773
|
+
Sidebar,
|
|
1774
|
+
),
|
|
1775
|
+
)
|
|
1776
|
+
|
|
1777
|
+
function sessionTitle(session) {
|
|
1778
|
+
if (session.blank) return ''
|
|
1779
|
+
const title = typeof session.title === 'string' ? session.title.trim() : ''
|
|
1780
|
+
return title !== '' ? title : session.displayTitle || ''
|
|
1781
|
+
}
|
|
1782
|
+
},
|
|
1783
|
+
}
|
|
1784
|
+
},
|
|
1785
|
+
})
|