From 05d627b846189f076c33e9fa99840d11f62d204f Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 23 May 2022 11:50:26 +0100 Subject: [PATCH] Finish new component DND experience --- .../src/components/common/NavItem.svelte | 1 + .../navigation/ComponentListPanel.svelte | 69 +++++++++++++------ .../navigation/ComponentTree.svelte | 20 ++---- .../DNDParentPositionIndicator.svelte | 9 --- .../navigation/DNDPositionIndicator.svelte | 66 +++++++++++------- .../_components/navigation/dndStore.js | 24 ++++--- 6 files changed, 109 insertions(+), 80 deletions(-) delete mode 100644 packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/navigation/DNDParentPositionIndicator.svelte diff --git a/packages/builder/src/components/common/NavItem.svelte b/packages/builder/src/components/common/NavItem.svelte index f0c447826e..4cb67dc9c4 100644 --- a/packages/builder/src/components/common/NavItem.svelte +++ b/packages/builder/src/components/common/NavItem.svelte @@ -156,6 +156,7 @@ } .icon.arrow { flex: 0 0 20px; + pointer-events: all; } .icon.arrow.absolute { position: absolute; diff --git a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/navigation/ComponentListPanel.svelte b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/navigation/ComponentListPanel.svelte index c887735ce7..5b86d4da29 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/navigation/ComponentListPanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/navigation/ComponentListPanel.svelte @@ -1,14 +1,15 @@ - -{#if $dndStore.targetParent?._id === component._id && $dndStore.dropPosition !== DropPosition.INSIDE} -
-{/if} diff --git a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/navigation/DNDPositionIndicator.svelte b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/navigation/DNDPositionIndicator.svelte index 8dbdc29c02..24b5839019 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/navigation/DNDPositionIndicator.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/navigation/DNDPositionIndicator.svelte @@ -1,47 +1,65 @@ -{#if $dndStore.dragging && $dndStore.valid} - {#if $dndStore?.target?._id === componentId} -
- {/if} +{#if component && position} +
{/if} -] diff --git a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/navigation/dndStore.js b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/navigation/dndStore.js index e512ddcca2..8a9e7ed915 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/navigation/dndStore.js +++ b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/navigation/dndStore.js @@ -20,7 +20,7 @@ const initialState = { valid: false, } -export default function () { +const createDNDStore = () => { const store = writable(initialState) const actions = { dragstart: component => { @@ -46,17 +46,8 @@ export default function () { let target let targetParent - // If the component has children, it cannot be dropped below - if (hasChildren) { - if (mousePosition <= 0.33) { - dropPosition = DropPosition.ABOVE - } else { - dropPosition = DropPosition.INSIDE - } - } - // If it can have children then it can be any position - else if (canHaveChildren) { + if (canHaveChildren) { if (mousePosition <= 0.33) { dropPosition = DropPosition.ABOVE } else if (mousePosition >= 0.66) { @@ -81,6 +72,15 @@ export default function () { target = component } + // If drop position and target are the same then we can skip this update + const state = get(store) + if ( + dropPosition === state.dropPosition && + target?._id === state.target?._id + ) { + return + } + // Find the parent of the target component if (target) { targetParent = findComponentParent( @@ -125,3 +125,5 @@ export default function () { actions, } } + +export const dndStore = createDNDStore()