mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:50:33 +08:00
Mergin better performance branch
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../Configuration"
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// @ts-check
|
||||
|
||||
import IInput from "../IInput"
|
||||
import ObjectSerializer from "../../serialization/ObjectSerializer"
|
||||
|
||||
@@ -26,7 +24,7 @@ export default class Copy extends IInput {
|
||||
}
|
||||
|
||||
copied() {
|
||||
const value = this.blueprint.getNodes(true).map(node => this.serializer.serialize(node.entity, false)).join("\n")
|
||||
const value = this.blueprint.getNodes(true).map(node => this.serializer.serialize(node.entity, false)).join("\n\n")
|
||||
navigator.clipboard.writeText(value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// @ts-check
|
||||
|
||||
import IInput from "../IInput"
|
||||
import NodeElement from "../../element/NodeElement"
|
||||
import ObjectSerializer from "../../serialization/ObjectSerializer"
|
||||
@@ -32,8 +30,8 @@ export default class Paste extends IInput {
|
||||
let count = 0
|
||||
let nodes = this.serializer.readMultiple(value).map(entity => {
|
||||
let node = new NodeElement(entity)
|
||||
top += node.location[1]
|
||||
left += node.location[0]
|
||||
top += node.locationY
|
||||
left += node.locationX
|
||||
++count
|
||||
return node
|
||||
})
|
||||
@@ -49,8 +47,8 @@ export default class Paste extends IInput {
|
||||
mousePosition[1] - top,
|
||||
]
|
||||
node.addLocation(locationOffset)
|
||||
node.setSelected(true)
|
||||
node.snapToGrid()
|
||||
node.setSelected(true)
|
||||
})
|
||||
this.blueprint.addGraphElement(...nodes)
|
||||
return true
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../../Configuration"
|
||||
import IInput from "../IInput"
|
||||
import ISerializer from "../../serialization/ISerializer"
|
||||
@@ -23,7 +21,6 @@ export default class IKeyboardShortcut extends IInput {
|
||||
return v
|
||||
}
|
||||
if (v.constructor === String) {
|
||||
// @ts-expect-error
|
||||
const parsed = ISerializer.grammar.KeyBinding.parse(v)
|
||||
if (parsed.status) {
|
||||
return parsed.value
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../../Configuration"
|
||||
import IKeyboardShortcut from "./IKeyboardShortcut"
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../../Configuration"
|
||||
import IKeyboardShortcut from "./IKeyboardShortcut"
|
||||
import Zoom from "../mouse/Zoom"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../../Configuration"
|
||||
import IKeyboardShortcut from "./IKeyboardShortcut"
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../../Configuration"
|
||||
import IPointing from "./IPointing"
|
||||
|
||||
@@ -43,12 +41,12 @@ export default class IMouseClickDrag extends IPointing {
|
||||
let self = this
|
||||
|
||||
this.#mouseDownHandler = e => {
|
||||
this.blueprint.setFocused(true)
|
||||
self.blueprint.setFocused(true)
|
||||
switch (e.button) {
|
||||
case self.options.clickButton:
|
||||
// Either doesn't matter or consider the click only when clicking on the parent, not descandants
|
||||
if (self.options.looseTarget || e.target == e.currentTarget) {
|
||||
if (this.options.consumeEvent) {
|
||||
if (self.options.consumeEvent) {
|
||||
e.stopImmediatePropagation() // Captured, don't call anyone else
|
||||
}
|
||||
// Attach the listeners
|
||||
@@ -67,7 +65,7 @@ export default class IMouseClickDrag extends IPointing {
|
||||
}
|
||||
|
||||
this.#mouseStartedMovingHandler = e => {
|
||||
if (this.options.consumeEvent) {
|
||||
if (self.options.consumeEvent) {
|
||||
e.stopImmediatePropagation() // Captured, don't call anyone else
|
||||
}
|
||||
// Delegate from now on to self.#mouseMoveHandler
|
||||
@@ -75,14 +73,15 @@ export default class IMouseClickDrag extends IPointing {
|
||||
movementListenedElement.addEventListener("mousemove", self.#mouseMoveHandler)
|
||||
// Handler calls e.preventDefault() when it receives the event, this means dispatchEvent returns false
|
||||
const dragEvent = self.getEvent(Configuration.trackingMouseEventName.begin)
|
||||
self.#trackingMouse = this.target.dispatchEvent(dragEvent) == false
|
||||
self.#trackingMouse = self.target.dispatchEvent(dragEvent) == false
|
||||
const location = self.locationFromEvent(e)
|
||||
// Do actual actions
|
||||
self.startDrag()
|
||||
self.startDrag(location)
|
||||
self.started = true
|
||||
}
|
||||
|
||||
this.#mouseMoveHandler = e => {
|
||||
if (this.options.consumeEvent) {
|
||||
if (self.options.consumeEvent) {
|
||||
e.stopImmediatePropagation() // Captured, don't call anyone else
|
||||
}
|
||||
const location = self.locationFromEvent(e)
|
||||
@@ -95,7 +94,7 @@ export default class IMouseClickDrag extends IPointing {
|
||||
|
||||
this.#mouseUpHandler = e => {
|
||||
if (!self.options.exitAnyButton || e.button == self.options.clickButton) {
|
||||
if (this.options.consumeEvent) {
|
||||
if (self.options.consumeEvent) {
|
||||
e.stopImmediatePropagation() // Captured, don't call anyone else
|
||||
}
|
||||
// Remove the handlers of "mousemove" and "mouseup"
|
||||
@@ -108,7 +107,7 @@ export default class IMouseClickDrag extends IPointing {
|
||||
self.unclicked()
|
||||
if (self.#trackingMouse) {
|
||||
const dragEvent = self.getEvent(Configuration.trackingMouseEventName.end)
|
||||
this.target.dispatchEvent(dragEvent)
|
||||
self.target.dispatchEvent(dragEvent)
|
||||
self.#trackingMouse = false
|
||||
}
|
||||
self.started = false
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../../Configuration"
|
||||
import IPointing from "./IPointing"
|
||||
|
||||
export default class IMouseWheel extends IPointing {
|
||||
@@ -24,7 +23,7 @@ export default class IMouseWheel extends IPointing {
|
||||
this.#mouseWheelHandler = e => {
|
||||
e.preventDefault()
|
||||
const location = self.locationFromEvent(e)
|
||||
self.wheel(Math.sign(e.deltaY), location)
|
||||
self.wheel(Math.sign(e.deltaY * Configuration.mouseWheelFactor), location)
|
||||
}
|
||||
this.#mouseParentWheelHandler = e => e.preventDefault()
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// @ts-check
|
||||
|
||||
import IInput from "../IInput"
|
||||
import Utility from "../../Utility"
|
||||
|
||||
@@ -22,11 +20,10 @@ export default class IPointing extends IInput {
|
||||
* @param {MouseEvent} mouseEvent
|
||||
*/
|
||||
locationFromEvent(mouseEvent) {
|
||||
return this.blueprint.compensateTranslation(
|
||||
Utility.convertLocation(
|
||||
[mouseEvent.clientX, mouseEvent.clientY],
|
||||
this.movementSpace
|
||||
)
|
||||
const location = Utility.convertLocation(
|
||||
[mouseEvent.clientX, mouseEvent.clientY],
|
||||
this.movementSpace
|
||||
)
|
||||
return this.blueprint.compensateTranslation(location)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
// @ts-check
|
||||
|
||||
import IMouseClickDrag from "./IMouseClickDrag"
|
||||
import LinkElement from "../../element/LinkElement"
|
||||
import LinkMessageElement from "../../element/LinkMessageElement"
|
||||
|
||||
/**
|
||||
* @typedef {import("../../element/PinElement").default} PinElement
|
||||
@@ -22,34 +19,34 @@ export default class MouseCreateLink extends IMouseClickDrag {
|
||||
/** @type {(e: MouseEvent) => void} */
|
||||
#mouseleaveHandler
|
||||
|
||||
/** @type {LinkElement} */
|
||||
/** @type {LinkElement?} */
|
||||
link
|
||||
|
||||
/** @type {PinElement} */
|
||||
/** @type {PinElement?} */
|
||||
enteredPin
|
||||
|
||||
linkValid = false
|
||||
|
||||
constructor(target, blueprint, options) {
|
||||
super(target, blueprint, options)
|
||||
|
||||
let self = this
|
||||
this.#mouseenterHandler = e => {
|
||||
if (!self.enteredPin) {
|
||||
self.linkValid = false
|
||||
self.enteredPin = /** @type {PinElement} */ (e.target)
|
||||
const a = self.enteredPin, b = self.target
|
||||
const a = self.enteredPin
|
||||
const b = self.target
|
||||
if (a.getNodeElement() == b.getNodeElement()) {
|
||||
this.setLinkMessage(LinkMessageElement.sameNode())
|
||||
self.link.setMessageSameNode()
|
||||
} else if (a.isOutput() == b.isOutput()) {
|
||||
this.setLinkMessage(LinkMessageElement.directionsIncompatible())
|
||||
self.link.setMessageDirectionsIncompatible()
|
||||
} else if (a.isOutput() == b.isOutput()) {
|
||||
this.setLinkMessage(LinkMessageElement.directionsIncompatible())
|
||||
self.link.setMessageDirectionsIncompatible()
|
||||
} else if (self.blueprint.getLinks([a, b]).length) {
|
||||
this.setLinkMessage(LinkMessageElement.replaceLink())
|
||||
self.link.setMessageReplaceLink()
|
||||
self.linkValid = true
|
||||
} else {
|
||||
this.setLinkMessage(LinkMessageElement.correct())
|
||||
self.link.setMessageCorrect()
|
||||
self.linkValid = true
|
||||
}
|
||||
}
|
||||
@@ -58,15 +55,15 @@ export default class MouseCreateLink extends IMouseClickDrag {
|
||||
if (self.enteredPin == e.target) {
|
||||
self.enteredPin = null
|
||||
self.linkValid = false
|
||||
this.setLinkMessage(LinkMessageElement.placeNode())
|
||||
self.link?.setMessagePlaceNode()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
startDrag() {
|
||||
startDrag(location) {
|
||||
this.link = new LinkElement(this.target, null)
|
||||
this.blueprint.nodesContainerElement.prepend(this.link)
|
||||
this.setLinkMessage(LinkMessageElement.placeNode())
|
||||
this.blueprint.linksContainerElement.prepend(this.link)
|
||||
this.link.setMessagePlaceNode()
|
||||
this.#listenedPins = this.blueprint.querySelectorAll("ueb-pin")
|
||||
this.#listenedPins.forEach(pin => {
|
||||
if (pin != this.target) {
|
||||
@@ -75,7 +72,7 @@ export default class MouseCreateLink extends IMouseClickDrag {
|
||||
}
|
||||
})
|
||||
this.link.startDragging()
|
||||
this.link.setDestinationLocation(this.clickedPosition)
|
||||
this.link.setDestinationLocation(location)
|
||||
}
|
||||
|
||||
dragTo(location, movement) {
|
||||
@@ -90,7 +87,7 @@ export default class MouseCreateLink extends IMouseClickDrag {
|
||||
if (this.enteredPin && this.linkValid) {
|
||||
this.blueprint.addGraphElement(this.link)
|
||||
this.link.destinationPin = this.enteredPin
|
||||
this.link.setLinkMessage(null)
|
||||
this.link.removeMessage()
|
||||
this.link.finishDragging()
|
||||
} else {
|
||||
this.link.finishDragging()
|
||||
@@ -100,8 +97,4 @@ export default class MouseCreateLink extends IMouseClickDrag {
|
||||
this.link = null
|
||||
this.#listenedPins = null
|
||||
}
|
||||
|
||||
setLinkMessage(linkMessage) {
|
||||
this.link.setLinkMessage(linkMessage)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../../Configuration"
|
||||
import IMouseClickDrag from "./IMouseClickDrag"
|
||||
import Utility from "../../Utility"
|
||||
|
||||
@@ -15,7 +14,7 @@ export default class MouseMoveNodes extends IMouseClickDrag {
|
||||
|
||||
constructor(target, blueprint, options) {
|
||||
super(target, blueprint, options)
|
||||
this.stepSize = parseInt(options?.stepSize ?? this.blueprint.gridSize)
|
||||
this.stepSize = parseInt(options?.stepSize ?? Configuration.gridSize)
|
||||
this.mouseLocation = [0, 0]
|
||||
}
|
||||
|
||||
@@ -30,9 +29,10 @@ export default class MouseMoveNodes extends IMouseClickDrag {
|
||||
}
|
||||
|
||||
dragTo(location, movement) {
|
||||
const initialTargetLocation = [this.target.locationX, this.target.locationY]
|
||||
const [mouseLocation, targetLocation] = this.stepSize > 1
|
||||
? [Utility.snapToGrid(location, this.stepSize), Utility.snapToGrid(this.target.location, this.stepSize)]
|
||||
: [location, this.target.location]
|
||||
? [Utility.snapToGrid(location, this.stepSize), Utility.snapToGrid(initialTargetLocation, this.stepSize)]
|
||||
: [location, initialTargetLocation]
|
||||
const d = [
|
||||
mouseLocation[0] - this.mouseLocation[0],
|
||||
mouseLocation[1] - this.mouseLocation[1]
|
||||
@@ -43,8 +43,8 @@ export default class MouseMoveNodes extends IMouseClickDrag {
|
||||
}
|
||||
|
||||
// Make sure it snaps on the grid
|
||||
d[0] += targetLocation[0] - this.target.location[0]
|
||||
d[1] += targetLocation[1] - this.target.location[1]
|
||||
d[0] += targetLocation[0] - this.target.locationX
|
||||
d[1] += targetLocation[1] - this.target.locationY
|
||||
|
||||
this.target.dispatchDragEvent(d)
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
// @ts-check
|
||||
|
||||
import IMouseClickDrag from "./IMouseClickDrag"
|
||||
|
||||
export default class MouseScrollGraph extends IMouseClickDrag {
|
||||
|
||||
startDrag() {
|
||||
this.blueprint.template.applyStartDragScrolling(this.blueprint)
|
||||
this.blueprint.scrolling = true
|
||||
}
|
||||
|
||||
dragTo(location, movement) {
|
||||
@@ -13,6 +11,6 @@ export default class MouseScrollGraph extends IMouseClickDrag {
|
||||
}
|
||||
|
||||
endDrag() {
|
||||
this.blueprint.template.applyEndDragScrolling(this.blueprint)
|
||||
this.blueprint.scrolling = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../../Configuration"
|
||||
import IPointing from "./IPointing"
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// @ts-check
|
||||
|
||||
import IMouseClickDrag from "./IMouseClickDrag"
|
||||
|
||||
export default class Select extends IMouseClickDrag {
|
||||
@@ -10,16 +8,16 @@ export default class Select extends IMouseClickDrag {
|
||||
}
|
||||
|
||||
startDrag() {
|
||||
this.selectorElement.startSelecting(this.clickedPosition)
|
||||
this.selectorElement.beginSelect(this.clickedPosition)
|
||||
}
|
||||
|
||||
dragTo(location, movement) {
|
||||
this.selectorElement.doSelecting(location)
|
||||
this.selectorElement.selectTo(location)
|
||||
}
|
||||
|
||||
endDrag() {
|
||||
if (this.started) {
|
||||
this.selectorElement.finishSelecting()
|
||||
this.selectorElement.endSelect()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// @ts-check
|
||||
|
||||
import IInput from "../IInput"
|
||||
|
||||
export default class Unfocus extends IInput {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// @ts-check
|
||||
|
||||
import IMouseWheel from "./IMouseWheel"
|
||||
|
||||
export default class Zoom extends IMouseWheel {
|
||||
|
||||
Reference in New Issue
Block a user