@ibyar/core 3.1.1 → 5.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/decorators.d.ts +4 -0
- package/annotation/decorators.d.ts.map +1 -1
- package/annotation/decorators.js +7 -1
- package/annotation/decorators.js.map +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/component.d.ts +1 -1
- package/component/component.d.ts.map +1 -1
- package/component/component.js +2 -2
- package/component/component.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/directive/providers.d.ts +1 -2
- package/directive/providers.d.ts.map +1 -1
- package/directive/providers.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 +10 -9
- package/pipe/pipe.d.ts +3 -9
- package/pipe/pipe.d.ts.map +1 -1
- package/pipe/pipe.js +39 -7
- package/pipe/pipe.js.map +1 -1
- package/providers/provider.d.ts +4 -4
- package/providers/provider.d.ts.map +1 -1
- package/providers/provider.js +9 -9
- package/providers/provider.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/form-view.js +1 -1
- package/view/form-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
package/di/inject.js
CHANGED
|
@@ -8,7 +8,7 @@ export function addProvider(modelProvider) {
|
|
|
8
8
|
PROVIDERS.push(modelProvider);
|
|
9
9
|
}
|
|
10
10
|
export function removeProvider(modelProvider) {
|
|
11
|
-
const index = PROVIDERS.
|
|
11
|
+
const index = PROVIDERS.lastIndexOf(modelProvider);
|
|
12
12
|
if (index >= 0) {
|
|
13
13
|
PROVIDERS.splice(index, 1);
|
|
14
14
|
}
|
package/di/inject.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject.js","sourceRoot":"","sources":["../../../src/core/di/inject.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAA4B,MAAM,eAAe,CAAC;AAG5E,MAAM,aAAa,GAAG,IAAI,iBAAiB,EAAE,CAAC;AAE9C,MAAM,SAAS,GAAwB,CAAC,aAAa,CAAC,CAAC;AAEvD,MAAM,UAAU,YAAY;IAC3B,OAAO,aAAa,CAAC,IAAI,EAAE,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,aAAgC;IAC3D,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,aAAgC;IAC9D,MAAM,KAAK,GAAG,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"inject.js","sourceRoot":"","sources":["../../../src/core/di/inject.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAA4B,MAAM,eAAe,CAAC;AAG5E,MAAM,aAAa,GAAG,IAAI,iBAAiB,EAAE,CAAC;AAE9C,MAAM,SAAS,GAAwB,CAAC,aAAa,CAAC,CAAC;AAEvD,MAAM,UAAU,YAAY;IAC3B,OAAO,aAAa,CAAC,IAAI,EAAE,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,aAAgC;IAC3D,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,aAAgC;IAC9D,MAAM,KAAK,GAAG,SAAS,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IACnD,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QAChB,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC5B,CAAC;AACF,CAAC;AAED,SAAS,WAAW;IACnB,OAAO,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC;AAC1C,CAAC;AAOD,MAAM,UAAU,OAAO,CAAI,QAAqB,EAAE,KAAS;IAC1D,WAAW,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;AACxC,CAAC;AAKD,MAAM,UAAU,MAAM,CAAI,QAAqB;IAC9C,OAAO,WAAW,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import { AbstractType, Type } from '../utils/typeof.js';\nimport { InjectionProvider, InjectionToken, Provider } from './provider.js';\n\n\nconst ROOT_PROVIDER = new InjectionProvider();\n\nconst PROVIDERS: InjectionProvider[] = [ROOT_PROVIDER];\n\nexport function forkProvider(): InjectionProvider {\n\treturn ROOT_PROVIDER.fork();\n}\n\nexport function addProvider(modelProvider: InjectionProvider) {\n\tPROVIDERS.push(modelProvider);\n}\n\nexport function removeProvider(modelProvider: InjectionProvider) {\n\tconst index = PROVIDERS.lastIndexOf(modelProvider);\n\tif (index >= 0) {\n\t\tPROVIDERS.splice(index, 1);\n\t}\n}\n\nfunction getProvider(): InjectionProvider {\n\treturn PROVIDERS.at(-1) ?? ROOT_PROVIDER;\n}\n\nexport function provide<T>(type: Type<T>): void;\nexport function provide<T>(type: AbstractType<T>): void;\nexport function provide<T>(type: Type<T>, value: T): void;\nexport function provide<T>(type: AbstractType<T>, value: T): void;\nexport function provide<T>(token: InjectionToken<T>, value: T): void;\nexport function provide<T>(provider: Provider<T>, value?: T) {\n\tgetProvider().provide(provider, value);\n}\n\nexport function inject<T>(type: Type<T>): T;\nexport function inject<T>(type: AbstractType<T>): T;\nexport function inject<T>(token: InjectionToken<T>): T | undefined;\nexport function inject<T>(provider: Provider<T>): T | undefined {\n\treturn getProvider().inject(provider);\n}\n"]}
|
package/directive/providers.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { ReactiveScope } from '@ibyar/expressions';
|
|
2
|
-
import { TypeOf } from '@ibyar/expressions/api/utils';
|
|
1
|
+
import { ReactiveScope, TypeOf } from '@ibyar/expressions';
|
|
3
2
|
import { AttributeDirective } from './directive.js';
|
|
4
3
|
export type ElementContext = {
|
|
5
4
|
this: HTMLElement;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../../src/core/directive/providers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../../src/core/directive/providers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,MAAM,MAAM,cAAc,GAAG;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS,CAAC;CAAE,CAAC;AACxG,qBAAa,oBAAqB,SAAQ,aAAa,CAAC,cAAc,CAAC;IAE1D,OAAO,CAAC,EAAE;IADtB,OAAO,CAAC,YAAY,CAA8C;gBAC9C,EAAE,EAAE,WAAW;IAInC,UAAU;IAGV,aAAa;IAGb,GAAG,CAAC,WAAW,EAAE,WAAW,GAAG,GAAG;IAyBlC,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,OAAO;IAyBlE,GAAG,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO;IAoBjC,QAAQ,IAAI,MAAM,CAAC,oBAAoB,CAAC;CAGxC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers.js","sourceRoot":"","sources":["../../../src/core/directive/providers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"providers.js","sourceRoot":"","sources":["../../../src/core/directive/providers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAU,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAGpD,MAAM,OAAO,oBAAqB,SAAQ,aAA6B;IAElD;IADZ,YAAY,GAAoC,IAAI,GAAG,EAAE,CAAC;IAClE,YAAoB,EAAe;QAClC,KAAK,CAAC,EAAoB,CAAC,CAAC;QADT,OAAE,GAAF,EAAE,CAAa;QAElC,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;IACrB,CAAC;IACD,UAAU;QACT,OAAO,IAAI,CAAC,EAAE,CAAC;IAChB,CAAC;IACD,aAAa;QACZ,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;IACD,GAAG,CAAC,WAAwB;QAC3B,IAAI,WAAW,KAAK,MAAM,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC,EAAE,CAAC;QAChB,CAAC;QACD,IAAI,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,WAAqB,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AAI,WAAW,IAAI,SAAS,EAAE,CAAC;gBAC9B,OAAO,IAAI,CAAC;YACb,CAAC;QACF,CAAC;QACD,IAAI,qBAAqB,CAAC,YAAY,CAAC,WAAW,CAAC,EAAE,CAAC;YACrD,OAAO,IAAI,CAAC;QACb,CAAC;QACD,IAAI,qBAAqB,CAAC,iBAAiB,CAAC,WAAW,CAAC,EAAE,CAAC;YAC1D,OAAO,IAAI,CAAC;QACb,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC;IACD,QAAQ;QACP,OAAO,oBAAoB,CAAC;IAC7B,CAAC;CACD","sourcesContent":["import { ReactiveScope, TypeOf } from '@ibyar/expressions';\nimport { isOnInit } from '../component/lifecycle.js';\nimport { classRegistryProvider } from '../providers/provider.js';\nimport { AttributeDirective } from './directive.js';\n\nexport type ElementContext = { this: HTMLElement } & { [key: string]: AttributeDirective | undefined; };\nexport class ElementReactiveScope extends ReactiveScope<ElementContext> {\n\tprivate directiveMap: Map<string, AttributeDirective> = new Map();\n\tconstructor(private el: HTMLElement) {\n\t\tsuper({} as ElementContext);\n\t\tthis._ctx.this = el;\n\t}\n\tgetElement() {\n\t\treturn this.el;\n\t}\n\tgetDirectives() {\n\t\treturn this.directiveMap;\n\t}\n\tget(propertyKey: PropertyKey): any {\n\t\tif (propertyKey === 'this') {\n\t\t\treturn this.el;\n\t\t}\n\t\tif (this.directiveMap.has(propertyKey as string)) {\n\t\t\tconst directive = this.directiveMap.get(propertyKey as string)!;\n\t\t\treturn directive;\n\t\t}\n\t\tfor (const directive of this.directiveMap.values()) {\n\t\t\tif (propertyKey in directive) {\n\t\t\t\treturn Reflect.get(directive, propertyKey);\n\t\t\t}\n\t\t}\n\t\tconst directiveRef = classRegistryProvider.getDirectiveRef<any>(propertyKey as string);\n\t\tif (directiveRef && directiveRef.modelClass instanceof AttributeDirective) {\n\t\t\tconst directive = new directiveRef.modelClass(this.el) as AttributeDirective;\n\t\t\tthis.directiveMap.set(propertyKey as string, directive);\n\t\t\tthis._ctx[propertyKey as string] = directive;\n\t\t\tif (isOnInit(directive)) {\n\t\t\t\tdirective.onInit();\n\t\t\t}\n\t\t\treturn Reflect.get(directive, propertyKey as string);\n\t\t}\n\t\treturn void 0;\n\t}\n\tset(propertyKey: PropertyKey, value: any, receiver?: any): boolean {\n\t\tif (propertyKey in this.el) {\n\t\t\treturn Reflect.set(this.el, propertyKey, value);\n\t\t}\n\t\tif (this.directiveMap.has(propertyKey as string)) {\n\t\t\tconst directive = this.directiveMap.get(propertyKey as string)!;\n\t\t\treturn Reflect.set(directive, propertyKey, value);\n\t\t}\n\t\tfor (const directive of this.directiveMap.values()) {\n\t\t\tif (propertyKey in directive) {\n\t\t\t\treturn Reflect.set(directive, propertyKey, value);\n\t\t\t}\n\t\t}\n\t\tconst directiveRef = classRegistryProvider.getDirectiveRef<any>(propertyKey as string);\n\t\tif (directiveRef && directiveRef.modelClass.prototype instanceof AttributeDirective) {\n\t\t\tconst directive = new directiveRef.modelClass(this.el) as AttributeDirective;\n\t\t\tthis.directiveMap.set(propertyKey as string, directive);\n\t\t\tconst result = Reflect.set(directive, propertyKey, value);\n\t\t\tif (isOnInit(directive)) {\n\t\t\t\tdirective.onInit();\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\t\treturn false;\n\t}\n\thas(propertyKey: string): boolean {\n\t\tif (propertyKey in this._ctx) {\n\t\t\treturn true;\n\t\t}\n\t\tif (this.directiveMap.has(propertyKey)) {\n\t\t\treturn true;\n\t\t}\n\t\tfor (const directive of this.directiveMap.values()) {\n\t\t\tif (propertyKey in directive) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\tif (classRegistryProvider.hasDirective(propertyKey)) {\n\t\t\treturn true;\n\t\t}\n\t\tif (classRegistryProvider.directiveHasInput(propertyKey)) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\tgetClass(): TypeOf<ElementReactiveScope> {\n\t\treturn ElementReactiveScope;\n\t}\n}\n"]}
|
|
@@ -8,10 +8,6 @@ interface IndexOptions {
|
|
|
8
8
|
* the index to insert the
|
|
9
9
|
*/
|
|
10
10
|
index?: number;
|
|
11
|
-
/**
|
|
12
|
-
* the default value is true
|
|
13
|
-
*/
|
|
14
|
-
insert?: boolean;
|
|
15
11
|
}
|
|
16
12
|
export interface ViewContainerOptions<C> extends IndexOptions {
|
|
17
13
|
context?: C;
|
|
@@ -21,6 +17,15 @@ export interface ViewContainerComponentOptions extends IndexOptions {
|
|
|
21
17
|
}
|
|
22
18
|
export interface HTMLElementOptions extends ElementCreationOptions, IndexOptions {
|
|
23
19
|
}
|
|
20
|
+
export type ElementRef<T> = {
|
|
21
|
+
nativeElement: T;
|
|
22
|
+
viewRef: EmbeddedViewRef<T>;
|
|
23
|
+
};
|
|
24
|
+
export type ComponentViewRef<T> = {
|
|
25
|
+
instance: T;
|
|
26
|
+
nativeElement: HTMLComponent<T>;
|
|
27
|
+
viewRef: EmbeddedViewRef<T>;
|
|
28
|
+
};
|
|
24
29
|
export declare abstract class ViewContainerRef {
|
|
25
30
|
/**
|
|
26
31
|
* Anchor element that specifies the location of this container in the containing view.
|
|
@@ -44,7 +49,11 @@ export declare abstract class ViewContainerRef {
|
|
|
44
49
|
* @param index The 0-based index of the view to retrieve.
|
|
45
50
|
* @returns The `ViewRef` instance, or null if the index is out of range.
|
|
46
51
|
*/
|
|
47
|
-
abstract get(index: number):
|
|
52
|
+
abstract get<T>(index: number): EmbeddedViewRef<T> | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Performs the specified action for each element in an array.
|
|
55
|
+
*/
|
|
56
|
+
abstract forEach<T>(callbackfn: (value: EmbeddedViewRef<T>, index: number) => void): void;
|
|
48
57
|
/**
|
|
49
58
|
* Reports how many views are currently attached to this container.
|
|
50
59
|
* @returns The number of views.
|
|
@@ -67,13 +76,13 @@ export declare abstract class ViewContainerRef {
|
|
|
67
76
|
* @param selector the tag name for the aurora custom-element
|
|
68
77
|
* @param options
|
|
69
78
|
*/
|
|
70
|
-
abstract createComponent<C extends {}>(selector: string, options?: IndexOptions): C
|
|
79
|
+
abstract createComponent<C extends {}>(selector: string, options?: IndexOptions): ComponentViewRef<C>;
|
|
71
80
|
/**
|
|
72
81
|
* create component by the aurora custom-element `View` Class
|
|
73
82
|
* @param viewClass the generated aurora view class
|
|
74
83
|
* @param options
|
|
75
84
|
*/
|
|
76
|
-
abstract createComponent<C extends {}>(viewClass: Type<HTMLComponent<C>>, options?: IndexOptions): C
|
|
85
|
+
abstract createComponent<C extends {}>(viewClass: Type<HTMLComponent<C>>, options?: IndexOptions): ComponentViewRef<C>;
|
|
77
86
|
/**
|
|
78
87
|
* Instantiates a single component and inserts its host view into this container.
|
|
79
88
|
*
|
|
@@ -86,20 +95,25 @@ export declare abstract class ViewContainerRef {
|
|
|
86
95
|
*
|
|
87
96
|
* @returns The new `HTMLComponent` which contains the component instance and the host view.
|
|
88
97
|
*/
|
|
89
|
-
abstract createComponent<C extends {}>(componentType: Type<C>, options?: ViewContainerComponentOptions): C
|
|
98
|
+
abstract createComponent<C extends {}>(componentType: Type<C>, options?: ViewContainerComponentOptions): ComponentViewRef<C>;
|
|
99
|
+
/**
|
|
100
|
+
* create an HTMLElement by tag name `selector`.
|
|
101
|
+
* @param selector the tag name for the aurora custom-element
|
|
102
|
+
* @param options
|
|
103
|
+
*/
|
|
104
|
+
abstract createElement<K extends keyof HTMLElementTagNameMap>(selector: K, options?: HTMLElementOptions): ElementRef<HTMLElementTagNameMap[K]>;
|
|
90
105
|
/**
|
|
91
106
|
* create an HTMLElement by tag name `selector`.
|
|
92
107
|
* @param selector the tag name for the aurora custom-element
|
|
93
108
|
* @param options
|
|
94
109
|
*/
|
|
95
|
-
abstract createElement<K extends keyof
|
|
96
|
-
abstract createElement<K extends keyof HTMLElementDeprecatedTagNameMap>(selector: K, options?: HTMLElementOptions): HTMLElementDeprecatedTagNameMap[K];
|
|
110
|
+
abstract createElement<K extends keyof HTMLElementDeprecatedTagNameMap>(selector: K, options?: HTMLElementOptions): ElementRef<HTMLElementDeprecatedTagNameMap[K]>;
|
|
97
111
|
/**
|
|
98
112
|
* create HTMLElement by View Class reference
|
|
99
113
|
* @param viewClass the generated aurora view class
|
|
100
114
|
* @param options
|
|
101
115
|
*/
|
|
102
|
-
abstract createElement<C extends HTMLElement>(htmlElementClass: Type<C>, options?: HTMLElementOptions): C
|
|
116
|
+
abstract createElement<C extends HTMLElement>(htmlElementClass: Type<C>, options?: HTMLElementOptions): ElementRef<C>;
|
|
103
117
|
/**
|
|
104
118
|
* create a text node and insert to the view
|
|
105
119
|
* @param data
|
|
@@ -115,13 +129,24 @@ export declare abstract class ViewContainerRef {
|
|
|
115
129
|
*
|
|
116
130
|
*/
|
|
117
131
|
abstract insert(viewRef: ViewRef, index?: number): ViewRef;
|
|
132
|
+
/**
|
|
133
|
+
* move a view to a new location from another container
|
|
134
|
+
* @param viewRef the view that needed to be inserted in this container.
|
|
135
|
+
* @param newIndex new index in this container, or append
|
|
136
|
+
*/
|
|
137
|
+
abstract adopt<T>(viewRef: EmbeddedViewRef<T>, newIndex?: number): void;
|
|
118
138
|
/**
|
|
119
139
|
* Moves a view to a new location in this container.
|
|
120
|
-
* @param
|
|
140
|
+
* @param oldIndex The 0-based index of the old location.
|
|
121
141
|
* @param newIndex The 0-based index of the new location.
|
|
122
|
-
* @returns The moved `ViewRef` instance.
|
|
123
142
|
*/
|
|
124
|
-
abstract move(
|
|
143
|
+
abstract move(oldIndex: number, newIndex: number): void;
|
|
144
|
+
/**
|
|
145
|
+
* swap 2 view position
|
|
146
|
+
* @param oldIndex
|
|
147
|
+
* @param newIndex
|
|
148
|
+
*/
|
|
149
|
+
abstract swap(index1: number, index2: number): void;
|
|
125
150
|
/**
|
|
126
151
|
* Returns the index of a view within the current container.
|
|
127
152
|
* @param viewRef The view to query.
|
|
@@ -134,19 +159,24 @@ export declare abstract class ViewContainerRef {
|
|
|
134
159
|
* @param index The 0-based index of the view to destroy.
|
|
135
160
|
* If not specified, the last view in the container is removed.
|
|
136
161
|
*/
|
|
137
|
-
abstract remove(index?: number):
|
|
162
|
+
abstract remove<T>(index?: number): EmbeddedViewRef<T> | undefined;
|
|
163
|
+
/**
|
|
164
|
+
* remove a view attached to this container with out destroying it.
|
|
165
|
+
* the view will be still attached to the DOM.
|
|
166
|
+
* useful in case of moving the view/component to anther container without realizing it again.
|
|
167
|
+
* returns the view.
|
|
168
|
+
* @param index
|
|
169
|
+
* @param destroy
|
|
170
|
+
* @returns the view in the index
|
|
171
|
+
*/
|
|
172
|
+
abstract remove<T>(index: number, destroy: false): EmbeddedViewRef<T> | undefined;
|
|
138
173
|
/**
|
|
139
174
|
* Detaches a view from this container without destroying it.
|
|
140
175
|
* Use along with `insert()` to move a view within the current container.
|
|
141
176
|
* @param index The 0-based index of the view to detach.
|
|
142
177
|
* If not specified, the last view in the container is detached.
|
|
143
178
|
*/
|
|
144
|
-
abstract detach(index?: number):
|
|
145
|
-
/**
|
|
146
|
-
* set the current views from this
|
|
147
|
-
* @param views the new `ViewRef` list
|
|
148
|
-
*/
|
|
149
|
-
abstract updateViews(views: ViewRef[]): void;
|
|
179
|
+
abstract detach<T>(index?: number): EmbeddedViewRef<T> | undefined;
|
|
150
180
|
}
|
|
151
181
|
export declare class ViewContainerRefImpl extends ViewContainerRef {
|
|
152
182
|
private _parent;
|
|
@@ -156,20 +186,22 @@ export declare class ViewContainerRefImpl extends ViewContainerRef {
|
|
|
156
186
|
get anchorElement(): Element;
|
|
157
187
|
get length(): number;
|
|
158
188
|
clear(): void;
|
|
159
|
-
get(index: number):
|
|
160
|
-
detach(index?: number):
|
|
161
|
-
|
|
162
|
-
|
|
189
|
+
get<T>(index: number): EmbeddedViewRef<T> | undefined;
|
|
190
|
+
detach<T>(index?: number): EmbeddedViewRef<T> | undefined;
|
|
191
|
+
adopt<T>(viewRef: EmbeddedViewRef<T>, newIndex?: number): void;
|
|
192
|
+
forEach<T>(callbackfn: (value: EmbeddedViewRef<T>, index: number) => void): void;
|
|
193
|
+
indexOf<T>(viewRef: EmbeddedViewRef<T>): number;
|
|
194
|
+
remove<T>(index?: number, destroy?: boolean): EmbeddedViewRef<T> | undefined;
|
|
163
195
|
insert(viewRef: EmbeddedViewRef<any>, index?: number): ViewRef;
|
|
164
|
-
move(
|
|
196
|
+
move(oldIndex: number, newIndex: number): void;
|
|
197
|
+
swap(index1: number, index2: number): void;
|
|
165
198
|
createEmbeddedView<C extends {}>(templateRef: TemplateRef, options?: ViewContainerOptions<C>): EmbeddedViewRef<C>;
|
|
166
|
-
createComponent<C extends {}>(selector: string, options?: IndexOptions): C
|
|
167
|
-
createComponent<C extends {}>(viewClass: MetadataClass<HTMLComponent<C>>, options?: IndexOptions): C
|
|
168
|
-
createComponent<C extends {}>(componentType: MetadataClass<C>, options?: ViewContainerComponentOptions): C
|
|
169
|
-
createElement<K extends keyof HTMLElementTagNameMap>(selector: K, options?: HTMLElementOptions): HTMLElementTagNameMap[K]
|
|
170
|
-
createElement<K extends keyof HTMLElementDeprecatedTagNameMap>(selector: K, options?: HTMLElementOptions): HTMLElementDeprecatedTagNameMap[K]
|
|
199
|
+
createComponent<C extends {}>(selector: string, options?: IndexOptions): ComponentViewRef<C>;
|
|
200
|
+
createComponent<C extends {}>(viewClass: MetadataClass<HTMLComponent<C>>, options?: IndexOptions): ComponentViewRef<C>;
|
|
201
|
+
createComponent<C extends {}>(componentType: MetadataClass<C>, options?: ViewContainerComponentOptions): ComponentViewRef<C>;
|
|
202
|
+
createElement<K extends keyof HTMLElementTagNameMap>(selector: K, options?: HTMLElementOptions): ElementRef<HTMLElementTagNameMap[K]>;
|
|
203
|
+
createElement<K extends keyof HTMLElementDeprecatedTagNameMap>(selector: K, options?: HTMLElementOptions): ElementRef<HTMLElementDeprecatedTagNameMap[K]>;
|
|
171
204
|
createTextNode(data: string, options?: IndexOptions): Text;
|
|
172
|
-
updateViews(views: ViewRef[]): void;
|
|
173
205
|
}
|
|
174
206
|
export {};
|
|
175
207
|
//# sourceMappingURL=view-container-ref.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view-container-ref.d.ts","sourceRoot":"","sources":["../../../src/core/linker/view-container-ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAuB,OAAO,EAAE,MAAM,eAAe,CAAC;AAE9E,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAG/D,UAAU,YAAY;IACrB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"view-container-ref.d.ts","sourceRoot":"","sources":["../../../src/core/linker/view-container-ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAuB,OAAO,EAAE,MAAM,eAAe,CAAC;AAE9E,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAG/D,UAAU,YAAY;IACrB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,oBAAoB,CAAC,CAAC,CAAE,SAAQ,YAAY;IAC5D,OAAO,CAAC,EAAE,CAAC,CAAC;CACZ;AAED,MAAM,WAAW,6BAA8B,SAAQ,YAAY;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,kBAAmB,SAAQ,sBAAsB,EAAE,YAAY;CAE/E;AAED,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;IAC3B,aAAa,EAAE,CAAC,CAAC;IACjB,OAAO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kBAAkB,GAAG,UAAU,CAAC,+BAA+B,CAAC,CAAC,CAAC,CAAC;IAezJ,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,IAAI;CAQnE"}
|
|
@@ -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,C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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,EA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B,EAAE,OAA4B;QACjG,IAAI,OAAU,CAAC;QACf,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAM,CAAC;QAClE,CAAC;aAAM,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE,CAAC;YACvC,OAAO,GAAG,IAAI,IAAI,EAAE,CAAC;QACtB,CAAC;aAAM,CAAC;YACP,MAAM,IAAI,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,iBAAi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A;IAItD,IAAI,OAAO,IAAI,CAAC,CAEf;IAED,IAAI,SAAS,IAAI,IAAI,EAAE,CAEtB;IACD,IAAI,KAAK,IAAI,OAAO,CAEnB;IACD,IAAI,IAAI,IAAI,OAAO,CAElB;IACD,IAAI,SAAS,IAAI,OAAO,CAEvB;IACD,OAAO,IAAI,IAAI;IAiBf,OAAO,CAAC,UAAU;IAQlB,KAAK,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI;IAG5B,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI;IAG7B,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,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,MAAM,OAAgB,OAAQ,SAAQ,iBAAiB;CAmBtD;AAGD,MAAM,OAAgB,eAAmB,SAAQ,OAAO;CAoDvD;AAED,MAAM,OAAO,mBAAuB,SAAQ,eAAkB;IAMpD;IACA;IACA;IAND,UAAU,GAAY,KAAK,CAAC;IAC5B,oBAAoB,GAAmB,EAAE,CAAC;IAElD,YACS,MAAyC,EACzC,UAAkB,EAClB,cAA6C;QACrD,KAAK,EAAE,CAAC;QAHA,WAAM,GAAN,MAAM,CAAmC;QACzC,eAAU,GAAV,UAAU,CAAQ;QAClB,mBAAc,GAAd,cAAc,CAA+B;IAEtD,CAAC;IAED,IAAI,OAAO;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;IACjC,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,IAAI;QACP,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAY,CAAC;IAC/D,CAAC;IACD,IAAI,SAAS;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC;IACxB,CAAC;IACD,OAAO;QACN,IAAI,CAAC,IAAI,CA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AAoB,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"]}
|