dsh-group-status 0.4.0 → 0.5.1

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.
Files changed (94) hide show
  1. package/CHANGELOG.md +128 -0
  2. package/README.en.md +10 -6
  3. package/README.md +12 -6
  4. package/lib/client.js +1913 -1804
  5. package/lib/client.js.map +1 -1
  6. package/lib/index.js +38 -8
  7. package/lib/types/build-stamp.d.ts +4 -0
  8. package/lib/types/build-stamp.d.ts.map +1 -0
  9. package/lib/types/build-stamp.js +23 -0
  10. package/lib/types/build-stamp.js.map +1 -0
  11. package/lib/types/client/BadgeSettingsCard.d.ts.map +1 -1
  12. package/lib/types/client/BadgeSettingsCard.js +8 -8
  13. package/lib/types/client/BadgeSettingsCard.js.map +1 -1
  14. package/lib/types/client/badge-field.d.ts +33 -10
  15. package/lib/types/client/badge-field.d.ts.map +1 -1
  16. package/lib/types/client/badge-field.js +35 -16
  17. package/lib/types/client/badge-field.js.map +1 -1
  18. package/lib/types/client/badge-labels.d.ts +3 -3
  19. package/lib/types/client/badge-labels.js +3 -3
  20. package/lib/types/client/badge-settings.d.ts +0 -25
  21. package/lib/types/client/badge-settings.d.ts.map +1 -1
  22. package/lib/types/client/badge-settings.js +0 -18
  23. package/lib/types/client/badge-settings.js.map +1 -1
  24. package/lib/types/client/facets.d.ts +39 -5
  25. package/lib/types/client/facets.d.ts.map +1 -1
  26. package/lib/types/client/facets.js +48 -4
  27. package/lib/types/client/facets.js.map +1 -1
  28. package/lib/types/client/group-status.d.ts +5 -0
  29. package/lib/types/client/group-status.d.ts.map +1 -1
  30. package/lib/types/client/group-status.js +25 -0
  31. package/lib/types/client/group-status.js.map +1 -1
  32. package/lib/types/client/locales.d.ts +4 -8
  33. package/lib/types/client/locales.d.ts.map +1 -1
  34. package/lib/types/client/locales.js +4 -8
  35. package/lib/types/client/locales.js.map +1 -1
  36. package/lib/types/client/rows/EmptySessions.d.ts +4 -0
  37. package/lib/types/client/rows/EmptySessions.d.ts.map +1 -0
  38. package/lib/types/client/rows/EmptySessions.js +10 -0
  39. package/lib/types/client/rows/EmptySessions.js.map +1 -0
  40. package/lib/types/client/rows/GroupBadge.d.ts +4 -4
  41. package/lib/types/client/rows/GroupBadge.d.ts.map +1 -1
  42. package/lib/types/client/rows/GroupBadge.js +10 -7
  43. package/lib/types/client/rows/GroupBadge.js.map +1 -1
  44. package/lib/types/client/rows/ListView.d.ts +24 -0
  45. package/lib/types/client/rows/ListView.d.ts.map +1 -0
  46. package/lib/types/client/rows/ListView.js +81 -0
  47. package/lib/types/client/rows/ListView.js.map +1 -0
  48. package/lib/types/client/rows/SessionTree.d.ts +4 -0
  49. package/lib/types/client/rows/SessionTree.d.ts.map +1 -0
  50. package/lib/types/client/rows/SessionTree.js +381 -0
  51. package/lib/types/client/rows/SessionTree.js.map +1 -0
  52. package/lib/types/client/rows/ViewOptionsMenu.d.ts +14 -0
  53. package/lib/types/client/rows/ViewOptionsMenu.d.ts.map +1 -0
  54. package/lib/types/client/rows/ViewOptionsMenu.js +50 -0
  55. package/lib/types/client/rows/ViewOptionsMenu.js.map +1 -0
  56. package/lib/types/client/rows/WorkspaceBrowser.d.ts +0 -5
  57. package/lib/types/client/rows/WorkspaceBrowser.d.ts.map +1 -1
  58. package/lib/types/client/rows/WorkspaceBrowser.js +8 -557
  59. package/lib/types/client/rows/WorkspaceBrowser.js.map +1 -1
  60. package/lib/types/client/rows/browser-shared.d.ts +105 -0
  61. package/lib/types/client/rows/browser-shared.d.ts.map +1 -0
  62. package/lib/types/client/rows/browser-shared.js +93 -0
  63. package/lib/types/client/rows/browser-shared.js.map +1 -0
  64. package/lib/types/client/session-actions/derived.d.ts.map +1 -1
  65. package/lib/types/client/session-actions/derived.js +13 -2
  66. package/lib/types/client/session-actions/derived.js.map +1 -1
  67. package/lib/types/client/session-watermarks.d.ts +6 -1
  68. package/lib/types/client/session-watermarks.d.ts.map +1 -1
  69. package/lib/types/client/session-watermarks.js +31 -11
  70. package/lib/types/client/session-watermarks.js.map +1 -1
  71. package/lib/types/client/toast/register.d.ts.map +1 -1
  72. package/lib/types/client/toast/register.js +102 -132
  73. package/lib/types/client/toast/register.js.map +1 -1
  74. package/lib/types/client/tree.d.ts +16 -1
  75. package/lib/types/client/tree.d.ts.map +1 -1
  76. package/lib/types/client/tree.js +20 -8
  77. package/lib/types/client/tree.js.map +1 -1
  78. package/lib/types/client/use-registered-facets.d.ts +11 -0
  79. package/lib/types/client/use-registered-facets.d.ts.map +1 -0
  80. package/lib/types/client/use-registered-facets.js +48 -0
  81. package/lib/types/client/use-registered-facets.js.map +1 -0
  82. package/lib/types/host-contract.d.ts +71 -0
  83. package/lib/types/host-contract.d.ts.map +1 -0
  84. package/lib/types/host-contract.js +127 -0
  85. package/lib/types/host-contract.js.map +1 -0
  86. package/lib/types/index.d.ts +13 -13
  87. package/lib/types/index.d.ts.map +1 -1
  88. package/lib/types/index.js +17 -8
  89. package/lib/types/index.js.map +1 -1
  90. package/package.json +16 -2
  91. package/lib/types/client/facet-visibility.d.ts +0 -17
  92. package/lib/types/client/facet-visibility.d.ts.map +0 -1
  93. package/lib/types/client/facet-visibility.js +0 -18
  94. package/lib/types/client/facet-visibility.js.map +0 -1
@@ -15,566 +15,18 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
15
15
  * are slot entries with their own behavior, so this component threads no
16
16
  * action callbacks and hosts no action surface.
17
17
  */
18
- import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
18
+ import { useEffect, useMemo, useRef, useState } from 'react';
19
19
  import clsx from 'clsx';
20
- import { Button, HoverCardGroup, IconArchiveCheckOutlineRegular, IconArchiveOffOutlineRegular, IconArchiveOutlineRegular, IconChevronsUpDownOutlineRegular, IconClockOutlineRegular, IconCloseFillRegular, IconFlatListOutlineRegular, IconFolderCloseRegular, IconProjectAddOutlineRegular, IconQueueOutlineRegular, IconSearchOutlineRegular, IconSlidersTwoOutlineRegular, IconWorkspaceTreeOutlineRegular, Menu, Modal, Tooltip, } from '@deepseek-ai/dsh-client-ui-primitives';
20
+ import { Button, IconCloseFillRegular, IconProjectAddOutlineRegular, IconSearchOutlineRegular, Modal, Tooltip, } from '@deepseek-ai/dsh-client-ui-primitives';
21
21
  import { workspaceDisplayTitle } from '@deepseek-ai/dsh-api-workspace-controller/default-workspace';
22
- import { deriveFlat, deriveGroups, deriveSearchResults, orderByRecency, owningGroupKey, owningParentFolder, pinCurrentBlank, reconcileManualOrder, sessionMemberIds, UNGROUPED_KEY, } from "../tree.js";
23
- import { directStatusesForGroups, withAggregatedStatus } from "../group-status.js";
24
- import { raiseWatermarks, requiredWatermark, SESSION_WATERMARK_BASE, watermarkRows, } from "../session-watermarks.js";
25
- import { facetStore } from "../facet-store.js";
26
- import { visibleFacets } from "../facet-visibility.js";
27
- import { ProjectRowItem, SearchResultItem, SessionNodeItem } from "./Rows.js";
28
- import { AnimatedRows } from "./AnimatedRows.js";
22
+ import { orderByRecency, pinCurrentBlank, reconcileManualOrder, sessionMemberIds, UNGROUPED_KEY, } from "../tree.js";
29
23
  import { FLAT_SESSION_ORDER_KEY } from "../stores.js";
30
24
  import { WorkspacePickFlow } from "../WorkspacePicker.js";
31
25
  import css from './WorkspaceBrowser.module.css';
32
- // 外部状态来源:**本文件不认识任何具体插件**。运行时只有登记面(`../facets.ts`)与
33
- // 它背后的存储订阅;谁想让自己的状态进折叠徽标,就按协议注册一个 facet
34
- // (`docs/facet-protocol.md`)。现有两家已各自注册,本插件不再代管任何来源。
35
- //
36
- // 这里只订阅一次外部存储并读一个版本号,与 facet 数量无关,所以增删来源不会改变
37
- // hook 调用序列(那正是逐个调 provider hook 的写法做不到的)。
38
- const facetsStore = facetStore();
39
- /**
40
- * Column slide length (--ds-transition-duration-slow): rail-search focus waits it out —
41
- * focus() forces a synchronous layout and would jank the slide.
42
- */
43
- const EXPAND_SLIDE_MS = 300;
44
- /** Pause between the latest keystroke and a Host content-search request. */
45
- const SEARCH_DEBOUNCE_MS = 250;
46
- /** `session.search` wire bound, measured in JavaScript UTF-16 code units. */
47
- const SEARCH_QUERY_MAX_CODE_UNITS = 500;
48
- /** Keep controlled input and RPC payload inside the session.search wire contract. */
49
- function sanitizeSearchQuery(value) {
50
- const withoutNul = value.replaceAll('\0', '');
51
- if (withoutNul.length <= SEARCH_QUERY_MAX_CODE_UNITS)
52
- return withoutNul;
53
- let end = SEARCH_QUERY_MAX_CODE_UNITS;
54
- const last = withoutNul.charCodeAt(end - 1);
55
- const next = withoutNul.charCodeAt(end);
56
- if (last >= 0xD800 && last <= 0xDBFF && next >= 0xDC00 && next <= 0xDFFF)
57
- end--;
58
- return withoutNul.slice(0, end);
59
- }
60
- /**
61
- * Accept the native drag at document level while a row drag is active: row
62
- * hover still owns the insertion marker, and releasing outside the list must
63
- * not be rendered as a rejected drop before dragend commits that last marker.
64
- */
65
- function useNativeDragAcceptance(active) {
66
- useEffect(() => {
67
- if (!active)
68
- return;
69
- const acceptDrag = (event) => {
70
- event.preventDefault();
71
- if (event.dataTransfer !== null)
72
- event.dataTransfer.dropEffect = 'move';
73
- };
74
- const acceptDrop = (event) => { event.preventDefault(); };
75
- document.addEventListener('dragover', acceptDrag);
76
- document.addEventListener('drop', acceptDrop);
77
- return () => {
78
- document.removeEventListener('dragover', acceptDrag);
79
- document.removeEventListener('drop', acceptDrop);
80
- };
81
- }, [active]);
82
- }
83
- /** Grouping, ordering, and archived-filter menu; own open state so it resets with the wide chrome. */
84
- function ViewOptionsMenu({ groupBy, orderBy, archivedFilter, onGroupPick, onOrderPick, onArchivedFilterPick, t }) {
85
- const [open, setOpen] = useState(false);
86
- return (_jsx(Menu, { open: open, onClose: () => { setOpen(false); }, items: [
87
- { type: 'label', id: 'group-by', text: t('groupBy.label') },
88
- { id: 'workspace', label: t('groupBy.workspace'), icon: _jsx(IconFolderCloseRegular, {}) },
89
- { id: 'workspace-tree', label: t('groupBy.workspaceTree'), icon: _jsx(IconWorkspaceTreeOutlineRegular, {}) },
90
- { id: 'flat', label: t('groupBy.flat'), icon: _jsx(IconFlatListOutlineRegular, {}) },
91
- { type: 'separator', id: 'order-by-separator' },
92
- { type: 'label', id: 'order-by', text: t('orderBy.label') },
93
- { id: 'manual', label: t('orderBy.manual'), icon: _jsx(IconChevronsUpDownOutlineRegular, {}) },
94
- { id: 'updated', label: t('orderBy.updated'), icon: _jsx(IconClockOutlineRegular, {}) },
95
- { type: 'separator', id: 'archived-filter-separator' },
96
- { type: 'label', id: 'filter-by', text: t('filterBy.label') },
97
- { id: 'hide-archived', label: t('viewOptions.hideArchived'), icon: _jsx(IconArchiveOffOutlineRegular, {}) },
98
- { id: 'show-archived', label: t('viewOptions.showArchived'), icon: _jsx(IconQueueOutlineRegular, {}) },
99
- { id: 'only-archived', label: t('viewOptions.onlyArchived'), icon: _jsx(IconArchiveCheckOutlineRegular, {}) },
100
- ], selectedIds: [
101
- groupBy,
102
- orderBy,
103
- { default: 'hide-archived', show: 'show-archived', only: 'only-archived' }[archivedFilter],
104
- ], onSelect: (id) => {
105
- if (id === 'workspace' || id === 'workspace-tree' || id === 'flat')
106
- onGroupPick(id);
107
- else if (id === 'manual' || id === 'updated')
108
- onOrderPick(id);
109
- else if (id === 'hide-archived')
110
- onArchivedFilterPick('default');
111
- else if (id === 'show-archived')
112
- onArchivedFilterPick('show');
113
- else if (id === 'only-archived')
114
- onArchivedFilterPick('only');
115
- setOpen(false);
116
- }, align: "end", dense: true, listClassName: css.viewOptionsMenu,
117
- // Portal: the section header clips overflow, so an in-place list would
118
- // be cut off at the header's bounds.
119
- portal: true, anchor: (_jsx(Tooltip, { label: t('viewOptions.label'), side: "bottom", delayMs: 500, children: _jsx("button", { type: "button", className: clsx(css.iconButton, css.wide), "aria-label": t('viewOptions.label'), onClick: () => { setOpen(v => !v); }, children: _jsx(IconSlidersTwoOutlineRegular, {}) }) })) }));
120
- }
121
- /** Apply a visible drop to the complete account without removing hidden members. */
122
- function sessionDragOrder(order, rows, drag, over) {
123
- const source = rows.find(row => row.id === drag.sessionId);
124
- const target = rows.find(row => row.id === over.id);
125
- if (source === undefined || target === undefined || source.blank
126
- || source.pinned !== drag.pinned || target.pinned !== drag.pinned
127
- || source.id === target.id || !order.includes(source.id))
128
- return;
129
- const section = rows.filter(row => row.pinned === drag.pinned);
130
- const sourceIndex = section.findIndex(row => row.id === source.id);
131
- const withoutSource = section.filter(row => row.id !== source.id);
132
- const insertAt = withoutSource.findIndex(row => row.id === target.id) + (over.half === 'after' ? 1 : 0);
133
- if (insertAt === sourceIndex)
134
- return;
135
- const next = order.filter(id => id !== source.id);
136
- const targetIndex = next.indexOf(target.id);
137
- if (targetIndex === -1)
138
- return;
139
- next.splice(targetIndex + (over.half === 'after' ? 1 : 0), 0, source.id);
140
- return pinCurrentBlank(next, rows.find(row => row.blank)?.id);
141
- }
142
- /** Resolve an insertion side across the Workspace header, descendants, and Sessions. */
143
- function workspaceGroupHalf(e) {
144
- const rect = e.currentTarget.getBoundingClientRect();
145
- return e.clientY < rect.top + rect.height / 2 ? 'before' : 'after';
146
- }
147
- /** The list-empty placeholder — a glyph over the text; the archived-only view names its filter and offers the way back. */
148
- function EmptySessions({ rowState, onLeaveArchivedOnly, t }) {
149
- const archivedOnly = rowState.archivedFilter === 'only';
150
- return (_jsxs("div", { className: css.emptyState, "data-row-key": "empty", children: [archivedOnly ? _jsx(IconArchiveOutlineRegular, { size: 24 }) : _jsx(IconQueueOutlineRegular, { size: 24 }), _jsx("div", { children: archivedOnly ? t('empty.noneArchived') : t('empty.none') }), archivedOnly && (_jsx("button", { type: "button", className: css.emptyAction, onClick: onLeaveArchivedOnly, children: t('empty.viewOthers') }))] }));
151
- }
152
- /** The scrolling session tree; unmounting drops the sessions subscription and local row limits. */
153
- function SessionTree({ list, useSessionStatus, startSession, open, workspaces, ungroupedSessionIds, rowState, onLeaveArchivedOnly, workspaceReady, animationResetKey, usePanelInfo, onRenameRequest, onDeleteRequest, onSessionRenameRequest, renderSlot, insertWorkspaceBefore, nestWorkspaces, groupExpansion, setGroupExpanded, setSessionOrder, home, t, revealSessionId, onSessionRevealed, shortcuts, useBadgeSettings, }) {
154
- const panelActive = usePanelInfo(info => info.activePanelId !== null);
155
- // 徽标设置:各来源显隐、悬停明细、数字样式。
156
- const badgeSettings = useBadgeSettings(settings => settings);
157
- const statuses = useSessionStatus(s => s);
158
- // 外部状态:一次订阅覆盖所有来源,版本号变即重渲染。`getVersion` 返回 number,
159
- // 引用天然稳定,不会像"每次新建一个快照对象"那样把订阅打成死循环(React #185)。
160
- useSyncExternalStore(facetsStore.subscribe, facetsStore.getVersion, facetsStore.getServerVersion);
161
- // 关掉的来源在**折叠之前**就筛掉:数字、图标、aria-label、悬停明细与"要不要画徽标"
162
- // 因此同源,不会出现在 label 里有、计数里没有的情况。
163
- const facets = useMemo(() => visibleFacets(facetsStore.list(), badgeSettings), [badgeSettings]);
164
- const current = panelActive
165
- ? undefined
166
- : Object.values(list.byId).find(session => (session.retainedBy.mainView ?? 0) > 0)?.id;
167
- const revealGroup = revealSessionId === undefined || !workspaceReady
168
- ? undefined
169
- : owningGroupKey(workspaces, revealSessionId);
170
- const [storedWatermarks, setStoredWatermarks] = useState({});
171
- const [watermarkMotionKey, setWatermarkMotionKey] = useState(0);
172
- // Transient drag marker state; the selected mode owns the resulting order.
173
- const [drag, setDrag] = useState(null);
174
- const sessionDropCommitted = useRef(false);
175
- const [workspaceDrag, setWorkspaceDrag] = useState(null);
176
- const workspaceDropCommitted = useRef(false);
177
- const nativeDragActive = drag !== null || workspaceDrag !== null;
178
- useNativeDragAcceptance(nativeDragActive);
179
- const currentGroup = current === undefined || !workspaceReady
180
- ? undefined
181
- : owningGroupKey(workspaces, current);
182
- useEffect(() => {
183
- if (current === undefined || currentGroup === undefined || Object.hasOwn(groupExpansion, currentGroup))
184
- return;
185
- setGroupExpanded(currentGroup, true);
186
- }, [current, currentGroup, setGroupExpanded, groupExpansion]);
187
- const parents = useMemo(() => {
188
- if (!nestWorkspaces)
189
- return new Map();
190
- const keysByPath = new Map(workspaces.map(workspace => [workspace.path, workspace.workspaceId]));
191
- const paths = [...keysByPath.keys()];
192
- return new Map(workspaces.map((workspace) => {
193
- const path = owningParentFolder(workspace.path, paths);
194
- return [workspace.workspaceId, path === undefined ? undefined : keysByPath.get(path)];
195
- }));
196
- }, [nestWorkspaces, workspaces]);
197
- const currentAncestors = useMemo(() => {
198
- const keys = new Set();
199
- for (let key = currentGroup === undefined ? undefined : parents.get(currentGroup); key !== undefined; key = parents.get(key)) {
200
- keys.add(key);
201
- }
202
- return keys;
203
- }, [currentGroup, parents]);
204
- const expandedGroups = useMemo(() => {
205
- const ancestorKeys = new Set(parents.values());
206
- return [...workspaces.map(workspace => workspace.workspaceId), UNGROUPED_KEY]
207
- .filter(key => groupExpansion[key] ?? ancestorKeys.has(key));
208
- }, [groupExpansion, parents, workspaces]);
209
- const groups = useMemo(() => deriveGroups(list, workspaces, rowState, statuses, {
210
- expandedGroups,
211
- ungroupedOrder: ungroupedSessionIds,
212
- }), [list, workspaces, rowState, statuses, expandedGroups, ungroupedSessionIds]);
213
- useEffect(() => {
214
- for (let key = revealGroup; key !== undefined; key = parents.get(key)) {
215
- if (groupExpansion[key] === false || (key === revealGroup && groupExpansion[key] !== true)) {
216
- setGroupExpanded(key, true);
217
- }
218
- }
219
- }, [groupExpansion, parents, revealGroup, setGroupExpanded]);
220
- const baselines = new Map(groups.map(group => [
221
- group.key,
222
- Math.max(SESSION_WATERMARK_BASE, requiredWatermark(group.expanded ? group.sessions : [], current, group.key === revealGroup ? revealSessionId : undefined)),
223
- ]));
224
- const foldedKeys = new Set(groups.filter(group => !group.expanded).map(group => group.key));
225
- const underFoldedAncestor = (key) => {
226
- for (let owner = parents.get(key); owner !== undefined; owner = parents.get(owner)) {
227
- if (foldedKeys.has(owner))
228
- return true;
229
- }
230
- return false;
231
- };
232
- const requiredWatermarks = new Map([...baselines].filter(([key]) => !underFoldedAncestor(key)));
233
- const sessionWatermarks = raiseWatermarks(storedWatermarks, requiredWatermarks);
234
- if (sessionWatermarks !== storedWatermarks) {
235
- setStoredWatermarks(marks => raiseWatermarks(marks, requiredWatermarks));
236
- }
237
- const dropWatermarks = (drop) => {
238
- if (!Object.keys(storedWatermarks).some(drop))
239
- return;
240
- setStoredWatermarks(marks => Object.fromEntries(Object.entries(marks).filter(([key]) => !drop(key))));
241
- setWatermarkMotionKey(key => key + 1);
242
- };
243
- const withinGroup = (key, root) => {
244
- for (let owner = key; owner !== undefined; owner = parents.get(owner)) {
245
- if (owner === root)
246
- return true;
247
- }
248
- return false;
249
- };
250
- const now = Date.now();
251
- const commitSessionDrag = (activeDrag, over) => {
252
- if (sessionDropCommitted.current)
253
- return;
254
- sessionDropCommitted.current = true;
255
- setDrag(null);
256
- const group = groups.find(candidate => candidate.key === activeDrag.accountKey);
257
- if (group === undefined)
258
- return;
259
- if (over.id === activeDrag.sessionId)
260
- return;
261
- const accountSessionIds = activeDrag.accountKey === UNGROUPED_KEY
262
- ? ungroupedSessionIds
263
- : workspaces.find(workspace => workspace.workspaceId === activeDrag.accountKey)?.sessionIds;
264
- if (accountSessionIds === undefined)
265
- return;
266
- const renderedSessions = watermarkRows(group.sessions, sessionWatermarks[group.key] ?? SESSION_WATERMARK_BASE).rows;
267
- const nextOrder = sessionDragOrder(accountSessionIds, renderedSessions, activeDrag, over);
268
- if (nextOrder !== undefined)
269
- setSessionOrder(activeDrag.accountKey, nextOrder);
270
- };
271
- const commitWorkspaceDrag = (activeDrag, over) => {
272
- if (workspaceDropCommitted.current)
273
- return;
274
- workspaceDropCommitted.current = true;
275
- setWorkspaceDrag(null);
276
- const owner = parents.get(activeDrag.workspaceId);
277
- const siblings = workspaces.filter(workspace => parents.get(workspace.workspaceId) === owner);
278
- const rowIndex = siblings.findIndex(workspace => workspace.workspaceId === over.id);
279
- if (rowIndex === -1)
280
- return;
281
- const anchor = over.half === 'before' ? over.id : siblings[rowIndex + 1]?.workspaceId;
282
- if (anchor === activeDrag.workspaceId)
283
- return;
284
- const sourceIndex = siblings.findIndex(workspace => workspace.workspaceId === activeDrag.workspaceId);
285
- const anchorIndex = anchor === undefined
286
- ? siblings.length
287
- : siblings.findIndex(workspace => workspace.workspaceId === anchor);
288
- if (sourceIndex !== -1 && (anchorIndex === sourceIndex || anchorIndex === sourceIndex + 1))
289
- return;
290
- insertWorkspaceBefore(activeDrag.workspaceId, anchor).catch((reason) => {
291
- console.warn('workspace reorder rejected:', reason);
292
- });
293
- };
294
- // Build tree structure from original groups (for aggregation traversal)
295
- const childrenByParentForAggregation = useMemo(() => {
296
- const rendered = new Set(groups.map(group => group.key));
297
- const children = new Map();
298
- for (const group of groups) {
299
- let parent = parents.get(group.key);
300
- while (parent !== undefined && !rendered.has(parent))
301
- parent = parents.get(parent);
302
- const siblings = children.get(parent);
303
- if (siblings === undefined)
304
- children.set(parent, [group]);
305
- else
306
- siblings.push(group);
307
- }
308
- return children;
309
- }, [groups, parents]);
310
- // Fork-owned: each group's DIRECT member status — the input to the tree-wide
311
- // aggregation below. deriveGroups stopped computing liveStatus (PR #10 moved it
312
- // out), so this map is the aggregator's only data source. Expanded groups are
313
- // measured too; see directStatusesForGroups.
314
- const directStatusByGroup = useMemo(() => directStatusesForGroups(groups, facets, now),
315
- // `now` 刻意不进依赖:它是渲染期的时钟读数,唯一影响的是"哪些截止还算将来"。
316
- // 提供方的 store 到点会通知,需要新答案的那次渲染本来就带着新的 `now` 发生。
317
- [groups, facets]);
318
- // Multi-level aggregation: a collapsed folder's badge covers its own members plus
319
- // every descendant group's, at any depth. Every row comes back measured, so the
320
- // render path can never see an unresolved liveStatus.
321
- const groupsWithAggregatedStatus = useMemo(() => withAggregatedStatus(groups, directStatusByGroup, childrenByParentForAggregation), [groups, directStatusByGroup, childrenByParentForAggregation]);
322
- // Rebuild tree structure with aggregated groups (for rendering)
323
- const childrenByParent = useMemo(() => {
324
- const rendered = new Set(groupsWithAggregatedStatus.map(group => group.key));
325
- const children = new Map();
326
- for (const group of groupsWithAggregatedStatus) {
327
- // The archived-only view drops empty groups, so an ancestor may be
328
- // absent; nest under the nearest rendered one.
329
- let parent = parents.get(group.key);
330
- while (parent !== undefined && !rendered.has(parent))
331
- parent = parents.get(parent);
332
- const siblings = children.get(parent);
333
- if (siblings === undefined)
334
- children.set(parent, [group]);
335
- else
336
- siblings.push(group);
337
- }
338
- return children;
339
- }, [groupsWithAggregatedStatus, parents]);
340
- const rootGroups = childrenByParent.get(undefined) ?? [];
341
- const workspaceDropAtListStart = rootGroups[0]?.workspaceId !== undefined
342
- && workspaceDrag?.over?.id === rootGroups[0].workspaceId
343
- && workspaceDrag.over.half === 'before';
344
- const rowKeys = groupsWithAggregatedStatus.length === 0 ? ['empty'] : [];
345
- const renderGroup = (group, depth) => {
346
- const workspaceId = group.workspaceId;
347
- const children = childrenByParent.get(group.key) ?? [];
348
- const compatibleDrag = workspaceDrag !== null && parents.get(workspaceDrag.workspaceId) === parents.get(group.key);
349
- const watermark = sessionWatermarks[group.key] ?? SESSION_WATERMARK_BASE;
350
- const collapsed = watermarkRows(group.sessions, baselines.get(group.key) ?? SESSION_WATERMARK_BASE);
351
- const visible = watermarkRows(group.sessions, watermark);
352
- const sessionsExpanded = visible.hiddenCount === 0;
353
- rowKeys.push(`workspace:${group.key}`);
354
- const childRows = group.expanded ? children.map(child => renderGroup(child, depth + 1)) : [];
355
- const sessions = visible.rows;
356
- for (const node of sessions)
357
- rowKeys.push(`session:${node.id}`);
358
- if (collapsed.hiddenCount > 0)
359
- rowKeys.push(`overflow:${group.key}`);
360
- const workspaceMarker = workspaceId !== undefined && workspaceDrag?.over?.id === workspaceId
361
- ? workspaceDrag.over.half
362
- : null;
363
- const workspaceDragProps = workspaceId === undefined ? undefined : {
364
- start: () => {
365
- workspaceDropCommitted.current = false;
366
- setWorkspaceDrag({ workspaceId, over: null });
367
- },
368
- end: () => {
369
- if (workspaceDrag?.over !== null && workspaceDrag?.over !== undefined) {
370
- commitWorkspaceDrag(workspaceDrag, workspaceDrag.over);
371
- }
372
- else {
373
- setWorkspaceDrag(null);
374
- }
375
- workspaceDropCommitted.current = false;
376
- },
377
- };
378
- const hoverWorkspace = workspaceId === undefined || !compatibleDrag
379
- ? undefined
380
- : (half) => {
381
- setWorkspaceDrag(active => active === null
382
- ? active
383
- : { ...active, over: { id: workspaceId, half } });
384
- };
385
- const dropWorkspace = workspaceId === undefined || !compatibleDrag
386
- ? undefined
387
- : (half) => {
388
- commitWorkspaceDrag(workspaceDrag, { id: workspaceId, half });
389
- };
390
- // group arrives from groupsWithAggregatedStatus: collapsed groups already
391
- // carry the bottom-up aggregated liveStatus (direct + all descendants).
392
- return (
393
- // Group section: header, descendant Workspaces, and own Session rows. The
394
- // inter-group breathing room is the section's own margin
395
- // (WorkspaceBrowser.module.css).
396
- _jsxs("div", { style: { '--dsh-workspace-indent': `${depth * 12}px` }, className: clsx(css.groupSection, workspaceMarker === 'before' && css.workspaceDropBefore, workspaceMarker === 'after' && css.workspaceDropAfter), onDragOver: workspaceDrag === null
397
- ? undefined
398
- : (e) => {
399
- e.preventDefault();
400
- if (hoverWorkspace === undefined && parents.get(group.key) !== undefined)
401
- return;
402
- e.stopPropagation();
403
- if (hoverWorkspace === undefined) {
404
- e.dataTransfer.dropEffect = 'none';
405
- if (workspaceDrag.over !== null)
406
- setWorkspaceDrag({ ...workspaceDrag, over: null });
407
- }
408
- else {
409
- e.dataTransfer.dropEffect = 'move';
410
- hoverWorkspace(workspaceGroupHalf(e));
411
- }
412
- }, onDrop: workspaceDrag === null
413
- ? undefined
414
- : (e) => {
415
- e.preventDefault();
416
- if (dropWorkspace === undefined && parents.get(group.key) !== undefined)
417
- return;
418
- e.stopPropagation();
419
- if (dropWorkspace === undefined) {
420
- workspaceDropCommitted.current = true;
421
- setWorkspaceDrag(null);
422
- }
423
- else {
424
- dropWorkspace(workspaceGroupHalf(e));
425
- }
426
- }, children: [_jsx(ProjectRowItem, { newShortcut: shortcuts.find(row => row.id === 'session.new'), group: group, containsCurrentDescendant: currentAncestors.has(group.key), home: home, settings: badgeSettings, now: now, t: t, onToggle: () => {
427
- if (group.expanded)
428
- dropWatermarks(key => withinGroup(key, group.key));
429
- setGroupExpanded(group.key, !group.expanded);
430
- }, onCreate: () => {
431
- if (group.workspaceId !== undefined) {
432
- setGroupExpanded(group.key, true);
433
- startSession(group.workspaceId);
434
- }
435
- }, drag: workspaceDragProps, actions: group.workspaceId === undefined
436
- ? undefined
437
- : {
438
- rename: () => {
439
- /* v8 ignore next -- narrowing guard: the actions object exists only for real-workspace groups. */
440
- if (group.workspaceId !== undefined)
441
- onRenameRequest(group.workspaceId, group.label);
442
- },
443
- delete: () => {
444
- /* v8 ignore next -- narrowing guard: the actions object exists only for real-workspace groups. */
445
- if (group.workspaceId !== undefined)
446
- onDeleteRequest(group.workspaceId, group.label);
447
- },
448
- } }), childRows.length > 0 && (_jsx("div", { role: "group", children: childRows })), group.expanded && sessions.map((node) => {
449
- // Session drag never leaves its browser-local account, and pinned
450
- // rows reorder only within their leading pinned block.
451
- const sameGroupDrag = drag !== null && drag.accountKey === group.key;
452
- const compatibleTarget = sameGroupDrag && drag.pinned === node.pinned;
453
- const normalizeHalf = (half) => node.blank ? 'after' : half;
454
- const dragProps = {
455
- start: () => {
456
- sessionDropCommitted.current = false;
457
- setDrag({ accountKey: group.key, sessionId: node.id, pinned: node.pinned, over: null });
458
- },
459
- active: compatibleTarget,
460
- marker: sameGroupDrag && drag.over?.id === node.id ? drag.over.half : null,
461
- hover: (half) => {
462
- /* v8 ignore next -- narrowing guard: Rows gates hover on `active`, which is false while the drag state is null. */
463
- setDrag(d => (d === null ? d : {
464
- ...d, over: { id: node.id, half: normalizeHalf(half) },
465
- }));
466
- },
467
- drop: (half) => {
468
- /* v8 ignore next -- narrowing guard: Rows gates drop on `active`, which is false while the drag state is null. */
469
- if (drag === null)
470
- return;
471
- commitSessionDrag(drag, { id: node.id, half: normalizeHalf(half) });
472
- },
473
- end: () => {
474
- if (drag?.over !== null && drag?.over !== undefined)
475
- commitSessionDrag(drag, drag.over);
476
- else
477
- setDrag(null);
478
- sessionDropCommitted.current = false;
479
- },
480
- };
481
- return (_jsx(SessionNodeItem, { node: node, currentId: current, now: now, onOpen: open, onRenameRequest: onSessionRenameRequest, renderSlot: renderSlot, onReveal: node.id === revealSessionId && group.key === revealGroup
482
- ? () => { onSessionRevealed(node.id); }
483
- : undefined, drag: dragProps, t: t }, node.id));
484
- }), group.expanded && collapsed.hiddenCount > 0 && (_jsx("button", { type: "button", className: css.sessionOverflowButton, "data-row-key": `overflow:${group.key}`, "aria-expanded": sessionsExpanded, onClick: () => {
485
- if (sessionsExpanded) {
486
- dropWatermarks(key => key === group.key);
487
- return;
488
- }
489
- setStoredWatermarks(marks => ({
490
- ...marks,
491
- [group.key]: visible.hiddenCount <= SESSION_WATERMARK_BASE
492
- ? Infinity
493
- : watermark + SESSION_WATERMARK_BASE,
494
- }));
495
- setWatermarkMotionKey(key => key + 1);
496
- }, children: sessionsExpanded
497
- ? t('sessions.collapse')
498
- : t('sessions.expand', { n: visible.hiddenCount }) }))] }, group.key));
499
- };
500
- const groupRows = rootGroups.map(group => renderGroup(group, 0));
501
- return (_jsxs(HoverCardGroup, { className: clsx(css.treeBody, css.wide), children: [workspaceDropAtListStart && _jsx("span", { className: css.listTopDropIndicator, "aria-hidden": "true" }), _jsxs(AnimatedRows, { className: clsx(css.list, workspaceDropAtListStart && css.listTopDropActive), label: t('section.sessions'), rowKeys: rowKeys, ready: list.phase === 'ready' && workspaceReady && !nativeDragActive, resetKey: JSON.stringify([animationResetKey, watermarkMotionKey]), children: [groupsWithAggregatedStatus.length === 0 && (_jsx(EmptySessions, { rowState: rowState, onLeaveArchivedOnly: onLeaveArchivedOnly, t: t })), groupRows] }), _jsx("span", { className: css.fade })] }));
502
- }
503
- /** The flat "In one list" body: every session is one draggable top-level row. */
504
- function FlatList({ list, sessionIds, rowState, onLeaveArchivedOnly, useSessionStatus, open, onSessionRenameRequest, usePanelInfo, setSessionOrder, workspaceReady, animationResetKey, revealSessionId, onSessionRevealed, renderSlot, t, }) {
505
- const panelActive = usePanelInfo(info => info.activePanelId !== null);
506
- const statuses = useSessionStatus(s => s);
507
- const rows = useMemo(() => deriveFlat(list, sessionIds, rowState, statuses), [list, sessionIds, rowState, statuses]);
508
- const [drag, setDrag] = useState(null);
509
- const dropCommitted = useRef(false);
510
- useNativeDragAcceptance(drag !== null);
511
- const currentId = panelActive
512
- ? undefined
513
- : Object.values(list.byId).find(session => (session.retainedBy.mainView ?? 0) > 0)?.id;
514
- const commitDrag = (activeDrag, over) => {
515
- if (dropCommitted.current)
516
- return;
517
- dropCommitted.current = true;
518
- setDrag(null);
519
- const nextOrder = sessionDragOrder(sessionIds, rows, activeDrag, over);
520
- if (nextOrder !== undefined)
521
- setSessionOrder(FLAT_SESSION_ORDER_KEY, nextOrder);
522
- };
523
- const now = Date.now();
524
- return (_jsxs(HoverCardGroup, { className: clsx(css.treeBody, css.wide), children: [_jsxs(AnimatedRows, { className: clsx(css.list, css.flatList), label: t('section.sessions'), rowKeys: rows.length === 0 ? ['empty'] : rows.map(row => `session:${row.id}`), ready: list.phase === 'ready' && workspaceReady && drag === null, resetKey: animationResetKey, children: [rows.length === 0 && (_jsx(EmptySessions, { rowState: rowState, onLeaveArchivedOnly: onLeaveArchivedOnly, t: t })), rows.map((node) => {
525
- const active = drag !== null && drag.pinned === node.pinned;
526
- const normalizeHalf = (half) => node.blank ? 'after' : half;
527
- return (_jsx(SessionNodeItem, { node: node, currentId: currentId, now: now, onOpen: open, onRenameRequest: onSessionRenameRequest, renderSlot: renderSlot, onReveal: node.id === revealSessionId
528
- ? () => { onSessionRevealed(node.id); }
529
- : undefined, drag: {
530
- start: () => {
531
- dropCommitted.current = false;
532
- setDrag({ accountKey: FLAT_SESSION_ORDER_KEY, sessionId: node.id, pinned: node.pinned, over: null });
533
- },
534
- active,
535
- marker: active && drag.over?.id === node.id ? drag.over.half : null,
536
- hover: (half) => {
537
- setDrag(current => current === null ? current : {
538
- ...current, over: { id: node.id, half: normalizeHalf(half) },
539
- });
540
- },
541
- drop: (half) => {
542
- if (drag !== null)
543
- commitDrag(drag, { id: node.id, half: normalizeHalf(half) });
544
- },
545
- end: () => {
546
- if (drag?.over !== null && drag?.over !== undefined)
547
- commitDrag(drag, drag.over);
548
- else
549
- setDrag(null);
550
- dropCommitted.current = false;
551
- },
552
- }, t: t }, node.id));
553
- })] }), _jsx("span", { className: css.fade })] }));
554
- }
555
- /** Flat search body: local metadata matches plus the current Host result page. */
556
- function SearchResults({ useSessions, useSessionStatus, open, onUnarchive, workspaces, archivedSessionIds, archivedFilter, query, remote, resultLimit, usePanelInfo, t, }) {
557
- const panelActive = usePanelInfo(info => info.activePanelId !== null);
558
- const list = useSessions(s => s);
559
- const statuses = useSessionStatus(s => s);
560
- const currentRemote = remote.query === query
561
- ? remote
562
- : { query, status: 'loading', items: [], hasMore: false };
563
- const results = useMemo(() => deriveSearchResults(list, workspaces, query, archivedSessionIds, archivedFilter, statuses, currentRemote, resultLimit), [list, workspaces, query, archivedSessionIds, archivedFilter, statuses, currentRemote, resultLimit]);
564
- const pending = currentRemote.status === 'loading';
565
- const currentId = panelActive
566
- ? undefined
567
- : Object.values(list.byId).find(session => (session.retainedBy.mainView ?? 0) > 0)?.id;
568
- return (_jsxs("div", { className: clsx(css.treeBody, css.wide), children: [_jsxs("div", { className: css.list, children: [_jsx("div", { className: css.searchTree, role: "tree", "aria-label": t('search.results.aria'), children: results.items.map(result => (_jsx(SearchResultItem, { result: result, currentId: currentId, onOpen: open, onUnarchive: onUnarchive, t: t }, result.id))) }), pending && (
569
- /* Two skeleton rows on an empty list, one when local matches already
570
- show and only the content hits are outstanding. */
571
- _jsx("div", { role: "status", "aria-label": t('search.pending'), children: (results.items.length === 0 ? [0, 1] : [0]).map(i => (_jsxs("div", { className: css.skeletonRow, "aria-hidden": "true", children: [_jsx("span", { className: css.skeletonDot }), _jsxs("span", { className: css.skeletonBars, children: [_jsx("span", { className: css.skeletonBar }), _jsx("span", { className: clsx(css.skeletonBar, css.skeletonBarWide) })] })] }, i))) })), !pending && results.items.length === 0 && (_jsx("div", { className: css.empty, children: t('search.noMatches') })), results.hasMore && (_jsx("div", { className: css.searchStatus, children: t('search.hasMore', { n: resultLimit }) }))] }), _jsx("span", { className: css.fade })] }));
572
- }
573
- /**
574
- * Render the browsing region.
575
- * @param props - composed slot props (shell owner share + store + injected actions).
576
- * @returns the region element tree.
577
- */
26
+ import { EXPAND_SLIDE_MS, SEARCH_DEBOUNCE_MS, SEARCH_QUERY_MAX_CODE_UNITS, mainViewSessionId, sanitizeSearchQuery, } from "./browser-shared.js";
27
+ import { ViewOptionsMenu } from "./ViewOptionsMenu.js";
28
+ import { SessionTree } from "./SessionTree.js";
29
+ import { FlatList, SearchResults } from "./ListView.js";
578
30
  export function WorkspaceBrowser({ wide, usePanelInfo, expandSidebar, useSessions, useSessionStatus, useWorkspaces, useStore, actions, startSession, open, requestSessionRename, notifyArchivedNotOpenable, renameWorkspace, deleteWorkspace, insertWorkspaceBefore, unarchiveSession, createWorkspace, searchSessions, searchResultLimit, useDirectoryFlow, useHostInfo, useShortcuts, useWorkspaceShortcuts, useBadgeSettings, requestSearch, requestAddWorkspace, closeAddWorkspace, setDirectoryBusy, renderSlot, t, }) {
579
31
  const home = useHostInfo(info => info.home);
580
32
  const shortcuts = useShortcuts(rows => rows);
@@ -616,8 +68,7 @@ export function WorkspaceBrowser({ wide, usePanelInfo, expandSidebar, useSession
616
68
  };
617
69
  const leaveArchivedOnly = () => { actions.setArchivedFilter('default'); };
618
70
  const workspaceReady = workspacePhase === 'ready' && workspaceStreamState !== 'loading';
619
- const mainSessionId = Object.values(list.byId)
620
- .find(session => (session.retainedBy.mainView ?? 0) > 0)?.id;
71
+ const mainSessionId = useMemo(() => mainViewSessionId(list), [list]);
621
72
  const currentBlank = mainSessionId !== undefined && list.byId[mainSessionId]?.blank === true
622
73
  ? mainSessionId
623
74
  : undefined;