Skip to content

feat: defineMacro ctx, session persistence, delta history#34

Merged
rohal12 merged 4 commits intomainfrom
feat/define-macro-ctx
Mar 8, 2026
Merged

feat: defineMacro ctx, session persistence, delta history#34
rohal12 merged 4 commits intomainfrom
feat/define-macro-ctx

Conversation

@rohal12
Copy link
Owner

@rohal12 rohal12 commented Mar 8, 2026

Summary

  • defineMacro config pattern: Migrate all macros to defineMacro() with feature flags (interpolate, merged, storeVar), providing ctx with h, renderNodes, hooks, and mutation helpers
  • Wiki-link desugaring: [[links]] desugar to {link} macro at AST level
  • Session persistence: Auto-save to sessionStorage on navigate — F5 resumes where you left off
  • Delta-based history: History uses Immer produceWithPatches/applyPatches — only changed variables stored per moment instead of full snapshots
  • Configurable history limit: Story.config.maxHistory (default 40) trims oldest entries
  • visited()/rendered() defaults: Called without arguments, defaults to current passage
  • PassageHeader/PassageFooter/PassageDone: Special passage support for header/footer/done hooks
  • {span} macro: Inline wrapper macro

Test plan

  • All 673 unit/DOM/e2e tests pass
  • Type check clean (tsc --noEmit)
  • Dev story compiles and runs
  • Manual test: F5 refresh preserves game state
  • Manual test: closing tab starts fresh
  • Manual test: save/load round-trip works with delta history

release-npm

🤖 Generated with Claude Code

…ches npm version

The build was reading the version from format.json (hardcoded 0.2.0) instead
of package.json. Since the release action bumps package.json before
prepublishOnly rebuilds, format.js now gets the correct version.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link

github-actions bot commented Mar 8, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 74.55% 1855 / 2488
🔵 Statements 73.75% 2035 / 2759
🔵 Functions 68.43% 349 / 510
🔵 Branches 65% 938 / 1443
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/expression.ts 85.4% 72.3% 86.36% 85.93% 77-78, 100-101, 112-113, 117, 119-120, 172-173, 211-212, 215-218, 276
src/index.tsx 0% 0% 0% 0% 19-154
src/store.ts 90.35% 81.69% 85.45% 91.86% 80, 114, 245-246, 301, 310-313, 344-349, 441, 474, 494-497, 511, 515-518
src/story-api.ts 2.17% 0% 4.16% 2.29% 84-302
src/components/Passage.tsx 67.44% 50% 88.88% 67.56% 56-60, 66-70, 76, 77, 82-86
src/components/StoryInterface.tsx 0% 0% 0% 0% 4-24
src/components/macros/MacroLink.tsx 67.64% 57.89% 80% 69.69% 26, 38, 43-56, 83-85
src/components/macros/PassageDisplay.tsx 18.18% 0% 0% 22.22% 9-40
src/components/macros/Span.tsx 50% 0% 0% 50% 6
src/components/macros/Timed.tsx 100% 90.9% 100% 100%
src/markup/ast.ts 81.44% 78.94% 100% 78.57% 124-167, 263-264
src/saves/save-manager.ts 92.95% 91.48% 92.59% 93.6% 322-333
src/saves/types.ts 100% 100% 100% 100%
Generated in workflow #91 for commit bcdce3e by the Vitest Coverage Report Action

clem and others added 2 commits March 8, 2026 20:58
…defaults

- Auto-save to sessionStorage on navigate — F5 resumes where you left off
- History uses Immer patches (only changed variables stored per moment)
- Configurable history limit via Story.config.maxHistory (default 40)
- visited()/rendered() default to current passage when called without args
- Decouple save format (full snapshots) from runtime format (patches)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rohal12 rohal12 changed the title fix: read format version from package.json so published format.js matches npm version feat: defineMacro ctx, session persistence, delta history Mar 8, 2026
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rohal12 rohal12 merged commit 5b23305 into main Mar 8, 2026
5 checks passed
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