@next-core/brick-kit 2.111.3 → 2.114.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,48 @@
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.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
+
8
+
9
+ ### Features
10
+
11
+ * add MEDIA gloabl object and onMediaChange life cycle ([3192ee4](https://github.com/easyops-cn/next-core/commit/3192ee4e595e2edc78d05b68d6cf0431905296fb))
12
+
13
+
14
+
15
+
16
+
17
+ # [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)
18
+
19
+
20
+ ### Features
21
+
22
+ * cache fetchMenu, and APP.getMenu change ([07ede47](https://github.com/easyops-cn/next-core/commit/07ede4778f012fbbb7e72d30b1c41d6478660aec))
23
+ * update type ([d7b480e](https://github.com/easyops-cn/next-core/commit/d7b480ecc287263345415c536bd263b7fb317b1e))
24
+
25
+
26
+
27
+
28
+
29
+ ## [2.112.1](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.112.0...@next-core/brick-kit@2.112.1) (2022-03-29)
30
+
31
+ **Note:** Version bump only for package @next-core/brick-kit
32
+
33
+
34
+
35
+
36
+
37
+ # [2.112.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.111.3...@next-core/brick-kit@2.112.0) (2022-03-29)
38
+
39
+
40
+ ### Features
41
+
42
+ * support updating storyboard on the fly ([0a50183](https://github.com/easyops-cn/next-core/commit/0a501838621d44c43ea7c16b211395b511e76c8a))
43
+
44
+
45
+
46
+
47
+
6
48
  ## [2.111.3](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.111.2...@next-core/brick-kit@2.111.3) (2022-03-29)
7
49
 
8
50
  **Note:** Version bump only for package @next-core/brick-kit
@@ -2186,6 +2186,56 @@
2186
2186
  return tplContextMap.get(tplContextId);
2187
2187
  }
2188
2188
 
2189
+ var MediaSize;
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 = {}));
2198
+
2199
+ var mediaSizeBreakpointMap = new Map([[MediaSize.xLarge, "1920px"], [MediaSize.large, "1600px"], [MediaSize.medium, "1280px"], [MediaSize.small, "1024px"], [MediaSize.xSmall, 0]]);
2200
+ var mediaEventTarget = new EventTarget$1();
2201
+ var sizeMatchesMap = {};
2202
+ var MEDIA = {};
2203
+
2204
+ function handleMatchesChange(data, size) {
2205
+ var changed = false;
2206
+ sizeMatchesMap[size] = data.matches;
2207
+
2208
+ for (var [_size] of mediaSizeBreakpointMap) {
2209
+ if (sizeMatchesMap[_size] && MEDIA.size !== _size) {
2210
+ MEDIA.size = _size;
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
+ mediaSizeBreakpointMap.forEach((breakpoint, size) => {
2224
+ var mediaQueryList = window.matchMedia("(min-width: ".concat(breakpoint, ")"));
2225
+ handleMatchesChange(mediaQueryList, size);
2226
+
2227
+ if (mediaQueryList.addEventListener) {
2228
+ mediaQueryList.addEventListener("change", event => {
2229
+ handleMatchesChange(event, size);
2230
+ });
2231
+ } else {
2232
+ mediaQueryList.addListener(event => {
2233
+ handleMatchesChange(event, size);
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
 
@@ -2663,6 +2716,7 @@
2663
2716
  // Caching menu requests to avoid flicker.
2664
2717
  var menuCache = new Map();
2665
2718
  var menuTitleCache = new Map();
2719
+ var processMenuCache = new Map();
2666
2720
  function constructMenu(_x, _x2, _x3) {
2667
2721
  return _constructMenu.apply(this, arguments);
2668
2722
  }
@@ -2699,12 +2753,14 @@
2699
2753
 
2700
2754
  function _constructMenuByMenusList() {
2701
2755
  _constructMenuByMenusList = _asyncToGenerator__default["default"](function* (menus, context, kernel) {
2702
- yield Promise.all(menus.map(menuId => processMenu(menuId, context, kernel)));
2756
+ processMenuCache.clear();
2757
+ var data = yield Promise.all(menus.map(menuId => processMenu(menuId, context, kernel)));
2758
+ data.forEach((item, index) => processMenuCache.set(menus[index], item));
2703
2759
  });
2704
2760
  return _constructMenuByMenusList.apply(this, arguments);
2705
2761
  }
2706
2762
 
2707
- var getMenu = menuId => menuCache.get(menuId);
2763
+ var getMenu = menuId => processMenuCache.get(menuId);
2708
2764
  function fetchMenuById(_x7, _x8) {
2709
2765
  return _fetchMenuById.apply(this, arguments);
2710
2766
  }
@@ -3114,6 +3170,11 @@
3114
3170
  getProviderBrick: kernel.getProviderBrick.bind(kernel)
3115
3171
  }, overrides);
3116
3172
  }
3173
+ /* istanbul ignore next */
3174
+
3175
+ function _dev_only_updateStoryboard(appId, storyboardPatch) {
3176
+ kernel._dev_only_updateStoryboard(appId, storyboardPatch);
3177
+ }
3117
3178
  class Runtime {
3118
3179
  constructor() {
3119
3180
  _defineProperty__default["default"](this, "registerBrickTemplate", registerBrickTemplate);
@@ -7797,9 +7858,9 @@
7797
7858
  }
7798
7859
 
7799
7860
  doFulfilStoryboard(storyboard) {
7800
- return _asyncToGenerator__default["default"](function* () {
7801
- var _storyboard$meta;
7861
+ var _this5 = this;
7802
7862
 
7863
+ return _asyncToGenerator__default["default"](function* () {
7803
7864
  if (window.STANDALONE_MICRO_APPS) {
7804
7865
  Object.assign(storyboard, {
7805
7866
  $$fulfilled: true
@@ -7818,28 +7879,43 @@
7818
7879
  });
7819
7880
  }
7820
7881
 
7821
- storyboard.app.$$routeAliasMap = brickUtils.scanRouteAliasInStoryboard(storyboard);
7882
+ _this5.postProcessStoryboard(storyboard);
7883
+ })();
7884
+ }
7822
7885
 
7823
- if ((_storyboard$meta = storyboard.meta) !== null && _storyboard$meta !== void 0 && _storyboard$meta.i18n) {
7824
- // Prefix to avoid conflict between brick package's i18n namespace.
7825
- var i18nNamespace = getI18nNamespace("app", storyboard.app.id); // Support any language in `meta.i18n`.
7886
+ postProcessStoryboard(storyboard) {
7887
+ var _storyboard$meta;
7826
7888
 
7827
- Object.entries(storyboard.meta.i18n).forEach(_ref => {
7828
- var [lang, resources] = _ref;
7829
- i18next__default["default"].addResourceBundle(lang, i18nNamespace, resources);
7830
- });
7831
- }
7832
- })();
7889
+ storyboard.app.$$routeAliasMap = brickUtils.scanRouteAliasInStoryboard(storyboard);
7890
+
7891
+ if ((_storyboard$meta = storyboard.meta) !== null && _storyboard$meta !== void 0 && _storyboard$meta.i18n) {
7892
+ // Prefix to avoid conflict between brick package's i18n namespace.
7893
+ var i18nNamespace = getI18nNamespace("app", storyboard.app.id); // Support any language in `meta.i18n`.
7894
+
7895
+ Object.entries(storyboard.meta.i18n).forEach(_ref => {
7896
+ var [lang, resources] = _ref;
7897
+ i18next__default["default"].addResourceBundle(lang, i18nNamespace, resources);
7898
+ });
7899
+ }
7900
+ }
7901
+
7902
+ _dev_only_updateStoryboard(appId, storyboardPatch) {
7903
+ var storyboard = this.bootstrapData.storyboards.find(item => item.app.id === appId);
7904
+ Object.assign(storyboard, _objectSpread__default["default"](_objectSpread__default["default"]({}, storyboardPatch), {}, {
7905
+ $$fulfilling: Promise.resolve(),
7906
+ $$fulfilled: true
7907
+ }));
7908
+ this.postProcessStoryboard(storyboard);
7833
7909
  }
7834
7910
 
7835
7911
  loadDepsOfStoryboard(storyboard) {
7836
- var _this5 = this;
7912
+ var _this6 = this;
7837
7913
 
7838
7914
  return _asyncToGenerator__default["default"](function* () {
7839
7915
  var {
7840
7916
  brickPackages,
7841
7917
  templatePackages
7842
- } = _this5.bootstrapData;
7918
+ } = _this6.bootstrapData;
7843
7919
 
7844
7920
  if (storyboard.dependsAll) {
7845
7921
  var dllPath = window.DLL_PATH || {};
@@ -7905,7 +7981,7 @@
7905
7981
  }
7906
7982
 
7907
7983
  loadDynamicBricksInBrickConf(brickConf) {
7908
- var _this6 = this;
7984
+ var _this7 = this;
7909
7985
 
7910
7986
  return _asyncToGenerator__default["default"](function* () {
7911
7987
  // Notice: `brickConf` contains runtime data,
@@ -7913,12 +7989,12 @@
7913
7989
  // which could cause stack overflow while traversing.
7914
7990
  var bricks = brickUtils.scanBricksInBrickConf(brickConf);
7915
7991
  var processors = brickUtils.scanProcessorsInAny(brickConf);
7916
- yield _this6.loadDynamicBricks(bricks, processors);
7992
+ yield _this7.loadDynamicBricks(bricks, processors);
7917
7993
  })();
7918
7994
  }
7919
7995
 
7920
7996
  loadDynamicBricks(bricks, processors) {
7921
- var _this7 = this;
7997
+ var _this8 = this;
7922
7998
 
7923
7999
  return _asyncToGenerator__default["default"](function* () {
7924
8000
  var filteredBricks = bricks.filter( // Only try to load undefined custom elements.
@@ -7930,7 +8006,7 @@
7930
8006
  } = brickUtils.getDllAndDepsByResource({
7931
8007
  bricks: filteredBricks,
7932
8008
  processors
7933
- }, _this7.bootstrapData.brickPackages);
8009
+ }, _this8.bootstrapData.brickPackages);
7934
8010
  yield loadScriptOfDll(dll);
7935
8011
  yield loadScriptOfBricksOrTemplates(deps);
7936
8012
  yield loadLazyBricks(filteredBricks);
@@ -7938,7 +8014,7 @@
7938
8014
  }
7939
8015
 
7940
8016
  loadEditorBricks(editorBricks) {
7941
- var _this8 = this;
8017
+ var _this9 = this;
7942
8018
 
7943
8019
  return _asyncToGenerator__default["default"](function* () {
7944
8020
  var {
@@ -7947,7 +8023,7 @@
7947
8023
  } = brickUtils.getDllAndDepsByResource({
7948
8024
  editorBricks: editorBricks.filter( // Only try to load undefined custom elements.
7949
8025
  item => !customElements.get(item))
7950
- }, _this8.bootstrapData.brickPackages);
8026
+ }, _this9.bootstrapData.brickPackages);
7951
8027
  yield loadScriptOfDll(dll);
7952
8028
  yield loadScriptOfBricksOrTemplates(deps);
7953
8029
  })();
@@ -8051,10 +8127,10 @@
8051
8127
  }
8052
8128
 
8053
8129
  getMicroAppApiOrchestrationMapAsync() {
8054
- var _this9 = this;
8130
+ var _this10 = this;
8055
8131
 
8056
8132
  return _asyncToGenerator__default["default"](function* () {
8057
- return yield _this9.allMicroAppApiOrchestrationPromise;
8133
+ return yield _this10.allMicroAppApiOrchestrationPromise;
8058
8134
  })();
8059
8135
  }
8060
8136
 
@@ -8146,14 +8222,14 @@
8146
8222
  }
8147
8223
 
8148
8224
  getRelatedAppsAsync(appId) {
8149
- var _this10 = this;
8225
+ var _this11 = this;
8150
8226
 
8151
8227
  return _asyncToGenerator__default["default"](function* () {
8152
8228
  if (!appId) {
8153
8229
  return [];
8154
8230
  }
8155
8231
 
8156
- var allRelatedApps = yield _this10.allRelatedAppsPromise;
8232
+ var allRelatedApps = yield _this11.allRelatedAppsPromise;
8157
8233
  var thisApp = allRelatedApps.find(item => item.microAppId === appId);
8158
8234
 
8159
8235
  if (!thisApp) {
@@ -8165,38 +8241,38 @@
8165
8241
  }
8166
8242
 
8167
8243
  updateWorkspaceStack() {
8168
- var _this11 = this;
8244
+ var _this12 = this;
8169
8245
 
8170
8246
  return _asyncToGenerator__default["default"](function* () {
8171
- if (_this11.currentApp && _this11.currentApp.id) {
8247
+ if (_this12.currentApp && _this12.currentApp.id) {
8172
8248
  var workspace = {
8173
- appId: _this11.currentApp.id,
8174
- appName: _this11.currentApp.name,
8175
- appLocaleName: _this11.currentApp.localeName,
8176
- url: _this11.currentUrl
8249
+ appId: _this12.currentApp.id,
8250
+ appName: _this12.currentApp.name,
8251
+ appLocaleName: _this12.currentApp.localeName,
8252
+ url: _this12.currentUrl
8177
8253
  };
8178
8254
 
8179
- if (_this11.workspaceStack.length > 0) {
8180
- var previousWorkspace = _this11.workspaceStack[_this11.workspaceStack.length - 1];
8255
+ if (_this12.workspaceStack.length > 0) {
8256
+ var previousWorkspace = _this12.workspaceStack[_this12.workspaceStack.length - 1];
8181
8257
 
8182
- var _relatedApps = yield _this11.getRelatedAppsAsync(previousWorkspace.appId);
8258
+ var _relatedApps = yield _this12.getRelatedAppsAsync(previousWorkspace.appId);
8183
8259
 
8184
- if (_relatedApps.some(item => item.microAppId === _this11.currentApp.id)) {
8260
+ if (_relatedApps.some(item => item.microAppId === _this12.currentApp.id)) {
8185
8261
  Object.assign(previousWorkspace, workspace);
8186
8262
  return;
8187
8263
  }
8188
8264
  }
8189
8265
 
8190
- var relatedApps = yield _this11.getRelatedAppsAsync(_this11.currentApp.id);
8266
+ var relatedApps = yield _this12.getRelatedAppsAsync(_this12.currentApp.id);
8191
8267
 
8192
8268
  if (relatedApps.length > 0) {
8193
- _this11.workspaceStack.push(workspace);
8269
+ _this12.workspaceStack.push(workspace);
8194
8270
 
8195
8271
  return;
8196
8272
  }
8197
8273
  }
8198
8274
 
8199
- _this11.workspaceStack = [];
8275
+ _this12.workspaceStack = [];
8200
8276
  })();
8201
8277
  }
8202
8278
 
@@ -8237,22 +8313,22 @@
8237
8313
  }
8238
8314
 
8239
8315
  getProviderBrick(provider) {
8240
- var _this12 = this;
8316
+ var _this13 = this;
8241
8317
 
8242
8318
  return _asyncToGenerator__default["default"](function* () {
8243
8319
  if (isCustomApiProvider(provider)) {
8244
8320
  provider = CUSTOM_API_PROVIDER;
8245
8321
  }
8246
8322
 
8247
- if (_this12.providerRepository.has(provider)) {
8248
- return _this12.providerRepository.get(provider);
8323
+ if (_this13.providerRepository.has(provider)) {
8324
+ return _this13.providerRepository.get(provider);
8249
8325
  }
8250
8326
 
8251
8327
  if (provider === CUSTOM_API_PROVIDER && !customElements.get(provider)) {
8252
8328
  registerCustomApi();
8253
8329
  }
8254
8330
 
8255
- yield _this12.loadDynamicBricks([provider]);
8331
+ yield _this13.loadDynamicBricks([provider]);
8256
8332
 
8257
8333
  if (!customElements.get(provider)) {
8258
8334
  throw new Error("Provider not defined: \"".concat(provider, "\"."));
@@ -8260,7 +8336,7 @@
8260
8336
 
8261
8337
  var brick = document.createElement(provider);
8262
8338
 
8263
- _this12.providerRepository.set(provider, brick);
8339
+ _this13.providerRepository.set(provider, brick);
8264
8340
 
8265
8341
  return brick;
8266
8342
  })();
@@ -8570,6 +8646,8 @@
8570
8646
 
8571
8647
  _defineProperty__default["default"](this, "anchorUnloadHandlers", []);
8572
8648
 
8649
+ _defineProperty__default["default"](this, "mediaChangeHandlers", []);
8650
+
8573
8651
  _defineProperty__default["default"](this, "messageCloseHandlers", []);
8574
8652
 
8575
8653
  _defineProperty__default["default"](this, "messageHandlers", []);
@@ -9084,6 +9162,7 @@
9084
9162
  onPageLeave,
9085
9163
  onAnchorLoad,
9086
9164
  onAnchorUnload,
9165
+ onMediaChange,
9087
9166
  onMessage,
9088
9167
  onMessageClose
9089
9168
  } = lifeCycle !== null && lifeCycle !== void 0 ? lifeCycle : {};
@@ -9142,6 +9221,15 @@
9142
9221
  });
9143
9222
  }
9144
9223
 
9224
+ if (onMediaChange) {
9225
+ this.mediaChangeHandlers.push({
9226
+ brick,
9227
+ match,
9228
+ tplContextId,
9229
+ handler: onMediaChange
9230
+ });
9231
+ }
9232
+
9145
9233
  if (onMessage) {
9146
9234
  this.messageHandlers.push({
9147
9235
  brick,
@@ -9197,6 +9285,12 @@
9197
9285
  }
9198
9286
  }
9199
9287
 
9288
+ handleMediaChange(detail) {
9289
+ this.dispatchLifeCycleEvent(new CustomEvent("media.change", {
9290
+ detail: getReadOnlyProxy(detail)
9291
+ }), this.mediaChangeHandlers);
9292
+ }
9293
+
9200
9294
  handleMessage() {
9201
9295
  this.messageDispatcher.create(this.messageHandlers, this.getCurrentContext());
9202
9296
  }
@@ -9708,6 +9802,8 @@
9708
9802
 
9709
9803
  _defineProperty__default["default"](this, "navConfig", void 0);
9710
9804
 
9805
+ _defineProperty__default["default"](this, "mediaEventTargetHandler", void 0);
9806
+
9711
9807
  this.kernel = kernel;
9712
9808
  this.featureFlags = this.kernel.getFeatureFlags();
9713
9809
  var history = getHistory();
@@ -10015,7 +10111,12 @@
10015
10111
  _this3.kernel.unsetBars({
10016
10112
  appChanged,
10017
10113
  legacy: actualLegacy
10018
- }); // There is a window to set theme and mode by `lifeCycle.onBeforePageLoad`.
10114
+ });
10115
+
10116
+ if (_this3.mediaEventTargetHandler) {
10117
+ mediaEventTarget.removeEventListener("change", _this3.mediaEventTargetHandler);
10118
+ _this3.mediaEventTargetHandler = undefined;
10119
+ } // There is a window to set theme and mode by `lifeCycle.onBeforePageLoad`.
10019
10120
 
10020
10121
 
10021
10122
  _this3.locationContext.handleBeforePageLoad();
@@ -10088,6 +10189,9 @@
10088
10189
  _this3.locationContext.handleMessage();
10089
10190
  }
10090
10191
 
10192
+ _this3.mediaEventTargetHandler = event => _this3.locationContext.handleMediaChange(event.detail);
10193
+
10194
+ mediaEventTarget.addEventListener("change", _this3.mediaEventTargetHandler);
10091
10195
  pageTracker === null || pageTracker === void 0 ? void 0 : pageTracker(locationContext.getCurrentMatch().path); // analytics page_view event
10092
10196
 
10093
10197
  easyopsAnalytics.userAnalytics.event("page_view", _objectSpread__default["default"]({
@@ -12836,7 +12940,8 @@
12836
12940
  getFakeKernel: _dev_only_getFakeKernel,
12837
12941
 
12838
12942
  /** @deprecated Keep it for backward-compatibility. */
12839
- checkoutTplContext: lodash.noop
12943
+ checkoutTplContext: lodash.noop,
12944
+ updateStoryboard: _dev_only_updateStoryboard
12840
12945
  };
12841
12946
 
12842
12947
  var _excluded$2 = ["type"];