port lexer to cpp
This commit is contained in:
parent
cacc641378
commit
b3b21f3101
13 changed files with 276 additions and 32 deletions
|
|
@ -1,8 +1,11 @@
|
|||
import { isCompileBinding } from "../compilers/bindings/Checker.js"
|
||||
import { Parser } from "../compilers/bindings/Parser.js"
|
||||
import { FormatProperties } from "../compilers/FormatProperties.js"
|
||||
import { Memory } from "../compilers/Memory.js"
|
||||
import { BindingType } from "../types/enums/BindingType.js"
|
||||
import { Renderer } from "../types/enums/Renderer.js"
|
||||
import { Type } from "../types/enums/Type.js"
|
||||
import { Properties } from "../types/properties/components.js"
|
||||
import { BindingItem } from "../types/properties/value.js"
|
||||
import { Class } from "./Class.js"
|
||||
import { RandomString } from "./Utils.js"
|
||||
|
||||
|
|
@ -18,6 +21,7 @@ export class UI<T extends Type, K extends Renderer | null = null> extends Class
|
|||
extendable: boolean
|
||||
|
||||
controls = new Map<string, [UI<Type, Renderer | null>, Properties<Type, Renderer | null>]>()
|
||||
bindings: BindingItem[] = []
|
||||
properties: Properties<T, K> = <any>{}
|
||||
|
||||
constructor(
|
||||
|
|
@ -47,6 +51,23 @@ export class UI<T extends Type, K extends Renderer | null = null> extends Class
|
|||
return this
|
||||
}
|
||||
|
||||
addBindings(...bindings: BindingItem[]) {
|
||||
for (const binding of bindings) {
|
||||
if (binding.source_property_name) {
|
||||
if (isCompileBinding(binding.source_property_name)) {
|
||||
const { gen, out } = new Parser(binding.source_property_name.slice(1, -1)).out()
|
||||
if (gen) this.bindings.push(...gen)
|
||||
binding.source_property_name = out
|
||||
}
|
||||
|
||||
binding.binding_type = BindingType.VIEW
|
||||
|
||||
if (!binding.target_property_name) throw new Error("Binding must have a target property name")
|
||||
}
|
||||
this.bindings.push(binding)
|
||||
}
|
||||
}
|
||||
|
||||
addChild<T extends Type, K extends Renderer | null>(child: UI<T, K>, properties?: Properties<T, K>, name?: string) {
|
||||
if (this === <any>child) {
|
||||
throw new Error("Cannot add a child to itself")
|
||||
|
|
@ -69,6 +90,10 @@ export class UI<T extends Type, K extends Renderer | null = null> extends Class
|
|||
obj.type = this.type
|
||||
}
|
||||
|
||||
if (this.bindings.length) {
|
||||
obj.bindings = this.bindings
|
||||
}
|
||||
|
||||
if (this.controls.size) {
|
||||
obj.controls = []
|
||||
this.controls.forEach((e, key) => obj.controls.push({ [key + e[0]]: e[1] }))
|
||||
|
|
@ -78,7 +103,13 @@ export class UI<T extends Type, K extends Renderer | null = null> extends Class
|
|||
}
|
||||
|
||||
[util.inspect.custom]($: any, opts: any) {
|
||||
const obj: any = FormatProperties(this.properties)
|
||||
const obj: any = {
|
||||
...FormatProperties(this.properties),
|
||||
}
|
||||
|
||||
if (this.bindings.length) {
|
||||
obj.bindings = this.bindings
|
||||
}
|
||||
|
||||
if (this.controls.size) {
|
||||
obj.controls = []
|
||||
|
|
@ -90,3 +121,10 @@ export class UI<T extends Type, K extends Renderer | null = null> extends Class
|
|||
}\x1b[0m> \x1b[92m"${this}\x1b[92m"\x1b[0m ${util.inspect(obj, opts)}\n`
|
||||
}
|
||||
}
|
||||
|
||||
export class ModifyUI<T extends Type> extends UI<T, null> {
|
||||
constructor(namespace: string, name: string, path: string) {
|
||||
if (!path) throw new Error("ModifyUI cannot have a path")
|
||||
super(undefined, name, namespace, path)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue