dsh-message-rewind 1.1.3 → 1.2.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.
- package/README.en.md +31 -13
- package/README.md +30 -12
- package/client.js +266 -130
- package/client.test.js +163 -62
- package/files.test.js +23 -2
- package/package.json +1 -1
- package/rewind.js +15 -2
- package/rewind.test.js +13 -0
package/README.en.md
CHANGED
|
@@ -16,7 +16,7 @@ Edit and delete your own messages in [DeepSeek Harness](https://github.com/deeps
|
|
|
16
16
|
| --- | --- |
|
|
17
17
|
| Change a sent message | Click the pencil under your bubble, edit the text, then click **Save and resend**. Everything after that message is truncated and the conversation restarts from your edited text. |
|
|
18
18
|
| Drop an out-of-line message | Click the trash icon and confirm. That message and every following turn are deleted. |
|
|
19
|
-
| Restore files too | When deleting or editing, if that turn recorded file changes, the
|
|
19
|
+
| Restore files too | When deleting or editing, if that turn recorded file changes, the popover lets you choose **messages only** or **messages and files**. |
|
|
20
20
|
| Stay out of a running task | The action is refused while a turn is still running, so it never races the agent's writes. |
|
|
21
21
|
|
|
22
22
|
Only messages you sent have these buttons. The **Copy** button is still there, in the same position.
|
|
@@ -25,15 +25,21 @@ Only messages you sent have these buttons. The **Copy** button is still there, i
|
|
|
25
25
|
|
|
26
26
|
Your own messages get **edit / delete / copy** buttons under the bubble:
|
|
27
27
|
|
|
28
|
-
<img src="img/message-actions.png" alt="Edit, delete and copy buttons under a user message" width="760">
|
|
28
|
+
<img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/message-actions.png" alt="Edit, delete and copy buttons under a user message" width="760">
|
|
29
29
|
|
|
30
|
-
The
|
|
30
|
+
The popover opens right under the button you clicked and points at it with a small arrow; click outside or press Esc to dismiss it. The editor reads the file changes recorded after that message as soon as it opens — collapsed into one **N file changes recorded** line unless you expand it — and a two-way switch decides whether files are restored too:
|
|
31
31
|
|
|
32
|
-
| Edit
|
|
32
|
+
| Edit popover | Delete confirmation |
|
|
33
33
|
| :---: | :---: |
|
|
34
|
-
| <img src="img/edit-dialog.png" alt="Edit
|
|
34
|
+
| <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/edit-dialog.png" alt="Edit popover: file changes collapse to one line, rollback scope is a two-way switch" width="360"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/delete-dialog.png" alt="Delete confirmation: a one-line confirm when no files changed" width="360"> |
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
The popover follows its button: it flips above when there is no room below, narrows to the screen width on small viewports, and keeps the same layering in the light theme:
|
|
37
|
+
|
|
38
|
+
| Flips above near the bottom | Narrow screen (390px) | Light theme |
|
|
39
|
+
| :---: | :---: | :---: |
|
|
40
|
+
| <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/popover-flip.png" alt="Popover flipped above the button, arrow pointing down at it" width="240"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/popover-narrow.png" alt="Popover narrowed to a 390px viewport" width="240"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/popover-light.png" alt="Delete popover in the light theme" width="240"> |
|
|
41
|
+
|
|
42
|
+
Snapshot and Git-worktree limits are shown in the popover itself, not after a failed operation.
|
|
37
43
|
|
|
38
44
|
## Install
|
|
39
45
|
|
|
@@ -41,12 +47,24 @@ Requires DSH 0.2.1-rc.3 or newer (0.2.x) and Node.js ≥ 20; verified on 0.2.1-r
|
|
|
41
47
|
|
|
42
48
|
### From npm (recommended)
|
|
43
49
|
|
|
50
|
+
Published on npm as [dsh-message-rewind](https://www.npmjs.com/package/dsh-message-rewind), and listed in the [plugin market](https://awesome-dsh-plugin.com/p/xCube007/dsh-message-rewind/).
|
|
51
|
+
|
|
52
|
+
One command:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
dsh plugin --profile web add dsh-message-rewind
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Or install from inside DSH: **Settings → Plugins → search `dsh-message-rewind`**.
|
|
59
|
+
|
|
60
|
+
If you prefer editing the profile yourself, the manual route is the same three steps:
|
|
61
|
+
|
|
44
62
|
1. Add the dependency to your profile's `package.json` (`~/.dsh/profiles/<profile>/package.json`):
|
|
45
63
|
|
|
46
64
|
```json
|
|
47
65
|
{
|
|
48
66
|
"dependencies": {
|
|
49
|
-
"dsh-message-rewind": "^1.
|
|
67
|
+
"dsh-message-rewind": "^1.2.0"
|
|
50
68
|
}
|
|
51
69
|
}
|
|
52
70
|
```
|
|
@@ -79,14 +97,14 @@ The DSH startup log lists `message-rewind` as active. Refresh the page and your
|
|
|
79
97
|
|
|
80
98
|
## Usage
|
|
81
99
|
|
|
82
|
-
1. Click the pencil →
|
|
100
|
+
1. Click the pencil → a popover opens under the button; change the text and click **Save and resend**.
|
|
83
101
|
2. Click the trash icon → click **Delete** to remove that message and every following turn.
|
|
84
|
-
3. The
|
|
85
|
-
- **
|
|
86
|
-
- **
|
|
102
|
+
3. The popover reads the file changes recorded after that message as soon as it opens and keeps them collapsed into one line; when files changed it also offers a two-way **Rollback scope**:
|
|
103
|
+
- **Messages only** (default) — leave files untouched;
|
|
104
|
+
- **Messages + files** — restore files to their content before that message;
|
|
87
105
|
- pick the scope, then click **Save and resend** or **Delete**.
|
|
88
106
|
|
|
89
|
-
|
|
107
|
+
Lost snapshots, queued prompts, and non-Git workspaces are called out in one-line notes inside the popover.
|
|
90
108
|
|
|
91
109
|
## File rollback: what can and cannot be restored
|
|
92
110
|
|
|
@@ -114,7 +132,7 @@ Normally it is deleted. Only when its log directory is still held open and canno
|
|
|
114
132
|
Attachments are stored as part of the message content, and editing only supports plain-text messages. Messages with attachments can still be deleted.
|
|
115
133
|
|
|
116
134
|
**Q: The button says a turn is still running?**
|
|
117
|
-
Stop the running task first. Also note that queued prompts are discarded together with the deleted record — the
|
|
135
|
+
Stop the running task first. Also note that queued prompts are discarded together with the deleted record — the popover warns you about this.
|
|
118
136
|
|
|
119
137
|
**Q: I don't see the buttons.**
|
|
120
138
|
Check that the plugin is enabled under **Settings → Plugins** and that you refreshed the page. Only messages you sent have these buttons.
|
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
| --- | --- |
|
|
19
19
|
| 改掉已发送的消息 | 点消息气泡下方的铅笔,改完点「保存并重发」,这条消息之后的内容会被截断,然后按你改后的内容重新开始 |
|
|
20
20
|
| 撤掉一条越界的消息 | 点垃圾桶,确认后这条消息连同它之后的所有对话一起删除 |
|
|
21
|
-
| 连文件一起还原 |
|
|
21
|
+
| 连文件一起还原 | 删除/编辑时,如果那一轮动过文件,按钮下方的小窗会让你选「只回滚消息」还是「连文件一起回滚」 |
|
|
22
22
|
| 不打扰正在跑的任务 | 有未结束的轮次时直接拒绝操作,不会和正在执行的 turn 抢写 |
|
|
23
23
|
|
|
24
24
|
只有你自己发出的消息才有这两个按钮;「复制」按钮仍在,位置不变。
|
|
@@ -27,15 +27,21 @@
|
|
|
27
27
|
|
|
28
28
|
自己发出的消息,气泡下方会多出「编辑 / 删除 / 复制」三个按钮:
|
|
29
29
|
|
|
30
|
-
<img src="img/message-actions.png" alt="消息气泡下方的编辑、删除、复制按钮" width="760">
|
|
30
|
+
<img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/message-actions.png" alt="消息气泡下方的编辑、删除、复制按钮" width="760">
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
点铅笔或垃圾桶之后,小窗直接出现在那个按钮正下方,并用一个小箭头指向它;点窗外或按 Esc 就收起。编辑窗一打开就会读出这条消息之后记录到的文件改动,默认只显示一行「已记录 N 处文件改动」,展开才看具体路径;要不要连文件一起还原,用一个二选一的开关决定:
|
|
33
33
|
|
|
34
|
-
|
|
|
34
|
+
| 编辑小窗 | 删除确认 |
|
|
35
35
|
| :---: | :---: |
|
|
36
|
-
| <img src="img/edit-dialog.png" alt="
|
|
36
|
+
| <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/edit-dialog.png" alt="编辑小窗:文件改动收起成一行,回滚范围二选一" width="360"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/delete-dialog.png" alt="删除确认:没有文件改动时只剩一行确认" width="360"> |
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
小窗跟着按钮走:窗口底部放不下时自动翻到按钮上方,窄屏下收窄到屏幕宽度,亮色主题也保持同一套层级:
|
|
39
|
+
|
|
40
|
+
| 靠近底部时翻到上方 | 窄屏(390px) | 亮色主题 |
|
|
41
|
+
| :---: | :---: | :---: |
|
|
42
|
+
| <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/popover-flip.png" alt="小窗翻到按钮上方,箭头朝下指向按钮" width="240"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/popover-narrow.png" alt="窄屏下小窗收窄到屏幕宽度" width="240"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/popover-light.png" alt="亮色主题下的删除小窗" width="240"> |
|
|
43
|
+
|
|
44
|
+
快照失效、工作区不在 Git 仓库等限制也会直接标在小窗里,不用等到操作失败才知道。
|
|
39
45
|
|
|
40
46
|
## 安装
|
|
41
47
|
|
|
@@ -43,12 +49,24 @@
|
|
|
43
49
|
|
|
44
50
|
### 从 npm 安装(推荐)
|
|
45
51
|
|
|
52
|
+
包已发布到 npm:[dsh-message-rewind](https://www.npmjs.com/package/dsh-message-rewind),也在[插件市场](https://awesome-dsh-plugin.com/p/xCube007/dsh-message-rewind/)里。
|
|
53
|
+
|
|
54
|
+
最省事的一条命令:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
dsh plugin --profile web add dsh-message-rewind
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
也可以直接在 DSH 里装:**设置 → 插件 → 搜索 `dsh-message-rewind`**。
|
|
61
|
+
|
|
62
|
+
习惯自己改配置的话,手动安装等价于下面三步:
|
|
63
|
+
|
|
46
64
|
1. 在 profile 的 `package.json`(`~/.dsh/profiles/<profile>/package.json`)里加依赖:
|
|
47
65
|
|
|
48
66
|
```json
|
|
49
67
|
{
|
|
50
68
|
"dependencies": {
|
|
51
|
-
"dsh-message-rewind": "^1.
|
|
69
|
+
"dsh-message-rewind": "^1.2.0"
|
|
52
70
|
}
|
|
53
71
|
}
|
|
54
72
|
```
|
|
@@ -81,14 +99,14 @@ DSH 启动日志里会出现 `message-rewind` 且状态为 active;刷新页面
|
|
|
81
99
|
|
|
82
100
|
## 使用
|
|
83
101
|
|
|
84
|
-
1. 点铅笔 →
|
|
102
|
+
1. 点铅笔 → 按钮下方弹出小窗,改完点「保存并重发」。
|
|
85
103
|
2. 点垃圾桶 → 点「删除」,删除这条消息及其后的全部对话。
|
|
86
|
-
3.
|
|
104
|
+
3. 小窗打开时就会读取这条消息之后记录到的文件改动:默认折叠成一行「已记录 N 处文件改动」,点开可看路径;有改动时还会多出一个二选一的回滚范围:
|
|
87
105
|
- **只回滚消息**(默认):文件保持现状;
|
|
88
|
-
-
|
|
106
|
+
- **连文件一起回滚**:文件恢复成这条消息之前的内容;
|
|
89
107
|
- 选好范围后,点「保存并重发」或「删除」执行。
|
|
90
108
|
|
|
91
|
-
|
|
109
|
+
快照失效、还有排队中的消息、工作区不在 Git 仓库等情况会在小窗里用一行提示说明。
|
|
92
110
|
|
|
93
111
|
## 文件回滚:什么能回、什么回不了
|
|
94
112
|
|
|
@@ -116,7 +134,7 @@ DSH 启动日志里会出现 `message-rewind` 且状态为 active;刷新页面
|
|
|
116
134
|
附件是作为消息内容的一部分存下来的,编辑只支持纯文本消息。带附件的消息可以删除。
|
|
117
135
|
|
|
118
136
|
**Q:点按钮提示「当前有未结束的轮次」?**
|
|
119
|
-
|
|
137
|
+
先停止正在运行的任务再操作。另外,如果有排队中的消息,它们会随被删除的记录一起作废——小窗里会提示。
|
|
120
138
|
|
|
121
139
|
**Q:看不到按钮?**
|
|
122
140
|
确认插件已在「设置 → 插件」里启用、并且刷新过一次页面;另外只有你自己发的消息才有这两个按钮。
|
package/client.js
CHANGED
|
@@ -9,17 +9,17 @@ window.__ModuleLoader__.load({
|
|
|
9
9
|
const zh = {
|
|
10
10
|
edit: '编辑并重发', remove: '删除这条消息及其后的对话', copy: '复制', copied: '已复制',
|
|
11
11
|
'clock.md': '{m}月{d}日', 'clock.ymd': '{y}年{m}月{d}日',
|
|
12
|
-
cancel: '取消',
|
|
13
|
-
editTitle: '
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
messagesOnly: '只回滚消息', withFiles: '
|
|
18
|
-
fileWarning: '
|
|
19
|
-
incomplete: '
|
|
12
|
+
cancel: '取消', loading: '正在检查文件改动…', save: '保存并重发', deleteConfirm: '删除', scope: '回滚范围', body: '消息内容',
|
|
13
|
+
editTitle: '编辑消息', deleteTitle: '删除这条消息?',
|
|
14
|
+
editNote: '截断之后的对话,再按新内容重发。',
|
|
15
|
+
deleteNote: '之后的对话会一起删除,无法恢复。',
|
|
16
|
+
filesCount: '已记录 {n} 处文件改动',
|
|
17
|
+
messagesOnly: '只回滚消息', withFiles: '连文件一起回滚',
|
|
18
|
+
fileWarning: '文件会还原到这条消息之前。',
|
|
19
|
+
incomplete: '文件快照已失效,只能回滚消息。',
|
|
20
20
|
running: '当前有未结束的轮次,请先停止运行',
|
|
21
|
-
queued: '
|
|
22
|
-
noGit: '
|
|
21
|
+
queued: '排队中的消息会一并作废。',
|
|
22
|
+
noGit: '工作区不在 Git 仓库内:只有 DSH 文件工具的改动可回滚。',
|
|
23
23
|
attachments: '含附件的消息暂时只能删除,不能编辑',
|
|
24
24
|
empty: '消息不能为空', failed: '操作失败,请重试。', dialog: '消息回滚',
|
|
25
25
|
'error.invalid-message': '消息位置无效。',
|
|
@@ -51,17 +51,17 @@ window.__ModuleLoader__.load({
|
|
|
51
51
|
const en = {
|
|
52
52
|
edit: 'Edit and resend', remove: 'Delete this message and every following turn', copy: 'Copy', copied: 'Copied',
|
|
53
53
|
'clock.md': '{m}/{d}', 'clock.ymd': '{y}-{m}-{d}',
|
|
54
|
-
cancel: 'Cancel',
|
|
55
|
-
editTitle: 'Edit
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
messagesOnly: '
|
|
60
|
-
fileWarning: 'Files are restored to their state before this message.
|
|
61
|
-
incomplete: '
|
|
54
|
+
cancel: 'Cancel', loading: 'Checking file changes…', save: 'Save and resend', deleteConfirm: 'Delete', scope: 'Rollback scope', body: 'Message text',
|
|
55
|
+
editTitle: 'Edit message', deleteTitle: 'Delete this message?',
|
|
56
|
+
editNote: 'Cuts off later turns, then resends.',
|
|
57
|
+
deleteNote: 'Following turns are deleted too, for good.',
|
|
58
|
+
filesCount: '{n} file changes recorded',
|
|
59
|
+
messagesOnly: 'Messages only', withFiles: 'Messages + files',
|
|
60
|
+
fileWarning: 'Files are restored to their state before this message.',
|
|
61
|
+
incomplete: 'File snapshots are gone; messages only.',
|
|
62
62
|
running: 'A turn is still running — stop it first',
|
|
63
|
-
queued: 'Queued prompts are discarded
|
|
64
|
-
noGit: '
|
|
63
|
+
queued: 'Queued prompts are discarded too.',
|
|
64
|
+
noGit: 'No Git here: only DSH file-tool edits can be rolled back.',
|
|
65
65
|
attachments: 'Messages with attachments can only be deleted, not edited',
|
|
66
66
|
empty: 'Message cannot be empty', failed: 'Operation failed. Please try again.', dialog: 'Message rewind',
|
|
67
67
|
'error.invalid-message': 'Invalid message position.',
|
|
@@ -100,30 +100,59 @@ window.__ModuleLoader__.load({
|
|
|
100
100
|
.dmr-action:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-secondary)}
|
|
101
101
|
.dmr-action:disabled,.dmr-action[data-unavailable]{cursor:default;opacity:.4}
|
|
102
102
|
.dmr-action:disabled:hover{background:0 0;color:var(--dsw-alias-label-tertiary)}
|
|
103
|
+
.dmr-action:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}
|
|
103
104
|
.dmr-danger:not(:disabled):hover{color:var(--dsw-alias-state-error-primary)}
|
|
104
|
-
.dmr-
|
|
105
|
-
.dmr-
|
|
106
|
-
.dmr-
|
|
107
|
-
.dmr-
|
|
108
|
-
.dmr-
|
|
109
|
-
.dmr-
|
|
110
|
-
.dmr-
|
|
111
|
-
.dmr-
|
|
112
|
-
.dmr-
|
|
113
|
-
.dmr-
|
|
114
|
-
.dmr-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
.dmr-
|
|
118
|
-
.dmr-
|
|
119
|
-
.dmr-
|
|
120
|
-
.dmr-
|
|
121
|
-
.dmr-
|
|
122
|
-
.dmr-
|
|
123
|
-
.dmr-
|
|
124
|
-
.dmr-
|
|
125
|
-
.dmr-
|
|
126
|
-
|
|
105
|
+
.dmr-layer{position:fixed;inset:0;z-index:1000;pointer-events:none}
|
|
106
|
+
.dmr-pop{position:fixed;z-index:1;box-sizing:border-box;visibility:hidden;pointer-events:auto;padding:14px 14px 12px;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);border:1px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-md);box-shadow:var(--dsw-elevation-prominent);font-size:13px;line-height:20px}
|
|
107
|
+
.dmr-pop-edit{width:min(420px,calc(100vw - 16px))}
|
|
108
|
+
.dmr-pop-delete{width:min(320px,calc(100vw - 16px))}
|
|
109
|
+
.dmr-pop[data-ready]{visibility:visible}
|
|
110
|
+
.dmr-pop[data-ready][data-side=bottom]{animation:dmr-drop .15s cubic-bezier(.2,.9,.3,1) both}
|
|
111
|
+
.dmr-pop[data-ready][data-side=top]{animation:dmr-rise .15s cubic-bezier(.2,.9,.3,1) both}
|
|
112
|
+
.dmr-pop:focus{outline:none}
|
|
113
|
+
.dmr-arrow{position:absolute;top:-6px;left:0;box-sizing:border-box;width:11px;height:11px;background:inherit;border:1px solid var(--dsw-alias-border-l2);transform:rotate(45deg);pointer-events:none}
|
|
114
|
+
.dmr-pop[data-side=bottom] .dmr-arrow{border-right-color:transparent;border-bottom-color:transparent}
|
|
115
|
+
.dmr-pop[data-side=top] .dmr-arrow{top:auto;bottom:-6px;border-left-color:transparent;border-top-color:transparent}
|
|
116
|
+
@keyframes dmr-drop{from{opacity:0;transform:translateY(-5px)}to{opacity:1;transform:translateY(0)}}
|
|
117
|
+
@keyframes dmr-rise{from{opacity:0;transform:translateY(5px)}to{opacity:1;transform:translateY(0)}}
|
|
118
|
+
.dmr-head{margin:0 0 8px}
|
|
119
|
+
.dmr-title{font-size:13px;font-weight:600;line-height:19px;margin:0;color:var(--dsw-alias-label-primary)}
|
|
120
|
+
.dmr-note{font-size:12px;line-height:17px;margin:3px 0 0;color:var(--dsw-alias-label-tertiary)}
|
|
121
|
+
.dmr-body{max-height:min(62vh,460px);overflow:auto;overscroll-behavior:contain}
|
|
122
|
+
.dmr-body>:first-child{margin-top:0}
|
|
123
|
+
.dmr-text{display:block;box-sizing:border-box;width:100%;min-height:104px;max-height:220px;resize:vertical;margin:0;border:1px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-sm);background:0 0;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;line-height:20px;padding:8px 10px;transition:border-color .12s}
|
|
124
|
+
.dmr-text:hover{border-color:var(--dsw-alias-border-l3)}
|
|
125
|
+
.dmr-text:focus{outline:none;border-color:var(--dsw-alias-state-business-primary)}
|
|
126
|
+
.dmr-files-block{margin:10px 0 0}
|
|
127
|
+
.dmr-summary{display:flex;align-items:center;gap:7px;width:fit-content;padding:1px 0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary);cursor:pointer;list-style:none;user-select:none;border-radius:var(--dsw-radius-xs)}
|
|
128
|
+
.dmr-summary::-webkit-details-marker{display:none}
|
|
129
|
+
.dmr-summary:hover{color:var(--dsw-alias-label-primary)}
|
|
130
|
+
.dmr-summary:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px}
|
|
131
|
+
.dmr-chevron{width:5px;height:5px;flex:0 0 auto;border-right:1.5px solid currentColor;border-bottom:1.5px solid currentColor;transform:rotate(-45deg);transition:transform .12s}
|
|
132
|
+
.dmr-files-block[open] .dmr-chevron{transform:rotate(45deg)}
|
|
133
|
+
.dmr-files{display:flex;flex-direction:column;gap:2px;max-height:112px;overflow:auto;margin:6px 0 0;padding:0 0 0 12px;list-style:none}
|
|
134
|
+
.dmr-files li{font:11.5px/16px var(--ds-font-family-code,ui-monospace,monospace);color:var(--dsw-alias-label-tertiary);overflow-wrap:anywhere}
|
|
135
|
+
.dmr-scope{display:flex;gap:2px;margin:10px 0 0;padding:2px;background:var(--dsw-alias-interactive-bg-hover);border-radius:calc(var(--dsw-radius-sm) + 1px)}
|
|
136
|
+
.dmr-seg{flex:1 1 0;min-width:0;overflow:hidden;border:0;border-radius:var(--dsw-radius-xs);background:0 0;color:var(--dsw-alias-label-secondary);font:inherit;font-size:12px;line-height:16px;padding:4px 6px;text-overflow:ellipsis;white-space:nowrap;cursor:pointer}
|
|
137
|
+
.dmr-seg:hover{color:var(--dsw-alias-label-primary)}
|
|
138
|
+
.dmr-seg[aria-checked=true]{background:var(--dsw-alias-button-elevated-fill);color:var(--dsw-alias-label-primary);font-weight:500;box-shadow:0 1px 3px rgba(0,0,0,.16),0 0 0 .5px var(--dsw-alias-border-l2)}
|
|
139
|
+
.dmr-seg:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}
|
|
140
|
+
.dmr-warning{margin:8px 0 0;font-size:12px;line-height:17px;color:var(--dsw-alias-state-warn-primary)}
|
|
141
|
+
.dmr-error{margin:8px 0 0;font-size:12px;line-height:17px;color:var(--dsw-alias-state-error-primary);overflow-wrap:anywhere}
|
|
142
|
+
.dmr-hint{display:flex;align-items:center;gap:6px;margin:8px 0 0;font-size:12px;line-height:17px;color:var(--dsw-alias-label-tertiary)}
|
|
143
|
+
.dmr-spinner{width:11px;height:11px;flex:0 0 auto;border:1.5px solid var(--dsw-alias-border-l4);border-top-color:var(--dsw-alias-label-tertiary);border-radius:50%;animation:dmr-spin .8s linear infinite}
|
|
144
|
+
@keyframes dmr-spin{to{transform:rotate(360deg)}}
|
|
145
|
+
.dmr-footer{display:flex;justify-content:flex-end;gap:6px;margin-top:12px}
|
|
146
|
+
.dmr-button{border:0;border-radius:var(--dsw-radius-sm);background:0 0;color:var(--dsw-alias-label-secondary);font:inherit;font-size:12.5px;line-height:18px;padding:5px 10px;white-space:nowrap;cursor:pointer;transition:background .12s,color .12s}
|
|
147
|
+
.dmr-button:not(:disabled):hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
|
|
148
|
+
.dmr-button:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}
|
|
149
|
+
.dmr-button:disabled{opacity:.45;cursor:not-allowed}
|
|
150
|
+
.dmr-primary{background:var(--dsw-alias-button-primary-fill);color:var(--dsw-alias-label-primary-foreground);font-weight:500;padding:5px 12px}
|
|
151
|
+
.dmr-primary:not(:disabled):hover{background:var(--dsw-alias-button-primary-hover);color:var(--dsw-alias-label-primary-foreground)}
|
|
152
|
+
.dmr-destructive{background:var(--dsw-alias-state-error-primary);color:var(--dsw-alias-label-primary-foreground);font-weight:500;padding:5px 12px}
|
|
153
|
+
.dmr-destructive:not(:disabled):hover{background:var(--dsw-alias-state-error-primary);box-shadow:inset 0 0 0 999px rgba(0,0,0,.12);color:var(--dsw-alias-label-primary-foreground)}
|
|
154
|
+
@media (prefers-reduced-motion:reduce){.dmr-pop[data-ready]{animation:none}.dmr-spinner{animation-duration:2.4s}}
|
|
155
|
+
@media (max-width:480px){.dmr-pop{padding:12px 12px 10px}.dmr-pop-edit,.dmr-pop-delete{width:calc(100vw - 16px)}}
|
|
127
156
|
`;
|
|
128
157
|
|
|
129
158
|
const pad2 = (value) => String(value).padStart(2, '0');
|
|
@@ -174,34 +203,122 @@ window.__ModuleLoader__.load({
|
|
|
174
203
|
return { text: texts.join(''), attachments, rest };
|
|
175
204
|
}
|
|
176
205
|
|
|
177
|
-
|
|
206
|
+
// Popover geometry stays pure so client.test.js can exercise the flip/clamp
|
|
207
|
+
// math without a browser; the markers below delimit the extractable region.
|
|
208
|
+
// #region popover-geometry
|
|
209
|
+
const POP_GAP = 8;
|
|
210
|
+
const POP_MARGIN = 8;
|
|
211
|
+
const ARROW_SIZE = 11;
|
|
212
|
+
const ARROW_INSET = 14;
|
|
213
|
+
const clamp = (value, min, max) => Math.min(Math.max(value, min), Math.max(min, max));
|
|
214
|
+
/** Below the trigger when it fits, otherwise above; clamp both axes and the arrow. */
|
|
215
|
+
function placePopover(anchor, pop, view) {
|
|
216
|
+
const roomBelow = view.height - anchor.bottom - POP_GAP - POP_MARGIN;
|
|
217
|
+
const roomAbove = anchor.top - POP_GAP - POP_MARGIN;
|
|
218
|
+
const below = roomBelow >= pop.height || roomBelow >= roomAbove;
|
|
219
|
+
const center = anchor.left + anchor.width / 2;
|
|
220
|
+
const left = clamp(center - pop.width / 2, POP_MARGIN, view.width - pop.width - POP_MARGIN);
|
|
221
|
+
const rawTop = below ? anchor.bottom + POP_GAP : anchor.top - POP_GAP - pop.height;
|
|
222
|
+
const top = clamp(rawTop, POP_MARGIN, view.height - pop.height - POP_MARGIN);
|
|
223
|
+
const arrow = clamp(center - left - ARROW_SIZE / 2, ARROW_INSET, pop.width - ARROW_INSET - ARROW_SIZE);
|
|
224
|
+
return { left: Math.round(left), top: Math.round(top), arrow: Math.round(arrow), below };
|
|
225
|
+
}
|
|
226
|
+
// #endregion
|
|
227
|
+
|
|
228
|
+
function Popover({ anchor, kind, title, note, locked, onClose, children, footer }) {
|
|
178
229
|
const ref = React.useRef(null);
|
|
230
|
+
const [layout, setLayout] = React.useState(null);
|
|
179
231
|
const lockedRef = React.useRef(locked);
|
|
180
232
|
lockedRef.current = locked;
|
|
181
|
-
React
|
|
233
|
+
// Measure before paint when the host React supports it, so the popover is
|
|
234
|
+
// never shown at a stale position for a frame. The headless test harness
|
|
235
|
+
// only provides useEffect, hence the fallback.
|
|
236
|
+
const useEffect = typeof React.useLayoutEffect === 'function' ? React.useLayoutEffect : React.useEffect;
|
|
237
|
+
// Mount-only: the popover is unmounted whenever the dialog closes, and a
|
|
238
|
+
// fresh instance id remounts it per open, so the captured anchor is live.
|
|
239
|
+
useEffect(() => {
|
|
240
|
+
const node = ref.current;
|
|
241
|
+
const trigger = anchor;
|
|
182
242
|
const previous = document.activeElement;
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
243
|
+
const first = node?.querySelector?.('textarea, button');
|
|
244
|
+
if (first && typeof first.focus === 'function') {
|
|
245
|
+
first.focus();
|
|
246
|
+
if (first.tagName === 'TEXTAREA' && typeof first.setSelectionRange === 'function') first.setSelectionRange(first.value.length, first.value.length);
|
|
247
|
+
}
|
|
248
|
+
let frame = 0;
|
|
249
|
+
const measure = () => {
|
|
250
|
+
if (!node || typeof node.getBoundingClientRect !== 'function') return;
|
|
251
|
+
// Client sizes exclude the scrollbar, so the popover never tucks under it.
|
|
252
|
+
const view = {
|
|
253
|
+
width: document.documentElement?.clientWidth || window.innerWidth || 0,
|
|
254
|
+
height: document.documentElement?.clientHeight || window.innerHeight || 0,
|
|
255
|
+
};
|
|
256
|
+
// A missing or detached trigger (keyboard shortcut, collapsed row)
|
|
257
|
+
// still gets a sensible spot: centred, above the middle of the view.
|
|
258
|
+
const box = typeof trigger?.getBoundingClientRect === 'function' && trigger.isConnected !== false
|
|
259
|
+
? trigger.getBoundingClientRect()
|
|
260
|
+
: { top: Math.round(view.height * 0.3), bottom: Math.round(view.height * 0.3), left: view.width / 2, width: 0 };
|
|
261
|
+
const next = placePopover(box, node.getBoundingClientRect(), view);
|
|
262
|
+
setLayout((last) => (last !== null && last.left === next.left && last.top === next.top && last.arrow === next.arrow && last.below === next.below ? last : next));
|
|
263
|
+
};
|
|
264
|
+
const raf = typeof window.requestAnimationFrame === 'function' ? window.requestAnimationFrame.bind(window) : null;
|
|
265
|
+
const caf = typeof window.cancelAnimationFrame === 'function' ? window.cancelAnimationFrame.bind(window) : null;
|
|
266
|
+
const schedule = raf === null ? measure : () => { if (frame !== 0) return; frame = raf(() => { frame = 0; measure(); }); };
|
|
186
267
|
const onKey = (event) => {
|
|
187
268
|
if (event.key === 'Escape' && !lockedRef.current) { event.preventDefault(); onClose(); return; }
|
|
188
|
-
if (event.key !== 'Tab') return;
|
|
189
|
-
const items = [...(
|
|
269
|
+
if (event.key !== 'Tab' || !node) return;
|
|
270
|
+
const items = [...(node.querySelectorAll?.('textarea, input:not(:disabled), button:not(:disabled)') ?? [])];
|
|
190
271
|
if (items.length === 0) { event.preventDefault(); return; }
|
|
191
|
-
const
|
|
192
|
-
const
|
|
193
|
-
if (event.shiftKey && document.activeElement ===
|
|
194
|
-
else if (!event.shiftKey && document.activeElement ===
|
|
272
|
+
const firstItem = items[0];
|
|
273
|
+
const lastItem = items[items.length - 1];
|
|
274
|
+
if (event.shiftKey && document.activeElement === firstItem) { event.preventDefault(); lastItem.focus(); }
|
|
275
|
+
else if (!event.shiftKey && document.activeElement === lastItem) { event.preventDefault(); firstItem.focus(); }
|
|
276
|
+
};
|
|
277
|
+
// Click-away dismisses; the trigger is excluded because its own click
|
|
278
|
+
// toggles the popover, and a busy write is never abandoned.
|
|
279
|
+
const onAway = (event) => {
|
|
280
|
+
if (lockedRef.current) return;
|
|
281
|
+
const target = event.target;
|
|
282
|
+
if (!target || node?.contains?.(target) || trigger?.contains?.(target)) return;
|
|
283
|
+
onClose();
|
|
195
284
|
};
|
|
196
|
-
|
|
285
|
+
const follow = () => schedule();
|
|
286
|
+
document.addEventListener?.('keydown', onKey);
|
|
287
|
+
document.addEventListener?.('mousedown', onAway, true);
|
|
288
|
+
window.addEventListener?.('scroll', follow, true);
|
|
289
|
+
window.addEventListener?.('resize', follow);
|
|
290
|
+
let observer = null;
|
|
291
|
+
if (typeof ResizeObserver === 'function' && node) { observer = new ResizeObserver(() => schedule()); observer.observe(node); }
|
|
292
|
+
measure();
|
|
197
293
|
return () => {
|
|
198
|
-
document.removeEventListener('keydown', onKey);
|
|
294
|
+
document.removeEventListener?.('keydown', onKey);
|
|
295
|
+
document.removeEventListener?.('mousedown', onAway, true);
|
|
296
|
+
window.removeEventListener?.('scroll', follow, true);
|
|
297
|
+
window.removeEventListener?.('resize', follow);
|
|
298
|
+
observer?.disconnect?.();
|
|
299
|
+
if (caf !== null && frame !== 0) caf(frame);
|
|
199
300
|
if (previous?.isConnected !== false) previous?.focus?.();
|
|
200
301
|
};
|
|
201
|
-
}, [
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
302
|
+
}, []);
|
|
303
|
+
const side = layout === null || layout.below ? 'bottom' : 'top';
|
|
304
|
+
return h('div', { className: 'dmr-layer' },
|
|
305
|
+
h('div', {
|
|
306
|
+
className: `dmr-pop dmr-pop-${kind}`,
|
|
307
|
+
role: 'dialog',
|
|
308
|
+
'aria-modal': 'false',
|
|
309
|
+
'aria-label': title,
|
|
310
|
+
tabIndex: -1,
|
|
311
|
+
ref,
|
|
312
|
+
'data-side': side,
|
|
313
|
+
'data-ready': layout === null ? undefined : '',
|
|
314
|
+
style: layout === null ? undefined : { top: `${layout.top}px`, left: `${layout.left}px` },
|
|
315
|
+
},
|
|
316
|
+
h('span', { className: 'dmr-arrow', 'aria-hidden': 'true', style: layout === null ? undefined : { left: `${layout.arrow}px` } }),
|
|
317
|
+
h('div', { className: 'dmr-head' },
|
|
318
|
+
h('h2', { className: 'dmr-title' }, title),
|
|
319
|
+
note ? h('p', { className: 'dmr-note' }, note) : null),
|
|
320
|
+
h('div', { className: 'dmr-body' }, children),
|
|
321
|
+
footer));
|
|
205
322
|
}
|
|
206
323
|
|
|
207
324
|
return {
|
|
@@ -266,6 +383,9 @@ window.__ModuleLoader__.load({
|
|
|
266
383
|
};
|
|
267
384
|
|
|
268
385
|
let current = null;
|
|
386
|
+
// Each open mints an instance id: it keys the popover (a fresh button
|
|
387
|
+
// anchor and a fresh measurement per open) and discards a stale draft.
|
|
388
|
+
let opens = 0;
|
|
269
389
|
const listeners = new Set();
|
|
270
390
|
const publish = (next) => { current = next; for (const listener of listeners) listener(); };
|
|
271
391
|
const subscribe = (listener) => { listeners.add(listener); return () => listeners.delete(listener); };
|
|
@@ -347,23 +467,26 @@ window.__ModuleLoader__.load({
|
|
|
347
467
|
}
|
|
348
468
|
}
|
|
349
469
|
|
|
350
|
-
|
|
351
|
-
|
|
470
|
+
const isOpenFor = (kind, sessionId, seq) => current !== null && current.kind === kind && current.sessionId === sessionId && current.seq === seq;
|
|
471
|
+
|
|
472
|
+
function openEdit(sessionId, seq, text, anchor) {
|
|
473
|
+
const dialog = { token: {}, instance: ++opens, kind: 'edit', sessionId, seq, text, anchor: anchor ?? null, phase: 'edit', busy: false, checking: true, error: null, details: null, abort: new AbortController() };
|
|
352
474
|
publish(dialog);
|
|
353
475
|
void inspectEdit(dialog);
|
|
354
476
|
}
|
|
355
477
|
|
|
356
|
-
function openDelete(sessionId, seq) {
|
|
357
|
-
publish({ token: {}, kind: 'delete', sessionId, seq, text: '', phase: 'loading', busy: true, error: null, details: null, abort: new AbortController() });
|
|
478
|
+
function openDelete(sessionId, seq, anchor) {
|
|
479
|
+
publish({ token: {}, instance: ++opens, kind: 'delete', sessionId, seq, text: '', anchor: anchor ?? null, phase: 'loading', busy: true, error: null, details: null, abort: new AbortController() });
|
|
358
480
|
void check();
|
|
359
481
|
}
|
|
360
482
|
|
|
361
483
|
function RewindDialog() {
|
|
362
484
|
const dialog = React.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
485
|
+
// Typing is local until save; the draft belongs to one opening, so a
|
|
486
|
+
// popover reopened for the same message starts from the message text.
|
|
487
|
+
const [draft, setDraft] = React.useState(null);
|
|
366
488
|
if (!dialog) return null;
|
|
489
|
+
const text = draft !== null && draft.instance === dialog.instance ? draft.text : dialog.text;
|
|
367
490
|
const editing = dialog.kind === 'edit';
|
|
368
491
|
const phase = dialog.phase;
|
|
369
492
|
const details = dialog.details;
|
|
@@ -371,62 +494,50 @@ window.__ModuleLoader__.load({
|
|
|
371
494
|
const blocked = Boolean(details?.unfinished);
|
|
372
495
|
const selected = dialog.withFiles === true;
|
|
373
496
|
const canRollback = details !== null && files.length > 0 && !details.incomplete;
|
|
374
|
-
|
|
375
|
-
//
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
h('div', { className: 'dmr-choice', role: 'radiogroup', 'aria-label': t('scope') },
|
|
380
|
-
h('p', { className: 'dmr-choice-title' }, t('scope')),
|
|
381
|
-
h('label', { className: 'dmr-option' },
|
|
382
|
-
h('input', {
|
|
383
|
-
type: 'radio',
|
|
384
|
-
name: 'dmr-rollback-scope',
|
|
385
|
-
checked: !selected,
|
|
386
|
-
onChange: () => patchIf(dialog.token, { withFiles: false }),
|
|
387
|
-
}),
|
|
388
|
-
t('messagesOnly')),
|
|
389
|
-
h('label', { className: canRollback ? 'dmr-option' : 'dmr-option dmr-option-disabled' },
|
|
390
|
-
h('input', {
|
|
391
|
-
type: 'radio',
|
|
392
|
-
name: 'dmr-rollback-scope',
|
|
393
|
-
checked: selected,
|
|
394
|
-
disabled: !canRollback,
|
|
395
|
-
onChange: () => patchIf(dialog.token, { withFiles: true }),
|
|
396
|
-
}),
|
|
397
|
-
t('withFiles'))),
|
|
398
|
-
h('p', { className: 'dmr-warning' }, details.incomplete ? t('incomplete') : t('fileWarning'))) : null;
|
|
399
|
-
const cancelButton = h('button', { className: 'dmr-button', type: 'button', onClick: close, disabled: dialog.busy }, t('cancel'));
|
|
400
|
-
return h(Modal, {
|
|
401
|
-
title: editing ? t('editTitle') : t('deleteTitle'),
|
|
402
|
-
locked: dialog.busy && phase !== 'loading',
|
|
403
|
-
onClose: close,
|
|
404
|
-
},
|
|
405
|
-
phase === 'edit' && h(React.Fragment, null,
|
|
406
|
-
h('p', { className: 'dmr-hint' }, t('editHint')),
|
|
407
|
-
h('textarea', {
|
|
408
|
-
className: 'dmr-text',
|
|
409
|
-
value: text,
|
|
410
|
-
disabled: dialog.busy,
|
|
411
|
-
'aria-label': t('body'),
|
|
412
|
-
onChange: (event) => setText(event.target.value),
|
|
413
|
-
}),
|
|
414
|
-
dialog.checking && h('p', { className: 'dmr-hint' }, t('loading')),
|
|
415
|
-
fileSection),
|
|
416
|
-
phase === 'loading' && h(React.Fragment, null,
|
|
417
|
-
h('p', { className: 'dmr-hint' }, t('loading')),
|
|
418
|
-
h('div', { className: 'dmr-footer' },
|
|
419
|
-
h('button', { className: 'dmr-button', type: 'button', onClick: close }, t('cancel')))),
|
|
420
|
-
phase === 'confirm' && h(React.Fragment, null,
|
|
421
|
-
h('p', { className: 'dmr-hint' }, t('deleteHint')),
|
|
422
|
-
fileSection),
|
|
423
|
-
blocked && h('p', { className: 'dmr-warning', role: 'status' }, t('running')),
|
|
424
|
-
(details?.queued ?? 0) > 0 && h('p', { className: 'dmr-warning', role: 'status' }, t('queued')),
|
|
425
|
-
details?.git === false && h('p', { className: 'dmr-warning', role: 'status' }, t('noGit')),
|
|
426
|
-
dialog.error && h('p', { className: 'dmr-error', role: 'alert' }, dialog.error),
|
|
427
|
-
phase === 'edit' && h('div', { className: 'dmr-footer' },
|
|
428
|
-
cancelButton,
|
|
497
|
+
const spinnerLine = h('p', { className: 'dmr-hint' }, h('span', { className: 'dmr-spinner', 'aria-hidden': 'true' }), t('loading'));
|
|
498
|
+
// Both dialogs ask the same question — how far the rewind reaches — so
|
|
499
|
+
// the scope control is built once. A lost snapshot leaves exactly one
|
|
500
|
+
// possible answer, so no choice is offered at all.
|
|
501
|
+
const scope = canRollback ? h('div', { className: 'dmr-scope', role: 'radiogroup', 'aria-label': t('scope') },
|
|
429
502
|
h('button', {
|
|
503
|
+
className: 'dmr-seg',
|
|
504
|
+
type: 'button',
|
|
505
|
+
role: 'radio',
|
|
506
|
+
'aria-checked': !selected,
|
|
507
|
+
onClick: () => patchIf(dialog.token, { withFiles: false }),
|
|
508
|
+
}, t('messagesOnly')),
|
|
509
|
+
h('button', {
|
|
510
|
+
className: 'dmr-seg',
|
|
511
|
+
type: 'button',
|
|
512
|
+
role: 'radio',
|
|
513
|
+
'aria-checked': selected,
|
|
514
|
+
onClick: () => patchIf(dialog.token, { withFiles: true }),
|
|
515
|
+
}, t('withFiles'))) : null;
|
|
516
|
+
const fileSection = details !== null && (files.length > 0 || details.incomplete) ? h(React.Fragment, null,
|
|
517
|
+
files.length > 0 && h('details', { className: 'dmr-files-block' },
|
|
518
|
+
h('summary', { className: 'dmr-summary' },
|
|
519
|
+
h('span', { className: 'dmr-chevron', 'aria-hidden': 'true' }),
|
|
520
|
+
t('filesCount', { n: files.length })),
|
|
521
|
+
h('ul', { className: 'dmr-files' }, files.map((file, index) => h('li', { key: `${index}:${file}`, title: file }, file)))),
|
|
522
|
+
scope,
|
|
523
|
+
details.incomplete
|
|
524
|
+
? h('p', { className: 'dmr-warning', role: 'status' }, t('incomplete'))
|
|
525
|
+
: selected ? h('p', { className: 'dmr-hint' }, t('fileWarning')) : null,
|
|
526
|
+
details.git === false ? h('p', { className: 'dmr-hint' }, t('noGit')) : null) : null;
|
|
527
|
+
const content = phase === 'edit'
|
|
528
|
+
? h(React.Fragment, null,
|
|
529
|
+
h('textarea', {
|
|
530
|
+
className: 'dmr-text',
|
|
531
|
+
value: text,
|
|
532
|
+
disabled: dialog.busy,
|
|
533
|
+
'aria-label': t('body'),
|
|
534
|
+
onChange: (event) => setDraft({ instance: dialog.instance, text: event.target.value }),
|
|
535
|
+
}),
|
|
536
|
+
dialog.checking ? spinnerLine : null,
|
|
537
|
+
fileSection)
|
|
538
|
+
: phase === 'loading' ? spinnerLine : fileSection;
|
|
539
|
+
const primary = phase === 'edit'
|
|
540
|
+
? h('button', {
|
|
430
541
|
className: 'dmr-button dmr-primary',
|
|
431
542
|
type: 'button',
|
|
432
543
|
disabled: dialog.busy || dialog.checking || text.trim() === '' || blocked,
|
|
@@ -435,15 +546,32 @@ window.__ModuleLoader__.load({
|
|
|
435
546
|
if (details === null) { void inspectEdit(current); return; }
|
|
436
547
|
void execute(canRollback && selected);
|
|
437
548
|
},
|
|
438
|
-
}, t('save'))
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
h('button', {
|
|
442
|
-
className: 'dmr-button dmr-primary',
|
|
549
|
+
}, t('save'))
|
|
550
|
+
: h('button', {
|
|
551
|
+
className: 'dmr-button dmr-destructive',
|
|
443
552
|
type: 'button',
|
|
444
553
|
disabled: dialog.busy || blocked,
|
|
445
554
|
onClick: () => void execute(canRollback && selected),
|
|
446
|
-
}, t('deleteConfirm'))
|
|
555
|
+
}, t('deleteConfirm'));
|
|
556
|
+
return h(Popover, {
|
|
557
|
+
// Remount per open so the anchor/measurement effect always belongs
|
|
558
|
+
// to the button that is currently being pointed at.
|
|
559
|
+
key: dialog.instance,
|
|
560
|
+
anchor: dialog.anchor ?? null,
|
|
561
|
+
kind: dialog.kind,
|
|
562
|
+
title: editing ? t('editTitle') : t('deleteTitle'),
|
|
563
|
+
note: editing ? t('editNote') : t('deleteNote'),
|
|
564
|
+
locked: dialog.busy && phase !== 'loading',
|
|
565
|
+
onClose: close,
|
|
566
|
+
footer: h('div', { className: 'dmr-footer' },
|
|
567
|
+
h('button', { className: 'dmr-button', type: 'button', onClick: close, disabled: dialog.busy && phase !== 'loading' }, t('cancel')),
|
|
568
|
+
primary),
|
|
569
|
+
},
|
|
570
|
+
h(React.Fragment, null,
|
|
571
|
+
content,
|
|
572
|
+
blocked && h('p', { className: 'dmr-warning', role: 'status' }, t('running')),
|
|
573
|
+
(details?.queued ?? 0) > 0 && h('p', { className: 'dmr-warning', role: 'status' }, t('queued')),
|
|
574
|
+
dialog.error && h('p', { className: 'dmr-error', role: 'alert' }, dialog.error)));
|
|
447
575
|
}
|
|
448
576
|
|
|
449
577
|
function UserActions({ node, sessionId, renderFactorySlot, loadImage, useSession }) {
|
|
@@ -490,17 +618,25 @@ window.__ModuleLoader__.load({
|
|
|
490
618
|
title: label,
|
|
491
619
|
onClick,
|
|
492
620
|
}, h(Icon, {}));
|
|
621
|
+
// The freshly clicked button is the anchor the popover points at;
|
|
622
|
+
// clicking the same action again toggles it closed.
|
|
623
|
+
const openFrom = (kind, event) => {
|
|
624
|
+
const anchor = event?.currentTarget ?? null;
|
|
625
|
+
if (isOpenFor(kind, sessionId, data.seq)) { close(); return; }
|
|
626
|
+
if (kind === 'edit') openEdit(sessionId, data.seq, parts.text, anchor);
|
|
627
|
+
else openDelete(sessionId, data.seq, anchor);
|
|
628
|
+
};
|
|
493
629
|
return h('div', { className: 'dmr-row' },
|
|
494
630
|
renderFactorySlot('conversation.chat.user.content', { content, loadImage, facts, interactive: true }),
|
|
495
631
|
h('div', { className: 'dmr-actions' },
|
|
496
632
|
data.time === undefined ? null : h('span', { className: 'dmr-time' }, formatMessageClock(data.time, t)),
|
|
497
633
|
button(IconEdit,
|
|
498
634
|
attachmentBlocked ? t('attachments') : running ? t('running') : t('edit'),
|
|
499
|
-
() =>
|
|
635
|
+
(event) => openFrom('edit', event),
|
|
500
636
|
{ disabled: running || attachmentBlocked }),
|
|
501
637
|
button(IconTrash,
|
|
502
638
|
running ? t('running') : t('remove'),
|
|
503
|
-
() =>
|
|
639
|
+
(event) => openFrom('delete', event),
|
|
504
640
|
{ danger: true, disabled: running }),
|
|
505
641
|
button(copied ? IconCheck : IconCopy,
|
|
506
642
|
copied ? t('copied') : t('copy'),
|
package/client.test.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Headless smoke test for the client half: it installs against a stubbed Cordis
|
|
3
|
-
* context, then renders the message actions and the
|
|
4
|
-
* minimal React stand-in. No browser and no real React are
|
|
3
|
+
* context, then renders the message actions and the anchored edit/delete
|
|
4
|
+
* popover with a minimal React stand-in. No browser and no real React are
|
|
5
|
+
* involved; the popover's placement math is pure and tested on its own.
|
|
5
6
|
*/
|
|
6
7
|
import assert from 'node:assert/strict';
|
|
7
8
|
import { readFile } from 'node:fs/promises';
|
|
@@ -60,6 +61,7 @@ globalThis.document = {
|
|
|
60
61
|
activeElement: null,
|
|
61
62
|
addEventListener() {},
|
|
62
63
|
removeEventListener() {},
|
|
64
|
+
documentElement: { clientWidth: 1280, clientHeight: 800 },
|
|
63
65
|
};
|
|
64
66
|
globalThis.window = {
|
|
65
67
|
setTimeout: (fn, ms) => globalThis.setTimeout(fn, ms),
|
|
@@ -161,20 +163,62 @@ const imageButtons = imageTree.children[1].children.filter(Boolean).slice(1);
|
|
|
161
163
|
assert.equal(imageButtons[0].props.disabled, true, 'attachment messages disable edit');
|
|
162
164
|
assert.equal(imageButtons[1].props.disabled, undefined, 'attachment messages stay deletable');
|
|
163
165
|
|
|
164
|
-
// ---
|
|
166
|
+
// --- the dialog is a popover anchored to the clicked button -----------------
|
|
165
167
|
const renderDialog = () => { react.__enter('dialog'); return overlayRegistration.component({}); };
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
168
|
+
const popoverOf = (element) => {
|
|
169
|
+
if (element?.type?.name === 'Popover') return element;
|
|
170
|
+
return queryAll(element, (candidate) => candidate.type?.name === 'Popover').at(-1) ?? null;
|
|
171
|
+
};
|
|
172
|
+
// The overlay component returns the popover element; expand it the way React
|
|
173
|
+
// would so the rendered tree (head, body, footer) can be inspected.
|
|
174
|
+
const expand = (element) => {
|
|
175
|
+
const popover = popoverOf(element);
|
|
176
|
+
if (!popover) return null;
|
|
177
|
+
const children = popover.children.length === 1 ? popover.children[0] : popover.children;
|
|
178
|
+
react.__enter('popover');
|
|
179
|
+
return popover.type({ ...popover.props, children });
|
|
180
|
+
};
|
|
181
|
+
const treeOf = () => expand(renderDialog());
|
|
182
|
+
const clickAction = (element, anchor) => element.props.onClick(anchor === undefined ? undefined : { currentTarget: anchor });
|
|
183
|
+
const tick = () => new Promise((resolve) => setImmediate(resolve));
|
|
184
|
+
|
|
185
|
+
// --- edit flow --------------------------------------------------------------
|
|
186
|
+
const editAnchor = { tagName: 'BUTTON', id: 'edit-trigger' };
|
|
187
|
+
clickAction(editButton, editAnchor);
|
|
188
|
+
const popover = popoverOf(renderDialog());
|
|
189
|
+
assert.ok(popover, 'edit opens the popover');
|
|
190
|
+
assert.equal(popover.props.kind, 'edit');
|
|
191
|
+
assert.equal(popover.props.anchor, editAnchor, 'the popover points at the button that opened it');
|
|
192
|
+
assert.equal(popover.props.title, 'message-rewind:editTitle');
|
|
193
|
+
assert.equal(popover.props.note, 'message-rewind:editNote', 'one short note instead of a paragraph');
|
|
194
|
+
let dialog = treeOf();
|
|
195
|
+
let pop = dialog.children[0];
|
|
196
|
+
assert.equal(dialog.props.className, 'dmr-layer', 'the popover is not a full-screen dialog');
|
|
197
|
+
assert.equal(pop.props.className, 'dmr-pop dmr-pop-edit');
|
|
198
|
+
assert.equal(pop.props.role, 'dialog');
|
|
199
|
+
assert.equal(pop.props['aria-label'], 'message-rewind:editTitle');
|
|
200
|
+
assert.equal(pop.props['data-side'], 'bottom', 'first paint assumes it hangs below the button');
|
|
201
|
+
assert.equal(pop.props.style, undefined, 'no coordinates until the browser measures');
|
|
202
|
+
assert.equal(pop.children[0].props.className, 'dmr-arrow');
|
|
203
|
+
assert.equal(pop.children[1].props.className, 'dmr-head');
|
|
204
|
+
assert.equal(pop.children[2].props.className, 'dmr-body');
|
|
205
|
+
assert.equal(pop.children[3].props.className, 'dmr-footer');
|
|
206
|
+
const textarea = () => queryAll(treeOf(), (element) => element.type === 'textarea').at(0);
|
|
207
|
+
assert.equal(textarea().props.value, 'hello', 'the message text is prefilled on the first paint');
|
|
208
|
+
textarea().props.onChange({ target: { value: 'hello there' } });
|
|
209
|
+
assert.equal(textarea().props.value, 'hello there', 'typing stays local until save');
|
|
210
|
+
textarea().props.onChange({ target: { value: 'hello' } });
|
|
211
|
+
await tick();
|
|
172
212
|
assert.equal(calls.filter((call) => call[0] === 'rpc.call').at(0)[2], 'inspect', 'opening edit inspects file changes');
|
|
173
213
|
assert.deepEqual(calls.filter((call) => call[0] === 'rpc.call').at(0)[3], { sessionId: 'session-1', seq: 7 });
|
|
174
|
-
const footer = () => queryAll(
|
|
214
|
+
const footer = () => queryAll(treeOf(), (element) => element.props?.className === 'dmr-footer').at(-1);
|
|
215
|
+
assert.deepEqual(footer().children.filter(Boolean).map((button) => button.children.join('')), [
|
|
216
|
+
'message-rewind:cancel',
|
|
217
|
+
'message-rewind:save',
|
|
218
|
+
], 'cancel plus the primary action');
|
|
175
219
|
footer().children.filter(Boolean).at(-1).props.onClick();
|
|
176
|
-
await
|
|
177
|
-
assert.ok(!renderDialog(), 'a clean edit closes the
|
|
220
|
+
await tick();
|
|
221
|
+
assert.ok(!renderDialog(), 'a clean edit closes the popover after forking');
|
|
178
222
|
assert.deepEqual(calls.filter((call) => call[0] === 'openSession'), [['openSession', 'child-1']], 'the branch is opened');
|
|
179
223
|
await new Promise((resolve) => setTimeout(resolve, 400));
|
|
180
224
|
const purged = calls.filter((call) => call[0] === 'rpc.call' && call[2] === 'purge').at(-1);
|
|
@@ -182,78 +226,98 @@ assert.deepEqual(purged[3], { sessionId: 'session-1' }, 'the untouched source is
|
|
|
182
226
|
|
|
183
227
|
// --- an edit that recorded file changes offers both rollback scopes ---------
|
|
184
228
|
inspectResult = { files: ['test.txt', 'src/app.js'], incomplete: false, unfinished: false };
|
|
185
|
-
editButton
|
|
186
|
-
await
|
|
187
|
-
dialog =
|
|
229
|
+
clickAction(editButton, editAnchor);
|
|
230
|
+
await tick();
|
|
231
|
+
dialog = treeOf();
|
|
232
|
+
const disclosure = queryAll(dialog, (element) => element.type === 'details').at(0);
|
|
233
|
+
assert.equal(disclosure.props.className, 'dmr-files-block', 'the recorded files start collapsed');
|
|
234
|
+
assert.equal(queryAll(disclosure, (element) => element.type === 'summary').at(0).children[1], 'message-rewind:filesCount');
|
|
188
235
|
assert.deepEqual(
|
|
189
|
-
queryAll(
|
|
236
|
+
queryAll(disclosure, (element) => element.type === 'li').map((item) => item.children.join('')),
|
|
190
237
|
['test.txt', 'src/app.js'],
|
|
191
|
-
'the
|
|
192
|
-
const
|
|
193
|
-
assert.equal(
|
|
194
|
-
assert.equal(
|
|
195
|
-
assert.
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
238
|
+
'the recorded files are listed');
|
|
239
|
+
const scope = queryAll(dialog, (element) => element.props?.role === 'radio');
|
|
240
|
+
assert.equal(scope.length, 2, 'edit offers the shared scope control');
|
|
241
|
+
assert.equal(scope[0].props['aria-checked'], true, 'messages-only is the default');
|
|
242
|
+
assert.deepEqual(scope.map((option) => option.children.join('')), [
|
|
243
|
+
'message-rewind:messagesOnly',
|
|
244
|
+
'message-rewind:withFiles',
|
|
245
|
+
], 'a compact either/or, not two radio lines');
|
|
246
|
+
scope[1].props.onClick();
|
|
247
|
+
dialog = treeOf();
|
|
248
|
+
const scopeAfter = queryAll(dialog, (element) => element.props?.role === 'radio');
|
|
249
|
+
assert.equal(scopeAfter[1].props['aria-checked'], true, 'the choice sticks');
|
|
250
|
+
assert.equal(queryAll(dialog, (element) => element.props?.className === 'dmr-hint').at(0).children[0], 'message-rewind:fileWarning',
|
|
251
|
+
'the consequence is only spelled out once files are chosen');
|
|
252
|
+
const scopeButtons = footer().children.filter(Boolean);
|
|
202
253
|
scopeButtons.at(-1).props.onClick();
|
|
203
|
-
await
|
|
254
|
+
await tick();
|
|
204
255
|
assert.deepEqual(
|
|
205
256
|
calls.filter((call) => call[0] === 'rpc.call' && call[2] === 'execute').at(-1)[3],
|
|
206
257
|
{ sessionId: 'session-1', seq: 7, action: 'edit', text: 'hello', rewindFiles: true },
|
|
207
258
|
'the edited text is resent after the files roll back');
|
|
208
|
-
assert.ok(!renderDialog(), 'the
|
|
259
|
+
assert.ok(!renderDialog(), 'the popover closes after rolling back and resending');
|
|
209
260
|
await new Promise((resolve) => setTimeout(resolve, 400));
|
|
210
261
|
|
|
211
|
-
// --- a lost snapshot
|
|
262
|
+
// --- a lost snapshot leaves exactly one choice, so no control is shown ------
|
|
212
263
|
inspectResult = { files: [], incomplete: true, unfinished: false };
|
|
213
|
-
editButton
|
|
214
|
-
await
|
|
215
|
-
dialog =
|
|
264
|
+
clickAction(editButton, editAnchor);
|
|
265
|
+
await tick();
|
|
266
|
+
dialog = treeOf();
|
|
216
267
|
assert.equal(queryAll(dialog, (element) => element.props?.className === 'dmr-warning').at(0).children[0], 'message-rewind:incomplete');
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
assert.equal(staleInputs[1].props.disabled, true, 'file rollback is unavailable');
|
|
220
|
-
const staleButtons = queryAll(renderDialog(), (element) => element.props?.className === 'dmr-footer').at(-1).children.filter(Boolean);
|
|
268
|
+
assert.equal(queryAll(dialog, (element) => element.props?.role === 'radio').length, 0, 'there is nothing to choose');
|
|
269
|
+
const staleButtons = footer().children.filter(Boolean);
|
|
221
270
|
assert.equal(staleButtons.length, 2, 'cancel plus the messages-only action');
|
|
222
271
|
staleButtons[0].props.onClick();
|
|
223
|
-
assert.ok(!renderDialog(), 'cancel closes the stale-snapshot
|
|
272
|
+
assert.ok(!renderDialog(), 'cancel closes the stale-snapshot popover');
|
|
224
273
|
inspectResult = { files: [], incomplete: false, unfinished: false };
|
|
225
274
|
|
|
226
275
|
// --- delete flow ------------------------------------------------------------
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
dialog =
|
|
230
|
-
|
|
276
|
+
const deleteAnchor = { tagName: 'BUTTON', id: 'delete-trigger' };
|
|
277
|
+
clickAction(deleteButton, deleteAnchor);
|
|
278
|
+
dialog = treeOf();
|
|
279
|
+
pop = dialog.children[0];
|
|
280
|
+
assert.equal(pop.props.className, 'dmr-pop dmr-pop-delete', 'the confirm bubble is narrower');
|
|
281
|
+
assert.equal(popoverOf(renderDialog()).props.anchor, deleteAnchor, 'the delete bubble points at the bin');
|
|
282
|
+
assert.equal(popoverOf(renderDialog()).props.note, 'message-rewind:deleteNote');
|
|
283
|
+
assert.equal(queryAll(dialog, (element) => element.props?.className === 'dmr-hint').at(0).children[1], 'message-rewind:loading');
|
|
284
|
+
const loadingFooter = queryAll(dialog, (element) => element.props?.className === 'dmr-footer').at(0);
|
|
285
|
+
const loadingButtons = loadingFooter.children.filter(Boolean);
|
|
286
|
+
assert.deepEqual(loadingButtons.map((button) => button.children.join('')), [
|
|
287
|
+
'message-rewind:cancel',
|
|
288
|
+
'message-rewind:deleteConfirm',
|
|
289
|
+
], 'the confirm stays put while the files are read');
|
|
290
|
+
assert.ok(!loadingButtons[0].props.disabled, 'loading stays cancellable');
|
|
291
|
+
assert.equal(loadingButtons[1].props.disabled, true, 'delete waits for the inspection');
|
|
292
|
+
await tick();
|
|
293
|
+
dialog = treeOf();
|
|
231
294
|
const deleteFooter = queryAll(dialog, (element) => element.props?.className === 'dmr-footer').at(-1);
|
|
232
295
|
const deleteButtons = deleteFooter.children.filter(Boolean);
|
|
233
296
|
assert.equal(deleteButtons.length, 2, 'cancel plus delete');
|
|
234
297
|
deleteButtons.at(-1).props.onClick();
|
|
235
|
-
await
|
|
298
|
+
await tick();
|
|
236
299
|
const execute = calls.filter((call) => call[0] === 'rpc.call' && call[2] === 'execute').at(-1);
|
|
237
300
|
assert.deepEqual(execute[3], { sessionId: 'session-1', seq: 7, action: 'delete', text: '', rewindFiles: false });
|
|
238
|
-
await
|
|
301
|
+
await tick();
|
|
239
302
|
assert.deepEqual(calls.filter((call) => call[0] === 'openSession').at(-1), ['openSession', 'child-1']);
|
|
240
303
|
|
|
241
304
|
// --- delete asks the same question, so it renders the same control ----------
|
|
242
305
|
inspectResult = { files: ['test.txt'], incomplete: false, unfinished: false };
|
|
243
|
-
deleteButton
|
|
244
|
-
await
|
|
245
|
-
dialog =
|
|
246
|
-
const deleteScope = queryAll(dialog, (element) => element.
|
|
306
|
+
clickAction(deleteButton, deleteAnchor);
|
|
307
|
+
await tick();
|
|
308
|
+
dialog = treeOf();
|
|
309
|
+
const deleteScope = queryAll(dialog, (element) => element.props?.role === 'radio');
|
|
247
310
|
assert.equal(deleteScope.length, 2, 'delete offers the same scope control');
|
|
248
|
-
assert.equal(deleteScope[0].props
|
|
249
|
-
deleteScope[1].props.
|
|
250
|
-
const deleteActions = queryAll(
|
|
311
|
+
assert.equal(deleteScope[0].props['aria-checked'], true, 'messages-only is the default');
|
|
312
|
+
deleteScope[1].props.onClick();
|
|
313
|
+
const deleteActions = queryAll(treeOf(), (element) => element.props?.className === 'dmr-footer').at(-1).children.filter(Boolean);
|
|
251
314
|
assert.deepEqual(deleteActions.map((button) => button.children.join('')), [
|
|
252
315
|
'message-rewind:cancel',
|
|
253
316
|
'message-rewind:deleteConfirm',
|
|
254
317
|
], 'the delete action follows the chosen scope');
|
|
318
|
+
assert.match(deleteActions.at(-1).props.className, /dmr-destructive/, 'the destructive confirm is styled as such');
|
|
255
319
|
deleteActions.at(-1).props.onClick();
|
|
256
|
-
await
|
|
320
|
+
await tick();
|
|
257
321
|
assert.deepEqual(
|
|
258
322
|
calls.filter((call) => call[0] === 'rpc.call' && call[2] === 'execute').at(-1)[3],
|
|
259
323
|
{ sessionId: 'session-1', seq: 7, action: 'delete', text: '', rewindFiles: true },
|
|
@@ -263,32 +327,69 @@ inspectResult = { files: [], incomplete: false, unfinished: false };
|
|
|
263
327
|
// let the delayed purge settle before the failure-path test swaps the RPC stub
|
|
264
328
|
await new Promise((resolve) => setTimeout(resolve, 400));
|
|
265
329
|
|
|
330
|
+
// --- clicking the open action again toggles the popover ---------------------
|
|
331
|
+
clickAction(editButton, editAnchor);
|
|
332
|
+
assert.ok(renderDialog(), 'edit opens');
|
|
333
|
+
textarea().props.onChange({ target: { value: 'unsent draft' } });
|
|
334
|
+
assert.equal(textarea().props.value, 'unsent draft');
|
|
335
|
+
clickAction(editButton, editAnchor);
|
|
336
|
+
assert.ok(!renderDialog(), 'a second click on the same action closes it');
|
|
337
|
+
clickAction(editButton, editAnchor);
|
|
338
|
+
assert.equal(textarea().props.value, 'hello', 'a reopened popover starts from the message, not the old draft');
|
|
339
|
+
clickAction(editButton, editAnchor);
|
|
340
|
+
assert.ok(!renderDialog(), 'and closes again');
|
|
341
|
+
|
|
266
342
|
// --- host failure codes are localized --------------------------------------
|
|
267
343
|
ctx.connection.rpc.call = () => Promise.resolve({
|
|
268
344
|
ok: false,
|
|
269
345
|
error: { message: '请先停止当前运行', details: { rewindCode: 'open-turn' } },
|
|
270
346
|
});
|
|
271
|
-
deleteButton
|
|
272
|
-
await
|
|
273
|
-
const failed = queryAll(
|
|
347
|
+
clickAction(deleteButton, deleteAnchor);
|
|
348
|
+
await tick();
|
|
349
|
+
const failed = queryAll(treeOf(), (element) => element.props?.className === 'dmr-error').at(0);
|
|
274
350
|
assert.equal(failed.children[0], 'message-rewind:error.open-turn');
|
|
351
|
+
queryAll(treeOf(), (element) => element.props?.className === 'dmr-footer').at(0).children[0].props.onClick();
|
|
352
|
+
assert.ok(!renderDialog(), 'cancel closes the failed popover');
|
|
275
353
|
|
|
276
|
-
// --- a late response cannot resurrect a closed
|
|
354
|
+
// --- a late response cannot resurrect a closed popover ----------------------
|
|
277
355
|
ctx.connection.rpc.call = (channel, endpoint, payload) => {
|
|
278
356
|
calls.push(['rpc.call', channel, endpoint, payload]);
|
|
279
357
|
return new Promise((resolve) => {
|
|
280
358
|
globalThis.setTimeout(() => resolve({ ok: true, value: { files: [], incomplete: false, unfinished: false } }), 20);
|
|
281
359
|
});
|
|
282
360
|
};
|
|
283
|
-
deleteButton
|
|
284
|
-
const loadingDialog =
|
|
361
|
+
clickAction(deleteButton, deleteAnchor);
|
|
362
|
+
const loadingDialog = treeOf();
|
|
285
363
|
assert.ok(loadingDialog, 'delete opens in the loading phase');
|
|
286
|
-
const
|
|
287
|
-
|
|
364
|
+
const lateFooter = queryAll(loadingDialog, (element) => element.props?.className === 'dmr-footer').at(0);
|
|
365
|
+
lateFooter.children[0].props.onClick();
|
|
288
366
|
assert.ok(!renderDialog(), 'the loading phase can be cancelled');
|
|
289
367
|
await new Promise((resolve) => setTimeout(resolve, 60));
|
|
290
|
-
assert.ok(!renderDialog(), 'the late inspect response does not reopen the
|
|
368
|
+
assert.ok(!renderDialog(), 'the late inspect response does not reopen the popover');
|
|
291
369
|
|
|
292
|
-
|
|
370
|
+
// --- placement: below the button, flipped when needed, always on screen -----
|
|
371
|
+
const geometry = source.match(/#region popover-geometry([\s\S]*?)#endregion/);
|
|
372
|
+
assert.ok(geometry, 'the placement block is marked for extraction');
|
|
373
|
+
const { placePopover } = new Function(`${geometry[1]}\nreturn { placePopover };`)();
|
|
374
|
+
const wide = { width: 1280, height: 800 };
|
|
293
375
|
|
|
376
|
+
assert.deepEqual(
|
|
377
|
+
placePopover({ left: 1100, top: 100, width: 28, bottom: 128 }, { width: 320, height: 180 }, wide),
|
|
378
|
+
{ left: 952, top: 136, arrow: 157, below: true },
|
|
379
|
+
'hangs 8px below the button, centred on it, clamped to the right edge');
|
|
380
|
+
assert.deepEqual(
|
|
381
|
+
placePopover({ left: 600, top: 300, width: 28, bottom: 328 }, { width: 320, height: 180 }, { width: 1280, height: 400 }),
|
|
382
|
+
{ left: 454, top: 112, arrow: 155, below: false },
|
|
383
|
+
'flips above the button when the space below is too small');
|
|
384
|
+
const edge = placePopover({ left: 8, top: 40, width: 28, bottom: 68 }, { width: 320, height: 180 }, wide);
|
|
385
|
+
assert.deepEqual(edge, { left: 8, top: 76, arrow: 14, below: true }, 'the arrow stays clear of the rounded corner');
|
|
386
|
+
assert.equal(
|
|
387
|
+
placePopover({ left: 1252, top: 40, width: 28, bottom: 68 }, { width: 320, height: 180 }, wide).arrow,
|
|
388
|
+
295,
|
|
389
|
+
'and clear of the far corner too');
|
|
390
|
+
assert.equal(
|
|
391
|
+
placePopover({ left: 600, top: 40, width: 28, bottom: 68 }, { width: 320, height: 900 }, { width: 1280, height: 500 }).top,
|
|
392
|
+
8,
|
|
393
|
+
'an oversized popover pins to the top edge instead of running off screen');
|
|
294
394
|
|
|
395
|
+
console.log('client self-check passed');
|
package/files.test.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* File-rewind self-check against a real temporary directory. The recorded
|
|
3
3
|
* diffs are handcrafted to match what `dsh-workspace-changes` produces: it diffs
|
|
4
|
-
* newline-terminated text with jsdiff
|
|
5
|
-
*
|
|
4
|
+
* newline-terminated text with jsdiff but hands back every hunk line without its
|
|
5
|
+
* newline — an empty body is one blank line — and a deletion is
|
|
6
|
+
* `before: true, after: false`.
|
|
6
7
|
*/
|
|
7
8
|
import assert from 'node:assert/strict';
|
|
8
9
|
import { promises as fsp } from 'node:fs';
|
|
@@ -49,6 +50,26 @@ await check('created file is removed', async () => {
|
|
|
49
50
|
await assert.rejects(() => fsp.stat(abs(createdName)));
|
|
50
51
|
});
|
|
51
52
|
|
|
53
|
+
// --- the recorder's hunk lines carry no newline; a blank line is one line ---
|
|
54
|
+
const blankCreatedName = 'blank-created.txt';
|
|
55
|
+
const blankCreatedDiff = textDiff(blankCreatedName, false, true, [{ oldStart: 0, oldLines: 0, newStart: 1, newLines: 3, lines: ['+a', '+', '+b'] }]);
|
|
56
|
+
await check('created file with a blank line is removed', async () => {
|
|
57
|
+
await fsp.writeFile(abs(blankCreatedName), 'a\n\nb\n', 'utf8');
|
|
58
|
+
const targets = await planRewind(readDiffFrom({ '13:0': blankCreatedDiff }), recordsFor([{ seq: 13, files: [{ path: blankCreatedName, display: blankCreatedName }] }]));
|
|
59
|
+
assert.deepEqual([...targets.values()][0].original, { exists: false, text: null });
|
|
60
|
+
await applyRewind(targets);
|
|
61
|
+
await assert.rejects(() => fsp.stat(abs(blankCreatedName)));
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const blankEditedName = 'blank-edited.txt';
|
|
65
|
+
const blankEditedDiff = textDiff(blankEditedName, true, true, [{ oldStart: 1, oldLines: 4, newStart: 1, newLines: 4, lines: [' a', ' ', '-b', '+B', ' c'] }]);
|
|
66
|
+
await check('blank context line still inverts a modification', async () => {
|
|
67
|
+
await fsp.writeFile(abs(blankEditedName), 'a\n\nB\nc\n', 'utf8');
|
|
68
|
+
const targets = await planRewind(readDiffFrom({ '14:0': blankEditedDiff }), recordsFor([{ seq: 14, files: [{ path: blankEditedName, display: blankEditedName }] }]));
|
|
69
|
+
await applyRewind(targets);
|
|
70
|
+
assert.equal(await fsp.readFile(abs(blankEditedName), 'utf8'), 'a\n\nb\nc\n');
|
|
71
|
+
});
|
|
72
|
+
|
|
52
73
|
// --- a turn that modified a file is reverted -------------------------------
|
|
53
74
|
const editedName = 'edited.txt';
|
|
54
75
|
const editedDiff = textDiff(editedName, true, true, [{ oldStart: 1, oldLines: 3, newStart: 1, newLines: 3, lines: [' zero\n', ' one\n', '-two\n', '+TWO\n'] }]);
|
package/package.json
CHANGED
package/rewind.js
CHANGED
|
@@ -65,6 +65,19 @@ export function terminated(text) {
|
|
|
65
65
|
return text.endsWith('\n') ? text : `${text}\n`;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
/**
|
|
69
|
+
* One hunk line's body with its terminating newline. The recorder's jsdiff
|
|
70
|
+
* output drops the newline from every hunk line, so an empty body means one
|
|
71
|
+
* blank line rather than no line; older fixtures keep the newline. Both shapes
|
|
72
|
+
* must read as exactly one line ending.
|
|
73
|
+
* @param body - the text after the leading marker.
|
|
74
|
+
* @returns the body with one terminating newline.
|
|
75
|
+
*/
|
|
76
|
+
function lineText(body) {
|
|
77
|
+
if (body === '') return '\n';
|
|
78
|
+
return body.endsWith('\n') ? body : `${body}\n`;
|
|
79
|
+
}
|
|
80
|
+
|
|
68
81
|
/**
|
|
69
82
|
* Undo one recorded diff against the current text.
|
|
70
83
|
* A hunk carries only changed and context lines; unrelated trailing lines are retained.
|
|
@@ -84,7 +97,7 @@ export function inversePatch(current, hunks) {
|
|
|
84
97
|
cursor = start;
|
|
85
98
|
for (const line of hunk.lines) {
|
|
86
99
|
const marker = line[0];
|
|
87
|
-
const body =
|
|
100
|
+
const body = lineText(line.slice(1));
|
|
88
101
|
if (marker === '\\') throw userError('unsupported-diff', '无结尾换行的文件差异暂不支持,未回滚任何文件。');
|
|
89
102
|
if (marker === '+') {
|
|
90
103
|
if (lines[cursor] !== body) throw userError('file-changed', '文件版本已改变,未回滚任何文件。');
|
|
@@ -115,7 +128,7 @@ export function textSide(exists, hunks, after) {
|
|
|
115
128
|
for (const hunk of hunks) {
|
|
116
129
|
for (const line of hunk.lines) {
|
|
117
130
|
const wanted = after ? line[0] !== '-' : line[0] !== '+';
|
|
118
|
-
if (wanted && line[0] !== '\\') lines.push(
|
|
131
|
+
if (wanted && line[0] !== '\\') lines.push(lineText(line.slice(1)));
|
|
119
132
|
}
|
|
120
133
|
}
|
|
121
134
|
if (!exists) {
|
package/rewind.test.js
CHANGED
|
@@ -72,5 +72,18 @@ assert.equal(terminated(''), '');
|
|
|
72
72
|
assert.equal(inversePatch('abc', [{ oldStart: 0, oldLines: 0, newStart: 1, newLines: 1, lines: ['+abc'] }]), '');
|
|
73
73
|
const unterminated = [{ oldStart: 1, oldLines: 1, newStart: 1, newLines: 2, lines: [' x\n', '+y'] }];
|
|
74
74
|
assert.equal(inversePatch('x\ny', unterminated), 'x\n');
|
|
75
|
+
// The recorder's jsdiff output strips the newline from every hunk line, and an
|
|
76
|
+
// empty body is one blank line rather than no line; both shapes must invert.
|
|
77
|
+
const stripped = [{ oldStart: 1, oldLines: 4, newStart: 1, newLines: 4, lines: [' a', ' ', '-b', '+B', ' c'] }];
|
|
78
|
+
assert.equal(textSide(true, stripped, true), 'a\n\nB\nc\n');
|
|
79
|
+
assert.equal(textSide(true, stripped, false), 'a\n\nb\nc\n');
|
|
80
|
+
assert.equal(inversePatch('a\n\nB\nc\n', stripped), 'a\n\nb\nc\n');
|
|
81
|
+
const insertedBlank = [{ oldStart: 1, oldLines: 4, newStart: 1, newLines: 5, lines: [' a', ' ', ' b', '+', ' c'] }];
|
|
82
|
+
assert.equal(textSide(true, insertedBlank, true), 'a\n\nb\n\nc\n');
|
|
83
|
+
assert.equal(inversePatch('a\n\nb\n\nc\n', insertedBlank), 'a\n\nb\nc\n');
|
|
84
|
+
const createdBlank = [{ oldStart: 0, oldLines: 0, newStart: 1, newLines: 3, lines: ['+a', '+', '+b'] }];
|
|
85
|
+
assert.equal(textSide(true, createdBlank, true), 'a\n\nb\n');
|
|
86
|
+
assert.equal(textSide(false, createdBlank, false), null);
|
|
87
|
+
|
|
75
88
|
console.log('rewind self-check passed');
|
|
76
89
|
|