Blueprint focusable

This commit is contained in:
barsdeveloper
2021-11-06 20:59:00 +01:00
parent ceb07688f2
commit afa27bf42c
13 changed files with 318 additions and 79 deletions

View File

@@ -7,14 +7,11 @@ import Utility from "./Utility"
import Zoom from "./input/Zoom"
import BlueprintData from "./BlueprintData"
import Paste from "./input/Paste"
import Unfocus from "./input/Unfocus"
/** @typedef {import("./graph/GraphNode").default} GraphNode */
export default class Blueprint extends GraphElement {
insertChildren() {
this.querySelector('[data-nodes]').append(...this.entity.nodes)
}
constructor() {
super(new BlueprintData(), new BlueprintTemplate())
/** @type {HTMLElement} */
@@ -33,8 +30,9 @@ export default class Blueprint extends GraphElement {
this.zoom = 0
/** @type {HTMLElement} */
this.headerElement = null
this.focused = false
/** @type {(node: GraphNode) => BoundariesInfo} */
this.nodeBoundariesSupplier = (node) => {
this.nodeBoundariesSupplier = node => {
let rect = node.getBoundingClientRect()
let gridRect = this.nodesContainerElement.getBoundingClientRect()
const scaleCorrection = 1 / this.getScale()
@@ -68,7 +66,9 @@ export default class Blueprint extends GraphElement {
this.nodesContainerElement = this.querySelector('[data-nodes]')
console.assert(this.nodesContainerElement, "Nodes container element not provided by the template.")
this.nodesContainerElement.append(this.selectorElement)
this.insertChildren()
this.querySelector('[data-nodes]').append(...this.entity.nodes)
this.pasteObject = new Paste(this.getGridDOMElement(), this)
this.dragObject = new DragScroll(this.getGridDOMElement(), this, {
clickButton: 2,
@@ -86,7 +86,7 @@ export default class Blueprint extends GraphElement {
exitAnyButton: true
})
this.pasteObject = new Paste(this.getGridDOMElement(), this)
this.unfocusObject = new Unfocus(this.getGridDOMElement(), this)
}
getGridDOMElement() {
@@ -312,6 +312,19 @@ export default class Blueprint extends GraphElement {
this.nodesContainerElement.append(...graphNodes)
}
}
setFocused(value = true) {
if (this.focused == value) {
return;
}
let event = new CustomEvent(value ? "blueprintfocus" : "blueprintunfocus")
this.focused = value
this.dataset.focused = this.focused
if (!this.focused) {
this.unselectAll()
}
this.dispatchEvent(event)
}
}
customElements.define('u-blueprint', Blueprint)