@player-tools/dsl 0.11.0--canary.212.4707 → 0.11.0
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 +40 -110
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +40 -100
- package/dist/index.mjs +40 -100
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/helpers/mock-data-refs.ts +1 -1
- package/src/__tests__/template.test.tsx +126 -30
- package/src/__tests__/util.test.tsx +8 -185
- package/src/compiler/schema.ts +7 -15
- package/src/index.ts +0 -1
- package/src/string-templates/index.ts +10 -20
- package/src/template.tsx +86 -25
- package/src/types.ts +1 -27
- package/src/utils.tsx +6 -65
- package/types/compiler/schema.d.ts +2 -5
- package/types/index.d.ts +0 -1
- package/types/string-templates/index.d.ts +7 -9
- package/types/template.d.ts +2 -0
- package/types/types.d.ts +1 -11
- package/types/utils.d.ts +3 -15
- package/src/expressions/__tests__/native.test.tsx +0 -159
- package/src/expressions/native.ts +0 -141
- package/types/expressions/native.d.ts +0 -50
package/dist/cjs/index.cjs
CHANGED
|
@@ -50,15 +50,11 @@ __export(src_exports, {
|
|
|
50
50
|
TemplateContext: () => TemplateContext,
|
|
51
51
|
TemplateStringComponent: () => TemplateStringComponent,
|
|
52
52
|
View: () => View,
|
|
53
|
-
and: () => and,
|
|
54
|
-
assign: () => assign,
|
|
55
53
|
binding: () => binding,
|
|
56
54
|
createSlot: () => createSlot,
|
|
57
|
-
equals: () => equals,
|
|
58
55
|
expression: () => expression,
|
|
59
56
|
fingerprintContent: () => fingerprintContent,
|
|
60
57
|
flattenChildren: () => flattenChildren,
|
|
61
|
-
generateDSLFunction: () => generateDSLFunction,
|
|
62
58
|
getBindingFromObject: () => getBindingFromObject,
|
|
63
59
|
getBindingStringFromObject: () => getBindingStringFromObject,
|
|
64
60
|
getObjectReferences: () => getObjectReferences,
|
|
@@ -67,20 +63,14 @@ __export(src_exports, {
|
|
|
67
63
|
isDefaultCompilerContentType: () => isDefaultCompilerContentType,
|
|
68
64
|
isTemplateStringInstance: () => isTemplateStringInstance,
|
|
69
65
|
makeBindingsForObject: () => makeBindingsForObject,
|
|
70
|
-
mapExpressionHandlersToFunctions: () => mapExpressionHandlersToFunctions,
|
|
71
66
|
mergeRefs: () => mergeRefs,
|
|
72
|
-
nand: () => nand,
|
|
73
|
-
nor: () => nor,
|
|
74
67
|
normalizeText: () => normalizeText,
|
|
75
68
|
normalizeToCollection: () => normalizeToCollection,
|
|
76
|
-
not: () => not,
|
|
77
|
-
or: () => or,
|
|
78
69
|
toArray: () => toArray,
|
|
79
70
|
toJsonElement: () => toJsonElement,
|
|
80
71
|
toJsonProperties: () => toJsonProperties,
|
|
81
72
|
useGetIdPrefix: () => useGetIdPrefix,
|
|
82
|
-
useIndexInSlot: () => useIndexInSlot
|
|
83
|
-
wrapFunctionInType: () => wrapFunctionInType
|
|
73
|
+
useIndexInSlot: () => useIndexInSlot
|
|
84
74
|
});
|
|
85
75
|
module.exports = __toCommonJS(src_exports);
|
|
86
76
|
|
|
@@ -368,36 +358,6 @@ function getObjectReferences(propertiesObject) {
|
|
|
368
358
|
}
|
|
369
359
|
return result;
|
|
370
360
|
}
|
|
371
|
-
function parseArg(arg, deref = false) {
|
|
372
|
-
if (isTemplateStringInstance(arg)) {
|
|
373
|
-
return `'${deref ? arg.toRefString() : arg.toValue()}'`;
|
|
374
|
-
} else if (Array.isArray(arg)) {
|
|
375
|
-
return `[${arg.map((a) => parseArg(a, true)).join(", ")}]`;
|
|
376
|
-
} else if (typeof arg === "string") {
|
|
377
|
-
return `'${arg}'`;
|
|
378
|
-
} else {
|
|
379
|
-
return arg;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
function generateDSLFunction(name, args) {
|
|
383
|
-
const expressionArgs = [];
|
|
384
|
-
args.forEach((arg) => {
|
|
385
|
-
expressionArgs.push(parseArg(arg));
|
|
386
|
-
});
|
|
387
|
-
return expression`${name}(${expressionArgs.join(", ")})`;
|
|
388
|
-
}
|
|
389
|
-
function wrapFunctionInType(fn) {
|
|
390
|
-
return (...args) => {
|
|
391
|
-
return generateDSLFunction(fn.name, args);
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
function mapExpressionHandlersToFunctions(functions) {
|
|
395
|
-
const result = {};
|
|
396
|
-
for (const fn of Object.values(functions)) {
|
|
397
|
-
result[fn.name] = wrapFunctionInType(fn);
|
|
398
|
-
}
|
|
399
|
-
return result;
|
|
400
|
-
}
|
|
401
361
|
|
|
402
362
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/components.tsx
|
|
403
363
|
var SlotContext = import_react2.default.createContext(void 0);
|
|
@@ -572,6 +532,39 @@ var import_react_json_reconciler3 = require("react-json-reconciler");
|
|
|
572
532
|
var TemplateContext = import_react4.default.createContext({
|
|
573
533
|
depth: 0
|
|
574
534
|
});
|
|
535
|
+
function determinePositionInfo(proxyNode) {
|
|
536
|
+
const result = {
|
|
537
|
+
placement: void 0,
|
|
538
|
+
insertionIndex: void 0
|
|
539
|
+
};
|
|
540
|
+
if (!proxyNode || !proxyNode.parent) {
|
|
541
|
+
return result;
|
|
542
|
+
}
|
|
543
|
+
if (proxyNode.parent.type === "array") {
|
|
544
|
+
const parentArray = proxyNode.parent;
|
|
545
|
+
const proxyIndex = parentArray.items.indexOf(proxyNode);
|
|
546
|
+
const hasNonProxyBefore = parentArray.items.slice(0, proxyIndex).some((item) => item.type !== "proxy");
|
|
547
|
+
const hasNonProxyAfter = parentArray.items.slice(proxyIndex + 1).some((item) => item.type !== "proxy");
|
|
548
|
+
if (hasNonProxyBefore) {
|
|
549
|
+
result.placement = "append";
|
|
550
|
+
} else if (hasNonProxyAfter) {
|
|
551
|
+
result.placement = "prepend";
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
const containingSlot = proxyNode.parent?.parent;
|
|
555
|
+
if (containingSlot && containingSlot.type === "property" && containingSlot.keyNode.type === "value") {
|
|
556
|
+
const parentObject = getParentObject(proxyNode);
|
|
557
|
+
if (parentObject) {
|
|
558
|
+
const index = parentObject.properties.findIndex((properties) => {
|
|
559
|
+
return properties.keyNode.value === containingSlot.keyNode.value;
|
|
560
|
+
});
|
|
561
|
+
if (index !== -1) {
|
|
562
|
+
result.insertionIndex = result.placement === "prepend" ? index : index + 1;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
return result;
|
|
567
|
+
}
|
|
575
568
|
function addTemplateToObject(obj, templateObj, templateParentNodeType, insertionIndex) {
|
|
576
569
|
let templateProp = obj.properties.find(
|
|
577
570
|
(p) => p.keyNode.value === "template" && p.valueNode?.type === "array"
|
|
@@ -653,18 +646,7 @@ var Template = (props) => {
|
|
|
653
646
|
if (!outputProp) {
|
|
654
647
|
return;
|
|
655
648
|
}
|
|
656
|
-
|
|
657
|
-
if (proxyRef.current.parent && proxyRef.current.parent.type === "array" && proxyRef.current.parent.items[0].type === "proxy") {
|
|
658
|
-
prefix = true;
|
|
659
|
-
}
|
|
660
|
-
const containingSlot = proxyRef.current.parent?.parent;
|
|
661
|
-
let insertionIndex = void 0;
|
|
662
|
-
if (containingSlot && containingSlot.type === "property" && containingSlot.keyNode.type === "value") {
|
|
663
|
-
insertionIndex = parentObject.properties.findIndex((properties) => {
|
|
664
|
-
return properties.keyNode.value === containingSlot.keyNode.value;
|
|
665
|
-
});
|
|
666
|
-
insertionIndex = prefix ? insertionIndex : insertionIndex + 1;
|
|
667
|
-
}
|
|
649
|
+
const { insertionIndex } = determinePositionInfo(proxyRef.current);
|
|
668
650
|
return addTemplateToObject(
|
|
669
651
|
parentObject,
|
|
670
652
|
templateObj,
|
|
@@ -673,6 +655,10 @@ var Template = (props) => {
|
|
|
673
655
|
);
|
|
674
656
|
}
|
|
675
657
|
}, [proxyRef, outputProp, outputElement.items]);
|
|
658
|
+
const { placement: inferredPlacement } = determinePositionInfo(
|
|
659
|
+
proxyRef.current
|
|
660
|
+
);
|
|
661
|
+
const resolvedPlacement = props.placement || inferredPlacement;
|
|
676
662
|
return /* @__PURE__ */ import_react4.default.createElement("proxy", { ref: proxyRef }, /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, (0, import_react_json_reconciler3.createPortal)(
|
|
677
663
|
/* @__PURE__ */ import_react4.default.createElement(
|
|
678
664
|
OptionalIDSuffixProvider,
|
|
@@ -680,7 +666,7 @@ var Template = (props) => {
|
|
|
680
666
|
wrapperRef: valueRef,
|
|
681
667
|
templateIndex: `_index${baseContext.depth === 0 ? "" : baseContext.depth}_`
|
|
682
668
|
},
|
|
683
|
-
/* @__PURE__ */ import_react4.default.createElement(TemplateProvider, null, /* @__PURE__ */ import_react4.default.createElement("object", null, /* @__PURE__ */ import_react4.default.createElement("property", { name: "data" }, props.data.toValue()), /* @__PURE__ */ import_react4.default.createElement("property", { name: "output" }, outputProp), /* @__PURE__ */ import_react4.default.createElement("property", { name: "value" }, props.children), dynamicProp && /* @__PURE__ */ import_react4.default.createElement("property", { name: "dynamic" }, toJsonElement(dynamicProp))))
|
|
669
|
+
/* @__PURE__ */ import_react4.default.createElement(TemplateProvider, null, /* @__PURE__ */ import_react4.default.createElement("object", null, /* @__PURE__ */ import_react4.default.createElement("property", { name: "data" }, props.data.toValue()), /* @__PURE__ */ import_react4.default.createElement("property", { name: "output" }, outputProp), /* @__PURE__ */ import_react4.default.createElement("property", { name: "value" }, props.children), dynamicProp && /* @__PURE__ */ import_react4.default.createElement("property", { name: "dynamic" }, toJsonElement(dynamicProp)), resolvedPlacement && /* @__PURE__ */ import_react4.default.createElement("property", { name: "placement" }, toJsonElement(resolvedPlacement))))
|
|
684
670
|
),
|
|
685
671
|
outputElement
|
|
686
672
|
), /* @__PURE__ */ import_react4.default.createElement("value", { ref: valueRef, value: void 0 })));
|
|
@@ -1039,52 +1025,6 @@ var DefaultCompilerContentTypes = ["view", "flow", "schema"];
|
|
|
1039
1025
|
function isDefaultCompilerContentType(t) {
|
|
1040
1026
|
return DefaultCompilerContentTypes.includes(t);
|
|
1041
1027
|
}
|
|
1042
|
-
|
|
1043
|
-
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/expressions/native.ts
|
|
1044
|
-
var escapePrimitive = (val) => {
|
|
1045
|
-
switch (typeof val) {
|
|
1046
|
-
case "string": {
|
|
1047
|
-
return `'${val}'`;
|
|
1048
|
-
}
|
|
1049
|
-
case "undefined": {
|
|
1050
|
-
return "null";
|
|
1051
|
-
}
|
|
1052
|
-
default: {
|
|
1053
|
-
return `${val}`;
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
};
|
|
1057
|
-
var handleBindingOrExpression = (val) => {
|
|
1058
|
-
if (isBindingTemplateInstance(val)) {
|
|
1059
|
-
return val.toRefString();
|
|
1060
|
-
} else {
|
|
1061
|
-
return `(${val.toValue()})`;
|
|
1062
|
-
}
|
|
1063
|
-
};
|
|
1064
|
-
var handleArgument = (arg) => {
|
|
1065
|
-
return isTemplateStringInstance(arg) ? handleBindingOrExpression(arg) : escapePrimitive(arg);
|
|
1066
|
-
};
|
|
1067
|
-
var assign = (binding2, value) => {
|
|
1068
|
-
return expression`${binding2} = ${isTemplateStringInstance(value) ? value : escapePrimitive(value)}`;
|
|
1069
|
-
};
|
|
1070
|
-
var equals = (a, b) => {
|
|
1071
|
-
return expression`${handleArgument(a)} == ${handleArgument(b)}`;
|
|
1072
|
-
};
|
|
1073
|
-
var not = (value) => {
|
|
1074
|
-
return expression`!(${value})`;
|
|
1075
|
-
};
|
|
1076
|
-
var or = (...values) => {
|
|
1077
|
-
return expression`${values.map(handleBindingOrExpression).join(" || ")}`;
|
|
1078
|
-
};
|
|
1079
|
-
var nor = (...values) => {
|
|
1080
|
-
return not(or(...values));
|
|
1081
|
-
};
|
|
1082
|
-
var and = (...values) => {
|
|
1083
|
-
return expression`${values.map(handleBindingOrExpression).join(" && ")}`;
|
|
1084
|
-
};
|
|
1085
|
-
var nand = (...values) => {
|
|
1086
|
-
return not(and(...values));
|
|
1087
|
-
};
|
|
1088
1028
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1089
1029
|
0 && (module.exports = {
|
|
1090
1030
|
Asset,
|
|
@@ -1106,15 +1046,11 @@ var nand = (...values) => {
|
|
|
1106
1046
|
TemplateContext,
|
|
1107
1047
|
TemplateStringComponent,
|
|
1108
1048
|
View,
|
|
1109
|
-
and,
|
|
1110
|
-
assign,
|
|
1111
1049
|
binding,
|
|
1112
1050
|
createSlot,
|
|
1113
|
-
equals,
|
|
1114
1051
|
expression,
|
|
1115
1052
|
fingerprintContent,
|
|
1116
1053
|
flattenChildren,
|
|
1117
|
-
generateDSLFunction,
|
|
1118
1054
|
getBindingFromObject,
|
|
1119
1055
|
getBindingStringFromObject,
|
|
1120
1056
|
getObjectReferences,
|
|
@@ -1123,20 +1059,14 @@ var nand = (...values) => {
|
|
|
1123
1059
|
isDefaultCompilerContentType,
|
|
1124
1060
|
isTemplateStringInstance,
|
|
1125
1061
|
makeBindingsForObject,
|
|
1126
|
-
mapExpressionHandlersToFunctions,
|
|
1127
1062
|
mergeRefs,
|
|
1128
|
-
nand,
|
|
1129
|
-
nor,
|
|
1130
1063
|
normalizeText,
|
|
1131
1064
|
normalizeToCollection,
|
|
1132
|
-
not,
|
|
1133
|
-
or,
|
|
1134
1065
|
toArray,
|
|
1135
1066
|
toJsonElement,
|
|
1136
1067
|
toJsonProperties,
|
|
1137
1068
|
useGetIdPrefix,
|
|
1138
1069
|
useIndexInSlot,
|
|
1139
|
-
wrapFunctionInType,
|
|
1140
1070
|
...require("react-json-reconciler")
|
|
1141
1071
|
});
|
|
1142
1072
|
//# sourceMappingURL=index.cjs.map
|