Skip to content

Definition factories: guard-preserving customization of pre-built components (#350)#354

Merged
CarlosNZ merged 4 commits into
v2.0-devfrom
feat/definition-factories
Jun 13, 2026
Merged

Definition factories: guard-preserving customization of pre-built components (#350)#354
CarlosNZ merged 4 commits into
v2.0-devfrom
feat/definition-factories

Conversation

@CarlosNZ

Copy link
Copy Markdown
Owner

Implements the core of #350: the pre-built custom-node definitions in @json-edit-react/components are now exported as definition factories rather than plain objects, so customizing them can no longer silently drop the built-in safety condition.

What changed

  • createDefinitionFactory (package-private, _common/): takes a plain CustomNodeDefinition base — its condition interpreted as the guard — and returns the consumer-facing factory. Consumer condition overrides are targeting, ANDed with the guard; the explicit guard key replaces the guard; componentProps shallow-merges; everything else is override-wins. The base objects keep their names/shape but are no longer exported — the factory is the only door.
  • 12 factories replace the former object exports: hyperlinkDefinition(), enhancedLinkDefinition(), datePickerDefinition(), dateObjectDefinition(), colorPickerDefinition(), markdownDefinition(), imageDefinition(), booleanToggleDefinition(), bigIntDefinition(), nanDefinition(), symbolDefinition(), undefinedDefinition(). Calling with no arguments reproduces the previous definition exactly.
  • Components + props types exported alongside the factories (MarkdownComponent, DateTimePicker, …) for wrapping and hand-rolled definitions; DefinitionOverrides<T> exported as the override-surface type. CodeEditor / ReactSelect stay component-only (no factory is possible — they have no default condition).
  • Demo converted — the former spread-usages were live examples of the footgun (both manually re-added typeof value === 'string' to compensate for dropping the guard); they're now factory calls with that boilerplate gone. Also removed a stale "override by index" comment (getConditionalDefinitions matches by name).
  • Docs: migration guide §2 (v1 LinkCustomNodeDefinition users now land on hyperlinkDefinition()), README spot-fixes (the components README usage example referenced a DateTimePickerDefinition export that never existed), two existing changesets corrected, new changeset added.
  • Cleanup: BooleanToggle's inline props generic ({ linkStyles?, stringTruncateLength? }, copy-pasted from Hyperlink) dropped — the component takes no custom props.

Verification

  • pnpm compile (components) and demo tsc -b --force both clean
  • Full rollup build: flattened build/index.d.ts exports exactly the designed surface — factories + components + props types + DefinitionOverrides; no createDefinitionFactory, no raw definition objects
  • Whole-tree sweep for the 13 old export names: remaining references are only the internal consts, the frozen demo/src/v1, and deliberate v1-name mentions in migration contexts

Follow-ups (tracked in #350)

  • Components README documentation: usage tiers, guard escape hatch, "UI-replacement components" category for CodeEditor/ReactSelect
  • Unit tests for the factory merge policy — needs a test-infrastructure decision first (the package has no Jest setup; core's config excludes packages/)

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown

Bundle size impact

@json-edit-react/components

Format Base raw PR raw Δ raw Base gzip PR gzip Δ gzip
esm 12.66 KB 13.22 KB 🔺 +572 B (+4.41%) 4.26 KB 4.49 KB 🔺 +242 B (+5.55%)
cjs 13.30 KB 13.91 KB 🔺 +626 B (+4.60%) 4.14 KB 4.36 KB 🔺 +228 B (+5.38%)

Measured from build/index.{cjs,esm}.js. Gzip at level 9.

@CarlosNZ CarlosNZ merged commit 19be8f0 into v2.0-dev Jun 13, 2026
2 checks passed
@CarlosNZ CarlosNZ deleted the feat/definition-factories branch June 13, 2026 03:04
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.

Definition factories — safely customize pre-built custom-node definitions (/components)

1 participant