-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.ts
79 lines (65 loc) · 2.21 KB
/
view.ts
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { Dom, NodeView } from "@antv/x6"
import type { SvelteComponentTyped } from "svelte"
import type { SvelteShape } from "./node"
import { shapeMaps } from "./registry"
import NodeWrapper from "./NodeWrapper.svelte"
export class SvelteShapeView extends NodeView<SvelteShape> {
component?: SvelteComponentTyped
getComponentContainer() {
return this.selectors && (this.selectors.foContent as HTMLDivElement)
}
confirmUpdate(flag: number) {
const ret = super.confirmUpdate(flag)
return this.handleAction(ret, SvelteShapeView.action, () => {
this.renderSvelteComponent()
})
}
protected renderSvelteComponent() {
this.unmountSvelteComponent()
const container = this.getComponentContainer()
const node = this.cell
if (container) {
const content = shapeMaps[node.shape]
this.component = new NodeWrapper({
target: container,
props: {
component: content.component,
node: node
}
})
}
}
protected unmountSvelteComponent() {
// const container = this.getComponentContainer()
if (this.component) {
this.component.$destroy()
this.component = undefined
}
}
onMouseDown(e: Dom.MouseDownEvent, x: number, y: number) {
const target = e.target as Element
const tagName = target.tagName.toLowerCase()
if (tagName === "input") {
const type = target.getAttribute("type")
if (type == null || ["text", "password", "number", "email", "search", "tel", "url"].includes(type)) {
return
}
}
super.onMouseDown(e, x, y)
}
unmount() {
this.unmountSvelteComponent()
super.unmount()
return this
}
}
export namespace SvelteShapeView {
export const action = "svelte" as any
SvelteShapeView.config({
bootstrap: [action],
actions: {
component: action
}
})
NodeView.registry.register("svelte-shape-view", SvelteShapeView, true)
}