@next-core/brick-kit 2.174.3 → 2.175.0

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.
package/dist/index.esm.js CHANGED
@@ -1803,6 +1803,7 @@ class StoryboardContextWrapper {
1803
1803
  _defineProperty$1(this, "data", new Map());
1804
1804
  _defineProperty$1(this, "batchUpdate", false);
1805
1805
  _defineProperty$1(this, "batchUpdateContextsNames", []);
1806
+ _defineProperty$1(this, "batchTriggerContextsNamesMap", new Map());
1806
1807
  _defineProperty$1(this, "tplContextId", void 0);
1807
1808
  _defineProperty$1(this, "formContextId", void 0);
1808
1809
  _defineProperty$1(this, "eventName", void 0);
@@ -2039,6 +2040,9 @@ class StoryboardContextWrapper {
2039
2040
  keyword: "CTX"
2040
2041
  };
2041
2042
  }
2043
+ getContextTriggerSetByLifecycle(lifecycle) {
2044
+ return this.batchTriggerContextsNamesMap.get(lifecycle) || [];
2045
+ }
2042
2046
  }
2043
2047
  function resolveStoryboardContext(_x, _x2, _x3, _x4) {
2044
2048
  return _resolveStoryboardContext.apply(this, arguments);
@@ -2062,6 +2066,7 @@ function _resolveStoryboardContext() {
2062
2066
  });
2063
2067
  return _resolveStoryboardContext.apply(this, arguments);
2064
2068
  }
2069
+ var supportContextResolveTriggerBrickLifeCycle = ["onBeforePageLoad", "onPageLoad", "onBeforePageLeave", "onPageLeave", "onAnchorLoad", "onAnchorUnload"];
2065
2070
  function resolveNormalStoryboardContext(_x5, _x6, _x7, _x8) {
2066
2071
  return _resolveNormalStoryboardContext.apply(this, arguments);
2067
2072
  }
@@ -2095,6 +2100,20 @@ function _resolveNormalStoryboardContext() {
2095
2100
  isLazyResolve = contextConf.resolve.lazy;
2096
2101
  if (!isLazyResolve) {
2097
2102
  value = yield load();
2103
+ } else if (isLazyResolve && contextConf.resolve.trigger) {
2104
+ var lifecycleName = contextConf.resolve.trigger;
2105
+ if (supportContextResolveTriggerBrickLifeCycle.includes(lifecycleName)) {
2106
+ var contextNameArray = storyboardContextWrapper.batchTriggerContextsNamesMap.get(lifecycleName) || [];
2107
+ contextNameArray.push({
2108
+ name: contextConf.name,
2109
+ type: storyboardContextWrapper.tplContextId ? "state" : "context",
2110
+ tplContextId: storyboardContextWrapper.tplContextId
2111
+ });
2112
+ storyboardContextWrapper.batchTriggerContextsNamesMap.set(lifecycleName, contextNameArray);
2113
+ } else {
2114
+ // eslint-disable-next-line no-console
2115
+ console.error("unsupported lifecycle: \"".concat(lifecycleName, "\""));
2116
+ }
2098
2117
  }
2099
2118
  } else if (!hasOwnProperty(contextConf, "value")) {
2100
2119
  return false;
@@ -2209,6 +2228,9 @@ class CustomTemplateContext {
2209
2228
  function getCustomTemplateContext(tplContextId) {
2210
2229
  return tplContextMap.get(tplContextId);
2211
2230
  }
2231
+ function getCustomContextTriggerListByLifecycle(lifecycle) {
2232
+ return [...tplContextMap.values()].map(tplContext => tplContext.state.getContextTriggerSetByLifecycle(lifecycle)).filter(trigger => trigger.length > 0).flat(1);
2233
+ }
2212
2234
 
2213
2235
  var MediaBreakpoint;
2214
2236
  (function (MediaBreakpoint) {
@@ -9536,7 +9558,9 @@ class Kernel {
9536
9558
  }
9537
9559
  getFeatureFlags() {
9538
9560
  var _this$bootstrapData, _this$bootstrapData$s, _this$nextApp, _this$nextApp$config, _this$nextApp$config$;
9539
- return Object.assign({}, (_this$bootstrapData = this.bootstrapData) === null || _this$bootstrapData === void 0 ? void 0 : (_this$bootstrapData$s = _this$bootstrapData.settings) === null || _this$bootstrapData$s === void 0 ? void 0 : _this$bootstrapData$s.featureFlags, (_this$nextApp = this.nextApp) === null || _this$nextApp === void 0 ? void 0 : (_this$nextApp$config = _this$nextApp.config) === null || _this$nextApp$config === void 0 ? void 0 : (_this$nextApp$config$ = _this$nextApp$config.settings) === null || _this$nextApp$config$ === void 0 ? void 0 : _this$nextApp$config$.featureFlags);
9561
+ var flags = _objectSpread(_objectSpread({}, (_this$bootstrapData = this.bootstrapData) === null || _this$bootstrapData === void 0 ? void 0 : (_this$bootstrapData$s = _this$bootstrapData.settings) === null || _this$bootstrapData$s === void 0 ? void 0 : _this$bootstrapData$s.featureFlags), (_this$nextApp = this.nextApp) === null || _this$nextApp === void 0 ? void 0 : (_this$nextApp$config = _this$nextApp.config) === null || _this$nextApp$config === void 0 ? void 0 : (_this$nextApp$config$ = _this$nextApp$config.settings) === null || _this$nextApp$config$ === void 0 ? void 0 : _this$nextApp$config$.featureFlags);
9562
+ delete flags["migrate-to-brick-next-v3"];
9563
+ return flags;
9540
9564
  }
9541
9565
  getStandaloneMenus(menuId, isPreFetch) {
9542
9566
  var _this12 = this;
@@ -10889,9 +10913,11 @@ class LocationContext {
10889
10913
  }
10890
10914
  }
10891
10915
  handleBeforePageLoad() {
10916
+ this.attachContextTriggerToLifecycle("onBeforePageLoad", this.beforePageLoadHandlers);
10892
10917
  this.dispatchLifeCycleEvent(new CustomEvent("page.beforeLoad"), this.beforePageLoadHandlers);
10893
10918
  }
10894
10919
  handlePageLoad() {
10920
+ this.attachContextTriggerToLifecycle("onPageLoad", this.pageLoadHandlers);
10895
10921
  var event = new CustomEvent("page.load");
10896
10922
  this.dispatchLifeCycleEvent(event, this.pageLoadHandlers);
10897
10923
 
@@ -10899,16 +10925,19 @@ class LocationContext {
10899
10925
  window.dispatchEvent(event);
10900
10926
  }
10901
10927
  handleBeforePageLeave(detail) {
10928
+ this.attachContextTriggerToLifecycle("onBeforePageLeave", this.beforePageLeaveHandlers);
10902
10929
  this.dispatchLifeCycleEvent(new CustomEvent("page.beforeLeave", {
10903
10930
  detail
10904
10931
  }), this.beforePageLeaveHandlers);
10905
10932
  }
10906
10933
  handlePageLeave() {
10934
+ this.attachContextTriggerToLifecycle("onPageLeave", this.pageLeaveHandlers);
10907
10935
  this.dispatchLifeCycleEvent(new CustomEvent("page.leave"), this.pageLeaveHandlers);
10908
10936
  }
10909
10937
  handleAnchorLoad() {
10910
10938
  var hash = getHistory().location.hash;
10911
10939
  if (hash && hash !== "#") {
10940
+ this.attachContextTriggerToLifecycle("onAnchorLoad", this.anchorLoadHandlers);
10912
10941
  this.dispatchLifeCycleEvent(new CustomEvent("anchor.load", {
10913
10942
  detail: {
10914
10943
  hash,
@@ -10916,6 +10945,7 @@ class LocationContext {
10916
10945
  }
10917
10946
  }), this.anchorLoadHandlers);
10918
10947
  } else {
10948
+ this.attachContextTriggerToLifecycle("onAnchorUnload", this.anchorUnloadHandlers);
10919
10949
  this.dispatchLifeCycleEvent(new CustomEvent("anchor.unload"), this.anchorUnloadHandlers);
10920
10950
  }
10921
10951
  }
@@ -10987,6 +11017,22 @@ class LocationContext {
10987
11017
  $$observe: () => observer.observe(brick.element)
10988
11018
  });
10989
11019
  }
11020
+ attachContextTriggerToLifecycle(lifecycle, handlers) {
11021
+ var contextNameArray = this.storyboardContextWrapper.getContextTriggerSetByLifecycle(lifecycle).concat(getCustomContextTriggerListByLifecycle(lifecycle));
11022
+ if ((contextNameArray === null || contextNameArray === void 0 ? void 0 : contextNameArray.length) > 0) {
11023
+ for (var context of contextNameArray) {
11024
+ handlers.push({
11025
+ brick: null,
11026
+ match: this.currentMatch,
11027
+ tplContextId: context.tplContextId,
11028
+ handler: [{
11029
+ action: "".concat(context.type, ".load"),
11030
+ args: [context.name]
11031
+ }]
11032
+ });
11033
+ }
11034
+ }
11035
+ }
10990
11036
  }
10991
11037
 
10992
11038
  function unmountTree(mountPoint) {