@next-core/brick-kit 2.114.0 → 2.116.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/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.116.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.115.1...@next-core/brick-kit@2.116.0) (2022-04-01)
7
+
8
+
9
+ ### Features
10
+
11
+ * support re-registering custom templates ([ea91d7d](https://github.com/easyops-cn/next-core/commit/ea91d7de23e0a9d3a935c01a9a103fb44b8cdfb3))
12
+
13
+
14
+
15
+
16
+
17
+ ## [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)
18
+
19
+ **Note:** Version bump only for package @next-core/brick-kit
20
+
21
+
22
+
23
+
24
+
25
+ # [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)
26
+
27
+
28
+ ### Features
29
+
30
+ * APP.getMenu support scan template & routes ([5498846](https://github.com/easyops-cn/next-core/commit/54988465a5357a97834aaca317b41b3fcb2c6a65))
31
+ * loactionContext preFetchMenu ([9a0ec7b](https://github.com/easyops-cn/next-core/commit/9a0ec7b0a19e26633772a71de829f014574ec735))
32
+ * support walkAny unit function ([8adff8e](https://github.com/easyops-cn/next-core/commit/8adff8e2538a43676c5eef1f275e1c5a8127171a))
33
+ * unit test update ([00b3606](https://github.com/easyops-cn/next-core/commit/00b3606c2a2d7ba9a26f3a0255721a11e225c7d9))
34
+
35
+
36
+
37
+
38
+
6
39
  # [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)
7
40
 
8
41
 
@@ -2186,28 +2186,28 @@
2186
2186
  return tplContextMap.get(tplContextId);
2187
2187
  }
2188
2188
 
2189
- var MediaSize;
2189
+ var MediaBreakpoint;
2190
2190
 
2191
- (function (MediaSize) {
2192
- MediaSize["xLarge"] = "xLarge";
2193
- MediaSize["large"] = "large";
2194
- MediaSize["medium"] = "medium";
2195
- MediaSize["small"] = "small";
2196
- MediaSize["xSmall"] = "xSmall";
2197
- })(MediaSize || (MediaSize = {}));
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
2198
 
2199
- var mediaSizeBreakpointMap = new Map([[MediaSize.xLarge, "1920px"], [MediaSize.large, "1600px"], [MediaSize.medium, "1280px"], [MediaSize.small, "1024px"], [MediaSize.xSmall, 0]]);
2199
+ var mediaBreakpointMinWidthMap = new Map([[MediaBreakpoint.xLarge, "1920px"], [MediaBreakpoint.large, "1600px"], [MediaBreakpoint.medium, "1280px"], [MediaBreakpoint.small, "1024px"], [MediaBreakpoint.xSmall, 0]]);
2200
2200
  var mediaEventTarget = new EventTarget$1();
2201
- var sizeMatchesMap = {};
2201
+ var breakpointMatchesMap = {};
2202
2202
  var MEDIA = {};
2203
2203
 
2204
- function handleMatchesChange(data, size) {
2204
+ function handleMatchesChange(data, breakpoint) {
2205
2205
  var changed = false;
2206
- sizeMatchesMap[size] = data.matches;
2206
+ breakpointMatchesMap[breakpoint] = data.matches;
2207
2207
 
2208
- for (var [_size] of mediaSizeBreakpointMap) {
2209
- if (sizeMatchesMap[_size] && MEDIA.size !== _size) {
2210
- MEDIA.size = _size;
2208
+ for (var [_breakpoint] of mediaBreakpointMinWidthMap) {
2209
+ if (breakpointMatchesMap[_breakpoint] && MEDIA.breakpoint !== _breakpoint) {
2210
+ MEDIA.breakpoint = _breakpoint;
2211
2211
  changed = true;
2212
2212
  break;
2213
2213
  }
@@ -2220,17 +2220,17 @@
2220
2220
  }
2221
2221
  }
2222
2222
 
2223
- mediaSizeBreakpointMap.forEach((breakpoint, size) => {
2224
- var mediaQueryList = window.matchMedia("(min-width: ".concat(breakpoint, ")"));
2225
- handleMatchesChange(mediaQueryList, size);
2223
+ mediaBreakpointMinWidthMap.forEach((minWidth, breakpoint) => {
2224
+ var mediaQueryList = window.matchMedia("(min-width: ".concat(minWidth, ")"));
2225
+ handleMatchesChange(mediaQueryList, breakpoint);
2226
2226
 
2227
2227
  if (mediaQueryList.addEventListener) {
2228
2228
  mediaQueryList.addEventListener("change", event => {
2229
- handleMatchesChange(event, size);
2229
+ handleMatchesChange(event, breakpoint);
2230
2230
  });
2231
2231
  } else {
2232
2232
  mediaQueryList.addListener(event => {
2233
- handleMatchesChange(event, size);
2233
+ handleMatchesChange(event, breakpoint);
2234
2234
  });
2235
2235
  }
2236
2236
  });
@@ -7903,7 +7903,9 @@
7903
7903
  var storyboard = this.bootstrapData.storyboards.find(item => item.app.id === appId);
7904
7904
  Object.assign(storyboard, _objectSpread__default["default"](_objectSpread__default["default"]({}, storyboardPatch), {}, {
7905
7905
  $$fulfilling: Promise.resolve(),
7906
- $$fulfilled: true
7906
+ $$fulfilled: true,
7907
+ $$registerCustomTemplateProcessed: false,
7908
+ $$depsProcessed: false
7907
7909
  }));
7908
7910
  this.postProcessStoryboard(storyboard);
7909
7911
  }
@@ -8837,15 +8839,11 @@
8837
8839
  }
8838
8840
 
8839
8841
  if (isRouteConfOfRoutes(route) && Array.isArray(route.routes)) {
8842
+ yield _this.preFetchMenu(route.context);
8840
8843
  yield _this.mountRoutes(route.routes, slotId, mountRoutesResult);
8841
8844
  } else if (isRouteConfOfBricks(route) && Array.isArray(route.bricks)) {
8842
- var useMenus = brickUtils.scanAppGetMenuInAny(route);
8843
-
8844
- if (useMenus.length) {
8845
- yield constructMenuByMenusList(useMenus, _this.getCurrentContext(), _this.kernel);
8846
- }
8847
-
8848
- yield _this.mountBricks(route.bricks, matched.match, slotId, mountRoutesResult); // analytics data (page_view event)
8845
+ yield _this.mountBricks(route.bricks, matched.match, slotId, mountRoutesResult);
8846
+ yield _this.preFetchMenu(route); // analytics data (page_view event)
8849
8847
 
8850
8848
  if (route.analyticsData) {
8851
8849
  mountRoutesResult.analyticsData = computeRealValue(route.analyticsData, context, true);
@@ -9101,6 +9099,9 @@
9101
9099
  var expandedBrickConf = brickConf;
9102
9100
 
9103
9101
  if (tplTagName) {
9102
+ var _customTemplateRegist;
9103
+
9104
+ yield _this6.preFetchMenu((_customTemplateRegist = customTemplateRegistry.get(tplTagName)) === null || _customTemplateRegist === void 0 ? void 0 : _customTemplateRegist.bricks);
9104
9105
  expandedBrickConf = yield asyncExpandCustomTemplate(_objectSpread__default["default"](_objectSpread__default["default"]({}, brickConf), {}, {
9105
9106
  brick: tplTagName,
9106
9107
  // Properties are computed for custom templates.
@@ -9321,6 +9322,18 @@
9321
9322
  }
9322
9323
  }
9323
9324
 
9325
+ preFetchMenu(data) {
9326
+ var _this7 = this;
9327
+
9328
+ return _asyncToGenerator__default["default"](function* () {
9329
+ var useMenus = brickUtils.scanAppGetMenuInAny(data);
9330
+
9331
+ if (useMenus.length) {
9332
+ yield constructMenuByMenusList(useMenus, _this7.getCurrentContext(), _this7.kernel);
9333
+ }
9334
+ })();
9335
+ }
9336
+
9324
9337
  }
9325
9338
 
9326
9339
  function unmountTree(mountPoint) {
@@ -10955,37 +10968,37 @@
10955
10968
  }
10956
10969
 
10957
10970
  function registerCustomTemplate(tplName, tplConstructor, appId) {
10958
- var _tplConstructor$proxy;
10959
-
10960
10971
  var tagName = tplName; // When a template is registered by an app, its namespace maybe missed.
10961
10972
 
10962
10973
  if (appId && !tplName.includes(".")) {
10963
10974
  tagName = "".concat(appId, ".").concat(tplName);
10964
10975
  }
10965
10976
 
10966
- if (customTemplateRegistry.has(tagName)) {
10977
+ var registered = customTemplateRegistry.has(tagName);
10978
+
10979
+ if (registered) {
10967
10980
  // When open launchpad, the storyboard will be updated.
10968
10981
  // However, we can't *undefine* a custom element.
10969
10982
  // Just ignore re-registering custom templates.
10970
10983
  if (!appId || appRegistered.has(appId)) {
10971
10984
  // eslint-disable-next-line no-console
10972
- console.error("Custom template of \"".concat(tagName, "\" already registered."));
10985
+ console.warn("Custom template of \"".concat(tagName, "\" already registered."));
10973
10986
  }
10987
+ } else {
10988
+ registered = !!customElements.get(tagName);
10974
10989
 
10975
- return;
10976
- }
10990
+ if (registered) {
10991
+ // eslint-disable-next-line no-console
10992
+ console.warn("Custom template of \"".concat(tagName, "\" already defined by customElements."));
10993
+ }
10994
+ } // Now we allow re-register custom template
10977
10995
 
10978
- if (customElements.get(tagName)) {
10979
- // eslint-disable-next-line no-console
10980
- console.error("Custom template of \"".concat(tagName, "\" already defined by customElements."));
10981
- return;
10982
- }
10983
10996
 
10984
10997
  customTemplateRegistry.set(tagName, _objectSpread__default["default"](_objectSpread__default["default"]({}, tplConstructor), {}, {
10985
10998
  name: tagName
10986
10999
  })); // Collect defined properties of the template.
10987
11000
 
10988
- var props = Object.keys(((_tplConstructor$proxy = tplConstructor.proxy) === null || _tplConstructor$proxy === void 0 ? void 0 : _tplConstructor$proxy.properties) || {});
11001
+ var props = getPropsOfCustomTemplate(tagName);
10989
11002
  var nativeProp = props.find(prop => prop in HTMLElement.prototype); // istanbul ignore if
10990
11003
 
10991
11004
  if (nativeProp !== undefined) {
@@ -10993,13 +11006,17 @@
10993
11006
  console.error("In custom template \"".concat(tagName, "\", \"").concat(nativeProp, "\" is a native HTMLElement property, and should be avoid to be used as a brick property."));
10994
11007
  }
10995
11008
 
11009
+ if (registered) {
11010
+ return;
11011
+ }
11012
+
10996
11013
  customElements.define(tagName, class TplElement extends HTMLElement {
10997
11014
  get $$typeof() {
10998
11015
  return "custom-template";
10999
11016
  }
11000
11017
 
11001
11018
  static get _dev_only_definedProperties() {
11002
- return props;
11019
+ return getPropsOfCustomTemplate(tagName);
11003
11020
  }
11004
11021
 
11005
11022
  connectedCallback() {
@@ -11017,6 +11034,16 @@
11017
11034
  }
11018
11035
  }
11019
11036
 
11037
+ function getPropsOfCustomTemplate(tagName) {
11038
+ var _state$map, _proxy$properties;
11039
+
11040
+ var {
11041
+ state,
11042
+ proxy
11043
+ } = customTemplateRegistry.get(tagName);
11044
+ return ((_state$map = state === null || state === void 0 ? void 0 : state.map(item => item.name)) !== null && _state$map !== void 0 ? _state$map : []).concat(Object.keys((_proxy$properties = proxy === null || proxy === void 0 ? void 0 : proxy.properties) !== null && _proxy$properties !== void 0 ? _proxy$properties : {}));
11045
+ }
11046
+
11020
11047
  var customProcessorRegistry = new Map();
11021
11048
  function registerCustomProcessor(processorFullName, processorFunc) {
11022
11049
  // `namespace` should be the camelCase of the package name.