@fish-under-sea/dsh-approval-guide 2.0.2 → 2.1.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 +5 -5
- package/README.md +5 -5
- package/lib/client.js +70 -11
- package/package.json +2 -2
package/README.en.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @fish-under-sea/dsh-approval-guide
|
|
2
2
|
|
|
3
|
-
**2.
|
|
3
|
+
**2.1.1 · Approval Guide**
|
|
4
4
|
|
|
5
5
|
Adds Chinese action, risk and rationale notes to approval prompts.
|
|
6
6
|
|
|
@@ -12,15 +12,15 @@ Adds Chinese action, risk and rationale explanations to approval prompts for fil
|
|
|
12
12
|
|
|
13
13
|
### Empty-input send
|
|
14
14
|
|
|
15
|
-
When the composer is empty, clicking Send fills in and sends “继续任务,并梳理进度” (continue the task and summarize progress). Non-empty input, the Stop button, attachments, pending uploads and IME composition are untouched; re-entry is guarded and the button wait is bounded to about 816 ms before a single warning.
|
|
15
|
+
When the composer is empty, clicking Send fills in and sends “继续任务,并梳理进度” (continue the task and summarize progress). Non-empty input, the Stop button, attachments, pending uploads and IME composition are untouched; the three write fallbacks allow only one successful path and normalize the editor to a single copy before submit, so the sentence is never inserted twice; re-entry is guarded and the button wait is bounded to about 816 ms before a single warning.
|
|
16
16
|
|
|
17
17
|
## Installation
|
|
18
18
|
|
|
19
19
|
```sh
|
|
20
|
-
dsh plugin --profile <profile> add @fish-under-sea/dsh-approval-guide@2.
|
|
20
|
+
dsh plugin --profile <profile> add @fish-under-sea/dsh-approval-guide@2.1.1
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
Also included in `@fish-under-sea/dsh-fish@2.
|
|
23
|
+
Also included in `@fish-under-sea/dsh-fish@2.1.1`. Do not expand duplicate rows through both aggregate and standalone bundles. Restart DSH after installation; use the desktop plugin manager when no CLI is available.
|
|
24
24
|
|
|
25
25
|
## Configuration and Safety
|
|
26
26
|
|
|
@@ -30,6 +30,6 @@ Node requirement: `>=24.9`. Host compatibility follows this package manifest; th
|
|
|
30
30
|
|
|
31
31
|
## Maintenance and Attribution
|
|
32
32
|
|
|
33
|
-
2.
|
|
33
|
+
2.1.1 is a coordinated release number, not a claim that all latest upstream commits are merged. Historical documentation remains in Git; see [aggregate changelog](https://github.com/Fish-under-sea/dsh-fish/blob/main/CHANGELOG.en.md).
|
|
34
34
|
|
|
35
35
|
Fish-native plugin. License: MIT.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @fish-under-sea/dsh-approval-guide
|
|
2
2
|
|
|
3
|
-
**2.
|
|
3
|
+
**2.1.1 · 审批说明**
|
|
4
4
|
|
|
5
5
|
为审批弹窗补充中文动作、风险与依据说明。
|
|
6
6
|
|
|
@@ -12,15 +12,15 @@
|
|
|
12
12
|
|
|
13
13
|
### 空输入发送
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
输入框为空时,点击发送按钮会自动填入并发送「继续任务,并梳理进度」,省去先打字的步骤。非空输入、停止按钮、附件、上传中与输入法组合态都不接管;三级写入兜底只允许一个成功路径、提交前把内容收敛为唯一一份,避免同一句话被插入多次;重复点击有重入保护,按钮未及时可用时最多等待约 816ms 后放弃并只记录一次警告。
|
|
16
16
|
|
|
17
17
|
## 安装
|
|
18
18
|
|
|
19
19
|
```sh
|
|
20
|
-
dsh plugin --profile <profile> add @fish-under-sea/dsh-approval-guide@2.
|
|
20
|
+
dsh plugin --profile <profile> add @fish-under-sea/dsh-approval-guide@2.1.1
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
也可安装聚合包 `@fish-under-sea/dsh-fish@2.
|
|
23
|
+
也可安装聚合包 `@fish-under-sea/dsh-fish@2.1.1`。聚合与独立安装不要重复展开相同插件行;安装完成后重启 DSH。桌面环境无 CLI 时使用插件管理器。
|
|
24
24
|
|
|
25
25
|
## 配置与边界
|
|
26
26
|
|
|
@@ -30,6 +30,6 @@ Node 要求: `>=24.9`. DSH 支持范围以本包声明为准;聚合包不覆
|
|
|
30
30
|
|
|
31
31
|
## 维护与来源
|
|
32
32
|
|
|
33
|
-
2.
|
|
33
|
+
2.1.1 统一发布版本,不表示已合并上游所有最新提交。历史说明保留在 Git 历史中;聚合变更见 [聚合变更记录](https://github.com/Fish-under-sea/dsh-fish/blob/main/CHANGELOG.md).
|
|
34
34
|
|
|
35
35
|
Fish 原生插件。 许可证: MIT.
|
package/lib/client.js
CHANGED
|
@@ -348,21 +348,74 @@ window.__ModuleLoader__.load({
|
|
|
348
348
|
}
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
|
+
/** 统计 target 在 text 中出现的次数(忽略空白差异)。 */
|
|
352
|
+
function countOf(text, target) {
|
|
353
|
+
const hay = String(text ?? "").replace(/\s+/g, "");
|
|
354
|
+
const needle = String(target ?? "").replace(/\s+/g, "");
|
|
355
|
+
if (needle === "") return 0;
|
|
356
|
+
let count = 0;
|
|
357
|
+
let from = 0;
|
|
358
|
+
for (;;) {
|
|
359
|
+
const at = hay.indexOf(needle, from);
|
|
360
|
+
if (at < 0) break;
|
|
361
|
+
count += 1;
|
|
362
|
+
from = at + needle.length;
|
|
363
|
+
}
|
|
364
|
+
return count;
|
|
365
|
+
}
|
|
366
|
+
/** 直接写 DOM 再发 input:唯一的 DOM 兜底路径。 */
|
|
367
|
+
function setEditorDomText(editor, text, win) {
|
|
368
|
+
editor.textContent = text;
|
|
369
|
+
let input;
|
|
370
|
+
try {
|
|
371
|
+
input = new win.InputEvent("input", { bubbles: true, inputType: "insertText", data: text });
|
|
372
|
+
} catch {
|
|
373
|
+
input = new win.Event("input", { bubbles: true });
|
|
374
|
+
}
|
|
375
|
+
editor.dispatchEvent(input);
|
|
376
|
+
}
|
|
377
|
+
/** 把编辑器内容收敛为唯一一份固定文案(防止三级兜底各插一遍)。 */
|
|
378
|
+
function normalizeEditorText(editor, text, doc, win) {
|
|
379
|
+
const current = editorText(editor);
|
|
380
|
+
if (current.trim() === "") return false;
|
|
381
|
+
if (current.trim() === text) return true;
|
|
382
|
+
// 只剩空白差异或同一文案被插入多次:重写为唯一一份。
|
|
383
|
+
if (countOf(current, text) > 1 || current.trim().split(text).join("").trim() === "") {
|
|
384
|
+
try {
|
|
385
|
+
setEditorDomText(editor, text, win);
|
|
386
|
+
} catch {
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return editorText(editor).trim() !== "";
|
|
391
|
+
}
|
|
351
392
|
/**
|
|
352
393
|
* 把文本写进 Lexical 编辑器,三级兜底(每一级都不抛异常):
|
|
353
394
|
* 1) document.execCommand("insertText"):原生编辑命令,Lexical 会收到
|
|
354
395
|
* beforeinput/input,DOM 与内部状态一起更新 —— 首选。
|
|
355
396
|
* 2) 合成 paste 事件(带 text/plain):Lexical 的粘贴处理插入纯文本。
|
|
356
397
|
* 3) 直接写 DOM 再发 input 事件:最后的兜底,至少让用户可以接着手动发送。
|
|
398
|
+
*
|
|
399
|
+
* 关键:同一文本只允许一个路径真正写入。旧实现即使 execCommand 已经
|
|
400
|
+
* 插入成功,只要同步读不到文本就继续走 paste 与 DOM,结果一次点击把
|
|
401
|
+
* 一句话插了三遍(新版输入框的提交因此重复)。现在每一级成功后立即返回,
|
|
402
|
+
* 并在返回前把内容收敛为唯一一份。
|
|
357
403
|
* @returns 编辑器里是否真的出现了文本。
|
|
358
404
|
*/
|
|
359
405
|
function writeTextToEditor(editor, text, doc, win) {
|
|
406
|
+
// 已经有同一份文案:不再插入。
|
|
407
|
+
if (editorText(editor).trim() === text) return true;
|
|
408
|
+
// 已残留一份或更多:先收敛为一份,绝不追加。
|
|
409
|
+
if (countOf(editorText(editor), text) >= 1) return normalizeEditorText(editor, text, doc, win);
|
|
360
410
|
try {
|
|
361
|
-
if (typeof doc?.execCommand === "function" && doc.execCommand("insertText", false, text) === true
|
|
411
|
+
if (typeof doc?.execCommand === "function" && doc.execCommand("insertText", false, text) === true) {
|
|
412
|
+
normalizeEditorText(editor, text, doc, win);
|
|
413
|
+
return true;
|
|
414
|
+
}
|
|
362
415
|
} catch {
|
|
363
416
|
/* 下一级兜底 */
|
|
364
417
|
}
|
|
365
|
-
try {
|
|
418
|
+
if (editorText(editor).trim() === "") try {
|
|
366
419
|
let data;
|
|
367
420
|
if (typeof win?.DataTransfer === "function") {
|
|
368
421
|
data = new win.DataTransfer();
|
|
@@ -382,19 +435,15 @@ window.__ModuleLoader__.load({
|
|
|
382
435
|
}
|
|
383
436
|
}
|
|
384
437
|
editor.dispatchEvent(paste);
|
|
385
|
-
if (editorText(editor).trim() !== "")
|
|
438
|
+
if (editorText(editor).trim() !== "") {
|
|
439
|
+
normalizeEditorText(editor, text, doc, win);
|
|
440
|
+
return true;
|
|
441
|
+
}
|
|
386
442
|
} catch {
|
|
387
443
|
/* 下一级兜底 */
|
|
388
444
|
}
|
|
389
445
|
try {
|
|
390
|
-
editor
|
|
391
|
-
let input;
|
|
392
|
-
try {
|
|
393
|
-
input = new win.InputEvent("input", { bubbles: true, inputType: "insertText", data: text });
|
|
394
|
-
} catch {
|
|
395
|
-
input = new win.Event("input", { bubbles: true });
|
|
396
|
-
}
|
|
397
|
-
editor.dispatchEvent(input);
|
|
446
|
+
setEditorDomText(editor, text, win);
|
|
398
447
|
} catch {
|
|
399
448
|
return false;
|
|
400
449
|
}
|
|
@@ -414,6 +463,11 @@ window.__ModuleLoader__.load({
|
|
|
414
463
|
const doc = typeof document === "undefined" ? void 0 : document;
|
|
415
464
|
const win = typeof window === "undefined" ? void 0 : window;
|
|
416
465
|
if (doc === void 0 || win === void 0 || typeof doc.addEventListener !== "function" || typeof doc.querySelector !== "function" || typeof win.setTimeout !== "function" || typeof win.clearTimeout !== "function") return () => {};
|
|
466
|
+
// 同一页面只允许一份监听:插件热重载或重复 apply 时旧代码可能来不及
|
|
467
|
+
// 卸载,两个捕获监听会把同一次点击接管两遍,导致文案被插入两次。
|
|
468
|
+
const installKey = "__dshApprovalGuideEmptySend";
|
|
469
|
+
if (win[installKey] === true) return () => {};
|
|
470
|
+
win[installKey] = true;
|
|
417
471
|
let disposed = false;
|
|
418
472
|
let inFlight = false;
|
|
419
473
|
let timer = 0;
|
|
@@ -508,6 +562,10 @@ window.__ModuleLoader__.load({
|
|
|
508
562
|
}
|
|
509
563
|
timer = 0;
|
|
510
564
|
}
|
|
565
|
+
// 提交前最后一道去重:无论编辑器里残留几份,都收敛为一份再发。
|
|
566
|
+
const card = composerCardOf(button);
|
|
567
|
+
const editor = editorOf(card, doc);
|
|
568
|
+
if (editor !== null) normalizeEditorText(editor, EMPTY_SEND_TEXT, doc, win);
|
|
511
569
|
try {
|
|
512
570
|
button.click();
|
|
513
571
|
} catch {
|
|
@@ -589,6 +647,7 @@ window.__ModuleLoader__.load({
|
|
|
589
647
|
} catch {
|
|
590
648
|
/* 忽略 */
|
|
591
649
|
}
|
|
650
|
+
if (win[installKey] === true) win[installKey] = false;
|
|
592
651
|
};
|
|
593
652
|
}
|
|
594
653
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fish-under-sea/dsh-approval-guide",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"icon": "./icon.png",
|
|
5
5
|
"description": "在 DSH Web GUI 的审批弹窗里追加中文说明:这次审批会做什么、有什么风险、依据是什么。原英文理由与命令原文保留显示。",
|
|
6
6
|
"type": "module",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dsh": {
|
|
51
51
|
"engines": {
|
|
52
|
-
"dsh": ">=0.2.2-rc.
|
|
52
|
+
"dsh": ">=0.2.2-rc.3"
|
|
53
53
|
},
|
|
54
54
|
"bundle": {
|
|
55
55
|
"patch": "./cordis.patch.yml"
|