Skip to content

Commit 95e3146

Browse files
committed
fix: cannot drag control to stage
flex controled height is not visible to sortablejs
1 parent 25852ba commit 95e3146

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

src/lib/js/components/columns/column.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export default class Column extends Component {
7171
Sortable.create(childWrap, {
7272
animation: 150,
7373
fallbackClass: 'field-moving',
74+
forceFallback: true,
7475
group: {
7576
name: 'column',
7677
pull: true,

src/lib/js/components/controls/index.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -285,31 +285,42 @@ export class Controls {
285285
for (let i = groups.length - 1; i >= 0; i--) {
286286
const storeID = `formeo-controls-${groups[i]}`
287287
if (!this.options.sortable) {
288-
window.localStorage.removeItem(storeID)
288+
globalThis.localStorage.removeItem(storeID)
289289
}
290290
Sortable.create(groups[i], {
291291
animation: 150,
292-
forceFallback: true,
293292
fallbackClass: 'control-moving',
294293
fallbackOnBody: true,
294+
forceFallback: true,
295+
fallbackTolerance: 5,
295296
group: {
296297
name: 'controls',
297298
pull: 'clone',
298299
put: false,
300+
revertClone: true,
299301
},
300-
onStart: async ({ item }) => {
301-
const { controlData } = this.get(item.id)
302+
onClone: ({ clone, item }) => {
303+
// Copy the item's id to the clone so we can identify what control it represents
304+
clone.id = item.id
305+
302306
if (this.options.ghostPreview) {
307+
const { controlData } = this.get(item.id)
303308
// Dynamically import Field to avoid circular dependency
304-
const { default: Field } = await import('../fields/field.js')
305-
item.innerHTML = ''
306-
item.appendChild(new Field(controlData).preview)
309+
import('../fields/field.js').then(({ default: Field }) => {
310+
clone.innerHTML = ''
311+
clone.appendChild(new Field(controlData).preview)
312+
})
307313
}
308314
},
309-
onEnd: ({ from, item, clone }) => {
310-
if (from.contains(clone)) {
311-
from.replaceChild(item, clone)
312-
}
315+
onStart: () => {
316+
// Prevent scrollbar flashing during drag by hiding overflow
317+
this.originalDocumentOverflow = document.documentElement.style.overflow
318+
document.documentElement.style.overflow = 'hidden'
319+
},
320+
onEnd: () => {
321+
// Restore overflow after drag completes
322+
document.documentElement.style.overflow = this.originalDocumentOverflow
323+
this.originalDocumentOverflow = null
313324
},
314325
sort: this.options.sortable,
315326
store: {
@@ -319,7 +330,7 @@ export class Controls {
319330
* @return {Array}
320331
*/
321332
get: () => {
322-
const order = window.localStorage.getItem(storeID)
333+
const order = globalThis.localStorage.getItem(storeID)
323334
return order ? order.split('|') : []
324335
},
325336

@@ -329,7 +340,7 @@ export class Controls {
329340
*/
330341
set: sortable => {
331342
const order = sortable.toArray()
332-
window.localStorage.setItem(storeID, order.join('|'))
343+
globalThis.localStorage.setItem(storeID, order.join('|'))
333344
},
334345
},
335346
})

src/lib/js/components/rows/row.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export default class Row extends Component {
5353
Sortable.create(children, {
5454
animation: 150,
5555
fallbackClass: 'column-moving',
56+
forceFallback: true,
5657
group: {
5758
name: 'row',
5859
pull: true,

src/lib/sass/components/_stage.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
>.children {
3131
@include mixins.display-column;
3232
gap: var.$component-gap;
33+
min-height: 100%;
3334
}
3435

3536
&.removing-all-fields {

0 commit comments

Comments
 (0)