feat: Add slots to edges and nodes

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
Braks
2021-11-18 03:19:13 +01:00
parent f22a3baa90
commit 8b82c4fb33
8 changed files with 70 additions and 50 deletions
+2
View File
@@ -65,6 +65,7 @@ export default {
</script> </script>
<template> <template>
<path class="vue-flow__edge-path" :style="props.style" :d="path" :marker-end="markerEnd" /> <path class="vue-flow__edge-path" :style="props.style" :d="path" :marker-end="markerEnd" />
<slot>
<EdgeText <EdgeText
v-if="props.label" v-if="props.label"
:x="centered[0]" :x="centered[0]"
@@ -76,4 +77,5 @@ export default {
:label-bg-padding="props.labelBgPadding" :label-bg-padding="props.labelBgPadding"
:label-bg-border-radius="props.labelBgBorderRadius" :label-bg-border-radius="props.labelBgBorderRadius"
/> />
</slot>
</template> </template>
+10 -4
View File
@@ -4,7 +4,12 @@ import { CSSProperties, HTMLAttributes } from 'vue'
interface EdgeTextProps extends HTMLAttributes { interface EdgeTextProps extends HTMLAttributes {
x: number x: number
y: number y: number
label?: any label?:
| string
| {
component: any
props?: any
}
labelStyle?: CSSProperties labelStyle?: CSSProperties
labelShowBg?: boolean labelShowBg?: boolean
labelBgStyle?: any labelBgStyle?: any
@@ -39,15 +44,16 @@ const bgPadding = computed(() => [props.labelBgPadding[0], props.labelBgPadding[
:ry="props.labelBgBorderRadius" :ry="props.labelBgBorderRadius"
/> />
<text ref="edge-text" class="vue-flow__edge-text" :y="height / 2" dy="0.3em" :style="props.labelStyle"> <text ref="edge-text" class="vue-flow__edge-text" :y="height / 2" dy="0.3em" :style="props.labelStyle">
<slot>
<component <component
:is="props.label.component" :is="props.label?.component"
v-if="typeof props.label.component !== 'undefined'" v-if="typeof props.label !== 'string' && typeof props.label?.component !== 'undefined'"
v-bind="{ ...props, ...props.label?.props, width, height, x, y }" v-bind="{ ...props, ...props.label?.props, width, height, x, y }"
/> />
<template v-else v-html="props.label"> <template v-else v-html="props.label">
{{ props.label }} {{ props.label }}
</template> </template>
</slot>
</text> </text>
<slot></slot>
</g> </g>
</template> </template>
+2
View File
@@ -68,6 +68,7 @@ export default {
</script> </script>
<template> <template>
<path class="vue-flow__edge-path" :style="props.style" :d="path" :marker-end="markerEnd" /> <path class="vue-flow__edge-path" :style="props.style" :d="path" :marker-end="markerEnd" />
<slot>
<EdgeText <EdgeText
v-if="props.label" v-if="props.label"
:x="centered[0]" :x="centered[0]"
@@ -79,4 +80,5 @@ export default {
:label-bg-padding="props.labelBgPadding" :label-bg-padding="props.labelBgPadding"
:label-bg-border-radius="props.labelBgBorderRadius" :label-bg-border-radius="props.labelBgBorderRadius"
/> />
</slot>
</template> </template>
+3 -1
View File
@@ -44,5 +44,7 @@ const props = withDefaults(defineProps<StepEdgeProps>(), {
}) })
</script> </script>
<template> <template>
<SmoothStepEdge v-bind="props" :border-radius="0" /> <SmoothStepEdge v-bind="props" :border-radius="0">
<slot />
</SmoothStepEdge>
</template> </template>
+2
View File
@@ -70,6 +70,7 @@ export default {
</script> </script>
<template> <template>
<path :style="props.style" class="vue-flow__edge-path" :d="path" :marker-end="markerEnd" /> <path :style="props.style" class="vue-flow__edge-path" :d="path" :marker-end="markerEnd" />
<slot>
<EdgeText <EdgeText
v-if="props.label" v-if="props.label"
:x="centerX" :x="centerX"
@@ -81,4 +82,5 @@ export default {
:label-bg-padding="props.labelBgPadding" :label-bg-padding="props.labelBgPadding"
:label-bg-border-radius="props.labelBgBorderRadius" :label-bg-border-radius="props.labelBgBorderRadius"
/> />
</slot>
</template> </template>
+2
View File
@@ -23,7 +23,9 @@ export default {
</script> </script>
<template> <template>
<Handle type="target" :position="props.targetPosition" :is-connectable="props.connectable" /> <Handle type="target" :position="props.targetPosition" :is-connectable="props.connectable" />
<slot>
<component :is="props.data?.label" v-if="typeof props.data?.label !== 'string'" /> <component :is="props.data?.label" v-if="typeof props.data?.label !== 'string'" />
<span v-else v-html="props.data?.label"></span> <span v-else v-html="props.data?.label"></span>
</slot>
<Handle type="source" :position="props.sourcePosition" :is-connectable="props.connectable" /> <Handle type="source" :position="props.sourcePosition" :is-connectable="props.connectable" />
</template> </template>
+2
View File
@@ -20,7 +20,9 @@ export default {
} }
</script> </script>
<template> <template>
<slot>
<component :is="props.data?.label" v-if="typeof props.data?.label !== 'string'" /> <component :is="props.data?.label" v-if="typeof props.data?.label !== 'string'" />
<span v-else v-html="props.data?.label"></span> <span v-else v-html="props.data?.label"></span>
</slot>
<Handle type="source" :position="props.sourcePosition" :connectable="props.connectable" /> <Handle type="source" :position="props.sourcePosition" :connectable="props.connectable" />
</template> </template>
+2
View File
@@ -20,7 +20,9 @@ export default {
} }
</script> </script>
<template> <template>
<slot>
<component :is="props.data?.label" v-if="typeof props.data?.label !== 'string'" /> <component :is="props.data?.label" v-if="typeof props.data?.label !== 'string'" />
<span v-else v-html="props.data?.label"></span> <span v-else v-html="props.data?.label"></span>
</slot>
<Handle type="source" :position="props.targetPosition" :is-connectable="props.connectable" /> <Handle type="source" :position="props.targetPosition" :is-connectable="props.connectable" />
</template> </template>