dsh-better-memo 0.1.0 → 0.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/CHANGELOG.md +28 -2
- package/README.md +15 -19
- package/client.js +936 -116
- package/index.js +39 -5
- package/lib/store.js +25 -2
- package/package.json +2 -2
package/client.js
CHANGED
|
@@ -1,48 +1,62 @@
|
|
|
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.1
|
|
36
|
+
const VERSION = '0.2.1';
|
|
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
|
-
const GROUP_LABEL = { session: '
|
|
55
|
+
const GROUP_LABEL = { session: '本会话:', profile: '全局共享:', user: '仅用户:' };
|
|
56
|
+
const SCOPE_TAG = { session: '会话', profile: '共享', user: '私人' };
|
|
43
57
|
const HINT_TEXT =
|
|
44
|
-
'
|
|
45
|
-
'
|
|
58
|
+
'本会话只在本会话里出现;全局共享会出现在同一 profile 的所有会话;' +
|
|
59
|
+
'仅用户只有你自己在这个面板里看得到,AI 读不到,也改不了。';
|
|
46
60
|
|
|
47
61
|
/** One style element per page, injected once; guarded by this flag inside the factory. */
|
|
48
62
|
let styleInjected = false;
|
|
@@ -50,58 +64,119 @@ 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 = [
|
|
53
|
-
|
|
67
|
+
/* ---- management UI (unchanged from 0.1.0) ---- */
|
|
68
|
+
'.bm-panel{display:flex;flex-direction:column;gap:16px;padding:16px 18px 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}',
|
|
56
71
|
'.bm-title{font-size:15px;font-weight:600;margin:0}',
|
|
57
72
|
'.bm-version{font-size:11px;color:var(--dsw-alias-label-secondary,#8a8f98);margin-left:2px}',
|
|
58
73
|
'.bm-head-spacer{flex:1 1 auto}',
|
|
59
|
-
'.bm-btn{font:inherit;font-size:12px;line-height:1;border-radius:
|
|
60
|
-
'.bm-btn:hover{border-color:var(--dsw-alias-border-
|
|
74
|
+
'.bm-btn{font:inherit;font-size:12px;line-height:1;border-radius:8px;border:1px solid var(--dsw-alias-border-l3,rgba(15,23,42,.16));background:var(--bm-surface,#fff);color:inherit;padding:7px 12px;cursor:pointer;transition:background 120ms ease,border-color 120ms ease}',
|
|
75
|
+
'.bm-btn:hover{background:var(--bm-hover,#eff3f8);border-color:var(--dsw-alias-border-l4,rgba(15,23,42,.22))}',
|
|
61
76
|
'.bm-btn:disabled{opacity:.45;cursor:not-allowed}',
|
|
62
77
|
'.bm-btn-primary{background:var(--dsw-alias-accent,#3b82f6);border-color:transparent;color:#fff}',
|
|
63
|
-
'.bm-btn-
|
|
64
|
-
'.bm-btn-
|
|
78
|
+
'.bm-btn-primary:hover{background:#2560d8;border-color:transparent}',
|
|
79
|
+
'.bm-btn-ghost{border-color:transparent;background:transparent;color:var(--dsw-alias-label-secondary,#8a8f98);padding:6px 8px}',
|
|
80
|
+
'.bm-btn-ghost:hover{background:var(--bm-hover,#eff3f8);color:var(--dsw-alias-label-primary,#1f2328)}',
|
|
81
|
+
'.bm-btn-danger{color:var(--dsw-alias-danger,#e5484d);border-color:rgba(209,36,47,.35);background:#fff}',
|
|
65
82
|
'.bm-hint{margin:0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#8a8f98)}',
|
|
66
|
-
'.bm-form{display:flex;flex-direction:column;gap:
|
|
83
|
+
'.bm-form{display:flex;flex-direction:column;gap:10px;padding:14px;border-radius:12px;background:var(--bm-surface-2,#f6f8fa);border:1px solid var(--bm-line,rgba(15,23,42,.09))}',
|
|
67
84
|
'.bm-form-top{display:flex;gap:8px;align-items:center}',
|
|
68
85
|
'.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-
|
|
70
|
-
'.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-
|
|
72
|
-
'.bm-textarea{resize:vertical;min-height:
|
|
86
|
+
'.bm-input{font:inherit;font-size:13px;width:100%;border-radius:8px;border:1px solid var(--dsw-alias-border-l3,rgba(15,23,42,.16));background:#fff;color:inherit;padding:8px 10px;transition:border-color 120ms ease,box-shadow 120ms ease}',
|
|
87
|
+
'.bm-input:focus{outline:none;border-color:var(--dsw-alias-accent,#3b82f6);box-shadow:0 0 0 3px rgba(47,111,237,.14)}',
|
|
88
|
+
'.bm-select{font:inherit;font-size:13px;border-radius:8px;border:1px solid var(--dsw-alias-border-l3,rgba(15,23,42,.16));background:#fff;color:inherit;padding:6px 8px}',
|
|
89
|
+
'.bm-textarea{resize:vertical;min-height:62px;line-height:19px}',
|
|
73
90
|
'.bm-form-actions{display:flex;justify-content:flex-end;gap:8px}',
|
|
74
91
|
'.bm-note{margin:0;font-size:11px;color:var(--dsw-alias-label-tertiary,#9aa0a6)}',
|
|
75
|
-
'.bm-groups{display:flex;flex-direction:column;gap:
|
|
76
|
-
'.bm-group{display:flex;flex-direction:column;gap:
|
|
77
|
-
'.bm-group-head{font-size:
|
|
78
|
-
'.bm-empty{margin:0;font-size:12px;color:var(--dsw-alias-label-tertiary,#9aa0a6);padding:
|
|
79
|
-
'.bm-list{display:flex;flex-direction:column;gap:
|
|
80
|
-
'.bm-row{display:flex;flex-direction:column;gap:6px;padding:10px 12px;border-radius:
|
|
92
|
+
'.bm-groups{display:flex;flex-direction:column;gap:18px}',
|
|
93
|
+
'.bm-group{display:flex;flex-direction:column;gap:4px}',
|
|
94
|
+
'.bm-group-head{font-size:11.5px;font-weight:600;letter-spacing:.02em;color:var(--dsw-alias-label-secondary,#8a8f98);margin:0 0 2px;text-transform:none}',
|
|
95
|
+
'.bm-empty{margin:0;font-size:12px;color:var(--dsw-alias-label-tertiary,#9aa0a6);padding:6px 2px}',
|
|
96
|
+
'.bm-list{display:flex;flex-direction:column;gap:2px;margin:0;padding:0;list-style:none}',
|
|
97
|
+
'.bm-row{display:flex;flex-direction:column;gap:6px;padding:10px 12px;border-radius:10px;border:1px solid transparent;background:transparent;animation:bm-item-frames 240ms cubic-bezier(.22,1,.36,1) both;transition:background 120ms ease,border-color 120ms ease}',
|
|
98
|
+
'.bm-row:hover{background:var(--bm-hover,#eff3f8);border-color:var(--bm-line,rgba(15,23,42,.09))}',
|
|
81
99
|
'.bm-row-out{animation:bm-out-frames 160ms cubic-bezier(.4,0,1,1) forwards;pointer-events:none}',
|
|
82
100
|
'.bm-row-head{display:flex;align-items:flex-start;gap:8px}',
|
|
83
101
|
'.bm-check{display:flex;align-items:flex-start;gap:8px;flex:1 1 auto;min-width:0;cursor:pointer}',
|
|
84
|
-
'.bm-check input{margin:2px 0 0}',
|
|
85
|
-
'.bm-row-title{font-size:13px;font-weight:500;word-break:break-word}',
|
|
102
|
+
'.bm-check input{margin:2px 0 0;accent-color:var(--dsw-alias-accent,#3b82f6)}',
|
|
103
|
+
'.bm-row-title{font-size:13px;font-weight:500;line-height:18px;word-break:break-word}',
|
|
86
104
|
'.bm-done{text-decoration:line-through;color:var(--dsw-alias-label-tertiary,#9aa0a6)}',
|
|
87
|
-
'.bm-row-body{margin:0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#8a8f98);white-space:pre-wrap;word-break:break-word;max-height:120px;overflow:auto}',
|
|
88
|
-
'.bm-row-actions{display:flex;
|
|
105
|
+
'.bm-row-body{margin:0;padding-left:26px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#8a8f98);white-space:pre-wrap;word-break:break-word;max-height:120px;overflow:auto}',
|
|
106
|
+
'.bm-row-actions{display:flex;flex:0 0 auto;gap:2px;opacity:.55;transition:opacity 120ms ease}',
|
|
107
|
+
'.bm-row:hover .bm-row-actions,.bm-row:focus-within .bm-row-actions{opacity:1}',
|
|
108
|
+
'.bm-row-act{font-size:11.5px;padding:4px 8px;border-radius:6px}',
|
|
89
109
|
'.bm-edit{display:flex;flex-direction:column;gap:6px}',
|
|
90
110
|
'.bm-edit-actions{display:flex;justify-content:flex-end;gap:6px}',
|
|
91
|
-
'.bm-error{display:flex;align-items:center;gap:10px;padding:10px 12px;border-radius:8px;border:1px solid
|
|
111
|
+
'.bm-error{display:flex;align-items:center;gap:10px;padding:10px 12px;border-radius:8px;border:1px solid rgba(209,36,47,.32);background:rgba(209,36,47,.06);color:#b3252f;font-size:12px}',
|
|
92
112
|
'.bm-error-spacer{flex:1 1 auto}',
|
|
93
113
|
'.bm-loading{margin:0;font-size:12px;color:var(--dsw-alias-label-secondary,#8a8f98)}',
|
|
94
|
-
|
|
114
|
+
/* ---- entry capsule ---- */
|
|
115
|
+
'.bm-capsule{position:fixed;top:11px;right:150px;z-index:2147483000;display:inline-flex;align-items:center;gap:6px;height:28px;padding:0 12px;border-radius:8px;border:1px solid rgba(15,23,42,.14);background:#fff;color:#1f2328;font:inherit;font-size:12px;line-height:1;cursor:pointer;pointer-events:auto;-webkit-app-region:no-drag;box-shadow:0 1px 3px rgba(16,24,40,.10);transition:background 120ms ease,border-color 120ms ease}',
|
|
116
|
+
'.bm-capsule:hover{background:#f2f5f9;border-color:rgba(15,23,42,.22)}',
|
|
117
|
+
'.bm-capsule[data-bm-open="1"]{border-color:#2f6fed;background:#fff}',
|
|
118
|
+
'.bm-capsule-floating{top:auto;right:16px;bottom:16px;height:40px;min-width:40px;padding:0 14px;border-radius:20px;box-shadow:0 8px 22px rgba(16,24,40,.18)}',
|
|
119
|
+
'.bm-capsule-label{font-weight:500;white-space:nowrap;color:#1f2328}',
|
|
120
|
+
'.bm-capsule-count{min-width:16px;height:16px;padding:0 4px;border-radius:8px;background:#2f6fed;color:#fff;font-size:10px;line-height:16px;text-align:center}',
|
|
121
|
+
/* ---- popout surfaces: light and high contrast whatever the host theme is ---- */
|
|
122
|
+
'.bm-card,.bm-page{--bm-fg:#1f2328;--bm-fg2:#57606a;--bm-fg3:#8b949e;--bm-line:rgba(15,23,42,.09);--bm-line-2:rgba(15,23,42,.14);--bm-hover:#eff3f8;--bm-surface:#fff;--bm-surface-2:#f6f8fa;--bm-accent:#2f6fed;color-scheme:light;--dsw-alias-bg-base:#fff;--dsw-alias-bg-l1:#fff;--dsw-alias-bg-l2:#f2f5f9;--dsw-alias-label-primary:#1f2328;--dsw-alias-label-secondary:#57606a;--dsw-alias-label-tertiary:#8b949e;--dsw-alias-border-l2:rgba(15,23,42,.10);--dsw-alias-border-l3:rgba(15,23,42,.16);--dsw-alias-border-l4:rgba(15,23,42,.22);--dsw-alias-accent:#2f6fed;--dsw-alias-danger:#d1242f}',
|
|
123
|
+
/* ---- floating card ---- */
|
|
124
|
+
'.bm-card{position:fixed;top:40px;right:150px;width:332px;max-height:58vh;z-index:2147483100;display:flex;flex-direction:column;border-radius:14px;border:1px solid var(--bm-line-2);background:var(--bm-surface);color:var(--bm-fg);box-shadow:0 12px 32px rgba(16,24,40,.14),0 2px 6px rgba(16,24,40,.08);overflow:hidden;pointer-events:auto;-webkit-app-region:no-drag;animation:bm-enter-frames 200ms cubic-bezier(.22,1,.36,1) both}',
|
|
125
|
+
'.bm-card-floating{top:auto;right:16px;bottom:64px}',
|
|
126
|
+
'.bm-card-out{animation:bm-out-frames 160ms cubic-bezier(.4,0,1,1) forwards;pointer-events:none}',
|
|
127
|
+
'.bm-card-head{display:flex;align-items:center;gap:8px;padding:11px 12px 11px 14px;border-bottom:1px solid var(--bm-line)}',
|
|
128
|
+
'.bm-card-title{font-size:13.5px;font-weight:600;letter-spacing:.01em;color:var(--bm-fg)}',
|
|
129
|
+
'.bm-card-count{min-width:18px;padding:1px 6px;border-radius:9px;background:var(--bm-surface-2);color:var(--bm-fg2);font-size:11px;line-height:15px;text-align:center}',
|
|
130
|
+
'.bm-card-spacer{flex:1 1 auto}',
|
|
131
|
+
'.bm-card-gear{display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;padding:0;border-radius:8px;border:1px solid transparent;background:transparent;color:var(--bm-fg3);cursor:pointer;transition:background 120ms ease,color 120ms ease}',
|
|
132
|
+
'.bm-card-gear:hover{background:var(--bm-hover);color:var(--bm-fg)}',
|
|
133
|
+
'.bm-card-body{display:flex;flex-direction:column;gap:2px;padding:6px;overflow:auto}',
|
|
134
|
+
'.bm-card-foot{padding:8px 14px 10px;border-top:1px solid var(--bm-line);font-size:11px;color:var(--bm-fg3)}',
|
|
135
|
+
'.bm-card-empty{margin:0;padding:22px 8px;text-align:center;font-size:12px;color:var(--bm-fg3)}',
|
|
136
|
+
'.bm-card-error{display:flex;align-items:center;gap:8px;margin:4px;padding:10px;border-radius:8px;border:1px solid rgba(209,36,47,.32);background:rgba(209,36,47,.06);color:#b3252f;font-size:12px}',
|
|
137
|
+
'.bm-card-item{display:flex;align-items:flex-start;gap:9px;width:100%;text-align:left;padding:9px 10px;border-radius:10px;border:1px solid transparent;background:transparent;color:var(--bm-fg);font:inherit;cursor:pointer;animation:bm-item-frames 240ms cubic-bezier(.22,1,.36,1) both;transition:background 120ms ease,border-color 120ms ease}',
|
|
138
|
+
'.bm-card-item:hover{background:var(--bm-hover);border-color:var(--bm-line)}',
|
|
139
|
+
'.bm-card-item:active{background:#e8eef7}',
|
|
140
|
+
'.bm-card-dot{flex:0 0 auto;width:7px;height:7px;margin-top:6px;border-radius:50%;background:var(--bm-fg3);box-shadow:0 0 0 3px rgba(15,23,42,.08)}',
|
|
141
|
+
'.bm-card-dot[data-bm-scope="session"]{background:#2f6fed;box-shadow:0 0 0 3px rgba(47,111,237,.14)}',
|
|
142
|
+
'.bm-card-dot[data-bm-scope="profile"]{background:#12a150;box-shadow:0 0 0 3px rgba(18,161,80,.14)}',
|
|
143
|
+
'.bm-card-dot[data-bm-scope="user"]{background:#e08700;box-shadow:0 0 0 3px rgba(224,135,0,.16)}',
|
|
144
|
+
'.bm-card-item-text{display:flex;flex-direction:column;gap:2px;flex:1 1 auto;min-width:0}',
|
|
145
|
+
'.bm-card-item-title{font-size:13px;font-weight:500;line-height:17px;color:var(--bm-fg);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
|
|
146
|
+
'.bm-card-item-sub{font-size:11.5px;line-height:15px;color:var(--bm-fg2);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
|
|
147
|
+
'.bm-card-tag{flex:0 0 auto;align-self:center;padding:2px 7px;border-radius:999px;font-size:10.5px;line-height:14px;color:var(--bm-fg2);background:var(--bm-surface-2);border:1px solid var(--bm-line)}',
|
|
148
|
+
'.bm-card-tag[data-bm-scope="session"]{color:#2559c4;background:rgba(47,111,237,.09);border-color:rgba(47,111,237,.18)}',
|
|
149
|
+
'.bm-card-tag[data-bm-scope="profile"]{color:#0d7f42;background:rgba(18,161,80,.09);border-color:rgba(18,161,80,.18)}',
|
|
150
|
+
'.bm-card-tag[data-bm-scope="user"]{color:#a86200;background:rgba(224,135,0,.10);border-color:rgba(224,135,0,.20)}',
|
|
151
|
+
'.bm-card-toast{position:absolute;right:12px;bottom:12px;padding:7px 13px;border-radius:999px;background:var(--bm-accent);color:#fff;font-size:12px;line-height:1;box-shadow:0 8px 20px rgba(16,24,40,.22);animation:bm-fade-frames 120ms ease both}',
|
|
152
|
+
/* ---- settings page ---- */
|
|
153
|
+
'.bm-overlay-backdrop{position:fixed;inset:0;z-index:2147483200;display:flex;align-items:center;justify-content:center;background:rgba(16,24,40,.32);pointer-events:auto;-webkit-app-region:no-drag}',
|
|
154
|
+
'.bm-page{display:flex;flex-direction:column;width:min(720px,92vw);height:min(80vh,80vh);max-height:80vh;border-radius:16px;border:1px solid var(--bm-line-2);background:var(--bm-surface);color:var(--bm-fg);box-shadow:0 24px 64px rgba(16,24,40,.22),0 4px 12px rgba(16,24,40,.10);overflow:hidden;animation:bm-enter-frames 200ms cubic-bezier(.22,1,.36,1) both}',
|
|
155
|
+
'.bm-page-head{display:flex;align-items:center;gap:8px;padding:12px 14px;border-bottom:1px solid var(--bm-line)}',
|
|
156
|
+
'.bm-page-back{font-size:12px}',
|
|
157
|
+
'.bm-page-title{font-size:14px;font-weight:600;color:var(--bm-fg)}',
|
|
158
|
+
'.bm-page-spacer{flex:1 1 auto}',
|
|
159
|
+
'.bm-page-close{font-size:18px;line-height:1;padding:4px 10px}',
|
|
160
|
+
'.bm-page-switch{display:flex;align-items:center;gap:10px;padding:12px 16px;border-bottom:1px solid var(--bm-line);flex-wrap:wrap;background:var(--bm-surface-2)}',
|
|
161
|
+
'.bm-switch{display:inline-flex;align-items:center;gap:8px;font-size:12.5px;color:var(--bm-fg);cursor:pointer}',
|
|
162
|
+
'.bm-switch input{cursor:pointer;margin:0}',
|
|
163
|
+
'.bm-switch-error{font-size:11px;color:#d1242f}',
|
|
164
|
+
'.bm-page-body{flex:1 1 auto;overflow:auto;min-height:0;background:var(--bm-surface)}',
|
|
165
|
+
/* ---- keyframes ---- */
|
|
166
|
+
'@keyframes bm-enter-frames{from{opacity:0;transform:translateY(8px) scale(.98)}to{opacity:1;transform:none}}',
|
|
95
167
|
'@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(.
|
|
168
|
+
'@keyframes bm-out-frames{from{opacity:1;transform:none}to{opacity:0;transform:scale(.96)}}',
|
|
97
169
|
'@keyframes bm-fade-frames{from{opacity:0}to{opacity:1}}',
|
|
98
|
-
'@
|
|
170
|
+
'@keyframes bm-fade-out-frames{to{opacity:0}}',
|
|
171
|
+
/* reduced motion: opacity only, no displacement, no stagger. */
|
|
172
|
+
'@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
173
|
].join('\n');
|
|
100
174
|
|
|
101
175
|
function injectStyle() {
|
|
102
176
|
if (styleInjected === true) return;
|
|
103
177
|
styleInjected = true;
|
|
104
178
|
try {
|
|
179
|
+
if (typeof document === 'undefined') return;
|
|
105
180
|
if (document.getElementById(STYLE_ID) !== null) return;
|
|
106
181
|
const style = document.createElement('style');
|
|
107
182
|
style.id = STYLE_ID;
|
|
@@ -167,14 +242,168 @@ window.__ModuleLoader__.load({
|
|
|
167
242
|
return payload;
|
|
168
243
|
}
|
|
169
244
|
|
|
245
|
+
/** Persist showTabEntry. GET + query (the host webserver only answers GET/HEAD). */
|
|
246
|
+
async function requestSettings(showTabEntry) {
|
|
247
|
+
const query = queryOf({ showTabEntry: showTabEntry === true ? '1' : '0' });
|
|
248
|
+
const response = await fetch(ROUTE + '/settings?' + query, { method: 'GET', headers: MARKER });
|
|
249
|
+
let payload = null;
|
|
250
|
+
try {
|
|
251
|
+
payload = await response.json();
|
|
252
|
+
} catch (thrown) {
|
|
253
|
+
payload = null;
|
|
254
|
+
}
|
|
255
|
+
if (response.ok === false || payload === null || payload.ok === false) {
|
|
256
|
+
const reason = payload && payload.reason ? payload.reason : 'HTTP ' + response.status;
|
|
257
|
+
const detail = payload && payload.error ? ':' + payload.error : '';
|
|
258
|
+
throw new Error(reason + detail);
|
|
259
|
+
}
|
|
260
|
+
return payload;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** Read {showTabEntry} out of a state or settings payload; missing settings means off. */
|
|
264
|
+
function settingsOf(source) {
|
|
265
|
+
const settings = source && typeof source === 'object' && source.settings && typeof source.settings === 'object'
|
|
266
|
+
? source.settings
|
|
267
|
+
: null;
|
|
268
|
+
return { showTabEntry: settings !== null && settings.showTabEntry === true };
|
|
269
|
+
}
|
|
270
|
+
|
|
170
271
|
/**
|
|
171
|
-
* The
|
|
172
|
-
* on
|
|
272
|
+
* The id of the session currently shown in the main view, or '' when the
|
|
273
|
+
* view is not on a real conversation. A session that exists but is still
|
|
274
|
+
* blank (`session.blank === true`) counts as "no conversation": the host
|
|
275
|
+
* renders the welcome screen for it, and the capsule stays hidden there.
|
|
173
276
|
*/
|
|
174
|
-
function
|
|
277
|
+
function currentSessionId(ctx) {
|
|
278
|
+
try {
|
|
279
|
+
const sessions = typeof ctx.get === 'function' ? ctx.get('sessions') : undefined;
|
|
280
|
+
if (!sessions || !sessions.list || typeof sessions.list.getSnapshot !== 'function') return '';
|
|
281
|
+
const snapshot = sessions.list.getSnapshot();
|
|
282
|
+
const byId = snapshot && snapshot.byId ? snapshot.byId : null;
|
|
283
|
+
if (!byId) return '';
|
|
284
|
+
const ids = Object.keys(byId);
|
|
285
|
+
for (let index = 0; index < ids.length; index += 1) {
|
|
286
|
+
const record = byId[ids[index]];
|
|
287
|
+
if (record && record.blank === true) continue;
|
|
288
|
+
const retained = record && record.retainedBy ? record.retainedBy : null;
|
|
289
|
+
if (retained && (retained.mainView | 0) > 0) return ids[index];
|
|
290
|
+
}
|
|
291
|
+
return '';
|
|
292
|
+
} catch (thrown) {
|
|
293
|
+
return '';
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function displayTitleOf(entry) {
|
|
298
|
+
if (entry && typeof entry.title === 'string' && entry.title !== '') return entry.title;
|
|
299
|
+
const first = String(entry && entry.body ? entry.body : '').split('\n')[0].trim();
|
|
300
|
+
if (first === '') return '(无标题)';
|
|
301
|
+
return first.length > 40 ? first.slice(0, 40) + '…' : first;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function bodyFirstLine(entry) {
|
|
305
|
+
const body = entry && typeof entry.body === 'string' ? entry.body : '';
|
|
306
|
+
const first = body.split('\n')[0].trim();
|
|
307
|
+
return first.length > 48 ? first.slice(0, 48) + '…' : first;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** The clipboard text for one memo: 标题 newline 正文. */
|
|
311
|
+
function buildCopyText(entry) {
|
|
312
|
+
const body = entry && typeof entry.body === 'string' ? entry.body : '';
|
|
313
|
+
let title = entry && typeof entry.title === 'string' && entry.title !== '' ? entry.title : '';
|
|
314
|
+
if (title === '') {
|
|
315
|
+
const first = body.split('\n')[0].trim();
|
|
316
|
+
title = first.length > 40 ? first.slice(0, 40) + '…' : first || '(无标题)';
|
|
317
|
+
}
|
|
318
|
+
return body === '' ? title : title + '\n' + body;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** Clipboard write: async Clipboard API first, then execCommand plus a temp textarea. */
|
|
322
|
+
async function copyTextToClipboard(text) {
|
|
323
|
+
const value = String(text);
|
|
324
|
+
try {
|
|
325
|
+
const nav = typeof navigator !== 'undefined' ? navigator : null;
|
|
326
|
+
if (nav && nav.clipboard && typeof nav.clipboard.writeText === 'function') {
|
|
327
|
+
await nav.clipboard.writeText(value);
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
330
|
+
} catch (thrown) {
|
|
331
|
+
/* Clipboard API rejected (permissions / insecure context): use the fallback. */
|
|
332
|
+
}
|
|
333
|
+
try {
|
|
334
|
+
if (typeof document === 'undefined') return false;
|
|
335
|
+
const area = document.createElement('textarea');
|
|
336
|
+
area.value = value;
|
|
337
|
+
area.setAttribute('readonly', '');
|
|
338
|
+
area.style.position = 'fixed';
|
|
339
|
+
area.style.top = '-1000px';
|
|
340
|
+
area.style.left = '-1000px';
|
|
341
|
+
area.style.opacity = '0';
|
|
342
|
+
(document.body || document.documentElement).appendChild(area);
|
|
343
|
+
let ok = false;
|
|
344
|
+
try {
|
|
345
|
+
area.select();
|
|
346
|
+
ok = document.execCommand('copy') === true;
|
|
347
|
+
} catch (thrown) {
|
|
348
|
+
ok = false;
|
|
349
|
+
}
|
|
350
|
+
if (area.parentNode) area.parentNode.removeChild(area);
|
|
351
|
+
return ok;
|
|
352
|
+
} catch (thrown) {
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function gearIcon() {
|
|
358
|
+
return h(
|
|
359
|
+
'svg',
|
|
360
|
+
{
|
|
361
|
+
width: 16,
|
|
362
|
+
height: 16,
|
|
363
|
+
viewBox: '0 0 24 24',
|
|
364
|
+
fill: 'none',
|
|
365
|
+
stroke: 'currentColor',
|
|
366
|
+
strokeWidth: 1.8,
|
|
367
|
+
strokeLinecap: 'round',
|
|
368
|
+
strokeLinejoin: 'round',
|
|
369
|
+
'aria-hidden': 'true',
|
|
370
|
+
},
|
|
371
|
+
[
|
|
372
|
+
h('circle', { key: 'c', cx: 12, cy: 12, r: 3 }),
|
|
373
|
+
h('path', {
|
|
374
|
+
key: 'p',
|
|
375
|
+
d:
|
|
376
|
+
'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',
|
|
377
|
+
}),
|
|
378
|
+
],
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/** Flatten the three scopes into one card list, session then profile then user. */
|
|
383
|
+
function flattenEntries(payload) {
|
|
384
|
+
const out = [];
|
|
385
|
+
if (!payload) return out;
|
|
386
|
+
const scopes = ['session', 'profile', 'user'];
|
|
387
|
+
for (let s = 0; s < scopes.length; s += 1) {
|
|
388
|
+
const scope = scopes[s];
|
|
389
|
+
const rows = Array.isArray(payload[scope]) ? payload[scope] : [];
|
|
390
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
391
|
+
out.push({ entry: rows[index], scope: scope });
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return out;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* The management UI (three scopes, add form, done toggle, inline edit, two
|
|
399
|
+
* step delete). Rendered as the tab seat (embedded=false, with its own head)
|
|
400
|
+
* or inside the overlay page (embedded=true, head supplied by the page).
|
|
401
|
+
*/
|
|
402
|
+
function MemoPanel(props) {
|
|
175
403
|
injectStyle();
|
|
176
404
|
|
|
177
405
|
const sessionId = props && typeof props.sessionId === 'string' ? props.sessionId : '';
|
|
406
|
+
const embedded = props && props.embedded === true;
|
|
178
407
|
const hasSession = sessionId !== '';
|
|
179
408
|
|
|
180
409
|
const [payload, setPayload] = React.useState(null);
|
|
@@ -332,13 +561,6 @@ window.__ModuleLoader__.load({
|
|
|
332
561
|
}, wait);
|
|
333
562
|
}
|
|
334
563
|
|
|
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
564
|
function renderHead() {
|
|
343
565
|
return h('div', { key: 'head', className: 'bm-head' }, [
|
|
344
566
|
h('span', { key: 'title', className: 'bm-title' }, '备忘录'),
|
|
@@ -391,8 +613,8 @@ window.__ModuleLoader__.load({
|
|
|
391
613
|
},
|
|
392
614
|
[
|
|
393
615
|
h('option', { key: 'session', value: 'session', disabled: !hasSession }, '本会话'),
|
|
394
|
-
h('option', { key: 'profile', value: 'profile' }, '
|
|
395
|
-
h('option', { key: 'user', value: 'user' }, '
|
|
616
|
+
h('option', { key: 'profile', value: 'profile' }, '全局共享'),
|
|
617
|
+
h('option', { key: 'user', value: 'user' }, '仅用户'),
|
|
396
618
|
],
|
|
397
619
|
),
|
|
398
620
|
]),
|
|
@@ -428,7 +650,7 @@ window.__ModuleLoader__.load({
|
|
|
428
650
|
: h(
|
|
429
651
|
'p',
|
|
430
652
|
{ key: 'note', className: 'bm-note' },
|
|
431
|
-
'
|
|
653
|
+
'这个视图没带会话,只能用「全局共享」或「仅用户」。',
|
|
432
654
|
),
|
|
433
655
|
h('div', { key: 'actions', className: 'bm-form-actions' }, [
|
|
434
656
|
h(
|
|
@@ -508,6 +730,7 @@ window.__ModuleLoader__.load({
|
|
|
508
730
|
]),
|
|
509
731
|
);
|
|
510
732
|
} else {
|
|
733
|
+
const confirming = confirmId === entry.id;
|
|
511
734
|
children.push(
|
|
512
735
|
h('div', { key: 'head', className: 'bm-row-head' }, [
|
|
513
736
|
h('label', { key: 'label', className: 'bm-check' }, [
|
|
@@ -523,7 +746,35 @@ window.__ModuleLoader__.load({
|
|
|
523
746
|
h(
|
|
524
747
|
'span',
|
|
525
748
|
{ key: 't', className: entry.done === true ? 'bm-row-title bm-done' : 'bm-row-title' },
|
|
526
|
-
|
|
749
|
+
displayTitleOf(entry),
|
|
750
|
+
),
|
|
751
|
+
]),
|
|
752
|
+
h('div', { key: 'actions', className: 'bm-row-actions' }, [
|
|
753
|
+
h(
|
|
754
|
+
'button',
|
|
755
|
+
{
|
|
756
|
+
key: 'edit',
|
|
757
|
+
type: 'button',
|
|
758
|
+
className: 'bm-btn bm-btn-ghost bm-row-act',
|
|
759
|
+
'data-bm-edit': entry.id,
|
|
760
|
+
onClick: function () {
|
|
761
|
+
startEdit(entry);
|
|
762
|
+
},
|
|
763
|
+
},
|
|
764
|
+
'改',
|
|
765
|
+
),
|
|
766
|
+
h(
|
|
767
|
+
'button',
|
|
768
|
+
{
|
|
769
|
+
key: 'delete',
|
|
770
|
+
type: 'button',
|
|
771
|
+
className: confirming ? 'bm-btn bm-btn-danger bm-row-act' : 'bm-btn bm-btn-ghost bm-row-act',
|
|
772
|
+
'data-bm-delete': entry.id,
|
|
773
|
+
onClick: function () {
|
|
774
|
+
requestDelete(entry);
|
|
775
|
+
},
|
|
776
|
+
},
|
|
777
|
+
confirming ? '确定删?' : '删',
|
|
527
778
|
),
|
|
528
779
|
]),
|
|
529
780
|
]),
|
|
@@ -531,37 +782,6 @@ window.__ModuleLoader__.load({
|
|
|
531
782
|
if (typeof entry.body === 'string' && entry.body !== '') {
|
|
532
783
|
children.push(h('div', { key: 'body', className: 'bm-row-body' }, entry.body));
|
|
533
784
|
}
|
|
534
|
-
const confirming = confirmId === entry.id;
|
|
535
|
-
children.push(
|
|
536
|
-
h('div', { key: 'actions', className: 'bm-row-actions' }, [
|
|
537
|
-
h(
|
|
538
|
-
'button',
|
|
539
|
-
{
|
|
540
|
-
key: 'edit',
|
|
541
|
-
type: 'button',
|
|
542
|
-
className: 'bm-btn',
|
|
543
|
-
'data-bm-edit': entry.id,
|
|
544
|
-
onClick: function () {
|
|
545
|
-
startEdit(entry);
|
|
546
|
-
},
|
|
547
|
-
},
|
|
548
|
-
'改',
|
|
549
|
-
),
|
|
550
|
-
h(
|
|
551
|
-
'button',
|
|
552
|
-
{
|
|
553
|
-
key: 'delete',
|
|
554
|
-
type: 'button',
|
|
555
|
-
className: confirming ? 'bm-btn bm-btn-danger' : 'bm-btn',
|
|
556
|
-
'data-bm-delete': entry.id,
|
|
557
|
-
onClick: function () {
|
|
558
|
-
requestDelete(entry);
|
|
559
|
-
},
|
|
560
|
-
},
|
|
561
|
-
confirming ? '确定删?' : '删',
|
|
562
|
-
),
|
|
563
|
-
]),
|
|
564
|
-
);
|
|
565
785
|
}
|
|
566
786
|
|
|
567
787
|
return h(
|
|
@@ -589,7 +809,7 @@ window.__ModuleLoader__.load({
|
|
|
589
809
|
}),
|
|
590
810
|
);
|
|
591
811
|
return h('section', { key: key, className: 'bm-group', 'data-bm-group': key }, [
|
|
592
|
-
h('div', { key: 'head', className: 'bm-group-head' }, GROUP_LABEL[key] +
|
|
812
|
+
h('div', { key: 'head', className: 'bm-group-head' }, GROUP_LABEL[key] + String(entries.length)),
|
|
593
813
|
list,
|
|
594
814
|
]);
|
|
595
815
|
}
|
|
@@ -622,8 +842,8 @@ window.__ModuleLoader__.load({
|
|
|
622
842
|
'data-better-memo-version': VERSION,
|
|
623
843
|
},
|
|
624
844
|
[
|
|
625
|
-
renderHead(),
|
|
626
|
-
showHint ? h('p', { key: 'hint', className: 'bm-hint' }, HINT_TEXT) : null,
|
|
845
|
+
embedded ? null : renderHead(),
|
|
846
|
+
!embedded && showHint ? h('p', { key: 'hint', className: 'bm-hint' }, HINT_TEXT) : null,
|
|
627
847
|
renderForm(),
|
|
628
848
|
error !== null ? renderError() : null,
|
|
629
849
|
loading && payload === null ? h('p', { key: 'loading', className: 'bm-loading' }, '加载中…') : null,
|
|
@@ -641,12 +861,594 @@ window.__ModuleLoader__.load({
|
|
|
641
861
|
}
|
|
642
862
|
|
|
643
863
|
/**
|
|
644
|
-
*
|
|
645
|
-
* and
|
|
646
|
-
*
|
|
864
|
+
* The overlay: capsule button plus either the floating card or the full page.
|
|
865
|
+
* Both card and page are portalled to document.body so a fixed position is
|
|
866
|
+
* never trapped by the shell.overlay container's stacking context.
|
|
867
|
+
*/
|
|
868
|
+
function OverlayEntry(props) {
|
|
869
|
+
injectStyle();
|
|
870
|
+
|
|
871
|
+
const getSessionId = props && typeof props.getSessionId === 'function' ? props.getSessionId : function () { return ''; };
|
|
872
|
+
const subscribeSessions = props && typeof props.subscribe === 'function' ? props.subscribe : null;
|
|
873
|
+
const seat = props && props.seat ? props.seat : null;
|
|
874
|
+
const variant = props && props.variant === 'floating' ? 'floating' : 'topbar';
|
|
875
|
+
|
|
876
|
+
const [phase, setPhase] = React.useState('closed');
|
|
877
|
+
const [closing, setClosing] = React.useState(false);
|
|
878
|
+
const [payload, setPayload] = React.useState(null);
|
|
879
|
+
const [loading, setLoading] = React.useState(false);
|
|
880
|
+
const [error, setError] = React.useState(null);
|
|
881
|
+
const [settings, setSettings] = React.useState({ showTabEntry: false });
|
|
882
|
+
const [settingsSaving, setSettingsSaving] = React.useState(false);
|
|
883
|
+
const [settingsError, setSettingsError] = React.useState(null);
|
|
884
|
+
const [toast, setToast] = React.useState(null);
|
|
885
|
+
const [sessionId, setSessionId] = React.useState(function () {
|
|
886
|
+
return getSessionId();
|
|
887
|
+
});
|
|
888
|
+
const [hasSession, setHasSession] = React.useState(function () {
|
|
889
|
+
return getSessionId() !== '';
|
|
890
|
+
});
|
|
891
|
+
|
|
892
|
+
const cardRef = React.useRef(null);
|
|
893
|
+
const capsuleRef = React.useRef(null);
|
|
894
|
+
const toastTimer = React.useRef(null);
|
|
895
|
+
|
|
896
|
+
function fetchState(sid) {
|
|
897
|
+
setLoading(true);
|
|
898
|
+
setError(null);
|
|
899
|
+
requestState(sid)
|
|
900
|
+
.then(function (next) {
|
|
901
|
+
setPayload(next);
|
|
902
|
+
setSettings(settingsOf(next));
|
|
903
|
+
setLoading(false);
|
|
904
|
+
})
|
|
905
|
+
.catch(function (thrown) {
|
|
906
|
+
setError(messageOf(thrown));
|
|
907
|
+
setLoading(false);
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
React.useEffect(function () {
|
|
912
|
+
const sid = getSessionId();
|
|
913
|
+
setSessionId(sid);
|
|
914
|
+
setHasSession(sid !== '');
|
|
915
|
+
requestState(sid)
|
|
916
|
+
.then(function (next) {
|
|
917
|
+
setPayload(next);
|
|
918
|
+
setSettings(settingsOf(next));
|
|
919
|
+
})
|
|
920
|
+
.catch(function () {
|
|
921
|
+
/* the capsule still opens; its first refresh will retry */
|
|
922
|
+
});
|
|
923
|
+
return function () {
|
|
924
|
+
if (toastTimer.current !== null) {
|
|
925
|
+
clearTimeout(toastTimer.current);
|
|
926
|
+
toastTimer.current = null;
|
|
927
|
+
}
|
|
928
|
+
};
|
|
929
|
+
}, []);
|
|
930
|
+
|
|
931
|
+
/* The capsule belongs to a conversation. On the new-session / welcome
|
|
932
|
+
screen there is no session in the main view, so it stays hidden. */
|
|
933
|
+
React.useEffect(function () {
|
|
934
|
+
if (subscribeSessions === null) return undefined;
|
|
935
|
+
const sync = function () {
|
|
936
|
+
const next = getSessionId();
|
|
937
|
+
setSessionId(function (prev) {
|
|
938
|
+
return prev === next ? prev : next;
|
|
939
|
+
});
|
|
940
|
+
setHasSession(next !== '');
|
|
941
|
+
if (next === '') setPhase('closed');
|
|
942
|
+
};
|
|
943
|
+
sync();
|
|
944
|
+
let stop = null;
|
|
945
|
+
try {
|
|
946
|
+
stop = subscribeSessions(sync);
|
|
947
|
+
} catch (thrown) {
|
|
948
|
+
stop = null;
|
|
949
|
+
}
|
|
950
|
+
return function () {
|
|
951
|
+
if (typeof stop === 'function') stop();
|
|
952
|
+
};
|
|
953
|
+
}, []);
|
|
954
|
+
|
|
955
|
+
React.useEffect(
|
|
956
|
+
function () {
|
|
957
|
+
if (toast === null) return undefined;
|
|
958
|
+
if (toastTimer.current !== null) clearTimeout(toastTimer.current);
|
|
959
|
+
toastTimer.current = setTimeout(function () {
|
|
960
|
+
toastTimer.current = null;
|
|
961
|
+
setToast(null);
|
|
962
|
+
}, COPY_MS);
|
|
963
|
+
return function () {
|
|
964
|
+
if (toastTimer.current !== null) {
|
|
965
|
+
clearTimeout(toastTimer.current);
|
|
966
|
+
toastTimer.current = null;
|
|
967
|
+
}
|
|
968
|
+
};
|
|
969
|
+
},
|
|
970
|
+
[toast],
|
|
971
|
+
);
|
|
972
|
+
|
|
973
|
+
function openCard() {
|
|
974
|
+
const sid = getSessionId();
|
|
975
|
+
setSessionId(sid);
|
|
976
|
+
setPhase('card');
|
|
977
|
+
setClosing(false);
|
|
978
|
+
fetchState(sid);
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
function requestClose() {
|
|
982
|
+
if (phase === 'card') {
|
|
983
|
+
if (closing) return;
|
|
984
|
+
if (prefersReduced()) {
|
|
985
|
+
setPhase('closed');
|
|
986
|
+
setClosing(false);
|
|
987
|
+
} else {
|
|
988
|
+
setClosing(true);
|
|
989
|
+
}
|
|
990
|
+
} else if (phase === 'page') {
|
|
991
|
+
setPhase('closed');
|
|
992
|
+
setClosing(false);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
function toggle() {
|
|
997
|
+
if (phase === 'closed') openCard();
|
|
998
|
+
else requestClose();
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
function toPage() {
|
|
1002
|
+
setPhase('page');
|
|
1003
|
+
setClosing(false);
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
function backToCard() {
|
|
1007
|
+
setPhase('card');
|
|
1008
|
+
setClosing(false);
|
|
1009
|
+
/* The page edits entries; the card list must not show the stale snapshot. */
|
|
1010
|
+
fetchState(getSessionId());
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
function onCardAnimationEnd(event) {
|
|
1014
|
+
if (event && event.target !== cardRef.current) return;
|
|
1015
|
+
if (closing) {
|
|
1016
|
+
setPhase('closed');
|
|
1017
|
+
setClosing(false);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
/* Outside click and ESC close the card. */
|
|
1022
|
+
React.useEffect(
|
|
1023
|
+
function () {
|
|
1024
|
+
if (phase !== 'card') return undefined;
|
|
1025
|
+
function onDown(event) {
|
|
1026
|
+
const card = cardRef.current;
|
|
1027
|
+
const capsule = capsuleRef.current;
|
|
1028
|
+
if (card && card.contains(event.target)) return;
|
|
1029
|
+
if (capsule && capsule.contains(event.target)) return;
|
|
1030
|
+
requestClose();
|
|
1031
|
+
}
|
|
1032
|
+
function onKey(event) {
|
|
1033
|
+
if (event.key === 'Escape') {
|
|
1034
|
+
event.stopPropagation();
|
|
1035
|
+
requestClose();
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
document.addEventListener('mousedown', onDown, true);
|
|
1039
|
+
document.addEventListener('keydown', onKey, true);
|
|
1040
|
+
return function () {
|
|
1041
|
+
document.removeEventListener('mousedown', onDown, true);
|
|
1042
|
+
document.removeEventListener('keydown', onKey, true);
|
|
1043
|
+
};
|
|
1044
|
+
},
|
|
1045
|
+
[phase, closing],
|
|
1046
|
+
);
|
|
1047
|
+
|
|
1048
|
+
/* ESC backs out of the page; a click on the area outside the page does the same.
|
|
1049
|
+
mousedown (not click) so a drag that starts inside the page never counts. */
|
|
1050
|
+
React.useEffect(
|
|
1051
|
+
function () {
|
|
1052
|
+
if (phase !== 'page') return undefined;
|
|
1053
|
+
function onKey(event) {
|
|
1054
|
+
if (event.key === 'Escape') {
|
|
1055
|
+
event.stopPropagation();
|
|
1056
|
+
backToCard();
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
function onDown(event) {
|
|
1060
|
+
const backdrop = document.querySelector('[data-bm-backdrop="1"]');
|
|
1061
|
+
if (!backdrop) return;
|
|
1062
|
+
if (backdrop.contains(event.target) && event.target !== backdrop) return;
|
|
1063
|
+
backToCard();
|
|
1064
|
+
}
|
|
1065
|
+
document.addEventListener('keydown', onKey, true);
|
|
1066
|
+
document.addEventListener('mousedown', onDown, true);
|
|
1067
|
+
return function () {
|
|
1068
|
+
document.removeEventListener('keydown', onKey, true);
|
|
1069
|
+
document.removeEventListener('mousedown', onDown, true);
|
|
1070
|
+
};
|
|
1071
|
+
},
|
|
1072
|
+
[phase],
|
|
1073
|
+
);
|
|
1074
|
+
|
|
1075
|
+
function copyEntry(entry) {
|
|
1076
|
+
copyTextToClipboard(buildCopyText(entry)).then(function (ok) {
|
|
1077
|
+
setToast(ok ? '已复制' : '复制失败');
|
|
1078
|
+
}).catch(function () {
|
|
1079
|
+
setToast('复制失败');
|
|
1080
|
+
});
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
function applyShowTab(next) {
|
|
1084
|
+
const prev = settings;
|
|
1085
|
+
const want = next === true;
|
|
1086
|
+
setSettings({ showTabEntry: want });
|
|
1087
|
+
setSettingsSaving(true);
|
|
1088
|
+
setSettingsError(null);
|
|
1089
|
+
requestSettings(want)
|
|
1090
|
+
.then(function (result) {
|
|
1091
|
+
const resolved = settingsOf(result);
|
|
1092
|
+
setSettings({ showTabEntry: resolved.showTabEntry });
|
|
1093
|
+
if (seat && typeof seat.setEnabled === 'function') seat.setEnabled(resolved.showTabEntry);
|
|
1094
|
+
setSettingsSaving(false);
|
|
1095
|
+
})
|
|
1096
|
+
.catch(function (thrown) {
|
|
1097
|
+
setSettings(prev);
|
|
1098
|
+
setSettingsError(messageOf(thrown));
|
|
1099
|
+
setSettingsSaving(false);
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
const entries = flattenEntries(payload);
|
|
1104
|
+
const count = entries.length;
|
|
1105
|
+
|
|
1106
|
+
const capsule = h(
|
|
1107
|
+
'button',
|
|
1108
|
+
{
|
|
1109
|
+
key: 'capsule',
|
|
1110
|
+
ref: capsuleRef,
|
|
1111
|
+
type: 'button',
|
|
1112
|
+
className: 'bm-capsule' + (variant === 'floating' ? ' bm-capsule-floating' : ''),
|
|
1113
|
+
'data-bm-entry': '1',
|
|
1114
|
+
'data-better-memo-version': VERSION,
|
|
1115
|
+
'data-bm-open': phase !== 'closed' ? '1' : '0',
|
|
1116
|
+
'aria-label': '备忘录',
|
|
1117
|
+
title: '备忘录',
|
|
1118
|
+
onClick: toggle,
|
|
1119
|
+
},
|
|
1120
|
+
[
|
|
1121
|
+
h('span', { key: 'label', className: 'bm-capsule-label' }, '备忘录'),
|
|
1122
|
+
count > 0 ? h('span', { key: 'count', className: 'bm-capsule-count' }, String(count)) : null,
|
|
1123
|
+
],
|
|
1124
|
+
);
|
|
1125
|
+
|
|
1126
|
+
function cardBody() {
|
|
1127
|
+
const items = [];
|
|
1128
|
+
if (loading && payload === null) {
|
|
1129
|
+
items.push(h('p', { key: 'loading', className: 'bm-card-empty' }, '加载中…'));
|
|
1130
|
+
} else if (error !== null) {
|
|
1131
|
+
items.push(
|
|
1132
|
+
h('div', { key: 'error', className: 'bm-card-error' }, [
|
|
1133
|
+
h('span', { key: 'm' }, '出错了:' + error),
|
|
1134
|
+
h(
|
|
1135
|
+
'button',
|
|
1136
|
+
{
|
|
1137
|
+
key: 'r',
|
|
1138
|
+
type: 'button',
|
|
1139
|
+
className: 'bm-btn bm-btn-ghost',
|
|
1140
|
+
onClick: function () {
|
|
1141
|
+
fetchState(sessionId);
|
|
1142
|
+
},
|
|
1143
|
+
},
|
|
1144
|
+
'重试',
|
|
1145
|
+
),
|
|
1146
|
+
]),
|
|
1147
|
+
);
|
|
1148
|
+
} else if (entries.length === 0) {
|
|
1149
|
+
items.push(h('p', { key: 'empty', className: 'bm-card-empty' }, '还没有备忘录'));
|
|
1150
|
+
} else {
|
|
1151
|
+
entries.forEach(function (item, index) {
|
|
1152
|
+
const delay = Math.min(index * STAGGER_MS, (MAX_STAGGER - 1) * STAGGER_MS) + 'ms';
|
|
1153
|
+
const sub = bodyFirstLine(item.entry);
|
|
1154
|
+
const rowChildren = [
|
|
1155
|
+
h('span', { key: 'dot', className: 'bm-card-dot', 'data-bm-scope': item.scope, 'aria-hidden': 'true' }),
|
|
1156
|
+
h('span', { key: 'text', className: 'bm-card-item-text' }, [
|
|
1157
|
+
h('span', { key: 't', className: 'bm-card-item-title' }, displayTitleOf(item.entry)),
|
|
1158
|
+
sub !== '' ? h('span', { key: 's', className: 'bm-card-item-sub' }, sub) : null,
|
|
1159
|
+
]),
|
|
1160
|
+
h('span', { key: 'tag', className: 'bm-card-tag', 'data-bm-scope': item.scope }, SCOPE_TAG[item.scope] || item.scope),
|
|
1161
|
+
];
|
|
1162
|
+
items.push(
|
|
1163
|
+
h(
|
|
1164
|
+
'button',
|
|
1165
|
+
{
|
|
1166
|
+
key: item.entry.id || 'entry-' + index,
|
|
1167
|
+
type: 'button',
|
|
1168
|
+
className: 'bm-card-item',
|
|
1169
|
+
'data-bm-copy': item.entry.id || '',
|
|
1170
|
+
'data-bm-scope': item.scope,
|
|
1171
|
+
title: displayTitleOf(item.entry),
|
|
1172
|
+
style: closing ? undefined : { animationDelay: delay },
|
|
1173
|
+
onClick: function () {
|
|
1174
|
+
copyEntry(item.entry);
|
|
1175
|
+
},
|
|
1176
|
+
},
|
|
1177
|
+
rowChildren,
|
|
1178
|
+
),
|
|
1179
|
+
);
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1182
|
+
return items;
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
function cardNode() {
|
|
1186
|
+
return h(
|
|
1187
|
+
'div',
|
|
1188
|
+
{
|
|
1189
|
+
key: 'card',
|
|
1190
|
+
ref: cardRef,
|
|
1191
|
+
className: 'bm-card' + (closing ? ' bm-card-out' : '') + (variant === 'floating' ? ' bm-card-floating' : ''),
|
|
1192
|
+
'data-bm-card': '1',
|
|
1193
|
+
onAnimationEnd: onCardAnimationEnd,
|
|
1194
|
+
},
|
|
1195
|
+
[
|
|
1196
|
+
h('div', { key: 'head', className: 'bm-card-head' }, [
|
|
1197
|
+
h('span', { key: 'title', className: 'bm-card-title' }, '备忘录'),
|
|
1198
|
+
h('span', { key: 'count', className: 'bm-card-count' }, String(count)),
|
|
1199
|
+
h('span', { key: 'spacer', className: 'bm-card-spacer' }),
|
|
1200
|
+
h(
|
|
1201
|
+
'button',
|
|
1202
|
+
{
|
|
1203
|
+
key: 'gear',
|
|
1204
|
+
type: 'button',
|
|
1205
|
+
className: 'bm-card-gear',
|
|
1206
|
+
'data-bm-gear': '1',
|
|
1207
|
+
'aria-label': '设置',
|
|
1208
|
+
title: '设置',
|
|
1209
|
+
onClick: toPage,
|
|
1210
|
+
},
|
|
1211
|
+
gearIcon(),
|
|
1212
|
+
),
|
|
1213
|
+
]),
|
|
1214
|
+
h('div', { key: 'body', className: 'bm-card-body' }, cardBody()),
|
|
1215
|
+
count > 0
|
|
1216
|
+
? h('div', { key: 'foot', className: 'bm-card-foot' }, '点一行即可复制;齿轮里管理全部')
|
|
1217
|
+
: null,
|
|
1218
|
+
toast !== null ? h('div', { key: 'toast', className: 'bm-card-toast', role: 'status' }, toast) : null,
|
|
1219
|
+
],
|
|
1220
|
+
);
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
function pageNode() {
|
|
1224
|
+
return h('div', { key: 'page', className: 'bm-overlay-backdrop', 'data-bm-backdrop': '1' }, [
|
|
1225
|
+
h('div', { key: 'panel', className: 'bm-page', 'data-bm-page': '1' }, [
|
|
1226
|
+
h('div', { key: 'head', className: 'bm-page-head' }, [
|
|
1227
|
+
h(
|
|
1228
|
+
'button',
|
|
1229
|
+
{ key: 'back', type: 'button', className: 'bm-btn bm-btn-ghost bm-page-back', 'data-bm-back': '1', onClick: backToCard },
|
|
1230
|
+
'← 返回',
|
|
1231
|
+
),
|
|
1232
|
+
h('span', { key: 'title', className: 'bm-page-title' }, '备忘录设置'),
|
|
1233
|
+
h('span', { key: 'spacer', className: 'bm-page-spacer' }),
|
|
1234
|
+
h(
|
|
1235
|
+
'button',
|
|
1236
|
+
{
|
|
1237
|
+
key: 'close',
|
|
1238
|
+
type: 'button',
|
|
1239
|
+
className: 'bm-btn bm-btn-ghost bm-page-close',
|
|
1240
|
+
'data-bm-close': '1',
|
|
1241
|
+
'aria-label': '关闭',
|
|
1242
|
+
onClick: function () {
|
|
1243
|
+
setPhase('closed');
|
|
1244
|
+
setClosing(false);
|
|
1245
|
+
},
|
|
1246
|
+
},
|
|
1247
|
+
'×',
|
|
1248
|
+
),
|
|
1249
|
+
]),
|
|
1250
|
+
h('div', { key: 'switch', className: 'bm-page-switch' }, [
|
|
1251
|
+
h('label', { key: 'label', className: 'bm-switch' }, [
|
|
1252
|
+
h('input', {
|
|
1253
|
+
key: 'input',
|
|
1254
|
+
type: 'checkbox',
|
|
1255
|
+
'data-bm-showtab': '1',
|
|
1256
|
+
checked: settings.showTabEntry === true,
|
|
1257
|
+
disabled: settingsSaving,
|
|
1258
|
+
onChange: function (event) {
|
|
1259
|
+
applyShowTab(event.target.checked);
|
|
1260
|
+
},
|
|
1261
|
+
}),
|
|
1262
|
+
h('span', { key: 'text' }, '在会话 tab 行显示「备忘录」入口'),
|
|
1263
|
+
]),
|
|
1264
|
+
settingsError !== null ? h('span', { key: 'err', className: 'bm-switch-error' }, settingsError) : null,
|
|
1265
|
+
]),
|
|
1266
|
+
h('div', { key: 'body', className: 'bm-page-body' }, h(MemoPanel, { sessionId: sessionId, embedded: true })),
|
|
1267
|
+
]),
|
|
1268
|
+
]);
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
if (hasSession === false) return null;
|
|
1272
|
+
|
|
1273
|
+
let overlay = null;
|
|
1274
|
+
if (phase === 'card') overlay = cardNode();
|
|
1275
|
+
else if (phase === 'page') overlay = pageNode();
|
|
1276
|
+
|
|
1277
|
+
const portal = overlay !== null && typeof document !== 'undefined' && document.body
|
|
1278
|
+
? ReactDOM.createPortal(overlay, document.body)
|
|
1279
|
+
: null;
|
|
1280
|
+
|
|
1281
|
+
return h(React.Fragment, null, [capsule, portal]);
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
/**
|
|
1285
|
+
* Owns the single conversation.view tab seat. Registering and disposing are
|
|
1286
|
+
* the two moments the settings switch drives; a not-yet-declared slot is
|
|
1287
|
+
* retried (never assumed), matching the "ask slots.spec first" rule.
|
|
647
1288
|
*/
|
|
1289
|
+
function createSeatController(ctx) {
|
|
1290
|
+
let dispose = null;
|
|
1291
|
+
let enabled = false;
|
|
1292
|
+
let attempts = 0;
|
|
1293
|
+
let timer = null;
|
|
1294
|
+
|
|
1295
|
+
function slotsOf() {
|
|
1296
|
+
try {
|
|
1297
|
+
return typeof ctx.get === 'function' ? ctx.get('slots') : undefined;
|
|
1298
|
+
} catch (thrown) {
|
|
1299
|
+
return undefined;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
function clearTimer() {
|
|
1304
|
+
if (timer !== null) {
|
|
1305
|
+
clearTimeout(timer);
|
|
1306
|
+
timer = null;
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
function schedule() {
|
|
1311
|
+
clearTimer();
|
|
1312
|
+
if (!enabled) return;
|
|
1313
|
+
if (attempts >= RETRY_LIMIT) return;
|
|
1314
|
+
attempts += 1;
|
|
1315
|
+
timer = setTimeout(function () {
|
|
1316
|
+
timer = null;
|
|
1317
|
+
register();
|
|
1318
|
+
}, RETRY_MS);
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
function register() {
|
|
1322
|
+
if (!enabled || dispose !== null) return;
|
|
1323
|
+
const slots = slotsOf();
|
|
1324
|
+
if (!slots || typeof slots.register !== 'function') {
|
|
1325
|
+
schedule();
|
|
1326
|
+
return;
|
|
1327
|
+
}
|
|
1328
|
+
let declared = false;
|
|
1329
|
+
try {
|
|
1330
|
+
declared = typeof slots.spec === 'function' && slots.spec(SLOT) !== undefined;
|
|
1331
|
+
} catch (thrown) {
|
|
1332
|
+
declared = false;
|
|
1333
|
+
}
|
|
1334
|
+
if (!declared) {
|
|
1335
|
+
schedule();
|
|
1336
|
+
return;
|
|
1337
|
+
}
|
|
1338
|
+
try {
|
|
1339
|
+
dispose = slots.register(
|
|
1340
|
+
{ name: SLOT, id: SEAT_ID, order: 1, label: function () { return '备忘录'; } },
|
|
1341
|
+
function (props) {
|
|
1342
|
+
const sid = props && typeof props.sessionId === 'string' ? props.sessionId : '';
|
|
1343
|
+
return h(MemoPanel, { sessionId: sid, embedded: false });
|
|
1344
|
+
},
|
|
1345
|
+
);
|
|
1346
|
+
} catch (thrown) {
|
|
1347
|
+
dispose = null;
|
|
1348
|
+
schedule();
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
function setEnabled(next) {
|
|
1353
|
+
const want = next === true;
|
|
1354
|
+
enabled = want;
|
|
1355
|
+
if (want) {
|
|
1356
|
+
attempts = 0;
|
|
1357
|
+
register();
|
|
1358
|
+
} else {
|
|
1359
|
+
clearTimer();
|
|
1360
|
+
attempts = 0;
|
|
1361
|
+
if (dispose !== null) {
|
|
1362
|
+
const drop = dispose;
|
|
1363
|
+
dispose = null;
|
|
1364
|
+
try {
|
|
1365
|
+
drop();
|
|
1366
|
+
} catch (thrown) {
|
|
1367
|
+
/* host already released it */
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
return {
|
|
1374
|
+
setEnabled: setEnabled,
|
|
1375
|
+
isEnabled: function () { return enabled; },
|
|
1376
|
+
hasSeat: function () { return dispose !== null; },
|
|
1377
|
+
};
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
function mountBodyFallback(deps) {
|
|
1381
|
+
if (typeof document === 'undefined' || !document.body) return;
|
|
1382
|
+
try {
|
|
1383
|
+
const host = document.createElement('div');
|
|
1384
|
+
host.id = FALLBACK_HOST_ID;
|
|
1385
|
+
host.setAttribute('data-better-memo-overlay', '');
|
|
1386
|
+
document.body.appendChild(host);
|
|
1387
|
+
const root = ReactDOMClient.createRoot(host);
|
|
1388
|
+
root.render(h(OverlayEntry, { seat: deps.seat, getSessionId: deps.getSessionId, subscribe: deps.subscribe, variant: 'floating' }));
|
|
1389
|
+
} catch (thrown) {
|
|
1390
|
+
console.error('[better-memo] floating entry failed', thrown);
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
|
|
648
1394
|
function apply(ctx) {
|
|
649
|
-
|
|
1395
|
+
injectStyle();
|
|
1396
|
+
const seat = createSeatController(ctx);
|
|
1397
|
+
const deps = {
|
|
1398
|
+
seat: seat,
|
|
1399
|
+
getSessionId: function () {
|
|
1400
|
+
return currentSessionId(ctx);
|
|
1401
|
+
},
|
|
1402
|
+
/* Sessions list changes decide whether a conversation is on screen at
|
|
1403
|
+
all; the capsule hides itself while the welcome screen is up. */
|
|
1404
|
+
subscribe: function (listener) {
|
|
1405
|
+
try {
|
|
1406
|
+
const sessions = typeof ctx.get === 'function' ? ctx.get('sessions') : undefined;
|
|
1407
|
+
if (!sessions || !sessions.list || typeof sessions.list.subscribe !== 'function') return null;
|
|
1408
|
+
return sessions.list.subscribe(listener);
|
|
1409
|
+
} catch (thrown) {
|
|
1410
|
+
return null;
|
|
1411
|
+
}
|
|
1412
|
+
},
|
|
1413
|
+
};
|
|
1414
|
+
|
|
1415
|
+
let overlayMounted = false;
|
|
1416
|
+
let seatStarted = false;
|
|
1417
|
+
|
|
1418
|
+
function startSeat() {
|
|
1419
|
+
if (seatStarted) return;
|
|
1420
|
+
seatStarted = true;
|
|
1421
|
+
requestState('')
|
|
1422
|
+
.then(function (payload) {
|
|
1423
|
+
seat.setEnabled(settingsOf(payload).showTabEntry);
|
|
1424
|
+
})
|
|
1425
|
+
.catch(function () {
|
|
1426
|
+
/* unreachable host: leave the seat off */
|
|
1427
|
+
});
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
function registerCapsule(slots) {
|
|
1431
|
+
if (overlayMounted) return;
|
|
1432
|
+
try {
|
|
1433
|
+
slots.register(
|
|
1434
|
+
{ name: TOPBAR_SLOT, id: CAPSULE_ID, order: 0, label: function () { return '备忘录'; } },
|
|
1435
|
+
function () {
|
|
1436
|
+
return h(OverlayEntry, { seat: seat, getSessionId: deps.getSessionId, subscribe: deps.subscribe, variant: 'topbar' });
|
|
1437
|
+
},
|
|
1438
|
+
);
|
|
1439
|
+
overlayMounted = true;
|
|
1440
|
+
} catch (thrown) {
|
|
1441
|
+
console.error('[better-memo] capsule registration failed', thrown);
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
function mountFloating() {
|
|
1446
|
+
if (overlayMounted) return;
|
|
1447
|
+
overlayMounted = true;
|
|
1448
|
+
mountBodyFallback(deps);
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
function boot(attemptsLeft) {
|
|
650
1452
|
let slots = null;
|
|
651
1453
|
try {
|
|
652
1454
|
slots = typeof ctx.get === 'function' ? ctx.get('slots') : undefined;
|
|
@@ -654,30 +1456,48 @@ window.__ModuleLoader__.load({
|
|
|
654
1456
|
slots = undefined;
|
|
655
1457
|
}
|
|
656
1458
|
if (slots === undefined || slots === null) {
|
|
657
|
-
if (attemptsLeft > 0)
|
|
1459
|
+
if (attemptsLeft > 0) {
|
|
1460
|
+
setTimeout(function () { boot(attemptsLeft - 1); }, RETRY_MS);
|
|
1461
|
+
return;
|
|
1462
|
+
}
|
|
1463
|
+
mountFloating();
|
|
658
1464
|
return;
|
|
659
1465
|
}
|
|
1466
|
+
startSeat();
|
|
1467
|
+
let hasOverlay = false;
|
|
660
1468
|
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
|
-
);
|
|
1469
|
+
hasOverlay = typeof slots.spec === 'function' && slots.spec(TOPBAR_SLOT) !== undefined;
|
|
674
1470
|
} catch (thrown) {
|
|
675
|
-
|
|
1471
|
+
hasOverlay = false;
|
|
676
1472
|
}
|
|
677
|
-
|
|
678
|
-
|
|
1473
|
+
if (hasOverlay) {
|
|
1474
|
+
registerCapsule(slots);
|
|
1475
|
+
return;
|
|
1476
|
+
}
|
|
1477
|
+
if (attemptsLeft > 0) {
|
|
1478
|
+
setTimeout(function () { boot(attemptsLeft - 1); }, RETRY_MS);
|
|
1479
|
+
return;
|
|
1480
|
+
}
|
|
1481
|
+
mountFloating();
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
boot(RETRY_LIMIT);
|
|
679
1485
|
}
|
|
680
1486
|
|
|
681
|
-
return {
|
|
1487
|
+
return {
|
|
1488
|
+
apply,
|
|
1489
|
+
/* Exposed only for the headless logic probe; the loader ignores extra keys. */
|
|
1490
|
+
__probe: {
|
|
1491
|
+
buildCopyText: buildCopyText,
|
|
1492
|
+
displayTitleOf: displayTitleOf,
|
|
1493
|
+
settingsOf: settingsOf,
|
|
1494
|
+
copyTextToClipboard: copyTextToClipboard,
|
|
1495
|
+
createSeatController: createSeatController,
|
|
1496
|
+
requestSettings: requestSettings,
|
|
1497
|
+
currentSessionId: currentSessionId,
|
|
1498
|
+
flattenEntries: flattenEntries,
|
|
1499
|
+
constants: { VERSION: VERSION, VERSION_STRING: '0.2.0' },
|
|
1500
|
+
},
|
|
1501
|
+
};
|
|
682
1502
|
},
|
|
683
1503
|
});
|