@microsoft/fast-html 1.0.0-alpha.2 → 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.
Files changed (52) hide show
  1. package/README.md +129 -18
  2. package/dist/dts/components/element.d.ts +10 -0
  3. package/dist/dts/components/index.d.ts +2 -0
  4. package/dist/dts/components/observer-map.d.ts +26 -0
  5. package/dist/dts/components/schema.d.ts +134 -0
  6. package/dist/dts/components/template.d.ts +35 -6
  7. package/dist/dts/components/utilities.d.ts +92 -19
  8. package/dist/dts/fixtures/observer-map/main.d.ts +1 -0
  9. package/dist/dts/fixtures/observer-map/observer-map.spec.d.ts +1 -0
  10. package/dist/dts/index.d.ts +1 -1
  11. package/dist/esm/components/element.js +27 -0
  12. package/dist/esm/components/index.js +2 -0
  13. package/dist/esm/components/observer-map.js +49 -0
  14. package/dist/esm/components/observer-map.spec.js +19 -0
  15. package/dist/esm/components/schema.js +215 -0
  16. package/dist/esm/components/schema.spec.js +257 -0
  17. package/dist/esm/components/template.js +160 -99
  18. package/dist/esm/components/utilities.js +553 -43
  19. package/dist/esm/components/utilities.spec.js +246 -44
  20. package/dist/esm/fixtures/attribute/main.js +3 -2
  21. package/dist/esm/fixtures/binding/binding.spec.js +6 -0
  22. package/dist/esm/fixtures/binding/main.js +13 -2
  23. package/dist/esm/fixtures/children/children.spec.js +4 -0
  24. package/dist/esm/fixtures/children/main.js +3 -2
  25. package/dist/esm/fixtures/dot-syntax/dot-syntax.spec.js +109 -2
  26. package/dist/esm/fixtures/dot-syntax/main.js +30 -4
  27. package/dist/esm/fixtures/event/event.spec.js +28 -5
  28. package/dist/esm/fixtures/event/main.js +21 -5
  29. package/dist/esm/fixtures/observer-map/main.js +304 -0
  30. package/dist/esm/fixtures/observer-map/observer-map.spec.js +174 -0
  31. package/dist/esm/fixtures/ref/main.js +3 -2
  32. package/dist/esm/fixtures/ref/ref.spec.js +2 -6
  33. package/dist/esm/fixtures/repeat/main.js +27 -2
  34. package/dist/esm/fixtures/repeat/repeat.spec.js +16 -6
  35. package/dist/esm/fixtures/slotted/main.js +15 -4
  36. package/dist/esm/fixtures/slotted/slotted.spec.js +18 -19
  37. package/dist/esm/fixtures/when/main.js +139 -2
  38. package/dist/esm/fixtures/when/when.spec.js +64 -1
  39. package/dist/esm/index.js +1 -1
  40. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  41. package/dist/fast-html.api.json +279 -0
  42. package/dist/fast-html.d.ts +215 -5
  43. package/dist/fast-html.untrimmed.d.ts +215 -5
  44. package/package.json +12 -9
  45. package/rules/attribute-directives.yml +38 -0
  46. package/rules/call-expression-with-event-argument.yml +41 -0
  47. package/rules/member-expression.yml +33 -0
  48. package/rules/tag-function-to-template-literal.yml +16 -0
  49. package/dist/esm/fixtures/partial/main.js +0 -31
  50. package/dist/esm/fixtures/partial/partial.spec.js +0 -14
  51. /package/dist/dts/{fixtures/partial/main.d.ts → components/observer-map.spec.d.ts} +0 -0
  52. /package/dist/dts/{fixtures/partial/partial.spec.d.ts → components/schema.spec.d.ts} +0 -0
@@ -172,6 +172,185 @@
172
172
  "name": "",
173
173
  "preserveMemberOrder": false,
174
174
  "members": [
175
+ {
176
+ "kind": "Class",
177
+ "canonicalReference": "@microsoft/fast-html!ObserverMap:class",
178
+ "docComment": "/**\n * ObserverMap provides functionality for caching binding paths, extracting root properties, and defining observable properties on class prototypes\n */\n",
179
+ "excerptTokens": [
180
+ {
181
+ "kind": "Content",
182
+ "text": "export declare class ObserverMap "
183
+ }
184
+ ],
185
+ "fileUrlPath": "dist/dts/components/observer-map.d.ts",
186
+ "releaseTag": "Public",
187
+ "isAbstract": false,
188
+ "name": "ObserverMap",
189
+ "preserveMemberOrder": false,
190
+ "members": [
191
+ {
192
+ "kind": "Constructor",
193
+ "canonicalReference": "@microsoft/fast-html!ObserverMap:constructor(1)",
194
+ "docComment": "/**\n * Constructs a new instance of the `ObserverMap` class\n */\n",
195
+ "excerptTokens": [
196
+ {
197
+ "kind": "Content",
198
+ "text": "constructor(classPrototype: "
199
+ },
200
+ {
201
+ "kind": "Content",
202
+ "text": "any"
203
+ },
204
+ {
205
+ "kind": "Content",
206
+ "text": ", schema: "
207
+ },
208
+ {
209
+ "kind": "Reference",
210
+ "text": "Schema",
211
+ "canonicalReference": "@microsoft/fast-html!~Schema:class"
212
+ },
213
+ {
214
+ "kind": "Content",
215
+ "text": ");"
216
+ }
217
+ ],
218
+ "releaseTag": "Public",
219
+ "isProtected": false,
220
+ "overloadIndex": 1,
221
+ "parameters": [
222
+ {
223
+ "parameterName": "classPrototype",
224
+ "parameterTypeTokenRange": {
225
+ "startIndex": 1,
226
+ "endIndex": 2
227
+ },
228
+ "isOptional": false
229
+ },
230
+ {
231
+ "parameterName": "schema",
232
+ "parameterTypeTokenRange": {
233
+ "startIndex": 3,
234
+ "endIndex": 4
235
+ },
236
+ "isOptional": false
237
+ }
238
+ ]
239
+ },
240
+ {
241
+ "kind": "Method",
242
+ "canonicalReference": "@microsoft/fast-html!ObserverMap#defineProperties:member(1)",
243
+ "docComment": "",
244
+ "excerptTokens": [
245
+ {
246
+ "kind": "Content",
247
+ "text": "defineProperties(): "
248
+ },
249
+ {
250
+ "kind": "Content",
251
+ "text": "void"
252
+ },
253
+ {
254
+ "kind": "Content",
255
+ "text": ";"
256
+ }
257
+ ],
258
+ "isStatic": false,
259
+ "returnTypeTokenRange": {
260
+ "startIndex": 1,
261
+ "endIndex": 2
262
+ },
263
+ "releaseTag": "Public",
264
+ "isProtected": false,
265
+ "overloadIndex": 1,
266
+ "parameters": [],
267
+ "isOptional": false,
268
+ "isAbstract": false,
269
+ "name": "defineProperties"
270
+ }
271
+ ],
272
+ "implementsTokenRanges": []
273
+ },
274
+ {
275
+ "kind": "Function",
276
+ "canonicalReference": "@microsoft/fast-html!RenderableFASTElement:function(1)",
277
+ "docComment": "/**\n * A mixin function that extends a base class with additional functionality for rendering and hydration.\n *\n * @param BaseCtor - The base class to extend.\n *\n * @returns A new class that extends the provided base class with additional functionality for rendering and hydration.\n *\n * @public\n */\n",
278
+ "excerptTokens": [
279
+ {
280
+ "kind": "Content",
281
+ "text": "export declare function RenderableFASTElement<T extends "
282
+ },
283
+ {
284
+ "kind": "Reference",
285
+ "text": "Constructable",
286
+ "canonicalReference": "@microsoft/fast-element!Constructable:type"
287
+ },
288
+ {
289
+ "kind": "Content",
290
+ "text": "<"
291
+ },
292
+ {
293
+ "kind": "Reference",
294
+ "text": "FASTElement",
295
+ "canonicalReference": "@microsoft/fast-element!FASTElement:interface"
296
+ },
297
+ {
298
+ "kind": "Content",
299
+ "text": ">"
300
+ },
301
+ {
302
+ "kind": "Content",
303
+ "text": ">(BaseCtor: "
304
+ },
305
+ {
306
+ "kind": "Content",
307
+ "text": "T"
308
+ },
309
+ {
310
+ "kind": "Content",
311
+ "text": "): "
312
+ },
313
+ {
314
+ "kind": "Content",
315
+ "text": "T"
316
+ },
317
+ {
318
+ "kind": "Content",
319
+ "text": ";"
320
+ }
321
+ ],
322
+ "fileUrlPath": "dist/dts/components/element.d.ts",
323
+ "returnTypeTokenRange": {
324
+ "startIndex": 8,
325
+ "endIndex": 9
326
+ },
327
+ "releaseTag": "Public",
328
+ "overloadIndex": 1,
329
+ "parameters": [
330
+ {
331
+ "parameterName": "BaseCtor",
332
+ "parameterTypeTokenRange": {
333
+ "startIndex": 6,
334
+ "endIndex": 7
335
+ },
336
+ "isOptional": false
337
+ }
338
+ ],
339
+ "typeParameters": [
340
+ {
341
+ "typeParameterName": "T",
342
+ "constraintTokenRange": {
343
+ "startIndex": 1,
344
+ "endIndex": 5
345
+ },
346
+ "defaultTypeTokenRange": {
347
+ "startIndex": 0,
348
+ "endIndex": 0
349
+ }
350
+ }
351
+ ],
352
+ "name": "RenderableFASTElement"
353
+ },
175
354
  {
176
355
  "kind": "Class",
177
356
  "canonicalReference": "@microsoft/fast-html!TemplateElement:class",
@@ -197,6 +376,21 @@
197
376
  "name": "TemplateElement",
198
377
  "preserveMemberOrder": false,
199
378
  "members": [
379
+ {
380
+ "kind": "Constructor",
381
+ "canonicalReference": "@microsoft/fast-html!TemplateElement:constructor(1)",
382
+ "docComment": "/**\n * Constructs a new instance of the `TemplateElement` class\n */\n",
383
+ "excerptTokens": [
384
+ {
385
+ "kind": "Content",
386
+ "text": "constructor();"
387
+ }
388
+ ],
389
+ "releaseTag": "Public",
390
+ "isProtected": false,
391
+ "overloadIndex": 1,
392
+ "parameters": []
393
+ },
200
394
  {
201
395
  "kind": "Method",
202
396
  "canonicalReference": "@microsoft/fast-html!TemplateElement#connectedCallback:member(1)",
@@ -228,6 +422,37 @@
228
422
  "isAbstract": false,
229
423
  "name": "connectedCallback"
230
424
  },
425
+ {
426
+ "kind": "Property",
427
+ "canonicalReference": "@microsoft/fast-html!TemplateElement.elementOptions:member",
428
+ "docComment": "/**\n * A dictionary of custom element options\n */\n",
429
+ "excerptTokens": [
430
+ {
431
+ "kind": "Content",
432
+ "text": "static elementOptions: "
433
+ },
434
+ {
435
+ "kind": "Reference",
436
+ "text": "ElementOptionsDictionary",
437
+ "canonicalReference": "@microsoft/fast-html!~ElementOptionsDictionary:interface"
438
+ },
439
+ {
440
+ "kind": "Content",
441
+ "text": ";"
442
+ }
443
+ ],
444
+ "isReadonly": false,
445
+ "isOptional": false,
446
+ "releaseTag": "Public",
447
+ "name": "elementOptions",
448
+ "propertyTypeTokenRange": {
449
+ "startIndex": 1,
450
+ "endIndex": 2
451
+ },
452
+ "isStatic": true,
453
+ "isProtected": false,
454
+ "isAbstract": false
455
+ },
231
456
  {
232
457
  "kind": "Property",
233
458
  "canonicalReference": "@microsoft/fast-html!TemplateElement#name:member",
@@ -257,6 +482,60 @@
257
482
  "isStatic": false,
258
483
  "isProtected": false,
259
484
  "isAbstract": false
485
+ },
486
+ {
487
+ "kind": "Method",
488
+ "canonicalReference": "@microsoft/fast-html!TemplateElement.options:member(1)",
489
+ "docComment": "",
490
+ "excerptTokens": [
491
+ {
492
+ "kind": "Content",
493
+ "text": "static options(elementOptions?: "
494
+ },
495
+ {
496
+ "kind": "Reference",
497
+ "text": "ElementOptionsDictionary",
498
+ "canonicalReference": "@microsoft/fast-html!~ElementOptionsDictionary:interface"
499
+ },
500
+ {
501
+ "kind": "Content",
502
+ "text": "): "
503
+ },
504
+ {
505
+ "kind": "Content",
506
+ "text": "typeof "
507
+ },
508
+ {
509
+ "kind": "Reference",
510
+ "text": "TemplateElement",
511
+ "canonicalReference": "@microsoft/fast-html!TemplateElement:class"
512
+ },
513
+ {
514
+ "kind": "Content",
515
+ "text": ";"
516
+ }
517
+ ],
518
+ "isStatic": true,
519
+ "returnTypeTokenRange": {
520
+ "startIndex": 3,
521
+ "endIndex": 5
522
+ },
523
+ "releaseTag": "Public",
524
+ "isProtected": false,
525
+ "overloadIndex": 1,
526
+ "parameters": [
527
+ {
528
+ "parameterName": "elementOptions",
529
+ "parameterTypeTokenRange": {
530
+ "startIndex": 1,
531
+ "endIndex": 2
532
+ },
533
+ "isOptional": true
534
+ }
535
+ ],
536
+ "isOptional": false,
537
+ "isAbstract": false,
538
+ "name": "options"
260
539
  }
261
540
  ],
262
541
  "extendsTokenRange": {
@@ -1,4 +1,197 @@
1
+ import { Constructable } from '@microsoft/fast-element';
1
2
  import { FASTElement } from '@microsoft/fast-element';
3
+ import { ShadowRootOptions } from '@microsoft/fast-element';
4
+
5
+ declare interface AccessCachedPath extends CachedPathCommon {
6
+ type: AccessCachedPathType;
7
+ }
8
+
9
+ declare type AccessCachedPathType = "access";
10
+
11
+ declare type CachedPath = DefaultCachedPath | RepeatCachedPath | AccessCachedPath | EventCachedPath;
12
+
13
+ declare interface CachedPathCommon {
14
+ parentContext: string | null;
15
+ currentContext: string | null;
16
+ path: string;
17
+ }
18
+
19
+ declare interface DefaultCachedPath extends CachedPathCommon {
20
+ type: DefaultCachedPathType;
21
+ }
22
+
23
+ declare type DefaultCachedPathType = "default";
24
+
25
+ declare interface ElementOptions {
26
+ shadowOptions?: ShadowRootOptions | undefined;
27
+ observerMap?: ObserverMapOption | undefined;
28
+ }
29
+
30
+ /**
31
+ * A dictionary of element options the TemplateElement will use to update the registered element
32
+ */
33
+ declare interface ElementOptionsDictionary<ElementOptionsType = ElementOptions> {
34
+ [key: string]: ElementOptionsType;
35
+ }
36
+
37
+ declare interface EventCachedPath extends CachedPathCommon {
38
+ type: EventCachedPathType;
39
+ }
40
+
41
+ declare type EventCachedPathType = "event";
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
+
61
+ /**
62
+ * ObserverMap provides functionality for caching binding paths, extracting root properties,
63
+ * and defining observable properties on class prototypes
64
+ */
65
+ export declare class ObserverMap {
66
+ private schema;
67
+ private classPrototype;
68
+ constructor(classPrototype: any, schema: Schema);
69
+ defineProperties(): void;
70
+ /**
71
+ * Creates a proxy for an object that intercepts property mutations and triggers Observable notifications
72
+ * @param target - The target instance that owns the root property
73
+ * @param rootProperty - The name of the root property for notification purposes
74
+ * @param object - The object to wrap with a proxy
75
+ * @returns A proxy that triggers notifications on property mutations
76
+ */
77
+ private getAndAssignObservables;
78
+ /**
79
+ * Creates a property change handler function for observable properties
80
+ * This handler is called when an observable property transitions from undefined to a defined value
81
+ * @param propertyName - The name of the property for which to create the change handler
82
+ * @returns A function that handles property changes and sets up proxies for object values
83
+ */
84
+ private defineChanged;
85
+ }
86
+
87
+ declare type ObserverMapOption = "all";
88
+
89
+ declare interface RegisterPathConfig {
90
+ rootPropertyName: string;
91
+ pathConfig: CachedPath;
92
+ }
93
+
94
+ /**
95
+ * A mixin function that extends a base class with additional functionality for
96
+ * rendering and hydration.
97
+ *
98
+ * @param BaseCtor - The base class to extend.
99
+ * @returns A new class that extends the provided base class with additional functionality for rendering and hydration.
100
+ * @public
101
+ */
102
+ export declare function RenderableFASTElement<T extends Constructable<FASTElement>>(BaseCtor: T): T;
103
+
104
+ declare interface RepeatCachedPath extends CachedPathCommon {
105
+ type: RepeatCachedPathType;
106
+ }
107
+
108
+ declare type RepeatCachedPathType = "repeat";
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
+ }
2
195
 
3
196
  /**
4
197
  * The <f-template> custom element that will provide view logic to the element
@@ -8,12 +201,30 @@ export declare class TemplateElement extends FASTElement {
8
201
  * The name of the custom element this template will be applied to
9
202
  */
10
203
  name?: string;
204
+ /**
205
+ * A dictionary of custom element options
206
+ */
207
+ static elementOptions: ElementOptionsDictionary;
11
208
  private partials;
209
+ /**
210
+ * ObserverMap instance for caching binding paths
211
+ */
212
+ private observerMap?;
213
+ private schema?;
214
+ private static defaultElementOptions;
215
+ static options(elementOptions?: ElementOptionsDictionary): typeof TemplateElement;
216
+ constructor();
217
+ /**
218
+ * Set options for a custom element
219
+ * @param name - The name of the custom element to set options for.
220
+ */
221
+ private static setOptions;
12
222
  connectedCallback(): void;
13
223
  /**
14
224
  * Resolve strings and values from an innerHTML string
15
225
  * @param innerHTML - The innerHTML.
16
226
  * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
227
+ * @param observerMap - ObserverMap instance for caching binding paths (optional).
17
228
  */
18
229
  private resolveStringsAndValues;
19
230
  /**
@@ -27,6 +238,8 @@ export declare class TemplateElement extends FASTElement {
27
238
  * @param behaviorConfig - The directive behavior configuration object.
28
239
  * @param externalValues - The interpreted values from the parent.
29
240
  * @param innerHTML - The innerHTML.
241
+ * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
242
+ * @param observerMap - ObserverMap instance for caching binding paths (optional).
30
243
  */
31
244
  private resolveTemplateDirective;
32
245
  /**
@@ -43,6 +256,7 @@ export declare class TemplateElement extends FASTElement {
43
256
  * @param values - The interpreted values.
44
257
  * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
45
258
  * @param behaviorConfig - The binding behavior configuration object.
259
+ * @param observerMap - ObserverMap instance for caching binding paths (optional).
46
260
  */
47
261
  private resolveDataBinding;
48
262
  /**
@@ -51,13 +265,9 @@ export declare class TemplateElement extends FASTElement {
51
265
  * @param strings - The strings array.
52
266
  * @param values - The interpreted values.
53
267
  * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
268
+ * @param observerMap - ObserverMap instance for caching binding paths (optional).
54
269
  */
55
270
  private resolveInnerHTML;
56
- /**
57
- * Resolve all partial templates
58
- * @param unresolvedInnerHTML - The innerHTML.
59
- */
60
- private resolveAllPartials;
61
271
  }
62
272
 
63
273
  export { }