Skip to content

Commit

Permalink
fix: remove redundant droppingToPlaceholderRow which uses the same ch…
Browse files Browse the repository at this point in the history
…eck as droppingToNewRow, and simplify the logic.
  • Loading branch information
lucasnetau committed Nov 4, 2023
1 parent b8fd49a commit 62c0562
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions src/js/form-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1316,34 +1316,32 @@ function FormBuilder(opts, element, $) {
const senderIsControlsBox = $(ui.sender).attr('id') === $cbUL.attr('id')

const droppingToNewRow = $(ui.item).parent().hasClass(tmpRowPlaceholderClass)
const droppingToPlaceholderRow = $(ui.item).parent().hasClass(tmpRowPlaceholderClass)
const droppingToExistingRow =
$(ui.item).parent().hasClass(rowWrapperClass) && !$(ui.item).parent().hasClass(tmpRowPlaceholderClass)
const droppingToExistingRow = !droppingToNewRow && $(ui.item).parent().hasClass(rowWrapperClass)

if (droppingToNewRow && !senderIsControlsBox) {
const colWrapper = $(ui.item)

const columnData = prepareFieldRow({})
if (droppingToNewRow) {
if (senderIsControlsBox) {
insertTargetIsRow = true
insertingNewControl = true
$targetInsertWrapper = $(ui.item).parent()
} else {
const colWrapper = $(ui.item)

const rowWrapperNode = m('div', null, {
id: `${colWrapper.find('li').attr('id')}-row`,
className: `row row-${columnData.rowUniqueId} ${rowWrapperClass}`,
})
const columnData = prepareFieldRow({})

$(ui.item).parent().replaceWith(rowWrapperNode)
AttachColWrapperHandler($(ui.item))
const rowWrapperNode = m('div', null, {
id: `${colWrapper.find('li').attr('id')}-row`,
className: `row row-${columnData.rowUniqueId} ${rowWrapperClass}`,
})

colWrapper.appendTo(rowWrapperNode)
$(ui.item).parent().replaceWith(rowWrapperNode)
AttachColWrapperHandler($(ui.item))

setupSortableRowWrapper(rowWrapperNode)
syncFieldWithNewRow(colWrapper.attr('id'))
checkRowCleanup()
}
colWrapper.appendTo(rowWrapperNode)

if (droppingToPlaceholderRow && senderIsControlsBox) {
insertTargetIsRow = true
insertingNewControl = true
$targetInsertWrapper = $(ui.item).parent()
setupSortableRowWrapper(rowWrapperNode)
syncFieldWithNewRow(colWrapper.attr('id'))
checkRowCleanup()
}
}

if (droppingToExistingRow && senderIsControlsBox) {
Expand Down

0 comments on commit 62c0562

Please sign in to comment.