dsh-matrix-todo 1.0.0 → 1.1.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/index.js CHANGED
@@ -63,6 +63,7 @@ function refusalOf(ctx, req) {
63
63
 
64
64
  const ACTIONS = {
65
65
  list: (store) => store.list(),
66
+ seed: (store, body) => store.seed(body),
66
67
  create: (store, body) => store.create(body),
67
68
  update: (store, body) => store.update(body),
68
69
  toggle: (store, body) => store.toggle(body),
@@ -73,7 +74,7 @@ const ACTIONS = {
73
74
 
74
75
  /** Every response carries the full list plus the layout preferences. */
75
76
  function resultOf(store) {
76
- return { todos: store.list(), settings: store.settings() }
77
+ return { todos: store.list(), settings: store.settings(), seeded: store.seeded() }
77
78
  }
78
79
 
79
80
  export function apply(ctx, config = {}) {
package/lib/store.js CHANGED
@@ -57,7 +57,7 @@ export class StoreError extends Error {
57
57
  }
58
58
 
59
59
  function emptyDoc() {
60
- return { version: VERSION, todos: [], settings: { ...DEFAULT_SETTINGS }, reordered: false }
60
+ return { version: VERSION, todos: [], settings: { ...DEFAULT_SETTINGS }, reordered: false, seeded: false }
61
61
  }
62
62
 
63
63
  const DAY_RE = /^\d{4}-\d{2}-\d{2}$/
@@ -197,7 +197,7 @@ function corruptBackupPath(file) {
197
197
  export function createStore({ file } = {}) {
198
198
  if (typeof file !== 'string' || file === '') throw new StoreError('invalid-input', '数据文件路径必填')
199
199
  const dataFile = file
200
- const state = { todos: [], settings: { ...DEFAULT_SETTINGS }, reordered: false, corrupt: false, sealed: false }
200
+ const state = { todos: [], settings: { ...DEFAULT_SETTINGS }, reordered: false, seeded: false, corrupt: false, sealed: false }
201
201
  let queue = Promise.resolve()
202
202
  let closed = false
203
203
 
@@ -209,7 +209,7 @@ export function createStore({ file } = {}) {
209
209
  async function persist() {
210
210
  if (state.sealed) throw new StoreError('io-error', CORRUPT_UNBACKUPED)
211
211
  const snapshotText = JSON.stringify(
212
- { version: VERSION, todos: state.todos, settings: state.settings, reordered: state.reordered },
212
+ { version: VERSION, todos: state.todos, settings: state.settings, reordered: state.reordered, seeded: state.seeded },
213
213
  null,
214
214
  2,
215
215
  )
@@ -243,6 +243,9 @@ export function createStore({ file } = {}) {
243
243
  state.todos = sanitizeTodos(doc.todos)
244
244
  state.settings = sanitizeSettings(doc.settings)
245
245
  state.reordered = doc.reordered === true
246
+ // A store that already holds rows, or one that was seeded before, never
247
+ // gets onboarding rows again — deleting the guide must stick.
248
+ state.seeded = corrupt || doc.seeded === true || state.todos.length > 0
246
249
  // Until someone drags a row, the list order is derived: newest first. Once
247
250
  // a drag is saved, the stored array order is the user's own order.
248
251
  if (!state.reordered) state.todos.sort((a, b) => String(b.createdAt).localeCompare(String(a.createdAt)))
@@ -270,6 +273,45 @@ export function createStore({ file } = {}) {
270
273
  return snapshot()
271
274
  },
272
275
 
276
+ /** True once onboarding rows were written, or when the store was never empty. */
277
+ seeded() {
278
+ return state.seeded
279
+ },
280
+
281
+ /**
282
+ * One-time onboarding rows for a brand-new store. The client sends localized
283
+ * titles; the flag makes the call idempotent and stops the guide from coming
284
+ * back after the user deletes it.
285
+ */
286
+ async seed(input = {}) {
287
+ if (state.seeded) return { added: 0 }
288
+ const source = asRecord(input)
289
+ const rows = Array.isArray(source.items) ? source.items.slice(0, 32) : []
290
+ const now = Date.now()
291
+ const added = []
292
+ rows.forEach((raw, index) => {
293
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return
294
+ const title = typeof raw.title === 'string' ? raw.title.trim() : ''
295
+ if (title === '' || title.length > TITLE_MAX) return
296
+ const createdAt = new Date(now - index * 1000).toISOString()
297
+ added.push({
298
+ id: newId(),
299
+ title,
300
+ important: raw.important === true,
301
+ urgent: raw.urgent === true,
302
+ done: false,
303
+ dueDate: sanitizeDueDate(raw.dueDate),
304
+ createdAt,
305
+ updatedAt: createdAt,
306
+ completedAt: null,
307
+ })
308
+ })
309
+ state.seeded = true
310
+ if (added.length > 0) state.todos = [...added, ...state.todos]
311
+ await guard(persist)
312
+ return { added: added.length }
313
+ },
314
+
273
315
  /** Current layout preferences (a copy; callers cannot mutate the source of truth). */
274
316
  settings() {
275
317
  return { ...state.settings }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-matrix-todo",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "description": "Eisenhower-matrix to-do list for DeepSeek Harness: four importance/urgency quadrants, drag sorting, due dates, completed view and minimal theme-aware styling.",
6
6
  "license": "MIT",
@@ -46,4 +46,4 @@
46
46
  ]
47
47
  }
48
48
  }
49
- }
49
+ }