@ibyar/core 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/annotation/decorators.d.ts +2 -3
- package/annotation/decorators.js.map +1 -1
- package/binding/binding.expressions.d.ts +32 -0
- package/binding/binding.expressions.js +104 -0
- package/binding/binding.expressions.js.map +1 -0
- package/component/component.d.ts +3 -4
- package/component/component.js +5 -7
- package/component/component.js.map +1 -1
- package/component/custom-element.d.ts +12 -16
- package/component/custom-element.js.map +1 -1
- package/component/provider.d.ts +2 -2
- package/component/provider.js +3 -3
- package/component/provider.js.map +1 -1
- package/directive/directive.d.ts +8 -10
- package/directive/directive.js +4 -8
- package/directive/directive.js.map +1 -1
- package/directive/parser.d.ts +30 -0
- package/directive/parser.js +174 -0
- package/directive/parser.js.map +1 -0
- package/html/expression.d.ts +21 -2
- package/html/expression.js +82 -22
- package/html/expression.js.map +1 -1
- package/index.d.ts +3 -1
- package/index.js +3 -1
- package/index.js.map +1 -1
- package/linker/change-detector-ref.d.ts +7 -0
- package/linker/change-detector-ref.js +31 -0
- package/linker/change-detector-ref.js.map +1 -0
- package/linker/template-ref.d.ts +22 -0
- package/linker/template-ref.js +57 -0
- package/linker/template-ref.js.map +1 -0
- package/linker/view-container-ref.d.ts +41 -0
- package/linker/view-container-ref.js +82 -0
- package/linker/view-container-ref.js.map +1 -0
- package/linker/view-ref.d.ts +38 -0
- package/linker/view-ref.js +78 -0
- package/linker/view-ref.js.map +1 -0
- package/package.json +5 -5
- package/pipe/pipe.d.ts +26 -5
- package/pipe/pipe.js +41 -10
- package/pipe/pipe.js.map +1 -1
- package/providers/provider.d.ts +1 -1
- package/providers/provider.js +6 -3
- package/providers/provider.js.map +1 -1
- package/utils/elements-util.js +4 -1
- package/utils/elements-util.js.map +1 -1
- package/view/base-view.d.ts +1 -1
- package/view/base-view.js +34 -50
- package/view/base-view.js.map +1 -1
- package/view/mutation.d.ts +9 -1
- package/view/mutation.js +37 -6
- package/view/mutation.js.map +1 -1
- package/view/render.d.ts +24 -24
- package/view/render.js +145 -155
- package/view/render.js.map +1 -1
- package/view/view.d.ts +2 -2
- package/view/view.js +7 -10
- package/view/view.js.map +1 -1
- package/html/update.d.ts +0 -12
- package/html/update.js +0 -24
- package/html/update.js.map +0 -1
- package/model/change-detection.d.ts +0 -13
- package/model/change-detection.js +0 -100
- package/model/change-detection.js.map +0 -1
- package/view/events.d.ts +0 -2
- package/view/events.js +0 -25
- package/view/events.js.map +0 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { TypeOf } from '../utils/typeof.js';
|
|
2
|
+
import { TemplateRef } from './template-ref.js';
|
|
3
|
+
import { EmbeddedViewRef, ViewRef } from './view-ref.js';
|
|
4
|
+
export declare type ViewContainerOptions<C> = {
|
|
5
|
+
index?: number;
|
|
6
|
+
context?: C;
|
|
7
|
+
};
|
|
8
|
+
export declare type ViewContainerComponentOptions = {
|
|
9
|
+
index?: number | undefined;
|
|
10
|
+
selector?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare abstract class ViewContainerRef {
|
|
13
|
+
abstract get anchorElement(): Element;
|
|
14
|
+
abstract clear(): void;
|
|
15
|
+
abstract get(index: number): ViewRef | undefined;
|
|
16
|
+
abstract get length(): number;
|
|
17
|
+
abstract createEmbeddedView<C extends object>(templateRef: TemplateRef, options?: ViewContainerOptions<C>): EmbeddedViewRef<C>;
|
|
18
|
+
abstract createComponent<C extends object>(componentType: TypeOf<C>, options?: ViewContainerComponentOptions): C;
|
|
19
|
+
abstract insert(viewRef: ViewRef, index?: number): ViewRef;
|
|
20
|
+
abstract move(viewRef: ViewRef, newIndex: number): ViewRef;
|
|
21
|
+
abstract indexOf(viewRef: ViewRef): number;
|
|
22
|
+
abstract remove(index?: number): void;
|
|
23
|
+
abstract detach(index?: number): ViewRef | undefined;
|
|
24
|
+
}
|
|
25
|
+
export declare class ViewContainerRefImpl extends ViewContainerRef {
|
|
26
|
+
private parent;
|
|
27
|
+
private firstComment;
|
|
28
|
+
private views;
|
|
29
|
+
constructor(parent: Element, firstComment: Comment);
|
|
30
|
+
get anchorElement(): Element;
|
|
31
|
+
get length(): number;
|
|
32
|
+
clear(): void;
|
|
33
|
+
get(index: number): ViewRef | undefined;
|
|
34
|
+
detach(index?: number): ViewRef | undefined;
|
|
35
|
+
indexOf(viewRef: EmbeddedViewRef<any>): number;
|
|
36
|
+
remove(index?: number): void;
|
|
37
|
+
insert(viewRef: EmbeddedViewRef<any>, index?: number): ViewRef;
|
|
38
|
+
move(viewRef: EmbeddedViewRef<any>, newIndex: number): ViewRef;
|
|
39
|
+
createEmbeddedView<C extends object>(templateRef: TemplateRef, options?: ViewContainerOptions<C>): EmbeddedViewRef<C>;
|
|
40
|
+
createComponent<C extends object>(componentType: TypeOf<C>, options?: ViewContainerComponentOptions): C;
|
|
41
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Components } from '../component/component.js';
|
|
2
|
+
import { EmbeddedViewRefImpl } from './view-ref.js';
|
|
3
|
+
import { getComponentView } from '../view/view.js';
|
|
4
|
+
export class ViewContainerRef {
|
|
5
|
+
}
|
|
6
|
+
export class ViewContainerRefImpl extends ViewContainerRef {
|
|
7
|
+
constructor(parent, firstComment) {
|
|
8
|
+
super();
|
|
9
|
+
this.parent = parent;
|
|
10
|
+
this.firstComment = firstComment;
|
|
11
|
+
this.views = [];
|
|
12
|
+
}
|
|
13
|
+
get anchorElement() {
|
|
14
|
+
return this.parent;
|
|
15
|
+
}
|
|
16
|
+
get length() {
|
|
17
|
+
return this.views.length;
|
|
18
|
+
}
|
|
19
|
+
clear() {
|
|
20
|
+
if (this.views.length > 0) {
|
|
21
|
+
for (const elm of this.views) {
|
|
22
|
+
elm.destroy();
|
|
23
|
+
}
|
|
24
|
+
this.views.splice(0);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
get(index) {
|
|
28
|
+
if (index >= this.views.length) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
return this.views[index];
|
|
32
|
+
}
|
|
33
|
+
detach(index) {
|
|
34
|
+
index ??= this.views.length - 1;
|
|
35
|
+
const viewRef = this.views[index];
|
|
36
|
+
viewRef.detach();
|
|
37
|
+
this.views.splice(index, 1);
|
|
38
|
+
return viewRef;
|
|
39
|
+
}
|
|
40
|
+
indexOf(viewRef) {
|
|
41
|
+
return this.views.indexOf(viewRef);
|
|
42
|
+
}
|
|
43
|
+
remove(index) {
|
|
44
|
+
index ??= this.views.length - 1;
|
|
45
|
+
this.views[index].destroy();
|
|
46
|
+
this.views.splice(index, 1);
|
|
47
|
+
}
|
|
48
|
+
insert(viewRef, index) {
|
|
49
|
+
index = ((index ??= this.views.length) > this.views.length) ? this.views.length : index;
|
|
50
|
+
const lastNode = index == 0 ? this.firstComment : this.views[index - 1].last;
|
|
51
|
+
this.views.splice(index, 0, viewRef);
|
|
52
|
+
viewRef.after(lastNode);
|
|
53
|
+
return viewRef;
|
|
54
|
+
}
|
|
55
|
+
move(viewRef, newIndex) {
|
|
56
|
+
const oldIndex = this.indexOf(viewRef);
|
|
57
|
+
if (oldIndex > -1) {
|
|
58
|
+
this.detach(oldIndex);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
viewRef.detach();
|
|
62
|
+
}
|
|
63
|
+
return this.insert(viewRef, newIndex);
|
|
64
|
+
}
|
|
65
|
+
createEmbeddedView(templateRef, options) {
|
|
66
|
+
const viewRef = templateRef.createEmbeddedView(options?.context || {}, this.parent);
|
|
67
|
+
this.insert(viewRef, options?.index);
|
|
68
|
+
return viewRef;
|
|
69
|
+
}
|
|
70
|
+
createComponent(componentType, options) {
|
|
71
|
+
const defaultTagName = Components.getComponentRef(componentType).selector;
|
|
72
|
+
const ViewClass = getComponentView(componentType, options?.selector ?? defaultTagName);
|
|
73
|
+
if (!ViewClass) {
|
|
74
|
+
throw new Error(`Can't find View component for class ${componentType.name}`);
|
|
75
|
+
}
|
|
76
|
+
const component = new ViewClass();
|
|
77
|
+
const viewRef = new EmbeddedViewRefImpl(component._proxyModel, [component]);
|
|
78
|
+
this.insert(viewRef, options?.index);
|
|
79
|
+
return component._proxyModel;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=view-container-ref.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view-container-ref.js","sourceRoot":"","sources":["../../../src/core/linker/view-container-ref.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEvD,OAAO,EAAmB,mBAAmB,EAAW,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAWnD,MAAM,OAAgB,gBAAgB;CAqGrC;AAGD,MAAM,OAAO,oBAAqB,SAAQ,gBAAgB;IAIzD,YACS,MAAe,EACf,YAAqB;QAE7B,KAAK,EAAE,CAAC;QAHA,WAAM,GAAN,MAAM,CAAS;QACf,iBAAY,GAAZ,YAAY,CAAS;QAJtB,UAAK,GAA2B,EAAE,CAAC;IAO3C,CAAC;IACD,IAAa,aAAa;QACzB,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IACD,IAAa,MAAM;QAClB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAC1B,CAAC;IACQ,KAAK;QACb,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,EAAE;gBAC7B,GAAG,CAAC,OAAO,EAAE,CAAC;aACd;YACD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;SACrB;IACF,CAAC;IACQ,GAAG,CAAC,KAAa;QACzB,IAAI,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;YAC/B,OAAO,SAAS,CAAC;SACjB;QACD,OAAO,IAAI,CAAC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AED","sourcesContent":["import type { TypeOf } from '../utils/typeof.js';\nimport { Components } from '../component/component.js';\nimport { TemplateRef } from './template-ref.js';\nimport { EmbeddedViewRef, EmbeddedViewRefImpl, ViewRef } from './view-ref.js';\nimport { getComponentView } from '../view/view.js';\n\nexport type ViewContainerOptions<C> = {\n\tindex?: number;\n\tcontext?: C;\n};\n\nexport type ViewContainerComponentOptions = {\n\tindex?: number | undefined;\n\tselector?: string;\n};\nexport abstract class ViewContainerRef {\n\n\t/**\n\t * Anchor element that specifies the location of this container in the containing view.\n\t * Each view container can have only one anchor element, and each anchor element\n\t * can have only a single view container.\n\t * \n\t * Root elements of views attached to this container become siblings of the anchor element in\n\t * the rendered view.\n\t *\n\t * Access the `ViewContainerRef` of an element by placing a `Directive` injected\n\t * with `ViewContainerRef` on the element, or use a `ViewChild` query.\n\t *\n\t */\n\tabstract get anchorElement(): Element;\n\n\t/**\n\t * Destroys all views in this container.\n\t */\n\tabstract clear(): void;\n\n\t/**\n\t * Retrieves a view from this container.\n\t * @param index The 0-based index of the view to retrieve.\n\t * @returns The `ViewRef` instance, or null if the index is out of range.\n\t */\n\tabstract get(index: number): ViewRef | undefined;\n\n\t/**\n\t * Reports how many views are currently attached to this container.\n\t * @returns The number of views.\n\t */\n\tabstract get length(): number;\n\n\t/**\n\t * Instantiates an embedded view and inserts it\n\t * into this container.\n\t * @param templateRef The HTML template that defines the view.\n\t * @param context The data-binding context of the embedded view, as declared\n\t * in the `<ng-template>` usage.\n\t * @param index The 0-based index at which to insert the new view into this container.\n\t * If not specified, appends the new view as the last entry.\n\t *\n\t * @returns The `ViewRef` instance for the newly created view.\n\t */\n\tabstract createEmbeddedView<C extends object>(templateRef: TemplateRef, options?: ViewContainerOptions<C>): EmbeddedViewRef<C>;\n\n\t/**\n * Instantiates a single component and inserts its host view into this container.\n *\n * @param componentType Component Type to use.\n * @param options An object that contains extra parameters:\n * * index: the index at which to insert the new component's host view into this container.\n * If not specified, appends the new view as the last entry.\n * * selector: the tag name of the new create component that attached with this model class.\n * \t\t\tAny Model class can have many views with different selectors. \n *\n * @returns The new `HTMLComponent` which contains the component instance and the host view.\n */\n\tabstract createComponent<C extends object>(componentType: TypeOf<C>, options?: ViewContainerComponentOptions): C;\n\n\t/**\n\t * Inserts a view into this container.\n\t * @param viewRef The view to insert.\n\t * @param index The 0-based index at which to insert the view.\n\t * If not specified, appends the new view as the last entry.\n\t * @returns The inserted `ViewRef` instance.\n\t *\n\t */\n\tabstract insert(viewRef: ViewRef, index?: number): ViewRef;\n\n\t/**\n\t * Moves a view to a new location in this container.\n\t * @param viewRef The view to move.\n\t * @param newIndex The 0-based index of the new location.\n\t * @returns The moved `ViewRef` instance.\n\t */\n\tabstract move(viewRef: ViewRef, newIndex: number): ViewRef;\n\n\t/**\n\t * Returns the index of a view within the current container.\n\t * @param viewRef The view to query.\n\t * @returns The 0-based index of the view's position in this container,\n\t * or `-1` if this container doesn't contain the view.\n\t */\n\tabstract indexOf(viewRef: ViewRef): number;\n\n\t/**\n\t * Destroys a view attached to this container\n\t * @param index The 0-based index of the view to destroy.\n\t * If not specified, the last view in the container is removed.\n\t */\n\tabstract remove(index?: number): void;\n\n\t/**\n\t * Detaches a view from this container without destroying it.\n\t * Use along with `insert()` to move a view within the current container.\n\t * @param index The 0-based index of the view to detach.\n\t * If not specified, the last view in the container is detached.\n\t */\n\tabstract detach(index?: number): ViewRef | undefined;\n}\n\n\nexport class ViewContainerRefImpl extends ViewContainerRef {\n\n\tprivate views: EmbeddedViewRef<any>[] = [];\n\n\tconstructor(\n\t\tprivate parent: Element,\n\t\tprivate firstComment: Comment\n\t) {\n\t\tsuper();\n\t}\n\toverride get anchorElement(): Element {\n\t\treturn this.parent;\n\t}\n\toverride get length(): number {\n\t\treturn this.views.length;\n\t}\n\toverride clear(): void {\n\t\tif (this.views.length > 0) {\n\t\t\tfor (const elm of this.views) {\n\t\t\t\telm.destroy();\n\t\t\t}\n\t\t\tthis.views.splice(0);\n\t\t}\n\t}\n\toverride get(index: number): ViewRef | undefined {\n\t\tif (index >= this.views.length) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.views[index];\n\t}\n\toverride detach(index?: number): ViewRef | undefined {\n\t\tindex ??= this.views.length - 1;\n\t\tconst viewRef = this.views[index];\n\t\tviewRef.detach();\n\t\tthis.views.splice(index, 1);\n\t\treturn viewRef;\n\t}\n\toverride indexOf(viewRef: EmbeddedViewRef<any>): number {\n\t\treturn this.views.indexOf(viewRef);\n\t}\n\toverride remove(index?: number): void {\n\t\tindex ??= this.views.length - 1;\n\t\tthis.views[index].destroy();\n\t\tthis.views.splice(index, 1);\n\t}\n\toverride insert(viewRef: EmbeddedViewRef<any>, index?: number): ViewRef {\n\t\tindex = ((index ??= this.views.length) > this.views.length) ? this.views.length : index;\n\t\tconst lastNode = index == 0 ? this.firstComment : this.views[index - 1].last;\n\t\tthis.views.splice(index, 0, viewRef);\n\t\tviewRef.after(lastNode);\n\t\treturn viewRef;\n\t}\n\toverride move(viewRef: EmbeddedViewRef<any>, newIndex: number): ViewRef {\n\t\tconst oldIndex = this.indexOf(viewRef);\n\t\tif (oldIndex > -1) {\n\t\t\tthis.detach(oldIndex);\n\t\t} else {\n\t\t\t// should remove it from the container first\n\t\t\tviewRef.detach();\n\t\t}\n\t\treturn this.insert(viewRef, newIndex);\n\t}\n\toverride createEmbeddedView<C extends object>(templateRef: TemplateRef, options?: ViewContainerOptions<C>): EmbeddedViewRef<C> {\n\t\tconst viewRef = templateRef.createEmbeddedView<C>(options?.context || <C>{}, this.parent);\n\t\tthis.insert(viewRef, options?.index);\n\t\treturn viewRef;\n\t}\n\toverride createComponent<C extends object>(componentType: TypeOf<C>, options?: ViewContainerComponentOptions): C {\n\t\tconst defaultTagName = Components.getComponentRef<C>(componentType).selector;\n\t\tconst ViewClass = getComponentView(componentType, options?.selector ?? defaultTagName);\n\t\tif (!ViewClass) {\n\t\t\tthrow new Error(`Can't find View component for class ${componentType.name}`);\n\t\t}\n\t\tconst component = new ViewClass();\n\t\tconst viewRef = new EmbeddedViewRefImpl<C>(component._proxyModel, [component]);\n\t\tthis.insert(viewRef, options?.index);\n\t\treturn component._proxyModel;\n\t}\n\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ScopeContext, ScopeSubscription } from '@ibyar/expressions';
|
|
2
|
+
export declare abstract class ViewRef {
|
|
3
|
+
abstract destroy(): void;
|
|
4
|
+
abstract get destroyed(): boolean;
|
|
5
|
+
abstract onDestroy(callback: Function): {
|
|
6
|
+
unsubscribe(): void;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export declare abstract class EmbeddedViewRef<C extends object> extends ViewRef {
|
|
10
|
+
abstract get context(): C;
|
|
11
|
+
abstract get rootNodes(): Node[];
|
|
12
|
+
abstract get first(): ChildNode;
|
|
13
|
+
abstract get last(): ChildNode;
|
|
14
|
+
abstract after(node: ChildNode): void;
|
|
15
|
+
abstract before(node: ChildNode): void;
|
|
16
|
+
abstract detach(): void;
|
|
17
|
+
}
|
|
18
|
+
export declare class EmbeddedViewRefImpl<C extends object> extends EmbeddedViewRef<C> {
|
|
19
|
+
private _context;
|
|
20
|
+
private _rootNodes;
|
|
21
|
+
private _subscriptions?;
|
|
22
|
+
private _destroyed;
|
|
23
|
+
private onDestroySubscribes;
|
|
24
|
+
constructor(_context: C, _rootNodes: Node[], _subscriptions?: ScopeSubscription<ScopeContext>[] | undefined);
|
|
25
|
+
get context(): C;
|
|
26
|
+
get rootNodes(): Node[];
|
|
27
|
+
get first(): Element;
|
|
28
|
+
get last(): Element;
|
|
29
|
+
get destroyed(): boolean;
|
|
30
|
+
destroy(): void;
|
|
31
|
+
private getAsANode;
|
|
32
|
+
after(node: ChildNode): void;
|
|
33
|
+
before(node: ChildNode): void;
|
|
34
|
+
detach(): void;
|
|
35
|
+
onDestroy(callback: () => void): {
|
|
36
|
+
unsubscribe(): void;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export class ViewRef {
|
|
2
|
+
}
|
|
3
|
+
export class EmbeddedViewRef extends ViewRef {
|
|
4
|
+
}
|
|
5
|
+
export class EmbeddedViewRefImpl extends EmbeddedViewRef {
|
|
6
|
+
constructor(_context, _rootNodes, _subscriptions) {
|
|
7
|
+
super();
|
|
8
|
+
this._context = _context;
|
|
9
|
+
this._rootNodes = _rootNodes;
|
|
10
|
+
this._subscriptions = _subscriptions;
|
|
11
|
+
this._destroyed = false;
|
|
12
|
+
this.onDestroySubscribes = [];
|
|
13
|
+
}
|
|
14
|
+
get context() {
|
|
15
|
+
return this._context;
|
|
16
|
+
}
|
|
17
|
+
get rootNodes() {
|
|
18
|
+
return this._rootNodes;
|
|
19
|
+
}
|
|
20
|
+
get first() {
|
|
21
|
+
return this._rootNodes[0];
|
|
22
|
+
}
|
|
23
|
+
get last() {
|
|
24
|
+
return this._rootNodes[this._rootNodes.length - 1];
|
|
25
|
+
}
|
|
26
|
+
get destroyed() {
|
|
27
|
+
return this._destroyed;
|
|
28
|
+
}
|
|
29
|
+
destroy() {
|
|
30
|
+
if (!this._destroyed) {
|
|
31
|
+
this._subscriptions?.forEach(sub => sub.unsubscribe());
|
|
32
|
+
this._subscriptions?.splice(0, this._subscriptions.length);
|
|
33
|
+
for (const node of this._rootNodes) {
|
|
34
|
+
node.remove();
|
|
35
|
+
}
|
|
36
|
+
this.onDestroySubscribes.forEach(callback => {
|
|
37
|
+
try {
|
|
38
|
+
callback();
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.error(error);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
this._destroyed = true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
getAsANode() {
|
|
48
|
+
if (this._rootNodes.length == 1) {
|
|
49
|
+
return this._rootNodes[0];
|
|
50
|
+
}
|
|
51
|
+
const fragment = document.createDocumentFragment();
|
|
52
|
+
this._rootNodes.forEach(node => fragment.append(node));
|
|
53
|
+
return fragment;
|
|
54
|
+
}
|
|
55
|
+
after(node) {
|
|
56
|
+
node.after(this.getAsANode());
|
|
57
|
+
}
|
|
58
|
+
before(node) {
|
|
59
|
+
node.before(this.getAsANode());
|
|
60
|
+
}
|
|
61
|
+
detach() {
|
|
62
|
+
for (const node of this._rootNodes) {
|
|
63
|
+
node.remove();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
onDestroy(callback) {
|
|
67
|
+
this.onDestroySubscribes.push(callback);
|
|
68
|
+
return {
|
|
69
|
+
unsubscribe: () => {
|
|
70
|
+
const index = this.onDestroySubscribes.indexOf(callback);
|
|
71
|
+
if (index > -1) {
|
|
72
|
+
this.onDestroySubscribes.splice(index, 1);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=view-ref.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view-ref.js","sourceRoot":"","sources":["../../../src/core/linker/view-ref.ts"],"names":[],"mappings":"AAEA,MAAM,OAAgB,OAAO;CAmB5B;AAGD,MAAM,OAAgB,eAAkC,SAAQ,OAAO;CAwCtE;AAED,MAAM,OAAO,mBAAsC,SAAQ,eAAkB;IAK5E,YACS,QAAW,EACX,UAAkB,EAClB,cAAkD;QAC1D,KAAK,EAAE,CAAC;QAHA,aAAQ,GAAR,QAAQ,CAAG;QACX,eAAU,GAAV,UAAU,CAAQ;QAClB,mBAAc,GAAd,cAAc,CAAoC;QANnD,eAAU,GAAY,KAAK,CAAC;QAC5B,wBAAmB,GAAmB,EAAE,CAAC;IAOjD,CAAC;IAED,IAAI,OAAO;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC;IACtB,CAAC;IAED,IAAI,SAAS;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC;IACxB,CAAC;IACD,IAAI,KAAK;QACR,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAY,CAAC;IACtC,CAAC;IACD,IAAI,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AAC;IACD,MAAM,CAAC,IAAe;QACrB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IAChC,CAAC;IACD,MAAM;QACL,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE;YACzB,IAAK,CAAC,MAAM,EAAE,CAAC;SACzB;IACF,CAAC;IACD,SAAS,CAAC,QAAoB;QAC7B,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxC,OAAO;YACN,WAAW,EAAE,GAAG,EAAE;gBACjB,MAAM,KAAK,GAAG,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;gBACzD,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE;oBACf,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;iBAC1C;YACF,CAAC;SACD,CAAC;IACH,CAAC;CAED","sourcesContent":["import { ScopeContext, ScopeSubscription } from '@ibyar/expressions';\n\nexport abstract class ViewRef {\n\t/**\n\t * Destroys this view and all of the data structures associated with it.\n\t */\n\tabstract destroy(): void;\n\n\t/**\n\t * Reports whether this view has been destroyed.\n\t * @returns True after the `destroy()` method has been called, false otherwise.\n\t */\n\tabstract get destroyed(): boolean;\n\n\t/**\n\t * A lifecycle hook that provides additional developer-defined cleanup\n\t * functionality for views.\n\t * @param callback A handler function that cleans up developer-defined data\n\t * associated with a view. Called when the `destroy()` method is invoked.\n\t */\n\tabstract onDestroy(callback: Function): { unsubscribe(): void };\n}\n\n\nexport abstract class EmbeddedViewRef<C extends object> extends ViewRef {\n\t/**\n\t * The context for this view, inherited from the anchor element.\n\t */\n\tabstract get context(): C;\n\n\t/**\n\t * The root nodes for this embedded view.\n\t */\n\tabstract get rootNodes(): Node[];\n\n\t/**\n\t * the first node for this embedded view.\n\t */\n\tabstract get first(): ChildNode;\n\n\t/**\n\t * the last node for this embedded view.\n\t */\n\tabstract get last(): ChildNode;\n\n\t/**\n\t * insert view after the node.\n\t * @param node \n\t */\n\tabstract after(node: ChildNode): void;\n\n\t/**\n\t * insert view before the node.\n\t * @param node \n\t */\n\tabstract before(node: ChildNode): void;\n\n\t/**\n\t * remove the root nodes from the view, but keep reference to them.\n\t * \n\t * Detaches a view from this container without destroying it.\n\t * Use along with after()/before() to move a view within the current container.\n\t */\n\tabstract detach(): void;\n}\n\nexport class EmbeddedViewRefImpl<C extends object> extends EmbeddedViewRef<C> {\n\n\tprivate _destroyed: boolean = false;\n\tprivate onDestroySubscribes: (() => void)[] = [];\n\n\tconstructor(\n\t\tprivate _context: C,\n\t\tprivate _rootNodes: Node[],\n\t\tprivate _subscriptions?: ScopeSubscription<ScopeContext>[]) {\n\t\tsuper();\n\t}\n\n\tget context(): C {\n\t\treturn this._context;\n\t}\n\n\tget rootNodes(): Node[] {\n\t\treturn this._rootNodes;\n\t}\n\tget first(): Element {\n\t\treturn this._rootNodes[0] as Element;\n\t}\n\tget last(): Element {\n\t\treturn this._rootNodes[this._rootNodes.length - 1] as Element;\n\t}\n\tget destroyed(): boolean {\n\t\treturn this._destroyed;\n\t}\n\tdestroy(): void {\n\t\tif (!this._destroyed) {\n\t\t\tthis._subscriptions?.forEach(sub => sub.unsubscribe());\n\t\t\tthis._subscriptions?.splice(0, this._subscriptions.length);\n\t\t\tfor (const node of this._rootNodes) {\n\t\t\t\t(<Element>node).remove();\n\t\t\t}\n\t\t\tthis.onDestroySubscribes.forEach(callback => {\n\t\t\t\ttry {\n\t\t\t\t\tcallback();\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconsole.error(error);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis._destroyed = true;\n\t\t}\n\t}\n\tprivate getAsANode() {\n\t\tif (this._rootNodes.length == 1) {\n\t\t\treturn this._rootNodes[0];\n\t\t}\n\t\tconst fragment = document.createDocumentFragment();\n\t\tthis._rootNodes.forEach(node => fragment.append(node));\n\t\treturn fragment;\n\t}\n\tafter(node: ChildNode): void {\n\t\tnode.after(this.getAsANode());\n\t}\n\tbefore(node: ChildNode): void {\n\t\tnode.before(this.getAsANode());\n\t}\n\tdetach(): void {\n\t\tfor (const node of this._rootNodes) {\n\t\t\t(<Element>node).remove();\n\t\t}\n\t}\n\tonDestroy(callback: () => void): { unsubscribe(): void; } {\n\t\tthis.onDestroySubscribes.push(callback);\n\t\treturn {\n\t\t\tunsubscribe: () => {\n\t\t\t\tconst index = this.onDestroySubscribes.indexOf(callback);\n\t\t\t\tif (index > -1) {\n\t\t\t\t\tthis.onDestroySubscribes.splice(index, 1);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}\n\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ibyar/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Implements Aurora's core functionality, low-level services, and utilities",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/ibyar/aurora/tree/dev/packages/core",
|
|
@@ -23,13 +23,13 @@
|
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@ibyar/elements": "^0.
|
|
27
|
-
"@ibyar/expressions": "^0.
|
|
26
|
+
"@ibyar/elements": "^0.5.1",
|
|
27
|
+
"@ibyar/expressions": "^0.5.1",
|
|
28
28
|
"reflect-metadata": "^0.1.13",
|
|
29
29
|
"tslib": "^2.3.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"typescript": "^4.
|
|
32
|
+
"typescript": "^4.5.2"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "tsc --build --verbose"
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"interceptor",
|
|
63
63
|
"typescript"
|
|
64
64
|
],
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "5e5951cccc30d333c2629a95d0c8a0627129d43c"
|
|
66
66
|
}
|
package/pipe/pipe.d.ts
CHANGED
|
@@ -1,17 +1,38 @@
|
|
|
1
|
-
import { ReadOnlyScope } from '@ibyar/expressions';
|
|
1
|
+
import { ReactiveScopeControl, ReadOnlyScope, ScopeSubscription } from '@ibyar/expressions';
|
|
2
|
+
import { OnDestroy } from '../component/lifecycle.js';
|
|
3
|
+
import { ChangeDetectorRef } from '../linker/change-detector-ref.js';
|
|
4
|
+
import { TypeOf } from '../utils/typeof.js';
|
|
2
5
|
export interface PipeTransform<T, U> {
|
|
3
6
|
transform(value: T, ...args: any[]): U;
|
|
4
7
|
}
|
|
8
|
+
export declare abstract class AsyncPipeTransform<T, U> implements PipeTransform<T, U>, OnDestroy {
|
|
9
|
+
protected changeDetectorRef: ChangeDetectorRef;
|
|
10
|
+
constructor(changeDetectorRef: ChangeDetectorRef);
|
|
11
|
+
abstract transform(value: T, ...args: any[]): U;
|
|
12
|
+
abstract onDestroy(): void;
|
|
13
|
+
}
|
|
5
14
|
export declare function isPipeTransform<T extends any, U extends any>(pipe: any): pipe is PipeTransform<T, U>;
|
|
6
|
-
export declare class PipeProvider extends ReadOnlyScope<
|
|
7
|
-
|
|
15
|
+
export declare class PipeProvider extends ReadOnlyScope<{
|
|
16
|
+
[pipeName: string]: Function;
|
|
17
|
+
}> {
|
|
8
18
|
constructor();
|
|
9
19
|
has(pipeName: string): boolean;
|
|
10
20
|
get(pipeName: string): any;
|
|
11
21
|
}
|
|
12
22
|
export declare class AsyncPipeProvider extends ReadOnlyScope<object> {
|
|
13
|
-
static AsyncPipeContext: any;
|
|
14
23
|
constructor();
|
|
15
24
|
has(pipeName: string): boolean;
|
|
16
|
-
get(pipeName: string):
|
|
25
|
+
get(pipeName: string): TypeOf<AsyncPipeTransform<any, any>> | undefined;
|
|
26
|
+
}
|
|
27
|
+
export declare class AsyncPipeScope<T extends {
|
|
28
|
+
[key: string]: AsyncPipeTransform<any, any>;
|
|
29
|
+
}> extends ReactiveScopeControl<T> {
|
|
30
|
+
static blockScope<P extends {
|
|
31
|
+
[key: string]: AsyncPipeTransform<any, any>;
|
|
32
|
+
}>(): AsyncPipeScope<P>;
|
|
33
|
+
private wrapper;
|
|
34
|
+
constructor();
|
|
35
|
+
set(propertyKey: keyof T, pipeClass: TypeOf<AsyncPipeTransform<any, any>>, receiver?: any): boolean;
|
|
36
|
+
get(propertyKey: keyof T): any;
|
|
37
|
+
unsubscribe(propertyKey: keyof T, subscription?: ScopeSubscription<T>): void;
|
|
17
38
|
}
|
package/pipe/pipe.js
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
import { ReadOnlyScope } from '@ibyar/expressions';
|
|
1
|
+
import { ReactiveScopeControl, ReadOnlyScope } from '@ibyar/expressions';
|
|
2
|
+
import { createChangeDetectorRef } from '../linker/change-detector-ref.js';
|
|
2
3
|
import { ClassRegistryProvider } from '../providers/provider.js';
|
|
4
|
+
export class AsyncPipeTransform {
|
|
5
|
+
constructor(changeDetectorRef) {
|
|
6
|
+
this.changeDetectorRef = changeDetectorRef;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
3
9
|
export function isPipeTransform(pipe) {
|
|
4
10
|
return Reflect.has(Object.getPrototypeOf(pipe), 'transform');
|
|
5
11
|
}
|
|
6
12
|
export class PipeProvider extends ReadOnlyScope {
|
|
7
13
|
constructor() {
|
|
8
|
-
super(
|
|
14
|
+
super({}, 'block');
|
|
9
15
|
}
|
|
10
16
|
has(pipeName) {
|
|
11
|
-
if (this.context
|
|
17
|
+
if (pipeName in this.context) {
|
|
12
18
|
return true;
|
|
13
19
|
}
|
|
14
20
|
const pipeRef = ClassRegistryProvider.getPipe(pipeName);
|
|
@@ -16,23 +22,22 @@ export class PipeProvider extends ReadOnlyScope {
|
|
|
16
22
|
}
|
|
17
23
|
get(pipeName) {
|
|
18
24
|
let transformFunc;
|
|
19
|
-
if (transformFunc = this.context
|
|
25
|
+
if (transformFunc = this.context[pipeName]) {
|
|
20
26
|
return transformFunc;
|
|
21
27
|
}
|
|
22
28
|
const pipeRef = ClassRegistryProvider.getPipe(pipeName);
|
|
23
29
|
if (pipeRef !== undefined && !pipeRef.asynchronous) {
|
|
24
30
|
const pipe = new pipeRef.modelClass();
|
|
25
31
|
transformFunc = (value, ...args) => pipe.transform(value, ...args);
|
|
26
|
-
this.context
|
|
32
|
+
this.context[pipeRef.name] = transformFunc;
|
|
27
33
|
return transformFunc;
|
|
28
34
|
}
|
|
29
35
|
return void 0;
|
|
30
36
|
}
|
|
31
37
|
}
|
|
32
|
-
PipeProvider.PipeContext = new Map();
|
|
33
38
|
export class AsyncPipeProvider extends ReadOnlyScope {
|
|
34
39
|
constructor() {
|
|
35
|
-
super(
|
|
40
|
+
super({}, 'block');
|
|
36
41
|
}
|
|
37
42
|
has(pipeName) {
|
|
38
43
|
const pipeRef = ClassRegistryProvider.getPipe(pipeName);
|
|
@@ -41,10 +46,36 @@ export class AsyncPipeProvider extends ReadOnlyScope {
|
|
|
41
46
|
get(pipeName) {
|
|
42
47
|
const pipeRef = ClassRegistryProvider.getPipe(pipeName);
|
|
43
48
|
if (pipeRef?.asynchronous) {
|
|
44
|
-
return
|
|
49
|
+
return pipeRef.modelClass;
|
|
45
50
|
}
|
|
46
|
-
return void 0;
|
|
47
51
|
}
|
|
48
52
|
}
|
|
49
|
-
|
|
53
|
+
export class AsyncPipeScope extends ReactiveScopeControl {
|
|
54
|
+
constructor() {
|
|
55
|
+
super({}, 'block');
|
|
56
|
+
this.wrapper = {};
|
|
57
|
+
}
|
|
58
|
+
static blockScope() {
|
|
59
|
+
return new AsyncPipeScope();
|
|
60
|
+
}
|
|
61
|
+
set(propertyKey, pipeClass, receiver) {
|
|
62
|
+
const detector = createChangeDetectorRef(this, propertyKey);
|
|
63
|
+
const pipe = new pipeClass(detector);
|
|
64
|
+
const result = super.set(propertyKey, pipe, receiver);
|
|
65
|
+
if (result) {
|
|
66
|
+
this.wrapper[propertyKey] = (value, ...args) => {
|
|
67
|
+
return pipe.transform(value, ...args);
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
get(propertyKey) {
|
|
73
|
+
return Reflect.get(this.wrapper, propertyKey);
|
|
74
|
+
}
|
|
75
|
+
unsubscribe(propertyKey, subscription) {
|
|
76
|
+
this.unsubscribe(propertyKey, subscription);
|
|
77
|
+
const pipe = this.context[propertyKey];
|
|
78
|
+
pipe.onDestroy();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
50
81
|
//# sourceMappingURL=pipe.js.map
|
package/pipe/pipe.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipe.js","sourceRoot":"","sources":["../../../src/core/pipe/pipe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"pipe.js","sourceRoot":"","sources":["../../../src/core/pipe/pipe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAqB,MAAM,oBAAoB,CAAC;AAE5F,OAAO,EAAqB,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAC9F,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAcjE,MAAM,OAAgB,kBAAkB;IACvC,YAAsB,iBAAoC;QAApC,sBAAiB,GAAjB,iBAAiB,CAAmB;IAAI,CAAC;CAG/D;AAED,MAAM,UAAU,eAAe,CAA+B,IAAS;IACtE,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,OAAO,YAAa,SAAQ,aAA+C;IAChF;QACC,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IACpB,CAAC;IACD,GAAG,CAAC,QAAgB;QACnB,IAAI,QAAQ,IAAI,IAAI,CAAC,OAAO,EAAE;YAC7B,OAAO,IAAI,CAAC;SACZ;QACD,MAAM,OAAO,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AC;CACD;AAED,MAAM,OAAO,cAA0E,SAAQ,oBAAuB;IAKrH;QACC,KAAK,CAAC,EAAO,EAAE,OAAO,CAAC,CAAC;QAFjB,YAAO,GAAgC,EAAE,CAAC;IAGlD,CAAC;IAND,MAAM,CAAC,UAAU;QAChB,OAAO,IAAI,cAAc,EAAE,CAAC;IAC7B,CAAC;IAKQ,GAAG,CAAC,WAAoB,EAAE,SAA+C,EAAE,QAAc;QACjG,MAAM,QAAQ,GAAG,uBAAuB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QAC5D,MAAM,IAAI,GAAG,IAAI,SAAS,CAAC,QAAQ,CAAC,CAAC;QACrC,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QACtD,IAAI,MAAM,EAAE;YACX,IAAI,CAAC,OAAO,CAAC,WAAqB,CAAC,GAAG,CAAC,KAAU,EAAE,GAAG,IAAW,EAAE,EAAE;gBACpE,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAA;YACtC,CAAC,CAAC;SACF;QACD,OAAO,MAAM,CAAC;IACf,CAAC;IACQ,GAAG,CAAC,WAAoB;QAChC,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IAC/C,CAAC;IACQ,WAAW,CAAC,WAAoB,EAAE,YAAmC;QAC7E,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;QAC5C,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACvC,IAAI,CAAC,SAAS,EAAE,CAAC;IAClB,CAAC;CACD","sourcesContent":["import { ReactiveScopeControl, ReadOnlyScope, ScopeSubscription } from '@ibyar/expressions';\nimport { OnDestroy } from '../component/lifecycle.js';\nimport { ChangeDetectorRef, createChangeDetectorRef } from '../linker/change-detector-ref.js';\nimport { ClassRegistryProvider } from '../providers/provider.js';\nimport { TypeOf } from '../utils/typeof.js';\n\n/**\n * Pipes are used as singleton\n * it will be created if it needed, had no life cycle\n * \n * * no dependency injection applied on filters for now,\n * TODO: add support of dependency injection\n */\nexport interface PipeTransform<T, U> {\n\ttransform(value: T, ...args: any[]): U;\n}\n\nexport abstract class AsyncPipeTransform<T, U> implements PipeTransform<T, U>, OnDestroy {\n\tconstructor(protected changeDetectorRef: ChangeDetectorRef) { }\n\tabstract transform(value: T, ...args: any[]): U;\n\tabstract onDestroy(): void;\n}\n\nexport function isPipeTransform<T extends any, U extends any>(pipe: any): pipe is PipeTransform<T, U> {\n\treturn Reflect.has(Object.getPrototypeOf(pipe), 'transform');\n}\n\nexport class PipeProvider extends ReadOnlyScope<{ [pipeName: string]: Function }> {\n\tconstructor() {\n\t\tsuper({}, 'block');\n\t}\n\thas(pipeName: string): boolean {\n\t\tif (pipeName in this.context) {\n\t\t\treturn true;\n\t\t}\n\t\tconst pipeRef = ClassRegistryProvider.getPipe<PipeTransform<any, any>>(pipeName);\n\t\treturn pipeRef !== undefined && !pipeRef.asynchronous;\n\t}\n\tget(pipeName: string): any {\n\t\tlet transformFunc: Function | undefined;\n\t\tif (transformFunc = this.context[pipeName]) {\n\t\t\treturn transformFunc;\n\t\t}\n\t\tconst pipeRef = ClassRegistryProvider.getPipe<PipeTransform<any, any>>(pipeName);\n\t\tif (pipeRef !== undefined && !pipeRef.asynchronous) {\n\t\t\tconst pipe = new pipeRef.modelClass();\n\t\t\ttransformFunc = (value: any, ...args: any[]) => pipe.transform(value, ...args);\n\t\t\tthis.context[pipeRef.name] = transformFunc;\n\t\t\treturn transformFunc;\n\t\t}\n\t\treturn void 0;\n\t}\n}\n\nexport class AsyncPipeProvider extends ReadOnlyScope<object> {\n\tconstructor() {\n\t\tsuper({}, 'block');\n\t}\n\thas(pipeName: string): boolean {\n\t\tconst pipeRef = ClassRegistryProvider.getPipe<AsyncPipeTransform<any, any>>(pipeName);\n\t\treturn pipeRef?.asynchronous ? true : false;\n\t}\n\tget(pipeName: string): TypeOf<AsyncPipeTransform<any, any>> | undefined {\n\t\tconst pipeRef = ClassRegistryProvider.getPipe<AsyncPipeTransform<any, any>>(pipeName);\n\t\tif (pipeRef?.asynchronous) {\n\t\t\treturn pipeRef.modelClass;\n\t\t}\n\t}\n}\n\nexport class AsyncPipeScope<T extends { [key: string]: AsyncPipeTransform<any, any> }> extends ReactiveScopeControl<T> {\n\tstatic blockScope<P extends { [key: string]: AsyncPipeTransform<any, any> }>(): AsyncPipeScope<P> {\n\t\treturn new AsyncPipeScope();\n\t}\n\tprivate wrapper: { [key: string]: Function } = {};\n\tconstructor() {\n\t\tsuper({} as T, 'block');\n\t}\n\toverride set(propertyKey: keyof T, pipeClass: TypeOf<AsyncPipeTransform<any, any>>, receiver?: any): boolean {\n\t\tconst detector = createChangeDetectorRef(this, propertyKey);\n\t\tconst pipe = new pipeClass(detector);\n\t\tconst result = super.set(propertyKey, pipe, receiver);\n\t\tif (result) {\n\t\t\tthis.wrapper[propertyKey as string] = (value: any, ...args: any[]) => {\n\t\t\t\treturn pipe.transform(value, ...args)\n\t\t\t};\n\t\t}\n\t\treturn result;\n\t}\n\toverride get(propertyKey: keyof T): any {\n\t\treturn Reflect.get(this.wrapper, propertyKey);\n\t}\n\toverride unsubscribe(propertyKey: keyof T, subscription?: ScopeSubscription<T>) {\n\t\tthis.unsubscribe(propertyKey, subscription);\n\t\tconst pipe = this.context[propertyKey];\n\t\tpipe.onDestroy();\n\t}\n}\n"]}
|
package/providers/provider.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare class ClassRegistry {
|
|
|
18
18
|
hasOutput<T>(model: Object, eventName: string): PropertyRef | false;
|
|
19
19
|
hasInput<T>(model: Object, eventName: string): PropertyRef | false;
|
|
20
20
|
hasDirective<T>(selector: string): boolean;
|
|
21
|
-
directiveHasInput<T>(input: string): boolean;
|
|
21
|
+
directiveHasInput<T>(input: string, directiveType?: 'attributes' | 'structural'): boolean;
|
|
22
22
|
getDirectiveRef<T>(selector: string): DirectiveRef<T> | undefined;
|
|
23
23
|
getPipe<T>(pipeName: string): PipeRef<T> | undefined;
|
|
24
24
|
getService<T>(serviceName: string): ServiceRef<T> | undefined;
|
package/providers/provider.js
CHANGED
|
@@ -85,11 +85,14 @@ export class ClassRegistry {
|
|
|
85
85
|
}
|
|
86
86
|
return false;
|
|
87
87
|
}
|
|
88
|
-
directiveHasInput(input) {
|
|
88
|
+
directiveHasInput(input, directiveType = 'attributes') {
|
|
89
89
|
for (const directiveClass of this.directiveSet) {
|
|
90
90
|
const directiveRef = Components.getBootstrap(directiveClass.prototype);
|
|
91
|
-
if (
|
|
92
|
-
|
|
91
|
+
if ((directiveType === 'attributes' && !directiveRef.selector.startsWith('*'))
|
|
92
|
+
|| (directiveType === 'structural' && directiveRef.selector.startsWith('*'))) {
|
|
93
|
+
if (directiveRef.inputs?.filter(ref => ref.viewAttribute === input).length > 0) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
98
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/core/providers/provider.ts"],"names":[],"mappings":"AACA,OAAO,EACN,UAAU,EAEV,MAAM,2BAA2B,CAAC;AAGnC,MAAM,OAAO,aAAa;IAA1B;QACC,YAAO,GAAkB,IAAI,GAAG,EAAE,CAAC;QACnC,iBAAY,GAAkB,IAAI,GAAG,EAAE,CAAC;QACxC,eAAU,GAAkB,IAAI,GAAG,EAAE,CAAC;QACtC,iBAAY,GAAkB,IAAI,GAAG,EAAE,CAAC;QACxC,YAAO,GAAkB,IAAI,GAAG,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/core/providers/provider.ts"],"names":[],"mappings":"AACA,OAAO,EACN,UAAU,EAEV,MAAM,2BAA2B,CAAC;AAGnC,MAAM,OAAO,aAAa;IAA1B;QAC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AC,SAAS,CAAC,SAAS,CAAC,CAAC;YACzE,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE;gBAC9B,OAAO,OAAO,CAAC;aACf;SACD;QACD,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,UAAU,CAAI,WAAmB;QAChC,KAAK,MAAM,YAAY,IAAI,IAAI,CAAC,UAAU,EAAE;YAC3C,MAAM,UAAU,GAAkB,UAAU,CAAC,YAAY,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;YAClF,IAAI,UAAU,CAAC,IAAI,KAAK,WAAW,EAAE;gBACpC,OAAO,UAAU,CAAC;aAClB;SACD;QACD,OAAO,SAAS,CAAC;IAClB,CAAC;CACD;AAED,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,aAAa,EAAE,CAAC","sourcesContent":["\nimport {\n\tComponents, ComponentRef, DirectiveRef,\n\tPipeRef, PropertyRef, ServiceRef\n} from '../component/component.js';\nexport type ProviderType = 'component' | 'service' | 'directive' | 'pipe' | 'self';\n\nexport class ClassRegistry {\n\tviewSet: Set<Function> = new Set();\n\tcomponentSet: Set<Function> = new Set();\n\tserviceSet: Set<Function> = new Set();\n\tdirectiveSet: Set<Function> = new Set();\n\tpipeSet: Set<Function> = new Set();\n\n\tregisterView(classRef: Function): void {\n\t\tthis.viewSet.add(classRef);\n\t}\n\tregisterComponent(classRef: Function): void {\n\t\tthis.componentSet.add(classRef);\n\t}\n\tregisterService(classRef: Function): void {\n\t\tthis.serviceSet.add(classRef);\n\t}\n\tregisterDirective(classRef: Function): void {\n\t\tthis.directiveSet.add(classRef);\n\t}\n\tregisterPipe(classRef: Function): void {\n\t\tthis.pipeSet.add(classRef);\n\t}\n\n\thasComponent<T>(selector: string): boolean {\n\t\tfor (const modelClass of this.componentSet) {\n\t\t\tconst componentRef: ComponentRef<T> = Components.getComponentRef(modelClass);\n\t\t\tif (componentRef.selector === selector) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\tgetComponentRef<T>(selector: string): ComponentRef<T> | undefined {\n\t\tfor (const modelClass of this.componentSet) {\n\t\t\tconst componentRef: ComponentRef<T> = Components.getComponentRef(modelClass);\n\t\t\tif (componentRef.selector === selector) {\n\t\t\t\treturn componentRef;\n\t\t\t}\n\t\t}\n\t}\n\n\tgetComponent<T>(selector: string) {\n\t\t// this.componentSet.\n\t\tfor (const modelClass of this.componentSet) {\n\t\t\tconst componentRef: ComponentRef<T> = Components.getComponentRef(modelClass);\n\t\t\tif (componentRef.selector === selector) {\n\t\t\t\treturn modelClass;\n\t\t\t}\n\t\t}\n\t}\n\n\tgetComponentView(selector: string) {\n\t\treturn this.getComponentRef(selector)?.viewClass;\n\t}\n\n\thasOutput<T>(model: Object, eventName: string): PropertyRef | false {\n\t\tif (Reflect.has(model, 'bootstrap')) {\n\t\t\tconst componentRef: ComponentRef<T> = Reflect.get(model, 'bootstrap');\n\t\t\tif (componentRef.outputs) {\n\t\t\t\tfor (const out of componentRef.outputs) {\n\t\t\t\t\tif (out.viewAttribute === eventName) {\n\t\t\t\t\t\treturn out;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\thasInput<T>(model: Object, eventName: string): PropertyRef | false {\n\t\tif (Reflect.has(model, 'bootstrap')) {\n\t\t\tconst componentRef: ComponentRef<T> = Reflect.get(model, 'bootstrap');\n\t\t\tif (componentRef.inputs) {\n\t\t\t\tfor (const input of componentRef.inputs) {\n\t\t\t\t\tif (input.viewAttribute === eventName) {\n\t\t\t\t\t\treturn input;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\thasDirective<T>(selector: string): boolean {\n\t\tfor (const directiveClass of this.directiveSet) {\n\t\t\tconst directiveRef: DirectiveRef<T> = Components.getBootstrap(directiveClass.prototype);\n\t\t\tif (directiveRef.selector === selector) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tdirectiveHasInput<T>(input: string, directiveType: 'attributes' | 'structural' = 'attributes'): boolean {\n\t\tfor (const directiveClass of this.directiveSet) {\n\t\t\tconst directiveRef: DirectiveRef<T> = Components.getBootstrap(directiveClass.prototype);\n\t\t\tif ((directiveType === 'attributes' && !directiveRef.selector.startsWith('*'))\n\t\t\t\t|| (directiveType === 'structural' && directiveRef.selector.startsWith('*'))) {\n\t\t\t\tif (directiveRef.inputs?.filter(ref => ref.viewAttribute === input).length > 0) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tgetDirectiveRef<T>(selector: string): DirectiveRef<T> | undefined {\n\t\tfor (const directiveClass of this.directiveSet) {\n\t\t\tconst directiveRef: DirectiveRef<T> = Components.getBootstrap(directiveClass.prototype);\n\t\t\tif (directiveRef.selector === selector) {\n\t\t\t\treturn directiveRef;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\n\tgetPipe<T>(pipeName: string): PipeRef<T> | undefined {\n\t\tfor (const pipeClass of this.pipeSet) {\n\t\t\tconst pipeRef: PipeRef<T> = Components.getBootstrap(pipeClass.prototype);\n\t\t\tif (pipeRef.name === pipeName) {\n\t\t\t\treturn pipeRef;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tgetService<T>(serviceName: string): ServiceRef<T> | undefined {\n\t\tfor (const serviceClass of this.serviceSet) {\n\t\t\tconst serviceRef: ServiceRef<T> = Components.getBootstrap(serviceClass.prototype);\n\t\t\tif (serviceRef.name === serviceName) {\n\t\t\t\treturn serviceRef;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n}\n\nexport const ClassRegistryProvider = new ClassRegistry();\n"]}
|
package/utils/elements-util.js
CHANGED
|
@@ -8,7 +8,10 @@ export function hasComponentAttr(element, attr) {
|
|
|
8
8
|
return false;
|
|
9
9
|
}
|
|
10
10
|
export function hasAttrCustomElement(element, attr) {
|
|
11
|
-
if (Reflect.has(element.constructor, '
|
|
11
|
+
if (Reflect.has(element.constructor, 'allAttributes')) {
|
|
12
|
+
return Reflect.get(element.constructor, 'allAttributes').some((prop) => prop === attr);
|
|
13
|
+
}
|
|
14
|
+
else if (Reflect.has(element.constructor, 'observedAttributes')) {
|
|
12
15
|
return Reflect.get(element.constructor, 'observedAttributes').some((prop) => prop === attr);
|
|
13
16
|
}
|
|
14
17
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"elements-util.js","sourceRoot":"","sources":["../../../src/core/utils/elements-util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEjE,MAAM,UAAU,gBAAgB,CAAC,OAAoB,EAAE,IAAY;IAClE,IAAI,eAAe,CAAC,OAAO,CAAC,EAAE;QAC7B,IAAI,YAAY,GAAsB,OAAO,CAAC,eAAe,EAAE,CAAC;QAChE,OAAO,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,aAAa,KAAK,IAAI,CAAC,CAAC;KACvE;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,OAAoB,EAAE,IAAY;IACtE,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,oBAAoB,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"elements-util.js","sourceRoot":"","sources":["../../../src/core/utils/elements-util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEjE,MAAM,UAAU,gBAAgB,CAAC,OAAoB,EAAE,IAAY;IAClE,IAAI,eAAe,CAAC,OAAO,CAAC,EAAE;QAC7B,IAAI,YAAY,GAAsB,OAAO,CAAC,eAAe,EAAE,CAAC;QAChE,OAAO,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,aAAa,KAAK,IAAI,CAAC,CAAC;KACvE;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,OAAoB,EAAE,IAAY;IACtE,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,eAAe,CAAC,EAAE;QACtD,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC,IAAI,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;KAC/F;SACI,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,oBAAoB,CAAC,EAAE;QAChE,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,oBAAoB,CAAC,CAAC,IAAI,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;KACpG;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,OAAoB,EAAE,IAAY;IACzD,OAAO,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,oBAAoB,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAC/G,CAAC","sourcesContent":["import { hasNativeAttr } from '@ibyar/elements';\nimport { ComponentRef } from '../component/component.js';\nimport { isHTMLComponent } from '../component/custom-element.js';\n\nexport function hasComponentAttr(element: HTMLElement, attr: string): boolean {\n\tif (isHTMLComponent(element)) {\n\t\tvar componentRef: ComponentRef<any> = element.getComponentRef();\n\t\treturn componentRef.inputs.some(input => input.viewAttribute === attr);\n\t}\n\treturn false;\n}\n\nexport function hasAttrCustomElement(element: HTMLElement, attr: string): boolean {\n\tif (Reflect.has(element.constructor, 'allAttributes')) {\n\t\treturn Reflect.get(element.constructor, 'allAttributes').some((prop: string) => prop === attr);\n\t}\n\telse if (Reflect.has(element.constructor, 'observedAttributes')) {\n\t\treturn Reflect.get(element.constructor, 'observedAttributes').some((prop: string) => prop === attr);\n\t}\n\treturn false;\n}\n\nexport function hasAttr(element: HTMLElement, attr: string): boolean {\n\treturn hasNativeAttr(element, attr) || hasAttrCustomElement(element, attr) || hasComponentAttr(element, attr);\n}\n"]}
|
package/view/base-view.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { TypeOf } from '../utils/typeof.js';
|
|
2
2
|
import { HTMLComponent } from '../component/custom-element.js';
|
|
3
|
-
export declare function baseFactoryView<T extends
|
|
3
|
+
export declare function baseFactoryView<T extends object>(htmlElementType: TypeOf<HTMLElement>): TypeOf<HTMLComponent<T>>;
|