@player-ui/async-node-plugin 0.11.3--canary.670.23708 → 0.11.3--canary.670.24048

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.
@@ -5596,6 +5596,178 @@ var AsyncNodePlugin = function() {
5596
5596
  ]);
5597
5597
  return AssetPlugin;
5598
5598
  }();
5599
+ var LocalStateStore = /*#__PURE__*/ function() {
5600
+ function LocalStateStore(onUpdate) {
5601
+ _class_call_check(this, LocalStateStore);
5602
+ this.updateCallback = onUpdate;
5603
+ this.state = /* @__PURE__ */ new Map();
5604
+ }
5605
+ _create_class(LocalStateStore, [
5606
+ {
5607
+ key: "removeKey",
5608
+ value: function removeKey(key) {
5609
+ this.state.delete(key);
5610
+ }
5611
+ },
5612
+ {
5613
+ key: "reset",
5614
+ value: function reset() {
5615
+ this.state.clear();
5616
+ }
5617
+ },
5618
+ {
5619
+ key: "useSharedState",
5620
+ value: function useSharedState(key) {
5621
+ var _this = this;
5622
+ return function(initialState) {
5623
+ if (!_this.state.has(key)) {
5624
+ _this.state.set(key, initialState);
5625
+ }
5626
+ return [
5627
+ _this.state.get(key),
5628
+ function(newState) {
5629
+ var current = _this.state.get(key);
5630
+ _this.state.set(key, newState);
5631
+ if (current !== newState) {
5632
+ var _this_updateCallback, _this1;
5633
+ (_this_updateCallback = (_this1 = _this).updateCallback) === null || _this_updateCallback === void 0 ? void 0 : _this_updateCallback.call(_this1);
5634
+ }
5635
+ }
5636
+ ];
5637
+ };
5638
+ }
5639
+ },
5640
+ {
5641
+ key: "getLocalStateFunction",
5642
+ value: function getLocalStateFunction(key, countKey) {
5643
+ var _this = this;
5644
+ return function(initialState) {
5645
+ if (!_this.state.has(key)) {
5646
+ _this.state.set(key, []);
5647
+ }
5648
+ if (!_this.state.has(countKey)) {
5649
+ _this.state.set(countKey, 0);
5650
+ }
5651
+ var localState = _this.state.get(key);
5652
+ var oldCount = _this.state.get(countKey);
5653
+ _this.state.set(countKey, oldCount + 1);
5654
+ if (localState.length <= oldCount) {
5655
+ localState.push(initialState);
5656
+ }
5657
+ var value = localState[oldCount];
5658
+ return [
5659
+ value,
5660
+ function(newState) {
5661
+ var oldValue = localState[oldCount];
5662
+ localState[oldCount] = newState;
5663
+ if (oldValue !== newState) {
5664
+ var _this_updateCallback, _this1;
5665
+ (_this_updateCallback = (_this1 = _this).updateCallback) === null || _this_updateCallback === void 0 ? void 0 : _this_updateCallback.call(_this1);
5666
+ }
5667
+ }
5668
+ ];
5669
+ };
5670
+ }
5671
+ }
5672
+ ]);
5673
+ return LocalStateStore;
5674
+ }();
5675
+ function findUp(node, target) {
5676
+ if (node === target) {
5677
+ return true;
5678
+ }
5679
+ if (node.parent) {
5680
+ return findUp(node.parent, target);
5681
+ }
5682
+ return false;
5683
+ }
5684
+ var AssetTransformCorePlugin = /*#__PURE__*/ function() {
5685
+ function AssetTransformCorePlugin(registry) {
5686
+ _class_call_check(this, AssetTransformCorePlugin);
5687
+ this.registry = registry;
5688
+ this.stateStore = /* @__PURE__ */ new Map();
5689
+ this.beforeResolveSymbol = Symbol("before resolve");
5690
+ this.resolveSymbol = Symbol("resolve");
5691
+ this.beforeResolveCountSymbol = Symbol("before resolve count");
5692
+ this.resolveCountSymbol = Symbol("resolve count");
5693
+ }
5694
+ _create_class(AssetTransformCorePlugin, [
5695
+ {
5696
+ key: "apply",
5697
+ value: function apply(view) {
5698
+ var _this = this;
5699
+ this.stateStore.clear();
5700
+ view.hooks.resolver.tap("asset-transform", function(resolver) {
5701
+ var lastUpdatedNode;
5702
+ var updateState = function(node) {
5703
+ lastUpdatedNode = node;
5704
+ view.update(/* @__PURE__ */ new Set());
5705
+ };
5706
+ var getStore = function(node, stepKey) {
5707
+ var store;
5708
+ var countKey = stepKey === _this.resolveSymbol ? _this.resolveCountSymbol : _this.beforeResolveCountSymbol;
5709
+ var storedState = _this.stateStore.get(node);
5710
+ if (storedState) {
5711
+ store = storedState;
5712
+ store.removeKey(countKey);
5713
+ } else {
5714
+ store = new LocalStateStore(function() {
5715
+ updateState(node);
5716
+ });
5717
+ _this.stateStore.set(node, store);
5718
+ }
5719
+ return {
5720
+ useSharedState: function(key) {
5721
+ return store.useSharedState(key);
5722
+ },
5723
+ useLocalState: function(initialState) {
5724
+ return store.getLocalStateFunction(stepKey, countKey)(initialState);
5725
+ }
5726
+ };
5727
+ };
5728
+ resolver.hooks.beforeResolve.tap("asset-transform", function(node, options) {
5729
+ if (node && (node.type === "asset" || node.type === "view")) {
5730
+ var transform = _this.registry.get(node.value);
5731
+ if (transform === null || transform === void 0 ? void 0 : transform.beforeResolve) {
5732
+ var _options_node;
5733
+ var store = getStore((_options_node = options.node) !== null && _options_node !== void 0 ? _options_node : node, _this.beforeResolveSymbol);
5734
+ return transform.beforeResolve(node, options, store);
5735
+ }
5736
+ }
5737
+ return node;
5738
+ });
5739
+ resolver.hooks.afterUpdate.tap("asset-transform", function() {
5740
+ lastUpdatedNode = void 0;
5741
+ });
5742
+ resolver.hooks.skipResolve.tap("asset-transform", function(skip, node) {
5743
+ if (!skip || !lastUpdatedNode) {
5744
+ return skip;
5745
+ }
5746
+ var isParentOfUpdated = findUp(lastUpdatedNode, node);
5747
+ var isChildOfUpdated = findUp(node, lastUpdatedNode);
5748
+ return !isParentOfUpdated && !isChildOfUpdated;
5749
+ });
5750
+ resolver.hooks.afterResolve.tap("asset-transform", function(value, node, options) {
5751
+ if (node.type !== "asset" && node.type !== "view") {
5752
+ return value;
5753
+ }
5754
+ var originalNode = resolver.getSourceNode(node);
5755
+ if (!originalNode) {
5756
+ return value;
5757
+ }
5758
+ var transform = _this.registry.get(value);
5759
+ if (transform === null || transform === void 0 ? void 0 : transform.resolve) {
5760
+ var store = getStore(originalNode, _this.resolveSymbol);
5761
+ return transform === null || transform === void 0 ? void 0 : transform.resolve(value, options, store);
5762
+ }
5763
+ return value;
5764
+ });
5765
+ });
5766
+ }
5767
+ }
5768
+ ]);
5769
+ return AssetTransformCorePlugin;
5770
+ }();
5599
5771
  var FlowInstance = /*#__PURE__*/ function() {
5600
5772
  function FlowInstance(id, flow, options) {
5601
5773
  _class_call_check(this, FlowInstance);
@@ -6625,180 +6797,6 @@ var AsyncNodePlugin = function() {
6625
6797
  ]);
6626
6798
  return ValidationController;
6627
6799
  }();
6628
- var LocalStateStore = /*#__PURE__*/ function() {
6629
- function LocalStateStore(onUpdate) {
6630
- _class_call_check(this, LocalStateStore);
6631
- this.updateCallback = onUpdate;
6632
- this.state = /* @__PURE__ */ new Map();
6633
- }
6634
- _create_class(LocalStateStore, [
6635
- {
6636
- key: "removeKey",
6637
- value: function removeKey(key) {
6638
- this.state.delete(key);
6639
- }
6640
- },
6641
- {
6642
- key: "reset",
6643
- value: function reset() {
6644
- this.state.clear();
6645
- }
6646
- },
6647
- {
6648
- key: "useSharedState",
6649
- value: function useSharedState(key) {
6650
- var _this = this;
6651
- return function(initialState) {
6652
- if (!_this.state.has(key)) {
6653
- _this.state.set(key, initialState);
6654
- }
6655
- return [
6656
- _this.state.get(key),
6657
- function(newState) {
6658
- var current = _this.state.get(key);
6659
- _this.state.set(key, newState);
6660
- if (current !== newState) {
6661
- var _this_updateCallback, _this1;
6662
- (_this_updateCallback = (_this1 = _this).updateCallback) === null || _this_updateCallback === void 0 ? void 0 : _this_updateCallback.call(_this1);
6663
- }
6664
- }
6665
- ];
6666
- };
6667
- }
6668
- },
6669
- {
6670
- key: "getLocalStateFunction",
6671
- value: function getLocalStateFunction(key, countKey) {
6672
- var _this = this;
6673
- return function(initialState) {
6674
- if (!_this.state.has(key)) {
6675
- _this.state.set(key, []);
6676
- }
6677
- if (!_this.state.has(countKey)) {
6678
- _this.state.set(countKey, 0);
6679
- }
6680
- var localState = _this.state.get(key);
6681
- var oldCount = _this.state.get(countKey);
6682
- _this.state.set(countKey, oldCount + 1);
6683
- if (localState.length <= oldCount) {
6684
- localState.push(initialState);
6685
- }
6686
- var value = localState[oldCount];
6687
- return [
6688
- value,
6689
- function(newState) {
6690
- var oldValue = localState[oldCount];
6691
- localState[oldCount] = newState;
6692
- if (oldValue !== newState) {
6693
- var _this_updateCallback, _this1;
6694
- (_this_updateCallback = (_this1 = _this).updateCallback) === null || _this_updateCallback === void 0 ? void 0 : _this_updateCallback.call(_this1);
6695
- }
6696
- }
6697
- ];
6698
- };
6699
- }
6700
- }
6701
- ]);
6702
- return LocalStateStore;
6703
- }();
6704
- function findUp(node, target) {
6705
- if (node === target) {
6706
- return true;
6707
- }
6708
- if (node.parent) {
6709
- return findUp(node.parent, target);
6710
- }
6711
- return false;
6712
- }
6713
- var AssetTransformCorePlugin = /*#__PURE__*/ function() {
6714
- function AssetTransformCorePlugin(registry) {
6715
- _class_call_check(this, AssetTransformCorePlugin);
6716
- this.registry = registry;
6717
- this.stateStore = /* @__PURE__ */ new Map();
6718
- this.beforeResolveSymbol = Symbol("before resolve");
6719
- this.resolveSymbol = Symbol("resolve");
6720
- this.beforeResolveCountSymbol = Symbol("before resolve count");
6721
- this.resolveCountSymbol = Symbol("resolve count");
6722
- }
6723
- _create_class(AssetTransformCorePlugin, [
6724
- {
6725
- key: "apply",
6726
- value: function apply(viewController) {
6727
- var _this = this;
6728
- viewController.hooks.view.tap("asset-transform", function(view) {
6729
- _this.stateStore.clear();
6730
- view.hooks.resolver.tap("asset-transform", function(resolver) {
6731
- var lastUpdatedNode;
6732
- var updateState = function(node) {
6733
- lastUpdatedNode = node;
6734
- view.update(/* @__PURE__ */ new Set());
6735
- };
6736
- var getStore = function(node, stepKey) {
6737
- var store;
6738
- var countKey = stepKey === _this.resolveSymbol ? _this.resolveCountSymbol : _this.beforeResolveCountSymbol;
6739
- var storedState = _this.stateStore.get(node);
6740
- if (storedState) {
6741
- store = storedState;
6742
- store.removeKey(countKey);
6743
- } else {
6744
- store = new LocalStateStore(function() {
6745
- updateState(node);
6746
- });
6747
- _this.stateStore.set(node, store);
6748
- }
6749
- return {
6750
- useSharedState: function(key) {
6751
- return store.useSharedState(key);
6752
- },
6753
- useLocalState: function(initialState) {
6754
- return store.getLocalStateFunction(stepKey, countKey)(initialState);
6755
- }
6756
- };
6757
- };
6758
- resolver.hooks.beforeResolve.tap("asset-transform", function(node, options) {
6759
- if (node && (node.type === "asset" || node.type === "view")) {
6760
- var transform = _this.registry.get(node.value);
6761
- if (transform === null || transform === void 0 ? void 0 : transform.beforeResolve) {
6762
- var _options_node;
6763
- var store = getStore((_options_node = options.node) !== null && _options_node !== void 0 ? _options_node : node, _this.beforeResolveSymbol);
6764
- return transform.beforeResolve(node, options, store);
6765
- }
6766
- }
6767
- return node;
6768
- });
6769
- resolver.hooks.afterUpdate.tap("asset-transform", function() {
6770
- lastUpdatedNode = void 0;
6771
- });
6772
- resolver.hooks.skipResolve.tap("asset-transform", function(skip, node) {
6773
- if (!skip || !lastUpdatedNode) {
6774
- return skip;
6775
- }
6776
- var isParentOfUpdated = findUp(lastUpdatedNode, node);
6777
- var isChildOfUpdated = findUp(node, lastUpdatedNode);
6778
- return !isParentOfUpdated && !isChildOfUpdated;
6779
- });
6780
- resolver.hooks.afterResolve.tap("asset-transform", function(value, node, options) {
6781
- if (node.type !== "asset" && node.type !== "view") {
6782
- return value;
6783
- }
6784
- var originalNode = resolver.getSourceNode(node);
6785
- if (!originalNode) {
6786
- return value;
6787
- }
6788
- var transform = _this.registry.get(value);
6789
- if (transform === null || transform === void 0 ? void 0 : transform.resolve) {
6790
- var store = getStore(originalNode, _this.resolveSymbol);
6791
- return transform === null || transform === void 0 ? void 0 : transform.resolve(value, options, store);
6792
- }
6793
- return value;
6794
- });
6795
- });
6796
- });
6797
- }
6798
- }
6799
- ]);
6800
- return AssetTransformCorePlugin;
6801
- }();
6802
6800
  var ViewController = /*#__PURE__*/ function() {
6803
6801
  function ViewController(initialViews, options) {
6804
6802
  var _this = this;
@@ -6816,7 +6814,6 @@ var AsyncNodePlugin = function() {
6816
6814
  viewMap[view.id] = view;
6817
6815
  return viewMap;
6818
6816
  }, {});
6819
- new AssetTransformCorePlugin(this.transformRegistry).apply(this);
6820
6817
  options.flowController.hooks.flow.tap("viewController", function(flow) {
6821
6818
  flow.hooks.transition.tap("viewController", function(_oldState, newState) {
6822
6819
  if (newState.value.state_type === "VIEW") {
@@ -7301,6 +7298,7 @@ var AsyncNodePlugin = function() {
7301
7298
  new AssetPlugin().apply(view);
7302
7299
  new SwitchPlugin(pluginOptions).apply(view);
7303
7300
  new ApplicabilityPlugin().apply(view);
7301
+ new AssetTransformCorePlugin(viewController.transformRegistry).apply(view);
7304
7302
  new StringResolverPlugin().apply(view);
7305
7303
  var templatePlugin = new TemplatePlugin(pluginOptions);
7306
7304
  templatePlugin.apply(view);