Registry and formatters
Component definitions and built-in formatters. Template reference in the DocStudio developer reference.
Public from docstudio/core: createRegistry, registerComponent, createDefaultRegistry, builtinDefinitions, BUILTIN_TYPES, createFormatterRegistry, registerFormatter and the related types. Decision record: ADR 0012.
Component definitions
A ComponentDefinition is { type, category, childSlots, schema?, resolve? }.
type: the node type name. Names match[A-Za-z][A-Za-z0-9_.-]{0,63};__proto__,constructorandprototypeare refused.category:leaf(no children),container(holds child nodes) ordata(driven by a source expression: table, repeater).childSlots: the property names that hold child node arrays, for example['children']. Walkers use it to descend without knowing node types.schema(optional): a JSON Schema for the component's props. Used by composite components from M9.resolve(optional): a pure function from props to resolved props. Used from M9.
Only the core facets exist here. The HTML renderer facet belongs to docstudio/render (Phase 2) and the editor facet to docstudio/designer (Phase 3); a server render never imports designer code.
Registry
createRegistry() returns an independent registry with get, has, types and register. registerComponent(registry, definition) returns { registered, diagnostics }: INVALID_REGISTRATION for a bad name and DUPLICATE_REGISTRATION for a type already present (the first definition is kept). Registered definitions are frozen and their slot list is copied. Registries are values; there is no global registry. Lookups use a Map, so inherited names never resolve.
createDefaultRegistry() holds the 15 built-ins, including slot. component (reference to a reusable component) is resolved by composite expansion (composites.md) rather than by a definition.
| Type | Category | Child slots |
|---|---|---|
| text, image, divider, shape, pageNumber, qr, barcode, slot | leaf | none |
| stack, row, grid, fixed, section | container | children |
| table | data | none |
| repeater | data | children, empty |
A test fails if the schema gains a node type without a built-in definition, and a property test checks that walking childSlots reaches exactly the nodes a generic walk finds.
Formatters
createFormatterRegistry({ locale }) returns a Map usable as the evaluator and binder formatters option. Built-ins use Intl, are UTC by default and return undefined (never throw) for invalid input. Use them with the format function: { fn: 'format', args: [name, value, ...options] }.
| Name | Value | Options | Example (en) |
|---|---|---|---|
date |
ISO 8601 string or epoch milliseconds | style short, medium (default), long, full, or iso (UTC YYYY-MM-DD); time zone name (default UTC) |
Mar 5, 2024 |
number |
finite number | decimals 0 to 20; default up to 3 | 1,234.50 |
currency |
finite number | three-letter uppercase code (required); decimals | $1,234.50 |
percent |
finite number, a ratio | decimals (default 0) | 26% for 0.256 |
boolean |
boolean | true text, false text (default Yes, No) |
Yes |
Date strings must be ISO 8601; free-form strings are refused because their parsing differs between engines. An invalid locale, time zone or currency code yields undefined, which the binder then treats as a missing value under the active policy. registerFormatter(registry, name, fn) adds a custom formatter and returns a diagnostic for a bad or duplicate name. A throwing custom formatter becomes FORMATTER_FAILURE.
Determinism and limits
Output for a locale is produced by the runtime's Intl data, so exact strings for Arabic and Urdu can differ between ICU versions. Tests for those locales assert stable fragments; English output is asserted exactly. Hosts that need byte-identical output across runtimes should register their own formatters. Each registry caches at most 256 Intl formatters per kind, so template-supplied options cannot grow memory without bound.
Performance
Median on macOS (Node 24), 100,000 evaluator calls: currency 1.0 µs, number 0.95 µs, percent 0.94 µs, date 1.6 µs, boolean 99 ns. See validation/artifacts/benchmarks/core-m6-formatters.json.