Appearance
JavaScript Modules
Overview
The FlowBuilder frontend is built using a modular JavaScript architecture that allows for better maintainability and code organization. Instead of having one large monolithic JavaScript file, the functionality is split into focused modules that are dynamically combined at runtime.
How JavaScript Modules Work
Module Structure
Each JavaScript module is a separate .js
file that exports a default object containing methods and properties:
javascript
// Example module structure
export default {
methodName() {
// Method implementation
// Has access to all FlowBuilder component properties via 'this'
},
anotherMethod() {
// Another method
},
};
JavaScript Module Integration
The ScriptManager
automatically combines all modules into a single Alpine.js component. The service:
- Reads each JavaScript module file
- Extracts the exported object content
- Combines all methods into the main FlowBuilder component
- Injects the combined code into the Blade template
Available Component Properties
When writing module methods, you have access to all FlowBuilder component properties through this
:
Core Data Properties
this.nodes
- Object containing all available node definitionsthis.flows
- Array of all flows in the systemthis.currentFlow
- The currently selected flow objectthis.drawflowData
- JSON string of the current flow's visual datathis.variables
- Object containing available system variables
Editor Properties
this.editor
- The Drawflow editor instancethis.mobileItemSelected
- Currently selected item on mobilethis.mobileLastMove
- Last touch move event on mobilethis.locked
- Whether the editor is in locked modethis.nodeSelectedTime
- Timestamp of last node selection
UI State Properties
this.unsavedChanges
- Boolean indicating unsaved changesthis.onSaving
- Boolean indicating save operation in progressthis.moreOptionsMenuOpen
- Boolean for more options menu statethis.creatingFlow
- Boolean indicating flow creation in progressthis.deleteFlowId
- ID of flow being deleted (null if none)this.showStartFlowButton
- Boolean to show/hide start flow button
Validation Properties
this.flowValidationErrors
- Array of flow-level validation errorsthis.nodesWithErrors
- Array of node IDs that have validation errors
Available Modules
Core Modules
editor-core.js
Contains the main initialization logic and core editor functionality:
initFlowBuilder()
- Main initialization methodinitEditor()
- Drawflow editor setupsetupEventListeners()
- DOM event listener setupinitGlobalVariables()
- Variable system initialization
event-handlers.js
Handles all Drawflow editor events:
registerEvents()
- Register all editor event listenersnodeCreated()
,nodeRemoved()
,nodeSelected()
- Node lifecycle eventsconnectionCreated()
,connectionRemoved()
- Connection eventshandleDuplicateConnections()
- Prevent duplicate connections
flow-management.js
Manages flow operations:
save()
- Save current flow datacreateFlow()
- Create new flowchangeFlow()
- Switch between flowsconfirmDeleteFlow()
- Delete flow confirmationstartFlow()
- Execute flow manuallyverifyIfHasTrigger()
- Check if flow has trigger nodes
node-operations.js
Handles node drag & drop and positioning:
setupTouchListeners()
- Mobile touch event setupdrag()
,drop()
- Drag and drop functionalityaddNodeToDrawFlow()
- Add nodes to the canvascalculateAdjustedPosition()
- Position calculation for different zoom levels
validation.js
Flow and node validation logic:
validateFlow()
- Validate entire flowprocessValidationErrors()
- Process and display validation errorshighlightNodeErrors()
- Visual error highlightingclearValidationErrors()
- Clear error highlights
ui-controls.js
User interface controls:
toggleLock()
- Toggle editor lock modezoomIn()
,zoomOut()
,zoomReset()
- Zoom controlsclear()
- Clear current flowopenHelpModal()
- Open help modal
key-bindings.js
Keyboard shortcuts and hotkeys:
registerKeyBindings()
- Register all keyboard shortcutsshouldHandleKeyEvent()
- Determine if key event should be handled
mobile-touch.js
Mobile device support and touch handling:
initMobileSupport()
- Initialize mobile-specific featuressetupMobileSpecificBehaviors()
- Mobile behavior adjustmentshandleViewportChanges()
- Handle mobile keyboard appearance
Using the ScriptManager
The ScriptManager is automatically used by the FlowBuilder component. All default modules are included by default.
Adding Custom Modules
You can add additional modules to extend FlowBuilder functionality:
php
use Modules\FlowBuilder\Facades\ScriptManager;
// Add a custom module
ScriptManager::push('resources/js/mymodule/my-custom-module.js');
Creating Custom Modules
- Create a new
.js
file - Export a default object with your methods:
javascript
export default {
myCustomMethod() {
// Access FlowBuilder data via this
console.log('Current flow:', this.currentFlow);
console.log('Available nodes:', this.nodes);
// Use Core FlowBuilder methods
this.setUnsavedChanges(true);
},
handleCustomEvent() {
// Handle custom functionality
this.$dispatch('custom-event', { data: 'example' });
},
};
- Register the module path in your ServiceProvider with
ScriptManager
php
use Modules\FlowBuilder\Facades\ScriptManager;
ScriptManager::push('resources/js/mymodule/my-custom-module.js');
Inject Code in component initialization
You can also inject custom code directly into the FlowBuilder component initialization, util for adding event listeners or custom logic that needs to run when the component is initialized:
php
use Modules\FlowBuilder\Facades\ScriptManager;
ScriptManager::inject('
document.addEventListener("my-custom-event", function() {
// Listen for a custom event for example
});
');
Available Stores
flowBuilder
The flowBuilder
Alpine store manages the main FlowBuilder state, including loaded flows, nodes, and variables.
Properties:
currentFlow
— The currently selected flow objectnodes
— Object containing all available node definitionsflows
— Array of all flows in the systemdrawflowData
— JSON string of the current flow's visual datavariables
— Array of available system variables
availableVariables
The availableVariables
Alpine store manages system variables, including creation, editing, removal, and synchronization with the backend and editor.
Properties:
variables
— Array of available variableseditingVariable
— The variable currently being edited (or null)creatingVariable
— Boolean indicating if a variable is being created
Methods:
add(variable)
— Add or update a variable in the store and dispatch an update eventcreateVariable(name, id, value, nodeId = null)
— Create a new variable, save it to the backend, and update the storeremove(variableId)
— Remove a variable by ID and dispatch an update eventreset()
— Clear all variables and editing stategetAll()
— Return all variablesgetById(id)
— Return a variable by IDsetEditingVariable(variable)
— Set the variable currently being editedsyncNodeVariables(drawflowData, currentFlowSlug)
— Synchronize variables between drawflow and the store, reflecting changes in the backend
These stores are accessible via Alpine.js and centralize FlowBuilder state and operations, ensuring reactivity and data consistency between frontend and backend.