@enerjisaformlibrary/formbuilder-react 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -36,19 +36,6 @@ function App() {
36
36
  }
37
37
  ```
38
38
 
39
- ## Props
40
-
41
- | Prop | Type | Default | Description |
42
- |------|------|---------|-------------|
43
- | `initialForm` | `FormSchema` | - | Initial form data to load |
44
- | `onChange` | `(form: FormSchema) => void` | - | Called when form changes |
45
- | `onSave` | `(form: FormSchema) => void` | - | Called when save is triggered |
46
- | `theme` | `'light' \| 'dark'` | `'light'` | Color theme |
47
- | `showToolbar` | `boolean` | `true` | Show/hide toolbar |
48
- | `showComponentLibrary` | `boolean` | `true` | Show/hide component library |
49
- | `showPropertiesPanel` | `boolean` | `true` | Show/hide properties panel |
50
- | `className` | `string` | - | Additional CSS class |
51
-
52
39
  ## Features
53
40
 
54
41
  - 20+ field types (input, textarea, dropdown, checkbox, radio, date, file, signature, rating, etc.)
@@ -60,6 +47,8 @@ function App() {
60
47
  - JSON export/import
61
48
  - Responsive grid system (12-column)
62
49
  - Dark/Light theme support
50
+ - **Container support**: Drop fields into containers with multiple columns
51
+ - **Column support**: Drop fields into existing columns
63
52
 
64
53
  ## License
65
54
 
package/index.cjs CHANGED
@@ -28521,7 +28521,7 @@ function JsonViewerModal({ isOpen, onClose, schema }) {
28521
28521
  }
28522
28522
 
28523
28523
  function FormBuilder({ initialForm, onSave, onChange, className = '', theme = 'light', showToolbar = true, showComponentLibrary = true, showPropertiesPanel = true, }) {
28524
- const { form, loadForm, addRowWithField } = useFormStore();
28524
+ const { form, loadForm, addRowWithField, addField, addFieldToContainer, addFieldToContainerDirect } = useFormStore();
28525
28525
  const [activeId, setActiveId] = React.useState(null);
28526
28526
  const [activeType, setActiveType] = React.useState(null);
28527
28527
  const [jsonViewerOpen, setJsonViewerOpen] = React.useState(false);
@@ -28582,33 +28582,61 @@ function FormBuilder({ initialForm, onSave, onChange, className = '', theme = 'l
28582
28582
  }
28583
28583
  const activeData = active.data.current;
28584
28584
  const overData = over.data.current;
28585
+ // Check for library item (using actual data structure from ComponentLibrary)
28586
+ const isLibraryItem = activeData?.isLibraryItem;
28587
+ const fieldType = activeData?.componentType || activeData?.type;
28588
+ // Determine drop target type
28589
+ const dropType = overData?.type;
28590
+ const isCanvas = dropType === 'canvas';
28591
+ const isColumn = dropType === 'column';
28592
+ const isContainerDrop = dropType === 'container-drop';
28593
+ const isContainerColumn = dropType === 'container-column';
28585
28594
  console.log('[FormBuilder] Checking conditions:', {
28586
- isNew: activeData?.isNew,
28587
- fieldType: activeData?.fieldType,
28588
- isCanvas: overData?.isCanvas,
28589
- columnId: overData?.columnId
28595
+ isLibraryItem,
28596
+ fieldType,
28597
+ dropType,
28598
+ isCanvas,
28599
+ isColumn,
28600
+ isContainerDrop,
28601
+ isContainerColumn,
28602
+ overData
28590
28603
  });
28591
- if (activeData?.isNew && activeData?.fieldType) {
28592
- const fieldType = activeData.fieldType;
28593
- if (overData?.isCanvas || overData?.columnId) {
28594
- console.log('[FormBuilder] Adding field:', fieldType);
28595
- addRowWithField({
28596
- type: fieldType,
28597
- props: {
28598
- key: `field_${Date.now()}`,
28599
- label: getDefaultLabel(fieldType),
28600
- placeholder: '',
28601
- },
28602
- validation: {},
28603
- customStyle: {},
28604
- });
28605
- }
28606
- else {
28607
- console.log('[FormBuilder] Drop target not canvas or column');
28608
- }
28604
+ if (!isLibraryItem || !fieldType) {
28605
+ console.log('[FormBuilder] Not a library item drag');
28606
+ return;
28607
+ }
28608
+ const newField = {
28609
+ type: fieldType,
28610
+ props: {
28611
+ key: `field_${Date.now()}`,
28612
+ label: getDefaultLabel(fieldType),
28613
+ placeholder: '',
28614
+ },
28615
+ validation: {},
28616
+ customStyle: {},
28617
+ };
28618
+ if (isContainerColumn && overData?.rowId && overData?.columnId && overData?.containerFieldId && overData?.containerRowId && overData?.containerColumnId) {
28619
+ // Drop into a specific container column
28620
+ console.log('[FormBuilder] Adding field to container column:', fieldType);
28621
+ addFieldToContainer(overData.rowId, overData.columnId, overData.containerFieldId, overData.containerRowId, overData.containerColumnId, newField);
28622
+ }
28623
+ else if (isContainerDrop && overData?.rowId && overData?.columnId && overData?.containerFieldId) {
28624
+ // Drop into container directly (adds to first row)
28625
+ console.log('[FormBuilder] Adding field to container direct:', fieldType);
28626
+ addFieldToContainerDirect(overData.rowId, overData.columnId, overData.containerFieldId, newField);
28627
+ }
28628
+ else if (isColumn && overData?.rowId && overData?.columnId) {
28629
+ // Drop into an existing column
28630
+ console.log('[FormBuilder] Adding field to existing column:', fieldType);
28631
+ addField(overData.rowId, overData.columnId, newField);
28632
+ }
28633
+ else if (isCanvas) {
28634
+ // Drop into canvas - create new row
28635
+ console.log('[FormBuilder] Adding field as new row:', fieldType);
28636
+ addRowWithField(newField);
28609
28637
  }
28610
28638
  else {
28611
- console.log('[FormBuilder] Not a new field drag');
28639
+ console.log('[FormBuilder] Unknown drop target');
28612
28640
  }
28613
28641
  };
28614
28642
  return (jsxRuntime.jsx(TooltipProvider, { children: jsxRuntime.jsxs("div", { className: `formbuilder-container ${theme} ${className}`, children: [jsxRuntime.jsxs(DndContext, { sensors: sensors, collisionDetection: closestCenter, onDragStart: handleDragStart, onDragOver: handleDragOver, onDragEnd: handleDragEnd, children: [jsxRuntime.jsxs("div", { className: "flex flex-col h-full", children: [showToolbar && (jsxRuntime.jsx(Toolbar, { onOpenJsonViewer: () => setJsonViewerOpen(true) })), jsxRuntime.jsxs("div", { className: "flex flex-1 overflow-hidden", children: [showComponentLibrary && (jsxRuntime.jsx(ComponentLibrary, {})), jsxRuntime.jsx("div", { className: "flex-1 overflow-auto", children: jsxRuntime.jsx(FormCanvas, {}) }), showPropertiesPanel && (jsxRuntime.jsx(PropertiesPanel, {}))] })] }), jsxRuntime.jsx(DragOverlay, { children: activeId && activeType && (jsxRuntime.jsx(DragOverlayContent, { type: activeType })) })] }), jsxRuntime.jsx(JsonViewerModal, { isOpen: jsonViewerOpen, onClose: () => setJsonViewerOpen(false), schema: form })] }) }));