Skip to content

DesignerController

Framework-neutral designer logic: the template being edited, selection, move/resize/snap, band and data management, clipboard and undo/redo. Every change produces a new template object, so views can compare by reference.

new DesignerController(options?): DesignerController;
Parameter Type
options DesignerControllerOptions

DesignerController

get redoLabel(): string | null;

string | null


get template(): ReportTemplate;

ReportTemplate


get undoLabel(): string | null;

Label of the change that undo would revert.

string | null

addChildRegion(parentRegionId, source): string;

Adds a nested (master-detail) region. Pass { relation: 'items' } or { dataSource: 'notes' }.

Parameter Type
parentRegionId string
source | { relation: string; } | { dataSource: string; }

string


addComponent<T>(
bandId,
type,
overrides?
): string;

Adds a component to a band and selects it. Returns its id.

Type Parameter
T extends "text" | "image" | "line" | "rectangle"
Parameter Type
bandId string
type T
overrides Partial< | Extract<TextComponent, { type: T; }> | Extract<ImageComponent, { type: T; }> | Extract<LineComponent, { type: T; }> | Extract<RectangleComponent, { type: T; }>>

string


addDataRegion(dataSource, index?): string;

Inserts a data region bound to a data source. Returns the region id.

Parameter Type
dataSource string
index? number

string


addDataSource(def): void;
Parameter Type
def DataSourceDefinition

void


addGroup(regionId, expression): string;

Adds a group to a region (as the innermost group). Returns the group id.

Parameter Type
regionId string
expression string

string


addParameter(def): void;
Parameter Type
def ParameterDefinition

void


addStaticBand(index?): string;

Inserts a static band into the body at index (end by default). Returns its id.

Parameter Type
index? number

string


align(alignment): void;
Parameter Type
alignment Alignment

void


beginInteraction(label): void;

Starts a drag or resize. Changes until endInteraction() become one undo step.

Parameter Type
label string

void


bodyWidth(): number;

Width of the printable body in template units: components should stay within it.

number


cancelInteraction(): void;

void


checkExpression(source): string | null;

Checks expression syntax; null when valid.

Parameter Type
source string

string | null


clearSelection(): void;

void


completions(bandId?): string[];

Names available in expressions inside a band, for autocompletion: scope variables, data sources, parameters and row fields.

Parameter Type
bandId? string

string[]


copy(): number;

number


cut(): number;

number


distribute(axis): void;
Parameter Type
axis "horizontal" | "vertical"

void


duplicate(): string[];

string[]


endInteraction(): void;

void


getSampleData(): unknown;

unknown


getState(): DesignerState;

DesignerState


handleKey(e): boolean;

Handles designer shortcuts. Returns true when the key was handled, so the view can call preventDefault(). Views should not forward keys typed into inputs.

Parameter Type
e KeyInput

boolean


inferDataSourceFields(name): number;

Infers a data source’s fields from the sample data. Returns the field count.

Parameter Type
name string

number


insertField(
bandId,
path,
at?,
root?
): string;

Inserts a text bound to a data field, e.g. path [“customer”, “name”] becomes {{ row.customer.name }}. root defaults to “row”.

Parameter Type Default value
bandId string undefined
path string[] undefined
at { x: number; y: number; } ...
at.x number undefined
at.y number undefined
root string 'row'

string


load(template): void;

Replaces the template (e.g. after opening a file). Clears history. Throws for invalid templates.

Parameter Type
template string | ReportTemplate

void


markSaved(): void;

Marks the current template as saved (clears dirty).

void


matchSize(dimension): void;

Gives the selected components the same width and/or height as the first one.

Parameter Type
dimension "height" | "width" | "both"

void


moveBodyItem(fromIndex, toIndex): void;

Moves a top-level body item (static band or region) to another position.

Parameter Type
fromIndex number
toIndex number

void


moveComponents(
ids,
dx,
dy,
snap?
): void;

Moves components by a delta. Inside an interaction the delta is measured from the drag start. Snaps the primary (first) component and moves the others by the same amount. Positions stay non-negative.

Parameter Type Default value
ids string[] undefined
dx number undefined
dy number undefined
snap boolean true

void


moveComponentsToBand(
ids,
bandId,
dx,
dy,
snap?
): void;

Moves components (all from one band) into another band while dragging. dx/dy are measured from the components’ original positions, in the target band’s coordinates: when the target band starts 30 units below the source band, a pointer movement of 35 units down is dy = 5. Inside an interaction the change is applied to the drag start state, so the drag can move back and forth between bands. Moving to the components’ own band is the same as moveComponents.

Parameter Type Default value
ids string[] undefined
bandId string undefined
dx number undefined
dy number undefined
snap boolean true

void


moveComponentToBand(
id,
bandId,
x,
y
): void;

Moves a component to another band at the given position (band coordinates).

Parameter Type
id string
bandId string
x number
y number

void


moveGroup(groupId, direction): void;

Moves a group one level out (-1) or in (+1).

Parameter Type
groupId string
direction -1 | 1

void


nudge(
dxSteps,
dySteps,
fine?
): void;

Moves the selection by a small step (arrow keys). Uses the grid unless fine is true.

Parameter Type Default value
dxSteps number undefined
dySteps number undefined
fine boolean false

void


pageSize(): object;

Page size in template units, with the orientation applied.

object

Name Type
height number
width number

paste(bandId?): string[];

Pastes into the selected band (or bandId), offset when pasting into the same place. Returns new ids.

Parameter Type
bandId string | null

string[]


preview(options?): object;

Generates the report with the sample data. Errors are returned, not thrown.

Parameter Type
options GenerateOptions

object

Name Type
document LayoutDocument | null
error Error | null

redo(): void;

void


regionFields(region): FieldDefinition[] | undefined;

Field schema of the rows a region iterates (from the data source or the parent’s relation).

Parameter Type
region DataRegion

FieldDefinition[] | undefined


removeBand(bandId): boolean;

Removes a band. Detail bands cannot be removed on their own: remove the region instead. Returns false when nothing was removed.

Parameter Type
bandId string

boolean


removeComponents(ids?): void;

Removes the selected (or given) components.

Parameter Type
ids string[]

void


removeDataSource(name): void;
Parameter Type
name string

void


removeGroup(groupId): void;
Parameter Type
groupId string

void


removeParameter(name): void;
Parameter Type
name string

void


removeRegion(regionId): void;

Removes a data region with all its bands and children.

Parameter Type
regionId string

void


removeStyle(name): void;

Removes a named style and detaches components that used it.

Parameter Type
name string

void


renameStyle(from, to): void;

Renames a named style and updates components that use it.

Parameter Type
from string
to string

void


reorder(where): void;

Changes paint order: components later in the band list are drawn on top.

Parameter Type
where "front" | "back" | "forward" | "backward"

void


resizeBand(bandId, height): void;

Resizes a band by dragging its bottom edge; height is in template units.

Parameter Type
bandId string
height number

void


resizeComponent(
id,
handle,
dx,
dy
): void;

Resizes a component with a handle; inside an interaction the delta is measured from the drag start.

Parameter Type
id string
handle ResizeHandle
dx number
dy number

void


resizeComponents(
ids,
handle,
dx,
dy
): void;

Resizes several components with the same handle and delta, e.g. to make every cell of a table row taller at once. Each component keeps its own opposite edge fixed.

Parameter Type
ids string[]
handle ResizeHandle
dx number
dy number

void


sections(labels?): DesignSection[];

Bands in design order. Pass translated labels for localized captions.

Parameter Type
labels? SectionLabels

DesignSection[]


select(ids, mode?): void;

Selects components. Components must share a band; selecting a component from another band replaces the selection.

Parameter Type Default value
ids string[] undefined
mode "replace" | "add" | "toggle" 'replace'

void


selectAll(bandId?): void;

Selects every component in a band (the selected band by default).

Parameter Type
bandId string | null

void


selectBand(bandId): void;
Parameter Type
bandId string | null

void


selectedComponents(): ReportComponent[];

Selected components, in selection order.

ReportComponent[]


selectInBands(rects, additive?): void;

Rubber-band selection that may cover several bands, e.g. started in the page margin. Selections are limited to one band, so the band with the most hits wins (the first one on a tie). rects are in each band’s coordinates. With no hits the selection is cleared (unless additive).

Parameter Type Default value
rects object[] undefined
additive boolean false

void


selectInRect(
bandId,
rect,
additive?
): void;

Rubber-band selection inside one band; rect is in band coordinates.

Parameter Type Default value
bandId string undefined
rect Rect undefined
additive boolean false

void


setGroupBand(
groupId,
which,
enabled
): void;
Parameter Type
groupId string
which "header" | "footer"
enabled boolean

void


setPageBand(slot, enabled): string | null;

Adds or removes a report/page header or footer.

Parameter Type
slot PageBandSlot
enabled boolean

string | null


setRegionBand(
regionId,
which,
enabled
): void;

Adds or removes a region’s header or footer band.

Parameter Type
regionId string
which "header" | "footer"
enabled boolean

void


setSampleData(data): void;
Parameter Type
data unknown

void


setStyle(name, style): void;

Creates or replaces a named style.

Parameter Type
name string
style StyleProps

void


setTextAlign(textAlign, ids?): void;

Sets the horizontal text alignment of the selected text components.

Parameter Type
textAlign "left" | "center" | "right" | "justify"
ids string[]

void


setVerticalAlign(verticalAlign, ids?): void;

Sets the vertical text alignment of the selected text components.

Parameter Type
verticalAlign "top" | "middle" | "bottom"
ids string[]

void


subscribe(listener): () => void;
Parameter Type
listener Listener

() => void


textAlignment(ids?): object;

Effective content alignment of the selected text components (named style and inline style applied). A value is null when the components differ or no text component is selected.

Parameter Type
ids string[]

object

Name Type
textAlign "left" | "center" | "right" | "justify" | null
verticalAlign "top" | "middle" | "bottom" | null

toJSON(pretty?): string;

Template as JSON text.

Parameter Type Default value
pretty boolean true

string


undo(): void;

void


updateBand(bandId, patch): void;
Parameter Type
bandId string
patch Partial<Omit<Band, "id" | "components">>

void


updateComponent(id, patch): void;

Replaces properties of a component. Use updateComponentStyle for style changes.

Parameter Type
id string
patch Partial<ReportComponent>

void


updateComponentStyle(patch, ids?): void;

Merges style properties into the selected (or given) components. undefined removes a property.

Parameter Type
patch Partial<Record<keyof StyleProps, unknown>>
ids string[]

void


updateDataSource(name, patch): void;

Updates a data source. Renaming also updates regions that use it.

Parameter Type
name string
patch Partial<DataSourceDefinition>

void


updateGroup(groupId, patch): void;
Parameter Type
groupId string
patch Partial<Pick<Group, "expression" | "sortDirection" | "pageBreakBefore">>

void


updateParameter(name, patch): void;
Parameter Type
name string
patch Partial<ParameterDefinition>

void


updateRegion(regionId, patch): void;
Parameter Type
regionId string
patch Partial<Omit<DataRegion, "kind" | "id" | "detail" | "header" | "footer" | "groups" | "children">>

void


updateSettings(patch): void;
Parameter Type
patch Partial<DesignerSettings>

void


updateTemplate(patch): void;

Updates top-level template fields. Changing unit converts every length.

Parameter Type
patch Partial<Pick<ReportTemplate, "name" | "description" | "locale" | "page" | "unit">>

void