Concrete
Concepts

The marker contract

Deciding what your markup owes the editor, when you are working out where a primitive goes and what it may replace.

A section's rendered DOM carries attributes naming which declaration produced each piece of it — enough for something outside your section to point at an element and know which slot put it there. The whole contract fits in one sentence: to render slot X you use slot X's primitive; there is nothing else, and the marker cannot be anywhere else.

What it is

import { compute, fact, object, Section, section, Slot, text } from "@homepages/concrete";

export const Address = section(
  {
    key: "address",
    label: "Address",
    slots: {
      address: object({
        label: compute(() => "Property address"),
        fields: {
          street: text.short({ label: "Street", source: fact.property.address.street }),
          locality: text.short({ label: "City", source: fact.property.address.city }),
        },
      }),
    },
  },
  ({ slot }) => (
    <Section>
      {/* One card in the editor sidebar: the object, with its fields inside it. */}
      <Slot.Object slot={slot.address} as="p" className="text-sm">
        <Slot.Text slot={slot.address.street} as="span" />
        <Slot.Text slot={slot.address.locality} as="span" />
      </Slot.Object>
    </Section>
  ),
);

Three things are marked, and only three: the section instance, a slot's value, and an object — a top-level object, or one item of a list of objects. Slot.Text here renders the span element you asked for, with your own props on it, and the marker rides on that same element. Slot.Object does the same for the card.

Why it works this way

The pipeline establishes that your code runs at exactly two moments, and that in both of them the platform hosting your render never sees your component — only the DOM it produced.

That is the constraint the editor lives inside. When someone clicks a piece of content on the canvas, the editor has to resolve that click back to the slot that produced it — and it has never had your component to inspect, only the markup. So the identity of a piece of content has to travel in the DOM, as an attribute on the element carrying it, because there is nowhere else for it to live.

The design choice that follows is where the markers sit: on your own elements, not on a wrapper the framework inserts around them. A slot's binding carries its identity, and the primitive derives the marker from it and places it on the element you named through as, with that element's own props. Because the marker rides on an element you already wrote, the framework needs no layout layer of its own and your DOM stays exactly the DOM you wrote.

The primitive is the marker, and that identity is deliberately exclusive: there is no marker-only carrier, no bag of attributes to spread onto an element of your own, and no second route identity could arrive by. When a primitive seems not to fit the markup you need, the answer is that the primitive can be that markup — as takes any element, the remaining props are that element's own, and your children render inside — never that you attach the marker some other way. One primitive per slot means the editor's picture of the page and your markup cannot disagree.

The same design is why a slot can be marked in several places at once. Each rendered copy carries its own marker, is patched live, and is its own editing target: a headline printed twice is editable in both spots. A copy that should never resolve a click — a carousel clone, a decorative mirror — declines with selectable={false}, and keeps its identity and its live patching, because a copy without identity would visibly lag its siblings.

How it works

The direction of travel

Every marker but one is emitted for you. The primitives read the slot's own declaration off its binding and put the right attribute on the right element, so you never author a marker's name. The exception goes the other way: the attribute naming the deliverable's section instance is written by the platform onto the section root, not by anything you render.

Both halves are checked. slots/no-marker-literal rejects a hand-written data-slot-* in section code, and render/missing-slot-marker reports a declared slot that never reached the DOM.

An object's fields render inside its Slot.Object, at the top level and in a list

A card is declared once, as an object in slots, and rendered through one Slot.Object over its binding. Which object a field belongs to is where its marker lands: the editor reads a field's marker and edits the object whose container holds it. So every field renders inside its own object's Slot.Object, through its own binding — a field marked outside it is a check error (render/group-ancestry). Only an object's binding type-checks as a Slot.Object; a value slot has no card to mark.

An item of a list of objects is the same editing unit with identity by index rather than by name, so it is the same primitive over the item's binding:

import { bindItems, fact, fill, list, object, Section, section, Slot, text } from "@homepages/concrete";

export const Features = section(
  {
    key: "features",
    label: "Features",
    slots: {
      features: list({
        label: "Features",
        min: 3,
        max: 6,
        source: fill.write({
          reads: [fact.property.uploads, fact.property.description],
          brief: "The features the property's photos show, each a short noun phrase.",
        }),
        item: (name) =>
          object({
            label: name,
            fields: {
              detail: text.short({ label: "Detail", cap: 80, source: fill.write({ reads: [fact.property.description, name], brief: "One line on it." }) }),
            },
          }),
      }),
    },
  },
  ({ slot }) => (
    <Section>
      <Slot.List slot={slot.features} as="ul">
        {bindItems(slot.features).map((item) => (
          <Slot.Object key={item.index} slot={item} as="li">
            <Slot.Text slot={item.label} as="span" />
            <Slot.Text slot={item.detail} as="span" />
          </Slot.Object>
        ))}
      </Slot.List>
    </Section>
  ),
);

Someone who marked a top-level object's card reaches for the same component to mark an item without being told to. That is the test a merged primitive has to pass here. An item of a list of plain values is no object, and is not marked: it renders as your own element inside the list's marker, with Image, Video or Tour drawing a media value.

An object's field can itself be a list of objects — a unit's floor plans inside a unit card. That list is one field, so its items are no editing unit of their own: Slot.Object over one of them, from bindItems(item.plans), marks it as the enclosing field, and so does every field binding that item hands out. A click anywhere inside a floor plan selects the unit's floor-plans field.

What it is not

Markup is yours

Nothing about the primitives dictates your DOM beyond the one element each renders. There is no wrapper you did not ask for, no forced tag, no required container and no ordering constraint. Layout, headings, links, icons, cards, tables — all plain JSX around them.

Markers are not styling hooks

A marker names the element carrying a slot's value, and which element that is depends on what the slot declares: an image slot's marker can land on a framed wrapper, on the image itself, or on a generated picture element. A CSS selector written against a marker attribute is written against that choice, and a declaration change moves it out from under the selector without touching a line of your markup. Style your own classes.

Markers are not attributes to write by hand

Writing one in your JSX does not create a slot, because a slot exists only where the declaration puts it. The marker-attribute constants are exported for one purpose: so a section's own browser-side code can query the DOM it rendered.

Where next

On this page