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
tsclass GrafloriaFlowElement extends HTMLElementBase
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): void
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) | 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) | ||
finalize | (api: unknown) | ||
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. This is the SAME Map instance the handle drives (handle.binderOf returns from it), so the two can never disagree — boards is now derived from the handle's own binders rather than a parallel copy. | |
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. INERT (empty views, every op a no-op) for a document that is not a dashboard — an ER/UML load carries no | |
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
tstype RenderOptions = Omit<CreateDiagramOptions, 'nodes' | 'edges'>;
RenderSpec
tstype RenderSpec = DiagramSpec | DashboardSpec | KitDiagramSpec | string;
SavedDiagram
Anything DiagramSerializer.deserialize() accepts, or the JSON string of it.
tstype SavedDiagram =
| SerializedDiagramData
| DiagramDocumentEnvelope
| Record<string, unknown>
| string;
Was this page helpful?