dsh-timeback 0.6.1 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -18
- package/client.js +1494 -35
- 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 +120 -1
- package/src/service.js +7 -0
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.1` 已发布到官方 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.1
|
|
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,104 @@ function normalizeEntry(input, now) {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
/** One empty sticky-note board canvas. */
|
|
50
|
+
const BOARD_ANCHORS = new Set(['top', 'right', 'bottom', 'left'])
|
|
51
|
+
const MAX_EDGES = 200
|
|
52
|
+
|
|
53
|
+
function emptyCanvas() {
|
|
54
|
+
return { notes: {}, background: [], drawings: {}, edges: [] }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Clamp note-to-note connector edges. */
|
|
58
|
+
function normalizeEdges(list) {
|
|
59
|
+
if (!Array.isArray(list)) return []
|
|
60
|
+
const edges = []
|
|
61
|
+
for (const raw of list.slice(0, MAX_EDGES)) {
|
|
62
|
+
if (raw === null || typeof raw !== 'object') continue
|
|
63
|
+
const from = raw.from
|
|
64
|
+
const to = raw.to
|
|
65
|
+
if (!from || !to || typeof from.noteId !== 'string' || typeof to.noteId !== 'string') continue
|
|
66
|
+
if (!BOARD_ANCHORS.has(from.anchor) || !BOARD_ANCHORS.has(to.anchor)) continue
|
|
67
|
+
if (from.noteId === to.noteId) continue
|
|
68
|
+
edges.push({
|
|
69
|
+
id: typeof raw.id === 'string' && raw.id !== '' ? raw.id : `eg-${Math.random().toString(36).slice(2, 10)}`,
|
|
70
|
+
from: { noteId: from.noteId, anchor: from.anchor },
|
|
71
|
+
to: { noteId: to.noteId, anchor: to.anchor },
|
|
72
|
+
color: STROKE_COLORS.test(String(raw.color || '')) ? String(raw.color) : '#7aa2ff',
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
return edges
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const STROKE_COLORS = /^#[0-9a-f]{3,8}$/i
|
|
79
|
+
const STROKE_KINDS = new Set(['pen', 'line', 'rect', 'ellipse', 'arrow', 'triangle'])
|
|
80
|
+
const MAX_STROKES = 120
|
|
81
|
+
const MAX_POINTS = 800
|
|
82
|
+
|
|
83
|
+
/** Clamp one stroke list to the stored shape. */
|
|
84
|
+
function normalizeStrokes(list) {
|
|
85
|
+
if (!Array.isArray(list)) return []
|
|
86
|
+
const strokes = []
|
|
87
|
+
for (const raw of list.slice(0, MAX_STROKES)) {
|
|
88
|
+
if (raw === null || typeof raw !== 'object' || !Array.isArray(raw.points)) continue
|
|
89
|
+
const kind = STROKE_KINDS.has(raw.kind) ? raw.kind : 'pen'
|
|
90
|
+
let points = raw.points
|
|
91
|
+
.filter((point) => Array.isArray(point) && point.length >= 2)
|
|
92
|
+
.map((point) => [Math.round(Number(point[0]) || 0), Math.round(Number(point[1]) || 0)])
|
|
93
|
+
.slice(0, MAX_POINTS)
|
|
94
|
+
if (kind !== 'pen') points = points.slice(0, 2)
|
|
95
|
+
if (points.length < 2) continue
|
|
96
|
+
strokes.push({
|
|
97
|
+
kind,
|
|
98
|
+
color: STROKE_COLORS.test(String(raw.color || '')) ? String(raw.color) : '#e6b84c',
|
|
99
|
+
width: Math.min(8, Math.max(1, Number(raw.width) || 2)),
|
|
100
|
+
points,
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
return strokes
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Clamp the sticky-note canvas (layout + drawings) to the stored shape. */
|
|
107
|
+
function normalizeCanvas(value) {
|
|
108
|
+
const canvas = value && typeof value === 'object' ? value : {}
|
|
109
|
+
const notes = {}
|
|
110
|
+
if (canvas.notes && typeof canvas.notes === 'object') {
|
|
111
|
+
for (const [id, layout] of Object.entries(canvas.notes)) {
|
|
112
|
+
if (typeof id !== 'string' || !layout || typeof layout !== 'object') continue
|
|
113
|
+
notes[id] = {
|
|
114
|
+
x: Math.round(Number(layout.x) || 0),
|
|
115
|
+
y: Math.round(Number(layout.y) || 0),
|
|
116
|
+
width: Math.min(640, Math.max(160, Math.round(Number(layout.width) || 232))),
|
|
117
|
+
height: Math.min(560, Math.max(120, Math.round(Number(layout.height) || 176))),
|
|
118
|
+
z: Math.round(Number(layout.z) || 0),
|
|
119
|
+
color: STROKE_COLORS.test(String(layout.color || '')) ? String(layout.color) : '#f0c36b',
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const drawings = {}
|
|
124
|
+
if (canvas.drawings && typeof canvas.drawings === 'object') {
|
|
125
|
+
for (const [id, strokes] of Object.entries(canvas.drawings)) {
|
|
126
|
+
const normalized = normalizeStrokes(strokes)
|
|
127
|
+
if (normalized.length > 0) drawings[id] = normalized
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return { notes, background: normalizeStrokes(canvas.background), drawings, edges: normalizeEdges(canvas.edges) }
|
|
131
|
+
}
|
|
132
|
+
|
|
49
133
|
/** Clone one board state without sharing references. */
|
|
50
134
|
function cloneBoard(board) {
|
|
51
135
|
return {
|
|
52
136
|
version: board.version,
|
|
53
137
|
updatedAt: board.updatedAt,
|
|
54
138
|
entries: board.entries.map((entry) => ({ ...entry })),
|
|
139
|
+
canvas: {
|
|
140
|
+
notes: Object.fromEntries(Object.entries(board.canvas?.notes ?? {}).map(([id, layout]) => [id, { ...layout }])),
|
|
141
|
+
background: (board.canvas?.background ?? []).map((stroke) => ({ ...stroke, points: stroke.points.map((point) => [...point]) })),
|
|
142
|
+
drawings: Object.fromEntries(
|
|
143
|
+
Object.entries(board.canvas?.drawings ?? {}).map(([id, strokes]) => [id, strokes.map((stroke) => ({ ...stroke, points: stroke.points.map((point) => [...point]) }))]),
|
|
144
|
+
),
|
|
145
|
+
edges: (board.canvas?.edges ?? []).map((edge) => ({ ...edge, from: { ...edge.from }, to: { ...edge.to } })),
|
|
146
|
+
},
|
|
55
147
|
}
|
|
56
148
|
}
|
|
57
149
|
|
|
@@ -96,6 +188,7 @@ export class NotesStore {
|
|
|
96
188
|
version: Number.isSafeInteger(loaded?.version) && loaded.version >= 0 ? loaded.version : 0,
|
|
97
189
|
updatedAt: Number.isFinite(loaded?.updatedAt) ? loaded.updatedAt : now,
|
|
98
190
|
entries,
|
|
191
|
+
canvas: normalizeCanvas(loaded?.canvas),
|
|
99
192
|
}
|
|
100
193
|
return this
|
|
101
194
|
})().finally(() => {
|
|
@@ -167,11 +260,36 @@ export class NotesStore {
|
|
|
167
260
|
const index = draft.entries.findIndex((candidate) => candidate.id === id)
|
|
168
261
|
if (index === -1) throw new NotesError('记录不存在或已删除', 'notes/not-found')
|
|
169
262
|
const [entry] = draft.entries.splice(index, 1)
|
|
263
|
+
delete draft.canvas.notes[entry.id]
|
|
264
|
+
delete draft.canvas.drawings[entry.id]
|
|
265
|
+
draft.canvas.edges = draft.canvas.edges.filter((edge) => edge.from.noteId !== entry.id && edge.to.noteId !== entry.id)
|
|
170
266
|
return { entry }
|
|
171
267
|
}, '删除记录')
|
|
172
268
|
return { entry: outcome.result.entry, board: outcome.board }
|
|
173
269
|
}
|
|
174
270
|
|
|
271
|
+
/**
|
|
272
|
+
* Persist the sticky-note canvas (positions, background drawings and per-note
|
|
273
|
+
* drawings). Layout/drawing changes are board revisions too, so a rewind
|
|
274
|
+
* restores the visual board along with the Markdown notes.
|
|
275
|
+
*/
|
|
276
|
+
async updateCanvas(value) {
|
|
277
|
+
const outcome = await this.mutate((draft) => {
|
|
278
|
+
draft.canvas = normalizeCanvas(value)
|
|
279
|
+
// Keep only drawings for notes that still exist.
|
|
280
|
+
const ids = new Set(draft.entries.map((entry) => entry.id))
|
|
281
|
+
for (const id of Object.keys(draft.canvas.drawings)) {
|
|
282
|
+
if (!ids.has(id)) delete draft.canvas.drawings[id]
|
|
283
|
+
}
|
|
284
|
+
for (const id of Object.keys(draft.canvas.notes)) {
|
|
285
|
+
if (!ids.has(id)) delete draft.canvas.notes[id]
|
|
286
|
+
}
|
|
287
|
+
draft.canvas.edges = draft.canvas.edges.filter((edge) => ids.has(edge.from.noteId) && ids.has(edge.to.noteId))
|
|
288
|
+
return { canvas: draft.canvas }
|
|
289
|
+
}, '更新便签板')
|
|
290
|
+
return { board: outcome.board }
|
|
291
|
+
}
|
|
292
|
+
|
|
175
293
|
/**
|
|
176
294
|
* Restore the board to one version. The restore itself becomes a new version,
|
|
177
295
|
* so later rewinds can still point at older snapshots and the monotonic
|
|
@@ -183,7 +301,7 @@ export class NotesStore {
|
|
|
183
301
|
if (!Number.isSafeInteger(version) || version < 0) return null
|
|
184
302
|
// Version 0 is the empty board a profile starts with; its snapshot is
|
|
185
303
|
// implicit because the file is only written on the first mutation.
|
|
186
|
-
let snapshot = { entries: [] }
|
|
304
|
+
let snapshot = { entries: [], canvas: emptyCanvas() }
|
|
187
305
|
if (version > 0) {
|
|
188
306
|
try {
|
|
189
307
|
snapshot = JSON.parse(await fs.readFile(path.join(this.historyDir, `${version}.json`), 'utf8'))
|
|
@@ -194,6 +312,7 @@ export class NotesStore {
|
|
|
194
312
|
if (!Array.isArray(snapshot?.entries)) return null
|
|
195
313
|
const outcome = await this.mutate((draft) => {
|
|
196
314
|
draft.entries = snapshot.entries.filter((entry) => entry && typeof entry === 'object').map((entry) => normalizeEntry(entry, this.now()))
|
|
315
|
+
draft.canvas = normalizeCanvas(snapshot.canvas)
|
|
197
316
|
return { restoredFrom: version }
|
|
198
317
|
}, '回溯记录板')
|
|
199
318
|
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()
|