dsh-timeback 0.6.1 → 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 +24 -18
- package/client.js +432 -36
- package/docs/MARKET.md +2 -2
- package/docs/PUBLISHING.md +11 -8
- 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
|
@@ -103,7 +103,7 @@ desktop app):
|
|
|
103
103
|
```bash
|
|
104
104
|
# From npm (published: https://www.npmjs.com/package/dsh-timeback)
|
|
105
105
|
dsh plugin --profile web add dsh-timeback
|
|
106
|
-
dsh plugin --profile web add dsh-timeback@0.
|
|
106
|
+
dsh plugin --profile web add dsh-timeback@0.7.0 # pin a release
|
|
107
107
|
|
|
108
108
|
# Straight from GitHub (no npm release needed)
|
|
109
109
|
dsh plugin --profile web add github:<owner>/dsh-timeback
|
|
@@ -168,22 +168,28 @@ workspace** under `<DSH_HOME>/timeback/repos/<hash>/`. The workspace's own `.git
|
|
|
168
168
|
commits and refs are never read or written. `node_modules/`, virtualenvs and
|
|
169
169
|
caches are excluded by default (configurable), keeping snapshots small and fast.
|
|
170
170
|
|
|
171
|
-
## Notes board (记录板)
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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/`.
|
|
187
193
|
|
|
188
194
|
## Using it
|
|
189
195
|
|
|
@@ -285,7 +291,7 @@ Session's working directory, then reload the plugin (config changes remount it).
|
|
|
285
291
|
|
|
286
292
|
## Verification status
|
|
287
293
|
|
|
288
|
-
- Host + client tests (
|
|
294
|
+
- Host + client tests (49 cases, `npm test`) cover snapshot/restore semantics
|
|
289
295
|
(add/edit/delete/symlink/mode, delete-extra policy, nested repositories,
|
|
290
296
|
file↔directory collisions, refusal to delete untracked content blocking a
|
|
291
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': '删除',
|
|
@@ -274,6 +286,18 @@ window.__ModuleLoader__.load({
|
|
|
274
286
|
'note.removed': 'Card note deleted',
|
|
275
287
|
'board.title': 'Notes board',
|
|
276
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',
|
|
277
301
|
'board.new': 'New note',
|
|
278
302
|
'board.edit': 'Edit',
|
|
279
303
|
'board.delete': 'Delete',
|
|
@@ -493,6 +517,36 @@ window.__ModuleLoader__.load({
|
|
|
493
517
|
.tb-resize-handle.se{right:0;bottom:0;width:18px;height:18px;cursor:nwse-resize}
|
|
494
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}
|
|
495
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}
|
|
496
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)}
|
|
497
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}
|
|
498
552
|
.tb-board-title{font-weight:600;font-size:13.5px}
|
|
@@ -2700,6 +2754,62 @@ window.__ModuleLoader__.load({
|
|
|
2700
2754
|
/* global notes board page */
|
|
2701
2755
|
/* ---------------------------------------------------------------- */
|
|
2702
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
|
+
|
|
2703
2813
|
function BoardPanel(props) {
|
|
2704
2814
|
const t = typeof props?.t === 'function' ? props.t : (key) => key
|
|
2705
2815
|
const [state, setState] = React.useState({ loading: true, board: null, error: null })
|
|
@@ -2720,11 +2830,32 @@ window.__ModuleLoader__.load({
|
|
|
2720
2830
|
})
|
|
2721
2831
|
const dialogSizeRef = React.useRef(dialogSize)
|
|
2722
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)
|
|
2723
2848
|
|
|
2724
2849
|
const refresh = React.useCallback(async () => {
|
|
2725
2850
|
try {
|
|
2726
2851
|
const body = await request('notes')
|
|
2727
|
-
|
|
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
|
+
}
|
|
2728
2859
|
} catch (error) {
|
|
2729
2860
|
setState((previous) => ({ ...previous, loading: false, error: error?.message || String(error) }))
|
|
2730
2861
|
}
|
|
@@ -2739,6 +2870,26 @@ window.__ModuleLoader__.load({
|
|
|
2739
2870
|
return () => window.removeEventListener('dsh-timeback:board-changed', handler)
|
|
2740
2871
|
}, [refresh])
|
|
2741
2872
|
|
|
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
|
+
|
|
2742
2893
|
const persistDialogSize = (value) => {
|
|
2743
2894
|
try {
|
|
2744
2895
|
window.localStorage.setItem('dsh-timeback:board-dialog-size', JSON.stringify(value))
|
|
@@ -2784,13 +2935,23 @@ window.__ModuleLoader__.load({
|
|
|
2784
2935
|
window.addEventListener('pointercancel', finish)
|
|
2785
2936
|
}
|
|
2786
2937
|
|
|
2787
|
-
const entries =
|
|
2938
|
+
const entries = state.board?.entries ?? []
|
|
2939
|
+
const sortedEntries = [...entries].sort((left, right) => (right.updatedAt ?? 0) - (left.updatedAt ?? 0))
|
|
2788
2940
|
const boardVersion = state.board?.version ?? 0
|
|
2941
|
+
const layoutFor = (entry, index) => canvas.notes[entry.id] ?? autoBoardLayout(index)
|
|
2789
2942
|
const startCreate = () => setDraft({ id: '', title: '', body: '', preview: false, busy: false, error: null })
|
|
2790
2943
|
const startEdit = (entry) => setDraft({ id: entry.id, title: entry.title, body: entry.body, preview: false, busy: false, error: null })
|
|
2791
2944
|
const closeDraft = () => {
|
|
2792
2945
|
if (draft && !draft.busy) setDraft(null)
|
|
2793
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
|
+
}
|
|
2794
2955
|
const saveDraft = async () => {
|
|
2795
2956
|
if (!draft || draft.busy) return
|
|
2796
2957
|
setDraft({ ...draft, busy: true, error: null })
|
|
@@ -2799,8 +2960,17 @@ window.__ModuleLoader__.load({
|
|
|
2799
2960
|
method: 'POST',
|
|
2800
2961
|
body: { action: 'note-save', ...(draft.id ? { id: draft.id } : {}), title: draft.title, body: draft.body },
|
|
2801
2962
|
})
|
|
2963
|
+
const board = body.board ?? state.board
|
|
2802
2964
|
setDraft(null)
|
|
2803
|
-
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
|
+
}
|
|
2804
2974
|
} catch (error) {
|
|
2805
2975
|
setDraft({ ...draft, busy: false, error: error?.message || String(error) })
|
|
2806
2976
|
}
|
|
@@ -2818,6 +2988,10 @@ window.__ModuleLoader__.load({
|
|
|
2818
2988
|
try {
|
|
2819
2989
|
const body = await request('action', { method: 'POST', body: { action: 'note-delete', id } })
|
|
2820
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)
|
|
2821
2995
|
} catch (error) {
|
|
2822
2996
|
setState((previous) => ({ ...previous, error: error?.message || String(error) }))
|
|
2823
2997
|
} finally {
|
|
@@ -2825,6 +2999,222 @@ window.__ModuleLoader__.load({
|
|
|
2825
2999
|
}
|
|
2826
3000
|
}
|
|
2827
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
|
+
|
|
2828
3218
|
return h(
|
|
2829
3219
|
'div',
|
|
2830
3220
|
{ className: 'tb-board-panel' },
|
|
@@ -2835,46 +3225,52 @@ window.__ModuleLoader__.load({
|
|
|
2835
3225
|
h('span', { className: 'tb-board-sub' }, t('board.subtitle')),
|
|
2836
3226
|
h('span', { style: { flex: 1 } }),
|
|
2837
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 })),
|
|
2838
3229
|
h('button', { type: 'button', className: 'tb-btn', disabled: state.loading, onClick: refresh }, t('board.refresh')),
|
|
2839
|
-
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')}`),
|
|
2840
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,
|
|
2841
3235
|
h(
|
|
2842
3236
|
'div',
|
|
2843
|
-
{ className:
|
|
2844
|
-
h(
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
{ className: `tb-chip ${entry.source === 'agent' ? 'ok' : ''}` },
|
|
2861
|
-
entry.source === 'agent' ? t('board.sourceAgent') : t('board.sourceUser'),
|
|
2862
|
-
),
|
|
2863
|
-
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) =>
|
|
2864
3254
|
h(
|
|
2865
|
-
'
|
|
2866
|
-
{ className:
|
|
2867
|
-
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' : ''}` },
|
|
2868
3257
|
h(
|
|
2869
|
-
'
|
|
2870
|
-
{
|
|
2871
|
-
|
|
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
|
+
),
|
|
2872
3270
|
),
|
|
3271
|
+
entry.body ? h('div', { className: 'tb-md' }, ...renderMarkdown(entry.body, `md-${entry.id}`)) : null,
|
|
2873
3272
|
),
|
|
2874
3273
|
),
|
|
2875
|
-
entry.body ? h('div', { className: 'tb-md' }, ...renderMarkdown(entry.body, `board-${entry.id}`)) : null,
|
|
2876
|
-
),
|
|
2877
|
-
),
|
|
2878
3274
|
),
|
|
2879
3275
|
draft
|
|
2880
3276
|
? h(
|
|
@@ -2892,7 +3288,7 @@ window.__ModuleLoader__.load({
|
|
|
2892
3288
|
h(
|
|
2893
3289
|
'div',
|
|
2894
3290
|
{ className: 'tb-detail-head' },
|
|
2895
|
-
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')),
|
|
2896
3292
|
h('span', { style: { flex: 1 } }),
|
|
2897
3293
|
h(
|
|
2898
3294
|
'button',
|
package/docs/MARKET.md
CHANGED
|
@@ -78,12 +78,12 @@ dshmarket;要让所有人的 dshmarket 搜到,必须走下一节的公共目
|
|
|
78
78
|
|
|
79
79
|
## 4. npm(已发布 0.6.0)
|
|
80
80
|
|
|
81
|
-
`dsh-timeback@0.
|
|
81
|
+
`dsh-timeback@0.7.0` 已发布到官方 npm(<https://www.npmjs.com/package/dsh-timeback>),
|
|
82
82
|
用户可以直接安装/固定版本:
|
|
83
83
|
|
|
84
84
|
```bash
|
|
85
85
|
dsh plugin --profile web add dsh-timeback
|
|
86
|
-
dsh plugin --profile web add dsh-timeback@0.
|
|
86
|
+
dsh plugin --profile web add dsh-timeback@0.7.0
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
awesome 目录 CI 会从 npm 自动补充映射,之后市场安装和更新会走 registry。发布流程参考:
|
package/docs/PUBLISHING.md
CHANGED
|
@@ -163,8 +163,9 @@ DSH 没有官方中央商店;Discover 读取的是 format-1 JSON 索引,实
|
|
|
163
163
|
|
|
164
164
|
## 5.5 Trusted Publishing(GitHub OIDC,推荐用于后续发版)
|
|
165
165
|
|
|
166
|
-
首次发布(0.6.0
|
|
167
|
-
|
|
166
|
+
首次发布(0.6.0)为手动完成;**Trusted Publishing 已配置并验证通过**(0.6.1 起由
|
|
167
|
+
GitHub Actions OIDC 发布,带 provenance)。工作流里**没有任何 npm token**,npm 会用
|
|
168
|
+
OIDC 换一个短期的发布凭证。
|
|
168
169
|
|
|
169
170
|
仓库里已带 [`.github/workflows/publish.yml`](../.github/workflows/publish.yml):
|
|
170
171
|
`release: published` 或手动 `workflow_dispatch` 触发,`permissions.id-token: write`,
|
|
@@ -185,18 +186,20 @@ DSH 没有官方中央商店;Discover 读取的是 format-1 JSON 索引,实
|
|
|
185
186
|
之后每次发版:
|
|
186
187
|
|
|
187
188
|
```bash
|
|
188
|
-
# 1) 同步版本:package.json version 与 client.js BUILD(如 0.6.
|
|
189
|
+
# 1) 同步版本:package.json version 与 client.js BUILD(如 0.6.2 / '0.6.2+xxx')
|
|
189
190
|
node --test test/*.test.js
|
|
190
|
-
git add -A && git commit -m "release: 0.6.
|
|
191
|
+
git add -A && git commit -m "release: 0.6.2"
|
|
191
192
|
git push
|
|
192
193
|
|
|
193
|
-
# 2) 打 tag
|
|
194
|
-
git tag v0.6.
|
|
195
|
-
# 在 GitHub → Releases → Draft a new release → 选择 v0.6.1 → Publish release
|
|
194
|
+
# 2) 打 tag 并推送;push tag 会直接触发 publish workflow
|
|
195
|
+
git tag v0.6.2 && git push origin v0.6.2
|
|
196
196
|
|
|
197
|
-
# 3) workflow
|
|
197
|
+
# 3) workflow 自动校验 tag、跑测试并 npm publish --provenance
|
|
198
198
|
```
|
|
199
199
|
|
|
200
|
+
也可以从 GitHub Actions 手动触发 `publish`(workflow_dispatch),或在 npm 侧用
|
|
201
|
+
`npm stage publish` 先暂存、再人工 2FA 审批。
|
|
202
|
+
|
|
200
203
|
可在 npm 包页面看到 **Provenance** 徽章;安装侧可用 `npm audit signatures` 验证签名。
|
|
201
204
|
|
|
202
205
|
注意:同一个版本号不能重复发布;发布前务必先 bump 版本。首次配置 Trusted Publisher 后,
|
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()
|