@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.
Files changed (35) hide show
  1. package/dist/dts/components/element.d.ts +10 -10
  2. package/dist/dts/components/index.d.ts +1 -0
  3. package/dist/dts/components/observer-map.d.ts +143 -0
  4. package/dist/dts/components/observer-map.spec.d.ts +1 -0
  5. package/dist/dts/components/template.d.ts +11 -0
  6. package/dist/dts/components/utilities.d.ts +60 -1
  7. package/dist/dts/fixtures/observer-map/main.d.ts +1 -0
  8. package/dist/dts/fixtures/observer-map/observer-map.spec.d.ts +1 -0
  9. package/dist/dts/index.d.ts +1 -1
  10. package/dist/esm/components/element.js +24 -17
  11. package/dist/esm/components/index.js +1 -0
  12. package/dist/esm/components/observer-map.js +551 -0
  13. package/dist/esm/components/observer-map.spec.js +613 -0
  14. package/dist/esm/components/template.js +103 -85
  15. package/dist/esm/components/utilities.js +301 -50
  16. package/dist/esm/components/utilities.spec.js +109 -1
  17. package/dist/esm/fixtures/attribute/main.js +3 -3
  18. package/dist/esm/fixtures/binding/main.js +5 -5
  19. package/dist/esm/fixtures/children/main.js +3 -3
  20. package/dist/esm/fixtures/dot-syntax/dot-syntax.spec.js +109 -2
  21. package/dist/esm/fixtures/dot-syntax/main.js +30 -4
  22. package/dist/esm/fixtures/event/main.js +6 -6
  23. package/dist/esm/fixtures/observer-map/main.js +304 -0
  24. package/dist/esm/fixtures/observer-map/observer-map.spec.js +174 -0
  25. package/dist/esm/fixtures/partial/main.js +3 -2
  26. package/dist/esm/fixtures/ref/main.js +3 -2
  27. package/dist/esm/fixtures/repeat/main.js +5 -5
  28. package/dist/esm/fixtures/slotted/main.js +3 -3
  29. package/dist/esm/fixtures/when/main.js +21 -21
  30. package/dist/esm/index.js +1 -1
  31. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  32. package/dist/fast-html.api.json +247 -32
  33. package/dist/fast-html.d.ts +214 -6
  34. package/dist/fast-html.untrimmed.d.ts +214 -6
  35. package/package.json +5 -4
@@ -1,10 +1,10 @@
1
- import { FASTElement } from "@microsoft/fast-element";
2
- export declare abstract class RenderableFASTElement extends FASTElement {
3
- deferHydration: boolean;
4
- constructor();
5
- /**
6
- * A user defined function for determining if the element is ready to be hydrated.
7
- * This function will get called if it has been defined after the template is connected.
8
- */
9
- private prepare;
10
- }
1
+ import { type Constructable, type FASTElement } from "@microsoft/fast-element";
2
+ /**
3
+ * A mixin function that extends a base class with additional functionality for
4
+ * rendering and hydration.
5
+ *
6
+ * @param BaseCtor - The base class to extend.
7
+ * @returns A new class that extends the provided base class with additional functionality for rendering and hydration.
8
+ * @public
9
+ */
10
+ export declare function RenderableFASTElement<T extends Constructable<FASTElement>>(BaseCtor: T): T;
@@ -1,2 +1,3 @@
1
1
  export { TemplateElement } from "./template.js";
2
2
  export { RenderableFASTElement } from "./element.js";
3
+ export { ObserverMap } from "./observer-map.js";
@@ -0,0 +1,143 @@
1
+ import type { CachedPathMap, ContextCache, PathType } from "./utilities.js";
2
+ interface PathConfig {
3
+ path: string;
4
+ self: boolean;
5
+ parentContext: string | null;
6
+ contextPath: string | null;
7
+ type: PathType;
8
+ level: number;
9
+ rootPath: string | null;
10
+ context: ContextCache | null;
11
+ }
12
+ /**
13
+ * ObserverMap provides functionality for caching binding paths, extracting root properties,
14
+ * and defining observable properties on class prototypes
15
+ */
16
+ export declare class ObserverMap {
17
+ private cachePaths;
18
+ private contextCache;
19
+ private classPrototype;
20
+ constructor(classPrototype: any);
21
+ private getRootProperty;
22
+ /**
23
+ * Caches a binding path with context information for later use in generating observable properties
24
+ * @param context - The path context information containing path, self, parentContext, contextPath, type, and level
25
+ */
26
+ cachePathWithContext(config: PathConfig): void;
27
+ /**
28
+ * Handles caching of paths with relative navigation ("../")
29
+ * Determines the correct context level and caches the path accordingly
30
+ */
31
+ private handleRelativePathCaching;
32
+ /**
33
+ * Counts the number of "../" sequences in a path without using regex
34
+ */
35
+ private countRelativeNavigationLevels;
36
+ /**
37
+ * Extracts the property name from a relative path, removing all "../" sequences
38
+ */
39
+ private extractPropertyNameFromRelativePath;
40
+ /**
41
+ * Determines the target context after navigating up the specified number of levels
42
+ */
43
+ private getTargetContextForRelativePath;
44
+ /**
45
+ * Caches a path at the root level
46
+ */
47
+ private cacheAtRootLevel;
48
+ /**
49
+ * Caches a path at a specific context level
50
+ */
51
+ private cacheAtContextLevel;
52
+ /**
53
+ * Handles caching of access-type paths (property bindings)
54
+ */
55
+ private handleAccessPath;
56
+ /**
57
+ * Handles caching of repeat-type paths (array/loop contexts)
58
+ */
59
+ private handleRepeatPath;
60
+ /**
61
+ * Caches a simple access path without context complexity
62
+ */
63
+ private cacheSimpleAccessPath;
64
+ /**
65
+ * Finds a context item in the temporary context cache
66
+ */
67
+ private findContextInCache;
68
+ /**
69
+ * Attempts to place an access path under an existing repeat structure
70
+ * @returns true if successfully placed, false otherwise
71
+ */
72
+ private tryPlaceInExistingRepeat;
73
+ /**
74
+ * Recursively searches for and places access paths in matching repeat structures
75
+ */
76
+ private searchAndPlaceInRepeat;
77
+ /**
78
+ * Checks if a cached path is a repeat structure with matching context
79
+ */
80
+ private isMatchingRepeatStructure;
81
+ /**
82
+ * Determines if a cached path can be searched for nested structures
83
+ */
84
+ private canSearchNested;
85
+ /**
86
+ * Places an access path within an existing repeat structure
87
+ */
88
+ private placeAccessInRepeat;
89
+ /**
90
+ * Builds absolute paths for nested repeat access patterns
91
+ * @example "root.items.__index__.subitems.__index__.title"
92
+ */
93
+ private buildNestedRepeatAbsolutePath;
94
+ /**
95
+ * Caches access paths that have context information
96
+ */
97
+ private cacheAccessPathWithContext;
98
+ /**
99
+ * Extracts the relative path from a context's absolute path
100
+ * For nested contexts, this should match the cache structure path
101
+ */
102
+ private getRelativeContextPath;
103
+ /**
104
+ * Ensures a repeat structure exists in the cache
105
+ */
106
+ private ensureRepeatStructureExists;
107
+ /**
108
+ * Creates the cache structure for nested repeat patterns
109
+ */
110
+ private createNestedRepeatStructure;
111
+ /**
112
+ * Finds the cache path where a parent context's repeat structure is located
113
+ */
114
+ private findParentRepeatPath;
115
+ getCachedPathsWithContext(): CachedPathMap;
116
+ private resolveContextPath;
117
+ private resolveRootAndContextPath;
118
+ getAbsolutePath(config: PathConfig): string;
119
+ /**
120
+ * Builds the full context path by looking up parent contexts in contextCache
121
+ * @param parentContext - The immediate parent context to start from
122
+ * @param contextPath - The current context path (like "items")
123
+ * @returns The full absolute path including all parent contexts
124
+ */
125
+ private getPathFromCachedContext;
126
+ defineProperties(): void;
127
+ /**
128
+ * Creates a proxy for an object that intercepts property mutations and triggers Observable notifications
129
+ * @param target - The target instance that owns the root property
130
+ * @param rootProperty - The name of the root property for notification purposes
131
+ * @param object - The object to wrap with a proxy
132
+ * @returns A proxy that triggers notifications on property mutations
133
+ */
134
+ private getAndAssignObservables;
135
+ /**
136
+ * Creates a property change handler function for observable properties
137
+ * This handler is called when an observable property transitions from undefined to a defined value
138
+ * @param propertyName - The name of the property for which to create the change handler
139
+ * @returns A function that handles property changes and sets up proxies for object values
140
+ */
141
+ private defineChanged;
142
+ }
143
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,7 +1,9 @@
1
1
  import { FASTElement, ShadowRootOptions } from "@microsoft/fast-element";
2
2
  import "@microsoft/fast-element/install-hydratable-view-templates.js";
3
+ export type ObserverMapOption = "all";
3
4
  export interface ElementOptions {
4
5
  shadowOptions?: ShadowRootOptions | undefined;
6
+ observerMap?: ObserverMapOption | undefined;
5
7
  }
6
8
  /**
7
9
  * A dictionary of element options the TemplateElement will use to update the registered element
@@ -22,6 +24,10 @@ declare class TemplateElement extends FASTElement {
22
24
  */
23
25
  static elementOptions: ElementOptionsDictionary;
24
26
  private partials;
27
+ /**
28
+ * ObserverMap instance for caching binding paths
29
+ */
30
+ private observerMap?;
25
31
  private static defaultElementOptions;
26
32
  static options(elementOptions?: ElementOptionsDictionary): typeof TemplateElement;
27
33
  constructor();
@@ -35,6 +41,7 @@ declare class TemplateElement extends FASTElement {
35
41
  * Resolve strings and values from an innerHTML string
36
42
  * @param innerHTML - The innerHTML.
37
43
  * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
44
+ * @param observerMap - ObserverMap instance for caching binding paths (optional).
38
45
  */
39
46
  private resolveStringsAndValues;
40
47
  /**
@@ -48,6 +55,8 @@ declare class TemplateElement extends FASTElement {
48
55
  * @param behaviorConfig - The directive behavior configuration object.
49
56
  * @param externalValues - The interpreted values from the parent.
50
57
  * @param innerHTML - The innerHTML.
58
+ * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
59
+ * @param observerMap - ObserverMap instance for caching binding paths (optional).
51
60
  */
52
61
  private resolveTemplateDirective;
53
62
  /**
@@ -64,6 +73,7 @@ declare class TemplateElement extends FASTElement {
64
73
  * @param values - The interpreted values.
65
74
  * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
66
75
  * @param behaviorConfig - The binding behavior configuration object.
76
+ * @param observerMap - ObserverMap instance for caching binding paths (optional).
67
77
  */
68
78
  private resolveDataBinding;
69
79
  /**
@@ -72,6 +82,7 @@ declare class TemplateElement extends FASTElement {
72
82
  * @param strings - The strings array.
73
83
  * @param values - The interpreted values.
74
84
  * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
85
+ * @param observerMap - ObserverMap instance for caching binding paths (optional).
75
86
  */
76
87
  private resolveInnerHTML;
77
88
  /**
@@ -1,3 +1,4 @@
1
+ import { type ObserverMap } from "./observer-map.js";
1
2
  type BehaviorType = "dataBinding" | "templateDirective";
2
3
  type TemplateDirective = "when" | "repeat" | "apply";
3
4
  export type AttributeDirective = "children" | "slotted" | "ref";
@@ -5,6 +6,7 @@ type DataBindingBindingType = "client" | "default" | "unescaped";
5
6
  interface BehaviorConfig {
6
7
  type: BehaviorType;
7
8
  }
9
+ export type PathType = "access" | "default" | "event" | "repeat";
8
10
  export interface ContentDataBindingBehaviorConfig extends BaseDataBindingBehaviorConfig {
9
11
  subtype: "content";
10
12
  }
@@ -39,6 +41,45 @@ interface PartialTemplateConfig {
39
41
  startIndex: number;
40
42
  endIndex: number;
41
43
  }
44
+ type AccessCachedPathType = "access";
45
+ export interface AccessCachedPath {
46
+ type: AccessCachedPathType;
47
+ relativePath: string;
48
+ absolutePath: string;
49
+ }
50
+ type DefaultCachedPathType = "default";
51
+ export interface DefaultCachedPath {
52
+ type: DefaultCachedPathType;
53
+ paths: Record<string, CachedPath>;
54
+ }
55
+ type EventCachedPathType = "event";
56
+ export interface EventCachedPath {
57
+ type: EventCachedPathType;
58
+ relativePath: string;
59
+ absolutePath: string;
60
+ }
61
+ type RepeatCachedPathType = "repeat";
62
+ export interface RepeatCachedPath {
63
+ type: RepeatCachedPathType;
64
+ context: string;
65
+ paths: Record<string, CachedPath>;
66
+ }
67
+ export type CachedPath = DefaultCachedPath | RepeatCachedPath | AccessCachedPath | EventCachedPath;
68
+ export type CachedPathMap = Record<string, CachedPath>;
69
+ export interface ContextCache {
70
+ /**
71
+ * The path to this context
72
+ */
73
+ absolutePath: string;
74
+ /**
75
+ * The self string of that context
76
+ */
77
+ context: string;
78
+ /**
79
+ * The parent of this context
80
+ */
81
+ parent: string | null;
82
+ }
42
83
  /**
43
84
  * Get the index of the next matching tag
44
85
  * @param openingTagStartSlice - The slice starting from the opening tag
@@ -74,6 +115,14 @@ export declare function getAllPartials(innerHTML: string, offset?: number, parti
74
115
  * @returns A function to access the value from a given path.
75
116
  */
76
117
  export declare function pathResolver(path: string, self?: boolean): (accessibleObject: any, context: any) => any;
118
+ export declare function bindingResolver(path: string, self: boolean | undefined, parentContext: string | null, type: PathType, observerMap: ObserverMap | null, contextPath: string | null, level: number): (accessibleObject: any, context: any) => any;
119
+ export declare function expressionResolver(self: boolean, expression: ChainedExpression, parentContext: string | null, level: number, observerMap?: ObserverMap): (accessibleObject: any, context: any) => any;
120
+ /**
121
+ * Extracts all paths from a ChainedExpression, including nested expressions
122
+ * @param chainedExpression - The chained expression to extract paths from
123
+ * @returns A Set containing all unique paths found in the expression chain
124
+ */
125
+ export declare function extractPathsFromChainedExpression(chainedExpression: ChainedExpression): Set<string>;
77
126
  /**
78
127
  * Available operators include:
79
128
  *
@@ -93,6 +142,7 @@ type ChainingOperator = "||" | "&&" | "&amp;&amp;";
93
142
  interface Expression {
94
143
  operator: Operator;
95
144
  left: string;
145
+ leftIsValue: boolean | null;
96
146
  right: string | boolean | number | null;
97
147
  rightIsValue: boolean | null;
98
148
  }
@@ -119,7 +169,16 @@ export declare function transformInnerHTML(innerHTML: string, index?: number): s
119
169
  * @param self - Where the first item in the path path refers to the item itself (used by repeat).
120
170
  * @param chainedExpression - The chained expression which includes the expression and the next expression
121
171
  * if there is another in the chain
172
+ * @param observerMap - Optional ObserverMap instance for caching paths during template processing
122
173
  * @returns - A binding that resolves the chained expression logic
123
174
  */
124
- export declare function resolveWhen(self: boolean, { expression, next }: ChainedExpression): (x: boolean, c: any) => any;
175
+ export declare function resolveWhen(self: boolean, expression: ChainedExpression, parentContext: string | null, level: number, observerMap?: ObserverMap): (x: boolean, c: any) => any;
176
+ /**
177
+ * Get the next property
178
+ * @param path The dot syntax data path
179
+ * @returns The next property
180
+ */
181
+ export declare function getNextProperty(path: string): string;
182
+ export declare function assignObservables(cachePath: CachedPath, data: any, target: any, rootProperty: string): typeof Proxy;
183
+ export declare function assignProxy(cachePath: CachedPath, target: any, rootProperty: string, object: any): typeof Proxy;
125
184
  export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1 @@
1
- export { RenderableFASTElement, TemplateElement } from "./components/index.js";
1
+ export { RenderableFASTElement, TemplateElement, ObserverMap, } from "./components/index.js";
@@ -1,20 +1,27 @@
1
- import { __decorate, __metadata } from "tslib";
2
- import { attr, FASTElement } from "@microsoft/fast-element";
3
- export class RenderableFASTElement extends FASTElement {
4
- constructor() {
5
- super();
6
- this.deferHydration = true;
7
- if (this.prepare) {
8
- this.prepare().then(() => {
1
+ import { attr } from "@microsoft/fast-element";
2
+ /**
3
+ * A mixin function that extends a base class with additional functionality for
4
+ * rendering and hydration.
5
+ *
6
+ * @param BaseCtor - The base class to extend.
7
+ * @returns A new class that extends the provided base class with additional functionality for rendering and hydration.
8
+ * @public
9
+ */
10
+ export function RenderableFASTElement(BaseCtor) {
11
+ const C = class extends BaseCtor {
12
+ constructor(...args) {
13
+ super(...args);
14
+ this.deferHydration = true;
15
+ if (this.prepare) {
16
+ this.prepare().then(() => {
17
+ this.deferHydration = false;
18
+ });
19
+ }
20
+ else {
9
21
  this.deferHydration = false;
10
- });
22
+ }
11
23
  }
12
- else {
13
- this.deferHydration = false;
14
- }
15
- }
24
+ };
25
+ attr({ mode: "boolean", attribute: "defer-hydration" })(C.prototype, "deferHydration");
26
+ return C;
16
27
  }
17
- __decorate([
18
- attr({ mode: "boolean", attribute: "defer-hydration" }),
19
- __metadata("design:type", Boolean)
20
- ], RenderableFASTElement.prototype, "deferHydration", void 0);
@@ -1,2 +1,3 @@
1
1
  export { TemplateElement } from "./template.js";
2
2
  export { RenderableFASTElement } from "./element.js";
3
+ export { ObserverMap } from "./observer-map.js";