Composition / foldkit-mixins-builder

Styling

BuilderSlots names every element; attach a Style as to any SlotView:

ts
import { Style } from 'foldkit-mixins'
import { BuilderSlots, BuilderView } from 'foldkit-mixins-builder'

const Styled = BuilderView.define(PageBuilder).pipe(
  Style.attach(
    Style.forSlots(BuilderSlots)({
      root: Style.class('builder'),
      row: Style.class('builder-row'),
      canvas: Style.class('builder-canvas'),
    }),
  ),
)

BuilderView.define places the editor inside root (the builder CSS container) with four structural slots:

  • panelTabs: compact toggle buttons shown below the narrow breakpoint.
  • regions: holds four named areas—start (palette, layers), bar (toolbar, crumbs, viewports, preview), stage (alert, canvas), and end (inspector).
  • live: polite/assertive announcement region.

root is a container (container: builder / inline-size, the Builder's default Style), so @container builder (max-width: 64rem) lays out panels by the editor's own width rather than the viewport width. Give root an explicit width (flex grow, grid track, or 100%) because inline-size containers take zero intrinsic width from their children. Custom layouts using assemble build their own structure from parts.

A node's props are drawn by its Block's settings form, a foldkit-mixins-form view the Builder makes. Give its Styles to define (or parts), and they are attached to every Block's settings form:

ts
import { FieldSlots, FormSlots } from 'foldkit-mixins-form'

const Configured = BuilderView.define(PageBuilder, {
  settings: {
    field: Style.attach(Style.forSlots(FieldSlots)({ label: Style.class('setting-label') })),
    form: Style.attach(Style.forSlots(FormSlots)({ root: Style.class('settings') })),
  },
})

A control kind of the application's own (Input.kind) is drawn by the renderers the application gives, the same ones its form views take. Each Block's settings form has Messages of its own, so they are given as a function of the Message, as foldkit-form-recipes/html's renderers is: BuilderView.define(PageBuilder, { settings: { renderers } }). Without one, the inspector says which renderer is missing.

The page on the canvas is the site's own markup, so it is styled by the site's CSS, and the editor marks it by drawing over it: the selectionBox Slot sits over the selected node, with its Block's label in selectionLabel, and the hoverBox Slot over the node under the pointer. They are placed from where the nodes are measured to be (Measure, from foldkit-primitives/dom), scroll with the page, and take no pointer; the Builder places them, and a Style says how they look:

ts
Style.forSlots(BuilderSlots)({
  selectionBox: Style.self({ outline: '2px solid Highlight', outlineOffset: '3px' }),
  selectionLabel: Style.self({ background: 'Highlight', color: 'HighlightText', fontSize: '0.75rem' }),
  hoverBox: Style.self({ outline: '1px dashed GrayText', outlineOffset: '3px' }),
})

A node's wrapper still carries data-composition-mark (selected, or hovered; a node that is both is selected), which is what the boxes are measured from, and data-composition-drop (before, inside or after) on the node a drop would land at. A wrapper is display: contents and draws nothing, so style the element inside it. The layer rows carry data-builder-drop and data-builder-dragging the same way.

Over a container's own space (the page's, or a Section's padding or the gap between two of its nodes) a drop lands between its children: before the first whose middle, along the container's flow (a row, a column, right to left), is past the pointer, else after the last, decided from where the pointer is when it moves and again where it lets go. Only that container's children are measured. Past the last node of the page itself it lands last, which the frame and the layers' tree mark as data-builder-drop="end". While a drag is under way dragPreview, canvas and tree carry data-drag-place: here where a drop would land and nowhere where it would be refused or the pointer is over nothing, so a look can show the one and refuse the other (a dashed preview, a not-allowed cursor).

A drag under way also writes the pointer's place on the document root, for the preview and for any style of yours that follows the pointer: --fk-drag-x and --fk-drag-y (pixels) and data-fk-drag="mouse | touch | pen", all removed when the drag ends. dragPreview reads them; the defaults put it beside the pointer, and above a finger.

css
[data-composition-drop='before'] > * { box-shadow: 0 -3px 0 Highlight; }
[data-composition-drop='after'] > * { box-shadow: 0 3px 0 Highlight; }
[data-composition-drop='inside'] > * { outline: 2px dashed Highlight; }
[data-builder-dragging] { opacity: 0.5; }