dsh-better-memo 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -2
- package/README.md +11 -15
- package/client.js +807 -59
- package/index.js +30 -1
- package/lib/store.js +24 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.0 — 2026-11-20
|
|
4
|
+
|
|
5
|
+
改成浮窗卡片(用户口径:不要整页)。
|
|
6
|
+
|
|
7
|
+
- **入口**:顶栏胶囊(slot `shell.overlay`)。没有该 slot 的环境退回右下角固定圆钮。
|
|
8
|
+
- **浮窗卡片**:点胶囊弹出,一条一条列三档备忘录(彩色圆点区分 session / profile / user),**点一条 = 直接复制**(`标题\n正文`),浮出「已复制」1.2 秒;点外部 / ESC / 再点胶囊关闭,退出走 160ms 动画后卸载。
|
|
9
|
+
- **设置页**:卡片右上角齿轮 → 同一个浮层切成整页模式(`min(720px,92vw) × min(80vh)`),里面是完整的三组管理界面(新增表单、勾完成、行内改、两次确认删)+ 开关「在会话 tab 行显示「备忘录」入口」。
|
|
10
|
+
- **tab 座位默认不显示**(`settings.showTabEntry = false`),只有打开开关才注册 `conversation.view` 座位;开关即时生效,不需要重启。
|
|
11
|
+
- 后端新增 `GET /better-memo/settings?showTabEntry=1|0`(marker 头 `x-better-memo: 1`),`/state` 现在带 `settings` 字段。
|
|
12
|
+
- 修:从设置页返回卡片时列表不刷新(现在返回即重取 state);输入框/下拉在深色主题下底色与宿主不一致。
|
|
13
|
+
|
|
3
14
|
## 0.1.0 — 2026-11-20
|
|
4
15
|
|
|
5
16
|
首版。
|
|
6
17
|
|
|
7
18
|
- 三层备忘录:`session`(本会话)/ `profile`(本 profile 所有会话)/ `user`(仅用户可见)。
|
|
8
19
|
- 两个 agent 工具:`memo_list` 查收、`memo_edit` 增改删。`user` 档不进 `memo_list`,也不接受工具写入。
|
|
9
|
-
- 浏览器半段:会话 tab 行新增「备忘录」座位,点开是面板——三组列表 + 常驻新增表单 + 行内改 + 两次确认删除。
|
|
10
20
|
- 存储:`$DSH_HOME/memo/memos.json`,原子写;上限 500 条,标题 120 字、正文 4000 字。
|
|
11
|
-
- 面板进入 / 列表错峰 / 删除退出三处动效,`prefers-reduced-motion` 下退化。
|
|
21
|
+
- 面板进入 / 列表错峰 / 删除退出三处动效,`prefers-reduced-motion` 下退化。
|
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# 备忘录 · dsh-better-memo
|
|
2
2
|
|
|
3
|
-
给 DeepSeek Harness
|
|
3
|
+
给 DeepSeek Harness 加一层**三层备忘录**:顶栏一个小胶囊,点开是浮窗卡片,一条一条列出来,**点一条就复制**。同一个面板里管三档归属,其中两档 AI 能读能改,第三档只有你自己看得到。
|
|
4
4
|
|
|
5
5
|
| 作用域 | 谁收得到 | AI 能看 | AI 能写 |
|
|
6
6
|
|---|---|---|---|
|
|
7
7
|
| **本会话** `session` | 只有这一个会话 | ✅ | ✅ |
|
|
8
8
|
| **本 profile** `profile` | 这个 profile 的所有会话 | ✅ | ✅ |
|
|
9
|
-
| **仅我可见** `user` |
|
|
9
|
+
| **仅我可见** `user` | 只有你自己 | ❌ 永远不返回 | ❌ 只有你能写 |
|
|
10
10
|
|
|
11
11
|
## 安装
|
|
12
12
|
|
|
@@ -18,34 +18,30 @@ dsh plugin --profile <你的 profile> add dsh-better-memo
|
|
|
18
18
|
|
|
19
19
|
## 用
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
- 顶上常驻新增表单:选作用域 → 填标题/正文 → 存下
|
|
25
|
-
- 每行可以勾完成、行内改、删(删除要点两次,3 秒内不确认自动恢复)
|
|
21
|
+
1. **顶栏胶囊**(窗口右上角,`备忘录`):点一下弹出浮窗卡片。
|
|
22
|
+
2. **浮窗卡片**:一条一条,左边彩色圆点区分三档(蓝=本会话 / 绿=本 profile / 黄=仅我可见)。**点一条 = 复制到剪贴板**(格式 `标题\n正文`),右下角浮出「已复制」。点卡片外面、按 ESC、或再点胶囊都能关。
|
|
23
|
+
3. **齿轮 → 设置页**:卡片右上角的齿轮点进去是整页模式,可以做全部管理(新增、勾完成、行内改、两次确认删),顶部有开关 **「在会话 tab 行显示「备忘录」入口」**,**默认关**。打开后会话 tab 行才出现「备忘录」座位,关掉立刻消失,不用重启。
|
|
26
24
|
|
|
27
25
|
## 给 AI 的两个工具
|
|
28
26
|
|
|
29
27
|
- **`memo_list`** —— 返回本会话该查收的条目:本会话的 `session` + 本 profile 的 `profile`,已勾完成的会过滤掉。**`仅我可见` 的条目永远不会出现在这里。**
|
|
30
28
|
- **`memo_edit`** —— `op=add|update|delete`。`add` 必须给 `scope`(`session` 或 `profile`);`update`/`delete` 要 `id`。只能改自己看得到的条目,跨会话或 `user` 条目会被拒。
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
> 会话开始时如果用户提到「备忘录 / 备忘 / 记一下 / 待办」,先调 `memo_list`。
|
|
30
|
+
会话开始时若用户提到「备忘录 / 备忘 / 记一下 / 待办」,会先调 `memo_list`(插件自带这段系统提示,一般不用再写)。
|
|
35
31
|
|
|
36
32
|
## 数据放哪
|
|
37
33
|
|
|
38
34
|
`$DSH_HOME/memo/memos.json`(`DSH_HOME` 缺省 `~/.dsh`),一个 JSON 文件,原子写。删掉它等于清空全部备忘录。
|
|
39
35
|
|
|
40
|
-
条目上限 500 条;标题 120 字、正文 4000
|
|
36
|
+
条目上限 500 条;标题 120 字、正文 4000 字(超出截断)。插件自己的开关(`showTabEntry`)也在这个文件的 `settings` 里。
|
|
41
37
|
|
|
42
38
|
## 已知限制
|
|
43
39
|
|
|
44
|
-
-
|
|
45
|
-
-
|
|
46
|
-
- profile 档只在本 profile
|
|
40
|
+
- **复制依赖窗口焦点**:用的是 `navigator.clipboard.writeText`,失败时退回 `document.execCommand('copy')`;两个都失败会明确显示「复制失败」,不会假装成功。窗口失焦的后台环境两个都会失败(这是浏览器的规矩,不是插件 bug)。
|
|
41
|
+
- 顶栏胶囊固定在 `top:6px; right:150px`,没有按窗口控件实测对齐;如果没有 `shell.overlay` 槽(个别环境),入口会退化成右下角的固定圆钮。
|
|
42
|
+
- 单机单文件,没有多端同步;profile 档只在本 profile 内共享。
|
|
47
43
|
- 没有提醒/定时:这不是提醒插件,是备忘录。
|
|
48
44
|
|
|
49
45
|
## License
|
|
50
46
|
|
|
51
|
-
MIT
|
|
47
|
+
MIT
|
package/client.js
CHANGED
|
@@ -1,45 +1,59 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* dsh-better-memo — Client half.
|
|
2
|
+
* dsh-better-memo — Client half (0.2.0 popout form).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Shape: a top-bar capsule (slot shell.overlay) opens a floating card list;
|
|
5
|
+
* every row copies its memo to the clipboard on click. The gear turns the same
|
|
6
|
+
* overlay into a centered management page (the three-scope CRUD UI) whose first
|
|
7
|
+
* row carries the showTabEntry switch. When that switch is on, a
|
|
8
|
+
* conversation.view tab seat is registered; when off, it is disposed. When
|
|
9
|
+
* shell.overlay is not declared (plain web) the capsule falls back to a fixed
|
|
10
|
+
* round button in the bottom-right corner of document.body.
|
|
9
11
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* Hard constraints held here on purpose (each has burned a release before):
|
|
13
|
+
* - every declaration lives inside factory(): the host concatenates every
|
|
14
|
+
* plugin client into ONE module, so a top-level const collides and the whole
|
|
15
|
+
* page dies with "Identifier X has already been declared".
|
|
16
|
+
* - CSS is plain string concatenation, never a template literal: one stray
|
|
17
|
+
* backtick truncates the file and the bundle fails to parse.
|
|
18
|
+
* - ctx.get('slots') is used instead of ctx.slots (property access throws
|
|
19
|
+
* when the service is not injected, and the whole entry shows "failed").
|
|
20
|
+
* - no native confirm; no background on the 40px drag band; the capsule is
|
|
21
|
+
* -webkit-app-region:no-drag.
|
|
15
22
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* DO NOT introduce a top-level declaration, a template literal in the CSS, or a
|
|
21
|
-
* native confirm dialog (deletes use an inline two-step confirm instead).
|
|
23
|
+
* Data path: GET /better-memo/state?sessionId=…, GET /better-memo/write?… and
|
|
24
|
+
* GET /better-memo/settings?showTabEntry=1|0 — all with the x-better-memo: 1
|
|
25
|
+
* marker. Writes answer the full fresh state payload, which the panels swap in.
|
|
22
26
|
*/
|
|
23
27
|
window.__ModuleLoader__.load({
|
|
24
28
|
id: 'dsh-better-memo',
|
|
25
29
|
factory(require) {
|
|
26
30
|
const React = require('react');
|
|
27
31
|
const h = React.createElement;
|
|
32
|
+
const ReactDOM = require('react-dom');
|
|
33
|
+
const ReactDOMClient = require('react-dom/client');
|
|
28
34
|
|
|
29
35
|
const NS = 'better-memo';
|
|
30
|
-
const VERSION = '0.
|
|
36
|
+
const VERSION = '0.2.0';
|
|
31
37
|
const SLOT = 'conversation.view';
|
|
32
38
|
const SEAT_ID = 'better-memo-seat';
|
|
39
|
+
const TOPBAR_SLOT = 'shell.overlay';
|
|
40
|
+
const CAPSULE_ID = 'better-memo.capsule';
|
|
41
|
+
const FALLBACK_HOST_ID = 'better-memo-overlay-fallback';
|
|
33
42
|
const ROUTE = '/better-memo';
|
|
34
43
|
const MARKER = { 'x-better-memo': '1' };
|
|
35
44
|
const STYLE_ID = 'better-memo-style';
|
|
36
45
|
const CONFIRM_MS = 3000;
|
|
37
46
|
const OUT_MS = 160;
|
|
38
|
-
const MAX_STAGGER = 8;
|
|
39
47
|
const STAGGER_MS = 40;
|
|
48
|
+
/* (MAX_STAGGER - 1) * STAGGER_MS = 280ms, the spec's stagger cap. */
|
|
49
|
+
const MAX_STAGGER = 8;
|
|
50
|
+
const COPY_MS = 1200;
|
|
51
|
+
const RETRY_LIMIT = 20;
|
|
52
|
+
const RETRY_MS = 250;
|
|
40
53
|
|
|
41
54
|
const FALLBACK_LIMITS = { title: 120, body: 4000, entries: 500 };
|
|
42
55
|
const GROUP_LABEL = { session: '本会话', profile: '本 profile', user: '仅我可见' };
|
|
56
|
+
const SCOPE_TAG = { session: '会话', profile: '共享', user: '私人' };
|
|
43
57
|
const HINT_TEXT =
|
|
44
58
|
'本会话只在本会话里出现;本 profile 会出现在同一 profile 的所有会话;' +
|
|
45
59
|
'仅我可见只有你自己在这个面板里看得到,AI 读不到,也改不了。';
|
|
@@ -50,6 +64,7 @@ window.__ModuleLoader__.load({
|
|
|
50
64
|
/* CSS is plain string concatenation on purpose: a template literal here would
|
|
51
65
|
let an accidental backtick truncate the file and break the whole bundle. */
|
|
52
66
|
const CSS = [
|
|
67
|
+
/* ---- management UI (unchanged from 0.1.0) ---- */
|
|
53
68
|
'.bm-panel{display:flex;flex-direction:column;gap:14px;padding:16px 20px;font-size:13px;color:inherit;box-sizing:border-box;animation:bm-enter-frames 200ms cubic-bezier(.22,1,.36,1) both}',
|
|
54
69
|
'.bm-panel *{box-sizing:border-box}',
|
|
55
70
|
'.bm-head{display:flex;align-items:center;gap:6px}',
|
|
@@ -66,9 +81,9 @@ window.__ModuleLoader__.load({
|
|
|
66
81
|
'.bm-form{display:flex;flex-direction:column;gap:8px;padding:12px;border-radius:10px;background:var(--dsw-alias-bg-l2,rgba(127,127,127,.07));border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.16))}',
|
|
67
82
|
'.bm-form-top{display:flex;gap:8px;align-items:center}',
|
|
68
83
|
'.bm-field{display:flex;align-items:center;gap:6px;font-size:12px;color:var(--dsw-alias-label-secondary,#8a8f98)}',
|
|
69
|
-
'.bm-input{font:inherit;font-size:13px;width:100%;border-radius:8px;border:1px solid var(--dsw-alias-border-l4,rgba(127,127,127,.32));background:var(--dsw-alias-bg-
|
|
84
|
+
'.bm-input{font:inherit;font-size:13px;width:100%;border-radius:8px;border:1px solid var(--dsw-alias-border-l4,rgba(127,127,127,.32));background:var(--dsw-alias-bg-l2,rgba(127,127,127,.10));color:inherit;padding:8px 10px}',
|
|
70
85
|
'.bm-input:focus{outline:none;border-color:var(--dsw-alias-accent,#3b82f6)}',
|
|
71
|
-
'.bm-select{font:inherit;font-size:13px;border-radius:8px;border:1px solid var(--dsw-alias-border-l4,rgba(127,127,127,.32));background:var(--dsw-alias-bg-
|
|
86
|
+
'.bm-select{font:inherit;font-size:13px;border-radius:8px;border:1px solid var(--dsw-alias-border-l4,rgba(127,127,127,.32));background:var(--dsw-alias-bg-l2,rgba(127,127,127,.10));color:inherit;padding:6px 8px}',
|
|
72
87
|
'.bm-textarea{resize:vertical;min-height:58px;line-height:19px}',
|
|
73
88
|
'.bm-form-actions{display:flex;justify-content:flex-end;gap:8px}',
|
|
74
89
|
'.bm-note{margin:0;font-size:11px;color:var(--dsw-alias-label-tertiary,#9aa0a6)}',
|
|
@@ -91,17 +106,65 @@ window.__ModuleLoader__.load({
|
|
|
91
106
|
'.bm-error{display:flex;align-items:center;gap:10px;padding:10px 12px;border-radius:8px;border:1px solid var(--dsw-alias-danger,#e5484d);color:var(--dsw-alias-danger,#e5484d);font-size:12px}',
|
|
92
107
|
'.bm-error-spacer{flex:1 1 auto}',
|
|
93
108
|
'.bm-loading{margin:0;font-size:12px;color:var(--dsw-alias-label-secondary,#8a8f98)}',
|
|
94
|
-
|
|
109
|
+
/* ---- entry capsule ---- */
|
|
110
|
+
'.bm-capsule{position:fixed;top:6px;right:150px;z-index:2147483000;display:inline-flex;align-items:center;gap:6px;height:28px;padding:0 12px;border-radius:14px;border:1px solid var(--dsw-alias-border-l3,rgba(127,127,127,.36));background:var(--dsw-alias-bg-l1,rgba(40,42,52,.92));color:var(--dsw-alias-label-primary,inherit);font:inherit;font-size:12px;line-height:1;cursor:pointer;pointer-events:auto;-webkit-app-region:no-drag;box-shadow:0 2px 10px rgba(0,0,0,.18)}',
|
|
111
|
+
'.bm-capsule:hover{border-color:var(--dsw-alias-border-l2,rgba(127,127,127,.55))}',
|
|
112
|
+
'.bm-capsule[data-bm-open="1"]{border-color:var(--dsw-alias-accent,#3b82f6)}',
|
|
113
|
+
'.bm-capsule-floating{top:auto;right:16px;bottom:16px;height:40px;min-width:40px;padding:0 14px;border-radius:20px;box-shadow:0 6px 20px rgba(0,0,0,.28)}',
|
|
114
|
+
'.bm-capsule-label{font-weight:500;white-space:nowrap}',
|
|
115
|
+
'.bm-capsule-count{min-width:16px;height:16px;padding:0 4px;border-radius:8px;background:var(--dsw-alias-accent,#3b82f6);color:#fff;font-size:10px;line-height:16px;text-align:center}',
|
|
116
|
+
/* ---- floating card ---- */
|
|
117
|
+
'.bm-card{position:fixed;top:40px;right:150px;width:320px;max-height:60vh;z-index:2147483100;display:flex;flex-direction:column;border-radius:12px;border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.22));background:var(--dsw-alias-bg-l1,#26262e);color:var(--dsw-alias-label-primary,inherit);box-shadow:0 18px 48px rgba(0,0,0,.4);overflow:hidden;pointer-events:auto;-webkit-app-region:no-drag;animation:bm-enter-frames 200ms cubic-bezier(.22,1,.36,1) both}',
|
|
118
|
+
'.bm-card-floating{top:auto;right:16px;bottom:64px}',
|
|
119
|
+
'.bm-card-out{animation:bm-out-frames 160ms cubic-bezier(.4,0,1,1) forwards;pointer-events:none}',
|
|
120
|
+
'.bm-card-head{display:flex;align-items:center;gap:6px;padding:10px 12px;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.16))}',
|
|
121
|
+
'.bm-card-title{font-size:13px;font-weight:600}',
|
|
122
|
+
'.bm-card-count{font-size:11px;color:var(--dsw-alias-label-secondary,#8a8f98)}',
|
|
123
|
+
'.bm-card-spacer{flex:1 1 auto}',
|
|
124
|
+
'.bm-card-gear{display:inline-flex;align-items:center;justify-content:center;width:26px;height:26px;padding:0;border-radius:7px;border:1px solid transparent;background:transparent;color:var(--dsw-alias-label-secondary,#8a8f98);cursor:pointer}',
|
|
125
|
+
'.bm-card-gear:hover{background:var(--dsw-alias-bg-l2,rgba(127,127,127,.1));color:var(--dsw-alias-label-primary,inherit)}',
|
|
126
|
+
'.bm-card-body{display:flex;flex-direction:column;gap:6px;padding:8px;overflow:auto}',
|
|
127
|
+
'.bm-card-empty{margin:0;padding:16px 8px;text-align:center;font-size:12px;color:var(--dsw-alias-label-tertiary,#9aa0a6)}',
|
|
128
|
+
'.bm-card-error{display:flex;align-items:center;gap:8px;padding:10px;border-radius:8px;border:1px solid var(--dsw-alias-danger,#e5484d);color:var(--dsw-alias-danger,#e5484d);font-size:12px}',
|
|
129
|
+
'.bm-card-item{display:flex;align-items:flex-start;gap:8px;width:100%;text-align:left;padding:8px 10px;border-radius:8px;border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.14));background:var(--dsw-alias-bg-l2,rgba(127,127,127,.05));color:inherit;font:inherit;cursor:pointer;animation:bm-item-frames 240ms cubic-bezier(.22,1,.36,1) both}',
|
|
130
|
+
'.bm-card-item:hover{border-color:var(--dsw-alias-accent,#3b82f6);background:var(--dsw-alias-bg-l2,rgba(127,127,127,.12))}',
|
|
131
|
+
'.bm-card-dot{flex:0 0 auto;width:8px;height:8px;margin-top:2px;border-radius:50%;background:var(--dsw-alias-label-tertiary,#9aa0a6)}',
|
|
132
|
+
'.bm-card-dot[data-bm-scope="session"]{background:#3b82f6}',
|
|
133
|
+
'.bm-card-dot[data-bm-scope="profile"]{background:#22c55e}',
|
|
134
|
+
'.bm-card-dot[data-bm-scope="user"]{background:#f59e0b}',
|
|
135
|
+
'.bm-card-item-text{display:flex;flex-direction:column;gap:1px;flex:1 1 auto;min-width:0}',
|
|
136
|
+
'.bm-card-item-title{font-size:12.5px;font-weight:500;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
|
|
137
|
+
'.bm-card-item-sub{font-size:11px;color:var(--dsw-alias-label-secondary,#8a8f98);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
|
|
138
|
+
'.bm-card-tag{flex:0 0 auto;font-size:10px;color:var(--dsw-alias-label-tertiary,#9aa0a6);align-self:center}',
|
|
139
|
+
'.bm-card-toast{position:absolute;right:12px;bottom:10px;padding:6px 12px;border-radius:14px;background:var(--dsw-alias-accent,#3b82f6);color:#fff;font-size:12px;line-height:1;box-shadow:0 6px 18px rgba(0,0,0,.3);animation:bm-fade-frames 120ms ease both}',
|
|
140
|
+
/* ---- full page management mode ---- */
|
|
141
|
+
'.bm-overlay-backdrop{position:fixed;inset:0;z-index:2147483200;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,.34);pointer-events:auto;-webkit-app-region:no-drag}',
|
|
142
|
+
'.bm-page{display:flex;flex-direction:column;width:min(720px,92vw);height:min(80vh,80vh);max-height:80vh;border-radius:14px;border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.24));background:var(--dsw-alias-bg-l1,#26262e);color:var(--dsw-alias-label-primary,inherit);box-shadow:0 28px 72px rgba(0,0,0,.5);overflow:hidden;animation:bm-enter-frames 200ms cubic-bezier(.22,1,.36,1) both}',
|
|
143
|
+
'.bm-page-head{display:flex;align-items:center;gap:8px;padding:10px 14px;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.18))}',
|
|
144
|
+
'.bm-page-back{font-size:12px}',
|
|
145
|
+
'.bm-page-title{font-size:14px;font-weight:600}',
|
|
146
|
+
'.bm-page-spacer{flex:1 1 auto}',
|
|
147
|
+
'.bm-page-close{font-size:18px;line-height:1;padding:4px 10px}',
|
|
148
|
+
'.bm-page-switch{display:flex;align-items:center;gap:10px;padding:10px 16px;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.14));flex-wrap:wrap}',
|
|
149
|
+
'.bm-switch{display:inline-flex;align-items:center;gap:8px;font-size:12.5px;cursor:pointer}',
|
|
150
|
+
'.bm-switch input{cursor:pointer;margin:0}',
|
|
151
|
+
'.bm-switch-error{font-size:11px;color:var(--dsw-alias-danger,#e5484d)}',
|
|
152
|
+
'.bm-page-body{flex:1 1 auto;overflow:auto;min-height:0}',
|
|
153
|
+
/* ---- keyframes ---- */
|
|
154
|
+
'@keyframes bm-enter-frames{from{opacity:0;transform:translateY(8px) scale(.98)}to{opacity:1;transform:none}}',
|
|
95
155
|
'@keyframes bm-item-frames{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}',
|
|
96
|
-
'@keyframes bm-out-frames{to{opacity:0;transform:scale(.
|
|
156
|
+
'@keyframes bm-out-frames{from{opacity:1;transform:none}to{opacity:0;transform:scale(.96)}}',
|
|
97
157
|
'@keyframes bm-fade-frames{from{opacity:0}to{opacity:1}}',
|
|
98
|
-
'@
|
|
158
|
+
'@keyframes bm-fade-out-frames{to{opacity:0}}',
|
|
159
|
+
/* reduced motion: opacity only, no displacement, no stagger. */
|
|
160
|
+
'@media (prefers-reduced-motion: reduce){.bm-panel,.bm-row:not(.bm-row-out){animation-name:bm-fade-frames !important;animation-duration:120ms !important;animation-delay:0ms !important}.bm-card,.bm-card-item,.bm-page{animation-name:bm-fade-frames !important;animation-duration:120ms !important;animation-delay:0ms !important}.bm-card-out{animation:bm-fade-out-frames 120ms linear forwards !important}.bm-row-out{animation:bm-out-frames 1ms linear forwards !important}}',
|
|
99
161
|
].join('\n');
|
|
100
162
|
|
|
101
163
|
function injectStyle() {
|
|
102
164
|
if (styleInjected === true) return;
|
|
103
165
|
styleInjected = true;
|
|
104
166
|
try {
|
|
167
|
+
if (typeof document === 'undefined') return;
|
|
105
168
|
if (document.getElementById(STYLE_ID) !== null) return;
|
|
106
169
|
const style = document.createElement('style');
|
|
107
170
|
style.id = STYLE_ID;
|
|
@@ -167,14 +230,162 @@ window.__ModuleLoader__.load({
|
|
|
167
230
|
return payload;
|
|
168
231
|
}
|
|
169
232
|
|
|
233
|
+
/** Persist showTabEntry. GET + query (the host webserver only answers GET/HEAD). */
|
|
234
|
+
async function requestSettings(showTabEntry) {
|
|
235
|
+
const query = queryOf({ showTabEntry: showTabEntry === true ? '1' : '0' });
|
|
236
|
+
const response = await fetch(ROUTE + '/settings?' + query, { method: 'GET', headers: MARKER });
|
|
237
|
+
let payload = null;
|
|
238
|
+
try {
|
|
239
|
+
payload = await response.json();
|
|
240
|
+
} catch (thrown) {
|
|
241
|
+
payload = null;
|
|
242
|
+
}
|
|
243
|
+
if (response.ok === false || payload === null || payload.ok === false) {
|
|
244
|
+
const reason = payload && payload.reason ? payload.reason : 'HTTP ' + response.status;
|
|
245
|
+
const detail = payload && payload.error ? ':' + payload.error : '';
|
|
246
|
+
throw new Error(reason + detail);
|
|
247
|
+
}
|
|
248
|
+
return payload;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** Read {showTabEntry} out of a state or settings payload; missing settings means off. */
|
|
252
|
+
function settingsOf(source) {
|
|
253
|
+
const settings = source && typeof source === 'object' && source.settings && typeof source.settings === 'object'
|
|
254
|
+
? source.settings
|
|
255
|
+
: null;
|
|
256
|
+
return { showTabEntry: settings !== null && settings.showTabEntry === true };
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** The id of the session currently shown in the main view, or '' when unknown. */
|
|
260
|
+
function currentSessionId(ctx) {
|
|
261
|
+
try {
|
|
262
|
+
const sessions = typeof ctx.get === 'function' ? ctx.get('sessions') : undefined;
|
|
263
|
+
if (!sessions || !sessions.list || typeof sessions.list.getSnapshot !== 'function') return '';
|
|
264
|
+
const snapshot = sessions.list.getSnapshot();
|
|
265
|
+
const byId = snapshot && snapshot.byId ? snapshot.byId : null;
|
|
266
|
+
if (!byId) return '';
|
|
267
|
+
const ids = Object.keys(byId);
|
|
268
|
+
for (let index = 0; index < ids.length; index += 1) {
|
|
269
|
+
const record = byId[ids[index]];
|
|
270
|
+
const retained = record && record.retainedBy ? record.retainedBy : null;
|
|
271
|
+
if (retained && (retained.mainView | 0) > 0) return ids[index];
|
|
272
|
+
}
|
|
273
|
+
return '';
|
|
274
|
+
} catch (thrown) {
|
|
275
|
+
return '';
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function displayTitleOf(entry) {
|
|
280
|
+
if (entry && typeof entry.title === 'string' && entry.title !== '') return entry.title;
|
|
281
|
+
const first = String(entry && entry.body ? entry.body : '').split('\n')[0].trim();
|
|
282
|
+
if (first === '') return '(无标题)';
|
|
283
|
+
return first.length > 40 ? first.slice(0, 40) + '…' : first;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function bodyFirstLine(entry) {
|
|
287
|
+
const body = entry && typeof entry.body === 'string' ? entry.body : '';
|
|
288
|
+
const first = body.split('\n')[0].trim();
|
|
289
|
+
return first.length > 48 ? first.slice(0, 48) + '…' : first;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** The clipboard text for one memo: 标题 newline 正文. */
|
|
293
|
+
function buildCopyText(entry) {
|
|
294
|
+
const body = entry && typeof entry.body === 'string' ? entry.body : '';
|
|
295
|
+
let title = entry && typeof entry.title === 'string' && entry.title !== '' ? entry.title : '';
|
|
296
|
+
if (title === '') {
|
|
297
|
+
const first = body.split('\n')[0].trim();
|
|
298
|
+
title = first.length > 40 ? first.slice(0, 40) + '…' : first || '(无标题)';
|
|
299
|
+
}
|
|
300
|
+
return body === '' ? title : title + '\n' + body;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** Clipboard write: async Clipboard API first, then execCommand plus a temp textarea. */
|
|
304
|
+
async function copyTextToClipboard(text) {
|
|
305
|
+
const value = String(text);
|
|
306
|
+
try {
|
|
307
|
+
const nav = typeof navigator !== 'undefined' ? navigator : null;
|
|
308
|
+
if (nav && nav.clipboard && typeof nav.clipboard.writeText === 'function') {
|
|
309
|
+
await nav.clipboard.writeText(value);
|
|
310
|
+
return true;
|
|
311
|
+
}
|
|
312
|
+
} catch (thrown) {
|
|
313
|
+
/* Clipboard API rejected (permissions / insecure context): use the fallback. */
|
|
314
|
+
}
|
|
315
|
+
try {
|
|
316
|
+
if (typeof document === 'undefined') return false;
|
|
317
|
+
const area = document.createElement('textarea');
|
|
318
|
+
area.value = value;
|
|
319
|
+
area.setAttribute('readonly', '');
|
|
320
|
+
area.style.position = 'fixed';
|
|
321
|
+
area.style.top = '-1000px';
|
|
322
|
+
area.style.left = '-1000px';
|
|
323
|
+
area.style.opacity = '0';
|
|
324
|
+
(document.body || document.documentElement).appendChild(area);
|
|
325
|
+
let ok = false;
|
|
326
|
+
try {
|
|
327
|
+
area.select();
|
|
328
|
+
ok = document.execCommand('copy') === true;
|
|
329
|
+
} catch (thrown) {
|
|
330
|
+
ok = false;
|
|
331
|
+
}
|
|
332
|
+
if (area.parentNode) area.parentNode.removeChild(area);
|
|
333
|
+
return ok;
|
|
334
|
+
} catch (thrown) {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function gearIcon() {
|
|
340
|
+
return h(
|
|
341
|
+
'svg',
|
|
342
|
+
{
|
|
343
|
+
width: 16,
|
|
344
|
+
height: 16,
|
|
345
|
+
viewBox: '0 0 24 24',
|
|
346
|
+
fill: 'none',
|
|
347
|
+
stroke: 'currentColor',
|
|
348
|
+
strokeWidth: 1.8,
|
|
349
|
+
strokeLinecap: 'round',
|
|
350
|
+
strokeLinejoin: 'round',
|
|
351
|
+
'aria-hidden': 'true',
|
|
352
|
+
},
|
|
353
|
+
[
|
|
354
|
+
h('circle', { key: 'c', cx: 12, cy: 12, r: 3 }),
|
|
355
|
+
h('path', {
|
|
356
|
+
key: 'p',
|
|
357
|
+
d:
|
|
358
|
+
'M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z',
|
|
359
|
+
}),
|
|
360
|
+
],
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** Flatten the three scopes into one card list, session then profile then user. */
|
|
365
|
+
function flattenEntries(payload) {
|
|
366
|
+
const out = [];
|
|
367
|
+
if (!payload) return out;
|
|
368
|
+
const scopes = ['session', 'profile', 'user'];
|
|
369
|
+
for (let s = 0; s < scopes.length; s += 1) {
|
|
370
|
+
const scope = scopes[s];
|
|
371
|
+
const rows = Array.isArray(payload[scope]) ? payload[scope] : [];
|
|
372
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
373
|
+
out.push({ entry: rows[index], scope: scope });
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return out;
|
|
377
|
+
}
|
|
378
|
+
|
|
170
379
|
/**
|
|
171
|
-
* The
|
|
172
|
-
*
|
|
380
|
+
* The management UI (three scopes, add form, done toggle, inline edit, two
|
|
381
|
+
* step delete). Rendered as the tab seat (embedded=false, with its own head)
|
|
382
|
+
* or inside the overlay page (embedded=true, head supplied by the page).
|
|
173
383
|
*/
|
|
174
|
-
function
|
|
384
|
+
function MemoPanel(props) {
|
|
175
385
|
injectStyle();
|
|
176
386
|
|
|
177
387
|
const sessionId = props && typeof props.sessionId === 'string' ? props.sessionId : '';
|
|
388
|
+
const embedded = props && props.embedded === true;
|
|
178
389
|
const hasSession = sessionId !== '';
|
|
179
390
|
|
|
180
391
|
const [payload, setPayload] = React.useState(null);
|
|
@@ -332,13 +543,6 @@ window.__ModuleLoader__.load({
|
|
|
332
543
|
}, wait);
|
|
333
544
|
}
|
|
334
545
|
|
|
335
|
-
function displayTitle(entry) {
|
|
336
|
-
if (typeof entry.title === 'string' && entry.title !== '') return entry.title;
|
|
337
|
-
const first = String(entry.body || '').split('\n')[0].trim();
|
|
338
|
-
if (first === '') return '(无标题)';
|
|
339
|
-
return first.length > 40 ? first.slice(0, 40) + '…' : first;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
546
|
function renderHead() {
|
|
343
547
|
return h('div', { key: 'head', className: 'bm-head' }, [
|
|
344
548
|
h('span', { key: 'title', className: 'bm-title' }, '备忘录'),
|
|
@@ -523,7 +727,7 @@ window.__ModuleLoader__.load({
|
|
|
523
727
|
h(
|
|
524
728
|
'span',
|
|
525
729
|
{ key: 't', className: entry.done === true ? 'bm-row-title bm-done' : 'bm-row-title' },
|
|
526
|
-
|
|
730
|
+
displayTitleOf(entry),
|
|
527
731
|
),
|
|
528
732
|
]),
|
|
529
733
|
]),
|
|
@@ -622,8 +826,8 @@ window.__ModuleLoader__.load({
|
|
|
622
826
|
'data-better-memo-version': VERSION,
|
|
623
827
|
},
|
|
624
828
|
[
|
|
625
|
-
renderHead(),
|
|
626
|
-
showHint ? h('p', { key: 'hint', className: 'bm-hint' }, HINT_TEXT) : null,
|
|
829
|
+
embedded ? null : renderHead(),
|
|
830
|
+
!embedded && showHint ? h('p', { key: 'hint', className: 'bm-hint' }, HINT_TEXT) : null,
|
|
627
831
|
renderForm(),
|
|
628
832
|
error !== null ? renderError() : null,
|
|
629
833
|
loading && payload === null ? h('p', { key: 'loading', className: 'bm-loading' }, '加载中…') : null,
|
|
@@ -641,12 +845,538 @@ window.__ModuleLoader__.load({
|
|
|
641
845
|
}
|
|
642
846
|
|
|
643
847
|
/**
|
|
644
|
-
*
|
|
645
|
-
* and
|
|
646
|
-
*
|
|
848
|
+
* The overlay: capsule button plus either the floating card or the full page.
|
|
849
|
+
* Both card and page are portalled to document.body so a fixed position is
|
|
850
|
+
* never trapped by the shell.overlay container's stacking context.
|
|
647
851
|
*/
|
|
852
|
+
function OverlayEntry(props) {
|
|
853
|
+
injectStyle();
|
|
854
|
+
|
|
855
|
+
const getSessionId = props && typeof props.getSessionId === 'function' ? props.getSessionId : function () { return ''; };
|
|
856
|
+
const seat = props && props.seat ? props.seat : null;
|
|
857
|
+
const variant = props && props.variant === 'floating' ? 'floating' : 'topbar';
|
|
858
|
+
|
|
859
|
+
const [phase, setPhase] = React.useState('closed');
|
|
860
|
+
const [closing, setClosing] = React.useState(false);
|
|
861
|
+
const [payload, setPayload] = React.useState(null);
|
|
862
|
+
const [loading, setLoading] = React.useState(false);
|
|
863
|
+
const [error, setError] = React.useState(null);
|
|
864
|
+
const [settings, setSettings] = React.useState({ showTabEntry: false });
|
|
865
|
+
const [settingsSaving, setSettingsSaving] = React.useState(false);
|
|
866
|
+
const [settingsError, setSettingsError] = React.useState(null);
|
|
867
|
+
const [toast, setToast] = React.useState(null);
|
|
868
|
+
const [sessionId, setSessionId] = React.useState('');
|
|
869
|
+
|
|
870
|
+
const cardRef = React.useRef(null);
|
|
871
|
+
const capsuleRef = React.useRef(null);
|
|
872
|
+
const toastTimer = React.useRef(null);
|
|
873
|
+
|
|
874
|
+
function fetchState(sid) {
|
|
875
|
+
setLoading(true);
|
|
876
|
+
setError(null);
|
|
877
|
+
requestState(sid)
|
|
878
|
+
.then(function (next) {
|
|
879
|
+
setPayload(next);
|
|
880
|
+
setSettings(settingsOf(next));
|
|
881
|
+
setLoading(false);
|
|
882
|
+
})
|
|
883
|
+
.catch(function (thrown) {
|
|
884
|
+
setError(messageOf(thrown));
|
|
885
|
+
setLoading(false);
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
React.useEffect(function () {
|
|
890
|
+
const sid = getSessionId();
|
|
891
|
+
setSessionId(sid);
|
|
892
|
+
requestState(sid)
|
|
893
|
+
.then(function (next) {
|
|
894
|
+
setPayload(next);
|
|
895
|
+
setSettings(settingsOf(next));
|
|
896
|
+
})
|
|
897
|
+
.catch(function () {
|
|
898
|
+
/* the capsule still opens; its first refresh will retry */
|
|
899
|
+
});
|
|
900
|
+
return function () {
|
|
901
|
+
if (toastTimer.current !== null) {
|
|
902
|
+
clearTimeout(toastTimer.current);
|
|
903
|
+
toastTimer.current = null;
|
|
904
|
+
}
|
|
905
|
+
};
|
|
906
|
+
}, []);
|
|
907
|
+
|
|
908
|
+
React.useEffect(
|
|
909
|
+
function () {
|
|
910
|
+
if (toast === null) return undefined;
|
|
911
|
+
if (toastTimer.current !== null) clearTimeout(toastTimer.current);
|
|
912
|
+
toastTimer.current = setTimeout(function () {
|
|
913
|
+
toastTimer.current = null;
|
|
914
|
+
setToast(null);
|
|
915
|
+
}, COPY_MS);
|
|
916
|
+
return function () {
|
|
917
|
+
if (toastTimer.current !== null) {
|
|
918
|
+
clearTimeout(toastTimer.current);
|
|
919
|
+
toastTimer.current = null;
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
},
|
|
923
|
+
[toast],
|
|
924
|
+
);
|
|
925
|
+
|
|
926
|
+
function openCard() {
|
|
927
|
+
const sid = getSessionId();
|
|
928
|
+
setSessionId(sid);
|
|
929
|
+
setPhase('card');
|
|
930
|
+
setClosing(false);
|
|
931
|
+
fetchState(sid);
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
function requestClose() {
|
|
935
|
+
if (phase === 'card') {
|
|
936
|
+
if (closing) return;
|
|
937
|
+
if (prefersReduced()) {
|
|
938
|
+
setPhase('closed');
|
|
939
|
+
setClosing(false);
|
|
940
|
+
} else {
|
|
941
|
+
setClosing(true);
|
|
942
|
+
}
|
|
943
|
+
} else if (phase === 'page') {
|
|
944
|
+
setPhase('closed');
|
|
945
|
+
setClosing(false);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
function toggle() {
|
|
950
|
+
if (phase === 'closed') openCard();
|
|
951
|
+
else requestClose();
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
function toPage() {
|
|
955
|
+
setPhase('page');
|
|
956
|
+
setClosing(false);
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
function backToCard() {
|
|
960
|
+
setPhase('card');
|
|
961
|
+
setClosing(false);
|
|
962
|
+
/* The page edits entries; the card list must not show the stale snapshot. */
|
|
963
|
+
fetchState(getSessionId());
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
function onCardAnimationEnd(event) {
|
|
967
|
+
if (event && event.target !== cardRef.current) return;
|
|
968
|
+
if (closing) {
|
|
969
|
+
setPhase('closed');
|
|
970
|
+
setClosing(false);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
/* Outside click and ESC close the card. */
|
|
975
|
+
React.useEffect(
|
|
976
|
+
function () {
|
|
977
|
+
if (phase !== 'card') return undefined;
|
|
978
|
+
function onDown(event) {
|
|
979
|
+
const card = cardRef.current;
|
|
980
|
+
const capsule = capsuleRef.current;
|
|
981
|
+
if (card && card.contains(event.target)) return;
|
|
982
|
+
if (capsule && capsule.contains(event.target)) return;
|
|
983
|
+
requestClose();
|
|
984
|
+
}
|
|
985
|
+
function onKey(event) {
|
|
986
|
+
if (event.key === 'Escape') {
|
|
987
|
+
event.stopPropagation();
|
|
988
|
+
requestClose();
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
document.addEventListener('mousedown', onDown, true);
|
|
992
|
+
document.addEventListener('keydown', onKey, true);
|
|
993
|
+
return function () {
|
|
994
|
+
document.removeEventListener('mousedown', onDown, true);
|
|
995
|
+
document.removeEventListener('keydown', onKey, true);
|
|
996
|
+
};
|
|
997
|
+
},
|
|
998
|
+
[phase, closing],
|
|
999
|
+
);
|
|
1000
|
+
|
|
1001
|
+
/* ESC backs out of the page. */
|
|
1002
|
+
React.useEffect(
|
|
1003
|
+
function () {
|
|
1004
|
+
if (phase !== 'page') return undefined;
|
|
1005
|
+
function onKey(event) {
|
|
1006
|
+
if (event.key === 'Escape') {
|
|
1007
|
+
event.stopPropagation();
|
|
1008
|
+
backToCard();
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
document.addEventListener('keydown', onKey, true);
|
|
1012
|
+
return function () {
|
|
1013
|
+
document.removeEventListener('keydown', onKey, true);
|
|
1014
|
+
};
|
|
1015
|
+
},
|
|
1016
|
+
[phase],
|
|
1017
|
+
);
|
|
1018
|
+
|
|
1019
|
+
function copyEntry(entry) {
|
|
1020
|
+
copyTextToClipboard(buildCopyText(entry)).then(function (ok) {
|
|
1021
|
+
setToast(ok ? '已复制' : '复制失败');
|
|
1022
|
+
}).catch(function () {
|
|
1023
|
+
setToast('复制失败');
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
function applyShowTab(next) {
|
|
1028
|
+
const prev = settings;
|
|
1029
|
+
const want = next === true;
|
|
1030
|
+
setSettings({ showTabEntry: want });
|
|
1031
|
+
setSettingsSaving(true);
|
|
1032
|
+
setSettingsError(null);
|
|
1033
|
+
requestSettings(want)
|
|
1034
|
+
.then(function (result) {
|
|
1035
|
+
const resolved = settingsOf(result);
|
|
1036
|
+
setSettings({ showTabEntry: resolved.showTabEntry });
|
|
1037
|
+
if (seat && typeof seat.setEnabled === 'function') seat.setEnabled(resolved.showTabEntry);
|
|
1038
|
+
setSettingsSaving(false);
|
|
1039
|
+
})
|
|
1040
|
+
.catch(function (thrown) {
|
|
1041
|
+
setSettings(prev);
|
|
1042
|
+
setSettingsError(messageOf(thrown));
|
|
1043
|
+
setSettingsSaving(false);
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
const entries = flattenEntries(payload);
|
|
1048
|
+
const count = entries.length;
|
|
1049
|
+
|
|
1050
|
+
const capsule = h(
|
|
1051
|
+
'button',
|
|
1052
|
+
{
|
|
1053
|
+
key: 'capsule',
|
|
1054
|
+
ref: capsuleRef,
|
|
1055
|
+
type: 'button',
|
|
1056
|
+
className: 'bm-capsule' + (variant === 'floating' ? ' bm-capsule-floating' : ''),
|
|
1057
|
+
'data-bm-entry': '1',
|
|
1058
|
+
'data-better-memo-version': VERSION,
|
|
1059
|
+
'data-bm-open': phase !== 'closed' ? '1' : '0',
|
|
1060
|
+
'aria-label': '备忘录',
|
|
1061
|
+
title: '备忘录',
|
|
1062
|
+
onClick: toggle,
|
|
1063
|
+
},
|
|
1064
|
+
[
|
|
1065
|
+
h('span', { key: 'label', className: 'bm-capsule-label' }, '备忘录'),
|
|
1066
|
+
count > 0 ? h('span', { key: 'count', className: 'bm-capsule-count' }, String(count)) : null,
|
|
1067
|
+
],
|
|
1068
|
+
);
|
|
1069
|
+
|
|
1070
|
+
function cardBody() {
|
|
1071
|
+
const items = [];
|
|
1072
|
+
if (loading && payload === null) {
|
|
1073
|
+
items.push(h('p', { key: 'loading', className: 'bm-card-empty' }, '加载中…'));
|
|
1074
|
+
} else if (error !== null) {
|
|
1075
|
+
items.push(
|
|
1076
|
+
h('div', { key: 'error', className: 'bm-card-error' }, [
|
|
1077
|
+
h('span', { key: 'm' }, '出错了:' + error),
|
|
1078
|
+
h(
|
|
1079
|
+
'button',
|
|
1080
|
+
{
|
|
1081
|
+
key: 'r',
|
|
1082
|
+
type: 'button',
|
|
1083
|
+
className: 'bm-btn bm-btn-ghost',
|
|
1084
|
+
onClick: function () {
|
|
1085
|
+
fetchState(sessionId);
|
|
1086
|
+
},
|
|
1087
|
+
},
|
|
1088
|
+
'重试',
|
|
1089
|
+
),
|
|
1090
|
+
]),
|
|
1091
|
+
);
|
|
1092
|
+
} else if (entries.length === 0) {
|
|
1093
|
+
items.push(h('p', { key: 'empty', className: 'bm-card-empty' }, '还没有备忘录'));
|
|
1094
|
+
} else {
|
|
1095
|
+
entries.forEach(function (item, index) {
|
|
1096
|
+
const delay = Math.min(index * STAGGER_MS, (MAX_STAGGER - 1) * STAGGER_MS) + 'ms';
|
|
1097
|
+
const sub = bodyFirstLine(item.entry);
|
|
1098
|
+
const rowChildren = [
|
|
1099
|
+
h('span', { key: 'dot', className: 'bm-card-dot', 'data-bm-scope': item.scope, 'aria-hidden': 'true' }),
|
|
1100
|
+
h('span', { key: 'text', className: 'bm-card-item-text' }, [
|
|
1101
|
+
h('span', { key: 't', className: 'bm-card-item-title' }, displayTitleOf(item.entry)),
|
|
1102
|
+
sub !== '' ? h('span', { key: 's', className: 'bm-card-item-sub' }, sub) : null,
|
|
1103
|
+
]),
|
|
1104
|
+
h('span', { key: 'tag', className: 'bm-card-tag' }, SCOPE_TAG[item.scope] || item.scope),
|
|
1105
|
+
];
|
|
1106
|
+
items.push(
|
|
1107
|
+
h(
|
|
1108
|
+
'button',
|
|
1109
|
+
{
|
|
1110
|
+
key: item.entry.id || 'entry-' + index,
|
|
1111
|
+
type: 'button',
|
|
1112
|
+
className: 'bm-card-item',
|
|
1113
|
+
'data-bm-copy': item.entry.id || '',
|
|
1114
|
+
'data-bm-scope': item.scope,
|
|
1115
|
+
title: displayTitleOf(item.entry),
|
|
1116
|
+
style: closing ? undefined : { animationDelay: delay },
|
|
1117
|
+
onClick: function () {
|
|
1118
|
+
copyEntry(item.entry);
|
|
1119
|
+
},
|
|
1120
|
+
},
|
|
1121
|
+
rowChildren,
|
|
1122
|
+
),
|
|
1123
|
+
);
|
|
1124
|
+
});
|
|
1125
|
+
}
|
|
1126
|
+
return items;
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
function cardNode() {
|
|
1130
|
+
return h(
|
|
1131
|
+
'div',
|
|
1132
|
+
{
|
|
1133
|
+
key: 'card',
|
|
1134
|
+
ref: cardRef,
|
|
1135
|
+
className: 'bm-card' + (closing ? ' bm-card-out' : '') + (variant === 'floating' ? ' bm-card-floating' : ''),
|
|
1136
|
+
'data-bm-card': '1',
|
|
1137
|
+
onAnimationEnd: onCardAnimationEnd,
|
|
1138
|
+
},
|
|
1139
|
+
[
|
|
1140
|
+
h('div', { key: 'head', className: 'bm-card-head' }, [
|
|
1141
|
+
h('span', { key: 'title', className: 'bm-card-title' }, '备忘录'),
|
|
1142
|
+
h('span', { key: 'count', className: 'bm-card-count' }, String(count)),
|
|
1143
|
+
h('span', { key: 'spacer', className: 'bm-card-spacer' }),
|
|
1144
|
+
h(
|
|
1145
|
+
'button',
|
|
1146
|
+
{
|
|
1147
|
+
key: 'gear',
|
|
1148
|
+
type: 'button',
|
|
1149
|
+
className: 'bm-card-gear',
|
|
1150
|
+
'data-bm-gear': '1',
|
|
1151
|
+
'aria-label': '设置',
|
|
1152
|
+
title: '设置',
|
|
1153
|
+
onClick: toPage,
|
|
1154
|
+
},
|
|
1155
|
+
gearIcon(),
|
|
1156
|
+
),
|
|
1157
|
+
]),
|
|
1158
|
+
h('div', { key: 'body', className: 'bm-card-body' }, cardBody()),
|
|
1159
|
+
toast !== null ? h('div', { key: 'toast', className: 'bm-card-toast', role: 'status' }, toast) : null,
|
|
1160
|
+
],
|
|
1161
|
+
);
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
function pageNode() {
|
|
1165
|
+
return h('div', { key: 'page', className: 'bm-overlay-backdrop', 'data-bm-backdrop': '1' }, [
|
|
1166
|
+
h('div', { key: 'panel', className: 'bm-page', 'data-bm-page': '1' }, [
|
|
1167
|
+
h('div', { key: 'head', className: 'bm-page-head' }, [
|
|
1168
|
+
h(
|
|
1169
|
+
'button',
|
|
1170
|
+
{ key: 'back', type: 'button', className: 'bm-btn bm-btn-ghost bm-page-back', 'data-bm-back': '1', onClick: backToCard },
|
|
1171
|
+
'← 返回',
|
|
1172
|
+
),
|
|
1173
|
+
h('span', { key: 'title', className: 'bm-page-title' }, '备忘录设置'),
|
|
1174
|
+
h('span', { key: 'spacer', className: 'bm-page-spacer' }),
|
|
1175
|
+
h(
|
|
1176
|
+
'button',
|
|
1177
|
+
{
|
|
1178
|
+
key: 'close',
|
|
1179
|
+
type: 'button',
|
|
1180
|
+
className: 'bm-btn bm-btn-ghost bm-page-close',
|
|
1181
|
+
'data-bm-close': '1',
|
|
1182
|
+
'aria-label': '关闭',
|
|
1183
|
+
onClick: function () {
|
|
1184
|
+
setPhase('closed');
|
|
1185
|
+
setClosing(false);
|
|
1186
|
+
},
|
|
1187
|
+
},
|
|
1188
|
+
'×',
|
|
1189
|
+
),
|
|
1190
|
+
]),
|
|
1191
|
+
h('div', { key: 'switch', className: 'bm-page-switch' }, [
|
|
1192
|
+
h('label', { key: 'label', className: 'bm-switch' }, [
|
|
1193
|
+
h('input', {
|
|
1194
|
+
key: 'input',
|
|
1195
|
+
type: 'checkbox',
|
|
1196
|
+
'data-bm-showtab': '1',
|
|
1197
|
+
checked: settings.showTabEntry === true,
|
|
1198
|
+
disabled: settingsSaving,
|
|
1199
|
+
onChange: function (event) {
|
|
1200
|
+
applyShowTab(event.target.checked);
|
|
1201
|
+
},
|
|
1202
|
+
}),
|
|
1203
|
+
h('span', { key: 'text' }, '在会话 tab 行显示「备忘录」入口'),
|
|
1204
|
+
]),
|
|
1205
|
+
settingsError !== null ? h('span', { key: 'err', className: 'bm-switch-error' }, settingsError) : null,
|
|
1206
|
+
]),
|
|
1207
|
+
h('div', { key: 'body', className: 'bm-page-body' }, h(MemoPanel, { sessionId: sessionId, embedded: true })),
|
|
1208
|
+
]),
|
|
1209
|
+
]);
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
let overlay = null;
|
|
1213
|
+
if (phase === 'card') overlay = cardNode();
|
|
1214
|
+
else if (phase === 'page') overlay = pageNode();
|
|
1215
|
+
|
|
1216
|
+
const portal = overlay !== null && typeof document !== 'undefined' && document.body
|
|
1217
|
+
? ReactDOM.createPortal(overlay, document.body)
|
|
1218
|
+
: null;
|
|
1219
|
+
|
|
1220
|
+
return h(React.Fragment, null, [capsule, portal]);
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
/**
|
|
1224
|
+
* Owns the single conversation.view tab seat. Registering and disposing are
|
|
1225
|
+
* the two moments the settings switch drives; a not-yet-declared slot is
|
|
1226
|
+
* retried (never assumed), matching the "ask slots.spec first" rule.
|
|
1227
|
+
*/
|
|
1228
|
+
function createSeatController(ctx) {
|
|
1229
|
+
let dispose = null;
|
|
1230
|
+
let enabled = false;
|
|
1231
|
+
let attempts = 0;
|
|
1232
|
+
let timer = null;
|
|
1233
|
+
|
|
1234
|
+
function slotsOf() {
|
|
1235
|
+
try {
|
|
1236
|
+
return typeof ctx.get === 'function' ? ctx.get('slots') : undefined;
|
|
1237
|
+
} catch (thrown) {
|
|
1238
|
+
return undefined;
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
function clearTimer() {
|
|
1243
|
+
if (timer !== null) {
|
|
1244
|
+
clearTimeout(timer);
|
|
1245
|
+
timer = null;
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
function schedule() {
|
|
1250
|
+
clearTimer();
|
|
1251
|
+
if (!enabled) return;
|
|
1252
|
+
if (attempts >= RETRY_LIMIT) return;
|
|
1253
|
+
attempts += 1;
|
|
1254
|
+
timer = setTimeout(function () {
|
|
1255
|
+
timer = null;
|
|
1256
|
+
register();
|
|
1257
|
+
}, RETRY_MS);
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
function register() {
|
|
1261
|
+
if (!enabled || dispose !== null) return;
|
|
1262
|
+
const slots = slotsOf();
|
|
1263
|
+
if (!slots || typeof slots.register !== 'function') {
|
|
1264
|
+
schedule();
|
|
1265
|
+
return;
|
|
1266
|
+
}
|
|
1267
|
+
let declared = false;
|
|
1268
|
+
try {
|
|
1269
|
+
declared = typeof slots.spec === 'function' && slots.spec(SLOT) !== undefined;
|
|
1270
|
+
} catch (thrown) {
|
|
1271
|
+
declared = false;
|
|
1272
|
+
}
|
|
1273
|
+
if (!declared) {
|
|
1274
|
+
schedule();
|
|
1275
|
+
return;
|
|
1276
|
+
}
|
|
1277
|
+
try {
|
|
1278
|
+
dispose = slots.register(
|
|
1279
|
+
{ name: SLOT, id: SEAT_ID, order: 1, label: function () { return '备忘录'; } },
|
|
1280
|
+
function (props) {
|
|
1281
|
+
const sid = props && typeof props.sessionId === 'string' ? props.sessionId : '';
|
|
1282
|
+
return h(MemoPanel, { sessionId: sid, embedded: false });
|
|
1283
|
+
},
|
|
1284
|
+
);
|
|
1285
|
+
} catch (thrown) {
|
|
1286
|
+
dispose = null;
|
|
1287
|
+
schedule();
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
function setEnabled(next) {
|
|
1292
|
+
const want = next === true;
|
|
1293
|
+
enabled = want;
|
|
1294
|
+
if (want) {
|
|
1295
|
+
attempts = 0;
|
|
1296
|
+
register();
|
|
1297
|
+
} else {
|
|
1298
|
+
clearTimer();
|
|
1299
|
+
attempts = 0;
|
|
1300
|
+
if (dispose !== null) {
|
|
1301
|
+
const drop = dispose;
|
|
1302
|
+
dispose = null;
|
|
1303
|
+
try {
|
|
1304
|
+
drop();
|
|
1305
|
+
} catch (thrown) {
|
|
1306
|
+
/* host already released it */
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
return {
|
|
1313
|
+
setEnabled: setEnabled,
|
|
1314
|
+
isEnabled: function () { return enabled; },
|
|
1315
|
+
hasSeat: function () { return dispose !== null; },
|
|
1316
|
+
};
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
function mountBodyFallback(deps) {
|
|
1320
|
+
if (typeof document === 'undefined' || !document.body) return;
|
|
1321
|
+
try {
|
|
1322
|
+
const host = document.createElement('div');
|
|
1323
|
+
host.id = FALLBACK_HOST_ID;
|
|
1324
|
+
host.setAttribute('data-better-memo-overlay', '');
|
|
1325
|
+
document.body.appendChild(host);
|
|
1326
|
+
const root = ReactDOMClient.createRoot(host);
|
|
1327
|
+
root.render(h(OverlayEntry, { seat: deps.seat, getSessionId: deps.getSessionId, variant: 'floating' }));
|
|
1328
|
+
} catch (thrown) {
|
|
1329
|
+
console.error('[better-memo] floating entry failed', thrown);
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
|
|
648
1333
|
function apply(ctx) {
|
|
649
|
-
|
|
1334
|
+
injectStyle();
|
|
1335
|
+
const seat = createSeatController(ctx);
|
|
1336
|
+
const deps = {
|
|
1337
|
+
seat: seat,
|
|
1338
|
+
getSessionId: function () {
|
|
1339
|
+
return currentSessionId(ctx);
|
|
1340
|
+
},
|
|
1341
|
+
};
|
|
1342
|
+
|
|
1343
|
+
let overlayMounted = false;
|
|
1344
|
+
let seatStarted = false;
|
|
1345
|
+
|
|
1346
|
+
function startSeat() {
|
|
1347
|
+
if (seatStarted) return;
|
|
1348
|
+
seatStarted = true;
|
|
1349
|
+
requestState('')
|
|
1350
|
+
.then(function (payload) {
|
|
1351
|
+
seat.setEnabled(settingsOf(payload).showTabEntry);
|
|
1352
|
+
})
|
|
1353
|
+
.catch(function () {
|
|
1354
|
+
/* unreachable host: leave the seat off */
|
|
1355
|
+
});
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
function registerCapsule(slots) {
|
|
1359
|
+
if (overlayMounted) return;
|
|
1360
|
+
try {
|
|
1361
|
+
slots.register(
|
|
1362
|
+
{ name: TOPBAR_SLOT, id: CAPSULE_ID, order: 0, label: function () { return '备忘录'; } },
|
|
1363
|
+
function () {
|
|
1364
|
+
return h(OverlayEntry, { seat: seat, getSessionId: deps.getSessionId, variant: 'topbar' });
|
|
1365
|
+
},
|
|
1366
|
+
);
|
|
1367
|
+
overlayMounted = true;
|
|
1368
|
+
} catch (thrown) {
|
|
1369
|
+
console.error('[better-memo] capsule registration failed', thrown);
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
function mountFloating() {
|
|
1374
|
+
if (overlayMounted) return;
|
|
1375
|
+
overlayMounted = true;
|
|
1376
|
+
mountBodyFallback(deps);
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
function boot(attemptsLeft) {
|
|
650
1380
|
let slots = null;
|
|
651
1381
|
try {
|
|
652
1382
|
slots = typeof ctx.get === 'function' ? ctx.get('slots') : undefined;
|
|
@@ -654,30 +1384,48 @@ window.__ModuleLoader__.load({
|
|
|
654
1384
|
slots = undefined;
|
|
655
1385
|
}
|
|
656
1386
|
if (slots === undefined || slots === null) {
|
|
657
|
-
if (attemptsLeft > 0)
|
|
1387
|
+
if (attemptsLeft > 0) {
|
|
1388
|
+
setTimeout(function () { boot(attemptsLeft - 1); }, RETRY_MS);
|
|
1389
|
+
return;
|
|
1390
|
+
}
|
|
1391
|
+
mountFloating();
|
|
658
1392
|
return;
|
|
659
1393
|
}
|
|
1394
|
+
startSeat();
|
|
1395
|
+
let hasOverlay = false;
|
|
660
1396
|
try {
|
|
661
|
-
|
|
662
|
-
if (attemptsLeft > 0) setTimeout(() => waitForSlots(attemptsLeft - 1), 250);
|
|
663
|
-
return;
|
|
664
|
-
}
|
|
665
|
-
slots.register(
|
|
666
|
-
{
|
|
667
|
-
name: SLOT,
|
|
668
|
-
id: SEAT_ID,
|
|
669
|
-
order: 1,
|
|
670
|
-
label: () => '备忘录',
|
|
671
|
-
},
|
|
672
|
-
Panel,
|
|
673
|
-
);
|
|
1397
|
+
hasOverlay = typeof slots.spec === 'function' && slots.spec(TOPBAR_SLOT) !== undefined;
|
|
674
1398
|
} catch (thrown) {
|
|
675
|
-
|
|
1399
|
+
hasOverlay = false;
|
|
676
1400
|
}
|
|
677
|
-
|
|
678
|
-
|
|
1401
|
+
if (hasOverlay) {
|
|
1402
|
+
registerCapsule(slots);
|
|
1403
|
+
return;
|
|
1404
|
+
}
|
|
1405
|
+
if (attemptsLeft > 0) {
|
|
1406
|
+
setTimeout(function () { boot(attemptsLeft - 1); }, RETRY_MS);
|
|
1407
|
+
return;
|
|
1408
|
+
}
|
|
1409
|
+
mountFloating();
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
boot(RETRY_LIMIT);
|
|
679
1413
|
}
|
|
680
1414
|
|
|
681
|
-
return {
|
|
1415
|
+
return {
|
|
1416
|
+
apply,
|
|
1417
|
+
/* Exposed only for the headless logic probe; the loader ignores extra keys. */
|
|
1418
|
+
__probe: {
|
|
1419
|
+
buildCopyText: buildCopyText,
|
|
1420
|
+
displayTitleOf: displayTitleOf,
|
|
1421
|
+
settingsOf: settingsOf,
|
|
1422
|
+
copyTextToClipboard: copyTextToClipboard,
|
|
1423
|
+
createSeatController: createSeatController,
|
|
1424
|
+
requestSettings: requestSettings,
|
|
1425
|
+
currentSessionId: currentSessionId,
|
|
1426
|
+
flattenEntries: flattenEntries,
|
|
1427
|
+
constants: { VERSION: VERSION, VERSION_STRING: '0.2.0' },
|
|
1428
|
+
},
|
|
1429
|
+
};
|
|
682
1430
|
},
|
|
683
1431
|
});
|
package/index.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* `user` scope is the user's own drawer. No tool returns it and no tool writes
|
|
9
9
|
* it — only the panel does, over the route.
|
|
10
10
|
*/
|
|
11
|
-
import { addEntry, AGENT_SCOPES, deleteEntry, read, updateEntry, visibleTo, write, LIMITS } from './lib/store.js';
|
|
11
|
+
import { addEntry, AGENT_SCOPES, deleteEntry, patchSettings, read, readSettings, updateEntry, visibleTo, write, LIMITS } from './lib/store.js';
|
|
12
12
|
|
|
13
13
|
export const name = 'dsh-better-memo';
|
|
14
14
|
export const inject = ['tools', 'systemPrompt'];
|
|
@@ -74,6 +74,7 @@ function panelPayload({ sessionId, profile, env = process.env }) {
|
|
|
74
74
|
profile: seen.profile.map(shape),
|
|
75
75
|
user: seen.user.map(shape),
|
|
76
76
|
limits: LIMITS,
|
|
77
|
+
settings: readSettings(db),
|
|
77
78
|
};
|
|
78
79
|
}
|
|
79
80
|
|
|
@@ -131,6 +132,33 @@ export function serveWrite(request, env = process.env) {
|
|
|
131
132
|
}
|
|
132
133
|
}
|
|
133
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Settings are the plugin's own preferences (not memo content). They live next
|
|
137
|
+
* to the entries but are patched separately and are never exposed to the agent
|
|
138
|
+
* tools. Query-param style, matching /write: `?showTabEntry=1|0`.
|
|
139
|
+
*/
|
|
140
|
+
export function serveSettings(request, env = process.env) {
|
|
141
|
+
if (markerOk(request) === false) return Response.json({ ok: false, reason: 'no-marker' }, { status: 403 });
|
|
142
|
+
try {
|
|
143
|
+
const params = new URL(request.url).searchParams;
|
|
144
|
+
const patch = {};
|
|
145
|
+
if (params.has('showTabEntry')) {
|
|
146
|
+
const raw = String(params.get('showTabEntry'));
|
|
147
|
+
patch.showTabEntry = raw === '1' || raw === 'true';
|
|
148
|
+
}
|
|
149
|
+
if (Object.keys(patch).length === 0) {
|
|
150
|
+
return Response.json({ ok: false, reason: 'bad-query', error: 'expected ?showTabEntry=1|0' }, { status: 400 });
|
|
151
|
+
}
|
|
152
|
+
const db = read(env);
|
|
153
|
+
const settings = patchSettings(db, patch);
|
|
154
|
+
write(db, env);
|
|
155
|
+
return Response.json({ ok: true, settings });
|
|
156
|
+
} catch (thrown) {
|
|
157
|
+
const message = thrown instanceof Error ? thrown.message : String(thrown);
|
|
158
|
+
return Response.json({ ok: false, reason: 'error', error: message }, { status: 400 });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
134
162
|
/** One prefix, dispatched by pathname so router order cannot pick the handler. */
|
|
135
163
|
export function serveRequest(request, env = process.env) {
|
|
136
164
|
let pathname = '';
|
|
@@ -141,6 +169,7 @@ export function serveRequest(request, env = process.env) {
|
|
|
141
169
|
}
|
|
142
170
|
if (pathname === `${ROUTE}/state`) return serveState(request, env);
|
|
143
171
|
if (pathname === `${ROUTE}/write`) return serveWrite(request, env);
|
|
172
|
+
if (pathname === `${ROUTE}/settings`) return serveSettings(request, env);
|
|
144
173
|
return Response.json({ ok: false, reason: 'not-found' }, { status: 404 });
|
|
145
174
|
}
|
|
146
175
|
|
package/lib/store.js
CHANGED
|
@@ -23,6 +23,28 @@ export const LIMITS = {
|
|
|
23
23
|
entries: 500,
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
/** Defaults for the plugin's own settings. `showTabEntry` off by default (user m26532). */
|
|
27
|
+
export const DEFAULT_SETTINGS = { showTabEntry: false };
|
|
28
|
+
|
|
29
|
+
export function sanitizeSettings(raw) {
|
|
30
|
+
const source = raw !== null && typeof raw === 'object' ? raw : {};
|
|
31
|
+
return { showTabEntry: source.showTabEntry === true };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Read the settings block out of a db that `sanitizeDb` produced. */
|
|
35
|
+
export function readSettings(db) {
|
|
36
|
+
return sanitizeSettings(db === null || typeof db !== 'object' ? null : db.settings);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Apply a partial patch; unknown keys are ignored, values are coerced. */
|
|
40
|
+
export function patchSettings(db, patch) {
|
|
41
|
+
const next = readSettings(db);
|
|
42
|
+
const source = patch !== null && typeof patch === 'object' ? patch : {};
|
|
43
|
+
if (source.showTabEntry !== undefined) next.showTabEntry = source.showTabEntry === true;
|
|
44
|
+
db.settings = next;
|
|
45
|
+
return next;
|
|
46
|
+
}
|
|
47
|
+
|
|
26
48
|
export function homeDir(env = process.env) {
|
|
27
49
|
const explicit = env.DSH_HOME;
|
|
28
50
|
if (typeof explicit === 'string' && explicit.trim() !== '') return explicit;
|
|
@@ -37,7 +59,7 @@ export function dataFile(env = process.env) {
|
|
|
37
59
|
}
|
|
38
60
|
|
|
39
61
|
function emptyDb() {
|
|
40
|
-
return { version: 1, entries: [] };
|
|
62
|
+
return { version: 1, entries: [], settings: { ...DEFAULT_SETTINGS } };
|
|
41
63
|
}
|
|
42
64
|
|
|
43
65
|
function str(value, max) {
|
|
@@ -57,6 +79,7 @@ function num(value, fallback) {
|
|
|
57
79
|
*/
|
|
58
80
|
export function sanitizeDb(raw) {
|
|
59
81
|
const db = emptyDb();
|
|
82
|
+
db.settings = sanitizeSettings(raw !== null && typeof raw === 'object' ? raw.settings : null);
|
|
60
83
|
const list = raw !== null && typeof raw === 'object' && Array.isArray(raw.entries) ? raw.entries : [];
|
|
61
84
|
for (const row of list) {
|
|
62
85
|
if (row === null || typeof row !== 'object') continue;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-better-memo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"private": false,
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "A popout memo card for DeepSeek Harness: top-bar capsule, one-line memos you copy with a click, three scopes (this session / this profile / you only) and agent tools to read and edit them. 浮窗备忘录:顶栏胶囊、点一条即复制、三档归属。",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./index.js",
|
|
8
8
|
"exports": {
|