Refactor to use generic flag for dragging and hide settings bar when dragging
This commit is contained in:
parent
f0b7188db3
commit
7eeb215e51
|
@ -21,6 +21,7 @@
|
||||||
// Update state
|
// Update state
|
||||||
dragTarget = e.target.dataset.componentId
|
dragTarget = e.target.dataset.componentId
|
||||||
builderStore.actions.selectComponent(dragTarget)
|
builderStore.actions.selectComponent(dragTarget)
|
||||||
|
builderStore.actions.setDragging(true)
|
||||||
|
|
||||||
// Highlight being dragged by setting opacity
|
// Highlight being dragged by setting opacity
|
||||||
const child = getDOMNodeForComponent(e.target)
|
const child = getDOMNodeForComponent(e.target)
|
||||||
|
@ -34,15 +35,13 @@
|
||||||
// Reset state and styles
|
// Reset state and styles
|
||||||
dropTarget = null
|
dropTarget = null
|
||||||
dropInfo = null
|
dropInfo = null
|
||||||
|
builderStore.actions.setDragging(false)
|
||||||
|
|
||||||
// Reset opacity style
|
// Reset opacity style
|
||||||
const child = getDOMNodeForComponent(e.target)
|
const child = getDOMNodeForComponent(e.target)
|
||||||
if (child) {
|
if (child) {
|
||||||
child.style.opacity = ""
|
child.style.opacity = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-enable the hover indicator
|
|
||||||
builderStore.actions.showHoverIndicator(true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Callback when on top of a component
|
// Callback when on top of a component
|
||||||
|
@ -96,11 +95,11 @@
|
||||||
element.dataset.droppable &&
|
element.dataset.droppable &&
|
||||||
element.dataset.id !== dragTarget
|
element.dataset.id !== dragTarget
|
||||||
) {
|
) {
|
||||||
// Disable hover selection again to ensure it's always disabled.
|
// Ensure the dragging flag is always set.
|
||||||
// There's a bit of a race condition between the app reinitialisation
|
// There's a bit of a race condition between the app reinitialisation
|
||||||
// after selecting the DND component and setting this the first time
|
// after selecting the DND component and setting this the first time
|
||||||
if (get(builderStore).showHoverIndicator) {
|
if (!get(builderStore).isDragging) {
|
||||||
builderStore.actions.showHoverIndicator(false)
|
builderStore.actions.setDragging(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store target ID
|
// Store target ID
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<IndicatorSet
|
<IndicatorSet
|
||||||
componentId={$builderStore.showHoverIndicator ? componentId : null}
|
componentId={$builderStore.isDragging ? null : componentId}
|
||||||
color="var(--spectrum-global-color-static-blue-200)"
|
color="var(--spectrum-global-color-static-blue-200)"
|
||||||
transition
|
transition
|
||||||
{zIndex}
|
{zIndex}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
let measured = false
|
let measured = false
|
||||||
|
|
||||||
$: definition = $builderStore.selectedComponentDefinition
|
$: definition = $builderStore.selectedComponentDefinition
|
||||||
$: showBar = definition?.showSettingsBar
|
$: showBar = definition?.showSettingsBar && !$builderStore.isDragging
|
||||||
$: settings = definition?.settings?.filter(setting => setting.showInBar) ?? []
|
$: settings = definition?.settings?.filter(setting => setting.showInBar) ?? []
|
||||||
|
|
||||||
const updatePosition = () => {
|
const updatePosition = () => {
|
||||||
|
|
|
@ -23,7 +23,7 @@ const createBuilderStore = () => {
|
||||||
theme: null,
|
theme: null,
|
||||||
customTheme: null,
|
customTheme: null,
|
||||||
previewDevice: "desktop",
|
previewDevice: "desktop",
|
||||||
showHoverIndicator: true,
|
isDragging: false,
|
||||||
}
|
}
|
||||||
const writableStore = writable(initialState)
|
const writableStore = writable(initialState)
|
||||||
const derivedStore = derived(writableStore, $state => {
|
const derivedStore = derived(writableStore, $state => {
|
||||||
|
@ -77,16 +77,15 @@ const createBuilderStore = () => {
|
||||||
mode,
|
mode,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
showHoverIndicator: show => {
|
setDragging: dragging => {
|
||||||
writableStore.update(state => {
|
writableStore.update(state => {
|
||||||
state.showHoverIndicator = show
|
state.isDragging = dragging
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
...writableStore,
|
...writableStore,
|
||||||
set: state => writableStore.set({ ...initialState, ...state }),
|
|
||||||
subscribe: derivedStore.subscribe,
|
subscribe: derivedStore.subscribe,
|
||||||
actions,
|
actions,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue