/** * Walks an experience composition and produces a flat description of what to * render, without producing any framework's elements. * * A framework binding maps the returned items onto its own element type; all the * decisions — which tag applies, how a node's fields become component content, * which preview attributes go where — are made here. * * @module */ import type { ExperienceNode } from '../../infer.js'; import type { ComponentRegistry } from '../../render/componentRegistry.js'; import type { OptimizelyContent } from './resolve.js'; /** Display settings after parsing, as a component receives them. */ export type ParsedDisplaySettings = Record | undefined; type RenderItemBase = { key: string; node: ExperienceNode; /** The node's display-template tag, already applied to `content` as `__tag`. */ tag: string | undefined; displaySettings: ParsedDisplaySettings; /** `data-epi-*` attributes for this node. Empty outside edit mode. */ previewAttrs: Record; }; /** A node holding a component. The binding renders `content` through its component lookup. */ export type ComponentRenderItem = RenderItemBase & { kind: 'component'; content: OptimizelyContent & Record; /** * Which kind of node produced this item. * * A section is a content type in its own right, so it renders as content * directly; a component node is what a binding offers a wrapper around. */ source: 'component' | 'section'; }; /** * A structure node — a row, a column, a form step — that wraps other items. * * `globalComponent` is whatever the registry holds for the node type (`_Row`, * `_Column`). A binding is free to prefer its own override and to fall back to * something of its own when both are absent. */ export type StructureRenderItem = RenderItemBase & { kind: 'structure'; nodeType: string; index: number; globalComponent: C | undefined; children: GridRenderItem[]; }; /** A node whose content type the CMS did not resolve. */ export type UnknownRenderItem = RenderItemBase & { kind: 'unknown'; }; /** What {@linkcode planGridSection} produces, at every depth. */ export type GridRenderItem = ComponentRenderItem | StructureRenderItem; export type RenderItem = GridRenderItem | UnknownRenderItem; /** Whether the item is a component node, which a binding renders inside a wrapper carrying its preview attributes. */ export declare function isWrappedComponent(item: RenderItem): item is ComponentRenderItem & { source: 'component'; }; /** Picks the container for a structure item: the binding's override, then the registered `_Row`/`_Column`, then the binding's fallback. */ export declare function getStructureContainer(item: StructureRenderItem, { overrides, fallbacks, }?: { overrides?: Partial>; fallbacks?: Partial>; }): C | undefined; /** * Plans a flat composition, as rendered inside an experience section. * * Component nodes are expected to be wrapped by the binding, which is why their * `previewAttrs` are reported separately rather than folded into `content`. * Structure nodes are rendered as content in their own right here — a section has * its own content type and its own component. */ export declare function planComposition(nodes: ExperienceNode[]): (ComponentRenderItem | UnknownRenderItem)[]; /** * Plans a grid section, recursing through rows and columns. * * Unlike {@linkcode planComposition}, a component node keeps a reference to the * node it came from under `__composition`, which is what lets a component read * its own display template key and its composition key. * * @param options.registry Looked up for `_Row` / `_Column` instead of the global registries. */ export declare function planGridSection(nodes: ExperienceNode[], options?: { registry?: ComponentRegistry; }): GridRenderItem[]; export {};