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.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new DesignerController(options?): DesignerController;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options |
DesignerControllerOptions |
Returns
Section titled “Returns”DesignerController
Accessors
Section titled “Accessors”redoLabel
Section titled “redoLabel”Get Signature
Section titled “Get Signature”get redoLabel(): string | null;Returns
Section titled “Returns”string | null
template
Section titled “template”Get Signature
Section titled “Get Signature”get template(): ReportTemplate;Returns
Section titled “Returns”undoLabel
Section titled “undoLabel”Get Signature
Section titled “Get Signature”get undoLabel(): string | null;Label of the change that undo would revert.
Returns
Section titled “Returns”string | null
Methods
Section titled “Methods”addChildRegion()
Section titled “addChildRegion()”addChildRegion(parentRegionId, source): string;Adds a nested (master-detail) region. Pass { relation: 'items' } or { dataSource: 'notes' }.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
parentRegionId |
string |
source |
| { relation: string; } | { dataSource: string; } |
Returns
Section titled “Returns”string
addComponent()
Section titled “addComponent()”addComponent<T>( bandId, type, overrides?): string;Adds a component to a band and selects it. Returns its id.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T extends "text" | "image" | "line" | "rectangle" |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
bandId |
string |
type |
T |
overrides |
Partial< | Extract<TextComponent, { type: T; }> | Extract<ImageComponent, { type: T; }> | Extract<LineComponent, { type: T; }> | Extract<RectangleComponent, { type: T; }>> |
Returns
Section titled “Returns”string
addDataRegion()
Section titled “addDataRegion()”addDataRegion(dataSource, index?): string;Inserts a data region bound to a data source. Returns the region id.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
dataSource |
string |
index? |
number |
Returns
Section titled “Returns”string
addDataSource()
Section titled “addDataSource()”addDataSource(def): void;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
def |
DataSourceDefinition |
Returns
Section titled “Returns”void
addGroup()
Section titled “addGroup()”addGroup(regionId, expression): string;Adds a group to a region (as the innermost group). Returns the group id.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
regionId |
string |
expression |
string |
Returns
Section titled “Returns”string
addParameter()
Section titled “addParameter()”addParameter(def): void;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
def |
ParameterDefinition |
Returns
Section titled “Returns”void
addStaticBand()
Section titled “addStaticBand()”addStaticBand(index?): string;Inserts a static band into the body at index (end by default). Returns its id.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
index? |
number |
Returns
Section titled “Returns”string
align()
Section titled “align()”align(alignment): void;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
alignment |
Alignment |
Returns
Section titled “Returns”void
beginInteraction()
Section titled “beginInteraction()”beginInteraction(label): void;Starts a drag or resize. Changes until endInteraction() become one undo step.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
label |
string |
Returns
Section titled “Returns”void
bodyWidth()
Section titled “bodyWidth()”bodyWidth(): number;Width of the printable body in template units: components should stay within it.
Returns
Section titled “Returns”number
cancelInteraction()
Section titled “cancelInteraction()”cancelInteraction(): void;Returns
Section titled “Returns”void
checkExpression()
Section titled “checkExpression()”checkExpression(source): string | null;Checks expression syntax; null when valid.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
source |
string |
Returns
Section titled “Returns”string | null
clearSelection()
Section titled “clearSelection()”clearSelection(): void;Returns
Section titled “Returns”void
completions()
Section titled “completions()”completions(bandId?): string[];Names available in expressions inside a band, for autocompletion:
scope variables, data sources, parameters and row fields.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
bandId? |
string |
Returns
Section titled “Returns”string[]
copy()
Section titled “copy()”copy(): number;Returns
Section titled “Returns”number
cut(): number;Returns
Section titled “Returns”number
distribute()
Section titled “distribute()”distribute(axis): void;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
axis |
"horizontal" | "vertical" |
Returns
Section titled “Returns”void
duplicate()
Section titled “duplicate()”duplicate(): string[];Returns
Section titled “Returns”string[]
endInteraction()
Section titled “endInteraction()”endInteraction(): void;Returns
Section titled “Returns”void
getSampleData()
Section titled “getSampleData()”getSampleData(): unknown;Returns
Section titled “Returns”unknown
getState()
Section titled “getState()”getState(): DesignerState;Returns
Section titled “Returns”handleKey()
Section titled “handleKey()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
e |
KeyInput |
Returns
Section titled “Returns”boolean
inferDataSourceFields()
Section titled “inferDataSourceFields()”inferDataSourceFields(name): number;Infers a data source’s fields from the sample data. Returns the field count.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
name |
string |
Returns
Section titled “Returns”number
insertField()
Section titled “insertField()”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”.
Parameters
Section titled “Parameters”| 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' |
Returns
Section titled “Returns”string
load()
Section titled “load()”load(template): void;Replaces the template (e.g. after opening a file). Clears history. Throws for invalid templates.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
template |
string | ReportTemplate |
Returns
Section titled “Returns”void
markSaved()
Section titled “markSaved()”markSaved(): void;Marks the current template as saved (clears dirty).
Returns
Section titled “Returns”void
matchSize()
Section titled “matchSize()”matchSize(dimension): void;Gives the selected components the same width and/or height as the first one.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
dimension |
"height" | "width" | "both" |
Returns
Section titled “Returns”void
moveBodyItem()
Section titled “moveBodyItem()”moveBodyItem(fromIndex, toIndex): void;Moves a top-level body item (static band or region) to another position.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
fromIndex |
number |
toIndex |
number |
Returns
Section titled “Returns”void
moveComponents()
Section titled “moveComponents()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
ids |
string[] |
undefined |
dx |
number |
undefined |
dy |
number |
undefined |
snap |
boolean |
true |
Returns
Section titled “Returns”void
moveComponentsToBand()
Section titled “moveComponentsToBand()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
ids |
string[] |
undefined |
bandId |
string |
undefined |
dx |
number |
undefined |
dy |
number |
undefined |
snap |
boolean |
true |
Returns
Section titled “Returns”void
moveComponentToBand()
Section titled “moveComponentToBand()”moveComponentToBand( id, bandId, x, y): void;Moves a component to another band at the given position (band coordinates).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
bandId |
string |
x |
number |
y |
number |
Returns
Section titled “Returns”void
moveGroup()
Section titled “moveGroup()”moveGroup(groupId, direction): void;Moves a group one level out (-1) or in (+1).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
groupId |
string |
direction |
-1 | 1 |
Returns
Section titled “Returns”void
nudge()
Section titled “nudge()”nudge( dxSteps, dySteps, fine?): void;Moves the selection by a small step (arrow keys). Uses the grid unless fine is true.
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
dxSteps |
number |
undefined |
dySteps |
number |
undefined |
fine |
boolean |
false |
Returns
Section titled “Returns”void
pageSize()
Section titled “pageSize()”pageSize(): object;Page size in template units, with the orientation applied.
Returns
Section titled “Returns”object
| Name | Type |
|---|---|
height |
number |
width |
number |
paste()
Section titled “paste()”paste(bandId?): string[];Pastes into the selected band (or bandId), offset when pasting into the same place. Returns new ids.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
bandId |
string | null |
Returns
Section titled “Returns”string[]
preview()
Section titled “preview()”preview(options?): object;Generates the report with the sample data. Errors are returned, not thrown.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options |
GenerateOptions |
Returns
Section titled “Returns”object
| Name | Type |
|---|---|
document |
LayoutDocument | null |
error |
Error | null |
redo()
Section titled “redo()”redo(): void;Returns
Section titled “Returns”void
regionFields()
Section titled “regionFields()”regionFields(region): FieldDefinition[] | undefined;Field schema of the rows a region iterates (from the data source or the parent’s relation).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
region |
DataRegion |
Returns
Section titled “Returns”FieldDefinition[] | undefined
removeBand()
Section titled “removeBand()”removeBand(bandId): boolean;Removes a band. Detail bands cannot be removed on their own: remove the region instead. Returns false when nothing was removed.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
bandId |
string |
Returns
Section titled “Returns”boolean
removeComponents()
Section titled “removeComponents()”removeComponents(ids?): void;Removes the selected (or given) components.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
ids |
string[] |
Returns
Section titled “Returns”void
removeDataSource()
Section titled “removeDataSource()”removeDataSource(name): void;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
name |
string |
Returns
Section titled “Returns”void
removeGroup()
Section titled “removeGroup()”removeGroup(groupId): void;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
groupId |
string |
Returns
Section titled “Returns”void
removeParameter()
Section titled “removeParameter()”removeParameter(name): void;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
name |
string |
Returns
Section titled “Returns”void
removeRegion()
Section titled “removeRegion()”removeRegion(regionId): void;Removes a data region with all its bands and children.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
regionId |
string |
Returns
Section titled “Returns”void
removeStyle()
Section titled “removeStyle()”removeStyle(name): void;Removes a named style and detaches components that used it.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
name |
string |
Returns
Section titled “Returns”void
renameStyle()
Section titled “renameStyle()”renameStyle(from, to): void;Renames a named style and updates components that use it.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
from |
string |
to |
string |
Returns
Section titled “Returns”void
reorder()
Section titled “reorder()”reorder(where): void;Changes paint order: components later in the band list are drawn on top.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
where |
"front" | "back" | "forward" | "backward" |
Returns
Section titled “Returns”void
resizeBand()
Section titled “resizeBand()”resizeBand(bandId, height): void;Resizes a band by dragging its bottom edge; height is in template units.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
bandId |
string |
height |
number |
Returns
Section titled “Returns”void
resizeComponent()
Section titled “resizeComponent()”resizeComponent( id, handle, dx, dy): void;Resizes a component with a handle; inside an interaction the delta is measured from the drag start.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
handle |
ResizeHandle |
dx |
number |
dy |
number |
Returns
Section titled “Returns”void
resizeComponents()
Section titled “resizeComponents()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
ids |
string[] |
handle |
ResizeHandle |
dx |
number |
dy |
number |
Returns
Section titled “Returns”void
sections()
Section titled “sections()”sections(labels?): DesignSection[];Bands in design order. Pass translated labels for localized captions.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
labels? |
SectionLabels |
Returns
Section titled “Returns”select()
Section titled “select()”select(ids, mode?): void;Selects components. Components must share a band; selecting a component from another band replaces the selection.
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
ids |
string[] |
undefined |
mode |
"replace" | "add" | "toggle" |
'replace' |
Returns
Section titled “Returns”void
selectAll()
Section titled “selectAll()”selectAll(bandId?): void;Selects every component in a band (the selected band by default).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
bandId |
string | null |
Returns
Section titled “Returns”void
selectBand()
Section titled “selectBand()”selectBand(bandId): void;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
bandId |
string | null |
Returns
Section titled “Returns”void
selectedComponents()
Section titled “selectedComponents()”selectedComponents(): ReportComponent[];Selected components, in selection order.
Returns
Section titled “Returns”selectInBands()
Section titled “selectInBands()”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).
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
rects |
object[] |
undefined |
additive |
boolean |
false |
Returns
Section titled “Returns”void
selectInRect()
Section titled “selectInRect()”selectInRect( bandId, rect, additive?): void;Rubber-band selection inside one band; rect is in band coordinates.
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
bandId |
string |
undefined |
rect |
Rect |
undefined |
additive |
boolean |
false |
Returns
Section titled “Returns”void
setGroupBand()
Section titled “setGroupBand()”setGroupBand( groupId, which, enabled): void;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
groupId |
string |
which |
"header" | "footer" |
enabled |
boolean |
Returns
Section titled “Returns”void
setPageBand()
Section titled “setPageBand()”setPageBand(slot, enabled): string | null;Adds or removes a report/page header or footer.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
slot |
PageBandSlot |
enabled |
boolean |
Returns
Section titled “Returns”string | null
setRegionBand()
Section titled “setRegionBand()”setRegionBand( regionId, which, enabled): void;Adds or removes a region’s header or footer band.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
regionId |
string |
which |
"header" | "footer" |
enabled |
boolean |
Returns
Section titled “Returns”void
setSampleData()
Section titled “setSampleData()”setSampleData(data): void;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
data |
unknown |
Returns
Section titled “Returns”void
setStyle()
Section titled “setStyle()”setStyle(name, style): void;Creates or replaces a named style.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
name |
string |
style |
StyleProps |
Returns
Section titled “Returns”void
setTextAlign()
Section titled “setTextAlign()”setTextAlign(textAlign, ids?): void;Sets the horizontal text alignment of the selected text components.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
textAlign |
"left" | "center" | "right" | "justify" |
ids |
string[] |
Returns
Section titled “Returns”void
setVerticalAlign()
Section titled “setVerticalAlign()”setVerticalAlign(verticalAlign, ids?): void;Sets the vertical text alignment of the selected text components.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
verticalAlign |
"top" | "middle" | "bottom" |
ids |
string[] |
Returns
Section titled “Returns”void
subscribe()
Section titled “subscribe()”subscribe(listener): () => void;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
listener |
Listener |
Returns
Section titled “Returns”() => void
textAlignment()
Section titled “textAlignment()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
ids |
string[] |
Returns
Section titled “Returns”object
| Name | Type |
|---|---|
textAlign |
"left" | "center" | "right" | "justify" | null |
verticalAlign |
"top" | "middle" | "bottom" | null |
toJSON()
Section titled “toJSON()”toJSON(pretty?): string;Template as JSON text.
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
pretty |
boolean |
true |
Returns
Section titled “Returns”string
undo()
Section titled “undo()”undo(): void;Returns
Section titled “Returns”void
updateBand()
Section titled “updateBand()”updateBand(bandId, patch): void;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
bandId |
string |
patch |
Partial<Omit<Band, "id" | "components">> |
Returns
Section titled “Returns”void
updateComponent()
Section titled “updateComponent()”updateComponent(id, patch): void;Replaces properties of a component. Use updateComponentStyle for style changes.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
patch |
Partial<ReportComponent> |
Returns
Section titled “Returns”void
updateComponentStyle()
Section titled “updateComponentStyle()”updateComponentStyle(patch, ids?): void;Merges style properties into the selected (or given) components. undefined removes a property.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
patch |
Partial<Record<keyof StyleProps, unknown>> |
ids |
string[] |
Returns
Section titled “Returns”void
updateDataSource()
Section titled “updateDataSource()”updateDataSource(name, patch): void;Updates a data source. Renaming also updates regions that use it.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
name |
string |
patch |
Partial<DataSourceDefinition> |
Returns
Section titled “Returns”void
updateGroup()
Section titled “updateGroup()”updateGroup(groupId, patch): void;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
groupId |
string |
patch |
Partial<Pick<Group, "expression" | "sortDirection" | "pageBreakBefore">> |
Returns
Section titled “Returns”void
updateParameter()
Section titled “updateParameter()”updateParameter(name, patch): void;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
name |
string |
patch |
Partial<ParameterDefinition> |
Returns
Section titled “Returns”void
updateRegion()
Section titled “updateRegion()”updateRegion(regionId, patch): void;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
regionId |
string |
patch |
Partial<Omit<DataRegion, "kind" | "id" | "detail" | "header" | "footer" | "groups" | "children">> |
Returns
Section titled “Returns”void
updateSettings()
Section titled “updateSettings()”updateSettings(patch): void;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
patch |
Partial<DesignerSettings> |
Returns
Section titled “Returns”void
updateTemplate()
Section titled “updateTemplate()”updateTemplate(patch): void;Updates top-level template fields. Changing unit converts every length.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
patch |
Partial<Pick<ReportTemplate, "name" | "description" | "locale" | "page" | "unit">> |
Returns
Section titled “Returns”void