@ibyar/core 0.6.1 → 0.8.2-dev.20221008
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 +3 -2
- package/annotation/decorators.d.ts +101 -5
- package/annotation/decorators.js +48 -21
- package/annotation/decorators.js.map +1 -1
- package/binding/binding.expressions.d.ts +7 -3
- package/binding/binding.expressions.js +21 -6
- package/binding/binding.expressions.js.map +1 -1
- package/component/component.d.ts +10 -48
- package/component/component.js +24 -90
- package/component/component.js.map +1 -1
- package/component/custom-element.d.ts +87 -6
- package/component/custom-element.js +6 -0
- package/component/custom-element.js.map +1 -1
- package/component/reflect.d.ts +54 -0
- package/component/reflect.js +95 -0
- package/component/reflect.js.map +1 -0
- package/html/deserialize.d.ts +2 -0
- package/html/deserialize.js +68 -0
- package/html/deserialize.js.map +1 -0
- package/html/expression.d.ts +2 -25
- package/html/expression.js +2 -2
- package/html/expression.js.map +1 -1
- package/html/types.d.ts +26 -0
- package/html/types.js +2 -0
- package/html/types.js.map +1 -0
- package/index.d.ts +3 -0
- package/index.js +3 -0
- package/index.js.map +1 -1
- package/linker/view-container-ref.js +3 -3
- package/linker/view-container-ref.js.map +1 -1
- package/node.d.ts +2 -0
- package/node.js +3 -0
- package/node.js.map +1 -0
- package/package.json +10 -8
- package/providers/provider.d.ts +2 -1
- package/providers/provider.js +9 -9
- package/providers/provider.js.map +1 -1
- package/render/host-listener.handler.d.ts +1 -1
- package/render/host-listener.handler.js.map +1 -1
- package/view/base-view.js +13 -15
- package/view/base-view.js.map +1 -1
- package/view/form-view.d.ts +14 -2
- package/view/form-view.js +90 -44
- package/view/form-view.js.map +1 -1
- package/view/render.js +9 -8
- package/view/render.js.map +1 -1
- package/view/utils.d.ts +6 -0
- package/view/utils.js +20 -0
- package/view/utils.js.map +1 -0
- package/view/view.d.ts +0 -2
- package/view/view.js +8 -34
- package/view/view.js.map +1 -1
package/component/component.js
CHANGED
|
@@ -2,93 +2,11 @@ import { findByTagName, htmlParser, templateParser, canAttachShadow, directiveRe
|
|
|
2
2
|
import { ClassRegistryProvider } from '../providers/provider.js';
|
|
3
3
|
import { initCustomElementView } from '../view/view.js';
|
|
4
4
|
import { buildExpressionNodes } from '../html/expression.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this.modelProperty = modelProperty;
|
|
8
|
-
this._viewName = _viewName;
|
|
9
|
-
}
|
|
10
|
-
get viewAttribute() {
|
|
11
|
-
return this._viewName || this.modelProperty;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export class ChildRef {
|
|
15
|
-
constructor(modelName, selector, childOptions) {
|
|
16
|
-
this.modelName = modelName;
|
|
17
|
-
this.selector = selector;
|
|
18
|
-
this.childOptions = childOptions;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
export class ListenerRef {
|
|
22
|
-
constructor(eventName, args, modelCallbackName) {
|
|
23
|
-
this.eventName = eventName;
|
|
24
|
-
this.args = args;
|
|
25
|
-
this.modelCallbackName = modelCallbackName;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export class HostBindingRef {
|
|
29
|
-
constructor(viewProperty, hostPropertyName) {
|
|
30
|
-
this.viewProperty = viewProperty;
|
|
31
|
-
this.hostPropertyName = hostPropertyName;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
const AuroraBootstrap = Symbol.for('aurora:bootstrap');
|
|
35
|
-
const AuroraMetadata = Symbol.for('aurora:metadata');
|
|
5
|
+
import { ReflectComponents } from './reflect.js';
|
|
6
|
+
import { deserializeExpressionNodes } from '../html/deserialize.js';
|
|
36
7
|
export class Components {
|
|
37
|
-
static getOrCreateBootstrap(target) {
|
|
38
|
-
let bootstrap = Reflect.getMetadata(AuroraBootstrap, target);
|
|
39
|
-
if (!bootstrap) {
|
|
40
|
-
bootstrap = {};
|
|
41
|
-
Reflect.defineMetadata(AuroraBootstrap, bootstrap, target);
|
|
42
|
-
}
|
|
43
|
-
return bootstrap;
|
|
44
|
-
}
|
|
45
|
-
static getBootstrap(target) {
|
|
46
|
-
return Reflect.getMetadata(AuroraBootstrap, target);
|
|
47
|
-
}
|
|
48
|
-
static getComponentRef(target) {
|
|
49
|
-
return Reflect.getMetadata(AuroraMetadata, target);
|
|
50
|
-
}
|
|
51
|
-
static setComponentRef(target, componentRef) {
|
|
52
|
-
Reflect.defineMetadata(AuroraMetadata, componentRef, target);
|
|
53
|
-
}
|
|
54
|
-
static addOptional(modelProperty) {
|
|
55
|
-
}
|
|
56
|
-
static addInput(modelProperty, modelName, viewName) {
|
|
57
|
-
const bootstrap = Components.getOrCreateBootstrap(modelProperty);
|
|
58
|
-
bootstrap.inputs = bootstrap.inputs || [];
|
|
59
|
-
bootstrap.inputs.push(new PropertyRef(modelName, viewName));
|
|
60
|
-
}
|
|
61
|
-
static addOutput(modelProperty, modelName, viewName) {
|
|
62
|
-
const bootstrap = Components.getOrCreateBootstrap(modelProperty);
|
|
63
|
-
bootstrap.outputs = bootstrap.outputs || [];
|
|
64
|
-
bootstrap.outputs.push(new PropertyRef(modelName, viewName));
|
|
65
|
-
}
|
|
66
|
-
static setComponentView(modelProperty, modelName) {
|
|
67
|
-
const bootstrap = Components.getOrCreateBootstrap(modelProperty);
|
|
68
|
-
bootstrap.view = modelName;
|
|
69
|
-
}
|
|
70
|
-
static addViewChild(modelProperty, modelName, selector, childOptions) {
|
|
71
|
-
const bootstrap = Components.getOrCreateBootstrap(modelProperty);
|
|
72
|
-
bootstrap.viewChild = bootstrap.viewChild || [];
|
|
73
|
-
bootstrap.viewChild.push(new ChildRef(modelName, selector, childOptions));
|
|
74
|
-
}
|
|
75
|
-
static addViewChildren(modelProperty, modelName, selector) {
|
|
76
|
-
const bootstrap = Components.getOrCreateBootstrap(modelProperty);
|
|
77
|
-
bootstrap.ViewChildren = bootstrap.ViewChildren || [];
|
|
78
|
-
bootstrap.ViewChildren.push(new ChildRef(modelName, selector));
|
|
79
|
-
}
|
|
80
|
-
static addHostListener(modelProperty, propertyKey, eventName, args) {
|
|
81
|
-
const bootstrap = Components.getOrCreateBootstrap(modelProperty);
|
|
82
|
-
bootstrap.hostListeners = bootstrap.hostListeners || [];
|
|
83
|
-
bootstrap.hostListeners.push(new ListenerRef(eventName, args, propertyKey));
|
|
84
|
-
}
|
|
85
|
-
static addHostBinding(modelProperty, propertyKey, hostPropertyName) {
|
|
86
|
-
const bootstrap = Components.getOrCreateBootstrap(modelProperty);
|
|
87
|
-
bootstrap.hostBinding = bootstrap.hostBinding || [];
|
|
88
|
-
bootstrap.hostBinding.push(new HostBindingRef(propertyKey, hostPropertyName));
|
|
89
|
-
}
|
|
90
8
|
static defineDirective(modelClass, opts) {
|
|
91
|
-
const bootstrap =
|
|
9
|
+
const bootstrap = ReflectComponents.getOrCreateBootstrap(modelClass.prototype);
|
|
92
10
|
for (const key in opts) {
|
|
93
11
|
bootstrap[key] = Reflect.get(opts, key);
|
|
94
12
|
}
|
|
@@ -100,7 +18,7 @@ export class Components {
|
|
|
100
18
|
});
|
|
101
19
|
}
|
|
102
20
|
static definePipe(modelClass, opts) {
|
|
103
|
-
const bootstrap =
|
|
21
|
+
const bootstrap = ReflectComponents.getOrCreateBootstrap(modelClass.prototype);
|
|
104
22
|
for (const key in opts) {
|
|
105
23
|
bootstrap[key] = Reflect.get(opts, key);
|
|
106
24
|
}
|
|
@@ -108,7 +26,7 @@ export class Components {
|
|
|
108
26
|
ClassRegistryProvider.registerPipe(modelClass);
|
|
109
27
|
}
|
|
110
28
|
static defineService(modelClass, opts) {
|
|
111
|
-
const bootstrap =
|
|
29
|
+
const bootstrap = ReflectComponents.getOrCreateBootstrap(modelClass.prototype);
|
|
112
30
|
for (const key in opts) {
|
|
113
31
|
bootstrap[key] = Reflect.get(opts, key);
|
|
114
32
|
}
|
|
@@ -117,7 +35,7 @@ export class Components {
|
|
|
117
35
|
ClassRegistryProvider.registerService(modelClass);
|
|
118
36
|
}
|
|
119
37
|
static defineComponent(modelClass, opts) {
|
|
120
|
-
const bootstrap =
|
|
38
|
+
const bootstrap = ReflectComponents.getOrCreateBootstrap(modelClass.prototype);
|
|
121
39
|
var componentRef = opts;
|
|
122
40
|
for (const key in bootstrap) {
|
|
123
41
|
Reflect.set(componentRef, key, bootstrap[key]);
|
|
@@ -133,6 +51,15 @@ export class Components {
|
|
|
133
51
|
}
|
|
134
52
|
buildExpressionNodes(componentRef.template);
|
|
135
53
|
}
|
|
54
|
+
else if (typeof componentRef.template === 'object') {
|
|
55
|
+
buildExpressionNodes(componentRef.template);
|
|
56
|
+
}
|
|
57
|
+
else if (typeof componentRef.compiledTemplate === 'object') {
|
|
58
|
+
htmlParser.deserializeNode(componentRef.compiledTemplate);
|
|
59
|
+
deserializeExpressionNodes(componentRef.compiledTemplate);
|
|
60
|
+
componentRef.template = componentRef.compiledTemplate;
|
|
61
|
+
componentRef.compiledTemplate = undefined;
|
|
62
|
+
}
|
|
136
63
|
if (!componentRef.template && /template/g.test(componentRef.encapsulation)) {
|
|
137
64
|
const template = document.querySelector('#' + componentRef.selector);
|
|
138
65
|
if (template && template instanceof HTMLTemplateElement) {
|
|
@@ -153,13 +80,16 @@ export class Components {
|
|
|
153
80
|
componentRef.isShadowDom = /shadow-dom/g.test(componentRef.encapsulation);
|
|
154
81
|
componentRef.shadowDomMode || (componentRef.shadowDomMode = 'open');
|
|
155
82
|
componentRef.shadowDomDelegatesFocus = componentRef.shadowDomDelegatesFocus === true || false;
|
|
83
|
+
if (!(componentRef.formAssociated === true || typeof componentRef.formAssociated === 'function')) {
|
|
84
|
+
componentRef.formAssociated = false;
|
|
85
|
+
}
|
|
156
86
|
if (componentRef.isShadowDom && componentRef.extend.name) {
|
|
157
87
|
componentRef.isShadowDom = canAttachShadow(componentRef.extend.name);
|
|
158
88
|
}
|
|
159
89
|
componentRef.modelClass = modelClass;
|
|
160
90
|
componentRef.viewClass = initCustomElementView(modelClass, componentRef);
|
|
161
|
-
|
|
162
|
-
|
|
91
|
+
ReflectComponents.setComponentRef(componentRef.modelClass, componentRef);
|
|
92
|
+
ReflectComponents.setComponentRef(componentRef.viewClass, componentRef);
|
|
163
93
|
ClassRegistryProvider.registerComponent(modelClass);
|
|
164
94
|
ClassRegistryProvider.registerView(bootstrap.viewClass);
|
|
165
95
|
const options = {};
|
|
@@ -171,5 +101,9 @@ export class Components {
|
|
|
171
101
|
}
|
|
172
102
|
customElements.define(componentRef.selector, componentRef.viewClass, options);
|
|
173
103
|
}
|
|
104
|
+
static defineView(viewClass, opt) {
|
|
105
|
+
ClassRegistryProvider.registerView(viewClass);
|
|
106
|
+
customElements.define(opt.selector, viewClass, Object.assign({}, opt, { selector: undefined }));
|
|
107
|
+
}
|
|
174
108
|
}
|
|
175
109
|
//# sourceMappingURL=component.js.map
|
|
@@ -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;AAO7D,MAAM,OAAO,WAAW;IACvB,YAAmB,aAAqB,EAAU,SAAkB;QAAjD,kBAAa,GAAb,aAAa,CAAQ;QAAU,cAAS,GAAT,SAAS,CAAS;IAAI,CAAC;IACzE,IAAI,aAAa;QAChB,OAAO,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,aAAa,CAAC;IAC7C,CAAC;CACD;AAED,MAAM,OAAO,QAAQ;IACpB,YACQ,SAAiB,EACjB,QAA4F,EAC5F,YAA2B;QAF3B,cAAS,GAAT,SAAS,CAAQ;QACjB,aAAQ,GAAR,QAAQ,CAAoF;QAC5F,iBAAY,GAAZ,YAAY,CAAe;IAC/B,CAAC;CACL;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AC,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';\nimport { ZoneType } from '../zone/bootstrap.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\tzone: ZoneType;\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\tzone: ZoneType;\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
|
+
{"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,OAAO,EAGO,iBAAiB,EAC9B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAwDpE,MAAM,OAAO,UAAU;IAEtB,MAAM,CAAC,eAAe,CAAC,UAAoB,EAAE,IAAsB;QAClE,MAAM,SAAS,GAAsB,iBAAiB,CAAC,oBAAoB,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QAClG,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;YACvB,SAAS,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;SACxC;QACD,SAAS,CAAC,UAAU,GAAG,UAAU,CAAC;QAClC,qBAAqB,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;QACpD,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE;YACzC,MAAM,EAAG,SAAS,CAAC,MAAwB,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC;YAC9E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CAAC;QACzE,iBAAiB,CAAC,eAAe,CAAC,YAAY,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;QACzE,iBAAiB,CAAC,eAAe,CAAC,YAAY,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;QAExE,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;IAED,MAAM,CAAC,UAAU,CAAwB,SAAoB,EAAE,GAAoD;QAClH,qBAAqB,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;QAC9C,cAAc,CAAC,MAAM,CACpB,GAAG,CAAC,QAAkB,EACtB,SAAS,EACT,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAC/C,CAAC;IACH,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, ValueControl } 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, PipeOptions,\n\tServiceOptions, DirectiveOptions\n} from '../annotation/decorators.js';\nimport { ZoneType } from '../zone/bootstrap.js';\nimport {\n\tBootstrapMetadata, ChildRef, HostBindingRef,\n\tInputPropertyRef, ListenerRef, OutputPropertyRef,\n\tPropertyRef, ReflectComponents\n} from './reflect.js';\nimport { deserializeExpressionNodes } from '../html/deserialize.js';\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\tzone: ZoneType;\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\tcompiledTemplate?: DomNode;\n\t// attrTemplate: JsxAttrComponent;\n\tstyles: string;\n\textend: Tag;\n\n\tviewClass: TypeOf<HTMLComponent<T>> & CustomElementConstructor;\n\tmodelClass: TypeOf<T>;\n\n\tinputs: InputPropertyRef[];\n\toutputs: OutputPropertyRef[];\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\tformAssociated: boolean | TypeOf<ValueControl<any>>;\n\tzone: ZoneType;\n}\n\nexport class Components {\n\n\tstatic defineDirective(modelClass: Function, opts: DirectiveOptions) {\n\t\tconst bootstrap: BootstrapMetadata = ReflectComponents.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 = ReflectComponents.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 = ReflectComponents.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 = ReflectComponents.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} else if (typeof componentRef.template === 'object') {\n\t\t\tbuildExpressionNodes(componentRef.template);\n\t\t} else if (typeof componentRef.compiledTemplate === 'object') {\n\t\t\thtmlParser.deserializeNode(componentRef.compiledTemplate);\n\t\t\tdeserializeExpressionNodes(componentRef.compiledTemplate);\n\t\t\tcomponentRef.template = componentRef.compiledTemplate;\n\t\t\tcomponentRef.compiledTemplate = undefined;\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.formAssociated === true || typeof componentRef.formAssociated === 'function')) {\n\t\t\tcomponentRef.formAssociated = false;\n\t\t}\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\tReflectComponents.setComponentRef(componentRef.modelClass, componentRef);\n\t\tReflectComponents.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\tstatic defineView<T extends HTMLElement>(viewClass: TypeOf<T>, opt: { selector: string } & ElementDefinitionOptions) {\n\t\tClassRegistryProvider.registerView(viewClass);\n\t\tcustomElements.define(\n\t\t\topt.selector as string,\n\t\t\tviewClass,\n\t\t\tObject.assign({}, opt, { selector: undefined }),\n\t\t);\n\t}\n}\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { ReactiveScope, ReactiveScopeControl, Context } from '@ibyar/expressions';
|
|
2
2
|
import type { TypeOf } from '../utils/typeof.js';
|
|
3
3
|
import { EventEmitter } from './events.js';
|
|
4
|
-
import {
|
|
4
|
+
import { ComponentRef } from './component.js';
|
|
5
5
|
import { AuroraZone } from '../zone/zone.js';
|
|
6
|
+
import { PropertyRef } from './reflect.js';
|
|
6
7
|
export interface CustomElement {
|
|
7
8
|
adoptedCallback(): void;
|
|
8
9
|
attributeChangedCallback(name: string, oldValue: any, newValue: any): void;
|
|
@@ -36,6 +37,10 @@ export interface BaseComponent<T> extends CustomElement {
|
|
|
36
37
|
getEventEmitter<V>(viewProp: string): EventEmitter<V> | undefined;
|
|
37
38
|
triggerOutput(eventName: string, value?: any): void;
|
|
38
39
|
onDestroy(callback: () => void): void;
|
|
40
|
+
/**
|
|
41
|
+
* apply change detection
|
|
42
|
+
*/
|
|
43
|
+
detectChanges(): void;
|
|
39
44
|
}
|
|
40
45
|
export interface HTMLComponent<T> extends BaseComponent<T>, HTMLElement {
|
|
41
46
|
}
|
|
@@ -54,13 +59,13 @@ export declare function isHTMLUnknownElement(element: HTMLElement): element is H
|
|
|
54
59
|
* https://html.spec.whatwg.org/multipage/custom-elements.html#the-elementinternals-interface
|
|
55
60
|
* https://docs.google.com/document/d/1JO8puctCSpW-ZYGU8lF-h4FWRIDQNDVexzHoOQ2iQmY/edit
|
|
56
61
|
*/
|
|
57
|
-
export interface
|
|
62
|
+
export interface FormAssociatedCustomElement extends CustomElement {
|
|
58
63
|
/**
|
|
59
64
|
* Called when the browser associates the element with a form element,
|
|
60
65
|
* or disassociates the element from a form element.
|
|
61
66
|
* @param form
|
|
62
67
|
*/
|
|
63
|
-
formAssociatedCallback(form: HTMLFormElement): void;
|
|
68
|
+
formAssociatedCallback(form: HTMLFormElement | null): void;
|
|
64
69
|
/**
|
|
65
70
|
* Called after the disabled state of the element changes,
|
|
66
71
|
* either because the disabled attribute of this element was added or removed;
|
|
@@ -83,7 +88,7 @@ export interface CustomFormElement extends CustomElement {
|
|
|
83
88
|
* When the browser restores the state of the element (for example, after a navigation, or when the browser restarts).
|
|
84
89
|
* The mode argument is "restore" in this case.
|
|
85
90
|
*
|
|
86
|
-
* When the browser's input-assist features such as form
|
|
91
|
+
* When the browser's input-assist features such as form auto filling sets a value.
|
|
87
92
|
* The mode argument is "autocomplete" in this case.
|
|
88
93
|
*
|
|
89
94
|
* The type of the first argument depends on how the setFormValue() method was called.
|
|
@@ -91,8 +96,84 @@ export interface CustomFormElement extends CustomElement {
|
|
|
91
96
|
*/
|
|
92
97
|
formStateRestoreCallback(value: any, mode: 'restore' | 'autocomplete'): void;
|
|
93
98
|
}
|
|
94
|
-
export
|
|
99
|
+
export declare type WriteValueMode = 'restore' | 'autocomplete' | 'reset';
|
|
100
|
+
export declare type WriteValueOptions<T> = {
|
|
101
|
+
value: T | null;
|
|
102
|
+
mode?: 'restore' | 'autocomplete';
|
|
103
|
+
} | {
|
|
104
|
+
value?: undefined;
|
|
105
|
+
mode: 'reset';
|
|
106
|
+
};
|
|
107
|
+
export interface ValueControl<T = any> {
|
|
108
|
+
/**
|
|
109
|
+
* reset the value of the
|
|
110
|
+
* @param value
|
|
111
|
+
* @param mode
|
|
112
|
+
*/
|
|
113
|
+
writeValue(opt: {
|
|
114
|
+
value?: undefined;
|
|
115
|
+
mode: 'reset';
|
|
116
|
+
}): void;
|
|
117
|
+
/**
|
|
118
|
+
*
|
|
119
|
+
* When the browser restores the state of the element (for example, after a navigation, or when the browser restarts).
|
|
120
|
+
* The mode argument is "restore" in this case.
|
|
121
|
+
*
|
|
122
|
+
* When the browser's input-assist features such as form auto filling sets a value.
|
|
123
|
+
* The mode argument is "autocomplete" in this case.
|
|
124
|
+
*
|
|
125
|
+
* @param opt: options contain the `value` to be written and `mode` represented by `restore` or `autocomplete` or `undefined`
|
|
126
|
+
*/
|
|
127
|
+
writeValue(opt: {
|
|
128
|
+
value: T | null;
|
|
129
|
+
mode?: 'restore' | 'autocomplete';
|
|
130
|
+
}): void;
|
|
131
|
+
writeValue(opt: {
|
|
132
|
+
value?: T | null;
|
|
133
|
+
mode?: WriteValueMode;
|
|
134
|
+
}): void;
|
|
135
|
+
writeValue(opt: WriteValueOptions<T>): void;
|
|
136
|
+
/**
|
|
137
|
+
* This method is called when new `ValueControl` assigned to the form associated element.
|
|
138
|
+
*
|
|
139
|
+
* When implementing the registerOnChange method in your own value accessor, save the given function so your class calls it at the appropriate time.
|
|
140
|
+
*
|
|
141
|
+
* ```ts
|
|
142
|
+
* registerOnChange(fn: (_: any) => void): void {
|
|
143
|
+
* this._onChange = fn;
|
|
144
|
+
* }
|
|
145
|
+
* ```
|
|
146
|
+
*
|
|
147
|
+
* When the value changes in the UI, call the registered function to allow the forms API to update itself:
|
|
148
|
+
*
|
|
149
|
+
* ```ts
|
|
150
|
+
*
|
|
151
|
+
* onChange(event: Event){
|
|
152
|
+
*
|
|
153
|
+
* }
|
|
154
|
+
*
|
|
155
|
+
* ```
|
|
156
|
+
* @param fn the function to be called when a control want to change the value of a form associated element.
|
|
157
|
+
*/
|
|
158
|
+
registerOnChange(fn: (value?: T | null) => void): void;
|
|
159
|
+
/**
|
|
160
|
+
* called when `disabled` attribute change.
|
|
161
|
+
* @param isDisabled
|
|
162
|
+
*/
|
|
163
|
+
setDisabledState?(isDisabled: boolean): void;
|
|
164
|
+
}
|
|
165
|
+
export declare function isValueControl(obj: any): obj is ValueControl;
|
|
166
|
+
export interface BaseFormAssociatedComponent<T extends Object> extends BaseComponent<T>, FormAssociatedCustomElement {
|
|
167
|
+
readonly internals: ElementInternals;
|
|
168
|
+
readonly form: HTMLFormElement | null;
|
|
169
|
+
readonly valueControl?: ValueControl<T>;
|
|
170
|
+
registerValueControl(valueControl: ValueControl): void;
|
|
95
171
|
}
|
|
96
|
-
export interface
|
|
172
|
+
export interface FormAssociatedComponent<T extends Object, V = any> extends BaseFormAssociatedComponent<T>, HTMLComponent<T> {
|
|
173
|
+
value: V | null;
|
|
97
174
|
}
|
|
98
175
|
export declare type HTMLFormElement = HTMLButtonElement | HTMLDataListElement | HTMLFieldSetElement | HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
|
|
176
|
+
export interface ConstructorOfView<T> {
|
|
177
|
+
new (): T;
|
|
178
|
+
readonly prototype: T;
|
|
179
|
+
}
|
|
@@ -12,4 +12,10 @@ export function isHTMLElement(element) {
|
|
|
12
12
|
export function isHTMLUnknownElement(element) {
|
|
13
13
|
return element && element instanceof HTMLUnknownElement && !element.tagName?.includes('-');
|
|
14
14
|
}
|
|
15
|
+
export function isValueControl(obj) {
|
|
16
|
+
return obj
|
|
17
|
+
&& typeof obj === 'object'
|
|
18
|
+
&& typeof obj.writeValue === 'function'
|
|
19
|
+
&& typeof obj.registerOnChange === 'function';
|
|
20
|
+
}
|
|
15
21
|
//# sourceMappingURL=custom-element.js.map
|
|
@@ -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":"AAwDA,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;AAqHD,MAAM,UAAU,cAAc,CAAC,GAAQ;IACtC,OAAO,GAAG;WACN,OAAO,GAAG,KAAK,QAAQ;WACvB,OAAO,GAAG,CAAC,UAAU,KAAK,UAAU;WACpC,OAAO,GAAG,CAAC,gBAAgB,KAAK,UAAU,CAAC;AAChD,CAAC","sourcesContent":["import type { ReactiveScope, ReactiveScopeControl, Context } from '@ibyar/expressions';\nimport type { TypeOf } from '../utils/typeof.js';\nimport { EventEmitter } from './events.js';\nimport { ComponentRef } from './component.js';\nimport { AuroraZone } from '../zone/zone.js';\nimport { PropertyRef } from './reflect.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 & Context;\n\nexport type NodeContextType<T> = { 'this': BaseComponent<T> };\n\nexport interface BaseComponent<T> extends CustomElement {\n\n\t_model: ModelType<T>;\n\t_modelScope: ReactiveScopeControl<T & Context>;\n\n\t_viewScope: ReactiveScope<{ 'this': BaseComponent<T> }>;\n\t_zone: AuroraZone;\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\tonDestroy(callback: () => void): void;\n\n\t/**\n\t * apply change detection\n\t */\n\tdetectChanges(): void;\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 FormAssociatedCustomElement 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 | null): 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 auto filling 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 type WriteValueMode = 'restore' | 'autocomplete' | 'reset';\n\nexport type WriteValueOptions<T> = { value: T | null, mode?: 'restore' | 'autocomplete' } | { value?: undefined, mode: 'reset' };\n\n\nexport interface ValueControl<T = any> {\n\t/**\n\t * reset the value of the\n\t * @param value \n\t * @param mode \n\t */\n\twriteValue(opt: { value?: undefined, mode: 'reset' }): void;\n\n\t/**\n\t * \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 auto filling sets a value.\n\t * The mode argument is \"autocomplete\" in this case.\n\t * \n\t * @param opt: options contain the `value` to be written and `mode` represented by `restore` or `autocomplete` or `undefined`\n\t */\n\n\twriteValue(opt: { value: T | null, mode?: 'restore' | 'autocomplete' }): void;\n\n\twriteValue(opt: { value?: T | null, mode?: WriteValueMode }): void;\n\n\twriteValue(opt: WriteValueOptions<T>): void;\n\n\t/**\n\t * This method is called when new `ValueControl` assigned to the form associated element.\n\t * \n\t * When implementing the registerOnChange method in your own value accessor, save the given function so your class calls it at the appropriate time.\n\t * \n\t * ```ts\n\t * registerOnChange(fn: (_: any) => void): void {\n\t * \tthis._onChange = fn;\n\t * }\n\t * ```\n\t * \n\t * When the value changes in the UI, call the registered function to allow the forms API to update itself:\n\t * \n\t * ```ts\n\t * \n\t * onChange(event: Event){\n\t * \t\n\t * }\n\t * \n\t * ```\n\t * @param fn the function to be called when a control want to change the value of a form associated element.\n\t */\n\n\tregisterOnChange(fn: (value?: T | null) => void): void;\n\n\t/**\n\t * called when `disabled` attribute change.\n\t * @param isDisabled \n\t */\n\tsetDisabledState?(isDisabled: boolean): void;\n}\n\nexport function isValueControl(obj: any): obj is ValueControl {\n\treturn obj\n\t\t&& typeof obj === 'object'\n\t\t&& typeof obj.writeValue === 'function'\n\t\t&& typeof obj.registerOnChange === 'function';\n}\n\nexport interface BaseFormAssociatedComponent<T extends Object> extends BaseComponent<T>, FormAssociatedCustomElement {\n\treadonly internals: ElementInternals;\n\treadonly form: HTMLFormElement | null;\n\treadonly valueControl?: ValueControl<T>;\n\n\tregisterValueControl(valueControl: ValueControl): void;\n}\n\nexport interface FormAssociatedComponent<T extends Object, V = any> extends BaseFormAssociatedComponent<T>, HTMLComponent<T> {\n\n\tvalue: V | null;\n}\n\nexport type HTMLFormElement = HTMLButtonElement | HTMLDataListElement | HTMLFieldSetElement | HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;\n\n\nexport interface ConstructorOfView<T> {\n\tnew(): T;\n\treadonly prototype: T;\n}\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ChildOptions, OutputEventInit } from '../annotation/decorators.js';
|
|
2
|
+
import type { ComponentRef } from './component.js';
|
|
3
|
+
export declare class PropertyRef {
|
|
4
|
+
modelProperty: string;
|
|
5
|
+
protected _viewName?: string | undefined;
|
|
6
|
+
constructor(modelProperty: string, _viewName?: string | undefined);
|
|
7
|
+
get viewAttribute(): string;
|
|
8
|
+
}
|
|
9
|
+
export declare class InputPropertyRef extends PropertyRef {
|
|
10
|
+
}
|
|
11
|
+
export declare class OutputPropertyRef extends PropertyRef {
|
|
12
|
+
options?: OutputEventInit | undefined;
|
|
13
|
+
constructor(modelProperty: string, viewName?: string, options?: OutputEventInit | undefined);
|
|
14
|
+
}
|
|
15
|
+
export declare class ChildRef {
|
|
16
|
+
modelName: string;
|
|
17
|
+
selector: string | {
|
|
18
|
+
new (): HTMLElement;
|
|
19
|
+
prototype: HTMLElement;
|
|
20
|
+
} | CustomElementConstructor;
|
|
21
|
+
childOptions?: ChildOptions | undefined;
|
|
22
|
+
constructor(modelName: string, selector: string | {
|
|
23
|
+
new (): HTMLElement;
|
|
24
|
+
prototype: HTMLElement;
|
|
25
|
+
} | CustomElementConstructor, childOptions?: ChildOptions | undefined);
|
|
26
|
+
}
|
|
27
|
+
export declare class ListenerRef {
|
|
28
|
+
eventName: string;
|
|
29
|
+
args: string[];
|
|
30
|
+
modelCallbackName: string;
|
|
31
|
+
constructor(eventName: string, args: string[], modelCallbackName: string);
|
|
32
|
+
}
|
|
33
|
+
export declare class HostBindingRef {
|
|
34
|
+
viewProperty: string;
|
|
35
|
+
hostPropertyName: string;
|
|
36
|
+
constructor(viewProperty: string, hostPropertyName: string);
|
|
37
|
+
}
|
|
38
|
+
export interface BootstrapMetadata {
|
|
39
|
+
[key: string]: any;
|
|
40
|
+
}
|
|
41
|
+
export declare class ReflectComponents {
|
|
42
|
+
static getOrCreateBootstrap<T extends {}>(target: Object): T;
|
|
43
|
+
static getBootstrap<T extends {}>(target: Object): T;
|
|
44
|
+
static getComponentRef<T>(target: object): ComponentRef<T>;
|
|
45
|
+
static setComponentRef<T>(target: object, componentRef: ComponentRef<T>): void;
|
|
46
|
+
static addOptional(modelProperty: Object): void;
|
|
47
|
+
static addInput(modelProperty: Object, modelName: string, viewName: string): void;
|
|
48
|
+
static addOutput(modelProperty: Object, modelName: string, viewName: string, options: OutputEventInit): void;
|
|
49
|
+
static setComponentView(modelProperty: Object, modelName: string): void;
|
|
50
|
+
static addViewChild(modelProperty: Object, modelName: string, selector: string | typeof HTMLElement | CustomElementConstructor, childOptions?: ChildOptions): void;
|
|
51
|
+
static addViewChildren(modelProperty: Object, modelName: string, selector: string | typeof HTMLElement | CustomElementConstructor): void;
|
|
52
|
+
static addHostListener(modelProperty: Object, propertyKey: string, eventName: string, args: string[]): void;
|
|
53
|
+
static addHostBinding(modelProperty: Object, propertyKey: string, hostPropertyName: string): void;
|
|
54
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export class PropertyRef {
|
|
2
|
+
constructor(modelProperty, _viewName) {
|
|
3
|
+
this.modelProperty = modelProperty;
|
|
4
|
+
this._viewName = _viewName;
|
|
5
|
+
}
|
|
6
|
+
get viewAttribute() {
|
|
7
|
+
return this._viewName || this.modelProperty;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export class InputPropertyRef extends PropertyRef {
|
|
11
|
+
}
|
|
12
|
+
export class OutputPropertyRef extends PropertyRef {
|
|
13
|
+
constructor(modelProperty, viewName, options) {
|
|
14
|
+
super(modelProperty, viewName);
|
|
15
|
+
this.options = options;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export class ChildRef {
|
|
19
|
+
constructor(modelName, selector, childOptions) {
|
|
20
|
+
this.modelName = modelName;
|
|
21
|
+
this.selector = selector;
|
|
22
|
+
this.childOptions = childOptions;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export class ListenerRef {
|
|
26
|
+
constructor(eventName, args, modelCallbackName) {
|
|
27
|
+
this.eventName = eventName;
|
|
28
|
+
this.args = args;
|
|
29
|
+
this.modelCallbackName = modelCallbackName;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class HostBindingRef {
|
|
33
|
+
constructor(viewProperty, hostPropertyName) {
|
|
34
|
+
this.viewProperty = viewProperty;
|
|
35
|
+
this.hostPropertyName = hostPropertyName;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const AuroraBootstrap = Symbol.for('aurora:bootstrap');
|
|
39
|
+
const AuroraMetadata = Symbol.for('aurora:metadata');
|
|
40
|
+
export class ReflectComponents {
|
|
41
|
+
static getOrCreateBootstrap(target) {
|
|
42
|
+
let bootstrap = Reflect.getMetadata(AuroraBootstrap, target);
|
|
43
|
+
if (!bootstrap) {
|
|
44
|
+
bootstrap = {};
|
|
45
|
+
Reflect.defineMetadata(AuroraBootstrap, bootstrap, target);
|
|
46
|
+
}
|
|
47
|
+
return bootstrap;
|
|
48
|
+
}
|
|
49
|
+
static getBootstrap(target) {
|
|
50
|
+
return Reflect.getMetadata(AuroraBootstrap, target);
|
|
51
|
+
}
|
|
52
|
+
static getComponentRef(target) {
|
|
53
|
+
return Reflect.getMetadata(AuroraMetadata, target);
|
|
54
|
+
}
|
|
55
|
+
static setComponentRef(target, componentRef) {
|
|
56
|
+
Reflect.defineMetadata(AuroraMetadata, componentRef, target);
|
|
57
|
+
}
|
|
58
|
+
static addOptional(modelProperty) {
|
|
59
|
+
}
|
|
60
|
+
static addInput(modelProperty, modelName, viewName) {
|
|
61
|
+
const bootstrap = ReflectComponents.getOrCreateBootstrap(modelProperty);
|
|
62
|
+
bootstrap.inputs = bootstrap.inputs || [];
|
|
63
|
+
bootstrap.inputs.push(new InputPropertyRef(modelName, viewName));
|
|
64
|
+
}
|
|
65
|
+
static addOutput(modelProperty, modelName, viewName, options) {
|
|
66
|
+
const bootstrap = ReflectComponents.getOrCreateBootstrap(modelProperty);
|
|
67
|
+
bootstrap.outputs = bootstrap.outputs || [];
|
|
68
|
+
bootstrap.outputs.push(new OutputPropertyRef(modelName, viewName, options));
|
|
69
|
+
}
|
|
70
|
+
static setComponentView(modelProperty, modelName) {
|
|
71
|
+
const bootstrap = ReflectComponents.getOrCreateBootstrap(modelProperty);
|
|
72
|
+
bootstrap.view = modelName;
|
|
73
|
+
}
|
|
74
|
+
static addViewChild(modelProperty, modelName, selector, childOptions) {
|
|
75
|
+
const bootstrap = ReflectComponents.getOrCreateBootstrap(modelProperty);
|
|
76
|
+
bootstrap.viewChild = bootstrap.viewChild || [];
|
|
77
|
+
bootstrap.viewChild.push(new ChildRef(modelName, selector, childOptions));
|
|
78
|
+
}
|
|
79
|
+
static addViewChildren(modelProperty, modelName, selector) {
|
|
80
|
+
const bootstrap = ReflectComponents.getOrCreateBootstrap(modelProperty);
|
|
81
|
+
bootstrap.ViewChildren = bootstrap.ViewChildren || [];
|
|
82
|
+
bootstrap.ViewChildren.push(new ChildRef(modelName, selector));
|
|
83
|
+
}
|
|
84
|
+
static addHostListener(modelProperty, propertyKey, eventName, args) {
|
|
85
|
+
const bootstrap = ReflectComponents.getOrCreateBootstrap(modelProperty);
|
|
86
|
+
bootstrap.hostListeners = bootstrap.hostListeners || [];
|
|
87
|
+
bootstrap.hostListeners.push(new ListenerRef(eventName, args, propertyKey));
|
|
88
|
+
}
|
|
89
|
+
static addHostBinding(modelProperty, propertyKey, hostPropertyName) {
|
|
90
|
+
const bootstrap = ReflectComponents.getOrCreateBootstrap(modelProperty);
|
|
91
|
+
bootstrap.hostBinding = bootstrap.hostBinding || [];
|
|
92
|
+
bootstrap.hostBinding.push(new HostBindingRef(propertyKey, hostPropertyName));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=reflect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reflect.js","sourceRoot":"","sources":["../../../src/core/component/reflect.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,WAAW;IACvB,YAAmB,aAAqB,EAAY,SAAkB;QAAnD,kBAAa,GAAb,aAAa,CAAQ;QAAY,cAAS,GAAT,SAAS,CAAS;IAAI,CAAC;IAC3E,IAAI,aAAa;QAChB,OAAO,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,aAAa,CAAC;IAC7C,CAAC;CACD;AAED,MAAM,OAAO,gBAAiB,SAAQ,WAAW;CAEhD;AAED,MAAM,OAAO,iBAAkB,SAAQ,WAAW;IACjD,YAAY,aAAqB,EAAE,QAAiB,EAAS,OAAyB;QACrF,KAAK,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;QAD6B,YAAO,GAAP,OAAO,CAAkB;IAEtF,CAAC;CACD;AAED,MAAM,OAAO,QAAQ;IACpB,YACQ,SAAiB,EACjB,QAA4F,EAC5F,YAA2B;QAF3B,cAAS,GAAT,SAAS,CAAQ;QACjB,aAAQ,GAAR,QAAQ,CAAoF;QAC5F,iBAAY,GAAZ,YAAY,CAAe;IAC/B,CAAC;CACL;AAED,MAAM,OAAO,WAAW;IACvB,YAAmB,SAAiB,EAAS,IAAc,EAAS,iBAAyB;QAA1E,cAAS,GAAT,SAAS,CAAQ;QAAS,SAAI,GAAJ,IAAI,CAAU;QAAS,sBAAiB,GAAjB,iBAAiB,CAAQ;IAAI,CAAC;CAClG;AAED,MAAM,OAAO,cAAc;IAC1B,YAAmB,YAAoB,EA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,MAAM,CAAC,eAAe,CAAC,aAAqB,EAAE,WAAmB,EAAE,SAAiB,EAAE,IAAc;QACnG,MAAM,SAAS,GAAsB,iBAAiB,CAAC,oBAAoB,CAAC,aAAa,CAAC,CAAC;QAC3F,SAAS,CAAC,aAAa,GAAG,SAAS,CAAC,aAAa,IAAI,EAAE,CAAC;QACxD,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,SAAS,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC;IAC7E,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,aAAqB,EAAE,WAAmB,EAAE,gBAAwB;QACzF,MAAM,SAAS,GAAsB,iBAAiB,CAAC,oBAAoB,CAAC,aAAa,CAAC,CAAC;QAC3F,SAAS,CAAC,WAAW,GAAG,SAAS,CAAC,WAAW,IAAI,EAAE,CAAC;QACpD,SAAS,CAAC,WAAW,CAAC,IAAI,CACzB,IAAI,cAAc,CAAC,WAAW,EAAE,gBAAgB,CAAC,CACjD,CAAC;IACH,CAAC;CACD","sourcesContent":["import type { ChildOptions, OutputEventInit } from '../annotation/decorators.js';\nimport type { ComponentRef } from './component.js';\n\nexport class PropertyRef {\n\tconstructor(public modelProperty: string, protected _viewName?: string) { }\n\tget viewAttribute(): string {\n\t\treturn this._viewName || this.modelProperty;\n\t}\n}\n\nexport class InputPropertyRef extends PropertyRef {\n\n}\n\nexport class OutputPropertyRef extends PropertyRef {\n\tconstructor(modelProperty: string, viewName?: string, public options?: OutputEventInit) {\n\t\tsuper(modelProperty, viewName);\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\nconst AuroraBootstrap = Symbol.for('aurora:bootstrap');\nconst AuroraMetadata = Symbol.for('aurora:metadata');\n\n\nexport class ReflectComponents {\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 = ReflectComponents.getOrCreateBootstrap(modelProperty);\n\t\tbootstrap.inputs = bootstrap.inputs || [];\n\t\tbootstrap.inputs.push(new InputPropertyRef(modelName, viewName));\n\t}\n\n\tstatic addOutput(modelProperty: Object, modelName: string, viewName: string, options: OutputEventInit) {\n\t\tconst bootstrap: BootstrapMetadata = ReflectComponents.getOrCreateBootstrap(modelProperty);\n\t\tbootstrap.outputs = bootstrap.outputs || [];\n\t\tbootstrap.outputs.push(new OutputPropertyRef(modelName, viewName, options));\n\t}\n\n\tstatic setComponentView(modelProperty: Object, modelName: string) {\n\t\tconst bootstrap: BootstrapMetadata = ReflectComponents.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 = ReflectComponents.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 = ReflectComponents.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 = ReflectComponents.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 = ReflectComponents.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"]}
|