@enerjisaformlibrary/formbuilder-react 1.0.7 → 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
@@ -47,6 +47,8 @@ function App() {
47
47
  - JSON export/import
48
48
  - Responsive grid system (12-column)
49
49
  - Dark/Light theme support
50
+ - **Container support**: Drop fields into containers with multiple columns
51
+ - **Column support**: Drop fields into existing columns
50
52
 
51
53
  ## License
52
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);
@@ -28585,36 +28585,58 @@ function FormBuilder({ initialForm, onSave, onChange, className = '', theme = 'l
28585
28585
  // Check for library item (using actual data structure from ComponentLibrary)
28586
28586
  const isLibraryItem = activeData?.isLibraryItem;
28587
28587
  const fieldType = activeData?.componentType || activeData?.type;
28588
- const isCanvas = overData?.type === 'canvas';
28589
- const isColumn = overData?.type === 'column' || overData?.columnId;
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';
28590
28594
  console.log('[FormBuilder] Checking conditions:', {
28591
28595
  isLibraryItem,
28592
28596
  fieldType,
28597
+ dropType,
28593
28598
  isCanvas,
28594
28599
  isColumn,
28595
- activeData,
28600
+ isContainerDrop,
28601
+ isContainerColumn,
28596
28602
  overData
28597
28603
  });
28598
- if (isLibraryItem && fieldType) {
28599
- if (isCanvas || isColumn) {
28600
- console.log('[FormBuilder] Adding field:', fieldType);
28601
- addRowWithField({
28602
- type: fieldType,
28603
- props: {
28604
- key: `field_${Date.now()}`,
28605
- label: getDefaultLabel(fieldType),
28606
- placeholder: '',
28607
- },
28608
- validation: {},
28609
- customStyle: {},
28610
- });
28611
- }
28612
- else {
28613
- console.log('[FormBuilder] Drop target not canvas or column');
28614
- }
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);
28615
28637
  }
28616
28638
  else {
28617
- console.log('[FormBuilder] Not a library item drag');
28639
+ console.log('[FormBuilder] Unknown drop target');
28618
28640
  }
28619
28641
  };
28620
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 })] }) }));