Skip to content

feat: defineMacro context API, dialog extraction, and wiki-link desugaring#33

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

feat: defineMacro context API, dialog extraction, and wiki-link desugaring#33
rohal12 merged 5 commits intomainfrom
feat/define-macro-ctx

Conversation

@rohal12
Copy link
Owner

@rohal12 rohal12 commented Mar 8, 2026

Summary

  • defineMacro context pattern: All macros now use ctx.h, ctx.hooks, ctx.renderNodes instead of direct Preact imports, enabling a cleaner public API
  • Dialog extraction: Split monolithic SaveLoadDialog/SettingsDialog into composable PassageDialog + SaveManager/SettingsControls/MenubarButtons components
  • Wiki-link desugaring: [[Go|Forest]] now produces the same AST as {link "Go" "Forest"} at parse time, removing the PassageLink component and unifying CSS under .macro-link

Breaking changes

  • .passage-link CSS class renamed to .macro-link — authors using custom CSS for wiki-links need to update selectors

Test plan

  • npx tsc --noEmit passes
  • 667 unit/dom tests pass
  • 177 e2e tests pass

release-npm

🤖 Generated with Claude Code

Introduce `defineMacro()` builder that eliminates boilerplate across all
36 macro components. Macros declare feature flags (interpolate, merged,
storeVar) and receive a pre-wired `ctx` object with always-on helpers
(h, renderNodes, hooks, cls, mutate, wrap, useAction) plus opt-in
capabilities (evaluate, resolve, value/setValue).

- New `src/define-macro.ts` with MacroContext/MacroDefinition types
- New `MacroError` shared component replaces 10+ duplicate error spans
- New `parseVarArgs()` utility deduplicates Textbox/Numberbox/Textarea
- All macros migrated to defineMacro() config pattern
- Public API: `Story.defineMacro()` for custom macros in {do} blocks
- Beginner-friendly custom-macros.md with step-by-step tutorials

release-npm

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.75% 1765 / 2361
🔵 Statements 74.01% 1937 / 2617
🔵 Functions 68.58% 334 / 487
🔵 Branches 65.32% 908 / 1390
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/action-registry.ts 100% 100% 100% 100%
src/define-macro.ts 100% 93.75% 100% 100%
src/story-api.ts 2.27% 0% 4.34% 2.4% 81-288
src/components/PassageDialog.tsx 10.52% 0% 0% 11.11% 23-67
src/components/macros/Button.tsx 87.5% 66.66% 100% 87.5% 11-14
src/components/macros/Checkbox.tsx 83.33% 40% 66.66% 81.25% 7, 30, 41
src/components/macros/Computed.tsx 75.92% 76.31% 100% 78.72% 13, 14, 17-18, 20, 26-28, 35-37, 48-51, 71-75, 96-100
src/components/macros/Cycle.tsx 71.42% 61.53% 66.66% 76.92% 10, 25-28
src/components/macros/Dialog.tsx 18.18% 0% 0% 18.18% 8-34
src/components/macros/Do.tsx 85.71% 100% 100% 85.71% 12
src/components/macros/For.tsx 83.72% 82.35% 80% 84.21% 27, 38, 41-43, 75, 99-103, 121-125
src/components/macros/Goto.tsx 87.5% 100% 100% 87.5% 14
src/components/macros/If.tsx 93.75% 100% 100% 93.75% 36-40
src/components/macros/Include.tsx 89.47% 83.33% 100% 94.11% 13, 20
src/components/macros/Listbox.tsx 66.66% 60% 50% 75% 19, 28
src/components/macros/MacroError.tsx 100% 50% 100% 100%
src/components/macros/MacroLink.tsx 67.64% 57.89% 80% 69.69% 26, 38, 43-56, 83-85
src/components/macros/MenubarButtons.tsx 54.76% 42.85% 34.78% 63.88% 28, 42-45, 55, 74, 108-109, 120-123, 132-133, 152
src/components/macros/Meter.tsx 88% 76.31% 100% 88.88% 23-25, 43-44, 46-47, 52
src/components/macros/Numberbox.tsx 62.5% 50% 33.33% 62.5% 16, 27-28
src/components/macros/PassageDisplay.tsx 20% 0% 0% 25% 9-30
src/components/macros/Print.tsx 100% 50% 100% 100%
src/components/macros/Radiobutton.tsx 76.47% 33.33% 66.66% 73.33% 15-20, 45, 57
src/components/macros/Repeat.tsx 9.67% 0% 0% 12% 14-58
src/components/macros/SaveManager.tsx 85.8% 80.72% 94.73% 89.28% 27-33, 67, 94, 101, 108, 119, 129, 140, 150, 157, 169, 181, 227, 398
src/components/macros/Set.tsx 77.77% 100% 100% 77.77% 14-18
src/components/macros/Stop.tsx 20% 100% 0% 20% 7-13
src/components/macros/StoryTitle.tsx 100% 50% 100% 100%
src/components/macros/Switch.tsx 100% 100% 100% 100%
src/components/macros/Textarea.tsx 71.42% 66.66% 33.33% 71.42% 16, 25
src/components/macros/Textbox.tsx 71.42% 33.33% 33.33% 71.42% 16, 26
src/components/macros/Timed.tsx 100% 90.9% 100% 100%
src/components/macros/Type.tsx 7.4% 0% 0% 8.33% 8-72
src/components/macros/Unset.tsx 91.66% 66.66% 100% 91.66% 19-21
src/components/macros/Widget.tsx 100% 100% 100% 100%
src/components/macros/option-utils.ts 92.3% 87.5% 100% 92.3% 9
src/markup/ast.ts 81.44% 78.94% 100% 78.57% 123-166, 262-263
src/markup/render.tsx 68.88% 51.11% 81.25% 74.02% 62, 72-85, 89, 153-162, 173, 180, 186-199, 214, 232
Generated in workflow #87 for commit 11cfbb8 by the Vitest Coverage Report Action

clem and others added 4 commits March 8, 2026 16:23
The test expected #timed-output to contain "Second section!", but after
the per-section class/id fix, that ID only applies to the first section.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use beforeAll to navigate once per describe block for tests that only
read DOM state, eliminating ~160 redundant page loads. Side-effect
tests (button clicks, form inputs, navigation) keep their own fresh
navigation. Reduces e2e suite time from ~90s to ~27s.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extract SaveLoadDialog/SettingsDialog into PassageDialog with
SaveManager/SettingsControls/MenubarButtons. Migrate all macros to use
defineMacro context pattern (ctx.h, ctx.hooks, ctx.renderNodes) instead
of direct imports.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Convert LinkNode → MacroNode in buildAST so [[Go|Forest]] produces the
same AST as {link "Go" "Forest"}. Removes PassageLink component and
unifies CSS under .macro-link.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rohal12 rohal12 changed the title feat: defineMacro config pattern with context-based API feat: defineMacro context API, dialog extraction, and wiki-link desugaring Mar 8, 2026
@rohal12 rohal12 merged commit 5ba56c6 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