update: make types for nodes and edges a computed prop
* remove nodeTypesId (was used in react to manually trigger a nodeTypes change) Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -45,7 +45,7 @@ const changeType = () => {
|
||||
const onConnect = (params: Connection | Edge) => (elements.value = addEdge(params, elements.value))
|
||||
</script>
|
||||
<template>
|
||||
<VueFlow :elements="elements" :node-types="nodeTypesObjects[nodeTypesId]" :node-types-id="nodeTypesId" @connect="onConnect">
|
||||
<VueFlow v-model="elements" :node-types="nodeTypesObjects[nodeTypesId]" @connect="onConnect">
|
||||
<template #node-a>
|
||||
<NodeA :node-styles="nodeStyles" />
|
||||
</template>
|
||||
|
||||
@@ -15,11 +15,14 @@ const props = withDefaults(defineProps<EdgeProps>(), {})
|
||||
|
||||
const store = useStore()
|
||||
|
||||
const edgeType = props.edge.type || 'default'
|
||||
const type = store.getEdgeTypes[edgeType] || store.getEdgeTypes.default
|
||||
if (!store.getEdgeTypes[edgeType]) {
|
||||
console.warn(`Edge type "${edgeType}" not found. Using fallback type "default".`)
|
||||
}
|
||||
const type = computed(() => {
|
||||
const edgeType = props.edge.type || 'default'
|
||||
const t = store.getEdgeTypes[edgeType] || store.getEdgeTypes.default
|
||||
if (!store.getEdgeTypes[edgeType]) {
|
||||
console.warn(`Edge type "${edgeType}" not found. Using fallback type "default".`)
|
||||
}
|
||||
return t
|
||||
})
|
||||
const updating = ref<boolean>(false)
|
||||
|
||||
const onEdgeClick = (event: MouseEvent) => {
|
||||
|
||||
@@ -20,11 +20,14 @@ 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 type = computed(() => {
|
||||
const nodeType = props.node.type ?? 'default'
|
||||
const t = store.getNodeTypes[nodeType] || store.getNodeTypes.default
|
||||
if (!store.getNodeTypes[nodeType]) {
|
||||
console.warn(`Node type "${nodeType}" not found. Using fallback type "default".`)
|
||||
}
|
||||
return t
|
||||
})
|
||||
|
||||
const selectable = computed(() =>
|
||||
typeof props.node.selectable === 'undefined' ? store.elementsSelectable : props.node.selectable,
|
||||
@@ -34,7 +37,7 @@ const connectable = computed(() =>
|
||||
typeof props.node.connectable === 'undefined' ? store.nodesConnectable : props.node.connectable,
|
||||
)
|
||||
const scale = computed(() => store.transform[2])
|
||||
const selected = computed(() => selectable && store.selectedElements?.some(({ id }) => id === props.node.id))
|
||||
const selected = computed(() => selectable.value && store.selectedElements?.some(({ id }) => id === props.node.id))
|
||||
|
||||
const onMouseEnterHandler = () =>
|
||||
props.node.__rf?.isDragging && ((event: MouseEvent) => store.hooks.nodeMouseEnter.trigger({ event, node: props.node }))
|
||||
|
||||
@@ -140,11 +140,10 @@ watch(
|
||||
)
|
||||
watch(
|
||||
() => props,
|
||||
(val, oldVal) => {
|
||||
const hasDiff = diff(val, oldVal)
|
||||
if (hasDiff.length > 0) init({ ...store.$state, ...val } as FlowState)
|
||||
(val) => {
|
||||
init({ ...store.$state, ...val } as FlowState)
|
||||
},
|
||||
{ flush: 'pre', deep: true },
|
||||
{ flush: 'post', deep: true },
|
||||
)
|
||||
init(options)
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user