Block composition system
The block composition system models a page as a tree of nested blocks and turns that tree into editable canvas content. It supports reusable component instances, data-driven values, copy and paste, and safe structural changes while keeping the saved page and the visible canvas aligned. This page complements the visual builder workspace and relates to canvas interaction, property and style editing, block templates, page routing, editing history, and client-side code and data blocks.
Block tree
The block tree is the page’s content model. A root block owns ordered child blocks, and each child keeps a link to its parent so the same structure supports rendering, selection, insertion, removal, and movement. A block can represent a container, text, media, raw HTML, a form control, or a data repeater.
The tree also carries the state that affects the block’s output. This includes content, attributes, classes, responsive style values, data bindings, visibility rules, component links, and optional properties. Blocks have stable identities while they are being edited. New copies receive new identities so later selection and history changes do not affect the source block.
The main tree rules are:
- The root is the page boundary and cannot be dragged or removed as normal content.
- A block can receive children only when its kind allows nesting.
- Child order is the content order used by the canvas and by saved page data.
- Parent links are restored when blocks are created or inserted.
- A block’s local values can add to or override values inherited from a component or from a responsive breakpoint.
References: frontend/…/block.ts• L75-105 frontend/…/block.ts• L178-205 frontend/…/block.ts• L583-629 frontend/…/tree.ts• L4-31 frontend/…/helpers.ts• L200-219
Component instance model
Reusable components provide a second tree that can be used inside the page tree. A component instance points to a component definition through extendedFromComponent. Its materialized descendants point back to matching definition blocks through isChildOfComponent and referenceBlockId. This link lets an instance use the component’s shared structure while still storing page-specific changes.
The model separates shared structure from instance changes:
| Concept | Purpose |
|---|---|
| Component definition | Shared block tree and component-level behavior. |
| Component instance | Page-level use of that definition. |
| Instance child | Materialized child linked to a definition block. |
| Instance override | A local value that differs from the definition. |
| Pinned version | A frozen definition used when an instance must not follow later live edits. |
When a component changes, the system can sync missing definition blocks into an instance. A full rebuild follows the new definition’s shape and preserves only changes that can be matched to the same definition block. Nested components keep their own links, which allows composition without flattening every component into page-owned content.
An instance can also be detached. Detachment turns inherited component values into ordinary block values and removes the component links. This gives the page an independent copy without changing the source component.
The component store loads live or pinned definitions as needed. It tracks outdated pins and can update one instance or all instances on a page. A missing pinned snapshot falls back to the live definition so the canvas can still show content.
References: frontend/…/block.ts• L116-159 frontend/…/block.ts• L772-805 frontend/…/componentInstance.ts• L6-25 frontend/…/componentInstance.ts• L27-77 frontend/…/componentInstance.ts• L79-187 frontend/…/componentStore.ts• L21-47 frontend/…/componentStore.ts• L211-239 frontend/…/componentStore.ts• L277-355
Block rendering
Rendering turns each visible tree node into a canvas element and then renders its children inside that element. The renderer chooses the output form from the block’s role. Text, links, and buttons use the text editor path. Raw HTML and inline SVG use an HTML path. Repeaters use a data loader. Other blocks use their HTML tag.
The render flow carries page data, component data, default properties, breakpoint, and repeater position down the tree. A component root gets data for its own instance. Its descendants then resolve values against that shared instance context. Visibility rules are checked before a child is rendered, so hidden blocks do not occupy a rendered child position.
This diagram shows how a saved block tree becomes editable canvas output.
flowchart TD
A[Page block tree] --> B[Visit visible block]
B --> C{Block role}
C -->|Text or link| D[Text output and editor]
C -->|Raw HTML or SVG| E[HTML output]
C -->|Repeater| F[Repeated child output]
C -->|Other block| G[Element output]
B --> H[Resolve styles, attributes, content, and props]
H --> D
H --> E
H --> F
H --> G
F --> I[Resolve item data]
I --> B
The canvas adds editor-only behavior around the output. It marks blocks for selection, supplies breakpoint identity, and mounts the editing overlay without changing the saved content model. Component client code runs only after the needed component data is ready.
References: frontend/…/BuilderBlock.vue• L1-25 frontend/…/BuilderBlock.vue• L114-165 frontend/…/BuilderBlock.vue• L258-305 frontend/…/BuilderBlock.vue• L398-437 frontend/…/DataLoaderBlock.vue• L1-19 frontend/…/BlockHTML.vue• L22-39 frontend/…/TextBlock.vue• L1-27
Value resolution
Value resolution maps a block’s binding to a value at render time. A binding names a source and a path. The source can be page data, component data, or properties. The path can address nested data with dot notation. The resolved value can supply block content, an HTML attribute, a style, or a visibility condition.
Properties form a shared input model for composed content. A block can use its own properties, inherited properties from a component or parent, and default properties supplied by the current render context. The resolver combines these inputs before it applies dynamic values, so the same component can render different content for each instance without changing its shared tree.
Repeaters use an array or object as their input and render one copy of the first child for each item. The item context is passed to the child resolver. The canvas limits the number of preview items so large data sets do not make editing unusable. Each rendered item receives a distinct UID even though the tree stores one child block.
The value sources have these roles:
- Page data: values produced for the current page, often used for ordinary dynamic blocks and repeaters.
- Component data: values produced for one component instance from its data script and properties.
- Properties: values passed into a component or inherited through its block tree.
- Static block values: content and presentation used when no binding supplies a value.
References: frontend/…/blockValueResolver.ts• L6-27 frontend/…/blockValueResolver.ts• L29-73 frontend/…/blockValueResolver.ts• L75-107 frontend/…/BuilderBlock.vue• L178-240 frontend/…/BuilderBlock.vue• L358-390 frontend/…/DataLoaderBlock.vue• L54-115 frontend/…/DataLoaderBlock.vue• L118-125
Copy and paste
Copy and paste moves block content as a portable composition rather than as a bare HTML fragment. The clipboard payload includes the selected block trees plus the component definitions and tokens that those trees use. A whole-page copy can also carry page settings, page scripts, and font information.
Paste first reads the Builder clipboard format. It also reads an HTML form of the same payload so copies work between browsers that do not share custom clipboard types. The paste flow then detects whether the source is another site and handles dependencies before inserting fresh block copies.
The paste paths are:
- Normalize legacy token names and create or reuse referenced tokens.
- Create referenced components and rewrite component and token IDs when the target site needs new IDs.
- Import or attach copied page scripts when a cross-site paste needs them.
- Insert new block copies into the selected valid container or the page root.
- For a whole-page paste, update the current page or create a new page with the copied settings and content.
- For a cross-site paste, offer to import remote images and fonts so the result can become self-contained.
Component-owned children are detached before they are copied as independent content. Ordinary copies omit parent links and receive new block identities when inserted. Cross-site paste also changes component IDs and token references in both the pasted blocks and the copied component trees, so the new page does not point at definitions owned by the source site. Relative image and background URLs are made absolute to the source site until the user accepts asset import.
The custom clipboard type is a cross-tool contract. Its field names must remain compatible with the Builder browser extension, the HTML fallback, and older payloads that use the previous variable name field.
References: frontend/…/builderBlockCopyPaste.ts• L29-62 frontend/…/builderBlockCopyPaste.ts• L66-155 frontend/…/builderBlockCopyPaste.ts• L157-189 frontend/…/builderBlockCopyPaste.ts• L191-248 frontend/…/builderBlockCopyPaste.ts• L250-321 frontend/…/builderBlockCopyPaste.ts• L324-443 frontend/…/builderBlockCopyPaste.ts• L445-524 frontend/…/builderBlockCopyPaste.ts• L526-575 frontend/…/builderBlockCopyPaste.ts• L600-627 frontend/…/helpers.ts• L225-277 frontend/…/helpers.ts• L279-295
Block reordering
Reordering changes the child order or moves a block to a different valid parent. The canvas uses a pointer drag with a visual drop line. It measures the layout that the pointer is over, which supports rows, columns, wrapped flex layouts, and grids without changing the tree during the drag.
The source block stays in its layout slot while a floating ghost follows the pointer. On release, the system makes one tree change and records it as one history action. A drop into a container nests the block. A drop near a container edge places it beside that container. Escape cancels the operation.
Some blocks are intentionally not reorderable:
- The page root is fixed.
- Absolutely or fixed-positioned blocks use free movement instead of sibling order.
- Component-owned children remain controlled by the component definition.
These limits protect the link between a component instance and its source tree. They also keep visual movement from changing content in a way that the composition model cannot represent.
References: frontend/…/useBlockReorder.ts• L11-30 frontend/…/useBlockReorder.ts• L31-52 frontend/…/useBlockReorder.ts• L155-203 frontend/…/useBlockReorder.ts• L248-286 frontend/…/useBlockEventHandlers.ts• L18-28 frontend/…/block.ts• L817-822
Composition controllers
Controllers provide the shared rules used by canvas commands and panels. They keep selection-based edits, component edits, and structural edits on the same block model instead of letting each UI surface make its own copy of the rules.
The controllers have distinct roles:
| Controller | System responsibility |
|---|---|
| Block controller | Reads and updates selection-wide styles, attributes, content, data keys, spacing, links, and block properties. It reports a mixed value when selected blocks differ. |
| Component controller | Holds the active component draft, computes a data preview, and applies or resets the draft. |
| Component store | Loads definitions and versions, stores per-instance data, saves components, and coordinates sync or re-pin actions. |
| Canvas store | Owns the active tree, selection, insertion, dirty state, and history boundary. |
Component editing uses a separate fragment context. The editor can preview component data with the current properties before saving. Saving updates the component definition. An optional sync action then refreshes pages that use it. Page editing remains distinct from fragment editing so changes to a component draft do not silently change a page before the component is saved.
References: frontend/…/blockController.ts• L9-47 frontend/…/blockController.ts• L98-187 frontend/…/blockController.ts• L203-220 frontend/…/blockController.ts• L258-345 frontend/…/componentController.ts• L27-63 frontend/…/componentController.ts• L80-139 frontend/…/componentStore.ts• L69-141 frontend/…/canvasStore.ts• L103-144
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to block identity, parent links, or copy rules must preserve selection, component references, and history behavior after insertion.
- Changes to component child matching must preserve
referenceBlockIdlinks so rebuilds retain valid instance overrides. - Changes to value sources or property shape must stay aligned across the resolver, component data request, repeater context, and client-script inputs.
- Changes to the clipboard payload must remain compatible with the Builder browser extension, its HTML fallback, legacy token names, and cross-site ID rewriting.
- Changes to cross-site paste must keep page scripts attached to the target page and keep source asset URLs valid until the import offer is handled.
- Changes to reorder limits must not allow edits that break component ownership or the distinction between flow order and free-positioned blocks.
- Changes to pinned component handling must cover both version loading and the live-component fallback path.
- Changes to selection-wide block controls must keep mixed-value reads and multi-block writes aligned with the property and style panels.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A copied tree keeps its parent link or block IDs | The pasted content can point to the old tree or share selection identity with the source. | Copy without parent links and create new block instances for inserted content. |
| A component child loses its reference block ID | A component rebuild cannot match the old child and its instance changes can be lost. | Set and preserve referenceBlockId for every materialized component child. |
| Cross-site component or token IDs are not rewritten | The pasted page can request definitions or values from the source site. | Create target IDs and rewrite references in both page blocks and component trees. |
| A cross-site paste leaves copied scripts or remote assets unresolved | Pasted behavior or media can depend on the source site or remain absent from the target page. | Attach copied scripts to the target page and offer import of remote images and fonts. |
| A dynamic path resolves to no value | The block keeps its static value or the visibility condition hides the block. | Keep static fallbacks and validate the source and path used by the binding. |
| A pinned version is missing | An instance may render the wrong shared structure or show no component content. | Load the pinned snapshot when present and fall back to the live component when it was pruned. |
| A component-owned child is reordered directly | The page tree no longer follows the component definition. | Exclude component-owned children from reorder actions. |
| A multi-selection contains different values but the panel treats them as one value | An edit can hide differences or apply an unintended value across selected blocks. | Return a mixed state when selected blocks disagree and apply writes to the intended selection. |
Key files
| File | Why to read it |
|---|---|
| frontend/…/block.ts | Defines the block model, tree operations, component inheritance, responsive values, and dynamic bindings. |
| frontend/…/BuilderBlock.vue | Shows how a block and its visible children become canvas output. |
| frontend/…/componentInstance.ts | Explains component expansion, reset, sync, rebuild, and override preservation. |
| frontend/…/componentStore.ts | Shows how definitions, versions, instance data, and page-wide component updates are coordinated. |
| frontend/…/blockValueResolver.ts | Defines the common path for data, properties, component data, and visibility values. |
| frontend/…/builderBlockCopyPaste.ts | Defines the portable composition payload, dependency handling, cross-site rewriting, page-script attachment, and asset import offer for paste. |
| frontend/…/useBlockReorder.ts | Shows the rules and lifecycle for pointer-based tree movement. |
| frontend/…/blockController.ts | Shows how selection-based panels read and write shared block values across styles, content, attributes, links, and props. |
| frontend/…/componentController.ts | Shows the component draft and preview boundary during fragment editing. |
| frontend/…/canvasStore.ts | Shows how the active tree receives blocks and participates in selection and history. |