@player-ui/async-node-plugin 0.10.5--canary.646.22748 → 0.10.5--canary.649.22815

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.
@@ -3563,6 +3563,9 @@ var AsyncNodePlugin = function() {
3563
3563
  },
3564
3564
  setDataVal: function() {
3565
3565
  return setDataVal;
3566
+ },
3567
+ waitFor: function() {
3568
+ return waitFor;
3566
3569
  }
3567
3570
  });
3568
3571
  var setDataVal = function(_context, binding, value) {
@@ -3590,6 +3593,27 @@ var AsyncNodePlugin = function() {
3590
3593
  return null;
3591
3594
  };
3592
3595
  conditional.resolveParams = false;
3596
+ var waitFor = function() {
3597
+ var _ref = _async_to_generator(function(ctx, promise) {
3598
+ return _ts_generator(this, function(_state) {
3599
+ switch(_state.label){
3600
+ case 0:
3601
+ return [
3602
+ 4,
3603
+ promise
3604
+ ];
3605
+ case 1:
3606
+ return [
3607
+ 2,
3608
+ _state.sent()
3609
+ ];
3610
+ }
3611
+ });
3612
+ });
3613
+ return function waitFor(ctx, promise) {
3614
+ return _ref.apply(this, arguments);
3615
+ };
3616
+ }();
3593
3617
  var andandOperator = function(ctx, a, b) {
3594
3618
  return ctx.evaluate(a) && ctx.evaluate(b);
3595
3619
  };
@@ -3695,7 +3719,12 @@ var AsyncNodePlugin = function() {
3695
3719
  this.operators = {
3696
3720
  binary: new Map(Object.entries(DEFAULT_BINARY_OPERATORS)),
3697
3721
  unary: new Map(Object.entries(DEFAULT_UNARY_OPERATORS)),
3698
- expressions: new Map(Object.entries(evaluator_functions_exports))
3722
+ expressions: new Map(_to_consumable_array(Object.entries(evaluator_functions_exports)).concat([
3723
+ [
3724
+ "await",
3725
+ waitFor
3726
+ ]
3727
+ ]))
3699
3728
  };
3700
3729
  this.defaultHookOptions = _object_spread_props(_object_spread({}, defaultOptions), {
3701
3730
  evaluate: function(expr) {
@@ -3705,7 +3734,12 @@ var AsyncNodePlugin = function() {
3705
3734
  return _this._execAST(node, _this.defaultHookOptions);
3706
3735
  }
3707
3736
  });
3708
- this.hooks.resolve.tap("ExpressionEvaluator", this._resolveNode.bind(this));
3737
+ this.hooks.resolve.tap("ExpressionEvaluator", function(result, node, options) {
3738
+ if (options.async) {
3739
+ return _this._resolveNodeAsync(result, node, options);
3740
+ }
3741
+ return _this._resolveNode(result, node, options);
3742
+ });
3709
3743
  this.evaluate = this.evaluate.bind(this);
3710
3744
  }
3711
3745
  _create_class(ExpressionEvaluator, [
@@ -3743,6 +3777,14 @@ var AsyncNodePlugin = function() {
3743
3777
  return this._execString(String(expression), resolvedOpts);
3744
3778
  }
3745
3779
  },
3780
+ {
3781
+ key: "evaluateAsync",
3782
+ value: function evaluateAsync(expr, options) {
3783
+ return this.evaluate(expr, _object_spread_props(_object_spread({}, options), {
3784
+ async: true
3785
+ }));
3786
+ }
3787
+ },
3746
3788
  {
3747
3789
  key: "addExpressionFunction",
3748
3790
  value: function addExpressionFunction(name, handler) {
@@ -3788,8 +3830,10 @@ var AsyncNodePlugin = function() {
3788
3830
  var matches = exp.match(/^@\[(.*)\]@$/);
3789
3831
  var matchedExp = exp;
3790
3832
  if (matches) {
3791
- var ref;
3792
- ref = _sliced_to_array(Array.from(matches), 2), matchedExp = ref[1], ref;
3833
+ var _Array_from = _sliced_to_array(Array.from(matches), 2), matched = _Array_from[1];
3834
+ if (matched) {
3835
+ matchedExp = matched;
3836
+ }
3793
3837
  }
3794
3838
  var storedAST;
3795
3839
  try {
@@ -3950,6 +3994,452 @@ var AsyncNodePlugin = function() {
3950
3994
  return resolveNode(node.left);
3951
3995
  }
3952
3996
  }
3997
+ },
3998
+ {
3999
+ key: "_resolveNodeAsync",
4000
+ value: function _resolveNodeAsync(_currentValue, node, options) {
4001
+ var _this = this;
4002
+ return _async_to_generator(function() {
4003
+ var resolveNode, model, expressionContext, operator, _tmp, _tmp1, operator1, _tmp2, _tmp3, attributes, resolvedAttributes, expressionName, operator2, args, obj, prop, value, value1, result, operation, newValue, _tmp4, _tmp5;
4004
+ return _ts_generator(this, function(_state) {
4005
+ switch(_state.label){
4006
+ case 0:
4007
+ resolveNode = options.resolveNode, model = options.model;
4008
+ expressionContext = _object_spread_props(_object_spread({}, options), {
4009
+ evaluate: function(expr) {
4010
+ return _this.evaluate(expr, options);
4011
+ }
4012
+ });
4013
+ if (!(node.type === "BinaryExpression" || node.type === "LogicalExpression")) return [
4014
+ 3,
4015
+ 7
4016
+ ];
4017
+ operator = _this.operators.binary.get(node.operator);
4018
+ if (!operator) return [
4019
+ 3,
4020
+ 6
4021
+ ];
4022
+ if (!("resolveParams" in operator)) return [
4023
+ 3,
4024
+ 3
4025
+ ];
4026
+ if (operator.resolveParams === false) {
4027
+ return [
4028
+ 2,
4029
+ operator(expressionContext, node.left, node.right)
4030
+ ];
4031
+ }
4032
+ _tmp = [
4033
+ expressionContext
4034
+ ];
4035
+ return [
4036
+ 4,
4037
+ resolveNode(node.left)
4038
+ ];
4039
+ case 1:
4040
+ _tmp = _tmp.concat([
4041
+ _state.sent()
4042
+ ]);
4043
+ return [
4044
+ 4,
4045
+ resolveNode(node.right)
4046
+ ];
4047
+ case 2:
4048
+ return [
4049
+ 2,
4050
+ operator.apply(void 0, _tmp.concat([
4051
+ _state.sent()
4052
+ ]))
4053
+ ];
4054
+ case 3:
4055
+ return [
4056
+ 4,
4057
+ resolveNode(node.left)
4058
+ ];
4059
+ case 4:
4060
+ _tmp1 = [
4061
+ _state.sent()
4062
+ ];
4063
+ return [
4064
+ 4,
4065
+ resolveNode(node.right)
4066
+ ];
4067
+ case 5:
4068
+ return [
4069
+ 2,
4070
+ operator.apply(void 0, _tmp1.concat([
4071
+ _state.sent()
4072
+ ]))
4073
+ ];
4074
+ case 6:
4075
+ return [
4076
+ 2
4077
+ ];
4078
+ case 7:
4079
+ if (!(node.type === "UnaryExpression")) return [
4080
+ 3,
4081
+ 14
4082
+ ];
4083
+ operator1 = _this.operators.unary.get(node.operator);
4084
+ if (!operator1) return [
4085
+ 3,
4086
+ 13
4087
+ ];
4088
+ if (!("resolveParams" in operator1)) return [
4089
+ 3,
4090
+ 11
4091
+ ];
4092
+ _tmp2 = [
4093
+ expressionContext
4094
+ ];
4095
+ if (!(operator1.resolveParams === false)) return [
4096
+ 3,
4097
+ 8
4098
+ ];
4099
+ _tmp3 = node.argument;
4100
+ return [
4101
+ 3,
4102
+ 10
4103
+ ];
4104
+ case 8:
4105
+ return [
4106
+ 4,
4107
+ resolveNode(node.argument)
4108
+ ];
4109
+ case 9:
4110
+ _tmp3 = _state.sent();
4111
+ _state.label = 10;
4112
+ case 10:
4113
+ return [
4114
+ 2,
4115
+ operator1.apply(void 0, _tmp2.concat([
4116
+ _tmp3
4117
+ ]))
4118
+ ];
4119
+ case 11:
4120
+ return [
4121
+ 4,
4122
+ resolveNode(node.argument)
4123
+ ];
4124
+ case 12:
4125
+ return [
4126
+ 2,
4127
+ operator1.apply(void 0, [
4128
+ _state.sent()
4129
+ ])
4130
+ ];
4131
+ case 13:
4132
+ return [
4133
+ 2
4134
+ ];
4135
+ case 14:
4136
+ if (!(node.type === "Object")) return [
4137
+ 3,
4138
+ 16
4139
+ ];
4140
+ attributes = node.attributes;
4141
+ resolvedAttributes = {};
4142
+ return [
4143
+ 4,
4144
+ Promise.all(attributes.map(function() {
4145
+ var _ref = _async_to_generator(function(attr) {
4146
+ var key, value;
4147
+ return _ts_generator(this, function(_state) {
4148
+ switch(_state.label){
4149
+ case 0:
4150
+ return [
4151
+ 4,
4152
+ resolveNode(attr.key)
4153
+ ];
4154
+ case 1:
4155
+ key = _state.sent();
4156
+ return [
4157
+ 4,
4158
+ resolveNode(attr.value)
4159
+ ];
4160
+ case 2:
4161
+ value = _state.sent();
4162
+ resolvedAttributes[key] = value;
4163
+ return [
4164
+ 2
4165
+ ];
4166
+ }
4167
+ });
4168
+ });
4169
+ return function(attr) {
4170
+ return _ref.apply(this, arguments);
4171
+ };
4172
+ }()))
4173
+ ];
4174
+ case 15:
4175
+ _state.sent();
4176
+ return [
4177
+ 2,
4178
+ resolvedAttributes
4179
+ ];
4180
+ case 16:
4181
+ if (!(node.type === "CallExpression")) return [
4182
+ 3,
4183
+ 18
4184
+ ];
4185
+ expressionName = node.callTarget.name;
4186
+ operator2 = _this.operators.expressions.get(expressionName);
4187
+ if (!operator2) {
4188
+ throw new Error("Unknown expression function: ".concat(expressionName));
4189
+ }
4190
+ if ("resolveParams" in operator2 && operator2.resolveParams === false) {
4191
+ return [
4192
+ 2,
4193
+ operator2.apply(void 0, [
4194
+ expressionContext
4195
+ ].concat(_to_consumable_array(node.args)))
4196
+ ];
4197
+ }
4198
+ return [
4199
+ 4,
4200
+ Promise.all(node.args.map(function() {
4201
+ var _ref = _async_to_generator(function(n) {
4202
+ return _ts_generator(this, function(_state) {
4203
+ switch(_state.label){
4204
+ case 0:
4205
+ return [
4206
+ 4,
4207
+ resolveNode(n)
4208
+ ];
4209
+ case 1:
4210
+ return [
4211
+ 2,
4212
+ _state.sent()
4213
+ ];
4214
+ }
4215
+ });
4216
+ });
4217
+ return function(n) {
4218
+ return _ref.apply(this, arguments);
4219
+ };
4220
+ }()))
4221
+ ];
4222
+ case 17:
4223
+ args = _state.sent();
4224
+ return [
4225
+ 2,
4226
+ operator2.apply(void 0, [
4227
+ expressionContext
4228
+ ].concat(_to_consumable_array(args)))
4229
+ ];
4230
+ case 18:
4231
+ if (node.type === "ModelRef") {
4232
+ return [
4233
+ 2,
4234
+ model.get(node.ref, {
4235
+ context: {
4236
+ model: options.model
4237
+ }
4238
+ })
4239
+ ];
4240
+ }
4241
+ if (!(node.type === "MemberExpression")) return [
4242
+ 3,
4243
+ 21
4244
+ ];
4245
+ return [
4246
+ 4,
4247
+ resolveNode(node.object)
4248
+ ];
4249
+ case 19:
4250
+ obj = _state.sent();
4251
+ return [
4252
+ 4,
4253
+ resolveNode(node.property)
4254
+ ];
4255
+ case 20:
4256
+ prop = _state.sent();
4257
+ return [
4258
+ 2,
4259
+ obj[prop]
4260
+ ];
4261
+ case 21:
4262
+ if (!(node.type === "Assignment")) return [
4263
+ 3,
4264
+ 26
4265
+ ];
4266
+ if (!(node.left.type === "ModelRef")) return [
4267
+ 3,
4268
+ 23
4269
+ ];
4270
+ return [
4271
+ 4,
4272
+ resolveNode(node.right)
4273
+ ];
4274
+ case 22:
4275
+ value = _state.sent();
4276
+ model.set([
4277
+ [
4278
+ node.left.ref,
4279
+ value
4280
+ ]
4281
+ ]);
4282
+ return [
4283
+ 2,
4284
+ value
4285
+ ];
4286
+ case 23:
4287
+ if (!(node.left.type === "Identifier")) return [
4288
+ 3,
4289
+ 25
4290
+ ];
4291
+ return [
4292
+ 4,
4293
+ resolveNode(node.right)
4294
+ ];
4295
+ case 24:
4296
+ value1 = _state.sent();
4297
+ _this.vars[node.left.name] = value1;
4298
+ return [
4299
+ 2,
4300
+ value1
4301
+ ];
4302
+ case 25:
4303
+ return [
4304
+ 2
4305
+ ];
4306
+ case 26:
4307
+ if (!(node.type === "ConditionalExpression")) return [
4308
+ 3,
4309
+ 28
4310
+ ];
4311
+ return [
4312
+ 4,
4313
+ resolveNode(node.test)
4314
+ ];
4315
+ case 27:
4316
+ result = _state.sent() ? node.consequent : node.alternate;
4317
+ return [
4318
+ 2,
4319
+ resolveNode(result)
4320
+ ];
4321
+ case 28:
4322
+ if (node.type === "ArrayExpression") {
4323
+ return [
4324
+ 2,
4325
+ Promise.all(node.elements.map(function() {
4326
+ var _ref = _async_to_generator(function(ele) {
4327
+ return _ts_generator(this, function(_state) {
4328
+ switch(_state.label){
4329
+ case 0:
4330
+ return [
4331
+ 4,
4332
+ resolveNode(ele)
4333
+ ];
4334
+ case 1:
4335
+ return [
4336
+ 2,
4337
+ _state.sent()
4338
+ ];
4339
+ }
4340
+ });
4341
+ });
4342
+ return function(ele) {
4343
+ return _ref.apply(this, arguments);
4344
+ };
4345
+ }()))
4346
+ ];
4347
+ }
4348
+ if (!(node.type === "Modification")) return [
4349
+ 3,
4350
+ 38
4351
+ ];
4352
+ operation = _this.operators.binary.get(node.operator);
4353
+ if (!operation) return [
4354
+ 3,
4355
+ 37
4356
+ ];
4357
+ if (!("resolveParams" in operation)) return [
4358
+ 3,
4359
+ 33
4360
+ ];
4361
+ if (!(operation.resolveParams === false)) return [
4362
+ 3,
4363
+ 29
4364
+ ];
4365
+ newValue = operation(expressionContext, node.left, node.right);
4366
+ return [
4367
+ 3,
4368
+ 32
4369
+ ];
4370
+ case 29:
4371
+ _tmp4 = [
4372
+ expressionContext
4373
+ ];
4374
+ return [
4375
+ 4,
4376
+ resolveNode(node.left)
4377
+ ];
4378
+ case 30:
4379
+ _tmp4 = _tmp4.concat([
4380
+ _state.sent()
4381
+ ]);
4382
+ return [
4383
+ 4,
4384
+ resolveNode(node.right)
4385
+ ];
4386
+ case 31:
4387
+ newValue = operation.apply(void 0, _tmp4.concat([
4388
+ _state.sent()
4389
+ ]));
4390
+ _state.label = 32;
4391
+ case 32:
4392
+ return [
4393
+ 3,
4394
+ 36
4395
+ ];
4396
+ case 33:
4397
+ return [
4398
+ 4,
4399
+ resolveNode(node.left)
4400
+ ];
4401
+ case 34:
4402
+ _tmp5 = [
4403
+ _state.sent()
4404
+ ];
4405
+ return [
4406
+ 4,
4407
+ resolveNode(node.right)
4408
+ ];
4409
+ case 35:
4410
+ newValue = operation.apply(void 0, _tmp5.concat([
4411
+ _state.sent()
4412
+ ]));
4413
+ _state.label = 36;
4414
+ case 36:
4415
+ if (node.left.type === "ModelRef") {
4416
+ model.set([
4417
+ [
4418
+ node.left.ref,
4419
+ newValue
4420
+ ]
4421
+ ]);
4422
+ } else if (node.left.type === "Identifier") {
4423
+ _this.vars[node.left.name] = newValue;
4424
+ }
4425
+ return [
4426
+ 2,
4427
+ newValue
4428
+ ];
4429
+ case 37:
4430
+ return [
4431
+ 2,
4432
+ resolveNode(node.left)
4433
+ ];
4434
+ case 38:
4435
+ return [
4436
+ 2,
4437
+ _this._resolveNode(_currentValue, node, options)
4438
+ ];
4439
+ }
4440
+ });
4441
+ })();
4442
+ }
3953
4443
  }
3954
4444
  ]);
3955
4445
  return ExpressionEvaluator;
@@ -7275,8 +7765,8 @@ var AsyncNodePlugin = function() {
7275
7765
  ]);
7276
7766
  return DefaultViewPlugin;
7277
7767
  }();
7278
- var PLAYER_VERSION = true ? "0.10.5--canary.646.22748" : "__VERSION__";
7279
- var COMMIT = true ? "8478f94d10c94a6f939ae39ee3d7a1d1443a06f0" : "__GIT_COMMIT__";
7768
+ var PLAYER_VERSION = true ? "0.10.5--canary.649.22815" : "__VERSION__";
7769
+ var COMMIT = true ? "9f52e9693e724aaf5edc228683937f01e57101c9" : "__GIT_COMMIT__";
7280
7770
  var _Player = /*#__PURE__*/ function() {
7281
7771
  function _Player2(config) {
7282
7772
  var _this = this;
@@ -7492,15 +7982,56 @@ var AsyncNodePlugin = function() {
7492
7982
  validationController.reset();
7493
7983
  }
7494
7984
  });
7495
- flow.hooks.afterTransition.tap("player", function(flowInstance) {
7496
- var _flowInstance_currentState;
7497
- var value = (_flowInstance_currentState = flowInstance.currentState) === null || _flowInstance_currentState === void 0 ? void 0 : _flowInstance_currentState.value;
7498
- if (value && value.state_type === "ACTION") {
7499
- var exp = value.exp;
7500
- flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(expressionEvaluator === null || expressionEvaluator === void 0 ? void 0 : expressionEvaluator.evaluate(exp)));
7501
- }
7502
- expressionEvaluator.reset();
7503
- });
7985
+ flow.hooks.afterTransition.tap("player", function() {
7986
+ var _ref = _async_to_generator(function(flowInstance) {
7987
+ var _flowInstance_currentState, value, exp, result, e;
7988
+ return _ts_generator(this, function(_state) {
7989
+ switch(_state.label){
7990
+ case 0:
7991
+ value = (_flowInstance_currentState = flowInstance.currentState) === null || _flowInstance_currentState === void 0 ? void 0 : _flowInstance_currentState.value;
7992
+ if (!(value && value.state_type === "ACTION")) return [
7993
+ 3,
7994
+ 4
7995
+ ];
7996
+ exp = value.exp;
7997
+ _state.label = 1;
7998
+ case 1:
7999
+ _state.trys.push([
8000
+ 1,
8001
+ 3,
8002
+ ,
8003
+ 4
8004
+ ]);
8005
+ return [
8006
+ 4,
8007
+ expressionEvaluator.evaluateAsync(exp)
8008
+ ];
8009
+ case 2:
8010
+ result = _state.sent();
8011
+ flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
8012
+ return [
8013
+ 3,
8014
+ 4
8015
+ ];
8016
+ case 3:
8017
+ e = _state.sent();
8018
+ flowResultDeferred.reject(e);
8019
+ return [
8020
+ 3,
8021
+ 4
8022
+ ];
8023
+ case 4:
8024
+ expressionEvaluator.reset();
8025
+ return [
8026
+ 2
8027
+ ];
8028
+ }
8029
+ });
8030
+ });
8031
+ return function(flowInstance) {
8032
+ return _ref.apply(this, arguments);
8033
+ };
8034
+ }());
7504
8035
  });
7505
8036
  this.hooks.dataController.call(dataController);
7506
8037
  validationController.setOptions({