@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/dist/index.esm.js CHANGED
@@ -2187,28 +2187,28 @@ function getCustomTemplateContext(tplContextId) {
2187
2187
  return tplContextMap.get(tplContextId);
2188
2188
  }
2189
2189
 
2190
- var MediaSize;
2190
+ var MediaBreakpoint;
2191
2191
 
2192
- (function (MediaSize) {
2193
- MediaSize["xLarge"] = "xLarge";
2194
- MediaSize["large"] = "large";
2195
- MediaSize["medium"] = "medium";
2196
- MediaSize["small"] = "small";
2197
- MediaSize["xSmall"] = "xSmall";
2198
- })(MediaSize || (MediaSize = {}));
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
2199
 
2200
- var mediaSizeBreakpointMap = new Map([[MediaSize.xLarge, "1920px"], [MediaSize.large, "1600px"], [MediaSize.medium, "1280px"], [MediaSize.small, "1024px"], [MediaSize.xSmall, 0]]);
2200
+ var mediaBreakpointMinWidthMap = new Map([[MediaBreakpoint.xLarge, "1920px"], [MediaBreakpoint.large, "1600px"], [MediaBreakpoint.medium, "1280px"], [MediaBreakpoint.small, "1024px"], [MediaBreakpoint.xSmall, 0]]);
2201
2201
  var mediaEventTarget = new EventTarget$1();
2202
- var sizeMatchesMap = {};
2202
+ var breakpointMatchesMap = {};
2203
2203
  var MEDIA = {};
2204
2204
 
2205
- function handleMatchesChange(data, size) {
2205
+ function handleMatchesChange(data, breakpoint) {
2206
2206
  var changed = false;
2207
- sizeMatchesMap[size] = data.matches;
2207
+ breakpointMatchesMap[breakpoint] = data.matches;
2208
2208
 
2209
- for (var [_size] of mediaSizeBreakpointMap) {
2210
- if (sizeMatchesMap[_size] && MEDIA.size !== _size) {
2211
- MEDIA.size = _size;
2209
+ for (var [_breakpoint] of mediaBreakpointMinWidthMap) {
2210
+ if (breakpointMatchesMap[_breakpoint] && MEDIA.breakpoint !== _breakpoint) {
2211
+ MEDIA.breakpoint = _breakpoint;
2212
2212
  changed = true;
2213
2213
  break;
2214
2214
  }
@@ -2221,17 +2221,17 @@ function handleMatchesChange(data, size) {
2221
2221
  }
2222
2222
  }
2223
2223
 
2224
- mediaSizeBreakpointMap.forEach((breakpoint, size) => {
2225
- var mediaQueryList = window.matchMedia("(min-width: ".concat(breakpoint, ")"));
2226
- handleMatchesChange(mediaQueryList, size);
2224
+ mediaBreakpointMinWidthMap.forEach((minWidth, breakpoint) => {
2225
+ var mediaQueryList = window.matchMedia("(min-width: ".concat(minWidth, ")"));
2226
+ handleMatchesChange(mediaQueryList, breakpoint);
2227
2227
 
2228
2228
  if (mediaQueryList.addEventListener) {
2229
2229
  mediaQueryList.addEventListener("change", event => {
2230
- handleMatchesChange(event, size);
2230
+ handleMatchesChange(event, breakpoint);
2231
2231
  });
2232
2232
  } else {
2233
2233
  mediaQueryList.addListener(event => {
2234
- handleMatchesChange(event, size);
2234
+ handleMatchesChange(event, breakpoint);
2235
2235
  });
2236
2236
  }
2237
2237
  });
@@ -7904,7 +7904,9 @@ class Kernel {
7904
7904
  var storyboard = this.bootstrapData.storyboards.find(item => item.app.id === appId);
7905
7905
  Object.assign(storyboard, _objectSpread(_objectSpread({}, storyboardPatch), {}, {
7906
7906
  $$fulfilling: Promise.resolve(),
7907
- $$fulfilled: true
7907
+ $$fulfilled: true,
7908
+ $$registerCustomTemplateProcessed: false,
7909
+ $$depsProcessed: false
7908
7910
  }));
7909
7911
  this.postProcessStoryboard(storyboard);
7910
7912
  }
@@ -8838,15 +8840,11 @@ class LocationContext {
8838
8840
  }
8839
8841
 
8840
8842
  if (isRouteConfOfRoutes(route) && Array.isArray(route.routes)) {
8843
+ yield _this.preFetchMenu(route.context);
8841
8844
  yield _this.mountRoutes(route.routes, slotId, mountRoutesResult);
8842
8845
  } else if (isRouteConfOfBricks(route) && Array.isArray(route.bricks)) {
8843
- var useMenus = scanAppGetMenuInAny(route);
8844
-
8845
- if (useMenus.length) {
8846
- yield constructMenuByMenusList(useMenus, _this.getCurrentContext(), _this.kernel);
8847
- }
8848
-
8849
- yield _this.mountBricks(route.bricks, matched.match, slotId, mountRoutesResult); // analytics data (page_view event)
8846
+ yield _this.mountBricks(route.bricks, matched.match, slotId, mountRoutesResult);
8847
+ yield _this.preFetchMenu(route); // analytics data (page_view event)
8850
8848
 
8851
8849
  if (route.analyticsData) {
8852
8850
  mountRoutesResult.analyticsData = computeRealValue(route.analyticsData, context, true);
@@ -9102,6 +9100,9 @@ class LocationContext {
9102
9100
  var expandedBrickConf = brickConf;
9103
9101
 
9104
9102
  if (tplTagName) {
9103
+ var _customTemplateRegist;
9104
+
9105
+ yield _this6.preFetchMenu((_customTemplateRegist = customTemplateRegistry.get(tplTagName)) === null || _customTemplateRegist === void 0 ? void 0 : _customTemplateRegist.bricks);
9105
9106
  expandedBrickConf = yield asyncExpandCustomTemplate(_objectSpread(_objectSpread({}, brickConf), {}, {
9106
9107
  brick: tplTagName,
9107
9108
  // Properties are computed for custom templates.
@@ -9322,6 +9323,18 @@ class LocationContext {
9322
9323
  }
9323
9324
  }
9324
9325
 
9326
+ preFetchMenu(data) {
9327
+ var _this7 = this;
9328
+
9329
+ return _asyncToGenerator$4(function* () {
9330
+ var useMenus = scanAppGetMenuInAny(data);
9331
+
9332
+ if (useMenus.length) {
9333
+ yield constructMenuByMenusList(useMenus, _this7.getCurrentContext(), _this7.kernel);
9334
+ }
9335
+ })();
9336
+ }
9337
+
9325
9338
  }
9326
9339
 
9327
9340
  function unmountTree(mountPoint) {
@@ -10956,37 +10969,37 @@ function handleProxyOfCustomTemplate(brick) {
10956
10969
  }
10957
10970
 
10958
10971
  function registerCustomTemplate(tplName, tplConstructor, appId) {
10959
- var _tplConstructor$proxy;
10960
-
10961
10972
  var tagName = tplName; // When a template is registered by an app, its namespace maybe missed.
10962
10973
 
10963
10974
  if (appId && !tplName.includes(".")) {
10964
10975
  tagName = "".concat(appId, ".").concat(tplName);
10965
10976
  }
10966
10977
 
10967
- if (customTemplateRegistry.has(tagName)) {
10978
+ var registered = customTemplateRegistry.has(tagName);
10979
+
10980
+ if (registered) {
10968
10981
  // When open launchpad, the storyboard will be updated.
10969
10982
  // However, we can't *undefine* a custom element.
10970
10983
  // Just ignore re-registering custom templates.
10971
10984
  if (!appId || appRegistered.has(appId)) {
10972
10985
  // eslint-disable-next-line no-console
10973
- console.error("Custom template of \"".concat(tagName, "\" already registered."));
10986
+ console.warn("Custom template of \"".concat(tagName, "\" already registered."));
10974
10987
  }
10988
+ } else {
10989
+ registered = !!customElements.get(tagName);
10975
10990
 
10976
- return;
10977
- }
10991
+ if (registered) {
10992
+ // eslint-disable-next-line no-console
10993
+ console.warn("Custom template of \"".concat(tagName, "\" already defined by customElements."));
10994
+ }
10995
+ } // Now we allow re-register custom template
10978
10996
 
10979
- if (customElements.get(tagName)) {
10980
- // eslint-disable-next-line no-console
10981
- console.error("Custom template of \"".concat(tagName, "\" already defined by customElements."));
10982
- return;
10983
- }
10984
10997
 
10985
10998
  customTemplateRegistry.set(tagName, _objectSpread(_objectSpread({}, tplConstructor), {}, {
10986
10999
  name: tagName
10987
11000
  })); // Collect defined properties of the template.
10988
11001
 
10989
- var props = Object.keys(((_tplConstructor$proxy = tplConstructor.proxy) === null || _tplConstructor$proxy === void 0 ? void 0 : _tplConstructor$proxy.properties) || {});
11002
+ var props = getPropsOfCustomTemplate(tagName);
10990
11003
  var nativeProp = props.find(prop => prop in HTMLElement.prototype); // istanbul ignore if
10991
11004
 
10992
11005
  if (nativeProp !== undefined) {
@@ -10994,13 +11007,17 @@ function registerCustomTemplate(tplName, tplConstructor, appId) {
10994
11007
  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."));
10995
11008
  }
10996
11009
 
11010
+ if (registered) {
11011
+ return;
11012
+ }
11013
+
10997
11014
  customElements.define(tagName, class TplElement extends HTMLElement {
10998
11015
  get $$typeof() {
10999
11016
  return "custom-template";
11000
11017
  }
11001
11018
 
11002
11019
  static get _dev_only_definedProperties() {
11003
- return props;
11020
+ return getPropsOfCustomTemplate(tagName);
11004
11021
  }
11005
11022
 
11006
11023
  connectedCallback() {
@@ -11018,6 +11035,16 @@ function registerCustomTemplate(tplName, tplConstructor, appId) {
11018
11035
  }
11019
11036
  }
11020
11037
 
11038
+ function getPropsOfCustomTemplate(tagName) {
11039
+ var _state$map, _proxy$properties;
11040
+
11041
+ var {
11042
+ state,
11043
+ proxy
11044
+ } = customTemplateRegistry.get(tagName);
11045
+ 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 : {}));
11046
+ }
11047
+
11021
11048
  var customProcessorRegistry = new Map();
11022
11049
  function registerCustomProcessor(processorFullName, processorFunc) {
11023
11050
  // `namespace` should be the camelCase of the package name.