@player-ui/common-expressions-plugin 0.12.0-next.3 → 0.12.0-next.5
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.
|
@@ -5506,6 +5506,178 @@ var CommonExpressionsPlugin = function() {
|
|
|
5506
5506
|
]);
|
|
5507
5507
|
return AssetPlugin;
|
|
5508
5508
|
}();
|
|
5509
|
+
var LocalStateStore = /*#__PURE__*/ function() {
|
|
5510
|
+
function LocalStateStore(onUpdate) {
|
|
5511
|
+
_class_call_check(this, LocalStateStore);
|
|
5512
|
+
this.updateCallback = onUpdate;
|
|
5513
|
+
this.state = /* @__PURE__ */ new Map();
|
|
5514
|
+
}
|
|
5515
|
+
_create_class(LocalStateStore, [
|
|
5516
|
+
{
|
|
5517
|
+
key: "removeKey",
|
|
5518
|
+
value: function removeKey(key) {
|
|
5519
|
+
this.state.delete(key);
|
|
5520
|
+
}
|
|
5521
|
+
},
|
|
5522
|
+
{
|
|
5523
|
+
key: "reset",
|
|
5524
|
+
value: function reset() {
|
|
5525
|
+
this.state.clear();
|
|
5526
|
+
}
|
|
5527
|
+
},
|
|
5528
|
+
{
|
|
5529
|
+
key: "useSharedState",
|
|
5530
|
+
value: function useSharedState(key) {
|
|
5531
|
+
var _this = this;
|
|
5532
|
+
return function(initialState) {
|
|
5533
|
+
if (!_this.state.has(key)) {
|
|
5534
|
+
_this.state.set(key, initialState);
|
|
5535
|
+
}
|
|
5536
|
+
return [
|
|
5537
|
+
_this.state.get(key),
|
|
5538
|
+
function(newState) {
|
|
5539
|
+
var current = _this.state.get(key);
|
|
5540
|
+
_this.state.set(key, newState);
|
|
5541
|
+
if (current !== newState) {
|
|
5542
|
+
var _this_updateCallback, _this1;
|
|
5543
|
+
(_this_updateCallback = (_this1 = _this).updateCallback) === null || _this_updateCallback === void 0 ? void 0 : _this_updateCallback.call(_this1);
|
|
5544
|
+
}
|
|
5545
|
+
}
|
|
5546
|
+
];
|
|
5547
|
+
};
|
|
5548
|
+
}
|
|
5549
|
+
},
|
|
5550
|
+
{
|
|
5551
|
+
key: "getLocalStateFunction",
|
|
5552
|
+
value: function getLocalStateFunction(key, countKey) {
|
|
5553
|
+
var _this = this;
|
|
5554
|
+
return function(initialState) {
|
|
5555
|
+
if (!_this.state.has(key)) {
|
|
5556
|
+
_this.state.set(key, []);
|
|
5557
|
+
}
|
|
5558
|
+
if (!_this.state.has(countKey)) {
|
|
5559
|
+
_this.state.set(countKey, 0);
|
|
5560
|
+
}
|
|
5561
|
+
var localState = _this.state.get(key);
|
|
5562
|
+
var oldCount = _this.state.get(countKey);
|
|
5563
|
+
_this.state.set(countKey, oldCount + 1);
|
|
5564
|
+
if (localState.length <= oldCount) {
|
|
5565
|
+
localState.push(initialState);
|
|
5566
|
+
}
|
|
5567
|
+
var value = localState[oldCount];
|
|
5568
|
+
return [
|
|
5569
|
+
value,
|
|
5570
|
+
function(newState) {
|
|
5571
|
+
var oldValue = localState[oldCount];
|
|
5572
|
+
localState[oldCount] = newState;
|
|
5573
|
+
if (oldValue !== newState) {
|
|
5574
|
+
var _this_updateCallback, _this1;
|
|
5575
|
+
(_this_updateCallback = (_this1 = _this).updateCallback) === null || _this_updateCallback === void 0 ? void 0 : _this_updateCallback.call(_this1);
|
|
5576
|
+
}
|
|
5577
|
+
}
|
|
5578
|
+
];
|
|
5579
|
+
};
|
|
5580
|
+
}
|
|
5581
|
+
}
|
|
5582
|
+
]);
|
|
5583
|
+
return LocalStateStore;
|
|
5584
|
+
}();
|
|
5585
|
+
function findUp(node, target) {
|
|
5586
|
+
if (node === target) {
|
|
5587
|
+
return true;
|
|
5588
|
+
}
|
|
5589
|
+
if (node.parent) {
|
|
5590
|
+
return findUp(node.parent, target);
|
|
5591
|
+
}
|
|
5592
|
+
return false;
|
|
5593
|
+
}
|
|
5594
|
+
var AssetTransformCorePlugin = /*#__PURE__*/ function() {
|
|
5595
|
+
function AssetTransformCorePlugin(registry) {
|
|
5596
|
+
_class_call_check(this, AssetTransformCorePlugin);
|
|
5597
|
+
this.registry = registry;
|
|
5598
|
+
this.stateStore = /* @__PURE__ */ new Map();
|
|
5599
|
+
this.beforeResolveSymbol = Symbol("before resolve");
|
|
5600
|
+
this.resolveSymbol = Symbol("resolve");
|
|
5601
|
+
this.beforeResolveCountSymbol = Symbol("before resolve count");
|
|
5602
|
+
this.resolveCountSymbol = Symbol("resolve count");
|
|
5603
|
+
}
|
|
5604
|
+
_create_class(AssetTransformCorePlugin, [
|
|
5605
|
+
{
|
|
5606
|
+
key: "apply",
|
|
5607
|
+
value: function apply(view) {
|
|
5608
|
+
var _this = this;
|
|
5609
|
+
this.stateStore.clear();
|
|
5610
|
+
view.hooks.resolver.tap("asset-transform", function(resolver) {
|
|
5611
|
+
var lastUpdatedNode;
|
|
5612
|
+
var updateState = function(node) {
|
|
5613
|
+
lastUpdatedNode = node;
|
|
5614
|
+
view.update(/* @__PURE__ */ new Set());
|
|
5615
|
+
};
|
|
5616
|
+
var getStore = function(node, stepKey) {
|
|
5617
|
+
var store;
|
|
5618
|
+
var countKey = stepKey === _this.resolveSymbol ? _this.resolveCountSymbol : _this.beforeResolveCountSymbol;
|
|
5619
|
+
var storedState = _this.stateStore.get(node);
|
|
5620
|
+
if (storedState) {
|
|
5621
|
+
store = storedState;
|
|
5622
|
+
store.removeKey(countKey);
|
|
5623
|
+
} else {
|
|
5624
|
+
store = new LocalStateStore(function() {
|
|
5625
|
+
updateState(node);
|
|
5626
|
+
});
|
|
5627
|
+
_this.stateStore.set(node, store);
|
|
5628
|
+
}
|
|
5629
|
+
return {
|
|
5630
|
+
useSharedState: function(key) {
|
|
5631
|
+
return store.useSharedState(key);
|
|
5632
|
+
},
|
|
5633
|
+
useLocalState: function(initialState) {
|
|
5634
|
+
return store.getLocalStateFunction(stepKey, countKey)(initialState);
|
|
5635
|
+
}
|
|
5636
|
+
};
|
|
5637
|
+
};
|
|
5638
|
+
resolver.hooks.beforeResolve.tap("asset-transform", function(node, options) {
|
|
5639
|
+
if (node && (node.type === "asset" || node.type === "view")) {
|
|
5640
|
+
var transform = _this.registry.get(node.value);
|
|
5641
|
+
if (transform === null || transform === void 0 ? void 0 : transform.beforeResolve) {
|
|
5642
|
+
var _options_node;
|
|
5643
|
+
var store = getStore((_options_node = options.node) !== null && _options_node !== void 0 ? _options_node : node, _this.beforeResolveSymbol);
|
|
5644
|
+
return transform.beforeResolve(node, options, store);
|
|
5645
|
+
}
|
|
5646
|
+
}
|
|
5647
|
+
return node;
|
|
5648
|
+
});
|
|
5649
|
+
resolver.hooks.afterUpdate.tap("asset-transform", function() {
|
|
5650
|
+
lastUpdatedNode = void 0;
|
|
5651
|
+
});
|
|
5652
|
+
resolver.hooks.skipResolve.tap("asset-transform", function(skip, node) {
|
|
5653
|
+
if (!skip || !lastUpdatedNode) {
|
|
5654
|
+
return skip;
|
|
5655
|
+
}
|
|
5656
|
+
var isParentOfUpdated = findUp(lastUpdatedNode, node);
|
|
5657
|
+
var isChildOfUpdated = findUp(node, lastUpdatedNode);
|
|
5658
|
+
return !isParentOfUpdated && !isChildOfUpdated;
|
|
5659
|
+
});
|
|
5660
|
+
resolver.hooks.afterResolve.tap("asset-transform", function(value, node, options) {
|
|
5661
|
+
if (node.type !== "asset" && node.type !== "view") {
|
|
5662
|
+
return value;
|
|
5663
|
+
}
|
|
5664
|
+
var originalNode = resolver.getSourceNode(node);
|
|
5665
|
+
if (!originalNode) {
|
|
5666
|
+
return value;
|
|
5667
|
+
}
|
|
5668
|
+
var transform = _this.registry.get(value);
|
|
5669
|
+
if (transform === null || transform === void 0 ? void 0 : transform.resolve) {
|
|
5670
|
+
var store = getStore(originalNode, _this.resolveSymbol);
|
|
5671
|
+
return transform === null || transform === void 0 ? void 0 : transform.resolve(value, options, store);
|
|
5672
|
+
}
|
|
5673
|
+
return value;
|
|
5674
|
+
});
|
|
5675
|
+
});
|
|
5676
|
+
}
|
|
5677
|
+
}
|
|
5678
|
+
]);
|
|
5679
|
+
return AssetTransformCorePlugin;
|
|
5680
|
+
}();
|
|
5509
5681
|
var FlowInstance = /*#__PURE__*/ function() {
|
|
5510
5682
|
function FlowInstance(id, flow, options) {
|
|
5511
5683
|
_class_call_check(this, FlowInstance);
|
|
@@ -6535,180 +6707,6 @@ var CommonExpressionsPlugin = function() {
|
|
|
6535
6707
|
]);
|
|
6536
6708
|
return ValidationController;
|
|
6537
6709
|
}();
|
|
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
6710
|
var ViewController = /*#__PURE__*/ function() {
|
|
6713
6711
|
function ViewController(initialViews, options) {
|
|
6714
6712
|
var _this = this;
|
|
@@ -6726,7 +6724,6 @@ var CommonExpressionsPlugin = function() {
|
|
|
6726
6724
|
viewMap[view.id] = view;
|
|
6727
6725
|
return viewMap;
|
|
6728
6726
|
}, {});
|
|
6729
|
-
new AssetTransformCorePlugin(this.transformRegistry).apply(this);
|
|
6730
6727
|
options.flowController.hooks.flow.tap("viewController", function(flow) {
|
|
6731
6728
|
flow.hooks.transition.tap("viewController", function(_oldState, newState) {
|
|
6732
6729
|
if (newState.value.state_type === "VIEW") {
|
|
@@ -7211,6 +7208,7 @@ var CommonExpressionsPlugin = function() {
|
|
|
7211
7208
|
new AssetPlugin().apply(view);
|
|
7212
7209
|
new SwitchPlugin(pluginOptions).apply(view);
|
|
7213
7210
|
new ApplicabilityPlugin().apply(view);
|
|
7211
|
+
new AssetTransformCorePlugin(viewController.transformRegistry).apply(view);
|
|
7214
7212
|
new StringResolverPlugin().apply(view);
|
|
7215
7213
|
var templatePlugin = new TemplatePlugin(pluginOptions);
|
|
7216
7214
|
templatePlugin.apply(view);
|