Names refactoring

This commit is contained in:
barsdeveloper
2022-12-10 14:48:27 +01:00
parent 153f329bdd
commit fffe3f7ad1
18 changed files with 159 additions and 89 deletions

View File

@@ -276,29 +276,47 @@ export default class Blueprint extends IElement {
return [x, y]
}
getNodes(selected = false) {
getNodes(
selected = false,
[t, r, b, l] = [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER]
) {
let result = this.nodes
if (selected) {
return this.nodes.filter(
node => node.selected
)
} else {
return this.nodes
result = result.filter(n => n.selected)
}
if (
t > Number.MIN_SAFE_INTEGER
|| r < Number.MAX_SAFE_INTEGER
|| b < Number.MAX_SAFE_INTEGER
|| l > Number.MIN_SAFE_INTEGER
) {
result = result.filter(n => {
return n.topBoundary() > t && n.rightBoundary() < r && n.bottomBoundary() < b && n.leftBoundary() > l
})
}
return result
}
getComments() {
let result = /** @type {NodeElement[]} */ ([...this.template.getComments()])
if (result.length === 0) {
result = this.nodes.filter(n => n.getType() === Configuration.nodeType.comment)
}
return result
}
/** @param {PinReferenceEntity} pinReference */
getPin(pinReference) {
let result = this.template.getPin(pinReference)
if (result
// Make sure it wasn't renamed in the meantime
&& result.nodeElement.getNodeName() == pinReference.objectName.toString()) {
return result
// Remember could be renamed in the meantime and DOM not yet updated
if (!result || result.nodeElement.getNodeName() != pinReference.objectName.toString()) {
// Slower fallback
result = [... this.nodes
.find(n => pinReference.objectName.toString() == n.getNodeName())
?.getPinElements() ?? []]
.find(p => pinReference.pinGuid.toString() == p.getPinId().toString())
}
// Slower fallback
return [... this.nodes
.find(n => pinReference.objectName.toString() == n.getNodeName())
?.getPinElements() ?? []]
.find(p => pinReference.pinGuid.toString() == p.getPinId().toString())
return result
}
/**
@@ -403,7 +421,7 @@ export default class Blueprint extends IElement {
}
/** @param {Boolean} begin */
dispatchEditTextEvent(begin) {
acknowledgeEditText(begin) {
const event = new CustomEvent(
begin
? Configuration.editTextEventName.begin

View File

@@ -6,11 +6,11 @@ import UnionType from "./entity/UnionType"
* @typedef {import("./element/IElement").default} IElement
* @typedef {import("./entity/IEntity").default} IEntity
* @typedef {import("./entity/LinearColorEntity").default} LinearColorEntity
* @typedef {import("./entity/TypeInitialization").AnyValue} AnyValue
* @typedef {import("./entity/TypeInitialization").AnyValue} AnyValue
*/
/**
* @template T
* @typedef {import("./entity/TypeInitialization").AnyValueConstructor<T>} AnyValueConstructor
* @typedef {import("./entity/TypeInitialization").AnyValueConstructor<T>} AnyValueConstructor
*/
export default class Utility {
@@ -167,7 +167,7 @@ export default class Utility {
/**
* @param {AnyValue | AnyValueConstructor<IEntity>} value
* @returns {AnyValueConstructor<IEntity> | AnyValueConstructor<IEntity>[]}
* @returns {AnyValueConstructor<IEntity> | AnyValueConstructor<IEntity>[]}
*/
static getType(value) {
if (value === null) {

View File

@@ -84,7 +84,7 @@ export default class IDraggableElement extends IElement {
}
/** @param {Number[]} value */
dispatchDragEvent(value) {
acknowledgeDrag(value) {
// @ts-expect-error
const dragEvent = new CustomEvent(this.constructor.dragGeneralEventName, {
detail: {

View File

@@ -78,6 +78,7 @@ export default class NodeElement extends ISelectableDraggableElement {
}
#pins
#boundComments
/**
* @param {ObjectEntity} entity
@@ -123,7 +124,7 @@ export default class NodeElement extends ISelectableDraggableElement {
disconnectedCallback() {
super.disconnectedCallback()
this.dispatchDeleteEvent()
this.acknowledgeDelete()
}
getType() {
@@ -138,6 +139,20 @@ export default class NodeElement extends ISelectableDraggableElement {
return this.entity.getDisplayName()
}
/** @param {Number} value */
setNodeWidth(value) {
this.entity.setNodeWidth(value)
this.sizeX = value
this.acknowledgeReflow()
}
/** @param {Number} value */
setNodeHeight(value) {
this.entity.setNodeHeight(value)
this.sizeY = value
this.acknowledgeReflow()
}
/** @param {IElement[]} nodesWhitelist */
sanitizeLinks(nodesWhitelist = []) {
this.getPinElements().forEach(pin => pin.sanitizeLinks(nodesWhitelist))
@@ -177,12 +192,12 @@ export default class NodeElement extends ISelectableDraggableElement {
super.setLocation(value)
}
dispatchDeleteEvent() {
acknowledgeDelete() {
let deleteEvent = new CustomEvent(Configuration.nodeDeleteEventName)
this.dispatchEvent(deleteEvent)
}
dispatchReflowEvent() {
acknowledgeReflow() {
this.addNextUpdatedCallbacks(() => this.computeSizes(), true)
let reflowEvent = new CustomEvent(Configuration.nodeReflowEventName)
this.dispatchEvent(reflowEvent)

View File

@@ -41,10 +41,10 @@ export default class WindowElement extends IDraggableElement {
disconnectedCallback() {
super.disconnectedCallback()
this.dispatchCloseEvent()
this.acknowledgeClose()
}
dispatchCloseEvent() {
acknowledgeClose() {
let deleteEvent = new CustomEvent(Configuration.windowCloseEventName)
this.dispatchEvent(deleteEvent)
}

View File

@@ -16,7 +16,7 @@ export default class MouseMoveNodes extends MouseMoveDraggable {
}
dragAction(location, offset) {
this.target.dispatchDragEvent(offset)
this.target.acknowledgeDrag(offset)
}
unclicked() {

View File

@@ -11,7 +11,7 @@ import GeneralSerializer from "./GeneralSerializer"
/**
* @template {AnyValue} T
* @extends {GeneralSerializer<T>}
* @extends {GeneralSerializer<T>}
*/
export default class CustomSerializer extends GeneralSerializer {

View File

@@ -18,7 +18,7 @@ export default class GeneralSerializer extends ISerializer {
/**
* @param {(value: String, entity: T) => String} wrap
* @param {AnyValueConstructor<T>} entityType
* @param {AnyValueConstructor<T>} entityType
*/
constructor(wrap, entityType, attributePrefix, attributeSeparator, trailingSeparator, attributeValueConjunctionSign, attributeKeyPrinter) {
wrap = wrap ?? (v => `(${v})`)

View File

@@ -133,7 +133,7 @@ export default class Grammar {
r.AttributeName
.skip(valueSeparator)
.chain(attributeName => {
// Once the attribute name is known, look into entityType.attributes to get its type
// Once the attribute name is known, look into entityType.attributes to get its type
const attributeKey = attributeName.split(".")
const attribute = Utility.objectGet(entityType.attributes, attributeKey)
let attributeValueGrammar = Grammar.getGrammarForType(r, attribute, r.AttributeAnyValue)

View File

@@ -123,6 +123,10 @@ export default class BlueprintTemplate extends ITemplate {
}
}
getComments() {
return this.element.querySelectorAll(`ueb-node[data-type="${Configuration.nodeType.comment}"]`)
}
/** @param {PinReferenceEntity} pinReference */
getPin(pinReference) {
return /** @type {PinElement} */(this.element.querySelector(

View File

@@ -48,8 +48,7 @@ export default class CommentNodeTemplate extends IResizeableTemplate {
setSizeX(value) {
value = Math.round(value)
if (value >= Configuration.gridSet * Configuration.gridSize) {
this.element.sizeX = value
this.element.entity.setNodeWidth(this.element.sizeX)
this.element.setNodeWidth(value)
return true
}
return false
@@ -59,8 +58,7 @@ export default class CommentNodeTemplate extends IResizeableTemplate {
setSizeY(value) {
value = Math.round(value)
if (value >= 3 * Configuration.gridSize) {
this.element.sizeY = Math.max(value, 3 * Configuration.gridSize)
this.element.entity.setNodeHeight(this.element.sizeY)
this.element.setNodeHeight(value)
return true
}
return false

View File

@@ -77,7 +77,7 @@ export default class IInputPinTemplate extends PinTemplate {
/** @param {String[]?} values */
setInputs(values = [], updateDefaultValue = true) {
// @ts-expect-error
// @ts-expect-error
this.#inputContentElements.forEach(this.constructor.singleLineInput
? (elem, i) => elem.innerText = values[i]
: (elem, i) => elem.innerText = values[i].replaceAll("\n", "")
@@ -85,7 +85,7 @@ export default class IInputPinTemplate extends PinTemplate {
if (updateDefaultValue) {
this.setDefaultValue(values.map(v => IInputPinTemplate.stringFromInputToUE(v)), values)
}
this.element.addNextUpdatedCallbacks(() => this.element.nodeElement.dispatchReflowEvent())
this.element.addNextUpdatedCallbacks(() => this.element.nodeElement.acknowledgeReflow())
}
setDefaultValue(values = [], rawValues = values) {

View File

@@ -130,13 +130,13 @@ export default class IResizeableTemplate extends NodeTemplate {
/** @param {Number} value */
setSizeX(value) {
this.element.sizeX = value
this.element.setNodeWidth(value)
return true
}
/** @param {Number} value */
setSizeY(value) {
this.element.sizeY = value
this.element.setNodeHeight(value)
return true
}
}

View File

@@ -6,13 +6,13 @@ import ITemplate from "./ITemplate"
export default class InputTemplate extends ITemplate {
#focusHandler = () => {
this.element.blueprint.dispatchEditTextEvent(true)
this.element.blueprint.acknowledgeEditText(true)
if (this.element.selectOnFocus) {
getSelection().selectAllChildren(this.element)
}
}
#focusoutHandler = () => {
this.element.blueprint.dispatchEditTextEvent(false)
this.element.blueprint.acknowledgeEditText(false)
document.getSelection()?.removeAllRanges() // Deselect eventually selected text inside the input
}
#inputSingleLineHandler =

View File

@@ -34,7 +34,7 @@ export default class NodeTemplate extends ISelectableDraggableTemplate {
toggleAdvancedDisplayHandler = () => {
this.element.toggleShowAdvancedPinDisplay()
this.element.addNextUpdatedCallbacks(() => this.element.dispatchReflowEvent(), true)
this.element.addNextUpdatedCallbacks(() => this.element.acknowledgeReflow(), true)
}
/** @param {NodeElement} element */
@@ -130,7 +130,7 @@ export default class NodeTemplate extends ISelectableDraggableTemplate {
firstUpdated(changedProperties) {
super.firstUpdated(changedProperties)
this.setupPins()
Promise.all(this.element.getPinElements().map(n => n.updateComplete)).then(() => this.element.dispatchReflowEvent())
Promise.all(this.element.getPinElements().map(n => n.updateComplete)).then(() => this.element.acknowledgeReflow())
}
setupPins() {

View File

@@ -72,7 +72,7 @@ export default class PinTemplate extends ITemplate {
if (this.element.isInput() && changedProperties.has("isLinked")) {
// When connected, an input may drop its input fields which means the node has to reflow
const node = this.element.nodeElement
node.addNextUpdatedCallbacks(() => node.dispatchReflowEvent())
node.addNextUpdatedCallbacks(() => node.acknowledgeReflow())
node.requestUpdate()
}
}