@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
package/README.md CHANGED
@@ -22,7 +22,13 @@ npm install --save @microsoft/fast-html
22
22
  In your JS bundle you will need to include the `@microsoft/fast-html` package:
23
23
 
24
24
  ```typescript
25
- import { TemplateElement } from "@microsoft/fast-html";
25
+ import { RenderableFASTElement, TemplateElement } from "@microsoft/fast-html";
26
+ import { MyCustomElement } from "./my-custom-element";
27
+
28
+ RenderableFASTElement(MyCustomElement).defineAsync({
29
+ name: "my-custom-element",
30
+ templateOptions: "defer-and-hydrate",
31
+ });
26
32
 
27
33
  TemplateElement.define({
28
34
  name: "f-template",
@@ -45,9 +51,57 @@ Example:
45
51
  </f-template>
46
52
  ```
47
53
 
54
+ #### Non-browser HTML rendering
55
+
56
+ One of the benefits of FAST declarative HTML templates is that the server can be stack agnostic as JavaScript does not need to be interpreted. By default `@microsoft/fast-html` will expect hydratable content and uses comments and datasets for tracking the binding logic. For more information on what that markup should look like, as well as an example of how initial state may be applied, read our [documentation](./RENDERING.md) to understand what markup should be generated for a hydratable experience. For the sake of brevity hydratable markup will be excluded from the README.
57
+
58
+ #### Adding shadowOptions
59
+
60
+ By default `shadowOptions` via the `TemplateElement` will be with `"mode": "open"` once the template has been set. To set each components `shadowOptions` you can pass an `options` object.
61
+
62
+ Example:
63
+
64
+ ```typescript
65
+ TemplateElement.options({
66
+ "my-custom-element": {
67
+ shadowOptions: {
68
+ mode: "closed",
69
+ }
70
+ },
71
+ }).define({
72
+ name: "f-template",
73
+ });
74
+ ```
75
+
76
+ #### Using the RenderableFASTElement
77
+
78
+ The use of `RenderableFASTElement` as a mixin for your custom element will automatically remove the `defer-hydration` attribute signalling for hydration to begin, and if you need to add state before hydration should occur you can make use of the `prepare` method.
79
+
80
+ Example:
81
+ ```typescript
82
+ class MyCustomElement extends FASTElement {
83
+ private prepare(): Promise<void> {
84
+ // Get initial state
85
+ }
86
+ }
87
+
88
+ RenderableFASTElement(MyCustomElement).defineAsync({
89
+ name: "my-custom-element",
90
+ templateOptions: "defer-and-hydrate",
91
+ });
92
+ ```
93
+
48
94
  ### Syntax
49
95
 
50
- All bindings use a handlebars syntax.
96
+ All bindings use a handlebars-like syntax.
97
+
98
+ Some bindings are only relevant to the browser, such as for click handlers or other pieces of dynamic interaction. As such, their bindings use single curly braces `{}`, this is to prevent an intial SSR (Server Side Rendering) or other build time rendering technologies from needing to interpret them.
99
+
100
+ If a binding is relevant to both client and the back end rendering engine, it will use `{{}}` or `{{{}}}` depending on what type of data injection is being done.
101
+
102
+ Browser-only bindings:
103
+ - Event bindings
104
+ - Attribute directives
51
105
 
52
106
  #### Content binding
53
107
 
@@ -60,33 +114,49 @@ All bindings use a handlebars syntax.
60
114
  Event bindings must include the `()` as well as being preceeded by `@` in keeping with `@microsoft/fast-element` tagged template `html` syntax.
61
115
 
62
116
  ```html
63
- <button @click="{{handleClick()}}"></button>
117
+ <button @click="{handleClick()}"></button>
118
+ ```
119
+
120
+ In addition you may include an event or attribute or observable, events are denoted with `e` as a reserved letter.
121
+
122
+ Event:
123
+ ```html
124
+ <button @click="{handleClick(e)}"></button>
125
+ ```
126
+
127
+ Attribute/Observable:
128
+ ```html
129
+ <button @click="{handleClick(foo)}"></button>
64
130
  ```
65
131
 
66
132
  #### Directives
67
133
 
68
134
  Directives are assumed to be either an attribute directive or a directive that also serves a template. Both are prepended by `f-`. The logic of these directives and what their use cases are is explained in the [FAST html documentation](https://fast.design/docs/getting-started/html-directives).
69
135
 
136
+ Attribute directives are part of [client side binding](#syntax) and therefore use the `{}` syntax.
137
+
70
138
  Attribute directives include:
71
139
  - **slotted**
72
140
 
73
141
  Example:
74
142
  ```html
75
- <slot f-slotted="{{slottedNodes}}"></slot>
143
+ <slot f-slotted="{slottedNodes}"></slot>
144
+ <slot f-slotted="{slottedNodes filter elements()}"></slot>
145
+ <slot f-slotted="{slottedNodes filter elements(div, p)}"></slot>
76
146
  ```
77
147
 
78
148
  - **children**
79
149
 
80
150
  Example:
81
151
  ```html
82
- <ul f-children="{{listItems}}"><f-repeat value="{{item in list}}"><li>{{item}}</li></f-repeat></ul>
152
+ <ul f-children="{listItems}"><f-repeat value="{{item in list}}"><li>{{item}}</li></f-repeat></ul>
83
153
  ```
84
154
 
85
155
  - **ref**
86
156
 
87
157
  Example:
88
158
  ```html
89
- <video f-ref="{{video}}"></video>
159
+ <video f-ref="{video}"></video>
90
160
  ```
91
161
 
92
162
  Template directives include:
@@ -95,8 +165,21 @@ Template directives include:
95
165
  Example:
96
166
  ```html
97
167
  <f-when value="{{show}}">Hello world</f-when>
168
+ <f-when value="{{!show}}">Goodbye world</f-when>
98
169
  ```
99
170
 
171
+ The following operators can also be used:
172
+ - `==`
173
+ - `!=`
174
+ - `>=`
175
+ - `>`
176
+ - `<=`
177
+ - `<`
178
+ - `||`
179
+ - `&&`
180
+
181
+ Where the right operand can be either a reference to a value (string e.g. `{{foo == 'bar'}}`, boolean e.g. `{{foo == true}}`, number e.g. `{{foo == 3}}`) or another binding value.
182
+
100
183
  - **repeat**
101
184
 
102
185
  Example:
@@ -104,26 +187,54 @@ Template directives include:
104
187
  <ul><f-repeat value="{{item in list}}"><li>{{item}}</li></f-repeat></ul>
105
188
  ```
106
189
 
107
- - **partial & apply**
108
-
109
- These directives are new to the declarative HTML model and allow for the ability to declare a `partial` directive containing a template partial which can then be referenced by an `apply` directive.
190
+ Should you need to refer to the parent element (not the individual item in the list), you can use the context of a previous repeat, or no context which will resolve to the custom element.
110
191
 
111
192
  Example:
112
193
  ```html
113
- <f-partial id="test">
114
- <ul>
115
- <f-repeat value="{{item in items}}">
116
- <li>{{item.text}}<f-apply partial="test" value="{{item.items}}"></f-apply></li>
117
- </f-repeat>
118
- </ul>
119
- </f-partial>
120
- <f-apply partial="test" value="{{items}}"></f-apply>
194
+ <ul><f-repeat value="{{item in list}}"><li>{{item}} - {{title}}</li></f-repeat></ul>
121
195
  ```
122
196
 
197
+ #### Unescaped HTML
198
+
199
+ You can add unescaped HTML using triple braces, this will create an additional `div` element as the HTML needs an element to bind to. Where possible it is advisable to not use unescaped HTML and instead use other binding techniques.
200
+
201
+ Example:
202
+ ```html
203
+ {{{html}}}
204
+ ```
205
+
123
206
  ### Writing Components
124
207
 
125
208
  When writing components with the intention of using the declarative HTML syntax, it is imperative that components are written with styling and rendering of the component to be less reliant on any JavaScript state management. An example of this is relying on `elementInterals` state to style a component.
126
209
 
210
+ ### Converting Components
211
+
212
+ FAST Components written using the `html` tag template literal can be partially converted via the supplied `.yml` rules made for use with [ast-grep](https://ast-grep.github.io/).
213
+
214
+ Example:
215
+
216
+ ```ts
217
+ // before
218
+ export const template = html`
219
+ <slot ${slotted("slottedNodes")}></slot>
220
+ `;
221
+ // after
222
+ export const template = `
223
+ <slot f-slotted="{slottedNodes}"></slot>
224
+ `;
225
+ ```
226
+
227
+ Which creates a starting point for converting the tag template literals to the declarative HTML syntax.
228
+
229
+ If your template includes JavaScript specific logic that does not conform to those rules, the fix may not be applied or may apply incorrectly. It is therefore suggested that complex logic instead leverages the custom elements JavaScript class.
230
+
231
+ #### Available Rules
232
+
233
+ - `@microsoft/fast-html/rules/attribute-directive.yml`
234
+ - `@microsoft/fast-html/rules/call-expression-with-event-argument.yml`
235
+ - `@microsoft/fast-html/rules/member-expression.yml`
236
+ - `@microsoft/fast-html/rules/tag-function-to-template-literal.yml`
237
+
127
238
  ## Acknowledgements
128
239
 
129
- This project has been heavily inspired by [Handlebars](https://handlebarsjs.com/) and [Vue.js](https://vuejs.org/).
240
+ This project has been heavily inspired by [Handlebars](https://handlebarsjs.com/) and [Vue.js](https://vuejs.org/).
@@ -0,0 +1,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 +1,3 @@
1
1
  export { TemplateElement } from "./template.js";
2
+ export { RenderableFASTElement } from "./element.js";
3
+ export { ObserverMap } from "./observer-map.js";
@@ -0,0 +1,26 @@
1
+ import { Schema } from "./schema.js";
2
+ /**
3
+ * ObserverMap provides functionality for caching binding paths, extracting root properties,
4
+ * and defining observable properties on class prototypes
5
+ */
6
+ export declare class ObserverMap {
7
+ private schema;
8
+ private classPrototype;
9
+ constructor(classPrototype: any, schema: Schema);
10
+ defineProperties(): void;
11
+ /**
12
+ * Creates a proxy for an object that intercepts property mutations and triggers Observable notifications
13
+ * @param target - The target instance that owns the root property
14
+ * @param rootProperty - The name of the root property for notification purposes
15
+ * @param object - The object to wrap with a proxy
16
+ * @returns A proxy that triggers notifications on property mutations
17
+ */
18
+ private getAndAssignObservables;
19
+ /**
20
+ * Creates a property change handler function for observable properties
21
+ * This handler is called when an observable property transitions from undefined to a defined value
22
+ * @param propertyName - The name of the property for which to create the change handler
23
+ * @returns A function that handles property changes and sets up proxies for object values
24
+ */
25
+ private defineChanged;
26
+ }
@@ -0,0 +1,134 @@
1
+ type FastContextMetaData = "$fast_context";
2
+ type FastContextsMetaData = "$fast_parent_contexts";
3
+ export interface JSONSchemaDefinition extends JSONSchemaCommon {
4
+ $fast_context: string;
5
+ $fast_parent_contexts: Array<string>;
6
+ }
7
+ interface JSONSchemaCommon {
8
+ type?: string;
9
+ properties?: any;
10
+ items?: any;
11
+ }
12
+ export interface JSONSchema extends JSONSchemaCommon {
13
+ $schema: string;
14
+ $id: string;
15
+ $defs?: Record<string, JSONSchemaDefinition>;
16
+ $ref?: string;
17
+ }
18
+ interface CachedPathCommon {
19
+ parentContext: string | null;
20
+ currentContext: string | null;
21
+ path: string;
22
+ }
23
+ type AccessCachedPathType = "access";
24
+ export interface AccessCachedPath extends CachedPathCommon {
25
+ type: AccessCachedPathType;
26
+ }
27
+ type DefaultCachedPathType = "default";
28
+ export interface DefaultCachedPath extends CachedPathCommon {
29
+ type: DefaultCachedPathType;
30
+ }
31
+ type EventCachedPathType = "event";
32
+ export interface EventCachedPath extends CachedPathCommon {
33
+ type: EventCachedPathType;
34
+ }
35
+ type RepeatCachedPathType = "repeat";
36
+ export interface RepeatCachedPath extends CachedPathCommon {
37
+ type: RepeatCachedPathType;
38
+ }
39
+ export type CachedPath = DefaultCachedPath | RepeatCachedPath | AccessCachedPath | EventCachedPath;
40
+ export type CachedPathMap = Map<string, JSONSchema>;
41
+ interface RegisterPathConfig {
42
+ rootPropertyName: string;
43
+ pathConfig: CachedPath;
44
+ }
45
+ export declare const fastContextMetaData: FastContextMetaData;
46
+ export declare const fastContextsMetaData: FastContextsMetaData;
47
+ export declare const defsPropertyName = "$defs";
48
+ export declare const refPropertyName = "$ref";
49
+ /**
50
+ * A constructed JSON schema from a template
51
+ */
52
+ export declare class Schema {
53
+ /**
54
+ * The name of the custom element
55
+ */
56
+ private customElementName;
57
+ /**
58
+ * A JSON schema describing each root schema
59
+ */
60
+ private jsonSchemaMap;
61
+ constructor(name: string);
62
+ /**
63
+ * Add a path to a schema
64
+ * @param config RegisterPathConfig
65
+ */
66
+ addPath(config: RegisterPathConfig): void;
67
+ /**
68
+ * Gets the JSON schema for a property name
69
+ * @param rootPropertyName - the root property the JSON schema is mapped to
70
+ * @returns The JSON schema for the root property
71
+ */
72
+ getSchema(rootPropertyName: string): JSONSchema | null;
73
+ /**
74
+ * Gets root properties
75
+ * @returns IterableIterator<string>
76
+ */
77
+ getRootProperties(): IterableIterator<string>;
78
+ /**
79
+ * Get a path split into property names
80
+ * @param path The dot syntax path e.g. a.b.c
81
+ * @returns An array of items in the path
82
+ */
83
+ private getSplitPath;
84
+ /**
85
+ * Gets the path to the $def
86
+ * @param context The context name e.g. {{item in items}} in a repeat creates the "item" context
87
+ * @returns A string to use as a $ref
88
+ */
89
+ private getDefsPath;
90
+ /**
91
+ * Add a new JSON schema to the JSON schema map
92
+ * @param propertyName The name of the property to assign this JSON schema to
93
+ */
94
+ private addNewSchema;
95
+ /**
96
+ * Add properties to a context
97
+ * @param schema The schema to add the properties to
98
+ * @param splitPath The path split into property/context names
99
+ * @param context The paths context
100
+ */
101
+ private addPropertiesToAContext;
102
+ /**
103
+ * Add properties to an object
104
+ * @param schema The schema to add the properties to
105
+ * @param splitPath The path split into property/context names
106
+ * @param context The paths context
107
+ * @param type The data type (see JSON schema for details)
108
+ */
109
+ private addPropertiesToAnObject;
110
+ /**
111
+ * Add an array to an object property
112
+ * @param schema The schema to add the properties to
113
+ * @param context The name of the context
114
+ */
115
+ private addArrayToAnObject;
116
+ /**
117
+ * Add a context to the $defs property
118
+ * @param schema The schema to use
119
+ * @param propertyName The name of the property the context belongs to
120
+ * @param currentContext The current context
121
+ * @param parentContext The parent context
122
+ * @returns
123
+ */
124
+ private addContext;
125
+ /**
126
+ * Get parent contexts
127
+ * @param schema The schema to use
128
+ * @param parentContext The parent context
129
+ * @param contexts A list of parent contexts
130
+ * @returns
131
+ */
132
+ private getParentContexts;
133
+ }
134
+ export {};
@@ -1,4 +1,16 @@
1
- import { FASTElement } from "@microsoft/fast-element";
1
+ import { FASTElement, ShadowRootOptions } from "@microsoft/fast-element";
2
+ import "@microsoft/fast-element/install-hydratable-view-templates.js";
3
+ export type ObserverMapOption = "all";
4
+ export interface ElementOptions {
5
+ shadowOptions?: ShadowRootOptions | undefined;
6
+ observerMap?: ObserverMapOption | undefined;
7
+ }
8
+ /**
9
+ * A dictionary of element options the TemplateElement will use to update the registered element
10
+ */
11
+ export interface ElementOptionsDictionary<ElementOptionsType = ElementOptions> {
12
+ [key: string]: ElementOptionsType;
13
+ }
2
14
  /**
3
15
  * The <f-template> custom element that will provide view logic to the element
4
16
  */
@@ -7,12 +19,30 @@ declare class TemplateElement extends FASTElement {
7
19
  * The name of the custom element this template will be applied to
8
20
  */
9
21
  name?: string;
22
+ /**
23
+ * A dictionary of custom element options
24
+ */
25
+ static elementOptions: ElementOptionsDictionary;
10
26
  private partials;
27
+ /**
28
+ * ObserverMap instance for caching binding paths
29
+ */
30
+ private observerMap?;
31
+ private schema?;
32
+ private static defaultElementOptions;
33
+ static options(elementOptions?: ElementOptionsDictionary): typeof TemplateElement;
34
+ constructor();
35
+ /**
36
+ * Set options for a custom element
37
+ * @param name - The name of the custom element to set options for.
38
+ */
39
+ private static setOptions;
11
40
  connectedCallback(): void;
12
41
  /**
13
42
  * Resolve strings and values from an innerHTML string
14
43
  * @param innerHTML - The innerHTML.
15
44
  * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
45
+ * @param observerMap - ObserverMap instance for caching binding paths (optional).
16
46
  */
17
47
  private resolveStringsAndValues;
18
48
  /**
@@ -26,6 +56,8 @@ declare class TemplateElement extends FASTElement {
26
56
  * @param behaviorConfig - The directive behavior configuration object.
27
57
  * @param externalValues - The interpreted values from the parent.
28
58
  * @param innerHTML - The innerHTML.
59
+ * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
60
+ * @param observerMap - ObserverMap instance for caching binding paths (optional).
29
61
  */
30
62
  private resolveTemplateDirective;
31
63
  /**
@@ -42,6 +74,7 @@ declare class TemplateElement extends FASTElement {
42
74
  * @param values - The interpreted values.
43
75
  * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
44
76
  * @param behaviorConfig - The binding behavior configuration object.
77
+ * @param observerMap - ObserverMap instance for caching binding paths (optional).
45
78
  */
46
79
  private resolveDataBinding;
47
80
  /**
@@ -50,12 +83,8 @@ declare class TemplateElement extends FASTElement {
50
83
  * @param strings - The strings array.
51
84
  * @param values - The interpreted values.
52
85
  * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
86
+ * @param observerMap - ObserverMap instance for caching binding paths (optional).
53
87
  */
54
88
  private resolveInnerHTML;
55
- /**
56
- * Resolve all partial templates
57
- * @param unresolvedInnerHTML - The innerHTML.
58
- */
59
- private resolveAllPartials;
60
89
  }
61
90
  export { TemplateElement };
@@ -1,9 +1,12 @@
1
+ import { JSONSchema, JSONSchemaDefinition, Schema } from "./schema.js";
1
2
  type BehaviorType = "dataBinding" | "templateDirective";
2
- type TemplateDirective = "when" | "repeat" | "apply";
3
+ type TemplateDirective = "when" | "repeat";
3
4
  export type AttributeDirective = "children" | "slotted" | "ref";
5
+ type DataBindingBindingType = "client" | "default" | "unescaped";
4
6
  interface BehaviorConfig {
5
7
  type: BehaviorType;
6
8
  }
9
+ export type PathType = "access" | "default" | "event" | "repeat";
7
10
  export interface ContentDataBindingBehaviorConfig extends BaseDataBindingBehaviorConfig {
8
11
  subtype: "content";
9
12
  }
@@ -18,6 +21,7 @@ export interface AttributeDirectiveBindingBehaviorConfig extends BaseDataBinding
18
21
  export type DataBindingBehaviorConfig = ContentDataBindingBehaviorConfig | AttributeDataBindingBehaviorConfig | AttributeDirectiveBindingBehaviorConfig;
19
22
  export interface BaseDataBindingBehaviorConfig extends BehaviorConfig {
20
23
  type: "dataBinding";
24
+ bindingType: DataBindingBindingType;
21
25
  openingStartIndex: number;
22
26
  openingEndIndex: number;
23
27
  closingStartIndex: number;
@@ -32,11 +36,6 @@ export interface TemplateDirectiveBehaviorConfig extends BehaviorConfig {
32
36
  closingTagStartIndex: number;
33
37
  closingTagEndIndex: number;
34
38
  }
35
- interface PartialTemplateConfig {
36
- innerHTML: string;
37
- startIndex: number;
38
- endIndex: number;
39
- }
40
39
  /**
41
40
  * Get the index of the next matching tag
42
41
  * @param openingTagStartSlice - The slice starting from the opening tag
@@ -52,18 +51,6 @@ export declare function getIndexOfNextMatchingTag(openingTagStartSlice: string,
52
51
  * @returns DataBindingBehaviorConfig | DirectiveBehaviorConfig | null - A configuration object or null
53
52
  */
54
53
  export declare function getNextBehavior(innerHTML: string): DataBindingBehaviorConfig | TemplateDirectiveBehaviorConfig | null;
55
- /**
56
- * Gets all the partials with their IDs
57
- * @param innerHTML - The innerHTML string to evaluate
58
- * @param offset - The index offset from the innerHTML
59
- * @param partials - The partials found
60
- * @returns {[key: string]: PartialTemplateConfig}
61
- */
62
- export declare function getAllPartials(innerHTML: string, offset?: number, partials?: {
63
- [key: string]: PartialTemplateConfig;
64
- }): {
65
- [key: string]: PartialTemplateConfig;
66
- };
67
54
  /**
68
55
  * Create a function to resolve a value from an object using a path with dot syntax.
69
56
  * e.g. "foo.bar"
@@ -71,5 +58,91 @@ export declare function getAllPartials(innerHTML: string, offset?: number, parti
71
58
  * @param self - Where the first item in the path path refers to the item itself (used by repeat).
72
59
  * @returns A function to access the value from a given path.
73
60
  */
74
- export declare function pathResolver(path: string, self?: boolean): (accessibleObject: any) => any;
61
+ export declare function pathResolver(path: string, contextPath: string | null, level: number, rootSchema: JSONSchema): (accessibleObject: any, context: any) => any;
62
+ export declare function bindingResolver(rootPropertyName: string | null, path: string, parentContext: string | null, type: PathType, schema: Schema, currentContext: string | null, level: number): (accessibleObject: any, context: any) => any;
63
+ export declare function expressionResolver(rootPropertyName: string | null, expression: ChainedExpression, parentContext: string | null, level: number, schema: Schema): (accessibleObject: any, context: any) => any;
64
+ /**
65
+ * Extracts all paths from a ChainedExpression, including nested expressions
66
+ * @param chainedExpression - The chained expression to extract paths from
67
+ * @returns A Set containing all unique paths found in the expression chain
68
+ */
69
+ export declare function extractPathsFromChainedExpression(chainedExpression: ChainedExpression): Set<string>;
70
+ /**
71
+ * Available operators include:
72
+ *
73
+ * - access (no operator)
74
+ * - not (!)
75
+ * - equals (==)
76
+ * - not equal (!=)
77
+ * - greater than or equal (>=)
78
+ * - greater than (>)
79
+ * - less than or equal (<=)
80
+ * - less than (<)
81
+ * - or (||)
82
+ * - and (&&) and the HTML character entity (&amp;&amp;)
83
+ */
84
+ type Operator = "access" | "!" | "==" | "!=" | ">=" | ">" | "<=" | "<";
85
+ type ChainingOperator = "||" | "&&" | "&amp;&amp;";
86
+ interface Expression {
87
+ operator: Operator;
88
+ left: string;
89
+ leftIsValue: boolean | null;
90
+ right: string | boolean | number | null;
91
+ rightIsValue: boolean | null;
92
+ }
93
+ export interface ChainedExpression {
94
+ operator?: ChainingOperator;
95
+ expression: Expression;
96
+ next?: ChainedExpression;
97
+ }
98
+ /**
99
+ * Gets the expression chain as a configuration object
100
+ * @param value - The binding string value
101
+ * @returns - A configuration object containing information about the expression
102
+ */
103
+ export declare function getExpressionChain(value: string): ChainedExpression | void;
104
+ /**
105
+ * This is the transform utility for rationalizing declarative HTML syntax
106
+ * with bindings in the ViewTemplate
107
+ * @param innerHTML The innerHTML to transform
108
+ * @param index The index to start the current slice of HTML to evaluate
109
+ */
110
+ export declare function transformInnerHTML(innerHTML: string, index?: number): string;
111
+ /**
112
+ * Resolves f-when
113
+ * @param self - Where the first item in the path path refers to the item itself (used by repeat).
114
+ * @param chainedExpression - The chained expression which includes the expression and the next expression
115
+ * if there is another in the chain
116
+ * @returns - A binding that resolves the chained expression logic
117
+ */
118
+ export declare function resolveWhen(rootPropertyName: string | null, expression: ChainedExpression, parentContext: string | null, level: number, schema: Schema): (x: boolean, c: any) => any;
119
+ /**
120
+ * Assign observables to data
121
+ * @param schema - The schema
122
+ * @param rootSchema - The root schema mapping to the root property
123
+ * @param data - The data
124
+ * @param target - The target custom element
125
+ * @param rootProperty - The root property
126
+ * @returns
127
+ */
128
+ export declare function assignObservables(schema: JSONSchema | JSONSchemaDefinition, rootSchema: JSONSchema, data: any, target: any, rootProperty: string): typeof Proxy;
129
+ /**
130
+ * Assign a proxy to an object
131
+ * @param schema - The current schema
132
+ * @param rootSchema - The root schema for the root property
133
+ * @param target - The target custom element
134
+ * @param rootProperty - The root property
135
+ * @param object - The object to assign the proxy to
136
+ * @returns Proxy object
137
+ */
138
+ export declare function assignProxy(schema: JSONSchema | JSONSchemaDefinition, rootSchema: JSONSchema, target: any, rootProperty: string, object: any): typeof Proxy;
139
+ /**
140
+ * Get the root property name
141
+ * @param rootPropertyName - The root property
142
+ * @param path - The dot syntax path
143
+ * @param context - The context created by a repeat
144
+ * @param type - The type of path binding
145
+ * @returns
146
+ */
147
+ export declare function getRootPropertyName(rootPropertyName: string | null, path: string, context: null | string, type: PathType): string | null;
75
148
  export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1 @@
1
- export { TemplateElement } from "./components/index.js";
1
+ export { RenderableFASTElement, TemplateElement, ObserverMap, } from "./components/index.js";
@@ -0,0 +1,27 @@
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 {
21
+ this.deferHydration = false;
22
+ }
23
+ }
24
+ };
25
+ attr({ mode: "boolean", attribute: "defer-hydration" })(C.prototype, "deferHydration");
26
+ return C;
27
+ }
@@ -1 +1,3 @@
1
1
  export { TemplateElement } from "./template.js";
2
+ export { RenderableFASTElement } from "./element.js";
3
+ export { ObserverMap } from "./observer-map.js";