JSDoc complete type check

This commit is contained in:
barsdeveloper
2022-10-09 11:43:28 +02:00
parent 91e1e0885e
commit cdc5e5b91b
68 changed files with 1603 additions and 648 deletions

View File

@@ -0,0 +1,37 @@
import LinearColorEntity from "../entity/LinearColorEntity"
import ColorHandlerTemplate from "../template/ColorHandlerTemplate"
import IDraggableElement from "./IDraggableElement"
/** @typedef {import("../template/ColorPickerWindowTemplate").default} ColorPickerWindowTemplate */
/**
* @template T
* @typedef {import("./WindowElement").default<T>} WindowElement
*/
export default class ColorHandlerElement extends IDraggableElement {
/** @type {WindowElement<ColorPickerWindowTemplate>} */
windowElement
constructor() {
super({}, new ColorHandlerTemplate())
}
connectedCallback() {
super.connectedCallback()
this.windowElement = this.closest("ueb-window")
}
/** @param {Number[]} param0 */
addLocation([x, y]) {
super.addLocation([x, y])
this.windowElement.windowOptions
this.windowElement.template.color = this.computeColor()
}
computeColor() {
return new LinearColorEntity()
}
}
customElements.define("ueb-color-handler", ColorHandlerElement)

View File

@@ -3,13 +3,13 @@ import IElement from "./IElement"
import Utility from "../Utility"
/**
* @typedef {import("../template/SelectableDraggableTemplate").default} SelectableDraggableTemplate
* @typedef {import("../template/IDraggableTemplate").default} IDraggableTemplate
* @typedef {import("../entity/IEntity").default} IEntity
*/
/**
* @template {IEntity} T
* @template {SelectableDraggableTemplate} U
* @template {IDraggableTemplate} U
* @extends {IElement<T, U>}
*/
export default class IDraggableElement extends IElement {
@@ -25,8 +25,11 @@ export default class IDraggableElement extends IElement {
attribute: false,
},
}
static dragEventName = Configuration.dragEventName
static dragGeneralEventName = Configuration.dragGeneralEventName
constructor(...args) {
// @ts-expect-error
super(...args)
this.locationX = 0
this.locationY = 0
@@ -38,7 +41,8 @@ export default class IDraggableElement extends IElement {
this.locationX = x
this.locationY = y
if (this.blueprint) {
const dragLocalEvent = new CustomEvent(Configuration.nodeDragLocalEventName, {
// @ts-expect-error
const dragLocalEvent = new CustomEvent(this.constructor.dragEventName, {
detail: {
value: d,
},
@@ -56,7 +60,8 @@ export default class IDraggableElement extends IElement {
/** @param {Number[]} value */
dispatchDragEvent(value) {
const dragEvent = new CustomEvent(Configuration.nodeDragEventName, {
// @ts-expect-error
const dragEvent = new CustomEvent(this.constructor.dragGeneralEventName, {
detail: {
value: value
},

View File

@@ -13,6 +13,7 @@ import { LitElement } from "lit"
*/
export default class IElement extends LitElement {
/** @type {import("lit").PropertyDeclarations} */
static properties = {
}
@@ -24,7 +25,7 @@ export default class IElement extends LitElement {
return this.#blueprint
}
set blueprint(v) {
return this.#blueprint = v
this.#blueprint = v
}
/** @type {T} */
@@ -63,7 +64,7 @@ export default class IElement extends LitElement {
connectedCallback() {
super.connectedCallback()
this.blueprint = this.closest("ueb-blueprint")
this.blueprint = /** @type {Blueprint} */ this.closest("ueb-blueprint")
this.template.connectedCallback()
}

View File

@@ -33,6 +33,7 @@ export default class IFromToPositionedElement extends IElement {
}
constructor(...args) {
// @ts-expect-error
super(...args)
this.initialPositionX = 0
this.initialPositionY = 0

View File

@@ -10,8 +10,8 @@ import IDraggableElement from "./IDraggableElement"
/**
* @template {IEntity} T
* @template {IDraggableElement} U
* @extends {IElement<T, U>}
* @template {SelectableDraggableTemplate} U
* @extends {IDraggableElement<T, U>}
*/
export default class ISelectableDraggableElement extends IDraggableElement {
@@ -40,7 +40,7 @@ export default class ISelectableDraggableElement extends IDraggableElement {
disconnectedCallback() {
super.disconnectedCallback()
this.blueprint.removeEventListener(Configuration.nodeDragEventName, this.dragHandler)
this.blueprint.removeEventListener(Configuration.nodeDragGeneralEventName, this.dragHandler)
}
setSelected(value = true) {
@@ -48,9 +48,9 @@ export default class ISelectableDraggableElement extends IDraggableElement {
if (this.blueprint) {
if (this.selected) {
this.listeningDrag = true
this.blueprint.addEventListener(Configuration.nodeDragEventName, this.dragHandler)
this.blueprint.addEventListener(Configuration.nodeDragGeneralEventName, this.dragHandler)
} else {
this.blueprint.removeEventListener(Configuration.nodeDragEventName, this.dragHandler)
this.blueprint.removeEventListener(Configuration.nodeDragGeneralEventName, this.dragHandler)
this.listeningDrag = false
}
}

View File

@@ -119,7 +119,7 @@ export default class LinkElement extends IFromToPositionedElement {
const nodeElement = getCurrentPin().getNodeElement()
nodeElement.removeEventListener(Configuration.nodeDeleteEventName, this.#nodeDeleteHandler)
nodeElement.removeEventListener(
Configuration.nodeDragLocalEventName,
Configuration.nodeDragEventName,
isDestinationPin ? this.#nodeDragDestinatonHandler : this.#nodeDragSourceHandler
)
nodeElement.removeEventListener(
@@ -135,7 +135,7 @@ export default class LinkElement extends IFromToPositionedElement {
const nodeElement = getCurrentPin().getNodeElement()
nodeElement.addEventListener(Configuration.nodeDeleteEventName, this.#nodeDeleteHandler)
nodeElement.addEventListener(
Configuration.nodeDragLocalEventName,
Configuration.nodeDragEventName,
isDestinationPin ? this.#nodeDragDestinatonHandler : this.#nodeDragSourceHandler
)
nodeElement.addEventListener(
@@ -178,7 +178,7 @@ export default class LinkElement extends IFromToPositionedElement {
Promise.all([this.updateComplete, this.sourcePin.updateComplete]).then(() => self.setSourceLocation())
return
}
location = this.sourcePin.template.getLinkLocation(this.sourcePin)
location = this.sourcePin.template.getLinkLocation()
}
const [x, y] = location
this.initialPositionX = x
@@ -193,7 +193,7 @@ export default class LinkElement extends IFromToPositionedElement {
Promise.all([this.updateComplete, this.destinationPin.updateComplete]).then(() => self.setDestinationLocation())
return
}
location = this.destinationPin.template.getLinkLocation(this.destinationPin)
location = this.destinationPin.template.getLinkLocation()
}
this.finaPositionX = location[0]
this.finaPositionY = location[1]

View File

@@ -43,6 +43,8 @@ export default class NodeElement extends ISelectableDraggableElement {
reflect: true,
}
}
static dragEventName = Configuration.nodeDragEventName
static dragGeneralEventName = Configuration.nodeDragGeneralEventName
get blueprint() {
return super.blueprint
@@ -83,6 +85,7 @@ export default class NodeElement extends ISelectableDraggableElement {
static fromSerializedObject(str) {
str = str.trim()
let entity = SerializerFactory.getSerializer(ObjectEntity).deserialize(str)
// @ts-expect-error
return new NodeElement(entity)
}
@@ -136,7 +139,9 @@ export default class NodeElement extends ISelectableDraggableElement {
setLocation(value = [0, 0]) {
let nodeType = this.entity.NodePosX.constructor
// @ts-expect-error
this.entity.NodePosX = new nodeType(value[0])
// @ts-expect-error
this.entity.NodePosY = new nodeType(value[1])
super.setLocation(value)
}

View File

@@ -9,20 +9,26 @@ import LinkElement from "./LinkElement"
import NamePinTemplate from "../template/NamePinTemplate"
import PinTemplate from "../template/PinTemplate"
import RealPinTemplate from "../template/RealPinTemplate"
import ReferencePinTemplate from "../template/ReferencePinTemplate"
import RotatorPinTemplate from "../template/RotatorPinTemplate"
import StringPinTemplate from "../template/StringPinTemplate"
import Utility from "../Utility"
import VectorPinTemplate from "../template/VectorPinTemplate"
import ReferencePinTemplate from "../template/ReferencePinTemplate"
import RotatorPinTemplate from "../template/RotatorPinTemplate"
/**
* @typedef {import("../entity/GuidEntity").default} GuidEntity
* @typedef {import("../entity/PinEntity").default} PinEntity
* @typedef {import("../entity/PinReferenceEntity").default} PinReferenceEntity
* @typedef {import("./NodeElement").default} NodeElement
*/
/**
* @template T
* @typedef {import("../entity/PinEntity").default<T>} PinEntity
*/
/** @extends {IElement<PinEntity, PinTemplate>} */
/**
* @template T
* @extends {IElement<PinEntity<T>, PinTemplate>}
*/
export default class PinElement extends IElement {
static #typeTemplateMap = {
@@ -31,9 +37,9 @@ export default class PinElement extends IElement {
"/Script/CoreUObject.Vector": VectorPinTemplate,
"bool": BoolPinTemplate,
"exec": ExecPinTemplate,
"MUTABLE_REFERENCE": ReferencePinTemplate,
"name": NamePinTemplate,
"real": RealPinTemplate,
"MUTABLE_REFERENCE": ReferencePinTemplate,
"string": StringPinTemplate,
}
@@ -47,6 +53,7 @@ export default class PinElement extends IElement {
type: LinearColorEntity,
converter: {
fromAttribute: (value, type) => {
// @ts-expect-error
return value ? ISerializer.grammar.LinearColorFromAnyColor.parse(value).value : null
},
toAttribute: (value, type) => {
@@ -79,8 +86,8 @@ export default class PinElement extends IElement {
}
/**
* @param {PinEntity} pinEntity
* @return {PinTemplate}
* @param {PinEntity<any>} pinEntity
* @return {new () => PinTemplate}
*/
static getTypeTemplate(pinEntity) {
let result = PinElement.#typeTemplateMap[
@@ -102,26 +109,22 @@ export default class PinElement extends IElement {
get defaultValue() {
return this.unreactiveDefaultValue
}
/** @param {String} value */
set defaultValue(value) {
let oldValue = this.unreactiveDefaultValue
this.unreactiveDefaultValue = value
this.requestUpdate("defaultValue", oldValue)
}
/** @param {PinEntity} entity */
/** @param {PinEntity<T>} entity */
constructor(entity) {
super(
entity,
new (PinElement.getTypeTemplate(entity))()
)
this.advancedView = entity.bAdvancedView
/** @type {String} */
this.unreactiveDefaultValue = entity.getDefaultValue()
if (this.unreactiveDefaultValue.constructor === String) {
this.unreactiveDefaultValue = entity.getDefaultValue()
}
this.pinType = this.entity.getType()
// @ts-expect-error
this.color = this.constructor.properties.color.converter.fromAttribute(Configuration.pinColor[this.pinType]?.toString())
this.isLinked = false
this.pinDirection = entity.isInput() ? "input" : entity.isOutput() ? "output" : "hidden"
@@ -176,7 +179,7 @@ export default class PinElement extends IElement {
}
getLinkLocation() {
return this.template.getLinkLocation(this)
return this.template.getLinkLocation()
}
/** @returns {NodeElement} */

View File

@@ -9,6 +9,7 @@ export default class SelectorElement extends IFromToPositionedElement {
super({}, new SelectorTemplate())
this.selectionModel = null
}
/** @param {Number[]} initialPosition */
beginSelect(initialPosition) {
this.blueprint.selecting = true

View File

@@ -3,7 +3,10 @@ import Configuration from "../Configuration"
import IDraggableElement from "./IDraggableElement"
import WindowTemplate from "../template/WindowTemplate"
/** @extends {ISelectableDraggableElement<Object, WindowTemplate>} */
/**
* @template {WindowTemplate} T
* @extends {IDraggableElement<Object, T>}
*/
export default class WindowElement extends IDraggableElement {
static #typeTemplateMap = {
@@ -25,13 +28,15 @@ export default class WindowElement extends IDraggableElement {
},
}
constructor(properties = {}) {
if (properties.type.constructor == String) {
properties.type = WindowElement.#typeTemplateMap[properties.type]
constructor(options = {}) {
if (options.type.constructor == String) {
options.type = WindowElement.#typeTemplateMap[options.type]
}
properties.type ??= WindowTemplate
super({}, new properties.type())
this.type = properties.type
options.type ??= WindowTemplate
options.windowOptions ??= {}
super({}, new options.type())
this.type = options.type
this.windowOptions = options.windowOptions
}
disconnectedCallback() {