Allow normal DND in and out of grid children
This commit is contained in:
parent
a870d2473d
commit
a367863d43
|
@ -4573,7 +4573,9 @@
|
||||||
"hasChildren": true,
|
"hasChildren": true,
|
||||||
"styles": [
|
"styles": [
|
||||||
"size"
|
"size"
|
||||||
]
|
],
|
||||||
|
"illegalChildren": ["grid", "section"],
|
||||||
|
"allowedDirectChildren": [""]
|
||||||
},
|
},
|
||||||
"formblock": {
|
"formblock": {
|
||||||
"name": "Form Block",
|
"name": "Form Block",
|
||||||
|
|
|
@ -23,7 +23,10 @@
|
||||||
$: drop = $dndStore.drop
|
$: drop = $dndStore.drop
|
||||||
|
|
||||||
const insideGrid = e => {
|
const insideGrid = e => {
|
||||||
return e.target?.closest?.(".grid") != null
|
return e.target
|
||||||
|
?.closest?.(".component")
|
||||||
|
?.parentNode?.closest?.(".component")
|
||||||
|
?.childNodes[0]?.classList.contains("grid")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Util to get the inner DOM node by a component ID
|
// Util to get the inner DOM node by a component ID
|
||||||
|
@ -218,7 +221,7 @@
|
||||||
|
|
||||||
// Callback when on top of a component.
|
// Callback when on top of a component.
|
||||||
const onDragOver = e => {
|
const onDragOver = e => {
|
||||||
if (!source || !target || insideGrid(e)) {
|
if (!source || !target) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
handleEvent(e)
|
handleEvent(e)
|
||||||
|
@ -226,7 +229,7 @@
|
||||||
|
|
||||||
// Callback when entering a potential drop target
|
// Callback when entering a potential drop target
|
||||||
const onDragEnter = e => {
|
const onDragEnter = e => {
|
||||||
if (!source || insideGrid(e)) {
|
if (!source) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,7 +252,7 @@
|
||||||
|
|
||||||
// Callback when dropping a drag on top of some component
|
// Callback when dropping a drag on top of some component
|
||||||
const onDrop = e => {
|
const onDrop = e => {
|
||||||
if (!source || !drop?.parent || drop?.index == null || insideGrid(e)) {
|
if (!source || !drop?.parent || drop?.index == null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,13 @@
|
||||||
$: applyStyles(dragNode, gridStyles)
|
$: applyStyles(dragNode, gridStyles)
|
||||||
|
|
||||||
const insideGrid = e => {
|
const insideGrid = e => {
|
||||||
return e.target?.closest?.(".grid") || e.target.classList.contains("anchor")
|
return (
|
||||||
|
e.target
|
||||||
|
?.closest?.(".component")
|
||||||
|
?.parentNode?.closest?.(".component")
|
||||||
|
?.childNodes[0]?.classList.contains("grid") ||
|
||||||
|
e.target.classList.contains("anchor")
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Util to get the inner DOM node by a component ID
|
// Util to get the inner DOM node by a component ID
|
||||||
|
|
|
@ -9,21 +9,17 @@
|
||||||
const onMouseOver = e => {
|
const onMouseOver = e => {
|
||||||
// Ignore if dragging
|
// Ignore if dragging
|
||||||
if (e.buttons > 0) {
|
if (e.buttons > 0) {
|
||||||
console.log("ignore")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let newId
|
let newId
|
||||||
|
|
||||||
if (e.target.classList.contains("anchor")) {
|
if (e.target.classList.contains("anchor")) {
|
||||||
// Handle resize anchors
|
// Handle resize anchors
|
||||||
newId = e.target.dataset.id
|
newId = e.target.dataset.id
|
||||||
console.log("anchor", newId)
|
|
||||||
} else {
|
} else {
|
||||||
// Handle normal components
|
// Handle normal components
|
||||||
const element = e.target.closest(".interactive.component")
|
const element = e.target.closest(".interactive.component")
|
||||||
newId = element?.dataset?.id
|
newId = element?.dataset?.id
|
||||||
console.log("normal", newId)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newId !== componentId) {
|
if (newId !== componentId) {
|
||||||
|
|
|
@ -34,8 +34,9 @@
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we're a descendent of a grid
|
return component?.parentNode
|
||||||
return domNode?.closest(".grid") != null
|
?.closest?.(".component")
|
||||||
|
?.childNodes[0]?.classList.contains("grid")
|
||||||
}
|
}
|
||||||
|
|
||||||
const createIntersectionCallback = idx => entries => {
|
const createIntersectionCallback = idx => entries => {
|
||||||
|
|
Loading…
Reference in New Issue