Import these from @grafloria/engine.
Functions
createTemplateLibrary
Create a new template library instance Factory function for creating template library managers
tsfunction createTemplateLibrary(includeBuiltIn = true): TemplateLibraryManager
Parameters
includeBuiltIn: Whether to include built-in templates (default: true)
Returns New template library manager instance
getAllTemplates
Get all templates as an array
tsfunction getAllTemplates(): NodeTemplate[]
getTemplatesByCategory
Get templates grouped by category
tsfunction getTemplatesByCategory(): Record<TemplateCategory, NodeTemplate[]>
getUnregisteredTemplates
Check if templates are registered in a TemplateRegistry
tsfunction getUnregisteredTemplates(registry: TemplateRegistry): string[]
Example
typescriptconst missing = getUnregisteredTemplates(engine.templateRegistry);
if (missing.length > 0) {
console.log('Missing templates:', missing);
registerTemplateLibrary(engine.templateRegistry);
}
initializeTemplateLibrary
Initialize a template library with all built-in templates
tsfunction initializeTemplateLibrary(manager?: TemplateLibraryManager): TemplateLibraryManager
Parameters
manager: Library manager to populate (optional, creates new if not provided)
Returns Populated template library manager
registerCustomTemplate
Create a custom template and register it
tsfunction registerCustomTemplate(
template: NodeTemplate,
category: TemplateCategory,
tags: string[] = []
): void
registerTemplateLibrary
Use this to make the template library available to NodeFactory:
tsfunction registerTemplateLibrary(registry: TemplateRegistry): number
Returns Number of templates registered
Example
typescriptimport { registerTemplateLibrary } from '@grafloria/engine';
// In your engine setup
const count = registerTemplateLibrary(engine.templateRegistry);
// count = 20 (number of templates registered)
// Now you can use templates with NodeFactory
const node = engine.nodeFactory.createFromTemplate(
'user-avatar',
{ name: 'John', status: 'online' },
{ x: 100, y: 100 }
);
registerTemplatesByCategory
Register templates from a specific category
tsfunction registerTemplatesByCategory(
registry: TemplateRegistry,
category: 'common' | 'workflow' | 'data-viz' | 'diagram' | 'erd'
): number
Returns Number of templates registered
Example
typescript// Only register workflow templates
const count = registerTemplatesByCategory(engine.templateRegistry, 'workflow');
// count = 7 (number of workflow templates)
registerTemplatesById
Register specific templates by ID
tsfunction registerTemplatesById(
registry: TemplateRegistry,
templateIds: string[]
): TemplateRegistrationResult
Returns Registration result with counts and missing template IDs
Example
typescript// Only register specific templates
const result = registerTemplatesById(engine.templateRegistry, [
'user-avatar',
'card-node',
'process-step'
]);
// result = { registered: 3, notFound: [], total: 3 }
Constants
CommonTemplates
Export all common templates
tsconst CommonTemplates: { UserAvatar: NodeTemplate; CardNode: NodeTemplate; ButtonNode: NodeTemplate; InputField: NodeTemplate; BadgeLabel: NodeTemplate; IconNode: NodeTemplate; }
DataVizTemplates
Export all data visualization templates
tsconst DataVizTemplates: { MetricCard: NodeTemplate; Gauge: NodeTemplate; BarChart: NodeTemplate; DataTable: NodeTemplate; PieChart: NodeTemplate; StatCounter: NodeTemplate; ProgressBar: NodeTemplate; }
ERDTemplates
Export all ERD templates
tsconst ERDTemplates: { ERDTable: NodeTemplate; ERDField: NodeTemplate; ERDRelationship: NodeTemplate; ERDTableOptionA: NodeTemplate; ERDFieldOptionA: NodeTemplate; ERDTableContainerOptionB: NodeTemplate; ERDTableHeaderOptionB: NodeTemplate; ERDFieldOptionB: NodeTemplate; ERDTableRepeater: NodeTemplate; }
TemplateLibrary
Global template library instance (backward compatible) Uses lazy initialization via getter
tsconst TemplateLibrary: TemplateLibraryManager
WorkflowTemplates
Export all workflow templates
tsconst WorkflowTemplates: { ProcessStep: NodeTemplate; DecisionNode: NodeTemplate; StartEvent: NodeTemplate; EndEvent: NodeTemplate; Subprocess: NodeTemplate; Gateway: NodeTemplate; Activity: NodeTemplate; }
Interfaces
TemplateInfo
Template metadata for discovery
tsinterface TemplateInfo
Properties
| Name | Type | Default | Description |
|---|---|---|---|
template | NodeTemplate | ||
category | TemplateCategory | ||
tags | string[] |
Types
TemplateCategory
Also has every member of String, listed on its own entry.
Template categories for organization
tstype TemplateCategory = 'common' | 'workflow' | 'data-viz' | 'diagram' | 'erd';
Other exports
Activity
tsActivity
BadgeLabel
tsBadgeLabel
BarChart
tsBarChart
ButtonNode
tsButtonNode
CardNode
tsCardNode
DataTable
tsDataTable
DecisionNode
tsDecisionNode
EndEvent
tsEndEvent
ERDField
tsERDField
ERDRelationship
tsERDRelationship
ERDTable
tsERDTable
Gateway
tsGateway
Gauge
tsGauge
IconNode
tsIconNode
InputField
tsInputField
MetricCard
tsMetricCard
PieChart
tsPieChart
ProcessStep
tsProcessStep
ProgressBar
tsProgressBar
StartEvent
tsStartEvent
StatCounter
tsStatCounter
Subprocess
tsSubprocess
UserAvatar
tsUserAvatar
Was this page helpful?