@ibyar/core 3.1.1 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/annotation/options.d.ts +4 -0
- package/annotation/options.d.ts.map +1 -1
- package/annotation/options.js.map +1 -1
- package/component/custom-element.d.ts +42 -0
- package/component/custom-element.d.ts.map +1 -1
- package/component/custom-element.js.map +1 -1
- package/component/initializer.d.ts +1 -1
- package/component/initializer.d.ts.map +1 -1
- package/component/initializer.js.map +1 -1
- package/component/lifecycle.d.ts +20 -0
- package/component/lifecycle.d.ts.map +1 -1
- package/component/lifecycle.js +6 -0
- package/component/lifecycle.js.map +1 -1
- package/di/inject.js +1 -1
- package/di/inject.js.map +1 -1
- package/linker/view-container-ref.d.ts +64 -32
- package/linker/view-container-ref.d.ts.map +1 -1
- package/linker/view-container-ref.js +39 -27
- package/linker/view-container-ref.js.map +1 -1
- package/linker/view-ref.d.ts +15 -3
- package/linker/view-ref.d.ts.map +1 -1
- package/linker/view-ref.js +17 -0
- package/linker/view-ref.js.map +1 -1
- package/package.json +9 -8
- package/pipe/pipe.d.ts +3 -9
- package/pipe/pipe.d.ts.map +1 -1
- package/pipe/pipe.js +9 -7
- package/pipe/pipe.js.map +1 -1
- package/view/base-view.d.ts.map +1 -1
- package/view/base-view.js +20 -9
- package/view/base-view.js.map +1 -1
- package/view/render.d.ts +0 -1
- package/view/render.d.ts.map +1 -1
- package/view/render.js +16 -30
- package/view/render.js.map +1 -1
- package/view/shadow-root.d.ts +8 -0
- package/view/shadow-root.d.ts.map +1 -0
- package/view/shadow-root.js +15 -0
- package/view/shadow-root.js.map +1 -0
|
@@ -37,18 +37,31 @@ export class ViewContainerRefImpl extends ViewContainerRef {
|
|
|
37
37
|
}
|
|
38
38
|
detach(index) {
|
|
39
39
|
index ??= this._views.length - 1;
|
|
40
|
+
if (index < 0 || index >= this._views.length) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
40
43
|
const viewRef = this._views[index];
|
|
41
44
|
viewRef.detach();
|
|
42
45
|
this._views.splice(index, 1);
|
|
43
46
|
return viewRef;
|
|
44
47
|
}
|
|
48
|
+
adopt(viewRef, newIndex = this._views.length) {
|
|
49
|
+
const lastNode = newIndex == 0 ? this._firstComment : this._views[newIndex - 1].last;
|
|
50
|
+
this._views.splice(newIndex, 0, viewRef);
|
|
51
|
+
viewRef.moveAfter(lastNode);
|
|
52
|
+
}
|
|
53
|
+
forEach(callbackfn) {
|
|
54
|
+
this._views.forEach((view, index) => callbackfn(view, index));
|
|
55
|
+
}
|
|
45
56
|
indexOf(viewRef) {
|
|
46
57
|
return this._views.indexOf(viewRef);
|
|
47
58
|
}
|
|
48
|
-
remove(index) {
|
|
49
|
-
index
|
|
50
|
-
|
|
51
|
-
|
|
59
|
+
remove(index = this._views.length - 1, destroy = true) {
|
|
60
|
+
if (index < 0 || index > this._views.length) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
destroy && this._views[index].destroy();
|
|
64
|
+
return this._views.splice(index, 1)[0];
|
|
52
65
|
}
|
|
53
66
|
insert(viewRef, index) {
|
|
54
67
|
index = ((index ??= this._views.length) > this._views.length) ? this._views.length : index;
|
|
@@ -57,20 +70,27 @@ export class ViewContainerRefImpl extends ViewContainerRef {
|
|
|
57
70
|
viewRef.after(lastNode);
|
|
58
71
|
return viewRef;
|
|
59
72
|
}
|
|
60
|
-
move(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
this.
|
|
73
|
+
move(oldIndex, newIndex) {
|
|
74
|
+
if (oldIndex === newIndex
|
|
75
|
+
|| oldIndex < 0 || oldIndex >= this._views.length
|
|
76
|
+
|| newIndex < 0 || newIndex >= this._views.length) {
|
|
77
|
+
return;
|
|
64
78
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
79
|
+
const view = this._views.at(oldIndex);
|
|
80
|
+
const next = this._views.at(newIndex);
|
|
81
|
+
view.moveBefore(next.first);
|
|
82
|
+
this._views.splice(oldIndex, 1);
|
|
83
|
+
this._views.splice(newIndex, 0, view);
|
|
84
|
+
}
|
|
85
|
+
swap(index1, index2) {
|
|
86
|
+
const min = Math.min(index1, index2);
|
|
87
|
+
const max = Math.max(index1, index2);
|
|
88
|
+
this.move(max, min);
|
|
89
|
+
this.move(min + 1, max);
|
|
70
90
|
}
|
|
71
91
|
createEmbeddedView(templateRef, options) {
|
|
72
92
|
const viewRef = templateRef.createEmbeddedView(options?.context || {}, this._parent);
|
|
73
|
-
|
|
93
|
+
this.insert(viewRef, options?.index);
|
|
74
94
|
return viewRef;
|
|
75
95
|
}
|
|
76
96
|
createComponent(arg0, options) {
|
|
@@ -97,8 +117,8 @@ export class ViewContainerRefImpl extends ViewContainerRef {
|
|
|
97
117
|
}
|
|
98
118
|
const component = new ViewClass();
|
|
99
119
|
const viewRef = new EmbeddedViewRefImpl(component._modelScope, [component]);
|
|
100
|
-
|
|
101
|
-
return component._model;
|
|
120
|
+
this.insert(viewRef, options?.index);
|
|
121
|
+
return { instance: component._model, nativeElement: component, viewRef: viewRef };
|
|
102
122
|
}
|
|
103
123
|
createElement(arg0, options) {
|
|
104
124
|
let element;
|
|
@@ -113,23 +133,15 @@ export class ViewContainerRefImpl extends ViewContainerRef {
|
|
|
113
133
|
}
|
|
114
134
|
const scope = ReactiveControlScope.for(element);
|
|
115
135
|
const viewRef = new EmbeddedViewRefImpl(scope, [element]);
|
|
116
|
-
|
|
117
|
-
return element;
|
|
136
|
+
this.insert(viewRef, options?.index);
|
|
137
|
+
return { nativeElement: element, viewRef: viewRef };
|
|
118
138
|
}
|
|
119
139
|
createTextNode(data, options) {
|
|
120
140
|
const text = document.createTextNode(data);
|
|
121
141
|
const scope = ReactiveControlScope.for(text);
|
|
122
142
|
const viewRef = new EmbeddedViewRefImpl(scope, [text]);
|
|
123
|
-
|
|
143
|
+
this.insert(viewRef, options?.index);
|
|
124
144
|
return text;
|
|
125
145
|
}
|
|
126
|
-
updateViews(views) {
|
|
127
|
-
for (let i = 0; i < views.length; i++) {
|
|
128
|
-
this.move(views[i], i);
|
|
129
|
-
}
|
|
130
|
-
while (this.length > views.length) {
|
|
131
|
-
this.remove();
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
146
|
}
|
|
135
147
|
//# sourceMappingURL=view-container-ref.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view-container-ref.js","sourceRoot":"","sources":["../../../src/core/linker/view-container-ref.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE1D,OAAO,EAAmB,mBAAmB,EAAW,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAe3D,CAAC;AAID,CAAC;AAMF,MAAM,OAAgB,gBAAgB;CA+IrC;AAGD,MAAM,OAAO,oBAAqB,SAAQ,gBAAgB;IAKrC;IAA0B;IAHtC,MAAM,GAA2B,EAAE,CAAC;IAG5C,YAAoB,OAAgB,EAAU,aAAsB;QACnE,KAAK,EAAE,CAAC;QADW,YAAO,GAAP,OAAO,CAAS;QAAU,kBAAa,GAAb,aAAa,CAAS;IAEpE,CAAC;IACD,IAAa,aAAa;QACzB,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IACD,IAAa,MAAM;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC3B,CAAC;IACQ,KAAK;QACb,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gBAC/B,GAAG,CAAC,OAAO,EAAE,CAAC;YACf,CAAC;YACD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACvB,CAAC;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OAAO,EAAE,CAAC,CAAC;QAC5E,CAAC;QACD,MAAM,KAAK,GAAG,oBAAoB,CAAC,GAAG,CAAI,OAAO,CAAC,CAAC;QACnD,MAAM,OAAO,GAAG,IAAI,mBAAmB,CAAI,KAAK,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;QAC7D,CAAC,OAAO,EAAE,MAAM,IAAI,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QACnE,OAAO,OAAO,CAAC;IAChB,CAAC;IACQ,cAAc,CAAC,IAAY,EAAE,OAAsB;QAC3D,MAAM,IAAI,GAAG,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAC3C,MAAM,KAAK,GAAG,oBAAoB,CAAC,GAAG,CAAO,IAAI,CAAC,CAAC;QACnD,MAAM,OAAO,GAAG,IAAI,mBAAmB,CAAO,KAAK,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7D,CAAC,OAAO,EAAE,MAAM,IAAI,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QACnE,OAAO,IAAI,CAAC;IACb,CAAC;IAEQ,WAAW,CAAC,KAAgB;QACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACvC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAyB,EAAE,CAAC,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;YACnC,IAAI,CAAC,MAAM,EAAE,CAAC;QACf,CAAC;IACF,CAAC;CAED","sourcesContent":["import type { MetadataClass } from '@ibyar/decorators';\nimport type { Type } from '../utils/typeof.js';\nimport { ReactiveControlScope } from '@ibyar/expressions';\nimport { TemplateRef } from './template-ref.js';\nimport { EmbeddedViewRef, EmbeddedViewRefImpl, ViewRef } from './view-ref.js';\nimport { getComponentView } from '../view/utils.js';\nimport { HTMLComponent } from '../component/custom-element.js';\nimport { ReflectComponents } from '../component/reflect.js';\n\ninterface IndexOptions {\n\t/**\n\t * the index to insert the \n\t */\n\tindex?: number;\n\t/**\n\t * the default value is true\n\t */\n\tinsert?: boolean\n}\n\nexport interface ViewContainerOptions<C> extends IndexOptions {\n\tcontext?: C;\n};\n\nexport interface ViewContainerComponentOptions extends IndexOptions {\n\tselector?: string;\n};\n\nexport interface HTMLElementOptions extends ElementCreationOptions, IndexOptions {\n\n}\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 {}>(templateRef: TemplateRef, options?: ViewContainerOptions<C>): EmbeddedViewRef<C>;\n\n\t/**\n\t * create component by tag name `selector`.\n\t * @param selector the tag name for the aurora custom-element\n\t * @param options \n\t */\n\tabstract createComponent<C extends {}>(selector: string, options?: IndexOptions): C;\n\n\t/**\n\t * create component by the aurora custom-element `View` Class\n\t * @param viewClass the generated aurora view class\n\t * @param options \n\t */\n\tabstract createComponent<C extends {}>(viewClass: Type<HTMLComponent<C>>, options?: IndexOptions): C;\n\n\t/**\n\t * Instantiates a single component and inserts its host view into this container.\n\t *\n\t * @param componentType Component Type to use.\n\t * @param options An object that contains extra parameters:\n\t * * index: the index at which to insert the new component's host view into this container.\n\t * If not specified, appends the new view as the last entry.\n\t * * 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\t *\n\t * @returns The new `HTMLComponent` which contains the component instance and the host view.\n\t */\n\tabstract createComponent<C extends {}>(componentType: Type<C>, options?: ViewContainerComponentOptions): C;\n\n\t/**\n\t * create an HTMLElement by tag name `selector`.\n\t * @param selector the tag name for the aurora custom-element\n\t * @param options \n\t */\n\tabstract createElement<K extends keyof HTMLElementTagNameMap>(selector: K, options?: HTMLElementOptions): HTMLElementTagNameMap[K];\n\tabstract createElement<K extends keyof HTMLElementDeprecatedTagNameMap>(selector: K, options?: HTMLElementOptions): HTMLElementDeprecatedTagNameMap[K];\n\n\t/**\n\t * create HTMLElement by View Class reference\n\t * @param viewClass the generated aurora view class\n\t * @param options \n\t */\n\tabstract createElement<C extends HTMLElement>(htmlElementClass: Type<C>, options?: HTMLElementOptions): C;\n\n\t/**\n\t * create a text node and insert to the view\n\t * @param data \n\t * @param options \n\t */\n\tabstract createTextNode(data: string, options?: IndexOptions): Text;\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\t/**\n\t * set the current views from this\n\t * @param views the new `ViewRef` list \n\t */\n\tabstract updateViews(views: ViewRef[]): void;\n}\n\n\nexport class ViewContainerRefImpl extends ViewContainerRef {\n\n\tprivate _views: EmbeddedViewRef<any>[] = [];\n\n\tconstructor(parent: Element, firstComment: Comment);\n\tconstructor(private _parent: Element, private _firstComment: Comment) {\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 {}>(templateRef: TemplateRef, options?: ViewContainerOptions<C>): EmbeddedViewRef<C> {\n\t\tconst viewRef = templateRef.createEmbeddedView<C>(options?.context || <C>{}, this._parent);\n\t\t(options?.insert != false) && this.insert(viewRef, options?.index);\n\t\treturn viewRef;\n\t}\n\toverride createComponent<C extends {}>(selector: string, options?: IndexOptions): C;\n\toverride createComponent<C extends {}>(viewClass: MetadataClass<HTMLComponent<C>>, options?: IndexOptions): C;\n\toverride createComponent<C extends {}>(componentType: MetadataClass<C>, options?: ViewContainerComponentOptions): C;\n\toverride createComponent<C extends {}>(arg0: string | MetadataClass<C> | Type<HTMLComponent<C>>, options?: ViewContainerComponentOptions): C {\n\t\tlet ViewClass: Type<HTMLComponent<C>>;\n\t\tif (typeof arg0 === 'string') {\n\t\t\tViewClass = customElements.get(arg0) as Type<HTMLComponent<C>>;\n\t\t} else if (typeof arg0 === 'function') {\n\t\t\tif (Reflect.has(arg0, 'observedAttributes')) {\n\t\t\t\tViewClass = arg0 as Type<HTMLComponent<C>>;\n\t\t\t} else {\n\t\t\t\tconst componentType = arg0 as MetadataClass<C>;\n\t\t\t\tconst defaultTagName = ReflectComponents.getMetaDate(componentType)?.selector;\n\t\t\t\tconst view = getComponentView(componentType, options?.selector ?? defaultTagName);\n\t\t\t\tif (!view) {\n\t\t\t\t\tthrow new Error(`Can't find View component for class ${componentType.name}`);\n\t\t\t\t}\n\t\t\t\tViewClass = view;\n\t\t\t}\n\t\t} else {\n\t\t\tthrow new Error(`Can't find View component for args, ${arg0}, ${options}`);\n\t\t}\n\t\tconst component = new ViewClass();\n\t\tconst viewRef = new EmbeddedViewRefImpl<C>(component._modelScope, [component]);\n\t\t(options?.insert != false) && this.insert(viewRef, options?.index);\n\t\treturn component._model;\n\t}\n\n\toverride createElement<K extends keyof HTMLElementTagNameMap>(selector: K, options?: HTMLElementOptions): HTMLElementTagNameMap[K];\n\toverride createElement<K extends keyof HTMLElementDeprecatedTagNameMap>(selector: K, options?: HTMLElementOptions): HTMLElementDeprecatedTagNameMap[K];\n\toverride createElement<C extends HTMLElement>(arg0: string | Type<C>, options?: HTMLElementOptions): C {\n\t\tlet element: C;\n\t\tif (typeof arg0 === 'string') {\n\t\t\telement = document.createElement(arg0, { is: options?.is }) as C;\n\t\t} else if (typeof arg0 === 'function') {\n\t\t\telement = new arg0();\n\t\t} else {\n\t\t\tthrow new Error(`Can't find View component for args, ${arg0}, ${options}`);\n\t\t}\n\t\tconst scope = ReactiveControlScope.for<C>(element);\n\t\tconst viewRef = new EmbeddedViewRefImpl<C>(scope, [element]);\n\t\t(options?.insert != false) && this.insert(viewRef, options?.index);\n\t\treturn element;\n\t}\n\toverride createTextNode(data: string, options?: IndexOptions): Text {\n\t\tconst text = document.createTextNode(data);\n\t\tconst scope = ReactiveControlScope.for<Text>(text);\n\t\tconst viewRef = new EmbeddedViewRefImpl<Text>(scope, [text]);\n\t\t(options?.insert != false) && this.insert(viewRef, options?.index);\n\t\treturn text;\n\t}\n\n\toverride updateViews(views: ViewRef[]): void {\n\t\tfor (let i = 0; i < views.length; i++) {\n\t\t\tthis.move(views[i] as EmbeddedViewRef<any>, i);\n\t\t}\n\t\twhile (this.length > views.length) {\n\t\t\tthis.remove();\n\t\t}\n\t}\n\n}\n"]}
|
|
1
|
+
{"version":3,"file":"view-container-ref.js","sourceRoot":"","sources":["../../../src/core/linker/view-container-ref.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE1D,OAAO,EAAmB,mBAAmB,EAAW,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAW3D,CAAC;AAID,CAAC;AAiBF,MAAM,OAAgB,gBAAgB;CA6KrC;AAGD,MAAM,OAAO,oBAAqB,SAAQ,gBAAgB;IAKrC;IAA0B;IAHtC,MAAM,GAA2B,EAAE,CAAC;IAG5C,YAAoB,OAAgB,EAAU,aAAsB;QACnE,KAAK,EAAE,CAAC;QADW,YAAO,GAAP,OAAO,CAAS;QAAU,kBAAa,GAAb,aAAa,CAAS;IAEpE,CAAC;IACD,IAAa,aAAa;QACzB,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IACD,IAAa,MAAM;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC3B,CAAC;IACQ,KAAK;QACb,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gBAC/B,GAAG,CAAC,OAAO,EAAE,CAAC;YACf,CAAC;YACD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACvB,CAAC;IACF,CAAC;IACQ,GAAG,CAAI,KAAa;QAC5B,IAAI,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACjC,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,OAAO,I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KAAK,CAAC,uCAAuC,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;QAC5E,CAAC;QACD,MAAM,KAAK,GAAG,oBAAoB,CAAC,GAAG,CAAI,OAAO,CAAC,CAAC;QACnD,MAAM,OAAO,GAAG,IAAI,mBAAmB,CAAI,KAAK,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;QAC7D,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QACrC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;IACrD,CAAC;IACQ,cAAc,CAAC,IAAY,EAAE,OAAsB;QAC3D,MAAM,IAAI,GAAG,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAC3C,MAAM,KAAK,GAAG,oBAAoB,CAAC,GAAG,CAAO,IAAI,CAAC,CAAC;QACnD,MAAM,OAAO,GAAG,IAAI,mBAAmB,CAAO,KAAK,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7D,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QACrC,OAAO,IAAI,CAAC;IACb,CAAC;CAED","sourcesContent":["import type { MetadataClass } from '@ibyar/decorators';\nimport type { Type } from '../utils/typeof.js';\nimport { ReactiveControlScope } from '@ibyar/expressions';\nimport { TemplateRef } from './template-ref.js';\nimport { EmbeddedViewRef, EmbeddedViewRefImpl, ViewRef } from './view-ref.js';\nimport { getComponentView } from '../view/utils.js';\nimport { HTMLComponent } from '../component/custom-element.js';\nimport { ReflectComponents } from '../component/reflect.js';\n\ninterface IndexOptions {\n\t/**\n\t * the index to insert the \n\t */\n\tindex?: number;\n}\n\nexport interface ViewContainerOptions<C> extends IndexOptions {\n\tcontext?: C;\n};\n\nexport interface ViewContainerComponentOptions extends IndexOptions {\n\tselector?: string;\n};\n\nexport interface HTMLElementOptions extends ElementCreationOptions, IndexOptions {\n\n}\n\nexport type ElementRef<T> = {\n\tnativeElement: T;\n\tviewRef: EmbeddedViewRef<T>;\n};\n\nexport type ComponentViewRef<T> = {\n\tinstance: T;\n\tnativeElement: HTMLComponent<T>;\n\tviewRef: EmbeddedViewRef<T>;\n};\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<T>(index: number): EmbeddedViewRef<T> | undefined;\n\n\t/**\n\t * Performs the specified action for each element in an array.\n\t */\n\tabstract forEach<T>(callbackfn: (value: EmbeddedViewRef<T>, index: number) => void): void;\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 {}>(templateRef: TemplateRef, options?: ViewContainerOptions<C>): EmbeddedViewRef<C>;\n\n\t/**\n\t * create component by tag name `selector`.\n\t * @param selector the tag name for the aurora custom-element\n\t * @param options \n\t */\n\tabstract createComponent<C extends {}>(selector: string, options?: IndexOptions): ComponentViewRef<C>;\n\n\t/**\n\t * create component by the aurora custom-element `View` Class\n\t * @param viewClass the generated aurora view class\n\t * @param options \n\t */\n\tabstract createComponent<C extends {}>(viewClass: Type<HTMLComponent<C>>, options?: IndexOptions): ComponentViewRef<C>;\n\n\t/**\n\t * Instantiates a single component and inserts its host view into this container.\n\t *\n\t * @param componentType Component Type to use.\n\t * @param options An object that contains extra parameters:\n\t * * index: the index at which to insert the new component's host view into this container.\n\t * If not specified, appends the new view as the last entry.\n\t * * 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\t *\n\t * @returns The new `HTMLComponent` which contains the component instance and the host view.\n\t */\n\tabstract createComponent<C extends {}>(componentType: Type<C>, options?: ViewContainerComponentOptions): ComponentViewRef<C>;\n\n\t/**\n\t * create an HTMLElement by tag name `selector`.\n\t * @param selector the tag name for the aurora custom-element\n\t * @param options \n\t */\n\tabstract createElement<K extends keyof HTMLElementTagNameMap>(selector: K, options?: HTMLElementOptions): ElementRef<HTMLElementTagNameMap[K]>;\n\n\t/**\n\t * create an HTMLElement by tag name `selector`.\n\t * @param selector the tag name for the aurora custom-element\n\t * @param options \n\t */\n\tabstract createElement<K extends keyof HTMLElementDeprecatedTagNameMap>(selector: K, options?: HTMLElementOptions): ElementRef<HTMLElementDeprecatedTagNameMap[K]>;\n\n\t/**\n\t * create HTMLElement by View Class reference\n\t * @param viewClass the generated aurora view class\n\t * @param options \n\t */\n\tabstract createElement<C extends HTMLElement>(htmlElementClass: Type<C>, options?: HTMLElementOptions): ElementRef<C>;\n\n\t/**\n\t * create a text node and insert to the view\n\t * @param data \n\t * @param options \n\t */\n\tabstract createTextNode(data: string, options?: IndexOptions): Text;\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 * move a view to a new location from another container\n\t * @param viewRef the view that needed to be inserted in this container.\n\t * @param newIndex new index in this container, or append\n\t */\n\tabstract adopt<T>(viewRef: EmbeddedViewRef<T>, newIndex?: number): void;\n\n\t/**\n\t * Moves a view to a new location in this container.\n\t * @param oldIndex The 0-based index of the old location.\n\t * @param newIndex The 0-based index of the new location.\n\t */\n\tabstract move(oldIndex: number, newIndex: number): void;\n\n\t/**\n\t * swap 2 view position\n\t * @param oldIndex \n\t * @param newIndex \n\t */\n\tabstract swap(index1: number, index2: number): void;\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<T>(index?: number): EmbeddedViewRef<T> | undefined;\n\n\t/**\n\t * remove a view attached to this container with out destroying it.\n\t * the view will be still attached to the DOM.\n\t * useful in case of moving the view/component to anther container without realizing it again.\n\t * returns the view.\n\t * @param index \n\t * @param destroy \n\t * @returns the view in the index\n\t */\n\tabstract remove<T>(index: number, destroy: false): EmbeddedViewRef<T> | undefined;\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<T>(index?: number): EmbeddedViewRef<T> | undefined;\n\n}\n\n\nexport class ViewContainerRefImpl extends ViewContainerRef {\n\n\tprivate _views: EmbeddedViewRef<any>[] = [];\n\n\tconstructor(parent: Element, firstComment: Comment);\n\tconstructor(private _parent: Element, private _firstComment: Comment) {\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<T>(index: number): EmbeddedViewRef<T> | 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<T>(index?: number): EmbeddedViewRef<T> | undefined {\n\t\tindex ??= this._views.length - 1;\n\t\tif (index < 0 || index >= this._views.length) {\n\t\t\treturn;\n\t\t}\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 adopt<T>(viewRef: EmbeddedViewRef<T>, newIndex = this._views.length): void {\n\t\tconst lastNode = newIndex == 0 ? this._firstComment : this._views[newIndex - 1].last;\n\t\tthis._views.splice(newIndex, 0, viewRef);\n\t\tviewRef.moveAfter(lastNode);\n\t}\n\toverride forEach<T>(callbackfn: (value: EmbeddedViewRef<T>, index: number) => void): void {\n\t\tthis._views.forEach((view, index) => callbackfn(view, index));\n\t}\n\toverride indexOf<T>(viewRef: EmbeddedViewRef<T>): number {\n\t\treturn this._views.indexOf(viewRef);\n\t}\n\toverride remove<T>(index = this._views.length - 1, destroy = true): EmbeddedViewRef<T> | undefined {\n\t\tif (index < 0 || index > this._views.length) {\n\t\t\treturn;\n\t\t}\n\t\tdestroy && this._views[index].destroy();\n\t\treturn this._views.splice(index, 1)[0];\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(oldIndex: number, newIndex: number): void {\n\t\tif (oldIndex === newIndex\n\t\t\t|| oldIndex < 0 || oldIndex >= this._views.length\n\t\t\t|| newIndex < 0 || newIndex >= this._views.length) {\n\t\t\treturn;\n\t\t}\n\t\tconst view = this._views.at(oldIndex)!;\n\t\tconst next = this._views.at(newIndex)!;\n\t\tview.moveBefore(next.first);\n\t\tthis._views.splice(oldIndex, 1);\n\t\tthis._views.splice(newIndex, 0, view);\n\t}\n\tswap(index1: number, index2: number): void {\n\t\tconst min = Math.min(index1, index2);\n\t\tconst max = Math.max(index1, index2);\n\t\tthis.move(max, min);\n\t\tthis.move(min + 1, max);\n\t}\n\toverride createEmbeddedView<C extends {}>(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 {}>(selector: string, options?: IndexOptions): ComponentViewRef<C>;\n\toverride createComponent<C extends {}>(viewClass: MetadataClass<HTMLComponent<C>>, options?: IndexOptions): ComponentViewRef<C>;\n\toverride createComponent<C extends {}>(componentType: MetadataClass<C>, options?: ViewContainerComponentOptions): ComponentViewRef<C>;\n\toverride createComponent<C extends {}>(arg0: string | MetadataClass<C> | Type<HTMLComponent<C>>, options?: ViewContainerComponentOptions): ComponentViewRef<C> {\n\t\tlet ViewClass: Type<HTMLComponent<C>>;\n\t\tif (typeof arg0 === 'string') {\n\t\t\tViewClass = customElements.get(arg0) as Type<HTMLComponent<C>>;\n\t\t} else if (typeof arg0 === 'function') {\n\t\t\tif (Reflect.has(arg0, 'observedAttributes')) {\n\t\t\t\tViewClass = arg0 as Type<HTMLComponent<C>>;\n\t\t\t} else {\n\t\t\t\tconst componentType = arg0 as MetadataClass<C>;\n\t\t\t\tconst defaultTagName = ReflectComponents.getMetaDate(componentType)?.selector;\n\t\t\t\tconst view = getComponentView(componentType, options?.selector ?? defaultTagName);\n\t\t\t\tif (!view) {\n\t\t\t\t\tthrow new Error(`Can't find View component for class ${componentType.name}`);\n\t\t\t\t}\n\t\t\t\tViewClass = view;\n\t\t\t}\n\t\t} else {\n\t\t\tthrow new Error(`Can't find View component for args, ${arg0}, ${options}`);\n\t\t}\n\t\tconst component = new ViewClass();\n\t\tconst viewRef = new EmbeddedViewRefImpl<C>(component._modelScope, [component]);\n\t\tthis.insert(viewRef, options?.index);\n\t\treturn { instance: component._model, nativeElement: component, viewRef: viewRef };\n\t}\n\n\toverride createElement<K extends keyof HTMLElementTagNameMap>(selector: K, options?: HTMLElementOptions): ElementRef<HTMLElementTagNameMap[K]>;\n\toverride createElement<K extends keyof HTMLElementDeprecatedTagNameMap>(selector: K, options?: HTMLElementOptions): ElementRef<HTMLElementDeprecatedTagNameMap[K]>;\n\toverride createElement<C extends HTMLElement>(arg0: string | Type<C>, options?: HTMLElementOptions): ElementRef<C> {\n\t\tlet element: C;\n\t\tif (typeof arg0 === 'string') {\n\t\t\telement = document.createElement(arg0, { is: options?.is }) as C;\n\t\t} else if (typeof arg0 === 'function') {\n\t\t\telement = new arg0();\n\t\t} else {\n\t\t\tthrow new Error(`Can't find View component for args, ${arg0}, ${options}`);\n\t\t}\n\t\tconst scope = ReactiveControlScope.for<C>(element);\n\t\tconst viewRef = new EmbeddedViewRefImpl<C>(scope, [element]);\n\t\tthis.insert(viewRef, options?.index);\n\t\treturn { nativeElement: element, viewRef: viewRef };\n\t}\n\toverride createTextNode(data: string, options?: IndexOptions): Text {\n\t\tconst text = document.createTextNode(data);\n\t\tconst scope = ReactiveControlScope.for<Text>(text);\n\t\tconst viewRef = new EmbeddedViewRefImpl<Text>(scope, [text]);\n\t\tthis.insert(viewRef, options?.index);\n\t\treturn text;\n\t}\n\n}\n"]}
|
package/linker/view-ref.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare abstract class ViewRef extends ChangeDetectorRef {
|
|
|
20
20
|
unsubscribe(): void;
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
export declare abstract class EmbeddedViewRef<C
|
|
23
|
+
export declare abstract class EmbeddedViewRef<C> extends ViewRef {
|
|
24
24
|
/**
|
|
25
25
|
* The context for this view, inherited from the anchor element.
|
|
26
26
|
*/
|
|
@@ -47,6 +47,16 @@ export declare abstract class EmbeddedViewRef<C extends object> extends ViewRef
|
|
|
47
47
|
* @param node
|
|
48
48
|
*/
|
|
49
49
|
abstract before(node: ChildNode): void;
|
|
50
|
+
/**
|
|
51
|
+
* move/resort/reorder after node
|
|
52
|
+
* @param node
|
|
53
|
+
*/
|
|
54
|
+
abstract moveAfter(node: ChildNode): void;
|
|
55
|
+
/**
|
|
56
|
+
* move/resort/reorder before node
|
|
57
|
+
* @param node
|
|
58
|
+
*/
|
|
59
|
+
abstract moveBefore(node: ChildNode): void;
|
|
50
60
|
/**
|
|
51
61
|
* remove the root nodes from the view, but keep reference to them.
|
|
52
62
|
*
|
|
@@ -55,13 +65,13 @@ export declare abstract class EmbeddedViewRef<C extends object> extends ViewRef
|
|
|
55
65
|
*/
|
|
56
66
|
abstract detach(): void;
|
|
57
67
|
}
|
|
58
|
-
export declare class EmbeddedViewRefImpl<C
|
|
68
|
+
export declare class EmbeddedViewRefImpl<C> extends EmbeddedViewRef<C> {
|
|
59
69
|
private _scope;
|
|
60
70
|
private _rootNodes;
|
|
61
71
|
private _subscriptions?;
|
|
62
72
|
private _destroyed;
|
|
63
73
|
private _onDestroySubscribes;
|
|
64
|
-
constructor(_scope: ReactiveControlScope<C>, _rootNodes: Node[], _subscriptions?: ScopeSubscription<Context>[] | undefined);
|
|
74
|
+
constructor(_scope: ReactiveControlScope<C & Context>, _rootNodes: Node[], _subscriptions?: ScopeSubscription<Context>[] | undefined);
|
|
65
75
|
get context(): C;
|
|
66
76
|
get rootNodes(): Node[];
|
|
67
77
|
get first(): Element;
|
|
@@ -71,6 +81,8 @@ export declare class EmbeddedViewRefImpl<C extends object> extends EmbeddedViewR
|
|
|
71
81
|
private getAsANode;
|
|
72
82
|
after(node: ChildNode): void;
|
|
73
83
|
before(node: ChildNode): void;
|
|
84
|
+
moveAfter(node: ChildNode): void;
|
|
85
|
+
moveBefore(node: ChildNode): void;
|
|
74
86
|
detach(): void;
|
|
75
87
|
reattach(): void;
|
|
76
88
|
markForCheck(): void;
|
package/linker/view-ref.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view-ref.d.ts","sourceRoot":"","sources":["../../../src/core/linker/view-ref.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACtF,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,8BAAsB,OAAQ,SAAQ,iBAAiB;IACtD;;OAEG;IACH,QAAQ,CAAC,OAAO,IAAI,IAAI;IAExB;;;OAGG;IACH,QAAQ,KAAK,SAAS,IAAI,OAAO,CAAC;IAElC;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG;QAAE,WAAW,IAAI,IAAI,CAAA;KAAE;CAC/D;AAGD,8BAAsB,eAAe,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"view-ref.d.ts","sourceRoot":"","sources":["../../../src/core/linker/view-ref.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACtF,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,8BAAsB,OAAQ,SAAQ,iBAAiB;IACtD;;OAEG;IACH,QAAQ,CAAC,OAAO,IAAI,IAAI;IAExB;;;OAGG;IACH,QAAQ,KAAK,SAAS,IAAI,OAAO,CAAC;IAElC;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG;QAAE,WAAW,IAAI,IAAI,CAAA;KAAE;CAC/D;AAGD,8BAAsB,eAAe,CAAC,CAAC,CAAE,SAAQ,OAAO;IACvD;;OAEG;IACH,QAAQ,KAAK,OAAO,IAAI,CAAC,CAAC;IAE1B;;O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SAAS,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI;IAOhC,UAAU,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI;IAQjC,MAAM,IAAI,IAAI;IAMd,QAAQ,IAAI,IAAI;IAGhB,YAAY,IAAI,IAAI;IAGpB,aAAa,IAAI,IAAI;IAGrB,cAAc,IAAI,IAAI;IAGtB,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG;QAAE,WAAW,IAAI,IAAI,CAAC;KAAE;CAYzD"}
|
package/linker/view-ref.js
CHANGED
|
@@ -62,6 +62,23 @@ export class EmbeddedViewRefImpl extends EmbeddedViewRef {
|
|
|
62
62
|
before(node) {
|
|
63
63
|
node.before(this.getAsANode());
|
|
64
64
|
}
|
|
65
|
+
moveAfter(node) {
|
|
66
|
+
if (node.nextSibling) {
|
|
67
|
+
this.moveBefore(node.nextSibling);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
this.after(node);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
moveBefore(node) {
|
|
74
|
+
const parent = node.parentNode;
|
|
75
|
+
if (parent?.moveBefore && node) {
|
|
76
|
+
parent.moveBefore(this.getAsANode(), node);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
this.before(node);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
65
82
|
detach() {
|
|
66
83
|
for (const node of this._rootNodes) {
|
|
67
84
|
node.remove();
|
package/linker/view-ref.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view-ref.js","sourceRoot":"","sources":["../../../src/core/linker/view-ref.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,MAAM,OAAgB,OAAQ,SAAQ,iBAAiB;CAmBtD;AAGD,MAAM,OAAgB,
|
|
1
|
+
{"version":3,"file":"view-ref.js","sourceRoot":"","sources":["../../../src/core/linker/view-ref.ts"],"names":[],"mappings":"AACA,OA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I,CAAC,UAAU,EAAE,EAAE,IAAI,CAAC,CAAC;QAC5C,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC;IACF,CAAC;IACD,MAAM;QACL,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAC1B,IAAK,CAAC,MAAM,EAAE,CAAC;QAC1B,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IACtB,CAAC;IACD,QAAQ;QACP,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;IAC3B,CAAC;IACD,YAAY;QACX,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;IAC3B,CAAC;IACD,aAAa;QACZ,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;IAC7B,CAAC;IACD,cAAc;QACb,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;IAC9B,CAAC;IACD,SAAS,CAAC,QAAoB;QAC7B,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACzC,OAAO;YACN,WAAW,EAAE,GAAG,EAAE;gBACjB,MAAM,KAAK,GAAG,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;gBAC1D,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;oBAChB,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;gBAC5C,CAAC;YACF,CAAC;SACD,CAAC;IACH,CAAC;CAED","sourcesContent":["import { ReactiveControlScope, Context, ScopeSubscription } from '@ibyar/expressions';\nimport { ChangeDetectorRef } from './change-detector-ref.js';\n\nexport abstract class ViewRef extends ChangeDetectorRef {\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 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 * move/resort/reorder after node\n\t * @param node \n\t */\n\tabstract moveAfter(node: ChildNode): void;\n\n\t/**\n\t * move/resort/reorder before node\n\t * @param node \n\t */\n\tabstract moveBefore(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 EmbeddedViewRef<C> {\n\n\tprivate _destroyed: boolean = false;\n\tprivate _onDestroySubscribes: (() => void)[] = [];\n\n\tconstructor(\n\t\tprivate _scope: ReactiveControlScope<C & Context>,\n\t\tprivate _rootNodes: Node[],\n\t\tprivate _subscriptions?: ScopeSubscription<Context>[]) {\n\t\tsuper();\n\t}\n\n\tget context(): C {\n\t\treturn this._scope.getContext();\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\tmoveAfter(node: ChildNode): void {\n\t\tif (node.nextSibling) {\n\t\t\tthis.moveBefore(node.nextSibling);\n\t\t} else {\n\t\t\tthis.after(node);\n\t\t}\n\t}\n\tmoveBefore(node: ChildNode): void {\n\t\tconst parent = node.parentNode as (ParentNode & { moveBefore?: (node: Node, child: ChildNode) => void }) | null;\n\t\tif (parent?.moveBefore && node) {\n\t\t\tparent.moveBefore(this.getAsANode(), node);\n\t\t} else {\n\t\t\tthis.before(node);\n\t\t}\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\tthis._scope.detach();\n\t}\n\treattach(): void {\n\t\tthis._scope.emitChanges();\n\t}\n\tmarkForCheck(): void {\n\t\tthis._scope.emitChanges();\n\t}\n\tdetectChanges(): void {\n\t\tthis._scope.detectChanges();\n\t}\n\tcheckNoChanges(): void {\n\t\tthis._scope.checkNoChanges();\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": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Ibyar core, 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",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"contributors": [
|
|
17
17
|
{
|
|
18
18
|
"name": "Muhammad Salem",
|
|
19
|
-
"email": "salem.ebo@gmail.com"
|
|
19
|
+
"email": "salem.ebo@gmail.com",
|
|
20
|
+
"url": "https://github.com/muhammad-salem"
|
|
20
21
|
}
|
|
21
22
|
],
|
|
22
23
|
"main": "./index.js",
|
|
@@ -35,16 +36,16 @@
|
|
|
35
36
|
"access": "public"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
38
|
-
"@ibyar/decorators": "^
|
|
39
|
-
"@ibyar/elements": "^
|
|
40
|
-
"@ibyar/expressions": "^
|
|
39
|
+
"@ibyar/decorators": "^4.0.0",
|
|
40
|
+
"@ibyar/elements": "^4.0.0",
|
|
41
|
+
"@ibyar/expressions": "^4.0.0",
|
|
41
42
|
"tslib": "^2.8.1"
|
|
42
43
|
},
|
|
43
44
|
"peerDependencies": {
|
|
44
|
-
"zone.js": "~0.15.
|
|
45
|
+
"zone.js": "~0.15.1"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
|
-
"typescript": "^5.
|
|
48
|
+
"typescript": "^5.8.3"
|
|
48
49
|
},
|
|
49
50
|
"scripts": {
|
|
50
51
|
"build": "tsc --build --verbose",
|
|
@@ -78,5 +79,5 @@
|
|
|
78
79
|
"typescript",
|
|
79
80
|
"front-end"
|
|
80
81
|
],
|
|
81
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "6671356b7c827061a32d138db5cad660ad0053c5"
|
|
82
83
|
}
|
package/pipe/pipe.d.ts
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
import { ReactiveControlScope, ReadOnlyScope, ScopeSubscription } from '@ibyar/expressions';
|
|
2
2
|
import { OnDestroy } from '../component/lifecycle.js';
|
|
3
|
-
import { ChangeDetectorRef } from '../linker/change-detector-ref.js';
|
|
4
3
|
import { Type } from '../utils/typeof.js';
|
|
5
4
|
/**
|
|
6
5
|
* Pipes are used as singleton
|
|
7
6
|
* it will be created if it needed, had no life cycle
|
|
8
|
-
*
|
|
9
|
-
* * no dependency injection applied on filters for now,
|
|
10
|
-
* TODO: add support of dependency injection
|
|
11
7
|
*/
|
|
12
8
|
export interface PipeTransform<T, U> {
|
|
13
9
|
transform(value: T, ...args: any[]): U;
|
|
14
10
|
}
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
abstract transform(value: T, ...args: any[]): U;
|
|
19
|
-
abstract onDestroy(): void;
|
|
11
|
+
export interface AsyncPipeTransform<T, U> extends PipeTransform<T, U>, OnDestroy {
|
|
12
|
+
transform(value: T, ...args: any[]): U;
|
|
13
|
+
onDestroy(): void;
|
|
20
14
|
}
|
|
21
15
|
export declare function isPipeTransform<T extends any, U extends any>(pipe: any): pipe is PipeTransform<T, U>;
|
|
22
16
|
export declare class PipeProvider extends ReadOnlyScope<{
|
package/pipe/pipe.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipe.d.ts","sourceRoot":"","sources":["../../../src/core/pip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AAED,qBAAa,iBAAkB,SAAQ,aAAa,CAAC,MAAM,CAAC;;IAI3D,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAI9B,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,GAAG,SAAS;IAOrE,QAAQ,IAAI,IAAI,CAAC,iBAAiB,CAAC;CAGnC;AAED,qBAAa,cAAc,CAAC,CAAC,SAAS;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;CAAE,CAAE,SAAQ,oBAAoB,CAAC,CAAC,CAAC;IACrH,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;KAAE,KAAK,cAAc,CAAC,CAAC,CAAC;IAGjG,OAAO,CAAC,OAAO,CAAmC;;IAIzC,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,OAAO;IAgBjG,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,GAAG,GAAG;IAG9B,WAAW,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,YAAY,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAK9E,QAAQ,IAAI,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;CAGnC"}
|
package/pipe/pipe.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { ReactiveControlScope, ReadOnlyScope } from '@ibyar/expressions';
|
|
2
|
-
import { createChangeDetectorRef } from '../linker/change-detector-ref.js';
|
|
2
|
+
import { ChangeDetectorRef, createChangeDetectorRef } from '../linker/change-detector-ref.js';
|
|
3
3
|
import { classRegistryProvider } from '../providers/provider.js';
|
|
4
|
-
|
|
5
|
-
changeDetectorRef;
|
|
6
|
-
constructor(changeDetectorRef) {
|
|
7
|
-
this.changeDetectorRef = changeDetectorRef;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
4
|
+
import { addProvider, forkProvider, removeProvider } from '../di/inject.js';
|
|
10
5
|
export function isPipeTransform(pipe) {
|
|
11
6
|
return Reflect.has(Object.getPrototypeOf(pipe), 'transform');
|
|
12
7
|
}
|
|
@@ -28,7 +23,10 @@ export class PipeProvider extends ReadOnlyScope {
|
|
|
28
23
|
}
|
|
29
24
|
const pipeRef = classRegistryProvider.getPipe(pipeName);
|
|
30
25
|
if (pipeRef !== undefined && !pipeRef.asynchronous) {
|
|
26
|
+
const provider = forkProvider();
|
|
27
|
+
addProvider(provider);
|
|
31
28
|
const pipe = new pipeRef.modelClass();
|
|
29
|
+
removeProvider(provider);
|
|
32
30
|
transformFunc = (value, ...args) => pipe.transform(value, ...args);
|
|
33
31
|
this._ctx[pipeRef.name] = transformFunc;
|
|
34
32
|
return transformFunc;
|
|
@@ -68,7 +66,11 @@ export class AsyncPipeScope extends ReactiveControlScope {
|
|
|
68
66
|
}
|
|
69
67
|
set(propertyKey, pipeClass, receiver) {
|
|
70
68
|
const detector = createChangeDetectorRef(this, propertyKey);
|
|
69
|
+
const provider = forkProvider();
|
|
70
|
+
provider.setType(ChangeDetectorRef, detector);
|
|
71
|
+
addProvider(provider);
|
|
71
72
|
const pipe = new pipeClass(detector);
|
|
73
|
+
removeProvider(provider);
|
|
72
74
|
const result = super.set(propertyKey, pipe, receiver);
|
|
73
75
|
if (result) {
|
|
74
76
|
this.wrapper[propertyKey] = (value, ...args) => {
|
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,oBAAoB,EAAE,aAAa,EAAqB,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,SAA6C,EAAE,QAAc;QAC/F,MAAM,QAAQ,GAAG,uBAAuB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QAC5D,MAAM,QAAQ,GAAG,YAAY,EAAE,CAAC;QAChC,QAAQ,CAAC,OAAO,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;QAC9C,WAAW,CAAC,QAAQ,CAAC,CAAC;QACtB,MAAM,IAAI,GAAG,IAAI,SAAS,CAAC,QAAQ,CAAC,CAAC;QACrC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAEzB,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QACtD,IAAI,MAAM,EAAE,CAAC;YACZ,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;QACH,CAAC;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,KAAK,CAAC,WAAW,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;QAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACpC,IAAI,CAAC,SAAS,EAAE,CAAC;IAClB,CAAC;IACD,QAAQ;QACP,OAAO,cAAc,CAAC;IACvB,CAAC;CACD","sourcesContent":["import { ReactiveControlScope, 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 { Type } from '../utils/typeof.js';\nimport { addProvider, forkProvider, inject, removeProvider } from '../di/inject.js';\n\n/**\n * Pipes are used as singleton\n * it will be created if it needed, had no life cycle\n */\nexport interface PipeTransform<T, U> {\n\ttransform(value: T, ...args: any[]): U;\n}\n\nexport interface AsyncPipeTransform<T, U> extends PipeTransform<T, U>, OnDestroy {\n\ttransform(value: T, ...args: any[]): U;\n\tonDestroy(): 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({});\n\t}\n\thas(pipeName: string): boolean {\n\t\tif (pipeName in this._ctx) {\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._ctx[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 provider = forkProvider();\n\t\t\taddProvider(provider);\n\t\t\tconst pipe = new pipeRef.modelClass();\n\t\t\tremoveProvider(provider);\n\t\t\ttransformFunc = (value: any, ...args: any[]) => pipe.transform(value, ...args);\n\t\t\tthis._ctx[pipeRef.name] = transformFunc;\n\t\t\treturn transformFunc;\n\t\t}\n\t\treturn void 0;\n\t}\n\tgetClass(): Type<PipeProvider> {\n\t\treturn PipeProvider;\n\t}\n}\n\nexport class AsyncPipeProvider extends ReadOnlyScope<object> {\n\tconstructor() {\n\t\tsuper({});\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): Type<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\treturn;\n\t}\n\tgetClass(): Type<AsyncPipeProvider> {\n\t\treturn AsyncPipeProvider;\n\t}\n}\n\nexport class AsyncPipeScope<T extends { [key: string]: AsyncPipeTransform<any, any> }> extends ReactiveControlScope<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);\n\t}\n\toverride set(propertyKey: keyof T, pipeClass: Type<AsyncPipeTransform<any, any>>, receiver?: any): boolean {\n\t\tconst detector = createChangeDetectorRef(this, propertyKey);\n\t\tconst provider = forkProvider();\n\t\tprovider.setType(ChangeDetectorRef, detector);\n\t\taddProvider(provider);\n\t\tconst pipe = new pipeClass(detector);\n\t\tremoveProvider(provider);\n\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\tsuper.unsubscribe(propertyKey, subscription);\n\t\tconst pipe = this._ctx[propertyKey];\n\t\tpipe.onDestroy();\n\t}\n\tgetClass(): Type<AsyncPipeScope<T>> {\n\t\treturn AsyncPipeScope;\n\t}\n}\n"]}
|
package/view/base-view.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-view.d.ts","sourceRoot":"","sources":["../../../src/core/view/base-view.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"base-view.d.ts","sourceRoot":"","sources":["../../../src/core/view/base-view.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAW/C,OAAO,EAAgC,aAAa,EAAa,MAAM,gCAAgC,CAAC;AAcxG,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,eAAe,EAAE,IAAI,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAkU5G"}
|
package/view/base-view.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactiveScope, ReactiveControlScope, isReactive } from '@ibyar/expressions';
|
|
2
|
-
import { isAfterContentChecked, isAfterContentInit, isAfterViewChecked, isAfterViewInit, isDoCheck, isOnChanges, isOnDestroy, isOnInit } from '../component/lifecycle.js';
|
|
2
|
+
import { isAfterContentChecked, isAfterContentInit, isAfterViewChecked, isAfterViewInit, isDoCheck, isOnChanges, isOnDestroy, isOnInit, isOnViewMove, isOnViewAdopted } from '../component/lifecycle.js';
|
|
3
3
|
import { EventEmitter } from '../component/events.js';
|
|
4
4
|
import { ComponentRender } from './render.js';
|
|
5
5
|
import { getRootZone } from '../zone/bootstrap.js';
|
|
@@ -7,14 +7,14 @@ import { AbstractAuroraZone, ProxyAuroraZone } from '../zone/zone.js';
|
|
|
7
7
|
import { ChangeDetectorRef, createModelChangeDetectorRef } from '../linker/change-detector-ref.js';
|
|
8
8
|
import { createProxyZone } from '../zone/proxy.js';
|
|
9
9
|
import { clearSignalScope, pushNewSignalScope } from '../signals/signals.js';
|
|
10
|
-
import { forkProvider, addProvider, removeProvider } from '../di/inject.js';
|
|
10
|
+
import { forkProvider, addProvider, removeProvider, inject } from '../di/inject.js';
|
|
11
11
|
import { isOutputSignal, VIEW_TOKEN } from '../component/initializer.js';
|
|
12
|
+
import { ShadowRootService } from './shadow-root.js';
|
|
12
13
|
export function baseFactoryView(htmlElementType) {
|
|
13
14
|
return class CustomView extends htmlElementType {
|
|
14
15
|
_model;
|
|
15
16
|
_signalScope;
|
|
16
17
|
_render;
|
|
17
|
-
_shadowRoot;
|
|
18
18
|
_componentRef;
|
|
19
19
|
_modelScope;
|
|
20
20
|
_viewScope;
|
|
@@ -28,7 +28,8 @@ export function baseFactoryView(htmlElementType) {
|
|
|
28
28
|
super();
|
|
29
29
|
this._componentRef = componentRef;
|
|
30
30
|
if (componentRef.isShadowDom && !componentRef.disabledFeatures?.includes('shadow')) {
|
|
31
|
-
|
|
31
|
+
const shadowRoot = this.attachShadow(componentRef.shadowRootInit);
|
|
32
|
+
inject(ShadowRootService).set(this, shadowRoot);
|
|
32
33
|
}
|
|
33
34
|
this._signalScope = pushNewSignalScope();
|
|
34
35
|
this._provider = forkProvider();
|
|
@@ -193,9 +194,9 @@ export function baseFactoryView(htmlElementType) {
|
|
|
193
194
|
// do once
|
|
194
195
|
if (this.needRendering) {
|
|
195
196
|
this.initView();
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
197
|
+
if (isAfterViewInit(this._model)) {
|
|
198
|
+
this._zone.run(this._model.afterViewInit, this._modelScope.getContextProxy());
|
|
199
|
+
}
|
|
199
200
|
}
|
|
200
201
|
if (isAfterViewChecked(this._model)) {
|
|
201
202
|
this._zone.run(this._model.afterViewChecked, this._modelScope.getContextProxy());
|
|
@@ -263,10 +264,18 @@ export function baseFactoryView(htmlElementType) {
|
|
|
263
264
|
this.onDestroyCalls.push(callback);
|
|
264
265
|
}
|
|
265
266
|
adoptedCallback() {
|
|
266
|
-
|
|
267
|
-
this.
|
|
267
|
+
(inject(ShadowRootService).get(this) ?? this).innerHTML = '';
|
|
268
|
+
this.needRendering = true;
|
|
269
|
+
if (isOnViewAdopted(this._model)) {
|
|
270
|
+
this._zone.run(this._model.onViewAdopted, this._modelScope.getContextProxy());
|
|
271
|
+
}
|
|
268
272
|
this.connectedCallback();
|
|
269
273
|
}
|
|
274
|
+
connectedMoveCallback() {
|
|
275
|
+
if (isOnViewMove(this._model)) {
|
|
276
|
+
this._zone.run(this._model.onViewMove, this._modelScope.getContextProxy());
|
|
277
|
+
}
|
|
278
|
+
}
|
|
270
279
|
disconnectedCallback() {
|
|
271
280
|
// notify first, then call model.onDestroy func
|
|
272
281
|
if (isOnDestroy(this._model)) {
|
|
@@ -285,6 +294,8 @@ export function baseFactoryView(htmlElementType) {
|
|
|
285
294
|
this.onDestroyCalls.splice(0, this.onDestroyCalls.length);
|
|
286
295
|
const event = new CustomEvent('disconnected', { cancelable: true, bubbles: false, composed: false });
|
|
287
296
|
this.dispatchEvent(event);
|
|
297
|
+
(inject(ShadowRootService).get(this) ?? this).innerHTML = '';
|
|
298
|
+
this.needRendering = true;
|
|
288
299
|
}
|
|
289
300
|
};
|
|
290
301
|
}
|