Import these from @grafloria/engine.
Functions
createConnectionGroupValidator
Creates a connection validator that enforces connection group restrictions
Rules:
- Nodes in the same connection group can connect to each other
- Nodes with no connection group can connect to any node
- Nodes in different connection groups cannot connect
Usage:
typescriptconst validator = createConnectionGroupValidator(engine);
connectionStateManager.addValidator(validator);
tsfunction createConnectionGroupValidator(engine: DiagramEngine)
isConnectionAllowedByGroup
Check if a connection between two ports is allowed based on connection groups This is a standalone function that doesn't require a validator to be registered
tsfunction isConnectionAllowedByGroup(
sourcePort: PortModel,
targetPort: PortModel,
engine: DiagramEngine
): boolean
Classes
TypeRegistry
tsclass TypeRegistry
Methods
registerNodeType(definition: NodeTypeDefinition): void— Register a node typeregisterPortType(definition: PortTypeDefinition): void— Register a port typeregisterLinkType(definition: LinkTypeDefinition): void— Register a link typeregisterGroupType(definition: GroupTypeDefinition): void— Register a group typeunregisterNodeType(type: string): boolean— Unregister a node typeunregisterPortType(type: string): boolean— Unregister a port typeunregisterLinkType(type: string): boolean— Unregister a link typeunregisterGroupType(type: string): boolean— Unregister a group typegetNodeType(type: string): NodeTypeDefinition | undefined— Get node type definitiongetPortType(type: string): PortTypeDefinition | undefined— Get port type definitiongetLinkType(type: string): LinkTypeDefinition | undefined— Get link type definitiongetGroupType(type: string): GroupTypeDefinition | undefined— Get group type definitionhasNodeType(type: string): boolean— Check if node type existshasPortType(type: string): boolean— Check if port type existshasLinkType(type: string): boolean— Check if link type existshasGroupType(type: string): boolean— Check if group type existslistNodeTypes(): NodeTypeDefinition[]— List all node typeslistPortTypes(): PortTypeDefinition[]— List all port typeslistLinkTypes(): LinkTypeDefinition[]— List all link typeslistGroupTypes(): GroupTypeDefinition[]— List all group typesclear(): void— Clear all registered typesgetStats(): { nodeTypes: number; portTypes: number; linkTypes: number; groupTypes: number; }— Get type statisticsresolveNodeType(type: string): NodeTypeDefinition— Resolve a node type with all inherited propertiesgetNodeTypesByCategory(category: string): NodeTypeDefinition[]— Get all node types in a categorygetNodeTypesByFamily(family: string): NodeTypeDefinition[]— Get all node types in a familygetNodeTypesByTag(tag: string): NodeTypeDefinition[]— Get all node types with a specific taggetNodeTypesByTemplate(templateId: string): NodeTypeDefinition[]— Get all node types using a specific template Includes types that inherit template ID from parent
ValidationEngine
tsclass ValidationEngine
Methods
constructor(typeRegistry: TypeRegistry, eventBus?: EventBus)enableRealTimeValidation(): void— Enable real-time validationdisableRealTimeValidation(): void— Disable real-time validationisRealTimeValidationEnabled(): boolean— Check if real-time validation is enabledvalidateDiagram( diagram: DiagramModel, options: ValidationOptions = {} ): ValidationResult— Validate entire diagramvalidateNode( node: NodeModel, options: ValidationOptions = {} ): ValidationResult— Validate a nodevalidatePort( port: PortModel, node: NodeModel, options: ValidationOptions = {} ): ValidationResult— Validate a portvalidateLink( link: LinkModel, diagram: DiagramModel, options: ValidationOptions = {} ): ValidationResult— Validate a linkvalidateHierarchy( node: NodeModel, diagram: DiagramModel, options: ValidationOptions = {} ): ValidationResult— Validate node hierarchyvalidateGroup( group: GroupModel, diagram: DiagramModel, options: ValidationOptions = {} ): ValidationResult— Validate groupvalidateLayout( group: GroupModel, diagram: DiagramModel, options: ValidationOptions = {} ): ValidationResult— Validate layout configurationaddRule( entityType: 'diagram' | 'node' | 'port' | 'link', rule: ValidationRule ): void— Add custom validation ruleclearRules(entityType: 'diagram' | 'node' | 'port' | 'link'): void— Remove all custom rules for an entity typeclearAllRules(): void— Clear all custom rulesgetRulesCount(entityType?: 'diagram' | 'node' | 'port' | 'link'): number— Get custom rules count
Interfaces
GroupTypeDefinition
tsinterface GroupTypeDefinition
Properties
| Name | Type | Default | Description |
|---|---|---|---|
type | string | ||
label | string | ||
description? | string | ||
allowedMemberTypes? | string[] | ||
allowedLinkTypes? | string[] | ||
minMembers? | number | ||
maxMembers? | number | ||
canNest? | boolean | ||
allowedLayoutTypes? | ('flexbox' | 'grid')[] | ||
requireLayout? | boolean | ||
validator? | (group: any) => ValidationResult |
LinkTypeDefinition
tsinterface LinkTypeDefinition
Properties
| Name | Type | Default | Description |
|---|---|---|---|
type | string | ||
label | string | ||
description? | string | ||
allowedSourcePortTypes? | string[] | ||
allowedTargetPortTypes? | string[] | ||
validator? | (link: any) => ValidationResult |
NodeTypeDefinition
tsinterface NodeTypeDefinition
Properties
| Name | Type | Default | Description |
|---|---|---|---|
type | string | ||
label? | string | ||
description? | string | ||
defaultData? | Record<string, any> | ||
allowedPortTypes? | string[] | ||
minPorts? | number | ||
maxPorts? | number | ||
validator? | (node: any) => ValidationResult | ||
extends? | string | ||
category? | string | ||
family? | string | ||
tags? | string[] | ||
defaultBehavior? | Partial<NodeBehavior> | ||
defaultStyle? | Partial<NodeStyle> | ||
defaultSize? | Partial<Size> | ||
allowedChildTypes? | string[] | ||
allowedParentTypes? | string[] | ||
maxChildren? | number | ||
maxDepth? | number | ||
canBeRoot? | boolean | ||
templateId? | string | ||
defaultPortRendering? | any |
PortTypeDefinition
tsinterface PortTypeDefinition
Properties
| Name | Type | Default | Description |
|---|---|---|---|
type | string | ||
label | string | ||
description? | string | ||
direction | 'input' | 'output' | 'bi' | ||
maxConnections? | number | ||
allowedLinkTypes? | string[] | ||
validator? | (port: any) => ValidationResult |
ValidationOptions
tsinterface ValidationOptions
Properties
| Name | Type | Default | Description |
|---|---|---|---|
validateTypes? | boolean | ||
validateConnections? | boolean | ||
validatePorts? | boolean | ||
strict? | boolean |
Types
ValidationRule
tstype ValidationRule<T = any> = (entity: T) => ValidationResult;
Was this page helpful?