@@ -2808,6 +3006,7 @@ const getComponentIcon = (type) => {
paragraph: 'heroicons:document-text',
divider: 'heroicons:minus',
'form-section': 'material-symbols:view-module-outline',
+ 'layout-grid': 'material-symbols:grid-on',
'info-display': 'heroicons:information-circle',
'dynamic-list': 'heroicons:list-bullet',
'repeating-table': 'heroicons:table-cells',
@@ -2846,6 +3045,7 @@ const getComponentTypeName = (type) => {
paragraph: 'Paragraph Text',
divider: 'Divider Line',
'form-section': 'Form Section',
+ 'layout-grid': 'Layout Grid',
'info-display': 'Information Display',
'dynamic-list': 'Dynamic List',
'repeating-table': 'Data Table',
@@ -2884,6 +3084,7 @@ const getComponentDescription = (type) => {
paragraph: 'Text content for instructions and descriptions',
divider: 'Visual separator to organize form sections',
'form-section': 'Visual container to group related form fields into sections',
+ 'layout-grid': 'Create custom grid layouts for precise component positioning',
'info-display': 'Read-only information display in organized format',
'dynamic-list': 'Dynamic list for displaying and managing items',
'repeating-table': 'Structured table for collecting multiple records with forms',
@@ -2939,7 +3140,7 @@ const showField = (fieldName) => {
const hasOptions = computed(() => showField('options'))
const hasSpecificSettings = computed(() => {
if (!props.component) return false
- const specificTypes = ['mask', 'otp', 'dropzone', 'range', 'button', 'form-section', 'dynamic-list', 'repeating-table', 'repeating-group', 'customHtml', 'info-display']
+ const specificTypes = ['mask', 'otp', 'dropzone', 'range', 'button', 'form-section', 'dynamic-list', 'repeating-table', 'repeating-group', 'customHtml', 'info-display', 'layout-grid']
return specificTypes.includes(props.component.type)
})
@@ -3791,6 +3992,161 @@ const cancelTypeChange = () => {
}
// Get default properties for a specific component type
+// Layout Grid Presets
+const layoutPresets = {
+ 'sidebar-right': {
+ rows: 2,
+ columns: 2,
+ cells: [
+ { id: 'cell-0', row: 0, col: 0, rowSpan: 1, colSpan: 1, component: null },
+ { id: 'cell-1', row: 0, col: 1, rowSpan: 2, colSpan: 1, component: null },
+ { id: 'cell-2', row: 1, col: 0, rowSpan: 1, colSpan: 1, component: null }
+ ]
+ },
+ 'sidebar-left': {
+ rows: 2,
+ columns: 2,
+ cells: [
+ { id: 'cell-0', row: 0, col: 0, rowSpan: 2, colSpan: 1, component: null },
+ { id: 'cell-1', row: 0, col: 1, rowSpan: 1, colSpan: 1, component: null },
+ { id: 'cell-2', row: 1, col: 1, rowSpan: 1, colSpan: 1, component: null }
+ ]
+ },
+ 'header-content': {
+ rows: 2,
+ columns: 2,
+ cells: [
+ { id: 'cell-0', row: 0, col: 0, rowSpan: 1, colSpan: 2, component: null },
+ { id: 'cell-1', row: 1, col: 0, rowSpan: 1, colSpan: 1, component: null },
+ { id: 'cell-2', row: 1, col: 1, rowSpan: 1, colSpan: 1, component: null }
+ ]
+ },
+ 'three-column': {
+ rows: 1,
+ columns: 3,
+ cells: [
+ { id: 'cell-0', row: 0, col: 0, rowSpan: 1, colSpan: 1, component: null },
+ { id: 'cell-1', row: 0, col: 1, rowSpan: 1, colSpan: 1, component: null },
+ { id: 'cell-2', row: 0, col: 2, rowSpan: 1, colSpan: 1, component: null }
+ ]
+ },
+ 'two-by-two': {
+ rows: 2,
+ columns: 2,
+ cells: [
+ { id: 'cell-0', row: 0, col: 0, rowSpan: 1, colSpan: 1, component: null },
+ { id: 'cell-1', row: 0, col: 1, rowSpan: 1, colSpan: 1, component: null },
+ { id: 'cell-2', row: 1, col: 0, rowSpan: 1, colSpan: 1, component: null },
+ { id: 'cell-3', row: 1, col: 1, rowSpan: 1, colSpan: 1, component: null }
+ ]
+ },
+ 'form-layout': {
+ rows: 3,
+ columns: 2,
+ cells: [
+ { id: 'cell-0', row: 0, col: 0, rowSpan: 1, colSpan: 1, component: null },
+ { id: 'cell-1', row: 0, col: 1, rowSpan: 1, colSpan: 1, component: null },
+ { id: 'cell-2', row: 1, col: 0, rowSpan: 1, colSpan: 1, component: null },
+ { id: 'cell-3', row: 1, col: 1, rowSpan: 1, colSpan: 1, component: null },
+ { id: 'cell-4', row: 2, col: 0, rowSpan: 1, colSpan: 2, component: null }
+ ]
+ },
+ 'header-sidebar': {
+ rows: 3,
+ columns: 2,
+ cells: [
+ { id: 'cell-0', row: 0, col: 0, rowSpan: 1, colSpan: 2, component: null },
+ { id: 'cell-1', row: 1, col: 0, rowSpan: 1, colSpan: 1, component: null },
+ { id: 'cell-2', row: 2, col: 0, rowSpan: 1, colSpan: 1, component: null },
+ { id: 'cell-3', row: 1, col: 1, rowSpan: 2, colSpan: 1, component: null }
+ ]
+ }
+}
+
+const currentPreset = ref('')
+
+// Apply a layout preset
+const applyPreset = (presetName) => {
+ if (!props.component || props.component.type !== 'layout-grid') return
+
+ const preset = layoutPresets[presetName]
+ if (!preset) return
+
+ // Update the component configuration
+ configModel.value.rows = preset.rows
+ configModel.value.columns = preset.columns
+ configModel.value.cells = [...preset.cells] // Create a copy to avoid reference issues
+
+ currentPreset.value = presetName
+}
+
+// Check if current layout matches a preset
+const isCurrentPreset = (presetName) => {
+ if (!props.component || props.component.type !== 'layout-grid') return false
+
+ const preset = layoutPresets[presetName]
+ if (!preset) return false
+
+ return (
+ configModel.value.rows === preset.rows &&
+ configModel.value.columns === preset.columns &&
+ JSON.stringify(configModel.value.cells) === JSON.stringify(preset.cells)
+ )
+}
+
+// Layout Grid Cell Management
+const addCell = () => {
+ if (!configModel.value.cells) {
+ configModel.value.cells = []
+ }
+
+ // Find the next available position
+ const rows = configModel.value.rows || 2
+ const cols = configModel.value.columns || 2
+ let newRow = 0
+ let newCol = 0
+
+ // Find first empty position
+ for (let row = 0; row < rows; row++) {
+ for (let col = 0; col < cols; col++) {
+ const isOccupied = configModel.value.cells.some(cell =>
+ cell.row === row && cell.col === col
+ )
+ if (!isOccupied) {
+ newRow = row
+ newCol = col
+ break
+ }
+ }
+ if (newRow !== 0 || newCol !== 0) break
+ }
+
+ const newCell = {
+ id: `cell-${Date.now()}`,
+ row: newRow,
+ col: newCol,
+ rowSpan: 1,
+ colSpan: 1,
+ component: null
+ }
+
+ configModel.value.cells.push(newCell)
+}
+
+const removeCell = (index) => {
+ if (configModel.value.cells && index >= 0 && index < configModel.value.cells.length) {
+ configModel.value.cells.splice(index, 1)
+ }
+}
+
+// Get total components in layout grid
+const getTotalComponents = () => {
+ if (props.component && props.component.type === 'layout-grid' && props.component.props.cells) {
+ return props.component.props.cells.filter(cell => cell.component).length
+ }
+ return 0
+}
+
const getDefaultPropsForType = (type) => {
const defaults = {
text: {
@@ -4264,6 +4620,89 @@ const getDefaultPropsForType = (type) => {
@apply mt-4 pt-4 border-t border-gray-200;
}
+/* Layout Grid Presets */
+.preset-button {
+ @apply flex flex-col items-center p-3 border border-gray-200 rounded-lg hover:border-blue-300 hover:bg-blue-50 transition-all duration-200;
+}
+
+.preset-button.preset-active {
+ @apply border-blue-500 bg-blue-100;
+}
+
+.preset-preview {
+ @apply w-full h-16 mb-2 bg-gray-100 rounded border border-gray-200 relative;
+}
+
+.preset-label {
+ @apply text-xs font-medium text-gray-700;
+}
+
+/* Preset Preview Layouts */
+.sidebar-right-preview {
+ background: linear-gradient(90deg, #e5e7eb 0%, #e5e7eb 50%, #d1d5db 50%, #d1d5db 100%);
+ background-size: 100% 50%;
+ background-position: 0 0, 0 100%;
+ background-repeat: no-repeat;
+}
+
+.sidebar-left-preview {
+ background: linear-gradient(90deg, #d1d5db 0%, #d1d5db 50%, #e5e7eb 50%, #e5e7eb 100%);
+ background-size: 100% 50%;
+ background-position: 0 0, 0 100%;
+ background-repeat: no-repeat;
+}
+
+.header-content-preview {
+ background: linear-gradient(180deg, #d1d5db 0%, #d1d5db 50%, #e5e7eb 50%, #e5e7eb 100%);
+}
+
+.three-column-preview {
+ background: linear-gradient(90deg, #e5e7eb 0%, #e5e7eb 33.33%, #d1d5db 33.33%, #d1d5db 66.66%, #f3f4f6 66.66%, #f3f4f6 100%);
+}
+
+.two-by-two-preview {
+ background:
+ linear-gradient(90deg, #e5e7eb 0%, #e5e7eb 50%, #d1d5db 50%, #d1d5db 100%) 0 0,
+ linear-gradient(90deg, #d1d5db 0%, #d1d5db 50%, #e5e7eb 50%, #e5e7eb 100%) 0 100%;
+ background-size: 100% 50%;
+ background-repeat: no-repeat;
+}
+
+.form-layout-preview {
+ background:
+ linear-gradient(90deg, #d1d5db 0%, #d1d5db 100%) 0 0,
+ linear-gradient(90deg, #e5e7eb 0%, #e5e7eb 50%, #d1d5db 50%, #d1d5db 100%) 0 33.33%,
+ linear-gradient(90deg, #f3f4f6 0%, #f3f4f6 100%) 0 66.66%;
+ background-size: 100% 33.33%;
+ background-repeat: no-repeat;
+}
+
+.header-sidebar-preview {
+ background:
+ linear-gradient(90deg, #d1d5db 0%, #d1d5db 100%) 0 0,
+ linear-gradient(90deg, #e5e7eb 0%, #e5e7eb 50%, #f3f4f6 50%, #f3f4f6 100%) 0 33.33%,
+ linear-gradient(90deg, #d1d5db 0%, #d1d5db 50%, #f3f4f6 50%, #f3f4f6 100%) 0 66.66%;
+ background-size: 100% 33.33%;
+ background-repeat: no-repeat;
+}
+
+/* Layout Grid Cell Spanning Controls */
+.cell-span-control {
+ @apply transition-all duration-200;
+}
+
+.cell-span-control:hover {
+ @apply transform scale-[1.02];
+}
+
+.cell-span-control input[type="number"] {
+ @apply text-center;
+}
+
+.cell-span-control input[type="number"]:focus {
+ @apply border-blue-500 ring-1 ring-blue-500;
+}
+
/* Toggle Switch */
.toggle-switch {
@apply flex items-center;
diff --git a/components/formkit/LayoutGrid.vue b/components/formkit/LayoutGrid.vue
new file mode 100644
index 0000000..8092495
--- /dev/null
+++ b/components/formkit/LayoutGrid.vue
@@ -0,0 +1,599 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Drop component here
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/docs/form-builder-node-creation-guide.md b/docs/form-builder-node-creation-guide.md
new file mode 100644
index 0000000..ebaa837
--- /dev/null
+++ b/docs/form-builder-node-creation-guide.md
@@ -0,0 +1,866 @@
+# Form Builder Node Creation Guide
+
+This guide explains how to create new nodes/components for the form builder system. The form builder supports various types of components from simple text inputs to complex container components like repeating groups and layout grids.
+
+## Table of Contents
+
+1. [Overview](#overview)
+2. [Component Types](#component-types)
+3. [Basic Component Creation](#basic-component-creation)
+4. [Container Component Creation](#container-component-creation)
+5. [Complex Component Creation](#complex-component-creation)
+6. [Component Registration](#component-registration)
+7. [Settings Modal Integration](#settings-modal-integration)
+8. [Component Preview Integration](#component-preview-integration)
+9. [Drag & Drop Integration](#drag--drop-integration)
+10. [Best Practices](#best-practices)
+11. [Examples](#examples)
+
+## Overview
+
+The form builder system consists of several key files:
+
+- **`FormBuilderComponents.vue`**: Defines available components and their metadata
+- **`ComponentPreview.vue`**: Renders components in the form builder
+- **`FormBuilderFieldSettingsModal.vue`**: Provides settings interface for components
+- **`stores/formBuilder.js`**: Manages form state and component operations
+
+## Component Types
+
+### 1. Basic Components
+Simple input components that collect data:
+- Text inputs, textareas, numbers
+- Select dropdowns, checkboxes, radio buttons
+- Date/time pickers, file uploads
+
+### 2. Container Components
+Components that can hold other components:
+- **Form Section**: Groups related fields
+- **Repeating Group**: Allows multiple instances of the same fields
+- **Layout Grid**: Custom grid layout with spanning capabilities
+
+### 3. Advanced Components
+Complex components with special functionality:
+- Custom HTML with CSS/JS
+- Conditional logic components
+- API integration components
+
+## Basic Component Creation
+
+### Step 1: Define Component Metadata
+
+Add your component to `FormBuilderComponents.vue`:
+
+```javascript
+{
+ type: 'my-component',
+ name: 'My Component',
+ category: 'Basic Inputs', // or 'Selection Inputs', 'Date and Time', 'Advanced', 'Layout'
+ icon: 'heroicons:document-text', // Use appropriate icon
+ description: 'Description of what this component does',
+ defaultProps: {
+ label: 'My Component',
+ name: 'my_component',
+ help: 'Help text for users',
+ required: false,
+ placeholder: 'Enter value...',
+ width: '100%',
+ gridColumn: 'span 6',
+ // Component-specific properties
+ myCustomProp: 'default value',
+ // Conditional Logic Properties
+ conditionalLogic: {
+ enabled: false,
+ conditions: [],
+ action: 'show',
+ operator: 'and'
+ }
+ }
+}
+```
+
+### Step 2: Add Component Preview
+
+Add rendering logic to `ComponentPreview.vue`:
+
+```vue
+
+
+
+
+
+
+
+
+
+
+ {{ component.props.help }}
+
+
+```
+
+### Step 3: Add Settings Modal Support
+
+Add settings to `FormBuilderFieldSettingsModal.vue`:
+
+```javascript
+// In the script section, add to getComponentTypeName function
+getComponentTypeName(type) {
+ const typeNames = {
+ // ... existing types
+ 'my-component': 'My Component'
+ }
+ return typeNames[type] || 'Unknown Component'
+}
+
+// Add to getComponentIcon function
+getComponentIcon(type) {
+ const icons = {
+ // ... existing icons
+ 'my-component': 'heroicons:document-text'
+ }
+ return icons[type] || 'heroicons:question-mark-circle'
+}
+
+// Add to getComponentDescription function
+getComponentDescription(type) {
+ const descriptions = {
+ // ... existing descriptions
+ 'my-component': 'A custom component for collecting specific data'
+ }
+ return descriptions[type] || 'Component description'
+}
+```
+
+## Container Component Creation
+
+Container components are more complex as they can hold other components.
+
+### Example: Creating a Custom Container
+
+```javascript
+// In FormBuilderComponents.vue
+{
+ type: 'custom-container',
+ name: 'Custom Container',
+ category: 'Layout',
+ icon: 'material-symbols:view-in-ar',
+ description: 'A custom container that can hold other components',
+ defaultProps: {
+ label: 'Custom Container',
+ name: 'custom_container',
+ help: 'Drag components here to add them',
+ showHeader: true,
+ headerBackground: '#f9fafb',
+ backgroundColor: '#ffffff',
+ showBorder: true,
+ borderStyle: 'solid', // 'solid', 'dashed', 'dotted'
+ spacing: 'normal', // 'compact', 'normal', 'relaxed'
+ children: [], // Array to hold nested components
+ // Conditional Logic Properties
+ conditionalLogic: {
+ enabled: false,
+ conditions: [],
+ action: 'show',
+ operator: 'and'
+ }
+ }
+}
+```
+
+### Container Component Preview
+
+```vue
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Drop Components Here
+
+ Drag form fields from the sidebar to add them to this container
+
+
+
+
+
+
+```
+
+## Complex Component Creation
+
+### Example: Repeating Group Component
+
+Repeating groups are complex container components that allow multiple instances of the same fields.
+
+#### 1. Component Definition
+
+```javascript
+{
+ type: 'repeating-group',
+ name: 'Repeating Group',
+ category: 'Layout',
+ icon: 'material-symbols:view-in-ar',
+ description: 'Group of fields that can be repeated multiple times',
+ defaultProps: {
+ label: 'Repeating Group',
+ name: 'repeating_group',
+ help: 'Add multiple instances of the same fields',
+ buttonText: 'Add Item',
+ showPlaceholder: true,
+ children: [], // Array to hold nested components
+ // Conditional Logic Properties
+ conditionalLogic: {
+ enabled: false,
+ conditions: [],
+ action: 'show',
+ operator: 'and'
+ }
+ }
+}
+```
+
+#### 2. Drag & Drop Integration
+
+Container components need special drag & drop handling:
+
+```javascript
+// In ComponentPreview.vue, add these functions:
+
+const handleSectionDrop = (event, containerId) => {
+ event.preventDefault();
+ event.stopPropagation();
+
+ // Reset drag state
+ if (sectionDropStates.value[containerId]) {
+ sectionDropStates.value[containerId].isDraggingOver = false;
+ }
+
+ try {
+ // Get the dropped component data
+ let componentData = null;
+
+ try {
+ componentData = JSON.parse(event.dataTransfer.getData('text/plain') || '{}');
+ } catch (parseError) {
+ componentData = window.__draggedComponentData || {};
+ }
+
+ if (!componentData.type) {
+ console.warn('No valid component data found in drop event');
+ return;
+ }
+
+ // Create a new component instance
+ const newComponent = {
+ id: `${componentData.type}_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
+ type: componentData.type,
+ name: componentData.name,
+ props: {
+ ...componentData.defaultProps,
+ gridColumn: 'span 6',
+ width: '50%',
+ label: componentData.defaultProps.label || componentData.name || `${componentData.type.charAt(0).toUpperCase() + componentData.type.slice(1)} Field`,
+ name: componentData.defaultProps.name || `${componentData.type}_${Date.now()}`
+ }
+ };
+
+ // Find the target container
+ const container = findContainerRecursively(containerId);
+ if (container && (container.type === 'form-section' || container.type === 'repeating-group')) {
+ // Initialize children array if it doesn't exist
+ if (!container.props.children) {
+ container.props.children = [];
+ }
+
+ // Add the component to the container
+ container.props.children.push(newComponent);
+
+ // Update the container in the form store
+ formStore.updateComponent(container);
+
+ console.log('Component added to container:', newComponent);
+ } else {
+ console.warn('Container not found or invalid container type:', containerId);
+ }
+ } catch (error) {
+ console.error('Error dropping component into container:', error);
+ }
+};
+```
+
+#### 3. Container Search Function
+
+```javascript
+// Helper function to find container at any nesting level
+const findContainerRecursively = (containerId, components = formStore.formComponents, childId = null) => {
+ for (const component of components) {
+ // Check if this is the target container
+ if (containerId && component.id === containerId) {
+ return component;
+ }
+
+ // If searching for parent by child ID, check if this component contains the child
+ if (childId && component.props.children && Array.isArray(component.props.children)) {
+ const hasChild = component.props.children.some(child => child.id === childId);
+ if (hasChild) {
+ return component;
+ }
+ }
+
+ // If this component has children, search recursively
+ if (component.props.children && Array.isArray(component.props.children)) {
+ const found = findContainerRecursively(containerId, component.props.children, childId);
+ if (found) {
+ return found;
+ }
+ }
+
+ // Special handling for Layout Grid components - search in their cells
+ if (component.type === 'layout-grid' && component.props.cells) {
+ for (const cell of component.props.cells) {
+ if (cell.component) {
+ // Check if this cell's component is the target container
+ if (containerId && cell.component.id === containerId) {
+ return cell.component;
+ }
+
+ // If searching for parent by child ID, check if this cell's component contains the child
+ if (childId && cell.component.props.children && Array.isArray(cell.component.props.children)) {
+ const hasChild = cell.component.props.children.some(child => child.id === childId);
+ if (hasChild) {
+ return cell.component;
+ }
+ }
+
+ // Recursively search in the cell's component children
+ if (cell.component.props.children && Array.isArray(cell.component.props.children)) {
+ const found = findContainerRecursively(containerId, cell.component.props.children, childId);
+ if (found) {
+ return found;
+ }
+ }
+ }
+ }
+ }
+ }
+ return null;
+};
+```
+
+## Component Registration
+
+### 1. Add to Available Components
+
+In `FormBuilderComponents.vue`, add your component to the `availableComponents` array:
+
+```javascript
+const availableComponents = [
+ // ... existing components
+ {
+ type: 'my-component',
+ name: 'My Component',
+ category: 'Basic Inputs',
+ icon: 'heroicons:document-text',
+ description: 'A custom component for collecting data',
+ defaultProps: {
+ // ... your default props
+ }
+ }
+];
+```
+
+### 2. Add Category Support
+
+If you're creating a new category, add it to the template:
+
+```vue
+
+
+
My Category
+
+
+
+ {{ component.name }}
+
+
+
+```
+
+## Settings Modal Integration
+
+### 1. Add Component Type Support
+
+In `FormBuilderFieldSettingsModal.vue`:
+
+```javascript
+// Add to getComponentTypeName function
+getComponentTypeName(type) {
+ const typeNames = {
+ // ... existing types
+ 'my-component': 'My Component'
+ }
+ return typeNames[type] || 'Unknown Component'
+}
+
+// Add to getComponentIcon function
+getComponentIcon(type) {
+ const icons = {
+ // ... existing icons
+ 'my-component': 'heroicons:document-text'
+ }
+ return icons[type] || 'heroicons:question-mark-circle'
+}
+
+// Add to getComponentDescription function
+getComponentDescription(type) {
+ const descriptions = {
+ // ... existing descriptions
+ 'my-component': 'A custom component for collecting specific data'
+ }
+ return descriptions[type] || 'Component description'
+}
+```
+
+### 2. Add Specific Settings
+
+For components with specific settings, add them to the settings modal:
+
+```vue
+
+
+```
+
+## Component Preview Integration
+
+### 1. Add Preview Rendering
+
+In `ComponentPreview.vue`, add your component's preview rendering:
+
+```vue
+
+
+
+
+
+
+
+
+
+
+ {{ component.props.help }}
+
+
+```
+
+### 2. Handle Preview Mode
+
+Make sure your component handles the `isPreview` prop correctly:
+
+```vue
+
+
+
+
+
+
+
+
+ {{ component.props.placeholder || 'Preview mode' }}
+
+
+
+
+ {{ component.props.help }}
+
+
+```
+
+## Drag & Drop Integration
+
+### 1. Basic Drag & Drop
+
+For basic components, drag & drop is handled automatically by the form builder system.
+
+### 2. Container Drag & Drop
+
+For container components, you need to implement custom drag & drop handlers:
+
+```javascript
+// In ComponentPreview.vue
+
+// Drag over handler
+const handleSectionDragOver = (event, containerId) => {
+ event.preventDefault();
+ event.stopPropagation();
+
+ // Initialize container drop state if it doesn't exist
+ if (!sectionDropStates.value[containerId]) {
+ sectionDropStates.value[containerId] = { isDraggingOver: false };
+ }
+ sectionDropStates.value[containerId].isDraggingOver = true;
+};
+
+// Drag leave handler
+const handleSectionDragLeave = (event, containerId) => {
+ event.preventDefault();
+ event.stopPropagation();
+
+ // Only hide the drag over state if we're actually leaving the drop zone
+ const rect = event.currentTarget.getBoundingClientRect();
+ const isOutside = (
+ event.clientX < rect.left ||
+ event.clientX > rect.right ||
+ event.clientY < rect.top ||
+ event.clientY > rect.bottom
+ );
+
+ if (isOutside && sectionDropStates.value[containerId]) {
+ sectionDropStates.value[containerId].isDraggingOver = false;
+ }
+};
+
+// Drag enter handler
+const handleSectionDragEnter = (event, containerId) => {
+ event.preventDefault();
+ event.stopPropagation();
+
+ // Initialize container drop state if it doesn't exist
+ if (!sectionDropStates.value[containerId]) {
+ sectionDropStates.value[containerId] = { isDraggingOver: false };
+ }
+};
+```
+
+### 3. Nested Component Management
+
+For container components, you need to handle nested component operations:
+
+```javascript
+// Remove component from container
+const removeFromSection = (sectionId, childIndex) => {
+ const section = findContainerRecursively(sectionId);
+ if (section && section.props.children) {
+ const removedComponent = section.props.children.splice(childIndex, 1)[0];
+ if (removedComponent) {
+ formStore.updateComponent(section);
+ console.log('Component deleted from section:', removedComponent);
+ }
+ }
+};
+
+// Open nested component settings
+const openNestedComponentSettings = (component) => {
+ selectedNestedComponent.value = { ...component };
+ showNestedSettingsModal.value = true;
+ console.log('Opening settings for component:', component);
+};
+
+// Save nested component settings
+const saveNestedComponentSettings = (updatedComponent) => {
+ if (!updatedComponent || !selectedNestedComponent.value) return;
+
+ // Find the parent container at any nesting level
+ const parentContainer = findContainerRecursively(null, formStore.formComponents, updatedComponent.id);
+
+ if (parentContainer) {
+ // Find and update the component in the parent's children
+ const childIndex = parentContainer.props.children.findIndex(child => child.id === updatedComponent.id);
+ if (childIndex !== -1) {
+ parentContainer.props.children[childIndex] = updatedComponent;
+ formStore.updateComponent(parentContainer);
+ console.log('Nested component updated in parent:', parentContainer);
+ }
+ } else {
+ // If not found in main form, it might be in a Layout Grid cell
+ console.log('Parent container not found, component might be in Layout Grid');
+ }
+
+ showNestedSettingsModal.value = false;
+ selectedNestedComponent.value = null;
+};
+```
+
+## Best Practices
+
+### 1. Component Design
+
+- **Consistent Props**: Use consistent prop names across components
+- **Default Values**: Always provide sensible default values
+- **Validation**: Include validation rules where appropriate
+- **Accessibility**: Ensure components are accessible (ARIA labels, keyboard navigation)
+
+### 2. Container Components
+
+- **Children Array**: Always initialize `children: []` for container components
+- **Drag & Drop**: Implement proper drag & drop handlers
+- **Nested Settings**: Support settings for nested components
+- **Recursive Search**: Use `findContainerRecursively` for finding parent containers
+
+### 3. Performance
+
+- **Lazy Loading**: Consider lazy loading for complex components
+- **Memoization**: Use computed properties for expensive calculations
+- **Event Handling**: Properly clean up event listeners
+
+### 4. Error Handling
+
+- **Validation**: Validate component props
+- **Fallbacks**: Provide fallback rendering for missing props
+- **Logging**: Add appropriate console logging for debugging
+
+## Examples
+
+### Example 1: Simple Text Input
+
+```javascript
+// Component definition
+{
+ type: 'custom-text',
+ name: 'Custom Text Input',
+ category: 'Basic Inputs',
+ icon: 'heroicons:document-text',
+ description: 'A custom text input with special styling',
+ defaultProps: {
+ label: 'Custom Text',
+ name: 'custom_text',
+ help: 'Enter your custom text',
+ placeholder: 'Type here...',
+ required: false,
+ width: '100%',
+ gridColumn: 'span 6',
+ conditionalLogic: {
+ enabled: false,
+ conditions: [],
+ action: 'show',
+ operator: 'and'
+ }
+ }
+}
+```
+
+### Example 2: Advanced Container
+
+```javascript
+// Component definition
+{
+ type: 'advanced-container',
+ name: 'Advanced Container',
+ category: 'Layout',
+ icon: 'material-symbols:view-in-ar',
+ description: 'An advanced container with custom styling and behavior',
+ defaultProps: {
+ label: 'Advanced Container',
+ name: 'advanced_container',
+ help: 'A container with advanced features',
+ showHeader: true,
+ headerBackground: '#f9fafb',
+ backgroundColor: '#ffffff',
+ showBorder: true,
+ borderStyle: 'solid',
+ spacing: 'normal',
+ children: [],
+ customFeature: 'default',
+ conditionalLogic: {
+ enabled: false,
+ conditions: [],
+ action: 'show',
+ operator: 'and'
+ }
+ }
+}
+```
+
+### Example 3: Complex Component with API Integration
+
+```javascript
+// Component definition
+{
+ type: 'api-select',
+ name: 'API Select',
+ category: 'Advanced',
+ icon: 'heroicons:globe-alt',
+ description: 'Dropdown populated from API endpoint',
+ defaultProps: {
+ label: 'API Select',
+ name: 'api_select',
+ help: 'Select from API data',
+ required: false,
+ apiEndpoint: '',
+ apiMethod: 'GET',
+ valueField: 'id',
+ labelField: 'name',
+ placeholder: 'Select an option...',
+ width: '100%',
+ gridColumn: 'span 6',
+ conditionalLogic: {
+ enabled: false,
+ conditions: [],
+ action: 'show',
+ operator: 'and'
+ }
+ }
+}
+```
+
+## Conclusion
+
+Creating new form builder nodes requires understanding the system architecture and following established patterns. Start with simple components and gradually work up to complex container components. Always test thoroughly and ensure proper integration with the existing form builder system.
+
+For complex components, consider breaking them down into smaller, reusable parts and following the established patterns for drag & drop, settings, and preview rendering.
diff --git a/package.json b/package.json
index 26cc354..eac7203 100644
--- a/package.json
+++ b/package.json
@@ -8,7 +8,7 @@
"preview": "nuxt preview",
"postinstall": "nuxt prepare",
"prisma": "npx prisma db pull && npx prisma generate",
- "deploy": "yarn prisma && yarn build && pm2 restart all"
+ "deploy": "npx prisma generate && yarn build && pm2 restart all"
},
"devDependencies": {
"@nuxtjs/tailwindcss": "^6.8.0",
diff --git a/pages/form-builder/index.vue b/pages/form-builder/index.vue
index 5483e9d..674fc07 100644
--- a/pages/form-builder/index.vue
+++ b/pages/form-builder/index.vue
@@ -291,7 +291,7 @@
class="grid-preview-container"
:class="{
'px-4 pt-0': selectedDevice !== 'Desktop',
- 'p-0': selectedDevice === 'Desktop'
+ 'p-0 pb-4': selectedDevice === 'Desktop'
}"
>
{
for (let i = 0; i < minItems; i++) {
const newGroup = {};
- // Add fields from configuration
+ // Add fields from configuration (legacy)
if (component.props.fields) {
component.props.fields.forEach(field => {
newGroup[field.name] = '';
});
}
+ // Add fields from children components (form builder format)
+ if (component.props.children) {
+ const extractFieldsFromComponent = (comp) => {
+ if (!comp) return;
+
+ // If this component has a name, add it to the group
+ if (comp.props && comp.props.name) {
+ // Initialize with default value based on component type
+ switch (comp.type) {
+ case 'number':
+ newGroup[comp.props.name] = 0;
+ break;
+ case 'checkbox':
+ newGroup[comp.props.name] = [];
+ break;
+ case 'select':
+ if (comp.props.options && comp.props.options.length > 0) {
+ newGroup[comp.props.name] = comp.props.options[0].value || '';
+ } else {
+ newGroup[comp.props.name] = '';
+ }
+ break;
+ default:
+ newGroup[comp.props.name] = '';
+ }
+ }
+
+ // Handle layout grid components
+ if (comp.type === 'layout-grid' && comp.props.cells) {
+ comp.props.cells.forEach(cell => {
+ if (cell.component) {
+ extractFieldsFromComponent(cell.component);
+ }
+ });
+ }
+
+ // Handle nested container components
+ if (comp.props.children && Array.isArray(comp.props.children)) {
+ comp.props.children.forEach(nestedChild => {
+ extractFieldsFromComponent(nestedChild);
+ });
+ }
+ };
+
+ component.props.children.forEach(child => {
+ extractFieldsFromComponent(child);
+ });
+ }
+
initialGroups.push(newGroup);
}
diff --git a/prisma/json/json-schema.json b/prisma/json/json-schema.json
index 421aa37..a4871e9 100644
--- a/prisma/json/json-schema.json
+++ b/prisma/json/json-schema.json
@@ -339,7 +339,7 @@
"form": {
"$ref": "#/definitions/form"
},
- "user": {
+ "savedByUser": {
"anyOf": [
{
"$ref": "#/definitions/user"
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index d80ec3b..25b2340 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -96,7 +96,7 @@ model formHistory {
savedBy Int?
savedDate DateTime @default(now()) @db.DateTime(0)
form form @relation(fields: [formID], references: [formID], onDelete: Cascade)
- user user? @relation(fields: [savedBy], references: [userID])
+ savedByUser user? @relation(fields: [savedBy], references: [userID])
@@index([formID], map: "FK_formHistory_form")
@@index([savedBy], map: "FK_formHistory_savedBy")