@microsoft/fast-html 1.0.0-alpha.22 → 1.0.0-alpha.24

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.
@@ -1,3 +1,4 @@
1
+ import { type ChildrenMap } from "./utilities.js";
1
2
  type FastContextMetaData = "$fast_context";
2
3
  type FastContextsMetaData = "$fast_parent_contexts";
3
4
  export interface JSONSchemaDefinition extends JSONSchemaCommon {
@@ -8,12 +9,13 @@ interface JSONSchemaCommon {
8
9
  type?: string;
9
10
  properties?: any;
10
11
  items?: any;
12
+ anyOf?: Array<any>;
13
+ $ref?: string;
11
14
  }
12
15
  export interface JSONSchema extends JSONSchemaCommon {
13
16
  $schema: string;
14
17
  $id: string;
15
18
  $defs?: Record<string, JSONSchemaDefinition>;
16
- $ref?: string;
17
19
  }
18
20
  interface CachedPathCommon {
19
21
  parentContext: string | null;
@@ -41,6 +43,7 @@ export type CachedPathMap = Map<string, Map<string, JSONSchema>>;
41
43
  interface RegisterPathConfig {
42
44
  rootPropertyName: string;
43
45
  pathConfig: CachedPath;
46
+ childrenMap: ChildrenMap | null;
44
47
  }
45
48
  export declare const fastContextMetaData: FastContextMetaData;
46
49
  export declare const fastContextsMetaData: FastContextsMetaData;
@@ -87,6 +90,13 @@ export declare class Schema {
87
90
  * @returns A string to use as a $ref
88
91
  */
89
92
  private getDefsPath;
93
+ /**
94
+ * Get the schema $id
95
+ * @param customElementName - The custom element name
96
+ * @param propertyName - The property name
97
+ * @returns The ID that can be used in the JSON schema as $id
98
+ */
99
+ private getSchemaId;
90
100
  /**
91
101
  * Add a new JSON schema to the JSON schema map
92
102
  * @param propertyName The name of the property to assign this JSON schema to
@@ -36,6 +36,10 @@ export interface TemplateDirectiveBehaviorConfig extends BehaviorConfig {
36
36
  closingTagStartIndex: number;
37
37
  closingTagEndIndex: number;
38
38
  }
39
+ export interface ChildrenMap {
40
+ customElementName: string;
41
+ attributeName: string;
42
+ }
39
43
  /**
40
44
  * Get the index of the next matching tag
41
45
  * @param openingTagStartSlice - The slice starting from the opening tag
@@ -59,7 +63,7 @@ export declare function getNextBehavior(innerHTML: string): DataBindingBehaviorC
59
63
  * @returns A function to access the value from a given path.
60
64
  */
61
65
  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;
66
+ export declare function bindingResolver(previousString: string | null, rootPropertyName: string | null, path: string, parentContext: string | null, type: PathType, schema: Schema, currentContext: string | null, level: number): (accessibleObject: any, context: any) => any;
63
67
  export declare function expressionResolver(rootPropertyName: string | null, expression: ChainedExpression, parentContext: string | null, level: number, schema: Schema): (accessibleObject: any, context: any) => any;
64
68
  /**
65
69
  * Extracts all paths from a ChainedExpression, including nested expressions
@@ -116,6 +120,14 @@ export declare function transformInnerHTML(innerHTML: string, index?: number): s
116
120
  * @returns - A binding that resolves the chained expression logic
117
121
  */
118
122
  export declare function resolveWhen(rootPropertyName: string | null, expression: ChainedExpression, parentContext: string | null, level: number, schema: Schema): (x: boolean, c: any) => any;
123
+ /**
124
+ * Find a definition
125
+ * This may exist as a $ref at the root or as a $ref in any anyOf or not at all
126
+ * if the Observer Map has not been enabled on a child component
127
+ * @param schema - The JSON schema to find the ref in
128
+ * @returns The definition or null
129
+ */
130
+ export declare function findDef(schema: JSONSchema | JSONSchemaDefinition): string | null;
119
131
  /**
120
132
  * Assign observables to data
121
133
  * @param schema - The schema
@@ -145,4 +157,10 @@ export declare function assignProxy(schema: JSONSchema | JSONSchemaDefinition, r
145
157
  * @returns
146
158
  */
147
159
  export declare function getRootPropertyName(rootPropertyName: string | null, path: string, context: null | string, type: PathType): string | null;
160
+ /**
161
+ * Get details of bindings to the attributes of child custom elements
162
+ * @param previousString - The previous string before the binding
163
+ * @returns null, or a custom element name and attribute name
164
+ */
165
+ export declare function getChildrenMap(previousString: string | null): ChildrenMap | null;
148
166
  export {};
@@ -20,17 +20,26 @@ export class Schema {
20
20
  var _a, _b, _c;
21
21
  const splitPath = this.getSplitPath(config.pathConfig.path);
22
22
  let schema = Schema.jsonSchemaMap.get(this.customElementName).get(config.rootPropertyName);
23
+ let childRef = null;
23
24
  // Create a root level property JSON
24
25
  if (!schema) {
25
26
  this.addNewSchema(config.rootPropertyName);
26
27
  schema = Schema.jsonSchemaMap.get(this.customElementName).get(config.rootPropertyName);
27
28
  }
29
+ if (config.childrenMap) {
30
+ childRef = this.getSchemaId(config.childrenMap.customElementName, config.childrenMap.attributeName);
31
+ if (splitPath.length === 1) {
32
+ schema.anyOf
33
+ ? schema.anyOf.push({ [refPropertyName]: childRef })
34
+ : (schema.anyOf = [{ [refPropertyName]: childRef }]);
35
+ }
36
+ }
28
37
  switch (config.pathConfig.type) {
29
38
  case "default":
30
39
  case "access": {
31
40
  if (splitPath.length > 1) {
32
41
  if (config.pathConfig.currentContext === null) {
33
- this.addPropertiesToAnObject(schema, splitPath.slice(1), config.pathConfig.currentContext);
42
+ this.addPropertiesToAnObject(schema, splitPath.slice(1), config.pathConfig.currentContext, childRef);
34
43
  }
35
44
  else {
36
45
  if (!((_a = schema[defsPropertyName]) === null || _a === void 0 ? void 0 : _a[splitPath[0]])) {
@@ -38,7 +47,7 @@ export class Schema {
38
47
  [splitPath[0]]: {},
39
48
  };
40
49
  }
41
- this.addPropertiesToAContext(schema[defsPropertyName][splitPath[0]], splitPath.slice(1), config.pathConfig.currentContext);
50
+ this.addPropertiesToAContext(schema[defsPropertyName][splitPath[0]], splitPath.slice(1), config.pathConfig.currentContext, childRef);
42
51
  }
43
52
  }
44
53
  break;
@@ -51,16 +60,16 @@ export class Schema {
51
60
  let updatedSchema = schema;
52
61
  const hasParentContext = !!config.pathConfig.parentContext;
53
62
  if (hasParentContext) {
54
- updatedSchema = this.addPropertiesToAnObject((_b = schema[defsPropertyName]) === null || _b === void 0 ? void 0 : _b[config.pathConfig.parentContext], splitPath.slice(1, -1), config.pathConfig.parentContext);
63
+ updatedSchema = this.addPropertiesToAnObject((_b = schema[defsPropertyName]) === null || _b === void 0 ? void 0 : _b[config.pathConfig.parentContext], splitPath.slice(1, -1), config.pathConfig.parentContext, childRef);
55
64
  }
56
- this.addPropertiesToAnObject(updatedSchema, hasParentContext ? splitPath.slice(2) : splitPath.slice(1), config.pathConfig.currentContext, "array");
65
+ this.addPropertiesToAnObject(updatedSchema, hasParentContext ? splitPath.slice(2) : splitPath.slice(1), config.pathConfig.currentContext, childRef, "array");
57
66
  }
58
67
  else if (splitPath.length > 1) {
59
68
  let schemaDefinition;
60
69
  if (config.pathConfig.parentContext) {
61
70
  schemaDefinition = (_c = schema === null || schema === void 0 ? void 0 : schema[defsPropertyName]) === null || _c === void 0 ? void 0 : _c[config.pathConfig.parentContext];
62
71
  }
63
- this.addPropertiesToAnObject(schemaDefinition !== null && schemaDefinition !== void 0 ? schemaDefinition : schema, splitPath.slice(1), config.pathConfig.currentContext, "array");
72
+ this.addPropertiesToAnObject(schemaDefinition !== null && schemaDefinition !== void 0 ? schemaDefinition : schema, splitPath.slice(1), config.pathConfig.currentContext, childRef, "array");
64
73
  }
65
74
  else {
66
75
  schema.type = "array";
@@ -102,6 +111,15 @@ export class Schema {
102
111
  getDefsPath(context) {
103
112
  return `#/${defsPropertyName}/${context}`;
104
113
  }
114
+ /**
115
+ * Get the schema $id
116
+ * @param customElementName - The custom element name
117
+ * @param propertyName - The property name
118
+ * @returns The ID that can be used in the JSON schema as $id
119
+ */
120
+ getSchemaId(customElementName, propertyName) {
121
+ return `https://fast.design/schemas/${customElementName}/${propertyName}.json`;
122
+ }
105
123
  /**
106
124
  * Add a new JSON schema to the JSON schema map
107
125
  * @param propertyName The name of the property to assign this JSON schema to
@@ -109,7 +127,7 @@ export class Schema {
109
127
  addNewSchema(propertyName) {
110
128
  Schema.jsonSchemaMap.get(this.customElementName).set(propertyName, {
111
129
  $schema: "https://json-schema.org/draft/2019-09/schema",
112
- $id: `https://fast.design/schemas/${this.customElementName}/${propertyName}.json`,
130
+ $id: this.getSchemaId(this.customElementName, propertyName),
113
131
  [defsPropertyName]: {},
114
132
  });
115
133
  }
@@ -119,7 +137,7 @@ export class Schema {
119
137
  * @param splitPath The path split into property/context names
120
138
  * @param context The paths context
121
139
  */
122
- addPropertiesToAContext(schema, splitPath, context) {
140
+ addPropertiesToAContext(schema, splitPath, context, childRef) {
123
141
  schema.type = "object";
124
142
  if (schema.properties && !schema.properties[splitPath[0]]) {
125
143
  schema.properties[splitPath[0]] = {};
@@ -130,7 +148,17 @@ export class Schema {
130
148
  };
131
149
  }
132
150
  if (splitPath.length > 1) {
133
- this.addPropertiesToAnObject(schema.properties[splitPath[0]], splitPath.slice(1), context);
151
+ this.addPropertiesToAnObject(schema.properties[splitPath[0]], splitPath.slice(1), context, childRef);
152
+ }
153
+ else if (childRef) {
154
+ if (schema.properties[splitPath[0]].anyOf) {
155
+ schema.properties[splitPath[0]].anyOf.push({
156
+ [refPropertyName]: childRef,
157
+ });
158
+ }
159
+ else {
160
+ schema.properties[splitPath[0]].anyOf = [{ [refPropertyName]: childRef }];
161
+ }
134
162
  }
135
163
  }
136
164
  /**
@@ -140,7 +168,7 @@ export class Schema {
140
168
  * @param context The paths context
141
169
  * @param type The data type (see JSON schema for details)
142
170
  */
143
- addPropertiesToAnObject(schema, splitPath, context, type = "object") {
171
+ addPropertiesToAnObject(schema, splitPath, context, childRef, type = "object") {
144
172
  schema.type = "object";
145
173
  if (schema.properties && !schema.properties[splitPath[0]]) {
146
174
  schema.properties[splitPath[0]] = {};
@@ -151,16 +179,22 @@ export class Schema {
151
179
  };
152
180
  }
153
181
  if (type === "object" && splitPath.length > 1) {
154
- return this.addPropertiesToAnObject(schema.properties[splitPath[0]], splitPath.slice(1), context, type);
182
+ return this.addPropertiesToAnObject(schema.properties[splitPath[0]], splitPath.slice(1), context, childRef, type);
155
183
  }
156
184
  else if (type === "array") {
157
185
  if (splitPath.length > 1) {
158
- return this.addPropertiesToAnObject(schema.properties[splitPath[0]], splitPath.slice(1), context, type);
186
+ return this.addPropertiesToAnObject(schema.properties[splitPath[0]], splitPath.slice(1), context, childRef, type);
159
187
  }
160
188
  else {
161
189
  return this.addArrayToAnObject(schema.properties[splitPath[0]], context);
162
190
  }
163
191
  }
192
+ if (schema.properties[splitPath[0]].anyOf && childRef) {
193
+ schema.properties[splitPath[0]].anyOf.push({ [refPropertyName]: childRef });
194
+ }
195
+ else if (childRef) {
196
+ schema.properties[splitPath[0]].anyOf = [{ [refPropertyName]: childRef }];
197
+ }
164
198
  return schema.properties[splitPath[0]];
165
199
  }
166
200
  /**
@@ -1,6 +1,6 @@
1
1
  import { __awaiter } from "tslib";
2
2
  import { expect, test } from "@playwright/test";
3
- import { Schema } from "./schema.js";
3
+ import { refPropertyName, Schema } from "./schema.js";
4
4
  test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
5
5
  test("should instantiate with a custom element name without throwing", () => __awaiter(void 0, void 0, void 0, function* () {
6
6
  expect(() => new Schema("my-custom-element")).not.toThrow();
@@ -18,7 +18,8 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
18
18
  path: "a",
19
19
  currentContext: null,
20
20
  parentContext: null,
21
- }
21
+ },
22
+ childrenMap: null,
22
23
  });
23
24
  const schemaA = schema.getSchema("a");
24
25
  expect(schemaA).not.toBe(null);
@@ -35,6 +36,7 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
35
36
  currentContext: null,
36
37
  parentContext: null,
37
38
  },
39
+ childrenMap: null,
38
40
  });
39
41
  let schemaA = schema.getSchema("a");
40
42
  expect(schemaA.properties).toBeDefined();
@@ -47,6 +49,7 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
47
49
  currentContext: null,
48
50
  parentContext: null,
49
51
  },
52
+ childrenMap: null,
50
53
  });
51
54
  schemaA = schema.getSchema("a");
52
55
  expect(schemaA.properties).toBeDefined();
@@ -65,6 +68,7 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
65
68
  currentContext: "item",
66
69
  parentContext: null,
67
70
  },
71
+ childrenMap: null,
68
72
  });
69
73
  const schemaA = schema.getSchema("items");
70
74
  expect(schemaA).toBeDefined();
@@ -86,6 +90,7 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
86
90
  currentContext: "item",
87
91
  parentContext: null,
88
92
  },
93
+ childrenMap: null,
89
94
  });
90
95
  schema.addPath({
91
96
  rootPropertyName: "items",
@@ -95,6 +100,7 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
95
100
  currentContext: "item",
96
101
  parentContext: null,
97
102
  },
103
+ childrenMap: null,
98
104
  });
99
105
  const schemaA = schema.getSchema("items");
100
106
  expect(schemaA).toBeDefined();
@@ -119,6 +125,7 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
119
125
  currentContext: null,
120
126
  parentContext: null,
121
127
  },
128
+ childrenMap: null,
122
129
  });
123
130
  schema.addPath({
124
131
  rootPropertyName: "a",
@@ -128,6 +135,7 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
128
135
  currentContext: "item",
129
136
  parentContext: null,
130
137
  },
138
+ childrenMap: null,
131
139
  });
132
140
  const schemaA = schema.getSchema("a");
133
141
  expect(schemaA).toBeDefined();
@@ -148,6 +156,7 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
148
156
  currentContext: null,
149
157
  parentContext: null,
150
158
  },
159
+ childrenMap: null,
151
160
  });
152
161
  schema.addPath({
153
162
  rootPropertyName: "a",
@@ -157,6 +166,7 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
157
166
  currentContext: "item",
158
167
  parentContext: null,
159
168
  },
169
+ childrenMap: null,
160
170
  });
161
171
  schema.addPath({
162
172
  rootPropertyName: "a",
@@ -166,6 +176,7 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
166
176
  currentContext: "item",
167
177
  parentContext: null,
168
178
  },
179
+ childrenMap: null,
169
180
  });
170
181
  const schemaA = schema.getSchema("a");
171
182
  expect(schemaA).toBeDefined();
@@ -187,6 +198,7 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
187
198
  currentContext: null,
188
199
  parentContext: null,
189
200
  },
201
+ childrenMap: null,
190
202
  });
191
203
  schema.addPath({
192
204
  rootPropertyName: "a",
@@ -196,6 +208,7 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
196
208
  currentContext: "user",
197
209
  parentContext: null,
198
210
  },
211
+ childrenMap: null,
199
212
  });
200
213
  schema.addPath({
201
214
  rootPropertyName: "a",
@@ -205,6 +218,7 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
205
218
  currentContext: "post",
206
219
  parentContext: "user"
207
220
  },
221
+ childrenMap: null,
208
222
  });
209
223
  const schemaA = schema.getSchema("a");
210
224
  expect(schemaA).toBeDefined();
@@ -226,6 +240,7 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
226
240
  currentContext: "user",
227
241
  parentContext: null,
228
242
  },
243
+ childrenMap: null,
229
244
  });
230
245
  schema.addPath({
231
246
  rootPropertyName: "a",
@@ -235,6 +250,7 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
235
250
  currentContext: "user",
236
251
  parentContext: null,
237
252
  },
253
+ childrenMap: null,
238
254
  });
239
255
  schema.addPath({
240
256
  rootPropertyName: "a",
@@ -244,6 +260,7 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
244
260
  currentContext: "post",
245
261
  parentContext: "user"
246
262
  },
263
+ childrenMap: null,
247
264
  });
248
265
  schema.addPath({
249
266
  rootPropertyName: "a",
@@ -253,6 +270,7 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
253
270
  currentContext: "post",
254
271
  parentContext: null,
255
272
  },
273
+ childrenMap: null,
256
274
  });
257
275
  schema.addPath({
258
276
  rootPropertyName: "a",
@@ -262,6 +280,7 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
262
280
  currentContext: "tag",
263
281
  parentContext: "post"
264
282
  },
283
+ childrenMap: null,
265
284
  });
266
285
  const schemaA = schema.getSchema("a");
267
286
  expect(schemaA).toBeDefined();
@@ -287,4 +306,180 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
287
306
  expect((_22 = schemaA.$defs) === null || _22 === void 0 ? void 0 : _22["tag"].$fast_context).toEqual("tags");
288
307
  expect((_23 = schemaA.$defs) === null || _23 === void 0 ? void 0 : _23["tag"].$fast_parent_contexts).toEqual([null, "user", "post"]);
289
308
  }));
309
+ test("should define an anyOf with a $ref to another schema", () => __awaiter(void 0, void 0, void 0, function* () {
310
+ var _24;
311
+ const schema = new Schema("my-custom-element");
312
+ schema.addPath({
313
+ rootPropertyName: "a",
314
+ pathConfig: {
315
+ type: "default",
316
+ path: "a",
317
+ currentContext: null,
318
+ parentContext: null,
319
+ },
320
+ childrenMap: {
321
+ customElementName: "my-custom-element-2",
322
+ attributeName: "b",
323
+ },
324
+ });
325
+ const schemaA = schema.getSchema("a");
326
+ expect(schemaA).not.toBe(null);
327
+ expect(schemaA.$id).toEqual("https://fast.design/schemas/my-custom-element/a.json");
328
+ expect(schemaA.$schema).toEqual("https://json-schema.org/draft/2019-09/schema");
329
+ expect(schemaA.anyOf).not.toBeUndefined();
330
+ expect(schemaA.anyOf).toHaveLength(1);
331
+ expect((_24 = schemaA.anyOf) === null || _24 === void 0 ? void 0 : _24[0].$ref).toEqual("https://fast.design/schemas/my-custom-element-2/b.json");
332
+ }));
333
+ test("should define an anyOf with a $ref to multiple schemas", () => __awaiter(void 0, void 0, void 0, function* () {
334
+ var _25, _26;
335
+ const schema = new Schema("my-custom-element");
336
+ schema.addPath({
337
+ rootPropertyName: "a",
338
+ pathConfig: {
339
+ type: "default",
340
+ path: "a",
341
+ currentContext: null,
342
+ parentContext: null,
343
+ },
344
+ childrenMap: {
345
+ customElementName: "my-custom-element-2",
346
+ attributeName: "b",
347
+ },
348
+ });
349
+ schema.addPath({
350
+ rootPropertyName: "a",
351
+ pathConfig: {
352
+ type: "default",
353
+ path: "a",
354
+ currentContext: null,
355
+ parentContext: null,
356
+ },
357
+ childrenMap: {
358
+ customElementName: "my-custom-element-3",
359
+ attributeName: "c",
360
+ },
361
+ });
362
+ const schemaA = schema.getSchema("a");
363
+ expect(schemaA).not.toBe(null);
364
+ expect(schemaA.$id).toEqual("https://fast.design/schemas/my-custom-element/a.json");
365
+ expect(schemaA.$schema).toEqual("https://json-schema.org/draft/2019-09/schema");
366
+ expect(schemaA.anyOf).not.toBeUndefined();
367
+ expect(schemaA.anyOf).toHaveLength(2);
368
+ expect((_25 = schemaA.anyOf) === null || _25 === void 0 ? void 0 : _25[0].$ref).toEqual("https://fast.design/schemas/my-custom-element-2/b.json");
369
+ expect((_26 = schemaA.anyOf) === null || _26 === void 0 ? void 0 : _26[1].$ref).toEqual("https://fast.design/schemas/my-custom-element-3/c.json");
370
+ }));
371
+ test("should define an anyOf with a $ref to another schema in a nested object", () => __awaiter(void 0, void 0, void 0, function* () {
372
+ const schema = new Schema("my-custom-element");
373
+ schema.addPath({
374
+ rootPropertyName: "a",
375
+ pathConfig: {
376
+ type: "default",
377
+ path: "a.b",
378
+ currentContext: null,
379
+ parentContext: null,
380
+ },
381
+ childrenMap: null,
382
+ });
383
+ let schemaA = schema.getSchema("a");
384
+ schema.addPath({
385
+ rootPropertyName: "a",
386
+ pathConfig: {
387
+ type: "default",
388
+ path: "a.b.c",
389
+ currentContext: null,
390
+ parentContext: null,
391
+ },
392
+ childrenMap: {
393
+ customElementName: "my-custom-element-2",
394
+ attributeName: "test"
395
+ },
396
+ });
397
+ schemaA = schema.getSchema("a");
398
+ expect(schemaA.properties.b.properties.c).toBeDefined();
399
+ expect(schemaA.properties.b.properties.c.anyOf).not.toBeUndefined();
400
+ expect(schemaA.properties.b.properties.c.anyOf[0].$ref).toEqual("https://fast.design/schemas/my-custom-element-2/test.json");
401
+ }));
402
+ test("should define an anyOf with a $ref to multiple schemas in a nested object", () => __awaiter(void 0, void 0, void 0, function* () {
403
+ const schema = new Schema("my-custom-element");
404
+ schema.addPath({
405
+ rootPropertyName: "a",
406
+ pathConfig: {
407
+ type: "default",
408
+ path: "a.b",
409
+ currentContext: null,
410
+ parentContext: null,
411
+ },
412
+ childrenMap: null,
413
+ });
414
+ let schemaA = schema.getSchema("a");
415
+ schema.addPath({
416
+ rootPropertyName: "a",
417
+ pathConfig: {
418
+ type: "default",
419
+ path: "a.b.c",
420
+ currentContext: null,
421
+ parentContext: null,
422
+ },
423
+ childrenMap: {
424
+ customElementName: "my-custom-element-2",
425
+ attributeName: "test"
426
+ },
427
+ });
428
+ schema.addPath({
429
+ rootPropertyName: "a",
430
+ pathConfig: {
431
+ type: "default",
432
+ path: "a.b.c",
433
+ currentContext: null,
434
+ parentContext: null,
435
+ },
436
+ childrenMap: {
437
+ customElementName: "my-custom-element-3",
438
+ attributeName: "test-2"
439
+ },
440
+ });
441
+ schemaA = schema.getSchema("a");
442
+ expect(schemaA.properties.b.properties.c).toBeDefined();
443
+ expect(schemaA.properties.b.properties.c.anyOf).not.toBeUndefined();
444
+ expect(schemaA.properties.b.properties.c.anyOf[0].$ref).toEqual("https://fast.design/schemas/my-custom-element-2/test.json");
445
+ expect(schemaA.properties.b.properties.c.anyOf[1].$ref).toEqual("https://fast.design/schemas/my-custom-element-3/test-2.json");
446
+ }));
447
+ test("should define an anyOf with a $ref in a nested object in a context", () => __awaiter(void 0, void 0, void 0, function* () {
448
+ var _27, _28, _29, _30, _31, _32, _33, _34, _35;
449
+ const schema = new Schema("my-custom-element");
450
+ schema.addPath({
451
+ rootPropertyName: "a",
452
+ pathConfig: {
453
+ type: "repeat",
454
+ path: "a.users",
455
+ currentContext: "user",
456
+ parentContext: null,
457
+ },
458
+ childrenMap: null,
459
+ });
460
+ schema.addPath({
461
+ rootPropertyName: "a",
462
+ pathConfig: {
463
+ type: "access",
464
+ path: "user.a.b",
465
+ currentContext: "user",
466
+ parentContext: null,
467
+ },
468
+ childrenMap: {
469
+ customElementName: "my-custom-element-2",
470
+ attributeName: "c"
471
+ },
472
+ });
473
+ const schemaA = schema.getSchema("a");
474
+ expect(schemaA).toBeDefined();
475
+ expect((_27 = schemaA.$defs) === null || _27 === void 0 ? void 0 : _27["user"]).toBeDefined();
476
+ expect((_28 = schemaA.$defs) === null || _28 === void 0 ? void 0 : _28["user"].$fast_context).toEqual("users");
477
+ expect((_29 = schemaA.$defs) === null || _29 === void 0 ? void 0 : _29["user"].$fast_parent_contexts).toEqual([null]);
478
+ expect((_30 = schemaA.$defs) === null || _30 === void 0 ? void 0 : _30["user"].type).toEqual("object");
479
+ expect((_31 = schemaA.$defs) === null || _31 === void 0 ? void 0 : _31["user"].properties).toBeDefined();
480
+ expect((_32 = schemaA.$defs) === null || _32 === void 0 ? void 0 : _32["user"].properties["a"]).toBeDefined();
481
+ expect((_33 = schemaA.$defs) === null || _33 === void 0 ? void 0 : _33["user"].properties["a"].properties["b"]).toBeDefined();
482
+ expect((_34 = schemaA.$defs) === null || _34 === void 0 ? void 0 : _34["user"].properties["a"].properties["b"].anyOf).toHaveLength(1);
483
+ expect((_35 = schemaA.$defs) === null || _35 === void 0 ? void 0 : _35["user"].properties["a"].properties["b"].anyOf[0][refPropertyName]).toEqual("https://fast.design/schemas/my-custom-element-2/c.json");
484
+ }));
290
485
  }));
@@ -119,7 +119,7 @@ class TemplateElement extends FASTElement {
119
119
  const updatedLevel = level + 1;
120
120
  const { repeat } = yield import("@microsoft/fast-element");
121
121
  rootPropertyName = getRootPropertyName(rootPropertyName, valueAttr[2], parentContext, behaviorConfig.name);
122
- const binding = bindingResolver(rootPropertyName, valueAttr[2], parentContext, behaviorConfig.name, schema, valueAttr[0], level);
122
+ const binding = bindingResolver(null, rootPropertyName, valueAttr[2], parentContext, behaviorConfig.name, schema, valueAttr[0], level);
123
123
  const { strings, values } = yield this.resolveStringsAndValues(rootPropertyName, innerHTML.slice(behaviorConfig.openingTagEndIndex, behaviorConfig.closingTagStartIndex), true, valueAttr[0], updatedLevel, schema, observerMap);
124
124
  externalValues.push(repeat((x, c) => binding(x, c), this.resolveTemplateOrBehavior(strings, values)));
125
125
  break;
@@ -184,7 +184,7 @@ class TemplateElement extends FASTElement {
184
184
  const type = "access";
185
185
  const propName = innerHTML.slice(behaviorConfig.openingEndIndex, behaviorConfig.closingStartIndex);
186
186
  rootPropertyName = getRootPropertyName(rootPropertyName, propName, parentContext, type);
187
- const binding = bindingResolver(rootPropertyName, propName, parentContext, type, schema, parentContext, level);
187
+ const binding = bindingResolver(strings.join(""), rootPropertyName, propName, parentContext, type, schema, parentContext, level);
188
188
  const contentBinding = (x, c) => binding(x, c);
189
189
  values.push(contentBinding);
190
190
  yield this.resolveInnerHTML(rootPropertyName, innerHTML.slice(behaviorConfig.closingEndIndex, innerHTML.length), strings, values, self, parentContext, level, schema, observerMap);
@@ -202,10 +202,10 @@ class TemplateElement extends FASTElement {
202
202
  const type = "event";
203
203
  rootPropertyName = getRootPropertyName(rootPropertyName, propName, parentContext, type);
204
204
  const arg = bindingHTML.slice(openingParenthesis + 1, closingParenthesis);
205
- const binding = bindingResolver(rootPropertyName, propName, parentContext, type, schema, parentContext, level);
205
+ const binding = bindingResolver(strings.join(""), rootPropertyName, propName, parentContext, type, schema, parentContext, level);
206
206
  const attributeBinding = (x, c) => binding(x, c).bind(x)(...(arg === "e" ? [c.event] : []), ...(arg !== "e" && arg !== ""
207
207
  ? [
208
- bindingResolver(rootPropertyName, arg, parentContext, type, schema, parentContext, level)(x, c),
208
+ bindingResolver(strings.join(""), rootPropertyName, arg, parentContext, type, schema, parentContext, level)(x, c),
209
209
  ]
210
210
  : []));
211
211
  values.push(attributeBinding);
@@ -214,7 +214,7 @@ class TemplateElement extends FASTElement {
214
214
  const propName = innerHTML.slice(behaviorConfig.openingEndIndex, behaviorConfig.closingStartIndex);
215
215
  const type = "access";
216
216
  rootPropertyName = getRootPropertyName(rootPropertyName, propName, parentContext, type);
217
- const binding = bindingResolver(rootPropertyName, propName, parentContext, type, schema, parentContext, level);
217
+ const binding = bindingResolver(strings.join(""), rootPropertyName, propName, parentContext, type, schema, parentContext, level);
218
218
  const attributeBinding = (x, c) => binding(x, c);
219
219
  values.push(attributeBinding);
220
220
  }