mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-23 23:34:43 +08:00
Select all nodes functionality added
This commit is contained in:
@@ -13,6 +13,7 @@ import Select from "./input/mouse/Select"
|
||||
import Unfocus from "./input/mouse/Unfocus"
|
||||
import Utility from "./Utility"
|
||||
import Zoom from "./input/mouse/Zoom"
|
||||
import KeyboardSelectAll from "./input/keybaord/KeyboardSelectAll"
|
||||
|
||||
export default class Blueprint extends GraphElement {
|
||||
|
||||
@@ -93,9 +94,11 @@ export default class Blueprint extends GraphElement {
|
||||
|
||||
createInputObjects() {
|
||||
return [
|
||||
|
||||
new Copy(this.getGridDOMElement(), this),
|
||||
new Paste(this.getGridDOMElement(), this),
|
||||
new KeyboardCanc(this.getGridDOMElement(), this),
|
||||
new KeyboardSelectAll(this.getGridDOMElement, this),
|
||||
new Zoom(this.getGridDOMElement(), this, {
|
||||
looseTarget: true,
|
||||
}),
|
||||
@@ -111,7 +114,7 @@ export default class Blueprint extends GraphElement {
|
||||
moveEverywhere: true,
|
||||
}),
|
||||
new Unfocus(this.getGridDOMElement(), this),
|
||||
new MouseTracking(this.getGridDOMElement(), this),
|
||||
new MouseTracking(this.getGridDOMElement(), this)
|
||||
]
|
||||
}
|
||||
|
||||
@@ -297,6 +300,13 @@ export default class Blueprint extends GraphElement {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Select all nodes
|
||||
*/
|
||||
selectAll() {
|
||||
this.nodes.forEach(node => this.nodeSelectToggleFunction(node, true))
|
||||
}
|
||||
|
||||
/**
|
||||
* Unselect all nodes
|
||||
*/
|
||||
|
||||
@@ -3,4 +3,96 @@ export default class Configuration {
|
||||
static deleteNodesKeyboardKey = "Delete"
|
||||
static expandGridSize = 400
|
||||
static gridSize = 16
|
||||
static selectAllKeyboardKey = "Ctrl+A"
|
||||
static keysSeparator = "+"
|
||||
static ModifierKeys = [
|
||||
"Ctrl",
|
||||
"Shift",
|
||||
"Alt",
|
||||
"Meta"
|
||||
]
|
||||
static Keys = {
|
||||
"Backspace": "Backspace",
|
||||
"Tab": "Tab",
|
||||
"Enter": "Enter",
|
||||
"Pause": "Pause",
|
||||
"CapsLock": "CapsLock",
|
||||
"Escape": "Escape",
|
||||
"Space": "Space",
|
||||
"PageUp": "PageUp",
|
||||
"PageDown": "PageDown",
|
||||
"End": "End",
|
||||
"Home": "Home",
|
||||
"ArrowLeft": "ArrowLeft",
|
||||
"ArrowUp": "ArrowUp",
|
||||
"ArrowRight": "ArrowRight",
|
||||
"ArrowDown": "ArrowDown",
|
||||
"PrintScreen": "PrintScreen",
|
||||
"Insert": "Insert",
|
||||
"Delete": "Delete",
|
||||
"Digit0": "Digit0",
|
||||
"Digit1": "Digit1",
|
||||
"Digit2": "Digit2",
|
||||
"Digit3": "Digit3",
|
||||
"Digit4": "Digit4",
|
||||
"Digit5": "Digit5",
|
||||
"Digit6": "Digit6",
|
||||
"Digit7": "Digit7",
|
||||
"Digit8": "Digit8",
|
||||
"Digit9": "Digit9",
|
||||
"A": "KeyA",
|
||||
"B": "KeyB",
|
||||
"C": "KeyC",
|
||||
"D": "KeyD",
|
||||
"E": "KeyE",
|
||||
"F": "KeyF",
|
||||
"G": "KeyG",
|
||||
"H": "KeyH",
|
||||
"I": "KeyI",
|
||||
"K": "KeyK",
|
||||
"L": "KeyL",
|
||||
"M": "KeyM",
|
||||
"N": "KeyN",
|
||||
"O": "KeyO",
|
||||
"P": "KeyP",
|
||||
"Q": "KeyQ",
|
||||
"R": "KeyR",
|
||||
"S": "KeyS",
|
||||
"T": "KeyT",
|
||||
"U": "KeyU",
|
||||
"V": "KeyV",
|
||||
"W": "KeyW",
|
||||
"X": "KeyX",
|
||||
"Y": "KeyY",
|
||||
"Z": "KeyZ",
|
||||
"Numpad0": "Numpad0",
|
||||
"Numpad1": "Numpad1",
|
||||
"Numpad2": "Numpad2",
|
||||
"Numpad3": "Numpad3",
|
||||
"Numpad4": "Numpad4",
|
||||
"Numpad5": "Numpad5",
|
||||
"Numpad6": "Numpad6",
|
||||
"Numpad7": "Numpad7",
|
||||
"Numpad8": "Numpad8",
|
||||
"Numpad9": "Numpad9",
|
||||
"NumpadMultiply": "NumpadMultiply",
|
||||
"NumpadAdd": "NumpadAdd",
|
||||
"NumpadSubtract": "NumpadSubtract",
|
||||
"NumpadDecimal": "NumpadDecimal",
|
||||
"NumpadDivide": "NumpadDivide",
|
||||
"F1": "F1",
|
||||
"F2": "F2",
|
||||
"F3": "F3",
|
||||
"F4": "F4",
|
||||
"F5": "F5",
|
||||
"F6": "F6",
|
||||
"F7": "F7",
|
||||
"F8": "F8",
|
||||
"F9": "F9",
|
||||
"F10": "F10",
|
||||
"F11": "F11",
|
||||
"F12": "F12",
|
||||
"NumLock": "NumLock",
|
||||
"ScrollLock": "ScrollLock",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,10 @@ export default class Copy extends Context {
|
||||
super(target, blueprint, options)
|
||||
this.serializer = new ObjectSerializer()
|
||||
let self = this
|
||||
this.copyHandler = _ => self.copied()
|
||||
this.copyHandler = _ => {
|
||||
self.copied()
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
blueprintFocused() {
|
||||
|
||||
@@ -47,5 +47,6 @@ export default class Paste extends Context {
|
||||
node.setSelected(true)
|
||||
node.snapToGrid()
|
||||
})
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
21
js/input/keybaord/KeyboardSelectAll.js
Executable file
21
js/input/keybaord/KeyboardSelectAll.js
Executable file
@@ -0,0 +1,21 @@
|
||||
import KeyboardShortcut from "./KeyboardShortcut"
|
||||
import Configuration from "../../Configuration"
|
||||
|
||||
|
||||
export default class KeyboardSelectAll extends KeyboardShortcut {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {HTMLElement} target
|
||||
* @param {import("../../Blueprint").default} blueprint
|
||||
* @param {Object} options
|
||||
*/
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options = KeyboardShortcut.keyOptionsParse(options, Configuration.selectAllKeyboardKey)
|
||||
super(target, blueprint, options)
|
||||
}
|
||||
|
||||
fire() {
|
||||
this.blueprint.selectAll()
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,38 @@
|
||||
import Configuration from "../../Configuration"
|
||||
import Context from "../Context"
|
||||
import Parsimmon from "parsimmon"
|
||||
|
||||
let P = Parsimmon
|
||||
|
||||
class KeyGrammar {
|
||||
|
||||
// Creates a grammar where each alternative is the string from ModifierKey mapped to a number for bit or use
|
||||
ModifierKey = r => P.alt(...Configuration.ModifierKeys.map((v, i) => P.string(v).map(_ => 1 << i)))
|
||||
Key = r => P.alt(...Object.keys(Configuration.Keys).map(v => P.string(v))).map(v => Configuration.Keys[v])
|
||||
KeyboardShortcut = r => P.alt(
|
||||
P.seqMap(
|
||||
P.seqMap(r.ModifierKey, P.optWhitespace, P.string(Configuration.keysSeparator), (v, _, __) => v)
|
||||
.atLeast(1)
|
||||
.map(v => v.reduce((acc, cur) => acc | cur)),
|
||||
P.optWhitespace,
|
||||
r.Key,
|
||||
(modifierKeysFlag, _, key) => ({
|
||||
key: key,
|
||||
ctrlKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Ctrl"))),
|
||||
shiftKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Shift"))),
|
||||
altKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Alt"))),
|
||||
metaKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Meta")))
|
||||
})
|
||||
),
|
||||
r.Key.map(v => ({ key: v }))
|
||||
)
|
||||
.trim(P.optWhitespace)
|
||||
}
|
||||
|
||||
export default class KeyboardShortcut extends Context {
|
||||
|
||||
static keyGrammar = P.createLanguage(new KeyGrammar())
|
||||
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options.wantsFocusCallback = true
|
||||
super(target, blueprint, options)
|
||||
@@ -23,7 +54,10 @@ export default class KeyboardShortcut extends Context {
|
||||
&& e.metaKey === self.metaKey
|
||||
) {
|
||||
self.fire()
|
||||
e.preventDefault()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +67,10 @@ export default class KeyboardShortcut extends Context {
|
||||
* @returns {Object}
|
||||
*/
|
||||
static keyOptionsParse(options, keyString) {
|
||||
options.key = keyString
|
||||
options = {
|
||||
...options,
|
||||
...KeyboardShortcut.keyGrammar.KeyboardShortcut.parse(keyString).value
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ export default class MouseClickDrag extends Pointing {
|
||||
document.addEventListener("mouseup", self.mouseUpHandler)
|
||||
self.clickedPosition = self.getLocation(e)
|
||||
self.clicked(self.clickedPosition)
|
||||
return true
|
||||
}
|
||||
break
|
||||
default:
|
||||
@@ -39,6 +40,7 @@ export default class MouseClickDrag extends Pointing {
|
||||
}
|
||||
break
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
this.mouseStartedMovingHandler = e => {
|
||||
|
||||
@@ -9,6 +9,7 @@ export default class MouseTracking extends Pointing {
|
||||
let self = this
|
||||
this.mousemoveHandler = e => {
|
||||
self.blueprint.entity.mousePosition = self.getLocation(e)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ export default class MouseWheel extends Pointing {
|
||||
e.preventDefault()
|
||||
const location = self.getLocation(e)
|
||||
self.wheel(Math.sign(e.deltaY), location)
|
||||
return true
|
||||
}
|
||||
this.mouseParentWheelHandler = e => e.preventDefault()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user