1
0
Fork 0
mirror of synced 2024-10-02 01:56:57 +13:00

Make DND work again by converting new parent+index params into old target+mode

This commit is contained in:
Andrew Kingston 2022-10-10 09:36:17 +01:00
parent 6cf3a0af5b
commit c5b36863d2

View file

@ -1,9 +1,11 @@
<script> <script>
import { onMount, onDestroy } from "svelte" import { onMount, onDestroy } from "svelte"
import { get } from "svelte/store"
import IndicatorSet from "./IndicatorSet.svelte" import IndicatorSet from "./IndicatorSet.svelte"
import { builderStore } from "stores" import { builderStore, componentStore } from "stores"
import PlaceholderOverlay from "./PlaceholderOverlay.svelte" import PlaceholderOverlay from "./PlaceholderOverlay.svelte"
import { Utils } from "@budibase/frontend-core" import { Utils } from "@budibase/frontend-core"
import { findComponentById } from "utils/components.js"
let sourceId let sourceId
let targetInfo let targetInfo
@ -34,8 +36,6 @@
// Callback when drag stops (whether dropped or not) // Callback when drag stops (whether dropped or not)
const stopDragging = () => { const stopDragging = () => {
console.log("END")
// Reset state // Reset state
sourceId = null sourceId = null
targetInfo = null targetInfo = null
@ -198,12 +198,37 @@
// Callback when dropping a drag on top of some component // Callback when dropping a drag on top of some component
const onDrop = () => { const onDrop = () => {
console.log("DROP") let target, mode
// builderStore.actions.moveComponent(
// dragInfo.target, // Convert parent + index into target + mode
// dropInfo.target, if (sourceId && dropInfo?.parent && dropInfo.index != null) {
// dropInfo.mode const parent = findComponentById(
// ) get(componentStore).currentAsset?.props,
dropInfo.parent
)
if (!parent) {
return
}
// Filter out source component from consideration
const children = parent._children?.filter(x => x._id !== sourceId)
// Use inside if no existing children
if (!children?.length) {
target = parent._id
mode = "inside"
} else if (dropInfo.index === 0) {
target = children[0]?._id
mode = "above"
} else {
target = children[dropInfo.index - 1]?._id
mode = "below"
}
}
if (target && mode) {
builderStore.actions.moveComponent(sourceId, target, mode)
}
} }
onMount(() => { onMount(() => {