Harden note-local frontmatter value editing and write semantics #65

Closed
opened 2026-05-21 13:29:34 +00:00 by steve · 0 comments
Owner

Make frontmatter value edits predictable and durable for all built-in property
widgets, and consolidate the duplicated note-local write path used by markdown
frontmatter surfaces.

Context

Audit findings from the current implementation:

  • file-frontmatter.svelte and file-properties.svelte duplicate the same
    processFrontMatter + lodash set/unset behavior.
  • Built-in widgets are imperative DOM renderers in widgets.ts; they update only
    on blur in most cases, so checkbox/date/number/text changes can be lost when
    focus is moved by a menu, a view switch, or editor remount.
  • Boolean, empty string, numeric, date, datetime, and unknown values have no
    focused regression tests for conversion, clearing, or YAML serialization.
  • processFrontMatter() is solid for the cache-missing case but has limited
    coverage for notes with no frontmatter block, empty frontmatter, parse errors,
    concurrent edits, or avoiding no-op writes.
  • UI callers do not surface write failures, so YAML or vault errors can appear as
    silent instability.

Acceptance Criteria

  • The markdown plugin exposes one note-local frontmatter mutation helper for add,
    update, clear, and nested path writes, reused by live-preview frontmatter and
    the file properties side view.
  • Built-in widgets commit at predictable interaction points; checkbox-style
    values update on change, and text-like values do not lose edits when menus or
    view transitions move focus.
  • Empty values, false, 0, empty arrays, and null/undefined removal have
    explicit behavior and tests.
  • FileManager.processFrontMatter() coverage includes adding a first
    frontmatter block, editing an existing block, preserving unrelated keys,
    handling parser/write failures, and suppressing unnecessary writes where
    practical.
  • Write failures are surfaced through the existing app notification/error path
    rather than silently failing.

Notes

Relevant files:

  • packages/api/src/lib/file-manager.ts
  • packages/api/src/lib/__tests__/file-manager.test.ts
  • packages/plugins/plugin-markdown/src/lib/components/frontmatter/file-frontmatter.svelte
  • packages/plugins/plugin-markdown/src/lib/views/file-properties/file-properties.svelte
  • packages/plugins/plugin-markdown/src/lib/components/frontmatter/widgets.ts

Implementation Summary

Consolidated note-local frontmatter writes behind a shared helper, hardened falsey and nullish mutation semantics, surfaced write failures through Notice, expanded FileManager processFrontMatter edge-case coverage, and added widget/frontmatter regression tests.

Make frontmatter value edits predictable and durable for all built-in property widgets, and consolidate the duplicated note-local write path used by markdown frontmatter surfaces. ## Context Audit findings from the current implementation: - `file-frontmatter.svelte` and `file-properties.svelte` duplicate the same `processFrontMatter` + lodash `set`/`unset` behavior. - Built-in widgets are imperative DOM renderers in `widgets.ts`; they update only on `blur` in most cases, so checkbox/date/number/text changes can be lost when focus is moved by a menu, a view switch, or editor remount. - Boolean, empty string, numeric, date, datetime, and unknown values have no focused regression tests for conversion, clearing, or YAML serialization. - `processFrontMatter()` is solid for the cache-missing case but has limited coverage for notes with no frontmatter block, empty frontmatter, parse errors, concurrent edits, or avoiding no-op writes. - UI callers do not surface write failures, so YAML or vault errors can appear as silent instability. ## Acceptance Criteria - The markdown plugin exposes one note-local frontmatter mutation helper for add, update, clear, and nested path writes, reused by live-preview frontmatter and the file properties side view. - Built-in widgets commit at predictable interaction points; checkbox-style values update on change, and text-like values do not lose edits when menus or view transitions move focus. - Empty values, `false`, `0`, empty arrays, and `null`/`undefined` removal have explicit behavior and tests. - `FileManager.processFrontMatter()` coverage includes adding a first frontmatter block, editing an existing block, preserving unrelated keys, handling parser/write failures, and suppressing unnecessary writes where practical. - Write failures are surfaced through the existing app notification/error path rather than silently failing. ## Notes Relevant files: - `packages/api/src/lib/file-manager.ts` - `packages/api/src/lib/__tests__/file-manager.test.ts` - `packages/plugins/plugin-markdown/src/lib/components/frontmatter/file-frontmatter.svelte` - `packages/plugins/plugin-markdown/src/lib/views/file-properties/file-properties.svelte` - `packages/plugins/plugin-markdown/src/lib/components/frontmatter/widgets.ts` ## Implementation Summary Consolidated note-local frontmatter writes behind a shared helper, hardened falsey and nullish mutation semantics, surfaced write failures through Notice, expanded FileManager processFrontMatter edge-case coverage, and added widget/frontmatter regression tests. <!-- backlog:task_id=TASK-PLUGIN-046 source_spec=spec/src/20-packages/plugins/markdown/index.md -->
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lapis-notes/lapis#65
No description provided.