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

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 (64) hide show
  1. package/dist/dts/components/index.d.ts +1 -0
  2. package/dist/dts/components/template.d.ts +61 -0
  3. package/dist/dts/components/utilities.d.ts +75 -0
  4. package/dist/dts/components/utilities.spec.d.ts +1 -0
  5. package/dist/dts/debug.d.ts +3 -0
  6. package/dist/dts/fixtures/attribute/attribute.spec.d.ts +1 -0
  7. package/dist/dts/fixtures/attribute/main.d.ts +1 -0
  8. package/dist/dts/fixtures/binding/binding.spec.d.ts +1 -0
  9. package/dist/dts/fixtures/binding/main.d.ts +1 -0
  10. package/dist/dts/fixtures/children/children.spec.d.ts +1 -0
  11. package/dist/dts/fixtures/children/main.d.ts +1 -0
  12. package/dist/dts/fixtures/dot-syntax/dot-syntax.spec.d.ts +1 -0
  13. package/dist/dts/fixtures/dot-syntax/main.d.ts +1 -0
  14. package/dist/dts/fixtures/event/event.spec.d.ts +1 -0
  15. package/dist/dts/fixtures/event/main.d.ts +1 -0
  16. package/dist/dts/fixtures/partial/main.d.ts +1 -0
  17. package/dist/dts/fixtures/partial/partial.spec.d.ts +1 -0
  18. package/dist/dts/fixtures/ref/main.d.ts +1 -0
  19. package/dist/dts/fixtures/ref/ref.spec.d.ts +1 -0
  20. package/dist/dts/fixtures/repeat/main.d.ts +1 -0
  21. package/dist/dts/fixtures/repeat/repeat.spec.d.ts +1 -0
  22. package/dist/dts/fixtures/slotted/main.d.ts +1 -0
  23. package/dist/dts/fixtures/slotted/slotted.spec.d.ts +1 -0
  24. package/dist/dts/fixtures/when/main.d.ts +1 -0
  25. package/dist/dts/fixtures/when/when.spec.d.ts +1 -0
  26. package/dist/dts/index.d.ts +1 -0
  27. package/dist/dts/interfaces.d.ts +7 -0
  28. package/dist/dts/tsdoc-metadata.json +11 -0
  29. package/dist/esm/components/index.js +1 -0
  30. package/dist/esm/components/template.js +223 -0
  31. package/dist/esm/components/utilities.js +229 -0
  32. package/dist/esm/components/utilities.spec.js +160 -0
  33. package/dist/esm/debug.js +3 -0
  34. package/dist/esm/fixtures/attribute/attribute.spec.js +23 -0
  35. package/dist/esm/fixtures/attribute/main.js +19 -0
  36. package/dist/esm/fixtures/binding/binding.spec.js +17 -0
  37. package/dist/esm/fixtures/binding/main.js +19 -0
  38. package/dist/esm/fixtures/children/children.spec.js +33 -0
  39. package/dist/esm/fixtures/children/main.js +24 -0
  40. package/dist/esm/fixtures/dot-syntax/dot-syntax.spec.js +9 -0
  41. package/dist/esm/fixtures/dot-syntax/main.js +16 -0
  42. package/dist/esm/fixtures/event/event.spec.js +12 -0
  43. package/dist/esm/fixtures/event/main.js +16 -0
  44. package/dist/esm/fixtures/partial/main.js +31 -0
  45. package/dist/esm/fixtures/partial/partial.spec.js +14 -0
  46. package/dist/esm/fixtures/ref/main.js +14 -0
  47. package/dist/esm/fixtures/ref/ref.spec.js +13 -0
  48. package/dist/esm/fixtures/repeat/main.js +19 -0
  49. package/dist/esm/fixtures/repeat/repeat.spec.js +26 -0
  50. package/dist/esm/fixtures/slotted/main.js +22 -0
  51. package/dist/esm/fixtures/slotted/slotted.spec.js +25 -0
  52. package/dist/esm/fixtures/when/main.js +19 -0
  53. package/dist/esm/fixtures/when/when.spec.js +19 -0
  54. package/dist/esm/index.js +4 -0
  55. package/dist/esm/interfaces.js +1 -0
  56. package/dist/esm/tsconfig.tsbuildinfo +1 -0
  57. package/dist/fast-html.api.json +271 -0
  58. package/dist/fast-html.d.ts +63 -0
  59. package/dist/fast-html.untrimmed.d.ts +63 -0
  60. package/package.json +4 -1
  61. package/CHANGELOG.json +0 -26
  62. package/CHANGELOG.md +0 -14
  63. package/docs/api-report.api.md +0 -18
  64. package/webpack.common.config.js +0 -18
@@ -0,0 +1 @@
1
+ export { TemplateElement } from "./template.js";
@@ -0,0 +1,61 @@
1
+ import { FASTElement } from "@microsoft/fast-element";
2
+ /**
3
+ * The <f-template> custom element that will provide view logic to the element
4
+ */
5
+ declare class TemplateElement extends FASTElement {
6
+ /**
7
+ * The name of the custom element this template will be applied to
8
+ */
9
+ name?: string;
10
+ private partials;
11
+ connectedCallback(): void;
12
+ /**
13
+ * Resolve strings and values from an innerHTML string
14
+ * @param innerHTML - The innerHTML.
15
+ * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
16
+ */
17
+ private resolveStringsAndValues;
18
+ /**
19
+ * Resolve a template or behavior
20
+ * @param strings - The strings array.
21
+ * @param values - The interpreted values.
22
+ */
23
+ private resolveTemplateOrBehavior;
24
+ /**
25
+ * Resolve a template directive
26
+ * @param behaviorConfig - The directive behavior configuration object.
27
+ * @param externalValues - The interpreted values from the parent.
28
+ * @param innerHTML - The innerHTML.
29
+ */
30
+ private resolveTemplateDirective;
31
+ /**
32
+ * Resolve a template directive
33
+ * @param name - The name of the directive.
34
+ * @param propName - The property name to pass to the directive.
35
+ * @param externalValues - The interpreted values from the parent.
36
+ */
37
+ private resolveAttributeDirective;
38
+ /**
39
+ * Resolver of a data binding
40
+ * @param innerHTML - The innerHTML.
41
+ * @param strings - The strings array.
42
+ * @param values - The interpreted values.
43
+ * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
44
+ * @param behaviorConfig - The binding behavior configuration object.
45
+ */
46
+ private resolveDataBinding;
47
+ /**
48
+ * Resolver of the innerHTML string
49
+ * @param innerHTML - The innerHTML.
50
+ * @param strings - The strings array.
51
+ * @param values - The interpreted values.
52
+ * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
53
+ */
54
+ private resolveInnerHTML;
55
+ /**
56
+ * Resolve all partial templates
57
+ * @param unresolvedInnerHTML - The innerHTML.
58
+ */
59
+ private resolveAllPartials;
60
+ }
61
+ export { TemplateElement };
@@ -0,0 +1,75 @@
1
+ type BehaviorType = "dataBinding" | "templateDirective";
2
+ type TemplateDirective = "when" | "repeat" | "apply";
3
+ export type AttributeDirective = "children" | "slotted" | "ref";
4
+ interface BehaviorConfig {
5
+ type: BehaviorType;
6
+ }
7
+ export interface ContentDataBindingBehaviorConfig extends BaseDataBindingBehaviorConfig {
8
+ subtype: "content";
9
+ }
10
+ export interface AttributeDataBindingBehaviorConfig extends BaseDataBindingBehaviorConfig {
11
+ subtype: "attribute";
12
+ aspect: "@" | ":" | "?" | null;
13
+ }
14
+ export interface AttributeDirectiveBindingBehaviorConfig extends BaseDataBindingBehaviorConfig {
15
+ subtype: "attributeDirective";
16
+ name: AttributeDirective;
17
+ }
18
+ export type DataBindingBehaviorConfig = ContentDataBindingBehaviorConfig | AttributeDataBindingBehaviorConfig | AttributeDirectiveBindingBehaviorConfig;
19
+ export interface BaseDataBindingBehaviorConfig extends BehaviorConfig {
20
+ type: "dataBinding";
21
+ openingStartIndex: number;
22
+ openingEndIndex: number;
23
+ closingStartIndex: number;
24
+ closingEndIndex: number;
25
+ }
26
+ export interface TemplateDirectiveBehaviorConfig extends BehaviorConfig {
27
+ type: "templateDirective";
28
+ name: TemplateDirective;
29
+ value: string;
30
+ openingTagStartIndex: number;
31
+ openingTagEndIndex: number;
32
+ closingTagStartIndex: number;
33
+ closingTagEndIndex: number;
34
+ }
35
+ interface PartialTemplateConfig {
36
+ innerHTML: string;
37
+ startIndex: number;
38
+ endIndex: number;
39
+ }
40
+ /**
41
+ * Get the index of the next matching tag
42
+ * @param openingTagStartSlice - The slice starting from the opening tag
43
+ * @param openingTag - The opening tag string
44
+ * @param closingTag - The closing tag
45
+ * @param openingTagStartIndex - The opening tag start index derived from the innerHTML
46
+ * @returns index
47
+ */
48
+ export declare function getIndexOfNextMatchingTag(openingTagStartSlice: string, openingTag: string, closingTag: string, openingTagStartIndex: number): number;
49
+ /**
50
+ * Get the next behavior
51
+ * @param innerHTML - The innerHTML string to evaluate
52
+ * @returns DataBindingBehaviorConfig | DirectiveBehaviorConfig | null - A configuration object or null
53
+ */
54
+ 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
+ /**
68
+ * Create a function to resolve a value from an object using a path with dot syntax.
69
+ * e.g. "foo.bar"
70
+ * @param path - The dot syntax path to an objects property.
71
+ * @param self - Where the first item in the path path refers to the item itself (used by repeat).
72
+ * @returns A function to access the value from a given path.
73
+ */
74
+ export declare function pathResolver(path: string, self?: boolean): (accessibleObject: any) => any;
75
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare const debugMessages: {
2
+ 2000: string;
3
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export { TemplateElement } from "./components/index.js";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Warning and error messages.
3
+ * @internal
4
+ */
5
+ export declare const enum Message {
6
+ noTemplateProvided = 2000
7
+ }
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.47.0"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1 @@
1
+ export { TemplateElement } from "./template.js";
@@ -0,0 +1,223 @@
1
+ import { __awaiter, __decorate, __metadata } from "tslib";
2
+ import { attr, FAST, FASTElement, fastElementRegistry, ViewTemplate, } from "@microsoft/fast-element";
3
+ import { DOMPolicy } from "@microsoft/fast-element/dom-policy.js";
4
+ import { getAllPartials, getNextBehavior, pathResolver, } from "./utilities.js";
5
+ /**
6
+ * The <f-template> custom element that will provide view logic to the element
7
+ */
8
+ class TemplateElement extends FASTElement {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.partials = {};
12
+ }
13
+ connectedCallback() {
14
+ super.connectedCallback();
15
+ if (this.name) {
16
+ this.$fastController.definition.registry
17
+ .whenDefined(this.name)
18
+ .then((value) => __awaiter(this, void 0, void 0, function* () {
19
+ const registeredFastElement = fastElementRegistry.getByType(value);
20
+ const template = this.getElementsByTagName("template").item(0);
21
+ if (template) {
22
+ yield this.resolveAllPartials(this.innerHTML);
23
+ const { strings, values } = yield this.resolveStringsAndValues(this.innerHTML);
24
+ if (registeredFastElement) {
25
+ // all new elements will get the updated template
26
+ registeredFastElement.template =
27
+ this.resolveTemplateOrBehavior(strings, values);
28
+ }
29
+ }
30
+ else {
31
+ throw FAST.error(2000 /* Message.noTemplateProvided */, { name: this.name });
32
+ }
33
+ }));
34
+ }
35
+ }
36
+ /**
37
+ * Resolve strings and values from an innerHTML string
38
+ * @param innerHTML - The innerHTML.
39
+ * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
40
+ */
41
+ resolveStringsAndValues(innerHTML, self = false) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ const strings = [];
44
+ const values = []; // these can be bindings, directives, etc.
45
+ yield this.resolveInnerHTML(innerHTML, strings, values, self);
46
+ strings.raw = strings.map(value => String.raw({ raw: value }));
47
+ return {
48
+ strings,
49
+ values,
50
+ };
51
+ });
52
+ }
53
+ /**
54
+ * Resolve a template or behavior
55
+ * @param strings - The strings array.
56
+ * @param values - The interpreted values.
57
+ */
58
+ resolveTemplateOrBehavior(strings, values) {
59
+ return ViewTemplate.create(strings, values, DOMPolicy.create());
60
+ }
61
+ /**
62
+ * Resolve a template directive
63
+ * @param behaviorConfig - The directive behavior configuration object.
64
+ * @param externalValues - The interpreted values from the parent.
65
+ * @param innerHTML - The innerHTML.
66
+ */
67
+ resolveTemplateDirective(behaviorConfig, externalValues, innerHTML, self = false) {
68
+ var _a;
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ switch (behaviorConfig.name) {
71
+ case "when":
72
+ {
73
+ const { strings, values } = yield this.resolveStringsAndValues(innerHTML.slice(behaviorConfig.openingTagEndIndex, behaviorConfig.closingTagStartIndex));
74
+ const { when } = yield import("@microsoft/fast-element");
75
+ externalValues.push(when(x => pathResolver(behaviorConfig.value, self)(x), this.resolveTemplateOrBehavior(strings, values)));
76
+ }
77
+ break;
78
+ case "repeat":
79
+ {
80
+ const valueAttr = behaviorConfig.value.split(" "); // syntax {{x in y}}
81
+ const { strings, values } = yield this.resolveStringsAndValues(innerHTML.slice(behaviorConfig.openingTagEndIndex, behaviorConfig.closingTagStartIndex), true);
82
+ const { repeat } = yield import("@microsoft/fast-element");
83
+ externalValues.push(repeat(x => pathResolver(valueAttr[2], self)(x), this.resolveTemplateOrBehavior(strings, values)));
84
+ }
85
+ break;
86
+ case "apply": {
87
+ const openingTag = innerHTML.slice(behaviorConfig.openingTagStartIndex, behaviorConfig.openingTagEndIndex);
88
+ const partial = (_a = openingTag
89
+ .split(" ")
90
+ .find(tagPart => {
91
+ return tagPart.startsWith("partial");
92
+ })) === null || _a === void 0 ? void 0 : _a.split('"')[1];
93
+ if (partial) {
94
+ const { when } = yield import("@microsoft/fast-element");
95
+ externalValues.push(when(x => pathResolver(behaviorConfig.value, self)(x), () => this.partials[partial]));
96
+ }
97
+ }
98
+ }
99
+ });
100
+ }
101
+ /**
102
+ * Resolve a template directive
103
+ * @param name - The name of the directive.
104
+ * @param propName - The property name to pass to the directive.
105
+ * @param externalValues - The interpreted values from the parent.
106
+ */
107
+ resolveAttributeDirective(name, propName, externalValues) {
108
+ return __awaiter(this, void 0, void 0, function* () {
109
+ switch (name) {
110
+ case "children":
111
+ {
112
+ const { children } = yield import("@microsoft/fast-element");
113
+ externalValues.push(children(propName));
114
+ }
115
+ break;
116
+ case "slotted":
117
+ {
118
+ const { slotted } = yield import("@microsoft/fast-element");
119
+ externalValues.push(slotted(propName));
120
+ }
121
+ break;
122
+ case "ref":
123
+ {
124
+ const { ref } = yield import("@microsoft/fast-element");
125
+ externalValues.push(ref(propName));
126
+ }
127
+ break;
128
+ }
129
+ });
130
+ }
131
+ /**
132
+ * Resolver of a data binding
133
+ * @param innerHTML - The innerHTML.
134
+ * @param strings - The strings array.
135
+ * @param values - The interpreted values.
136
+ * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
137
+ * @param behaviorConfig - The binding behavior configuration object.
138
+ */
139
+ resolveDataBinding(innerHTML, strings, values, self = false, behaviorConfig) {
140
+ return __awaiter(this, void 0, void 0, function* () {
141
+ switch (behaviorConfig.subtype) {
142
+ case "content":
143
+ {
144
+ strings.push(innerHTML.slice(0, behaviorConfig.openingStartIndex));
145
+ const propName = innerHTML.slice(behaviorConfig.openingEndIndex, behaviorConfig.closingStartIndex);
146
+ const binding = (x) => pathResolver(propName, self)(x);
147
+ values.push(binding);
148
+ yield this.resolveInnerHTML(innerHTML.slice(behaviorConfig.closingEndIndex, innerHTML.length), strings, values, self);
149
+ }
150
+ break;
151
+ case "attribute":
152
+ strings.push(innerHTML.slice(0, behaviorConfig.openingStartIndex));
153
+ if (behaviorConfig.aspect === "@") {
154
+ const propName = innerHTML.slice(behaviorConfig.openingEndIndex, behaviorConfig.closingStartIndex - 2);
155
+ const binding = (x) => pathResolver(propName, self)(x)();
156
+ values.push(binding);
157
+ }
158
+ else {
159
+ const propName = innerHTML.slice(behaviorConfig.openingEndIndex, behaviorConfig.closingStartIndex);
160
+ const binding = (x) => pathResolver(propName, self)(x);
161
+ values.push(binding);
162
+ }
163
+ yield this.resolveInnerHTML(innerHTML.slice(behaviorConfig.closingEndIndex, innerHTML.length), strings, values, self);
164
+ break;
165
+ case "attributeDirective":
166
+ {
167
+ strings.push(innerHTML.slice(0, behaviorConfig.openingStartIndex -
168
+ behaviorConfig.name.length -
169
+ 4));
170
+ const propName = innerHTML.slice(behaviorConfig.openingEndIndex, behaviorConfig.closingStartIndex);
171
+ yield this.resolveAttributeDirective(behaviorConfig.name, propName, values);
172
+ yield this.resolveInnerHTML(innerHTML.slice(behaviorConfig.closingEndIndex + 1, innerHTML.length), strings, values, self);
173
+ }
174
+ break;
175
+ }
176
+ });
177
+ }
178
+ /**
179
+ * Resolver of the innerHTML string
180
+ * @param innerHTML - The innerHTML.
181
+ * @param strings - The strings array.
182
+ * @param values - The interpreted values.
183
+ * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
184
+ */
185
+ resolveInnerHTML(innerHTML, strings, values, self = false) {
186
+ return __awaiter(this, void 0, void 0, function* () {
187
+ const behaviorConfig = getNextBehavior(innerHTML);
188
+ if (behaviorConfig === null) {
189
+ strings.push(innerHTML);
190
+ }
191
+ else {
192
+ switch (behaviorConfig.type) {
193
+ case "dataBinding":
194
+ yield this.resolveDataBinding(innerHTML, strings, values, self, behaviorConfig);
195
+ break;
196
+ case "templateDirective":
197
+ strings.push(innerHTML.slice(0, behaviorConfig.openingTagStartIndex));
198
+ yield this.resolveTemplateDirective(behaviorConfig, values, innerHTML, self);
199
+ yield this.resolveInnerHTML(innerHTML.slice(behaviorConfig.closingTagEndIndex, innerHTML.length), strings, values, self);
200
+ break;
201
+ }
202
+ }
203
+ });
204
+ }
205
+ /**
206
+ * Resolve all partial templates
207
+ * @param unresolvedInnerHTML - The innerHTML.
208
+ */
209
+ resolveAllPartials(unresolvedInnerHTML) {
210
+ return __awaiter(this, void 0, void 0, function* () {
211
+ const allPartials = Object.entries(getAllPartials(unresolvedInnerHTML));
212
+ for (let i = 0, partialLength = allPartials.length; i < partialLength; i++) {
213
+ const { strings, values } = yield this.resolveStringsAndValues(allPartials[i][1].innerHTML);
214
+ this.partials[allPartials[i][0]] = this.resolveTemplateOrBehavior(strings, values);
215
+ }
216
+ });
217
+ }
218
+ }
219
+ __decorate([
220
+ attr,
221
+ __metadata("design:type", String)
222
+ ], TemplateElement.prototype, "name", void 0);
223
+ export { TemplateElement };