@ibyar/core 0.8.3 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/annotation/decorators.d.ts +33 -9
- package/annotation/decorators.js +1 -0
- package/annotation/decorators.js.map +1 -1
- package/binding/binding.expressions.d.ts +3 -3
- package/binding/binding.expressions.js +9 -9
- package/binding/binding.expressions.js.map +1 -1
- package/component/component.d.ts +9 -4
- package/component/component.js +41 -12
- package/component/component.js.map +1 -1
- package/component/custom-element.d.ts +5 -5
- package/component/reflect.d.ts +2 -2
- package/component/reflect.js +9 -9
- package/component/reflect.js.map +1 -1
- package/directive/directive.d.ts +7 -3
- package/directive/directive.js +6 -3
- package/directive/directive.js.map +1 -1
- package/directive/parser.d.ts +1 -1
- package/directive/parser.js +12 -12
- package/directive/parser.js.map +1 -1
- package/directive/providers.d.ts +1 -1
- package/html/expression.js +29 -2
- package/html/expression.js.map +1 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/index.js.map +1 -1
- package/package.json +17 -7
- package/pipe/pipe.js +3 -3
- package/pipe/pipe.js.map +1 -1
- package/providers/provider.d.ts +1 -1
- package/render/host-binding.handler.d.ts +46 -0
- package/render/host-binding.handler.js +60 -0
- package/render/host-binding.handler.js.map +1 -0
- package/render/host-listener.handler.d.ts +16 -9
- package/render/host-listener.handler.js +17 -15
- package/render/host-listener.handler.js.map +1 -1
- package/utils/elements-util.d.ts +1 -0
- package/utils/elements-util.js +7 -1
- package/utils/elements-util.js.map +1 -1
- package/utils/path.d.ts +1 -1
- package/view/base-view.js +8 -15
- package/view/base-view.js.map +1 -1
- package/view/form-view.js +69 -66
- package/view/form-view.js.map +1 -1
- package/view/render.d.ts +20 -3
- package/view/render.js +110 -87
- package/view/render.js.map +1 -1
- package/view/utils.js +12 -12
- package/view/utils.js.map +1 -1
- package/view/view.d.ts +3 -1
- package/view/view.js +9 -1
- package/view/view.js.map +1 -1
- package/zone/bootstrap.d.ts +3 -3
- package/zone/bootstrap.js +1 -11
- package/zone/bootstrap.js.map +1 -1
- package/zone/proxy.d.ts +3 -2
- package/zone/proxy.js +6 -3
- package/zone/proxy.js.map +1 -1
- package/zone/task.js +8 -8
- package/zone/task.js.map +1 -1
- package/zone/zone.d.ts +5 -4
- package/zone/zone.js +22 -3
- package/zone/zone.js.map +1 -1
|
@@ -11,6 +11,22 @@ export interface DirectiveOptions {
|
|
|
11
11
|
* and an attributes directive should not.
|
|
12
12
|
*/
|
|
13
13
|
selector: string;
|
|
14
|
+
/**
|
|
15
|
+
* - use `manual` for no zone.js patch effect applied,
|
|
16
|
+
* and used for manual change detection for heavily process components.
|
|
17
|
+
*
|
|
18
|
+
* - use `proxy` zone for automatic detect changes without use of `zone.js`
|
|
19
|
+
*
|
|
20
|
+
* - use `aurora` for detection events like `rxjs` observables, `setTimeout`,
|
|
21
|
+
* `setInterval` and `fetch` and `XMLHttpRequest`, etc...
|
|
22
|
+
* make sure that `zone.js` is imported in the polyfills module.
|
|
23
|
+
*
|
|
24
|
+
* if no value specified, the value will be initialized by the custom element `web component` zone,
|
|
25
|
+
* - if the web component zone is `manual`, the directive zone also will be `manual`, expect weird behavior.
|
|
26
|
+
* - if the web component zone is `proxy`, the directive zone also will be `proxy`.
|
|
27
|
+
* - if the web component zone is `aurora`, the directive zone also will be `aurora` and will get the benefit of `zone.js`.
|
|
28
|
+
*/
|
|
29
|
+
zone?: ZoneType;
|
|
14
30
|
}
|
|
15
31
|
export interface ServiceOptions {
|
|
16
32
|
provideIn?: TypeOf<CustomElementConstructor> | 'root' | 'platform' | 'any';
|
|
@@ -212,22 +228,30 @@ export interface ComponentOptions<T = Function> {
|
|
|
212
228
|
*/
|
|
213
229
|
formAssociated?: boolean | TypeOf<ValueControl<any>>;
|
|
214
230
|
/**
|
|
215
|
-
* use `
|
|
216
|
-
* and used for manual change detection for heavily process components
|
|
217
|
-
*
|
|
231
|
+
* - use `manual` for no zone.js patch effect applied,
|
|
232
|
+
* and used for manual change detection for heavily process components.
|
|
233
|
+
*
|
|
234
|
+
* - use `proxy` zone for automatic detect changes without use of `zone.js`
|
|
235
|
+
*
|
|
236
|
+
* - use `aurora` for detection events like `rxjs` observables, `setTimeout`,
|
|
218
237
|
* `setInterval` and `fetch` and `XMLHttpRequest`, etc...
|
|
219
238
|
* make sure that `zone.js` is imported in the polyfills module.
|
|
220
239
|
*
|
|
221
|
-
* the default is the platform which
|
|
240
|
+
* the default value is the platform zone type which can be changed by:
|
|
222
241
|
*
|
|
223
242
|
* ```js
|
|
224
|
-
* bootstrapZone('
|
|
243
|
+
* bootstrapZone('manual')
|
|
244
|
+
* bootstrapZone('proxy')
|
|
225
245
|
* bootstrapZone('aurora')
|
|
226
246
|
* ```
|
|
227
247
|
*
|
|
228
|
-
* if `bootstrapZone` never been called, then the default zone is a
|
|
248
|
+
* if `bootstrapZone` never been called, then the default zone is a `manual`.
|
|
229
249
|
*/
|
|
230
250
|
zone?: ZoneType;
|
|
251
|
+
/**
|
|
252
|
+
* The imports property specifies the component's template dependencies — those directives, components, and pipes that can be used within its template.
|
|
253
|
+
*/
|
|
254
|
+
imports?: (TypeOf<any> | ReadonlyArray<any>)[];
|
|
231
255
|
}
|
|
232
256
|
export interface ChildOptions {
|
|
233
257
|
[key: string]: any;
|
|
@@ -238,8 +262,8 @@ export interface ViewChildOpt {
|
|
|
238
262
|
}
|
|
239
263
|
export declare function Input(name?: string): Function;
|
|
240
264
|
export declare function FormValue(): Function;
|
|
241
|
-
export
|
|
242
|
-
export
|
|
265
|
+
export type OutputEventInit = Omit<EventInit, 'cancelable'>;
|
|
266
|
+
export type OutputOptions = {
|
|
243
267
|
name?: string;
|
|
244
268
|
} & OutputEventInit;
|
|
245
269
|
export declare function Output(options?: OutputOptions): Function;
|
|
@@ -247,7 +271,7 @@ export declare function Output(name?: string, options?: OutputEventInit): Functi
|
|
|
247
271
|
export declare function View(): Function;
|
|
248
272
|
export declare function ViewChild(selector: string | typeof HTMLElement | CustomElementConstructor, childOptions?: ChildOptions): Function;
|
|
249
273
|
export declare function ViewChildren(selector: string | typeof HTMLElement | CustomElementConstructor): Function;
|
|
250
|
-
export declare function HostListener(eventName: string, args?: string[]): Function;
|
|
274
|
+
export declare function HostListener(eventName: string, args?: string | string[]): Function;
|
|
251
275
|
export declare function HostBinding(hostPropertyName: string): Function;
|
|
252
276
|
export declare function Pipe(opt: PipeOptions): Function;
|
|
253
277
|
export declare function Service(opt: ServiceOptions): Function;
|
package/annotation/decorators.js
CHANGED
|
@@ -38,6 +38,7 @@ export function ViewChildren(selector) {
|
|
|
38
38
|
}
|
|
39
39
|
export function HostListener(eventName, args) {
|
|
40
40
|
return (target, propertyKey) => {
|
|
41
|
+
args = typeof args === 'string' ? [args] : args;
|
|
41
42
|
ReflectComponents.addHostListener(target, propertyKey, eventName, args || []);
|
|
42
43
|
};
|
|
43
44
|
}
|
|
@@ -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,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAe,MAAM,kBAAkB,CAAC;AAyP1D,MAAM,UAAU,KAAK,CAAC,IAAa;IAClC,OAAO,CAAC,MAAc,EAAE,WAAmB,EAAE,EAAE;QAC9C,iBAAiB,CAAC,QAAQ,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,IAAI,WAAW,CAAC,CAAC;IACtE,CAAC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,SAAS;IACxB,OAAO,CAAC,MAAc,EAAE,WAAmB,EAAE,EAAE;QAC9C,iBAAiB,CAAC,QAAQ,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC,CAAC;AACH,CAAC;AAOD,MAAM,UAAU,MAAM,CAAC,IAA6B,EAAE,OAAyB;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AC,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,aAAa,CAAwB,GAAoD;IACxG,OAAO,CAAC,MAAiB,EAAE,EAAE;QAC5B,UAAU,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACnC,OAAO,MAAM,CAAC;IACf,CAAC,CAAC;AACH,CAAC","sourcesContent":["import type { TypeOf } from '../utils/typeof.js';\nimport { DomNode } from '@ibyar/elements';\nimport { Components } from '../component/component.js';\nimport { ReflectComponents } from '../component/reflect.js';\nimport { fetchHtml, TemplateUrl } from '../utils/path.js';\nimport { ZoneType } from '../zone/bootstrap.js';\nimport { ValueControl } from '../component/custom-element.js';\n\n\nexport interface DirectiveOptions {\n\n\t/**\n\t * the name of the directive which is used in the template\n\t * \n\t * a structural directive name should start with `*`,\n\t * and an attributes directive should not.\n\t */\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;\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?: keyof HTMLElementTagNameMap;\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\t/**\n\t * Create a custom form-associated element with HTMLElement.attachInternals\n\t * default: false\n\t * \n\t * if the value is `true` it is expected from the model class to implement `ValueControl<T>` interface\n\t * \n\t * otherwise you can register another class that implement `ValueControl<T>`,\n\t * in case if you want split the model and the value controller.\n\t * \n\t * #### Usage Notes:\n\t * \n\t * ```ts\n\t * \n\t * @Component({\n\t * \tselector: 'custom-message',\n\t * \ttemplate: `\n\t * \t\t<label for=\"message\">Message</label>\n\t * \t\t<textarea id=\"message\" [(value)]=\"message\" [disabled]=\"disabled\" (change)=\"onMessageChange($event.target.value)\"></textarea>\n\t * \t`,\n\t * \tformAssociated: true,\n\t * \t// formAssociated: CustomMessage,\n\t * })\n\t * export class CustomMessage implements ValueControl<string> {\n\t * \n\t * \tprivate message: string | null = '';\n\t * \tprivate disabled: boolean = false;\n\t * \tprivate _onChange: (_: any) => void = () => {};\n\t * \n\t * \twriteValue({ value, mode }: WriteValueOptions<string>) {\n\t * \t\tthis.message = mode !== 'reset' ? value : '';\n\t * \t}\n\t * \n\t * \tregisterOnChange(fn: (_: any) => void): void {\n\t * \t\tthis._onChange = fn;\n\t * \t}\n\t * \n\t * \tsetDisabledState(isDisabled: boolean) {\n\t * \t\tthis.disabled = isDisabled;\n\t * \t}\n\t * \n\t * \tonMessageChange(message: string) {\n\t * \t\tthis._onChange(message);\n\t * \t}\n\t * \t\n\t * }\n\t * \n\t * \n\t * export class CustomInputValueControl implements ValueControl<number> {\n\t * \n\t * \tprivate _value: number | null = null;\n\t * \tprivate _disabled: boolean = false;\n\t * \tprivate _onChange: (_: any) => void = () => {};\n\t * \n\t * \twriteValue({ value, mode }: WriteValueOptions<number>) {\n\t * \t\tthis._value = mode !== 'reset' ? value : null;\n\t * \t}\n\t * \n\t * \tregisterOnChange(fn: (_: any) => void): void {\n\t * \t\tthis._onChange = fn;\n\t * \t}\n\t * \n\t * \tsetDisabledState(isDisabled: boolean) {\n\t * \t\tthis._disabled = isDisabled;\n\t * \t}\n\t * \t\n\t * }\n\t * \n\t * @Component({\n\t * \tselector: 'custom-input',\n\t * \textend: 'input',\n\t * \tformAssociated: CustomInputValueControl,\n\t * })\n\t * export class CustomInputElement {\n\t * \t@View()\n\t * \tview: HTMLInputElement;\n\t * \n\t * \tonInit() {\n\t * \t\tthis.view.type = 'number';\n\t * \t}\n\t * }\n\t * \n\t * ```\n\t */\n\tformAssociated?: boolean | TypeOf<ValueControl<any>>;\n\n\t/**\n\t * use `noop` to no zone.js patch effect applied,\n\t * and used for manual change detection for heavily process components\n\t * use `aurora` for detection events like `rxjs` observables, `setTimeout`,\n\t * `setInterval` and `fetch` and `XMLHttpRequest`, etc...\n\t * make sure that `zone.js` is imported in the polyfills module. \n\t * \n\t * the default is the platform which is initialized using\n\t * \n\t * ```js\n\t * bootstrapZone('noop')\n\t * bootstrapZone('aurora')\n\t * ```\n\t * \n\t * if `bootstrapZone` never been called, then the default zone is a noop zone.\n\t */\n\tzone?: ZoneType;\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\tReflectComponents.addInput(target, propertyKey, name || propertyKey);\n\t};\n}\n\nexport function FormValue(): Function {\n\treturn (target: Object, propertyKey: string) => {\n\t\tReflectComponents.addInput(target, propertyKey, 'value');\n\t};\n}\n\nexport type OutputEventInit = Omit<EventInit, 'cancelable'>;\nexport type OutputOptions = { name?: string } & OutputEventInit;\n\nexport function Output(options?: OutputOptions): Function;\nexport function Output(name?: string, options?: OutputEventInit): Function;\nexport function Output(name?: string | OutputOptions, options?: OutputEventInit): Function {\n\tconst eventType = typeof name === 'object' ? name.name : name;\n\tconst eventOpts = typeof name === 'object' ? name : options;\n\treturn (target: Object, propertyKey: string) => {\n\t\tReflectComponents.addOutput(\n\t\t\ttarget,\n\t\t\tpropertyKey, eventType || propertyKey,\n\t\t\t{\n\t\t\t\tbubbles: eventOpts?.bubbles ?? false,\n\t\t\t\tcomposed: eventOpts?.composed ?? false\n\t\t\t}\n\t\t);\n\t};\n}\n\nexport function View(): Function {\n\treturn (target: Object, propertyKey: string) => {\n\t\tReflectComponents.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\tReflectComponents.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\tReflectComponents.addViewChildren(target, propertyKey, selector);\n\t};\n}\n\nexport function HostListener(eventName: string, args?: string[]): Function {\n\treturn (target: Object, propertyKey: string) => {\n\t\tReflectComponents.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\tReflectComponents.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\nfunction generateComponent<T extends { new(...args: any[]): {} }>(target: TypeOf<T>, opt: ComponentOptions<T>) {\n\tif (opt.templateUrl) {\n\t\tfetchHtml(opt.templateUrl)\n\t\t\t.then(htmlTemplate => {\n\t\t\t\tif (htmlTemplate) {\n\t\t\t\t\topt.template = htmlTemplate;\n\t\t\t\t\tComponents.defineComponent(target, opt);\n\t\t\t\t}\n\t\t\t})\n\t\t\t.catch(reason => {\n\t\t\t\tconsole.error(`Error @URL: ${opt.templateUrl}, for model Class: ${target.name},\\n Reason: ${reason}.`);\n\t\t\t});\n\t} else {\n\t\tComponents.defineComponent(target, opt);\n\t}\n}\n\nexport function Component<T extends { new(...args: any[]): {} }>(opt: ComponentOptions<T> | ComponentOptions<T>[]): Function {\n\treturn (target: TypeOf<T>) => {\n\t\tif (Array.isArray(opt)) {\n\t\t\tfor (const comp of opt) {\n\t\t\t\tgenerateComponent(target, comp);\n\t\t\t}\n\t\t} else if (typeof opt === 'object') {\n\t\t\tgenerateComponent(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\nexport function customElement<T extends HTMLElement>(opt: { selector: string } & ElementDefinitionOptions): Function {\n\treturn (target: TypeOf<T>) => {\n\t\tComponents.defineView(target, opt);\n\t\treturn target;\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,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAe,MAAM,kBAAkB,CAAC;AAmR1D,MAAM,UAAU,KAAK,CAAC,IAAa;IAClC,OAAO,CAAC,MAAc,EAAE,WAAmB,EAAE,EAAE;QAC9C,iBAAiB,CAAC,QAAQ,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,IAAI,WAAW,CAAC,CAAC;IACtE,CAAC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,SAAS;IACxB,OAAO,CAAC,MAAc,EAAE,WAAmB,EAAE,EAAE;QAC9C,iBAAiB,CAAC,QAAQ,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC,CAAC;AACH,CAAC;AAOD,MAAM,UAAU,MAAM,CAAC,IAA6B,EAAE,OAAyB;IAC9E,MAAM,SAAS,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IAC9D,MAAM,SAAS,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;IAC5D,OAAO,CAAC,MAAc,EAAE,WAAmB,EAAE,EAAE;QAC9C,iBAAiB,CAAC,SAAS,CAC1B,MAAM,EACN,WAAW,EAAE,SAAS,IAAI,WAAW,EACrC;YACC,OAAO,EAAE,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AAG,CAAC,CAAC;QACnC,OAAO,MAAM,CAAC;IACf,CAAC,CAAC;AACH,CAAC","sourcesContent":["import type { TypeOf } from '../utils/typeof.js';\nimport { DomNode } from '@ibyar/elements';\nimport { Components } from '../component/component.js';\nimport { ReflectComponents } from '../component/reflect.js';\nimport { fetchHtml, TemplateUrl } from '../utils/path.js';\nimport { ZoneType } from '../zone/bootstrap.js';\nimport { ValueControl } from '../component/custom-element.js';\n\n\nexport interface DirectiveOptions {\n\n\t/**\n\t * the name of the directive which is used in the template\n\t * \n\t * a structural directive name should start with `*`,\n\t * and an attributes directive should not.\n\t */\n\tselector: string;\n\n\t/**\n\t * - use `manual` for no zone.js patch effect applied,\n\t * and used for manual change detection for heavily process components.\n\t * \n\t * - use `proxy` zone for automatic detect changes without use of `zone.js`\n\t * \n\t * - use `aurora` for detection events like `rxjs` observables, `setTimeout`,\n\t * `setInterval` and `fetch` and `XMLHttpRequest`, etc...\n\t * make sure that `zone.js` is imported in the polyfills module. \n\t * \n\t * if no value specified, the value will be initialized by the custom element `web component` zone,\n\t * - if the web component zone is `manual`, the directive zone also will be `manual`, expect weird behavior.\n\t * - if the web component zone is `proxy`, the directive zone also will be `proxy`.\n\t * - if the web component zone is `aurora`, the directive zone also will be `aurora` and will get the benefit of `zone.js`.\n\t */\n\tzone?: ZoneType;\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;\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?: keyof HTMLElementTagNameMap;\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\t/**\n\t * Create a custom form-associated element with HTMLElement.attachInternals\n\t * default: false\n\t * \n\t * if the value is `true` it is expected from the model class to implement `ValueControl<T>` interface\n\t * \n\t * otherwise you can register another class that implement `ValueControl<T>`,\n\t * in case if you want split the model and the value controller.\n\t * \n\t * #### Usage Notes:\n\t * \n\t * ```ts\n\t * \n\t * @Component({\n\t * \tselector: 'custom-message',\n\t * \ttemplate: `\n\t * \t\t<label for=\"message\">Message</label>\n\t * \t\t<textarea id=\"message\" [(value)]=\"message\" [disabled]=\"disabled\" (change)=\"onMessageChange($event.target.value)\"></textarea>\n\t * \t`,\n\t * \tformAssociated: true,\n\t * \t// formAssociated: CustomMessage,\n\t * })\n\t * export class CustomMessage implements ValueControl<string> {\n\t * \n\t * \tprivate message: string | null = '';\n\t * \tprivate disabled: boolean = false;\n\t * \tprivate _onChange: (_: any) => void = () => {};\n\t * \n\t * \twriteValue({ value, mode }: WriteValueOptions<string>) {\n\t * \t\tthis.message = mode !== 'reset' ? value : '';\n\t * \t}\n\t * \n\t * \tregisterOnChange(fn: (_: any) => void): void {\n\t * \t\tthis._onChange = fn;\n\t * \t}\n\t * \n\t * \tsetDisabledState(isDisabled: boolean) {\n\t * \t\tthis.disabled = isDisabled;\n\t * \t}\n\t * \n\t * \tonMessageChange(message: string) {\n\t * \t\tthis._onChange(message);\n\t * \t}\n\t * \t\n\t * }\n\t * \n\t * \n\t * export class CustomInputValueControl implements ValueControl<number> {\n\t * \n\t * \tprivate _value: number | null = null;\n\t * \tprivate _disabled: boolean = false;\n\t * \tprivate _onChange: (_: any) => void = () => {};\n\t * \n\t * \twriteValue({ value, mode }: WriteValueOptions<number>) {\n\t * \t\tthis._value = mode !== 'reset' ? value : null;\n\t * \t}\n\t * \n\t * \tregisterOnChange(fn: (_: any) => void): void {\n\t * \t\tthis._onChange = fn;\n\t * \t}\n\t * \n\t * \tsetDisabledState(isDisabled: boolean) {\n\t * \t\tthis._disabled = isDisabled;\n\t * \t}\n\t * \t\n\t * }\n\t * \n\t * @Component({\n\t * \tselector: 'custom-input',\n\t * \textend: 'input',\n\t * \tformAssociated: CustomInputValueControl,\n\t * })\n\t * export class CustomInputElement {\n\t * \t@View()\n\t * \tview: HTMLInputElement;\n\t * \n\t * \tonInit() {\n\t * \t\tthis.view.type = 'number';\n\t * \t}\n\t * }\n\t * \n\t * ```\n\t */\n\tformAssociated?: boolean | TypeOf<ValueControl<any>>;\n\n\t/**\n\t * - use `manual` for no zone.js patch effect applied,\n\t * and used for manual change detection for heavily process components.\n\t * \n\t * - use `proxy` zone for automatic detect changes without use of `zone.js`\n\t * \n\t * - use `aurora` for detection events like `rxjs` observables, `setTimeout`,\n\t * `setInterval` and `fetch` and `XMLHttpRequest`, etc...\n\t * make sure that `zone.js` is imported in the polyfills module. \n\t * \n\t * the default value is the platform zone type which can be changed by:\n\t * \n\t * ```js\n\t * bootstrapZone('manual')\n\t * bootstrapZone('proxy')\n\t * bootstrapZone('aurora')\n\t * ```\n\t * \n\t * if `bootstrapZone` never been called, then the default zone is a `manual`.\n\t */\n\tzone?: ZoneType;\n\n\t/**\n\t * The imports property specifies the component's template dependencies — those directives, components, and pipes that can be used within its template.\n\t */\n\timports?: (TypeOf<any> | ReadonlyArray<any>)[];\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\tReflectComponents.addInput(target, propertyKey, name || propertyKey);\n\t};\n}\n\nexport function FormValue(): Function {\n\treturn (target: Object, propertyKey: string) => {\n\t\tReflectComponents.addInput(target, propertyKey, 'value');\n\t};\n}\n\nexport type OutputEventInit = Omit<EventInit, 'cancelable'>;\nexport type OutputOptions = { name?: string } & OutputEventInit;\n\nexport function Output(options?: OutputOptions): Function;\nexport function Output(name?: string, options?: OutputEventInit): Function;\nexport function Output(name?: string | OutputOptions, options?: OutputEventInit): Function {\n\tconst eventType = typeof name === 'object' ? name.name : name;\n\tconst eventOpts = typeof name === 'object' ? name : options;\n\treturn (target: Object, propertyKey: string) => {\n\t\tReflectComponents.addOutput(\n\t\t\ttarget,\n\t\t\tpropertyKey, eventType || propertyKey,\n\t\t\t{\n\t\t\t\tbubbles: eventOpts?.bubbles ?? false,\n\t\t\t\tcomposed: eventOpts?.composed ?? false\n\t\t\t}\n\t\t);\n\t};\n}\n\nexport function View(): Function {\n\treturn (target: Object, propertyKey: string) => {\n\t\tReflectComponents.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\tReflectComponents.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\tReflectComponents.addViewChildren(target, propertyKey, selector);\n\t};\n}\n\nexport function HostListener(eventName: string, args?: string | string[]): Function {\n\treturn (target: Object, propertyKey: string) => {\n\t\targs = typeof args === 'string' ? [args] : args;\n\t\tReflectComponents.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\tReflectComponents.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\nfunction generateComponent<T extends { new(...args: any[]): {} }>(target: TypeOf<T>, opt: ComponentOptions<T>) {\n\tif (opt.templateUrl) {\n\t\tfetchHtml(opt.templateUrl)\n\t\t\t.then(htmlTemplate => {\n\t\t\t\tif (htmlTemplate) {\n\t\t\t\t\topt.template = htmlTemplate;\n\t\t\t\t\tComponents.defineComponent(target, opt);\n\t\t\t\t}\n\t\t\t})\n\t\t\t.catch(reason => {\n\t\t\t\tconsole.error(`Error @URL: ${opt.templateUrl}, for model Class: ${target.name},\\n Reason: ${reason}.`);\n\t\t\t});\n\t} else {\n\t\tComponents.defineComponent(target, opt);\n\t}\n}\n\nexport function Component<T extends { new(...args: any[]): {} }>(opt: ComponentOptions<T> | ComponentOptions<T>[]): Function {\n\treturn (target: TypeOf<T>) => {\n\t\tif (Array.isArray(opt)) {\n\t\t\tfor (const comp of opt) {\n\t\t\t\tgenerateComponent(target, comp);\n\t\t\t}\n\t\t} else if (typeof opt === 'object') {\n\t\t\tgenerateComponent(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\nexport function customElement<T extends HTMLElement>(opt: { selector: string } & ElementDefinitionOptions): Function {\n\treturn (target: TypeOf<T>) => {\n\t\tComponents.defineView(target, opt);\n\t\treturn target;\n\t};\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ExpressionNode, InfixExpressionNode, ScopeSubscription, Stack, Context, MemberExpression, Identifier, VisitNodeType, NodeDeserializer } from '@ibyar/expressions';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
type OneWayOperator = '=:';
|
|
3
|
+
type TwoWayOperator = '=::';
|
|
4
|
+
type BindingOperators = OneWayOperator | TwoWayOperator;
|
|
5
5
|
export interface BindingAssignment extends InfixExpressionNode<BindingOperators> {
|
|
6
6
|
subscribe(stack: Stack, pipelineNames?: string[]): ScopeSubscription<Context>[];
|
|
7
7
|
}
|
|
@@ -5,10 +5,6 @@ import { createSubscriptionDestroyer } from '../context/subscription.js';
|
|
|
5
5
|
import { isOnDestroy } from '../component/lifecycle.js';
|
|
6
6
|
import { AsyncPipeProvider, AsyncPipeScope, PipeProvider } from '../pipe/pipe.js';
|
|
7
7
|
let OneWayAssignmentExpression = OneWayAssignmentExpression_1 = class OneWayAssignmentExpression extends InfixExpressionNode {
|
|
8
|
-
constructor(left, right) {
|
|
9
|
-
super('=:', left, right);
|
|
10
|
-
this.rightEvents = this.right.events();
|
|
11
|
-
}
|
|
12
8
|
static fromJSON(node, deserializer) {
|
|
13
9
|
return new OneWayAssignmentExpression_1(deserializer(node.left), deserializer(node.right));
|
|
14
10
|
}
|
|
@@ -16,6 +12,10 @@ let OneWayAssignmentExpression = OneWayAssignmentExpression_1 = class OneWayAssi
|
|
|
16
12
|
visitNode(node.left);
|
|
17
13
|
visitNode(node.right);
|
|
18
14
|
}
|
|
15
|
+
constructor(left, right) {
|
|
16
|
+
super('=:', left, right);
|
|
17
|
+
this.rightEvents = this.right.events();
|
|
18
|
+
}
|
|
19
19
|
set(stack, value) {
|
|
20
20
|
return this.left.set(stack, value);
|
|
21
21
|
}
|
|
@@ -68,11 +68,6 @@ export { OneWayAssignmentExpression };
|
|
|
68
68
|
*
|
|
69
69
|
*/
|
|
70
70
|
let TwoWayAssignmentExpression = TwoWayAssignmentExpression_1 = class TwoWayAssignmentExpression extends InfixExpressionNode {
|
|
71
|
-
constructor(left, right) {
|
|
72
|
-
super('=::', left, right);
|
|
73
|
-
this.rightEvents = this.right.events();
|
|
74
|
-
this.leftEvents = this.left.events();
|
|
75
|
-
}
|
|
76
71
|
static fromJSON(node, deserializer) {
|
|
77
72
|
return new TwoWayAssignmentExpression_1(deserializer(node.left), deserializer(node.right));
|
|
78
73
|
}
|
|
@@ -80,6 +75,11 @@ let TwoWayAssignmentExpression = TwoWayAssignmentExpression_1 = class TwoWayAssi
|
|
|
80
75
|
visitNode(node.left);
|
|
81
76
|
visitNode(node.right);
|
|
82
77
|
}
|
|
78
|
+
constructor(left, right) {
|
|
79
|
+
super('=::', left, right);
|
|
80
|
+
this.rightEvents = this.right.events();
|
|
81
|
+
this.leftEvents = this.left.events();
|
|
82
|
+
}
|
|
83
83
|
set(stack, value) {
|
|
84
84
|
return this.setRTL(stack, value);
|
|
85
85
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binding.expressions.js","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AAa,CAAC;IACtB,CAAC;IAED,SAAS,CAAC,KAAY;QAErB,gBAAgB;QAChB,MAAM,WAAW,GAAG,2BAA2B,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;QACzE,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACxC,MAAM,gBAAgB,GAAG,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;QAE/E,iBAAiB;QACjB,MAAM,UAAU,GAAG,2BAA2B,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QACvE,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACxC,MAAM,gBAAgB,GAAG,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;QAE9E,OAAO,gBAAgB,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAClD,CAAC;CAED,CAAA;AA5EY,0BAA0B;IADtC,YAAY,CAAC,kBAAkB,CAAC;qCAkBd,gBAAgB;GAjBtB,0BAA0B,CA4EtC;SA5EY,0BAA0B","sourcesContent":["import {\n\tExpressionNode, InfixExpressionNode, ScopeSubscription,\n\tStack, findReactiveScopeByEventMap, ReactiveScope,\n\tContext, ValueChangedCallback, Scope,\n\tMemberExpression, Identifier, Deserializer,\n\tVisitNodeType, NodeDeserializer\n} from '@ibyar/expressions';\nimport { createSubscriptionDestroyer } from '../context/subscription.js';\nimport { isOnDestroy } from '../component/lifecycle.js';\nimport { AsyncPipeProvider, AsyncPipeScope, PipeProvider } 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<Context>[];\n}\n\n\n@Deserializer('OneWayAssignment')\nexport class OneWayAssignmentExpression extends InfixExpressionNode<OneWayOperator> implements BindingAssignment {\n\tstatic fromJSON(node: OneWayAssignmentExpression, deserializer: NodeDeserializer): OneWayAssignmentExpression {\n\t\treturn new OneWayAssignmentExpression(\n\t\t\tdeserializer(node.left) as MemberExpression,\n\t\t\tdeserializer(node.right)\n\t\t);\n\t}\n\tstatic visit(node: OneWayAssignmentExpression, visitNode: VisitNodeType): void {\n\t\tvisitNode(node.left);\n\t\tvisitNode(node.right);\n\t}\n\n\tdeclare protected left: MemberExpression;\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<Context>[] {\n\t\tconst subscriptions: ScopeSubscription<Context>[] = [];\n\t\tif (pipelineNames?.length) {\n\t\t\tconst syncPipeScope = Scope.blockScope();\n\t\t\tconst asyncPipeScope = AsyncPipeScope.blockScope();\n\t\t\tlet hasAsync = false, hasSync = false;\n\t\t\tpipelineNames.forEach(pipelineName => {\n\t\t\t\tconst scope = stack.findScope(pipelineName);\n\t\t\t\tconst pipe = scope.get(pipelineName)!;\n\t\t\t\tif (scope instanceof AsyncPipeProvider) {\n\t\t\t\t\thasAsync = true;\n\t\t\t\t\tasyncPipeScope.set(pipelineName, pipe);\n\t\t\t\t\tif (isOnDestroy(pipe.prototype)) {\n\t\t\t\t\t\tsubscriptions.push(createSubscriptionDestroyer(() => asyncPipeScope.unsubscribe(pipelineName)));\n\t\t\t\t\t}\n\t\t\t\t} else if (scope instanceof PipeProvider) {\n\t\t\t\t\thasSync = true;\n\t\t\t\t\tsyncPipeScope.set(pipelineName, pipe);\n\t\t\t\t}\n\t\t\t});\n\t\t\thasSync && stack.pushScope(syncPipeScope);\n\t\t\thasAsync && stack.pushScope(asyncPipeScope);\n\t\t}\n\t\tconst tuples = findReactiveScopeByEventMap(this.rightEvents, stack);\n\t\tconst callback: ValueChangedCallback = () => this.get(stack);\n\t\ttuples.forEach(tuple => {\n\t\t\tconst subscription = tuple[1].subscribe(tuple[0], callback);\n\t\t\tsubscriptions.push(subscription);\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 */\n@Deserializer('TwoWayAssignment')\nexport class TwoWayAssignmentExpression extends InfixExpressionNode<TwoWayOperator> implements BindingAssignment {\n\tstatic fromJSON(node: TwoWayAssignmentExpression, deserializer: NodeDeserializer): TwoWayAssignmentExpression {\n\t\treturn new TwoWayAssignmentExpression(\n\t\t\tdeserializer(node.left) as MemberExpression,\n\t\t\tdeserializer(node.right) as MemberExpression | Identifier\n\t\t);\n\t}\n\tstatic visit(node: TwoWayAssignmentExpression, visitNode: VisitNodeType): void {\n\t\tvisitNode(node.left);\n\t\tvisitNode(node.right);\n\t}\n\n\tdeclare protected left: MemberExpression;\n\tdeclare protected 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 () => this.getRTL(stack);\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 () => this.getLTR(stack);\n\t}\n\n\tprivate subscribeToEvents(stack: Stack, tuples: [string, ReactiveScope<Context>][], actionCallback: ValueChangedCallback) {\n\t\tconst subscriptions: ScopeSubscription<Context>[] = [];\n\t\ttuples.forEach(tuple => {\n\t\t\tconst subscription = tuple[1].subscribe(tuple[0], actionCallback);\n\t\t\tsubscriptions.push(subscription);\n\t\t});\n\t\treturn subscriptions;\n\t}\n\n\tsubscribe(stack: Stack): ScopeSubscription<Context>[] {\n\n\t\t// right to left\n\t\tconst rightTuples = findReactiveScopeByEventMap(this.rightEvents, stack);\n\t\tconst rtlAction = this.actionRTL(stack);\n\t\tconst rtlSubscriptions = this.subscribeToEvents(stack, rightTuples, rtlAction);\n\n\t\t// left to right \n\t\tconst leftTuples = findReactiveScopeByEventMap(this.leftEvents, stack);\n\t\tconst ltrAction = this.actionLTR(stack);\n\t\tconst ltrSubscriptions = this.subscribeToEvents(stack, leftTuples, ltrAction);\n\n\t\treturn rtlSubscriptions.concat(ltrSubscriptions);\n\t}\n\n}\n"]}
|
|
1
|
+
{"version":3,"file":"binding.expressions.js","sourceRoot":"","sources":["../../../src/core/binding/binding.expressions.ts"],"names":[],"mappings":";;AAAA,OAAO,EACU,mBAAmB,EAC5B,2BAA2B,EACH,KAAK,EACpC,gBAAgB,EAAc,YAAY,EAE1C,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAY3E,IAAM,0BAA0B,kCAAhC,MAAM,0BAA2B,SAAQ,mBAAmC;IAClF,MAAM,CAA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I,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACxC,MAAM,gBAAgB,GAAG,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;QAE9E,OAAO,gBAAgB,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAClD,CAAC;CAED,CAAA;AA5EY,0BAA0B;IADtC,YAAY,CAAC,kBAAkB,CAAC;qCAkBd,gBAAgB;GAjBtB,0BAA0B,CA4EtC;SA5EY,0BAA0B","sourcesContent":["import {\n\tExpressionNode, InfixExpressionNode, ScopeSubscription,\n\tStack, findReactiveScopeByEventMap, ReactiveScope,\n\tContext, ValueChangedCallback, Scope,\n\tMemberExpression, Identifier, Deserializer,\n\tVisitNodeType, NodeDeserializer\n} from '@ibyar/expressions';\nimport { createSubscriptionDestroyer } from '../context/subscription.js';\nimport { isOnDestroy } from '../component/lifecycle.js';\nimport { AsyncPipeProvider, AsyncPipeScope, PipeProvider } 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<Context>[];\n}\n\n\n@Deserializer('OneWayAssignment')\nexport class OneWayAssignmentExpression extends InfixExpressionNode<OneWayOperator> implements BindingAssignment {\n\tstatic fromJSON(node: OneWayAssignmentExpression, deserializer: NodeDeserializer): OneWayAssignmentExpression {\n\t\treturn new OneWayAssignmentExpression(\n\t\t\tdeserializer(node.left) as MemberExpression,\n\t\t\tdeserializer(node.right)\n\t\t);\n\t}\n\tstatic visit(node: OneWayAssignmentExpression, visitNode: VisitNodeType): void {\n\t\tvisitNode(node.left);\n\t\tvisitNode(node.right);\n\t}\n\n\tdeclare protected left: MemberExpression;\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<Context>[] {\n\t\tconst subscriptions: ScopeSubscription<Context>[] = [];\n\t\tif (pipelineNames?.length) {\n\t\t\tconst syncPipeScope = Scope.blockScope();\n\t\t\tconst asyncPipeScope = AsyncPipeScope.blockScope();\n\t\t\tlet hasAsync = false, hasSync = false;\n\t\t\tpipelineNames.forEach(pipelineName => {\n\t\t\t\tconst scope = stack.findScope(pipelineName);\n\t\t\t\tconst pipe = scope.get(pipelineName)!;\n\t\t\t\tif (scope instanceof AsyncPipeProvider) {\n\t\t\t\t\thasAsync = true;\n\t\t\t\t\tasyncPipeScope.set(pipelineName, pipe);\n\t\t\t\t\tif (isOnDestroy(pipe.prototype)) {\n\t\t\t\t\t\tsubscriptions.push(createSubscriptionDestroyer(() => asyncPipeScope.unsubscribe(pipelineName)));\n\t\t\t\t\t}\n\t\t\t\t} else if (scope instanceof PipeProvider) {\n\t\t\t\t\thasSync = true;\n\t\t\t\t\tsyncPipeScope.set(pipelineName, pipe);\n\t\t\t\t}\n\t\t\t});\n\t\t\thasSync && stack.pushScope(syncPipeScope);\n\t\t\thasAsync && stack.pushScope(asyncPipeScope);\n\t\t}\n\t\tconst tuples = findReactiveScopeByEventMap(this.rightEvents, stack);\n\t\tconst callback: ValueChangedCallback = () => this.get(stack);\n\t\ttuples.forEach(tuple => {\n\t\t\tconst subscription = tuple[1].subscribe(tuple[0], callback);\n\t\t\tsubscriptions.push(subscription);\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 */\n@Deserializer('TwoWayAssignment')\nexport class TwoWayAssignmentExpression extends InfixExpressionNode<TwoWayOperator> implements BindingAssignment {\n\tstatic fromJSON(node: TwoWayAssignmentExpression, deserializer: NodeDeserializer): TwoWayAssignmentExpression {\n\t\treturn new TwoWayAssignmentExpression(\n\t\t\tdeserializer(node.left) as MemberExpression,\n\t\t\tdeserializer(node.right) as MemberExpression | Identifier\n\t\t);\n\t}\n\tstatic visit(node: TwoWayAssignmentExpression, visitNode: VisitNodeType): void {\n\t\tvisitNode(node.left);\n\t\tvisitNode(node.right);\n\t}\n\n\tdeclare protected left: MemberExpression;\n\tdeclare protected 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 () => this.getRTL(stack);\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 () => this.getLTR(stack);\n\t}\n\n\tprivate subscribeToEvents(stack: Stack, tuples: [string, ReactiveScope<Context>][], actionCallback: ValueChangedCallback) {\n\t\tconst subscriptions: ScopeSubscription<Context>[] = [];\n\t\ttuples.forEach(tuple => {\n\t\t\tconst subscription = tuple[1].subscribe(tuple[0], actionCallback);\n\t\t\tsubscriptions.push(subscription);\n\t\t});\n\t\treturn subscriptions;\n\t}\n\n\tsubscribe(stack: Stack): ScopeSubscription<Context>[] {\n\n\t\t// right to left\n\t\tconst rightTuples = findReactiveScopeByEventMap(this.rightEvents, stack);\n\t\tconst rtlAction = this.actionRTL(stack);\n\t\tconst rtlSubscriptions = this.subscribeToEvents(stack, rightTuples, rtlAction);\n\n\t\t// left to right \n\t\tconst leftTuples = findReactiveScopeByEventMap(this.leftEvents, stack);\n\t\tconst ltrAction = this.actionLTR(stack);\n\t\tconst ltrSubscriptions = this.subscribeToEvents(stack, leftTuples, ltrAction);\n\n\t\treturn rtlSubscriptions.concat(ltrSubscriptions);\n\t}\n\n}\n"]}
|
package/component/component.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { TypeOf } from '../utils/typeof.js';
|
|
2
|
-
import {
|
|
2
|
+
import type { ZoneType } from '../zone/bootstrap.js';
|
|
3
|
+
import { Tag, DomNode, DomRenderNode, DomElementNode } from '@ibyar/elements';
|
|
3
4
|
import { HTMLComponent, ValueControl } from './custom-element.js';
|
|
4
5
|
import { AttributeDirective, StructuralDirective } from '../directive/directive.js';
|
|
5
6
|
import { ComponentOptions, PipeOptions, ServiceOptions, DirectiveOptions } from '../annotation/decorators.js';
|
|
6
|
-
import { ZoneType } from '../zone/bootstrap.js';
|
|
7
7
|
import { ChildRef, HostBindingRef, InputPropertyRef, ListenerRef, OutputPropertyRef, PropertyRef } from './reflect.js';
|
|
8
8
|
export interface ServiceRef<T> {
|
|
9
9
|
provideIn: TypeOf<CustomElementConstructor> | 'root' | 'platform' | 'any';
|
|
@@ -17,7 +17,7 @@ export interface PipeRef<T> {
|
|
|
17
17
|
}
|
|
18
18
|
export interface DirectiveRef<T> {
|
|
19
19
|
selector: string;
|
|
20
|
-
zone
|
|
20
|
+
zone?: ZoneType;
|
|
21
21
|
modelClass: TypeOf<StructuralDirective> | TypeOf<AttributeDirective>;
|
|
22
22
|
inputs: PropertyRef[];
|
|
23
23
|
outputs: PropertyRef[];
|
|
@@ -26,6 +26,7 @@ export interface DirectiveRef<T> {
|
|
|
26
26
|
ViewChildren: ChildRef[];
|
|
27
27
|
hostListeners: ListenerRef[];
|
|
28
28
|
hostBindings: HostBindingRef[];
|
|
29
|
+
viewBindings?: DomElementNode;
|
|
29
30
|
}
|
|
30
31
|
export interface ComponentRef<T> {
|
|
31
32
|
selector: string;
|
|
@@ -42,14 +43,18 @@ export interface ComponentRef<T> {
|
|
|
42
43
|
ViewChildren: ChildRef[];
|
|
43
44
|
hostBindings: HostBindingRef[];
|
|
44
45
|
hostListeners: ListenerRef[];
|
|
46
|
+
viewBindings?: DomElementNode;
|
|
45
47
|
encapsulation: 'custom' | 'shadow-dom' | 'template' | 'shadow-dom-template';
|
|
46
48
|
isShadowDom: boolean;
|
|
47
49
|
shadowDomMode: ShadowRootMode;
|
|
48
50
|
shadowDomDelegatesFocus: boolean;
|
|
49
51
|
formAssociated: boolean | TypeOf<ValueControl<any>>;
|
|
50
|
-
zone
|
|
52
|
+
zone?: ZoneType;
|
|
51
53
|
}
|
|
52
54
|
export declare class Components {
|
|
55
|
+
private static EMPTY_LIST;
|
|
56
|
+
private static emptyList;
|
|
57
|
+
private static parseHostBinding;
|
|
53
58
|
static defineDirective(modelClass: Function, opts: DirectiveOptions): void;
|
|
54
59
|
static definePipe(modelClass: Function, opts: PipeOptions): void;
|
|
55
60
|
static defineService(modelClass: Function, opts: ServiceOptions): void;
|
package/component/component.js
CHANGED
|
@@ -5,10 +5,33 @@ import { buildExpressionNodes } from '../html/expression.js';
|
|
|
5
5
|
import { ReflectComponents } from './reflect.js';
|
|
6
6
|
import { deserializeExpressionNodes } from '../html/deserialize.js';
|
|
7
7
|
export class Components {
|
|
8
|
+
static emptyList() {
|
|
9
|
+
return Components.EMPTY_LIST;
|
|
10
|
+
}
|
|
11
|
+
static parseHostBinding(option) {
|
|
12
|
+
const inputs = option.hostBindings?.map(binding => {
|
|
13
|
+
const descriptor = Object.getOwnPropertyDescriptor(option.prototype, binding.modelPropertyName);
|
|
14
|
+
if (typeof descriptor?.value === 'function') {
|
|
15
|
+
return `[${binding.hostPropertyName}]="${binding.modelPropertyName}()"`;
|
|
16
|
+
}
|
|
17
|
+
return `[${binding.hostPropertyName}]="${binding.modelPropertyName}"`;
|
|
18
|
+
}) ?? [];
|
|
19
|
+
const outputs = option.hostListeners?.map(listener => `(${listener.eventName})="${listener.modelCallbackName}(${listener.args.join(', ')})"`) ?? [];
|
|
20
|
+
option.selector ?? (option.selector = 'div');
|
|
21
|
+
const template = `<${option.selector} ${inputs.join(' ')} ${outputs.join(' ')}></${option.selector}>`;
|
|
22
|
+
const viewBindings = htmlParser.toDomRootNode(template);
|
|
23
|
+
buildExpressionNodes(viewBindings);
|
|
24
|
+
return viewBindings;
|
|
25
|
+
}
|
|
8
26
|
static defineDirective(modelClass, opts) {
|
|
9
27
|
const bootstrap = ReflectComponents.getOrCreateBootstrap(modelClass.prototype);
|
|
10
|
-
|
|
11
|
-
|
|
28
|
+
Object.assign(bootstrap, opts);
|
|
29
|
+
if (bootstrap.hostListeners?.length || bootstrap.hostBindings?.length) {
|
|
30
|
+
bootstrap.viewBindings = Components.parseHostBinding({
|
|
31
|
+
prototype: modelClass.prototype,
|
|
32
|
+
hostBindings: bootstrap.hostBindings,
|
|
33
|
+
hostListeners: bootstrap.hostListeners,
|
|
34
|
+
});
|
|
12
35
|
}
|
|
13
36
|
bootstrap.modelClass = modelClass;
|
|
14
37
|
ClassRegistryProvider.registerDirective(modelClass);
|
|
@@ -36,10 +59,7 @@ export class Components {
|
|
|
36
59
|
}
|
|
37
60
|
static defineComponent(modelClass, opts) {
|
|
38
61
|
const bootstrap = ReflectComponents.getOrCreateBootstrap(modelClass.prototype);
|
|
39
|
-
|
|
40
|
-
for (const key in bootstrap) {
|
|
41
|
-
Reflect.set(componentRef, key, bootstrap[key]);
|
|
42
|
-
}
|
|
62
|
+
const componentRef = Object.assign({}, opts, bootstrap);
|
|
43
63
|
componentRef.extend = findByTagName(opts.extend);
|
|
44
64
|
if (typeof componentRef.template === 'string') {
|
|
45
65
|
if (componentRef.styles) {
|
|
@@ -70,16 +90,24 @@ export class Components {
|
|
|
70
90
|
// didn't find this template in 'index.html' document
|
|
71
91
|
}
|
|
72
92
|
}
|
|
73
|
-
componentRef.inputs || (componentRef.inputs =
|
|
74
|
-
componentRef.outputs || (componentRef.outputs =
|
|
75
|
-
componentRef.viewChild || (componentRef.viewChild =
|
|
76
|
-
componentRef.ViewChildren || (componentRef.ViewChildren =
|
|
77
|
-
componentRef.hostBindings || (componentRef.hostBindings =
|
|
78
|
-
componentRef.hostListeners || (componentRef.hostListeners =
|
|
93
|
+
componentRef.inputs || (componentRef.inputs = Components.emptyList());
|
|
94
|
+
componentRef.outputs || (componentRef.outputs = Components.emptyList());
|
|
95
|
+
componentRef.viewChild || (componentRef.viewChild = Components.emptyList());
|
|
96
|
+
componentRef.ViewChildren || (componentRef.ViewChildren = Components.emptyList());
|
|
97
|
+
componentRef.hostBindings || (componentRef.hostBindings = Components.emptyList());
|
|
98
|
+
componentRef.hostListeners || (componentRef.hostListeners = Components.emptyList());
|
|
79
99
|
componentRef.encapsulation || (componentRef.encapsulation = 'custom');
|
|
80
100
|
componentRef.isShadowDom = /shadow-dom/g.test(componentRef.encapsulation);
|
|
81
101
|
componentRef.shadowDomMode || (componentRef.shadowDomMode = 'open');
|
|
82
102
|
componentRef.shadowDomDelegatesFocus = componentRef.shadowDomDelegatesFocus === true || false;
|
|
103
|
+
if (componentRef.hostListeners.length || componentRef.hostBindings.length) {
|
|
104
|
+
componentRef.viewBindings = Components.parseHostBinding({
|
|
105
|
+
prototype: modelClass.prototype,
|
|
106
|
+
selector: componentRef.selector,
|
|
107
|
+
hostBindings: componentRef.hostBindings,
|
|
108
|
+
hostListeners: componentRef.hostListeners,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
83
111
|
if (!(componentRef.formAssociated === true || typeof componentRef.formAssociated === 'function')) {
|
|
84
112
|
componentRef.formAssociated = false;
|
|
85
113
|
}
|
|
@@ -106,4 +134,5 @@ export class Components {
|
|
|
106
134
|
customElements.define(opt.selector, viewClass, Object.assign({}, opt, { selector: undefined }));
|
|
107
135
|
}
|
|
108
136
|
}
|
|
137
|
+
Components.EMPTY_LIST = Object.freeze([]);
|
|
109
138
|
//# 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;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,OAAO,EAAG,SAAS,CAAC,OAAyB,EAAE,GAAG,CAAC,MAA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U,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
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../../src/core/component/component.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,aAAa,EAAO,UAAU,EAAE,cAAc,EACtB,eAAe,EACvC,iBAAiB,EACjB,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;AAK7D,OAAO,EAGO,iBAAiB,EAC9B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAiEpE,MAAM,OAAO,UAAU;IAGd,MAAM,CAAC,SAAS;QACvB,OAAO,UAAU,CAAC,UAAiB,CAAC;IACrC,CAAC;IAEO,MAAM,CAAC,gBAAgB,CAAC,MAAyB;QACxD,MAAM,MAAM,GAAG,MAAM,CAAC,YAAY,EAAE,GAAG,C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,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;;AAxJc,qBAAU,GAAG,MAAM,CAAC,MAAM,CAAM,EAAE,CAAC,CAAC","sourcesContent":["import type { TypeOf } from '../utils/typeof.js';\nimport type { ZoneType } from '../zone/bootstrap.js';\nimport {\n\tfindByTagName, Tag, htmlParser, templateParser,\n\tDomNode, DomRenderNode, canAttachShadow,\n\tdirectiveRegistry, DomElementNode\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 {\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\tviewBindings?: DomElementNode;\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\tviewBindings?: DomElementNode;\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\ntype ViewBindingOption = {\n\tprototype: Record<PropertyKey, any>;\n\thostBindings?: HostBindingRef[];\n\thostListeners?: ListenerRef[];\n\tselector?: string;\n};\n\nexport class Components {\n\n\tprivate static EMPTY_LIST = Object.freeze<any>([]);\n\tprivate static emptyList<T>(): T[] {\n\t\treturn Components.EMPTY_LIST as T[];\n\t}\n\n\tprivate static parseHostBinding(option: ViewBindingOption): DomElementNode {\n\t\tconst inputs = option.hostBindings?.map(binding => {\n\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(option.prototype, binding.modelPropertyName);\n\t\t\tif (typeof descriptor?.value === 'function') {\n\t\t\t\treturn `[${binding.hostPropertyName}]=\"${binding.modelPropertyName}()\"`\n\t\t\t}\n\t\t\treturn `[${binding.hostPropertyName}]=\"${binding.modelPropertyName}\"`;\n\t\t}) ?? [];\n\t\tconst outputs = option.hostListeners?.map(\n\t\t\tlistener => `(${listener.eventName})=\"${listener.modelCallbackName}(${listener.args.join(', ')})\"`\n\t\t) ?? [];\n\t\toption.selector ??= 'div';\n\t\tconst template = `<${option.selector} ${inputs.join(' ')} ${outputs.join(' ')}></${option.selector}>`;\n\t\tconst viewBindings = htmlParser.toDomRootNode(template) as DomElementNode;\n\t\tbuildExpressionNodes(viewBindings);\n\t\treturn viewBindings;\n\t}\n\n\tstatic defineDirective(modelClass: Function, opts: DirectiveOptions) {\n\t\tconst bootstrap: BootstrapMetadata = ReflectComponents.getOrCreateBootstrap(modelClass.prototype);\n\t\tObject.assign(bootstrap, opts);\n\t\tif (bootstrap.hostListeners?.length || bootstrap.hostBindings?.length) {\n\t\t\tbootstrap.viewBindings = Components.parseHostBinding({\n\t\t\t\tprototype: modelClass.prototype,\n\t\t\t\thostBindings: bootstrap.hostBindings,\n\t\t\t\thostListeners: bootstrap.hostListeners,\n\t\t\t});\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\t\tconst componentRef = Object.assign({}, opts, bootstrap) as any as ComponentRef<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 ||= Components.emptyList();\n\t\tcomponentRef.outputs ||= Components.emptyList();\n\t\tcomponentRef.viewChild ||= Components.emptyList();\n\t\tcomponentRef.ViewChildren ||= Components.emptyList();\n\t\tcomponentRef.hostBindings ||= Components.emptyList();\n\t\tcomponentRef.hostListeners ||= Components.emptyList();\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.hostListeners.length || componentRef.hostBindings.length) {\n\t\t\tcomponentRef.viewBindings = Components.parseHostBinding({\n\t\t\t\tprototype: modelClass.prototype,\n\t\t\t\tselector: componentRef.selector,\n\t\t\t\thostBindings: componentRef.hostBindings,\n\t\t\t\thostListeners: componentRef.hostListeners,\n\t\t\t});\n\t\t}\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"]}
|
|
@@ -10,8 +10,8 @@ export interface CustomElement {
|
|
|
10
10
|
connectedCallback(): void;
|
|
11
11
|
disconnectedCallback(): void;
|
|
12
12
|
}
|
|
13
|
-
export
|
|
14
|
-
export
|
|
13
|
+
export type ModelType<T> = T & Context;
|
|
14
|
+
export type NodeContextType<T> = {
|
|
15
15
|
'this': BaseComponent<T>;
|
|
16
16
|
};
|
|
17
17
|
export interface BaseComponent<T> extends CustomElement {
|
|
@@ -96,8 +96,8 @@ export interface FormAssociatedCustomElement extends CustomElement {
|
|
|
96
96
|
*/
|
|
97
97
|
formStateRestoreCallback(value: any, mode: 'restore' | 'autocomplete'): void;
|
|
98
98
|
}
|
|
99
|
-
export
|
|
100
|
-
export
|
|
99
|
+
export type WriteValueMode = 'restore' | 'autocomplete' | 'reset';
|
|
100
|
+
export type WriteValueOptions<T> = {
|
|
101
101
|
value: T | null;
|
|
102
102
|
mode?: 'restore' | 'autocomplete';
|
|
103
103
|
} | {
|
|
@@ -172,7 +172,7 @@ export interface BaseFormAssociatedComponent<T extends Object> extends BaseCompo
|
|
|
172
172
|
export interface FormAssociatedComponent<T extends Object, V = any> extends BaseFormAssociatedComponent<T>, HTMLComponent<T> {
|
|
173
173
|
value: V | null;
|
|
174
174
|
}
|
|
175
|
-
export
|
|
175
|
+
export type HTMLFormElement = HTMLButtonElement | HTMLDataListElement | HTMLFieldSetElement | HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
|
|
176
176
|
export interface ConstructorOfView<T> {
|
|
177
177
|
new (): T;
|
|
178
178
|
readonly prototype: T;
|
package/component/reflect.d.ts
CHANGED
|
@@ -31,9 +31,9 @@ export declare class ListenerRef {
|
|
|
31
31
|
constructor(eventName: string, args: string[], modelCallbackName: string);
|
|
32
32
|
}
|
|
33
33
|
export declare class HostBindingRef {
|
|
34
|
-
|
|
34
|
+
modelPropertyName: string;
|
|
35
35
|
hostPropertyName: string;
|
|
36
|
-
constructor(
|
|
36
|
+
constructor(modelPropertyName: string, hostPropertyName: string);
|
|
37
37
|
}
|
|
38
38
|
export interface BootstrapMetadata {
|
|
39
39
|
[key: string]: any;
|
package/component/reflect.js
CHANGED
|
@@ -30,8 +30,8 @@ export class ListenerRef {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
export class HostBindingRef {
|
|
33
|
-
constructor(
|
|
34
|
-
this.
|
|
33
|
+
constructor(modelPropertyName, hostPropertyName) {
|
|
34
|
+
this.modelPropertyName = modelPropertyName;
|
|
35
35
|
this.hostPropertyName = hostPropertyName;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -59,12 +59,12 @@ export class ReflectComponents {
|
|
|
59
59
|
}
|
|
60
60
|
static addInput(modelProperty, modelName, viewName) {
|
|
61
61
|
const bootstrap = ReflectComponents.getOrCreateBootstrap(modelProperty);
|
|
62
|
-
bootstrap.inputs
|
|
62
|
+
bootstrap.inputs ?? (bootstrap.inputs = []);
|
|
63
63
|
bootstrap.inputs.push(new InputPropertyRef(modelName, viewName));
|
|
64
64
|
}
|
|
65
65
|
static addOutput(modelProperty, modelName, viewName, options) {
|
|
66
66
|
const bootstrap = ReflectComponents.getOrCreateBootstrap(modelProperty);
|
|
67
|
-
bootstrap.outputs
|
|
67
|
+
bootstrap.outputs ?? (bootstrap.outputs = []);
|
|
68
68
|
bootstrap.outputs.push(new OutputPropertyRef(modelName, viewName, options));
|
|
69
69
|
}
|
|
70
70
|
static setComponentView(modelProperty, modelName) {
|
|
@@ -73,23 +73,23 @@ export class ReflectComponents {
|
|
|
73
73
|
}
|
|
74
74
|
static addViewChild(modelProperty, modelName, selector, childOptions) {
|
|
75
75
|
const bootstrap = ReflectComponents.getOrCreateBootstrap(modelProperty);
|
|
76
|
-
bootstrap.viewChild
|
|
76
|
+
bootstrap.viewChild ?? (bootstrap.viewChild = []);
|
|
77
77
|
bootstrap.viewChild.push(new ChildRef(modelName, selector, childOptions));
|
|
78
78
|
}
|
|
79
79
|
static addViewChildren(modelProperty, modelName, selector) {
|
|
80
80
|
const bootstrap = ReflectComponents.getOrCreateBootstrap(modelProperty);
|
|
81
|
-
bootstrap.ViewChildren
|
|
81
|
+
bootstrap.ViewChildren ?? (bootstrap.ViewChildren = []);
|
|
82
82
|
bootstrap.ViewChildren.push(new ChildRef(modelName, selector));
|
|
83
83
|
}
|
|
84
84
|
static addHostListener(modelProperty, propertyKey, eventName, args) {
|
|
85
85
|
const bootstrap = ReflectComponents.getOrCreateBootstrap(modelProperty);
|
|
86
|
-
bootstrap.hostListeners
|
|
86
|
+
bootstrap.hostListeners ?? (bootstrap.hostListeners = []);
|
|
87
87
|
bootstrap.hostListeners.push(new ListenerRef(eventName, args, propertyKey));
|
|
88
88
|
}
|
|
89
89
|
static addHostBinding(modelProperty, propertyKey, hostPropertyName) {
|
|
90
90
|
const bootstrap = ReflectComponents.getOrCreateBootstrap(modelProperty);
|
|
91
|
-
bootstrap.
|
|
92
|
-
bootstrap.
|
|
91
|
+
bootstrap.hostBindings ?? (bootstrap.hostBindings = []);
|
|
92
|
+
bootstrap.hostBindings.push(new HostBindingRef(propertyKey, hostPropertyName));
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
//# sourceMappingURL=reflect.js.map
|