Skip to content

feat(templates): editor snippet insert + save-as-template (B11.10 surface #2)#85

Merged
th3-br41n merged 1 commit into
mainfrom
feat/b11.10-editor-templates
Jul 3, 2026
Merged

feat(templates): editor snippet insert + save-as-template (B11.10 surface #2)#85
th3-br41n merged 1 commit into
mainfrom
feat/b11.10-editor-templates

Conversation

@th3-br41n

Copy link
Copy Markdown
Contributor

Completes B11.10 Templates — the editor-side surface. Surface #1 (Database create-flow picker + object save-as-template) landed in #48; this is surface #2, inherited by every editor-bearing app.

Foundation (reusable keystones)

  • @brainstorm/editor insertSnippet(editor, json) — inserts a serialized-blocks snippet at the caret via the same paste path, so a snippet's transclusion / mention / object-link nodes carry their entityId verbatim (OQ-TPL-2: a snippet is a reusable view of the graph, not a text macro). Replaces the empty slash paragraph so it lands in place; fail-closed on malformed/empty.
  • @brainstorm/sdk blockSnippetToTemplateProperties / snippetFromTemplate — a block-snippet stores its fragment as serialized-blocks JSON on prototype.snippet. Storage decision (per @razor): reuse the paste wire format — no headless @lexical/yjs binding (the intricate alternative). Object templates keep their Yjs-root body unchanged.

Notes wiring (the 3 shared surfaces, mirroring Database)

  • /template slash command — queries block-snippet templates, opens the shared anchored-menu picker (caret-anchored; captures the point before the async query), inserts on select; quiet no-op when none exist.
  • "Save selection as template" block-selection action — serializeBlocksAsJson of the selected blocks → a new Template/v1{block-snippet}, name derived from the first block's text.
  • "Save as template" object-⋯ item — Note → object template via objectToTemplateProperties + copyEntityBody (Database's path).

Verified

+53 tests (insertSnippet round-trip/fail-closed; snippet codec produce/read/round-trip; templatesToSnippetOptions filter + deriveSnippetName). Workspace + apps/notes tsc + bun run lint (incl. the i18n + phantom-CSS-token checkers) clean; full suite 0 test-case failures (the 10 failed files are the known worktree Electron-collection artifact). Real-shell dogfood of the picker + save round-trip is the remaining B11.10 gate (unit-unverifiable).

🤖 Generated with Claude Code

…face #2)

Completes B11.10 — the editor-side templates surface (surface #1, the Database
create-flow picker + object save-as-template, landed in #48). Every editor-
bearing app inherits these once wired.

Foundation (reusable keystones):
- @brainstorm/editor `insertSnippet(editor, json)` — inserts a serialized-blocks
  snippet (the ClipboardPayload shape serializeBlocksAsJson emits) at the caret
  via the SAME paste path, so a snippet's transclusion/mention/object-link nodes
  carry their entityId verbatim (OQ-TPL-2 — a snippet is a reusable view of the
  graph, not a text macro). Replaces the empty slash paragraph so it lands in
  place. Returns false on a malformed/empty payload.
- @brainstorm/sdk `blockSnippetToTemplateProperties`/`snippetFromTemplate`/
  `TEMPLATE_SNIPPET_KEY` — a block-snippet stores its fragment as serialized-
  blocks JSON on `prototype.snippet` (per the user's storage decision: reuse the
  paste wire format, no headless @lexical/yjs binding). Object templates keep
  their Yjs-root body unchanged.

Notes wiring (the 3 shared surfaces, mirroring Database):
- `/template` slash command — queries block-snippet templates, opens the shared
  anchored-menu picker (caret-anchored; captures the point before the async
  query), inserts on select; quiet no-op when none exist.
- "Save selection as template" block-selection action — serializeBlocksAsJson of
  the selected blocks → a new Template/v1{block-snippet}, name derived from the
  first block's text (truncated) or a default.
- "Save as template" object-⋯ item — Note → object template via
  objectToTemplateProperties + copyEntityBody (Database's path).

+53 tests (insertSnippet round-trip/fail-closed; snippet codec produce/read/
round-trip; templatesToSnippetOptions filter + deriveSnippetName). Workspace +
apps/notes tsc + lint (incl. i18n + css-token checkers) clean. Real-shell dogfood
of the picker + save round-trip is the remaining B11.10 gate (unit-unverifiable).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@th3-br41n th3-br41n merged commit 82ee93b into main Jul 3, 2026
3 checks passed
@th3-br41n th3-br41n deleted the feat/b11.10-editor-templates branch July 3, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant