update(pane): remove slots

* remove ref and set store state directly

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
Braks
2021-12-20 19:29:52 +01:00
parent 2210c59bf8
commit c8d701d3b4
+20 -33
View File
@@ -4,15 +4,12 @@ import { useStore, useKeyPress } from '../../composables'
import { getConnectedEdges } from '../../utils' import { getConnectedEdges } from '../../utils'
import NodesSelection from '../../components/NodesSelection/NodesSelection.vue' import NodesSelection from '../../components/NodesSelection/NodesSelection.vue'
import UserSelection from '../../components/UserSelection/UserSelection.vue' import UserSelection from '../../components/UserSelection/UserSelection.vue'
import NodeRenderer from '../NodeRenderer/NodeRenderer.vue'
import EdgeRenderer from '../EdgeRenderer/EdgeRenderer.vue'
const store = useStore() const store = useStore()
const userSelection = ref(false)
const onClick = (event: MouseEvent) => { const onClick = (event: MouseEvent) => {
store.hooks.paneClick.trigger(event) store.hooks.paneClick.trigger(event)
store.unsetNodesSelection() store.nodesSelectionActive = false
store.resetSelectedElements() store.resetSelectedElements()
} }
@@ -22,15 +19,15 @@ const onWheel = (event: WheelEvent) => store.hooks.paneScroll.trigger(event)
onMounted(() => { onMounted(() => {
useKeyPress(store.deleteKeyCode, (keyPressed) => { useKeyPress(store.deleteKeyCode, (keyPressed) => {
if (keyPressed && store.selectedElements) { if (keyPressed && (store.selectedNodes || store.selectedEdges)) {
const connectedEdges = getConnectedEdges(store.getSelectedNodes, store.getEdges) const connectedEdges = (store.selectedNodes && getConnectedEdges(store.selectedNodes, store.getEdges)) ?? []
const elementsToRemove = [...store.selectedElements, ...connectedEdges].reduce( const elementsToRemove = [...(store.selectedNodes ?? []), ...(store.selectedEdges ?? []), ...connectedEdges].reduce(
(res, item) => res.set(item.id, item), (res, item) => res.set(item.id, item),
new Map<string, FlowElement>(), new Map<string, FlowElement>(),
) )
store.hooks.elementsRemove.trigger(Array.from(elementsToRemove.values())) store.hooks.elementsRemove.trigger(Array.from(elementsToRemove.values()))
store.unsetNodesSelection() store.nodesSelectionActive = false
store.resetSelectedElements() store.resetSelectedElements()
} }
}) })
@@ -40,7 +37,8 @@ onMounted(() => {
}) })
useKeyPress(store.selectionKeyCode, (keyPressed) => { useKeyPress(store.selectionKeyCode, (keyPressed) => {
userSelection.value = keyPressed && (store.selectionActive || store.elementsSelectable) store.selectionActive =
store.selectionActive === true && keyPressed ? true : keyPressed && (store.selectionActive || store.elementsSelectable)
}) })
}) })
</script> </script>
@@ -51,28 +49,17 @@ export default {
} }
</script> </script>
<template> <template>
<NodeRenderer :key="`node-renderer-${store.id}`"> <UserSelection v-if="store.selectionActive" :key="`user-selection-${store.id}`" />
<template <NodesSelection
v-for="nodeName of Object.keys(store.getNodeTypes)" v-if="store.selectedNodes.length && !store.selectionActive && store.nodesSelectionActive"
#[`node-${nodeName}`]="nodeProps" :key="`nodes-selction-${store.id}`"
:key="`node-${nodeName}-${store.id}`" :nodes="store.selectedNodes"
> />
<slot :name="`node-${nodeName}`" v-bind="nodeProps" /> <div
</template> :key="`flow-pane-${store.id}`"
</NodeRenderer> class="vue-flow__pane vue-flow__container"
<EdgeRenderer :key="`edge-renderer-${store.id}`"> @click="onClick"
<template @contextmenu="onContextMenu"
v-for="edgeName of Object.keys(store.getEdgeTypes)" @wheel="onWheel"
#[`edge-${edgeName}`]="edgeProps" />
:key="`edge-${edgeName}-${store.id}`"
>
<slot :name="`edge-${edgeName}`" v-bind="edgeProps" />
</template>
<template #custom-connection-line="customConnectionLineProps">
<slot name="custom-connection-line" v-bind="customConnectionLineProps" />
</template>
</EdgeRenderer>
<UserSelection v-if="userSelection" :key="`user-selection-${store.id}`" />
<NodesSelection v-if="store.nodesSelectionActive" :key="`nodes-selction-${store.id}`" />
<div :key="`flow-pane-${store.id}`" class="vue-flow__pane" @click="onClick" @contextmenu="onContextMenu" @wheel="onWheel" />
</template> </template>