@ibyar/core 0.5.6 → 0.5.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/annotation/decorators.d.ts +97 -0
- package/binding/binding.expressions.d.ts +5 -0
- package/binding/binding.expressions.js +7 -0
- package/binding/binding.expressions.js.map +1 -1
- package/component/component.js +1 -0
- package/component/component.js.map +1 -1
- package/component/custom-element.d.ts +42 -0
- package/context/stack.js +4 -0
- package/context/stack.js.map +1 -1
- package/directive/directive.d.ts +9 -0
- package/directive/directive.js +9 -0
- package/directive/directive.js.map +1 -1
- package/directive/parser.d.ts +4 -0
- package/directive/parser.js +19 -0
- package/directive/parser.js.map +1 -1
- package/html/expression.d.ts +5 -0
- package/html/expression.js +12 -0
- package/html/expression.js.map +1 -1
- package/linker/change-detector-ref.d.ts +14 -0
- package/linker/change-detector-ref.js +3 -0
- package/linker/change-detector-ref.js.map +1 -1
- package/linker/template-ref.d.ts +12 -0
- package/linker/template-ref.js +2 -0
- package/linker/template-ref.js.map +1 -1
- package/linker/view-container-ref.d.ts +78 -0
- package/linker/view-container-ref.js +1 -0
- package/linker/view-container-ref.js.map +1 -1
- package/linker/view-ref.d.ts +39 -0
- package/package.json +4 -4
- package/pipe/pipe.d.ts +7 -0
- package/providers/injector.js +1 -0
- package/providers/injector.js.map +1 -1
- package/render/host-listener.handler.d.ts +17 -0
- package/render/host-listener.handler.js +17 -0
- package/render/host-listener.handler.js.map +1 -1
- package/render/render-handler.d.ts +6 -0
- package/utils/typeof.d.ts +3 -0
- package/utils/utils.js +1 -0
- package/utils/utils.js.map +1 -1
- package/view/base-view.js +12 -1
- package/view/base-view.js.map +1 -1
- package/view/form-view.js +21 -0
- package/view/form-view.js.map +1 -1
- package/view/mutation.js +1 -0
- package/view/mutation.js.map +1 -1
- package/view/render.js +28 -3
- package/view/render.js.map +1 -1
- package/view/view.d.ts +5 -0
- package/view/view.js +6 -0
- package/view/view.js.map +1 -1
package/view/view.js.map
C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AAE;YACb,aAAa,GAAG,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;YAC/C,IAAI,CAAC,aAAa,EAAE;gBACnB,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,CAAC,IAAI,iBAAiB,QAAQ,UAAU,CAAC,CAAC;aACvE;SACD;aAAM;YACN,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;SACrD;QACD,OAAO,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;KAC9C;IACD,OAAO;AACR,CAAC","sourcesContent":["import type { TypeOf } from '../utils/typeof.js';\nimport { getAllAttributes, isFormElement } from '@ibyar/elements';\nimport { ComponentRef } from '../component/component.js';\nimport { HTMLComponent } from '../component/custom-element.js';\nimport { EventEmitter, Subscription } from '../component/events.js';\nimport { ToCamelCase } from '../utils/utils.js';\nimport { Constructable } from '../providers/injector.js';\nimport { baseFactoryView } from './base-view.js';\nimport { baseFormFactoryView } from './form-view.js';\n\n/**\n * \n * @param modelClass \n * @param componentRef \n */\nexport function initCustomElementView<T extends Object>(modelClass: TypeOf<T>, componentRef: ComponentRef<T>): TypeOf<HTMLComponent<T>> {\n\tconst htmlParent = componentRef.extend.classRef as TypeOf<HTMLElement>;\n\tlet viewClass: TypeOf<HTMLComponent<T>>;\n\tconst viewClassName = buildViewClassNameFromSelector(componentRef.selector);\n\tconst htmlViewClassName = `HTML${viewClassName}Element`;\n\tconst parentClass = componentRef.extend.name\n\t\t? (isFormElement(componentRef.extend.name)\n\t\t\t? baseFormFactoryView<T>(htmlParent)\n\t\t\t: baseFactoryView<T>(htmlParent)\n\t\t)\n\t\t: baseFactoryView<T>(HTMLElement);\n\tviewClass = ({\n\t\t[htmlViewClassName]: class extends parentClass { constructor() { super(componentRef, modelClass); } }\n\t})[htmlViewClassName];\n\n\tcomponentRef.inputs.forEach((input) => {\n\t\tObject.defineProperty(viewClass.prototype, input.viewAttribute, {\n\t\t\tget(this: HTMLComponent<T>): any {\n\t\t\t\treturn this._modelScope.get(input.modelProperty);\n\t\t\t},\n\t\t\tset(this: HTMLComponent<{ [key: string]: any; }>, value: any) {\n\t\t\t\tthis._modelScope.set(input.modelProperty, value);\n\t\t\t},\n\t\t\tenumerable: true,\n\t\t});\n\t});\n\n\tcomponentRef.outputs.forEach(output => {\n\t\tObject.defineProperty(viewClass.prototype, output.viewAttribute, {\n\t\t\tget(): EventEmitter<any> {\n\t\t\t\treturn this._model[output.modelProperty];\n\t\t\t},\n\t\t\tenumerable: true\n\t\t});\n\t\tlet eventListener: Function | undefined;\n\t\tlet subscription: Subscription<any>;\n\t\tObject.defineProperty(viewClass.prototype, 'on' + ToCamelCase(output.viewAttribute), {\n\t\t\tget(): Function | undefined {\n\t\t\t\treturn eventListener;\n\t\t\t},\n\t\t\tset(this: HTMLComponent<T>, event: string | Function): void {\n\t\t\t\tif (!event) {\n\t\t\t\t\tif (subscription) {\n\t\t\t\t\t\tsubscription.unsubscribe();\n\t\t\t\t\t\teventListener = undefined;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (typeof event === 'string') {\n\t\t\t\t\tif (event.endsWith('()')) {\n\t\t\t\t\t\tevent = event.substring(0, event.length - 2);\n\t\t\t\t\t}\n\t\t\t\t\tevent = Reflect.get(window, event);\n\t\t\t\t}\n\t\t\t\teventListener = event as Function;\n\t\t\t\tsubscription = (this._model[output.modelProperty] as EventEmitter<any>).subscribe(event);\n\t\t\t},\n\t\t\tenumerable: true\n\t\t});\n\t});\n\n\tcomponentRef.inputs.map(input => input.modelProperty)\n\t\t.concat(componentRef.outputs.map(output => output.modelProperty))\n\t\t.concat(componentRef.hostBindings.map(host => host.hostPropertyName))\n\t\t.concat(componentRef.viewChild.map(child => child.modelName))\n\t\t.forEach(modelName => modelClass.prototype[modelName] = undefined);\n\n\tconst defaultAttributes = getAllAttributes(componentRef.extend.name);\n\tconst observedAttributes = componentRef.inputs.map(input => input.viewAttribute)\n\tReflect.set(viewClass, 'observedAttributes', observedAttributes);\n\tReflect.set(viewClass, 'allAttributes', defaultAttributes.concat(observedAttributes));\n\t// https://html.spec.whatwg.org/multipage/custom-elements.html#custom-elements-face-example\n\tif (false) {\n\t\tObject.defineProperty(viewClass, 'formAssociated', {\n\t\t\tget() {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t});\n\t}\n\taddViewToModelClass<T>(modelClass, componentRef.selector, viewClass, htmlViewClassName);\n\tif (!Reflect.has(window, htmlViewClassName)) {\n\t\tReflect.set(window, htmlViewClassName, viewClass);\n\t}\n\treturn viewClass;\n}\n\nexport type ComponentModelClass = Constructable & { [key: string]: string } & { component: { [key: string]: string } };\n\nexport function isComponentModelClass(target: Constructable): target is ComponentModelClass {\n\treturn Reflect.has(target, 'component');\n}\n\nexport function addViewToModelClass<T extends object>(modelClass: TypeOf<T>, selector: string, viewClass: TypeOf<HTMLComponent<T>>, htmlViewClassName: string) {\n\tObject.defineProperty(modelClass, htmlViewClassName, { value: viewClass });\n\n\tif (!isComponentModelClass(modelClass)) {\n\t\tReflect.set(modelClass, 'component', {});\n\t}\n\n\tif (isComponentModelClass(modelClass)) {\n\t\tmodelClass.component[selector] = htmlViewClassName;\n\t}\n}\n\nexport function buildViewClassNameFromSelector(selector: string) {\n\treturn selector\n\t\t.split('-')\n\t\t.map(name => name.replace(/^\\w/, char => char.toUpperCase()))\n\t\t.join('');\n}\n\nexport function getComponentView<T extends object>(modelClass: TypeOf<T>, selector?: string): TypeOf<HTMLComponent<T>> | undefined {\n\tif (isComponentModelClass(modelClass)) {\n\t\tlet viewClassName: string;\n\t\tif (selector) {\n\t\t\tviewClassName = modelClass.component[selector];\n\t\t\tif (!viewClassName) {\n\t\t\t\tthrow new Error(`${modelClass.name} doesn't have ${selector} as view`);\n\t\t\t}\n\t\t} else {\n\t\t\tviewClassName = Object.keys(modelClass.component)[0];\n\t\t}\n\t\treturn Reflect.get(modelClass, viewClassName);\n\t}\n\treturn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IAAI,QAAQ,EAAE;YACb,aAAa,GAAG,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;YAC/C,IAAI,CAAC,aAAa,EAAE;gBACnB,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,CAAC,IAAI,iBAAiB,QAAQ,UAAU,CAAC,CAAC;aACvE;SACD;aAAM;YACN,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;SACrD;QACD,OAAO,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;KAC9C;IACD,OAAO;AACR,CAAC","sourcesContent":["import type { TypeOf } from '../utils/typeof.js';\nimport { getAllAttributes, isFormElement } from '@ibyar/elements';\nimport { ComponentRef } from '../component/component.js';\nimport { HTMLComponent } from '../component/custom-element.js';\nimport { EventEmitter, Subscription } from '../component/events.js';\nimport { ToCamelCase } from '../utils/utils.js';\nimport { Constructable } from '../providers/injector.js';\nimport { baseFactoryView } from './base-view.js';\nimport { baseFormFactoryView } from './form-view.js';\n\n/**\n * \n * @param modelClass \n * @param componentRef \n */\nexport function initCustomElementView<T extends Object>(modelClass: TypeOf<T>, componentRef: ComponentRef<T>): TypeOf<HTMLComponent<T>> {\n\tconst htmlParent = componentRef.extend.classRef as TypeOf<HTMLElement>;\n\tlet viewClass: TypeOf<HTMLComponent<T>>;\n\tconst viewClassName = buildViewClassNameFromSelector(componentRef.selector);\n\tconst htmlViewClassName = `HTML${viewClassName}Element`;\n\tconst parentClass = componentRef.extend.name\n\t\t? (isFormElement(componentRef.extend.name)\n\t\t\t? baseFormFactoryView<T>(htmlParent)\n\t\t\t: baseFactoryView<T>(htmlParent)\n\t\t)\n\t\t: baseFactoryView<T>(HTMLElement);\n\tviewClass = ({\n\t\t[htmlViewClassName]: class extends parentClass { constructor() { super(componentRef, modelClass); } }\n\t})[htmlViewClassName];\n\n\tcomponentRef.inputs.forEach((input) => {\n\t\tObject.defineProperty(viewClass.prototype, input.viewAttribute, {\n\t\t\tget(this: HTMLComponent<T>): any {\n\t\t\t\treturn this._modelScope.get(input.modelProperty);\n\t\t\t},\n\t\t\tset(this: HTMLComponent<{ [key: string]: any; }>, value: any) {\n\t\t\t\tthis._modelScope.set(input.modelProperty, value);\n\t\t\t},\n\t\t\tenumerable: true,\n\t\t});\n\t});\n\n\tcomponentRef.outputs.forEach(output => {\n\t\tObject.defineProperty(viewClass.prototype, output.viewAttribute, {\n\t\t\tget(): EventEmitter<any> {\n\t\t\t\treturn this._model[output.modelProperty];\n\t\t\t},\n\t\t\tenumerable: true\n\t\t});\n\t\tlet eventListener: Function | undefined;\n\t\tlet subscription: Subscription<any>;\n\t\tObject.defineProperty(viewClass.prototype, 'on' + ToCamelCase(output.viewAttribute), {\n\t\t\tget(): Function | undefined {\n\t\t\t\treturn eventListener;\n\t\t\t},\n\t\t\tset(this: HTMLComponent<T>, event: string | Function): void {\n\t\t\t\tif (!event) {\n\t\t\t\t\tif (subscription) {\n\t\t\t\t\t\tsubscription.unsubscribe();\n\t\t\t\t\t\teventListener = undefined;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (typeof event === 'string') {\n\t\t\t\t\tif (event.endsWith('()')) {\n\t\t\t\t\t\tevent = event.substring(0, event.length - 2);\n\t\t\t\t\t}\n\t\t\t\t\tevent = Reflect.get(window, event);\n\t\t\t\t}\n\t\t\t\teventListener = event as Function;\n\t\t\t\tsubscription = (this._model[output.modelProperty] as EventEmitter<any>).subscribe(event);\n\t\t\t},\n\t\t\tenumerable: true\n\t\t});\n\t});\n\n\tcomponentRef.inputs.map(input => input.modelProperty)\n\t\t.concat(componentRef.outputs.map(output => output.modelProperty))\n\t\t.concat(componentRef.hostBindings.map(host => host.hostPropertyName))\n\t\t.concat(componentRef.viewChild.map(child => child.modelName))\n\t\t.forEach(modelName => modelClass.prototype[modelName] = undefined);\n\n\tconst defaultAttributes = getAllAttributes(componentRef.extend.name);\n\tconst observedAttributes = componentRef.inputs.map(input => input.viewAttribute)\n\tReflect.set(viewClass, 'observedAttributes', observedAttributes);\n\tReflect.set(viewClass, 'allAttributes', defaultAttributes.concat(observedAttributes));\n\t// https://html.spec.whatwg.org/multipage/custom-elements.html#custom-elements-face-example\n\tif (false) {\n\t\tObject.defineProperty(viewClass, 'formAssociated', {\n\t\t\tget() {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t});\n\t}\n\taddViewToModelClass<T>(modelClass, componentRef.selector, viewClass, htmlViewClassName);\n\tif (!Reflect.has(window, htmlViewClassName)) {\n\t\tReflect.set(window, htmlViewClassName, viewClass);\n\t}\n\treturn viewClass;\n}\n\nexport type ComponentModelClass = Constructable & { [key: string]: string } & { component: { [key: string]: string } };\n\nexport function isComponentModelClass(target: Constructable): target is ComponentModelClass {\n\treturn Reflect.has(target, 'component');\n}\n\nexport function addViewToModelClass<T extends object>(modelClass: TypeOf<T>, selector: string, viewClass: TypeOf<HTMLComponent<T>>, htmlViewClassName: string) {\n\tObject.defineProperty(modelClass, htmlViewClassName, { value: viewClass });\n\n\tif (!isComponentModelClass(modelClass)) {\n\t\tReflect.set(modelClass, 'component', {});\n\t}\n\n\tif (isComponentModelClass(modelClass)) {\n\t\tmodelClass.component[selector] = htmlViewClassName;\n\t}\n}\n\nexport function buildViewClassNameFromSelector(selector: string) {\n\treturn selector\n\t\t.split('-')\n\t\t.map(name => name.replace(/^\\w/, char => char.toUpperCase()))\n\t\t.join('');\n}\n\nexport function getComponentView<T extends object>(modelClass: TypeOf<T>, selector?: string): TypeOf<HTMLComponent<T>> | undefined {\n\tif (isComponentModelClass(modelClass)) {\n\t\tlet viewClassName: string;\n\t\tif (selector) {\n\t\t\tviewClassName = modelClass.component[selector];\n\t\t\tif (!viewClassName) {\n\t\t\t\tthrow new Error(`${modelClass.name} doesn't have ${selector} as view`);\n\t\t\t}\n\t\t} else {\n\t\t\tviewClassName = Object.keys(modelClass.component)[0];\n\t\t}\n\t\treturn Reflect.get(modelClass, viewClassName);\n\t}\n\treturn;\n}\n"]}
|