@player-ui/stage-revert-data-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.
@@ -5389,6 +5389,178 @@ var StageRevertDataPlugin = function() {
5389
5389
  ]);
5390
5390
  return AssetPlugin;
5391
5391
  }();
5392
+ var LocalStateStore = /*#__PURE__*/ function() {
5393
+ function LocalStateStore(onUpdate) {
5394
+ _class_call_check(this, LocalStateStore);
5395
+ this.updateCallback = onUpdate;
5396
+ this.state = /* @__PURE__ */ new Map();
5397
+ }
5398
+ _create_class(LocalStateStore, [
5399
+ {
5400
+ key: "removeKey",
5401
+ value: function removeKey(key) {
5402
+ this.state.delete(key);
5403
+ }
5404
+ },
5405
+ {
5406
+ key: "reset",
5407
+ value: function reset() {
5408
+ this.state.clear();
5409
+ }
5410
+ },
5411
+ {
5412
+ key: "useSharedState",
5413
+ value: function useSharedState(key) {
5414
+ var _this = this;
5415
+ return function(initialState) {
5416
+ if (!_this.state.has(key)) {
5417
+ _this.state.set(key, initialState);
5418
+ }
5419
+ return [
5420
+ _this.state.get(key),
5421
+ function(newState) {
5422
+ var current = _this.state.get(key);
5423
+ _this.state.set(key, newState);
5424
+ if (current !== newState) {
5425
+ var _this_updateCallback, _this1;
5426
+ (_this_updateCallback = (_this1 = _this).updateCallback) === null || _this_updateCallback === void 0 ? void 0 : _this_updateCallback.call(_this1);
5427
+ }
5428
+ }
5429
+ ];
5430
+ };
5431
+ }
5432
+ },
5433
+ {
5434
+ key: "getLocalStateFunction",
5435
+ value: function getLocalStateFunction(key, countKey) {
5436
+ var _this = this;
5437
+ return function(initialState) {
5438
+ if (!_this.state.has(key)) {
5439
+ _this.state.set(key, []);
5440
+ }
5441
+ if (!_this.state.has(countKey)) {
5442
+ _this.state.set(countKey, 0);
5443
+ }
5444
+ var localState = _this.state.get(key);
5445
+ var oldCount = _this.state.get(countKey);
5446
+ _this.state.set(countKey, oldCount + 1);
5447
+ if (localState.length <= oldCount) {
5448
+ localState.push(initialState);
5449
+ }
5450
+ var value = localState[oldCount];
5451
+ return [
5452
+ value,
5453
+ function(newState) {
5454
+ var oldValue = localState[oldCount];
5455
+ localState[oldCount] = newState;
5456
+ if (oldValue !== newState) {
5457
+ var _this_updateCallback, _this1;
5458
+ (_this_updateCallback = (_this1 = _this).updateCallback) === null || _this_updateCallback === void 0 ? void 0 : _this_updateCallback.call(_this1);
5459
+ }
5460
+ }
5461
+ ];
5462
+ };
5463
+ }
5464
+ }
5465
+ ]);
5466
+ return LocalStateStore;
5467
+ }();
5468
+ function findUp(node, target) {
5469
+ if (node === target) {
5470
+ return true;
5471
+ }
5472
+ if (node.parent) {
5473
+ return findUp(node.parent, target);
5474
+ }
5475
+ return false;
5476
+ }
5477
+ var AssetTransformCorePlugin = /*#__PURE__*/ function() {
5478
+ function AssetTransformCorePlugin(registry) {
5479
+ _class_call_check(this, AssetTransformCorePlugin);
5480
+ this.registry = registry;
5481
+ this.stateStore = /* @__PURE__ */ new Map();
5482
+ this.beforeResolveSymbol = Symbol("before resolve");
5483
+ this.resolveSymbol = Symbol("resolve");
5484
+ this.beforeResolveCountSymbol = Symbol("before resolve count");
5485
+ this.resolveCountSymbol = Symbol("resolve count");
5486
+ }
5487
+ _create_class(AssetTransformCorePlugin, [
5488
+ {
5489
+ key: "apply",
5490
+ value: function apply(view) {
5491
+ var _this = this;
5492
+ this.stateStore.clear();
5493
+ view.hooks.resolver.tap("asset-transform", function(resolver) {
5494
+ var lastUpdatedNode;
5495
+ var updateState = function(node) {
5496
+ lastUpdatedNode = node;
5497
+ view.update(/* @__PURE__ */ new Set());
5498
+ };
5499
+ var getStore = function(node, stepKey) {
5500
+ var store;
5501
+ var countKey = stepKey === _this.resolveSymbol ? _this.resolveCountSymbol : _this.beforeResolveCountSymbol;
5502
+ var storedState = _this.stateStore.get(node);
5503
+ if (storedState) {
5504
+ store = storedState;
5505
+ store.removeKey(countKey);
5506
+ } else {
5507
+ store = new LocalStateStore(function() {
5508
+ updateState(node);
5509
+ });
5510
+ _this.stateStore.set(node, store);
5511
+ }
5512
+ return {
5513
+ useSharedState: function(key) {
5514
+ return store.useSharedState(key);
5515
+ },
5516
+ useLocalState: function(initialState) {
5517
+ return store.getLocalStateFunction(stepKey, countKey)(initialState);
5518
+ }
5519
+ };
5520
+ };
5521
+ resolver.hooks.beforeResolve.tap("asset-transform", function(node, options) {
5522
+ if (node && (node.type === "asset" || node.type === "view")) {
5523
+ var transform = _this.registry.get(node.value);
5524
+ if (transform === null || transform === void 0 ? void 0 : transform.beforeResolve) {
5525
+ var _options_node;
5526
+ var store = getStore((_options_node = options.node) !== null && _options_node !== void 0 ? _options_node : node, _this.beforeResolveSymbol);
5527
+ return transform.beforeResolve(node, options, store);
5528
+ }
5529
+ }
5530
+ return node;
5531
+ });
5532
+ resolver.hooks.afterUpdate.tap("asset-transform", function() {
5533
+ lastUpdatedNode = void 0;
5534
+ });
5535
+ resolver.hooks.skipResolve.tap("asset-transform", function(skip, node) {
5536
+ if (!skip || !lastUpdatedNode) {
5537
+ return skip;
5538
+ }
5539
+ var isParentOfUpdated = findUp(lastUpdatedNode, node);
5540
+ var isChildOfUpdated = findUp(node, lastUpdatedNode);
5541
+ return !isParentOfUpdated && !isChildOfUpdated;
5542
+ });
5543
+ resolver.hooks.afterResolve.tap("asset-transform", function(value, node, options) {
5544
+ if (node.type !== "asset" && node.type !== "view") {
5545
+ return value;
5546
+ }
5547
+ var originalNode = resolver.getSourceNode(node);
5548
+ if (!originalNode) {
5549
+ return value;
5550
+ }
5551
+ var transform = _this.registry.get(value);
5552
+ if (transform === null || transform === void 0 ? void 0 : transform.resolve) {
5553
+ var store = getStore(originalNode, _this.resolveSymbol);
5554
+ return transform === null || transform === void 0 ? void 0 : transform.resolve(value, options, store);
5555
+ }
5556
+ return value;
5557
+ });
5558
+ });
5559
+ }
5560
+ }
5561
+ ]);
5562
+ return AssetTransformCorePlugin;
5563
+ }();
5392
5564
  var FlowInstance = /*#__PURE__*/ function() {
5393
5565
  function FlowInstance(id, flow, options) {
5394
5566
  _class_call_check(this, FlowInstance);
@@ -6418,180 +6590,6 @@ var StageRevertDataPlugin = function() {
6418
6590
  ]);
6419
6591
  return ValidationController;
6420
6592
  }();
6421
- var LocalStateStore = /*#__PURE__*/ function() {
6422
- function LocalStateStore(onUpdate) {
6423
- _class_call_check(this, LocalStateStore);
6424
- this.updateCallback = onUpdate;
6425
- this.state = /* @__PURE__ */ new Map();
6426
- }
6427
- _create_class(LocalStateStore, [
6428
- {
6429
- key: "removeKey",
6430
- value: function removeKey(key) {
6431
- this.state.delete(key);
6432
- }
6433
- },
6434
- {
6435
- key: "reset",
6436
- value: function reset() {
6437
- this.state.clear();
6438
- }
6439
- },
6440
- {
6441
- key: "useSharedState",
6442
- value: function useSharedState(key) {
6443
- var _this = this;
6444
- return function(initialState) {
6445
- if (!_this.state.has(key)) {
6446
- _this.state.set(key, initialState);
6447
- }
6448
- return [
6449
- _this.state.get(key),
6450
- function(newState) {
6451
- var current = _this.state.get(key);
6452
- _this.state.set(key, newState);
6453
- if (current !== newState) {
6454
- var _this_updateCallback, _this1;
6455
- (_this_updateCallback = (_this1 = _this).updateCallback) === null || _this_updateCallback === void 0 ? void 0 : _this_updateCallback.call(_this1);
6456
- }
6457
- }
6458
- ];
6459
- };
6460
- }
6461
- },
6462
- {
6463
- key: "getLocalStateFunction",
6464
- value: function getLocalStateFunction(key, countKey) {
6465
- var _this = this;
6466
- return function(initialState) {
6467
- if (!_this.state.has(key)) {
6468
- _this.state.set(key, []);
6469
- }
6470
- if (!_this.state.has(countKey)) {
6471
- _this.state.set(countKey, 0);
6472
- }
6473
- var localState = _this.state.get(key);
6474
- var oldCount = _this.state.get(countKey);
6475
- _this.state.set(countKey, oldCount + 1);
6476
- if (localState.length <= oldCount) {
6477
- localState.push(initialState);
6478
- }
6479
- var value = localState[oldCount];
6480
- return [
6481
- value,
6482
- function(newState) {
6483
- var oldValue = localState[oldCount];
6484
- localState[oldCount] = newState;
6485
- if (oldValue !== newState) {
6486
- var _this_updateCallback, _this1;
6487
- (_this_updateCallback = (_this1 = _this).updateCallback) === null || _this_updateCallback === void 0 ? void 0 : _this_updateCallback.call(_this1);
6488
- }
6489
- }
6490
- ];
6491
- };
6492
- }
6493
- }
6494
- ]);
6495
- return LocalStateStore;
6496
- }();
6497
- function findUp(node, target) {
6498
- if (node === target) {
6499
- return true;
6500
- }
6501
- if (node.parent) {
6502
- return findUp(node.parent, target);
6503
- }
6504
- return false;
6505
- }
6506
- var AssetTransformCorePlugin = /*#__PURE__*/ function() {
6507
- function AssetTransformCorePlugin(registry) {
6508
- _class_call_check(this, AssetTransformCorePlugin);
6509
- this.registry = registry;
6510
- this.stateStore = /* @__PURE__ */ new Map();
6511
- this.beforeResolveSymbol = Symbol("before resolve");
6512
- this.resolveSymbol = Symbol("resolve");
6513
- this.beforeResolveCountSymbol = Symbol("before resolve count");
6514
- this.resolveCountSymbol = Symbol("resolve count");
6515
- }
6516
- _create_class(AssetTransformCorePlugin, [
6517
- {
6518
- key: "apply",
6519
- value: function apply(viewController) {
6520
- var _this = this;
6521
- viewController.hooks.view.tap("asset-transform", function(view) {
6522
- _this.stateStore.clear();
6523
- view.hooks.resolver.tap("asset-transform", function(resolver) {
6524
- var lastUpdatedNode;
6525
- var updateState = function(node) {
6526
- lastUpdatedNode = node;
6527
- view.update(/* @__PURE__ */ new Set());
6528
- };
6529
- var getStore = function(node, stepKey) {
6530
- var store;
6531
- var countKey = stepKey === _this.resolveSymbol ? _this.resolveCountSymbol : _this.beforeResolveCountSymbol;
6532
- var storedState = _this.stateStore.get(node);
6533
- if (storedState) {
6534
- store = storedState;
6535
- store.removeKey(countKey);
6536
- } else {
6537
- store = new LocalStateStore(function() {
6538
- updateState(node);
6539
- });
6540
- _this.stateStore.set(node, store);
6541
- }
6542
- return {
6543
- useSharedState: function(key) {
6544
- return store.useSharedState(key);
6545
- },
6546
- useLocalState: function(initialState) {
6547
- return store.getLocalStateFunction(stepKey, countKey)(initialState);
6548
- }
6549
- };
6550
- };
6551
- resolver.hooks.beforeResolve.tap("asset-transform", function(node, options) {
6552
- if (node && (node.type === "asset" || node.type === "view")) {
6553
- var transform = _this.registry.get(node.value);
6554
- if (transform === null || transform === void 0 ? void 0 : transform.beforeResolve) {
6555
- var _options_node;
6556
- var store = getStore((_options_node = options.node) !== null && _options_node !== void 0 ? _options_node : node, _this.beforeResolveSymbol);
6557
- return transform.beforeResolve(node, options, store);
6558
- }
6559
- }
6560
- return node;
6561
- });
6562
- resolver.hooks.afterUpdate.tap("asset-transform", function() {
6563
- lastUpdatedNode = void 0;
6564
- });
6565
- resolver.hooks.skipResolve.tap("asset-transform", function(skip, node) {
6566
- if (!skip || !lastUpdatedNode) {
6567
- return skip;
6568
- }
6569
- var isParentOfUpdated = findUp(lastUpdatedNode, node);
6570
- var isChildOfUpdated = findUp(node, lastUpdatedNode);
6571
- return !isParentOfUpdated && !isChildOfUpdated;
6572
- });
6573
- resolver.hooks.afterResolve.tap("asset-transform", function(value, node, options) {
6574
- if (node.type !== "asset" && node.type !== "view") {
6575
- return value;
6576
- }
6577
- var originalNode = resolver.getSourceNode(node);
6578
- if (!originalNode) {
6579
- return value;
6580
- }
6581
- var transform = _this.registry.get(value);
6582
- if (transform === null || transform === void 0 ? void 0 : transform.resolve) {
6583
- var store = getStore(originalNode, _this.resolveSymbol);
6584
- return transform === null || transform === void 0 ? void 0 : transform.resolve(value, options, store);
6585
- }
6586
- return value;
6587
- });
6588
- });
6589
- });
6590
- }
6591
- }
6592
- ]);
6593
- return AssetTransformCorePlugin;
6594
- }();
6595
6593
  var ViewController = /*#__PURE__*/ function() {
6596
6594
  function ViewController(initialViews, options) {
6597
6595
  var _this = this;
@@ -6609,7 +6607,6 @@ var StageRevertDataPlugin = function() {
6609
6607
  viewMap[view.id] = view;
6610
6608
  return viewMap;
6611
6609
  }, {});
6612
- new AssetTransformCorePlugin(this.transformRegistry).apply(this);
6613
6610
  options.flowController.hooks.flow.tap("viewController", function(flow) {
6614
6611
  flow.hooks.transition.tap("viewController", function(_oldState, newState) {
6615
6612
  if (newState.value.state_type === "VIEW") {
@@ -7094,6 +7091,7 @@ var StageRevertDataPlugin = function() {
7094
7091
  new AssetPlugin().apply(view);
7095
7092
  new SwitchPlugin(pluginOptions).apply(view);
7096
7093
  new ApplicabilityPlugin().apply(view);
7094
+ new AssetTransformCorePlugin(viewController.transformRegistry).apply(view);
7097
7095
  new StringResolverPlugin().apply(view);
7098
7096
  var templatePlugin = new TemplatePlugin(pluginOptions);
7099
7097
  templatePlugin.apply(view);