@@ -35,68 +35,10 @@ import { MobileNotification } from "@/components/form-builder/ui/mobile-notifica
3535import { useIsMobile } from "@/hooks/use-mobile" ;
3636import SocialLinks from "@/components/form-builder/sidebar/socialLinks" ;
3737import { OpenJsonDialog } from "@/components/form-builder/dialogs/open-json-dialog" ;
38- import { sortableKeyboardCoordinates } from "@dnd-kit/sortable" ;
3938import { useForm } from "react-hook-form" ;
40- import { FormComponentModel } from "@/models/FormComponent" ;
41- import { Viewports } from "@/types/form-builder.types" ;
39+ import { getGridRows , updateColSpans } from "@/lib/utils" ;
4240import { RenderEditorComponent } from "@/components/form-builder/helpers/render-editor-component" ;
43-
44- const getGridRows = (
45- items : FormComponentModel [ ] ,
46- viewport : Viewports
47- ) : FormComponentModel [ ] [ ] => {
48- const rows : FormComponentModel [ ] [ ] = [ ] ;
49- let currentRow : FormComponentModel [ ] = [ ] ;
50- let currentRowSpan = 0 ;
51-
52- items . forEach ( ( item ) => {
53- const colSpan = + item . getField ( "properties.style.colSpan" , viewport ) || 12 ;
54-
55- // If adding this item would exceed 12 columns, start a new row
56- if ( currentRowSpan + colSpan > 12 ) {
57- if ( currentRow . length > 0 ) {
58- rows . push ( [ ...currentRow ] ) ;
59- }
60- currentRow = [ item ] ;
61- currentRowSpan = colSpan ;
62- } else {
63- currentRow . push ( item ) ;
64- currentRowSpan += colSpan ;
65- }
66- } ) ;
67-
68- // Add the last row if it has items
69- if ( currentRow . length > 0 ) {
70- rows . push ( currentRow ) ;
71- }
72-
73- return rows ;
74- } ;
75-
76- export function updateColSpans (
77- updateItems : FormComponentModel [ ]
78- ) : { id : string ; span : number } [ ] {
79- if ( ! updateItems . length ) return [ ] ;
80-
81- const totalColumns = 12 ;
82- const itemCount = updateItems . length ;
83-
84- // Calculate base span and remainder
85- const baseSpan = Math . floor ( totalColumns / itemCount ) ;
86- const remainder = totalColumns % itemCount ;
87-
88- const adjustedSpans : { id : string ; span : number } [ ] = [ ] ;
89-
90- // Distribute spans equally, with remainder distributed to first few items
91- updateItems . forEach ( ( item , index ) => {
92- if ( ! item ) return ;
93- // Add one extra column to the first 'remainder' items
94- const span = index < remainder ? baseSpan + 1 : baseSpan ;
95- adjustedSpans . push ( { id : item . id , span } ) ;
96- } ) ;
97-
98- return adjustedSpans ;
99- }
41+ import { FormComponentModel } from "@/models/FormComponent" ;
10042
10143export default function FormBuilderPage ( ) {
10244 const isMobile = useIsMobile ( ) ;
@@ -118,7 +60,7 @@ export default function FormBuilderPage() {
11860 code : string ;
11961 dependenciesImports : DependenciesImports ;
12062 } > ( { code : "" , dependenciesImports : { } } ) ;
121- const [ activeId , setActiveId ] = useState < string | null > ( null ) ;
63+ const [ draggingDOMElement , setDraggingDOMElement ] = useState < HTMLElement | null > ( null ) ;
12264 const form = useForm ( ) ;
12365
12466 // Memoize static values
@@ -281,7 +223,10 @@ export default function FormBuilderPage() {
281223 const handleDragStart = useCallback (
282224 ( event : DragStartEvent ) => {
283225 selectComponent ( null ) ;
284- setActiveId ( event . active . id as string ) ;
226+ const element = document . querySelector ( `[data-item-id="${ event . active . data . current ?. component . id } "]` ) ;
227+ if ( element ) {
228+ setDraggingDOMElement ( element as HTMLElement ) ;
229+ }
285230 } ,
286231 [ selectComponent ]
287232 ) ;
@@ -388,9 +333,11 @@ export default function FormBuilderPage() {
388333 < SidebarRight />
389334 </ div >
390335 < DragOverlay >
391- < div >
392- Form element
393- </ div >
336+ { draggingDOMElement && (
337+ < div className = "bg-white p-2 rounded-md shadow opacity-80" >
338+ < div dangerouslySetInnerHTML = { { __html : draggingDOMElement . innerHTML } } className = "max-h-52 overflow-hidden" />
339+ </ div >
340+ ) }
394341 </ DragOverlay >
395342 </ DndContext >
396343 </ SidebarProvider >
0 commit comments