@player-ui/player 0.3.1-next.1 → 0.4.0-next.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/index.cjs.js +197 -39
- package/dist/index.d.ts +38 -13
- package/dist/index.esm.js +197 -40
- package/package.json +5 -4
- package/src/binding/resolver.ts +1 -3
- package/src/controllers/data.ts +4 -2
- package/src/controllers/validation/controller.ts +26 -13
- package/src/data/model.ts +5 -0
- package/src/expressions/evaluator.ts +1 -1
- package/src/expressions/parser.ts +64 -18
- package/src/expressions/types.ts +27 -12
- package/src/expressions/utils.ts +124 -1
- package/src/player.ts +28 -13
- package/src/string-resolver/index.ts +1 -0
- package/src/validator/validation-middleware.ts +21 -3
- package/src/view/plugins/string-resolver.ts +27 -5
package/dist/index.esm.js
CHANGED
|
@@ -834,6 +834,15 @@ function throwError(message, index) {
|
|
|
834
834
|
err.description = message;
|
|
835
835
|
throw err;
|
|
836
836
|
}
|
|
837
|
+
function createSpanningLocation(start, end) {
|
|
838
|
+
if (!start || !end) {
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
return {
|
|
842
|
+
start: start.start,
|
|
843
|
+
end: end.end
|
|
844
|
+
};
|
|
845
|
+
}
|
|
837
846
|
function getMaxKeyLen(obj) {
|
|
838
847
|
let maxLen = 0;
|
|
839
848
|
Object.keys(obj).forEach((key) => {
|
|
@@ -855,7 +864,7 @@ const thisStr = "this";
|
|
|
855
864
|
function binaryPrecedence(opVal) {
|
|
856
865
|
return binaryOps[opVal] || 0;
|
|
857
866
|
}
|
|
858
|
-
function createBinaryExpression(operator, left, right) {
|
|
867
|
+
function createBinaryExpression(operator, left, right, location) {
|
|
859
868
|
let type;
|
|
860
869
|
if (operator === "||" || operator === "&&") {
|
|
861
870
|
type = "LogicalExpression";
|
|
@@ -871,7 +880,8 @@ function createBinaryExpression(operator, left, right) {
|
|
|
871
880
|
type,
|
|
872
881
|
operator,
|
|
873
882
|
left,
|
|
874
|
-
right
|
|
883
|
+
right,
|
|
884
|
+
location
|
|
875
885
|
};
|
|
876
886
|
}
|
|
877
887
|
function isDecimalDigit(ch) {
|
|
@@ -891,6 +901,16 @@ function parseExpression(expr) {
|
|
|
891
901
|
const charCodeAtFunc = expr.charCodeAt;
|
|
892
902
|
const { length } = expr;
|
|
893
903
|
let index = 0;
|
|
904
|
+
const getLocation = (startChar) => {
|
|
905
|
+
return {
|
|
906
|
+
start: {
|
|
907
|
+
character: startChar
|
|
908
|
+
},
|
|
909
|
+
end: {
|
|
910
|
+
character: index
|
|
911
|
+
}
|
|
912
|
+
};
|
|
913
|
+
};
|
|
894
914
|
function exprI(i) {
|
|
895
915
|
return charAtFunc.call(expr, i);
|
|
896
916
|
}
|
|
@@ -904,6 +924,7 @@ function parseExpression(expr) {
|
|
|
904
924
|
let key;
|
|
905
925
|
let value;
|
|
906
926
|
let chCode;
|
|
927
|
+
const startCharIndex = index;
|
|
907
928
|
++index;
|
|
908
929
|
while (index < length) {
|
|
909
930
|
gobbleSpaces();
|
|
@@ -949,7 +970,8 @@ function parseExpression(expr) {
|
|
|
949
970
|
return {
|
|
950
971
|
__id: ExpNodeOpaqueIdentifier,
|
|
951
972
|
type: "Object",
|
|
952
|
-
attributes
|
|
973
|
+
attributes,
|
|
974
|
+
location: getLocation(startCharIndex)
|
|
953
975
|
};
|
|
954
976
|
}
|
|
955
977
|
function gobbleSpaces() {
|
|
@@ -961,6 +983,7 @@ function parseExpression(expr) {
|
|
|
961
983
|
function gobbleExpression() {
|
|
962
984
|
const test = gobbleBinaryExpression();
|
|
963
985
|
gobbleSpaces();
|
|
986
|
+
const startCharIndex = index;
|
|
964
987
|
if (index < length && exprICode(index) === QUMARK_CODE) {
|
|
965
988
|
index++;
|
|
966
989
|
const consequent = gobbleExpression();
|
|
@@ -979,7 +1002,8 @@ function parseExpression(expr) {
|
|
|
979
1002
|
type: "ConditionalExpression",
|
|
980
1003
|
test,
|
|
981
1004
|
consequent,
|
|
982
|
-
alternate
|
|
1005
|
+
alternate,
|
|
1006
|
+
location: getLocation(startCharIndex)
|
|
983
1007
|
};
|
|
984
1008
|
}
|
|
985
1009
|
throwError("Expected :", index);
|
|
@@ -1025,7 +1049,7 @@ function parseExpression(expr) {
|
|
|
1025
1049
|
right = stack.pop();
|
|
1026
1050
|
biop = stack.pop().value;
|
|
1027
1051
|
left = stack.pop();
|
|
1028
|
-
node = createBinaryExpression(biop, left, right);
|
|
1052
|
+
node = createBinaryExpression(biop, left, right, createSpanningLocation(left.location, right.location));
|
|
1029
1053
|
stack.push(node);
|
|
1030
1054
|
}
|
|
1031
1055
|
node = gobbleToken();
|
|
@@ -1038,7 +1062,7 @@ function parseExpression(expr) {
|
|
|
1038
1062
|
i = stack.length - 1;
|
|
1039
1063
|
node = stack[i];
|
|
1040
1064
|
while (i > 1) {
|
|
1041
|
-
node = createBinaryExpression(stack[i - 1].value, stack[i - 2], node);
|
|
1065
|
+
node = createBinaryExpression(stack[i - 1].value, stack[i - 2], node, createSpanningLocation(stack[i - 2].location, node.location));
|
|
1042
1066
|
i -= 2;
|
|
1043
1067
|
}
|
|
1044
1068
|
return node;
|
|
@@ -1046,6 +1070,7 @@ function parseExpression(expr) {
|
|
|
1046
1070
|
function gobbleToken() {
|
|
1047
1071
|
gobbleSpaces();
|
|
1048
1072
|
const ch = exprICode(index);
|
|
1073
|
+
const startCharIndex = index;
|
|
1049
1074
|
if (isDecimalDigit(ch) || ch === PERIOD_CODE) {
|
|
1050
1075
|
return gobbleNumericLiteral();
|
|
1051
1076
|
}
|
|
@@ -1074,7 +1099,8 @@ function parseExpression(expr) {
|
|
|
1074
1099
|
type: "UnaryExpression",
|
|
1075
1100
|
operator: toCheck,
|
|
1076
1101
|
argument: gobbleToken(),
|
|
1077
|
-
prefix: true
|
|
1102
|
+
prefix: true,
|
|
1103
|
+
location: getLocation(startCharIndex)
|
|
1078
1104
|
};
|
|
1079
1105
|
}
|
|
1080
1106
|
toCheck = toCheck.substr(0, --tcLen);
|
|
@@ -1083,6 +1109,7 @@ function parseExpression(expr) {
|
|
|
1083
1109
|
}
|
|
1084
1110
|
function gobbleNumericLiteral() {
|
|
1085
1111
|
let num = "";
|
|
1112
|
+
const startCharIndex = index;
|
|
1086
1113
|
while (isDecimalDigit(exprICode(index))) {
|
|
1087
1114
|
num += exprI(index++);
|
|
1088
1115
|
}
|
|
@@ -1116,13 +1143,15 @@ function parseExpression(expr) {
|
|
|
1116
1143
|
__id: ExpNodeOpaqueIdentifier,
|
|
1117
1144
|
type: "Literal",
|
|
1118
1145
|
value: parseFloat(num),
|
|
1119
|
-
raw: num
|
|
1146
|
+
raw: num,
|
|
1147
|
+
location: getLocation(startCharIndex)
|
|
1120
1148
|
};
|
|
1121
1149
|
}
|
|
1122
1150
|
function gobbleStringLiteral() {
|
|
1123
1151
|
const quote = exprI(index++);
|
|
1124
1152
|
let str = "";
|
|
1125
1153
|
let closed = false;
|
|
1154
|
+
const startCharIndex = index;
|
|
1126
1155
|
while (index < length) {
|
|
1127
1156
|
let ch = exprI(index++);
|
|
1128
1157
|
if (ch === quote) {
|
|
@@ -1162,13 +1191,15 @@ function parseExpression(expr) {
|
|
|
1162
1191
|
__id: ExpNodeOpaqueIdentifier,
|
|
1163
1192
|
type: "Literal",
|
|
1164
1193
|
value: str,
|
|
1165
|
-
raw: `${quote}${str}${quote}
|
|
1194
|
+
raw: `${quote}${str}${quote}`,
|
|
1195
|
+
location: getLocation(startCharIndex)
|
|
1166
1196
|
};
|
|
1167
1197
|
}
|
|
1168
1198
|
function gobbleModelRef() {
|
|
1169
1199
|
let str = "";
|
|
1170
1200
|
let closed = false;
|
|
1171
1201
|
let openBraceCount = 1;
|
|
1202
|
+
const startCharIndex = index;
|
|
1172
1203
|
index += 2;
|
|
1173
1204
|
while (index < length) {
|
|
1174
1205
|
const ch = exprI(index++);
|
|
@@ -1194,7 +1225,8 @@ function parseExpression(expr) {
|
|
|
1194
1225
|
return {
|
|
1195
1226
|
__id: ExpNodeOpaqueIdentifier,
|
|
1196
1227
|
type: "ModelRef",
|
|
1197
|
-
ref: str
|
|
1228
|
+
ref: str,
|
|
1229
|
+
location: getLocation(startCharIndex)
|
|
1198
1230
|
};
|
|
1199
1231
|
}
|
|
1200
1232
|
function gobbleIdentifier() {
|
|
@@ -1219,19 +1251,22 @@ function parseExpression(expr) {
|
|
|
1219
1251
|
__id: ExpNodeOpaqueIdentifier,
|
|
1220
1252
|
type: "Literal",
|
|
1221
1253
|
value: literals[identifier],
|
|
1222
|
-
raw: identifier
|
|
1254
|
+
raw: identifier,
|
|
1255
|
+
location: getLocation(start)
|
|
1223
1256
|
};
|
|
1224
1257
|
}
|
|
1225
1258
|
if (identifier === thisStr) {
|
|
1226
1259
|
return {
|
|
1227
1260
|
__id: ExpNodeOpaqueIdentifier,
|
|
1228
|
-
type: "ThisExpression"
|
|
1261
|
+
type: "ThisExpression",
|
|
1262
|
+
location: getLocation(start)
|
|
1229
1263
|
};
|
|
1230
1264
|
}
|
|
1231
1265
|
return {
|
|
1232
1266
|
__id: ExpNodeOpaqueIdentifier,
|
|
1233
1267
|
type: "Identifier",
|
|
1234
|
-
name: identifier
|
|
1268
|
+
name: identifier,
|
|
1269
|
+
location: getLocation(start)
|
|
1235
1270
|
};
|
|
1236
1271
|
}
|
|
1237
1272
|
function gobbleArguments(termination) {
|
|
@@ -1260,6 +1295,7 @@ function parseExpression(expr) {
|
|
|
1260
1295
|
function gobbleVariable() {
|
|
1261
1296
|
let charIndex = exprICode(index);
|
|
1262
1297
|
let node = charIndex === OPAREN_CODE ? gobbleGroup() : gobbleIdentifier();
|
|
1298
|
+
const startCharIndex = index;
|
|
1263
1299
|
gobbleSpaces();
|
|
1264
1300
|
charIndex = exprICode(index);
|
|
1265
1301
|
while (charIndex === PERIOD_CODE || charIndex === OBRACK_CODE || charIndex === OPAREN_CODE) {
|
|
@@ -1271,7 +1307,8 @@ function parseExpression(expr) {
|
|
|
1271
1307
|
type: "MemberExpression",
|
|
1272
1308
|
computed: false,
|
|
1273
1309
|
object: node,
|
|
1274
|
-
property: gobbleIdentifier()
|
|
1310
|
+
property: gobbleIdentifier(),
|
|
1311
|
+
location: getLocation(startCharIndex)
|
|
1275
1312
|
};
|
|
1276
1313
|
} else if (charIndex === OBRACK_CODE) {
|
|
1277
1314
|
node = {
|
|
@@ -1279,7 +1316,8 @@ function parseExpression(expr) {
|
|
|
1279
1316
|
type: "MemberExpression",
|
|
1280
1317
|
computed: true,
|
|
1281
1318
|
object: node,
|
|
1282
|
-
property: gobbleExpression()
|
|
1319
|
+
property: gobbleExpression(),
|
|
1320
|
+
location: getLocation(startCharIndex)
|
|
1283
1321
|
};
|
|
1284
1322
|
gobbleSpaces();
|
|
1285
1323
|
charIndex = exprICode(index);
|
|
@@ -1292,7 +1330,8 @@ function parseExpression(expr) {
|
|
|
1292
1330
|
__id: ExpNodeOpaqueIdentifier,
|
|
1293
1331
|
type: "CallExpression",
|
|
1294
1332
|
args: gobbleArguments(CPAREN_CODE),
|
|
1295
|
-
callTarget: node
|
|
1333
|
+
callTarget: node,
|
|
1334
|
+
location: getLocation(startCharIndex)
|
|
1296
1335
|
};
|
|
1297
1336
|
}
|
|
1298
1337
|
gobbleSpaces();
|
|
@@ -1311,11 +1350,13 @@ function parseExpression(expr) {
|
|
|
1311
1350
|
throwError("Unclosed (", index);
|
|
1312
1351
|
}
|
|
1313
1352
|
function gobbleArray() {
|
|
1353
|
+
const startCharIndex = index;
|
|
1314
1354
|
index++;
|
|
1315
1355
|
return {
|
|
1316
1356
|
__id: ExpNodeOpaqueIdentifier,
|
|
1317
1357
|
type: "ArrayExpression",
|
|
1318
|
-
elements: gobbleArguments(CBRACK_CODE)
|
|
1358
|
+
elements: gobbleArguments(CBRACK_CODE),
|
|
1359
|
+
location: getLocation(startCharIndex)
|
|
1319
1360
|
};
|
|
1320
1361
|
}
|
|
1321
1362
|
const nodes = [];
|
|
@@ -1338,7 +1379,8 @@ function parseExpression(expr) {
|
|
|
1338
1379
|
return {
|
|
1339
1380
|
__id: ExpNodeOpaqueIdentifier,
|
|
1340
1381
|
type: "Compound",
|
|
1341
|
-
body: nodes
|
|
1382
|
+
body: nodes,
|
|
1383
|
+
location: getLocation(0)
|
|
1342
1384
|
};
|
|
1343
1385
|
}
|
|
1344
1386
|
|
|
@@ -1616,6 +1658,76 @@ class ExpressionEvaluator {
|
|
|
1616
1658
|
function withoutContext(fn) {
|
|
1617
1659
|
return (_context, ...args) => fn(...args);
|
|
1618
1660
|
}
|
|
1661
|
+
function isInRange(position, location) {
|
|
1662
|
+
return position.character >= location.start.character && position.character <= location.end.character;
|
|
1663
|
+
}
|
|
1664
|
+
function findClosestNodeAtPosition(node, position) {
|
|
1665
|
+
var _a, _b, _c, _d, _e;
|
|
1666
|
+
switch (node.type) {
|
|
1667
|
+
case "Modification":
|
|
1668
|
+
case "Assignment":
|
|
1669
|
+
case "LogicalExpression":
|
|
1670
|
+
case "BinaryExpression": {
|
|
1671
|
+
const check = (_a = findClosestNodeAtPosition(node.left, position)) != null ? _a : findClosestNodeAtPosition(node.right, position);
|
|
1672
|
+
if (check) {
|
|
1673
|
+
return check;
|
|
1674
|
+
}
|
|
1675
|
+
break;
|
|
1676
|
+
}
|
|
1677
|
+
case "UnaryExpression": {
|
|
1678
|
+
const checkArg = findClosestNodeAtPosition(node.argument, position);
|
|
1679
|
+
if (checkArg) {
|
|
1680
|
+
return checkArg;
|
|
1681
|
+
}
|
|
1682
|
+
break;
|
|
1683
|
+
}
|
|
1684
|
+
case "MemberExpression": {
|
|
1685
|
+
const checkObject = (_b = findClosestNodeAtPosition(node.object, position)) != null ? _b : findClosestNodeAtPosition(node.property, position);
|
|
1686
|
+
if (checkObject) {
|
|
1687
|
+
return checkObject;
|
|
1688
|
+
}
|
|
1689
|
+
break;
|
|
1690
|
+
}
|
|
1691
|
+
case "ConditionalExpression": {
|
|
1692
|
+
const checkObject = (_d = (_c = findClosestNodeAtPosition(node.test, position)) != null ? _c : findClosestNodeAtPosition(node.consequent, position)) != null ? _d : findClosestNodeAtPosition(node.alternate, position);
|
|
1693
|
+
if (checkObject) {
|
|
1694
|
+
return checkObject;
|
|
1695
|
+
}
|
|
1696
|
+
break;
|
|
1697
|
+
}
|
|
1698
|
+
case "ArrayExpression":
|
|
1699
|
+
case "Compound": {
|
|
1700
|
+
const elements = node.type === "ArrayExpression" ? node.elements : node.body;
|
|
1701
|
+
const anyElements = elements.find((e) => findClosestNodeAtPosition(e, position));
|
|
1702
|
+
if (anyElements) {
|
|
1703
|
+
return anyElements;
|
|
1704
|
+
}
|
|
1705
|
+
break;
|
|
1706
|
+
}
|
|
1707
|
+
case "Object": {
|
|
1708
|
+
const checkObject = node.attributes.reduce((found, next) => {
|
|
1709
|
+
var _a2;
|
|
1710
|
+
return (_a2 = found != null ? found : findClosestNodeAtPosition(next.key, position)) != null ? _a2 : findClosestNodeAtPosition(next.value, position);
|
|
1711
|
+
}, void 0);
|
|
1712
|
+
if (checkObject) {
|
|
1713
|
+
return checkObject;
|
|
1714
|
+
}
|
|
1715
|
+
break;
|
|
1716
|
+
}
|
|
1717
|
+
case "CallExpression": {
|
|
1718
|
+
const anyArgs = (_e = node.args.find((arg) => {
|
|
1719
|
+
return findClosestNodeAtPosition(arg, position);
|
|
1720
|
+
})) != null ? _e : findClosestNodeAtPosition(node.callTarget, position);
|
|
1721
|
+
if (anyArgs) {
|
|
1722
|
+
return anyArgs;
|
|
1723
|
+
}
|
|
1724
|
+
break;
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
if (node.location && isInRange(position, node.location)) {
|
|
1728
|
+
return node;
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1619
1731
|
|
|
1620
1732
|
const severities = ["trace", "debug", "info", "warn", "error"];
|
|
1621
1733
|
|
|
@@ -1952,6 +2064,8 @@ function traverseObject(val, options) {
|
|
|
1952
2064
|
return resolveDataRefsInString(val, options);
|
|
1953
2065
|
}
|
|
1954
2066
|
case "object": {
|
|
2067
|
+
if (!val)
|
|
2068
|
+
return val;
|
|
1955
2069
|
const keys = Object.keys(val);
|
|
1956
2070
|
let newVal = val;
|
|
1957
2071
|
if (keys.length > 0) {
|
|
@@ -2007,14 +2121,22 @@ class ValidationMiddleware {
|
|
|
2007
2121
|
if (validations === void 0) {
|
|
2008
2122
|
nextTransaction.push([binding, value]);
|
|
2009
2123
|
} else if (validations instanceof Set) {
|
|
2010
|
-
|
|
2124
|
+
validations.forEach((validation) => {
|
|
2125
|
+
invalidBindings.push(validation.binding);
|
|
2126
|
+
if (!validation.isStrong) {
|
|
2127
|
+
nextTransaction.push([validation.binding, value]);
|
|
2128
|
+
}
|
|
2129
|
+
});
|
|
2011
2130
|
} else {
|
|
2012
2131
|
(_a = this.logger) == null ? void 0 : _a.debug(`Invalid value for path: ${binding.asString()} - ${validations.severity} - ${validations.message}`);
|
|
2013
2132
|
}
|
|
2014
2133
|
});
|
|
2015
2134
|
if (next && nextTransaction.length > 0) {
|
|
2016
2135
|
nextTransaction.forEach(([binding]) => this.shadowModelPaths.delete(binding));
|
|
2017
|
-
|
|
2136
|
+
const result = next.set(nextTransaction, options);
|
|
2137
|
+
if (invalidBindings.length === 0) {
|
|
2138
|
+
return result;
|
|
2139
|
+
}
|
|
2018
2140
|
}
|
|
2019
2141
|
return invalidBindings.map((binding) => {
|
|
2020
2142
|
return {
|
|
@@ -2680,14 +2802,27 @@ const findBasePath = (node) => {
|
|
|
2680
2802
|
return findBasePath(parentNode);
|
|
2681
2803
|
};
|
|
2682
2804
|
class StringResolverPlugin {
|
|
2805
|
+
constructor() {
|
|
2806
|
+
this.propertiesToSkipCache = new Map();
|
|
2807
|
+
}
|
|
2683
2808
|
applyResolver(resolver) {
|
|
2684
2809
|
resolver.hooks.resolve.tap("string-resolver", (value, node, options) => {
|
|
2685
|
-
var _a, _b, _c, _d;
|
|
2810
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2686
2811
|
if (node.type === NodeType.Empty || node.type === NodeType.Unknown) {
|
|
2687
2812
|
return null;
|
|
2688
2813
|
}
|
|
2689
2814
|
if (node.type === NodeType.Value || node.type === NodeType.Asset || node.type === NodeType.View) {
|
|
2690
|
-
|
|
2815
|
+
let propsToSkip;
|
|
2816
|
+
if (node.type === NodeType.Asset || node.type === NodeType.View) {
|
|
2817
|
+
propsToSkip = new Set((_c = (_b = (_a = node.plugins) == null ? void 0 : _a.stringResolver) == null ? void 0 : _b.propertiesToSkip) != null ? _c : ["exp"]);
|
|
2818
|
+
if ((_d = node.value) == null ? void 0 : _d.id) {
|
|
2819
|
+
this.propertiesToSkipCache.set(node.value.id, propsToSkip);
|
|
2820
|
+
}
|
|
2821
|
+
} else if (((_e = node.parent) == null ? void 0 : _e.type) === NodeType.MultiNode && (((_g = (_f = node.parent) == null ? void 0 : _f.parent) == null ? void 0 : _g.type) === NodeType.Asset || ((_i = (_h = node.parent) == null ? void 0 : _h.parent) == null ? void 0 : _i.type) === NodeType.View) && ((_j = node.parent.parent.value) == null ? void 0 : _j.id) && this.propertiesToSkipCache.has(node.parent.parent.value.id)) {
|
|
2822
|
+
propsToSkip = this.propertiesToSkipCache.get(node.parent.parent.value.id);
|
|
2823
|
+
} else {
|
|
2824
|
+
propsToSkip = new Set(["exp"]);
|
|
2825
|
+
}
|
|
2691
2826
|
const nodePath = findBasePath(node);
|
|
2692
2827
|
if (nodePath.length > 0 && nodePath.some((segment) => propsToSkip.has(segment.toString()))) {
|
|
2693
2828
|
return node.value;
|
|
@@ -3513,19 +3648,30 @@ class ValidationController {
|
|
|
3513
3648
|
getDataMiddleware() {
|
|
3514
3649
|
return [
|
|
3515
3650
|
new ValidationMiddleware((binding) => {
|
|
3651
|
+
var _a;
|
|
3516
3652
|
if (!this.options) {
|
|
3517
3653
|
return;
|
|
3518
3654
|
}
|
|
3519
3655
|
this.updateValidationsForBinding(binding, "change", this.options);
|
|
3520
3656
|
const strongValidation = this.getValidationForBinding(binding);
|
|
3521
|
-
if (strongValidation == null ? void 0 : strongValidation.get())
|
|
3657
|
+
if (((_a = strongValidation == null ? void 0 : strongValidation.get()) == null ? void 0 : _a.severity) === "error") {
|
|
3522
3658
|
return strongValidation.get();
|
|
3659
|
+
}
|
|
3523
3660
|
const newInvalidBindings = new Set();
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3661
|
+
this.validations.forEach((weakValidation, strongBinding) => {
|
|
3662
|
+
var _a2;
|
|
3663
|
+
if (caresAboutDataChanges(new Set([binding]), weakValidation.weakBindings) && ((_a2 = weakValidation == null ? void 0 : weakValidation.get()) == null ? void 0 : _a2.severity) === "error") {
|
|
3664
|
+
weakValidation == null ? void 0 : weakValidation.weakBindings.forEach((weakBinding) => {
|
|
3665
|
+
weakBinding === strongBinding ? newInvalidBindings.add({
|
|
3666
|
+
binding: weakBinding,
|
|
3667
|
+
isStrong: true
|
|
3668
|
+
}) : newInvalidBindings.add({
|
|
3669
|
+
binding: weakBinding,
|
|
3670
|
+
isStrong: false
|
|
3671
|
+
});
|
|
3672
|
+
});
|
|
3527
3673
|
}
|
|
3528
|
-
}
|
|
3674
|
+
});
|
|
3529
3675
|
if (newInvalidBindings.size > 0) {
|
|
3530
3676
|
return newInvalidBindings;
|
|
3531
3677
|
}
|
|
@@ -3551,7 +3697,9 @@ class ValidationController {
|
|
|
3551
3697
|
ignoreDefaultValue: true
|
|
3552
3698
|
});
|
|
3553
3699
|
if (originalValue !== withoutDefault) {
|
|
3554
|
-
this.options.model.set([[binding, originalValue]]
|
|
3700
|
+
this.options.model.set([[binding, originalValue]], {
|
|
3701
|
+
silent: true
|
|
3702
|
+
});
|
|
3555
3703
|
}
|
|
3556
3704
|
this.updateValidationsForBinding(binding, "load", this.options, () => {
|
|
3557
3705
|
view.update(new Set([binding]));
|
|
@@ -3591,7 +3739,7 @@ class ValidationController {
|
|
|
3591
3739
|
this.validations.forEach((validation, vBinding) => {
|
|
3592
3740
|
if (vBinding !== binding && caresAboutDataChanges(new Set([binding]), validation.weakBindings)) {
|
|
3593
3741
|
validation.update(trigger, true, (validationObj) => {
|
|
3594
|
-
const response = this.validationRunner(validationObj, context,
|
|
3742
|
+
const response = this.validationRunner(validationObj, context, vBinding);
|
|
3595
3743
|
return response ? { message: response.message } : void 0;
|
|
3596
3744
|
});
|
|
3597
3745
|
}
|
|
@@ -3678,16 +3826,16 @@ class ValidationController {
|
|
|
3678
3826
|
return (_b = (_a = this.tracker) == null ? void 0 : _a.getBindings()) != null ? _b : new Set();
|
|
3679
3827
|
}
|
|
3680
3828
|
validateView(trigger = "navigation") {
|
|
3681
|
-
var _a, _b;
|
|
3682
3829
|
this.updateValidationsForView(trigger);
|
|
3683
3830
|
const validations = new Map();
|
|
3684
|
-
|
|
3831
|
+
this.getBindings().forEach((b) => {
|
|
3832
|
+
var _a, _b;
|
|
3685
3833
|
const invalid = (_a = this.getValidationForBinding(b)) == null ? void 0 : _a.get();
|
|
3686
3834
|
if (invalid) {
|
|
3687
3835
|
(_b = this.options) == null ? void 0 : _b.logger.debug(`Validation on binding: ${b.asString()} is preventing navigation. ${JSON.stringify(invalid)}`);
|
|
3688
3836
|
validations.set(b, invalid);
|
|
3689
3837
|
}
|
|
3690
|
-
}
|
|
3838
|
+
});
|
|
3691
3839
|
return {
|
|
3692
3840
|
canTransition: validations.size === 0,
|
|
3693
3841
|
validations: validations.size ? validations : void 0
|
|
@@ -4057,8 +4205,9 @@ class DataController {
|
|
|
4057
4205
|
}
|
|
4058
4206
|
});
|
|
4059
4207
|
this.hooks.onSet.call(normalizedTransaction);
|
|
4208
|
+
this.hooks.onSet.call(normalizedTransaction);
|
|
4060
4209
|
if (setUpdates.length > 0) {
|
|
4061
|
-
this.hooks.onUpdate.call(setUpdates);
|
|
4210
|
+
this.hooks.onUpdate.call(setUpdates, options);
|
|
4062
4211
|
}
|
|
4063
4212
|
return result;
|
|
4064
4213
|
}
|
|
@@ -4259,8 +4408,8 @@ var __async = (__this, __arguments, generator) => {
|
|
|
4259
4408
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
4260
4409
|
});
|
|
4261
4410
|
};
|
|
4262
|
-
const PLAYER_VERSION = "0.
|
|
4263
|
-
const COMMIT = "
|
|
4411
|
+
const PLAYER_VERSION = "0.4.0-next.0";
|
|
4412
|
+
const COMMIT = "6f7a8b3424cb819dfcbe830586a92711adf130ba";
|
|
4264
4413
|
const _Player = class {
|
|
4265
4414
|
constructor(config) {
|
|
4266
4415
|
this.logger = new TapableLogger();
|
|
@@ -4387,17 +4536,18 @@ const _Player = class {
|
|
|
4387
4536
|
}
|
|
4388
4537
|
flowController.hooks.flow.tap("player", (flow) => {
|
|
4389
4538
|
flow.hooks.beforeTransition.tap("player", (state, transitionVal) => {
|
|
4390
|
-
|
|
4539
|
+
const computedTransitionVal = state.transitions[transitionVal] ? transitionVal : "*";
|
|
4540
|
+
if (state.onEnd && state.transitions[computedTransitionVal]) {
|
|
4391
4541
|
if (typeof state.onEnd === "object" && "exp" in state.onEnd) {
|
|
4392
4542
|
expressionEvaluator == null ? void 0 : expressionEvaluator.evaluate(state.onEnd.exp);
|
|
4393
4543
|
} else {
|
|
4394
4544
|
expressionEvaluator == null ? void 0 : expressionEvaluator.evaluate(state.onEnd);
|
|
4395
4545
|
}
|
|
4396
4546
|
}
|
|
4397
|
-
if (!("transitions" in state) || !state.transitions[
|
|
4547
|
+
if (!("transitions" in state) || !state.transitions[computedTransitionVal]) {
|
|
4398
4548
|
return state;
|
|
4399
4549
|
}
|
|
4400
|
-
return setIn(state, ["transitions",
|
|
4550
|
+
return setIn(state, ["transitions", computedTransitionVal], resolveStrings(state.transitions[computedTransitionVal]));
|
|
4401
4551
|
});
|
|
4402
4552
|
flow.hooks.skipTransition.tap("validation", (currentState) => {
|
|
4403
4553
|
var _a;
|
|
@@ -4425,7 +4575,14 @@ const _Player = class {
|
|
|
4425
4575
|
if (newState.value.state_type === "ACTION") {
|
|
4426
4576
|
const { exp } = newState.value;
|
|
4427
4577
|
queueMicrotask(() => {
|
|
4428
|
-
|
|
4578
|
+
try {
|
|
4579
|
+
flowController == null ? void 0 : flowController.transition(String(expressionEvaluator == null ? void 0 : expressionEvaluator.evaluate(exp)));
|
|
4580
|
+
} catch (error) {
|
|
4581
|
+
const state = this.getState();
|
|
4582
|
+
if (error instanceof Error && state.status === "in-progress") {
|
|
4583
|
+
state.fail(error);
|
|
4584
|
+
}
|
|
4585
|
+
}
|
|
4429
4586
|
});
|
|
4430
4587
|
}
|
|
4431
4588
|
expressionEvaluator.reset();
|
|
@@ -4548,5 +4705,5 @@ Player.info = {
|
|
|
4548
4705
|
commit: COMMIT
|
|
4549
4706
|
};
|
|
4550
4707
|
|
|
4551
|
-
export { ApplicabilityPlugin, AssetTransformCorePlugin, BindingInstance, BindingParser, Builder, ConsoleLogger, ConstantsController, DataController, DependencyMiddleware, DependencyModel, DependencyTracker, EMPTY_NODE, ExpNodeOpaqueIdentifier, ExpressionEvaluator, FlowController, FlowExpPlugin, FlowInstance, LocalModel, LocalStateStore, NOOPDataModel, NOOP_MODEL, NOT_STARTED_STATE, NodeType, NoopLogger, Parser, PipelinedDataModel, Player, ProxyLogger, ROOT_BINDING, Resolver, SIMPLE_BINDING_REGEX, SchemaController, StringResolverPlugin, SwitchPlugin, TapableLogger, TemplatePlugin, ValidationBindingTrackerViewPlugin, ValidationController, ValidationMiddleware, ValidatorRegistry, ViewController, ViewInstance, caresAboutDataChanges, constructModelForPipeline, findInArray, findNextExp, getBindingSegments, isBinding, isExpressionNode, maybeConvertToNum, parse, resolveDataRefs, resolveDataRefsInString, resolveExpressionsInString, severities, toModel, toNodeResolveOptions, withParser, withoutContext };
|
|
4708
|
+
export { ApplicabilityPlugin, AssetTransformCorePlugin, BindingInstance, BindingParser, Builder, ConsoleLogger, ConstantsController, DataController, DependencyMiddleware, DependencyModel, DependencyTracker, EMPTY_NODE, ExpNodeOpaqueIdentifier, ExpressionEvaluator, FlowController, FlowExpPlugin, FlowInstance, LocalModel, LocalStateStore, NOOPDataModel, NOOP_MODEL, NOT_STARTED_STATE, NodeType, NoopLogger, Parser, PipelinedDataModel, Player, ProxyLogger, ROOT_BINDING, Resolver, SIMPLE_BINDING_REGEX, SchemaController, StringResolverPlugin, SwitchPlugin, TapableLogger, TemplatePlugin, ValidationBindingTrackerViewPlugin, ValidationController, ValidationMiddleware, ValidatorRegistry, ViewController, ViewInstance, caresAboutDataChanges, constructModelForPipeline, findClosestNodeAtPosition, findInArray, findNextExp, getBindingSegments, isBinding, isExpressionNode, maybeConvertToNum, parse, resolveDataRefs, resolveDataRefsInString, resolveExpressionsInString, severities, toModel, toNodeResolveOptions, withParser, withoutContext };
|
|
4552
4709
|
//# sourceMappingURL=index.esm.js.map
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@player-ui/player",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0-next.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
7
7
|
},
|
|
8
8
|
"peerDependencies": {},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@player-ui/partial-match-registry": "0.
|
|
11
|
-
"@player-ui/types": "0.
|
|
10
|
+
"@player-ui/partial-match-registry": "0.4.0-next.0",
|
|
11
|
+
"@player-ui/types": "0.4.0-next.0",
|
|
12
12
|
"dequal": "^2.0.2",
|
|
13
13
|
"p-defer": "^3.0.0",
|
|
14
14
|
"queue-microtask": "^1.2.3",
|
|
15
|
-
"tapable-ts": "^0.
|
|
15
|
+
"tapable-ts": "^0.2.2",
|
|
16
16
|
"nested-error-stacks": "^2.1.1",
|
|
17
17
|
"@types/nested-error-stacks": "^2.1.0",
|
|
18
18
|
"parsimmon": "^1.12.0",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"arr-flatten": "^1.1.0",
|
|
21
21
|
"ebnf": "^1.9.0",
|
|
22
22
|
"timm": "^1.6.2",
|
|
23
|
+
"error-polyfill": "^0.1.3",
|
|
23
24
|
"@babel/runtime": "7.15.4"
|
|
24
25
|
},
|
|
25
26
|
"main": "dist/index.cjs.js",
|
package/src/binding/resolver.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import NestedError from 'nested-error-stacks';
|
|
2
2
|
import type { SyncWaterfallHook } from 'tapable-ts';
|
|
3
3
|
import type { PathNode, AnyNode } from '../binding-grammar';
|
|
4
|
-
|
|
5
|
-
import { maybeConvertToNum } from '.';
|
|
6
|
-
import { findInArray } from './utils';
|
|
4
|
+
import { findInArray, maybeConvertToNum } from './utils';
|
|
7
5
|
|
|
8
6
|
export interface NormalizedResult {
|
|
9
7
|
/** The normalized path */
|
package/src/controllers/data.ts
CHANGED
|
@@ -27,7 +27,7 @@ export class DataController implements DataModelWithParser<DataModelOptions> {
|
|
|
27
27
|
onDelete: new SyncHook<[any]>(),
|
|
28
28
|
onSet: new SyncHook<[BatchSetTransaction]>(),
|
|
29
29
|
onGet: new SyncHook<[any, any]>(),
|
|
30
|
-
onUpdate: new SyncHook<[Updates]>(),
|
|
30
|
+
onUpdate: new SyncHook<[Updates, DataModelOptions | undefined]>(),
|
|
31
31
|
|
|
32
32
|
format: new SyncWaterfallHook<[any, BindingInstance]>(),
|
|
33
33
|
deformat: new SyncWaterfallHook<[any, BindingInstance]>(),
|
|
@@ -157,8 +157,10 @@ export class DataController implements DataModelWithParser<DataModelOptions> {
|
|
|
157
157
|
|
|
158
158
|
this.hooks.onSet.call(normalizedTransaction);
|
|
159
159
|
|
|
160
|
+
this.hooks.onSet.call(normalizedTransaction);
|
|
161
|
+
|
|
160
162
|
if (setUpdates.length > 0) {
|
|
161
|
-
this.hooks.onUpdate.call(setUpdates);
|
|
163
|
+
this.hooks.onUpdate.call(setUpdates, options);
|
|
162
164
|
}
|
|
163
165
|
|
|
164
166
|
return result;
|