IBuilderProperties interface
đ Descriptionâ
Properties interface for configuring the builder instance. This interface is used when constructing a new builder instance.
đ Type declarationâ
interface IBuilderProperties { element?: HTMLElement;Optional fonts?: string | "inherit";Optional locale?: L10n.ILocale;Optional translations?: L10n.TTranslation | L10n.TTranslation[];Optional namespace?: { identifier: string; umd?: string; url?: string; onLoad?: (namespace: INamespace) => void; };Optional tier?: IBuilderTier;Optional license?: string;Optional zoom?: "1:1" | "fit" | "fit-horizontal" | "fit-vertical";Optional centering?: boolean;Optional controls?: "left" | "right";Optional rubberBandEffect?: "always" | true | false;Optional disableResizing?: boolean;Optional disablePrologue?: boolean;Optional disableEpilogue?: boolean;Optional disableNesting?: boolean;Optional disableZoombar?: boolean;Optional disableLogo?: boolean;Optional disableSaveButton?: boolean;Optional disableRestoreButton?: boolean;Optional disableClearButton?: boolean;Optional disableEditButton?: boolean;Optional disableCloseButton?: boolean;Optional disableTutorialButton?: boolean;Optional disableOpenCloseAnimation?: boolean;Optional showTutorial?: boolean;Optional previewURL?: string;Optional supportURL?: string | false;Optional nestedFormMode?: boolean;Optional disableFormAbort?: boolean;Optional disableCreateEmptyForm?: boolean;Optional disableConvertToForm?: boolean;Optional disableMoveToForm?: boolean;Optional browseFormsLabel?: string;Optional saveFormLabel?: string;Optional helpTopics?: { prologue?: string; epilogue?: string; branches?: string; conditions?: string; culling?: string; terminators?: string; [topic: string]: string | undefined; };Optional onLoad?: (builder: Builder) => void;EventOptional onError?: (erroneousBlocks: number, missingBlockTypes: string[], builder: Builder) => void;EventOptional onReady?: (builder: Builder) => void;EventOptional onOpen?: (builder: Builder) => void;EventOptional onSave?: (definition: IDefinition, builder: Builder) => void | Promise<void>;EventOptional onChange?: (definition: IDefinition, builder: Builder) => void | Promise<void>;EventOptional onPreview?: (definition: IDefinition, builder: Builder) => void;EventOptional onEdit?: (data: TBuilderEditData) => void;EventOptional onClose?: (builder: Builder) => void;EventOptional onOpenForm?: (definition: INestedDefinition, layer: Layer) => Promise<INestedDefinition | string | void> | boolean | void;EventOptional onListForms?: TFormsList | (() => TFormsList | Promise<TFormsList>);EventOptional onBrowseForms?: (element: Element, layer: Layer) => Promise<INestedDefinition | string>;EventOptional onLoadForm?: (reference: string) => INestedDefinition | undefined | Promise<INestedDefinition>;EventOptional onUpdateForm?: (reference: string, version?: string) => boolean | Promise<boolean>;EventOptional onSaveForm?: (definition: INestedDefinition, element: Element, layer: Layer) => Promise<{ reference: string; version?: string; readonly?: boolean; } | string>;EventOptional onBreadcrumb?: ( forms: { name: string; edit: () => void; activate: () => void; close: () => void; }[], back: (() => void) | undefined ) => void;EventOptional onMenu?: ( type: "node" | "section" | "branch" | "condition", options: MenuOption[], reference: Node | Section | Branch | Condition ) => MenuOption[];EventOptional }
đī¸ Propertiesâ
đˇī¸ browseFormsLabel
â
Specifies an alternative label for the browse forms feature (default is Browse forms
).
Typeâ
string
đˇī¸ centering
â
Specifies if the content in the builder is centered instead of left-aligned (default is true
).
Typeâ
boolean
đˇī¸ controls
â
Specifies the location of the navigation and zoombar (default is right
).
Typeâ
"left" | "right"
đˇī¸ disableClearButton
â
Disables the clear button in the navigation bar (default is true
). When the clear button is pressed, the whole form is removed and a new empty one is created.
Typeâ
boolean
đˇī¸ disableCloseButton
â
Disables the close button in the navigation bar. The close button closes the builder and invokes the onClose
event.
Typeâ
boolean
đˇī¸ disableConvertToForm
â
Disables the possibility to convert sections into nested forms or vice-versa.
Typeâ
boolean
đˇī¸ disableCreateEmptyForm
â
Disables the possibility to create new (empty) nested forms.
Typeâ
boolean
đˇī¸ disableEditButton
â
Disables the edit button in the navigation bar. The edit button opens the form properties editor panel, where the name, language, description, and keywords of the form are managed.
Typeâ
boolean
đˇī¸ disableEpilogue
â
Specifies if the epilogue feature should be disabled. The epilogue is the closing message that is shown when a form is completed. If you don't need this feature, you should disable it so that users cannot access it in the builder.
Typeâ
boolean
đˇī¸ disableFormAbort
â
Disables the possibility to abort the whole form in nested forms. Nested forms can then only return to the parent form, but never end the whole form.
Typeâ
boolean
đˇī¸ disableLogo
â
Disables the Tripetto logo in the navigation bar.
Typeâ
boolean
đˇī¸ disableMoveToForm
â
Disables the possibility to move sections to existing nested forms.
Typeâ
boolean
đˇī¸ disableNesting
â
Specifies if creating new nested branches (subforms) should be disabled.
Typeâ
boolean
đˇī¸ disableOpenCloseAnimation
â
Disables the open and close animation of the builder. When the builder is opened or closed a zoom animation can be used.
Typeâ
boolean
đˇī¸ disablePrologue
â
Specifies if the prologue feature should be disabled. The prologue is the welcome message that is shown before a form starts. If you don't need this feature, you should disable it so that users cannot access it in the builder.
Typeâ
boolean
đˇī¸ disableResizing
â
Disables automatic resizing when the dimensions of the HTML element that holds the builder are changed. If you set this to true
you should invoke the resize
function of the builder instance whenever the parent element is resized.
Typeâ
boolean
See this guide for more information about handling resizing.
đˇī¸ disableRestoreButton
â
Disables the restore button in the navigation bar (default is true
). The restore button restores a form to the previous saved state. So this will undo any changes made to the form since the last save action was called.
Typeâ
boolean
đˇī¸ disableSaveButton
â
Disables the save button in the navigation bar.
Typeâ
boolean
đˇī¸ disableTutorialButton
â
Disables the tutorial button in the navigation bar.
Typeâ
boolean
đˇī¸ disableZoombar
â
Disables the visual zoombar that is shown when the form exceeds the size of the builder viewport.
Typeâ
boolean
đˇī¸ element
â
Host HTML element for the builder. The builder renders inside this element. If omitted, the builder renders in the document body element.
Typeâ
When you specify a custom HTML element for the builder, you need to make sure to set the position
style attribute of that element to absolute
, relative
, fixed
, or sticky
. Otherwise, it is possible that the builder is displayed outside of the element boundaries.
đˇī¸ fonts
â
Specifies the path to the folder with the font files. The Tripetto builder requires these font files, and they are included in the builder package in the fonts
folder. If you don't specify a value for this property, the fonts will be loaded from the unpkg CDN. We recommend to copy the font files to the static asset folder of your project and then supply a relative path or an absolute URL to those files. You can also supply inherit
if you take care of the font loading yourself.
Typeâ
string | "inherit"
See this guide for more information about font loading.
đˇī¸ helpTopics
â
Specifies URLs to help topics and enables assistive buttons/links in the builder. You can define as many topics as you like, but the following topics are used in the builder:
prologue
: Help topic about welcome messages;epilogue
: Help topic about closing messages;branches
: Help topic about using branches;conditions
: Help topic about using conditions;culling
: Help topic about branch culling modes;terminators
: Help topic about branch terminators.
Typeâ
{
[topic: string]: string | undefined;
}
Use the getHelpTopic
function to retrieve the topic data.
đˇī¸ license
â
Specifies a license code for the builder.
Typeâ
string
See this guide for more information about licenses.
đˇī¸ locale
â
Specifies the locale data for the builder. The locale data contains localization information to configure the builder for a particular locale. This is used to show the right number and date/time formats in the builder. The builder package comes with all the locales included. Locale information is stored in a JSON file per locale. The locale JSON files are in the locales
folder of the package. You need to load the appropriate locale JSON and feed it to this property. If omitted, the default locale en
is used.
Typeâ
You can only set the locale when creating a new builder instance. If you want to change the locale during runtime, you need to construct a new builder instance.
See this guide for more information about localization.
đˇī¸ namespace
â
Specifies a block namespace object to use or load. This can be used to supply a bundle of blocks that needs to be loaded. The supplied object contains the following properties:
identifier
: Specifies the namespace identifier;umd
: Specifies the UMD bundle code for the namespace;url
: Specifies the URL of the UMD bundle to load;onLoad
: Optional callback invoked when the namespace is loaded.
Typeâ
{
identifier: string;
umd?: string;
url?: string;
onLoad?: (namespace: INamespace) => void;
}
If your application implements a Content Security Policy (CSP) and prohibits the use of eval()
, you should always load namespace block bundles using the url
property. This method uses a Trusted Type policy named tripetto#loader
for loading the bundle, so make sure to whitelist that Trusted Type. More on CSP and Trusted Types can be found in this guide.
See this guide for more information about block loading.
đˇī¸ nestedFormMode
â
Specifies if the builder should run in nested form mode. This disables the use of a prologue or epilogue on the main branch and optimizes the builder for editing forms that can be used as nested forms (subforms).
Typeâ
boolean
đˇī¸ previewURL
â
Specifies the URL of a preview page. When set, a preview button will be shown in the navigation bar. When the user clicks that button, a new tab/window with the supplied URL is loaded.
Typeâ
string
đˇī¸ rubberBandEffect
â
Specifies if the rubber band effect (also known as the elastic overscrolling effect) is enabled for the builder. Can be one of the following values:
always
: Rubber band effect is always enabled, even when the content doesn't exceed the builder viewport (this is the default value);true
: Rubber band effect is enabled when the content exceeds the builder viewport;false
: Rubber band effect is disabled.
Typeâ
"always" | true | false
đˇī¸ saveFormLabel
â
Specifies an alternative label for the save form feature (default is Save
).
Typeâ
string
đˇī¸ showTutorial
â
Shows the tutorial dialog on startup.
Typeâ
boolean
đˇī¸ supportURL
â
Specifies an URL to a custom help or support page or supply false
to disable this button.
Typeâ
string | false
đˇī¸ tier
â
Specifies a tier for the builder. The tier defines which blocks are available for the user or not.
Typeâ
See this guide for more information about using tiers.
đˇī¸ translations
â
Specifies the translations for the builder and blocks. To use the builder in another language, the translation for this language needs to be loaded. Builder translations are bundled with the builder package and stored in the translations
folder. You need to load the appropriate translation JSON and feed it to this property.
This property can also be used to load translations for the blocks. Simply load the block translation JSON files and feed them as an array of translations.
Typeâ
L10n.TTranslation
| L10n.TTranslation[]
You can only set the translations when creating a new builder instance. If you want to change the translation during runtime, you need to construct a new builder instance.
See this guide for more information about localization and translations.
đˇī¸ zoom
â
Specifies the initial zoom state for the builder. It can be one of the following values:
1:1
: Start the builder without zooming out;fit
: Start the builder with a zoom factor so it can fit the entire form (this is the default behavior);fit-horizontal
: Start the builder with a zoom factor so it can fit the form horizontally;fit-vertical
: Start the builder with a zoom factor so it can fit the form vertically.
Typeâ
"1:1" | "fit" | "fit-horizontal" | "fit-vertical"
đĸ Eventsâ
đ onBreadcrumb
â
Invoked everytime when a nested subform is opened or closed in the builder. Useful for rendering a breadcrumb that shows all the opened forms and allows to navigate back to parent form.
When this event is implemented, the default navigation bar to close a subform (this is a floating bar in the builder) will not be shown anymore. So you should use this event to provide an interactive breadcrumb to the user with controls to edit the name of the subform and to close the subform (so it returns to the parent form).
Signatureâ
(
forms: {
name: string;
edit: () => void;
activate: () => void;
close: () => void;
}[],
back: (() => void) | undefined
) => void
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
forms | {...}[] | No | Array with forms to show in the breadcrumb. For each form, the following properties are supplied: - name : Contains the name of the form;- edit : Function to show the form properties editor where the name of the form can be edited;- activate : Function to activate the form if it is not the active form currently;- close : Function to close the form and return to the parent form. |
back | (() => void) | undefined | No | Function to go back to the previous form (this parameter may be undefined when the root form is opened and you cannot go back any further). |
See the Subforms guide for more information.
đ onBrowseForms
â
Invoked when the builder wants to browse for a subform. This allows to implement a custom UI for browsing through the possible forms and select the desired form to load.
Signatureâ
(element: Element, layer: Layer) => Promise<INestedDefinition | string>
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
element | Element | No | Reference to the Element instance. This instance is a wrapper around the actual DOM element of the browser. If you need access to the DOM element itself, use element.HTMLElement . |
layer | Layer | No | Reference to the Layer instance which is the internal layering system of the Tripetto UI. |
Return valueâ
Should return a Promise
that resolves with a definition or reference. To cancel browsing for a form, the promise should reject. When a reference is returned, the builder will invoke the onLoadForm
event to obtain the definition that belongs to that reference.
Exampleâ
import { Builder } from "@tripetto/builder";
const builder = new Builder({
onBrowseForms: (element) =>
new Promise((resolve, reject) => {
const root = ReactDOM.createRoot(element.HTMLElement);
root.render(
<div>
<h1>Browse forms</h1>
<ul>
<li onClick={() => resolve("1")}>Form 1</li>
<li onClick={() => resolve("2")}>Form 2</li>
</ul>
<button onClick={() => reject()}>Cancel</button>
</div>
);
})
});
You can use the browseFormsLabel
property to set a label for the save option in the builder menu.
See the Subforms guide for more information.
đ onChange
â
Invoked when the definition is changed.
Signatureâ
(definition: IDefinition, builder: Builder) => void | Promise<void>
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
definition | IDefinition | No | Contains the changed form definition. |
builder | Builder | No | Reference to the builder instance. |
Return valueâ
When a Promise
is returned the builder goes into a loading state until the promise resolves or rejects.
If you need live (or real-time) saving of form definitions, you should use this event.
You can also use the hook
method to hook into this event.
đ onClose
â
Invoked when the builder is closed.
Signatureâ
(builder: Builder) => void
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
builder | Builder | No | Reference to the builder instance. |
You can also use the hook
method to hook into this event.
đ onEdit
â
Invoked when an editor panel is opened or closed.
Signatureâ
(data: TBuilderEditData) => void
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
data | TBuilderEditData | No | Contains information about the element being edited. |
You can also use the hook
method to hook into this event.
đ onError
â
Invoked when there was an error during loading a form definition. It also gives some details about the number of errors found (that's the number of blocks that could not load) and a list of blocks types that are missing (and the reason for the error).
Signatureâ
(erroneousBlocks: number, missingBlockTypes: string[], builder: Builder) => void
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
erroneousBlocks | number | No | Contains the number of blocks that could not load. |
missingBlockTypes | string[] | No | Contains an array of block type identifiers that are missing. |
builder | Builder | No | Reference to the builder instance. |
You can also use the hook
method to hook into this event.
đ onListForms
â
Invoked when the builder needs the list of forms that can be used as subform. This list is shown to the builder user when a new subform is about to be created. The list can contain forms, categories, and dividers. The TFormsList
type describes the format for the list structure. You can either supply the list as value for the onListForms
property, return it from a function, or use a Promise
(in case you need asynchronous loading of the list).
Signatureâ
TFormsList | (() => TFormsList | Promise<TFormsList>)
Usageâ
The TFormsList
type is used to define the list of forms. This is an array that allows the following types of items:
Formsâ
Forms can be defined using a reference or the actual definition for the subform. When a reference is supplied, the builder will invoke the onLoadForm
event to obtain the definition that belongs to that reference.
Specify a form by referenceâ
{
/* Name of the form. */
name: string;
/* Reference (identifier) of the form. */
reference: string
}
This requires the onLoadForm
event to load the actual form definition.
Specify a form by its definitionâ
{
/* Name of the form. */
name: string;
/* Definition of the form. */
definition: INestedDefinition | (() => INestedDefinition | Promise<INestedDefinition>)
}
You can either supply a form definition, or a function that returns a form definition, or a promise to a form definition. The latter is useful when you want to retrieve the form definition from an API or other asynchronous process when the user selects the form in the list.
Categoriesâ
Categories can be used to organize forms. This is a recursive structure, so it can be used to define subcategories. You can create as many levels as you want.
{
/* Name of the category. */
category: string;
/* Items for the category. */
forms: TFormsList;
}
Dividersâ
Dividers can be used to create sections in the menu. Each section is divided by a separator (line) and the name of the divider.
{
/* Name of the divider. */
divider: string;
}
Exampleâ
import { Builder } from "@tripetto/builder";
const builder = new Builder({
onListForms: [
{
divider: "Recently used forms"
},
{
name: "Form 1",
reference: "1"
},
{
name: "Form 2",
reference: "2"
},
{
divider: "Your forms library"
},
{
category: "Contact forms",
forms: [
{
name: "Form 3",
reference: "3"
},
]
},
{
category: "Quotation forms",
forms: []
},
]
});
See the Subforms guide for more information.
đ onLoad
â
Invoked when the builder is loading.
Signatureâ
(builder: Builder) => void
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
builder | Builder | No | Reference to the builder instance. |
You can also use the hook
method to hook into this event.
đ onLoadForm
â
Invoked when the builder wants to load a certain subform.
Signatureâ
(reference: string) => INestedDefinition | undefined | Promise<INestedDefinition>
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
reference | string | No | Reference of the form to load. |
Return valueâ
Should return a INestedDefinition
object or undefined
if the form could not be loaded. You may also return a Promise
that resolves with the definition or rejects when the load failed.
Exampleâ
import { Builder } from "@tripetto/builder";
const builder = new Builder({
onLoadForm: (reference) =>
new Promise((resolve, reject) => {
fetch("/api/form/get/" + reference)
.then((response) => response.json())
.then((data) => resolve(data))
.catch(() => reject());
})
});
See the Subforms guide for more information.
đ onMenu
â
Invoked when the context menu of a node, section, branch, or condition is requested. This event receives both a reference to the context and the layout of an item. The context serves as the model of the item in the definition and the layout as the view of the item in the UI. Most actions (like adding, reordering, or deleting items) are performed on the model (so using the context
parameter), but some actions are initated using the layout. Hence the reason why it is supplied as parameter to this event.
The most common action that should be invoked from the layout is opening the editor panel of an item in the builder. This is done by calling the layout.edit()
method.
This event can be used to alter the default menus used by the builder. If you do this, always make sure to verify your implementation when you update the builder to a new version. Changes in the default context menus might require updates to your code.
Signatureâ
(
type: "node" | "section" | "branch" | "condition",
options: MenuOption[],
context: Node | Section | Branch | Condition,
layout: NodeLayout | SectionLayout | BranchLayout | ConditionLayout
) => MenuOption[]
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
type | "node" | "section" | "branch" | "condition" | No | Specifies the type of context menu. |
options | MenuOption[] | No | Contains the default context menu options. |
context | Node | Section | Branch | Condition | No | Reference to the item for which the context menu is. |
layout | NodeLayout | SectionLayout | BranchLayout | ConditionLayout | No | Reference to the layout of the context. |
Return valueâ
Should return an array with menu options.
đ onOpen
â
Invoked when the builder is opened and shown to the user.
Signatureâ
(builder: Builder) => void
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
builder | Builder | No | Reference to the builder instance. |
You can also use the hook
method to hook into this event.
đ onOpenForm
â
Invoked when the builder wants to open a subform for editing.
Signatureâ
(definition: INestedDefinition, layer: Layer) =>
Promise<INestedDefinition | string | void> | boolean | void
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
definition | INestedDefinition | No | Reference to form definition of the subform (this is an immutable version of the definition). |
layer | Layer | No | Reference to the Layer instance which is the internal layering system of the Tripetto UI. |
Return valueâ
There are three options for the return value of this event:
- Return nothing (
void
) when you want to use this event to track opening a subform, but don't want to change the default editing behavior; - A boolean value to indicate if the default editing behavior should execute (return
true
if the subform should be opened or returnfalse
to disallow opening the subform); - A
Promise
to indicate to the builder that you are controlling the opening of the form. Resolve the promise when the editing of the form ends. Optionally you can resolve with the updated definition (or the reference of the updated definition in case you've implemented theonLoadForm
event). As long as the promise is not resolved or rejected, the builder will remain in a waiting state where no user interaction is allowed.
đ onPreview
â
Invoked when a definition preview should be updated.
Signatureâ
(definition: IDefinition, builder: Builder) => void
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
definition | IDefinition | No | Contains the changed form definition. |
builder | Builder | No | Reference to the builder instance. |
You can also use the hook
method to hook into this event.
đ onReady
â
Invoked when the builder is ready loading.
Signatureâ
(builder: Builder) => void
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
builder | Builder | No | Reference to the builder instance. |
You can also use the hook
method to hook into this event.
đ onSave
â
Invoked when the definition is saved. This happens when the user clicks the save button in the Tripetto toolbar.
Signatureâ
(definition: IDefinition, builder: Builder) => void | Promise<void>
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
definition | IDefinition | No | Contains the form definition to save. |
builder | Builder | No | Reference to the builder instance. |
Return valueâ
When a Promise
is returned the builder goes into a loading state until the promise resolves or rejects.
It is possible to disable the save button (or the whole toolbar). Then you can use the 'save' method to initiate a save action or use the onChange
event for real-time monitoring changes in the form definition.
You can also use the hook
method to hook into this event.
đ onSaveForm
â
Invoked when the builder wants to save a subform. This event allows to implement a custom UI with a save dialog.
Signatureâ
(definition: INestedDefinition, element: Element, layer: Layer) => Promise<{
reference: string;
version?: string;
readonly?: boolean;
} | string>
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
definition | INestedDefinition | No | Reference to form definition. |
element | Element | No | Reference to the Element instance. This instance is a wrapper around the actual DOM element of the browser. If you need access to the DOM element itself, use element.HTMLElement . |
layer | Layer | No | Reference to the Layer instance which is the internal layering system of the Tripetto UI. |
Return valueâ
Should return a Promise
that resolves with a string that contains the reference of the saved form, or an object with the reference
, version
, and readonly
properties for the saved form.
You can use the saveFormLabel
property to set a label for the save option in the builder menu.
See the Subforms guide for more information.
đ onUpdateForm
â
Invoked when the builder wants to know if there is an update available for a certain form.
Signatureâ
(reference: string, version?: string) => boolean | Promise<boolean>
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
reference | string | No | Reference of the form to verify. |
version | string | No | Version of the form that is currently loaded. |
Return valueâ
Should return true
if there is an update available for the form (the update button in the builder becomes available) or false
when there is no newer version of the form available. You may also return a Promise
that resolves with the result.
See the Subforms guide for more information.