Prevent dragging the screen or layout components, and prevent dragging any layout components when previewing a screen

This commit is contained in:
Andrew Kingston 2021-09-16 07:52:49 +01:00
parent 5cd1559a86
commit b0f6bd9e76
4 changed files with 15 additions and 5 deletions

View File

@ -105,7 +105,10 @@
<div id="app-root">
<CustomThemeWrapper>
{#key $screenStore.activeLayout._id}
<Component instance={$screenStore.activeLayout.props} />
<Component
isLayout
instance={$screenStore.activeLayout.props}
/>
{/key}
<!-- Layers on top of app -->

View File

@ -11,6 +11,8 @@
import Placeholder from "components/app/Placeholder.svelte"
export let instance = {}
export let isLayout = false
export let isScreen = false
// The enriched component settings
let enrichedSettings
@ -178,7 +180,8 @@
data-type={interactive ? "component" : ""}
data-id={id}
data-name={name}
data-droppable={definition?.hasChildren || false}
data-draggable={interactive && !isLayout && !isScreen ? "true" : "false"}
data-droppable={definition?.hasChildren ? "true" : "false"}
>
<svelte:component this={constructor} {...componentSettings}>
{#if children.length}
@ -197,7 +200,7 @@
.component {
display: contents;
}
.component > :global(*:hover) {
[data-draggable="true"] {
cursor: pointer;
}
</style>

View File

@ -22,6 +22,6 @@
<!-- Ensure to fully remount when screen changes -->
{#key screenDefinition?._id}
<Provider key="url" data={params}>
<Component instance={screenDefinition} />
<Component isScreen instance={screenDefinition} />
</Provider>
{/key}

View File

@ -23,7 +23,11 @@ export const styleable = (node, styles = {}) => {
let applyHoverStyles
let selectComponent
node.setAttribute("draggable", true)
// Allow dragging if required
const parent = node.closest("[data-type='component']")
if (parent && parent.dataset.draggable === "true") {
node.setAttribute("draggable", true)
}
// Creates event listeners and applies initial styles
const setupStyles = (newStyles = {}) => {