Merge pull request #536 from mjashanks/dnd

Few Dnd Bugfixes
This commit is contained in:
Michael Shanks 2020-08-27 09:33:25 +01:00 committed by GitHub
commit 53eccb5379
5 changed files with 43 additions and 6 deletions

View File

@ -24,6 +24,7 @@ import {
saveScreenApi as _saveScreenApi, saveScreenApi as _saveScreenApi,
regenerateCssForCurrentScreen, regenerateCssForCurrentScreen,
generateNewIdsForComponent, generateNewIdsForComponent,
getComponentDefinition,
} from "../storeUtils" } from "../storeUtils"
export const getStore = () => { export const getStore = () => {
const initial = { const initial = {
@ -74,9 +75,6 @@ export const getStore = () => {
export default getStore export default getStore
export const getComponentDefinition = (state, name) =>
name.startsWith("##") ? getBuiltin(name) : state.components[name]
const setPackage = (store, initial) => async pkg => { const setPackage = (store, initial) => async pkg => {
const [main_screens, unauth_screens] = await Promise.all([ const [main_screens, unauth_screens] = await Promise.all([
api api

View File

@ -1,4 +1,7 @@
import { makePropsSafe } from "components/userInterface/pagesParsing/createProps" import {
makePropsSafe,
getBuiltin,
} from "components/userInterface/pagesParsing/createProps"
import api from "./api" import api from "./api"
import { generate_screen_css } from "./generate_css" import { generate_screen_css } from "./generate_css"
import { uuid } from "./uuid" import { uuid } from "./uuid"
@ -85,3 +88,6 @@ export const generateNewIdsForComponent = c =>
walkProps(c, p => { walkProps(c, p => {
p._id = uuid() p._id = uuid()
}) })
export const getComponentDefinition = (state, name) =>
name.startsWith("##") ? getBuiltin(name) : state.components[name]

View File

@ -1,7 +1,7 @@
<script> <script>
import { MoreIcon } from "components/common/Icons" import { MoreIcon } from "components/common/Icons"
import { store } from "builderStore" import { store } from "builderStore"
import { getComponentDefinition } from "builderStore/store" import { getComponentDefinition } from "builderStore/storeUtils"
import ConfirmDialog from "components/common/ConfirmDialog.svelte" import ConfirmDialog from "components/common/ConfirmDialog.svelte"
import { last, cloneDeep } from "lodash/fp" import { last, cloneDeep } from "lodash/fp"
import UIkit from "uikit" import UIkit from "uikit"

View File

@ -11,6 +11,11 @@
export let screens = [] export let screens = []
/*
Using a store here seems odd....
have a look in the <ComponentsHierarchyChildren /> code file to find out why.
I have commented the dragDropStore parameter
*/
const dragDropStore = writable({}) const dragDropStore = writable({})
let confirmDeleteDialog let confirmDeleteDialog

View File

@ -10,11 +10,29 @@
ChevronDownIcon, ChevronDownIcon,
CopyIcon, CopyIcon,
} from "../common/Icons" } from "../common/Icons"
import { getComponentDefinition } from "builderStore/storeUtils"
export let components = [] export let components = []
export let currentComponent export let currentComponent
export let onSelect = () => {} export let onSelect = () => {}
export let level = 0 export let level = 0
/*
"dragDropStore" is a svelte store.
This component is recursive... a tree.
Using a single, shared store, all the nodes in the tree can subscribe to state that is changed by other nodes, in the same tree.
e.g. Say i have the structure
- Heading 1
- Container
- Heading 2
- Heading 3
- Heading 4
1. When I dragover "Heading 1", a placeholder drop-slot appears below it
2. I drag down a bit so the cursor is INSIDE the container (i.e. now in a child <ComponentsHierarchyChildren />)
3. Using store subscribes... the original drop-slot now knows that it should disappear, and a new one is created inside the container.
*/
export let dragDropStore export let dragDropStore
let dropUnderComponent let dropUnderComponent
@ -47,7 +65,7 @@
const dragover = (component, index) => e => { const dragover = (component, index) => e => {
const canHaveChildrenButIsEmpty = const canHaveChildrenButIsEmpty =
$store.components[component._component].children && getComponentDefinition($store, component._component).children &&
component._children.length === 0 component._children.length === 0
e.dataTransfer.dropEffect = "copy" e.dataTransfer.dropEffect = "copy"
@ -97,6 +115,15 @@
return s return s
}) })
} }
const dragend = () => {
dragDropStore.update(s => {
s.dropPosition = ""
s.targetComponent = null
s.componentToDrop = null
return s
})
}
</script> </script>
<ul> <ul>
@ -117,6 +144,7 @@
class:selected={currentComponent === component} class:selected={currentComponent === component}
style="padding-left: {level * 20 + 40}px" style="padding-left: {level * 20 + 40}px"
draggable={true} draggable={true}
on:dragend={dragend}
on:dragstart={dragstart(component)} on:dragstart={dragstart(component)}
on:dragover={dragover(component, index)} on:dragover={dragover(component, index)}
on:drop={drop} on:drop={drop}