@next-core/brick-kit 2.113.0 → 2.115.1

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
@@ -2187,6 +2187,56 @@ function getCustomTemplateContext(tplContextId) {
2187
2187
  return tplContextMap.get(tplContextId);
2188
2188
  }
2189
2189
 
2190
+ var MediaBreakpoint;
2191
+
2192
+ (function (MediaBreakpoint) {
2193
+ MediaBreakpoint["xLarge"] = "xLarge";
2194
+ MediaBreakpoint["large"] = "large";
2195
+ MediaBreakpoint["medium"] = "medium";
2196
+ MediaBreakpoint["small"] = "small";
2197
+ MediaBreakpoint["xSmall"] = "xSmall";
2198
+ })(MediaBreakpoint || (MediaBreakpoint = {}));
2199
+
2200
+ var mediaBreakpointMinWidthMap = new Map([[MediaBreakpoint.xLarge, "1920px"], [MediaBreakpoint.large, "1600px"], [MediaBreakpoint.medium, "1280px"], [MediaBreakpoint.small, "1024px"], [MediaBreakpoint.xSmall, 0]]);
2201
+ var mediaEventTarget = new EventTarget$1();
2202
+ var breakpointMatchesMap = {};
2203
+ var MEDIA = {};
2204
+
2205
+ function handleMatchesChange(data, breakpoint) {
2206
+ var changed = false;
2207
+ breakpointMatchesMap[breakpoint] = data.matches;
2208
+
2209
+ for (var [_breakpoint] of mediaBreakpointMinWidthMap) {
2210
+ if (breakpointMatchesMap[_breakpoint] && MEDIA.breakpoint !== _breakpoint) {
2211
+ MEDIA.breakpoint = _breakpoint;
2212
+ changed = true;
2213
+ break;
2214
+ }
2215
+ }
2216
+
2217
+ if (changed) {
2218
+ mediaEventTarget.dispatchEvent(new CustomEvent("change", {
2219
+ detail: MEDIA
2220
+ }));
2221
+ }
2222
+ }
2223
+
2224
+ mediaBreakpointMinWidthMap.forEach((minWidth, breakpoint) => {
2225
+ var mediaQueryList = window.matchMedia("(min-width: ".concat(minWidth, ")"));
2226
+ handleMatchesChange(mediaQueryList, breakpoint);
2227
+
2228
+ if (mediaQueryList.addEventListener) {
2229
+ mediaQueryList.addEventListener("change", event => {
2230
+ handleMatchesChange(event, breakpoint);
2231
+ });
2232
+ } else {
2233
+ mediaQueryList.addListener(event => {
2234
+ handleMatchesChange(event, breakpoint);
2235
+ });
2236
+ }
2237
+ });
2238
+ var getMedia = () => MEDIA;
2239
+
2190
2240
  var symbolForRaw = Symbol.for("pre.evaluated.raw");
2191
2241
  var symbolForContext = Symbol.for("pre.evaluated.context");
2192
2242
  function isPreEvaluated(raw) {
@@ -2423,6 +2473,9 @@ function evaluate(raw) {
2423
2473
  case "SYS":
2424
2474
  return getReadOnlyProxy(sys);
2425
2475
 
2476
+ case "MEDIA":
2477
+ return getReadOnlyProxy(getMedia());
2478
+
2426
2479
  case "__WIDGET_FN__":
2427
2480
  return widgetFunctions;
2428
2481
 
@@ -8594,6 +8647,8 @@ class LocationContext {
8594
8647
 
8595
8648
  _defineProperty$1(this, "anchorUnloadHandlers", []);
8596
8649
 
8650
+ _defineProperty$1(this, "mediaChangeHandlers", []);
8651
+
8597
8652
  _defineProperty$1(this, "messageCloseHandlers", []);
8598
8653
 
8599
8654
  _defineProperty$1(this, "messageHandlers", []);
@@ -8783,15 +8838,11 @@ class LocationContext {
8783
8838
  }
8784
8839
 
8785
8840
  if (isRouteConfOfRoutes(route) && Array.isArray(route.routes)) {
8841
+ yield _this.preFetchMenu(route.context);
8786
8842
  yield _this.mountRoutes(route.routes, slotId, mountRoutesResult);
8787
8843
  } else if (isRouteConfOfBricks(route) && Array.isArray(route.bricks)) {
8788
- var useMenus = scanAppGetMenuInAny(route);
8789
-
8790
- if (useMenus.length) {
8791
- yield constructMenuByMenusList(useMenus, _this.getCurrentContext(), _this.kernel);
8792
- }
8793
-
8794
- yield _this.mountBricks(route.bricks, matched.match, slotId, mountRoutesResult); // analytics data (page_view event)
8844
+ yield _this.mountBricks(route.bricks, matched.match, slotId, mountRoutesResult);
8845
+ yield _this.preFetchMenu(route); // analytics data (page_view event)
8795
8846
 
8796
8847
  if (route.analyticsData) {
8797
8848
  mountRoutesResult.analyticsData = computeRealValue(route.analyticsData, context, true);
@@ -9047,6 +9098,9 @@ class LocationContext {
9047
9098
  var expandedBrickConf = brickConf;
9048
9099
 
9049
9100
  if (tplTagName) {
9101
+ var _customTemplateRegist;
9102
+
9103
+ yield _this6.preFetchMenu((_customTemplateRegist = customTemplateRegistry.get(tplTagName)) === null || _customTemplateRegist === void 0 ? void 0 : _customTemplateRegist.bricks);
9050
9104
  expandedBrickConf = yield asyncExpandCustomTemplate(_objectSpread(_objectSpread({}, brickConf), {}, {
9051
9105
  brick: tplTagName,
9052
9106
  // Properties are computed for custom templates.
@@ -9108,6 +9162,7 @@ class LocationContext {
9108
9162
  onPageLeave,
9109
9163
  onAnchorLoad,
9110
9164
  onAnchorUnload,
9165
+ onMediaChange,
9111
9166
  onMessage,
9112
9167
  onMessageClose
9113
9168
  } = lifeCycle !== null && lifeCycle !== void 0 ? lifeCycle : {};
@@ -9166,6 +9221,15 @@ class LocationContext {
9166
9221
  });
9167
9222
  }
9168
9223
 
9224
+ if (onMediaChange) {
9225
+ this.mediaChangeHandlers.push({
9226
+ brick,
9227
+ match,
9228
+ tplContextId,
9229
+ handler: onMediaChange
9230
+ });
9231
+ }
9232
+
9169
9233
  if (onMessage) {
9170
9234
  this.messageHandlers.push({
9171
9235
  brick,
@@ -9221,6 +9285,12 @@ class LocationContext {
9221
9285
  }
9222
9286
  }
9223
9287
 
9288
+ handleMediaChange(detail) {
9289
+ this.dispatchLifeCycleEvent(new CustomEvent("media.change", {
9290
+ detail: getReadOnlyProxy(detail)
9291
+ }), this.mediaChangeHandlers);
9292
+ }
9293
+
9224
9294
  handleMessage() {
9225
9295
  this.messageDispatcher.create(this.messageHandlers, this.getCurrentContext());
9226
9296
  }
@@ -9251,6 +9321,18 @@ class LocationContext {
9251
9321
  }
9252
9322
  }
9253
9323
 
9324
+ preFetchMenu(data) {
9325
+ var _this7 = this;
9326
+
9327
+ return _asyncToGenerator$4(function* () {
9328
+ var useMenus = scanAppGetMenuInAny(data);
9329
+
9330
+ if (useMenus.length) {
9331
+ yield constructMenuByMenusList(useMenus, _this7.getCurrentContext(), _this7.kernel);
9332
+ }
9333
+ })();
9334
+ }
9335
+
9254
9336
  }
9255
9337
 
9256
9338
  function unmountTree(mountPoint) {
@@ -9732,6 +9814,8 @@ class Router {
9732
9814
 
9733
9815
  _defineProperty$1(this, "navConfig", void 0);
9734
9816
 
9817
+ _defineProperty$1(this, "mediaEventTargetHandler", void 0);
9818
+
9735
9819
  this.kernel = kernel;
9736
9820
  this.featureFlags = this.kernel.getFeatureFlags();
9737
9821
  var history = getHistory();
@@ -10039,7 +10123,12 @@ class Router {
10039
10123
  _this3.kernel.unsetBars({
10040
10124
  appChanged,
10041
10125
  legacy: actualLegacy
10042
- }); // There is a window to set theme and mode by `lifeCycle.onBeforePageLoad`.
10126
+ });
10127
+
10128
+ if (_this3.mediaEventTargetHandler) {
10129
+ mediaEventTarget.removeEventListener("change", _this3.mediaEventTargetHandler);
10130
+ _this3.mediaEventTargetHandler = undefined;
10131
+ } // There is a window to set theme and mode by `lifeCycle.onBeforePageLoad`.
10043
10132
 
10044
10133
 
10045
10134
  _this3.locationContext.handleBeforePageLoad();
@@ -10112,6 +10201,9 @@ class Router {
10112
10201
  _this3.locationContext.handleMessage();
10113
10202
  }
10114
10203
 
10204
+ _this3.mediaEventTargetHandler = event => _this3.locationContext.handleMediaChange(event.detail);
10205
+
10206
+ mediaEventTarget.addEventListener("change", _this3.mediaEventTargetHandler);
10115
10207
  pageTracker === null || pageTracker === void 0 ? void 0 : pageTracker(locationContext.getCurrentMatch().path); // analytics page_view event
10116
10208
 
10117
10209
  userAnalytics.event("page_view", _objectSpread({