mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-05-18 03:27:32 +08:00
Refactoring
This commit is contained in:
18
js/graph/GraphElement.js
Executable file
18
js/graph/GraphElement.js
Executable file
@@ -0,0 +1,18 @@
|
||||
export default class GraphElement extends HTMLElement {
|
||||
/**
|
||||
*
|
||||
* @param {import("../template/Template").default} template The template to render this node
|
||||
*/
|
||||
constructor(entity, template) {
|
||||
super()
|
||||
/** @type {import("../Blueprint").default}" */
|
||||
this.blueprint = null
|
||||
this.entity = entity
|
||||
this.template = template
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
this.blueprint = this.closest('u-blueprint')
|
||||
this.append(...this.template.getElements(this.entity))
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
export default class GraphEntity extends HTMLElement {
|
||||
/**
|
||||
*
|
||||
* @param {import("../template/Template").default} template The template to render this node
|
||||
*/
|
||||
constructor(template) {
|
||||
super()
|
||||
/** @type {import("../Blueprint").Blueprint}" */
|
||||
this.blueprint = null
|
||||
this.template = template
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
this.blueprint = this.closest('u-blueprint')
|
||||
this.append(...this.template.getElements(this))
|
||||
}
|
||||
|
||||
// Subclasses want to rewrite this
|
||||
render() {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import UBlueprintEntity from "./UBlueprintEntity"
|
||||
import GraphElement from "./GraphElement"
|
||||
|
||||
export default class GraphLink extends UBlueprintEntity {
|
||||
export default class GraphLink extends GraphElement {
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
import ObjectEntity from "../entity/ObjectEntity"
|
||||
import SerializerFactory from "../serialization/SerializerFactory"
|
||||
import NodeTemplate from "../template/NodeTemplate"
|
||||
import SelectableDraggable from "./SelectableDraggable"
|
||||
|
||||
export default class GraphNode extends SelectableDraggable {
|
||||
|
||||
constructor() {
|
||||
super(new NodeTemplate())
|
||||
static fromSerializedObject(str) {
|
||||
let entity = SerializerFactory.getSerializer(ObjectEntity).read(str)
|
||||
return new GraphNode(entity)
|
||||
}
|
||||
|
||||
constructor(entity) {
|
||||
super(entity, new NodeTemplate())
|
||||
this.graphNodeName = 'n/a'
|
||||
this.inputs = []
|
||||
this.outputs = []
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import FastSelectionModel from "../selection/FastSelectionModel"
|
||||
import GraphEntity from "./GraphEntity"
|
||||
import GraphElement from "./GraphElement"
|
||||
import Template from "../template/Template"
|
||||
|
||||
export default class GraphSelector extends GraphEntity {
|
||||
export default class GraphSelector extends GraphElement {
|
||||
|
||||
constructor() {
|
||||
super(new Template())
|
||||
super({}, new Template())
|
||||
/**
|
||||
* @type {import("./GraphSelector").default}
|
||||
*/
|
||||
@@ -31,7 +31,7 @@ export default class GraphSelector extends GraphEntity {
|
||||
this.style.setProperty('--ueb-select-to-x', initialPosition[0])
|
||||
this.style.setProperty('--ueb-select-to-y', initialPosition[1])
|
||||
this.dataset.selecting = "true"
|
||||
this.selectionModel = new FastSelectionModel(initialPosition, this.blueprint.nodes, this.blueprint.nodeBoundariesSupplier, this.blueprint.nodeSelectToggleFunction)
|
||||
this.selectionModel = new FastSelectionModel(initialPosition, this.blueprint.getNodes(), this.blueprint.nodeBoundariesSupplier, this.blueprint.nodeSelectToggleFunction)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import Drag from "../input/Drag"
|
||||
import GraphEntity from "./GraphEntity"
|
||||
import GraphElement from "./GraphElement"
|
||||
|
||||
export default class SelectableDraggable extends GraphEntity {
|
||||
export default class SelectableDraggable extends GraphElement {
|
||||
|
||||
constructor(template) {
|
||||
super(template)
|
||||
constructor(...args) {
|
||||
super(...args)
|
||||
this.dragObject = null
|
||||
this.location = [0, 0]
|
||||
this.selected = false
|
||||
|
||||
Reference in New Issue
Block a user