@next-core/brick-kit 2.144.0 → 2.145.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,17 @@
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.145.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.144.0...@next-core/brick-kit@2.145.0) (2022-09-26)
7
+
8
+
9
+ ### Features
10
+
11
+ * support router if condition ([4486130](https://github.com/easyops-cn/next-core/commit/44861303b0c236ec36f3bb55f469229e23116e5d))
12
+
13
+
14
+
15
+
16
+
6
17
  # [2.144.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.143.0...@next-core/brick-kit@2.144.0) (2022-09-25)
7
18
 
8
19
 
@@ -10565,31 +10565,49 @@
10565
10565
  }
10566
10566
 
10567
10567
  matchRoutes(routes, app) {
10568
- for (var route of routes) {
10568
+ var _this = this;
10569
+
10570
+ var _loop = function (route) {
10569
10571
  var computedPath = brickUtils.computeRealRoutePath(route.path, app);
10570
10572
 
10571
10573
  if ([].concat(computedPath).includes(undefined)) {
10572
10574
  // eslint-disable-next-line no-console
10573
10575
  console.error("Invalid route with invalid path:", route);
10574
- return "missed";
10576
+ return {
10577
+ v: "missed"
10578
+ };
10575
10579
  }
10576
10580
 
10577
- var match = brickUtils.matchPath(this.location.pathname, {
10581
+ var match = brickUtils.matchPath(_this.location.pathname, {
10578
10582
  path: computedPath,
10579
- exact: route.exact
10583
+ exact: route.exact,
10584
+ checkIf: context => looseCheckIf(route, context),
10585
+ getContext: match => _this.getContext({
10586
+ match
10587
+ })
10580
10588
  });
10581
10589
 
10582
10590
  if (match !== null) {
10583
10591
  if (app.noAuthGuard || route.public || isLoggedIn()) {
10584
- this.currentMatch = match;
10592
+ _this.currentMatch = match;
10585
10593
  return {
10586
- match,
10587
- route
10594
+ v: {
10595
+ match,
10596
+ route
10597
+ }
10588
10598
  };
10589
10599
  }
10590
10600
 
10591
- return "unauthenticated";
10601
+ return {
10602
+ v: "unauthenticated"
10603
+ };
10592
10604
  }
10605
+ };
10606
+
10607
+ for (var route of routes) {
10608
+ var _ret = _loop(route);
10609
+
10610
+ if (typeof _ret === "object") return _ret.v;
10593
10611
  }
10594
10612
 
10595
10613
  return "missed";
@@ -10635,10 +10653,10 @@
10635
10653
  }
10636
10654
 
10637
10655
  mountRoutes(routes, slotId, mountRoutesResult) {
10638
- var _this = this;
10656
+ var _this2 = this;
10639
10657
 
10640
10658
  return _asyncToGenerator__default["default"](function* () {
10641
- var matched = _this.matchRoutes(routes, _this.kernel.nextApp);
10659
+ var matched = _this2.matchRoutes(routes, _this2.kernel.nextApp);
10642
10660
 
10643
10661
  var redirect;
10644
10662
  var redirectConf = {};
@@ -10657,22 +10675,22 @@
10657
10675
  mountRoutesResult.route = route = matched.route;
10658
10676
 
10659
10677
  if (route.segues) {
10660
- Object.assign(_this.segues, route.segues);
10678
+ Object.assign(_this2.segues, route.segues);
10661
10679
  }
10662
10680
 
10663
10681
  if (route.hybrid) {
10664
10682
  mountRoutesResult.flags.hybrid = true;
10665
10683
  }
10666
10684
 
10667
- context = _this.getContext({
10685
+ context = _this2.getContext({
10668
10686
  match: matched.match
10669
10687
  });
10670
10688
 
10671
- _this.resolver.defineResolves(route.defineResolves, context);
10689
+ _this2.resolver.defineResolves(route.defineResolves, context);
10672
10690
 
10673
- yield _this.mountProviders(route.providers, matched.match, slotId, mountRoutesResult);
10674
- yield _this.storyboardContextWrapper.define(route.context, context);
10675
- yield _this.preCheckPermissions(route, context);
10691
+ yield _this2.mountProviders(route.providers, matched.match, slotId, mountRoutesResult);
10692
+ yield _this2.storyboardContextWrapper.define(route.context, context);
10693
+ yield _this2.preCheckPermissions(route, context);
10676
10694
  redirect = computeRealValue(route.redirect, context, true);
10677
10695
 
10678
10696
  if (redirect) {
@@ -10684,7 +10702,7 @@
10684
10702
  break;
10685
10703
  } else {
10686
10704
  // Resolvable redirect.
10687
- yield _this.resolver.resolveOne("reference", redirect, redirectConf);
10705
+ yield _this2.resolver.resolveOne("reference", redirect, redirectConf);
10688
10706
 
10689
10707
  if (redirectConf.redirect) {
10690
10708
  mountRoutesResult.flags.redirect = {
@@ -10695,18 +10713,18 @@
10695
10713
  }
10696
10714
  }
10697
10715
 
10698
- yield _this.mountMenu(route.menu, matched.match, mountRoutesResult);
10716
+ yield _this2.mountMenu(route.menu, matched.match, mountRoutesResult);
10699
10717
 
10700
10718
  if (route.documentId) {
10701
10719
  mountRoutesResult.appBar.documentId = route.documentId;
10702
10720
  }
10703
10721
 
10704
10722
  if (isRouteConfOfRoutes(route) && Array.isArray(route.routes)) {
10705
- yield _this.preFetchMenu(route.context);
10706
- yield _this.mountRoutes(route.routes, slotId, mountRoutesResult);
10723
+ yield _this2.preFetchMenu(route.context);
10724
+ yield _this2.mountRoutes(route.routes, slotId, mountRoutesResult);
10707
10725
  } else if (isRouteConfOfBricks(route) && Array.isArray(route.bricks)) {
10708
- yield _this.preFetchMenu(route);
10709
- yield _this.mountBricks(route.bricks, matched.match, slotId, mountRoutesResult); // analytics data (page_view event)
10726
+ yield _this2.preFetchMenu(route);
10727
+ yield _this2.mountBricks(route.bricks, matched.match, slotId, mountRoutesResult); // analytics data (page_view event)
10710
10728
 
10711
10729
  if (route.analyticsData) {
10712
10730
  mountRoutesResult.analyticsData = computeRealValue(route.analyticsData, context, true);
@@ -10720,7 +10738,7 @@
10720
10738
  }
10721
10739
 
10722
10740
  mountMenu(menuConf, match, mountRoutesResult) {
10723
- var _this2 = this;
10741
+ var _this3 = this;
10724
10742
 
10725
10743
  return _asyncToGenerator__default["default"](function* () {
10726
10744
  if (menuConf === false) {
@@ -10734,7 +10752,7 @@
10734
10752
  return;
10735
10753
  }
10736
10754
 
10737
- var context = _this2.getContext({
10755
+ var context = _this3.getContext({
10738
10756
  match
10739
10757
  });
10740
10758
 
@@ -10753,10 +10771,10 @@
10753
10771
  children: []
10754
10772
  };
10755
10773
 
10756
- _this2.registerHandlersFromLifeCycle(menuConf.lifeCycle, brick, match); // Then, resolve the brick.
10774
+ _this3.registerHandlersFromLifeCycle(menuConf.lifeCycle, brick, match); // Then, resolve the brick.
10757
10775
 
10758
10776
 
10759
- yield _this2.resolver.resolve(menuConf, brick, context);
10777
+ yield _this3.resolver.resolve(menuConf, brick, context);
10760
10778
  mountRoutesResult.menuInBg.push(brick);
10761
10779
  return;
10762
10780
  }
@@ -10764,7 +10782,7 @@
10764
10782
  var injectDeep = menuConf.injectDeep;
10765
10783
 
10766
10784
  if (menuConf.type === "resolve") {
10767
- yield _this2.resolver.resolveOne("reference", _objectSpread__default["default"]({
10785
+ yield _this3.resolver.resolveOne("reference", _objectSpread__default["default"]({
10768
10786
  transformMapArray: false
10769
10787
  }, menuConf.resolve), menuConf, null, context);
10770
10788
  injectDeep = false;
@@ -10810,12 +10828,12 @@
10810
10828
  }
10811
10829
 
10812
10830
  mountProviders(providers, match, slotId, mountRoutesResult) {
10813
- var _this3 = this;
10831
+ var _this4 = this;
10814
10832
 
10815
10833
  return _asyncToGenerator__default["default"](function* () {
10816
10834
  if (Array.isArray(providers)) {
10817
10835
  for (var providerConf of providers) {
10818
- yield _this3.mountBrick(_objectSpread__default["default"](_objectSpread__default["default"]({}, typeof providerConf === "string" ? {
10836
+ yield _this4.mountBrick(_objectSpread__default["default"](_objectSpread__default["default"]({}, typeof providerConf === "string" ? {
10819
10837
  brick: providerConf
10820
10838
  } : providerConf), {}, {
10821
10839
  bg: true,
@@ -10827,12 +10845,12 @@
10827
10845
  }
10828
10846
 
10829
10847
  mountBricks(bricks, match, slotId, mountRoutesResult, tplStack) {
10830
- var _this4 = this;
10848
+ var _this5 = this;
10831
10849
 
10832
10850
  return _asyncToGenerator__default["default"](function* () {
10833
10851
  for (var brickConf of bricks) {
10834
10852
  try {
10835
- yield _this4.mountBrick(brickConf, match, slotId, mountRoutesResult, tplStack === null || tplStack === void 0 ? void 0 : tplStack.slice());
10853
+ yield _this5.mountBrick(brickConf, match, slotId, mountRoutesResult, tplStack === null || tplStack === void 0 ? void 0 : tplStack.slice());
10836
10854
  } catch (error) {
10837
10855
  if (error instanceof ResolveRequestError) {
10838
10856
  var errorMessage = httpErrorToString(error.rawError);
@@ -10861,13 +10879,13 @@
10861
10879
  }
10862
10880
 
10863
10881
  checkResolvableIf(ifContainer, context) {
10864
- var _this5 = this;
10882
+ var _this6 = this;
10865
10883
 
10866
10884
  return _asyncToGenerator__default["default"](function* () {
10867
10885
  if (brickUtils.isObject(ifContainer.if)) {
10868
10886
  var ifChecked = computeRealValue(ifContainer.if, context, true);
10869
10887
  var ifConf = {};
10870
- yield _this5.resolver.resolveOne("reference", ifChecked, ifConf);
10888
+ yield _this6.resolver.resolveOne("reference", ifChecked, ifConf);
10871
10889
  return !brickUtils.hasOwnProperty(ifConf, "if") || !!ifConf.if;
10872
10890
  }
10873
10891
 
@@ -10886,39 +10904,39 @@
10886
10904
 
10887
10905
  mountBrick(brickConf, match, slotId, mountRoutesResult) {
10888
10906
  var _arguments = arguments,
10889
- _this6 = this;
10907
+ _this7 = this;
10890
10908
 
10891
10909
  return _asyncToGenerator__default["default"](function* () {
10892
- var _this6$kernel$nextApp, _brickConf$lifeCycle, _brick$lifeCycle;
10910
+ var _this7$kernel$nextApp, _brickConf$lifeCycle, _brick$lifeCycle;
10893
10911
 
10894
10912
  var tplStack = _arguments.length > 4 && _arguments[4] !== undefined ? _arguments[4] : [];
10895
10913
  var tplContextId = brickConf[symbolForTplContextId];
10896
10914
  var formContextId = brickConf[symbolForFormContextId];
10897
10915
 
10898
- var context = _this6.getContext({
10916
+ var context = _this7.getContext({
10899
10917
  match,
10900
10918
  tplContextId,
10901
10919
  formContextId
10902
10920
  }); // First, check whether the brick should be rendered.
10903
10921
 
10904
10922
 
10905
- if (!(yield _this6.checkResolvableIf(brickConf, context))) {
10923
+ if (!(yield _this7.checkResolvableIf(brickConf, context))) {
10906
10924
  return;
10907
10925
  } // Then, resolve the template to a brick.
10908
10926
 
10909
10927
 
10910
10928
  if (brickConf.template) {
10911
- yield _this6.resolver.resolve(brickConf, null, context);
10929
+ yield _this7.resolver.resolve(brickConf, null, context);
10912
10930
  } // Check `if` again for dynamic loaded templates.
10913
10931
 
10914
10932
 
10915
- if (!(yield _this6.checkResolvableIf(brickConf, context))) {
10933
+ if (!(yield _this7.checkResolvableIf(brickConf, context))) {
10916
10934
  return;
10917
10935
  } // If it's a custom template, `tplTagName` is the tag name of the template.
10918
10936
  // Otherwise, `tplTagName` is false.
10919
10937
 
10920
10938
 
10921
- var tplTagName = getTagNameOfCustomTemplate(brickConf.brick, (_this6$kernel$nextApp = _this6.kernel.nextApp) === null || _this6$kernel$nextApp === void 0 ? void 0 : _this6$kernel$nextApp.id);
10939
+ var tplTagName = getTagNameOfCustomTemplate(brickConf.brick, (_this7$kernel$nextApp = _this7.kernel.nextApp) === null || _this7$kernel$nextApp === void 0 ? void 0 : _this7$kernel$nextApp.id);
10922
10940
 
10923
10941
  if (tplTagName) {
10924
10942
  if (tplStack.includes(tplTagName)) {
@@ -10933,8 +10951,8 @@
10933
10951
  }
10934
10952
 
10935
10953
  var brick = {};
10936
- yield _this6.storyboardContextWrapper.define(brickConf.context, context, brick);
10937
- yield _this6.preCheckPermissions(brickConf, context);
10954
+ yield _this7.storyboardContextWrapper.define(brickConf.context, context, brick);
10955
+ yield _this7.preCheckPermissions(brickConf, context);
10938
10956
  var trackingContextList = [];
10939
10957
  Object.assign(brick, _objectSpread__default["default"]({
10940
10958
  type: tplTagName || brickConf.brick,
@@ -10966,40 +10984,40 @@
10966
10984
  brick.refForProxy.brick = brick;
10967
10985
  }
10968
10986
 
10969
- _this6.registerHandlersFromLifeCycle(brickConf.lifeCycle, brick, match, tplContextId);
10987
+ _this7.registerHandlersFromLifeCycle(brickConf.lifeCycle, brick, match, tplContextId);
10970
10988
 
10971
10989
  if ((_brick$lifeCycle = brick.lifeCycle) !== null && _brick$lifeCycle !== void 0 && _brick$lifeCycle.onScrollIntoView) {
10972
- _this6.brickBindObserver(brick);
10990
+ _this7.brickBindObserver(brick);
10973
10991
  } // Then, resolve the brick.
10974
10992
 
10975
10993
 
10976
- yield _this6.resolver.resolve(brickConf, brick, context);
10994
+ yield _this7.resolver.resolve(brickConf, brick, context);
10977
10995
  var expandedBrickConf = brickConf;
10978
10996
  var isBaseLayout = ["base-layout.tpl-homepage-base-module", "base-layout.tpl-base-page-module", "base-layout.tpl-homepage-base-module-cmdb", "base-layout.tpl-base-page-module-cmdb"].includes(tplTagName);
10979
10997
 
10980
- if (tplTagName && (!isBaseLayout || _this6.kernel.getFeatureFlags()["support-ui-8.0-base-layout"] && isBaseLayout)) {
10998
+ if (tplTagName && (!isBaseLayout || _this7.kernel.getFeatureFlags()["support-ui-8.0-base-layout"] && isBaseLayout)) {
10981
10999
  var _customTemplateRegist;
10982
11000
 
10983
- yield _this6.preFetchMenu((_customTemplateRegist = customTemplateRegistry.get(tplTagName)) === null || _customTemplateRegist === void 0 ? void 0 : _customTemplateRegist.bricks);
11001
+ yield _this7.preFetchMenu((_customTemplateRegist = customTemplateRegistry.get(tplTagName)) === null || _customTemplateRegist === void 0 ? void 0 : _customTemplateRegist.bricks);
10984
11002
  expandedBrickConf = yield asyncExpandCustomTemplate(_objectSpread__default["default"](_objectSpread__default["default"]({}, brickConf), {}, {
10985
11003
  brick: tplTagName,
10986
11004
  // Properties are computed for custom templates.
10987
11005
  properties: brick.properties
10988
11006
  }), brick, context); // Try to load deps for dynamic added bricks.
10989
11007
 
10990
- yield _this6.kernel.loadDynamicBricksInBrickConf(expandedBrickConf);
11008
+ yield _this7.kernel.loadDynamicBricksInBrickConf(expandedBrickConf);
10991
11009
  }
10992
11010
 
10993
11011
  if (brick.type === formRenderer) {
10994
11012
  var formData = JSON.parse(brick.properties.formData);
10995
11013
  expandedBrickConf = yield ExpandCustomForm(formData, brickConf, brick.properties.isPreview, context);
10996
- yield _this6.kernel.loadDynamicBricksInBrickConf(expandedBrickConf);
11014
+ yield _this7.kernel.loadDynamicBricksInBrickConf(expandedBrickConf);
10997
11015
  }
10998
11016
 
10999
11017
  if (expandedBrickConf.exports) {
11000
11018
  for (var [prop, ctxName] of Object.entries(expandedBrickConf.exports)) {
11001
11019
  if (typeof ctxName === "string" && ctxName.startsWith("CTX.")) {
11002
- _this6.storyboardContextWrapper.set(ctxName.substring(4), {
11020
+ _this7.storyboardContextWrapper.set(ctxName.substring(4), {
11003
11021
  type: "brick-property",
11004
11022
  brick,
11005
11023
  prop
@@ -11011,7 +11029,7 @@
11011
11029
  if (expandedBrickConf.bg) {
11012
11030
  // A bg brick has no slotId.
11013
11031
  brick.slotId = undefined;
11014
- appendBrick(brick, _this6.kernel.mountPoints.bg);
11032
+ appendBrick(brick, _this7.kernel.mountPoints.bg);
11015
11033
  } else {
11016
11034
  if (expandedBrickConf.portal) {
11017
11035
  // A portal brick has no slotId.
@@ -11028,9 +11046,9 @@
11028
11046
  });
11029
11047
 
11030
11048
  if (slotConf.type === "bricks") {
11031
- yield _this6.mountBricks(slotConf.bricks, match, _slotId, slottedMountRoutesResult, tplStack);
11049
+ yield _this7.mountBricks(slotConf.bricks, match, _slotId, slottedMountRoutesResult, tplStack);
11032
11050
  } else if (slotConf.type === "routes") {
11033
- yield _this6.mountRoutes(slotConf.routes, _slotId, slottedMountRoutesResult);
11051
+ yield _this7.mountRoutes(slotConf.routes, _slotId, slottedMountRoutesResult);
11034
11052
  }
11035
11053
  }
11036
11054
  }
@@ -11231,13 +11249,13 @@
11231
11249
  }
11232
11250
 
11233
11251
  preFetchMenu(data) {
11234
- var _this7 = this;
11252
+ var _this8 = this;
11235
11253
 
11236
11254
  return _asyncToGenerator__default["default"](function* () {
11237
11255
  var useMenus = brickUtils.scanAppGetMenuInAny(data);
11238
11256
 
11239
11257
  if (useMenus.length) {
11240
- yield preConstructMenus(useMenus, _this7.getCurrentContext(), _this7.kernel);
11258
+ yield preConstructMenus(useMenus, _this8.getCurrentContext(), _this8.kernel);
11241
11259
  }
11242
11260
  })();
11243
11261
  }