mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-03 23:55:04 +08:00
Create knot on link double click
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import ElementFactory from "../../element/ElementFactory"
|
||||
import IInput from "../IInput"
|
||||
import NodeElement from "../../element/NodeElement"
|
||||
import ObjectSerializer from "../../serialization/ObjectSerializer"
|
||||
|
||||
/** @typedef {import("../../element/NodeElement").default} NodeElement */
|
||||
|
||||
export default class Paste extends IInput {
|
||||
|
||||
static #serializer = new ObjectSerializer()
|
||||
@@ -30,7 +32,9 @@ export default class Paste extends IInput {
|
||||
let left = 0
|
||||
let count = 0
|
||||
let nodes = Paste.#serializer.readMultiple(value).map(entity => {
|
||||
let node = new NodeElement(entity)
|
||||
/** @type {NodeElement} */
|
||||
// @ts-expect-error
|
||||
let node = new (ElementFactory.getConstructor("ueb-node"))(entity)
|
||||
top += node.locationY
|
||||
left += node.locationX
|
||||
++count
|
||||
|
||||
@@ -6,7 +6,7 @@ import IPointing from "./IPointing"
|
||||
* @template {HTMLElement} T
|
||||
* @extends {IPointing<T>}
|
||||
*/
|
||||
export default class IMouseClick extends IPointing {
|
||||
export default class MouseClick extends IPointing {
|
||||
|
||||
#mouseDownHandler =
|
||||
/** @param {MouseEvent} e */
|
||||
@@ -15,7 +15,7 @@ export default class IMouseClick extends IPointing {
|
||||
switch (e.button) {
|
||||
case this.options.clickButton:
|
||||
// Either doesn't matter or consider the click only when clicking on the target, not descandants
|
||||
if (!this.options.strictTarget || e.target == e.currentTarget) {
|
||||
if (!this.options.strictTarget || e.target === e.currentTarget) {
|
||||
if (this.options.consumeEvent) {
|
||||
e.stopImmediatePropagation() // Captured, don't call anyone else
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
import Configuration from "../../Configuration"
|
||||
import ElementFactory from "../../element/ElementFactory"
|
||||
import IMouseClickDrag from "./IMouseClickDrag"
|
||||
import LinkElement from "../../element/LinkElement"
|
||||
|
||||
/**
|
||||
* @typedef {import("../../element/PinElement").default} PinElement
|
||||
* @typedef {import("../../element/LinkElement").default} LinkElement
|
||||
* @typedef {import("../../template/KnotNodeTemplate").default} KnotNodeTemplate
|
||||
*/
|
||||
|
||||
@@ -69,7 +70,9 @@ export default class MouseCreateLink extends IMouseClickDrag {
|
||||
if (this.target.nodeElement.getType() == Configuration.knotNodeTypeName) {
|
||||
this.#knotPin = this.target
|
||||
}
|
||||
this.link = new LinkElement(this.target, null)
|
||||
/** @type {LinkElement} */
|
||||
// @ts-expect-error
|
||||
this.link = new (ElementFactory.getConstructor("ueb-link"))(this.target, null)
|
||||
this.blueprint.linksContainerElement.prepend(this.link)
|
||||
this.link.setMessagePlaceNode()
|
||||
this.#listenedPins = this.blueprint.querySelectorAll("ueb-pin")
|
||||
@@ -99,8 +102,8 @@ export default class MouseCreateLink extends IMouseClickDrag {
|
||||
// Knot pin direction correction
|
||||
if (this.#knotPin.isInput() && otherPin.isInput() || this.#knotPin.isOutput() && otherPin.isOutput()) {
|
||||
const oppositePin = this.#knotPin.isInput()
|
||||
?/** @type {KnotNodeTemplate} */(this.#knotPin.nodeElement.template).outputPin
|
||||
:/** @type {KnotNodeTemplate} */(this.#knotPin.nodeElement.template).inputPin
|
||||
? /** @type {KnotNodeTemplate} */(this.#knotPin.nodeElement.template).outputPin
|
||||
: /** @type {KnotNodeTemplate} */(this.#knotPin.nodeElement.template).inputPin
|
||||
if (this.#knotPin === this.link.sourcePin) {
|
||||
this.link.sourcePin = oppositePin
|
||||
} else {
|
||||
|
||||
59
js/input/mouse/MouseDbClick.js
Normal file
59
js/input/mouse/MouseDbClick.js
Normal file
@@ -0,0 +1,59 @@
|
||||
import IPointing from "./IPointing"
|
||||
|
||||
/** @typedef {import("../../Blueprint").default} Blueprint */
|
||||
|
||||
/**
|
||||
* @template {HTMLElement} T
|
||||
* @extends {IPointing<T>}
|
||||
*/
|
||||
export default class MouseDbClick extends IPointing {
|
||||
|
||||
static ignoreDbClick =
|
||||
/** @param {Number[]} location */
|
||||
location => { }
|
||||
|
||||
#mouseDbClickHandler =
|
||||
/** @param {MouseEvent} e */
|
||||
e => {
|
||||
if (!this.options.strictTarget || e.target === e.currentTarget) {
|
||||
if (this.options.consumeEvent) {
|
||||
e.stopImmediatePropagation() // Captured, don't call anyone else
|
||||
}
|
||||
this.clickedPosition = this.locationFromEvent(e)
|
||||
this.blueprint.mousePosition[0] = this.clickedPosition[0]
|
||||
this.blueprint.mousePosition[1] = this.clickedPosition[1]
|
||||
this.dbclicked(this.clickedPosition)
|
||||
}
|
||||
}
|
||||
|
||||
#onDbClick
|
||||
get onDbClick() {
|
||||
return this.#onDbClick
|
||||
}
|
||||
set onDbClick(value) {
|
||||
this.#onDbClick = value
|
||||
}
|
||||
|
||||
clickedPosition = [0, 0]
|
||||
|
||||
constructor(target, blueprint, options = {}, onDbClick = MouseDbClick.ignoreDbClick) {
|
||||
options.consumeEvent ??= true
|
||||
options.strictTarget ??= false
|
||||
super(target, blueprint, options)
|
||||
this.#onDbClick = onDbClick
|
||||
this.listenEvents()
|
||||
}
|
||||
|
||||
listenEvents() {
|
||||
this.target.addEventListener("dblclick", this.#mouseDbClickHandler)
|
||||
}
|
||||
|
||||
unlistenEvents() {
|
||||
this.target.removeEventListener("dblclick", this.#mouseDbClickHandler)
|
||||
}
|
||||
|
||||
/* Subclasses will override the following method */
|
||||
dbclicked(location) {
|
||||
this.onDbClick(location)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user