@player-ui/common-types-plugin 0.12.0-next.0 → 0.12.0-next.10

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.
@@ -5503,6 +5503,178 @@ var CommonTypesPlugin = function() {
5503
5503
  ]);
5504
5504
  return AssetPlugin;
5505
5505
  }();
5506
+ var LocalStateStore = /*#__PURE__*/ function() {
5507
+ function LocalStateStore(onUpdate) {
5508
+ _class_call_check(this, LocalStateStore);
5509
+ this.updateCallback = onUpdate;
5510
+ this.state = /* @__PURE__ */ new Map();
5511
+ }
5512
+ _create_class(LocalStateStore, [
5513
+ {
5514
+ key: "removeKey",
5515
+ value: function removeKey(key) {
5516
+ this.state.delete(key);
5517
+ }
5518
+ },
5519
+ {
5520
+ key: "reset",
5521
+ value: function reset() {
5522
+ this.state.clear();
5523
+ }
5524
+ },
5525
+ {
5526
+ key: "useSharedState",
5527
+ value: function useSharedState(key) {
5528
+ var _this = this;
5529
+ return function(initialState) {
5530
+ if (!_this.state.has(key)) {
5531
+ _this.state.set(key, initialState);
5532
+ }
5533
+ return [
5534
+ _this.state.get(key),
5535
+ function(newState) {
5536
+ var current = _this.state.get(key);
5537
+ _this.state.set(key, newState);
5538
+ if (current !== newState) {
5539
+ var _this_updateCallback, _this1;
5540
+ (_this_updateCallback = (_this1 = _this).updateCallback) === null || _this_updateCallback === void 0 ? void 0 : _this_updateCallback.call(_this1);
5541
+ }
5542
+ }
5543
+ ];
5544
+ };
5545
+ }
5546
+ },
5547
+ {
5548
+ key: "getLocalStateFunction",
5549
+ value: function getLocalStateFunction(key, countKey) {
5550
+ var _this = this;
5551
+ return function(initialState) {
5552
+ if (!_this.state.has(key)) {
5553
+ _this.state.set(key, []);
5554
+ }
5555
+ if (!_this.state.has(countKey)) {
5556
+ _this.state.set(countKey, 0);
5557
+ }
5558
+ var localState = _this.state.get(key);
5559
+ var oldCount = _this.state.get(countKey);
5560
+ _this.state.set(countKey, oldCount + 1);
5561
+ if (localState.length <= oldCount) {
5562
+ localState.push(initialState);
5563
+ }
5564
+ var value = localState[oldCount];
5565
+ return [
5566
+ value,
5567
+ function(newState) {
5568
+ var oldValue = localState[oldCount];
5569
+ localState[oldCount] = newState;
5570
+ if (oldValue !== newState) {
5571
+ var _this_updateCallback, _this1;
5572
+ (_this_updateCallback = (_this1 = _this).updateCallback) === null || _this_updateCallback === void 0 ? void 0 : _this_updateCallback.call(_this1);
5573
+ }
5574
+ }
5575
+ ];
5576
+ };
5577
+ }
5578
+ }
5579
+ ]);
5580
+ return LocalStateStore;
5581
+ }();
5582
+ function findUp(node, target) {
5583
+ if (node === target) {
5584
+ return true;
5585
+ }
5586
+ if (node.parent) {
5587
+ return findUp(node.parent, target);
5588
+ }
5589
+ return false;
5590
+ }
5591
+ var AssetTransformCorePlugin = /*#__PURE__*/ function() {
5592
+ function AssetTransformCorePlugin(registry) {
5593
+ _class_call_check(this, AssetTransformCorePlugin);
5594
+ this.registry = registry;
5595
+ this.stateStore = /* @__PURE__ */ new Map();
5596
+ this.beforeResolveSymbol = Symbol("before resolve");
5597
+ this.resolveSymbol = Symbol("resolve");
5598
+ this.beforeResolveCountSymbol = Symbol("before resolve count");
5599
+ this.resolveCountSymbol = Symbol("resolve count");
5600
+ }
5601
+ _create_class(AssetTransformCorePlugin, [
5602
+ {
5603
+ key: "apply",
5604
+ value: function apply(view) {
5605
+ var _this = this;
5606
+ this.stateStore.clear();
5607
+ view.hooks.resolver.tap("asset-transform", function(resolver) {
5608
+ var lastUpdatedNode;
5609
+ var updateState = function(node) {
5610
+ lastUpdatedNode = node;
5611
+ view.update(/* @__PURE__ */ new Set());
5612
+ };
5613
+ var getStore = function(node, stepKey) {
5614
+ var store;
5615
+ var countKey = stepKey === _this.resolveSymbol ? _this.resolveCountSymbol : _this.beforeResolveCountSymbol;
5616
+ var storedState = _this.stateStore.get(node);
5617
+ if (storedState) {
5618
+ store = storedState;
5619
+ store.removeKey(countKey);
5620
+ } else {
5621
+ store = new LocalStateStore(function() {
5622
+ updateState(node);
5623
+ });
5624
+ _this.stateStore.set(node, store);
5625
+ }
5626
+ return {
5627
+ useSharedState: function(key) {
5628
+ return store.useSharedState(key);
5629
+ },
5630
+ useLocalState: function(initialState) {
5631
+ return store.getLocalStateFunction(stepKey, countKey)(initialState);
5632
+ }
5633
+ };
5634
+ };
5635
+ resolver.hooks.beforeResolve.tap("asset-transform", function(node, options) {
5636
+ if (node && (node.type === "asset" || node.type === "view")) {
5637
+ var transform = _this.registry.get(node.value);
5638
+ if (transform === null || transform === void 0 ? void 0 : transform.beforeResolve) {
5639
+ var _options_node;
5640
+ var store = getStore((_options_node = options.node) !== null && _options_node !== void 0 ? _options_node : node, _this.beforeResolveSymbol);
5641
+ return transform.beforeResolve(node, options, store);
5642
+ }
5643
+ }
5644
+ return node;
5645
+ });
5646
+ resolver.hooks.afterUpdate.tap("asset-transform", function() {
5647
+ lastUpdatedNode = void 0;
5648
+ });
5649
+ resolver.hooks.skipResolve.tap("asset-transform", function(skip, node) {
5650
+ if (!skip || !lastUpdatedNode) {
5651
+ return skip;
5652
+ }
5653
+ var isParentOfUpdated = findUp(lastUpdatedNode, node);
5654
+ var isChildOfUpdated = findUp(node, lastUpdatedNode);
5655
+ return !isParentOfUpdated && !isChildOfUpdated;
5656
+ });
5657
+ resolver.hooks.afterResolve.tap("asset-transform", function(value, node, options) {
5658
+ if (node.type !== "asset" && node.type !== "view") {
5659
+ return value;
5660
+ }
5661
+ var originalNode = resolver.getSourceNode(node);
5662
+ if (!originalNode) {
5663
+ return value;
5664
+ }
5665
+ var transform = _this.registry.get(value);
5666
+ if (transform === null || transform === void 0 ? void 0 : transform.resolve) {
5667
+ var store = getStore(originalNode, _this.resolveSymbol);
5668
+ return transform === null || transform === void 0 ? void 0 : transform.resolve(value, options, store);
5669
+ }
5670
+ return value;
5671
+ });
5672
+ });
5673
+ }
5674
+ }
5675
+ ]);
5676
+ return AssetTransformCorePlugin;
5677
+ }();
5506
5678
  var FlowInstance = /*#__PURE__*/ function() {
5507
5679
  function FlowInstance(id, flow, options) {
5508
5680
  _class_call_check(this, FlowInstance);
@@ -6532,180 +6704,6 @@ var CommonTypesPlugin = function() {
6532
6704
  ]);
6533
6705
  return ValidationController;
6534
6706
  }();
6535
- var LocalStateStore = /*#__PURE__*/ function() {
6536
- function LocalStateStore(onUpdate) {
6537
- _class_call_check(this, LocalStateStore);
6538
- this.updateCallback = onUpdate;
6539
- this.state = /* @__PURE__ */ new Map();
6540
- }
6541
- _create_class(LocalStateStore, [
6542
- {
6543
- key: "removeKey",
6544
- value: function removeKey(key) {
6545
- this.state.delete(key);
6546
- }
6547
- },
6548
- {
6549
- key: "reset",
6550
- value: function reset() {
6551
- this.state.clear();
6552
- }
6553
- },
6554
- {
6555
- key: "useSharedState",
6556
- value: function useSharedState(key) {
6557
- var _this = this;
6558
- return function(initialState) {
6559
- if (!_this.state.has(key)) {
6560
- _this.state.set(key, initialState);
6561
- }
6562
- return [
6563
- _this.state.get(key),
6564
- function(newState) {
6565
- var current = _this.state.get(key);
6566
- _this.state.set(key, newState);
6567
- if (current !== newState) {
6568
- var _this_updateCallback, _this1;
6569
- (_this_updateCallback = (_this1 = _this).updateCallback) === null || _this_updateCallback === void 0 ? void 0 : _this_updateCallback.call(_this1);
6570
- }
6571
- }
6572
- ];
6573
- };
6574
- }
6575
- },
6576
- {
6577
- key: "getLocalStateFunction",
6578
- value: function getLocalStateFunction(key, countKey) {
6579
- var _this = this;
6580
- return function(initialState) {
6581
- if (!_this.state.has(key)) {
6582
- _this.state.set(key, []);
6583
- }
6584
- if (!_this.state.has(countKey)) {
6585
- _this.state.set(countKey, 0);
6586
- }
6587
- var localState = _this.state.get(key);
6588
- var oldCount = _this.state.get(countKey);
6589
- _this.state.set(countKey, oldCount + 1);
6590
- if (localState.length <= oldCount) {
6591
- localState.push(initialState);
6592
- }
6593
- var value = localState[oldCount];
6594
- return [
6595
- value,
6596
- function(newState) {
6597
- var oldValue = localState[oldCount];
6598
- localState[oldCount] = newState;
6599
- if (oldValue !== newState) {
6600
- var _this_updateCallback, _this1;
6601
- (_this_updateCallback = (_this1 = _this).updateCallback) === null || _this_updateCallback === void 0 ? void 0 : _this_updateCallback.call(_this1);
6602
- }
6603
- }
6604
- ];
6605
- };
6606
- }
6607
- }
6608
- ]);
6609
- return LocalStateStore;
6610
- }();
6611
- function findUp(node, target) {
6612
- if (node === target) {
6613
- return true;
6614
- }
6615
- if (node.parent) {
6616
- return findUp(node.parent, target);
6617
- }
6618
- return false;
6619
- }
6620
- var AssetTransformCorePlugin = /*#__PURE__*/ function() {
6621
- function AssetTransformCorePlugin(registry) {
6622
- _class_call_check(this, AssetTransformCorePlugin);
6623
- this.registry = registry;
6624
- this.stateStore = /* @__PURE__ */ new Map();
6625
- this.beforeResolveSymbol = Symbol("before resolve");
6626
- this.resolveSymbol = Symbol("resolve");
6627
- this.beforeResolveCountSymbol = Symbol("before resolve count");
6628
- this.resolveCountSymbol = Symbol("resolve count");
6629
- }
6630
- _create_class(AssetTransformCorePlugin, [
6631
- {
6632
- key: "apply",
6633
- value: function apply(viewController) {
6634
- var _this = this;
6635
- viewController.hooks.view.tap("asset-transform", function(view) {
6636
- _this.stateStore.clear();
6637
- view.hooks.resolver.tap("asset-transform", function(resolver) {
6638
- var lastUpdatedNode;
6639
- var updateState = function(node) {
6640
- lastUpdatedNode = node;
6641
- view.update(/* @__PURE__ */ new Set());
6642
- };
6643
- var getStore = function(node, stepKey) {
6644
- var store;
6645
- var countKey = stepKey === _this.resolveSymbol ? _this.resolveCountSymbol : _this.beforeResolveCountSymbol;
6646
- var storedState = _this.stateStore.get(node);
6647
- if (storedState) {
6648
- store = storedState;
6649
- store.removeKey(countKey);
6650
- } else {
6651
- store = new LocalStateStore(function() {
6652
- updateState(node);
6653
- });
6654
- _this.stateStore.set(node, store);
6655
- }
6656
- return {
6657
- useSharedState: function(key) {
6658
- return store.useSharedState(key);
6659
- },
6660
- useLocalState: function(initialState) {
6661
- return store.getLocalStateFunction(stepKey, countKey)(initialState);
6662
- }
6663
- };
6664
- };
6665
- resolver.hooks.beforeResolve.tap("asset-transform", function(node, options) {
6666
- if (node && (node.type === "asset" || node.type === "view")) {
6667
- var transform = _this.registry.get(node.value);
6668
- if (transform === null || transform === void 0 ? void 0 : transform.beforeResolve) {
6669
- var _options_node;
6670
- var store = getStore((_options_node = options.node) !== null && _options_node !== void 0 ? _options_node : node, _this.beforeResolveSymbol);
6671
- return transform.beforeResolve(node, options, store);
6672
- }
6673
- }
6674
- return node;
6675
- });
6676
- resolver.hooks.afterUpdate.tap("asset-transform", function() {
6677
- lastUpdatedNode = void 0;
6678
- });
6679
- resolver.hooks.skipResolve.tap("asset-transform", function(skip, node) {
6680
- if (!skip || !lastUpdatedNode) {
6681
- return skip;
6682
- }
6683
- var isParentOfUpdated = findUp(lastUpdatedNode, node);
6684
- var isChildOfUpdated = findUp(node, lastUpdatedNode);
6685
- return !isParentOfUpdated && !isChildOfUpdated;
6686
- });
6687
- resolver.hooks.afterResolve.tap("asset-transform", function(value, node, options) {
6688
- if (node.type !== "asset" && node.type !== "view") {
6689
- return value;
6690
- }
6691
- var originalNode = resolver.getSourceNode(node);
6692
- if (!originalNode) {
6693
- return value;
6694
- }
6695
- var transform = _this.registry.get(value);
6696
- if (transform === null || transform === void 0 ? void 0 : transform.resolve) {
6697
- var store = getStore(originalNode, _this.resolveSymbol);
6698
- return transform === null || transform === void 0 ? void 0 : transform.resolve(value, options, store);
6699
- }
6700
- return value;
6701
- });
6702
- });
6703
- });
6704
- }
6705
- }
6706
- ]);
6707
- return AssetTransformCorePlugin;
6708
- }();
6709
6707
  var ViewController = /*#__PURE__*/ function() {
6710
6708
  function ViewController(initialViews, options) {
6711
6709
  var _this = this;
@@ -6723,7 +6721,6 @@ var CommonTypesPlugin = function() {
6723
6721
  viewMap[view.id] = view;
6724
6722
  return viewMap;
6725
6723
  }, {});
6726
- new AssetTransformCorePlugin(this.transformRegistry).apply(this);
6727
6724
  options.flowController.hooks.flow.tap("viewController", function(flow) {
6728
6725
  flow.hooks.transition.tap("viewController", function(_oldState, newState) {
6729
6726
  if (newState.value.state_type === "VIEW") {
@@ -7208,6 +7205,7 @@ var CommonTypesPlugin = function() {
7208
7205
  new AssetPlugin().apply(view);
7209
7206
  new SwitchPlugin(pluginOptions).apply(view);
7210
7207
  new ApplicabilityPlugin().apply(view);
7208
+ new AssetTransformCorePlugin(viewController.transformRegistry).apply(view);
7211
7209
  new StringResolverPlugin().apply(view);
7212
7210
  var templatePlugin = new TemplatePlugin(pluginOptions);
7213
7211
  templatePlugin.apply(view);
@@ -7483,9 +7481,11 @@ var CommonTypesPlugin = function() {
7483
7481
  }),
7484
7482
  constants: this.constantsController
7485
7483
  });
7486
- viewController.hooks.view.tap("player", function(view) {
7487
- validationController.onView(view);
7488
- _this.hooks.view.call(view);
7484
+ this.hooks.viewController.tap("player", function(vc) {
7485
+ vc.hooks.view.tap("player", function(view) {
7486
+ validationController.onView(view);
7487
+ _this.hooks.view.call(view);
7488
+ });
7489
7489
  });
7490
7490
  this.hooks.viewController.call(viewController);
7491
7491
  return {