Import these from @grafloria/element.
Functions
defineGrafloriaFlow
Register the element. Idempotent, and safe to call on the server (where
customElements does not exist) — which is what lets a bundle be imported
from an SSR entry point without a typeof window dance at every call site.
tsfunction defineGrafloriaFlow(tagName = 'grafloria-flow'): void
fromDocument
Turn a saved document back into something render() can mount.
tsconst json = JSON.stringify(new DiagramSerializer().serialize(api.getModel()));
// …later, in a fresh page:
render(fromDocument(json), host);
Accepts the flat serializer form, the portable envelope, or the JSON string of either.
tsfunction fromDocument(
document: SavedDiagram,
options: FromDocumentOptions = {}
): LoadedDiagramSpec
getNodeType
tsfunction getNodeType(type: string): NodeTypeRenderer | undefined
hasNodeType
tsfunction hasNodeType(type: string): boolean
registeredNodeTypes
Every registered type name.
tsfunction registeredNodeTypes(): string[]
registerNodeType
Register (or replace) a node type globally.
tsfunction registerNodeType(type: string, renderer: NodeTypeRenderer): void
render
Mount spec into target and return the live instance.
target may be an element or a CSS selector. Custom nodes (custom: true)
are rendered by the types registered with {@link registerNodeType}.
SCOPE, stated plainly: spec is data (an object or its JSON), not a Mermaid-
style text DSL. The engine does have a DSL, but wiring it in is a separate
card — render() is the embedding surface, not a parser.
tsfunction render(
spec: RenderSpec,
target: HTMLElement | string,
options: RenderOptions = {}
): DiagramInstance
renderFromTemplate
Render a node from a slotted <template data-node-type="...">.
Clones the template's content into element and substitutes node.data into
every [data-field="key"] descendant's text. Values are written with
textContent, never innerHTML: a diagram's data is frequently
user-supplied, and a template engine that injected raw HTML here would be an
XSS vector in every host that embeds us.
tsfunction renderFromTemplate(
template: HTMLTemplateElement,
node: NodeModel,
element: HTMLElement
): void
renderStatic
Server-side render. Re-exported so the tiny API is self-contained.
tsfunction renderStatic(options: StaticRenderOptions = {}): StaticRenderResult
unregisterNodeType
Drop a registration (mostly for tests).
tsfunction unregisterNodeType(type: string): void
Classes
GrafloriaFlowElement
Also has every member of HTMLElement, Element, Node, ARIAMixin, GlobalEventHandlers, listed on their own entries.
tsclass GrafloriaFlowElement extends HTMLElementBase
Use it as <grafloria-flow> in a template.
Props
| Name | Type | Default | Description |
|---|---|---|---|
nodes? | |||
edges? | |||
theme? | |||
fit-view | |||
readonly? | |||
zoom? | |||
min-zoom | |||
max-zoom | |||
pan? | |||
wheel-zoom | |||
highlight-connected |
Events
grafloria-readygrafloria-nodes-changegrafloria-edges-changegrafloria-selection-changegrafloria-connectgrafloria-node-clickgrafloria-edge-clickgrafloria-viewport-change
Properties
| Name | Type | Default | Description |
|---|---|---|---|
nextElementSibling | Element | null | Returns the first following sibling that is an element, and null otherwise. | |
previousElementSibling | Element | null | Returns the first preceding sibling that is an element, and null otherwise. | |
childElementCount | number | MDN Reference | |
children | HTMLCollection | Returns the child elements. | |
firstElementChild | Element | null | Returns the first child that is an element, and null otherwise. | |
lastElementChild | Element | null | Returns the last child that is an element, and null otherwise. | |
assignedSlot | HTMLSlotElement | null | MDN Reference | |
attributeStyleMap | StylePropertyMap | MDN Reference | |
contentEditable | string | MDN Reference | |
enterKeyHint | string | MDN Reference | |
inputMode | string | MDN Reference | |
isContentEditable | boolean | MDN Reference | |
autofocus | boolean | MDN Reference | |
dataset | DOMStringMap | MDN Reference | |
nonce? | string | MDN Reference | |
tabIndex | number | MDN Reference |
Methods
static get observedAttributes(): string[](static)get nodes(): NodeSpec[]set nodes(value: NodeSpec[])get edges(): EdgeSpec[]set edges(value: EdgeSpec[])get diagram(): DiagramInstance | null— The headless instance — the escape hatch to everything else.connectedCallback(): voiddisconnectedCallback(): voidattributeChangedCallback(name: string, previous: string | null, next: string | null): voidfitView(padding?: number): voiddispatchEvent(event: Event): boolean— ThedispatchEvent()method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order.
animate(keyframes: Keyframe[] | PropertyIndexedKeyframes | null, options?: number | KeyframeAnimationOptions): Animation— MDN ReferencegetAnimations(options?: GetAnimationsOptions): Animation[]— MDN Referenceafter(...nodes: (Node | string)[]): void— Inserts nodes just after node, while replacing strings in nodes with equivalent Text nodes.
Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated.
before(...nodes: (Node | string)[]): void— Inserts nodes just before node, while replacing strings in nodes with equivalent Text nodes.
Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated.
remove(): void— Removes node.
replaceWith(...nodes: (Node | string)[]): void— Replaces node with nodes, while replacing strings in nodes with equivalent Text nodes.
Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated.
append(...nodes: (Node | string)[]): void— Inserts nodes after the last child of node, while replacing strings in nodes with equivalent Text nodes.
Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated.
prepend(...nodes: (Node | string)[]): void— Inserts nodes before the first child of node, while replacing strings in nodes with equivalent Text nodes.
Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated.
querySelector<K extends keyof HTMLElementTagNameMap>(selectors: K): HTMLElementTagNameMap[K] | null— Returns the first element that is a descendant of node that matches selectors.
querySelectorAll<K extends keyof HTMLElementTagNameMap>(selectors: K): NodeListOf<HTMLElementTagNameMap[K]>— Returns all element descendants of node that match selectors.
replaceChildren(...nodes: (Node | string)[]): void— Replace all children of node with nodes, while replacing strings in nodes with equivalent Text nodes.
Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated.
blur(): void— MDN Referencefocus(options?: FocusOptions): void— MDN Reference
Constants
Grafloria
The namespace object, for import { Grafloria } and for <script> globals.
tsconst Grafloria: { render: (spec: RenderSpec, target: string | HTMLElement, options?: RenderOptions) => DiagramInstance; renderStatic: (options?: StaticRenderOptions) => StaticRenderResult; registerNodeType: (type: string, renderer: NodeTypeRenderer) => void; registeredNodeTypes: () => string[]; define: (tagName?: string) => void; }
GRAFLORIA_EVENTS
Events emitted on the element. All bubble and cross shadow boundaries.
tsconst GRAFLORIA_EVENTS: { readonly ready: "grafloria-ready"; readonly nodesChange: "grafloria-nodes-change"; readonly edgesChange: "grafloria-edges-change"; readonly selectionChange: "grafloria-selection-change"; readonly connect: "grafloria-connect"; readonly nodeClick: "grafloria-node-click"; readonly edgeClick: "grafloria-edge-click"; readonly viewportChange: "grafloria-viewport-change"; }
Interfaces
DiagramSpec
What Grafloria.render() accepts: an object spec, or the JSON string of one.
tsinterface DiagramSpec
Properties
| Name | Type | Default | Description |
|---|---|---|---|
nodes? | NodeSpec[] | ||
edges? | EdgeSpec[] | ||
groups? | GroupSpec[] | Zones around some boxes, each with its own frame and caption. See GroupSpec. | |
layout? | 'architecture' | 'architecture': compose the drawing — zones as regions, boxes sized to their words in rows, straight lines where boxes line up. Positions are not needed. |
FromDocumentOptions
tsinterface FromDocumentOptions
Properties
| Name | Type | Default | Description |
|---|---|---|---|
renderWidget? | WidgetRenderer | The app's own widget painter — the same function it passed to dashboard({ renderWidget }). A board authored with a custom painter must be RELOADED with it, or the reload silently drops the app's chrome. | |
renderCustomNode? | (node: NodeModel, host: HTMLElement) => void | Full override of the custom-node painter. Outranks everything. | |
interactive? | boolean | Re-attach kit interaction wiring (row selection, in-canvas editing, the dashboard grid binder). Default true — a loaded diagram should behave like the one that was saved. Pass false for a read-only viewer. |
LoadedDiagramSpec
What {@link fromDocument} returns: a render() spec, plus the way back in.
tsinterface LoadedDiagramSpec
Properties
| Name | Type | Default | Description |
|---|---|---|---|
nodes | NodeModel[] | ||
edges | LinkModel[] | ||
renderCustomNode | (node: NodeModel, host: HTMLElement) => void | ||
finalize | (api: unknown) => void | ||
model | DiagramModel | The deserialized model — the escape hatch, available before any render. | |
boards | Map<string, DashboardGridHandle> | Live grid binders for the boards finalize() re-attached, keyed by group id. Empty for a document that is not a dashboard. | |
handle | DashboardHandle | The dashboard toolbar handle over the reloaded board(s) — the SAME DashboardHandle dashboard() returns, built by the one shared builder so it cannot drift from the authoring surface: addWidget/showView/setSizing/ setColumns/toJSON/exportIds and the widget handles, all live on the reload. | |
renderOptions? | { minZoom?: number; maxZoom?: number } | Instance options the loaded spec asks render() to apply (a fluid board pins zoom). |
Types
NodeTypeRenderer
Fills element with the visual for node. Called once per mounted node.
tstype NodeTypeRenderer = (node: NodeModel, element: HTMLElement) => void;
RenderOptions
Also has every member of CreateDiagramOptions, DomEventBinderOptions, listed on their own entries.
tstype RenderOptions = Omit<CreateDiagramOptions, 'nodes' | 'edges'>;
RenderSpec
tstype RenderSpec = DiagramSpec | DashboardSpec | KitDiagramSpec | string;
Members
toString(): string— Returns a string representation of a string.valueOf(): string— Returns the primitive value of the specified object.
SavedDiagram
Anything DiagramSerializer.deserialize() accepts, or the JSON string of it.
tstype SavedDiagram =
| SerializedDiagramData
| DiagramDocumentEnvelope
| Record<string, unknown>
| string;
Members
toString(): string— Returns a string representation of a string.valueOf(): string— Returns the primitive value of the specified object.
Was this page helpful?