@microsoft/fast-html 1.0.0-alpha.17 → 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.
@@ -2,8 +2,43 @@ import { Constructable } from '@microsoft/fast-element';
2
2
  import { FASTElement } from '@microsoft/fast-element';
3
3
  import { ShadowRootOptions } from '@microsoft/fast-element';
4
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
+
5
39
  declare interface ElementOptions {
6
40
  shadowOptions?: ShadowRootOptions | undefined;
41
+ observerMap?: ObserverMapOption | undefined;
7
42
  }
8
43
 
9
44
  /**
@@ -13,6 +48,161 @@ declare interface ElementOptionsDictionary<ElementOptionsType = ElementOptions>
13
48
  [key: string]: ElementOptionsType;
14
49
  }
15
50
 
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;
111
+ /**
112
+ * Finds a context item in the temporary context cache
113
+ */
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;
202
+ }
203
+
204
+ declare type PathType = "access" | "default" | "event" | "repeat";
205
+
16
206
  /**
17
207
  * A mixin function that extends a base class with additional functionality for
18
208
  * rendering and hydration.
@@ -23,6 +213,14 @@ declare interface ElementOptionsDictionary<ElementOptionsType = ElementOptions>
23
213
  */
24
214
  export declare function RenderableFASTElement<T extends Constructable<FASTElement>>(BaseCtor: T): T;
25
215
 
216
+ declare interface RepeatCachedPath {
217
+ type: RepeatCachedPathType;
218
+ context: string;
219
+ paths: Record<string, CachedPath>;
220
+ }
221
+
222
+ declare type RepeatCachedPathType = "repeat";
223
+
26
224
  /**
27
225
  * The <f-template> custom element that will provide view logic to the element
28
226
  */
@@ -36,6 +234,10 @@ export declare class TemplateElement extends FASTElement {
36
234
  */
37
235
  static elementOptions: ElementOptionsDictionary;
38
236
  private partials;
237
+ /**
238
+ * ObserverMap instance for caching binding paths
239
+ */
240
+ private observerMap?;
39
241
  private static defaultElementOptions;
40
242
  static options(elementOptions?: ElementOptionsDictionary): typeof TemplateElement;
41
243
  constructor();
@@ -49,6 +251,7 @@ export declare class TemplateElement extends FASTElement {
49
251
  * Resolve strings and values from an innerHTML string
50
252
  * @param innerHTML - The innerHTML.
51
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).
52
255
  */
53
256
  private resolveStringsAndValues;
54
257
  /**
@@ -62,6 +265,8 @@ export declare class TemplateElement extends FASTElement {
62
265
  * @param behaviorConfig - The directive behavior configuration object.
63
266
  * @param externalValues - The interpreted values from the parent.
64
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).
65
270
  */
66
271
  private resolveTemplateDirective;
67
272
  /**
@@ -78,6 +283,7 @@ export declare class TemplateElement extends FASTElement {
78
283
  * @param values - The interpreted values.
79
284
  * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
80
285
  * @param behaviorConfig - The binding behavior configuration object.
286
+ * @param observerMap - ObserverMap instance for caching binding paths (optional).
81
287
  */
82
288
  private resolveDataBinding;
83
289
  /**
@@ -86,6 +292,7 @@ export declare class TemplateElement extends FASTElement {
86
292
  * @param strings - The strings array.
87
293
  * @param values - The interpreted values.
88
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).
89
296
  */
90
297
  private resolveInnerHTML;
91
298
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/fast-html",
3
- "version": "1.0.0-alpha.17",
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.5.0"
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.5.0",
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",