-
Notifications
You must be signed in to change notification settings - Fork 0
/
NodeWrapper.svelte
47 lines (36 loc) · 1.03 KB
/
NodeWrapper.svelte
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
<svelte:options immutable={true} />
<script lang="ts">
import type { Node } from "@antv/x6"
import { onDestroy, type ComponentType } from "svelte"
export let component: ComponentType
export let node: Node
let width: number
let height: number
$: node.size(width, height)
const updateSize = () => {
width = node.size().width
height = node.size().height
}
node.on("change:size", updateSize)
let posX: number
let posY: number
$: node.position(posX, posY)
const updatePos = () => {
posX = node.position().x
posY = node.position().y
}
node.on("change:position", updatePos)
onDestroy(() => {
node.off("change:size", updateSize)
node.off("change:position", updatePos)
})
</script>
<section>
<svelte:component this={component} {node} bind:width bind:height bind:posX bind:posY />
</section>
<style>
section {
width: max-content;
height: max-content;
}
</style>