EDS Coder Open builder

Universal Editor Component Models for EDS, Explained

How component-definition.json, component-models.json and component-filters.json work in AEM Edge Delivery Services xwalk projects: how they link, how fields become block rows, naming conventions, and common mistakes.

On this page 9 sections
  1. The three files in one sentence each
  2. Don't edit the root files directly
  3. Definitions: what authors can add
  4. Models: the fields, and how they become rows
  5. Naming conventions that change the markup
  6. Filters: where components can go
  7. Keep instrumentation when you decorate
  8. Common mistakes
  9. How EDS Coder uses this

In an Edge Delivery Services (EDS) project authored with the Universal Editor, three JSON files decide what authors can do: which components they can add, which fields they fill in, and where each component is allowed. Get them right and authoring feels effortless. Get them wrong and authors see a block they can't place, a field that doesn't save, or a page that renders differently from the editor.

This post explains how the three files fit together, using the files in the aem-boilerplate-xwalk starter.

How component definitions, models and filters link together

The three files in one sentence each#

  • component-definition.json: what can be added. Each entry is a component in the editor's "Add" menu, with the AEM resource it creates.
  • component-models.json: which fields a component has. Each entry is the form shown in the properties panel.
  • component-filters.json: where it can go. Each entry lists the components allowed inside a container.

They're joined by IDs. A definition's template.model points to a model id; its template.filter points to a filter id. Filters list definition ids.

Don't edit the root files directly#

In the xwalk boilerplate, the three root files are generated. The sources are partials:

  • models/_component-definition.json, _component-models.json and _component-filters.json, which pull in the shared partials (_page.json, _section.json, _text.json, _image.json, _title.json, _button.json) and every blocks/*/_*.json.
  • blocks/<name>/_<name>.json, one per block, holding that block's definitions, models and filters together.

npm run build:json merges them with merge-json-cli, and the boilerplate's Husky pre-commit hook runs it automatically whenever you commit a changed _*.json file. Edit the partials, and keep each block's model next to its code.

Definitions: what authors can add#

Here's the Hero block's definition from the boilerplate:

JSON
{
  "title": "Hero",
  "id": "hero",
  "plugins": {
    "xwalk": {
      "page": {
        "resourceType": "core/franklin/components/block/v1/block",
        "template": { "name": "Hero", "model": "hero" }
      }
    }
  }
}
  • title is what authors see in the menu.
  • id is how filters refer to it.
  • resourceType tells AEM what kind of node to create. Blocks use core/franklin/components/block/v1/block. Items inside a block, like each card in Cards, use .../block/v1/block/item. The built-in default content uses its own types, such as section/v1/section and button/v1/button.
  • template.name becomes the block name, and therefore the CSS class and the folder EDS loads code from. template.model and template.filter link to the other two files.

Models: the fields, and how they become rows#

A model is a list of fields. The Hero's:

JSON
{
  "id": "hero",
  "fields": [
    { "component": "reference", "valueType": "string", "name": "image", "label": "Image", "multi": false },
    { "component": "text", "valueType": "string", "name": "imageAlt", "label": "Alt", "value": "" },
    { "component": "richtext", "name": "text", "value": "", "label": "Text", "valueType": "string" }
  ]
}

The component value picks the input: text, richtext, reference (an asset), aem-content (a link to a page), select, multiselect, boolean, number and others.

The part that surprises developers is how fields reach your block's JavaScript. Each field becomes one row of the block, in the order it's defined. The Hero above renders as two rows, an image and the rich text, which is the same markup a document author would create with a two-row table. That's why block code can stay the same across authoring methods.

The Hero has three fields but only two rows because of the naming conventions below.

Naming conventions that change the markup#

Field names aren't just labels. EDS uses them to decide how fields are rendered:

  • Field collapse. A field whose name is another field's name plus a suffix (Alt, Text, Title, Type or MimeType) is merged into that field instead of getting its own row. imageAlt becomes the alt attribute of image. The boilerplate's button uses link, linkText, linkTitle and linkType to produce one styled link.
  • Element grouping. Fields that share a prefix followed by an underscore, such as cta_link and cta_label, are rendered together in a single cell.
  • classes. A field named classes doesn't render as a row. Its values are added as classes on the block, the Universal Editor equivalent of Hero (dark) in a document. Use a select or multiselect so authors pick from known variants.

If a block's rows come out in an unexpected shape, check field names before you debug the JavaScript.

Filters: where components can go#

Filters build the page's hierarchy. From the boilerplate:

JSON
[
  { "id": "main", "components": ["section"] },
  { "id": "section", "components": ["text", "image", "button", "title", "hero", "cards", "columns", "fragment"] },
  { "id": "cards", "components": ["card"] }
]
  • A page's main can only contain sections.
  • A section can contain default content and the listed blocks. A new block can't be added anywhere until you add its id here, in models/_section.json.
  • The Cards definition has "filter": "cards", so it's a container whose children can only be card items. Each card is a block/v1/block/item with its own model, and renders as one row of the Cards block.

Use this container-and-item pattern for anything authors repeat: cards, tabs, accordion panels, slides.

Keep instrumentation when you decorate#

The Universal Editor finds editable elements through data-aue-* attributes in the page. When decorate replaces a row with a new element, those attributes are lost and the author can no longer select that part of the block.

The xwalk boilerplate's scripts.js exports moveInstrumentation(from, to) for this. The Cards block calls it on each row and each image it replaces. Call it whenever you create a new element to stand in for an authored one.

Live editing is handled by scripts/editor-support.js. When an author changes a field, it fetches the updated HTML, sanitises it with DOMPurify and re-runs decoration on just that block. That's why decorate must be safe to run on a fresh copy of the block.

Common mistakes#

  1. Block missing from the section filter. It's defined and modelled but never appears in the Add menu.
  2. Editing component-models.json instead of the partial. Your change is overwritten the next time someone commits a model change.
  3. Mismatched IDs. template.model: "Hero" against a model id of hero gives an empty properties panel. IDs are case-sensitive.
  4. Reordering or renaming fields after launch. Rows are positional and values are stored under field names, so existing pages break or lose content. Add new fields at the end.
  5. text where you meant richtext. Authors can't add links or bold text, and a fix later means re-entering content.
  6. Dropping instrumentation. The block renders correctly but can't be selected in the editor.

How EDS Coder uses this#

When EDS Coder generates a block, it writes the _<block>.json partial with the JavaScript and CSS, adds the block to the section filter, and keeps moveInstrumentation calls in decorate. The file tree marks each of those files as added or modified, so you can review the model alongside the code before syncing.


Sources: aem.live: Component model definitions · aem.live: Universal Editor tutorial · aem.live: AEM authoring · adobe-rnd/aem-boilerplate-xwalk on GitHub

Turn this guide into a working block

Describe a block or drop in a design. EDS Coder writes the JS, CSS and Universal Editor model, previews it live, and syncs to GitHub.

Build a block with AI →

Keep reading

All guides →