@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/index.js CHANGED
@@ -28501,7 +28501,7 @@ function JsonViewerModal({ isOpen, onClose, schema }) {
28501
28501
  }
28502
28502
 
28503
28503
  function FormBuilder({ initialForm, onSave, onChange, className = '', theme = 'light', showToolbar = true, showComponentLibrary = true, showPropertiesPanel = true, }) {
28504
- const { form, loadForm, addRowWithField } = useFormStore();
28504
+ const { form, loadForm, addRowWithField, addField, addFieldToContainer, addFieldToContainerDirect } = useFormStore();
28505
28505
  const [activeId, setActiveId] = useState(null);
28506
28506
  const [activeType, setActiveType] = useState(null);
28507
28507
  const [jsonViewerOpen, setJsonViewerOpen] = useState(false);
@@ -28562,33 +28562,61 @@ function FormBuilder({ initialForm, onSave, onChange, className = '', theme = 'l
28562
28562
  }
28563
28563
  const activeData = active.data.current;
28564
28564
  const overData = over.data.current;
28565
+ // Check for library item (using actual data structure from ComponentLibrary)
28566
+ const isLibraryItem = activeData?.isLibraryItem;
28567
+ const fieldType = activeData?.componentType || activeData?.type;
28568
+ // Determine drop target type
28569
+ const dropType = overData?.type;
28570
+ const isCanvas = dropType === 'canvas';
28571
+ const isColumn = dropType === 'column';
28572
+ const isContainerDrop = dropType === 'container-drop';
28573
+ const isContainerColumn = dropType === 'container-column';
28565
28574
  console.log('[FormBuilder] Checking conditions:', {
28566
- isNew: activeData?.isNew,
28567
- fieldType: activeData?.fieldType,
28568
- isCanvas: overData?.isCanvas,
28569
- columnId: overData?.columnId
28575
+ isLibraryItem,
28576
+ fieldType,
28577
+ dropType,
28578
+ isCanvas,
28579
+ isColumn,
28580
+ isContainerDrop,
28581
+ isContainerColumn,
28582
+ overData
28570
28583
  });
28571
- if (activeData?.isNew && activeData?.fieldType) {
28572
- const fieldType = activeData.fieldType;
28573
- if (overData?.isCanvas || overData?.columnId) {
28574
- console.log('[FormBuilder] Adding field:', fieldType);
28575
- addRowWithField({
28576
- type: fieldType,
28577
- props: {
28578
- key: `field_${Date.now()}`,
28579
- label: getDefaultLabel(fieldType),
28580
- placeholder: '',
28581
- },
28582
- validation: {},
28583
- customStyle: {},
28584
- });
28585
- }
28586
- else {
28587
- console.log('[FormBuilder] Drop target not canvas or column');
28588
- }
28584
+ if (!isLibraryItem || !fieldType) {
28585
+ console.log('[FormBuilder] Not a library item drag');
28586
+ return;
28587
+ }
28588
+ const newField = {
28589
+ type: fieldType,
28590
+ props: {
28591
+ key: `field_${Date.now()}`,
28592
+ label: getDefaultLabel(fieldType),
28593
+ placeholder: '',
28594
+ },
28595
+ validation: {},
28596
+ customStyle: {},
28597
+ };
28598
+ if (isContainerColumn && overData?.rowId && overData?.columnId && overData?.containerFieldId && overData?.containerRowId && overData?.containerColumnId) {
28599
+ // Drop into a specific container column
28600
+ console.log('[FormBuilder] Adding field to container column:', fieldType);
28601
+ addFieldToContainer(overData.rowId, overData.columnId, overData.containerFieldId, overData.containerRowId, overData.containerColumnId, newField);
28602
+ }
28603
+ else if (isContainerDrop && overData?.rowId && overData?.columnId && overData?.containerFieldId) {
28604
+ // Drop into container directly (adds to first row)
28605
+ console.log('[FormBuilder] Adding field to container direct:', fieldType);
28606
+ addFieldToContainerDirect(overData.rowId, overData.columnId, overData.containerFieldId, newField);
28607
+ }
28608
+ else if (isColumn && overData?.rowId && overData?.columnId) {
28609
+ // Drop into an existing column
28610
+ console.log('[FormBuilder] Adding field to existing column:', fieldType);
28611
+ addField(overData.rowId, overData.columnId, newField);
28612
+ }
28613
+ else if (isCanvas) {
28614
+ // Drop into canvas - create new row
28615
+ console.log('[FormBuilder] Adding field as new row:', fieldType);
28616
+ addRowWithField(newField);
28589
28617
  }
28590
28618
  else {
28591
- console.log('[FormBuilder] Not a new field drag');
28619
+ console.log('[FormBuilder] Unknown drop target');
28592
28620
  }
28593
28621
  };
28594
28622
  return (jsx(TooltipProvider, { children: jsxs("div", { className: `formbuilder-container ${theme} ${className}`, children: [jsxs(DndContext, { sensors: sensors, collisionDetection: closestCenter, onDragStart: handleDragStart, onDragOver: handleDragOver, onDragEnd: handleDragEnd, children: [jsxs("div", { className: "flex flex-col h-full", children: [showToolbar && (jsx(Toolbar, { onOpenJsonViewer: () => setJsonViewerOpen(true) })), jsxs("div", { className: "flex flex-1 overflow-hidden", children: [showComponentLibrary && (jsx(ComponentLibrary, {})), jsx("div", { className: "flex-1 overflow-auto", children: jsx(FormCanvas, {}) }), showPropertiesPanel && (jsx(PropertiesPanel, {}))] })] }), jsx(DragOverlay, { children: activeId && activeType && (jsx(DragOverlayContent, { type: activeType })) })] }), jsx(JsonViewerModal, { isOpen: jsonViewerOpen, onClose: () => setJsonViewerOpen(false), schema: form })] }) }));