@player-tools/dsl 0.10.0-next.0 → 0.10.1
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.
- package/dist/cjs/index.cjs +2 -7
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +4 -9
- package/dist/index.mjs +4 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/asset-api.test.tsx +7 -7
- package/src/__tests__/edge-cases.test.tsx +3 -3
- package/src/__tests__/helpers/asset-library.tsx +9 -9
- package/src/__tests__/jsx.test.tsx +7 -7
- package/src/__tests__/schema.test.tsx +11 -13
- package/src/__tests__/view-api.test.tsx +1 -1
- package/src/auto-id.tsx +5 -8
- package/src/compiler/__tests__/compiler.test.tsx +1 -1
- package/src/compiler/__tests__/schema.test.ts +3 -3
- package/src/compiler/compiler.ts +10 -11
- package/src/compiler/schema.ts +10 -10
- package/src/compiler/types.ts +1 -1
- package/src/compiler/utils.ts +1 -1
- package/src/components.tsx +2 -3
- package/src/string-templates/__tests__/binding.test.ts +9 -9
- package/src/string-templates/__tests__/edge-cases.test.ts +1 -1
- package/src/string-templates/__tests__/expression.test.ts +1 -0
- package/src/string-templates/__tests__/react.test.tsx +3 -3
- package/src/string-templates/index.ts +10 -10
- package/src/switch.tsx +1 -1
- package/src/template.tsx +8 -8
- package/src/types.ts +22 -21
- package/src/utils.tsx +10 -8
|
@@ -46,7 +46,7 @@ test("works with JSX", async () => {
|
|
|
46
46
|
);
|
|
47
47
|
|
|
48
48
|
expect((await render(element)).jsonValue).toStrictEqual(
|
|
49
|
-
expectedBasicCollection
|
|
49
|
+
expectedBasicCollection,
|
|
50
50
|
);
|
|
51
51
|
});
|
|
52
52
|
|
|
@@ -57,7 +57,7 @@ test("works for any json props", async () => {
|
|
|
57
57
|
other: "",
|
|
58
58
|
};
|
|
59
59
|
expect(
|
|
60
|
-
(await render(<object>{toJsonProperties(testObj)}</object>)).jsonValue
|
|
60
|
+
(await render(<object>{toJsonProperties(testObj)}</object>)).jsonValue,
|
|
61
61
|
).toStrictEqual(testObj);
|
|
62
62
|
});
|
|
63
63
|
|
|
@@ -67,7 +67,7 @@ test("works for BindingTemplateInstances and ExpressionTemplateInstances", async
|
|
|
67
67
|
page_experience: e`foo.bar.GetDataResult`,
|
|
68
68
|
};
|
|
69
69
|
expect(
|
|
70
|
-
(await render(<object>{toJsonProperties(testObj)}</object>)).jsonValue
|
|
70
|
+
(await render(<object>{toJsonProperties(testObj)}</object>)).jsonValue,
|
|
71
71
|
).toStrictEqual(expectedTemplateInstanceObjects);
|
|
72
72
|
});
|
|
73
73
|
|
|
@@ -103,7 +103,7 @@ test("flattens fragments", async () => {
|
|
|
103
103
|
);
|
|
104
104
|
|
|
105
105
|
expect((await render(element)).jsonValue).toStrictEqual(
|
|
106
|
-
expectedBasicCollection
|
|
106
|
+
expectedBasicCollection,
|
|
107
107
|
);
|
|
108
108
|
});
|
|
109
109
|
|
|
@@ -124,15 +124,15 @@ test("can ignore json props", async () => {
|
|
|
124
124
|
other: "",
|
|
125
125
|
};
|
|
126
126
|
expect(
|
|
127
|
-
(await render(<object>{toJsonProperties(testObj)}</object>)).jsonValue
|
|
127
|
+
(await render(<object>{toJsonProperties(testObj)}</object>)).jsonValue,
|
|
128
128
|
).toStrictEqual(processedTestObj);
|
|
129
129
|
expect(
|
|
130
130
|
(
|
|
131
131
|
await render(
|
|
132
132
|
<object>
|
|
133
133
|
{toJsonProperties(testObj, { propertiesToSkip: ["foo"] })}
|
|
134
|
-
</object
|
|
134
|
+
</object>,
|
|
135
135
|
)
|
|
136
|
-
).jsonValue
|
|
136
|
+
).jsonValue,
|
|
137
137
|
).toStrictEqual(unprocessedTestObj);
|
|
138
138
|
});
|
|
@@ -37,20 +37,18 @@ describe("Schema Bindings Generate Properly", () => {
|
|
|
37
37
|
expect(schema.main.sub2.toRefString()).toStrictEqual("{{main.sub2}}");
|
|
38
38
|
expect(schema.main.sub2[0].toRefString()).toStrictEqual("{{main.sub2.0}}");
|
|
39
39
|
expect(schema.main.sub2._index_.toRefString()).toStrictEqual(
|
|
40
|
-
"{{main.sub2._index_}}"
|
|
40
|
+
"{{main.sub2._index_}}",
|
|
41
41
|
);
|
|
42
42
|
|
|
43
43
|
expect(schema.main.sub2[0].val.toRefString()).toStrictEqual(
|
|
44
|
-
"{{main.sub2.0.val}}"
|
|
44
|
+
"{{main.sub2.0.val}}",
|
|
45
|
+
);
|
|
46
|
+
expect(schema.main.sub2["_index_"].toRefString()).toStrictEqual(
|
|
47
|
+
"{{main.sub2._index_}}",
|
|
48
|
+
);
|
|
49
|
+
expect(schema.main.sub2["_index_"].val.toRefString()).toStrictEqual(
|
|
50
|
+
"{{main.sub2._index_.val}}",
|
|
45
51
|
);
|
|
46
|
-
expect(
|
|
47
|
-
// eslint-disable-next-line dot-notation
|
|
48
|
-
schema.main.sub2["_index_"].toRefString()
|
|
49
|
-
).toStrictEqual("{{main.sub2._index_}}");
|
|
50
|
-
expect(
|
|
51
|
-
// eslint-disable-next-line dot-notation
|
|
52
|
-
schema.main.sub2["_index_"].val.toRefString()
|
|
53
|
-
).toStrictEqual("{{main.sub2._index_.val}}");
|
|
54
52
|
});
|
|
55
53
|
|
|
56
54
|
test("is able to serialize to a schema object", () => {
|
|
@@ -191,7 +189,7 @@ describe("Schema Bindings Generate Properly", () => {
|
|
|
191
189
|
const results = g.toSchema(badObj);
|
|
192
190
|
expect(mockLogger.warn).toHaveBeenCalledTimes(1);
|
|
193
191
|
expect(mockLogger.warn).toHaveBeenCalledWith(
|
|
194
|
-
"WARNING: Generated two intermediate types with the name: subType that are of different shapes, using artificial type subType2"
|
|
192
|
+
"WARNING: Generated two intermediate types with the name: subType that are of different shapes, using artificial type subType2",
|
|
195
193
|
);
|
|
196
194
|
expect(results).toMatchInlineSnapshot(`
|
|
197
195
|
{
|
|
@@ -292,7 +290,7 @@ describe("Schema Bindings Generate Properly", () => {
|
|
|
292
290
|
const content = await render(
|
|
293
291
|
<obj>
|
|
294
292
|
<property name="test">{schema.main.sub.a}</property>
|
|
295
|
-
</obj
|
|
293
|
+
</obj>,
|
|
296
294
|
);
|
|
297
295
|
|
|
298
296
|
expect(content.jsonValue).toMatchInlineSnapshot(`
|
|
@@ -332,7 +330,7 @@ describe("Schema Bindings Generate Properly", () => {
|
|
|
332
330
|
expect(schema.main.sub.c.enum).toStrictEqual(["A", "B", "C"]);
|
|
333
331
|
// make sure iterable method is still there and works
|
|
334
332
|
expect(
|
|
335
|
-
schema.main.sub.c.enum.every((it: any) => typeof it === "string")
|
|
333
|
+
schema.main.sub.c.enum.every((it: any) => typeof it === "string"),
|
|
336
334
|
).toStrictEqual(true);
|
|
337
335
|
});
|
|
338
336
|
});
|
package/src/auto-id.tsx
CHANGED
|
@@ -18,7 +18,7 @@ export const IDSuffixProvider = (
|
|
|
18
18
|
props: WithChildren<{
|
|
19
19
|
/** The suffix to append */
|
|
20
20
|
suffix: string;
|
|
21
|
-
}
|
|
21
|
+
}>,
|
|
22
22
|
) => {
|
|
23
23
|
const currentPrefix = useGetIdPrefix();
|
|
24
24
|
|
|
@@ -41,7 +41,7 @@ export const IDProvider = (
|
|
|
41
41
|
props: WithChildren<{
|
|
42
42
|
/** The new id to use */
|
|
43
43
|
id?: string;
|
|
44
|
-
}
|
|
44
|
+
}>,
|
|
45
45
|
) => {
|
|
46
46
|
if (props.id) {
|
|
47
47
|
return (
|
|
@@ -51,7 +51,6 @@ export const IDProvider = (
|
|
|
51
51
|
);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
// eslint-disable-next-line react/jsx-no-useless-fragment
|
|
55
54
|
return <>{props.children}</>;
|
|
56
55
|
};
|
|
57
56
|
|
|
@@ -67,7 +66,7 @@ export const useIndexInSlot = (ref: React.RefObject<JsonNode>) => {
|
|
|
67
66
|
|
|
68
67
|
if (ref.current && slotContext?.ref.current?.valueNode?.type === "array") {
|
|
69
68
|
const allChildren = flattenNodes(
|
|
70
|
-
slotContext.ref.current.valueNode.children
|
|
69
|
+
slotContext.ref.current.valueNode.children,
|
|
71
70
|
);
|
|
72
71
|
const foundIndex = allChildren.indexOf(ref.current);
|
|
73
72
|
|
|
@@ -88,14 +87,13 @@ export const IDSuffixIndexProvider = (
|
|
|
88
87
|
|
|
89
88
|
/** if the suffix is in a template, the id to use */
|
|
90
89
|
templateIndex?: string;
|
|
91
|
-
}
|
|
90
|
+
}>,
|
|
92
91
|
) => {
|
|
93
92
|
const slotIndex = useIndexInSlot(props.wrapperRef);
|
|
94
93
|
|
|
95
94
|
const stopIndex = React.useContext(IndexSuffixStopContext);
|
|
96
95
|
|
|
97
96
|
if (stopIndex) {
|
|
98
|
-
// eslint-disable-next-line react/jsx-no-useless-fragment
|
|
99
97
|
return <>{props.children}</>;
|
|
100
98
|
}
|
|
101
99
|
|
|
@@ -116,7 +114,7 @@ export const OptionalIDSuffixProvider = (
|
|
|
116
114
|
|
|
117
115
|
/** if the suffix is in a template, the id to use */
|
|
118
116
|
templateIndex?: string;
|
|
119
|
-
}
|
|
117
|
+
}>,
|
|
120
118
|
) => {
|
|
121
119
|
const slotContext = React.useContext(SlotContext);
|
|
122
120
|
|
|
@@ -131,7 +129,6 @@ export const OptionalIDSuffixProvider = (
|
|
|
131
129
|
);
|
|
132
130
|
}
|
|
133
131
|
|
|
134
|
-
// eslint-disable-next-line react/jsx-no-useless-fragment
|
|
135
132
|
return <>{props.children}</>;
|
|
136
133
|
};
|
|
137
134
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { test, expect } from "vitest";
|
|
2
|
-
import { SchemaGenerator
|
|
2
|
+
import { SchemaGenerator } from "../schema";
|
|
3
3
|
|
|
4
4
|
const BasicDataType = {
|
|
5
5
|
type: "StringType",
|
|
@@ -20,7 +20,7 @@ test("generates proper schema", () => {
|
|
|
20
20
|
item1: BasicDataType,
|
|
21
21
|
},
|
|
22
22
|
],
|
|
23
|
-
})
|
|
23
|
+
}),
|
|
24
24
|
).toStrictEqual({
|
|
25
25
|
ROOT: {
|
|
26
26
|
foo: {
|
|
@@ -75,7 +75,7 @@ test("Edge Case - two artificial array nodes", () => {
|
|
|
75
75
|
},
|
|
76
76
|
],
|
|
77
77
|
},
|
|
78
|
-
})
|
|
78
|
+
}),
|
|
79
79
|
).toMatchInlineSnapshot(`
|
|
80
80
|
{
|
|
81
81
|
"ROOT": {
|
package/src/compiler/compiler.ts
CHANGED
|
@@ -72,7 +72,7 @@ type SourceMapList = Array<{
|
|
|
72
72
|
/** Given a list of source maps for all generated views, merge them into 1 */
|
|
73
73
|
const mergeSourceMaps = (
|
|
74
74
|
sourceMaps: SourceMapList,
|
|
75
|
-
generated: string
|
|
75
|
+
generated: string,
|
|
76
76
|
): string => {
|
|
77
77
|
const generator = new SourceMapGenerator();
|
|
78
78
|
sourceMaps.forEach(({ sourceMap, offsetIndexSearch, source }) => {
|
|
@@ -135,7 +135,7 @@ export class DSLCompiler {
|
|
|
135
135
|
/** Convert an object (flow, view, schema, etc) into it's JSON representation */
|
|
136
136
|
async serialize(
|
|
137
137
|
value: unknown,
|
|
138
|
-
context?: SerializeContext
|
|
138
|
+
context?: SerializeContext,
|
|
139
139
|
): Promise<CompilerReturn> {
|
|
140
140
|
if (typeof value !== "object" || value === null) {
|
|
141
141
|
throw new Error("Unable to serialize non-object");
|
|
@@ -183,8 +183,8 @@ export class DSLCompiler {
|
|
|
183
183
|
.split("\n")
|
|
184
184
|
.find((line) =>
|
|
185
185
|
line.includes(
|
|
186
|
-
`"id": "${(jsonValue as Record<string, string>).id}"
|
|
187
|
-
)
|
|
186
|
+
`"id": "${(jsonValue as Record<string, string>).id}"`,
|
|
187
|
+
),
|
|
188
188
|
);
|
|
189
189
|
|
|
190
190
|
if (searchIdLine) {
|
|
@@ -200,7 +200,7 @@ export class DSLCompiler {
|
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
return node;
|
|
203
|
-
}) ?? []
|
|
203
|
+
}) ?? [],
|
|
204
204
|
)) as View[];
|
|
205
205
|
|
|
206
206
|
// Go through the flow and sub out any view refs that are react elements w/ the right id
|
|
@@ -216,7 +216,7 @@ export class DSLCompiler {
|
|
|
216
216
|
React.isValidElement(flowNode.ref)
|
|
217
217
|
) {
|
|
218
218
|
const actualViewIndex = (value as Flow).views?.indexOf?.(
|
|
219
|
-
flowNode.ref as any
|
|
219
|
+
flowNode.ref as any,
|
|
220
220
|
);
|
|
221
221
|
|
|
222
222
|
if (actualViewIndex !== undefined && actualViewIndex > -1) {
|
|
@@ -236,19 +236,18 @@ export class DSLCompiler {
|
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
copiedValue.navigation = parseNavigationExpressions(
|
|
239
|
-
copiedValue.navigation
|
|
239
|
+
copiedValue.navigation,
|
|
240
240
|
);
|
|
241
241
|
|
|
242
242
|
if (value) {
|
|
243
|
-
const postProcessFlow =
|
|
244
|
-
copiedValue
|
|
245
|
-
);
|
|
243
|
+
const postProcessFlow =
|
|
244
|
+
await this.hooks.postProcessFlow.call(copiedValue);
|
|
246
245
|
|
|
247
246
|
return {
|
|
248
247
|
value: postProcessFlow as JsonType,
|
|
249
248
|
sourceMap: mergeSourceMaps(
|
|
250
249
|
allSourceMaps,
|
|
251
|
-
JSON.stringify(copiedValue, null, 2)
|
|
250
|
+
JSON.stringify(copiedValue, null, 2),
|
|
252
251
|
),
|
|
253
252
|
};
|
|
254
253
|
}
|
package/src/compiler/schema.ts
CHANGED
|
@@ -51,7 +51,7 @@ export class SchemaGenerator {
|
|
|
51
51
|
createSchemaNode: new SyncWaterfallHook<
|
|
52
52
|
[
|
|
53
53
|
node: Schema.DataType,
|
|
54
|
-
originalProperty: Record<string | symbol, unknown
|
|
54
|
+
originalProperty: Record<string | symbol, unknown>,
|
|
55
55
|
]
|
|
56
56
|
>(),
|
|
57
57
|
};
|
|
@@ -78,7 +78,7 @@ export class SchemaGenerator {
|
|
|
78
78
|
const subType = schema[property] as SchemaNode;
|
|
79
79
|
newSchema.ROOT[property] = this.hooks.createSchemaNode.call(
|
|
80
80
|
this.processChild(property, subType),
|
|
81
|
-
subType as any
|
|
81
|
+
subType as any,
|
|
82
82
|
);
|
|
83
83
|
});
|
|
84
84
|
|
|
@@ -95,7 +95,7 @@ export class SchemaGenerator {
|
|
|
95
95
|
const subType = (child as any)[property] as SchemaNode;
|
|
96
96
|
typeDef[property] = this.hooks.createSchemaNode.call(
|
|
97
97
|
this.processChild(property, subType),
|
|
98
|
-
subType as any
|
|
98
|
+
subType as any,
|
|
99
99
|
);
|
|
100
100
|
});
|
|
101
101
|
newSchema[name] = typeDef;
|
|
@@ -119,7 +119,7 @@ export class SchemaGenerator {
|
|
|
119
119
|
if (Array.isArray(subType)) {
|
|
120
120
|
if (subType.length > 1) {
|
|
121
121
|
this.logger.warn(
|
|
122
|
-
`Type ${property} has multiple types in array, should only contain one top level object type. Only taking first defined type
|
|
122
|
+
`Type ${property} has multiple types in array, should only contain one top level object type. Only taking first defined type`,
|
|
123
123
|
);
|
|
124
124
|
}
|
|
125
125
|
|
|
@@ -136,12 +136,12 @@ export class SchemaGenerator {
|
|
|
136
136
|
|
|
137
137
|
if (this.generatedDataTypes.has(intermediateType.type)) {
|
|
138
138
|
const generatedType = this.generatedDataTypes.get(
|
|
139
|
-
intermediateType.type
|
|
139
|
+
intermediateType.type,
|
|
140
140
|
) as GeneratedDataType;
|
|
141
141
|
if (
|
|
142
142
|
!dequal(
|
|
143
143
|
child,
|
|
144
|
-
this.generatedDataTypes.get(intermediateType.type)?.node as object
|
|
144
|
+
this.generatedDataTypes.get(intermediateType.type)?.node as object,
|
|
145
145
|
)
|
|
146
146
|
) {
|
|
147
147
|
generatedType.count += 1;
|
|
@@ -150,7 +150,7 @@ export class SchemaGenerator {
|
|
|
150
150
|
type: `${intermediateType.type}${generatedType.count}`,
|
|
151
151
|
};
|
|
152
152
|
this.logger.warn(
|
|
153
|
-
`WARNING: Generated two intermediate types with the name: ${intermediateType.type} that are of different shapes, using artificial type ${newIntermediateType.type}
|
|
153
|
+
`WARNING: Generated two intermediate types with the name: ${intermediateType.type} that are of different shapes, using artificial type ${newIntermediateType.type}`,
|
|
154
154
|
);
|
|
155
155
|
intermediateType = newIntermediateType;
|
|
156
156
|
this.children.pop();
|
|
@@ -195,8 +195,8 @@ export type MakeBindingRefable<T> = {
|
|
|
195
195
|
[P in keyof T]: T[P] extends object[]
|
|
196
196
|
? MakeArrayIntoIndexRef<T[P]>
|
|
197
197
|
: T[P] extends unknown[]
|
|
198
|
-
|
|
199
|
-
|
|
198
|
+
? T[P]
|
|
199
|
+
: MakeBindingRefable<T[P]>;
|
|
200
200
|
} & BindingTemplateInstance;
|
|
201
201
|
|
|
202
202
|
/**
|
|
@@ -204,7 +204,7 @@ export type MakeBindingRefable<T> = {
|
|
|
204
204
|
*/
|
|
205
205
|
export function makeBindingsForObject<Type>(
|
|
206
206
|
obj: Type,
|
|
207
|
-
arrayAccessorKeys = ["_index_"]
|
|
207
|
+
arrayAccessorKeys = ["_index_"],
|
|
208
208
|
): MakeBindingRefable<Type> {
|
|
209
209
|
/** Proxy to track binding callbacks */
|
|
210
210
|
const accessor = (paths: string[]) => {
|
package/src/compiler/types.ts
CHANGED
|
@@ -90,7 +90,7 @@ export type DefaultCompilerContentType =
|
|
|
90
90
|
|
|
91
91
|
/** Helper function to determine whether a content type is compiler default */
|
|
92
92
|
export function isDefaultCompilerContentType(
|
|
93
|
-
t: string
|
|
93
|
+
t: string,
|
|
94
94
|
): t is DefaultCompilerContentType {
|
|
95
95
|
return DefaultCompilerContentTypes.includes(t as DefaultCompilerContentType);
|
|
96
96
|
}
|
package/src/compiler/utils.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { DefaultCompilerContentType } from "./types";
|
|
|
4
4
|
/** Basic way of identifying the type of file based on the default content export */
|
|
5
5
|
export const fingerprintContent = (
|
|
6
6
|
content: unknown,
|
|
7
|
-
filename?: string
|
|
7
|
+
filename?: string,
|
|
8
8
|
): DefaultCompilerContentType | undefined => {
|
|
9
9
|
if (content !== null || content !== undefined) {
|
|
10
10
|
if (React.isValidElement(content as any)) {
|
package/src/components.tsx
CHANGED
|
@@ -157,7 +157,7 @@ export const View = React.forwardRef<ObjectNode, AssetProps & ViewType>(
|
|
|
157
157
|
{children}
|
|
158
158
|
</Asset>
|
|
159
159
|
);
|
|
160
|
-
}
|
|
160
|
+
},
|
|
161
161
|
);
|
|
162
162
|
|
|
163
163
|
View.displayName = "View";
|
|
@@ -213,7 +213,6 @@ export const Slot = (props: {
|
|
|
213
213
|
<array>
|
|
214
214
|
{React.Children.map(children, (child, index) => {
|
|
215
215
|
return (
|
|
216
|
-
// eslint-disable-next-line react/no-array-index-key
|
|
217
216
|
<React.Fragment key={`${props.name}-${index}`}>
|
|
218
217
|
{normalizeText({ node: child, TextComp })}
|
|
219
218
|
</React.Fragment>
|
|
@@ -260,7 +259,7 @@ export function createSlot<SlotProps = unknown>(options: {
|
|
|
260
259
|
props: {
|
|
261
260
|
/** An object to include in this property */
|
|
262
261
|
children?: React.ReactNode;
|
|
263
|
-
} & SlotProps
|
|
262
|
+
} & SlotProps,
|
|
264
263
|
) => {
|
|
265
264
|
const { children, ...other } = props;
|
|
266
265
|
return (
|
|
@@ -10,7 +10,7 @@ describe("string template binding", () => {
|
|
|
10
10
|
test("returns string ref versions", () => {
|
|
11
11
|
expect(b`foo.bar.baz`.toRefString()).toBe("{{foo.bar.baz}}");
|
|
12
12
|
expect(b`foo.bar.${b`foo.bar`}`.toRefString()).toBe(
|
|
13
|
-
"{{foo.bar.{{foo.bar}}}}"
|
|
13
|
+
"{{foo.bar.{{foo.bar}}}}",
|
|
14
14
|
);
|
|
15
15
|
});
|
|
16
16
|
|
|
@@ -20,13 +20,13 @@ describe("string template binding", () => {
|
|
|
20
20
|
|
|
21
21
|
const expr = e`test() == "foo"`;
|
|
22
22
|
expect(b`${expr}.${expr}`.toValue()).toBe(
|
|
23
|
-
'`test() == "foo"`.`test() == "foo"`'
|
|
23
|
+
'`test() == "foo"`.`test() == "foo"`',
|
|
24
24
|
);
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
test("works when in a string", () => {
|
|
28
28
|
expect(`This is a ${b`foo.bar`} reference.`).toBe(
|
|
29
|
-
"This is a {{foo.bar}} reference."
|
|
29
|
+
"This is a {{foo.bar}} reference.",
|
|
30
30
|
);
|
|
31
31
|
});
|
|
32
32
|
|
|
@@ -38,11 +38,11 @@ describe("string template binding", () => {
|
|
|
38
38
|
test("should provide unique identifiers for each _index_ provided for the binding in the template", () => {
|
|
39
39
|
const segments = ["some", "_index_", "data", "_index_", "foo", "_index_"];
|
|
40
40
|
expect(b`${segments.join(".")}`.toValue()).toBe(
|
|
41
|
-
"some._index_.data._index1_.foo._index2_"
|
|
41
|
+
"some._index_.data._index1_.foo._index2_",
|
|
42
42
|
);
|
|
43
43
|
|
|
44
44
|
expect(b`${segments.join(".")}`.toRefString()).toBe(
|
|
45
|
-
"{{some._index_.data._index1_.foo._index2_}}"
|
|
45
|
+
"{{some._index_.data._index1_.foo._index2_}}",
|
|
46
46
|
);
|
|
47
47
|
});
|
|
48
48
|
|
|
@@ -57,11 +57,11 @@ describe("string template binding", () => {
|
|
|
57
57
|
const segments = ["some", "_index_", "data", "_index_", "foo", "_index_"];
|
|
58
58
|
|
|
59
59
|
const expressionNestedBindings = e`test(${b`${segments.join(
|
|
60
|
-
"."
|
|
60
|
+
".",
|
|
61
61
|
)}`})`.toValue();
|
|
62
62
|
|
|
63
63
|
expect(expressionNestedBindings).toBe(
|
|
64
|
-
"test({{some._index_.data._index1_.foo._index2_}})"
|
|
64
|
+
"test({{some._index_.data._index1_.foo._index2_}})",
|
|
65
65
|
);
|
|
66
66
|
});
|
|
67
67
|
|
|
@@ -77,11 +77,11 @@ describe("string template binding", () => {
|
|
|
77
77
|
];
|
|
78
78
|
|
|
79
79
|
const expressionNestedBindings = e`test(${b`${segments.join(
|
|
80
|
-
"."
|
|
80
|
+
".",
|
|
81
81
|
)}`} == true, ${b`some._index_.data`} = ${b`some._index_.other._index_.data`})`.toValue();
|
|
82
82
|
|
|
83
83
|
expect(expressionNestedBindings).toBe(
|
|
84
|
-
"test({{some._index_.data._index1_.foo._index2_.bar}} == true, {{some._index_.data}} = {{some._index_.other._index1_.data}})"
|
|
84
|
+
"test({{some._index_.data._index1_.foo._index2_.bar}} == true, {{some._index_.data}} = {{some._index_.other._index1_.data}})",
|
|
85
85
|
);
|
|
86
86
|
});
|
|
87
87
|
});
|
|
@@ -10,6 +10,7 @@ test("works with nested expressions", () => {
|
|
|
10
10
|
|
|
11
11
|
test("throws errors for syntactically wrong expressions", () => {
|
|
12
12
|
expect(() => {
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
13
14
|
const exp = e`something(1,2`;
|
|
14
15
|
}).toThrowErrorMatchingInlineSnapshot(`
|
|
15
16
|
[Error: Error: Expected ) at character 13 in expression:
|
|
@@ -11,7 +11,7 @@ test("can be used as a react child element", async () => {
|
|
|
11
11
|
<object>
|
|
12
12
|
<property name="expression">{e`test()`}</property>
|
|
13
13
|
<property name="binding">{b`foo.bar`}</property>
|
|
14
|
-
</object
|
|
14
|
+
</object>,
|
|
15
15
|
)
|
|
16
16
|
).jsonValue;
|
|
17
17
|
|
|
@@ -26,7 +26,7 @@ test("Works when used as a child asset", async () => {
|
|
|
26
26
|
await render(
|
|
27
27
|
<Collection>
|
|
28
28
|
<Collection.Label>{b`foo.bar`}</Collection.Label>
|
|
29
|
-
</Collection
|
|
29
|
+
</Collection>,
|
|
30
30
|
)
|
|
31
31
|
).jsonValue;
|
|
32
32
|
|
|
@@ -52,7 +52,7 @@ test("Works as a switch child", async () => {
|
|
|
52
52
|
<Switch.Case>Testing 123 {b`foo.bar`}</Switch.Case>
|
|
53
53
|
</Switch>
|
|
54
54
|
</Collection.Label>
|
|
55
|
-
</Collection
|
|
55
|
+
</Collection>,
|
|
56
56
|
)
|
|
57
57
|
).jsonValue;
|
|
58
58
|
|
|
@@ -18,7 +18,7 @@ export interface TemplateInstanceRefStringOptions {
|
|
|
18
18
|
/** Convert the value to a reference nested in the given context */
|
|
19
19
|
toRefString: (
|
|
20
20
|
options: TemplateRefStringOptions | undefined,
|
|
21
|
-
value: string
|
|
21
|
+
value: string,
|
|
22
22
|
) => string;
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -55,13 +55,13 @@ export const TemplateStringComponent = (props: {
|
|
|
55
55
|
{
|
|
56
56
|
value: props.value,
|
|
57
57
|
},
|
|
58
|
-
null
|
|
58
|
+
null,
|
|
59
59
|
);
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
/** The generic template string handler */
|
|
63
63
|
const createTemplateInstance = (
|
|
64
|
-
options: TemplateInstanceRefStringOptions
|
|
64
|
+
options: TemplateInstanceRefStringOptions,
|
|
65
65
|
): TemplateStringType => {
|
|
66
66
|
const value = options.strings.reduce((sum, next, i) => {
|
|
67
67
|
const element = options.other[i];
|
|
@@ -109,7 +109,7 @@ const createTemplateInstance = (
|
|
|
109
109
|
{
|
|
110
110
|
value: toString(),
|
|
111
111
|
},
|
|
112
|
-
null
|
|
112
|
+
null,
|
|
113
113
|
) as TemplateStringType;
|
|
114
114
|
|
|
115
115
|
return {
|
|
@@ -137,15 +137,15 @@ const addBindingIndexes = (binding: string): string => {
|
|
|
137
137
|
|
|
138
138
|
/** Creating an instance of a handler for bindings */
|
|
139
139
|
const createBindingTemplateInstance = (
|
|
140
|
-
options: Omit<TemplateInstanceRefStringOptions, "toRefString"
|
|
140
|
+
options: Omit<TemplateInstanceRefStringOptions, "toRefString">,
|
|
141
141
|
): BindingTemplateInstance => {
|
|
142
142
|
const templateInstance = createTemplateInstance({
|
|
143
143
|
...options,
|
|
144
144
|
strings: options.strings.map((element: string) =>
|
|
145
|
-
addBindingIndexes(element)
|
|
145
|
+
addBindingIndexes(element),
|
|
146
146
|
),
|
|
147
147
|
other: options.other.map((element) =>
|
|
148
|
-
typeof element === "string" ? addBindingIndexes(element) : element
|
|
148
|
+
typeof element === "string" ? addBindingIndexes(element) : element,
|
|
149
149
|
),
|
|
150
150
|
toRefString: (context, value) => {
|
|
151
151
|
return `{{${value}}}`;
|
|
@@ -159,7 +159,7 @@ const createBindingTemplateInstance = (
|
|
|
159
159
|
|
|
160
160
|
/** Creating an instance of a handler for bindings */
|
|
161
161
|
const createExpressionTemplateInstance = (
|
|
162
|
-
options: Omit<TemplateInstanceRefStringOptions, "toRefString"
|
|
162
|
+
options: Omit<TemplateInstanceRefStringOptions, "toRefString">,
|
|
163
163
|
) => {
|
|
164
164
|
const templateInstance = createTemplateInstance({
|
|
165
165
|
...options,
|
|
@@ -206,7 +206,7 @@ export const expression = (
|
|
|
206
206
|
|
|
207
207
|
/** Check if a value is a template string */
|
|
208
208
|
export const isTemplateStringInstance = (
|
|
209
|
-
val: unknown
|
|
209
|
+
val: unknown,
|
|
210
210
|
): val is ExpressionTemplateInstance | BindingTemplateInstance => {
|
|
211
211
|
return (
|
|
212
212
|
val !== null &&
|
|
@@ -217,7 +217,7 @@ export const isTemplateStringInstance = (
|
|
|
217
217
|
|
|
218
218
|
/** Check if a value is a binding */
|
|
219
219
|
export const isBindingTemplateInstance = (
|
|
220
|
-
val: unknown
|
|
220
|
+
val: unknown,
|
|
221
221
|
): val is BindingTemplateInstance => {
|
|
222
222
|
return (
|
|
223
223
|
val !== null &&
|
package/src/switch.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PropsWithChildren } from "react";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import type { ArrayNode, JsonNode, ObjectNode } from "react-json-reconciler";
|
|
4
|
-
import { flattenNodes
|
|
4
|
+
import { flattenNodes } from "react-json-reconciler";
|
|
5
5
|
import { SlotContext } from ".";
|
|
6
6
|
import { IDSuffixProvider, OptionalIDSuffixProvider } from "./auto-id";
|
|
7
7
|
import type {
|