Refactoring

This commit is contained in:
barsdeveloper
2021-10-31 16:05:38 +01:00
parent 12e44c5482
commit 199005ec20
13 changed files with 1297 additions and 81 deletions

18
js/graph/GraphElement.js Executable file
View 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))
}
}

View File

@@ -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 ''
}
}

View File

@@ -1,6 +1,6 @@
import UBlueprintEntity from "./UBlueprintEntity"
import GraphElement from "./GraphElement"
export default class GraphLink extends UBlueprintEntity {
export default class GraphLink extends GraphElement {
/**
*

View File

@@ -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 = []

View File

@@ -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)
}
/**

View File

@@ -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