@microsoft/fast-html 1.0.0-alpha.16 → 1.0.0-alpha.18
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/dist/dts/components/element.d.ts +10 -10
- package/dist/dts/components/index.d.ts +1 -0
- package/dist/dts/components/observer-map.d.ts +143 -0
- package/dist/dts/components/observer-map.spec.d.ts +1 -0
- package/dist/dts/components/template.d.ts +11 -0
- package/dist/dts/components/utilities.d.ts +60 -1
- package/dist/dts/fixtures/observer-map/main.d.ts +1 -0
- package/dist/dts/fixtures/observer-map/observer-map.spec.d.ts +1 -0
- package/dist/dts/index.d.ts +1 -1
- package/dist/esm/components/element.js +24 -17
- package/dist/esm/components/index.js +1 -0
- package/dist/esm/components/observer-map.js +551 -0
- package/dist/esm/components/observer-map.spec.js +613 -0
- package/dist/esm/components/template.js +103 -85
- package/dist/esm/components/utilities.js +301 -50
- package/dist/esm/components/utilities.spec.js +109 -1
- package/dist/esm/fixtures/attribute/main.js +3 -3
- package/dist/esm/fixtures/binding/main.js +5 -5
- package/dist/esm/fixtures/children/main.js +3 -3
- package/dist/esm/fixtures/dot-syntax/dot-syntax.spec.js +109 -2
- package/dist/esm/fixtures/dot-syntax/main.js +30 -4
- package/dist/esm/fixtures/event/main.js +6 -6
- package/dist/esm/fixtures/observer-map/main.js +304 -0
- package/dist/esm/fixtures/observer-map/observer-map.spec.js +174 -0
- package/dist/esm/fixtures/partial/main.js +3 -2
- package/dist/esm/fixtures/ref/main.js +3 -2
- package/dist/esm/fixtures/repeat/main.js +5 -5
- package/dist/esm/fixtures/slotted/main.js +3 -3
- package/dist/esm/fixtures/when/main.js +21 -21
- package/dist/esm/index.js +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/fast-html.api.json +247 -32
- package/dist/fast-html.d.ts +214 -6
- package/dist/fast-html.untrimmed.d.ts +214 -6
- package/package.json +5 -4
|
@@ -1,8 +1,44 @@
|
|
|
1
|
+
import { Constructable } from '@microsoft/fast-element';
|
|
1
2
|
import { FASTElement } from '@microsoft/fast-element';
|
|
2
3
|
import { ShadowRootOptions } from '@microsoft/fast-element';
|
|
3
4
|
|
|
5
|
+
declare interface AccessCachedPath {
|
|
6
|
+
type: AccessCachedPathType;
|
|
7
|
+
relativePath: string;
|
|
8
|
+
absolutePath: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare type AccessCachedPathType = "access";
|
|
12
|
+
|
|
13
|
+
declare type CachedPath = DefaultCachedPath | RepeatCachedPath | AccessCachedPath | EventCachedPath;
|
|
14
|
+
|
|
15
|
+
declare type CachedPathMap = Record<string, CachedPath>;
|
|
16
|
+
|
|
17
|
+
declare interface ContextCache {
|
|
18
|
+
/**
|
|
19
|
+
* The path to this context
|
|
20
|
+
*/
|
|
21
|
+
absolutePath: string;
|
|
22
|
+
/**
|
|
23
|
+
* The self string of that context
|
|
24
|
+
*/
|
|
25
|
+
context: string;
|
|
26
|
+
/**
|
|
27
|
+
* The parent of this context
|
|
28
|
+
*/
|
|
29
|
+
parent: string | null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
declare interface DefaultCachedPath {
|
|
33
|
+
type: DefaultCachedPathType;
|
|
34
|
+
paths: Record<string, CachedPath>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
declare type DefaultCachedPathType = "default";
|
|
38
|
+
|
|
4
39
|
declare interface ElementOptions {
|
|
5
40
|
shadowOptions?: ShadowRootOptions | undefined;
|
|
41
|
+
observerMap?: ObserverMapOption | undefined;
|
|
6
42
|
}
|
|
7
43
|
|
|
8
44
|
/**
|
|
@@ -12,16 +48,179 @@ declare interface ElementOptionsDictionary<ElementOptionsType = ElementOptions>
|
|
|
12
48
|
[key: string]: ElementOptionsType;
|
|
13
49
|
}
|
|
14
50
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
51
|
+
declare interface EventCachedPath {
|
|
52
|
+
type: EventCachedPathType;
|
|
53
|
+
relativePath: string;
|
|
54
|
+
absolutePath: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
declare type EventCachedPathType = "event";
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* ObserverMap provides functionality for caching binding paths, extracting root properties,
|
|
61
|
+
* and defining observable properties on class prototypes
|
|
62
|
+
*/
|
|
63
|
+
export declare class ObserverMap {
|
|
64
|
+
private cachePaths;
|
|
65
|
+
private contextCache;
|
|
66
|
+
private classPrototype;
|
|
67
|
+
constructor(classPrototype: any);
|
|
68
|
+
private getRootProperty;
|
|
69
|
+
/**
|
|
70
|
+
* Caches a binding path with context information for later use in generating observable properties
|
|
71
|
+
* @param context - The path context information containing path, self, parentContext, contextPath, type, and level
|
|
72
|
+
*/
|
|
73
|
+
cachePathWithContext(config: PathConfig): void;
|
|
74
|
+
/**
|
|
75
|
+
* Handles caching of paths with relative navigation ("../")
|
|
76
|
+
* Determines the correct context level and caches the path accordingly
|
|
77
|
+
*/
|
|
78
|
+
private handleRelativePathCaching;
|
|
79
|
+
/**
|
|
80
|
+
* Counts the number of "../" sequences in a path without using regex
|
|
81
|
+
*/
|
|
82
|
+
private countRelativeNavigationLevels;
|
|
83
|
+
/**
|
|
84
|
+
* Extracts the property name from a relative path, removing all "../" sequences
|
|
85
|
+
*/
|
|
86
|
+
private extractPropertyNameFromRelativePath;
|
|
87
|
+
/**
|
|
88
|
+
* Determines the target context after navigating up the specified number of levels
|
|
89
|
+
*/
|
|
90
|
+
private getTargetContextForRelativePath;
|
|
91
|
+
/**
|
|
92
|
+
* Caches a path at the root level
|
|
93
|
+
*/
|
|
94
|
+
private cacheAtRootLevel;
|
|
95
|
+
/**
|
|
96
|
+
* Caches a path at a specific context level
|
|
97
|
+
*/
|
|
98
|
+
private cacheAtContextLevel;
|
|
99
|
+
/**
|
|
100
|
+
* Handles caching of access-type paths (property bindings)
|
|
101
|
+
*/
|
|
102
|
+
private handleAccessPath;
|
|
103
|
+
/**
|
|
104
|
+
* Handles caching of repeat-type paths (array/loop contexts)
|
|
105
|
+
*/
|
|
106
|
+
private handleRepeatPath;
|
|
107
|
+
/**
|
|
108
|
+
* Caches a simple access path without context complexity
|
|
109
|
+
*/
|
|
110
|
+
private cacheSimpleAccessPath;
|
|
18
111
|
/**
|
|
19
|
-
*
|
|
20
|
-
* This function will get called if it has been defined after the template is connected.
|
|
112
|
+
* Finds a context item in the temporary context cache
|
|
21
113
|
*/
|
|
22
|
-
private
|
|
114
|
+
private findContextInCache;
|
|
115
|
+
/**
|
|
116
|
+
* Attempts to place an access path under an existing repeat structure
|
|
117
|
+
* @returns true if successfully placed, false otherwise
|
|
118
|
+
*/
|
|
119
|
+
private tryPlaceInExistingRepeat;
|
|
120
|
+
/**
|
|
121
|
+
* Recursively searches for and places access paths in matching repeat structures
|
|
122
|
+
*/
|
|
123
|
+
private searchAndPlaceInRepeat;
|
|
124
|
+
/**
|
|
125
|
+
* Checks if a cached path is a repeat structure with matching context
|
|
126
|
+
*/
|
|
127
|
+
private isMatchingRepeatStructure;
|
|
128
|
+
/**
|
|
129
|
+
* Determines if a cached path can be searched for nested structures
|
|
130
|
+
*/
|
|
131
|
+
private canSearchNested;
|
|
132
|
+
/**
|
|
133
|
+
* Places an access path within an existing repeat structure
|
|
134
|
+
*/
|
|
135
|
+
private placeAccessInRepeat;
|
|
136
|
+
/**
|
|
137
|
+
* Builds absolute paths for nested repeat access patterns
|
|
138
|
+
* @example "root.items.__index__.subitems.__index__.title"
|
|
139
|
+
*/
|
|
140
|
+
private buildNestedRepeatAbsolutePath;
|
|
141
|
+
/**
|
|
142
|
+
* Caches access paths that have context information
|
|
143
|
+
*/
|
|
144
|
+
private cacheAccessPathWithContext;
|
|
145
|
+
/**
|
|
146
|
+
* Extracts the relative path from a context's absolute path
|
|
147
|
+
* For nested contexts, this should match the cache structure path
|
|
148
|
+
*/
|
|
149
|
+
private getRelativeContextPath;
|
|
150
|
+
/**
|
|
151
|
+
* Ensures a repeat structure exists in the cache
|
|
152
|
+
*/
|
|
153
|
+
private ensureRepeatStructureExists;
|
|
154
|
+
/**
|
|
155
|
+
* Creates the cache structure for nested repeat patterns
|
|
156
|
+
*/
|
|
157
|
+
private createNestedRepeatStructure;
|
|
158
|
+
/**
|
|
159
|
+
* Finds the cache path where a parent context's repeat structure is located
|
|
160
|
+
*/
|
|
161
|
+
private findParentRepeatPath;
|
|
162
|
+
getCachedPathsWithContext(): CachedPathMap;
|
|
163
|
+
private resolveContextPath;
|
|
164
|
+
private resolveRootAndContextPath;
|
|
165
|
+
getAbsolutePath(config: PathConfig): string;
|
|
166
|
+
/**
|
|
167
|
+
* Builds the full context path by looking up parent contexts in contextCache
|
|
168
|
+
* @param parentContext - The immediate parent context to start from
|
|
169
|
+
* @param contextPath - The current context path (like "items")
|
|
170
|
+
* @returns The full absolute path including all parent contexts
|
|
171
|
+
*/
|
|
172
|
+
private getPathFromCachedContext;
|
|
173
|
+
defineProperties(): void;
|
|
174
|
+
/**
|
|
175
|
+
* Creates a proxy for an object that intercepts property mutations and triggers Observable notifications
|
|
176
|
+
* @param target - The target instance that owns the root property
|
|
177
|
+
* @param rootProperty - The name of the root property for notification purposes
|
|
178
|
+
* @param object - The object to wrap with a proxy
|
|
179
|
+
* @returns A proxy that triggers notifications on property mutations
|
|
180
|
+
*/
|
|
181
|
+
private getAndAssignObservables;
|
|
182
|
+
/**
|
|
183
|
+
* Creates a property change handler function for observable properties
|
|
184
|
+
* This handler is called when an observable property transitions from undefined to a defined value
|
|
185
|
+
* @param propertyName - The name of the property for which to create the change handler
|
|
186
|
+
* @returns A function that handles property changes and sets up proxies for object values
|
|
187
|
+
*/
|
|
188
|
+
private defineChanged;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
declare type ObserverMapOption = "all";
|
|
192
|
+
|
|
193
|
+
declare interface PathConfig {
|
|
194
|
+
path: string;
|
|
195
|
+
self: boolean;
|
|
196
|
+
parentContext: string | null;
|
|
197
|
+
contextPath: string | null;
|
|
198
|
+
type: PathType;
|
|
199
|
+
level: number;
|
|
200
|
+
rootPath: string | null;
|
|
201
|
+
context: ContextCache | null;
|
|
23
202
|
}
|
|
24
203
|
|
|
204
|
+
declare type PathType = "access" | "default" | "event" | "repeat";
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* A mixin function that extends a base class with additional functionality for
|
|
208
|
+
* rendering and hydration.
|
|
209
|
+
*
|
|
210
|
+
* @param BaseCtor - The base class to extend.
|
|
211
|
+
* @returns A new class that extends the provided base class with additional functionality for rendering and hydration.
|
|
212
|
+
* @public
|
|
213
|
+
*/
|
|
214
|
+
export declare function RenderableFASTElement<T extends Constructable<FASTElement>>(BaseCtor: T): T;
|
|
215
|
+
|
|
216
|
+
declare interface RepeatCachedPath {
|
|
217
|
+
type: RepeatCachedPathType;
|
|
218
|
+
context: string;
|
|
219
|
+
paths: Record<string, CachedPath>;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
declare type RepeatCachedPathType = "repeat";
|
|
223
|
+
|
|
25
224
|
/**
|
|
26
225
|
* The <f-template> custom element that will provide view logic to the element
|
|
27
226
|
*/
|
|
@@ -35,6 +234,10 @@ export declare class TemplateElement extends FASTElement {
|
|
|
35
234
|
*/
|
|
36
235
|
static elementOptions: ElementOptionsDictionary;
|
|
37
236
|
private partials;
|
|
237
|
+
/**
|
|
238
|
+
* ObserverMap instance for caching binding paths
|
|
239
|
+
*/
|
|
240
|
+
private observerMap?;
|
|
38
241
|
private static defaultElementOptions;
|
|
39
242
|
static options(elementOptions?: ElementOptionsDictionary): typeof TemplateElement;
|
|
40
243
|
constructor();
|
|
@@ -48,6 +251,7 @@ export declare class TemplateElement extends FASTElement {
|
|
|
48
251
|
* Resolve strings and values from an innerHTML string
|
|
49
252
|
* @param innerHTML - The innerHTML.
|
|
50
253
|
* @param self - Indicates that this should refer to itself instead of a property when creating bindings.
|
|
254
|
+
* @param observerMap - ObserverMap instance for caching binding paths (optional).
|
|
51
255
|
*/
|
|
52
256
|
private resolveStringsAndValues;
|
|
53
257
|
/**
|
|
@@ -61,6 +265,8 @@ export declare class TemplateElement extends FASTElement {
|
|
|
61
265
|
* @param behaviorConfig - The directive behavior configuration object.
|
|
62
266
|
* @param externalValues - The interpreted values from the parent.
|
|
63
267
|
* @param innerHTML - The innerHTML.
|
|
268
|
+
* @param self - Indicates that this should refer to itself instead of a property when creating bindings.
|
|
269
|
+
* @param observerMap - ObserverMap instance for caching binding paths (optional).
|
|
64
270
|
*/
|
|
65
271
|
private resolveTemplateDirective;
|
|
66
272
|
/**
|
|
@@ -77,6 +283,7 @@ export declare class TemplateElement extends FASTElement {
|
|
|
77
283
|
* @param values - The interpreted values.
|
|
78
284
|
* @param self - Indicates that this should refer to itself instead of a property when creating bindings.
|
|
79
285
|
* @param behaviorConfig - The binding behavior configuration object.
|
|
286
|
+
* @param observerMap - ObserverMap instance for caching binding paths (optional).
|
|
80
287
|
*/
|
|
81
288
|
private resolveDataBinding;
|
|
82
289
|
/**
|
|
@@ -85,6 +292,7 @@ export declare class TemplateElement extends FASTElement {
|
|
|
85
292
|
* @param strings - The strings array.
|
|
86
293
|
* @param values - The interpreted values.
|
|
87
294
|
* @param self - Indicates that this should refer to itself instead of a property when creating bindings.
|
|
295
|
+
* @param observerMap - ObserverMap instance for caching binding paths (optional).
|
|
88
296
|
*/
|
|
89
297
|
private resolveInnerHTML;
|
|
90
298
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/fast-html",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.18",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Microsoft",
|
|
@@ -33,8 +33,9 @@
|
|
|
33
33
|
"build:when": "webpack --config ./src/fixtures/when/webpack.config.js",
|
|
34
34
|
"build:ref": "webpack --config ./src/fixtures/ref/webpack.config.js",
|
|
35
35
|
"build:repeat": "webpack --config ./src/fixtures/repeat/webpack.config.js",
|
|
36
|
+
"build:observer-map": "webpack --config ./src/fixtures/observer-map/webpack.config.js",
|
|
36
37
|
"build:slotted": "webpack --config ./src/fixtures/slotted/webpack.config.js",
|
|
37
|
-
"build-app": "npm run build:attribute && npm run build:dot-syntax && npm run build:partial && npm run build:event && npm run build:children && npm run build:binding && npm run build:when && npm run build:ref && npm run build:repeat && npm run build:slotted",
|
|
38
|
+
"build-app": "npm run build:attribute && npm run build:dot-syntax && npm run build:partial && npm run build:event && npm run build:children && npm run build:binding && npm run build:when && npm run build:ref && npm run build:repeat && npm run build:observer-map && npm run build:slotted",
|
|
38
39
|
"build-server": "tsc -b server",
|
|
39
40
|
"doc": "api-extractor run --local",
|
|
40
41
|
"doc:ci": "api-extractor run",
|
|
@@ -63,12 +64,12 @@
|
|
|
63
64
|
"./dist/esm/index.js"
|
|
64
65
|
],
|
|
65
66
|
"peerDependencies": {
|
|
66
|
-
"@microsoft/fast-element": "^2.
|
|
67
|
+
"@microsoft/fast-element": "^2.6.0"
|
|
67
68
|
},
|
|
68
69
|
"devDependencies": {
|
|
69
70
|
"@ast-grep/cli": "^0.37.0",
|
|
70
71
|
"@microsoft/api-extractor": "^7.47.0",
|
|
71
|
-
"@microsoft/fast-element": "^2.
|
|
72
|
+
"@microsoft/fast-element": "^2.6.0",
|
|
72
73
|
"@playwright/test": "^1.49.0",
|
|
73
74
|
"@types/express": "^4.17.21",
|
|
74
75
|
"@types/node": "^17.0.17",
|