dsh-todo-board 0.4.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.
@@ -0,0 +1,1261 @@
1
+ window.__ModuleLoader__.load({ id: "dsh-todo-board", factory: (require) => {
2
+ var module = { exports: {} }; var exports = module.exports;
3
+ 'use strict'
4
+
5
+ /**
6
+ * dsh-todo-board — browser half.
7
+ *
8
+ * Floating board in `shell.overlay` (frame-wide layer, top-right). Design
9
+ * direction: an engineering job ticket — hairline rules, tabular monospace
10
+ * readouts, a square "auto" box versus a round "human" box, and motion used
11
+ * only where it carries meaning (row arrival, a box being checked).
12
+ *
13
+ * Transport: GET/POST `/dsh-todo-board/api`.
14
+ * Rows are drag-reorderable; on-screen top-to-bottom order IS the
15
+ * auto-continue execution order.
16
+ */
17
+
18
+ const React = require('react')
19
+ const h = React.createElement
20
+
21
+ const ROUTE = '/dsh-todo-board/api'
22
+ const MODES = ['remind', 'resume', 'newSession']
23
+ /** Must not exceed the host's MAX_IMAGES_PER_TODO. */
24
+ const MAX_IMAGES = 4
25
+ const MEDIA_TYPE_BY_EXTENSION = {
26
+ png: 'image/png',
27
+ jpg: 'image/jpeg',
28
+ jpeg: 'image/jpeg',
29
+ webp: 'image/webp',
30
+ gif: 'image/gif',
31
+ }
32
+ const MODE_LABEL = { remind: '提醒', resume: '自动续跑', newSession: '自动新会话' }
33
+ const MODE_SHORT = { remind: '提醒', resume: '续跑', newSession: '新会话' }
34
+ const MODE_HINT = {
35
+ remind: '只在这里提醒你,不会自动发送任何消息。',
36
+ resume: 'AI 一停就自动把这条注入当前会话继续跑。',
37
+ newSession: 'AI 一停就自动新建一个同目录会话来执行。',
38
+ }
39
+ const MONO = 'ui-monospace,"Cascadia Mono","SF Mono",Menlo,Consolas,monospace'
40
+ /** Bumped whenever the browser half changes, so the footer proves which build is live. */
41
+ const BUILD = '0.4.0'
42
+
43
+ const CSS = `
44
+ .dshtb-root{position:fixed;top:56px;right:16px;z-index:2147482000;pointer-events:auto;
45
+ --tb-line:var(--dsw-alias-border-l1);--tb-line2:var(--dsw-alias-border-l2);
46
+ --tb-bg:var(--dsw-alias-bg-overlay);--tb-dim:var(--dsw-alias-label-secondary);
47
+ --tb-ink:var(--dsw-alias-label-primary);--tb-accent:var(--dsw-alias-brand-primary);
48
+ --tb-ok:var(--dsw-alias-state-success-primary);--tb-warn:var(--dsw-alias-state-warn-primary);
49
+ display:flex;flex-direction:column;width:380px;max-width:calc(100vw - 32px);
50
+ max-height:min(80vh,680px);font-size:13px;line-height:1.5;color:var(--tb-ink)}
51
+ .dshtb-root *{box-sizing:border-box}
52
+ .dshtb-card{position:relative;flex:1;min-height:0;display:flex;flex-direction:column;border-radius:14px;
53
+ background:var(--tb-bg);border:1px solid var(--tb-line);overflow:hidden;
54
+ box-shadow:0 18px 50px -14px rgba(0,0,0,.5),inset 0 1px 0 rgba(255,255,255,.04);
55
+ animation:dshtb-in .16s ease-out}
56
+ .dshtb-resize{position:absolute;right:1px;bottom:1px;width:16px;height:16px;cursor:nwse-resize;
57
+ opacity:.55;background:
58
+ linear-gradient(135deg,transparent 46%,currentColor 46%,currentColor 54%,transparent 54%),
59
+ linear-gradient(135deg,transparent 68%,currentColor 68%,currentColor 76%,transparent 76%);
60
+ color:var(--tb-dim)}
61
+ .dshtb-resize:hover{opacity:1;color:var(--tb-ink)}
62
+ @keyframes dshtb-in{from{opacity:0;transform:translateY(-6px) scale(.985)}to{opacity:1;transform:none}}
63
+ .dshtb-head{display:flex;align-items:center;gap:8px;padding:10px 12px;
64
+ border-bottom:1px solid var(--tb-line);cursor:move;user-select:none}
65
+ .dshtb-title{font-weight:700;letter-spacing:.02em;white-space:nowrap}
66
+ .dshtb-title b{color:var(--tb-accent)}
67
+ .dshtb-stats{display:flex;gap:9px;font:600 11px/1 ${MONO};font-variant-numeric:tabular-nums;
68
+ color:var(--tb-dim);white-space:nowrap}
69
+ .dshtb-stats i{font-style:normal;display:inline-flex;align-items:center;gap:4px}
70
+ .dshtb-stats i::before{content:'';width:5px;height:5px;border-radius:50%;background:currentColor;opacity:.75}
71
+ .dshtb-sp{flex:1}
72
+ .dshtb-fold{width:20px;height:20px;border:0;border-radius:6px;background:transparent;color:var(--tb-dim);
73
+ cursor:pointer;font:600 13px/1 ${MONO};padding:0;transition:background .12s,color .12s}
74
+ .dshtb-fold:hover{background:var(--dsw-alias-bg-layer-1);color:var(--tb-ink)}
75
+ .dshtb-seg{display:flex;gap:2px;margin:9px 12px 0;padding:2px;border-radius:10px;
76
+ background:var(--dsw-alias-bg-layer-1);border:1px solid var(--tb-line)}
77
+ .dshtb-seg button{flex:1;display:flex;align-items:center;justify-content:center;gap:5px;padding:5px 6px;
78
+ border:0;border-radius:8px;background:transparent;color:var(--tb-dim);font:inherit;font-size:12px;
79
+ cursor:pointer;transition:background .12s,color .12s,box-shadow .12s}
80
+ .dshtb-seg button:hover{color:var(--tb-ink)}
81
+ .dshtb-seg button.on{background:var(--tb-bg);color:var(--tb-ink);font-weight:600;
82
+ box-shadow:0 1px 3px rgba(0,0,0,.2)}
83
+ .dshtb-seg em{font-style:normal;font:600 11px/1 ${MONO};font-variant-numeric:tabular-nums;opacity:.6}
84
+ .dshtb-compose{display:flex;flex-direction:column;gap:8px;padding:11px 12px;border-bottom:1px solid var(--tb-line)}
85
+ .dshtb-add{display:flex;gap:6px;align-items:flex-end}
86
+ .dshtb-add textarea{flex:1;min-width:0;min-height:66px;max-height:180px;resize:vertical;
87
+ padding:8px 10px;border-radius:9px;border:1px solid var(--tb-line);
88
+ background:var(--dsw-alias-bg-layer-1);color:var(--tb-ink);font:inherit;font-size:13px;line-height:1.5;
89
+ outline:none;transition:border-color .12s,box-shadow .12s}
90
+ .dshtb-add textarea::placeholder{color:var(--tb-dim)}
91
+ .dshtb-add textarea:focus{border-color:var(--tb-accent);box-shadow:0 0 0 3px rgba(128,128,128,.16)}
92
+ .dshtb-modes{display:flex;gap:4px}
93
+ .dshtb-modes button{flex:1;padding:6px 3px;border-radius:8px;border:1px solid var(--tb-line);
94
+ background:transparent;color:var(--tb-dim);font:inherit;font-size:12px;line-height:1.2;cursor:pointer;
95
+ white-space:nowrap;transition:border-color .12s,color .12s}
96
+ .dshtb-modes button:hover{color:var(--tb-ink);border-color:var(--tb-line2)}
97
+ .dshtb-modes button.on{border-color:var(--tb-accent);color:var(--tb-accent);font-weight:600}
98
+ .dshtb-hint{font-size:11.5px;color:var(--tb-dim);line-height:1.4}
99
+ .dshtb-dir input{width:100%;padding:6px 9px;border-radius:8px;border:1px dashed var(--tb-line);
100
+ background:transparent;color:var(--tb-dim);font:inherit;font-size:12px;outline:none;
101
+ transition:border-color .12s,color .12s}
102
+ .dshtb-when{display:flex;align-items:center;gap:7px;font:600 11px/1 ${MONO};color:var(--tb-dim)}
103
+ .dshtb-when .lbl{letter-spacing:.08em}
104
+ .dshtb-when input{flex:1;min-width:0;padding:5px 8px;border-radius:8px;border:1px dashed var(--tb-line);
105
+ background:transparent;color:var(--tb-dim);font:inherit;font-size:12px;outline:none;
106
+ transition:border-color .12s,color .12s;color-scheme:dark light}
107
+ .dshtb-when input:focus{border-style:solid;border-color:var(--tb-accent);color:var(--tb-ink)}
108
+ .dshtb-attach{display:flex;flex-direction:column;gap:6px}
109
+ .dshtb-attach label{cursor:pointer;display:inline-flex;align-items:center;gap:4px;align-self:flex-start}
110
+ .dshtb-attach label.off{opacity:.5;cursor:not-allowed}
111
+ .dshtb-thumbs{display:flex;flex-wrap:wrap;gap:6px}
112
+ .dshtb-thumb{position:relative;width:52px;height:52px;padding:0;border:1px solid var(--tb-line);
113
+ border-radius:8px;background:transparent;cursor:pointer;overflow:hidden}
114
+ .dshtb-thumb img{width:100%;height:100%;object-fit:cover;display:block}
115
+ .dshtb-thumb .x{position:absolute;top:0;right:0;padding:0 3px;background:rgba(0,0,0,.6);color:#fff;
116
+ font:700 10px/1.4 ${MONO};border-bottom-left-radius:6px}
117
+ .dshtb-imgs{display:flex;flex-wrap:wrap;gap:5px;margin-top:5px}
118
+ .dshtb-imgwrap{position:relative;display:inline-flex}
119
+ .dshtb-img{width:64px;height:64px;object-fit:cover;border-radius:7px;border:1px solid var(--tb-line);
120
+ cursor:zoom-in;display:block}
121
+ .dshtb-imgx{position:absolute;top:-5px;right:-5px;width:16px;height:16px;padding:0;border:0;border-radius:50%;
122
+ background:var(--dsw-alias-bg-overlay);color:var(--tb-dim);box-shadow:0 0 0 1px var(--tb-line);
123
+ font:700 9px/1 ${MONO};cursor:pointer;display:grid;place-items:center}
124
+ .dshtb-imgx:hover{color:var(--tb-ink)}
125
+ .dshtb-light{position:fixed;inset:0;z-index:2147483000;display:flex;flex-direction:column;
126
+ align-items:center;justify-content:center;gap:10px;background:rgba(0,0,0,.72);cursor:zoom-out;
127
+ animation:dshtb-in .14s ease-out}
128
+ .dshtb-light img{max-width:88vw;max-height:82vh;border-radius:10px;box-shadow:0 20px 60px -18px rgba(0,0,0,.8);cursor:default}
129
+ .dshtb-lightcap{font:600 11px/1.4 ${MONO};color:#fff;opacity:.85}
130
+ .dshtb-dir input::placeholder{color:var(--tb-dim);opacity:.85}
131
+ .dshtb-dir input:focus{border-style:solid;border-color:var(--tb-accent);color:var(--tb-ink)}
132
+ .dshtb-list{overflow:auto;padding:2px 0 6px;scrollbar-width:thin}
133
+ .dshtb-list::-webkit-scrollbar{width:9px}
134
+ .dshtb-list::-webkit-scrollbar-thumb{background:var(--tb-line2);border-radius:5px;
135
+ border:3px solid transparent;background-clip:content-box}
136
+ .dshtb-group{display:flex;align-items:center;gap:7px;padding:10px 12px 4px;
137
+ font:600 10.5px/1 ${MONO};letter-spacing:.09em;text-transform:uppercase;color:var(--tb-dim)}
138
+ .dshtb-group::after{content:'';flex:1;height:1px;background:var(--tb-line)}
139
+ .dshtb-item{display:flex;gap:7px;padding:7px 12px;align-items:flex-start;position:relative;
140
+ border-top:2px solid transparent;animation:dshtb-row .2s ease-out both;transition:background .12s}
141
+ @keyframes dshtb-row{from{opacity:0;transform:translateX(-5px)}to{opacity:1;transform:none}}
142
+ .dshtb-item::before{content:'';position:absolute;left:0;top:0;bottom:0;width:2px;background:transparent;
143
+ transition:background .12s}
144
+ .dshtb-item:hover{background:var(--dsw-alias-bg-layer-2)}
145
+ .dshtb-item:hover::before{background:var(--tb-line2)}
146
+ .dshtb-item.done{opacity:.55}
147
+ .dshtb-item.done .dshtb-t{text-decoration:line-through}
148
+ .dshtb-item.dragging{opacity:.3}
149
+ .dshtb-item.over{border-top-color:var(--tb-accent)}
150
+ .dshtb-grip{flex:0 0 auto;width:9px;padding-top:3px;cursor:grab;user-select:none;opacity:0;
151
+ color:var(--tb-dim);font:700 10px/1 ${MONO};letter-spacing:-1px;transition:opacity .12s}
152
+ .dshtb-item:hover .dshtb-grip,.dshtb-item.dragging .dshtb-grip{opacity:.8}
153
+ .dshtb-grip:active{cursor:grabbing}
154
+ .dshtb-checks{display:flex;flex-direction:column;gap:5px;padding-top:2px;flex:0 0 auto}
155
+ .dshtb-cb{width:18px;height:18px;padding:0;border:1.5px solid var(--tb-line2);background:transparent;
156
+ cursor:pointer;display:grid;place-items:center;font:700 11px/1 ${MONO};color:transparent;
157
+ transition:background .14s,border-color .14s,color .14s}
158
+ .dshtb-cb.ai{border-radius:4px}
159
+ .dshtb-cb.me{border-radius:50%}
160
+ .dshtb-cb:hover{border-color:var(--tb-accent)}
161
+ .dshtb-cb.ai.on{background:var(--tb-accent);border-color:var(--tb-accent);color:#fff}
162
+ .dshtb-cb.me.on{background:var(--tb-ok);border-color:var(--tb-ok);color:#fff}
163
+ .dshtb-cb.on{animation:dshtb-pop .18s ease-out}
164
+ @keyframes dshtb-pop{0%{transform:scale(.55)}60%{transform:scale(1.18)}100%{transform:scale(1)}}
165
+ .dshtb-body{flex:1;min-width:0}
166
+ .dshtb-t{font-size:13px;word-break:break-word;white-space:pre-wrap;line-height:1.45}
167
+ .dshtb-facts{margin-top:3px;font:400 11px/1.4 ${MONO};font-variant-numeric:tabular-nums;
168
+ color:var(--tb-dim);word-break:break-all}
169
+ .dshtb-t input{width:100%;padding:2px 5px;border-radius:5px;border:1px solid var(--tb-accent);
170
+ background:var(--dsw-alias-bg-layer-1);color:var(--tb-ink);font:inherit;outline:none}
171
+ .dshtb-edit{display:block;width:100%;min-height:76px;max-height:220px;resize:vertical;
172
+ padding:6px 8px;border-radius:7px;border:1px solid var(--tb-accent);
173
+ background:var(--dsw-alias-bg-layer-1);color:var(--tb-ink);font:inherit;font-size:13px;
174
+ line-height:1.45;outline:none;box-shadow:0 0 0 3px rgba(128,128,128,.16)}
175
+ .dshtb-edit::placeholder{color:var(--tb-dim)}
176
+ .dshtb-meta{display:flex;flex-wrap:wrap;gap:5px;margin-top:5px;
177
+ font:400 12px/1.5 ${MONO};color:var(--tb-dim)}
178
+ .dshtb-chip{display:inline-flex;align-items:center;gap:4px;padding:2px 7px;border-radius:6px;
179
+ background:var(--dsw-alias-bg-layer-1);border:1px solid var(--tb-line);white-space:nowrap;
180
+ font:inherit;font-size:12px;color:var(--tb-dim)}
181
+ button.dshtb-chip{cursor:pointer;font:inherit;color:inherit;transition:border-color .12s,color .12s}
182
+ button.dshtb-chip:hover{border-color:var(--tb-line2);color:var(--tb-ink)}
183
+ .dshtb-chip.sent{color:var(--tb-ok);border-color:var(--tb-ok)}
184
+ .dshtb-chip.due{color:var(--tb-warn);border-color:var(--tb-warn);font-weight:600}
185
+ .dshtb-acts{display:flex;gap:1px;flex:0 0 auto;opacity:0;transition:opacity .12s}
186
+ .dshtb-item:hover .dshtb-acts{opacity:1}
187
+ .dshtb-ic{width:22px;height:22px;padding:0;border:0;border-radius:6px;background:transparent;
188
+ color:var(--tb-dim);cursor:pointer;display:grid;place-items:center;font-size:11px;
189
+ transition:background .12s,color .12s}
190
+ .dshtb-ic:hover{background:var(--dsw-alias-bg-layer-1);color:var(--tb-ink)}
191
+ .dshtb-ic:disabled{opacity:.4;cursor:default}
192
+ .dshtb-empty{padding:24px 16px;text-align:center;color:var(--tb-dim)}
193
+ .dshtb-empty b{display:block;font:700 24px/1 ${MONO};opacity:.3;margin-bottom:9px}
194
+ .dshtb-empty span{font-size:11px;opacity:.9}
195
+ .dshtb-foot{display:flex;align-items:center;flex-wrap:wrap;gap:6px 8px;padding:8px 12px;
196
+ border-top:1px solid var(--tb-line);
197
+ font:600 11px/1 ${MONO};font-variant-numeric:tabular-nums;color:var(--tb-dim)}
198
+ .dshtb-link{padding:2px 6px;border:1px solid var(--tb-line);border-radius:6px;background:transparent;
199
+ color:var(--tb-dim);font:inherit;cursor:pointer;transition:background .12s,color .12s,border-color .12s}
200
+ .dshtb-link:hover{background:var(--dsw-alias-bg-layer-1);color:var(--tb-ink);border-color:var(--tb-line2)}
201
+ .dshtb-link.off{opacity:.5;cursor:not-allowed}
202
+ /* Shipped Cordis popup: parked under this panel, right-aligned to it.
203
+ !important beats the inline left/bottom the panel computes from its anchor. */
204
+ [data-dsh-todo-cordis]>div:first-child{left:auto !important;bottom:auto !important;
205
+ right:var(--dsh-todo-cordis-right,16px) !important;
206
+ top:var(--dsh-todo-cordis-top,120px) !important;
207
+ max-height:var(--dsh-todo-cordis-maxh,60vh) !important}
208
+ .dshtb-err{padding:6px 12px;color:var(--dsw-alias-state-error-primary);font:400 10.5px/1.4 ${MONO};
209
+ word-break:break-all;border-top:1px solid var(--tb-line)}
210
+ .dshtb-pill{display:inline-flex;align-items:center;gap:7px;padding:7px 12px 7px 10px;border-radius:999px;
211
+ background:var(--tb-bg);border:1px solid var(--tb-line);cursor:pointer;user-select:none;
212
+ box-shadow:0 8px 26px -10px rgba(0,0,0,.5);transition:transform .14s,border-color .14s}
213
+ .dshtb-pill:hover{transform:translateY(-1px);border-color:var(--tb-line2)}
214
+ .dshtb-pill .lbl{font:600 10px/1 ${MONO};letter-spacing:.12em;text-transform:uppercase}
215
+ .dshtb-badge{min-width:18px;height:18px;padding:0 5px;border-radius:9px;background:var(--tb-accent);
216
+ color:#fff;font:700 10px/1 ${MONO};font-variant-numeric:tabular-nums;display:inline-grid;place-items:center}
217
+ .dshtb-badge.warn{background:var(--tb-warn)}
218
+ `
219
+
220
+ // ---------------------------------------------------------------------------
221
+ // Bridge to the shipped Cordis dynamic-plugin panel.
222
+ //
223
+ // That panel belongs to @deepseek-ai/dsh-client-ui-cordis and lives in the
224
+ // sidebar footer. No slot API can move another plugin's entry, so this is a
225
+ // DOM bridge with three parts:
226
+ //
227
+ // 1. locate the trigger by the `data-cordis-badge` attribute it renders
228
+ // itself — stable across versions and locales, and still present when the
229
+ // sidebar collapses to the 56px rail, where the text label is not
230
+ // rendered at all (text matching is only a fallback);
231
+ // 2. hide its sidebar row, so the entry exists only inside this panel;
232
+ // 3. park the shipped popup UNDER this panel: the popup is a child of that
233
+ // same layer, and a tagged, !important CSS rule overrides the inline
234
+ // `left`/`bottom` the panel computes from the layer's rect. That makes the
235
+ // placement independent of the collapsed anchor and guarantees the two
236
+ // panels never overlap.
237
+ //
238
+ // The layer's inline styles and attribute are restored when this plugin
239
+ // unloads.
240
+ // ---------------------------------------------------------------------------
241
+ const CORDIS_TRIGGER = 'Cordis Plugin'
242
+ const CORDIS_BADGE_SELECTOR = 'button[data-cordis-badge]'
243
+ const CORDIS_LAYER_ATTR = 'data-dsh-todo-cordis'
244
+ let cordisSaved = null
245
+
246
+ function cordisBadge() {
247
+ const direct = document.querySelector(CORDIS_BADGE_SELECTOR)
248
+ if (direct !== null) return direct
249
+ const buttons = document.querySelectorAll('button')
250
+ for (const button of buttons) {
251
+ // Never match this panel's own footer entry: it carries the same label.
252
+ if (button.closest('.dshtb-root') !== null) continue
253
+ const text = button.textContent === null ? '' : button.textContent.trim()
254
+ // Prefix match: the shipped badge appends a running count.
255
+ if (text.indexOf(CORDIS_TRIGGER) === 0) return button
256
+ }
257
+ return null
258
+ }
259
+
260
+ function collapseCordisFooter() {
261
+ if (cordisSaved !== null && cordisSaved.button.isConnected) return
262
+ const badge = cordisBadge()
263
+ if (badge === null) return
264
+ const row = badge.parentElement
265
+ const layer = row === null ? null : row.parentElement
266
+ // Refuse to touch any ancestor of this panel: collapsing our own card would
267
+ // hide the entire board behind its own overflow:hidden.
268
+ const owner = layer === null ? row : layer
269
+ if (owner === null || owner.querySelector('.dshtb-root') !== null) return
270
+ cordisSaved = {
271
+ button: badge,
272
+ row,
273
+ layer,
274
+ rowDisplay: row === null ? '' : row.style.display,
275
+ layerHeight: layer === null ? '' : layer.style.height,
276
+ layerMargin: layer === null ? '' : layer.style.margin,
277
+ layerPadding: layer === null ? '' : layer.style.padding,
278
+ }
279
+ if (row !== null) row.style.display = 'none'
280
+ if (layer !== null) {
281
+ layer.style.height = '0px'
282
+ layer.style.margin = '0px'
283
+ layer.style.padding = '0px'
284
+ layer.setAttribute(CORDIS_LAYER_ATTR, '')
285
+ }
286
+ }
287
+
288
+ /**
289
+ * Keep the shipped popup parked directly under this panel, right-aligned to
290
+ * it, with a max-height that stops it running off the bottom of the viewport.
291
+ * Recomputed on every poll so dragging or resizing this panel moves it too.
292
+ */
293
+ function anchorCordisPanel() {
294
+ const layer = cordisSaved === null ? null : cordisSaved.layer
295
+ if (layer === null || !layer.isConnected) return
296
+ const root = document.querySelector('.dshtb-root')
297
+ if (root === null) return
298
+ const rect = root.getBoundingClientRect()
299
+ const gap = 8
300
+ layer.style.setProperty('--dsh-todo-cordis-right', Math.max(8, Math.round(window.innerWidth - rect.right)) + 'px')
301
+ layer.style.setProperty('--dsh-todo-cordis-top', Math.round(rect.bottom + gap) + 'px')
302
+ layer.style.setProperty(
303
+ '--dsh-todo-cordis-maxh',
304
+ Math.max(160, Math.round(window.innerHeight - rect.bottom - gap * 3)) + 'px',
305
+ )
306
+ }
307
+
308
+ function restoreCordisFooter() {
309
+ if (cordisSaved === null) return
310
+ const saved = cordisSaved
311
+ cordisSaved = null
312
+ if (saved.row !== null && saved.row.isConnected) saved.row.style.display = saved.rowDisplay
313
+ if (saved.layer !== null && saved.layer.isConnected) {
314
+ saved.layer.style.height = saved.layerHeight
315
+ saved.layer.style.margin = saved.layerMargin
316
+ saved.layer.style.padding = saved.layerPadding
317
+ saved.layer.removeAttribute(CORDIS_LAYER_ATTR)
318
+ }
319
+ }
320
+
321
+ /**
322
+ * Open — never toggle — the shipped panel from this one.
323
+ *
324
+ * The badge sits inside a collapsed row, so a bare `.click()` races the
325
+ * panel's own dismiss-on-outside-pointer hook: that hook sees a pointer
326
+ * outside its root and closes whatever we just opened. Priming the interaction
327
+ * with a pointerdown/mousedown dispatched ON the badge makes the target
328
+ * "inside", so the click survives.
329
+ *
330
+ * @returns whether the shipped trigger was found at all.
331
+ */
332
+ function openCordisPanel() {
333
+ const badge = cordisBadge()
334
+ if (badge === null) return false
335
+ if (badge.getAttribute('aria-expanded') === 'true') return true
336
+ try {
337
+ const options = { bubbles: true, cancelable: true, view: window }
338
+ badge.dispatchEvent(new PointerEvent('pointerdown', options))
339
+ badge.dispatchEvent(new MouseEvent('mousedown', options))
340
+ } catch (err) {
341
+ /* no PointerEvent in this engine: the plain click below still tries */
342
+ }
343
+ badge.click()
344
+ return true
345
+ }
346
+
347
+ // --------------------------------------------------------------- transport
348
+
349
+ async function request(method, body) {
350
+ const response =
351
+ body === undefined
352
+ ? await fetch(ROUTE, { headers: { accept: 'application/json' } })
353
+ : await fetch(ROUTE, {
354
+ method: 'POST',
355
+ headers: { 'content-type': 'application/json' },
356
+ body: JSON.stringify(body),
357
+ })
358
+ if (!response.ok) throw new Error('HTTP ' + response.status)
359
+ return response.json()
360
+ }
361
+
362
+ const transport = {
363
+ snapshot: () => request('GET'),
364
+ call: (method, args) => request('POST', Object.assign({ action: method }, args)),
365
+ }
366
+
367
+ function describe(failure) {
368
+ if (failure === null || failure === undefined) return 'unknown error'
369
+ if (typeof failure === 'string') return failure
370
+ if (typeof failure.message === 'string') return failure.message
371
+ return String(failure)
372
+ }
373
+
374
+ /** Durable attachment bytes, served by this plugin's own board-scoped route. */
375
+ function imageUrl(attachmentId) {
376
+ return ROUTE.replace(/\/api$/, '/image') + '?id=' + encodeURIComponent(String(attachmentId))
377
+ }
378
+
379
+ // ------------------------------------------------------------- panel layout
380
+
381
+ const LAYOUT_KEY = 'dsh.todoBoard.layout.v1'
382
+ const MIN_W = 300
383
+ const MIN_H = 260
384
+
385
+ function loadLayout() {
386
+ try {
387
+ const raw = window.localStorage.getItem(LAYOUT_KEY)
388
+ if (raw === null) return null
389
+ const parsed = JSON.parse(raw)
390
+ if (parsed === null || typeof parsed !== 'object') return null
391
+ const x = Number(parsed.x)
392
+ const y = Number(parsed.y)
393
+ const w = Number(parsed.w)
394
+ const h = Number(parsed.h)
395
+ if (!isFinite(x) || !isFinite(y) || !isFinite(w) || !isFinite(h)) return null
396
+ return { x, y, w, h }
397
+ } catch (err) {
398
+ return null
399
+ }
400
+ }
401
+
402
+ function saveLayout(layout) {
403
+ try {
404
+ if (layout === null) window.localStorage.removeItem(LAYOUT_KEY)
405
+ else window.localStorage.setItem(LAYOUT_KEY, JSON.stringify(layout))
406
+ } catch (err) {
407
+ /* storage unavailable */
408
+ }
409
+ }
410
+
411
+ function clampLayout(layout) {
412
+ const maxW = Math.max(MIN_W, window.innerWidth - 16)
413
+ const maxH = Math.max(MIN_H, window.innerHeight - 16)
414
+ const w = Math.min(Math.max(layout.w, MIN_W), maxW)
415
+ const h = Math.min(Math.max(layout.h, MIN_H), maxH)
416
+ const x = Math.min(Math.max(layout.x, 8), Math.max(8, window.innerWidth - w - 8))
417
+ const y = Math.min(Math.max(layout.y, 8), Math.max(8, window.innerHeight - h - 8))
418
+ return { x, y, w, h }
419
+ }
420
+
421
+ // --------------------------------------------------------------- component
422
+
423
+ function TodoBoard(props) {
424
+ const currentId = props.useSessions((s) => s.current)
425
+ const currentSummary = props.useSessions((s) => (s.current === undefined ? undefined : s.byId[s.current]))
426
+ const cwd =
427
+ currentSummary !== undefined && currentSummary !== null && typeof currentSummary.cwd === 'string'
428
+ ? currentSummary.cwd
429
+ : ''
430
+ const currentTitle =
431
+ currentSummary !== undefined && currentSummary !== null && typeof currentSummary.title === 'string'
432
+ ? currentSummary.title
433
+ : ''
434
+
435
+ const [open, setOpen] = React.useState(true)
436
+ const [data, setData] = React.useState(null)
437
+ const [err, setErr] = React.useState('')
438
+ const [draft, setDraft] = React.useState('')
439
+ const [mode, setMode] = React.useState('remind')
440
+ const [dirInput, setDirInput] = React.useState('')
441
+ const [when, setWhen] = React.useState('')
442
+ const [pending, setPending] = React.useState([])
443
+ const [viewing, setViewing] = React.useState(null)
444
+ const [filter, setFilter] = React.useState('dir')
445
+ const [busy, setBusy] = React.useState(false)
446
+ const [dragId, setDragId] = React.useState('')
447
+ const [overId, setOverId] = React.useState('')
448
+ const [editId, setEditId] = React.useState('')
449
+ const [editText, setEditText] = React.useState('')
450
+ const [layout, setLayout] = React.useState(loadLayout)
451
+ const [cordisFound, setCordisFound] = React.useState(true)
452
+ const layoutRef = React.useRef(null)
453
+ const dragRef = React.useRef(null)
454
+ const inputRef = React.useRef(null)
455
+ const editRef = React.useRef(null)
456
+ /** id -> remindedAt already surfaced, so a reminder notifies exactly once. */
457
+ const seenReminders = React.useRef({})
458
+
459
+ function applyLayout(next) {
460
+ const clamped = clampLayout(next)
461
+ layoutRef.current = clamped
462
+ setLayout(clamped)
463
+ }
464
+
465
+ /** Seed a concrete geometry from the live rect, so CSS defaults stop applying. */
466
+ function seedFrom(event, mode) {
467
+ if (event.button !== 0) return null
468
+ const root = event.currentTarget.closest('.dshtb-root')
469
+ if (root === null) return null
470
+ const rect = root.getBoundingClientRect()
471
+ const origin = { x: rect.left, y: rect.top, w: rect.width, h: rect.height }
472
+ layoutRef.current = clampLayout(origin)
473
+ setLayout(layoutRef.current)
474
+ dragRef.current = { mode, pointerId: event.pointerId, startX: event.clientX, startY: event.clientY, origin }
475
+ event.currentTarget.setPointerCapture(event.pointerId)
476
+ event.preventDefault()
477
+ return origin
478
+ }
479
+
480
+ function beginDrag(event) {
481
+ seedFrom(event, 'move')
482
+ }
483
+
484
+ function beginResize(event) {
485
+ if (seedFrom(event, 'size') === null) return
486
+ event.stopPropagation()
487
+ }
488
+
489
+ function movePointer(event) {
490
+ const drag = dragRef.current
491
+ if (drag === null || drag.pointerId !== event.pointerId) return
492
+ const dx = event.clientX - drag.startX
493
+ const dy = event.clientY - drag.startY
494
+ if (drag.mode === 'move') {
495
+ applyLayout({ x: drag.origin.x + dx, y: drag.origin.y + dy, w: drag.origin.w, h: drag.origin.h })
496
+ } else {
497
+ applyLayout({ x: drag.origin.x, y: drag.origin.y, w: drag.origin.w + dx, h: drag.origin.h + dy })
498
+ }
499
+ }
500
+
501
+ function endPointer() {
502
+ if (dragRef.current === null) return
503
+ dragRef.current = null
504
+ saveLayout(layoutRef.current)
505
+ }
506
+
507
+ function resetLayout() {
508
+ layoutRef.current = null
509
+ setLayout(null)
510
+ saveLayout(null)
511
+ }
512
+
513
+ // Grow the composer with its content, up to the CSS max-height.
514
+ React.useEffect(() => {
515
+ const el = inputRef.current
516
+ if (el === null) return
517
+ el.style.height = 'auto'
518
+ el.style.height = Math.min(el.scrollHeight, 180) + 'px'
519
+ }, [draft])
520
+
521
+ // The rename field grows with the text the same way, so a long todo stays
522
+ // readable while it is being edited.
523
+ React.useEffect(() => {
524
+ const el = editRef.current
525
+ if (el === null) return
526
+ el.style.height = 'auto'
527
+ el.style.height = Math.min(el.scrollHeight, 220) + 'px'
528
+ }, [editText, editId])
529
+
530
+ function refresh() {
531
+ transport.snapshot().then(
532
+ (result) => {
533
+ setData(result)
534
+ setErr('')
535
+ if (result !== null && result !== undefined && Array.isArray(result.todos)) {
536
+ notifyDue(result.todos)
537
+ }
538
+ },
539
+ (failure) => setErr(describe(failure)),
540
+ )
541
+ collapseCordisFooter()
542
+ anchorCordisPanel()
543
+ setCordisFound(cordisBadge() !== null)
544
+ }
545
+
546
+ React.useEffect(() => {
547
+ refresh()
548
+ const id = window.setInterval(refresh, 2500)
549
+ return () => window.clearInterval(id)
550
+ }, [])
551
+
552
+ // Ask once for desktop-notification permission, so a due 「提醒」待办 can
553
+ // surface even while the panel is collapsed.
554
+ React.useEffect(() => {
555
+ try {
556
+ if (typeof Notification !== 'undefined' && Notification.permission === 'default') {
557
+ Notification.requestPermission().catch(() => {})
558
+ }
559
+ } catch (err) {
560
+ /* no Notification API in this engine */
561
+ }
562
+ }, [])
563
+
564
+ const todos = data !== null && data !== undefined && Array.isArray(data.todos) ? data.todos : []
565
+ const cwdKey = cwd === '' ? '' : cwd.replace(/\//g, '\\').replace(/\\+$/, '').toLowerCase()
566
+
567
+ const byDir = todos.filter((t) => t.dir === cwdKey)
568
+ const bySession = todos.filter((t) => t.sourceSessionId === currentId)
569
+ const scope = filter === 'dir' ? byDir : filter === 'session' ? bySession : todos
570
+ const visible = scope.slice().sort((a, b) => a.order - b.order || a.createdAt - b.createdAt)
571
+
572
+ const awaitingVerify = todos.filter((t) => t.aiDone && !t.verified).length
573
+ const verifiedCount = todos.filter((t) => t.verified).length
574
+ const openCount = todos.filter((t) => !t.verified).length
575
+
576
+ const groups = []
577
+ const index = {}
578
+ for (const todo of visible) {
579
+ const key = todo.dirLabel || '(未指定目录)'
580
+ if (index[key] === undefined) {
581
+ index[key] = groups.length
582
+ groups.push({ key, items: [] })
583
+ }
584
+ groups[index[key]].items.push(todo)
585
+ }
586
+
587
+ async function call(method, args) {
588
+ setBusy(true)
589
+ try {
590
+ const result = await transport.call(method, args)
591
+ if (result !== null && result !== undefined && result.ok === false && typeof result.error === 'string') {
592
+ setErr(result.error)
593
+ } else {
594
+ setErr('')
595
+ }
596
+ } catch (failure) {
597
+ setErr(describe(failure))
598
+ }
599
+ setBusy(false)
600
+ refresh()
601
+ }
602
+
603
+ function add() {
604
+ const title = draft.trim()
605
+ if (title === '') return
606
+ const targetDir = dirInput.trim() !== '' ? dirInput.trim() : cwd
607
+ const images = pending
608
+ setDraft('')
609
+ setWhen('')
610
+ setPending([])
611
+ call('create', {
612
+ title,
613
+ mode,
614
+ dir: targetDir,
615
+ schedule: when,
616
+ images,
617
+ sessionId: currentId === undefined ? '' : currentId,
618
+ sessionTitle: currentTitle,
619
+ })
620
+ }
621
+
622
+ /** Read one picked file into the wire shape the host admits. */
623
+ function readImageFile(file) {
624
+ return new Promise((resolve, reject) => {
625
+ const reader = new FileReader()
626
+ reader.onerror = () => reject(new Error('读取失败:' + file.name))
627
+ reader.onload = () => {
628
+ const result = typeof reader.result === 'string' ? reader.result : ''
629
+ const comma = result.indexOf(',')
630
+ if (comma < 0) {
631
+ reject(new Error('无法编码:' + file.name))
632
+ return
633
+ }
634
+ resolve({
635
+ data: result.slice(comma + 1),
636
+ mediaType: file.type,
637
+ name: file.name,
638
+ })
639
+ }
640
+ reader.readAsDataURL(file)
641
+ })
642
+ }
643
+
644
+ function pickImages(event) {
645
+ const files = Array.from((event.target.files || []))
646
+ event.target.value = ''
647
+ if (files.length === 0) return
648
+ setBusy(true)
649
+ Promise.all(files.map(readImageFile)).then(
650
+ (encoded) => {
651
+ setPending((current) => current.concat(encoded).slice(0, MAX_IMAGES))
652
+ setErr('')
653
+ setBusy(false)
654
+ },
655
+ (failure) => {
656
+ setErr(describe(failure))
657
+ setBusy(false)
658
+ },
659
+ )
660
+ }
661
+
662
+ function setSchedule(todo, value) {
663
+ patch(todo.id, { schedule: value })
664
+ }
665
+
666
+ /** One desktop notification per reminder the host has stamped as due. */
667
+ function notifyDue(list) {
668
+ for (const todo of list) {
669
+ const stamp = typeof todo.remindedAt === 'number' ? todo.remindedAt : 0
670
+ if (stamp === 0) {
671
+ delete seenReminders.current[todo.id]
672
+ continue
673
+ }
674
+ if (seenReminders.current[todo.id] === stamp) continue
675
+ seenReminders.current[todo.id] = stamp
676
+ if (todo.verified) continue
677
+ try {
678
+ if (typeof Notification !== 'undefined' && Notification.permission === 'granted') {
679
+ new Notification('TODO 到时间了', { body: todo.title, tag: 'dshtb-' + todo.id })
680
+ }
681
+ } catch (err) {
682
+ /* notification blocked: the row chip still shows 已到时间 */
683
+ }
684
+ }
685
+ }
686
+
687
+ function patch(id, p) {
688
+ call('patch', { id, patch: p })
689
+ }
690
+
691
+ function cycleMode(todo) {
692
+ const next = MODES[(MODES.indexOf(todo.mode) + 1) % MODES.length]
693
+ patch(todo.id, { mode: next })
694
+ }
695
+
696
+ function beginEdit(todo) {
697
+ setEditId(todo.id)
698
+ setEditText(todo.title)
699
+ }
700
+
701
+ function commitEdit() {
702
+ const id = editId
703
+ const text = editText.trim()
704
+ setEditId('')
705
+ if (id === '' || text === '') return
706
+ patch(id, { title: text })
707
+ }
708
+
709
+ function dropOn(targetId) {
710
+ const from = dragId
711
+ setDragId('')
712
+ setOverId('')
713
+ if (from === '' || from === targetId) return
714
+ const ids = []
715
+ for (const t of visible) ids.push(t.id)
716
+ const fromIndex = ids.indexOf(from)
717
+ const toIndex = ids.indexOf(targetId)
718
+ if (fromIndex < 0 || toIndex < 0) return
719
+ ids.splice(fromIndex, 1)
720
+ ids.splice(toIndex, 0, from)
721
+ call('reorder', { ids })
722
+ }
723
+
724
+ function item(todo, rowIndex) {
725
+ let cls = 'dshtb-item'
726
+ if (todo.verified) cls += ' done'
727
+ if (dragId === todo.id) cls += ' dragging'
728
+ if (overId === todo.id && dragId !== '' && dragId !== todo.id) cls += ' over'
729
+
730
+ const meta = [
731
+ h(
732
+ 'span',
733
+ {
734
+ className: 'dshtb-chip',
735
+ key: 'd',
736
+ title: todo.dirPath
737
+ ? '工作目录:' + todo.dirPath
738
+ : '这条待办没有绑定目录(新增时目录留空且当前会话没有工作区)',
739
+ },
740
+ todo.dirLabel,
741
+ ),
742
+ ]
743
+ meta.push(
744
+ h(
745
+ 'button',
746
+ {
747
+ className: 'dshtb-chip',
748
+ key: 'm',
749
+ title: '点击切换执行模式(当前:' + MODE_LABEL[todo.mode] + ')',
750
+ onClick: () => cycleMode(todo),
751
+ },
752
+ MODE_SHORT[todo.mode],
753
+ ),
754
+ )
755
+ if (todo.dispatchedAt > 0 && !todo.aiDone) {
756
+ meta.push(h('span', { className: 'dshtb-chip sent', key: 's', title: '已经派发过一次' }, '已派发'))
757
+ }
758
+ if (todo.schedule) {
759
+ const due = typeof todo.dueAt === 'number' && todo.dueAt > 0 && todo.dueAt <= Date.now()
760
+ meta.push(
761
+ h(
762
+ 'button',
763
+ {
764
+ className: 'dshtb-chip' + (due ? ' due' : ''),
765
+ key: 'w',
766
+ title: due
767
+ ? '已到时间:' + todo.schedule + '(点 ✕ 取消定时)'
768
+ : '定时执行:' + todo.schedule + '(点 ✕ 取消定时)',
769
+ onClick: () => setSchedule(todo, ''),
770
+ },
771
+ (due ? '\u23F0 ' : '\u25F4 ') + todo.schedule.slice(5).replace('T', ' ') + ' ✕',
772
+ ),
773
+ )
774
+ }
775
+ if (todo.sourceSessionTitle) {
776
+ meta.push(h('span', { className: 'dshtb-chip', key: 't' }, todo.sourceSessionTitle))
777
+ }
778
+ // The bound run session is deliberately NOT shown on the row: it is an
779
+ // internal detail, and the panel stays readable without it. The binding is
780
+ // still what ▶ reuses; `todo_board list` and the host API expose it when
781
+ // it actually matters.
782
+
783
+ // Renaming happens inline and to the full width of the row: a long todo
784
+ // needs to be readable while you edit it, not squeezed into one line.
785
+ const editNode =
786
+ editId === todo.id
787
+ ? h('textarea', {
788
+ className: 'dshtb-edit',
789
+ ref: editRef,
790
+ autoFocus: true,
791
+ rows: 2,
792
+ value: editText,
793
+ onChange: (e) => setEditText(e.target.value),
794
+ onBlur: commitEdit,
795
+ onKeyDown: (e) => {
796
+ if (e.key === 'Enter' && !e.shiftKey) {
797
+ e.preventDefault()
798
+ commitEdit()
799
+ }
800
+ if (e.key === 'Escape') setEditId('')
801
+ },
802
+ })
803
+ : null
804
+
805
+ const titleNode = editNode === null
806
+ ? h('div', { className: 'dshtb-t', title: '双击编辑', onDoubleClick: () => beginEdit(todo) }, todo.title)
807
+ : editNode
808
+
809
+ // A plain monospace readout under the title: the two facts the chips can
810
+ // bury in a narrow panel are always visible here — the working directory
811
+ // this task runs in, and the time it is scheduled for.
812
+ const facts = []
813
+ facts.push('目录 ' + (todo.dirPath || todo.dir || '(未指定)'))
814
+ facts.push(todo.schedule ? '定时 ' + todo.schedule : '不定时')
815
+ if (todo.runSessionId && todo.mode !== 'newSession') {
816
+ facts.push('会话 ' + todo.runSessionId.slice(-6))
817
+ }
818
+ const detailNode = h('div', { className: 'dshtb-facts' }, facts.join(' · '))
819
+
820
+ // Attached images: thumbnails on the row, click to enlarge, ✕ to drop.
821
+ const images = Array.isArray(todo.images) ? todo.images : []
822
+ const imagesNode =
823
+ images.length === 0
824
+ ? null
825
+ : h(
826
+ 'div',
827
+ { className: 'dshtb-imgs' },
828
+ images.map((image, at) =>
829
+ h(
830
+ 'span',
831
+ { className: 'dshtb-imgwrap', key: 'i' + at },
832
+ h('img', {
833
+ className: 'dshtb-img',
834
+ src: imageUrl(image.attachmentId),
835
+ alt: image.name || '附图',
836
+ title: (image.name || '附图') + ' · ' + image.width + '×' + image.height + '(点击放大)',
837
+ onClick: () => setViewing(image),
838
+ onError: (e) => {
839
+ e.currentTarget.style.opacity = '0.25'
840
+ },
841
+ }),
842
+ h(
843
+ 'button',
844
+ {
845
+ className: 'dshtb-imgx',
846
+ title: '移除这张图片',
847
+ onClick: () => patch(todo.id, {
848
+ images: images.filter((_, i) => i !== at),
849
+ clearImages: images.length === 1,
850
+ }),
851
+ },
852
+ '\u2715',
853
+ ),
854
+ ),
855
+ ),
856
+ )
857
+
858
+ return h(
859
+ 'div',
860
+ {
861
+ className: cls,
862
+ key: todo.id,
863
+ style: { animationDelay: Math.min(rowIndex, 12) * 18 + 'ms' },
864
+ draggable: editId !== todo.id,
865
+ onDragStart: (e) => {
866
+ setDragId(todo.id)
867
+ if (e.dataTransfer) {
868
+ e.dataTransfer.effectAllowed = 'move'
869
+ e.dataTransfer.setData('text/plain', todo.id)
870
+ }
871
+ },
872
+ onDragOver: (e) => {
873
+ e.preventDefault()
874
+ if (e.dataTransfer) e.dataTransfer.dropEffect = 'move'
875
+ if (overId !== todo.id) setOverId(todo.id)
876
+ },
877
+ onDragLeave: () => {
878
+ if (overId === todo.id) setOverId('')
879
+ },
880
+ onDrop: (e) => {
881
+ e.preventDefault()
882
+ dropOn(todo.id)
883
+ },
884
+ onDragEnd: () => {
885
+ setDragId('')
886
+ setOverId('')
887
+ },
888
+ },
889
+ h('span', { className: 'dshtb-grip', title: '拖动调整执行顺序' }, '\u283F'),
890
+ h(
891
+ 'div',
892
+ { className: 'dshtb-checks' },
893
+ h(
894
+ 'button',
895
+ {
896
+ className: 'dshtb-cb ai' + (todo.aiDone ? ' on' : ''),
897
+ 'aria-label': 'AI 已完成',
898
+ title: todo.aiDone ? 'AI 已完成 — 点击撤销' : 'AI 已完成(由 AI 自动勾选,也可手点)',
899
+ onClick: () => patch(todo.id, { aiDone: !todo.aiDone }),
900
+ },
901
+ todo.aiDone ? '\u2713' : '',
902
+ ),
903
+ h(
904
+ 'button',
905
+ {
906
+ className: 'dshtb-cb me' + (todo.verified ? ' on' : ''),
907
+ 'aria-label': '用户已验收',
908
+ title: todo.verified ? '已验收 — 点击撤销' : '用户已验收(只有你能勾)',
909
+ onClick: () => patch(todo.id, { verified: !todo.verified }),
910
+ },
911
+ todo.verified ? '\u2713' : '',
912
+ ),
913
+ ),
914
+ h('div', { className: 'dshtb-body' }, titleNode, detailNode, imagesNode, h('div', { className: 'dshtb-meta' }, meta)),
915
+ h(
916
+ 'div',
917
+ { className: 'dshtb-acts' },
918
+ h(
919
+ 'button',
920
+ {
921
+ className: 'dshtb-ic',
922
+ title: todo.dispatchedAt > 0 ? '重新接续到当前会话' : '立即接续到当前会话',
923
+ disabled: busy,
924
+ onClick: () =>
925
+ call('run', { id: todo.id, sessionId: currentId === undefined ? '' : currentId }),
926
+ },
927
+ '\u25B6',
928
+ ),
929
+ h(
930
+ 'button',
931
+ {
932
+ className: 'dshtb-ic',
933
+ title: '删除',
934
+ disabled: busy,
935
+ onClick: () => call('remove', { id: todo.id }),
936
+ },
937
+ '\u2715',
938
+ ),
939
+ ),
940
+ )
941
+ }
942
+
943
+ if (!open) {
944
+ return h(
945
+ 'div',
946
+ {
947
+ className: 'dshtb-root',
948
+ style:
949
+ layout === null
950
+ ? {}
951
+ : {
952
+ left: layout.x + 'px',
953
+ top: layout.y + 'px',
954
+ right: 'auto',
955
+ width: 'auto',
956
+ height: 'auto',
957
+ maxWidth: 'none',
958
+ maxHeight: 'none',
959
+ },
960
+ },
961
+ h(
962
+ 'div',
963
+ {
964
+ className: 'dshtb-pill',
965
+ title:
966
+ 'TODO 板 · 点击展开' +
967
+ (data !== null && data !== undefined && data.storagePath ? '\n存储:' + data.storagePath : ''),
968
+ onClick: () => setOpen(true),
969
+ },
970
+ h('span', { className: 'lbl' }, 'TODO'),
971
+ h(
972
+ 'span',
973
+ { className: 'dshtb-badge' + (awaitingVerify > 0 ? ' warn' : '') },
974
+ String(openCount),
975
+ ),
976
+ ),
977
+ )
978
+ }
979
+
980
+ const segments = [
981
+ { id: 'dir', label: '当前目录', count: byDir.filter((t) => !t.verified).length },
982
+ { id: 'session', label: '当前会话', count: bySession.filter((t) => !t.verified).length },
983
+ { id: 'all', label: '全部', count: openCount },
984
+ ].map((seg) =>
985
+ h(
986
+ 'button',
987
+ {
988
+ key: seg.id,
989
+ className: filter === seg.id ? 'on' : '',
990
+ onClick: () => setFilter(seg.id),
991
+ },
992
+ seg.label,
993
+ h('em', null, String(seg.count)),
994
+ ),
995
+ )
996
+
997
+ let rowIndex = 0
998
+ const rows = groups.map((group) =>
999
+ h(
1000
+ 'div',
1001
+ { key: group.key },
1002
+ h('div', { className: 'dshtb-group' }, group.key),
1003
+ group.items.map((todo) => item(todo, rowIndex++)),
1004
+ ),
1005
+ )
1006
+
1007
+ const rootStyle =
1008
+ layout === null
1009
+ ? {}
1010
+ : {
1011
+ left: layout.x + 'px',
1012
+ top: layout.y + 'px',
1013
+ right: 'auto',
1014
+ width: layout.w + 'px',
1015
+ height: layout.h + 'px',
1016
+ maxWidth: 'none',
1017
+ maxHeight: 'none',
1018
+ }
1019
+
1020
+ return h(
1021
+ 'div',
1022
+ { className: 'dshtb-root', style: rootStyle },
1023
+ h(
1024
+ 'div',
1025
+ { className: 'dshtb-card' },
1026
+ h(
1027
+ 'div',
1028
+ {
1029
+ className: 'dshtb-head',
1030
+ title: '拖动移动 · 双击还原位置',
1031
+ onPointerDown: beginDrag,
1032
+ onPointerMove: movePointer,
1033
+ onPointerUp: endPointer,
1034
+ onPointerCancel: endPointer,
1035
+ onDoubleClick: resetLayout,
1036
+ },
1037
+ h(
1038
+ 'span',
1039
+ {
1040
+ className: 'dshtb-title',
1041
+ title:
1042
+ (data !== null && data !== undefined && data.storagePath
1043
+ ? '存储:' + data.storagePath + '\n'
1044
+ : '') +
1045
+ '拖动标题栏移动 · 右下角 \u25E2 缩放 · 双击还原 · 拖动 \u283F 调整执行顺序 · 双击标题改名',
1046
+ },
1047
+ h('b', null, '\u2611'),
1048
+ ' TODO',
1049
+ ),
1050
+ h('span', { className: 'dshtb-sp' }),
1051
+ h(
1052
+ 'span',
1053
+ { className: 'dshtb-stats' },
1054
+ h('i', { title: '未验收' }, String(openCount)),
1055
+ awaitingVerify > 0 ? h('i', { title: 'AI 已完成,等你验收' }, '待验 ' + awaitingVerify) : null,
1056
+ ),
1057
+ h('button', { className: 'dshtb-fold', title: '收起', onClick: () => setOpen(false) }, '\u2013'),
1058
+ ),
1059
+ h('div', { className: 'dshtb-seg' }, segments),
1060
+ h(
1061
+ 'div',
1062
+ { className: 'dshtb-compose' },
1063
+ h(
1064
+ 'div',
1065
+ { className: 'dshtb-add' },
1066
+ h('textarea', {
1067
+ ref: inputRef,
1068
+ rows: 3,
1069
+ placeholder: '新增待办…(Enter 添加,Shift+Enter 换行)',
1070
+ value: draft,
1071
+ onChange: (e) => setDraft(e.target.value),
1072
+ onKeyDown: (e) => {
1073
+ if (e.key === 'Enter' && !e.shiftKey) {
1074
+ e.preventDefault()
1075
+ add()
1076
+ }
1077
+ },
1078
+ }),
1079
+ h(
1080
+ 'button',
1081
+ { className: 'dshtb-ic', title: '添加', disabled: busy || draft.trim() === '', onClick: add },
1082
+ '\uFF0B',
1083
+ ),
1084
+ ),
1085
+ h(
1086
+ 'div',
1087
+ { className: 'dshtb-attach' },
1088
+ h('label', { className: 'dshtb-link' + (pending.length >= MAX_IMAGES ? ' off' : ''), title: '给这条待办附图(最多 ' + MAX_IMAGES + ' 张,PNG/JPG/WebP/GIF)' },
1089
+ '\uD83D\uDCCE 图片',
1090
+ h('input', {
1091
+ type: 'file',
1092
+ accept: 'image/png,image/jpeg,image/webp,image/gif',
1093
+ multiple: true,
1094
+ disabled: pending.length >= MAX_IMAGES,
1095
+ style: { display: 'none' },
1096
+ onChange: pickImages,
1097
+ }),
1098
+ ),
1099
+ pending.length === 0
1100
+ ? null
1101
+ : h(
1102
+ 'div',
1103
+ { className: 'dshtb-thumbs' },
1104
+ pending.map((image, at) =>
1105
+ h(
1106
+ 'button',
1107
+ {
1108
+ key: 'p' + at,
1109
+ className: 'dshtb-thumb',
1110
+ title: (image.name || '图片') + '(点击移除)',
1111
+ onClick: () => setPending((current) => current.filter((_, i) => i !== at)),
1112
+ },
1113
+ h('img', { src: 'data:' + image.mediaType + ';base64,' + image.data, alt: image.name || '' }),
1114
+ h('span', { className: 'x' }, '\u2715'),
1115
+ ),
1116
+ ),
1117
+ ),
1118
+ ),
1119
+ h(
1120
+ 'div',
1121
+ { className: 'dshtb-modes' },
1122
+ MODES.map((id) =>
1123
+ h(
1124
+ 'button',
1125
+ { key: id, className: mode === id ? 'on' : '', title: MODE_LABEL[id], onClick: () => setMode(id) },
1126
+ MODE_SHORT[id],
1127
+ ),
1128
+ ),
1129
+ ),
1130
+ h('div', { className: 'dshtb-hint' }, MODE_HINT[mode]),
1131
+ h(
1132
+ 'div',
1133
+ { className: 'dshtb-when' },
1134
+ h('span', { className: 'lbl' }, '定时'),
1135
+ h('input', {
1136
+ type: 'datetime-local',
1137
+ value: when,
1138
+ title: '到点后才执行(留空 = 立即可以执行)',
1139
+ onChange: (e) => setWhen(e.target.value),
1140
+ }),
1141
+ when !== ''
1142
+ ? h(
1143
+ 'button',
1144
+ {
1145
+ className: 'dshtb-ic',
1146
+ title: '取消定时',
1147
+ onClick: () => setWhen(''),
1148
+ },
1149
+ '\u2715',
1150
+ )
1151
+ : h('span', { className: 'dshtb-hint' }, '不填'),
1152
+ ),
1153
+ h(
1154
+ 'div',
1155
+ { className: 'dshtb-dir' },
1156
+ h('input', {
1157
+ placeholder: cwd === '' ? '目录(绝对路径)' : '目录:' + cwd,
1158
+ value: dirInput,
1159
+ onChange: (e) => setDirInput(e.target.value),
1160
+ }),
1161
+ ),
1162
+ ),
1163
+ rows.length === 0
1164
+ ? h(
1165
+ 'div',
1166
+ { className: 'dshtb-empty' },
1167
+ h('b', null, '\u2610'),
1168
+ h(
1169
+ 'span',
1170
+ null,
1171
+ filter === 'dir' ? '当前目录还没有待办' : '这里还没有待办',
1172
+ ),
1173
+ )
1174
+ : h('div', { className: 'dshtb-list' }, rows),
1175
+ err !== '' ? h('div', { className: 'dshtb-err' }, err) : null,
1176
+ data !== null && data !== undefined && data.storageError
1177
+ ? h('div', { className: 'dshtb-err' }, data.storageError)
1178
+ : null,
1179
+ h(
1180
+ 'div',
1181
+ { className: 'dshtb-foot' },
1182
+ h('span', { title: '客户端构建标记,用来确认浏览器加载的是哪一版' }, 'v' + BUILD),
1183
+ h('span', null, '未验收 ' + openCount),
1184
+ awaitingVerify > 0 ? h('span', null, '· 待验 ' + awaitingVerify) : null,
1185
+ h('span', { className: 'dshtb-sp' }),
1186
+ verifiedCount > 0
1187
+ ? h(
1188
+ 'button',
1189
+ {
1190
+ className: 'dshtb-link',
1191
+ title: '删除所有已验收的条目(共 ' + verifiedCount + ' 条)',
1192
+ onClick: () => call('clearVerified'),
1193
+ },
1194
+ '清理已验收 ' + verifiedCount,
1195
+ )
1196
+ : null,
1197
+ h(
1198
+ 'button',
1199
+ {
1200
+ className: 'dshtb-link' + (cordisFound ? '' : ' off'),
1201
+ title: cordisFound
1202
+ ? '打开 Cordis 动态插件面板(显示在本面板正下方)'
1203
+ : '找不到 Cordis 入口,暂时打不开',
1204
+ onClick: openCordisPanel,
1205
+ },
1206
+ 'Cordis Plugin',
1207
+ ),
1208
+ ),
1209
+ h('div', {
1210
+ className: 'dshtb-resize',
1211
+ title: '拖动缩放 · 双击还原',
1212
+ onPointerDown: beginResize,
1213
+ onPointerMove: movePointer,
1214
+ onPointerUp: endPointer,
1215
+ onPointerCancel: endPointer,
1216
+ onDoubleClick: resetLayout,
1217
+ }),
1218
+ viewing === null
1219
+ ? null
1220
+ : h(
1221
+ 'div',
1222
+ { className: 'dshtb-light', onClick: () => setViewing(null) },
1223
+ h('img', {
1224
+ src: imageUrl(viewing.attachmentId),
1225
+ alt: viewing.name || '附图',
1226
+ onClick: (e) => e.stopPropagation(),
1227
+ }),
1228
+ h('div', { className: 'dshtb-lightcap' }, viewing.name || '附图', ' · ', viewing.width + '×' + viewing.height, ' · 点空白处关闭'),
1229
+ ),
1230
+ ),
1231
+ )
1232
+ }
1233
+
1234
+ // ------------------------------------------------------------ plugin entry
1235
+
1236
+ exports.name = 'dsh-todo-board'
1237
+ exports.inject = ['slots']
1238
+ exports.apply = function apply(ctx) {
1239
+ ctx.effect(
1240
+ () => {
1241
+ const style = document.createElement('style')
1242
+ style.setAttribute('data-dsh-todo-board', '')
1243
+ style.textContent = CSS
1244
+ document.head.appendChild(style)
1245
+ return () => style.remove()
1246
+ },
1247
+ 'dsh-todo-board: styles',
1248
+ )
1249
+
1250
+ ctx.effect(() => () => restoreCordisFooter(), 'dsh-todo-board: cordis bridge')
1251
+
1252
+ ctx.slots.inject('shell.overlay', () =>
1253
+ ctx.slots.register(
1254
+ { name: 'shell.overlay', id: 'todo-board', order: 40, label: 'TODO 板' },
1255
+ TodoBoard,
1256
+ ),
1257
+ )
1258
+ }
1259
+
1260
+ return module.exports;
1261
+ } });