@next-core/brick-kit 2.146.1 → 2.147.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,30 @@
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.147.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.146.2...@next-core/brick-kit@2.147.0) (2022-10-08)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * fix jumping to outside apps ([b27b129](https://github.com/easyops-cn/next-core/commit/b27b129fd276fc02f26c95a29b1e1ab418b9a4bd))
12
+
13
+
14
+ ### Features
15
+
16
+ * support cancel pending requests on route changed ([aa37eed](https://github.com/easyops-cn/next-core/commit/aa37eed0ab03f558fea693d7763da60d0807189b))
17
+
18
+
19
+
20
+
21
+
22
+ ## [2.146.2](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.146.1...@next-core/brick-kit@2.146.2) (2022-09-29)
23
+
24
+ **Note:** Version bump only for package @next-core/brick-kit
25
+
26
+
27
+
28
+
29
+
6
30
  ## [2.146.1](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.146.0...@next-core/brick-kit@2.146.1) (2022-09-28)
7
31
 
8
32
 
@@ -3519,6 +3519,43 @@
3519
3519
  return loadLazyBricks(lazyBrickRegistry.keys());
3520
3520
  }
3521
3521
 
3522
+ function matchStoryboard(storyboards, pathname) {
3523
+ // Put apps with longer homepage before shorter ones.
3524
+ // E.g., `/legacy/tool` will match first before `/legacy`.
3525
+ // This enables two apps with relationship of parent-child of homepage.
3526
+ var sortedStoryboards = _.orderBy(storyboards, storyboard => {
3527
+ var _storyboard$app$homep, _storyboard$app, _storyboard$app$homep2;
3528
+
3529
+ return (_storyboard$app$homep = (_storyboard$app = storyboard.app) === null || _storyboard$app === void 0 ? void 0 : (_storyboard$app$homep2 = _storyboard$app.homepage) === null || _storyboard$app$homep2 === void 0 ? void 0 : _storyboard$app$homep2.length) !== null && _storyboard$app$homep !== void 0 ? _storyboard$app$homep : 0;
3530
+ }, "desc");
3531
+
3532
+ for (var storyboard of sortedStoryboards) {
3533
+ var _storyboard$app2;
3534
+
3535
+ var homepage = (_storyboard$app2 = storyboard.app) === null || _storyboard$app2 === void 0 ? void 0 : _storyboard$app2.homepage;
3536
+
3537
+ if (typeof homepage === "string" && homepage[0] === "/") {
3538
+ if (brickUtils.matchPath(pathname, {
3539
+ path: homepage,
3540
+ exact: homepage === "/"
3541
+ })) {
3542
+ return storyboard;
3543
+ }
3544
+ }
3545
+ }
3546
+ }
3547
+ /**
3548
+ * We say it's an outside app when at least one of the below conditions are true:
3549
+ * - target app is not found.
3550
+ * - current app is non-standalone mode and target app is standalone mode.
3551
+ *
3552
+ * Note: when current app is standalone mode, other apps will not be found.
3553
+ */
3554
+
3555
+ function isOutsideApp(storyboard) {
3556
+ return !storyboard || !window.STANDALONE_MICRO_APPS && storyboard.app.standaloneMode;
3557
+ }
3558
+
3522
3559
  var kernel;
3523
3560
  /* istanbul ignore next */
3524
3561
 
@@ -3890,16 +3927,10 @@
3890
3927
 
3891
3928
  return kernel.router.getCurrentContext();
3892
3929
  }
3893
- function _internalApiHasMatchedApp(pathname) {
3894
- for (var {
3895
- homepage
3896
- } of kernel.bootstrapData.microApps) {
3897
- if (pathname === homepage || pathname.startsWith("".concat(homepage, "/"))) {
3898
- return true;
3899
- }
3900
- }
3930
+ /* istanbul ignore next */
3901
3931
 
3902
- return false;
3932
+ function _internalApiMatchStoryboard(pathname) {
3933
+ return matchStoryboard(kernel.bootstrapData.storyboards, pathname);
3903
3934
  }
3904
3935
  /* istanbul ignore next */
3905
3936
 
@@ -4016,13 +4047,11 @@
4016
4047
  reload,
4017
4048
  setBlockMessage,
4018
4049
  getBlockMessage,
4019
- unblock,
4020
- push,
4021
- replace
4022
- }, window.STANDALONE_MICRO_APPS ? standaloneHistoryOverridden(_objectSpread__default["default"](_objectSpread__default["default"]({}, browserHistory), {}, {
4050
+ unblock
4051
+ }, historyOverridden(_objectSpread__default["default"](_objectSpread__default["default"]({}, browserHistory), {}, {
4023
4052
  push,
4024
4053
  replace
4025
- })) : {});
4054
+ })));
4026
4055
  }
4027
4056
  /**
4028
4057
  * Override history for standalone micro apps.
@@ -4030,7 +4059,7 @@
4030
4059
  * when `push` or `replace` to other apps, force page refresh.
4031
4060
  */
4032
4061
 
4033
- function standaloneHistoryOverridden(browserHistory) {
4062
+ function historyOverridden(browserHistory) {
4034
4063
  var {
4035
4064
  push: originalPush,
4036
4065
  replace: originalReplace
@@ -4045,14 +4074,16 @@
4045
4074
  pathname = history$1.parsePath(path).pathname;
4046
4075
  } else {
4047
4076
  pathname = path.pathname;
4048
- }
4077
+ } // When history.push or history.replace is performing with a non-empty pathname,
4078
+ // force load the target page when it is a page of an outside app.
4049
4079
 
4050
- if (pathname === "" || _internalApiHasMatchedApp(pathname)) {
4051
- return (method === "push" ? originalPush : originalReplace)(path, state, callback);
4052
- } // Going to outside apps.
4053
4080
 
4081
+ if (pathname !== "" && isOutsideApp(_internalApiMatchStoryboard(pathname))) {
4082
+ // Going to outside apps.
4083
+ return location[method === "push" ? "assign" : "replace"](pathIsString ? getBasePath() + path.replace(/^\//, "") : browserHistory.createHref(path));
4084
+ }
4054
4085
 
4055
- return location[method === "push" ? "assign" : "replace"](pathIsString ? getBasePath() + path.replace(/^\//, "") : browserHistory.createHref(path));
4086
+ return (method === "push" ? originalPush : originalReplace)(path, state, callback);
4056
4087
  };
4057
4088
  }
4058
4089
 
@@ -4088,6 +4119,12 @@
4088
4119
  return error instanceof brickHttp.HttpResponseError && error.response.status === 401 && !!error.responseJson && error.responseJson.code === 100003;
4089
4120
  }
4090
4121
 
4122
+ /** @internal */
4123
+
4124
+ function isHttpAbortError(error) {
4125
+ return error instanceof brickHttp.HttpAbortError;
4126
+ }
4127
+
4091
4128
  /**
4092
4129
  * 将 http 请求错误转换为可读的字符串。
4093
4130
  *
@@ -4129,7 +4166,12 @@
4129
4166
  */
4130
4167
 
4131
4168
  function handleHttpError(error) {
4132
- // Redirect to login page if not logged in.
4169
+ // Do nothing if aborted http requests
4170
+ if (isHttpAbortError(error)) {
4171
+ return;
4172
+ } // Redirect to login page if not logged in.
4173
+
4174
+
4133
4175
  if (isUnauthenticatedError(error) && !window.NO_AUTH_GUARD) {
4134
4176
  // Do not show multiple confirm modals.
4135
4177
  if (unauthenticatedConfirmModal) {
@@ -10615,30 +10657,8 @@
10615
10657
  return "missed";
10616
10658
  }
10617
10659
 
10618
- matchStoryboard(storyboards, location) {
10619
- // Put apps with longer homepage before shorter ones.
10620
- // E.g., `/legacy/tool` will match first before `/legacy`.
10621
- // This enables two apps with relationship of parent-child of homepage.
10622
- var sortedStoryboards = _.orderBy(storyboards, storyboard => {
10623
- var _storyboard$app$homep, _storyboard$app, _storyboard$app$homep2;
10624
-
10625
- return (_storyboard$app$homep = (_storyboard$app = storyboard.app) === null || _storyboard$app === void 0 ? void 0 : (_storyboard$app$homep2 = _storyboard$app.homepage) === null || _storyboard$app$homep2 === void 0 ? void 0 : _storyboard$app$homep2.length) !== null && _storyboard$app$homep !== void 0 ? _storyboard$app$homep : 0;
10626
- }, "desc");
10627
-
10628
- for (var storyboard of sortedStoryboards) {
10629
- var _storyboard$app2;
10630
-
10631
- var homepage = (_storyboard$app2 = storyboard.app) === null || _storyboard$app2 === void 0 ? void 0 : _storyboard$app2.homepage;
10632
-
10633
- if (typeof homepage === "string" && homepage[0] === "/") {
10634
- if (brickUtils.matchPath((location || this.location).pathname, {
10635
- path: homepage,
10636
- exact: homepage === "/"
10637
- })) {
10638
- return storyboard;
10639
- }
10640
- }
10641
- }
10660
+ matchStoryboard(storyboards) {
10661
+ return matchStoryboard(storyboards, this.location.pathname);
10642
10662
  }
10643
10663
 
10644
10664
  getSubStoryboardByRoute(storyboard) {
@@ -11897,6 +11917,39 @@
11897
11917
  return mergedRoutes;
11898
11918
  }
11899
11919
 
11920
+ /** @internal */
11921
+ var abortController = (() => {
11922
+ var supported = ("AbortController" in window);
11923
+
11924
+ if (!supported) {
11925
+ return {
11926
+ abortPendingRequest() {// Do nothing
11927
+ },
11928
+
11929
+ getSignalToken() {
11930
+ return null;
11931
+ }
11932
+
11933
+ };
11934
+ }
11935
+
11936
+ var controller = new AbortController();
11937
+ var signal = controller.signal;
11938
+
11939
+ var abortPendingRequest = () => {
11940
+ controller.abort();
11941
+ controller = new AbortController();
11942
+ signal = controller.signal;
11943
+ };
11944
+
11945
+ var getSignalToken = () => signal;
11946
+
11947
+ return {
11948
+ abortPendingRequest,
11949
+ getSignalToken
11950
+ };
11951
+ })();
11952
+
11900
11953
  class Router {
11901
11954
  constructor(kernel) {
11902
11955
  _defineProperty__default["default"](this, "defaultCollapsed", false);
@@ -12012,6 +12065,8 @@
12012
12065
  return;
12013
12066
  }
12014
12067
 
12068
+ abortController.abortPendingRequest();
12069
+
12015
12070
  _this.locationChangeNotify(_this.prevLocation.pathname, location.pathname);
12016
12071
 
12017
12072
  _this.prevLocation = location;
@@ -12020,16 +12075,11 @@
12020
12075
 
12021
12076
  _this.locationContext.messageDispatcher.reset();
12022
12077
 
12023
- var storyboard = _this.locationContext.matchStoryboard(_this.kernel.bootstrapData.storyboards, location); // Whether non-standalone app to standalone app, or standlone app to non-standalone app
12024
- // window should reload to refresh the resource
12078
+ if (action === "POP") {
12079
+ var storyboard = matchStoryboard(_this.kernel.bootstrapData.storyboards, location.pathname); // When a browser action of goBack or goForward is performing,
12080
+ // force reload when the target page is a page of an outside app.
12025
12081
 
12026
-
12027
- if (!window.STANDALONE_MICRO_APPS) {
12028
- if (storyboard && storyboard.app.standaloneMode) {
12029
- window.location.reload();
12030
- }
12031
- } else {
12032
- if (!storyboard) {
12082
+ if (isOutsideApp(storyboard)) {
12033
12083
  window.location.reload();
12034
12084
  }
12035
12085
  }
@@ -12206,6 +12256,8 @@
12206
12256
 
12207
12257
  if (isUnauthenticatedError(error) && !window.NO_AUTH_GUARD) {
12208
12258
  mountRoutesResult.flags.unauthenticated = true;
12259
+ } else if (isHttpAbortError(error)) {
12260
+ return;
12209
12261
  } else {
12210
12262
  yield _this3.kernel.layoutBootstrap(layoutType);
12211
12263
  var brickPageError = _this3.kernel.presetBricks.pageError;
@@ -14968,6 +15020,7 @@
14968
15020
  exports.SingleBrickAsComponent = SingleBrickAsComponent;
14969
15021
  exports.StoryboardFunctionRegistryFactory = StoryboardFunctionRegistryFactory;
14970
15022
  exports.UpdatingElement = UpdatingElement;
15023
+ exports.abortController = abortController;
14971
15024
  exports.authenticate = authenticate;
14972
15025
  exports.batchSetAppsLocalTheme = batchSetAppsLocalTheme;
14973
15026
  exports.checkIf = checkIf;