@player-ui/common-expressions-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.
@@ -2082,6 +2082,9 @@ var CommonExpressionsPlugin = function() {
2082
2082
  __export(src_exports, {
2083
2083
  CommonExpressionsPlugin: function() {
2084
2084
  return CommonExpressionsPlugin;
2085
+ },
2086
+ Expressions: function() {
2087
+ return expressions_exports;
2085
2088
  }
2086
2089
  });
2087
2090
  // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/node_modules/.aspect_rules_js/@player-ui+expression-plugin@0.0.0/node_modules/@player-ui/expression-plugin/dist/index.mjs
@@ -2154,6 +2157,12 @@ var CommonExpressionsPlugin = function() {
2154
2157
  size: function() {
2155
2158
  return size;
2156
2159
  },
2160
+ split: function() {
2161
+ return split;
2162
+ },
2163
+ substr: function() {
2164
+ return substr;
2165
+ },
2157
2166
  sum: function() {
2158
2167
  return sum;
2159
2168
  },
@@ -2961,8 +2970,8 @@ var CommonExpressionsPlugin = function() {
2961
2970
  return new _BindingInstance(rawBinding);
2962
2971
  };
2963
2972
  _class_call_check(this, _BindingInstance);
2964
- var split = Array.isArray(raw) ? raw : raw.split(".");
2965
- this.split = split.map(function(segment) {
2973
+ var split2 = Array.isArray(raw) ? raw : raw.split(".");
2974
+ this.split = split2.map(function(segment) {
2966
2975
  if (typeof segment === "number") {
2967
2976
  return segment;
2968
2977
  }
@@ -5503,6 +5512,178 @@ var CommonExpressionsPlugin = function() {
5503
5512
  ]);
5504
5513
  return AssetPlugin;
5505
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
+ }();
5506
5687
  var FlowInstance = /*#__PURE__*/ function() {
5507
5688
  function FlowInstance(id, flow, options) {
5508
5689
  _class_call_check(this, FlowInstance);
@@ -6532,180 +6713,6 @@ var CommonExpressionsPlugin = function() {
6532
6713
  ]);
6533
6714
  return ValidationController;
6534
6715
  }();
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
6716
  var ViewController = /*#__PURE__*/ function() {
6710
6717
  function ViewController(initialViews, options) {
6711
6718
  var _this = this;
@@ -6723,7 +6730,6 @@ var CommonExpressionsPlugin = function() {
6723
6730
  viewMap[view.id] = view;
6724
6731
  return viewMap;
6725
6732
  }, {});
6726
- new AssetTransformCorePlugin(this.transformRegistry).apply(this);
6727
6733
  options.flowController.hooks.flow.tap("viewController", function(flow) {
6728
6734
  flow.hooks.transition.tap("viewController", function(_oldState, newState) {
6729
6735
  if (newState.value.state_type === "VIEW") {
@@ -7208,6 +7214,7 @@ var CommonExpressionsPlugin = function() {
7208
7214
  new AssetPlugin().apply(view);
7209
7215
  new SwitchPlugin(pluginOptions).apply(view);
7210
7216
  new ApplicabilityPlugin().apply(view);
7217
+ new AssetTransformCorePlugin(viewController.transformRegistry).apply(view);
7211
7218
  new StringResolverPlugin().apply(view);
7212
7219
  var templatePlugin = new TemplatePlugin(pluginOptions);
7213
7220
  templatePlugin.apply(view);
@@ -7483,9 +7490,11 @@ var CommonExpressionsPlugin = function() {
7483
7490
  }),
7484
7491
  constants: this.constantsController
7485
7492
  });
7486
- viewController.hooks.view.tap("player", function(view) {
7487
- validationController.onView(view);
7488
- _this.hooks.view.call(view);
7493
+ this.hooks.viewController.tap("player", function(vc) {
7494
+ vc.hooks.view.tap("player", function(view) {
7495
+ validationController.onView(view);
7496
+ _this.hooks.view.call(view);
7497
+ });
7489
7498
  });
7490
7499
  this.hooks.viewController.call(viewController);
7491
7500
  return {
@@ -7675,6 +7684,31 @@ var CommonExpressionsPlugin = function() {
7675
7684
  return word.toUpperCase();
7676
7685
  });
7677
7686
  }));
7687
+ var split = withoutContext(function(str, separator, limit) {
7688
+ if (separator === void 0 || separator === null) {
7689
+ return str;
7690
+ }
7691
+ var separatorStr = String(separator);
7692
+ if (separatorStr === "") {
7693
+ var result2 = str.split("");
7694
+ if (limit !== void 0 && limit !== null && limit > 0) {
7695
+ return result2.slice(0, limit);
7696
+ }
7697
+ return result2;
7698
+ }
7699
+ var result = str.split(separatorStr);
7700
+ if (limit !== void 0 && limit !== null && limit > 0) {
7701
+ return result.slice(0, limit);
7702
+ }
7703
+ return result;
7704
+ });
7705
+ var substr = withoutContext(function(str, start, length2) {
7706
+ var actualStartIndex = start < 0 ? str.length + start : start;
7707
+ if (length2 !== void 0) {
7708
+ return str.substring(actualStartIndex, actualStartIndex + length2);
7709
+ }
7710
+ return str.substring(actualStartIndex);
7711
+ });
7678
7712
  var number = withoutContext(toNum);
7679
7713
  var round = withoutContext(function(num) {
7680
7714
  var _toNum;