schangxiang@126.com
2025-05-07 cace264ad9d86a7831099810b079da1141957add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import {
  defineComponent,
  Fragment,
  computed,
  Component,
  DefineComponent,
  SetupContext,
} from 'vue'
 
export default defineComponent<{
  grid: Record<string, any>
  minimap: Record<string, any> | boolean
  height?: number
  width?: number
  [key: string]: any
}>({
  name: 'Canvas',
  emits: ['drop'],
  setup(props: any, { slots, attrs, emit }: SetupContext) {
    const config = {
      layout: {
        type: 'dagre',
        nodesep: 100,
        ranksep: 40,
        controlPoints: true,
      },
      fitView: true,
      autoFit: false,
    }
 
    const baseConfig = computed(() => {
      return {
        ...config,
        ...props,
        ...attrs,
      }
    })
    return () => {
      const Widgets = (slots.default && slots.default()) || []
      return (
        <span onDrop={(...arg) => emit('drop', ...arg)}>
          {Widgets.map((Widget: any) => {
            return <Widget {...baseConfig.value} />
          })}
        </span>
      )
    }
  },
})