Skip to content

Commit b670250

Browse files
EralChenDymoneLewis
authored andcommitted
feat: add nested transform and the test
1 parent 99d80db commit b670250

File tree

15 files changed

+406
-1
lines changed

15 files changed

+406
-1
lines changed

examples/vue3-app/src/App.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ import { RouterView } from 'vue-router'
3232
<el-icon><TrendCharts /></el-icon>
3333
<span>LFChartView</span>
3434
</el-menu-item>
35+
36+
<el-menu-item index="/nested-transform">
37+
<el-icon><TrendCharts /></el-icon>
38+
<span>NestedTransform</span>
39+
</el-menu-item>
3540
</el-menu>
3641
</div>
3742
</header>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { App } from 'vue'
2+
import VkLogicFlow from './src/index.vue'
3+
4+
export * as __VkLogicFlow from './src/types'
5+
export { useLogicFlow } from './src/use'
6+
7+
VkLogicFlow.install = (app: App): void => {
8+
app.component(VkLogicFlow.name || 'VkLogicFlow', VkLogicFlow)
9+
}
10+
export { VkLogicFlow }
11+
export default VkLogicFlow
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script lang="ts" setup>
2+
import { getTeleport } from '@logicflow/vue-node-registry'
3+
import { ref } from 'vue'
4+
import { useLogicFlow } from './use'
5+
6+
const flowId = ref('')
7+
const TeleportContainer = getTeleport()
8+
9+
const lf = useLogicFlow()
10+
lf.once('graph:rendered', ({ graphModel }) => {
11+
flowId.value = graphModel.flowId as string
12+
})
13+
</script>
14+
15+
<template>
16+
<TeleportContainer v-if="flowId" :flow-id="flowId" />
17+
</template>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { PropType } from 'vue'
2+
import type { DefaultOptions, LoadEvent } from './types'
3+
4+
export const props = {
5+
defaultOptions: {
6+
type: Object as PropType<DefaultOptions>,
7+
default: () => ({})
8+
},
9+
10+
defaultEdgeType: {
11+
type: String,
12+
required: false
13+
}
14+
}
15+
16+
export const emits = {
17+
load: (_e: LoadEvent) => true
18+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<script lang="ts">
2+
import type { Ref } from 'vue'
3+
import { LogicFlow } from '@logicflow/core'
4+
import { defineComponent, onMounted, ref, watchEffect } from 'vue'
5+
import { emits, props } from './ctx'
6+
7+
import TeleportContainer from './TeleportContainer.vue'
8+
import { provideLogicFlow, tryLogicFlow } from './use'
9+
10+
export default defineComponent({
11+
name: 'VkLogicFlow',
12+
components: {
13+
TeleportContainer
14+
},
15+
inheritAttrs: false,
16+
props,
17+
emits,
18+
setup(props, { emit }) {
19+
const parentLogicFlow = tryLogicFlow()
20+
const containerRef = ref() as Ref<HTMLDivElement>
21+
const ready = ref(false)
22+
onMounted(() => {
23+
const options = {
24+
container: containerRef.value,
25+
parentTransform: parentLogicFlow?.graphModel.transformModel,
26+
// 其他配置
27+
...props.defaultOptions
28+
}
29+
const lf = new LogicFlow(options)
30+
31+
watchEffect(() => {
32+
props.defaultEdgeType && lf.setDefaultEdgeType(props.defaultEdgeType)
33+
})
34+
35+
ready.value = true
36+
provideLogicFlow(lf)
37+
emit('load', { lf })
38+
})
39+
40+
return {
41+
containerRef,
42+
ready
43+
}
44+
}
45+
})
46+
</script>
47+
48+
<template>
49+
<div class="vk-logic-flow" v-bind="$attrs">
50+
<main ref="containerRef"></main>
51+
52+
<TeleportContainer v-if="ready" />
53+
<slot v-if="ready"></slot>
54+
</div>
55+
</template>
56+
57+
<style>
58+
.vk-logic-flow {
59+
width: 100%;
60+
height: 100%;
61+
position: relative;
62+
}
63+
.vk-logic-flow main {
64+
width: 100%;
65+
height: 100%;
66+
}
67+
</style>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { LogicFlow, Options } from '@logicflow/core'
2+
3+
export type DefaultOptions = Partial<Options.Common>
4+
5+
export interface LoadEvent {
6+
lf: LogicFlow
7+
}
8+
9+
export type OnLoad = (e: LoadEvent) => void
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { LogicFlow } from '@logicflow/core'
2+
import type { InjectionKey } from 'vue'
3+
4+
import { inject, provide } from 'vue'
5+
6+
const symbol = Symbol('LogicFlow') as InjectionKey<LogicFlow>
7+
8+
export function provideLogicFlow(lf: LogicFlow) {
9+
provide(symbol, lf)
10+
}
11+
12+
export function useLogicFlow(): LogicFlow {
13+
const lf = inject(symbol, null)
14+
if (!lf) {
15+
throw new Error(
16+
'LogicFlow instance is not provided. Please ensure you have called provideLogicFlow before using useLogicFlow.'
17+
)
18+
}
19+
return lf
20+
}
21+
22+
export function tryLogicFlow(): LogicFlow | null {
23+
return inject(symbol, null)
24+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<script lang="tsx" setup>
2+
import { register } from '@logicflow/vue-node-registry'
3+
import { useLogicFlow, VkLogicFlow } from '../LogicFlow'
4+
import { h } from 'vue'
5+
const lf = useLogicFlow()
6+
7+
defineOptions({
8+
name: 'LoopNode'
9+
})
10+
11+
register(
12+
{
13+
type: 'loop-node',
14+
component: {
15+
props: ['node', 'graph'],
16+
17+
setup() {
18+
return () =>
19+
h(
20+
'div',
21+
{
22+
class: 'vk-register-node-x',
23+
onMousedown: (e) => {
24+
e.stopPropagation()
25+
},
26+
onWheel: (e) => {
27+
e.stopPropagation()
28+
}
29+
},
30+
[
31+
h(VkLogicFlow, {
32+
onLoad: ({ lf }) => {
33+
lf.render({
34+
nodes: [
35+
{
36+
id: 'start-node-1',
37+
type: 'rect',
38+
x: 50,
39+
y: 50,
40+
properties: {
41+
name: 'Start Node'
42+
}
43+
}
44+
],
45+
edges: []
46+
})
47+
}
48+
})
49+
]
50+
)
51+
}
52+
}
53+
},
54+
lf
55+
)
56+
</script>
57+
<template>
58+
<slot></slot>
59+
</template>
60+
<style>
61+
.vk-register-node-x {
62+
width: 500px;
63+
height: 300px;
64+
}
65+
</style>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { GraphModel, Model } from '@logicflow/core'
2+
import type { VueNodeModel } from '@logicflow/vue-node-registry'
3+
4+
export interface RegisterNodeComponentProps {
5+
graph: GraphModel
6+
node: VueNodeModel
7+
}
8+
9+
export interface AnchorConfig extends Model.AnchorConfig {
10+
/**
11+
* @description 控制是否可以在此锚点手动创建连线
12+
* @link http://logicflow.cn/release/upgrade-to-v1-1#118-%E4%BB%A5%E4%B8%8B
13+
*/
14+
edgeAddable?: boolean
15+
}

examples/vue3-app/src/router/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ const router = createRouter({
2828
path: '/lf-chart',
2929
name: 'lfChart',
3030
component: () => import('../views/LFChartView.vue')
31+
},
32+
{
33+
path: '/nested-transform',
34+
name: 'nestedTransform',
35+
component: () => import('../views/NestedTransformView.vue')
3136
}
3237
]
3338
})

0 commit comments

Comments
 (0)