Data types-related fixes

This commit is contained in:
barsdeveloper
2022-03-20 22:29:53 +01:00
parent 871f76b305
commit 4dd2929a9f
15 changed files with 128 additions and 23 deletions

32
js/entity/Identifier.js Normal file
View File

@@ -0,0 +1,32 @@
import IEntity from "./IEntity"
export default class Identifier extends IEntity {
static attributes = {
value: String,
}
constructor(options = {}) {
// Not instanceof to pick also primitive string
if (options.constructor === String) {
options = {
value: options
}
}
super(options)
/** @type {String} */
this.value
if (!this.value.match(/\w+/)) {
throw new Error("The value must be an identifier (/\w+/).")
}
}
valueOf() {
return this.value
}
toString() {
return this.value
}
}

View File

@@ -1,5 +1,6 @@
import FunctionReferenceEntity from "./FunctionReferenceEntity"
import GuidEntity from "./GuidEntity"
import Identifier from "./Identifier"
import IEntity from "./IEntity"
import IntegerEntity from "./IntegerEntity"
import ObjectReferenceEntity from "./ObjectReferenceEntity"
@@ -19,6 +20,7 @@ export default class ObjectEntity extends IEntity {
TargetType: new TypeInitialization(ObjectReferenceEntity, false, null),
NodePosX: IntegerEntity,
NodePosY: IntegerEntity,
AdvancedPinDisplay: new TypeInitialization(Identifier, false, null),
NodeGuid: GuidEntity,
ErrorType: new TypeInitialization(IntegerEntity, false),
ErrorMsg: new TypeInitialization(String, false, ""),

View File

@@ -1,5 +1,6 @@
import FunctionReferenceEntity from "../entity/FunctionReferenceEntity"
import GuidEntity from "../entity/GuidEntity"
import Identifier from "../entity/Identifier"
import IntegerEntity from "../entity/IntegerEntity"
import LocalizedTextEntity from "../entity/LocalizedTextEntity"
import ObjectEntity from "../entity/ObjectEntity"
@@ -47,6 +48,9 @@ export default class Grammar {
/** @param {Grammar} r */
Guid = r => P.regex(/[0-9a-zA-Z]{32}/).map(v => new GuidEntity({ value: v })).desc("32 digit hexadecimal (accepts all the letters for safety) value")
/** @param {Grammar} */
Identifier = r => P.regex(/\w+/).map(v => new Identifier(v))
/** @param {Grammar} r */
PathSymbolEntity = r => P.regex(/[0-9a-zA-Z_]+/).map(v => new PathSymbolEntity({ value: v }))
@@ -121,6 +125,8 @@ export default class Grammar {
return r.String
case GuidEntity:
return r.Guid
case Identifier:
return r.Identifier
case ObjectReferenceEntity:
return r.Reference
case LocalizedTextEntity:

View File

@@ -58,7 +58,7 @@ export default class ISerializer {
// Recursive call when finding an object
result += (result.length ? this.separator : "")
+ this.subWrite(fullKey, value)
} else if (value !== undefined && this.showProperty(fullKey, value)) {
} else if (value !== undefined && this.showProperty(object, fullKey, value)) {
result += (result.length ? this.separator : "")
+ this.prefix
+ this.attributeKeyPrinter(fullKey)
@@ -73,7 +73,7 @@ export default class ISerializer {
return result
}
showProperty(attributeKey, attributeValue) {
showProperty(object, attributeKey, attributeValue) {
const attributes = this.entityType.attributes
const attribute = Utility.objectGet(attributes, attributeKey)
if (attribute instanceof TypeInitialization) {

View File

@@ -9,7 +9,7 @@ export default class ObjectSerializer extends ISerializer {
super(ObjectEntity, " ", "\n", false)
}
showProperty(attributeKey, attributeValue) {
showProperty(object, attributeKey, attributeValue) {
switch (attributeKey.toString()) {
case "Class":
case "Name":
@@ -17,7 +17,7 @@ export default class ObjectSerializer extends ISerializer {
// Serielized separately
return false
}
return super.showProperty(attributeKey, attributeValue)
return super.showProperty(object, attributeKey, attributeValue)
}
read(value) {
@@ -49,7 +49,12 @@ export default class ObjectSerializer extends ISerializer {
let result = `Begin Object Class=${object.Class.path} Name=${this.writeValue(object.Name)}
${this.subWrite([], object)
+ object
.CustomProperties.map(pin => this.separator + this.prefix + "CustomProperties " + SerializerFactory.getSerializer(PinEntity).write(pin))
.CustomProperties.map(pin =>
this.separator
+ this.prefix
+ "CustomProperties "
+ SerializerFactory.getSerializer(PinEntity).write(pin)
)
.join("")}
End Object\n`
return result

View File

@@ -12,6 +12,7 @@ import PinEntity from "../entity/PinEntity"
import PinReferenceEntity from "../entity/PinReferenceEntity"
import SerializerFactory from "./SerializerFactory"
import ToStringSerializer from "./ToStringSerializer"
import Identifier from "../entity/Identifier"
export default function initializeSerializerFactory() {
SerializerFactory.registerSerializer(
@@ -44,6 +45,7 @@ export default function initializeSerializerFactory() {
: ""
))
)
SerializerFactory.registerSerializer(Identifier, new ToStringSerializer(Identifier))
SerializerFactory.registerSerializer(PathSymbolEntity, new ToStringSerializer(PathSymbolEntity))
SerializerFactory.registerSerializer(GuidEntity, new ToStringSerializer(GuidEntity))
SerializerFactory.registerSerializer(IntegerEntity, new ToStringSerializer(IntegerEntity))

View File

@@ -42,6 +42,9 @@ export default class NodeTemplate extends SelectableDraggableTemplate {
node.classList.add("ueb-selected")
}
node.dataset.name = node.getNodeName()
if (node.entity.AdvancedPinDisplay) {
node.dataset.advancedDisplay = node.entity.AdvancedPinDisplay
}
node.style.setProperty("--ueb-position-x", sanitizeText(node.location[0]))
node.style.setProperty("--ueb-position-y", sanitizeText(node.location[1]))
/** @type {HTMLElement} */

View File

@@ -40,6 +40,9 @@ export default class PinTemplate extends ITemplate {
"ueb-pin-" + sanitizeText(pin.getType())
)
pin.dataset.id = pin.GetPinIdValue()
if (pin.entity.bAdvancedView) {
pin.dataset.advancedView = "true"
}
pin.clickableElement = pin
window.customElements.whenDefined("ueb-node").then(pin.nodeElement = pin.closest("ueb-node"))
pin.getLinks().forEach(pinReference => {