feat(types): Add NodeTypes and EdgeTypes

* Interface for passing an object of NodeTypes/EdgeTypes
* Object needs to be passed with components markedRaw

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
Braks
2021-11-19 17:47:57 +01:00
parent 8c4747a8a9
commit 37388ddf47
17 changed files with 69 additions and 74 deletions
+9 -3
View File
@@ -1,12 +1,11 @@
<script lang="ts" setup>
import { DraggableEventListener, DraggableCore } from '@braks/revue-draggable'
import { useStore } from '../../composables'
import { Node, NodeType, SnapGrid } from '../../types'
import { Node, SnapGrid } from '../../types'
import { NodeId } from '../../context'
interface NodeProps {
node: Node
type: NodeType
selectNodesOnDrag?: boolean
snapGrid?: SnapGrid
}
@@ -21,6 +20,12 @@ provide(NodeId, props.node.id)
const nodeElement = templateRef<HTMLDivElement>('node-element', null)
const nodeType = props.node.type || 'default'
const type = store.getNodeTypes[nodeType] || store.getNodeTypes.default
if (!store.getNodeTypes[nodeType]) {
console.warn(`Node type "${nodeType}" not found. Using fallback type "default".`)
}
const selectable = computed(() =>
typeof props.node.selectable === 'undefined' ? store.elementsSelectable : props.node.selectable,
)
@@ -184,7 +189,8 @@ onMounted(() => {
}"
>
<component
:is="props.type"
:is="type"
v-if="typeof type !== 'boolean'"
v-bind="{
id: props.node.id,
data: props.node.data,