@ibyar/core 0.4.2 → 0.5.0
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/README.md +1 -0
- package/annotation/decorators.d.ts +2 -3
- package/annotation/decorators.js.map +1 -1
- package/binding/binding.expressions.d.ts +32 -0
- package/binding/binding.expressions.js +99 -0
- package/binding/binding.expressions.js.map +1 -0
- package/component/component.d.ts +2 -2
- package/component/component.js +4 -10
- package/component/component.js.map +1 -1
- package/component/custom-element.d.ts +10 -14
- package/component/custom-element.js.map +1 -1
- package/component/provider.js +1 -1
- package/component/provider.js.map +1 -1
- package/directive/directive.d.ts +5 -10
- package/directive/directive.js +3 -9
- package/directive/directive.js.map +1 -1
- package/directive/parser.d.ts +30 -0
- package/directive/parser.js +174 -0
- package/directive/parser.js.map +1 -0
- package/html/expression.d.ts +13 -10
- package/html/expression.js +75 -20
- package/html/expression.js.map +1 -1
- package/index.d.ts +3 -1
- package/index.js +3 -1
- package/index.js.map +1 -1
- package/linker/template-ref.d.ts +18 -0
- package/linker/template-ref.js +59 -0
- package/linker/template-ref.js.map +1 -0
- package/linker/view-container-ref.d.ts +39 -0
- package/linker/view-container-ref.js +82 -0
- package/linker/view-container-ref.js.map +1 -0
- package/linker/view-ref.d.ts +36 -0
- package/linker/view-ref.js +75 -0
- package/linker/view-ref.js.map +1 -0
- package/package.json +5 -5
- package/pipe/pipe.d.ts +14 -1
- package/pipe/pipe.js +28 -1
- package/pipe/pipe.js.map +1 -1
- package/utils/elements-util.js +4 -1
- package/utils/elements-util.js.map +1 -1
- package/view/base-view.d.ts +1 -1
- package/view/base-view.js +26 -49
- package/view/base-view.js.map +1 -1
- package/view/render.d.ts +21 -19
- package/view/render.js +124 -161
- package/view/render.js.map +1 -1
- package/view/view.d.ts +1 -1
- package/view/view.js +7 -10
- package/view/view.js.map +1 -1
- package/html/update.d.ts +0 -12
- package/html/update.js +0 -24
- package/html/update.js.map +0 -1
- package/model/change-detection.d.ts +0 -13
- package/model/change-detection.js +0 -100
- package/model/change-detection.js.map +0 -1
- package/view/events.d.ts +0 -2
- package/view/events.js +0 -25
- package/view/events.js.map +0 -1
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
Aurora API is the base of this project
|
|
20
20
|
Implements Aurora's core functionality, low-level services, and utilities.
|
|
21
21
|
- Defines the class infrastructure for components, view, model change detection, rendering, and event handling.
|
|
22
|
+
- Data Binding for inputs and outputs.
|
|
22
23
|
- Defines the decorators that supply metadata.
|
|
23
24
|
- Defines infrastructure for dependency injection (DI).
|
|
24
25
|
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { TypeOf } from '../utils/typeof.js';
|
|
2
|
-
import {
|
|
2
|
+
import { DomNode, DomRenderNode } from '@ibyar/elements';
|
|
3
3
|
import { TemplateUrl } from '../utils/path.js';
|
|
4
4
|
export interface DirectiveOptions {
|
|
5
5
|
selector: string;
|
|
6
|
-
nextSiblingDirectives?: string[];
|
|
7
6
|
}
|
|
8
7
|
export interface ServiceOptions {
|
|
9
8
|
provideIn?: TypeOf<CustomElementConstructor> | 'root' | 'platform' | 'any';
|
|
@@ -15,7 +14,7 @@ export interface PipeOptions {
|
|
|
15
14
|
export interface ComponentOptions<T = Function> {
|
|
16
15
|
selector: string;
|
|
17
16
|
templateUrl?: TemplateUrl | string;
|
|
18
|
-
template?: string |
|
|
17
|
+
template?: string | DomNode | DomRenderNode<T> | Promise<string>;
|
|
19
18
|
styles?: string | {
|
|
20
19
|
[key: string]: string;
|
|
21
20
|
}[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../src/core/annotation/decorators.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,SAAS,EAAe,MAAM,kBAAkB,CAAC;AAyI1D,MAAM,UAAU,KAAK,CAAC,IAAa;IAClC,OAAO,CAAC,MA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,CAAC,CAAC;SACxC;QACD,OAAO,MAAM,CAAC;IACf,CAAC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,IAAa;IACrC,OAAO,CAAC,MAAgB,EAAE,WAAmB,EAAE,KAAa,EAAE,EAAE;QAC/D,IAAI,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QACpE,IAAI,CAAC,QAAQ,EAAE;YACd,QAAQ,GAAG,EAAE,CAAC;YACd,OAAO,CAAC,cAAc,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;SAClE;QACD,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IACxB,CAAC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,QAAQ;IACvB,OAAO,CAAC,MAAgB,EAAE,WAAmB,EAAE,KAAa,EAAE,EAAE;QAC/D,IAAI,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QACpE,IAAI,CAAC,QAAQ,EAAE;YACd,QAAQ,GAAG,EAAE,CAAC;YACd,OAAO,CAAC,cAAc,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;SAClE;QACD,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IACxB,CAAC,CAAC;AACH,CAAC","sourcesContent":["import type { TypeOf } from '../utils/typeof.js';\nimport { DOMNode, DOMRenderNode } from '@ibyar/elements';\nimport { Components } from '../component/component.js';\nimport { fetchHtml, TemplateUrl } from '../utils/path.js';\n\nexport interface DirectiveOptions {\n\tselector: string;\n\tnextSiblingDirectives?: string[];\n}\n\nexport interface ServiceOptions {\n\tprovideIn?: TypeOf<CustomElementConstructor> | 'root' | 'platform' | 'any';\n}\n\nexport interface PipeOptions {\n\tname: string;\n\tasynchronous?: boolean;\n}\n\nexport interface ComponentOptions<T = Function> {\n\t/**\n\t * a tag name for the component,\n\t * if the tag name is valid custom element name, the view class will be a custom element,\n\t * otherwise an HTMLUnknownElement will be created\n\t */\n\tselector: string;\n\n\t/**\n\t * add html file url path to fetch,\n\t * templateUrl had propriety than template, and will override it.\n\t *\n\t * Can provide file name as \"person-view.html\" will resolved \n\t * as 'http://site-address.org/persin-view.html',\n\t * \n\t * OR as an object { moduleMeta: import.meta, filename: 'person-edit.html' }\n\t * let (import.meta = '/person/person.js') will resolved \n\t * as 'http://site-address.org/person/person-edit.html',\n\t * \n\t * OR as an object { moduleMeta: import.meta }\n\t * let (import.meta = '/person/person.js') will resolved as 'http://site-address.org/person/person.html'.\n\t * \n\t * if url not found, component will not be defined,\n\t * \n\t * if you didn't use webpack or rollup.js or any bundler, \n\t * you should copy the html files to its folder by yourself. \n\t */\n\ttemplateUrl?: TemplateUrl | string;\n\t/**\n\t * template: typeof 'string' ==> html string,\n\t * \t\t\t TypeOf 'DomRootRenderNode<T>' ==> JSX, create factory\n\t * \tif template === null || undefined ==> it had nothing to render, \n\t * and may be inherit from an html element\n\t * \n\t * 2 possible way to write a template, as inline string, represent a a valid html, \n\t * or us aurora jsx factory \n\t * \t\t\t\t\n\t */\n\ttemplate?: string | DOMNode | DOMRenderNode<T> | Promise<string>;\n\t/**\n\t * style for this element\n\t */\n\tstyles?: string | { [key: string]: string }[];\n\t/**\n\t * what basic element should the new component inherit from,\n\t * the tag name to inherit from as 'a', 'div', 'table', 'td', 'th', 'tr', etc ...\n\t */\n\textend?: string;\n\n\t/**\n\t * An encapsulation policy for the template and CSS styles. One of:\n\t * 'custom': Use global CSS without any encapsulation.\n\t * 'shadow-dom': Use Shadow DOM v1 to encapsulate styles.\n\t * \n\t * 'template': like 'custom', with load the template from the document ('index.html' file)\n\t * \t \t\t\tthat had the same id as the component \"selector\".\n\t * 'shadow-dom-template': like 'shadowDom', and load template by selector id.\n\t * \n\t * Both 'template' & 'shadow-dom-template' encapsulation type:\n\t * should had attributes name like lowercase,\n\t * \tthe browser itself, will convert all attributes to lowercase\n\t * \n\t * ```typescript\n\t *\t\t@Input('personage') personAge: number;\n\t *\t\t@Input('propname') propName: string;\n\t *\t\t@Output('savebuttonclick') saveButtonClick = new EventEmitter<Persons>();\n\t *\t\t@View('personform') personForm: HTMLFormElement;\n\t * ```\n\t * \n\t * any root element as \n\t * \n\t * ```html\n\t * <root-app></root-app>\n\t * ```\n\t * \n\t * the supported bind options is 'One way binding *(as passing data only)'\n\t * and 'template parsing' and 'event binding' syntax, HTML (angular) like.\n\t * it load its attributes from 'window object'\n\t * \n\t * so to pass date to A root element, \n\t * \n\t * ```html\n\t * <script>\n\t * \tlet appVersion = '0.1.504';\n\t * \tfunction onRootAppClick() {\n\t *\t\tconsole.log('root app clicked');\n\t * \t}\n\t * \tfunction onSave(data){\n\t *\t\tconsole.log('root app save', data);\n\t * \t}\n\t * </script>\n\t * <root-app [version]=\"appVersion\" \n\t * \t\tonclick=\"onRootAppClick()\"\n\t * \t\t(save)=\"onSave()\" ></root-app>\n\t * ```\n\t * \n\t * default is 'custom'\n\t * @type {'custom' | 'shadowDom' | 'template' | 'shadowDom-template'}\n\t */\n\tencapsulation?: 'custom' | 'shadow-dom' | 'template' | 'shadow-dom-template';\n\n\t/**\n\t * default: 'open'\n\t */\n\tshadowDomMode?: ShadowRootMode;\n\n\t/**\n\t * default: false\n\t */\n\tshadowDomDelegatesFocus?: boolean;\n}\n\nexport interface ChildOptions {\n\t[key: string]: any;\n}\n\nexport interface ViewChildOpt {\n\tselector: string | typeof HTMLElement | CustomElementConstructor;\n\tchildOptions?: ChildOptions;\n}\n\nexport function Input(name?: string): Function {\n\treturn (target: Object, propertyKey: string) => {\n\t\tComponents.addInput(target, propertyKey, name || propertyKey);\n\t};\n}\nexport function Output(name?: string): Function {\n\treturn (target: Object, propertyKey: string) => {\n\t\tComponents.addOutput(target, propertyKey, name || propertyKey);\n\t};\n}\n\nexport function View(): Function {\n\treturn (target: Object, propertyKey: string) => {\n\t\tComponents.setComponentView(target, propertyKey);\n\t};\n}\n\nexport function ViewChild(selector: string | typeof HTMLElement | CustomElementConstructor,\n\tchildOptions?: ChildOptions): Function {\n\treturn (target: Object, propertyKey: string) => {\n\t\tComponents.addViewChild(target, propertyKey, selector, childOptions);\n\t};\n}\n\nexport function ViewChildren(selector: string | typeof HTMLElement | CustomElementConstructor): Function {\n\treturn (target: Object, propertyKey: string) => {\n\t\tComponents.addViewChildren(target, propertyKey, selector);\n\t};\n}\n\nexport function HostListener(eventName: string, args?: string[]): Function {\n\treturn (target: Object, propertyKey: string) => {\n\t\tComponents.addHostListener(\n\t\t\ttarget,\n\t\t\tpropertyKey,\n\t\t\teventName,\n\t\t\targs || []\n\t\t);\n\t};\n}\n\nexport function HostBinding(hostPropertyName: string): Function {\n\treturn (target: Object, propertyKey: string) => {\n\t\tComponents.addHostBinding(target, propertyKey, hostPropertyName);\n\t};\n}\n\nexport function Pipe(opt: PipeOptions): Function {\n\treturn (target: Function) => {\n\t\tComponents.definePipe(target, opt);\n\t\treturn target;\n\t};\n}\n\nexport function Service(opt: ServiceOptions): Function {\n\treturn (target: Function) => {\n\t\tComponents.defineService(target, opt);\n\t\treturn target;\n\t};\n}\nexport function Directive(opt: DirectiveOptions): Function {\n\treturn (target: Function) => {\n\t\tComponents.defineDirective(target, opt);\n\t\treturn target;\n\t};\n}\n\nexport function Component<T extends object>(opt: ComponentOptions<T>): Function {\n\treturn (target: TypeOf<T>) => {\n\t\tif (opt.templateUrl) {\n\t\t\tfetchHtml(opt.templateUrl)\n\t\t\t\t.then(htmlTemplate => {\n\t\t\t\t\tif (htmlTemplate) {\n\t\t\t\t\t\topt.template = htmlTemplate;\n\t\t\t\t\t\tComponents.defineComponent(target, opt);\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch(reason => {\n\t\t\t\t\tconsole.error(`Error @URL: ${opt.templateUrl}, for model Class: ${target.name},\\n Reason: ${reason}.`);\n\t\t\t\t});\n\t\t} else {\n\t\t\tComponents.defineComponent(target, opt);\n\t\t}\n\t\treturn target;\n\t};\n}\n\nexport function SelfSkip(name?: string): Function {\n\treturn (target: Function, propertyKey: string, index: number) => {\n\t\tlet metadata = Reflect.getMetadata('selfskip', target, propertyKey);\n\t\tif (!metadata) {\n\t\t\tmetadata = {};\n\t\t\tReflect.defineMetadata('selfskip', metadata, target, propertyKey);\n\t\t}\n\t\tmetadata[index] = name;\n\t};\n}\n\nexport function Optional(): Function {\n\treturn (target: Function, propertyKey: string, index: number) => {\n\t\tlet metadata = Reflect.getMetadata('optional', target, propertyKey);\n\t\tif (!metadata) {\n\t\t\tmetadata = {};\n\t\t\tReflect.defineMetadata('optional', metadata, target, propertyKey);\n\t\t}\n\t\tmetadata[index] = true;\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../src/core/annotation/decorators.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,SAAS,EAAe,MAAM,kBAAkB,CAAC;AAwI1D,MAAM,UAAU,KAAK,CAAC,IAAa;IAClC,OAAO,CAAC,MAAc,EAAE,WAAmB,EAAE,EAAE;QAC9C,UAAU,CAAC,QAAQ,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,IAAI,WAAW,CAAC,CAAC;IAC/D,CAAC,CAAC;AACH,CAAC;AACD,MAAM,UAAU,MAAM,CAAC,IAAa;IACnC,OAAO,CAAC,MAAc,EAAE,WAAmB,EAAE,EAAE;QAC9C,UAAU,CAAC,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,IAAI,WAAW,CAAC,CAAC;IAChE,CAAC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,IAAI;IACnB,OAAO,CAAC,MAAc,EAAE,WAAmB,EAAE,EAAE;QAC9C,UAAU,CAAC,gBAAgB,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAClD,CAAC,CAAC;AACH,CAAC;AAED,MAA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B,OAAO,CAAC,MAAgB,EAAE,WAAmB,EAAE,KAAa,EAAE,EAAE;QAC/D,IAAI,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QACpE,IAAI,CAAC,QAAQ,EAAE;YACd,QAAQ,GAAG,EAAE,CAAC;YACd,OAAO,CAAC,cAAc,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;SAClE;QACD,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IACxB,CAAC,CAAC;AACH,CAAC","sourcesContent":["import type { TypeOf } from '../utils/typeof.js';\nimport { DomNode, DomRenderNode } from '@ibyar/elements';\nimport { Components } from '../component/component.js';\nimport { fetchHtml, TemplateUrl } from '../utils/path.js';\n\nexport interface DirectiveOptions {\n\tselector: string;\n}\n\nexport interface ServiceOptions {\n\tprovideIn?: TypeOf<CustomElementConstructor> | 'root' | 'platform' | 'any';\n}\n\nexport interface PipeOptions {\n\tname: string;\n\tasynchronous?: boolean;\n}\n\nexport interface ComponentOptions<T = Function> {\n\t/**\n\t * a tag name for the component,\n\t * if the tag name is valid custom element name, the view class will be a custom element,\n\t * otherwise an HTMLUnknownElement will be created\n\t */\n\tselector: string;\n\n\t/**\n\t * add html file url path to fetch,\n\t * templateUrl had propriety than template, and will override it.\n\t *\n\t * Can provide file name as \"person-view.html\" will resolved \n\t * as 'http://site-address.org/persin-view.html',\n\t * \n\t * OR as an object { moduleMeta: import.meta, filename: 'person-edit.html' }\n\t * let (import.meta = '/person/person.js') will resolved \n\t * as 'http://site-address.org/person/person-edit.html',\n\t * \n\t * OR as an object { moduleMeta: import.meta }\n\t * let (import.meta = '/person/person.js') will resolved as 'http://site-address.org/person/person.html'.\n\t * \n\t * if url not found, component will not be defined,\n\t * \n\t * if you didn't use webpack or rollup.js or any bundler, \n\t * you should copy the html files to its folder by yourself. \n\t */\n\ttemplateUrl?: TemplateUrl | string;\n\t/**\n\t * template: typeof 'string' ==> html string,\n\t * \t\t\t TypeOf 'DomRootRenderNode<T>' ==> JSX, create factory\n\t * \tif template === null || undefined ==> it had nothing to render, \n\t * and may be inherit from an html element\n\t * \n\t * 2 possible way to write a template, as inline string, represent a a valid html, \n\t * or us aurora jsx factory \n\t * \t\t\t\t\n\t */\n\ttemplate?: string | DomNode | DomRenderNode<T> | Promise<string>;\n\t/**\n\t * style for this element\n\t */\n\tstyles?: string | { [key: string]: string }[];\n\t/**\n\t * what basic element should the new component inherit from,\n\t * the tag name to inherit from as 'a', 'div', 'table', 'td', 'th', 'tr', etc ...\n\t */\n\textend?: string;\n\n\t/**\n\t * An encapsulation policy for the template and CSS styles. One of:\n\t * 'custom': Use global CSS without any encapsulation.\n\t * 'shadow-dom': Use Shadow DOM v1 to encapsulate styles.\n\t * \n\t * 'template': like 'custom', with load the template from the document ('index.html' file)\n\t * \t \t\t\tthat had the same id as the component \"selector\".\n\t * 'shadow-dom-template': like 'shadowDom', and load template by selector id.\n\t * \n\t * Both 'template' & 'shadow-dom-template' encapsulation type:\n\t * should had attributes name like lowercase,\n\t * \tthe browser itself, will convert all attributes to lowercase\n\t * \n\t * ```typescript\n\t *\t\t@Input('personage') personAge: number;\n\t *\t\t@Input('propname') propName: string;\n\t *\t\t@Output('savebuttonclick') saveButtonClick = new EventEmitter<Persons>();\n\t *\t\t@View('personform') personForm: HTMLFormElement;\n\t * ```\n\t * \n\t * any root element as \n\t * \n\t * ```html\n\t * <root-app></root-app>\n\t * ```\n\t * \n\t * the supported bind options is 'One way binding *(as passing data only)'\n\t * and 'template parsing' and 'event binding' syntax, HTML (angular) like.\n\t * it load its attributes from 'window object'\n\t * \n\t * so to pass date to A root element, \n\t * \n\t * ```html\n\t * <script>\n\t * \tlet appVersion = '0.1.504';\n\t * \tfunction onRootAppClick() {\n\t *\t\tconsole.log('root app clicked');\n\t * \t}\n\t * \tfunction onSave(data){\n\t *\t\tconsole.log('root app save', data);\n\t * \t}\n\t * </script>\n\t * <root-app [version]=\"appVersion\" \n\t * \t\tonclick=\"onRootAppClick()\"\n\t * \t\t(save)=\"onSave()\" ></root-app>\n\t * ```\n\t * \n\t * default is 'custom'\n\t * @type {'custom' | 'shadowDom' | 'template' | 'shadowDom-template'}\n\t */\n\tencapsulation?: 'custom' | 'shadow-dom' | 'template' | 'shadow-dom-template';\n\n\t/**\n\t * default: 'open'\n\t */\n\tshadowDomMode?: ShadowRootMode;\n\n\t/**\n\t * default: false\n\t */\n\tshadowDomDelegatesFocus?: boolean;\n}\n\nexport interface ChildOptions {\n\t[key: string]: any;\n}\n\nexport interface ViewChildOpt {\n\tselector: string | typeof HTMLElement | CustomElementConstructor;\n\tchildOptions?: ChildOptions;\n}\n\nexport function Input(name?: string): Function {\n\treturn (target: Object, propertyKey: string) => {\n\t\tComponents.addInput(target, propertyKey, name || propertyKey);\n\t};\n}\nexport function Output(name?: string): Function {\n\treturn (target: Object, propertyKey: string) => {\n\t\tComponents.addOutput(target, propertyKey, name || propertyKey);\n\t};\n}\n\nexport function View(): Function {\n\treturn (target: Object, propertyKey: string) => {\n\t\tComponents.setComponentView(target, propertyKey);\n\t};\n}\n\nexport function ViewChild(selector: string | typeof HTMLElement | CustomElementConstructor,\n\tchildOptions?: ChildOptions): Function {\n\treturn (target: Object, propertyKey: string) => {\n\t\tComponents.addViewChild(target, propertyKey, selector, childOptions);\n\t};\n}\n\nexport function ViewChildren(selector: string | typeof HTMLElement | CustomElementConstructor): Function {\n\treturn (target: Object, propertyKey: string) => {\n\t\tComponents.addViewChildren(target, propertyKey, selector);\n\t};\n}\n\nexport function HostListener(eventName: string, args?: string[]): Function {\n\treturn (target: Object, propertyKey: string) => {\n\t\tComponents.addHostListener(\n\t\t\ttarget,\n\t\t\tpropertyKey,\n\t\t\teventName,\n\t\t\targs || []\n\t\t);\n\t};\n}\n\nexport function HostBinding(hostPropertyName: string): Function {\n\treturn (target: Object, propertyKey: string) => {\n\t\tComponents.addHostBinding(target, propertyKey, hostPropertyName);\n\t};\n}\n\nexport function Pipe(opt: PipeOptions): Function {\n\treturn (target: Function) => {\n\t\tComponents.definePipe(target, opt);\n\t\treturn target;\n\t};\n}\n\nexport function Service(opt: ServiceOptions): Function {\n\treturn (target: Function) => {\n\t\tComponents.defineService(target, opt);\n\t\treturn target;\n\t};\n}\nexport function Directive(opt: DirectiveOptions): Function {\n\treturn (target: Function) => {\n\t\tComponents.defineDirective(target, opt);\n\t\treturn target;\n\t};\n}\n\nexport function Component<T extends object>(opt: ComponentOptions<T>): Function {\n\treturn (target: TypeOf<T>) => {\n\t\tif (opt.templateUrl) {\n\t\t\tfetchHtml(opt.templateUrl)\n\t\t\t\t.then(htmlTemplate => {\n\t\t\t\t\tif (htmlTemplate) {\n\t\t\t\t\t\topt.template = htmlTemplate;\n\t\t\t\t\t\tComponents.defineComponent(target, opt);\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch(reason => {\n\t\t\t\t\tconsole.error(`Error @URL: ${opt.templateUrl}, for model Class: ${target.name},\\n Reason: ${reason}.`);\n\t\t\t\t});\n\t\t} else {\n\t\t\tComponents.defineComponent(target, opt);\n\t\t}\n\t\treturn target;\n\t};\n}\n\nexport function SelfSkip(name?: string): Function {\n\treturn (target: Function, propertyKey: string, index: number) => {\n\t\tlet metadata = Reflect.getMetadata('selfskip', target, propertyKey);\n\t\tif (!metadata) {\n\t\t\tmetadata = {};\n\t\t\tReflect.defineMetadata('selfskip', metadata, target, propertyKey);\n\t\t}\n\t\tmetadata[index] = name;\n\t};\n}\n\nexport function Optional(): Function {\n\treturn (target: Function, propertyKey: string, index: number) => {\n\t\tlet metadata = Reflect.getMetadata('optional', target, propertyKey);\n\t\tif (!metadata) {\n\t\t\tmetadata = {};\n\t\t\tReflect.defineMetadata('optional', metadata, target, propertyKey);\n\t\t}\n\t\tmetadata[index] = true;\n\t};\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ExpressionNode, InfixExpressionNode, ScopeSubscription, Stack, ScopeContext, MemberExpression, Identifier } from '@ibyar/expressions';
|
|
2
|
+
declare type OneWayOperator = ':=';
|
|
3
|
+
declare type TwoWayOperator = ':=:';
|
|
4
|
+
declare type BindingOperators = OneWayOperator | TwoWayOperator;
|
|
5
|
+
export interface BindingAssignment extends InfixExpressionNode<BindingOperators> {
|
|
6
|
+
subscribe(stack: Stack, pipelineNames?: string[]): ScopeSubscription<ScopeContext>[];
|
|
7
|
+
}
|
|
8
|
+
export declare class OneWayAssignmentExpression extends InfixExpressionNode<OneWayOperator> implements BindingAssignment {
|
|
9
|
+
private rightEvents;
|
|
10
|
+
constructor(left: MemberExpression, right: ExpressionNode);
|
|
11
|
+
set(stack: Stack, value: any): any;
|
|
12
|
+
get(stack: Stack): any;
|
|
13
|
+
subscribe(stack: Stack, pipelineNames?: string[]): ScopeSubscription<ScopeContext>[];
|
|
14
|
+
}
|
|
15
|
+
export declare class TwoWayAssignmentExpression extends InfixExpressionNode<TwoWayOperator> implements BindingAssignment {
|
|
16
|
+
protected left: MemberExpression;
|
|
17
|
+
protected right: MemberExpression | Identifier;
|
|
18
|
+
private rightEvents;
|
|
19
|
+
private leftEvents;
|
|
20
|
+
constructor(left: MemberExpression, right: MemberExpression | Identifier);
|
|
21
|
+
set(stack: Stack, value: any): any;
|
|
22
|
+
get(stack: Stack): any;
|
|
23
|
+
private setRTL;
|
|
24
|
+
private getRTL;
|
|
25
|
+
private actionRTL;
|
|
26
|
+
private setLTR;
|
|
27
|
+
private getLTR;
|
|
28
|
+
private actionLTR;
|
|
29
|
+
private subscribeToEvents;
|
|
30
|
+
subscribe(stack: Stack): ScopeSubscription<ScopeContext>[];
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { InfixExpressionNode, findScopeByEventMap, ReactiveScope } from '@ibyar/expressions';
|
|
2
|
+
import { AsyncPipeProvider, AsyncPipeScope } from '../pipe/pipe.js';
|
|
3
|
+
export class OneWayAssignmentExpression extends InfixExpressionNode {
|
|
4
|
+
constructor(left, right) {
|
|
5
|
+
super(':=', left, right);
|
|
6
|
+
this.rightEvents = this.right.events();
|
|
7
|
+
}
|
|
8
|
+
set(stack, value) {
|
|
9
|
+
return this.left.set(stack, value);
|
|
10
|
+
}
|
|
11
|
+
get(stack) {
|
|
12
|
+
const rv = this.right.get(stack);
|
|
13
|
+
this.set(stack, rv);
|
|
14
|
+
return rv;
|
|
15
|
+
}
|
|
16
|
+
subscribe(stack, pipelineNames) {
|
|
17
|
+
if (pipelineNames?.length) {
|
|
18
|
+
const asyncPipeScope = new AsyncPipeScope();
|
|
19
|
+
pipelineNames.forEach(pipeline => {
|
|
20
|
+
const scope = stack.findScope(pipeline);
|
|
21
|
+
if (scope instanceof AsyncPipeProvider) {
|
|
22
|
+
const pipe = scope.get(pipeline);
|
|
23
|
+
asyncPipeScope.set(pipeline, pipe);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
stack.pushScope(asyncPipeScope);
|
|
27
|
+
}
|
|
28
|
+
const map = findScopeByEventMap(this.rightEvents, stack);
|
|
29
|
+
const subscriptions = [];
|
|
30
|
+
map.forEach((scope, eventName) => {
|
|
31
|
+
if (scope instanceof ReactiveScope) {
|
|
32
|
+
const subscription = scope.subscribe(eventName, (newValue, oldValue) => {
|
|
33
|
+
this.get(stack);
|
|
34
|
+
});
|
|
35
|
+
subscriptions.push(subscription);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return subscriptions;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export class TwoWayAssignmentExpression extends InfixExpressionNode {
|
|
42
|
+
constructor(left, right) {
|
|
43
|
+
super(':=:', left, right);
|
|
44
|
+
this.rightEvents = this.right.events();
|
|
45
|
+
this.leftEvents = this.left.events();
|
|
46
|
+
}
|
|
47
|
+
set(stack, value) {
|
|
48
|
+
return this.setRTL(stack, value);
|
|
49
|
+
}
|
|
50
|
+
get(stack) {
|
|
51
|
+
return this.getRTL(stack);
|
|
52
|
+
}
|
|
53
|
+
setRTL(stack, value) {
|
|
54
|
+
return this.left.set(stack, value);
|
|
55
|
+
}
|
|
56
|
+
getRTL(stack) {
|
|
57
|
+
const rv = this.right.get(stack);
|
|
58
|
+
this.setRTL(stack, rv);
|
|
59
|
+
return rv;
|
|
60
|
+
}
|
|
61
|
+
actionRTL(stack) {
|
|
62
|
+
return (newValue, oldValue) => {
|
|
63
|
+
this.getRTL(stack);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
setLTR(stack, value) {
|
|
67
|
+
return this.right.set(stack, value);
|
|
68
|
+
}
|
|
69
|
+
getLTR(stack) {
|
|
70
|
+
const lv = this.left.get(stack);
|
|
71
|
+
this.setLTR(stack, lv);
|
|
72
|
+
return lv;
|
|
73
|
+
}
|
|
74
|
+
actionLTR(stack) {
|
|
75
|
+
return (newValue, oldValue) => {
|
|
76
|
+
this.getLTR(stack);
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
subscribeToEvents(stack, map, actionCallback) {
|
|
80
|
+
const subscriptions = [];
|
|
81
|
+
map.forEach((scope, eventName) => {
|
|
82
|
+
if (scope instanceof ReactiveScope) {
|
|
83
|
+
const subscription = scope.subscribe(eventName, actionCallback);
|
|
84
|
+
subscriptions.push(subscription);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
return subscriptions;
|
|
88
|
+
}
|
|
89
|
+
subscribe(stack) {
|
|
90
|
+
const rightMap = findScopeByEventMap(this.rightEvents, stack);
|
|
91
|
+
const rtlAction = this.actionRTL(stack);
|
|
92
|
+
const rtlSubscriptions = this.subscribeToEvents(stack, rightMap, rtlAction);
|
|
93
|
+
const leftMap = findScopeByEventMap(this.leftEvents, stack);
|
|
94
|
+
const ltrAction = this.actionLTR(stack);
|
|
95
|
+
const ltrSubscriptions = this.subscribeToEvents(stack, leftMap, ltrAction);
|
|
96
|
+
return rtlSubscriptions.concat(ltrSubscriptions);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=binding.expressions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binding.expressions.js","sourceRoot":"","sources":["../../../src/core/binding/binding.expressions.ts"],"names":[],"mappings":"AAAA,OAAO,EACU,mBAAmB,EAC5B,mBAAmB,EAAE,aAAa,EAGzC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAWpE,MAAM,OAAO,0BAA2B,SAAQ,mBAAmC;IAGlF,YAAY,IAAsB,EAAE,KAAqB;QACxD,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QAFlB,gBAAW,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;IAG1C,CAAC;IACD,GAAG,CAAC,KAAY,EAAE,KAAU;QAC3B,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;IACD,GAAG,CAAC,KAAY;QACf,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACjC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACpB,OAAO,EAAE,CAAC;IACX,CAAC;IACD,SAAS,CAAC,KAAY,EAAE,aAAwB;QAC/C,IAAI,aAAa,EAAE,MAAM,EAAE;YAC1B,MAAM,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC;YAC5C,aAAa,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;gBAChC,MAAM,KAAK,GAAG,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;gBACxC,IAAI,KAAK,YAAY,iBAAiB,EAAE;oBACvC,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAE,CAAC;oBAClC,cAAc,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,C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mB,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;QAC9D,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACxC,MAAM,gBAAgB,GAAG,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;QAG5E,MAAM,OAAO,GAAG,mBAAmB,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QAC5D,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACxC,MAAM,gBAAgB,GAAG,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;QAE3E,OAAO,gBAAgB,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAClD,CAAC;CAED","sourcesContent":["import {\n\tExpressionNode, InfixExpressionNode, ScopeSubscription,\n\tStack, findScopeByEventMap, ReactiveScope,\n\tScopeContext, ValueChangedCallback, Scope,\n\tMemberExpression, Identifier\n} from '@ibyar/expressions';\nimport { AsyncPipeProvider, AsyncPipeScope } from '../pipe/pipe.js';\n\ntype OneWayOperator = ':=';\ntype TwoWayOperator = ':=:';\ntype BindingOperators = OneWayOperator | TwoWayOperator;\n\nexport interface BindingAssignment extends InfixExpressionNode<BindingOperators> {\n\tsubscribe(stack: Stack, pipelineNames?: string[]): ScopeSubscription<ScopeContext>[];\n}\n\n\nexport class OneWayAssignmentExpression extends InfixExpressionNode<OneWayOperator> implements BindingAssignment {\n\n\tprivate rightEvents = this.right.events();\n\tconstructor(left: MemberExpression, right: ExpressionNode) {\n\t\tsuper(':=', left, right);\n\t}\n\tset(stack: Stack, value: any) {\n\t\treturn this.left.set(stack, value);\n\t}\n\tget(stack: Stack): any {\n\t\tconst rv = this.right.get(stack);\n\t\tthis.set(stack, rv);\n\t\treturn rv;\n\t}\n\tsubscribe(stack: Stack, pipelineNames?: string[]): ScopeSubscription<ScopeContext>[] {\n\t\tif (pipelineNames?.length) {\n\t\t\tconst asyncPipeScope = new AsyncPipeScope();\n\t\t\tpipelineNames.forEach(pipeline => {\n\t\t\t\tconst scope = stack.findScope(pipeline);\n\t\t\t\tif (scope instanceof AsyncPipeProvider) {\n\t\t\t\t\tconst pipe = scope.get(pipeline)!;\n\t\t\t\t\tasyncPipeScope.set(pipeline, pipe);\n\t\t\t\t}\n\t\t\t});\n\t\t\tstack.pushScope(asyncPipeScope);\n\t\t}\n\t\tconst map = findScopeByEventMap(this.rightEvents, stack);\n\t\tconst subscriptions: ScopeSubscription<ScopeContext>[] = [];\n\t\tmap.forEach((scope, eventName) => {\n\t\t\tif (scope instanceof ReactiveScope) {\n\t\t\t\tconst subscription = scope.subscribe(eventName, (newValue: any, oldValue?: any) => {\n\t\t\t\t\tthis.get(stack);\n\t\t\t\t});\n\t\t\t\tsubscriptions.push(subscription);\n\t\t\t}\n\t\t});\n\t\treturn subscriptions;\n\t}\n}\n\n\n/**\n * the default behavior is assign the right hand side to the left hand side.\n * \n * \n */\nexport class TwoWayAssignmentExpression extends InfixExpressionNode<TwoWayOperator> implements BindingAssignment {\n\n\tprotected left: MemberExpression;\n\tprotected right: MemberExpression | Identifier;\n\n\tprivate rightEvents = this.right.events();\n\tprivate leftEvents = this.left.events();\n\tconstructor(left: MemberExpression, right: MemberExpression | Identifier) {\n\t\tsuper(':=:', left, right);\n\t}\n\n\tset(stack: Stack, value: any) {\n\t\treturn this.setRTL(stack, value);\n\t}\n\tget(stack: Stack): any {\n\t\treturn this.getRTL(stack);\n\t}\n\n\tprivate setRTL(stack: Stack, value: any) {\n\t\treturn this.left.set(stack, value);\n\t}\n\tprivate getRTL(stack: Stack): any {\n\t\tconst rv = this.right.get(stack);\n\t\tthis.setRTL(stack, rv);\n\t\treturn rv;\n\t}\n\tprivate actionRTL(stack: Stack): ValueChangedCallback {\n\t\treturn (newValue: any, oldValue?: any) => {\n\t\t\tthis.getRTL(stack);\n\t\t};\n\t}\n\n\tprivate setLTR(stack: Stack, value: any) {\n\t\treturn this.right.set(stack, value);\n\t}\n\tprivate getLTR(stack: Stack): any {\n\t\tconst lv = this.left.get(stack);\n\t\tthis.setLTR(stack, lv);\n\t\treturn lv;\n\t}\n\tprivate actionLTR(stack: Stack): ValueChangedCallback {\n\t\treturn (newValue: any, oldValue?: any) => {\n\t\t\tthis.getLTR(stack);\n\t\t};\n\t}\n\n\tprivate subscribeToEvents(stack: Stack, map: Map<string, Scope<ScopeContext>>, actionCallback: ValueChangedCallback) {\n\t\tconst subscriptions: ScopeSubscription<ScopeContext>[] = [];\n\t\tmap.forEach((scope, eventName) => {\n\t\t\tif (scope instanceof ReactiveScope) {\n\t\t\t\tconst subscription = scope.subscribe(eventName, actionCallback);\n\t\t\t\tsubscriptions.push(subscription);\n\t\t\t}\n\t\t});\n\t\treturn subscriptions;\n\t}\n\n\tsubscribe(stack: Stack): ScopeSubscription<ScopeContext>[] {\n\n\t\t// right to left\n\t\tconst rightMap = findScopeByEventMap(this.rightEvents, stack);\n\t\tconst rtlAction = this.actionRTL(stack);\n\t\tconst rtlSubscriptions = this.subscribeToEvents(stack, rightMap, rtlAction);\n\n\t\t// left to right \n\t\tconst leftMap = findScopeByEventMap(this.leftEvents, stack);\n\t\tconst ltrAction = this.actionLTR(stack);\n\t\tconst ltrSubscriptions = this.subscribeToEvents(stack, leftMap, ltrAction);\n\n\t\treturn rtlSubscriptions.concat(ltrSubscriptions);\n\t}\n\n}\n"]}
|
package/component/component.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TypeOf } from '../utils/typeof.js';
|
|
2
|
-
import { Tag,
|
|
2
|
+
import { Tag, DomNode, DomRenderNode } from '@ibyar/elements';
|
|
3
3
|
import { HTMLComponent } from './custom-element.js';
|
|
4
4
|
import { AttributeDirective, StructuralDirective } from '../directive/directive.js';
|
|
5
5
|
import { ComponentOptions, ChildOptions, PipeOptions, ServiceOptions, DirectiveOptions } from '../annotation/decorators.js';
|
|
@@ -58,7 +58,7 @@ export interface DirectiveRef<T> {
|
|
|
58
58
|
}
|
|
59
59
|
export interface ComponentRef<T> {
|
|
60
60
|
selector: string;
|
|
61
|
-
template:
|
|
61
|
+
template: DomNode | DomRenderNode<T>;
|
|
62
62
|
styles: string;
|
|
63
63
|
extend: Tag;
|
|
64
64
|
viewClass: TypeOf<HTMLComponent<T>> & CustomElementConstructor;
|
package/component/component.js
CHANGED
|
@@ -94,16 +94,10 @@ export class Components {
|
|
|
94
94
|
}
|
|
95
95
|
bootstrap.modelClass = modelClass;
|
|
96
96
|
ClassRegistryProvider.registerDirective(modelClass);
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
bootstrap.
|
|
100
|
-
|
|
101
|
-
const structuralDirectiveName = opts.selector.substring(1);
|
|
102
|
-
directiveRegistry.register(structuralDirectiveName, {
|
|
103
|
-
attributes,
|
|
104
|
-
nextSiblingDirectives: opts.nextSiblingDirectives,
|
|
105
|
-
});
|
|
106
|
-
}
|
|
97
|
+
directiveRegistry.register(opts.selector, {
|
|
98
|
+
inputs: bootstrap.inputs?.map(input => input.viewAttribute),
|
|
99
|
+
outputs: bootstrap.outputs?.map(output => output.viewAttribute),
|
|
100
|
+
});
|
|
107
101
|
}
|
|
108
102
|
static definePipe(modelClass, opts) {
|
|
109
103
|
const bootstrap = Components.getOrCreateBootstrap(modelClass.prototype);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../../src/core/component/component.ts"],"names":[],"mappings":"AACA,OAAO,EACN,aAAa,EAAO,UAAU,EAAE,cAAc,EACtB,eAAe,EAAE,iBAAiB,EAC1D,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAM7D,MAAM,OA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qBAAqB,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;QACzE,UAAU,CAAC,eAAe,CAAC,YAAY,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;QAClE,UAAU,CAAC,eAAe,CAAC,YAAY,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;QAEjE,qBAAqB,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;QACpD,qBAAqB,CAAC,YAAY,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAExD,MAAM,OAAO,GAA6B,EAAE,CAAC;QAC7C,MAAM,aAAa,GAAG,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC;QAChD,IAAI,aAAa,EAAE;YAClB,IAAI,aAAa,KAAK,GAAG,IAAI,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE;gBAC/D,OAAO,CAAC,OAAO,GAAG,aAAa,CAAC;aAChC;SACD;QAGD,cAAc,CAAC,MAAM,CACpB,YAAY,CAAC,QAAkB,EAC/B,YAAY,CAAC,SAAqC,EAClD,OAAO,CACP,CAAC;IAEH,CAAC;CACD","sourcesContent":["import type { TypeOf } from '../utils/typeof.js';\nimport {\n\tfindByTagName, Tag, htmlParser, templateParser,\n\tDOMNode, DOMRenderNode, canAttachShadow, directiveRegistry\n} from '@ibyar/elements';\n\nimport { HTMLComponent } from './custom-element.js';\nimport { ClassRegistryProvider } from '../providers/provider.js';\nimport { AttributeDirective, StructuralDirective } from '../directive/directive.js';\nimport { initCustomElementView } from '../view/view.js';\nimport { buildExpressionNodes } from '../html/expression.js';\nimport {\n\tComponentOptions, ChildOptions, PipeOptions,\n\tServiceOptions, DirectiveOptions\n} from '../annotation/decorators.js';\n\nexport class PropertyRef {\n\tconstructor(public modelProperty: string, private _viewName?: string) { }\n\tget viewAttribute(): string {\n\t\treturn this._viewName || this.modelProperty;\n\t}\n}\n\nexport class ChildRef {\n\tconstructor(\n\t\tpublic modelName: string,\n\t\tpublic selector: string | { new(): HTMLElement; prototype: HTMLElement } | CustomElementConstructor,\n\t\tpublic childOptions?: ChildOptions\n\t) { }\n}\n\nexport class ListenerRef {\n\tconstructor(public eventName: string, public args: string[], public modelCallbackName: string) { }\n}\n\nexport class HostBindingRef {\n\tconstructor(public viewProperty: string, public hostPropertyName: string) { }\n}\n\nexport interface BootstrapMetadata {\n\t[key: string]: any;\n}\n\nexport interface ServiceRef<T> {\n\tprovideIn: TypeOf<CustomElementConstructor> | 'root' | 'platform' | 'any';\n\tmodelClass: TypeOf<T>;\n\tname: string;\n}\n\nexport interface PipeRef<T> {\n\tname: string;\n\tasynchronous?: boolean;\n\tmodelClass: TypeOf<T>;\n}\nexport interface DirectiveRef<T> {\n\tselector: string;\n\n\tmodelClass: TypeOf<StructuralDirective> | TypeOf<AttributeDirective>;\n\n\tinputs: PropertyRef[];\n\toutputs: PropertyRef[];\n\tview: string;\n\tviewChild: ChildRef[];\n\tViewChildren: ChildRef[];\n\thostListeners: ListenerRef[];\n\thostBindings: HostBindingRef[];\n}\n\nexport interface ComponentRef<T> {\n\tselector: string;\n\ttemplate: DOMNode | DOMRenderNode<T>;\n\t// attrTemplate: JsxAttrComponent;\n\tstyles: string;\n\textend: Tag;\n\n\tviewClass: TypeOf<HTMLComponent<T>> & CustomElementConstructor;\n\tmodelClass: TypeOf<T>;\n\n\tinputs: PropertyRef[];\n\toutputs: PropertyRef[];\n\tview: string;\n\tviewChild: ChildRef[];\n\tViewChildren: ChildRef[];\n\thostBindings: HostBindingRef[];\n\thostListeners: ListenerRef[];\n\n\tencapsulation: 'custom' | 'shadow-dom' | 'template' | 'shadow-dom-template';\n\tisShadowDom: boolean;\n\tshadowDomMode: ShadowRootMode;\n\tshadowDomDelegatesFocus: boolean;\n}\n\nconst AuroraBootstrap = Symbol.for('aurora:bootstrap');\nconst AuroraMetadata = Symbol.for('aurora:metadata');\n\nexport class Components {\n\n\tstatic getOrCreateBootstrap<T extends {}>(target: Object): T {\n\t\tlet bootstrap: T = Reflect.getMetadata(AuroraBootstrap, target);\n\t\tif (!bootstrap) {\n\t\t\tbootstrap = {} as T;\n\t\t\tReflect.defineMetadata(AuroraBootstrap, bootstrap, target);\n\t\t}\n\t\treturn bootstrap;\n\t}\n\n\tstatic getBootstrap<T extends {}>(target: Object): T {\n\t\treturn Reflect.getMetadata(AuroraBootstrap, target);\n\t}\n\n\tstatic getComponentRef<T>(target: object): ComponentRef<T> {\n\t\treturn Reflect.getMetadata(AuroraMetadata, target);\n\t}\n\n\tstatic setComponentRef<T>(target: object, componentRef: ComponentRef<T>): void {\n\t\tReflect.defineMetadata(AuroraMetadata, componentRef, target);\n\t}\n\n\tstatic addOptional(modelProperty: Object) {\n\t}\n\n\tstatic addInput(modelProperty: Object, modelName: string, viewName: string) {\n\t\tconst bootstrap: BootstrapMetadata = Components.getOrCreateBootstrap(modelProperty);\n\t\tbootstrap.inputs = bootstrap.inputs || [];\n\t\tbootstrap.inputs.push(new PropertyRef(modelName, viewName));\n\t}\n\n\tstatic addOutput(modelProperty: Object, modelName: string, viewName: string) {\n\t\tconst bootstrap: BootstrapMetadata = Components.getOrCreateBootstrap(modelProperty);\n\t\tbootstrap.outputs = bootstrap.outputs || [];\n\t\tbootstrap.outputs.push(new PropertyRef(modelName, viewName));\n\t}\n\n\tstatic setComponentView(modelProperty: Object, modelName: string) {\n\t\tconst bootstrap: BootstrapMetadata = Components.getOrCreateBootstrap(modelProperty);\n\t\tbootstrap.view = modelName;\n\t}\n\n\tstatic addViewChild(modelProperty: Object, modelName: string, selector: string | typeof HTMLElement | CustomElementConstructor, childOptions?: ChildOptions) {\n\t\tconst bootstrap: BootstrapMetadata = Components.getOrCreateBootstrap(modelProperty);\n\t\tbootstrap.viewChild = bootstrap.viewChild || [];\n\t\tbootstrap.viewChild.push(new ChildRef(modelName, selector, childOptions));\n\t}\n\n\tstatic addViewChildren(modelProperty: Object, modelName: string, selector: string | typeof HTMLElement | CustomElementConstructor) {\n\t\tconst bootstrap: BootstrapMetadata = Components.getOrCreateBootstrap(modelProperty);\n\t\tbootstrap.ViewChildren = bootstrap.ViewChildren || [];\n\t\tbootstrap.ViewChildren.push(new ChildRef(modelName, selector));\n\t}\n\n\tstatic addHostListener(modelProperty: Object, propertyKey: string, eventName: string, args: string[]) {\n\t\tconst bootstrap: BootstrapMetadata = Components.getOrCreateBootstrap(modelProperty);\n\t\tbootstrap.hostListeners = bootstrap.hostListeners || [];\n\t\tbootstrap.hostListeners.push(new ListenerRef(eventName, args, propertyKey));\n\t}\n\n\tstatic addHostBinding(modelProperty: Object, propertyKey: string, hostPropertyName: string) {\n\t\tconst bootstrap: BootstrapMetadata = Components.getOrCreateBootstrap(modelProperty);\n\t\tbootstrap.hostBinding = bootstrap.hostBinding || [];\n\t\tbootstrap.hostBinding.push(\n\t\t\tnew HostBindingRef(propertyKey, hostPropertyName)\n\t\t);\n\t}\n\n\tstatic defineDirective(modelClass: Function, opts: DirectiveOptions) {\n\t\tconst bootstrap: BootstrapMetadata = Components.getOrCreateBootstrap(modelClass.prototype);\n\t\tfor (const key in opts) {\n\t\t\tbootstrap[key] = Reflect.get(opts, key);\n\t\t}\n\t\tbootstrap.modelClass = modelClass;\n\t\tClassRegistryProvider.registerDirective(modelClass);\n\t\tif (opts.selector.startsWith('*')) {\n\t\t\tconst attributes: string[] = [];\n\t\t\t(bootstrap.inputs as PropertyRef[])?.forEach(input => attributes.push(input.viewAttribute));\n\t\t\t(bootstrap.outputs as PropertyRef[])?.forEach(output => attributes.push(output.viewAttribute));\n\t\t\tconst structuralDirectiveName = opts.selector.substring(1);\n\t\t\tdirectiveRegistry.register(structuralDirectiveName, {\n\t\t\t\tattributes,\n\t\t\t\tnextSiblingDirectives: opts.nextSiblingDirectives,\n\t\t\t});\n\t\t}\n\t}\n\n\tstatic definePipe(modelClass: Function, opts: PipeOptions) {\n\t\tconst bootstrap: BootstrapMetadata = Components.getOrCreateBootstrap(modelClass.prototype);\n\t\tfor (const key in opts) {\n\t\t\tbootstrap[key] = Reflect.get(opts, key);\n\t\t}\n\t\tbootstrap.modelClass = modelClass;\n\t\tClassRegistryProvider.registerPipe(modelClass);\n\t}\n\n\tstatic defineService(modelClass: Function, opts: ServiceOptions) {\n\t\tconst bootstrap: BootstrapMetadata = Components.getOrCreateBootstrap(modelClass.prototype);\n\t\tfor (const key in opts) {\n\t\t\tbootstrap[key] = Reflect.get(opts, key);\n\t\t}\n\t\tbootstrap.modelClass = modelClass;\n\t\tbootstrap.name = modelClass.name;\n\t\tClassRegistryProvider.registerService(modelClass);\n\t}\n\n\tstatic defineComponent<T extends Object>(modelClass: TypeOf<T>, opts: ComponentOptions<T>) {\n\t\tconst bootstrap: BootstrapMetadata = Components.getOrCreateBootstrap(modelClass.prototype);\n\n\t\tvar componentRef: ComponentRef<T> = opts as unknown as ComponentRef<T>;\n\t\tfor (const key in bootstrap) {\n\t\t\tReflect.set(componentRef, key, bootstrap[key]);\n\t\t}\n\t\tcomponentRef.extend = findByTagName(opts.extend);\n\n\t\tif (typeof componentRef.template === 'string') {\n\t\t\tif (componentRef.styles) {\n\t\t\t\tconst template = `<style>${componentRef.styles}</style>${componentRef.template}`;\n\t\t\t\tcomponentRef.template = htmlParser.toDomRootNode(template);\n\t\t\t} else {\n\t\t\t\tcomponentRef.template = htmlParser.toDomRootNode(componentRef.template);\n\t\t\t}\n\t\t\tbuildExpressionNodes(componentRef.template);\n\t\t}\n\n\t\tif (!componentRef.template && /template/g.test(componentRef.encapsulation)) {\n\t\t\tconst template = document.querySelector('#' + componentRef.selector);\n\t\t\tif (template && template instanceof HTMLTemplateElement) {\n\t\t\t\tcomponentRef.template = templateParser.parse(template);\n\t\t\t\tbuildExpressionNodes(componentRef.template);\n\t\t\t} else {\n\t\t\t\t// didn't find this template in 'index.html' document\n\t\t\t}\n\t\t}\n\n\t\tcomponentRef.inputs ||= [];\n\t\tcomponentRef.outputs ||= [];\n\t\tcomponentRef.viewChild ||= [];\n\t\tcomponentRef.ViewChildren ||= [];\n\t\tcomponentRef.hostBindings ||= [];\n\t\tcomponentRef.hostListeners ||= [];\n\t\tcomponentRef.encapsulation ||= 'custom';\n\t\tcomponentRef.isShadowDom = /shadow-dom/g.test(componentRef.encapsulation);\n\t\tcomponentRef.shadowDomMode ||= 'open';\n\t\tcomponentRef.shadowDomDelegatesFocus = componentRef.shadowDomDelegatesFocus === true || false;\n\n\t\tif (componentRef.isShadowDom && componentRef.extend.name) {\n\t\t\tcomponentRef.isShadowDom = canAttachShadow(componentRef.extend.name);\n\t\t}\n\n\t\tcomponentRef.modelClass = modelClass;\n\t\tcomponentRef.viewClass = initCustomElementView(modelClass, componentRef);\n\t\tComponents.setComponentRef(componentRef.modelClass, componentRef);\n\t\tComponents.setComponentRef(componentRef.viewClass, componentRef);\n\n\t\tClassRegistryProvider.registerComponent(modelClass);\n\t\tClassRegistryProvider.registerView(bootstrap.viewClass);\n\n\t\tconst options: ElementDefinitionOptions = {};\n\t\tconst parentTagName = componentRef.extend?.name;\n\t\tif (parentTagName) {\n\t\t\tif (parentTagName !== '!' && parentTagName.indexOf('-') === -1) {\n\t\t\t\toptions.extends = parentTagName;\n\t\t\t}\n\t\t}\n\n\n\t\tcustomElements.define(\n\t\t\tcomponentRef.selector as string,\n\t\t\tcomponentRef.viewClass as CustomElementConstructor,\n\t\t\toptions\n\t\t);\n\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../../src/core/component/component.ts"],"names":[],"mappings":"AACA,OAAO,EACN,aAAa,EAAO,UAAU,EAAE,cAAc,EACtB,eAAe,EAAE,iBAAiB,EAC1D,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAM7D,MAAM,OAAO,WAAW;IACvB,YAAmB,aAAqB,EAAU,SAAkB;QAAjD,kBAAa,GAA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C7C,MAAM,aAAa,GAAG,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC;QAChD,IAAI,aAAa,EAAE;YAClB,IAAI,aAAa,KAAK,GAAG,IAAI,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE;gBAC/D,OAAO,CAAC,OAAO,GAAG,aAAa,CAAC;aAChC;SACD;QAGD,cAAc,CAAC,MAAM,CACpB,YAAY,CAAC,QAAkB,EAC/B,YAAY,CAAC,SAAqC,EAClD,OAAO,CACP,CAAC;IAEH,CAAC;CACD","sourcesContent":["import type { TypeOf } from '../utils/typeof.js';\nimport {\n\tfindByTagName, Tag, htmlParser, templateParser,\n\tDomNode, DomRenderNode, canAttachShadow, directiveRegistry\n} from '@ibyar/elements';\n\nimport { HTMLComponent } from './custom-element.js';\nimport { ClassRegistryProvider } from '../providers/provider.js';\nimport { AttributeDirective, StructuralDirective } from '../directive/directive.js';\nimport { initCustomElementView } from '../view/view.js';\nimport { buildExpressionNodes } from '../html/expression.js';\nimport {\n\tComponentOptions, ChildOptions, PipeOptions,\n\tServiceOptions, DirectiveOptions\n} from '../annotation/decorators.js';\n\nexport class PropertyRef {\n\tconstructor(public modelProperty: string, private _viewName?: string) { }\n\tget viewAttribute(): string {\n\t\treturn this._viewName || this.modelProperty;\n\t}\n}\n\nexport class ChildRef {\n\tconstructor(\n\t\tpublic modelName: string,\n\t\tpublic selector: string | { new(): HTMLElement; prototype: HTMLElement } | CustomElementConstructor,\n\t\tpublic childOptions?: ChildOptions\n\t) { }\n}\n\nexport class ListenerRef {\n\tconstructor(public eventName: string, public args: string[], public modelCallbackName: string) { }\n}\n\nexport class HostBindingRef {\n\tconstructor(public viewProperty: string, public hostPropertyName: string) { }\n}\n\nexport interface BootstrapMetadata {\n\t[key: string]: any;\n}\n\nexport interface ServiceRef<T> {\n\tprovideIn: TypeOf<CustomElementConstructor> | 'root' | 'platform' | 'any';\n\tmodelClass: TypeOf<T>;\n\tname: string;\n}\n\nexport interface PipeRef<T> {\n\tname: string;\n\tasynchronous?: boolean;\n\tmodelClass: TypeOf<T>;\n}\nexport interface DirectiveRef<T> {\n\tselector: string;\n\n\tmodelClass: TypeOf<StructuralDirective> | TypeOf<AttributeDirective>;\n\n\tinputs: PropertyRef[];\n\toutputs: PropertyRef[];\n\tview: string;\n\tviewChild: ChildRef[];\n\tViewChildren: ChildRef[];\n\thostListeners: ListenerRef[];\n\thostBindings: HostBindingRef[];\n}\n\nexport interface ComponentRef<T> {\n\tselector: string;\n\ttemplate: DomNode | DomRenderNode<T>;\n\t// attrTemplate: JsxAttrComponent;\n\tstyles: string;\n\textend: Tag;\n\n\tviewClass: TypeOf<HTMLComponent<T>> & CustomElementConstructor;\n\tmodelClass: TypeOf<T>;\n\n\tinputs: PropertyRef[];\n\toutputs: PropertyRef[];\n\tview: string;\n\tviewChild: ChildRef[];\n\tViewChildren: ChildRef[];\n\thostBindings: HostBindingRef[];\n\thostListeners: ListenerRef[];\n\n\tencapsulation: 'custom' | 'shadow-dom' | 'template' | 'shadow-dom-template';\n\tisShadowDom: boolean;\n\tshadowDomMode: ShadowRootMode;\n\tshadowDomDelegatesFocus: boolean;\n}\n\nconst AuroraBootstrap = Symbol.for('aurora:bootstrap');\nconst AuroraMetadata = Symbol.for('aurora:metadata');\n\nexport class Components {\n\n\tstatic getOrCreateBootstrap<T extends {}>(target: Object): T {\n\t\tlet bootstrap: T = Reflect.getMetadata(AuroraBootstrap, target);\n\t\tif (!bootstrap) {\n\t\t\tbootstrap = {} as T;\n\t\t\tReflect.defineMetadata(AuroraBootstrap, bootstrap, target);\n\t\t}\n\t\treturn bootstrap;\n\t}\n\n\tstatic getBootstrap<T extends {}>(target: Object): T {\n\t\treturn Reflect.getMetadata(AuroraBootstrap, target);\n\t}\n\n\tstatic getComponentRef<T>(target: object): ComponentRef<T> {\n\t\treturn Reflect.getMetadata(AuroraMetadata, target);\n\t}\n\n\tstatic setComponentRef<T>(target: object, componentRef: ComponentRef<T>): void {\n\t\tReflect.defineMetadata(AuroraMetadata, componentRef, target);\n\t}\n\n\tstatic addOptional(modelProperty: Object) {\n\t}\n\n\tstatic addInput(modelProperty: Object, modelName: string, viewName: string) {\n\t\tconst bootstrap: BootstrapMetadata = Components.getOrCreateBootstrap(modelProperty);\n\t\tbootstrap.inputs = bootstrap.inputs || [];\n\t\tbootstrap.inputs.push(new PropertyRef(modelName, viewName));\n\t}\n\n\tstatic addOutput(modelProperty: Object, modelName: string, viewName: string) {\n\t\tconst bootstrap: BootstrapMetadata = Components.getOrCreateBootstrap(modelProperty);\n\t\tbootstrap.outputs = bootstrap.outputs || [];\n\t\tbootstrap.outputs.push(new PropertyRef(modelName, viewName));\n\t}\n\n\tstatic setComponentView(modelProperty: Object, modelName: string) {\n\t\tconst bootstrap: BootstrapMetadata = Components.getOrCreateBootstrap(modelProperty);\n\t\tbootstrap.view = modelName;\n\t}\n\n\tstatic addViewChild(modelProperty: Object, modelName: string, selector: string | typeof HTMLElement | CustomElementConstructor, childOptions?: ChildOptions) {\n\t\tconst bootstrap: BootstrapMetadata = Components.getOrCreateBootstrap(modelProperty);\n\t\tbootstrap.viewChild = bootstrap.viewChild || [];\n\t\tbootstrap.viewChild.push(new ChildRef(modelName, selector, childOptions));\n\t}\n\n\tstatic addViewChildren(modelProperty: Object, modelName: string, selector: string | typeof HTMLElement | CustomElementConstructor) {\n\t\tconst bootstrap: BootstrapMetadata = Components.getOrCreateBootstrap(modelProperty);\n\t\tbootstrap.ViewChildren = bootstrap.ViewChildren || [];\n\t\tbootstrap.ViewChildren.push(new ChildRef(modelName, selector));\n\t}\n\n\tstatic addHostListener(modelProperty: Object, propertyKey: string, eventName: string, args: string[]) {\n\t\tconst bootstrap: BootstrapMetadata = Components.getOrCreateBootstrap(modelProperty);\n\t\tbootstrap.hostListeners = bootstrap.hostListeners || [];\n\t\tbootstrap.hostListeners.push(new ListenerRef(eventName, args, propertyKey));\n\t}\n\n\tstatic addHostBinding(modelProperty: Object, propertyKey: string, hostPropertyName: string) {\n\t\tconst bootstrap: BootstrapMetadata = Components.getOrCreateBootstrap(modelProperty);\n\t\tbootstrap.hostBinding = bootstrap.hostBinding || [];\n\t\tbootstrap.hostBinding.push(\n\t\t\tnew HostBindingRef(propertyKey, hostPropertyName)\n\t\t);\n\t}\n\n\tstatic defineDirective(modelClass: Function, opts: DirectiveOptions) {\n\t\tconst bootstrap: BootstrapMetadata = Components.getOrCreateBootstrap(modelClass.prototype);\n\t\tfor (const key in opts) {\n\t\t\tbootstrap[key] = Reflect.get(opts, key);\n\t\t}\n\t\tbootstrap.modelClass = modelClass;\n\t\tClassRegistryProvider.registerDirective(modelClass);\n\t\tdirectiveRegistry.register(opts.selector, {\n\t\t\tinputs: (bootstrap.inputs as PropertyRef[])?.map(input => input.viewAttribute),\n\t\t\toutputs: (bootstrap.outputs as PropertyRef[])?.map(output => output.viewAttribute),\n\t\t});\n\t}\n\n\tstatic definePipe(modelClass: Function, opts: PipeOptions) {\n\t\tconst bootstrap: BootstrapMetadata = Components.getOrCreateBootstrap(modelClass.prototype);\n\t\tfor (const key in opts) {\n\t\t\tbootstrap[key] = Reflect.get(opts, key);\n\t\t}\n\t\tbootstrap.modelClass = modelClass;\n\t\tClassRegistryProvider.registerPipe(modelClass);\n\t}\n\n\tstatic defineService(modelClass: Function, opts: ServiceOptions) {\n\t\tconst bootstrap: BootstrapMetadata = Components.getOrCreateBootstrap(modelClass.prototype);\n\t\tfor (const key in opts) {\n\t\t\tbootstrap[key] = Reflect.get(opts, key);\n\t\t}\n\t\tbootstrap.modelClass = modelClass;\n\t\tbootstrap.name = modelClass.name;\n\t\tClassRegistryProvider.registerService(modelClass);\n\t}\n\n\tstatic defineComponent<T extends Object>(modelClass: TypeOf<T>, opts: ComponentOptions<T>) {\n\t\tconst bootstrap: BootstrapMetadata = Components.getOrCreateBootstrap(modelClass.prototype);\n\n\t\tvar componentRef: ComponentRef<T> = opts as unknown as ComponentRef<T>;\n\t\tfor (const key in bootstrap) {\n\t\t\tReflect.set(componentRef, key, bootstrap[key]);\n\t\t}\n\t\tcomponentRef.extend = findByTagName(opts.extend);\n\n\t\tif (typeof componentRef.template === 'string') {\n\t\t\tif (componentRef.styles) {\n\t\t\t\tconst template = `<style>${componentRef.styles}</style>${componentRef.template}`;\n\t\t\t\tcomponentRef.template = htmlParser.toDomRootNode(template);\n\t\t\t} else {\n\t\t\t\tcomponentRef.template = htmlParser.toDomRootNode(componentRef.template);\n\t\t\t}\n\t\t\tbuildExpressionNodes(componentRef.template);\n\t\t}\n\n\t\tif (!componentRef.template && /template/g.test(componentRef.encapsulation)) {\n\t\t\tconst template = document.querySelector('#' + componentRef.selector);\n\t\t\tif (template && template instanceof HTMLTemplateElement) {\n\t\t\t\tcomponentRef.template = templateParser.parse(template);\n\t\t\t\tbuildExpressionNodes(componentRef.template);\n\t\t\t} else {\n\t\t\t\t// didn't find this template in 'index.html' document\n\t\t\t}\n\t\t}\n\n\t\tcomponentRef.inputs ||= [];\n\t\tcomponentRef.outputs ||= [];\n\t\tcomponentRef.viewChild ||= [];\n\t\tcomponentRef.ViewChildren ||= [];\n\t\tcomponentRef.hostBindings ||= [];\n\t\tcomponentRef.hostListeners ||= [];\n\t\tcomponentRef.encapsulation ||= 'custom';\n\t\tcomponentRef.isShadowDom = /shadow-dom/g.test(componentRef.encapsulation);\n\t\tcomponentRef.shadowDomMode ||= 'open';\n\t\tcomponentRef.shadowDomDelegatesFocus = componentRef.shadowDomDelegatesFocus === true || false;\n\n\t\tif (componentRef.isShadowDom && componentRef.extend.name) {\n\t\t\tcomponentRef.isShadowDom = canAttachShadow(componentRef.extend.name);\n\t\t}\n\n\t\tcomponentRef.modelClass = modelClass;\n\t\tcomponentRef.viewClass = initCustomElementView(modelClass, componentRef);\n\t\tComponents.setComponentRef(componentRef.modelClass, componentRef);\n\t\tComponents.setComponentRef(componentRef.viewClass, componentRef);\n\n\t\tClassRegistryProvider.registerComponent(modelClass);\n\t\tClassRegistryProvider.registerView(bootstrap.viewClass);\n\n\t\tconst options: ElementDefinitionOptions = {};\n\t\tconst parentTagName = componentRef.extend?.name;\n\t\tif (parentTagName) {\n\t\t\tif (parentTagName !== '!' && parentTagName.indexOf('-') === -1) {\n\t\t\t\toptions.extends = parentTagName;\n\t\t\t}\n\t\t}\n\n\n\t\tcustomElements.define(\n\t\t\tcomponentRef.selector as string,\n\t\t\tcomponentRef.viewClass as CustomElementConstructor,\n\t\t\toptions\n\t\t);\n\n\t}\n}\n"]}
|
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
import type { ReactiveScope } from '@ibyar/expressions';
|
|
1
|
+
import type { ReactiveScope, ScopeContext } from '@ibyar/expressions';
|
|
2
2
|
import type { TypeOf } from '../utils/typeof.js';
|
|
3
|
-
import type { ElementReactiveScope } from '../directive/providers.js';
|
|
4
3
|
import { EventEmitter } from './events.js';
|
|
5
4
|
import { PropertyRef, ComponentRef } from './component.js';
|
|
6
|
-
import { Model } from '../model/change-detection.js';
|
|
7
5
|
export interface CustomElement {
|
|
8
6
|
adoptedCallback(): void;
|
|
9
7
|
attributeChangedCallback(name: string, oldValue: any, newValue: any): void;
|
|
10
8
|
connectedCallback(): void;
|
|
11
9
|
disconnectedCallback(): void;
|
|
12
10
|
}
|
|
13
|
-
export declare type ModelType<T> = T &
|
|
14
|
-
|
|
11
|
+
export declare type ModelType<T> = T & ScopeContext;
|
|
12
|
+
export declare type NodeContextType<T> = {
|
|
13
|
+
'this': BaseComponent<T>;
|
|
15
14
|
};
|
|
16
15
|
export interface BaseComponent<T> extends CustomElement {
|
|
17
16
|
_model: ModelType<T>;
|
|
18
17
|
_proxyModel: ModelType<T>;
|
|
19
|
-
_modelScope: ReactiveScope<T &
|
|
20
|
-
|
|
18
|
+
_modelScope: ReactiveScope<T & ScopeContext>;
|
|
19
|
+
_viewScope: ReactiveScope<{
|
|
20
|
+
'this': BaseComponent<T>;
|
|
21
21
|
}>;
|
|
22
|
-
_viewScope: ElementReactiveScope;
|
|
23
22
|
getComponentRef(): ComponentRef<T>;
|
|
24
|
-
setParentComponent<V>(parent: HTMLComponent<V>): void;
|
|
25
|
-
getParentComponent<V>(): HTMLComponent<V>;
|
|
23
|
+
setParentComponent<V extends object>(parent: HTMLComponent<V>): void;
|
|
24
|
+
getParentComponent<V extends object>(): HTMLComponent<V>;
|
|
26
25
|
hasParentComponent(): boolean;
|
|
27
26
|
hasInputStartWith(viewProp: string): boolean;
|
|
28
27
|
getInputStartWith(viewProp: string): PropertyRef | undefined;
|
|
@@ -35,14 +34,11 @@ export interface BaseComponent<T> extends CustomElement {
|
|
|
35
34
|
getOutput(viewProp: string): PropertyRef | undefined;
|
|
36
35
|
getEventEmitter<V>(viewProp: string): EventEmitter<V> | undefined;
|
|
37
36
|
triggerOutput(eventName: string, value?: any): void;
|
|
38
|
-
triggerModelChange(eventName: string, value?: any, source?: HTMLElement): void;
|
|
39
|
-
emitRootChanges(): void;
|
|
40
|
-
emitChanges(...events: string[]): void;
|
|
41
37
|
}
|
|
42
38
|
export interface HTMLComponent<T> extends BaseComponent<T>, HTMLElement {
|
|
43
39
|
}
|
|
44
40
|
export declare function isHTMLComponent(object: any): object is HTMLComponent<any>;
|
|
45
|
-
export declare function isHTMLComponentOfType<T>(object: any, typeClass: TypeOf<T>): object is HTMLComponent<T>;
|
|
41
|
+
export declare function isHTMLComponentOfType<T extends object>(object: any, typeClass: TypeOf<T>): object is HTMLComponent<T>;
|
|
46
42
|
export declare function isHTMLElement(element: HTMLElement): element is HTMLElement;
|
|
47
43
|
export declare function isHTMLUnknownElement(element: HTMLElement): element is HTMLElement;
|
|
48
44
|
export interface CustomFormElement extends CustomElement {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-element.js","sourceRoot":"","sources":["../../../src/core/component/custom-element.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"custom-element.js","sourceRoot":"","sources":["../../../src/core/component/custom-element.ts"],"names":[],"mappings":"AAiDA,MAAM,UAAU,eAAe,CAAC,MAAW;IAC1C,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC;WAChC,MAAM,YAAY,WAAW,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAmB,MAAW,EAAE,SAAoB;IACxF,OAAO,eAAe,CAAC,MAAM,CAAC;WAC1B,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,YAAY,SAAS,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAoB;IACjD,OAAO,OAAO,IAAI,OAAO,YAAY,WAAW,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC;AACrF,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,OAAoB;IACxD,OAAO,OAAO,IAAI,OAAO,YAAY,kBAAkB,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC;AAC5F,CAAC","sourcesContent":["import type { ReactiveScope, ScopeContext } from '@ibyar/expressions';\nimport type { TypeOf } from '../utils/typeof.js';\nimport { EventEmitter } from './events.js';\nimport { PropertyRef, ComponentRef } from './component.js';\n\nexport interface CustomElement {\n\tadoptedCallback(): void;\n\tattributeChangedCallback(name: string, oldValue: any, newValue: any): void;\n\tconnectedCallback(): void;\n\tdisconnectedCallback(): void;\n}\n\nexport type ModelType<T> = T & ScopeContext;\n\nexport type NodeContextType<T> = { 'this': BaseComponent<T> };\n\nexport interface BaseComponent<T> extends CustomElement {\n\n\t_model: ModelType<T>;\n\t_proxyModel: ModelType<T>;\n\t_modelScope: ReactiveScope<T & ScopeContext>;\n\n\t_viewScope: ReactiveScope<{ 'this': BaseComponent<T> }>;\n\n\tgetComponentRef(): ComponentRef<T>;\n\n\tsetParentComponent<V extends object>(parent: HTMLComponent<V>): void;\n\tgetParentComponent<V extends object>(): HTMLComponent<V>;\n\thasParentComponent(): boolean;\n\n\thasInputStartWith(viewProp: string): boolean;\n\tgetInputStartWith(viewProp: string): PropertyRef | undefined;\n\tgetInput(viewProp: string): PropertyRef | undefined;\n\tgetInputValue(viewProp: string): any;\n\tsetInputValue(viewProp: string, value: any): void;\n\n\thasInput(viewProp: string): boolean;\n\thasProp(propName: string): boolean;\n\thasOutput(viewProp: string): boolean;\n\n\tgetOutput(viewProp: string): PropertyRef | undefined;\n\tgetEventEmitter<V>(viewProp: string): EventEmitter<V> | undefined;\n\n\ttriggerOutput(eventName: string, value?: any): void;\n\n}\n\nexport interface HTMLComponent<T> extends BaseComponent<T>, HTMLElement { }\n\nexport function isHTMLComponent(object: any): object is HTMLComponent<any> {\n\treturn Reflect.has(object, '_model')\n\t\t&& object instanceof HTMLElement;\n}\n\nexport function isHTMLComponentOfType<T extends object>(object: any, typeClass: TypeOf<T>): object is HTMLComponent<T> {\n\treturn isHTMLComponent(object)\n\t\t&& Reflect.get(object, '_model') instanceof typeClass;\n}\n\nexport function isHTMLElement(element: HTMLElement): element is HTMLElement {\n\treturn element && element instanceof HTMLElement && !element.tagName?.includes('-');\n}\n\nexport function isHTMLUnknownElement(element: HTMLElement): element is HTMLElement {\n\treturn element && element instanceof HTMLUnknownElement && !element.tagName?.includes('-');\n}\n\n/**\n * Lifecycle callbacks\n * A map, whose keys are the strings \"connectedCallback\", \"disconnectedCallback\", \"adoptedCallback\", \"attributeChangedCallback\", \n * \"formAssociatedCallback\", \"formDisabledCallback\", \"formResetCallback\", and \"formStateRestoreCallback\" \n * https://html.spec.whatwg.org/multipage/custom-elements.html#concept-custom-element-definition-lifecycle-callbacks\n * \n * A form-associated custom element API includes a set of extra lifecycle callbacks to tie in to the form lifecycle.\n * The callbacks are optional: only implement a callback if your element needs to do something at that point in the lifecycle.\n * https://html.spec.whatwg.org/multipage/custom-elements.html#the-elementinternals-interface \n * https://docs.google.com/document/d/1JO8puctCSpW-ZYGU8lF-h4FWRIDQNDVexzHoOQ2iQmY/edit\n */\nexport interface CustomFormElement extends CustomElement {\n\n\t/**\n\t * Called when the browser associates the element with a form element,\n\t * or disassociates the element from a form element.\n\t * @param form \n\t */\n\tformAssociatedCallback(form: HTMLFormElement): void;\n\n\t/**\n\t * Called after the disabled state of the element changes,\n\t * either because the disabled attribute of this element was added or removed;\n\t * or because the disabled state changed on a <fieldset> that's an ancestor of this element.\n\t * The disabled parameter represents the new disabled state of the element.\n\t * The element may, for example, disable elements in its shadow DOM when it is disabled.\n\t * @param disabled \n\t */\n\tformDisabledCallback(disabled: boolean): void;\n\n\t/**\n\t * Called after the form is reset.\n\t * The element should reset itself to some kind of default state.\n\t * For <input> elements, this usually involves setting the value property to\n\t * match the value attribute set in markup (or in the case of a checkbox,\n\t * setting the checked property to match the checked attribute.\n\t */\n\tformResetCallback(): void;\n\n\t/**\n\t * Called in one of two circumstances:\n\t * When the browser restores the state of the element (for example, after a navigation, or when the browser restarts).\n\t * The mode argument is \"restore\" in this case.\n\t * \n\t * When the browser's input-assist features such as form autofilling sets a value.\n\t * The mode argument is \"autocomplete\" in this case.\n\t * \n\t * The type of the first argument depends on how the setFormValue() method was called.\n\t * For more details, see Restoring form state.\n\t */\n\tformStateRestoreCallback(value: any, mode: 'restore' | 'autocomplete'): void;\n}\n\nexport interface BaseFormElementComponent<T extends Object> extends BaseComponent<T>, CustomFormElement { }\n\nexport interface HTMLFormElementComponent<T extends Object> extends BaseFormElementComponent<T>, HTMLComponent<T> { }\n\nexport type HTMLFormElement = HTMLButtonElement | HTMLDataListElement | HTMLFieldSetElement | HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;\n"]}
|
package/component/provider.js
CHANGED
|
@@ -3,7 +3,7 @@ export class ElementModelReactiveScope extends ReactiveScope {
|
|
|
3
3
|
constructor() {
|
|
4
4
|
super(...arguments);
|
|
5
5
|
this.functionProxyMap = new Map();
|
|
6
|
-
this.contextProxy = createProxyForContext(this
|
|
6
|
+
this.contextProxy = createProxyForContext(this);
|
|
7
7
|
}
|
|
8
8
|
static for(context, type) {
|
|
9
9
|
return new ElementModelReactiveScope(context, type);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/core/component/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,aAAa,EAAa,MAAM,oBAAoB,CAAC;AAG3G,MAAM,OAAO,yBAAiE,SAAQ,aAAgB;IAAtG;;QAmBS,qBAAgB,GAAG,IAAI,GAAG,EAAyB,CAAC;QACpD,iBAAY,GAAG,qBAAqB,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/core/component/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,aAAa,EAAa,MAAM,oBAAoB,CAAC;AAG3G,MAAM,OAAO,yBAAiE,SAAQ,aAAgB;IAAtG;;QAmBS,qBAAgB,GAAG,IAAI,GAAG,EAAyB,CAAC;QACpD,iBAAY,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAgBpD,CAAC;IAnCA,MAAM,CAAC,GAAG,CAAmB,OAAU,EAAE,IAAe;QACvD,OAAO,IAAI,yBAAyB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACrD,CAAC;IACD,MAAM,CAAC,aAAa,CAAmB,OAAU;QAChD,OAAO,IAAI,yBAAyB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACxD,CAAC;IACD,MAAM,CAAC,gBAAgB,CAAmB,OAAU;QACnD,OAAO,IAAI,yBAAyB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAC3D,CAAC;IACD,MAAM,CAAC,aAAa,CAAmB,OAAU;QAChD,OAAO,IAAI,yBAAyB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACxD,CAAC;IACD,MAAM,CAAC,cAAc,CAAmB,OAAU;QACjD,OAAO,IAAI,yBAAyB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACzD,CAAC;IACD,MAAM,CAAC,cAAc,CAAmB,OAAU;QACjD,OAAO,IAAI,yBAAyB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACzD,CAAC;IAGD,eAAe;QACd,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;IACD,GAAG,CAAC,WAAwB;QAC3B,IAAI,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;YAC3C,OAAO,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;SAC9C;QACD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QACrD,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE;YAChC,MAAM,KAAK,GAAG,IAAI,KAAK,CAAW,KAAK,EAAE,IAAI,oBAAoB,CAAW,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;YAChG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;YAC9C,OAAO,KAAK,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACd,CAAC;CACD","sourcesContent":["import { createProxyForContext, FunctionProxyHandler, ReactiveScope, ScopeType } from '@ibyar/expressions';\n\n\nexport class ElementModelReactiveScope<T extends { [key: PropertyKey]: any }> extends ReactiveScope<T> {\n\tstatic for<T extends object>(context: T, type: ScopeType) {\n\t\treturn new ElementModelReactiveScope(context, type);\n\t}\n\tstatic blockScopeFor<T extends object>(context: T) {\n\t\treturn new ElementModelReactiveScope(context, 'block');\n\t}\n\tstatic functionScopeFor<T extends object>(context: T) {\n\t\treturn new ElementModelReactiveScope(context, 'function');\n\t}\n\tstatic classScopeFor<T extends object>(context: T) {\n\t\treturn new ElementModelReactiveScope(context, 'class');\n\t}\n\tstatic moduleScopeFor<T extends object>(context: T) {\n\t\treturn new ElementModelReactiveScope(context, 'module');\n\t}\n\tstatic globalScopeFor<T extends object>(context: T) {\n\t\treturn new ElementModelReactiveScope(context, 'global');\n\t}\n\tprivate functionProxyMap = new Map<PropertyKey, Function>();\n\tprivate contextProxy = createProxyForContext(this);\n\tgetContextProxy() {\n\t\treturn this.contextProxy;\n\t}\n\tget(propertyKey: PropertyKey): any {\n\t\tif (this.functionProxyMap.has(propertyKey)) {\n\t\t\treturn this.functionProxyMap.get(propertyKey);\n\t\t}\n\t\tconst value = Reflect.get(this.context, propertyKey);\n\t\tif (typeof value === 'function') {\n\t\t\tconst proxy = new Proxy<Function>(value, new FunctionProxyHandler<Function>(this.contextProxy));\n\t\t\tthis.functionProxyMap.set(propertyKey, proxy);\n\t\t\treturn proxy;\n\t\t}\n\t\treturn value;\n\t}\n}\n"]}
|
package/directive/directive.d.ts
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import type { Stack } from '@ibyar/expressions';
|
|
1
|
+
import { TemplateRef } from '../linker/template-ref.js';
|
|
2
|
+
import { ViewContainerRef } from '../linker/view-container-ref.js';
|
|
4
3
|
export declare class StructuralDirective {
|
|
5
|
-
protected
|
|
6
|
-
protected
|
|
7
|
-
|
|
8
|
-
protected parentNode: Node;
|
|
9
|
-
protected node: DOMNode;
|
|
10
|
-
constructor(render: ComponentRender<any>, directiveStack: Stack, comment: Comment, parentNode: Node, node: DOMNode);
|
|
11
|
-
protected findTemplate(templateRefName: string): DOMElementNode | undefined;
|
|
4
|
+
protected templateRef: TemplateRef;
|
|
5
|
+
protected viewContainerRef: ViewContainerRef;
|
|
6
|
+
constructor(templateRef: TemplateRef, viewContainerRef: ViewContainerRef);
|
|
12
7
|
}
|
|
13
8
|
export declare class AttributeDirective {
|
|
14
9
|
protected el: HTMLElement;
|
package/directive/directive.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
export class StructuralDirective {
|
|
2
|
-
constructor(
|
|
3
|
-
this.
|
|
4
|
-
this.
|
|
5
|
-
this.comment = comment;
|
|
6
|
-
this.parentNode = parentNode;
|
|
7
|
-
this.node = node;
|
|
8
|
-
}
|
|
9
|
-
findTemplate(templateRefName) {
|
|
10
|
-
return this.render.templateRefMap.get(templateRefName);
|
|
2
|
+
constructor(templateRef, viewContainerRef) {
|
|
3
|
+
this.templateRef = templateRef;
|
|
4
|
+
this.viewContainerRef = viewContainerRef;
|
|
11
5
|
}
|
|
12
6
|
}
|
|
13
7
|
export class AttributeDirective {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"directive.js","sourceRoot":"","sources":["../../../src/core/directive/directive.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"directive.js","sourceRoot":"","sources":["../../../src/core/directive/directive.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,mBAAmB;IAC/B,YACW,WAAwB,EACxB,gBAAkC;QADlC,gBAAW,GAAX,WAAW,CAAa;QACxB,qBAAgB,GAAhB,gBAAgB,CAAkB;IACzC,CAAC;CACL;AAKD,MAAM,OAAO,kBAAkB;IAC9B,YAAsB,EAAe;QAAf,OAAE,GAAF,EAAE,CAAa;IAAI,CAAC;CAC1C","sourcesContent":["\nimport { TemplateRef } from '../linker/template-ref.js';\nimport { ViewContainerRef } from '../linker/view-container-ref.js';\n\n/**\n * A structural directive selector as '*if' '*for'\n */\nexport class StructuralDirective {\n\tconstructor(\n\t\tprotected templateRef: TemplateRef,\n\t\tprotected viewContainerRef: ViewContainerRef,\n\t) { }\n}\n\n/**\n * An attributes directive selector as '[class] [style]'\n */\nexport class AttributeDirective {\n\tconstructor(protected el: HTMLElement) { }\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Token, TokenExpression, TokenStream } from '@ibyar/expressions';
|
|
2
|
+
export declare type DirectiveExpressionType = {
|
|
3
|
+
templateExpressions: Array<TokenExpression[]>;
|
|
4
|
+
directiveInputs: Map<string, string>;
|
|
5
|
+
};
|
|
6
|
+
export declare class DirectiveExpressionParser {
|
|
7
|
+
protected directiveName: string;
|
|
8
|
+
protected stream: TokenStream;
|
|
9
|
+
static parse(directiveName: string, expression: string): DirectiveExpressionType;
|
|
10
|
+
protected templateExpressions: TokenExpression[][];
|
|
11
|
+
protected directiveInputs: Map<string, string>;
|
|
12
|
+
constructor(directiveName: string, stream: TokenStream);
|
|
13
|
+
getDirectiveExpressionType(): DirectiveExpressionType;
|
|
14
|
+
scan(): void;
|
|
15
|
+
protected consume(token: Token): void;
|
|
16
|
+
protected check(token: Token): boolean;
|
|
17
|
+
protected consumeToList(token: Token, list: TokenExpression[]): void;
|
|
18
|
+
protected consumeIfToken(token: Token, list: TokenExpression[]): boolean;
|
|
19
|
+
protected isLet(): boolean;
|
|
20
|
+
protected isIdentifier(): boolean;
|
|
21
|
+
protected isAsKeyword(): boolean;
|
|
22
|
+
protected consumeAsKeyword(): void;
|
|
23
|
+
protected isSemicolon(): boolean;
|
|
24
|
+
protected isComma(): boolean;
|
|
25
|
+
protected consumeSemicolonOrComma(): void;
|
|
26
|
+
protected parseTemplateInput(): boolean;
|
|
27
|
+
protected parseExpression(inputName: string): void;
|
|
28
|
+
protected parseDirectiveAndTemplateInputs(): void;
|
|
29
|
+
private mapTokenToString;
|
|
30
|
+
}
|