@player-ui/common-expressions-plugin 0.12.0-next.4 → 0.12.0-next.6

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.
@@ -2157,6 +2157,12 @@ var CommonExpressionsPlugin = function() {
2157
2157
  size: function() {
2158
2158
  return size;
2159
2159
  },
2160
+ split: function() {
2161
+ return split;
2162
+ },
2163
+ substr: function() {
2164
+ return substr;
2165
+ },
2160
2166
  sum: function() {
2161
2167
  return sum;
2162
2168
  },
@@ -2964,8 +2970,8 @@ var CommonExpressionsPlugin = function() {
2964
2970
  return new _BindingInstance(rawBinding);
2965
2971
  };
2966
2972
  _class_call_check(this, _BindingInstance);
2967
- var split = Array.isArray(raw) ? raw : raw.split(".");
2968
- this.split = split.map(function(segment) {
2973
+ var split2 = Array.isArray(raw) ? raw : raw.split(".");
2974
+ this.split = split2.map(function(segment) {
2969
2975
  if (typeof segment === "number") {
2970
2976
  return segment;
2971
2977
  }
@@ -5506,6 +5512,178 @@ var CommonExpressionsPlugin = function() {
5506
5512
  ]);
5507
5513
  return AssetPlugin;
5508
5514
  }();
5515
+ var LocalStateStore = /*#__PURE__*/ function() {
5516
+ function LocalStateStore(onUpdate) {
5517
+ _class_call_check(this, LocalStateStore);
5518
+ this.updateCallback = onUpdate;
5519
+ this.state = /* @__PURE__ */ new Map();
5520
+ }
5521
+ _create_class(LocalStateStore, [
5522
+ {
5523
+ key: "removeKey",
5524
+ value: function removeKey(key) {
5525
+ this.state.delete(key);
5526
+ }
5527
+ },
5528
+ {
5529
+ key: "reset",
5530
+ value: function reset() {
5531
+ this.state.clear();
5532
+ }
5533
+ },
5534
+ {
5535
+ key: "useSharedState",
5536
+ value: function useSharedState(key) {
5537
+ var _this = this;
5538
+ return function(initialState) {
5539
+ if (!_this.state.has(key)) {
5540
+ _this.state.set(key, initialState);
5541
+ }
5542
+ return [
5543
+ _this.state.get(key),
5544
+ function(newState) {
5545
+ var current = _this.state.get(key);
5546
+ _this.state.set(key, newState);
5547
+ if (current !== newState) {
5548
+ var _this_updateCallback, _this1;
5549
+ (_this_updateCallback = (_this1 = _this).updateCallback) === null || _this_updateCallback === void 0 ? void 0 : _this_updateCallback.call(_this1);
5550
+ }
5551
+ }
5552
+ ];
5553
+ };
5554
+ }
5555
+ },
5556
+ {
5557
+ key: "getLocalStateFunction",
5558
+ value: function getLocalStateFunction(key, countKey) {
5559
+ var _this = this;
5560
+ return function(initialState) {
5561
+ if (!_this.state.has(key)) {
5562
+ _this.state.set(key, []);
5563
+ }
5564
+ if (!_this.state.has(countKey)) {
5565
+ _this.state.set(countKey, 0);
5566
+ }
5567
+ var localState = _this.state.get(key);
5568
+ var oldCount = _this.state.get(countKey);
5569
+ _this.state.set(countKey, oldCount + 1);
5570
+ if (localState.length <= oldCount) {
5571
+ localState.push(initialState);
5572
+ }
5573
+ var value = localState[oldCount];
5574
+ return [
5575
+ value,
5576
+ function(newState) {
5577
+ var oldValue = localState[oldCount];
5578
+ localState[oldCount] = newState;
5579
+ if (oldValue !== newState) {
5580
+ var _this_updateCallback, _this1;
5581
+ (_this_updateCallback = (_this1 = _this).updateCallback) === null || _this_updateCallback === void 0 ? void 0 : _this_updateCallback.call(_this1);
5582
+ }
5583
+ }
5584
+ ];
5585
+ };
5586
+ }
5587
+ }
5588
+ ]);
5589
+ return LocalStateStore;
5590
+ }();
5591
+ function findUp(node, target) {
5592
+ if (node === target) {
5593
+ return true;
5594
+ }
5595
+ if (node.parent) {
5596
+ return findUp(node.parent, target);
5597
+ }
5598
+ return false;
5599
+ }
5600
+ var AssetTransformCorePlugin = /*#__PURE__*/ function() {
5601
+ function AssetTransformCorePlugin(registry) {
5602
+ _class_call_check(this, AssetTransformCorePlugin);
5603
+ this.registry = registry;
5604
+ this.stateStore = /* @__PURE__ */ new Map();
5605
+ this.beforeResolveSymbol = Symbol("before resolve");
5606
+ this.resolveSymbol = Symbol("resolve");
5607
+ this.beforeResolveCountSymbol = Symbol("before resolve count");
5608
+ this.resolveCountSymbol = Symbol("resolve count");
5609
+ }
5610
+ _create_class(AssetTransformCorePlugin, [
5611
+ {
5612
+ key: "apply",
5613
+ value: function apply(view) {
5614
+ var _this = this;
5615
+ this.stateStore.clear();
5616
+ view.hooks.resolver.tap("asset-transform", function(resolver) {
5617
+ var lastUpdatedNode;
5618
+ var updateState = function(node) {
5619
+ lastUpdatedNode = node;
5620
+ view.update(/* @__PURE__ */ new Set());
5621
+ };
5622
+ var getStore = function(node, stepKey) {
5623
+ var store;
5624
+ var countKey = stepKey === _this.resolveSymbol ? _this.resolveCountSymbol : _this.beforeResolveCountSymbol;
5625
+ var storedState = _this.stateStore.get(node);
5626
+ if (storedState) {
5627
+ store = storedState;
5628
+ store.removeKey(countKey);
5629
+ } else {
5630
+ store = new LocalStateStore(function() {
5631
+ updateState(node);
5632
+ });
5633
+ _this.stateStore.set(node, store);
5634
+ }
5635
+ return {
5636
+ useSharedState: function(key) {
5637
+ return store.useSharedState(key);
5638
+ },
5639
+ useLocalState: function(initialState) {
5640
+ return store.getLocalStateFunction(stepKey, countKey)(initialState);
5641
+ }
5642
+ };
5643
+ };
5644
+ resolver.hooks.beforeResolve.tap("asset-transform", function(node, options) {
5645
+ if (node && (node.type === "asset" || node.type === "view")) {
5646
+ var transform = _this.registry.get(node.value);
5647
+ if (transform === null || transform === void 0 ? void 0 : transform.beforeResolve) {
5648
+ var _options_node;
5649
+ var store = getStore((_options_node = options.node) !== null && _options_node !== void 0 ? _options_node : node, _this.beforeResolveSymbol);
5650
+ return transform.beforeResolve(node, options, store);
5651
+ }
5652
+ }
5653
+ return node;
5654
+ });
5655
+ resolver.hooks.afterUpdate.tap("asset-transform", function() {
5656
+ lastUpdatedNode = void 0;
5657
+ });
5658
+ resolver.hooks.skipResolve.tap("asset-transform", function(skip, node) {
5659
+ if (!skip || !lastUpdatedNode) {
5660
+ return skip;
5661
+ }
5662
+ var isParentOfUpdated = findUp(lastUpdatedNode, node);
5663
+ var isChildOfUpdated = findUp(node, lastUpdatedNode);
5664
+ return !isParentOfUpdated && !isChildOfUpdated;
5665
+ });
5666
+ resolver.hooks.afterResolve.tap("asset-transform", function(value, node, options) {
5667
+ if (node.type !== "asset" && node.type !== "view") {
5668
+ return value;
5669
+ }
5670
+ var originalNode = resolver.getSourceNode(node);
5671
+ if (!originalNode) {
5672
+ return value;
5673
+ }
5674
+ var transform = _this.registry.get(value);
5675
+ if (transform === null || transform === void 0 ? void 0 : transform.resolve) {
5676
+ var store = getStore(originalNode, _this.resolveSymbol);
5677
+ return transform === null || transform === void 0 ? void 0 : transform.resolve(value, options, store);
5678
+ }
5679
+ return value;
5680
+ });
5681
+ });
5682
+ }
5683
+ }
5684
+ ]);
5685
+ return AssetTransformCorePlugin;
5686
+ }();
5509
5687
  var FlowInstance = /*#__PURE__*/ function() {
5510
5688
  function FlowInstance(id, flow, options) {
5511
5689
  _class_call_check(this, FlowInstance);
@@ -6535,180 +6713,6 @@ var CommonExpressionsPlugin = function() {
6535
6713
  ]);
6536
6714
  return ValidationController;
6537
6715
  }();
6538
- var LocalStateStore = /*#__PURE__*/ function() {
6539
- function LocalStateStore(onUpdate) {
6540
- _class_call_check(this, LocalStateStore);
6541
- this.updateCallback = onUpdate;
6542
- this.state = /* @__PURE__ */ new Map();
6543
- }
6544
- _create_class(LocalStateStore, [
6545
- {
6546
- key: "removeKey",
6547
- value: function removeKey(key) {
6548
- this.state.delete(key);
6549
- }
6550
- },
6551
- {
6552
- key: "reset",
6553
- value: function reset() {
6554
- this.state.clear();
6555
- }
6556
- },
6557
- {
6558
- key: "useSharedState",
6559
- value: function useSharedState(key) {
6560
- var _this = this;
6561
- return function(initialState) {
6562
- if (!_this.state.has(key)) {
6563
- _this.state.set(key, initialState);
6564
- }
6565
- return [
6566
- _this.state.get(key),
6567
- function(newState) {
6568
- var current = _this.state.get(key);
6569
- _this.state.set(key, newState);
6570
- if (current !== newState) {
6571
- var _this_updateCallback, _this1;
6572
- (_this_updateCallback = (_this1 = _this).updateCallback) === null || _this_updateCallback === void 0 ? void 0 : _this_updateCallback.call(_this1);
6573
- }
6574
- }
6575
- ];
6576
- };
6577
- }
6578
- },
6579
- {
6580
- key: "getLocalStateFunction",
6581
- value: function getLocalStateFunction(key, countKey) {
6582
- var _this = this;
6583
- return function(initialState) {
6584
- if (!_this.state.has(key)) {
6585
- _this.state.set(key, []);
6586
- }
6587
- if (!_this.state.has(countKey)) {
6588
- _this.state.set(countKey, 0);
6589
- }
6590
- var localState = _this.state.get(key);
6591
- var oldCount = _this.state.get(countKey);
6592
- _this.state.set(countKey, oldCount + 1);
6593
- if (localState.length <= oldCount) {
6594
- localState.push(initialState);
6595
- }
6596
- var value = localState[oldCount];
6597
- return [
6598
- value,
6599
- function(newState) {
6600
- var oldValue = localState[oldCount];
6601
- localState[oldCount] = newState;
6602
- if (oldValue !== newState) {
6603
- var _this_updateCallback, _this1;
6604
- (_this_updateCallback = (_this1 = _this).updateCallback) === null || _this_updateCallback === void 0 ? void 0 : _this_updateCallback.call(_this1);
6605
- }
6606
- }
6607
- ];
6608
- };
6609
- }
6610
- }
6611
- ]);
6612
- return LocalStateStore;
6613
- }();
6614
- function findUp(node, target) {
6615
- if (node === target) {
6616
- return true;
6617
- }
6618
- if (node.parent) {
6619
- return findUp(node.parent, target);
6620
- }
6621
- return false;
6622
- }
6623
- var AssetTransformCorePlugin = /*#__PURE__*/ function() {
6624
- function AssetTransformCorePlugin(registry) {
6625
- _class_call_check(this, AssetTransformCorePlugin);
6626
- this.registry = registry;
6627
- this.stateStore = /* @__PURE__ */ new Map();
6628
- this.beforeResolveSymbol = Symbol("before resolve");
6629
- this.resolveSymbol = Symbol("resolve");
6630
- this.beforeResolveCountSymbol = Symbol("before resolve count");
6631
- this.resolveCountSymbol = Symbol("resolve count");
6632
- }
6633
- _create_class(AssetTransformCorePlugin, [
6634
- {
6635
- key: "apply",
6636
- value: function apply(viewController) {
6637
- var _this = this;
6638
- viewController.hooks.view.tap("asset-transform", function(view) {
6639
- _this.stateStore.clear();
6640
- view.hooks.resolver.tap("asset-transform", function(resolver) {
6641
- var lastUpdatedNode;
6642
- var updateState = function(node) {
6643
- lastUpdatedNode = node;
6644
- view.update(/* @__PURE__ */ new Set());
6645
- };
6646
- var getStore = function(node, stepKey) {
6647
- var store;
6648
- var countKey = stepKey === _this.resolveSymbol ? _this.resolveCountSymbol : _this.beforeResolveCountSymbol;
6649
- var storedState = _this.stateStore.get(node);
6650
- if (storedState) {
6651
- store = storedState;
6652
- store.removeKey(countKey);
6653
- } else {
6654
- store = new LocalStateStore(function() {
6655
- updateState(node);
6656
- });
6657
- _this.stateStore.set(node, store);
6658
- }
6659
- return {
6660
- useSharedState: function(key) {
6661
- return store.useSharedState(key);
6662
- },
6663
- useLocalState: function(initialState) {
6664
- return store.getLocalStateFunction(stepKey, countKey)(initialState);
6665
- }
6666
- };
6667
- };
6668
- resolver.hooks.beforeResolve.tap("asset-transform", function(node, options) {
6669
- if (node && (node.type === "asset" || node.type === "view")) {
6670
- var transform = _this.registry.get(node.value);
6671
- if (transform === null || transform === void 0 ? void 0 : transform.beforeResolve) {
6672
- var _options_node;
6673
- var store = getStore((_options_node = options.node) !== null && _options_node !== void 0 ? _options_node : node, _this.beforeResolveSymbol);
6674
- return transform.beforeResolve(node, options, store);
6675
- }
6676
- }
6677
- return node;
6678
- });
6679
- resolver.hooks.afterUpdate.tap("asset-transform", function() {
6680
- lastUpdatedNode = void 0;
6681
- });
6682
- resolver.hooks.skipResolve.tap("asset-transform", function(skip, node) {
6683
- if (!skip || !lastUpdatedNode) {
6684
- return skip;
6685
- }
6686
- var isParentOfUpdated = findUp(lastUpdatedNode, node);
6687
- var isChildOfUpdated = findUp(node, lastUpdatedNode);
6688
- return !isParentOfUpdated && !isChildOfUpdated;
6689
- });
6690
- resolver.hooks.afterResolve.tap("asset-transform", function(value, node, options) {
6691
- if (node.type !== "asset" && node.type !== "view") {
6692
- return value;
6693
- }
6694
- var originalNode = resolver.getSourceNode(node);
6695
- if (!originalNode) {
6696
- return value;
6697
- }
6698
- var transform = _this.registry.get(value);
6699
- if (transform === null || transform === void 0 ? void 0 : transform.resolve) {
6700
- var store = getStore(originalNode, _this.resolveSymbol);
6701
- return transform === null || transform === void 0 ? void 0 : transform.resolve(value, options, store);
6702
- }
6703
- return value;
6704
- });
6705
- });
6706
- });
6707
- }
6708
- }
6709
- ]);
6710
- return AssetTransformCorePlugin;
6711
- }();
6712
6716
  var ViewController = /*#__PURE__*/ function() {
6713
6717
  function ViewController(initialViews, options) {
6714
6718
  var _this = this;
@@ -6726,7 +6730,6 @@ var CommonExpressionsPlugin = function() {
6726
6730
  viewMap[view.id] = view;
6727
6731
  return viewMap;
6728
6732
  }, {});
6729
- new AssetTransformCorePlugin(this.transformRegistry).apply(this);
6730
6733
  options.flowController.hooks.flow.tap("viewController", function(flow) {
6731
6734
  flow.hooks.transition.tap("viewController", function(_oldState, newState) {
6732
6735
  if (newState.value.state_type === "VIEW") {
@@ -7211,6 +7214,7 @@ var CommonExpressionsPlugin = function() {
7211
7214
  new AssetPlugin().apply(view);
7212
7215
  new SwitchPlugin(pluginOptions).apply(view);
7213
7216
  new ApplicabilityPlugin().apply(view);
7217
+ new AssetTransformCorePlugin(viewController.transformRegistry).apply(view);
7214
7218
  new StringResolverPlugin().apply(view);
7215
7219
  var templatePlugin = new TemplatePlugin(pluginOptions);
7216
7220
  templatePlugin.apply(view);
@@ -7678,6 +7682,31 @@ var CommonExpressionsPlugin = function() {
7678
7682
  return word.toUpperCase();
7679
7683
  });
7680
7684
  }));
7685
+ var split = withoutContext(function(str, separator, limit) {
7686
+ if (separator === void 0 || separator === null) {
7687
+ return str;
7688
+ }
7689
+ var separatorStr = String(separator);
7690
+ if (separatorStr === "") {
7691
+ var result2 = str.split("");
7692
+ if (limit !== void 0 && limit !== null && limit > 0) {
7693
+ return result2.slice(0, limit);
7694
+ }
7695
+ return result2;
7696
+ }
7697
+ var result = str.split(separatorStr);
7698
+ if (limit !== void 0 && limit !== null && limit > 0) {
7699
+ return result.slice(0, limit);
7700
+ }
7701
+ return result;
7702
+ });
7703
+ var substr = withoutContext(function(str, start, length2) {
7704
+ var actualStartIndex = start < 0 ? str.length + start : start;
7705
+ if (length2 !== void 0) {
7706
+ return str.substring(actualStartIndex, actualStartIndex + length2);
7707
+ }
7708
+ return str.substring(actualStartIndex);
7709
+ });
7681
7710
  var number = withoutContext(toNum);
7682
7711
  var round = withoutContext(function(num) {
7683
7712
  var _toNum;