dsh-timeback 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -18
- package/client.js +517 -39
- package/docs/MARKET.md +10 -2
- package/docs/PUBLISHING.md +44 -0
- package/index.js +6 -1
- package/package.json +1 -1
- package/src/notes.js +87 -1
- package/src/service.js +7 -0
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# dsh-timeback (时间回溯)
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/dsh-timeback)
|
|
4
|
+
|
|
3
5
|
A DeepSeek Harness plugin that combines two things the built-in UI keeps apart:
|
|
4
6
|
|
|
5
7
|
1. **A conversation tree** — branch a conversation at any completed turn; the old
|
|
@@ -99,8 +101,9 @@ Pick the profile you actually use (`web` for `dsh web`/browser, `desktop` for th
|
|
|
99
101
|
desktop app):
|
|
100
102
|
|
|
101
103
|
```bash
|
|
102
|
-
# From npm (
|
|
104
|
+
# From npm (published: https://www.npmjs.com/package/dsh-timeback)
|
|
103
105
|
dsh plugin --profile web add dsh-timeback
|
|
106
|
+
dsh plugin --profile web add dsh-timeback@0.7.0 # pin a release
|
|
104
107
|
|
|
105
108
|
# Straight from GitHub (no npm release needed)
|
|
106
109
|
dsh plugin --profile web add github:<owner>/dsh-timeback
|
|
@@ -165,22 +168,28 @@ workspace** under `<DSH_HOME>/timeback/repos/<hash>/`. The workspace's own `.git
|
|
|
165
168
|
commits and refs are never read or written. `node_modules/`, virtualenvs and
|
|
166
169
|
caches are excluded by default (configurable), keeping snapshots small and fast.
|
|
167
170
|
|
|
168
|
-
## Notes board (记录板)
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
171
|
+
## Notes board (记录板 · sticky notes)
|
|
172
|
+
|
|
173
|
+
The board is a **sticky-note canvas** with a graph-paper background:
|
|
174
|
+
|
|
175
|
+
- **Movable sticky notes** — every Markdown note is a card you can drag around the
|
|
176
|
+
grid; positions and colours are remembered per board.
|
|
177
|
+
- **Drawing tools** — a pen, an eraser and colour swatches. You can draw on the
|
|
178
|
+
graph-paper background and on any sticky note; strokes are stored with the
|
|
179
|
+
board and **roll back with a rewind** just like the Markdown entries.
|
|
180
|
+
- **New sticky** — the “新建便签” button opens the centred Markdown editor
|
|
181
|
+
(resizable dialog); saving creates a note and places a sticky card.
|
|
182
|
+
- **Session notes are hyperlink stickies** — when the model writes a note through
|
|
183
|
+
`timeback_note`, it is created as a Markdown file and appears on the board as a
|
|
184
|
+
compact 🔗 **link sticky**; clicking it reveals the note.
|
|
185
|
+
- **Markdown below the canvas** — the bottom pane always shows the current board
|
|
186
|
+
contents fully rendered (`#`/lists/code/bold/links…), with edit/delete/open
|
|
187
|
+
actions, so the Markdown documents stay readable even when the canvas is full.
|
|
188
|
+
|
|
189
|
+
Every board change (notes, layout, drawings) is a numbered board revision and is
|
|
190
|
+
captured by checkpoints: rewinding restores the sticky layout and drawings at that
|
|
191
|
+
point together with the conversation and files. History lives under
|
|
192
|
+
`<DSH_HOME>/timeback/notes-history/`.
|
|
184
193
|
|
|
185
194
|
## Using it
|
|
186
195
|
|
|
@@ -282,7 +291,7 @@ Session's working directory, then reload the plugin (config changes remount it).
|
|
|
282
291
|
|
|
283
292
|
## Verification status
|
|
284
293
|
|
|
285
|
-
- Host + client tests (
|
|
294
|
+
- Host + client tests (49 cases, `npm test`) cover snapshot/restore semantics
|
|
286
295
|
(add/edit/delete/symlink/mode, delete-extra policy, nested repositories,
|
|
287
296
|
file↔directory collisions, refusal to delete untracked content blocking a
|
|
288
297
|
restore, excludes, missing trees), registry persistence/trimming, and a
|
package/client.js
CHANGED
|
@@ -23,7 +23,7 @@ window.__ModuleLoader__.load({
|
|
|
23
23
|
const REFRESH_MS = 3000
|
|
24
24
|
const MAX_ROWS = 240
|
|
25
25
|
/** Bump together with package.json so a stale browser bundle is obvious. */
|
|
26
|
-
const BUILD = '0.
|
|
26
|
+
const BUILD = '0.7.0+sticky'
|
|
27
27
|
/** Set by apply(): opens another Session in the main column. */
|
|
28
28
|
let openSessionBridge = null
|
|
29
29
|
/** Set by apply(): opens the Timeback tab in the right sidebar. */
|
|
@@ -98,6 +98,18 @@ window.__ModuleLoader__.load({
|
|
|
98
98
|
'note.removed': '卡片记录已删除',
|
|
99
99
|
'board.title': '记录板',
|
|
100
100
|
'board.subtitle': '全局 Markdown 记录板 · 回溯时一起恢复',
|
|
101
|
+
'board.newSticky': '新建便签',
|
|
102
|
+
'board.stickyHint': '便签可拖动;画笔可在方格纸背景或便签上绘制,橡皮擦除笔画。',
|
|
103
|
+
'board.toolSelect': '拖动',
|
|
104
|
+
'board.toolPen': '画笔',
|
|
105
|
+
'board.toolEraser': '橡皮',
|
|
106
|
+
'board.clearBg': '清背景笔迹',
|
|
107
|
+
'board.clearNote': '清便签笔迹',
|
|
108
|
+
'board.linkSticky': '超链接便签',
|
|
109
|
+
'board.openMd': '打开 md',
|
|
110
|
+
'board.mdBelow': '记录板内容(Markdown)',
|
|
111
|
+
'board.canvasVersion': '便签板 v{version}',
|
|
112
|
+
'board.color': '颜色',
|
|
101
113
|
'board.new': '新建记录',
|
|
102
114
|
'board.edit': '编辑',
|
|
103
115
|
'board.delete': '删除',
|
|
@@ -115,6 +127,8 @@ window.__ModuleLoader__.load({
|
|
|
115
127
|
'board.saved': '记录已保存',
|
|
116
128
|
'board.deleted': '记录已删除',
|
|
117
129
|
'board.count': '{count} 条记录 · 版本 v{version}',
|
|
130
|
+
'board.resetSize': '默认大小',
|
|
131
|
+
'board.resizeHint': '可拖拽弹框右边缘、下边缘或右下角调整大小',
|
|
118
132
|
'board.error': '记录板操作失败:{error}',
|
|
119
133
|
'board.agentHint': '提示:让会话调用 timeback_note 工具即可把结论写进记录板;回溯时记录板会一起回退。',
|
|
120
134
|
'guide.boardTitle': '记录板',
|
|
@@ -272,6 +286,18 @@ window.__ModuleLoader__.load({
|
|
|
272
286
|
'note.removed': 'Card note deleted',
|
|
273
287
|
'board.title': 'Notes board',
|
|
274
288
|
'board.subtitle': 'Global Markdown notes · rewinds restore them too',
|
|
289
|
+
'board.newSticky': 'New sticky',
|
|
290
|
+
'board.stickyHint': 'Sticky notes are draggable; draw on the grid or on a note, erase strokes with the eraser.',
|
|
291
|
+
'board.toolSelect': 'Move',
|
|
292
|
+
'board.toolPen': 'Pen',
|
|
293
|
+
'board.toolEraser': 'Eraser',
|
|
294
|
+
'board.clearBg': 'Clear drawings',
|
|
295
|
+
'board.clearNote': 'Clear note drawing',
|
|
296
|
+
'board.linkSticky': 'Link sticky',
|
|
297
|
+
'board.openMd': 'Open md',
|
|
298
|
+
'board.mdBelow': 'Board contents (Markdown)',
|
|
299
|
+
'board.canvasVersion': 'Board v{version}',
|
|
300
|
+
'board.color': 'Colour',
|
|
275
301
|
'board.new': 'New note',
|
|
276
302
|
'board.edit': 'Edit',
|
|
277
303
|
'board.delete': 'Delete',
|
|
@@ -289,6 +315,8 @@ window.__ModuleLoader__.load({
|
|
|
289
315
|
'board.saved': 'Note saved',
|
|
290
316
|
'board.deleted': 'Note deleted',
|
|
291
317
|
'board.count': '{count} notes · version v{version}',
|
|
318
|
+
'board.resetSize': 'Default size',
|
|
319
|
+
'board.resizeHint': 'Drag the right edge, bottom edge or bottom-right corner to resize',
|
|
292
320
|
'board.error': 'Notes board failed: {error}',
|
|
293
321
|
'board.agentHint': 'Tip: ask the session to use the timeback_note tool; rewinds roll the board back with the conversation.',
|
|
294
322
|
'guide.boardTitle': 'Notes board',
|
|
@@ -480,8 +508,45 @@ window.__ModuleLoader__.load({
|
|
|
480
508
|
.tb-note-dialog textarea,.tb-board-dialog textarea,.tb-board-dialog input{width:100%;box-sizing:border-box;background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.04));color:var(--dsw-alias-label-primary,#e6e6e6);border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));border-radius:7px;padding:7px 9px;font-size:12px;line-height:1.5;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;resize:vertical}
|
|
481
509
|
.tb-note-dialog textarea{min-height:180px}
|
|
482
510
|
.tb-note-actions{display:flex;gap:6px;flex-wrap:wrap;justify-content:flex-end;margin-top:auto}
|
|
483
|
-
.tb-board-dialog{
|
|
484
|
-
.tb-board-dialog textarea{min-height:
|
|
511
|
+
.tb-board-dialog{box-sizing:border-box;position:relative;min-width:340px;min-height:260px;background:var(--dsw-alias-bg-layer-2,rgba(28,32,40,.98));border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.14));border-radius:10px;padding:12px;display:flex;flex-direction:column;gap:8px;max-width:94vw;max-height:90vh;overflow:auto;box-shadow:0 18px 48px rgba(0,0,0,.38)}
|
|
512
|
+
.tb-board-dialog textarea{min-height:120px;flex:1;resize:none}
|
|
513
|
+
.tb-board-dialog .tb-md{flex:1;min-height:120px;overflow:auto;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.1));border-radius:7px;padding:8px 10px}
|
|
514
|
+
.tb-resize-handle{position:absolute;z-index:6;background:transparent}
|
|
515
|
+
.tb-resize-handle.e{top:10px;right:0;bottom:10px;width:8px;cursor:ew-resize}
|
|
516
|
+
.tb-resize-handle.s{left:10px;right:10px;bottom:0;height:8px;cursor:ns-resize}
|
|
517
|
+
.tb-resize-handle.se{right:0;bottom:0;width:18px;height:18px;cursor:nwse-resize}
|
|
518
|
+
.tb-resize-handle.se:after{content:"";position:absolute;right:3px;bottom:3px;width:8px;height:8px;border-right:2px solid var(--dsw-alias-label-secondary,#9aa0a6);border-bottom:2px solid var(--dsw-alias-label-secondary,#9aa0a6);opacity:.55}
|
|
519
|
+
.tb-board-testid{display:none}
|
|
520
|
+
.tb-board-toolbar{display:flex;align-items:center;gap:6px;flex-wrap:wrap;padding:6px 12px;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.08))}
|
|
521
|
+
.tb-tool{appearance:none;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));background:transparent;color:var(--dsw-alias-label-secondary,#9aa0a6);border-radius:6px;padding:3px 8px;font-size:11.5px;cursor:pointer;line-height:1.4}
|
|
522
|
+
.tb-tool.on{color:var(--dsw-alias-label-primary,#e6e6e6);border-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.08))}
|
|
523
|
+
.tb-swatch{width:18px;height:18px;border-radius:50%;border:2px solid transparent;cursor:pointer;padding:0}
|
|
524
|
+
.tb-swatch.on{border-color:var(--dsw-alias-label-primary,#e6e6e6);box-shadow:0 0 0 2px rgba(0,0,0,.3)}
|
|
525
|
+
.tb-board-canvas{position:relative;flex:1;min-height:240px;overflow:auto;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.12));background-color:var(--dsw-alias-bg-base,#16181d);background-image:linear-gradient(to right,var(--dsw-alias-border-l2,rgba(255,255,255,.07)) 1px,transparent 1px),linear-gradient(to bottom,var(--dsw-alias-border-l2,rgba(255,255,255,.07)) 1px,transparent 1px),linear-gradient(to right,var(--dsw-alias-border-l2,rgba(255,255,255,.12)) 1px,transparent 1px),linear-gradient(to bottom,var(--dsw-alias-border-l2,rgba(255,255,255,.12)) 1px,transparent 1px);background-size:22px 22px,22px 22px,110px 110px,110px 110px;cursor:crosshair}
|
|
526
|
+
.tb-board-canvas.select{cursor:default}
|
|
527
|
+
.tb-board-stage{position:relative;width:1800px;height:1200px}
|
|
528
|
+
.tb-board-bgdraw{position:absolute;left:0;top:0;pointer-events:none;overflow:visible}
|
|
529
|
+
.tb-sticky{position:absolute;width:232px;height:176px;box-sizing:border-box;border-radius:5px;padding:8px 9px;display:flex;flex-direction:column;gap:5px;color:#2a2418;box-shadow:0 6px 16px rgba(0,0,0,.28);border:1px solid rgba(0,0,0,.18);overflow:hidden;cursor:grab;user-select:none}
|
|
530
|
+
.tb-sticky:active{cursor:grabbing}
|
|
531
|
+
.tb-sticky.selected{outline:2px solid var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);outline-offset:1px}
|
|
532
|
+
.tb-sticky.link{border-style:dashed;cursor:pointer}
|
|
533
|
+
.tb-sticky-head{display:flex;align-items:center;gap:5px;font-size:12px;font-weight:700;line-height:1.3}
|
|
534
|
+
.tb-sticky-title{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
535
|
+
.tb-sticky-actions{display:flex;gap:3px;opacity:.65}
|
|
536
|
+
.tb-sticky-actions button{appearance:none;border:0;background:rgba(0,0,0,.08);border-radius:4px;font-size:10px;line-height:16px;padding:0 4px;cursor:pointer;color:#2a2418}
|
|
537
|
+
.tb-sticky-actions button:hover{background:rgba(0,0,0,.16)}
|
|
538
|
+
.tb-sticky-body{flex:1;min-height:0;overflow:hidden;font-size:11px;line-height:1.45;color:#3a3326;word-break:break-word;position:relative;z-index:2}
|
|
539
|
+
.tb-sticky-body.md{display:-webkit-box;-webkit-line-clamp:5;-webkit-box-orient:vertical}
|
|
540
|
+
.tb-sticky-linkline{display:flex;align-items:center;gap:6px;font-size:12px;font-weight:600;color:#1c4d8f;text-decoration:underline;cursor:pointer;background:rgba(255,255,255,.35);border-radius:5px;padding:6px 8px}
|
|
541
|
+
.tb-sticky-src{font-size:9.5px;font-weight:600;opacity:.6;white-space:nowrap}
|
|
542
|
+
.tb-sticky-draw{position:absolute;inset:0;pointer-events:none;z-index:1}
|
|
543
|
+
.tb-board-md-pane{flex:0 0 36%;min-height:140px;overflow:auto;padding:8px 12px 20px;display:flex;flex-direction:column;gap:8px;background:var(--dsw-alias-bg-base,#16181d)}
|
|
544
|
+
.tb-board-md-head{font-size:11px;color:var(--dsw-alias-label-secondary,#9aa0a6);position:sticky;top:0;background:var(--dsw-alias-bg-base,#16181d);padding:2px 0;z-index:1}
|
|
545
|
+
.tb-board-md-item{border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.12));border-radius:8px;padding:8px 10px;display:flex;flex-direction:column;gap:5px;background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.03))}
|
|
546
|
+
.tb-board-md-item.selected{border-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6)}
|
|
547
|
+
.tb-board-md-item-head{display:flex;align-items:center;gap:6px;flex-wrap:wrap}
|
|
548
|
+
.tb-board-md-item-title{font-weight:600;font-size:12px}
|
|
549
|
+
.tb-board-md-empty{padding:10px;text-align:center;color:var(--dsw-alias-label-secondary,#9aa0a6);font-size:12px}
|
|
485
550
|
.tb-board-panel{display:flex;flex-direction:column;height:100%;min-height:100%;width:100%;font-size:12.5px;color:var(--dsw-alias-label-primary,#e6e6e6);background:var(--dsw-alias-bg-base,#16181d)}
|
|
486
551
|
.tb-board-head{display:flex;align-items:center;gap:8px;padding:10px 12px;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.1));flex-wrap:wrap}
|
|
487
552
|
.tb-board-title{font-weight:600;font-size:13.5px}
|
|
@@ -2689,16 +2754,108 @@ window.__ModuleLoader__.load({
|
|
|
2689
2754
|
/* global notes board page */
|
|
2690
2755
|
/* ---------------------------------------------------------------- */
|
|
2691
2756
|
|
|
2757
|
+
const BOARD_NOTE_W = 232
|
|
2758
|
+
const BOARD_NOTE_H = 176
|
|
2759
|
+
const BOARD_STAGE_W = 1800
|
|
2760
|
+
const BOARD_STAGE_H = 1200
|
|
2761
|
+
const BOARD_COLORS = ['#e6b84c', '#ff8f7a', '#7ad3ff', '#8be28b', '#d9a8ff', '#ffffff']
|
|
2762
|
+
const BOARD_INKS = ['#e6b84c', '#ff7a7a', '#7ad3ff', '#8be28b', '#ffffff']
|
|
2763
|
+
|
|
2764
|
+
function emptyBoardCanvas() {
|
|
2765
|
+
return { notes: {}, background: [], drawings: {} }
|
|
2766
|
+
}
|
|
2767
|
+
|
|
2768
|
+
/** Deep-copy the sticky canvas so React sees new references. */
|
|
2769
|
+
function cloneBoardCanvas(value) {
|
|
2770
|
+
const canvas = value && typeof value === 'object' ? value : {}
|
|
2771
|
+
const copyStrokes = (strokes) =>
|
|
2772
|
+
(Array.isArray(strokes) ? strokes : []).map((stroke) => ({
|
|
2773
|
+
...stroke,
|
|
2774
|
+
points: (Array.isArray(stroke.points) ? stroke.points : []).map((point) => [...point]),
|
|
2775
|
+
}))
|
|
2776
|
+
return {
|
|
2777
|
+
notes: Object.fromEntries(
|
|
2778
|
+
Object.entries(canvas.notes && typeof canvas.notes === 'object' ? canvas.notes : {}).map(([id, layout]) => [id, { ...layout }]),
|
|
2779
|
+
),
|
|
2780
|
+
background: copyStrokes(canvas.background),
|
|
2781
|
+
drawings: Object.fromEntries(
|
|
2782
|
+
Object.entries(canvas.drawings && typeof canvas.drawings === 'object' ? canvas.drawings : {}).map(([id, strokes]) => [id, copyStrokes(strokes)]),
|
|
2783
|
+
),
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
|
|
2787
|
+
/** SVG polylines for one stroke layer. */
|
|
2788
|
+
function boardPolylines(strokes, keyPrefix) {
|
|
2789
|
+
return (strokes ?? []).map((stroke, index) =>
|
|
2790
|
+
h('polyline', {
|
|
2791
|
+
key: `${keyPrefix}-${index}`,
|
|
2792
|
+
points: stroke.points.map((point) => `${point[0]},${point[1]}`).join(' '),
|
|
2793
|
+
fill: 'none',
|
|
2794
|
+
stroke: stroke.color,
|
|
2795
|
+
strokeWidth: stroke.width,
|
|
2796
|
+
strokeLinecap: 'round',
|
|
2797
|
+
strokeLinejoin: 'round',
|
|
2798
|
+
}),
|
|
2799
|
+
)
|
|
2800
|
+
}
|
|
2801
|
+
|
|
2802
|
+
/** Default position/colour for a note without a saved layout. */
|
|
2803
|
+
function autoBoardLayout(index) {
|
|
2804
|
+
const columns = 5
|
|
2805
|
+
return {
|
|
2806
|
+
x: 24 + (index % columns) * (BOARD_NOTE_W + 20),
|
|
2807
|
+
y: 24 + Math.floor(index / columns) * (BOARD_NOTE_H + 20),
|
|
2808
|
+
z: index,
|
|
2809
|
+
color: BOARD_COLORS[index % BOARD_COLORS.length],
|
|
2810
|
+
}
|
|
2811
|
+
}
|
|
2812
|
+
|
|
2692
2813
|
function BoardPanel(props) {
|
|
2693
2814
|
const t = typeof props?.t === 'function' ? props.t : (key) => key
|
|
2694
2815
|
const [state, setState] = React.useState({ loading: true, board: null, error: null })
|
|
2695
2816
|
const [draft, setDraft] = React.useState(null)
|
|
2696
2817
|
const [busy, setBusy] = React.useState('')
|
|
2818
|
+
const [dialogSize, setDialogSize] = React.useState(() => {
|
|
2819
|
+
const fallback = { width: 680, height: 520 }
|
|
2820
|
+
try {
|
|
2821
|
+
const raw = JSON.parse(window.localStorage.getItem('dsh-timeback:board-dialog-size') || 'null')
|
|
2822
|
+
if (raw && Number.isFinite(raw.width) && Number.isFinite(raw.height)) {
|
|
2823
|
+
return { width: Math.min(1200, Math.max(340, raw.width)), height: Math.min(900, Math.max(260, raw.height)) }
|
|
2824
|
+
}
|
|
2825
|
+
} catch {
|
|
2826
|
+
// fall through to the default
|
|
2827
|
+
}
|
|
2828
|
+
const height = typeof window !== 'undefined' && Number.isFinite(window.innerHeight) ? Math.round(window.innerHeight * 0.62) : fallback.height
|
|
2829
|
+
return { width: fallback.width, height: Math.max(320, Math.min(640, height)) }
|
|
2830
|
+
})
|
|
2831
|
+
const dialogSizeRef = React.useRef(dialogSize)
|
|
2832
|
+
dialogSizeRef.current = dialogSize
|
|
2833
|
+
const [canvas, setCanvas] = React.useState(emptyBoardCanvas)
|
|
2834
|
+
const canvasRef = React.useRef(canvas)
|
|
2835
|
+
canvasRef.current = canvas
|
|
2836
|
+
const [tool, setTool] = React.useState('select')
|
|
2837
|
+
const toolRef = React.useRef(tool)
|
|
2838
|
+
toolRef.current = tool
|
|
2839
|
+
const [ink, setInk] = React.useState(BOARD_INKS[0])
|
|
2840
|
+
const inkRef = React.useRef(ink)
|
|
2841
|
+
inkRef.current = ink
|
|
2842
|
+
const [selected, setSelected] = React.useState('')
|
|
2843
|
+
const selectedRef = React.useRef(selected)
|
|
2844
|
+
selectedRef.current = selected
|
|
2845
|
+
const stageRef = React.useRef(null)
|
|
2846
|
+
const saveTimerRef = React.useRef(null)
|
|
2847
|
+
const gestureRef = React.useRef(null)
|
|
2697
2848
|
|
|
2698
2849
|
const refresh = React.useCallback(async () => {
|
|
2699
2850
|
try {
|
|
2700
2851
|
const body = await request('notes')
|
|
2701
|
-
|
|
2852
|
+
const board = body.board ?? null
|
|
2853
|
+
setState({ loading: false, board, error: null })
|
|
2854
|
+
if (board) {
|
|
2855
|
+
const next = cloneBoardCanvas(board.canvas)
|
|
2856
|
+
canvasRef.current = next
|
|
2857
|
+
setCanvas(next)
|
|
2858
|
+
}
|
|
2702
2859
|
} catch (error) {
|
|
2703
2860
|
setState((previous) => ({ ...previous, loading: false, error: error?.message || String(error) }))
|
|
2704
2861
|
}
|
|
@@ -2713,13 +2870,88 @@ window.__ModuleLoader__.load({
|
|
|
2713
2870
|
return () => window.removeEventListener('dsh-timeback:board-changed', handler)
|
|
2714
2871
|
}, [refresh])
|
|
2715
2872
|
|
|
2716
|
-
|
|
2873
|
+
React.useEffect(() => () => {
|
|
2874
|
+
if (saveTimerRef.current) clearTimeout(saveTimerRef.current)
|
|
2875
|
+
}, [])
|
|
2876
|
+
|
|
2877
|
+
/** Persist the canvas shortly after the last change (drag/draw). */
|
|
2878
|
+
const saveCanvasSoon = (next) => {
|
|
2879
|
+
canvasRef.current = next
|
|
2880
|
+
setCanvas(next)
|
|
2881
|
+
if (saveTimerRef.current) clearTimeout(saveTimerRef.current)
|
|
2882
|
+
saveTimerRef.current = setTimeout(async () => {
|
|
2883
|
+
saveTimerRef.current = null
|
|
2884
|
+
try {
|
|
2885
|
+
const body = await request('action', { method: 'POST', body: { action: 'board-canvas', canvas: next } })
|
|
2886
|
+
setState((previous) => ({ ...previous, board: body.board ?? previous.board, error: null }))
|
|
2887
|
+
} catch (error) {
|
|
2888
|
+
setState((previous) => ({ ...previous, error: error?.message || String(error) }))
|
|
2889
|
+
}
|
|
2890
|
+
}, 420)
|
|
2891
|
+
}
|
|
2892
|
+
|
|
2893
|
+
const persistDialogSize = (value) => {
|
|
2894
|
+
try {
|
|
2895
|
+
window.localStorage.setItem('dsh-timeback:board-dialog-size', JSON.stringify(value))
|
|
2896
|
+
} catch {
|
|
2897
|
+
// Storage can be disabled.
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
2900
|
+
const resetDialogSize = () => {
|
|
2901
|
+
const next = { width: 680, height: 520 }
|
|
2902
|
+
setDialogSize(next)
|
|
2903
|
+
persistDialogSize(next)
|
|
2904
|
+
}
|
|
2905
|
+
/** Drag one edge/corner of the note dialog to resize it. */
|
|
2906
|
+
const beginDialogResize = (event, direction) => {
|
|
2907
|
+
if (event.button !== 0) return
|
|
2908
|
+
event.preventDefault()
|
|
2909
|
+
event.stopPropagation()
|
|
2910
|
+
const startX = event.clientX
|
|
2911
|
+
const startY = event.clientY
|
|
2912
|
+
const start = { ...dialogSizeRef.current }
|
|
2913
|
+
const apply = (width, height) => {
|
|
2914
|
+
const next = {
|
|
2915
|
+
width: Math.min(1200, Math.max(340, Math.round(width))),
|
|
2916
|
+
height: Math.min(900, Math.max(260, Math.round(height))),
|
|
2917
|
+
}
|
|
2918
|
+
dialogSizeRef.current = next
|
|
2919
|
+
setDialogSize(next)
|
|
2920
|
+
}
|
|
2921
|
+
const move = (next) => {
|
|
2922
|
+
apply(
|
|
2923
|
+
start.width + (direction.includes('e') ? next.clientX - startX : 0),
|
|
2924
|
+
start.height + (direction.includes('s') ? next.clientY - startY : 0),
|
|
2925
|
+
)
|
|
2926
|
+
}
|
|
2927
|
+
const finish = () => {
|
|
2928
|
+
window.removeEventListener('pointermove', move)
|
|
2929
|
+
window.removeEventListener('pointerup', finish)
|
|
2930
|
+
window.removeEventListener('pointercancel', finish)
|
|
2931
|
+
persistDialogSize(dialogSizeRef.current)
|
|
2932
|
+
}
|
|
2933
|
+
window.addEventListener('pointermove', move)
|
|
2934
|
+
window.addEventListener('pointerup', finish)
|
|
2935
|
+
window.addEventListener('pointercancel', finish)
|
|
2936
|
+
}
|
|
2937
|
+
|
|
2938
|
+
const entries = state.board?.entries ?? []
|
|
2939
|
+
const sortedEntries = [...entries].sort((left, right) => (right.updatedAt ?? 0) - (left.updatedAt ?? 0))
|
|
2717
2940
|
const boardVersion = state.board?.version ?? 0
|
|
2941
|
+
const layoutFor = (entry, index) => canvas.notes[entry.id] ?? autoBoardLayout(index)
|
|
2718
2942
|
const startCreate = () => setDraft({ id: '', title: '', body: '', preview: false, busy: false, error: null })
|
|
2719
2943
|
const startEdit = (entry) => setDraft({ id: entry.id, title: entry.title, body: entry.body, preview: false, busy: false, error: null })
|
|
2720
2944
|
const closeDraft = () => {
|
|
2721
2945
|
if (draft && !draft.busy) setDraft(null)
|
|
2722
2946
|
}
|
|
2947
|
+
const focusEntry = (id) => {
|
|
2948
|
+
setSelected(id)
|
|
2949
|
+
try {
|
|
2950
|
+
if (typeof document !== 'undefined') document.getElementById(`tb-md-${id}`)?.scrollIntoView({ block: 'nearest' })
|
|
2951
|
+
} catch {
|
|
2952
|
+
// Scrolling is a convenience.
|
|
2953
|
+
}
|
|
2954
|
+
}
|
|
2723
2955
|
const saveDraft = async () => {
|
|
2724
2956
|
if (!draft || draft.busy) return
|
|
2725
2957
|
setDraft({ ...draft, busy: true, error: null })
|
|
@@ -2728,8 +2960,17 @@ window.__ModuleLoader__.load({
|
|
|
2728
2960
|
method: 'POST',
|
|
2729
2961
|
body: { action: 'note-save', ...(draft.id ? { id: draft.id } : {}), title: draft.title, body: draft.body },
|
|
2730
2962
|
})
|
|
2963
|
+
const board = body.board ?? state.board
|
|
2731
2964
|
setDraft(null)
|
|
2732
|
-
setState({ loading: false, board
|
|
2965
|
+
setState({ loading: false, board, error: null })
|
|
2966
|
+
// Put a brand-new note where the sticky board expects one.
|
|
2967
|
+
if (!draft.id && body.entry?.id && board && !canvasRef.current.notes[body.entry.id]) {
|
|
2968
|
+
const index = Math.max(0, (board.entries?.length ?? 1) - 1)
|
|
2969
|
+
saveCanvasSoon({
|
|
2970
|
+
...canvasRef.current,
|
|
2971
|
+
notes: { ...canvasRef.current.notes, [body.entry.id]: autoBoardLayout(index) },
|
|
2972
|
+
})
|
|
2973
|
+
}
|
|
2733
2974
|
} catch (error) {
|
|
2734
2975
|
setDraft({ ...draft, busy: false, error: error?.message || String(error) })
|
|
2735
2976
|
}
|
|
@@ -2747,6 +2988,10 @@ window.__ModuleLoader__.load({
|
|
|
2747
2988
|
try {
|
|
2748
2989
|
const body = await request('action', { method: 'POST', body: { action: 'note-delete', id } })
|
|
2749
2990
|
setState({ loading: false, board: body.board ?? state.board, error: null })
|
|
2991
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
2992
|
+
delete next.notes[id]
|
|
2993
|
+
delete next.drawings[id]
|
|
2994
|
+
saveCanvasSoon(next)
|
|
2750
2995
|
} catch (error) {
|
|
2751
2996
|
setState((previous) => ({ ...previous, error: error?.message || String(error) }))
|
|
2752
2997
|
} finally {
|
|
@@ -2754,6 +2999,222 @@ window.__ModuleLoader__.load({
|
|
|
2754
2999
|
}
|
|
2755
3000
|
}
|
|
2756
3001
|
|
|
3002
|
+
/* -------------------------------------------------------------- */
|
|
3003
|
+
/* sticky canvas: drag notes and draw strokes */
|
|
3004
|
+
/* -------------------------------------------------------------- */
|
|
3005
|
+
|
|
3006
|
+
const setGesture = (gesture) => {
|
|
3007
|
+
gestureRef.current = gesture
|
|
3008
|
+
const move = (event) => {
|
|
3009
|
+
const current = gestureRef.current
|
|
3010
|
+
if (!current) return
|
|
3011
|
+
if (current.type === 'drag') {
|
|
3012
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
3013
|
+
const layout = { ...(next.notes[current.noteId] ?? autoBoardLayout(0)) }
|
|
3014
|
+
layout.x = Math.max(0, Math.min(BOARD_STAGE_W - BOARD_NOTE_W, current.originX + event.clientX - current.startX))
|
|
3015
|
+
layout.y = Math.max(0, Math.min(BOARD_STAGE_H - BOARD_NOTE_H, current.originY + event.clientY - current.startY))
|
|
3016
|
+
next.notes[current.noteId] = layout
|
|
3017
|
+
canvasRef.current = next
|
|
3018
|
+
setCanvas(next)
|
|
3019
|
+
return
|
|
3020
|
+
}
|
|
3021
|
+
const point = [Math.round(event.clientX - current.rect.left), Math.round(event.clientY - current.rect.top)]
|
|
3022
|
+
if (current.type === 'draw') {
|
|
3023
|
+
const stroke = current.stroke
|
|
3024
|
+
const last = stroke.points[stroke.points.length - 1]
|
|
3025
|
+
if (last && Math.abs(last[0] - point[0]) + Math.abs(last[1] - point[1]) < 2) return
|
|
3026
|
+
if (stroke.points.length >= 800) return
|
|
3027
|
+
stroke.points.push(point)
|
|
3028
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
3029
|
+
if (current.layer === 'background') {
|
|
3030
|
+
next.background = [...next.background]
|
|
3031
|
+
next.background[current.strokeIndex] = { ...stroke, points: stroke.points.map((item) => [...item]) }
|
|
3032
|
+
} else {
|
|
3033
|
+
const list = [...(next.drawings[current.noteId] ?? [])]
|
|
3034
|
+
list[current.strokeIndex] = { ...stroke, points: stroke.points.map((item) => [...item]) }
|
|
3035
|
+
next.drawings[current.noteId] = list
|
|
3036
|
+
}
|
|
3037
|
+
canvasRef.current = next
|
|
3038
|
+
setCanvas(next)
|
|
3039
|
+
} else if (current.type === 'erase') {
|
|
3040
|
+
eraseAt(current, point)
|
|
3041
|
+
}
|
|
3042
|
+
}
|
|
3043
|
+
const finish = () => {
|
|
3044
|
+
window.removeEventListener('pointermove', move)
|
|
3045
|
+
window.removeEventListener('pointerup', finish)
|
|
3046
|
+
window.removeEventListener('pointercancel', finish)
|
|
3047
|
+
const current = gestureRef.current
|
|
3048
|
+
gestureRef.current = null
|
|
3049
|
+
if (current && current.type !== 'erase') saveCanvasSoon(cloneBoardCanvas(canvasRef.current))
|
|
3050
|
+
else if (current) saveCanvasSoon(cloneBoardCanvas(canvasRef.current))
|
|
3051
|
+
}
|
|
3052
|
+
window.addEventListener('pointermove', move)
|
|
3053
|
+
window.addEventListener('pointerup', finish)
|
|
3054
|
+
window.addEventListener('pointercancel', finish)
|
|
3055
|
+
}
|
|
3056
|
+
|
|
3057
|
+
const eraseAt = (gesture, point) => {
|
|
3058
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
3059
|
+
const list = gesture.layer === 'background' ? [...next.background] : [...(next.drawings[gesture.noteId] ?? [])]
|
|
3060
|
+
const kept = list.filter((stroke) => !stroke.points.some(([x, y]) => Math.hypot(x - point[0], y - point[1]) < 12))
|
|
3061
|
+
if (kept.length === list.length) return
|
|
3062
|
+
if (gesture.layer === 'background') next.background = kept
|
|
3063
|
+
else if (kept.length > 0) next.drawings[gesture.noteId] = kept
|
|
3064
|
+
else delete next.drawings[gesture.noteId]
|
|
3065
|
+
canvasRef.current = next
|
|
3066
|
+
setCanvas(next)
|
|
3067
|
+
}
|
|
3068
|
+
|
|
3069
|
+
const beginPointer = (event) => {
|
|
3070
|
+
if (event.button !== 0) return
|
|
3071
|
+
if (event.target?.closest?.('button')) return
|
|
3072
|
+
const stage = stageRef.current
|
|
3073
|
+
if (!stage) return
|
|
3074
|
+
const noteElement = event.target?.closest?.('.tb-sticky')
|
|
3075
|
+
const noteId = noteElement?.getAttribute?.('data-note-id') || ''
|
|
3076
|
+
if (toolRef.current === 'select') {
|
|
3077
|
+
if (!noteId) {
|
|
3078
|
+
setSelected('')
|
|
3079
|
+
return
|
|
3080
|
+
}
|
|
3081
|
+
event.preventDefault()
|
|
3082
|
+
setSelected(noteId)
|
|
3083
|
+
const layout = canvasRef.current.notes[noteId] ?? autoBoardLayout(0)
|
|
3084
|
+
setGesture({
|
|
3085
|
+
type: 'drag',
|
|
3086
|
+
noteId,
|
|
3087
|
+
startX: event.clientX,
|
|
3088
|
+
startY: event.clientY,
|
|
3089
|
+
originX: Number(layout.x) || 0,
|
|
3090
|
+
originY: Number(layout.y) || 0,
|
|
3091
|
+
})
|
|
3092
|
+
return
|
|
3093
|
+
}
|
|
3094
|
+
event.preventDefault()
|
|
3095
|
+
const rect = (noteElement ?? stage).getBoundingClientRect()
|
|
3096
|
+
const point = [Math.round(event.clientX - rect.left), Math.round(event.clientY - rect.top)]
|
|
3097
|
+
const layer = noteId ? 'note' : 'background'
|
|
3098
|
+
if (toolRef.current === 'eraser') {
|
|
3099
|
+
const gesture = { type: 'erase', layer, noteId, rect }
|
|
3100
|
+
eraseAt(gesture, point)
|
|
3101
|
+
setGesture(gesture)
|
|
3102
|
+
return
|
|
3103
|
+
}
|
|
3104
|
+
const stroke = { color: inkRef.current, width: 2, points: [point] }
|
|
3105
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
3106
|
+
let strokeIndex
|
|
3107
|
+
if (layer === 'background') {
|
|
3108
|
+
strokeIndex = next.background.length
|
|
3109
|
+
next.background.push(stroke)
|
|
3110
|
+
} else {
|
|
3111
|
+
const list = [...(next.drawings[noteId] ?? [])]
|
|
3112
|
+
strokeIndex = list.length
|
|
3113
|
+
list.push(stroke)
|
|
3114
|
+
next.drawings[noteId] = list
|
|
3115
|
+
}
|
|
3116
|
+
canvasRef.current = next
|
|
3117
|
+
setCanvas(next)
|
|
3118
|
+
setGesture({ type: 'draw', layer, noteId, rect, stroke, strokeIndex })
|
|
3119
|
+
}
|
|
3120
|
+
|
|
3121
|
+
const clearBackground = () => {
|
|
3122
|
+
if (canvasRef.current.background.length === 0) return
|
|
3123
|
+
saveCanvasSoon({ ...cloneBoardCanvas(canvasRef.current), background: [] })
|
|
3124
|
+
}
|
|
3125
|
+
const clearSelectedDrawing = () => {
|
|
3126
|
+
const id = selectedRef.current
|
|
3127
|
+
if (!id || !canvasRef.current.drawings[id]?.length) return
|
|
3128
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
3129
|
+
delete next.drawings[id]
|
|
3130
|
+
saveCanvasSoon(next)
|
|
3131
|
+
}
|
|
3132
|
+
|
|
3133
|
+
/* -------------------------------------------------------------- */
|
|
3134
|
+
/* render */
|
|
3135
|
+
/* -------------------------------------------------------------- */
|
|
3136
|
+
|
|
3137
|
+
const drawingLayer = (strokes, prefix) =>
|
|
3138
|
+
h('svg', { className: prefix === 'bg' ? 'tb-board-bgdraw' : 'tb-sticky-draw', width: prefix === 'bg' ? BOARD_STAGE_W : '100%', height: prefix === 'bg' ? BOARD_STAGE_H : '100%' }, ...boardPolylines(strokes, prefix))
|
|
3139
|
+
|
|
3140
|
+
const stickyFor = (entry, index) => {
|
|
3141
|
+
const layout = layoutFor(entry, index)
|
|
3142
|
+
const agent = entry.source === 'agent'
|
|
3143
|
+
return h(
|
|
3144
|
+
'article',
|
|
3145
|
+
{
|
|
3146
|
+
key: entry.id,
|
|
3147
|
+
className: `tb-sticky${agent ? ' link' : ''}${selected === entry.id ? ' selected' : ''}`,
|
|
3148
|
+
'data-note-id': entry.id,
|
|
3149
|
+
style: {
|
|
3150
|
+
left: Number(layout.x) || 0,
|
|
3151
|
+
top: Number(layout.y) || 0,
|
|
3152
|
+
zIndex: 100 + (Number(layout.z) || 0),
|
|
3153
|
+
background: layout.color || BOARD_COLORS[index % BOARD_COLORS.length],
|
|
3154
|
+
},
|
|
3155
|
+
onDoubleClick: (event) => {
|
|
3156
|
+
event.stopPropagation()
|
|
3157
|
+
startEdit(entry)
|
|
3158
|
+
},
|
|
3159
|
+
},
|
|
3160
|
+
h(
|
|
3161
|
+
'div',
|
|
3162
|
+
{ className: 'tb-sticky-head' },
|
|
3163
|
+
h('span', { className: 'tb-sticky-src' }, agent ? '🔗' : t('board.sourceUser')),
|
|
3164
|
+
h('span', { className: 'tb-sticky-title', title: entry.title }, entry.title || '未命名便签'),
|
|
3165
|
+
h(
|
|
3166
|
+
'div',
|
|
3167
|
+
{ className: 'tb-sticky-actions' },
|
|
3168
|
+
h('button', { type: 'button', title: t('board.edit'), onClick: (event) => { event.stopPropagation(); startEdit(entry) } }, '✎'),
|
|
3169
|
+
h('button', { type: 'button', title: t('board.delete'), disabled: busy !== '', onClick: (event) => { event.stopPropagation(); removeEntry(entry.id) } }, '✕'),
|
|
3170
|
+
),
|
|
3171
|
+
),
|
|
3172
|
+
agent
|
|
3173
|
+
? h(
|
|
3174
|
+
'div',
|
|
3175
|
+
{ className: 'tb-sticky-body' },
|
|
3176
|
+
h(
|
|
3177
|
+
'span',
|
|
3178
|
+
{
|
|
3179
|
+
className: 'tb-sticky-linkline',
|
|
3180
|
+
role: 'link',
|
|
3181
|
+
tabIndex: 0,
|
|
3182
|
+
onClick: (event) => {
|
|
3183
|
+
event.stopPropagation()
|
|
3184
|
+
focusEntry(entry.id)
|
|
3185
|
+
},
|
|
3186
|
+
},
|
|
3187
|
+
`🔗 ${t('board.openMd')}`,
|
|
3188
|
+
),
|
|
3189
|
+
h('div', { className: 'tb-board-meta' }, stripMarkdown(entry.body).slice(0, 90)),
|
|
3190
|
+
)
|
|
3191
|
+
: h('div', { className: 'tb-sticky-body md' }, stripMarkdown(entry.body) || t('board.empty')),
|
|
3192
|
+
drawingLayer(canvas.drawings[entry.id] ?? [], `d-${entry.id}`),
|
|
3193
|
+
)
|
|
3194
|
+
}
|
|
3195
|
+
|
|
3196
|
+
const toolbar = h(
|
|
3197
|
+
'div',
|
|
3198
|
+
{ className: 'tb-board-toolbar' },
|
|
3199
|
+
h('button', { type: 'button', className: `tb-tool${tool === 'select' ? ' on' : ''}`, onClick: () => setTool('select') }, t('board.toolSelect')),
|
|
3200
|
+
h('button', { type: 'button', className: `tb-tool${tool === 'pen' ? ' on' : ''}`, onClick: () => setTool('pen') }, `✏️ ${t('board.toolPen')}`),
|
|
3201
|
+
h('button', { type: 'button', className: `tb-tool${tool === 'eraser' ? ' on' : ''}`, onClick: () => setTool('eraser') }, `🧽 ${t('board.toolEraser')}`),
|
|
3202
|
+
h('span', { className: 'tb-board-meta' }, t('board.color')),
|
|
3203
|
+
...BOARD_INKS.map((value) =>
|
|
3204
|
+
h('button', {
|
|
3205
|
+
key: value,
|
|
3206
|
+
type: 'button',
|
|
3207
|
+
className: `tb-swatch${ink === value ? ' on' : ''}`,
|
|
3208
|
+
style: { background: value },
|
|
3209
|
+
title: value,
|
|
3210
|
+
onClick: () => setInk(value),
|
|
3211
|
+
}),
|
|
3212
|
+
),
|
|
3213
|
+
h('span', { style: { flex: 1 } }),
|
|
3214
|
+
h('button', { type: 'button', className: 'tb-btn', disabled: canvas.background.length === 0, onClick: clearBackground }, t('board.clearBg')),
|
|
3215
|
+
h('button', { type: 'button', className: 'tb-btn', disabled: !selected || !(canvas.drawings[selected]?.length > 0), onClick: clearSelectedDrawing }, t('board.clearNote')),
|
|
3216
|
+
)
|
|
3217
|
+
|
|
2757
3218
|
return h(
|
|
2758
3219
|
'div',
|
|
2759
3220
|
{ className: 'tb-board-panel' },
|
|
@@ -2764,46 +3225,52 @@ window.__ModuleLoader__.load({
|
|
|
2764
3225
|
h('span', { className: 'tb-board-sub' }, t('board.subtitle')),
|
|
2765
3226
|
h('span', { style: { flex: 1 } }),
|
|
2766
3227
|
h('span', { className: 'tb-muted tb-small' }, format(t('board.count'), { count: entries.length, version: boardVersion })),
|
|
3228
|
+
h('span', { className: 'tb-muted tb-small' }, format(t('board.canvasVersion'), { version: boardVersion })),
|
|
2767
3229
|
h('button', { type: 'button', className: 'tb-btn', disabled: state.loading, onClick: refresh }, t('board.refresh')),
|
|
2768
|
-
h('button', { type: 'button', className: 'tb-btn primary', onClick: startCreate }, `+ ${t('board.
|
|
3230
|
+
h('button', { type: 'button', className: 'tb-btn primary', onClick: startCreate }, `+ ${t('board.newSticky')}`),
|
|
2769
3231
|
),
|
|
3232
|
+
toolbar,
|
|
3233
|
+
h('div', { className: 'tb-board-hint-wrap' }, h('span', { className: 'tb-ws-hint' }, t('board.stickyHint'))),
|
|
3234
|
+
state.error ? h('div', { className: 'tb-feedback err' }, format(t('board.error'), { error: state.error })) : null,
|
|
2770
3235
|
h(
|
|
2771
3236
|
'div',
|
|
2772
|
-
{ className:
|
|
2773
|
-
h(
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
{ className: `tb-chip ${entry.source === 'agent' ? 'ok' : ''}` },
|
|
2790
|
-
entry.source === 'agent' ? t('board.sourceAgent') : t('board.sourceUser'),
|
|
2791
|
-
),
|
|
2792
|
-
h('span', { className: 'tb-board-meta' }, clock(entry.updatedAt)),
|
|
3237
|
+
{ className: `tb-board-canvas${tool === 'select' ? ' select' : ''}`, onPointerDown: beginPointer },
|
|
3238
|
+
h(
|
|
3239
|
+
'div',
|
|
3240
|
+
{ className: 'tb-board-stage', ref: stageRef, style: { width: BOARD_STAGE_W, height: BOARD_STAGE_H } },
|
|
3241
|
+
drawingLayer(canvas.background, 'bg'),
|
|
3242
|
+
...entries.map((entry, index) => stickyFor(entry, index)),
|
|
3243
|
+
),
|
|
3244
|
+
state.loading && !state.board ? h('p', { className: 'tb-board-md-empty' }, t('panel.loading')) : null,
|
|
3245
|
+
!state.loading && entries.length === 0 ? h('p', { className: 'tb-board-md-empty' }, t('board.empty')) : null,
|
|
3246
|
+
),
|
|
3247
|
+
h(
|
|
3248
|
+
'div',
|
|
3249
|
+
{ className: 'tb-board-md-pane' },
|
|
3250
|
+
h('div', { className: 'tb-board-md-head' }, t('board.mdBelow')),
|
|
3251
|
+
sortedEntries.length === 0
|
|
3252
|
+
? h('p', { className: 'tb-board-md-empty' }, t('board.empty'))
|
|
3253
|
+
: sortedEntries.map((entry) =>
|
|
2793
3254
|
h(
|
|
2794
|
-
'
|
|
2795
|
-
{ className:
|
|
2796
|
-
h('button', { type: 'button', className: 'tb-btn', onClick: () => startEdit(entry) }, t('board.edit')),
|
|
3255
|
+
'section',
|
|
3256
|
+
{ key: entry.id, id: `tb-md-${entry.id}`, className: `tb-board-md-item${selected === entry.id ? ' selected' : ''}` },
|
|
2797
3257
|
h(
|
|
2798
|
-
'
|
|
2799
|
-
{
|
|
2800
|
-
|
|
3258
|
+
'div',
|
|
3259
|
+
{ className: 'tb-board-md-item-head' },
|
|
3260
|
+
h('span', { className: 'tb-board-md-item-title' }, entry.title || '未命名便签'),
|
|
3261
|
+
h('span', { className: `tb-chip ${entry.source === 'agent' ? 'ok' : ''}` }, entry.source === 'agent' ? t('board.sourceAgent') : t('board.sourceUser')),
|
|
3262
|
+
h('span', { className: 'tb-board-meta' }, clock(entry.updatedAt)),
|
|
3263
|
+
h(
|
|
3264
|
+
'div',
|
|
3265
|
+
{ className: 'tb-board-actions' },
|
|
3266
|
+
h('button', { type: 'button', className: 'tb-btn', onClick: () => focusEntry(entry.id) }, t('board.openMd')),
|
|
3267
|
+
h('button', { type: 'button', className: 'tb-btn', onClick: () => startEdit(entry) }, t('board.edit')),
|
|
3268
|
+
h('button', { type: 'button', className: 'tb-btn danger', disabled: busy !== '', onClick: () => removeEntry(entry.id) }, busy === entry.id ? '…' : t('board.delete')),
|
|
3269
|
+
),
|
|
2801
3270
|
),
|
|
3271
|
+
entry.body ? h('div', { className: 'tb-md' }, ...renderMarkdown(entry.body, `md-${entry.id}`)) : null,
|
|
2802
3272
|
),
|
|
2803
3273
|
),
|
|
2804
|
-
entry.body ? h('div', { className: 'tb-md' }, ...renderMarkdown(entry.body, `board-${entry.id}`)) : null,
|
|
2805
|
-
),
|
|
2806
|
-
),
|
|
2807
3274
|
),
|
|
2808
3275
|
draft
|
|
2809
3276
|
? h(
|
|
@@ -2811,11 +3278,17 @@ window.__ModuleLoader__.load({
|
|
|
2811
3278
|
{ className: 'tb-overlay center', onClick: closeDraft },
|
|
2812
3279
|
h(
|
|
2813
3280
|
'div',
|
|
2814
|
-
{
|
|
3281
|
+
{
|
|
3282
|
+
className: 'tb-board-dialog',
|
|
3283
|
+
role: 'dialog',
|
|
3284
|
+
'aria-modal': true,
|
|
3285
|
+
style: { width: dialogSize.width, height: dialogSize.height },
|
|
3286
|
+
onClick: (event) => event.stopPropagation(),
|
|
3287
|
+
},
|
|
2815
3288
|
h(
|
|
2816
3289
|
'div',
|
|
2817
3290
|
{ className: 'tb-detail-head' },
|
|
2818
|
-
h('span', { className: 'tb-detail-title' }, draft.id ? t('board.edit') : t('board.
|
|
3291
|
+
h('span', { className: 'tb-detail-title' }, draft.id ? t('board.edit') : t('board.newSticky')),
|
|
2819
3292
|
h('span', { style: { flex: 1 } }),
|
|
2820
3293
|
h(
|
|
2821
3294
|
'button',
|
|
@@ -2826,6 +3299,7 @@ window.__ModuleLoader__.load({
|
|
|
2826
3299
|
},
|
|
2827
3300
|
draft.preview ? t('board.editMode') : t('board.preview'),
|
|
2828
3301
|
),
|
|
3302
|
+
h('button', { type: 'button', className: 'tb-btn', title: t('board.resizeHint'), onClick: resetDialogSize }, t('board.resetSize')),
|
|
2829
3303
|
),
|
|
2830
3304
|
h('input', {
|
|
2831
3305
|
value: draft.title,
|
|
@@ -2841,6 +3315,7 @@ window.__ModuleLoader__.load({
|
|
|
2841
3315
|
disabled: draft.busy,
|
|
2842
3316
|
onChange: (event) => setDraft({ ...draft, body: event.target.value }),
|
|
2843
3317
|
}),
|
|
3318
|
+
h('div', { className: 'tb-ws-hint' }, t('board.resizeHint')),
|
|
2844
3319
|
draft.error ? h('div', { className: 'tb-feedback err' }, format(t('board.error'), { error: draft.error })) : null,
|
|
2845
3320
|
h(
|
|
2846
3321
|
'div',
|
|
@@ -2848,6 +3323,9 @@ window.__ModuleLoader__.load({
|
|
|
2848
3323
|
h('button', { type: 'button', className: 'tb-btn', disabled: draft.busy, onClick: closeDraft }, t('board.cancel')),
|
|
2849
3324
|
h('button', { type: 'button', className: 'tb-btn primary', disabled: draft.busy, onClick: saveDraft }, t('board.save')),
|
|
2850
3325
|
),
|
|
3326
|
+
h('div', { className: 'tb-resize-handle e', onPointerDown: (event) => beginDialogResize(event, 'e') }),
|
|
3327
|
+
h('div', { className: 'tb-resize-handle s', onPointerDown: (event) => beginDialogResize(event, 's') }),
|
|
3328
|
+
h('div', { className: 'tb-resize-handle se', onPointerDown: (event) => beginDialogResize(event, 'se') }),
|
|
2851
3329
|
),
|
|
2852
3330
|
)
|
|
2853
3331
|
: null,
|
package/docs/MARKET.md
CHANGED
|
@@ -76,9 +76,17 @@ dshmarket;要让所有人的 dshmarket 搜到,必须走下一节的公共目
|
|
|
76
76
|
- **dshbase**:<https://github.com/ylwl1997/dshbase/issues> 用插件提交表单;
|
|
77
77
|
- **dshhub**:<https://dshhub.dev/submit>(明确要求声明许可证,本项目 MIT)。
|
|
78
78
|
|
|
79
|
-
## 4. npm
|
|
79
|
+
## 4. npm(已发布 0.6.0)
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
`dsh-timeback@0.7.0` 已发布到官方 npm(<https://www.npmjs.com/package/dsh-timeback>),
|
|
82
|
+
用户可以直接安装/固定版本:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
dsh plugin --profile web add dsh-timeback
|
|
86
|
+
dsh plugin --profile web add dsh-timeback@0.7.0
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
awesome 目录 CI 会从 npm 自动补充映射,之后市场安装和更新会走 registry。发布流程参考:
|
|
82
90
|
|
|
83
91
|
```bash
|
|
84
92
|
cd /home/kali/timeback
|
package/docs/PUBLISHING.md
CHANGED
|
@@ -161,6 +161,50 @@ DSH 没有官方中央商店;Discover 读取的是 format-1 JSON 索引,实
|
|
|
161
161
|
|
|
162
162
|
然后用户在 `Plugins → Discover → Index sources` 添加该 URL 即可。
|
|
163
163
|
|
|
164
|
+
## 5.5 Trusted Publishing(GitHub OIDC,推荐用于后续发版)
|
|
165
|
+
|
|
166
|
+
首次发布(0.6.0)为手动完成;**Trusted Publishing 已配置并验证通过**(0.6.1 起由
|
|
167
|
+
GitHub Actions OIDC 发布,带 provenance)。工作流里**没有任何 npm token**,npm 会用
|
|
168
|
+
OIDC 换一个短期的发布凭证。
|
|
169
|
+
|
|
170
|
+
仓库里已带 [`.github/workflows/publish.yml`](../.github/workflows/publish.yml):
|
|
171
|
+
`release: published` 或手动 `workflow_dispatch` 触发,`permissions.id-token: write`,
|
|
172
|
+
跑测试后执行 `npm publish --provenance`,没有 `NODE_AUTH_TOKEN`。
|
|
173
|
+
|
|
174
|
+
在 npm 侧一次性配置:
|
|
175
|
+
|
|
176
|
+
1. 打开 <https://www.npmjs.com/package/dsh-timeback/access>(或包页面 → Settings →
|
|
177
|
+
**Trusted Publishers**)
|
|
178
|
+
2. **Add publisher** → 选 **GitHub Actions**
|
|
179
|
+
3. 填:
|
|
180
|
+
- Organization or user: `ppmchen`
|
|
181
|
+
- Repository: `dsh-timeback`
|
|
182
|
+
- Workflow filename: `publish.yml`(只写文件名,不带路径)
|
|
183
|
+
- Environment: `npm`(与 workflow 里的 `environment: npm` 一致;不设环境名也可以,但两边必须一致)
|
|
184
|
+
4. 保存时按提示完成 2FA(你的安全密钥)
|
|
185
|
+
|
|
186
|
+
之后每次发版:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
# 1) 同步版本:package.json version 与 client.js BUILD(如 0.6.2 / '0.6.2+xxx')
|
|
190
|
+
node --test test/*.test.js
|
|
191
|
+
git add -A && git commit -m "release: 0.6.2"
|
|
192
|
+
git push
|
|
193
|
+
|
|
194
|
+
# 2) 打 tag 并推送;push tag 会直接触发 publish workflow
|
|
195
|
+
git tag v0.6.2 && git push origin v0.6.2
|
|
196
|
+
|
|
197
|
+
# 3) workflow 自动校验 tag、跑测试并 npm publish --provenance
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
也可以从 GitHub Actions 手动触发 `publish`(workflow_dispatch),或在 npm 侧用
|
|
201
|
+
`npm stage publish` 先暂存、再人工 2FA 审批。
|
|
202
|
+
|
|
203
|
+
可在 npm 包页面看到 **Provenance** 徽章;安装侧可用 `npm audit signatures` 验证签名。
|
|
204
|
+
|
|
205
|
+
注意:同一个版本号不能重复发布;发布前务必先 bump 版本。首次配置 Trusted Publisher 后,
|
|
206
|
+
建议把旧的发布 token(如果有)在 npm → Access Tokens 里撤销。
|
|
207
|
+
|
|
164
208
|
## 6. 发布前检查清单
|
|
165
209
|
|
|
166
210
|
- [ ] `node --test test/*.test.js` 全绿(当前 40 个)
|
package/index.js
CHANGED
|
@@ -30,7 +30,7 @@ const JSON_HEADERS = {
|
|
|
30
30
|
'cache-control': 'no-store',
|
|
31
31
|
'x-content-type-options': 'nosniff',
|
|
32
32
|
}
|
|
33
|
-
const BODY_LIMIT =
|
|
33
|
+
const BODY_LIMIT = 2 * 1024 * 1024
|
|
34
34
|
const RENDER_LIMIT = 12_000
|
|
35
35
|
|
|
36
36
|
/** Plugin package version, used by the browser half to detect a stale bundle. */
|
|
@@ -290,6 +290,7 @@ export function apply(ctx, rawConfig) {
|
|
|
290
290
|
'note-save',
|
|
291
291
|
'note-delete',
|
|
292
292
|
'card-note',
|
|
293
|
+
'board-canvas',
|
|
293
294
|
])
|
|
294
295
|
const handler = async (req, res) => {
|
|
295
296
|
try {
|
|
@@ -367,6 +368,10 @@ export function apply(ctx, rawConfig) {
|
|
|
367
368
|
)
|
|
368
369
|
return
|
|
369
370
|
}
|
|
371
|
+
if (action === 'board-canvas') {
|
|
372
|
+
writeJson(res, 200, await service.saveBoardCanvas(body.canvas ?? {}), req)
|
|
373
|
+
return
|
|
374
|
+
}
|
|
370
375
|
if (action === 'notes-list') {
|
|
371
376
|
writeJson(res, 200, { ok: true, board: await service.board() }, req)
|
|
372
377
|
return
|
package/package.json
CHANGED
package/src/notes.js
CHANGED
|
@@ -46,12 +46,73 @@ function normalizeEntry(input, now) {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
/** One empty sticky-note board canvas. */
|
|
50
|
+
function emptyCanvas() {
|
|
51
|
+
return { notes: {}, background: [], drawings: {} }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const STROKE_COLORS = /^#[0-9a-f]{3,8}$/i
|
|
55
|
+
const MAX_STROKES = 120
|
|
56
|
+
const MAX_POINTS = 800
|
|
57
|
+
|
|
58
|
+
/** Clamp one stroke list to the stored shape. */
|
|
59
|
+
function normalizeStrokes(list) {
|
|
60
|
+
if (!Array.isArray(list)) return []
|
|
61
|
+
const strokes = []
|
|
62
|
+
for (const raw of list.slice(0, MAX_STROKES)) {
|
|
63
|
+
if (raw === null || typeof raw !== 'object' || !Array.isArray(raw.points)) continue
|
|
64
|
+
const points = raw.points
|
|
65
|
+
.filter((point) => Array.isArray(point) && point.length >= 2)
|
|
66
|
+
.map((point) => [Math.round(Number(point[0]) || 0), Math.round(Number(point[1]) || 0)])
|
|
67
|
+
.slice(0, MAX_POINTS)
|
|
68
|
+
if (points.length < 2) continue
|
|
69
|
+
strokes.push({
|
|
70
|
+
color: STROKE_COLORS.test(String(raw.color || '')) ? String(raw.color) : '#e6b84c',
|
|
71
|
+
width: Math.min(8, Math.max(1, Number(raw.width) || 2)),
|
|
72
|
+
points,
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
return strokes
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Clamp the sticky-note canvas (layout + drawings) to the stored shape. */
|
|
79
|
+
function normalizeCanvas(value) {
|
|
80
|
+
const canvas = value && typeof value === 'object' ? value : {}
|
|
81
|
+
const notes = {}
|
|
82
|
+
if (canvas.notes && typeof canvas.notes === 'object') {
|
|
83
|
+
for (const [id, layout] of Object.entries(canvas.notes)) {
|
|
84
|
+
if (typeof id !== 'string' || !layout || typeof layout !== 'object') continue
|
|
85
|
+
notes[id] = {
|
|
86
|
+
x: Math.round(Number(layout.x) || 0),
|
|
87
|
+
y: Math.round(Number(layout.y) || 0),
|
|
88
|
+
z: Math.round(Number(layout.z) || 0),
|
|
89
|
+
color: STROKE_COLORS.test(String(layout.color || '')) ? String(layout.color) : '#f0c36b',
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const drawings = {}
|
|
94
|
+
if (canvas.drawings && typeof canvas.drawings === 'object') {
|
|
95
|
+
for (const [id, strokes] of Object.entries(canvas.drawings)) {
|
|
96
|
+
const normalized = normalizeStrokes(strokes)
|
|
97
|
+
if (normalized.length > 0) drawings[id] = normalized
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return { notes, background: normalizeStrokes(canvas.background), drawings }
|
|
101
|
+
}
|
|
102
|
+
|
|
49
103
|
/** Clone one board state without sharing references. */
|
|
50
104
|
function cloneBoard(board) {
|
|
51
105
|
return {
|
|
52
106
|
version: board.version,
|
|
53
107
|
updatedAt: board.updatedAt,
|
|
54
108
|
entries: board.entries.map((entry) => ({ ...entry })),
|
|
109
|
+
canvas: {
|
|
110
|
+
notes: Object.fromEntries(Object.entries(board.canvas?.notes ?? {}).map(([id, layout]) => [id, { ...layout }])),
|
|
111
|
+
background: (board.canvas?.background ?? []).map((stroke) => ({ ...stroke, points: stroke.points.map((point) => [...point]) })),
|
|
112
|
+
drawings: Object.fromEntries(
|
|
113
|
+
Object.entries(board.canvas?.drawings ?? {}).map(([id, strokes]) => [id, strokes.map((stroke) => ({ ...stroke, points: stroke.points.map((point) => [...point]) }))]),
|
|
114
|
+
),
|
|
115
|
+
},
|
|
55
116
|
}
|
|
56
117
|
}
|
|
57
118
|
|
|
@@ -96,6 +157,7 @@ export class NotesStore {
|
|
|
96
157
|
version: Number.isSafeInteger(loaded?.version) && loaded.version >= 0 ? loaded.version : 0,
|
|
97
158
|
updatedAt: Number.isFinite(loaded?.updatedAt) ? loaded.updatedAt : now,
|
|
98
159
|
entries,
|
|
160
|
+
canvas: normalizeCanvas(loaded?.canvas),
|
|
99
161
|
}
|
|
100
162
|
return this
|
|
101
163
|
})().finally(() => {
|
|
@@ -167,11 +229,34 @@ export class NotesStore {
|
|
|
167
229
|
const index = draft.entries.findIndex((candidate) => candidate.id === id)
|
|
168
230
|
if (index === -1) throw new NotesError('记录不存在或已删除', 'notes/not-found')
|
|
169
231
|
const [entry] = draft.entries.splice(index, 1)
|
|
232
|
+
delete draft.canvas.notes[entry.id]
|
|
233
|
+
delete draft.canvas.drawings[entry.id]
|
|
170
234
|
return { entry }
|
|
171
235
|
}, '删除记录')
|
|
172
236
|
return { entry: outcome.result.entry, board: outcome.board }
|
|
173
237
|
}
|
|
174
238
|
|
|
239
|
+
/**
|
|
240
|
+
* Persist the sticky-note canvas (positions, background drawings and per-note
|
|
241
|
+
* drawings). Layout/drawing changes are board revisions too, so a rewind
|
|
242
|
+
* restores the visual board along with the Markdown notes.
|
|
243
|
+
*/
|
|
244
|
+
async updateCanvas(value) {
|
|
245
|
+
const outcome = await this.mutate((draft) => {
|
|
246
|
+
draft.canvas = normalizeCanvas(value)
|
|
247
|
+
// Keep only drawings for notes that still exist.
|
|
248
|
+
const ids = new Set(draft.entries.map((entry) => entry.id))
|
|
249
|
+
for (const id of Object.keys(draft.canvas.drawings)) {
|
|
250
|
+
if (!ids.has(id)) delete draft.canvas.drawings[id]
|
|
251
|
+
}
|
|
252
|
+
for (const id of Object.keys(draft.canvas.notes)) {
|
|
253
|
+
if (!ids.has(id)) delete draft.canvas.notes[id]
|
|
254
|
+
}
|
|
255
|
+
return { canvas: draft.canvas }
|
|
256
|
+
}, '更新便签板')
|
|
257
|
+
return { board: outcome.board }
|
|
258
|
+
}
|
|
259
|
+
|
|
175
260
|
/**
|
|
176
261
|
* Restore the board to one version. The restore itself becomes a new version,
|
|
177
262
|
* so later rewinds can still point at older snapshots and the monotonic
|
|
@@ -183,7 +268,7 @@ export class NotesStore {
|
|
|
183
268
|
if (!Number.isSafeInteger(version) || version < 0) return null
|
|
184
269
|
// Version 0 is the empty board a profile starts with; its snapshot is
|
|
185
270
|
// implicit because the file is only written on the first mutation.
|
|
186
|
-
let snapshot = { entries: [] }
|
|
271
|
+
let snapshot = { entries: [], canvas: emptyCanvas() }
|
|
187
272
|
if (version > 0) {
|
|
188
273
|
try {
|
|
189
274
|
snapshot = JSON.parse(await fs.readFile(path.join(this.historyDir, `${version}.json`), 'utf8'))
|
|
@@ -194,6 +279,7 @@ export class NotesStore {
|
|
|
194
279
|
if (!Array.isArray(snapshot?.entries)) return null
|
|
195
280
|
const outcome = await this.mutate((draft) => {
|
|
196
281
|
draft.entries = snapshot.entries.filter((entry) => entry && typeof entry === 'object').map((entry) => normalizeEntry(entry, this.now()))
|
|
282
|
+
draft.canvas = normalizeCanvas(snapshot.canvas)
|
|
197
283
|
return { restoredFrom: version }
|
|
198
284
|
}, '回溯记录板')
|
|
199
285
|
return { restoredFrom: version, version: outcome.board.version, entries: outcome.board.entries.length }
|
package/src/service.js
CHANGED
|
@@ -776,6 +776,13 @@ export class TimebackService {
|
|
|
776
776
|
}
|
|
777
777
|
}
|
|
778
778
|
|
|
779
|
+
/** Persist the sticky-note canvas (layout, background strokes, per-note strokes). */
|
|
780
|
+
async saveBoardCanvas(canvas) {
|
|
781
|
+
await this.start()
|
|
782
|
+
if (!this.notes) throw new TimebackError('记录板存储不可用', 'timeback/notes-unavailable')
|
|
783
|
+
return { ok: true, ...(await this.notes.updateCanvas(canvas ?? {})) }
|
|
784
|
+
}
|
|
785
|
+
|
|
779
786
|
/** Delete one board note. */
|
|
780
787
|
async deleteBoardNote(id) {
|
|
781
788
|
await this.start()
|