@player-tools/dsl 0.13.0-next.5 → 1.0.0--canary.245.6238
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 +43 -29
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +43 -29
- package/dist/index.mjs +43 -29
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/cjs/index.cjs
CHANGED
|
@@ -119,10 +119,11 @@ var useIndexInSlot = (ref) => {
|
|
|
119
119
|
const [index, setIndex] = import_react.default.useState(-1);
|
|
120
120
|
const slotContext = import_react.default.useContext(SlotContext);
|
|
121
121
|
import_react.default.useEffect(() => {
|
|
122
|
-
|
|
122
|
+
var _a, _b;
|
|
123
|
+
if (!(slotContext == null ? void 0 : slotContext.isArray)) {
|
|
123
124
|
throw new Error("Cannot get index in non-array slot");
|
|
124
125
|
}
|
|
125
|
-
if (ref.current && slotContext
|
|
126
|
+
if (ref.current && ((_b = (_a = slotContext == null ? void 0 : slotContext.ref.current) == null ? void 0 : _a.valueNode) == null ? void 0 : _b.type) === "array") {
|
|
126
127
|
const allChildren = (0, import_react_json_reconciler.flattenNodes)(
|
|
127
128
|
slotContext.ref.current.valueNode.children
|
|
128
129
|
);
|
|
@@ -131,7 +132,7 @@ var useIndexInSlot = (ref) => {
|
|
|
131
132
|
setIndex(foundIndex);
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
|
-
}, [index, ref, slotContext
|
|
135
|
+
}, [index, ref, slotContext == null ? void 0 : slotContext.isArray, slotContext == null ? void 0 : slotContext.ref]);
|
|
135
136
|
return index;
|
|
136
137
|
};
|
|
137
138
|
var IDSuffixIndexProvider = (props) => {
|
|
@@ -144,7 +145,7 @@ var IDSuffixIndexProvider = (props) => {
|
|
|
144
145
|
};
|
|
145
146
|
var OptionalIDSuffixProvider = (props) => {
|
|
146
147
|
const slotContext = import_react.default.useContext(SlotContext);
|
|
147
|
-
if (slotContext
|
|
148
|
+
if (slotContext == null ? void 0 : slotContext.isArray) {
|
|
148
149
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
149
150
|
IDSuffixIndexProvider,
|
|
150
151
|
{
|
|
@@ -183,7 +184,7 @@ var createTemplateInstance = (options) => {
|
|
|
183
184
|
if (typeof element2 === "string") {
|
|
184
185
|
return sum + next + element2;
|
|
185
186
|
}
|
|
186
|
-
return sum + next + (element2
|
|
187
|
+
return sum + next + ((element2 == null ? void 0 : element2.toRefString(options)) ?? "");
|
|
187
188
|
}, "");
|
|
188
189
|
if (options.nestedContext === "expression") {
|
|
189
190
|
try {
|
|
@@ -253,10 +254,10 @@ var createExpressionTemplateInstance = (options) => {
|
|
|
253
254
|
const templateInstance = createTemplateInstance({
|
|
254
255
|
...options,
|
|
255
256
|
toRefString: (contextOptions, value) => {
|
|
256
|
-
if (contextOptions
|
|
257
|
+
if ((contextOptions == null ? void 0 : contextOptions.nestedContext) === "expression") {
|
|
257
258
|
return value;
|
|
258
259
|
}
|
|
259
|
-
const inBinding = contextOptions
|
|
260
|
+
const inBinding = (contextOptions == null ? void 0 : contextOptions.nestedContext) === "binding";
|
|
260
261
|
return `${inBinding ? "`" : "@["}${value}${inBinding ? "`" : "]@"}`;
|
|
261
262
|
}
|
|
262
263
|
});
|
|
@@ -289,9 +290,10 @@ function toArray(val) {
|
|
|
289
290
|
return Array.isArray(val) ? val : [val];
|
|
290
291
|
}
|
|
291
292
|
function toJsonElement(value, indexOrKey, options) {
|
|
293
|
+
var _a;
|
|
292
294
|
const indexProp = typeof indexOrKey === "number" ? { key: indexOrKey } : null;
|
|
293
295
|
if (isTemplateStringInstance(value)) {
|
|
294
|
-
if (typeof indexOrKey === "string" && options
|
|
296
|
+
if (typeof indexOrKey === "string" && ((_a = options == null ? void 0 : options.propertiesToSkip) == null ? void 0 : _a.includes(indexOrKey))) {
|
|
295
297
|
return /* @__PURE__ */ React3.createElement("value", { ...indexProp }, value.toValue());
|
|
296
298
|
}
|
|
297
299
|
return /* @__PURE__ */ React3.createElement("value", { ...indexProp }, value.toRefString());
|
|
@@ -419,7 +421,7 @@ var Asset = import_react2.default.forwardRef((props, ref) => {
|
|
|
419
421
|
const { id, type, applicability, children, ...rest } = props;
|
|
420
422
|
const slotContext = import_react2.default.useContext(SlotContext);
|
|
421
423
|
const localRef = import_react2.default.useRef(null);
|
|
422
|
-
const Wrapper = slotContext
|
|
424
|
+
const Wrapper = (slotContext == null ? void 0 : slotContext.wrapInAsset) ? AssetWrapper : import_react2.default.Fragment;
|
|
423
425
|
const getResolvedValue = () => {
|
|
424
426
|
if (applicability !== void 0) {
|
|
425
427
|
if (typeof applicability === "boolean") {
|
|
@@ -434,13 +436,13 @@ var Asset = import_react2.default.forwardRef((props, ref) => {
|
|
|
434
436
|
return /* @__PURE__ */ import_react2.default.createElement(
|
|
435
437
|
Wrapper,
|
|
436
438
|
{
|
|
437
|
-
ref: slotContext
|
|
438
|
-
...slotContext
|
|
439
|
+
ref: (slotContext == null ? void 0 : slotContext.wrapInAsset) ? mergeRefs([ref, localRef]) : void 0,
|
|
440
|
+
...(slotContext == null ? void 0 : slotContext.wrapInAsset) && (slotContext == null ? void 0 : slotContext.additionalProperties) ? slotContext == null ? void 0 : slotContext.additionalProperties : {}
|
|
439
441
|
},
|
|
440
442
|
/* @__PURE__ */ import_react2.default.createElement(OptionalIDSuffixProvider, { wrapperRef: localRef }, /* @__PURE__ */ import_react2.default.createElement(SlotContext.Provider, { value: void 0 }, /* @__PURE__ */ import_react2.default.createElement(IDProvider, { id }, /* @__PURE__ */ import_react2.default.createElement(
|
|
441
443
|
"obj",
|
|
442
444
|
{
|
|
443
|
-
ref: slotContext
|
|
445
|
+
ref: (slotContext == null ? void 0 : slotContext.wrapInAsset) ? void 0 : mergeRefs([ref, localRef])
|
|
444
446
|
},
|
|
445
447
|
/* @__PURE__ */ import_react2.default.createElement(GeneratedIDProperty, { id }),
|
|
446
448
|
/* @__PURE__ */ import_react2.default.createElement("property", { name: "type" }, type),
|
|
@@ -514,12 +516,12 @@ var Switch = (props) => {
|
|
|
514
516
|
{
|
|
515
517
|
value: {
|
|
516
518
|
...props,
|
|
517
|
-
TextComp: slotContext
|
|
518
|
-
CollectionComp: slotContext
|
|
519
|
+
TextComp: slotContext == null ? void 0 : slotContext.TextComp,
|
|
520
|
+
CollectionComp: slotContext == null ? void 0 : slotContext.CollectionComp
|
|
519
521
|
}
|
|
520
522
|
},
|
|
521
523
|
/* @__PURE__ */ import_react3.default.createElement(OptionalIDSuffixProvider, { wrapperRef: propertyNode }, /* @__PURE__ */ import_react3.default.createElement("property", { name: props.isDynamic ? "dynamicSwitch" : "staticSwitch" }, /* @__PURE__ */ import_react3.default.createElement(SlotContext.Provider, { value: void 0 }, /* @__PURE__ */ import_react3.default.createElement("array", null, props.children))))
|
|
522
|
-
), slotContext
|
|
524
|
+
), (slotContext == null ? void 0 : slotContext.additionalProperties) && toJsonProperties(slotContext.additionalProperties));
|
|
523
525
|
};
|
|
524
526
|
var findParentArray = (node) => {
|
|
525
527
|
if (node.type === "array") {
|
|
@@ -564,8 +566,8 @@ var Case = (props) => {
|
|
|
564
566
|
},
|
|
565
567
|
/* @__PURE__ */ import_react3.default.createElement("property", { name: "asset" }, normalizeToCollection({
|
|
566
568
|
node: props.children,
|
|
567
|
-
TextComp: switchContext
|
|
568
|
-
CollectionComp: switchContext
|
|
569
|
+
TextComp: switchContext == null ? void 0 : switchContext.TextComp,
|
|
570
|
+
CollectionComp: switchContext == null ? void 0 : switchContext.CollectionComp
|
|
569
571
|
}))
|
|
570
572
|
)
|
|
571
573
|
));
|
|
@@ -579,6 +581,7 @@ var TemplateContext = import_react4.default.createContext({
|
|
|
579
581
|
depth: 0
|
|
580
582
|
});
|
|
581
583
|
function determinePositionInfo(proxyNode) {
|
|
584
|
+
var _a;
|
|
582
585
|
const result = {
|
|
583
586
|
placement: void 0,
|
|
584
587
|
insertionIndex: void 0
|
|
@@ -597,7 +600,7 @@ function determinePositionInfo(proxyNode) {
|
|
|
597
600
|
result.placement = "prepend";
|
|
598
601
|
}
|
|
599
602
|
}
|
|
600
|
-
const containingSlot = proxyNode.parent
|
|
603
|
+
const containingSlot = (_a = proxyNode.parent) == null ? void 0 : _a.parent;
|
|
601
604
|
if (containingSlot && containingSlot.type === "property" && containingSlot.keyNode.type === "value") {
|
|
602
605
|
const parentObject = getParentObject(proxyNode);
|
|
603
606
|
if (parentObject) {
|
|
@@ -612,8 +615,12 @@ function determinePositionInfo(proxyNode) {
|
|
|
612
615
|
return result;
|
|
613
616
|
}
|
|
614
617
|
function addTemplateToObject(obj, templateObj, templateParentNodeType, insertionIndex) {
|
|
618
|
+
var _a;
|
|
615
619
|
let templateProp = obj.properties.find(
|
|
616
|
-
(p) =>
|
|
620
|
+
(p) => {
|
|
621
|
+
var _a2;
|
|
622
|
+
return p.keyNode.value === "template" && ((_a2 = p.valueNode) == null ? void 0 : _a2.type) === "array";
|
|
623
|
+
}
|
|
617
624
|
);
|
|
618
625
|
if (!templateProp) {
|
|
619
626
|
templateProp = new import_react_json_reconciler3.PropertyNode(new import_react_json_reconciler3.ValueNode("template"), new import_react_json_reconciler3.ArrayNode());
|
|
@@ -628,11 +635,14 @@ function addTemplateToObject(obj, templateObj, templateParentNodeType, insertion
|
|
|
628
635
|
templateItems.items.push(templateObj);
|
|
629
636
|
templateObj.parent = templateItems;
|
|
630
637
|
const templateParentProp = obj.properties.find(
|
|
631
|
-
(p) =>
|
|
638
|
+
(p) => {
|
|
639
|
+
var _a2;
|
|
640
|
+
return p.keyNode.value === templateParentNodeType && ((_a2 = p.valueNode) == null ? void 0 : _a2.type) === "array";
|
|
641
|
+
}
|
|
632
642
|
);
|
|
633
643
|
if (templateParentProp) {
|
|
634
644
|
const indexOfTemplateParent = obj.properties.indexOf(templateParentProp, 1);
|
|
635
|
-
const templateParentValueNode = obj.properties[indexOfTemplateParent]
|
|
645
|
+
const templateParentValueNode = (_a = obj.properties[indexOfTemplateParent]) == null ? void 0 : _a.valueNode;
|
|
636
646
|
if (templateParentValueNode) {
|
|
637
647
|
const templateParentArray = (0, import_react_json_reconciler3.toJSON)(templateParentValueNode);
|
|
638
648
|
if (Array.isArray(templateParentArray) && templateParentArray.length === 0) {
|
|
@@ -781,6 +791,7 @@ var SchemaGenerator = class {
|
|
|
781
791
|
* Newly discovered children get added to the provided array
|
|
782
792
|
*/
|
|
783
793
|
processChild(property, subType) {
|
|
794
|
+
var _a;
|
|
784
795
|
if (isTypeDef(subType)) {
|
|
785
796
|
return subType;
|
|
786
797
|
}
|
|
@@ -807,7 +818,7 @@ var SchemaGenerator = class {
|
|
|
807
818
|
);
|
|
808
819
|
if (!(0, import_dequal.dequal)(
|
|
809
820
|
child,
|
|
810
|
-
this.generatedDataTypes.get(intermediateType.type)
|
|
821
|
+
(_a = this.generatedDataTypes.get(intermediateType.type)) == null ? void 0 : _a.node
|
|
811
822
|
)) {
|
|
812
823
|
generatedType.count += 1;
|
|
813
824
|
const newIntermediateType = {
|
|
@@ -871,7 +882,7 @@ function makeBindingsForObject(obj, arrayAccessorKeys = ["_index_"]) {
|
|
|
871
882
|
return new Proxy(target[key], accessor(paths.concat([key])));
|
|
872
883
|
}
|
|
873
884
|
const createdInstance = bindingMap.get(target);
|
|
874
|
-
return createdInstance
|
|
885
|
+
return createdInstance == null ? void 0 : createdInstance[key];
|
|
875
886
|
}
|
|
876
887
|
};
|
|
877
888
|
};
|
|
@@ -979,10 +990,11 @@ var DSLCompiler = class {
|
|
|
979
990
|
}
|
|
980
991
|
/** Convert an object (flow, view, schema, etc) into it's JSON representation */
|
|
981
992
|
async serialize(value, context) {
|
|
993
|
+
var _a;
|
|
982
994
|
if (typeof value !== "object" || value === null) {
|
|
983
995
|
throw new Error("Unable to serialize non-object");
|
|
984
996
|
}
|
|
985
|
-
const type = context
|
|
997
|
+
const type = (context == null ? void 0 : context.type) ? context.type : fingerprintContent(value);
|
|
986
998
|
if (!this.schemaGenerator) {
|
|
987
999
|
this.schemaGenerator = new SchemaGenerator(this.logger);
|
|
988
1000
|
this.hooks.schemaGenerator.call(this.schemaGenerator);
|
|
@@ -1002,7 +1014,7 @@ var DSLCompiler = class {
|
|
|
1002
1014
|
...value
|
|
1003
1015
|
};
|
|
1004
1016
|
copiedValue.views = await Promise.all(
|
|
1005
|
-
copiedValue
|
|
1017
|
+
((_a = copiedValue == null ? void 0 : copiedValue.views) == null ? void 0 : _a.map(async (node) => {
|
|
1006
1018
|
if (import_react6.default.isValidElement(node)) {
|
|
1007
1019
|
const { jsonValue, sourceMap, stringValue } = await (0, import_react_json_reconciler4.render)(node, {
|
|
1008
1020
|
collectSourceMap: true
|
|
@@ -1024,18 +1036,20 @@ var DSLCompiler = class {
|
|
|
1024
1036
|
return jsonValue;
|
|
1025
1037
|
}
|
|
1026
1038
|
return node;
|
|
1027
|
-
}) ?? []
|
|
1039
|
+
})) ?? []
|
|
1028
1040
|
);
|
|
1029
1041
|
if ("navigation" in value) {
|
|
1030
1042
|
Object.entries(value.navigation).forEach(([navKey, node]) => {
|
|
1031
1043
|
if (typeof node === "object") {
|
|
1032
1044
|
Object.entries(node).forEach(([nodeKey, flowNode]) => {
|
|
1045
|
+
var _a2, _b, _c, _d;
|
|
1033
1046
|
if (flowNode && typeof flowNode === "object" && "state_type" in flowNode && flowNode.state_type === "VIEW" && import_react6.default.isValidElement(flowNode.ref)) {
|
|
1034
|
-
const actualViewIndex = value.views
|
|
1047
|
+
const actualViewIndex = (_b = (_a2 = value.views) == null ? void 0 : _a2.indexOf) == null ? void 0 : _b.call(
|
|
1048
|
+
_a2,
|
|
1035
1049
|
flowNode.ref
|
|
1036
1050
|
);
|
|
1037
1051
|
if (actualViewIndex !== void 0 && actualViewIndex > -1) {
|
|
1038
|
-
const actualId = copiedValue.views
|
|
1052
|
+
const actualId = (_d = (_c = copiedValue.views) == null ? void 0 : _c[actualViewIndex]) == null ? void 0 : _d.id;
|
|
1039
1053
|
copiedValue.navigation[navKey][nodeKey].ref = actualId;
|
|
1040
1054
|
}
|
|
1041
1055
|
}
|
|
@@ -1131,7 +1145,7 @@ function testExpression(exp, initialData, expressions) {
|
|
|
1131
1145
|
});
|
|
1132
1146
|
const model = (0, import_player2.withParser)(localModel, bindingParser.parse);
|
|
1133
1147
|
const evaluator = new import_player2.ExpressionEvaluator({ model });
|
|
1134
|
-
expressions
|
|
1148
|
+
expressions == null ? void 0 : expressions.forEach((fn, name) => evaluator.addExpressionFunction(name, fn));
|
|
1135
1149
|
evaluator.evaluate(exp.toValue());
|
|
1136
1150
|
return localModel.get();
|
|
1137
1151
|
}
|