@microsoft/fast-html 1.0.0-alpha.19 → 1.0.0-alpha.20
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/README.md +3 -19
- package/dist/dts/components/observer-map.d.ts +3 -120
- package/dist/dts/components/schema.d.ts +23 -15
- package/dist/dts/components/template.d.ts +1 -5
- package/dist/dts/components/utilities.d.ts +33 -69
- package/dist/esm/components/observer-map.js +10 -512
- package/dist/esm/components/observer-map.spec.js +5 -599
- package/dist/esm/components/schema.js +39 -20
- package/dist/esm/components/schema.spec.js +9 -0
- package/dist/esm/components/template.js +31 -50
- package/dist/esm/components/utilities.js +202 -179
- package/dist/esm/components/utilities.spec.js +6 -29
- package/dist/esm/fixtures/repeat/main.js +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/fast-html.api.json +13 -126
- package/dist/fast-html.d.ts +118 -150
- package/dist/fast-html.untrimmed.d.ts +118 -150
- package/package.json +2 -3
- package/dist/dts/fixtures/partial/main.d.ts +0 -1
- package/dist/dts/fixtures/partial/partial.spec.d.ts +0 -1
- package/dist/esm/fixtures/partial/main.js +0 -32
- package/dist/esm/fixtures/partial/partial.spec.js +0 -14
|
@@ -2,36 +2,22 @@ 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 {
|
|
5
|
+
declare interface AccessCachedPath extends CachedPathCommon {
|
|
6
6
|
type: AccessCachedPathType;
|
|
7
|
-
relativePath: string;
|
|
8
|
-
absolutePath: string;
|
|
9
7
|
}
|
|
10
8
|
|
|
11
9
|
declare type AccessCachedPathType = "access";
|
|
12
10
|
|
|
13
11
|
declare type CachedPath = DefaultCachedPath | RepeatCachedPath | AccessCachedPath | EventCachedPath;
|
|
14
12
|
|
|
15
|
-
declare
|
|
16
|
-
|
|
17
|
-
|
|
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;
|
|
13
|
+
declare interface CachedPathCommon {
|
|
14
|
+
parentContext: string | null;
|
|
15
|
+
currentContext: string | null;
|
|
16
|
+
path: string;
|
|
30
17
|
}
|
|
31
18
|
|
|
32
|
-
declare interface DefaultCachedPath {
|
|
19
|
+
declare interface DefaultCachedPath extends CachedPathCommon {
|
|
33
20
|
type: DefaultCachedPathType;
|
|
34
|
-
paths: Record<string, CachedPath>;
|
|
35
21
|
}
|
|
36
22
|
|
|
37
23
|
declare type DefaultCachedPathType = "default";
|
|
@@ -48,128 +34,38 @@ declare interface ElementOptionsDictionary<ElementOptionsType = ElementOptions>
|
|
|
48
34
|
[key: string]: ElementOptionsType;
|
|
49
35
|
}
|
|
50
36
|
|
|
51
|
-
declare interface EventCachedPath {
|
|
37
|
+
declare interface EventCachedPath extends CachedPathCommon {
|
|
52
38
|
type: EventCachedPathType;
|
|
53
|
-
relativePath: string;
|
|
54
|
-
absolutePath: string;
|
|
55
39
|
}
|
|
56
40
|
|
|
57
41
|
declare type EventCachedPathType = "event";
|
|
58
42
|
|
|
43
|
+
declare interface JSONSchema extends JSONSchemaCommon {
|
|
44
|
+
$schema: string;
|
|
45
|
+
$id: string;
|
|
46
|
+
$defs?: Record<string, JSONSchemaDefinition>;
|
|
47
|
+
$ref?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare interface JSONSchemaCommon {
|
|
51
|
+
type?: string;
|
|
52
|
+
properties?: any;
|
|
53
|
+
items?: any;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
declare interface JSONSchemaDefinition extends JSONSchemaCommon {
|
|
57
|
+
$fast_context: string;
|
|
58
|
+
$fast_parent_contexts: Array<string>;
|
|
59
|
+
}
|
|
60
|
+
|
|
59
61
|
/**
|
|
60
62
|
* ObserverMap provides functionality for caching binding paths, extracting root properties,
|
|
61
63
|
* and defining observable properties on class prototypes
|
|
62
64
|
*/
|
|
63
65
|
export declare class ObserverMap {
|
|
64
|
-
private
|
|
65
|
-
private contextCache;
|
|
66
|
+
private schema;
|
|
66
67
|
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;
|
|
68
|
+
constructor(classPrototype: any, schema: Schema);
|
|
173
69
|
defineProperties(): void;
|
|
174
70
|
/**
|
|
175
71
|
* Creates a proxy for an object that intercepts property mutations and triggers Observable notifications
|
|
@@ -190,19 +86,11 @@ export declare class ObserverMap {
|
|
|
190
86
|
|
|
191
87
|
declare type ObserverMapOption = "all";
|
|
192
88
|
|
|
193
|
-
declare interface
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
parentContext: string | null;
|
|
197
|
-
contextPath: string | null;
|
|
198
|
-
type: PathType;
|
|
199
|
-
level: number;
|
|
200
|
-
rootPath: string | null;
|
|
201
|
-
context: ContextCache | null;
|
|
89
|
+
declare interface RegisterPathConfig {
|
|
90
|
+
rootPropertyName: string;
|
|
91
|
+
pathConfig: CachedPath;
|
|
202
92
|
}
|
|
203
93
|
|
|
204
|
-
declare type PathType = "access" | "default" | "event" | "repeat";
|
|
205
|
-
|
|
206
94
|
/**
|
|
207
95
|
* A mixin function that extends a base class with additional functionality for
|
|
208
96
|
* rendering and hydration.
|
|
@@ -213,14 +101,98 @@ declare type PathType = "access" | "default" | "event" | "repeat";
|
|
|
213
101
|
*/
|
|
214
102
|
export declare function RenderableFASTElement<T extends Constructable<FASTElement>>(BaseCtor: T): T;
|
|
215
103
|
|
|
216
|
-
declare interface RepeatCachedPath {
|
|
104
|
+
declare interface RepeatCachedPath extends CachedPathCommon {
|
|
217
105
|
type: RepeatCachedPathType;
|
|
218
|
-
context: string;
|
|
219
|
-
paths: Record<string, CachedPath>;
|
|
220
106
|
}
|
|
221
107
|
|
|
222
108
|
declare type RepeatCachedPathType = "repeat";
|
|
223
109
|
|
|
110
|
+
/**
|
|
111
|
+
* A constructed JSON schema from a template
|
|
112
|
+
*/
|
|
113
|
+
declare class Schema {
|
|
114
|
+
/**
|
|
115
|
+
* The name of the custom element
|
|
116
|
+
*/
|
|
117
|
+
private customElementName;
|
|
118
|
+
/**
|
|
119
|
+
* A JSON schema describing each root schema
|
|
120
|
+
*/
|
|
121
|
+
private jsonSchemaMap;
|
|
122
|
+
constructor(name: string);
|
|
123
|
+
/**
|
|
124
|
+
* Add a path to a schema
|
|
125
|
+
* @param config RegisterPathConfig
|
|
126
|
+
*/
|
|
127
|
+
addPath(config: RegisterPathConfig): void;
|
|
128
|
+
/**
|
|
129
|
+
* Gets the JSON schema for a property name
|
|
130
|
+
* @param rootPropertyName - the root property the JSON schema is mapped to
|
|
131
|
+
* @returns The JSON schema for the root property
|
|
132
|
+
*/
|
|
133
|
+
getSchema(rootPropertyName: string): JSONSchema | null;
|
|
134
|
+
/**
|
|
135
|
+
* Gets root properties
|
|
136
|
+
* @returns IterableIterator<string>
|
|
137
|
+
*/
|
|
138
|
+
getRootProperties(): IterableIterator<string>;
|
|
139
|
+
/**
|
|
140
|
+
* Get a path split into property names
|
|
141
|
+
* @param path The dot syntax path e.g. a.b.c
|
|
142
|
+
* @returns An array of items in the path
|
|
143
|
+
*/
|
|
144
|
+
private getSplitPath;
|
|
145
|
+
/**
|
|
146
|
+
* Gets the path to the $def
|
|
147
|
+
* @param context The context name e.g. {{item in items}} in a repeat creates the "item" context
|
|
148
|
+
* @returns A string to use as a $ref
|
|
149
|
+
*/
|
|
150
|
+
private getDefsPath;
|
|
151
|
+
/**
|
|
152
|
+
* Add a new JSON schema to the JSON schema map
|
|
153
|
+
* @param propertyName The name of the property to assign this JSON schema to
|
|
154
|
+
*/
|
|
155
|
+
private addNewSchema;
|
|
156
|
+
/**
|
|
157
|
+
* Add properties to a context
|
|
158
|
+
* @param schema The schema to add the properties to
|
|
159
|
+
* @param splitPath The path split into property/context names
|
|
160
|
+
* @param context The paths context
|
|
161
|
+
*/
|
|
162
|
+
private addPropertiesToAContext;
|
|
163
|
+
/**
|
|
164
|
+
* Add properties to an object
|
|
165
|
+
* @param schema The schema to add the properties to
|
|
166
|
+
* @param splitPath The path split into property/context names
|
|
167
|
+
* @param context The paths context
|
|
168
|
+
* @param type The data type (see JSON schema for details)
|
|
169
|
+
*/
|
|
170
|
+
private addPropertiesToAnObject;
|
|
171
|
+
/**
|
|
172
|
+
* Add an array to an object property
|
|
173
|
+
* @param schema The schema to add the properties to
|
|
174
|
+
* @param context The name of the context
|
|
175
|
+
*/
|
|
176
|
+
private addArrayToAnObject;
|
|
177
|
+
/**
|
|
178
|
+
* Add a context to the $defs property
|
|
179
|
+
* @param schema The schema to use
|
|
180
|
+
* @param propertyName The name of the property the context belongs to
|
|
181
|
+
* @param currentContext The current context
|
|
182
|
+
* @param parentContext The parent context
|
|
183
|
+
* @returns
|
|
184
|
+
*/
|
|
185
|
+
private addContext;
|
|
186
|
+
/**
|
|
187
|
+
* Get parent contexts
|
|
188
|
+
* @param schema The schema to use
|
|
189
|
+
* @param parentContext The parent context
|
|
190
|
+
* @param contexts A list of parent contexts
|
|
191
|
+
* @returns
|
|
192
|
+
*/
|
|
193
|
+
private getParentContexts;
|
|
194
|
+
}
|
|
195
|
+
|
|
224
196
|
/**
|
|
225
197
|
* The <f-template> custom element that will provide view logic to the element
|
|
226
198
|
*/
|
|
@@ -238,6 +210,7 @@ export declare class TemplateElement extends FASTElement {
|
|
|
238
210
|
* ObserverMap instance for caching binding paths
|
|
239
211
|
*/
|
|
240
212
|
private observerMap?;
|
|
213
|
+
private schema?;
|
|
241
214
|
private static defaultElementOptions;
|
|
242
215
|
static options(elementOptions?: ElementOptionsDictionary): typeof TemplateElement;
|
|
243
216
|
constructor();
|
|
@@ -295,11 +268,6 @@ export declare class TemplateElement extends FASTElement {
|
|
|
295
268
|
* @param observerMap - ObserverMap instance for caching binding paths (optional).
|
|
296
269
|
*/
|
|
297
270
|
private resolveInnerHTML;
|
|
298
|
-
/**
|
|
299
|
-
* Resolve all partial templates
|
|
300
|
-
* @param unresolvedInnerHTML - The innerHTML.
|
|
301
|
-
*/
|
|
302
|
-
private resolveAllPartials;
|
|
303
271
|
}
|
|
304
272
|
|
|
305
273
|
export { }
|
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.20",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Microsoft",
|
|
@@ -29,13 +29,12 @@
|
|
|
29
29
|
"build:binding": "webpack --config ./src/fixtures/binding/webpack.config.js",
|
|
30
30
|
"build:children": "webpack --config ./src/fixtures/children/webpack.config.js",
|
|
31
31
|
"build:dot-syntax": "webpack --config ./src/fixtures/dot-syntax/webpack.config.js",
|
|
32
|
-
"build:partial": "webpack --config ./src/fixtures/partial/webpack.config.js",
|
|
33
32
|
"build:when": "webpack --config ./src/fixtures/when/webpack.config.js",
|
|
34
33
|
"build:ref": "webpack --config ./src/fixtures/ref/webpack.config.js",
|
|
35
34
|
"build:repeat": "webpack --config ./src/fixtures/repeat/webpack.config.js",
|
|
36
35
|
"build:observer-map": "webpack --config ./src/fixtures/observer-map/webpack.config.js",
|
|
37
36
|
"build:slotted": "webpack --config ./src/fixtures/slotted/webpack.config.js",
|
|
38
|
-
"build-app": "npm run build:attribute && npm run build:dot-syntax && npm run build:
|
|
37
|
+
"build-app": "npm run build:attribute && npm run build:dot-syntax && 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",
|
|
39
38
|
"build-server": "tsc -b server",
|
|
40
39
|
"doc": "api-extractor run --local",
|
|
41
40
|
"doc:ci": "api-extractor run",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { FASTElement } from "@microsoft/fast-element";
|
|
2
|
-
import { RenderableFASTElement, TemplateElement } from "@microsoft/fast-html";
|
|
3
|
-
class TestElement extends FASTElement {
|
|
4
|
-
constructor() {
|
|
5
|
-
super(...arguments);
|
|
6
|
-
this.items = [
|
|
7
|
-
{
|
|
8
|
-
text: "Hello",
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
text: "Earth",
|
|
12
|
-
items: [
|
|
13
|
-
{
|
|
14
|
-
text: "Pluto",
|
|
15
|
-
items: [
|
|
16
|
-
{
|
|
17
|
-
text: "Mars",
|
|
18
|
-
},
|
|
19
|
-
],
|
|
20
|
-
},
|
|
21
|
-
],
|
|
22
|
-
},
|
|
23
|
-
];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
RenderableFASTElement(TestElement).defineAsync({
|
|
27
|
-
name: "test-element",
|
|
28
|
-
templateOptions: "defer-and-hydrate",
|
|
29
|
-
});
|
|
30
|
-
TemplateElement.define({
|
|
31
|
-
name: "f-template",
|
|
32
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
2
|
-
import { expect, test } from "@playwright/test";
|
|
3
|
-
test.describe("f-template", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
4
|
-
test("create a partial", ({ page }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
5
|
-
yield page.goto("/partial");
|
|
6
|
-
const customElement = yield page.locator("#test");
|
|
7
|
-
let customElementListItems = yield customElement.locator("li");
|
|
8
|
-
expect(yield customElementListItems.count()).toEqual(4);
|
|
9
|
-
expect(yield customElementListItems.nth(0).textContent()).toEqual("Hello");
|
|
10
|
-
expect(yield customElementListItems.nth(1).textContent()).toContain("Earth");
|
|
11
|
-
expect(yield customElementListItems.nth(2).textContent()).toContain("Pluto");
|
|
12
|
-
expect(yield customElementListItems.nth(3).textContent()).toContain("Mars");
|
|
13
|
-
}));
|
|
14
|
-
}));
|