@player-ui/common-types-plugin 0.13.0-next.0 → 0.13.0-next.2

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.
@@ -5174,20 +5174,15 @@ var CommonTypesPlugin = function() {
5174
5174
  }();
5175
5175
  var ViewInstance = /*#__PURE__*/ function() {
5176
5176
  function ViewInstance(initialView, resolverOptions) {
5177
- var _this = this;
5178
5177
  _class_call_check(this, ViewInstance);
5179
5178
  this.hooks = {
5180
5179
  onUpdate: new SyncHook(),
5181
5180
  parser: new SyncHook(),
5182
5181
  resolver: new SyncHook(),
5183
- onTemplatePluginCreated: new SyncHook(),
5184
5182
  templatePlugin: new SyncHook()
5185
5183
  };
5186
5184
  this.initialView = initialView;
5187
5185
  this.resolverOptions = resolverOptions;
5188
- this.hooks.onTemplatePluginCreated.tap("view", function(templatePlugin) {
5189
- _this.templatePlugin = templatePlugin;
5190
- });
5191
5186
  }
5192
5187
  _create_class(ViewInstance, [
5193
5188
  {
@@ -5234,6 +5229,12 @@ var CommonTypesPlugin = function() {
5234
5229
  var _this_validationProvider;
5235
5230
  return (_this_validationProvider = this.validationProvider) === null || _this_validationProvider === void 0 ? void 0 : _this_validationProvider.getValidationsForBinding(binding);
5236
5231
  }
5232
+ },
5233
+ {
5234
+ key: "setTemplatePlugin",
5235
+ value: function setTemplatePlugin(plugin) {
5236
+ this.templatePlugin = plugin;
5237
+ }
5237
5238
  }
5238
5239
  ]);
5239
5240
  return ViewInstance;
@@ -5405,6 +5406,7 @@ var CommonTypesPlugin = function() {
5405
5406
  value: function apply(view) {
5406
5407
  view.hooks.parser.tap("template", this.applyParser.bind(this));
5407
5408
  view.hooks.resolver.tap("template", this.applyResolverHooks.bind(this));
5409
+ view.setTemplatePlugin(this);
5408
5410
  }
5409
5411
  }
5410
5412
  ]);
@@ -5984,13 +5986,13 @@ var CommonTypesPlugin = function() {
5984
5986
  this.isTransitioning = false;
5985
5987
  this.hooks = {
5986
5988
  beforeStart: new SyncBailHook(),
5987
- /** A callback when the onStart node was present */ onStart: new SyncHook(),
5988
- /** A callback when the onEnd node was present */ onEnd: new SyncHook(),
5989
- /** A hook to intercept and block a transition */ skipTransition: new SyncBailHook(),
5990
- /** A chance to manipulate the flow-node used to calculate the given transition used */ beforeTransition: new SyncWaterfallHook(),
5991
- /** A chance to manipulate the flow-node calculated after a transition */ resolveTransitionNode: new SyncWaterfallHook(),
5992
- /** A callback when a transition from 1 state to another was made */ transition: new SyncHook(),
5993
- /** A callback to run actions after a transition occurs */ afterTransition: new SyncHook()
5989
+ onStart: new SyncHook(),
5990
+ onEnd: new SyncHook(),
5991
+ skipTransition: new SyncBailHook(),
5992
+ beforeTransition: new SyncWaterfallHook(),
5993
+ resolveTransitionNode: new SyncWaterfallHook(),
5994
+ transition: new SyncHook(),
5995
+ afterTransition: new SyncHook()
5994
5996
  };
5995
5997
  this.id = id;
5996
5998
  this.flow = flow;
@@ -7013,8 +7015,7 @@ var CommonTypesPlugin = function() {
7013
7015
  var _this1 = this;
7014
7016
  _class_call_check(this, ViewController);
7015
7017
  this.hooks = {
7016
- /** Do any processing before the `View` instance is created */ resolveView: new SyncWaterfallHook(),
7017
- // The hook right before the View starts resolving. Attach anything custom here
7018
+ resolveView: new SyncWaterfallHook(),
7018
7019
  view: new SyncHook()
7019
7020
  };
7020
7021
  this.transformRegistry = new Registry();
@@ -7062,6 +7063,7 @@ var CommonTypesPlugin = function() {
7062
7063
  ]));
7063
7064
  }
7064
7065
  });
7066
+ this.viewPlugins = this.createViewPlugins();
7065
7067
  }
7066
7068
  _create_class(ViewController, [
7067
7069
  {
@@ -7117,9 +7119,50 @@ var CommonTypesPlugin = function() {
7117
7119
  }
7118
7120
  var view = new ViewInstance(source, this.viewOptions);
7119
7121
  this.currentView = view;
7122
+ this.applyViewPlugins(view);
7120
7123
  this.hooks.view.call(view);
7121
7124
  view.update();
7122
7125
  }
7126
+ },
7127
+ {
7128
+ key: "applyViewPlugins",
7129
+ value: function applyViewPlugins(view) {
7130
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
7131
+ try {
7132
+ for(var _iterator = this.viewPlugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
7133
+ var plugin = _step.value;
7134
+ plugin.apply(view);
7135
+ }
7136
+ } catch (err) {
7137
+ _didIteratorError = true;
7138
+ _iteratorError = err;
7139
+ } finally{
7140
+ try {
7141
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
7142
+ _iterator.return();
7143
+ }
7144
+ } finally{
7145
+ if (_didIteratorError) {
7146
+ throw _iteratorError;
7147
+ }
7148
+ }
7149
+ }
7150
+ }
7151
+ },
7152
+ {
7153
+ key: "createViewPlugins",
7154
+ value: function createViewPlugins() {
7155
+ var pluginOptions = toNodeResolveOptions(this.viewOptions);
7156
+ return [
7157
+ new AssetPlugin(),
7158
+ new SwitchPlugin(pluginOptions),
7159
+ new ApplicabilityPlugin(),
7160
+ new AssetTransformCorePlugin(this.transformRegistry),
7161
+ new StringResolverPlugin(),
7162
+ new TemplatePlugin(pluginOptions),
7163
+ new MultiNodePlugin()
7164
+ ];
7165
+ }
7123
7166
  }
7124
7167
  ]);
7125
7168
  return ViewController;
@@ -7492,35 +7535,6 @@ var CommonTypesPlugin = function() {
7492
7535
  ref: Symbol("not-started"),
7493
7536
  status: "not-started"
7494
7537
  };
7495
- var DefaultViewPlugin = /*#__PURE__*/ function() {
7496
- function DefaultViewPlugin() {
7497
- _class_call_check(this, DefaultViewPlugin);
7498
- this.name = "default-view-plugin";
7499
- }
7500
- _create_class(DefaultViewPlugin, [
7501
- {
7502
- key: "apply",
7503
- value: function apply(player) {
7504
- var _this = this;
7505
- player.hooks.viewController.tap(this.name, function(viewController) {
7506
- viewController.hooks.view.tap(_this.name, function(view) {
7507
- var pluginOptions = toNodeResolveOptions(view.resolverOptions);
7508
- new AssetPlugin().apply(view);
7509
- new SwitchPlugin(pluginOptions).apply(view);
7510
- new ApplicabilityPlugin().apply(view);
7511
- new AssetTransformCorePlugin(viewController.transformRegistry).apply(view);
7512
- new StringResolverPlugin().apply(view);
7513
- var templatePlugin = new TemplatePlugin(pluginOptions);
7514
- templatePlugin.apply(view);
7515
- view.hooks.onTemplatePluginCreated.call(templatePlugin);
7516
- new MultiNodePlugin().apply(view);
7517
- });
7518
- });
7519
- }
7520
- }
7521
- ]);
7522
- return DefaultViewPlugin;
7523
- }();
7524
7538
  var PLAYER_VERSION = "__VERSION__";
7525
7539
  var COMMIT = "__GIT_COMMIT__";
7526
7540
  var _Player = /*#__PURE__*/ function() {
@@ -7550,8 +7564,7 @@ var CommonTypesPlugin = function() {
7550
7564
  }
7551
7565
  this.config = config || {};
7552
7566
  this.config.plugins = [
7553
- new DefaultExpPlugin(),
7554
- new DefaultViewPlugin()
7567
+ new DefaultExpPlugin()
7555
7568
  ].concat(_to_consumable_array(this.config.plugins || []), [
7556
7569
  new FlowExpPlugin()
7557
7570
  ]);
@@ -7738,95 +7751,41 @@ var CommonTypesPlugin = function() {
7738
7751
  validationController.reset();
7739
7752
  }
7740
7753
  });
7741
- flow.hooks.afterTransition.tap("player", function(flowInstance) {
7754
+ flow.hooks.afterTransition.tap("player-action-states", function(flowInstance) {
7742
7755
  var _flowInstance_currentState;
7743
7756
  var value = (_flowInstance_currentState = flowInstance.currentState) === null || _flowInstance_currentState === void 0 ? void 0 : _flowInstance_currentState.value;
7744
- if (value && value.state_type === "ACTION") {
7757
+ if (value && value.state_type === "ASYNC_ACTION") {
7745
7758
  var exp = value.exp;
7746
- var result = expressionEvaluator.evaluate(exp);
7747
- if (isPromiseLike(result)) {
7759
+ try {
7760
+ var result = expressionEvaluator.evaluateAsync(exp);
7761
+ if (isPromiseLike(result)) {
7762
+ if (value.await) {
7763
+ queueMicrotask(function() {
7764
+ result.then(function(r) {
7765
+ return flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(r));
7766
+ }).catch(flowResultDeferred.reject);
7767
+ });
7768
+ } else {
7769
+ _this.logger.warn("Unawaited promise used as return value in in non-async context, transitioning with '*' value");
7770
+ flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
7771
+ }
7772
+ } else {
7773
+ _this.logger.warn("Non async expression used in async action node");
7774
+ flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
7775
+ }
7776
+ } catch (e) {
7777
+ flowResultDeferred.reject(e);
7778
+ }
7779
+ } else if (value && value.state_type === "ACTION") {
7780
+ var exp1 = value.exp;
7781
+ var result1 = expressionEvaluator.evaluate(exp1);
7782
+ if (isPromiseLike(result1)) {
7748
7783
  _this.logger.warn("Async expression used as return value in in non-async context, transitioning with '*' value");
7749
7784
  }
7750
- flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
7785
+ flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result1));
7751
7786
  }
7752
7787
  expressionEvaluator.reset();
7753
7788
  });
7754
- var _this1 = _this;
7755
- flow.hooks.afterTransition.tap("player", function() {
7756
- var _ref = _async_to_generator(function(flowInstance) {
7757
- var _flowInstance_currentState, value, exp, result, e;
7758
- return _ts_generator(this, function(_state) {
7759
- switch(_state.label){
7760
- case 0:
7761
- value = (_flowInstance_currentState = flowInstance.currentState) === null || _flowInstance_currentState === void 0 ? void 0 : _flowInstance_currentState.value;
7762
- if (!(value && value.state_type === "ASYNC_ACTION")) return [
7763
- 3,
7764
- 8
7765
- ];
7766
- exp = value.exp;
7767
- _state.label = 1;
7768
- case 1:
7769
- _state.trys.push([
7770
- 1,
7771
- 7,
7772
- ,
7773
- 8
7774
- ]);
7775
- result = expressionEvaluator.evaluateAsync(exp);
7776
- if (!isPromiseLike(result)) return [
7777
- 3,
7778
- 5
7779
- ];
7780
- if (!value.await) return [
7781
- 3,
7782
- 3
7783
- ];
7784
- return [
7785
- 4,
7786
- result
7787
- ];
7788
- case 2:
7789
- result = _state.sent();
7790
- return [
7791
- 3,
7792
- 4
7793
- ];
7794
- case 3:
7795
- _this1.logger.warn("Unawaited promise used as return value in in non-async context, transitioning with '*' value");
7796
- _state.label = 4;
7797
- case 4:
7798
- return [
7799
- 3,
7800
- 6
7801
- ];
7802
- case 5:
7803
- _this1.logger.warn("Non async expression used in async action node");
7804
- _state.label = 6;
7805
- case 6:
7806
- flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
7807
- return [
7808
- 3,
7809
- 8
7810
- ];
7811
- case 7:
7812
- e = _state.sent();
7813
- flowResultDeferred.reject(e);
7814
- return [
7815
- 3,
7816
- 8
7817
- ];
7818
- case 8:
7819
- expressionEvaluator.reset();
7820
- return [
7821
- 2
7822
- ];
7823
- }
7824
- });
7825
- });
7826
- return function(flowInstance) {
7827
- return _ref.apply(this, arguments);
7828
- };
7829
- }());
7830
7789
  });
7831
7790
  this.hooks.dataController.call(dataController);
7832
7791
  validationController.setOptions({
@@ -7864,11 +7823,9 @@ var CommonTypesPlugin = function() {
7864
7823
  }),
7865
7824
  constants: this.constantsController
7866
7825
  });
7867
- this.hooks.viewController.tap("player", function(vc) {
7868
- vc.hooks.view.tap("player", function(view) {
7869
- validationController.onView(view);
7870
- _this.hooks.view.call(view);
7871
- });
7826
+ viewController.hooks.view.tap("player", function(view) {
7827
+ validationController.onView(view);
7828
+ _this.hooks.view.call(view);
7872
7829
  });
7873
7830
  this.hooks.viewController.call(viewController);
7874
7831
  return {