@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 +2 -0
- package/index.cjs +44 -22
- package/index.cjs.map +1 -1
- package/index.js +44 -22
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/types/lib/FormBuilder.d.ts.map +1 -1
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);
|
|
@@ -28565,36 +28565,58 @@ function FormBuilder({ initialForm, onSave, onChange, className = '', theme = 'l
|
|
|
28565
28565
|
// Check for library item (using actual data structure from ComponentLibrary)
|
|
28566
28566
|
const isLibraryItem = activeData?.isLibraryItem;
|
|
28567
28567
|
const fieldType = activeData?.componentType || activeData?.type;
|
|
28568
|
-
|
|
28569
|
-
const
|
|
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';
|
|
28570
28574
|
console.log('[FormBuilder] Checking conditions:', {
|
|
28571
28575
|
isLibraryItem,
|
|
28572
28576
|
fieldType,
|
|
28577
|
+
dropType,
|
|
28573
28578
|
isCanvas,
|
|
28574
28579
|
isColumn,
|
|
28575
|
-
|
|
28580
|
+
isContainerDrop,
|
|
28581
|
+
isContainerColumn,
|
|
28576
28582
|
overData
|
|
28577
28583
|
});
|
|
28578
|
-
if (isLibraryItem
|
|
28579
|
-
|
|
28580
|
-
|
|
28581
|
-
|
|
28582
|
-
|
|
28583
|
-
|
|
28584
|
-
|
|
28585
|
-
|
|
28586
|
-
|
|
28587
|
-
|
|
28588
|
-
|
|
28589
|
-
|
|
28590
|
-
|
|
28591
|
-
|
|
28592
|
-
|
|
28593
|
-
|
|
28594
|
-
|
|
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);
|
|
28595
28617
|
}
|
|
28596
28618
|
else {
|
|
28597
|
-
console.log('[FormBuilder]
|
|
28619
|
+
console.log('[FormBuilder] Unknown drop target');
|
|
28598
28620
|
}
|
|
28599
28621
|
};
|
|
28600
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 })] }) }));
|