feat: #3580092 Add support for json-render output format
Adds json-render as a third Custom Elements JSON serialization format alongside
the existing explicit and legacy formats.
Caveat
Currently, json-render does not support named slots in its specifications (only a single default children slot is supported). Drupal Canvas (CLI, Workbench) uses the slots structure proposed in json-render PR #105.
That PR is currently based on an older version of json-render, from when React was its only supported adapter. I'll work on bringing it up to date and extending named-slot support to the additional framework adapters that json-render now supports.
Changes
- Refactor
CustomElementNormalizerinto a facade backed by tagged, format-specific normalizers:JsonFormatNormalizerpreserves the existing explicit and legacy formats.JsonRenderFormatNormalizerproduces a flat{root, elements}json-render spec.- For multi-root trees,
renderless-containeris used as the single synthetic root. - For empty render trees, empty json-render spec is returned
{ "root": "", "elements": {} }. - Named slots use the format proposed in the json-render PR #105.
- For multi-root trees,
- Add
json-renderto the Custom Elements configuration form and allow callers to select it explicitly through thejson_formatnormalization context.
I used an AI coding agent to assist in implementing this.
Edited by wotnak