@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/CHANGELOG.md CHANGED
@@ -3,6 +3,39 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [2.115.1](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.115.0...@next-core/brick-kit@2.115.1) (2022-03-30)
7
+
8
+ **Note:** Version bump only for package @next-core/brick-kit
9
+
10
+
11
+
12
+
13
+
14
+ # [2.115.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.114.0...@next-core/brick-kit@2.115.0) (2022-03-30)
15
+
16
+
17
+ ### Features
18
+
19
+ * APP.getMenu support scan template & routes ([5498846](https://github.com/easyops-cn/next-core/commit/54988465a5357a97834aaca317b41b3fcb2c6a65))
20
+ * loactionContext preFetchMenu ([9a0ec7b](https://github.com/easyops-cn/next-core/commit/9a0ec7b0a19e26633772a71de829f014574ec735))
21
+ * support walkAny unit function ([8adff8e](https://github.com/easyops-cn/next-core/commit/8adff8e2538a43676c5eef1f275e1c5a8127171a))
22
+ * unit test update ([00b3606](https://github.com/easyops-cn/next-core/commit/00b3606c2a2d7ba9a26f3a0255721a11e225c7d9))
23
+
24
+
25
+
26
+
27
+
28
+ # [2.114.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.113.0...@next-core/brick-kit@2.114.0) (2022-03-29)
29
+
30
+
31
+ ### Features
32
+
33
+ * add MEDIA gloabl object and onMediaChange life cycle ([3192ee4](https://github.com/easyops-cn/next-core/commit/3192ee4e595e2edc78d05b68d6cf0431905296fb))
34
+
35
+
36
+
37
+
38
+
6
39
  # [2.113.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.112.1...@next-core/brick-kit@2.113.0) (2022-03-29)
7
40
 
8
41
 
@@ -2186,6 +2186,56 @@
2186
2186
  return tplContextMap.get(tplContextId);
2187
2187
  }
2188
2188
 
2189
+ var MediaBreakpoint;
2190
+
2191
+ (function (MediaBreakpoint) {
2192
+ MediaBreakpoint["xLarge"] = "xLarge";
2193
+ MediaBreakpoint["large"] = "large";
2194
+ MediaBreakpoint["medium"] = "medium";
2195
+ MediaBreakpoint["small"] = "small";
2196
+ MediaBreakpoint["xSmall"] = "xSmall";
2197
+ })(MediaBreakpoint || (MediaBreakpoint = {}));
2198
+
2199
+ var mediaBreakpointMinWidthMap = new Map([[MediaBreakpoint.xLarge, "1920px"], [MediaBreakpoint.large, "1600px"], [MediaBreakpoint.medium, "1280px"], [MediaBreakpoint.small, "1024px"], [MediaBreakpoint.xSmall, 0]]);
2200
+ var mediaEventTarget = new EventTarget$1();
2201
+ var breakpointMatchesMap = {};
2202
+ var MEDIA = {};
2203
+
2204
+ function handleMatchesChange(data, breakpoint) {
2205
+ var changed = false;
2206
+ breakpointMatchesMap[breakpoint] = data.matches;
2207
+
2208
+ for (var [_breakpoint] of mediaBreakpointMinWidthMap) {
2209
+ if (breakpointMatchesMap[_breakpoint] && MEDIA.breakpoint !== _breakpoint) {
2210
+ MEDIA.breakpoint = _breakpoint;
2211
+ changed = true;
2212
+ break;
2213
+ }
2214
+ }
2215
+
2216
+ if (changed) {
2217
+ mediaEventTarget.dispatchEvent(new CustomEvent("change", {
2218
+ detail: MEDIA
2219
+ }));
2220
+ }
2221
+ }
2222
+
2223
+ mediaBreakpointMinWidthMap.forEach((minWidth, breakpoint) => {
2224
+ var mediaQueryList = window.matchMedia("(min-width: ".concat(minWidth, ")"));
2225
+ handleMatchesChange(mediaQueryList, breakpoint);
2226
+
2227
+ if (mediaQueryList.addEventListener) {
2228
+ mediaQueryList.addEventListener("change", event => {
2229
+ handleMatchesChange(event, breakpoint);
2230
+ });
2231
+ } else {
2232
+ mediaQueryList.addListener(event => {
2233
+ handleMatchesChange(event, breakpoint);
2234
+ });
2235
+ }
2236
+ });
2237
+ var getMedia = () => MEDIA;
2238
+
2189
2239
  var symbolForRaw = Symbol.for("pre.evaluated.raw");
2190
2240
  var symbolForContext = Symbol.for("pre.evaluated.context");
2191
2241
  function isPreEvaluated(raw) {
@@ -2422,6 +2472,9 @@
2422
2472
  case "SYS":
2423
2473
  return getReadOnlyProxy(sys);
2424
2474
 
2475
+ case "MEDIA":
2476
+ return getReadOnlyProxy(getMedia());
2477
+
2425
2478
  case "__WIDGET_FN__":
2426
2479
  return widgetFunctions;
2427
2480
 
@@ -8593,6 +8646,8 @@
8593
8646
 
8594
8647
  _defineProperty__default["default"](this, "anchorUnloadHandlers", []);
8595
8648
 
8649
+ _defineProperty__default["default"](this, "mediaChangeHandlers", []);
8650
+
8596
8651
  _defineProperty__default["default"](this, "messageCloseHandlers", []);
8597
8652
 
8598
8653
  _defineProperty__default["default"](this, "messageHandlers", []);
@@ -8782,15 +8837,11 @@
8782
8837
  }
8783
8838
 
8784
8839
  if (isRouteConfOfRoutes(route) && Array.isArray(route.routes)) {
8840
+ yield _this.preFetchMenu(route.context);
8785
8841
  yield _this.mountRoutes(route.routes, slotId, mountRoutesResult);
8786
8842
  } else if (isRouteConfOfBricks(route) && Array.isArray(route.bricks)) {
8787
- var useMenus = brickUtils.scanAppGetMenuInAny(route);
8788
-
8789
- if (useMenus.length) {
8790
- yield constructMenuByMenusList(useMenus, _this.getCurrentContext(), _this.kernel);
8791
- }
8792
-
8793
- yield _this.mountBricks(route.bricks, matched.match, slotId, mountRoutesResult); // analytics data (page_view event)
8843
+ yield _this.mountBricks(route.bricks, matched.match, slotId, mountRoutesResult);
8844
+ yield _this.preFetchMenu(route); // analytics data (page_view event)
8794
8845
 
8795
8846
  if (route.analyticsData) {
8796
8847
  mountRoutesResult.analyticsData = computeRealValue(route.analyticsData, context, true);
@@ -9046,6 +9097,9 @@
9046
9097
  var expandedBrickConf = brickConf;
9047
9098
 
9048
9099
  if (tplTagName) {
9100
+ var _customTemplateRegist;
9101
+
9102
+ yield _this6.preFetchMenu((_customTemplateRegist = customTemplateRegistry.get(tplTagName)) === null || _customTemplateRegist === void 0 ? void 0 : _customTemplateRegist.bricks);
9049
9103
  expandedBrickConf = yield asyncExpandCustomTemplate(_objectSpread__default["default"](_objectSpread__default["default"]({}, brickConf), {}, {
9050
9104
  brick: tplTagName,
9051
9105
  // Properties are computed for custom templates.
@@ -9107,6 +9161,7 @@
9107
9161
  onPageLeave,
9108
9162
  onAnchorLoad,
9109
9163
  onAnchorUnload,
9164
+ onMediaChange,
9110
9165
  onMessage,
9111
9166
  onMessageClose
9112
9167
  } = lifeCycle !== null && lifeCycle !== void 0 ? lifeCycle : {};
@@ -9165,6 +9220,15 @@
9165
9220
  });
9166
9221
  }
9167
9222
 
9223
+ if (onMediaChange) {
9224
+ this.mediaChangeHandlers.push({
9225
+ brick,
9226
+ match,
9227
+ tplContextId,
9228
+ handler: onMediaChange
9229
+ });
9230
+ }
9231
+
9168
9232
  if (onMessage) {
9169
9233
  this.messageHandlers.push({
9170
9234
  brick,
@@ -9220,6 +9284,12 @@
9220
9284
  }
9221
9285
  }
9222
9286
 
9287
+ handleMediaChange(detail) {
9288
+ this.dispatchLifeCycleEvent(new CustomEvent("media.change", {
9289
+ detail: getReadOnlyProxy(detail)
9290
+ }), this.mediaChangeHandlers);
9291
+ }
9292
+
9223
9293
  handleMessage() {
9224
9294
  this.messageDispatcher.create(this.messageHandlers, this.getCurrentContext());
9225
9295
  }
@@ -9250,6 +9320,18 @@
9250
9320
  }
9251
9321
  }
9252
9322
 
9323
+ preFetchMenu(data) {
9324
+ var _this7 = this;
9325
+
9326
+ return _asyncToGenerator__default["default"](function* () {
9327
+ var useMenus = brickUtils.scanAppGetMenuInAny(data);
9328
+
9329
+ if (useMenus.length) {
9330
+ yield constructMenuByMenusList(useMenus, _this7.getCurrentContext(), _this7.kernel);
9331
+ }
9332
+ })();
9333
+ }
9334
+
9253
9335
  }
9254
9336
 
9255
9337
  function unmountTree(mountPoint) {
@@ -9731,6 +9813,8 @@
9731
9813
 
9732
9814
  _defineProperty__default["default"](this, "navConfig", void 0);
9733
9815
 
9816
+ _defineProperty__default["default"](this, "mediaEventTargetHandler", void 0);
9817
+
9734
9818
  this.kernel = kernel;
9735
9819
  this.featureFlags = this.kernel.getFeatureFlags();
9736
9820
  var history = getHistory();
@@ -10038,7 +10122,12 @@
10038
10122
  _this3.kernel.unsetBars({
10039
10123
  appChanged,
10040
10124
  legacy: actualLegacy
10041
- }); // There is a window to set theme and mode by `lifeCycle.onBeforePageLoad`.
10125
+ });
10126
+
10127
+ if (_this3.mediaEventTargetHandler) {
10128
+ mediaEventTarget.removeEventListener("change", _this3.mediaEventTargetHandler);
10129
+ _this3.mediaEventTargetHandler = undefined;
10130
+ } // There is a window to set theme and mode by `lifeCycle.onBeforePageLoad`.
10042
10131
 
10043
10132
 
10044
10133
  _this3.locationContext.handleBeforePageLoad();
@@ -10111,6 +10200,9 @@
10111
10200
  _this3.locationContext.handleMessage();
10112
10201
  }
10113
10202
 
10203
+ _this3.mediaEventTargetHandler = event => _this3.locationContext.handleMediaChange(event.detail);
10204
+
10205
+ mediaEventTarget.addEventListener("change", _this3.mediaEventTargetHandler);
10114
10206
  pageTracker === null || pageTracker === void 0 ? void 0 : pageTracker(locationContext.getCurrentMatch().path); // analytics page_view event
10115
10207
 
10116
10208
  easyopsAnalytics.userAnalytics.event("page_view", _objectSpread__default["default"]({