@microsoft/fast-html 1.0.0-alpha.2 → 1.0.0-alpha.21

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 +111 -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 +39 -5
  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 +154 -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 +219 -5
  43. package/dist/fast-html.untrimmed.d.ts +219 -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,39 @@ 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
+ #### Using the RenderableFASTElement
59
+
60
+ 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.
61
+
62
+ Example:
63
+ ```typescript
64
+ class MyCustomElement extends FASTElement {
65
+ private prepare(): Promise<void> {
66
+ // Get initial state
67
+ }
68
+ }
69
+
70
+ RenderableFASTElement(MyCustomElement).defineAsync({
71
+ name: "my-custom-element",
72
+ templateOptions: "defer-and-hydrate",
73
+ });
74
+ ```
75
+
48
76
  ### Syntax
49
77
 
50
- All bindings use a handlebars syntax.
78
+ All bindings use a handlebars-like syntax.
79
+
80
+ 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.
81
+
82
+ 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.
83
+
84
+ Browser-only bindings:
85
+ - Event bindings
86
+ - Attribute directives
51
87
 
52
88
  #### Content binding
53
89
 
@@ -60,33 +96,49 @@ All bindings use a handlebars syntax.
60
96
  Event bindings must include the `()` as well as being preceeded by `@` in keeping with `@microsoft/fast-element` tagged template `html` syntax.
61
97
 
62
98
  ```html
63
- <button @click="{{handleClick()}}"></button>
99
+ <button @click="{handleClick()}"></button>
100
+ ```
101
+
102
+ In addition you may include an event or attribute or observable, events are denoted with `e` as a reserved letter.
103
+
104
+ Event:
105
+ ```html
106
+ <button @click="{handleClick(e)}"></button>
107
+ ```
108
+
109
+ Attribute/Observable:
110
+ ```html
111
+ <button @click="{handleClick(foo)}"></button>
64
112
  ```
65
113
 
66
114
  #### Directives
67
115
 
68
116
  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
117
 
118
+ Attribute directives are part of [client side binding](#syntax) and therefore use the `{}` syntax.
119
+
70
120
  Attribute directives include:
71
121
  - **slotted**
72
122
 
73
123
  Example:
74
124
  ```html
75
- <slot f-slotted="{{slottedNodes}}"></slot>
125
+ <slot f-slotted="{slottedNodes}"></slot>
126
+ <slot f-slotted="{slottedNodes filter elements()}"></slot>
127
+ <slot f-slotted="{slottedNodes filter elements(div, p)}"></slot>
76
128
  ```
77
129
 
78
130
  - **children**
79
131
 
80
132
  Example:
81
133
  ```html
82
- <ul f-children="{{listItems}}"><f-repeat value="{{item in list}}"><li>{{item}}</li></f-repeat></ul>
134
+ <ul f-children="{listItems}"><f-repeat value="{{item in list}}"><li>{{item}}</li></f-repeat></ul>
83
135
  ```
84
136
 
85
137
  - **ref**
86
138
 
87
139
  Example:
88
140
  ```html
89
- <video f-ref="{{video}}"></video>
141
+ <video f-ref="{video}"></video>
90
142
  ```
91
143
 
92
144
  Template directives include:
@@ -95,8 +147,21 @@ Template directives include:
95
147
  Example:
96
148
  ```html
97
149
  <f-when value="{{show}}">Hello world</f-when>
150
+ <f-when value="{{!show}}">Goodbye world</f-when>
98
151
  ```
99
152
 
153
+ The following operators can also be used:
154
+ - `==`
155
+ - `!=`
156
+ - `>=`
157
+ - `>`
158
+ - `<=`
159
+ - `<`
160
+ - `||`
161
+ - `&&`
162
+
163
+ 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.
164
+
100
165
  - **repeat**
101
166
 
102
167
  Example:
@@ -104,26 +169,54 @@ Template directives include:
104
169
  <ul><f-repeat value="{{item in list}}"><li>{{item}}</li></f-repeat></ul>
105
170
  ```
106
171
 
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.
172
+ 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
173
 
111
174
  Example:
112
175
  ```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>
176
+ <ul><f-repeat value="{{item in list}}"><li>{{item}} - {{title}}</li></f-repeat></ul>
121
177
  ```
122
178
 
179
+ #### Unescaped HTML
180
+
181
+ 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.
182
+
183
+ Example:
184
+ ```html
185
+ {{{html}}}
186
+ ```
187
+
123
188
  ### Writing Components
124
189
 
125
190
  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
191
 
192
+ ### Converting Components
193
+
194
+ 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/).
195
+
196
+ Example:
197
+
198
+ ```ts
199
+ // before
200
+ export const template = html`
201
+ <slot ${slotted("slottedNodes")}></slot>
202
+ `;
203
+ // after
204
+ export const template = `
205
+ <slot f-slotted="{slottedNodes}"></slot>
206
+ `;
207
+ ```
208
+
209
+ Which creates a starting point for converting the tag template literals to the declarative HTML syntax.
210
+
211
+ 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.
212
+
213
+ #### Available Rules
214
+
215
+ - `@microsoft/fast-html/rules/attribute-directive.yml`
216
+ - `@microsoft/fast-html/rules/call-expression-with-event-argument.yml`
217
+ - `@microsoft/fast-html/rules/member-expression.yml`
218
+ - `@microsoft/fast-html/rules/tag-function-to-template-literal.yml`
219
+
127
220
  ## Acknowledgements
128
221
 
129
- This project has been heavily inspired by [Handlebars](https://handlebarsjs.com/) and [Vue.js](https://vuejs.org/).
222
+ 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,15 @@
1
1
  import { FASTElement } from "@microsoft/fast-element";
2
+ import "@microsoft/fast-element/install-hydratable-view-templates.js";
3
+ export type ObserverMapOption = "all";
4
+ export interface ElementOptions {
5
+ observerMap?: ObserverMapOption | undefined;
6
+ }
7
+ /**
8
+ * A dictionary of element options the TemplateElement will use to update the registered element
9
+ */
10
+ export interface ElementOptionsDictionary<ElementOptionsType = ElementOptions> {
11
+ [key: string]: ElementOptionsType;
12
+ }
2
13
  /**
3
14
  * The <f-template> custom element that will provide view logic to the element
4
15
  */
@@ -7,12 +18,36 @@ declare class TemplateElement extends FASTElement {
7
18
  * The name of the custom element this template will be applied to
8
19
  */
9
20
  name?: string;
21
+ /**
22
+ * A dictionary of custom element options
23
+ */
24
+ static elementOptions: ElementOptionsDictionary;
10
25
  private partials;
26
+ /**
27
+ * ObserverMap instance for caching binding paths
28
+ */
29
+ private observerMap?;
30
+ /**
31
+ * Default element options
32
+ */
33
+ private static defaultElementOptions;
34
+ /**
35
+ * Metadata containing JSON schema for properties on a custom eleemnt
36
+ */
37
+ private schema?;
38
+ static options(elementOptions?: ElementOptionsDictionary): typeof TemplateElement;
39
+ constructor();
40
+ /**
41
+ * Set options for a custom element
42
+ * @param name - The name of the custom element to set options for.
43
+ */
44
+ private static setOptions;
11
45
  connectedCallback(): void;
12
46
  /**
13
47
  * Resolve strings and values from an innerHTML string
14
48
  * @param innerHTML - The innerHTML.
15
49
  * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
50
+ * @param observerMap - ObserverMap instance for caching binding paths (optional).
16
51
  */
17
52
  private resolveStringsAndValues;
18
53
  /**
@@ -26,6 +61,8 @@ declare class TemplateElement extends FASTElement {
26
61
  * @param behaviorConfig - The directive behavior configuration object.
27
62
  * @param externalValues - The interpreted values from the parent.
28
63
  * @param innerHTML - The innerHTML.
64
+ * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
65
+ * @param observerMap - ObserverMap instance for caching binding paths (optional).
29
66
  */
30
67
  private resolveTemplateDirective;
31
68
  /**
@@ -42,6 +79,7 @@ declare class TemplateElement extends FASTElement {
42
79
  * @param values - The interpreted values.
43
80
  * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
44
81
  * @param behaviorConfig - The binding behavior configuration object.
82
+ * @param observerMap - ObserverMap instance for caching binding paths (optional).
45
83
  */
46
84
  private resolveDataBinding;
47
85
  /**
@@ -50,12 +88,8 @@ declare class TemplateElement extends FASTElement {
50
88
  * @param strings - The strings array.
51
89
  * @param values - The interpreted values.
52
90
  * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
91
+ * @param observerMap - ObserverMap instance for caching binding paths (optional).
53
92
  */
54
93
  private resolveInnerHTML;
55
- /**
56
- * Resolve all partial templates
57
- * @param unresolvedInnerHTML - The innerHTML.
58
- */
59
- private resolveAllPartials;
60
94
  }
61
95
  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";