@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
package/src/template.tsx
CHANGED
|
@@ -41,13 +41,13 @@ function addTemplateToObject(
|
|
|
41
41
|
obj: ObjectNode,
|
|
42
42
|
templateObj: ObjectNode,
|
|
43
43
|
templateParentNodeType: string,
|
|
44
|
-
insertionIndex: number | undefined
|
|
44
|
+
insertionIndex: number | undefined,
|
|
45
45
|
): () => void {
|
|
46
46
|
// find a template property
|
|
47
47
|
// add one if none exists
|
|
48
48
|
|
|
49
49
|
let templateProp = obj.properties.find(
|
|
50
|
-
(p) => p.keyNode.value === "template" && p.valueNode?.type === "array"
|
|
50
|
+
(p) => p.keyNode.value === "template" && p.valueNode?.type === "array",
|
|
51
51
|
);
|
|
52
52
|
|
|
53
53
|
if (!templateProp) {
|
|
@@ -56,20 +56,20 @@ function addTemplateToObject(
|
|
|
56
56
|
obj.properties.splice(
|
|
57
57
|
insertionIndex ?? obj.properties.length - 1,
|
|
58
58
|
0,
|
|
59
|
-
templateProp
|
|
59
|
+
templateProp,
|
|
60
60
|
);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
const templateItems = templateProp.valueNode as ArrayNode;
|
|
64
64
|
|
|
65
65
|
templateItems.items.push(templateObj);
|
|
66
|
-
|
|
66
|
+
|
|
67
67
|
templateObj.parent = templateItems;
|
|
68
68
|
|
|
69
69
|
const templateParentProp = obj.properties.find(
|
|
70
70
|
(p) =>
|
|
71
71
|
p.keyNode.value === templateParentNodeType &&
|
|
72
|
-
p.valueNode?.type === "array"
|
|
72
|
+
p.valueNode?.type === "array",
|
|
73
73
|
);
|
|
74
74
|
|
|
75
75
|
if (templateParentProp) {
|
|
@@ -138,7 +138,7 @@ export const Template = (props: TemplateProps) => {
|
|
|
138
138
|
const baseContext = React.useContext(TemplateContext);
|
|
139
139
|
const dynamicProp = props.dynamic ?? false;
|
|
140
140
|
const [outputProp, setOutputProp] = React.useState<string | undefined>(
|
|
141
|
-
props.output
|
|
141
|
+
props.output,
|
|
142
142
|
);
|
|
143
143
|
const proxyRef = React.useRef<ProxyNode>(null);
|
|
144
144
|
const valueRef = React.useRef<ValueNode>(null);
|
|
@@ -193,7 +193,7 @@ export const Template = (props: TemplateProps) => {
|
|
|
193
193
|
parentObject,
|
|
194
194
|
templateObj,
|
|
195
195
|
outputProp,
|
|
196
|
-
insertionIndex
|
|
196
|
+
insertionIndex,
|
|
197
197
|
);
|
|
198
198
|
}
|
|
199
199
|
}, [proxyRef, outputProp, outputElement.items]);
|
|
@@ -221,7 +221,7 @@ export const Template = (props: TemplateProps) => {
|
|
|
221
221
|
</object>
|
|
222
222
|
</TemplateProvider>
|
|
223
223
|
</OptionalIDSuffixProvider>,
|
|
224
|
-
outputElement
|
|
224
|
+
outputElement,
|
|
225
225
|
)}
|
|
226
226
|
<value ref={valueRef} value={undefined} />
|
|
227
227
|
</>
|
package/src/types.ts
CHANGED
|
@@ -56,11 +56,12 @@ export type SwapKeysToType<T, K extends keyof T, NewType> = {
|
|
|
56
56
|
[P in keyof T]: P extends K ? NewType : T[P];
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
export type WithTemplateTypes<T> =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
export type WithTemplateTypes<T> =
|
|
60
|
+
T extends Record<any, any>
|
|
61
|
+
? {
|
|
62
|
+
[P in keyof T]: WithTemplateTypes<T[P]>;
|
|
63
|
+
}
|
|
64
|
+
: T | BindingTemplateInstance | ExpressionTemplateInstance;
|
|
64
65
|
|
|
65
66
|
type ValidKeys = "exp" | "onStart" | "onEnd";
|
|
66
67
|
|
|
@@ -70,15 +71,15 @@ type DeepReplace<T, Old, New> = {
|
|
|
70
71
|
? New
|
|
71
72
|
: DeepReplace<T[P], Old, New> // Set to new if one of the valid keys: replace with `? New` for all keys
|
|
72
73
|
: T[P] extends (infer R)[] // Is this a Tuple or array
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
? DeepReplace<R, Old, New>[] // Replace the type of the tuple/array
|
|
75
|
+
: T[P] extends object
|
|
76
|
+
? DeepReplace<T[P], Old, New>
|
|
77
|
+
: Extract<T[P], Old> extends Old // Is this a union with the searched for type?
|
|
78
|
+
?
|
|
79
|
+
| DeepReplace<Extract<T[P], object>, Old, New> // Replace all object types of the union
|
|
80
|
+
| Exclude<T[P], Old | object> // Get all types that are not objects (handled above) or Old (handled below
|
|
81
|
+
| New // Direct Replacement of Old
|
|
82
|
+
: T[P];
|
|
82
83
|
};
|
|
83
84
|
|
|
84
85
|
export type Navigation = DeepReplace<
|
|
@@ -99,16 +100,16 @@ type RemoveIndexSignature<T> = {
|
|
|
99
100
|
[K in keyof T as string extends K
|
|
100
101
|
? never
|
|
101
102
|
: number extends K
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
? never
|
|
104
|
+
: symbol extends K
|
|
105
|
+
? never
|
|
106
|
+
: K]: T[K];
|
|
106
107
|
};
|
|
107
108
|
|
|
108
109
|
export type ValidationRefProps = RemoveIndexSignature<Validation.Reference>;
|
|
109
110
|
|
|
110
111
|
export type DataTypeRefs<
|
|
111
|
-
DataTypeObjects extends Record<string, Schema.DataType
|
|
112
|
+
DataTypeObjects extends Record<string, Schema.DataType>,
|
|
112
113
|
> = {
|
|
113
114
|
/** Property name with DataType object */
|
|
114
115
|
[Property in Extract<keyof DataTypeObjects, string> as `${Property}Ref`]: {
|
|
@@ -118,7 +119,7 @@ export type DataTypeRefs<
|
|
|
118
119
|
};
|
|
119
120
|
|
|
120
121
|
export type ValidatorFunctionRefs<
|
|
121
|
-
ValidatorObjects extends { [key: string]: (...args: any[]) => any }
|
|
122
|
+
ValidatorObjects extends { [key: string]: (...args: any[]) => any },
|
|
122
123
|
> = {
|
|
123
124
|
/** Property name with validator ref object */
|
|
124
125
|
[Property in Extract<keyof ValidatorObjects, string> as `${Property}Ref`]: {
|
|
@@ -131,7 +132,7 @@ export type ValidatorFunctionRefs<
|
|
|
131
132
|
export type DataTypeReference<
|
|
132
133
|
DataTypeProp = { [key: string]: Schema.DataType },
|
|
133
134
|
ValidationRef = { [key: string]: Validation.Reference },
|
|
134
|
-
SymbolType = never
|
|
135
|
+
SymbolType = never,
|
|
135
136
|
> =
|
|
136
137
|
| (Omit<Schema.DataType, "type" | "validation"> & {
|
|
137
138
|
/** Handled data type */
|
package/src/utils.tsx
CHANGED
|
@@ -14,7 +14,7 @@ export function toArray<T>(val: T | Array<T>): Array<T> {
|
|
|
14
14
|
export function toJsonElement(
|
|
15
15
|
value: any,
|
|
16
16
|
indexOrKey?: number | string,
|
|
17
|
-
options?: toJsonOptions
|
|
17
|
+
options?: toJsonOptions,
|
|
18
18
|
): React.ReactElement {
|
|
19
19
|
const indexProp = typeof indexOrKey === "number" ? { key: indexOrKey } : null;
|
|
20
20
|
|
|
@@ -56,7 +56,7 @@ export function toJsonElement(
|
|
|
56
56
|
/** Create a fragment for the properties */
|
|
57
57
|
export function toJsonProperties(
|
|
58
58
|
value: Record<string, any>,
|
|
59
|
-
options: toJsonOptions = { propertiesToSkip: ["applicability"] }
|
|
59
|
+
options: toJsonOptions = { propertiesToSkip: ["applicability"] },
|
|
60
60
|
) {
|
|
61
61
|
return Object.keys(value).map((key) => {
|
|
62
62
|
return (
|
|
@@ -81,7 +81,7 @@ export function normalizeText(options: {
|
|
|
81
81
|
|
|
82
82
|
if (
|
|
83
83
|
nodeArr.every(
|
|
84
|
-
(n) => React.isValidElement(n) && n.type !== TemplateStringComponent
|
|
84
|
+
(n) => React.isValidElement(n) && n.type !== TemplateStringComponent,
|
|
85
85
|
)
|
|
86
86
|
) {
|
|
87
87
|
return node;
|
|
@@ -92,7 +92,7 @@ export function normalizeText(options: {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
throw new Error(
|
|
95
|
-
`Tried to convert node to Text Asset, but no Component was supplied
|
|
95
|
+
`Tried to convert node to Text Asset, but no Component was supplied.`,
|
|
96
96
|
);
|
|
97
97
|
}
|
|
98
98
|
|
|
@@ -115,7 +115,7 @@ export function normalizeToCollection(options: {
|
|
|
115
115
|
) {
|
|
116
116
|
if (!CollectionComp) {
|
|
117
117
|
throw new Error(
|
|
118
|
-
`Tried to convert array to a collection asset, but no Component was given
|
|
118
|
+
`Tried to convert array to a collection asset, but no Component was given.`,
|
|
119
119
|
);
|
|
120
120
|
}
|
|
121
121
|
|
|
@@ -137,7 +137,7 @@ export function flattenChildren(children: React.ReactNode): ReactChildArray {
|
|
|
137
137
|
return childrenArray.reduce((flatChildren: ReactChildArray, child) => {
|
|
138
138
|
if ((child as React.ReactElement<any>).type === React.Fragment) {
|
|
139
139
|
return flatChildren.concat(
|
|
140
|
-
flattenChildren((child as React.ReactElement<any>).props.children)
|
|
140
|
+
flattenChildren((child as React.ReactElement<any>).props.children),
|
|
141
141
|
);
|
|
142
142
|
}
|
|
143
143
|
|
|
@@ -152,7 +152,9 @@ export function flattenChildren(children: React.ReactNode): ReactChildArray {
|
|
|
152
152
|
* used in an esm environment
|
|
153
153
|
*/
|
|
154
154
|
export function mergeRefs<T = any>(
|
|
155
|
-
refs: Array<
|
|
155
|
+
refs: Array<
|
|
156
|
+
React.MutableRefObject<T> | React.LegacyRef<T> | undefined | null
|
|
157
|
+
>,
|
|
156
158
|
): React.RefCallback<T> {
|
|
157
159
|
return (value) => {
|
|
158
160
|
refs.forEach((ref) => {
|
|
@@ -168,7 +170,7 @@ export function mergeRefs<T = any>(
|
|
|
168
170
|
/** Generates object reference properties from the provided object */
|
|
169
171
|
export function getObjectReferences<
|
|
170
172
|
OriginalPropertiesObject extends Record<string, unknown>,
|
|
171
|
-
ReferencesPropertyObject extends Record<string, unknown
|
|
173
|
+
ReferencesPropertyObject extends Record<string, unknown>,
|
|
172
174
|
>(propertiesObject: OriginalPropertiesObject): ReferencesPropertyObject {
|
|
173
175
|
const result: any = {};
|
|
174
176
|
|