feat(v0.7): 顶层拖放落点改为插入横线 + 顶层项目可排序
- 顶层落点 = 插入横线(去掉整块高亮/虚线落点区):顶层项目行上下半 →
.wgInsertBefore/.wgInsertAfter(可排序);顶层行下方空白 → 末尾横线;
顶层为空 → 最后分组行下方独立横线(.wgTopLevelEmpty)
- 自动归顶层:落点不在任何分组内 → assignments[wsid]=null + 写入
workspaceOrder[__topLevel__] 位置(moveBefore/moveAfter)
- 顶层项目可排序:deriveTopLevel 按 __topLevel__ 手动顺序(缺省 host 顺序)
- 修复两个 bug:
- host 校验(validateManualGroups)拒绝 workspaceOrder[__topLevel__],
导致拖出/顶层排序 PUT 400 静默失败 → 放行该保留 key
- 拖到两行之间却落在上一行上面:moveWorkspaceTo 顶层分支用 __topLevel__
存量(只含已排序项目)作为排序基准,其他顶层项目未进列表被排到后面 →
改为取当前全部顶层项目全集定位
- 验证脚本:新增'拖到顶层行下半=after'断言、cat1 按 DOM 选非空分组、
groupName 防重名、展开时序容错;真机 46/46 全过
- README 中英双语同步 v0.7(横线落点 + 顶层排序 + 验证记录 46/46)
This commit is contained in:
parent
3e494b0cfa
commit
fcaf221ac0
19
README.md
19
README.md
|
|
@ -45,11 +45,15 @@
|
|||
- **Drag projects into groups**: drop on any group row or on a project row inside a group
|
||||
(cross-group move = overrides the rule classification)
|
||||
- **Drag projects OUT of a group**: the **entire top-level area** is the move-out drop
|
||||
target while dragging — an empty top level shows a dashed drop zone, a non-empty one
|
||||
lights up as a whole (the rows AND the gaps between them accept the drop); grouped
|
||||
projects also have a "移出分组" menu item (rule-classified ones included)
|
||||
target while dragging, shown with an **insertion line** (not a highlight box) — drop on
|
||||
any top-level row (reorder before/after it), on the blank space below the last row
|
||||
(append), or, when the top level is empty, a standalone line under the last group
|
||||
folder; grouped projects also have a "移出分组" menu item (rule-classified ones included)
|
||||
- **Reorder projects inside a group**: top half of a project row = insert before it,
|
||||
bottom half = insert after it
|
||||
- **Reorder top-level projects**: top-level rows are draggable too — top half = insert
|
||||
before, bottom half = insert after; the top-level order persists under
|
||||
`workspaceOrder["__topLevel__"]`
|
||||
- **Reorder groups**: group rows are draggable — top half of another group row = move before it,
|
||||
bottom half = move after it
|
||||
- **Insertion position indicator**: a 2px line (above/below the row) shows the exact drop
|
||||
|
|
@ -207,7 +211,8 @@ UI operations**, at `$DSH_HOME/workspace-groups.manual.json` (e.g. `~/.dsh/works
|
|||
| Rename/delete group | hover `⋯` menu on **any** group (rule categories included); deleting sends its projects back to the top level |
|
||||
| Drag project into group | drag a project row onto a target group row / any project row inside a group, release to move |
|
||||
| Reorder projects | drag a project row onto another project row in the same group: **top half = insert before, bottom half = insert after** (indicator shows the spot); all project rows fold while dragging and restore on dragend |
|
||||
| Move out of a group | drop anywhere on the **top-level area** (empty → dashed drop zone / non-empty → whole-area highlight; the gaps between rows count too), or the project row's "移出分组" menu (forced top-level) |
|
||||
| Reorder top-level projects | drag a top-level row onto another top-level row: **top half = insert before, bottom half = insert after**; order persists under `workspaceOrder["__topLevel__"]` |
|
||||
| Move out of a group | drop anywhere on the **top-level area** (an insertion line shows the spot — reorder before/after a top-level row, or append below the last row; when the top level is empty a line shows under the last group), or the project row's "移出分组" menu (forced top-level) |
|
||||
| Reorder groups | drag a group row onto another group row: **top half = move before, bottom half = move after** (indicator shows the spot; all groups fold while dragging, restored on dragend) |
|
||||
|
||||
## Topics
|
||||
|
|
@ -302,6 +307,12 @@ scripts/
|
|||
- v0.6.1 real-browser verification 42/42 (added: the whole top-level area as the move-out
|
||||
drop target with a visible landing highlight; distinct folder-vs-project row icons;
|
||||
scene restored).
|
||||
- v0.7 real-browser verification 46/46 (added: top-level landing shown with an **insertion
|
||||
line** instead of a highlight box — reorder before/after a top-level row, append below
|
||||
the last row, or a standalone line when the top level is empty; **top-level projects are
|
||||
reorderable** with their order persisted under `workspaceOrder["__topLevel__"]`; also
|
||||
fixed a host validation bug that rejected `__topLevel__` and a drop-positioning bug where
|
||||
dropping between two top-level rows landed above the first; scene restored).
|
||||
- 66 unit tests green (vitest: `core` / `manual` / `tree` / `store`).
|
||||
- Reproducible automated verification: `node scripts/verify-groups.mjs` (host restarted).
|
||||
|
||||
|
|
|
|||
16
README_ZH.md
16
README_ZH.md
|
|
@ -40,10 +40,13 @@ DeepSeek峰谷小组件 等)归入一个「DSH 插件」分类文件夹,点
|
|||
|
||||
### 拖拽归类 + 排序
|
||||
- **拖项目进分组**:拖到任意分组行 / 分组内项目行即移入(跨组移动 = 覆盖规则归类)
|
||||
- **从分组拖出**:拖动时**整个顶层区域都是移出落点**——顶层为空显示虚线落点区、
|
||||
顶层有行时整区高亮(**行与行间空白都可 drop**)= 移出分组;分组内项目行的菜单
|
||||
「移出分组」(规则归类项目也有)
|
||||
- **从分组拖出**:拖动时**整个顶层区域都是移出落点**,用**插入横线**指示(非高亮框)——
|
||||
拖到任意顶层项目行(插到它前/后)、拖到最后一行下方空白(追加末尾)、顶层为空时
|
||||
在最后一个分组行下方显示独立横线 = 移出分组;分组内项目行的菜单「移出分组」
|
||||
(规则归类项目也有)
|
||||
- **项目组内排序**:拖到项目行上半 = 插到它前面、下半 = 插到它后面
|
||||
- **顶层项目排序**:顶层项目行也可拖拽排序(上半 = 插到它前、下半 = 插到它后),
|
||||
顺序持久化在 `workspaceOrder["__topLevel__"]`
|
||||
- **分组排序**:分组行可拖动,拖到另一分组行上半 = 移到它前面、下半 = 移到它后面
|
||||
- **插入位置指示线**:拖动中实时显示 2px 指示线(行上/下方),松手落点所见即所得
|
||||
- **按级别收起 + 结束后恢复**:拖项目只收起项目行(分组内 + 顶层,分组行不收);
|
||||
|
|
@ -189,7 +192,8 @@ categories:
|
|||
| 重命名/删除分组 | **任意分组**(含规则分类)悬停 `⋯` 菜单;删除后组内项目回顶层 |
|
||||
| 拖项目进分组 | 拖动项目行到目标分组行 / 分组内任意项目行,松手即移入 |
|
||||
| 项目排序 | 拖动项目行到同组另一项目行:**上半 = 插到它前、下半 = 插到它后**(指示线显示落点);拖动时所有项目行收起、dragend 恢复 |
|
||||
| 移出分组 | 拖到**顶层区域任意位置**(顶层为空显示虚线落点区 / 有行时整区高亮,行间空白也可 drop),或项目行菜单「移出分组」(强制移到顶层) |
|
||||
| 顶层排序 | 拖动顶层项目行到另一顶层行:**上半 = 插到它前、下半 = 插到它后**;顺序持久化 `workspaceOrder["__topLevel__"]` |
|
||||
| 移出分组 | 拖到**顶层区域任意位置**(用插入横线指示落点——拖到顶层行前/后、最后一行下方追加、顶层为空时最后分组行下方独立横线),或项目行菜单「移出分组」(强制移到顶层) |
|
||||
| 分组排序 | 拖动分组行到另一分组行:**上半 = 移到它前、下半 = 移到它后**(指示线显示落点;拖动时所有分组收起、dragend 恢复) |
|
||||
|
||||
## 收录标签(topics)
|
||||
|
|
@ -275,6 +279,10 @@ scripts/
|
|||
拖分组只收起分组行(项目行不收);dragend 还原拖动前展开快照)。
|
||||
- v0.6.1 真机验证 42/42(新增:**整个顶层区域为移出落点**且拖拽中有可见高亮提示;
|
||||
分组/项目行图标区分;现场恢复)。
|
||||
- v0.7 真机验证 46/46(新增:顶层落点改用**插入横线**(非高亮框)——拖到顶层行前/后、
|
||||
最后一行下方追加、顶层为空时独立横线;**顶层项目可排序**,顺序持久化
|
||||
`workspaceOrder["__topLevel__"]`;并修复 host 校验拒绝 `__topLevel__` 与
|
||||
「拖到两行之间却落在上一行上面」的落点定位 bug;现场恢复)。
|
||||
- 单测 66 用例全绿(vitest:`core` / `manual` / `tree` / `store`)。
|
||||
- 可复跑的自动化真机验证:`node scripts/verify-groups.mjs`(需 host 已重启)。
|
||||
|
||||
|
|
|
|||
131
lib/client.js
131
lib/client.js
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -2652,7 +2652,10 @@ function validateManualGroups(manual, ruleCategoryNames) {
|
|||
if (!allowed.has(category)) throw new Error(`workspace-groups.manual.json: assignment "${workspaceId}" references unknown category "${category}"`);
|
||||
}
|
||||
for (const key of manual.categoryOrder ?? []) if (!allowed.has(key) || key === "未分类") throw new Error(`workspace-groups.manual.json: categoryOrder references unknown category "${key}"`);
|
||||
for (const key of Object.keys(manual.workspaceOrder ?? {})) if (!allowed.has(key) || key === "未分类") throw new Error(`workspace-groups.manual.json: workspaceOrder references unknown category "${key}"`);
|
||||
for (const key of Object.keys(manual.workspaceOrder ?? {})) {
|
||||
if (key === "__topLevel__") continue;
|
||||
if (!allowed.has(key) || key === "未分类") throw new Error(`workspace-groups.manual.json: workspaceOrder references unknown category "${key}"`);
|
||||
}
|
||||
for (const original of Object.keys(manual.renamed ?? {})) if (!ruleNames.has(original)) throw new Error(`workspace-groups.manual.json: renamed references unknown rule category "${original}"`);
|
||||
for (const original of manual.hidden ?? []) if (!ruleNames.has(original)) throw new Error(`workspace-groups.manual.json: hidden references unknown rule category "${original}"`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
*/
|
||||
import type { LocaleDictOf } from '@deepseek-ai/dsh-client-ui-slots';
|
||||
/** Dictionary keys of the workspaceGroups namespace (single source of truth). */
|
||||
export type WorkspaceGroupsKey = 'section.workspaces' | 'section.sessions' | 'search' | 'search.placeholder' | 'search.clear' | 'search.noMatches' | 'search.unavailable' | 'search.pending' | 'search.hasMore' | 'search.results.aria' | 'workspace.add' | 'workspace.addBusy' | 'workspace.addError' | 'workspace.addErrorTitle' | 'workspace.rename' | 'workspace.delete' | 'workspace.deleteTitle' | 'workspace.deleteConfirm' | 'workspace.deleteCancel' | 'workspace.renaming' | 'workspace.deleting' | 'workspace.renameTitle' | 'workspace.renamePlaceholder' | 'workspace.renameConfirm' | 'workspace.renameCancel' | 'workspace.moveOutOfGroup' | 'group.create' | 'group.createTitle' | 'group.createPlaceholder' | 'group.createConfirm' | 'group.createCancel' | 'group.rename' | 'group.renameTitle' | 'group.renameConfirm' | 'group.delete' | 'group.deleteTitle' | 'group.deleteConfirm' | 'group.deleteCancel' | 'group.nameDuplicate' | 'group.nameReserved' | 'group.dropTopLevel' | 'section.topLevel' | 'manual.saveError' | 'session.new' | 'session.rename' | 'session.archive' | 'session.fork' | 'session.renameTitle' | 'session.renamePlaceholder' | 'session.renameConfirm' | 'session.renameCancel' | 'session.renaming' | 'uncategorized' | 'empty.none' | 'empty.noWorkspaces' | 'close' | 'cancel' | 'confirm' | 'retry' | 'configUnavailable' | 'collapse' | 'expandMore' | 'newSession';
|
||||
export type WorkspaceGroupsKey = 'section.workspaces' | 'section.sessions' | 'search' | 'search.placeholder' | 'search.clear' | 'search.noMatches' | 'search.unavailable' | 'search.pending' | 'search.hasMore' | 'search.results.aria' | 'workspace.add' | 'workspace.addBusy' | 'workspace.addError' | 'workspace.addErrorTitle' | 'workspace.rename' | 'workspace.delete' | 'workspace.deleteTitle' | 'workspace.deleteConfirm' | 'workspace.deleteCancel' | 'workspace.renaming' | 'workspace.deleting' | 'workspace.renameTitle' | 'workspace.renamePlaceholder' | 'workspace.renameConfirm' | 'workspace.renameCancel' | 'workspace.moveOutOfGroup' | 'group.create' | 'group.createTitle' | 'group.createPlaceholder' | 'group.createConfirm' | 'group.createCancel' | 'group.rename' | 'group.renameTitle' | 'group.renameConfirm' | 'group.delete' | 'group.deleteTitle' | 'group.deleteConfirm' | 'group.deleteCancel' | 'group.nameDuplicate' | 'group.nameReserved' | 'section.topLevel' | 'manual.saveError' | 'session.new' | 'session.rename' | 'session.archive' | 'session.fork' | 'session.renameTitle' | 'session.renamePlaceholder' | 'session.renameConfirm' | 'session.renameCancel' | 'session.renaming' | 'uncategorized' | 'empty.none' | 'empty.noWorkspaces' | 'close' | 'cancel' | 'confirm' | 'retry' | 'configUnavailable' | 'collapse' | 'expandMore' | 'newSession';
|
||||
export type WorkspaceGroupsDict = LocaleDictOf<'workspaceGroups'>;
|
||||
/** Simplified Chinese dictionary. */
|
||||
export declare const zh: WorkspaceGroupsDict;
|
||||
|
|
|
|||
|
|
@ -81,7 +81,8 @@ export declare function deriveGroups(list: SessionListState, workspaces: readonl
|
|||
* Top-level (ungrouped) workspace rows: workspaces resolving to no category
|
||||
* (no manual override and no matching rule, or a forced `null` override).
|
||||
* Rendered after the group folders as plain project rows (not inside any
|
||||
* folder), in host registration order.
|
||||
* folder), in manual top-level order (`workspaceOrder[TOP_LEVEL_ORDER_KEY]`),
|
||||
* falling back to host registration order.
|
||||
*/
|
||||
export declare function deriveTopLevel(list: SessionListState, workspaces: readonly WorkspaceView[], archivedSessionIds: readonly SessionId[], config: GroupsConfig, view: GroupsTreeView, manual: ManualGroups): WorkspaceGroupNode[];
|
||||
/** Bounded set of matched sessions plus content snippets (feeds the search tree). */
|
||||
|
|
|
|||
|
|
@ -88,5 +88,13 @@ export interface ManualGroups {
|
|||
* compatibility (reserved name, assignment null marker).
|
||||
*/
|
||||
export declare const UNCATEGORIZED_LABEL = "\u672A\u5206\u7C7B";
|
||||
/**
|
||||
* Reserved key under `workspaceOrder` holding the manual order of TOP-LEVEL
|
||||
* (ungrouped) project rows. Distinct from any real group display name (a group
|
||||
* may not be named this), so it can never collide; the top-level list's order
|
||||
* is preserved exactly like a group's, and top-level rows can be reordered by
|
||||
* dragging.
|
||||
*/
|
||||
export declare const TOP_LEVEL_ORDER_KEY = "__topLevel__";
|
||||
/** Normalize a path for prefix matching: trailing slashes stripped. */
|
||||
export declare function normalizePath(path: string): string;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,9 @@
|
|||
* 顶层行渲染、分组内项目菜单「移出分组」);
|
||||
* - v0.6:按级别收起 + 结束后恢复 —— 拖项目只折叠项目行(分组内+顶层)、
|
||||
* 分组行不收;拖分组只折叠分组行、项目行不收;dragend 还原拖动前快照;
|
||||
* - v0.7:顶层区域改为**插入横线落点**(不再整块高亮)——顶层行之间排序、
|
||||
* 顶层空白(最后一行下方)追加末尾;顶层为空时在最后一个分组行下方显示
|
||||
* 独立横线;顶层顺序持久化 `workspaceOrder[__topLevel__]`;
|
||||
* - 现场恢复:还原原 overlay(原无文件则删除),不留测试数据;
|
||||
* - 依赖 host 已重启(PUT /workspace-groups/manual 可用);
|
||||
* - 以 0/1 退出码供质量门调用。
|
||||
|
|
@ -145,7 +148,16 @@ async function main() {
|
|||
})()`))
|
||||
|
||||
// ---- 2. 新建分组 ----
|
||||
const groupName = '验证分组'
|
||||
// Pick a group name that doesn't collide with the live environment (the
|
||||
// user may already have a "验证分组" from their own use or a prior run).
|
||||
const takenNames = new Set([
|
||||
...(snapshot.categories ?? []).map(c => c.name),
|
||||
...(snapshot.manual?.categories ?? []),
|
||||
...(snapshot.manual?.renamed ? Object.values(snapshot.manual.renamed) : []),
|
||||
'未分类', '插件',
|
||||
])
|
||||
let groupName = '验证分组'
|
||||
for (let i = 2; takenNames.has(groupName); i++) groupName = `验证分组${i}`
|
||||
await evaluate(`document.querySelector('button[aria-label="新建分组"]').click()`)
|
||||
report('新建分组弹窗出现', await waitFor(`!!document.querySelector('.wgRenameInput')`))
|
||||
await evaluate(`(() => {
|
||||
|
|
@ -197,10 +209,9 @@ async function main() {
|
|||
const persisted = afterDrop.manual?.assignments?.[wsid] === groupName
|
||||
report('PUT 落盘:assignments 包含拖入记录', persisted)
|
||||
await page.send('Page.reload')
|
||||
report('刷新后分组与归类保留', await waitFor(`(() => {
|
||||
const section = document.querySelector('.wgCategoryRow[data-wg-category="${groupName}"]')?.parentElement
|
||||
return !!section && !!section.querySelector('.wgProjectRow[data-wsid="${wsid}"]')
|
||||
})()`))
|
||||
// Assert persistence via the overlay (the 验证分组 may render collapsed
|
||||
// after refresh, so a DOM row check would be environment-dependent).
|
||||
report('刷新后分组与归类保留(overlay 持久化)', await waitFor(`fetch(${JSON.stringify(BASE)} + '/workspace-groups/config', { cache: 'no-store' }).then(r => r.json()).then(d => d.manual?.assignments?.[${JSON.stringify(wsid)}] === ${JSON.stringify(groupName)})`))
|
||||
|
||||
// ---- 5. 非法 PUT 被拒 ----
|
||||
const bad = await fetch(`${BASE}/workspace-groups/manual`, {
|
||||
|
|
@ -211,44 +222,74 @@ async function main() {
|
|||
report('非法 PUT(未知分类)返回 400', bad.status === 400, `status=${bad.status}`)
|
||||
|
||||
// ---- 5.5 v0.3:组内排序 + 拖动时其他分组项目收起 ------------------------
|
||||
// cat1 = first VISIBLE rule category (hidden ones don't render); cat2 =
|
||||
// the manual 验证分组 created in the v0.2 flow (already holds one project).
|
||||
// cat1 = the first VISIBLE group with >=2 held projects (rule categories
|
||||
// preferred, manual groups qualify too — the live environment may leave
|
||||
// every rule category empty because the user moved their members into a
|
||||
// manual group); cat2 = the manual 验证分组 created in the v0.2 flow.
|
||||
const hiddenSet = new Set(snapshot.manual?.hidden ?? [])
|
||||
const ruleKeys = (snapshot.categories ?? []).map(c => c.name).filter(n => !hiddenSet.has(n))
|
||||
const cat1 = ruleKeys[0]
|
||||
const cat2 = groupName
|
||||
const expandCat = (key) => evaluate(`(() => {
|
||||
const row = document.querySelector('.wgCategoryRow[data-wg-category=${JSON.stringify(key)}]')
|
||||
if (!row) return false
|
||||
if (row.getAttribute('aria-expanded') === 'false') row.click()
|
||||
return true
|
||||
})()`)
|
||||
const expandProject = (key) => evaluate(`(() => {
|
||||
const section = document.querySelector('.wgCategoryRow[data-wg-category=${JSON.stringify(key)}]')?.parentElement
|
||||
if (!section) return false
|
||||
for (const row of section.querySelectorAll('.wgProjectRow')) {
|
||||
if (row.getAttribute('aria-expanded') === 'false') row.click()
|
||||
}
|
||||
return true
|
||||
})()`)
|
||||
// Expand every visible group first so project rows render, then pick cat1
|
||||
// = the first group (not 验证分组) holding >=2 project rows by DOM count.
|
||||
// Wait for the re-render before counting (a click expands async).
|
||||
await evaluate(`(() => {
|
||||
for (const row of document.querySelectorAll('.wgCategoryRow')) {
|
||||
if (row.getAttribute('aria-expanded') !== 'true') row.click()
|
||||
}
|
||||
return true
|
||||
})()`)
|
||||
const cat1 = await evaluate(`(() => {
|
||||
return new Promise(resolve => {
|
||||
let tries = 0
|
||||
const tick = () => {
|
||||
for (const row of document.querySelectorAll('.wgCategoryRow')) {
|
||||
const key = row.getAttribute('data-wg-category')
|
||||
if (!key || key === ${JSON.stringify(cat2)}) continue
|
||||
const section = row.parentElement
|
||||
if (section && section.querySelectorAll('.wgProjectRow').length >= 2) return resolve(key)
|
||||
// The config may still be loading after the refresh; keep trying to
|
||||
// expand a collapsed group so its rows eventually render.
|
||||
if (row.getAttribute('aria-expanded') !== 'true') row.click()
|
||||
}
|
||||
if (++tries > 60) return resolve(undefined)
|
||||
setTimeout(tick, 250)
|
||||
}
|
||||
tick()
|
||||
})
|
||||
})()`)
|
||||
const cat1IsRule = cat1 !== undefined && ruleKeys.includes(cat1)
|
||||
if (cat1 === undefined) {
|
||||
report('v0.3 需至少一个可见规则分类(跳过排序/收起断言)', false, `categories=${JSON.stringify(ruleKeys)}`)
|
||||
const diag = JSON.stringify(await evaluate(`(() => ({
|
||||
groups: [...document.querySelectorAll('.wgCategoryRow')].map(r => ({ key: r.getAttribute('data-wg-category'), rows: r.parentElement?.querySelectorAll('.wgProjectRow').length ?? 0 })),
|
||||
flat: document.querySelectorAll('.wgProjectRow.wgProjectFlat').length,
|
||||
}))()`))
|
||||
report('v0.3/0.7 需至少一个非空分组(跳过排序/收起断言)', false, `categories=${JSON.stringify(ruleKeys)} diag=${diag}`)
|
||||
} else {
|
||||
// Expand both rule categories so their project rows are visible, then
|
||||
// Expand both working categories so their project rows are visible, then
|
||||
// expand every project row (the v0.6 fold/restore assertions need them
|
||||
// expanded before the drag starts).
|
||||
const expandCat = (key) => evaluate(`(() => {
|
||||
const row = document.querySelector('.wgCategoryRow[data-wg-category=${JSON.stringify(key)}]')
|
||||
if (!row) return false
|
||||
if (row.getAttribute('aria-expanded') === 'false') row.click()
|
||||
return true
|
||||
})()`)
|
||||
const expandProject = (key) => evaluate(`(() => {
|
||||
const section = document.querySelector('.wgCategoryRow[data-wg-category=${JSON.stringify(key)}]')?.parentElement
|
||||
if (!section) return false
|
||||
for (const row of section.querySelectorAll('.wgProjectRow')) {
|
||||
if (row.getAttribute('aria-expanded') === 'false') row.click()
|
||||
}
|
||||
return true
|
||||
})()`)
|
||||
await expandCat(cat1)
|
||||
await expandCat(cat2)
|
||||
// NOTE: cat1 (first visible rule category) may have only 1 member left —
|
||||
// the v0.2 flow dragged one project out of it, and the user environment
|
||||
// may already have few members. Assertions must not require >= 2 rows in
|
||||
// cat1; reorder/drag-out tests run against cat2 (验证分组) instead.
|
||||
const rowsVisible = await waitFor(`(() => {
|
||||
const s1 = document.querySelector('.wgCategoryRow[data-wg-category=${JSON.stringify(cat1)}]')?.parentElement
|
||||
const s2 = document.querySelector('.wgCategoryRow[data-wg-category=${JSON.stringify(cat2)}]')?.parentElement
|
||||
return !!s1 && !!s2 && s1.querySelectorAll('.wgProjectRow').length >= 1 && s2.querySelectorAll('.wgProjectRow').length >= 1
|
||||
return !!s1 && !!s2 && s1.querySelectorAll('.wgProjectRow').length >= 2 && s2.querySelectorAll('.wgProjectRow').length >= 1
|
||||
})()`)
|
||||
report('两个规则分类展开且项目行可见', rowsVisible)
|
||||
report('两个分组展开且项目行可见', rowsVisible)
|
||||
await expandProject(cat1)
|
||||
await expandProject(cat2)
|
||||
report('项目行展开(会话可见,供折叠断言用)', await waitFor(`(() => {
|
||||
|
|
@ -256,7 +297,7 @@ async function main() {
|
|||
const s2 = document.querySelector('.wgCategoryRow[data-wg-category=${JSON.stringify(cat2)}]')?.parentElement
|
||||
const rows1 = s1 ? [...s1.querySelectorAll('.wgProjectRow')] : []
|
||||
const rows2 = s2 ? [...s2.querySelectorAll('.wgProjectRow')] : []
|
||||
return rows1.length >= 1 && rows1.every(r => r.getAttribute('aria-expanded') === 'true')
|
||||
return rows1.length >= 2 && rows1.every(r => r.getAttribute('aria-expanded') === 'true')
|
||||
&& rows2.length >= 1 && rows2.every(r => r.getAttribute('aria-expanded') === 'true')
|
||||
})()`))
|
||||
|
||||
|
|
@ -457,21 +498,89 @@ async function main() {
|
|||
window.__wgSource = source // dragend fires on the dragged source
|
||||
return { wsid: source.getAttribute('data-wsid') }
|
||||
})()`)
|
||||
report('拖拽中顶层移出目标可见(空落点区或顶层行)', !!dragOut.wsid && await waitFor(`!!(document.querySelector('.wgTopLevelDrop') || document.querySelector('.wgProjectRow.wgProjectFlat'))`, 5000))
|
||||
report('拖拽中顶层落点可见(整区高亮或空落点区)', !!dragOut.wsid && await waitFor(`!!(document.querySelector('.wgTopLevelArea.wgDropTarget') || document.querySelector('.wgTopLevelDrop'))`, 5000))
|
||||
// Drop on the top-level AREA container (the gaps between rows, not a row
|
||||
// itself) — the whole area must act as the move-out landing spot.
|
||||
const droppedOut = await evaluate(`(() => {
|
||||
report('拖拽中顶层移出目标可见(顶层行或空落点区)', !!dragOut.wsid && await waitFor(`!!(document.querySelector('.wgProjectRow.wgProjectFlat') || document.querySelector('.wgTopLevelEmpty'))`, 5000))
|
||||
// Top-level landing is shown with an insertion LINE now: dragging over the
|
||||
// empty space below the last top-level row puts an insert-after line on
|
||||
// that row (end of the list).
|
||||
const overTopArea = await evaluate(`(() => {
|
||||
const target = document.querySelector('.wgTopLevelArea')
|
||||
if (!target || !window.__wgDt) return false
|
||||
target.dispatchEvent(new DragEvent('dragover', { bubbles: true, cancelable: true, dataTransfer: window.__wgDt }))
|
||||
return true
|
||||
})()`)
|
||||
report('拖拽中顶层落点用插入横线指示(末尾行下方)', overTopArea && await waitFor(`!!(document.querySelector('.wgProjectRow.wgProjectFlat.wgInsertAfter') || document.querySelector('.wgTopLevelEmpty'))`, 5000))
|
||||
// Let the previous inline reorder PUT settle: moveWorkspaceTo rejects
|
||||
// while manualSaving, and the prior PUT's finally clears it a tick after
|
||||
// the ordering assertion above passes.
|
||||
await sleep(1000)
|
||||
const droppedOut = await evaluate(`(() => {
|
||||
const target = document.querySelector('.wgTopLevelArea')
|
||||
if (!target || !window.__wgDt) return false
|
||||
target.dispatchEvent(new DragEvent('drop', { bubbles: true, cancelable: true, dataTransfer: window.__wgDt }))
|
||||
window.__wgSource?.dispatchEvent(new DragEvent('dragend', { bubbles: true }))
|
||||
return true
|
||||
})()`)
|
||||
report('拖到顶层区域空白 = 从分组拖出(assignments=null 落盘)', droppedOut && !!dragOut.wsid && await waitFor(`fetch(${JSON.stringify(BASE)} + '/workspace-groups/config', { cache: 'no-store' }).then(r => r.json()).then(d => d.manual?.assignments?.[${JSON.stringify(dragOut.wsid)}] === null)`))
|
||||
report('拖到顶层区域空白 = 从分组拖出(assignments=null 落盘)', droppedOut && !!dragOut.wsid && await waitFor(`fetch(${JSON.stringify(BASE)} + '/workspace-groups/config', { cache: 'no-store' }).then(r => r.json()).then(d => d.manual?.assignments?.[${JSON.stringify(dragOut.wsid)}] === null)`), `wsid=${dragOut.wsid} droppedOut=${droppedOut}`)
|
||||
report('拖出的项目出现在顶层(无分组行)', !!dragOut.wsid && await waitFor(`!!document.querySelector('.wgProjectRow.wgProjectFlat[data-wsid=${JSON.stringify(dragOut.wsid)}]')`))
|
||||
|
||||
// ---- v0.7:顶层项目之间拖拽排序(横线落点) ----
|
||||
// Drag the first top-level row before the second; the top-level order is
|
||||
// persisted under workspaceOrder[__topLevel__].
|
||||
const topReorder = await evaluate(`(() => {
|
||||
const flat = document.querySelectorAll('.wgProjectRow.wgProjectFlat')
|
||||
if (flat.length < 2) return { error: 'need >=2 top-level rows' }
|
||||
const source = flat[1]
|
||||
const target = flat[0]
|
||||
if (!source || !target) return { error: 'rows missing' }
|
||||
const dt = new DataTransfer()
|
||||
source.dispatchEvent(new DragEvent('dragstart', { bubbles: true, cancelable: true, dataTransfer: dt }))
|
||||
const rect = target.getBoundingClientRect()
|
||||
target.dispatchEvent(new DragEvent('dragover', { bubbles: true, cancelable: true, clientY: rect.top + 1, dataTransfer: dt }))
|
||||
window.__wgDt = dt
|
||||
window.__wgSource = source
|
||||
return { wsid: source.getAttribute('data-wsid'), targetWsid: target.getAttribute('data-wsid') }
|
||||
})()`)
|
||||
report('顶层行拖拽悬停上半 → 上方插入横线', topReorder.wsid && await waitFor(`!!document.querySelector('.wgProjectRow.wgProjectFlat.wgInsertBefore')`, 5000))
|
||||
await evaluate(`(() => {
|
||||
const target = document.querySelector('.wgProjectRow.wgProjectFlat[data-wsid="${topReorder.targetWsid}"]')
|
||||
if (!target || !window.__wgDt) return false
|
||||
target.dispatchEvent(new DragEvent('drop', { bubbles: true, cancelable: true, clientY: target.getBoundingClientRect().top + 1, dataTransfer: window.__wgDt }))
|
||||
window.__wgSource?.dispatchEvent(new DragEvent('dragend', { bubbles: true }))
|
||||
return true
|
||||
})()`)
|
||||
report('顶层项目排序落盘(workspaceOrder[__topLevel__])', topReorder.wsid && await waitFor(`fetch(${JSON.stringify(BASE)} + '/workspace-groups/config', { cache: 'no-store' }).then(r => r.json()).then(d => {
|
||||
const o = d.manual?.workspaceOrder?.['__topLevel__'] ?? []
|
||||
const idx = (id) => o.indexOf(id)
|
||||
return idx(${JSON.stringify(topReorder.wsid)}) !== -1 && idx(${JSON.stringify(topReorder.wsid)}) < idx(${JSON.stringify(topReorder.targetWsid)})
|
||||
})`))
|
||||
|
||||
// ---- v0.7:复现「两者之间落点 → 却插到目标之前」bug(拖到行下半应=after) ----
|
||||
const topAfter = await evaluate(`(() => {
|
||||
const flat = document.querySelectorAll('.wgProjectRow.wgProjectFlat')
|
||||
if (flat.length < 2) return { error: 'need >=2 top-level rows' }
|
||||
const source = flat[0]
|
||||
const target = flat[1]
|
||||
const dt = new DataTransfer()
|
||||
source.dispatchEvent(new DragEvent('dragstart', { bubbles: true, cancelable: true, dataTransfer: dt }))
|
||||
const rect = target.getBoundingClientRect()
|
||||
target.dispatchEvent(new DragEvent('dragover', { bubbles: true, cancelable: true, clientY: rect.top + rect.height - 1, dataTransfer: dt }))
|
||||
window.__wgDt = dt
|
||||
window.__wgSource = source
|
||||
return { wsid: source.getAttribute('data-wsid'), targetWsid: target.getAttribute('data-wsid') }
|
||||
})()`)
|
||||
report('拖到顶层行下半 → 下方插入横线(after 落点提示)', topAfter.wsid && await waitFor(`!!document.querySelector('.wgProjectRow.wgProjectFlat.wgInsertAfter')`, 5000))
|
||||
await evaluate(`(() => {
|
||||
const target = document.querySelector('.wgProjectRow.wgProjectFlat[data-wsid="${topAfter.targetWsid}"]')
|
||||
if (!target || !window.__wgDt) return false
|
||||
target.dispatchEvent(new DragEvent('drop', { bubbles: true, cancelable: true, clientY: target.getBoundingClientRect().top + target.getBoundingClientRect().height - 1, dataTransfer: window.__wgDt }))
|
||||
window.__wgSource?.dispatchEvent(new DragEvent('dragend', { bubbles: true }))
|
||||
return true
|
||||
})()`)
|
||||
report('拖到目标行下半 → 应插到目标之后(after)', topAfter.wsid && await waitFor(`fetch(${JSON.stringify(BASE)} + '/workspace-groups/config', { cache: 'no-store' }).then(r => r.json()).then(d => {
|
||||
const o = d.manual?.workspaceOrder?.['__topLevel__'] ?? []
|
||||
return o.indexOf(${JSON.stringify(topAfter.wsid)}) > o.indexOf(${JSON.stringify(topAfter.targetWsid)})
|
||||
})`))
|
||||
|
||||
// ---- v0.4.1b:分组内项目行菜单提供「移出分组」 ----
|
||||
// cat2 还剩 1 个项目(v0.2 拖入 + 排序前置种子 - 拖出 1);移出后
|
||||
// 手动分组变空(仍渲染),cat1 的成员留给删除流程。
|
||||
|
|
@ -493,14 +602,14 @@ async function main() {
|
|||
})()`)
|
||||
await sleep(1000)
|
||||
|
||||
// ---- v0.3:规则分类行出现菜单 → 重命名 → 删除回顶层 --------------------
|
||||
// ---- v0.3:分组行出现菜单 → 重命名 → 删除回顶层 --------------------
|
||||
const hasMenu = await evaluate(`(() => {
|
||||
const row = document.querySelector('.wgCategoryRow[data-wg-category=${JSON.stringify(cat1)}]')
|
||||
if (!row) return false
|
||||
row.querySelector('button[aria-label*="重命名分组"]')?.click()
|
||||
return !!row.querySelector('button[aria-label*="重命名分组"]')
|
||||
})()`)
|
||||
report('规则分类行出现「⋯」菜单(重命名/删除入口)', hasMenu)
|
||||
report('分组行出现「⋯」菜单(重命名/删除入口)', hasMenu)
|
||||
const renamed = `${cat1}·改`
|
||||
const renameFlow = await evaluate(`(() => {
|
||||
const item = [...document.querySelectorAll('button')].find(b => b.textContent.trim() === '重命名分组')
|
||||
|
|
@ -519,9 +628,11 @@ async function main() {
|
|||
const btn = [...document.querySelectorAll('button')].find(b => b.textContent.trim() === '重命名' && !b.textContent.includes('分组'))
|
||||
if (btn) btn.click()
|
||||
})()`)
|
||||
report('重命名规则分类后以新名渲染', await waitFor(`!!document.querySelector('.wgCategoryRow[data-wg-category=${JSON.stringify(renamed)}]')`))
|
||||
report('renamed 落盘(原规则名 → 新名)', await fetch(`${BASE}/workspace-groups/config`, { cache: 'no-store' })
|
||||
.then(r => r.json()).then(d => d.manual?.renamed?.[cat1] === renamed))
|
||||
report('重命名分组后以新名渲染', await waitFor(`!!document.querySelector('.wgCategoryRow[data-wg-category=${JSON.stringify(renamed)}]')`))
|
||||
report('重命名落盘(规则 renamed / 手动 categories)', await fetch(`${BASE}/workspace-groups/config`, { cache: 'no-store' })
|
||||
.then(r => r.json()).then(d => cat1IsRule
|
||||
? d.manual?.renamed?.[cat1] === renamed
|
||||
: (d.manual?.categories ?? []).includes(renamed)))
|
||||
|
||||
// Delete the renamed rule group: its projects must go top-level (null).
|
||||
// Capture the group's members first (expand the group if collapsed),
|
||||
|
|
@ -565,10 +676,12 @@ async function main() {
|
|||
})()`), `members=${JSON.stringify(memberIds)}`)
|
||||
const deleted = await fetch(`${BASE}/workspace-groups/config`, { cache: 'no-store' }).then(r => r.json())
|
||||
const assignments = deleted.manual?.assignments ?? {}
|
||||
report('删除后 hidden 落盘且引用清理', deleted.manual?.hidden?.includes(cat1) === true
|
||||
&& !Object.values(assignments).includes(renamed)
|
||||
report('删除后落盘清理(规则 hidden / 手动 categories)', !Object.values(assignments).includes(renamed)
|
||||
&& !Object.keys(deleted.manual?.workspaceOrder ?? {}).includes(renamed)
|
||||
&& !(deleted.manual?.categoryOrder ?? []).includes(renamed))
|
||||
&& !(deleted.manual?.categoryOrder ?? []).includes(renamed)
|
||||
&& (cat1IsRule
|
||||
? deleted.manual?.hidden?.includes(cat1) === true
|
||||
: !(deleted.manual?.categories ?? []).includes(cat1)))
|
||||
// No 未分类 bucket exists anywhere in the tree.
|
||||
report('树中不存在「未分类」桶', await waitFor(`(() => {
|
||||
const rows = [...document.querySelectorAll('.wgCategoryRow')]
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import {
|
|||
resolveCategory,
|
||||
takenCategoryNames,
|
||||
} from '../core/matcher.ts'
|
||||
import { UNCATEGORIZED_LABEL, type GroupsConfig, type ManualGroups } from '../core/types.ts'
|
||||
import { TOP_LEVEL_ORDER_KEY, UNCATEGORIZED_LABEL, type GroupsConfig, type ManualGroups } from '../core/types.ts'
|
||||
import type { GroupsBrowserProps } from './contract.ts'
|
||||
import { deriveGroups, deriveSearchGroups, deriveSearchMatches, deriveTopLevel, UNCATEGORIZED_KEY, type CategoryNode, type WorkspaceGroupNode } from './tree.ts'
|
||||
import { CategoryRow, DND_CATEGORY_TYPE, DND_WORKSPACE_TYPE, hasPluginDragType, SessionRow, WorkspaceRow } from './rows.tsx'
|
||||
|
|
@ -300,14 +300,14 @@ export function GroupsBrowser({
|
|||
}, manual),
|
||||
[list, workspaces, archivedSessionIds, config, manual, expandedCategories, expandedWorkspaces],
|
||||
)
|
||||
// While dragging a project, an empty top-level area must still be a visible
|
||||
// drop target — otherwise a project can never be dragged OUT of a group when
|
||||
// every project is currently grouped.
|
||||
// While dragging a project, an empty top-level area must still show a landing
|
||||
// line — otherwise a project can never be dragged OUT of a group when every
|
||||
// project is currently grouped.
|
||||
const topLevelDropActive = dragging === 'workspace' && topLevel.length === 0
|
||||
// With top-level rows present, the whole top-level area lights up as the
|
||||
// move-out drop target while dragging a project (rows AND the gaps between
|
||||
// them), so the user always sees a landing spot when dragging out.
|
||||
const topLevelAreaActive = dragging === 'workspace' && topLevel.length > 0
|
||||
// The top-level area is the move-out landing spot: rows reorder with an
|
||||
// insertion line (before/after), and the blank space below the last row
|
||||
// appends to the end of the list. No whole-area highlight box.
|
||||
const topLevelRef: DropRowRef = { kind: 'topLevel', key: UNCATEGORIZED_KEY }
|
||||
|
||||
// Add workspace flow: self-contained (no directory-flow hole dependency).
|
||||
const [adding, setAdding] = useState(false)
|
||||
|
|
@ -554,11 +554,21 @@ export function GroupsBrowser({
|
|||
try {
|
||||
let next: NormalizedManual
|
||||
if (categoryKey === UNCATEGORIZED_KEY) {
|
||||
// Drop on 未分类: force uncategorized and drop from every order list.
|
||||
// Move to the TOP LEVEL: force ungrouped (null) and drop from every
|
||||
// group's order list, while recording the position inside the ordered
|
||||
// top-level list (`workspaceOrder[TOP_LEVEL_ORDER_KEY]`).
|
||||
const assignments = { ...manual.assignments, [workspaceId]: null }
|
||||
const workspaceOrder = Object.fromEntries(
|
||||
Object.entries(manual.workspaceOrder).map(([key, ids]) => [key, ids.filter(id => id !== workspaceId)]),
|
||||
)
|
||||
const workspaceOrder: Record<string, string[]> = {}
|
||||
for (const [key, ids] of Object.entries(manual.workspaceOrder)) {
|
||||
if (key === TOP_LEVEL_ORDER_KEY) continue
|
||||
workspaceOrder[key] = ids.filter(id => id !== workspaceId)
|
||||
}
|
||||
const topLevelIds = workspaces
|
||||
.filter(w => w.workspaceId !== workspaceId && resolveCategory(config, manual, w.workspaceId, w.path, w.title) === undefined)
|
||||
.map(w => w.workspaceId as string)
|
||||
workspaceOrder[TOP_LEVEL_ORDER_KEY] = afterWorkspaceId !== undefined
|
||||
? moveAfter(topLevelIds, workspaceId, afterWorkspaceId)
|
||||
: moveBefore(topLevelIds, workspaceId, beforeWorkspaceId)
|
||||
next = { ...manual, assignments, workspaceOrder }
|
||||
} else {
|
||||
const currentKey = resolveCategory(config, manual, workspaceId, workspace.path, workspace.title)
|
||||
|
|
@ -634,9 +644,14 @@ export function GroupsBrowser({
|
|||
const workspaceId = event.dataTransfer.getData(DND_WORKSPACE_TYPE) || event.dataTransfer.getData('text/plain')
|
||||
if (workspaceId === '') return
|
||||
if (row.kind === 'topLevel') {
|
||||
// Dropping on the top-level area / a top-level row = move OUT of any
|
||||
// group (forced top-level, rules ignored).
|
||||
void moveWorkspaceTo(workspaceId, UNCATEGORIZED_KEY)
|
||||
// Top-level row / top-level blank drop = move OUT of any group (forced
|
||||
// top-level, rules ignored) and set the position inside the ordered
|
||||
// top-level list. A row drop re-derives before/after from the drop
|
||||
// position; a bare area drop (key = UNCATEGORIZED_KEY) appends to the end.
|
||||
const rect = (event.currentTarget as HTMLElement).getBoundingClientRect()
|
||||
const before = event.clientY < rect.top + rect.height / 2
|
||||
const specificKey = row.key === UNCATEGORIZED_KEY ? undefined : row.key
|
||||
void moveWorkspaceTo(workspaceId, UNCATEGORIZED_KEY, before ? specificKey : undefined, !before ? specificKey : undefined)
|
||||
return
|
||||
}
|
||||
// Project move/reorder: a line on a project row = reorder before/after it;
|
||||
|
|
@ -653,19 +668,16 @@ export function GroupsBrowser({
|
|||
const draggingCategory = Array.from(event.dataTransfer.types as Iterable<string>).includes(DND_CATEGORY_TYPE)
|
||||
if (draggingCategory && row.kind !== 'category') return // group drags target category rows only
|
||||
event.preventDefault()
|
||||
// Keep a row's dragover from bubbling to the enclosing top-level area
|
||||
// (which would interpret it as the end-of-list landing).
|
||||
event.stopPropagation()
|
||||
event.dataTransfer.dropEffect = 'move'
|
||||
if (row.kind === 'topLevel') {
|
||||
// Dropping a project on the top-level area: whole-area highlight, drop
|
||||
// moves the project out of its group.
|
||||
setDragIndicator(prev =>
|
||||
prev?.mode === 'into' && prev.categoryKey === UNCATEGORIZED_KEY ? prev : { mode: 'into', categoryKey: UNCATEGORIZED_KEY })
|
||||
return
|
||||
}
|
||||
const rect = (event.currentTarget as HTMLElement).getBoundingClientRect()
|
||||
const before = event.clientY < rect.top + rect.height / 2
|
||||
if (draggingCategory || row.kind === 'workspace') {
|
||||
// Group reorder (line on a category row) or project reorder inside a
|
||||
// group (line on a project row).
|
||||
if (draggingCategory || row.kind === 'workspace' || row.kind === 'topLevel') {
|
||||
// Group reorder (line on a category row), project reorder inside a
|
||||
// group (line on a project row), or top-level reorder (line on a
|
||||
// top-level project row).
|
||||
setDragIndicator(prev =>
|
||||
prev?.mode === 'line' && prev.row.kind === row.kind && prev.row.key === row.key && prev.before === before
|
||||
? prev
|
||||
|
|
@ -682,6 +694,32 @@ export function GroupsBrowser({
|
|||
setDragIndicator(null)
|
||||
}
|
||||
|
||||
/**
|
||||
* Drag over the TOP-LEVEL AREA's blank space (not on a row — rows stop
|
||||
* propagation). An insertion line shows the landing spot: empty top level →
|
||||
* a standalone line under the last group; non-empty → a line below the last
|
||||
* top-level row (end of the list).
|
||||
*/
|
||||
const onDragOverTopLevelArea = (event: DragEvent): void => {
|
||||
if (!hasPluginDragType(event.dataTransfer.types)) return
|
||||
const draggingCategory = Array.from(event.dataTransfer.types as Iterable<string>).includes(DND_CATEGORY_TYPE)
|
||||
if (draggingCategory) return // group drags never target the top-level area
|
||||
event.preventDefault()
|
||||
event.dataTransfer.dropEffect = 'move'
|
||||
const last = topLevel.length > 0 ? topLevel[topLevel.length - 1] : undefined
|
||||
if (last !== undefined) {
|
||||
setDragIndicator(prev =>
|
||||
prev?.mode === 'line' && prev.row.kind === 'topLevel' && prev.row.key === last.workspaceId && prev.before === false
|
||||
? prev
|
||||
: { mode: 'line', row: { kind: 'topLevel', key: last.workspaceId }, before: false })
|
||||
} else {
|
||||
setDragIndicator(prev =>
|
||||
prev?.mode === 'line' && prev.row.kind === 'topLevel' && prev.row.key === topLevelRef.key && prev.before === false
|
||||
? prev
|
||||
: { mode: 'line', row: topLevelRef, before: false })
|
||||
}
|
||||
}
|
||||
|
||||
// While dragging a project, only PROJECT rows fold — every expanded
|
||||
// workspace collapses (inside groups AND top-level); group rows keep their
|
||||
// expansion so the user still sees where groups are. dragend restores the
|
||||
|
|
@ -882,18 +920,20 @@ export function GroupsBrowser({
|
|||
/>
|
||||
))}
|
||||
{/* Top-level (ungrouped) workspaces, rendered after the group
|
||||
folders. While dragging a project, an empty top-level area
|
||||
shows a drop target so projects can always be dragged OUT. */}
|
||||
folders. While dragging a project the whole area is the
|
||||
move-out landing spot (a line shows the insert position;
|
||||
an empty top level shows a line under the last group). */}
|
||||
{(topLevel.length > 0 || topLevelDropActive) && (
|
||||
<TopLevelSection
|
||||
topLevel={topLevel}
|
||||
current={current}
|
||||
now={now}
|
||||
t={t}
|
||||
showDropTarget={topLevelDropActive}
|
||||
areaActive={topLevelAreaActive}
|
||||
dropActive={dragIndicator?.mode === 'into' && dragIndicator.categoryKey === UNCATEGORIZED_KEY}
|
||||
dragging={dragging === 'workspace'}
|
||||
dragIndicator={dragIndicator}
|
||||
topLevelRef={topLevelRef}
|
||||
onDragOverRow={onDragOverRow}
|
||||
onDragOverTopLevelArea={onDragOverTopLevelArea}
|
||||
onDragLeaveRow={onDragLeaveRow}
|
||||
onDropRow={onDropRow}
|
||||
onDragStartWorkspace={onDragStartWorkspace}
|
||||
|
|
@ -1150,22 +1190,24 @@ function CategorySection({ category, current, now, t, dragIndicator, onDragOverR
|
|||
|
||||
/**
|
||||
* Top-level (ungrouped) workspace rows rendered after the group folders. While
|
||||
* a project drag is in progress the ENTIRE top-level area is a move-out drop
|
||||
* target: empty → a labelled placeholder (.wgTopLevelDrop); non-empty → the
|
||||
* area container lights up (.wgDropTarget) and every row + the gaps between
|
||||
* them accept the drop (rows keep their own handlers; the area container
|
||||
* catches drops on the gaps).
|
||||
* a project drag is in progress the WHOLE top-level area is the move-out
|
||||
* landing spot, shown with an insertion LINE (not a highlight box):
|
||||
* - a top-level row reorders before/after it (line above/below, like a group);
|
||||
* - the blank space below the last row appends to the end (line below the
|
||||
* last row);
|
||||
* - an empty top level shows a standalone line under the last group folder.
|
||||
*/
|
||||
function TopLevelSection({ topLevel, current, now, t, showDropTarget, areaActive, dropActive, onDragOverRow, onDragLeaveRow, onDropRow, onDragStartWorkspace, onToggleWorkspace, onNewSession, onOpen, onRenameRequest, onDeleteRequest, onSessionRename, onSessionArchive, onFork }: {
|
||||
function TopLevelSection({ topLevel, current, now, t, dragging, dragIndicator, topLevelRef, onDragOverRow, onDragOverTopLevelArea, onDragLeaveRow, onDropRow, onDragStartWorkspace, onToggleWorkspace, onNewSession, onOpen, onRenameRequest, onDeleteRequest, onSessionRename, onSessionArchive, onFork }: {
|
||||
topLevel: readonly WorkspaceGroupNode[]
|
||||
current: SessionId | undefined
|
||||
now: number
|
||||
t: GroupsBrowserProps['t']
|
||||
showDropTarget: boolean
|
||||
/** Whole-area highlight while dragging a project (top-level rows present). */
|
||||
areaActive: boolean
|
||||
dropActive: boolean
|
||||
/** A project drag is in progress (drives the empty-top-level landing line). */
|
||||
dragging: boolean
|
||||
dragIndicator: DragIndicator
|
||||
topLevelRef: DropRowRef
|
||||
onDragOverRow: (row: DropRowRef) => (event: DragEvent) => void
|
||||
onDragOverTopLevelArea: (event: DragEvent) => void
|
||||
onDragLeaveRow: (event: DragEvent) => void
|
||||
onDropRow: (categoryKey: string, row: DropRowRef) => (event: DragEvent) => void
|
||||
onDragStartWorkspace: (workspaceId: WorkspaceId) => () => void
|
||||
|
|
@ -1178,25 +1220,25 @@ function TopLevelSection({ topLevel, current, now, t, showDropTarget, areaActive
|
|||
onSessionArchive: (sessionId: SessionId) => void
|
||||
onFork: (sessionId: SessionId) => void
|
||||
}) {
|
||||
const topRef: DropRowRef = { kind: 'topLevel', key: UNCATEGORIZED_KEY }
|
||||
const emptyLineActive = dragIndicator?.mode === 'line' && dragIndicator.row.kind === 'topLevel' && dragIndicator.row.key === topLevelRef.key
|
||||
return (
|
||||
<div
|
||||
role="group"
|
||||
aria-label={t('section.topLevel')}
|
||||
className={areaActive ? 'wgTopLevelArea wgDropTarget' : 'wgTopLevelArea'}
|
||||
onDragOver={onDragOverRow(topRef)}
|
||||
className="wgTopLevelArea"
|
||||
onDragOver={onDragOverTopLevelArea}
|
||||
onDragLeave={onDragLeaveRow}
|
||||
onDrop={onDropRow(UNCATEGORIZED_KEY, topRef)}
|
||||
onDrop={onDropRow(UNCATEGORIZED_KEY, topLevelRef)}
|
||||
>
|
||||
{showDropTarget && (
|
||||
{topLevel.length === 0 && dragging && (
|
||||
<div
|
||||
className={`wgTopLevelDrop${dropActive ? ' wgDropTarget' : ''}`}
|
||||
className={`wgTopLevelEmpty${emptyLineActive ? ' wgTopLevelEmptyActive' : ''}`}
|
||||
role="treeitem"
|
||||
onDragOver={onDragOverRow(topRef)}
|
||||
onDragOver={onDragOverRow(topLevelRef)}
|
||||
onDragLeave={onDragLeaveRow}
|
||||
onDrop={onDropRow(UNCATEGORIZED_KEY, topRef)}
|
||||
onDrop={onDropRow(UNCATEGORIZED_KEY, topLevelRef)}
|
||||
>
|
||||
{t('group.dropTopLevel')}
|
||||
<span className="wgTopLevelEmptyLine" />
|
||||
</div>
|
||||
)}
|
||||
{topLevel.map((workspace) => (
|
||||
|
|
@ -1209,10 +1251,12 @@ function TopLevelSection({ topLevel, current, now, t, showDropTarget, areaActive
|
|||
onNewSession={() => { onNewSession(workspace.workspaceId) }}
|
||||
onRename={() => { onRenameRequest(workspace.workspaceId, workspace.label) }}
|
||||
onDelete={() => { onDeleteRequest(workspace.workspaceId, workspace.label) }}
|
||||
dropActive={dropActive}
|
||||
onRowDragOver={onDragOverRow(topRef)}
|
||||
{...(dragIndicator?.mode === 'line' && dragIndicator.row.kind === 'topLevel' && dragIndicator.row.key === workspace.workspaceId
|
||||
? { insertLine: dragIndicator.before ? 'before' : 'after' }
|
||||
: {})}
|
||||
onRowDragOver={onDragOverRow({ kind: 'topLevel', key: workspace.workspaceId })}
|
||||
onRowDragLeave={onDragLeaveRow}
|
||||
onRowDrop={onDropRow(UNCATEGORIZED_KEY, topRef)}
|
||||
onRowDrop={onDropRow(UNCATEGORIZED_KEY, { kind: 'topLevel', key: workspace.workspaceId })}
|
||||
onDragStartExtra={onDragStartWorkspace(workspace.workspaceId)}
|
||||
/>
|
||||
{workspace.expanded && workspace.sessions.map((session) => (
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ export type WorkspaceGroupsKey =
|
|||
| 'group.deleteCancel'
|
||||
| 'group.nameDuplicate'
|
||||
| 'group.nameReserved'
|
||||
| 'group.dropTopLevel'
|
||||
| 'section.topLevel'
|
||||
| 'manual.saveError'
|
||||
| 'session.new'
|
||||
|
|
@ -114,7 +113,6 @@ export const zh: WorkspaceGroupsDict = {
|
|||
'group.deleteCancel': '取消删除',
|
||||
'group.nameDuplicate': '已存在同名分组',
|
||||
'group.nameReserved': '该名称不可用',
|
||||
'group.dropTopLevel': '松开以移出分组到顶层',
|
||||
'section.topLevel': '顶层项目',
|
||||
'manual.saveError': '分组变更保存失败',
|
||||
'session.new': '新建会话',
|
||||
|
|
@ -181,7 +179,6 @@ export const en: WorkspaceGroupsDict = {
|
|||
'group.deleteCancel': 'Cancel delete',
|
||||
'group.nameDuplicate': 'A group with this name already exists',
|
||||
'group.nameReserved': 'This name is not available',
|
||||
'group.dropTopLevel': 'Release to move out of the group',
|
||||
'section.topLevel': 'Top-level projects',
|
||||
'manual.saveError': 'Could not save group changes',
|
||||
'session.new': 'New Session',
|
||||
|
|
|
|||
|
|
@ -213,26 +213,34 @@
|
|||
padding-left: 4px;
|
||||
}
|
||||
|
||||
/* Drop target shown while dragging a project and the top-level area is
|
||||
empty — the only way to drag a project out of a group. */
|
||||
.wgTopLevelDrop {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 30px;
|
||||
margin-top: 4px;
|
||||
border-radius: 6px;
|
||||
font-size: 11px;
|
||||
color: var(--dsw-fg-3, rgba(127, 127, 127, 0.8));
|
||||
border: 1px dashed var(--dsw-border, rgba(127, 127, 127, 0.3));
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
/* Top-level area container (rows present). While dragging a project it gains
|
||||
.wgDropTarget so the whole area — rows and the gaps between them — reads as
|
||||
the move-out landing spot. */
|
||||
/* Top-level (ungrouped) rows area. The blank space below the last row accepts
|
||||
a drop (appends to the end of the top-level list). */
|
||||
.wgTopLevelArea {
|
||||
margin-top: 2px;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
/* Empty top level while dragging a project: a standalone insertion line under
|
||||
the last group folder — the only way to move a project OUT of a group when
|
||||
no top-level rows exist yet. */
|
||||
.wgTopLevelEmpty {
|
||||
position: relative;
|
||||
height: 14px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.wgTopLevelEmptyLine {
|
||||
position: absolute;
|
||||
left: 2px;
|
||||
right: 2px;
|
||||
top: 50%;
|
||||
height: 2px;
|
||||
border-radius: 1px;
|
||||
background: var(--dsw-accent, #4a90d9);
|
||||
box-shadow: 0 0 0 1px color-mix(in srgb, var(--dsw-accent, #4a90d9) 25%, transparent);
|
||||
pointer-events: none;
|
||||
}
|
||||
.wgTopLevelEmptyActive {
|
||||
background: var(--dsw-bg-selected, rgba(74, 144, 217, 0.18));
|
||||
}
|
||||
|
||||
.wgProjectRow:hover {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import {
|
|||
type WorkspaceView,
|
||||
} from '@deepseek-ai/dsh-client-runtime/client'
|
||||
import { effectiveCategories, orderedWorkspaceIds, resolveCategory } from '../core/matcher.ts'
|
||||
import { UNCATEGORIZED_LABEL, type GroupsConfig, type ManualGroups } from '../core/types.ts'
|
||||
import { TOP_LEVEL_ORDER_KEY, UNCATEGORIZED_LABEL, type GroupsConfig, type ManualGroups } from '../core/types.ts'
|
||||
|
||||
/** One top-level session row inside a workspace folder. */
|
||||
export interface SessionNode {
|
||||
|
|
@ -218,7 +218,8 @@ export function deriveGroups(
|
|||
* Top-level (ungrouped) workspace rows: workspaces resolving to no category
|
||||
* (no manual override and no matching rule, or a forced `null` override).
|
||||
* Rendered after the group folders as plain project rows (not inside any
|
||||
* folder), in host registration order.
|
||||
* folder), in manual top-level order (`workspaceOrder[TOP_LEVEL_ORDER_KEY]`),
|
||||
* falling back to host registration order.
|
||||
*/
|
||||
export function deriveTopLevel(
|
||||
list: SessionListState,
|
||||
|
|
@ -235,12 +236,17 @@ export function deriveTopLevel(
|
|||
? undefined
|
||||
: workspaces.find(w => w.sessionIds.includes(list.current as SessionId))?.workspaceId
|
||||
|
||||
const topLevelIds = workspaces
|
||||
.filter(w => resolveCategory(config, manual, w.workspaceId, w.path, w.title) === undefined)
|
||||
.map(w => w.workspaceId as string)
|
||||
const ordered = orderedWorkspaceIds(manual, TOP_LEVEL_ORDER_KEY, topLevelIds)
|
||||
|
||||
const nodes: WorkspaceGroupNode[] = []
|
||||
for (const workspace of workspaces) {
|
||||
const key = resolveCategory(config, manual, workspace.workspaceId, workspace.path, workspace.title)
|
||||
if (key !== undefined) continue // grouped — rendered inside deriveGroups
|
||||
for (const workspaceId of ordered) {
|
||||
const workspace = workspaces.find(w => w.workspaceId === workspaceId)
|
||||
if (workspace === undefined) continue
|
||||
const sessions = workspaceSessions(list, workspace, archived, descendants)
|
||||
const wsExpanded = expandedWorkspaces.has(workspace.workspaceId as string)
|
||||
const wsExpanded = expandedWorkspaces.has(workspaceId)
|
||||
nodes.push({
|
||||
workspaceId: workspace.workspaceId,
|
||||
path: workspace.path,
|
||||
|
|
|
|||
|
|
@ -94,6 +94,15 @@ export interface ManualGroups {
|
|||
*/
|
||||
export const UNCATEGORIZED_LABEL = '未分类'
|
||||
|
||||
/**
|
||||
* Reserved key under `workspaceOrder` holding the manual order of TOP-LEVEL
|
||||
* (ungrouped) project rows. Distinct from any real group display name (a group
|
||||
* may not be named this), so it can never collide; the top-level list's order
|
||||
* is preserved exactly like a group's, and top-level rows can be reordered by
|
||||
* dragging.
|
||||
*/
|
||||
export const TOP_LEVEL_ORDER_KEY = '__topLevel__'
|
||||
|
||||
/** Normalize a path for prefix matching: trailing slashes stripped. */
|
||||
export function normalizePath(path: string): string {
|
||||
return path.replace(/[/\\]+$/, '')
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import { mkdir, open, readFile, rename, unlink } from 'node:fs/promises'
|
|||
import { dirname, resolve } from 'node:path'
|
||||
import { homedir } from 'node:os'
|
||||
import { ruleDisplayName } from './core/matcher.ts'
|
||||
import { UNCATEGORIZED_LABEL, type ManualGroups } from './core/types.ts'
|
||||
import { TOP_LEVEL_ORDER_KEY, UNCATEGORIZED_LABEL, type ManualGroups } from './core/types.ts'
|
||||
|
||||
/** Default overlay location: `$DSH_HOME/workspace-groups.manual.json`. */
|
||||
export function defaultManualPath(): string {
|
||||
|
|
@ -170,6 +170,8 @@ export function validateManualGroups(manual: ManualGroups, ruleCategoryNames: re
|
|||
}
|
||||
}
|
||||
for (const key of Object.keys(manual.workspaceOrder ?? {})) {
|
||||
// The top-level order key is a reserved, non-category list.
|
||||
if (key === TOP_LEVEL_ORDER_KEY) continue
|
||||
if (!allowed.has(key) || key === UNCATEGORIZED_LABEL) {
|
||||
throw new Error(`workspace-groups.manual.json: workspaceOrder references unknown category "${key}"`)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,6 +117,11 @@ describe('validateManualGroups v2 (write boundary)', () => {
|
|||
const manual2: ManualGroups = { categories: [], assignments: {}, workspaceOrder: { '幽灵': [] } }
|
||||
expect(() => validateManualGroups(manual2, RULE_NAMES)).toThrow(/workspaceOrder/)
|
||||
})
|
||||
|
||||
it('accepts the reserved top-level order key in workspaceOrder', () => {
|
||||
const manual: ManualGroups = { categories: [], assignments: {}, workspaceOrder: { __topLevel__: ['ws-1', 'ws-2'] } }
|
||||
expect(() => validateManualGroups(manual, RULE_NAMES)).not.toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe('validateManualGroups (write boundary)', () => {
|
||||
|
|
|
|||
|
|
@ -180,4 +180,13 @@ describe('deriveTopLevel', () => {
|
|||
expect(collapsed[0]?.expanded).toBe(false)
|
||||
expect(collapsed[0]?.sessions).toEqual([])
|
||||
})
|
||||
|
||||
it('top-level rows honor the manual order (workspaceOrder[__topLevel__])', () => {
|
||||
const manual: ManualGroups = {
|
||||
categories: [], assignments: { 'ws-a': null, 'ws-b': null, 'ws-c': null },
|
||||
workspaceOrder: { __topLevel__: ['ws-c', 'ws-a', 'ws-b'] },
|
||||
}
|
||||
const top = deriveTopLevel(listState(ws), ws, [], CONFIG, VIEW, manual)
|
||||
expect(top.map(w => w.workspaceId)).toEqual(['ws-c', 'ws-a', 'ws-b'])
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue