mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-03-15 04:50:53 +08:00
Move inputs to templates
This commit is contained in:
@@ -1,10 +1,20 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../Configuration"
|
||||
import Copy from "../input/common/Copy"
|
||||
import html from "./html"
|
||||
import ITemplate from "./ITemplate"
|
||||
import KeyboardCanc from "../input/keybaord/KeyboardCanc"
|
||||
import KeyboardEnableZoom from "../input/keybaord/KeyboardEnableZoom"
|
||||
import KeyboardSelectAll from "../input/keybaord/KeyboardSelectAll"
|
||||
import MouseScrollGraph from "../input/mouse/MouseScrollGraph"
|
||||
import MouseTracking from "../input/mouse/MouseTracking"
|
||||
import Paste from "../input/common/Paste"
|
||||
import sanitizeText from "./sanitizeText"
|
||||
import Select from "../input/mouse/Select"
|
||||
import SelectorElement from "../element/SelectorElement"
|
||||
import Unfocus from "../input/mouse/Unfocus"
|
||||
import Zoom from "../input/mouse/Zoom"
|
||||
|
||||
/**
|
||||
* @typedef {import("../Blueprint").default} Blueprint
|
||||
@@ -14,6 +24,36 @@ import SelectorElement from "../element/SelectorElement"
|
||||
|
||||
export default class BlueprintTemplate extends ITemplate {
|
||||
|
||||
/**
|
||||
* @param {Blueprint} blueprint
|
||||
*/
|
||||
createInputObjects(blueprint) {
|
||||
return [
|
||||
new Copy(blueprint.getGridDOMElement(), blueprint),
|
||||
new Paste(blueprint.getGridDOMElement(), blueprint),
|
||||
new KeyboardCanc(blueprint.getGridDOMElement(), blueprint),
|
||||
new KeyboardSelectAll(blueprint.getGridDOMElement(), blueprint),
|
||||
new Zoom(blueprint.getGridDOMElement(), blueprint, {
|
||||
looseTarget: true,
|
||||
}),
|
||||
new Select(blueprint.getGridDOMElement(), blueprint, {
|
||||
clickButton: 0,
|
||||
exitAnyButton: true,
|
||||
looseTarget: true,
|
||||
moveEverywhere: true,
|
||||
}),
|
||||
new MouseScrollGraph(blueprint.getGridDOMElement(), blueprint, {
|
||||
clickButton: 2,
|
||||
exitAnyButton: false,
|
||||
looseTarget: true,
|
||||
moveEverywhere: true,
|
||||
}),
|
||||
new Unfocus(blueprint.getGridDOMElement(), blueprint),
|
||||
new MouseTracking(blueprint.getGridDOMElement(), blueprint),
|
||||
new KeyboardEnableZoom(blueprint.getGridDOMElement(), blueprint),
|
||||
]
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Blueprint} element
|
||||
*/
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
/**
|
||||
* @typedef {import("../element/IElement").default} IElement
|
||||
* @typedef {import("../input/IInput").default} IInput")}
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -9,7 +10,7 @@
|
||||
*/
|
||||
export default class ITemplate {
|
||||
|
||||
/** @type {Object[]} */
|
||||
/** @type {IInput[]} */
|
||||
inputObjects = []
|
||||
|
||||
/**
|
||||
@@ -25,7 +26,13 @@ export default class ITemplate {
|
||||
setup(element) {
|
||||
// TODO replace with the safer element.setHTML(...) when it will be availableBreack
|
||||
element.innerHTML = this.render(element)
|
||||
this.inputObjects = this.createInputObjects()
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {T} element
|
||||
*/
|
||||
inputSetup(element) {
|
||||
this.inputObjects = this.createInputObjects(element)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,7 +42,10 @@ export default class ITemplate {
|
||||
this.inputObjects.forEach(v => v.unlistenDOMElement())
|
||||
}
|
||||
|
||||
createInputObjects() {
|
||||
return []
|
||||
/**
|
||||
* @param {T} element
|
||||
*/
|
||||
createInputObjects(element) {
|
||||
return /** @type {IInput[]} */([])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import html from "./html"
|
||||
import ITemplate from "./ITemplate"
|
||||
import MouseCreateLink from "../input/mouse/MouseCreateLink"
|
||||
import sanitizeText from "./sanitizeText"
|
||||
import Utility from "../Utility"
|
||||
|
||||
@@ -12,6 +13,19 @@ import Utility from "../Utility"
|
||||
|
||||
export default class PinTemplate extends ITemplate {
|
||||
|
||||
/**
|
||||
* @param {PinElement} pin
|
||||
*
|
||||
*/
|
||||
createInputObjects(pin) {
|
||||
return [
|
||||
new MouseCreateLink(pin.clickableElement, pin.blueprint, {
|
||||
moveEverywhere: true,
|
||||
looseTarget: true
|
||||
})
|
||||
]
|
||||
}
|
||||
|
||||
hasInput() {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// @ts-check
|
||||
|
||||
import MouseMoveNodes from "../input/mouse/MouseMoveNodes"
|
||||
import ITemplate from "./ITemplate"
|
||||
import sanitizeText from "./sanitizeText"
|
||||
|
||||
@@ -7,11 +8,27 @@ import sanitizeText from "./sanitizeText"
|
||||
* @typedef {import("../element/ISelectableDraggableElement").default} ISelectableDraggableElement
|
||||
*/
|
||||
|
||||
/**
|
||||
* @extends {ITemplate<ISelectableDraggableElement>}
|
||||
*/
|
||||
export default class SelectableDraggableTemplate extends ITemplate {
|
||||
|
||||
/**
|
||||
* Returns the html elements rendered from this template.
|
||||
* @param {ISelectableDraggableElement} element Element of the graph
|
||||
* @param {ISelectableDraggableElement} element
|
||||
*/
|
||||
createInputObjects(element) {
|
||||
return [
|
||||
...super.createInputObjects(element),
|
||||
...[
|
||||
new MouseMoveNodes(this, element.blueprint, {
|
||||
looseTarget: true
|
||||
}),
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ISelectableDraggableElement} element
|
||||
*/
|
||||
applyLocation(element) {
|
||||
element.style.setProperty("--ueb-position-x", sanitizeText(element.location[0]))
|
||||
@@ -19,8 +36,7 @@ export default class SelectableDraggableTemplate extends ITemplate {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html elements rendered from this template.
|
||||
* @param {ISelectableDraggableElement} element Element of the graph
|
||||
* @param {ISelectableDraggableElement} element
|
||||
*/
|
||||
applySelected(element) {
|
||||
if (element.selected) {
|
||||
|
||||
Reference in New Issue
Block a user