@next-core/brick-kit 2.159.5 → 2.160.1

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
@@ -4,7 +4,7 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
4
4
  import _asyncToGenerator$3 from '@babel/runtime/helpers/asyncToGenerator';
5
5
  import _defineProperty$1 from '@babel/runtime/helpers/defineProperty';
6
6
  import React, { useState, useEffect, useRef, useMemo, useCallback, forwardRef, useImperativeHandle, useContext, createContext, useReducer } from 'react';
7
- import { JsonStorage, toPath, computeRealRoutePath, hasOwnProperty, isObject, isEvaluable, transformAndInject, transform, trackContext, trackState, trackFormState, scanPermissionActionsInStoryboard, precookFunction, cook, resolveContextConcurrently, syncResolveContextConcurrently, trackUsedState, trackUsedContext, shouldAllowRecursiveEvaluations, preevaluate, inject, scanPermissionActionsInAny, matchPath, deepFreeze, createProviderClass, removeDeadConditionsInTpl, getTemplateDepsOfStoryboard, getDllAndDepsOfStoryboard, asyncProcessStoryboard, getDllAndDepsByResource, scanRouteAliasInStoryboard, prefetchScript, scanBricksInBrickConf, scanProcessorsInAny, loadScript, scanAppGetMenuInAny, asyncProcessBrick, scanInstalledAppsInStoryboard, removeDeadConditions, restoreDynamicTemplates, scanStoryboard, mapCustomApisToNameAndNamespace } from '@next-core/brick-utils';
7
+ import { JsonStorage, toPath, computeRealRoutePath, hasOwnProperty, isObject, isEvaluable, transformAndInject, transform, trackContext, trackState, trackFormState, scanPermissionActionsInStoryboard, precookFunction, cook, collectContextUsage, deferResolveContextConcurrently, resolveContextConcurrently, syncResolveContextConcurrently, trackUsedState, trackUsedContext, shouldAllowRecursiveEvaluations, preevaluate, inject, scanPermissionActionsInAny, matchPath, deepFreeze, createProviderClass, removeDeadConditionsInTpl, getTemplateDepsOfStoryboard, getDllAndDepsOfStoryboard, asyncProcessStoryboard, getDllAndDepsByResource, scanRouteAliasInStoryboard, prefetchScript, scanBricksInBrickConf, scanProcessorsInAny, loadScript, scanAppGetMenuInAny, asyncProcessBrick, scanInstalledAppsInStoryboard, removeDeadConditions, restoreDynamicTemplates, scanStoryboard, mapCustomApisToNameAndNamespace } from '@next-core/brick-utils';
8
8
  import _, { set, get, difference, identity, uniqueId, cloneDeep, clamp, isNil, isEmpty, sortBy, orderBy, merge, isObject as isObject$1, uniq, pick, omit, findLastIndex, noop, isString as isString$1 } from 'lodash';
9
9
  import { http, HttpResponseError, HttpAbortError, HttpFetchError } from '@next-core/brick-http';
10
10
  import moment from 'moment';
@@ -841,6 +841,7 @@ function doTransform(data, to, options) {
841
841
  data
842
842
  };
843
843
  if (options !== null && options !== void 0 && options.tplContextId) runtimeContext.tplContextId = options.tplContextId;
844
+ if (options !== null && options !== void 0 && options.formContextId) runtimeContext.formContextId = options.formContextId;
844
845
  result = evaluate(to, runtimeContext, options === null || options === void 0 ? void 0 : options.evaluateOptions);
845
846
  dismissRecursiveMarkingInjected = shouldDismissRecursiveMarkingInjected(to);
846
847
  } else {
@@ -1731,6 +1732,7 @@ class StoryboardContextWrapper {
1731
1732
  _defineProperty$1(this, "data", new Map());
1732
1733
  _defineProperty$1(this, "tplContextId", void 0);
1733
1734
  _defineProperty$1(this, "formContextId", void 0);
1735
+ _defineProperty$1(this, "pendingStack", []);
1734
1736
  this.tplContextId = tplContextId;
1735
1737
  this.formContextId = formContextId;
1736
1738
  }
@@ -1832,15 +1834,57 @@ class StoryboardContextWrapper {
1832
1834
  detail: item.value
1833
1835
  }));
1834
1836
  }
1835
- define(contextConfs, coreContext, brick) {
1837
+ waitForUsedContext(data) {
1836
1838
  var _this = this;
1839
+ return _asyncToGenerator$3(function* () {
1840
+ if (_this.tplContextId || _this.formContextId) {
1841
+ return;
1842
+ }
1843
+ var usage = collectContextUsage(data, "CTX");
1844
+ if (usage.includesComputed) {
1845
+ for (var pending of _this.pendingStack) {
1846
+ yield pending.pendingResult;
1847
+ }
1848
+ } else if (usage.usedContexts.length > 0) {
1849
+ var _loop = function* (pendingContexts) {
1850
+ yield Promise.all(usage.usedContexts.map(ctx => pendingContexts.get(ctx)));
1851
+ };
1852
+ for (var {
1853
+ pendingContexts
1854
+ } of _this.pendingStack) {
1855
+ yield* _loop(pendingContexts);
1856
+ }
1857
+ }
1858
+ })();
1859
+ }
1860
+ waitForAllContext() {
1861
+ var _this2 = this;
1862
+ return _asyncToGenerator$3(function* () {
1863
+ if (_this2.tplContextId || _this2.formContextId) {
1864
+ return;
1865
+ }
1866
+ for (var pending of _this2.pendingStack) {
1867
+ yield pending.pendingResult;
1868
+ }
1869
+ })();
1870
+ }
1871
+ deferDefine(contextConfs, coreContext, brick) {
1872
+ var {
1873
+ mergedContext,
1874
+ keyword
1875
+ } = this.getResolveOptions(coreContext);
1876
+ var pending = deferResolveContextConcurrently(Array.isArray(contextConfs) ? contextConfs : [], contextConf => resolveStoryboardContext(contextConf, mergedContext, this, brick), keyword);
1877
+ this.pendingStack.push(pending);
1878
+ }
1879
+ define(contextConfs, coreContext, brick) {
1880
+ var _this3 = this;
1837
1881
  return _asyncToGenerator$3(function* () {
1838
1882
  if (Array.isArray(contextConfs)) {
1839
1883
  var {
1840
1884
  mergedContext,
1841
1885
  keyword
1842
- } = _this.getResolveOptions(coreContext);
1843
- yield resolveContextConcurrently(contextConfs, contextConf => resolveStoryboardContext(contextConf, mergedContext, _this, brick), keyword);
1886
+ } = _this3.getResolveOptions(coreContext);
1887
+ yield resolveContextConcurrently(contextConfs, contextConf => resolveStoryboardContext(contextConf, mergedContext, _this3, brick), keyword);
1844
1888
  }
1845
1889
  })();
1846
1890
  }
@@ -1892,6 +1936,7 @@ function resolveNormalStoryboardContext(_x5, _x6, _x7, _x8) {
1892
1936
  }
1893
1937
  function _resolveNormalStoryboardContext() {
1894
1938
  _resolveNormalStoryboardContext = _asyncToGenerator$3(function* (contextConf, mergedContext, storyboardContextWrapper, brick) {
1939
+ yield storyboardContextWrapper.waitForUsedContext(contextConf.if);
1895
1940
  if (!looseCheckIf(contextConf, mergedContext)) {
1896
1941
  return false;
1897
1942
  }
@@ -1901,6 +1946,7 @@ function _resolveNormalStoryboardContext() {
1901
1946
  var isLazyResolve = false;
1902
1947
  if (value === undefined) {
1903
1948
  if (contextConf.resolve) {
1949
+ yield storyboardContextWrapper.waitForUsedContext(contextConf.resolve.if);
1904
1950
  if (looseCheckIf(contextConf.resolve, mergedContext)) {
1905
1951
  load = /*#__PURE__*/function () {
1906
1952
  var _ref = _asyncToGenerator$3(function* (options) {
@@ -1924,6 +1970,7 @@ function _resolveNormalStoryboardContext() {
1924
1970
  }
1925
1971
  }
1926
1972
  if ((!load || isLazyResolve) && contextConf.value !== undefined) {
1973
+ yield storyboardContextWrapper.waitForUsedContext(contextConf.value);
1927
1974
  // If the context has no resolve, just use its `value`.
1928
1975
  // Or if the resolve is ignored or lazy, use its `value` as a fallback.
1929
1976
  value = computeRealValue(contextConf.value, mergedContext, true);
@@ -2069,7 +2116,7 @@ class CustomFormContext {
2069
2116
  _defineProperty$1(this, "formState", void 0);
2070
2117
  _defineProperty$1(this, "id", uniqueId("form-ctx-"));
2071
2118
  FormContextMap.set(this.id, this);
2072
- this.formState = new StoryboardContextWrapper("", this.id);
2119
+ this.formState = new StoryboardContextWrapper(undefined, this.id);
2073
2120
  }
2074
2121
  }
2075
2122
  function getCustomFormContext(formContextId) {
@@ -2820,8 +2867,8 @@ function _mergeMenu() {
2820
2867
  (function () {
2821
2868
  var menuI18nNamespace = getI18nNamespace("menu", "".concat(menu.menuId, "~").concat(menu.app[0].appId, "+").concat(menu.instanceId));
2822
2869
  // Support any language in `meta.i18n`.
2823
- Object.entries(menu.i18n).forEach(_ref3 => {
2824
- var [lang, resources] = _ref3;
2870
+ Object.entries(menu.i18n).forEach(_ref4 => {
2871
+ var [lang, resources] = _ref4;
2825
2872
  i18next.addResourceBundle(lang, menuI18nNamespace, resources);
2826
2873
  });
2827
2874
  menuWithI18n.set(menu, menuI18nNamespace);
@@ -2921,8 +2968,8 @@ function _processMenu() {
2921
2968
  }
2922
2969
  collectAppsRequireI18nFulfilled(items, context.app.id, appsRequireI18nFulfilled);
2923
2970
  yield kernel.fulfilStoryboardI18n([...appsRequireI18nFulfilled]);
2924
- var menuData = _objectSpread(_objectSpread({}, computeRealValueWithOverrideApp(restMenuData, rootAppId, context, kernel)), {}, {
2925
- items: computeMenuItemsWithOverrideApp(items, context, kernel)
2971
+ var menuData = _objectSpread(_objectSpread({}, yield computeRealValueWithOverrideApp(restMenuData, rootAppId, context, kernel)), {}, {
2972
+ items: yield computeMenuItemsWithOverrideApp(items, context, kernel)
2926
2973
  });
2927
2974
  return {
2928
2975
  title: yield processMenuTitle(menuData),
@@ -2970,17 +3017,22 @@ function collectAppsRequireI18nFulfilled(items, contextAppId, appIds) {
2970
3017
  collect(items);
2971
3018
  }
2972
3019
  function computeMenuItemsWithOverrideApp(items, context, kernel) {
2973
- return items.map(_ref2 => {
2974
- var {
2975
- children
2976
- } = _ref2,
2977
- rest = _objectWithoutProperties(_ref2, _excluded2$2);
2978
- return _objectSpread(_objectSpread({}, computeRealValueWithOverrideApp(rest, rest[symbolAppId], context, kernel)), {}, {
2979
- children: children && computeMenuItemsWithOverrideApp(children, context, kernel)
3020
+ return Promise.all(items.map( /*#__PURE__*/function () {
3021
+ var _ref3 = _asyncToGenerator$3(function* (_ref2) {
3022
+ var {
3023
+ children
3024
+ } = _ref2,
3025
+ rest = _objectWithoutProperties(_ref2, _excluded2$2);
3026
+ return _objectSpread(_objectSpread({}, yield computeRealValueWithOverrideApp(rest, rest[symbolAppId], context, kernel)), {}, {
3027
+ children: children && (yield computeMenuItemsWithOverrideApp(children, context, kernel))
3028
+ });
2980
3029
  });
2981
- });
3030
+ return function (_x20) {
3031
+ return _ref3.apply(this, arguments);
3032
+ };
3033
+ }()));
2982
3034
  }
2983
- function processMenuTitle(_x20) {
3035
+ function processMenuTitle(_x21) {
2984
3036
  return _processMenuTitle.apply(this, arguments);
2985
3037
  }
2986
3038
  function _processMenuTitle() {
@@ -3059,25 +3111,32 @@ function attemptToVisit(data, globals) {
3059
3111
  }
3060
3112
  return false;
3061
3113
  }
3062
- function computeRealValueWithOverrideApp(data, overrideAppId, context, kernel) {
3063
- var newContext = context;
3064
- if (overrideAppId !== context.app.id && attemptToVisit(data, ["APP", "I18N"])) {
3065
- if (window.STANDALONE_MICRO_APPS) {
3066
- newContext = _objectSpread(_objectSpread({}, context), {}, {
3067
- overrideApp: data[symbolOverrideApp],
3068
- appendI18nNamespace: data[symbolMenuI18nNamespace]
3069
- });
3070
- } else {
3071
- var storyboard = kernel.bootstrapData.storyboards.find(story => story.app.id === overrideAppId);
3072
- newContext = _objectSpread(_objectSpread({}, context), {}, {
3073
- overrideApp: storyboard === null || storyboard === void 0 ? void 0 : storyboard.app,
3074
- appendI18nNamespace: data[symbolMenuI18nNamespace]
3075
- });
3114
+ function computeRealValueWithOverrideApp(_x22, _x23, _x24, _x25) {
3115
+ return _computeRealValueWithOverrideApp.apply(this, arguments);
3116
+ }
3117
+ function _computeRealValueWithOverrideApp() {
3118
+ _computeRealValueWithOverrideApp = _asyncToGenerator$3(function* (data, overrideAppId, context, kernel) {
3119
+ var newContext = context;
3120
+ if (overrideAppId !== context.app.id && attemptToVisit(data, ["APP", "I18N"])) {
3121
+ if (window.STANDALONE_MICRO_APPS) {
3122
+ newContext = _objectSpread(_objectSpread({}, context), {}, {
3123
+ overrideApp: data[symbolOverrideApp],
3124
+ appendI18nNamespace: data[symbolMenuI18nNamespace]
3125
+ });
3126
+ } else {
3127
+ var storyboard = kernel.bootstrapData.storyboards.find(story => story.app.id === overrideAppId);
3128
+ newContext = _objectSpread(_objectSpread({}, context), {}, {
3129
+ overrideApp: storyboard === null || storyboard === void 0 ? void 0 : storyboard.app,
3130
+ appendI18nNamespace: data[symbolMenuI18nNamespace]
3131
+ });
3132
+ }
3076
3133
  }
3077
- }
3078
- return computeRealValue(data, newContext, true, {
3079
- ignoreSymbols: true
3134
+ yield kernel.router.waitForUsedContext(data);
3135
+ return computeRealValue(data, newContext, true, {
3136
+ ignoreSymbols: true
3137
+ });
3080
3138
  });
3139
+ return _computeRealValueWithOverrideApp.apply(this, arguments);
3081
3140
  }
3082
3141
 
3083
3142
  var lazyBrickRegistry = new Map();
@@ -7634,17 +7693,21 @@ function expandCustomTemplate(brickConf, proxyBrick, context) {
7634
7693
  }
7635
7694
  return lowLevelExpandCustomTemplate(template, brickConf, proxyBrick, context, tplContext);
7636
7695
  }
7637
- function asyncExpandCustomTemplate(_x, _x2, _x3) {
7696
+ function asyncExpandCustomTemplate(_x, _x2, _x3, _x4) {
7638
7697
  return _asyncExpandCustomTemplate.apply(this, arguments);
7639
7698
  }
7640
7699
  function _asyncExpandCustomTemplate() {
7641
- _asyncExpandCustomTemplate = _asyncToGenerator$3(function* (brickConf, proxyBrick, context) {
7700
+ _asyncExpandCustomTemplate = _asyncToGenerator$3(function* (brickConf, proxyBrick, context, locationContext) {
7642
7701
  var tplContext = new CustomTemplateContext(proxyBrick);
7643
7702
  var template = customTemplateRegistry.get(brickConf.brick);
7644
7703
  if (template.contracts) {
7645
7704
  collectWidgetContract(template.contracts);
7646
7705
  }
7647
7706
  if (Array.isArray(template.state)) {
7707
+ if (locationContext) {
7708
+ // Handle use cases of using `CTX.*` in template states.
7709
+ yield locationContext.storyboardContextWrapper.waitForUsedContext(template.state.map(state => [state.if, state.value, state.resolve]));
7710
+ }
7648
7711
  yield tplContext.state.define(template.state, context, proxyBrick);
7649
7712
  }
7650
7713
  return lowLevelExpandCustomTemplate(template, brickConf, proxyBrick, context, tplContext);
@@ -8991,50 +9054,85 @@ function isRouteConfOfRoutes(conf) {
8991
9054
  return conf.type === "routes";
8992
9055
  }
8993
9056
 
8994
- function getSubStoryboardByRoute(storyboard, matcher) {
8995
- function getSubRoutes(routes) {
8996
- return matcher(routes).map(getSubRoute);
8997
- }
8998
- function getSubRoute(route) {
8999
- if (route.type === "routes") {
9000
- return _objectSpread(_objectSpread({}, route), {}, {
9001
- routes: getSubRoutes(route.routes)
9057
+ function getSubStoryboardByRoute(_x, _x2) {
9058
+ return _getSubStoryboardByRoute.apply(this, arguments);
9059
+ }
9060
+ function _getSubStoryboardByRoute() {
9061
+ _getSubStoryboardByRoute = _asyncToGenerator$3(function* (storyboard, matcher) {
9062
+ function getSubRoutes(_x3) {
9063
+ return _getSubRoutes.apply(this, arguments);
9064
+ }
9065
+ function _getSubRoutes() {
9066
+ _getSubRoutes = _asyncToGenerator$3(function* (routes) {
9067
+ return Promise.all((yield matcher(routes)).map(getSubRoute));
9002
9068
  });
9069
+ return _getSubRoutes.apply(this, arguments);
9003
9070
  }
9004
- return _objectSpread(_objectSpread({}, route), {}, {
9005
- bricks: getSubBricks(route.bricks)
9006
- });
9007
- }
9008
- function getSubBricks(bricks) {
9009
- if (Array.isArray(bricks)) {
9010
- return bricks.map(brickConf => getSubBrick(brickConf));
9011
- }
9012
- return bricks;
9013
- }
9014
- function getSubBrick(brickConf) {
9015
- if (isObject(brickConf.slots)) {
9016
- return _objectSpread(_objectSpread({}, brickConf), {}, {
9017
- slots: Object.fromEntries(Object.entries(brickConf.slots).map(_ref => {
9018
- var [slotId, slotConf] = _ref;
9019
- if (slotConf.type === "routes") {
9020
- return [slotId, _objectSpread(_objectSpread({}, slotConf), {}, {
9021
- routes: getSubRoutes(slotConf.routes)
9022
- })];
9023
- } /* istanbul ignore else: should never reach */else if (slotConf.type === "bricks") {
9024
- return [slotId, _objectSpread(_objectSpread({}, slotConf), {}, {
9025
- bricks: getSubBricks(slotConf.bricks)
9026
- })];
9027
- }
9028
- /* istanbul ignore next: should never reach */
9029
- return [slotId, slotConf];
9030
- }))
9071
+ function getSubRoute(_x4) {
9072
+ return _getSubRoute.apply(this, arguments);
9073
+ }
9074
+ function _getSubRoute() {
9075
+ _getSubRoute = _asyncToGenerator$3(function* (route) {
9076
+ if (route.type === "routes") {
9077
+ return _objectSpread(_objectSpread({}, route), {}, {
9078
+ routes: yield getSubRoutes(route.routes)
9079
+ });
9080
+ }
9081
+ return _objectSpread(_objectSpread({}, route), {}, {
9082
+ bricks: yield getSubBricks(route.bricks)
9083
+ });
9031
9084
  });
9085
+ return _getSubRoute.apply(this, arguments);
9032
9086
  }
9033
- return brickConf;
9034
- }
9035
- return _objectSpread(_objectSpread({}, storyboard), {}, {
9036
- routes: getSubRoutes(storyboard.routes)
9087
+ function getSubBricks(_x5) {
9088
+ return _getSubBricks.apply(this, arguments);
9089
+ }
9090
+ function _getSubBricks() {
9091
+ _getSubBricks = _asyncToGenerator$3(function* (bricks) {
9092
+ if (Array.isArray(bricks)) {
9093
+ return Promise.all(bricks.map(brickConf => getSubBrick(brickConf)));
9094
+ }
9095
+ return bricks;
9096
+ });
9097
+ return _getSubBricks.apply(this, arguments);
9098
+ }
9099
+ function getSubBrick(_x6) {
9100
+ return _getSubBrick.apply(this, arguments);
9101
+ }
9102
+ function _getSubBrick() {
9103
+ _getSubBrick = _asyncToGenerator$3(function* (brickConf) {
9104
+ if (isObject(brickConf.slots)) {
9105
+ return _objectSpread(_objectSpread({}, brickConf), {}, {
9106
+ slots: Object.fromEntries(yield Promise.all(Object.entries(brickConf.slots).map( /*#__PURE__*/function () {
9107
+ var _ref2 = _asyncToGenerator$3(function* (_ref) {
9108
+ var [slotId, slotConf] = _ref;
9109
+ if (slotConf.type === "routes") {
9110
+ return [slotId, _objectSpread(_objectSpread({}, slotConf), {}, {
9111
+ routes: yield getSubRoutes(slotConf.routes)
9112
+ })];
9113
+ } /* istanbul ignore else: should never reach */else if (slotConf.type === "bricks") {
9114
+ return [slotId, _objectSpread(_objectSpread({}, slotConf), {}, {
9115
+ bricks: yield getSubBricks(slotConf.bricks)
9116
+ })];
9117
+ }
9118
+ /* istanbul ignore next: should never reach */
9119
+ return [slotId, slotConf];
9120
+ });
9121
+ return function (_x7) {
9122
+ return _ref2.apply(this, arguments);
9123
+ };
9124
+ }())))
9125
+ });
9126
+ }
9127
+ return brickConf;
9128
+ });
9129
+ return _getSubBrick.apply(this, arguments);
9130
+ }
9131
+ return _objectSpread(_objectSpread({}, storyboard), {}, {
9132
+ routes: yield getSubRoutes(storyboard.routes)
9133
+ });
9037
9134
  });
9135
+ return _getSubStoryboardByRoute.apply(this, arguments);
9038
9136
  }
9039
9137
 
9040
9138
  function listenOnTrackingContext(brick, trackingContextList, context) {
@@ -9085,14 +9183,18 @@ function ExpandCustomForm(formData, brickConf, isPreview, context) {
9085
9183
  }
9086
9184
  return getFinalStoryBoard(formData, brickConf, isPreview, formContext);
9087
9185
  }
9088
- function AsyncExpandCustomForm(_x, _x2, _x3, _x4) {
9186
+ function AsyncExpandCustomForm(_x, _x2, _x3, _x4, _x5) {
9089
9187
  return _AsyncExpandCustomForm.apply(this, arguments);
9090
9188
  }
9091
9189
  function _AsyncExpandCustomForm() {
9092
- _AsyncExpandCustomForm = _asyncToGenerator$3(function* (formData, brickConf, isPreview, context) {
9190
+ _AsyncExpandCustomForm = _asyncToGenerator$3(function* (formData, brickConf, isPreview, context, locationContext) {
9093
9191
  var formContext = new CustomFormContext();
9094
9192
  formData = initFormContext(formData, brickConf, isPreview);
9095
9193
  if (Array.isArray(formData.context)) {
9194
+ if (locationContext) {
9195
+ // Handle use cases of using `CTX.*` in template states.
9196
+ yield locationContext.storyboardContextWrapper.waitForUsedContext(formData.context.map(state => [state.if, state.value, state.resolve]));
9197
+ }
9096
9198
  yield formContext.formState.define(formData.context, _objectSpread(_objectSpread({}, context), {}, {
9097
9199
  formContextId: formContext.id
9098
9200
  }), {});
@@ -9478,7 +9580,7 @@ class LocationContext {
9478
9580
  _defineProperty$1(this, "observersList", []);
9479
9581
  this.kernel = kernel;
9480
9582
  this.location = location;
9481
- this.resolver = new Resolver(kernel);
9583
+ this.resolver = new Resolver(kernel, this);
9482
9584
  this.query = new URLSearchParams(location.search);
9483
9585
  this.messageDispatcher = getMessageDispatcher();
9484
9586
  }
@@ -9516,60 +9618,79 @@ class LocationContext {
9516
9618
  match: this.currentMatch
9517
9619
  });
9518
9620
  }
9621
+ deferComputeRealValue() {
9622
+ var _arguments = arguments,
9623
+ _this = this;
9624
+ return _asyncToGenerator$3(function* () {
9625
+ yield _this.storyboardContextWrapper.waitForUsedContext(_arguments.length <= 0 ? undefined : _arguments[0]);
9626
+ return computeRealValue(..._arguments);
9627
+ })();
9628
+ }
9519
9629
  matchRoutes(routes, app) {
9520
- var _this = this;
9521
- var _loop = function (route) {
9522
- var computedPath = computeRealRoutePath(route.path, app);
9523
- if ([].concat(computedPath).includes(undefined)) {
9524
- // eslint-disable-next-line no-console
9525
- console.error("Invalid route with invalid path:", route);
9526
- return {
9527
- v: "missed"
9528
- };
9529
- }
9530
- var match = matchPath(_this.location.pathname, {
9531
- path: computedPath,
9532
- exact: route.exact,
9533
- checkIf: context => looseCheckIf(route, context),
9534
- getContext: match => _this.getContext({
9535
- match
9536
- })
9537
- });
9538
- if (match !== null) {
9539
- if (app.noAuthGuard || route.public || isLoggedIn()) {
9540
- _this.currentMatch = match;
9630
+ var _this2 = this;
9631
+ return _asyncToGenerator$3(function* () {
9632
+ var _loop = function* (route) {
9633
+ var computedPath = computeRealRoutePath(route.path, app);
9634
+ if ([].concat(computedPath).includes(undefined)) {
9635
+ // eslint-disable-next-line no-console
9636
+ console.error("Invalid route with invalid path:", route);
9541
9637
  return {
9542
- v: {
9543
- match,
9544
- route
9545
- }
9638
+ v: "missed"
9546
9639
  };
9547
9640
  }
9548
- return {
9549
- v: "unauthenticated"
9550
- };
9641
+ yield _this2.storyboardContextWrapper.waitForUsedContext(route.if);
9642
+ var match = matchPath(_this2.location.pathname, {
9643
+ path: computedPath,
9644
+ exact: route.exact,
9645
+ checkIf: context => looseCheckIf(route, context),
9646
+ getContext: match => _this2.getContext({
9647
+ match
9648
+ })
9649
+ });
9650
+ if (match !== null) {
9651
+ if (app.noAuthGuard || route.public || isLoggedIn()) {
9652
+ _this2.currentMatch = match;
9653
+ return {
9654
+ v: {
9655
+ match,
9656
+ route
9657
+ }
9658
+ };
9659
+ }
9660
+ return {
9661
+ v: "unauthenticated"
9662
+ };
9663
+ }
9664
+ };
9665
+ for (var route of routes) {
9666
+ var _ret = yield* _loop(route);
9667
+ if (typeof _ret === "object") return _ret.v;
9551
9668
  }
9552
- };
9553
- for (var route of routes) {
9554
- var _ret = _loop(route);
9555
- if (typeof _ret === "object") return _ret.v;
9556
- }
9557
- return "missed";
9669
+ return "missed";
9670
+ })();
9558
9671
  }
9559
9672
  matchStoryboard(storyboards) {
9560
9673
  return matchStoryboard(storyboards, this.location.pathname);
9561
9674
  }
9562
9675
  getSubStoryboardByRoute(storyboard) {
9563
- var matcher = routes => {
9564
- var matched = this.matchRoutes(routes, storyboard.app);
9565
- return isObject(matched) ? [matched.route] : [];
9566
- };
9567
- return getSubStoryboardByRoute(storyboard, matcher);
9676
+ var _this3 = this;
9677
+ return _asyncToGenerator$3(function* () {
9678
+ var matcher = /*#__PURE__*/function () {
9679
+ var _ref2 = _asyncToGenerator$3(function* (routes) {
9680
+ var matched = yield _this3.matchRoutes(routes, storyboard.app);
9681
+ return isObject(matched) ? [matched.route] : [];
9682
+ });
9683
+ return function matcher(_x) {
9684
+ return _ref2.apply(this, arguments);
9685
+ };
9686
+ }();
9687
+ return getSubStoryboardByRoute(storyboard, matcher);
9688
+ })();
9568
9689
  }
9569
9690
  mountRoutes(routes, slotId, mountRoutesResult) {
9570
- var _this2 = this;
9691
+ var _this4 = this;
9571
9692
  return _asyncToGenerator$3(function* () {
9572
- var matched = _this2.matchRoutes(routes, _this2.kernel.nextApp);
9693
+ var matched = yield _this4.matchRoutes(routes, _this4.kernel.nextApp);
9573
9694
  var redirect;
9574
9695
  var redirectConf = {};
9575
9696
  var context;
@@ -9583,19 +9704,26 @@ class LocationContext {
9583
9704
  default:
9584
9705
  mountRoutesResult.route = route = matched.route;
9585
9706
  if (route.segues) {
9586
- Object.assign(_this2.segues, route.segues);
9707
+ Object.assign(_this4.segues, route.segues);
9587
9708
  }
9588
9709
  if (route.hybrid) {
9589
9710
  mountRoutesResult.flags.hybrid = true;
9590
9711
  }
9591
- context = _this2.getContext({
9712
+ context = _this4.getContext({
9592
9713
  match: matched.match
9593
9714
  });
9594
- _this2.resolver.defineResolves(route.defineResolves, context);
9595
- yield _this2.mountProviders(route.providers, matched.match, slotId, mountRoutesResult);
9596
- yield _this2.storyboardContextWrapper.define(route.context, context);
9597
- yield _this2.preCheckPermissions(route, context);
9598
- redirect = computeRealValue(route.redirect, context, true);
9715
+ yield _this4.storyboardContextWrapper.waitForUsedContext(route.defineResolves);
9716
+ _this4.resolver.defineResolves(route.defineResolves, context);
9717
+ yield _this4.mountProviders(route.providers, matched.match, slotId, mountRoutesResult);
9718
+
9719
+ // istanbul ignore else
9720
+ if (_this4.kernel.getFeatureFlags()["next-core-deferred-context"]) {
9721
+ _this4.storyboardContextWrapper.deferDefine(route.context, context);
9722
+ } else {
9723
+ yield _this4.storyboardContextWrapper.define(route.context, context);
9724
+ }
9725
+ yield _this4.preCheckPermissions(route, context);
9726
+ redirect = yield _this4.deferComputeRealValue(route.redirect, context, true);
9599
9727
  if (redirect) {
9600
9728
  if (typeof redirect === "string") {
9601
9729
  // Directly redirect.
@@ -9605,7 +9733,7 @@ class LocationContext {
9605
9733
  break;
9606
9734
  } else {
9607
9735
  // Resolvable redirect.
9608
- yield _this2.resolver.resolveOne("reference", redirect, redirectConf);
9736
+ yield _this4.resolver.resolveOne("reference", redirect, redirectConf);
9609
9737
  if (redirectConf.redirect) {
9610
9738
  mountRoutesResult.flags.redirect = {
9611
9739
  path: redirectConf.redirect
@@ -9614,20 +9742,20 @@ class LocationContext {
9614
9742
  }
9615
9743
  }
9616
9744
  }
9617
- yield _this2.mountMenu(route.menu, matched.match, mountRoutesResult);
9745
+ yield _this4.mountMenu(route.menu, matched.match, mountRoutesResult);
9618
9746
  if (route.documentId) {
9619
9747
  mountRoutesResult.appBar.documentId = route.documentId;
9620
9748
  }
9621
9749
  if (isRouteConfOfRoutes(route) && Array.isArray(route.routes)) {
9622
- yield _this2.preFetchMenu(route.context);
9623
- yield _this2.mountRoutes(route.routes, slotId, mountRoutesResult);
9750
+ yield _this4.preFetchMenu(route.context);
9751
+ yield _this4.mountRoutes(route.routes, slotId, mountRoutesResult);
9624
9752
  } else if (isRouteConfOfBricks(route) && Array.isArray(route.bricks)) {
9625
- yield _this2.preFetchMenu(route);
9626
- yield _this2.mountBricks(route.bricks, matched.match, slotId, mountRoutesResult);
9753
+ yield _this4.preFetchMenu(route);
9754
+ yield _this4.mountBricks(route.bricks, matched.match, slotId, mountRoutesResult);
9627
9755
 
9628
9756
  // analytics data (page_view event)
9629
9757
  if (route.analyticsData) {
9630
- mountRoutesResult.analyticsData = computeRealValue(route.analyticsData, context, true);
9758
+ mountRoutesResult.analyticsData = yield _this4.deferComputeRealValue(route.analyticsData, context, true);
9631
9759
  }
9632
9760
  }
9633
9761
  }
@@ -9635,7 +9763,7 @@ class LocationContext {
9635
9763
  })();
9636
9764
  }
9637
9765
  mountMenu(menuConf, match, mountRoutesResult) {
9638
- var _this3 = this;
9766
+ var _this5 = this;
9639
9767
  return _asyncToGenerator$3(function* () {
9640
9768
  if (menuConf === false) {
9641
9769
  // `route.menu` 设置为 `false` 表示不显示顶栏和侧栏。
@@ -9647,7 +9775,7 @@ class LocationContext {
9647
9775
  if (!menuConf) {
9648
9776
  return;
9649
9777
  }
9650
- var context = _this3.getContext({
9778
+ var context = _this5.getContext({
9651
9779
  match
9652
9780
  });
9653
9781
  if (menuConf.type === "brick") {
@@ -9657,6 +9785,7 @@ class LocationContext {
9657
9785
  // 那么可以将菜单配置指定为一个构件,这个构件会被装载到背景容器中(不会在界面中显示),
9658
9786
  // 应该在这个构件的 `connectedCallback` 中执行相关菜单设置,
9659
9787
  // 例如 `getRuntime().menuBar.setAppMenu(...)`。
9788
+ yield _this5.storyboardContextWrapper.waitForUsedContext(menuConf.properties);
9660
9789
  var brick = {
9661
9790
  type: menuConf.brick,
9662
9791
  properties: computeRealProperties(menuConf.properties, context, menuConf.injectDeep !== false),
@@ -9664,16 +9793,16 @@ class LocationContext {
9664
9793
  context,
9665
9794
  children: []
9666
9795
  };
9667
- _this3.registerHandlersFromLifeCycle(menuConf.lifeCycle, brick, match);
9796
+ _this5.registerHandlersFromLifeCycle(menuConf.lifeCycle, brick, match);
9668
9797
 
9669
9798
  // Then, resolve the brick.
9670
- yield _this3.resolver.resolve(menuConf, brick, context);
9799
+ yield _this5.resolver.resolve(menuConf, brick, context);
9671
9800
  mountRoutesResult.menuInBg.push(brick);
9672
9801
  return;
9673
9802
  }
9674
9803
  var injectDeep = menuConf.injectDeep;
9675
9804
  if (menuConf.type === "resolve") {
9676
- yield _this3.resolver.resolveOne("reference", _objectSpread({
9805
+ yield _this5.resolver.resolveOne("reference", _objectSpread({
9677
9806
  transformMapArray: false
9678
9807
  }, menuConf.resolve), menuConf, null, context);
9679
9808
  injectDeep = false;
@@ -9681,7 +9810,7 @@ class LocationContext {
9681
9810
 
9682
9811
  // 静态菜单配置,仅在有值时才设置,这样可以让菜单设置也具有按路由层级覆盖的能力。
9683
9812
  var otherMenuConf = omit(menuConf, ["injectDeep", "type"]);
9684
- var injectedMenuConf = injectDeep !== false ? computeRealValue(otherMenuConf, context, true) : otherMenuConf;
9813
+ var injectedMenuConf = injectDeep !== false ? yield _this5.deferComputeRealValue(otherMenuConf, context, true) : otherMenuConf;
9685
9814
  var {
9686
9815
  sidebarMenu,
9687
9816
  pageTitle,
@@ -9713,11 +9842,11 @@ class LocationContext {
9713
9842
  })();
9714
9843
  }
9715
9844
  mountProviders(providers, match, slotId, mountRoutesResult) {
9716
- var _this4 = this;
9845
+ var _this6 = this;
9717
9846
  return _asyncToGenerator$3(function* () {
9718
9847
  if (Array.isArray(providers)) {
9719
9848
  for (var providerConf of providers) {
9720
- yield _this4.mountBrick(_objectSpread(_objectSpread({}, typeof providerConf === "string" ? {
9849
+ yield _this6.mountBrick(_objectSpread(_objectSpread({}, typeof providerConf === "string" ? {
9721
9850
  brick: providerConf
9722
9851
  } : providerConf), {}, {
9723
9852
  bg: true,
@@ -9728,11 +9857,11 @@ class LocationContext {
9728
9857
  })();
9729
9858
  }
9730
9859
  mountBricks(bricks, match, slotId, mountRoutesResult, tplStack) {
9731
- var _this5 = this;
9860
+ var _this7 = this;
9732
9861
  return _asyncToGenerator$3(function* () {
9733
9862
  for (var brickConf of bricks) {
9734
9863
  try {
9735
- yield _this5.mountBrick(brickConf, match, slotId, mountRoutesResult, tplStack && new Map(tplStack));
9864
+ yield _this7.mountBrick(brickConf, match, slotId, mountRoutesResult, tplStack && new Map(tplStack));
9736
9865
  } catch (error) {
9737
9866
  if (error instanceof ResolveRequestError) {
9738
9867
  var errorMessage = httpErrorToString(error.rawError);
@@ -9760,57 +9889,59 @@ class LocationContext {
9760
9889
  })();
9761
9890
  }
9762
9891
  checkResolvableIf(ifContainer, context) {
9763
- var _this6 = this;
9892
+ var _this8 = this;
9764
9893
  return _asyncToGenerator$3(function* () {
9894
+ yield _this8.storyboardContextWrapper.waitForUsedContext(ifContainer.if);
9765
9895
  if (isObject(ifContainer.if)) {
9766
9896
  var ifChecked = computeRealValue(ifContainer.if, context, true);
9767
9897
  var ifConf = {};
9768
- yield _this6.resolver.resolveOne("reference", ifChecked, ifConf);
9898
+ yield _this8.resolver.resolveOne("reference", ifChecked, ifConf);
9769
9899
  return !hasOwnProperty(ifConf, "if") || !!ifConf.if;
9770
9900
  }
9771
9901
  return looseCheckIf(ifContainer, context);
9772
9902
  })();
9773
9903
  }
9774
9904
  preCheckPermissions(container, context) {
9905
+ var _this9 = this;
9775
9906
  return _asyncToGenerator$3(function* () {
9776
9907
  if (isLoggedIn() && !getAuth().isAdmin && container.permissionsPreCheck && Array.isArray(container.permissionsPreCheck)) {
9777
- var usedActions = computeRealValue(container.permissionsPreCheck, context, true);
9908
+ var usedActions = yield _this9.deferComputeRealValue(container.permissionsPreCheck, context, true);
9778
9909
  yield validatePermissions(usedActions);
9779
9910
  }
9780
9911
  })();
9781
9912
  }
9782
9913
  mountBrick(brickConf, match, slotId, mountRoutesResult) {
9783
- var _arguments = arguments,
9784
- _this7 = this;
9914
+ var _arguments2 = arguments,
9915
+ _this10 = this;
9785
9916
  return _asyncToGenerator$3(function* () {
9786
- var _this7$kernel$nextApp, _brickConf$lifeCycle, _brick$lifeCycle;
9787
- var tplStack = _arguments.length > 4 && _arguments[4] !== undefined ? _arguments[4] : new Map();
9917
+ var _this10$kernel$nextAp, _brickConf$lifeCycle, _brick$lifeCycle;
9918
+ var tplStack = _arguments2.length > 4 && _arguments2[4] !== undefined ? _arguments2[4] : new Map();
9788
9919
  var tplContextId = brickConf[symbolForTplContextId];
9789
9920
  var formContextId = brickConf[symbolForFormContextId];
9790
- var context = _this7.getContext({
9921
+ var context = _this10.getContext({
9791
9922
  match,
9792
9923
  tplContextId,
9793
9924
  formContextId
9794
9925
  });
9795
9926
 
9796
9927
  // First, check whether the brick should be rendered.
9797
- if (!(yield _this7.checkResolvableIf(brickConf, context))) {
9928
+ if (!(yield _this10.checkResolvableIf(brickConf, context))) {
9798
9929
  return;
9799
9930
  }
9800
9931
 
9801
9932
  // Then, resolve the template to a brick.
9802
9933
  if (brickConf.template) {
9803
- yield _this7.resolver.resolve(brickConf, null, context);
9934
+ yield _this10.resolver.resolve(brickConf, null, context);
9804
9935
  }
9805
9936
 
9806
9937
  // Check `if` again for dynamic loaded templates.
9807
- if (!(yield _this7.checkResolvableIf(brickConf, context))) {
9938
+ if (!(yield _this10.checkResolvableIf(brickConf, context))) {
9808
9939
  return;
9809
9940
  }
9810
9941
 
9811
9942
  // If it's a custom template, `tplTagName` is the tag name of the template.
9812
9943
  // Otherwise, `tplTagName` is false.
9813
- var tplTagName = getTagNameOfCustomTemplate(brickConf.brick, (_this7$kernel$nextApp = _this7.kernel.nextApp) === null || _this7$kernel$nextApp === void 0 ? void 0 : _this7$kernel$nextApp.id);
9944
+ var tplTagName = getTagNameOfCustomTemplate(brickConf.brick, (_this10$kernel$nextAp = _this10.kernel.nextApp) === null || _this10$kernel$nextAp === void 0 ? void 0 : _this10$kernel$nextAp.id);
9814
9945
  if (tplTagName) {
9815
9946
  var _tplStack$get;
9816
9947
  var tplCount = (_tplStack$get = tplStack.get(tplTagName)) !== null && _tplStack$get !== void 0 ? _tplStack$get : 0;
@@ -9823,9 +9954,16 @@ class LocationContext {
9823
9954
  brickConf.properties.formData = JSON.stringify(brickConf.properties.formData);
9824
9955
  }
9825
9956
  var brick = {};
9826
- yield _this7.storyboardContextWrapper.define(brickConf.context, context, brick);
9827
- yield _this7.preCheckPermissions(brickConf, context);
9957
+
9958
+ // istanbul ignore else
9959
+ if (_this10.kernel.getFeatureFlags()["next-core-deferred-context"]) {
9960
+ _this10.storyboardContextWrapper.deferDefine(brickConf.context, context, brick);
9961
+ } else {
9962
+ yield _this10.storyboardContextWrapper.define(brickConf.context, context, brick);
9963
+ }
9964
+ yield _this10.preCheckPermissions(brickConf, context);
9828
9965
  var trackingContextList = [];
9966
+ yield _this10.storyboardContextWrapper.waitForUsedContext(brickConf.properties);
9829
9967
  Object.assign(brick, _objectSpread({
9830
9968
  type: tplTagName || brickConf.brick,
9831
9969
  properties: computeRealProperties(brickConf.properties, context, brickConf.injectDeep !== false, trackingContextList),
@@ -9843,8 +9981,8 @@ class LocationContext {
9843
9981
  }
9844
9982
  } : {}));
9845
9983
  if (brickConf[symbolForComputedPropsFromProxy]) {
9846
- Object.entries(brickConf[symbolForComputedPropsFromProxy]).forEach(_ref2 => {
9847
- var [propName, propValue] = _ref2;
9984
+ Object.entries(brickConf[symbolForComputedPropsFromProxy]).forEach(_ref3 => {
9985
+ var [propName, propValue] = _ref3;
9848
9986
  set(brick.properties, propName, propValue);
9849
9987
  });
9850
9988
  }
@@ -9852,36 +9990,36 @@ class LocationContext {
9852
9990
  if (brick.refForProxy) {
9853
9991
  brick.refForProxy.brick = brick;
9854
9992
  }
9855
- _this7.registerHandlersFromLifeCycle(brickConf.lifeCycle, brick, match, tplContextId);
9993
+ _this10.registerHandlersFromLifeCycle(brickConf.lifeCycle, brick, match, tplContextId);
9856
9994
  if ((_brick$lifeCycle = brick.lifeCycle) !== null && _brick$lifeCycle !== void 0 && _brick$lifeCycle.onScrollIntoView) {
9857
- _this7.brickBindObserver(brick);
9995
+ _this10.brickBindObserver(brick);
9858
9996
  }
9859
9997
 
9860
9998
  // Then, resolve the brick.
9861
- yield _this7.resolver.resolve(brickConf, brick, context);
9999
+ yield _this10.resolver.resolve(brickConf, brick, context);
9862
10000
  var expandedBrickConf = brickConf;
9863
10001
  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);
9864
- if (tplTagName && (!isBaseLayout || _this7.kernel.getFeatureFlags()["support-ui-8.0-base-layout"] && isBaseLayout)) {
10002
+ if (tplTagName && (!isBaseLayout || _this10.kernel.getFeatureFlags()["support-ui-8.0-base-layout"] && isBaseLayout)) {
9865
10003
  var _customTemplateRegist;
9866
- yield _this7.preFetchMenu((_customTemplateRegist = customTemplateRegistry.get(tplTagName)) === null || _customTemplateRegist === void 0 ? void 0 : _customTemplateRegist.bricks);
10004
+ yield _this10.preFetchMenu((_customTemplateRegist = customTemplateRegistry.get(tplTagName)) === null || _customTemplateRegist === void 0 ? void 0 : _customTemplateRegist.bricks);
9867
10005
  expandedBrickConf = yield asyncExpandCustomTemplate(_objectSpread(_objectSpread({}, brickConf), {}, {
9868
10006
  brick: tplTagName,
9869
10007
  // Properties are computed for custom templates.
9870
10008
  properties: brick.properties
9871
- }), brick, context);
10009
+ }), brick, context, _this10);
9872
10010
 
9873
10011
  // Try to load deps for dynamic added bricks.
9874
- yield _this7.kernel.loadDynamicBricksInBrickConf(expandedBrickConf);
10012
+ yield _this10.kernel.loadDynamicBricksInBrickConf(expandedBrickConf);
9875
10013
  }
9876
10014
  if (brick.type === formRenderer) {
9877
10015
  var formData = typeof brick.properties.formData === "string" ? JSON.parse(brick.properties.formData) : brick.properties.formData;
9878
- expandedBrickConf = yield AsyncExpandCustomForm(formData, brickConf, brick.properties.isPreview, context);
9879
- yield _this7.kernel.loadDynamicBricksInBrickConf(expandedBrickConf);
10016
+ expandedBrickConf = yield AsyncExpandCustomForm(formData, brickConf, brick.properties.isPreview, context, _this10);
10017
+ yield _this10.kernel.loadDynamicBricksInBrickConf(expandedBrickConf);
9880
10018
  }
9881
10019
  if (expandedBrickConf.exports) {
9882
10020
  for (var [prop, ctxName] of Object.entries(expandedBrickConf.exports)) {
9883
10021
  if (typeof ctxName === "string" && ctxName.startsWith("CTX.")) {
9884
- _this7.storyboardContextWrapper.set(ctxName.substring(4), {
10022
+ _this10.storyboardContextWrapper.set(ctxName.substring(4), {
9885
10023
  type: "brick-property",
9886
10024
  brick,
9887
10025
  prop
@@ -9892,8 +10030,8 @@ class LocationContext {
9892
10030
  if (expandedBrickConf.bg) {
9893
10031
  // A bg brick has no slotId.
9894
10032
  brick.slotId = undefined;
9895
- yield _this7.kernel.loadDynamicBricks([brick.type]);
9896
- appendBrick(brick, _this7.kernel.mountPoints.bg);
10033
+ yield _this10.kernel.loadDynamicBricks([brick.type]);
10034
+ appendBrick(brick, _this10.kernel.mountPoints.bg);
9897
10035
  } else {
9898
10036
  if (expandedBrickConf.portal) {
9899
10037
  // A portal brick has no slotId.
@@ -9908,9 +10046,9 @@ class LocationContext {
9908
10046
  main: brick.children
9909
10047
  });
9910
10048
  if (slotConf.type === "bricks") {
9911
- yield _this7.mountBricks(slotConf.bricks, match, _slotId, slottedMountRoutesResult, tplStack);
10049
+ yield _this10.mountBricks(slotConf.bricks, match, _slotId, slottedMountRoutesResult, tplStack);
9912
10050
  } else if (slotConf.type === "routes") {
9913
- yield _this7.mountRoutes(slotConf.routes, _slotId, slottedMountRoutesResult);
10051
+ yield _this10.mountRoutes(slotConf.routes, _slotId, slottedMountRoutesResult);
9914
10052
  }
9915
10053
  }
9916
10054
  }
@@ -10086,11 +10224,11 @@ class LocationContext {
10086
10224
  }
10087
10225
  }
10088
10226
  preFetchMenu(data) {
10089
- var _this8 = this;
10227
+ var _this11 = this;
10090
10228
  return _asyncToGenerator$3(function* () {
10091
10229
  var useMenus = scanAppGetMenuInAny(data);
10092
10230
  if (useMenus.length) {
10093
- yield preConstructMenus(useMenus, _this8.getCurrentContext(), _this8.kernel);
10231
+ yield preConstructMenus(useMenus, _this11.getCurrentContext(), _this11.kernel);
10094
10232
  }
10095
10233
  })();
10096
10234
  }
@@ -10277,12 +10415,13 @@ function makeProviderRefreshable(providerBrick) {
10277
10415
  }
10278
10416
 
10279
10417
  class Resolver {
10280
- constructor(kernel) {
10418
+ constructor(kernel, locationContext) {
10281
10419
  _defineProperty$1(this, "cache", new Map());
10282
10420
  _defineProperty$1(this, "refreshQueue", new Map());
10283
10421
  _defineProperty$1(this, "definedResolves", new Map());
10284
10422
  _defineProperty$1(this, "active", true);
10285
10423
  this.kernel = kernel;
10424
+ this.locationContext = locationContext;
10286
10425
  }
10287
10426
  resetRefreshQueue() {
10288
10427
  if (this.refreshQueue.size > 0) {
@@ -10306,9 +10445,15 @@ class Resolver {
10306
10445
  var _this = this;
10307
10446
  return _asyncToGenerator$3(function* () {
10308
10447
  var _brickConf$lifeCycle$, _brickConf$lifeCycle;
10309
- var useResolves = ((_brickConf$lifeCycle$ = (_brickConf$lifeCycle = brickConf.lifeCycle) === null || _brickConf$lifeCycle === void 0 ? void 0 : _brickConf$lifeCycle.useResolves) !== null && _brickConf$lifeCycle$ !== void 0 ? _brickConf$lifeCycle$ : []).filter(r => {
10310
- return looseCheckIf(r, context);
10311
- });
10448
+ var useResolves = (yield Promise.all(((_brickConf$lifeCycle$ = (_brickConf$lifeCycle = brickConf.lifeCycle) === null || _brickConf$lifeCycle === void 0 ? void 0 : _brickConf$lifeCycle.useResolves) !== null && _brickConf$lifeCycle$ !== void 0 ? _brickConf$lifeCycle$ : []).map( /*#__PURE__*/function () {
10449
+ var _ref = _asyncToGenerator$3(function* (r) {
10450
+ yield _this.locationContext.storyboardContextWrapper.waitForUsedContext(r.if);
10451
+ return r;
10452
+ });
10453
+ return function (_x) {
10454
+ return _ref.apply(this, arguments);
10455
+ };
10456
+ }()))).filter(r => looseCheckIf(r, context));
10312
10457
  yield Promise.all(useResolves.map(resolveConf => _this.resolveOne("brick", resolveConf, brickConf, brick, context)));
10313
10458
  if (brickConf.template) {
10314
10459
  brickConf.$$resolved = true;
@@ -10392,7 +10537,7 @@ class Resolver {
10392
10537
  }
10393
10538
  }
10394
10539
  var actualArgs = args ? ref ? args // `args` are already computed for `defineResolves`
10395
- : context ? computeRealValue(args, context, true) : args : providerBrick.args || [];
10540
+ : context ? yield _this2.locationContext.deferComputeRealValue(args, context, true) : args : providerBrick.args || [];
10396
10541
  var cacheKey;
10397
10542
  try {
10398
10543
  // `actualArgs` may contain circular references, which makes
@@ -10455,6 +10600,7 @@ class Resolver {
10455
10600
  yield fetchData();
10456
10601
  } catch (error) {
10457
10602
  if (isHandleRejectByTransform(onReject)) {
10603
+ yield _this2.locationContext.storyboardContextWrapper.waitForUsedContext(onReject.transform);
10458
10604
  transformProperties(props, error, context ? computeRealValue(onReject.transform, context, true) : onReject.transform);
10459
10605
  return;
10460
10606
  } else if (isHandleRejectByCatch(onReject)) {
@@ -10467,18 +10613,21 @@ class Resolver {
10467
10613
  yield fetchData();
10468
10614
  }
10469
10615
  if (ref) {
10616
+ yield _this2.locationContext.storyboardContextWrapper.waitForUsedContext(transform);
10470
10617
  data = transformIntermediateData(data, context ? computeRealValue(transform, context, true) : transform, transformFrom, transformMapArray);
10471
10618
  }
10619
+ var transformTo = resolveConf.transform || resolveConf.name;
10620
+ yield _this2.locationContext.storyboardContextWrapper.waitForUsedContext(transformTo);
10472
10621
  transformProperties(props, data,
10473
10622
  // Also support legacy `name`
10474
- context ? computeRealValue(resolveConf.transform || resolveConf.name, context, true) : resolveConf.transform || resolveConf.name, resolveConf.transformFrom, resolveConf.transformMapArray);
10623
+ context ? computeRealValue(transformTo, context, true) : transformTo, resolveConf.transformFrom, resolveConf.transformMapArray);
10475
10624
  })();
10476
10625
  }
10477
10626
  scheduleRefreshing() {
10478
10627
  var _this3 = this;
10479
10628
  var _loop = function (providerBrick, interval) {
10480
10629
  var request = /*#__PURE__*/function () {
10481
- var _ref2 = _asyncToGenerator$3(function* () {
10630
+ var _ref3 = _asyncToGenerator$3(function* () {
10482
10631
  yield providerBrick.$refresh({
10483
10632
  ignoreErrors: interval.ignoreErrors,
10484
10633
  throwErrors: true,
@@ -10490,7 +10639,7 @@ class Resolver {
10490
10639
  }
10491
10640
  });
10492
10641
  return function request() {
10493
- return _ref2.apply(this, arguments);
10642
+ return _ref3.apply(this, arguments);
10494
10643
  };
10495
10644
  }();
10496
10645
  interval.timeoutId = setTimeout(request, interval.delay);
@@ -10887,7 +11036,7 @@ class Router {
10887
11036
  yield Promise.all(parallelRequests);
10888
11037
 
10889
11038
  // 如果找到匹配的 storyboard,那么根据路由匹配得到的 sub-storyboard 加载它的依赖库。
10890
- var subStoryboard = _this3.locationContext.getSubStoryboardByRoute(storyboard);
11039
+ var subStoryboard = yield _this3.locationContext.getSubStoryboardByRoute(storyboard);
10891
11040
  ({
10892
11041
  pendingTask
10893
11042
  } = yield _this3.kernel.loadDepsOfStoryboard(subStoryboard));
@@ -10959,6 +11108,7 @@ class Router {
10959
11108
  try {
10960
11109
  var mergedRoutes = mergePreviewRoutes(storyboard.routes);
10961
11110
  yield locationContext.mountRoutes(mergedRoutes, undefined, mountRoutesResult);
11111
+ yield locationContext.storyboardContextWrapper.waitForAllContext();
10962
11112
  } catch (error) {
10963
11113
  // eslint-disable-next-line no-console
10964
11114
  console.error(error);
@@ -11259,6 +11409,9 @@ class Router {
11259
11409
  handleMessageClose(event) {
11260
11410
  return this.locationContext.handleMessageClose(event);
11261
11411
  }
11412
+ waitForUsedContext(data) {
11413
+ return this.locationContext.storyboardContextWrapper.waitForUsedContext(data);
11414
+ }
11262
11415
  }
11263
11416
 
11264
11417
  var customProcessorRegistry = new Map();
@@ -11565,13 +11718,15 @@ function expandTemplateInUseBrick(useBrick, tplTagName, brick, requireSuspense)
11565
11718
  var getCurrentRunTimeBrick = (useBrick, tplTagName, data) => {
11566
11719
  var trackingContextList = [];
11567
11720
  var tplContextId = useBrick[symbolForTplContextId];
11721
+ var formContextId = useBrick[symbolForFormContextId];
11568
11722
  var transformOption = {
11569
11723
  // Keep lazy fields inside `useBrick` inside the `properties`.
11570
11724
  // They will be transformed by their `BrickAsComponent` later.
11571
11725
  $$lazyForUseBrick: true,
11572
11726
  trackingContextList,
11573
11727
  allowInject: true,
11574
- tplContextId
11728
+ tplContextId,
11729
+ formContextId
11575
11730
  };
11576
11731
  var properties = doTransform(data, cloneDeepWithInjectedMark(useBrick.properties) || {}, transformOption);
11577
11732
  var brick = _objectSpread(_objectSpread({}, useBrick), {}, {
@@ -11581,7 +11736,8 @@ var getCurrentRunTimeBrick = (useBrick, tplTagName, data) => {
11581
11736
  });
11582
11737
  var runtimeContext = _internalApiGetCurrentContext();
11583
11738
  listenOnTrackingContext(brick, trackingContextList, _objectSpread(_objectSpread({}, runtimeContext), {}, {
11584
- tplContextId
11739
+ tplContextId,
11740
+ formContextId
11585
11741
  }));
11586
11742
  return brick;
11587
11743
  };
@@ -11632,7 +11788,8 @@ var SingleBrickAsComponent = /*#__PURE__*/React.memo(function SingleBrickAsCompo
11632
11788
  var requireSuspense = useMemo(() => {
11633
11789
  var context;
11634
11790
  if (useBrick.brick === formRenderer) {
11635
- context = useBrick.properties.formData.context;
11791
+ var formData = typeof useBrick.properties.formData === "string" ? JSON.parse(useBrick.properties.formData) : useBrick.properties.formData;
11792
+ context = formData.context;
11636
11793
  } else if (tplTagName) {
11637
11794
  context = customTemplateRegistry.get(tplTagName).state;
11638
11795
  }
@@ -11650,7 +11807,7 @@ var SingleBrickAsComponent = /*#__PURE__*/React.memo(function SingleBrickAsCompo
11650
11807
  }
11651
11808
  _internalApiLoadDynamicBricksInBrickConf(useBrick).catch(handleHttpError);
11652
11809
  var brick = getCurrentRunTimeBrick(useBrick, tplTagName, data);
11653
- var expanded = useBrick.brick === formRenderer ? (requireSuspense ? AsyncExpandCustomForm : ExpandCustomForm)(useBrick.properties.formData, useBrick, false) : expandTemplateInUseBrick(useBrick, tplTagName, brick, requireSuspense);
11810
+ var expanded = useBrick.brick === formRenderer ? (requireSuspense ? AsyncExpandCustomForm : ExpandCustomForm)(typeof useBrick.properties.formData === "string" ? JSON.parse(useBrick.properties.formData) : useBrick.properties.formData, useBrick, false) : expandTemplateInUseBrick(useBrick, tplTagName, brick, requireSuspense);
11654
11811
  if (requireSuspense) {
11655
11812
  setExpandedBrickConf(yield expanded);
11656
11813
  setSuspenseReady(true);
@@ -11676,7 +11833,8 @@ var SingleBrickAsComponent = /*#__PURE__*/React.memo(function SingleBrickAsCompo
11676
11833
  brick: useBrick.brick,
11677
11834
  lifeCycle: useBrick.lifeCycle
11678
11835
  }, brick, _objectSpread(_objectSpread({}, _internalApiGetCurrentContext()), {}, {
11679
- tplContextId: useBrick[symbolForTplContextId]
11836
+ tplContextId: useBrick[symbolForTplContextId],
11837
+ formContextId: useBrick[symbolForFormContextId]
11680
11838
  }));
11681
11839
  }
11682
11840
  return brick;
@@ -11685,7 +11843,8 @@ var SingleBrickAsComponent = /*#__PURE__*/React.memo(function SingleBrickAsCompo
11685
11843
  var _ref4 = _asyncToGenerator$3(function* (event, handlers, brick) {
11686
11844
  for (var handler of [].concat(handlers)) {
11687
11845
  listenerFactory(handler, _objectSpread(_objectSpread({}, _internalApiGetCurrentContext()), {}, {
11688
- tplContextId: useBrick[symbolForTplContextId]
11846
+ tplContextId: useBrick[symbolForTplContextId],
11847
+ formContextId: useBrick[symbolForFormContextId]
11689
11848
  }), brick)(event);
11690
11849
  }
11691
11850
  });
@@ -11698,6 +11857,9 @@ var SingleBrickAsComponent = /*#__PURE__*/React.memo(function SingleBrickAsCompo
11698
11857
  var {
11699
11858
  [symbolForTplContextId]: tplContextId
11700
11859
  } = useBrick;
11860
+ var {
11861
+ [symbolForFormContextId]: formContextId
11862
+ } = useBrick;
11701
11863
  if (useBrick.iid) {
11702
11864
  element.dataset.iid = useBrick.iid;
11703
11865
  }
@@ -11705,7 +11867,8 @@ var SingleBrickAsComponent = /*#__PURE__*/React.memo(function SingleBrickAsCompo
11705
11867
  unbindListeners(element);
11706
11868
  if (brick.events) {
11707
11869
  bindListeners(element, transformEvents(data, brick.events), _objectSpread(_objectSpread({}, _internalApiGetCurrentContext()), {}, {
11708
- tplContextId
11870
+ tplContextId,
11871
+ formContextId
11709
11872
  }));
11710
11873
  }
11711
11874
  // 设置proxyEvent
@@ -11879,7 +12042,8 @@ var ForwardRefSingleBrickAsComponent = /*#__PURE__*/React.memo( /*#__PURE__*/for
11879
12042
  var requireSuspense = useMemo(() => {
11880
12043
  var context;
11881
12044
  if (useBrick.brick === formRenderer) {
11882
- context = useBrick.properties.formData.context;
12045
+ var formData = typeof useBrick.properties.formData === "string" ? JSON.parse(useBrick.properties.formData) : useBrick.properties.formData;
12046
+ context = formData.context;
11883
12047
  } else if (tplTagName) {
11884
12048
  context = customTemplateRegistry.get(tplTagName).state;
11885
12049
  }
@@ -11902,7 +12066,7 @@ var ForwardRefSingleBrickAsComponent = /*#__PURE__*/React.memo( /*#__PURE__*/for
11902
12066
  }
11903
12067
  _internalApiLoadDynamicBricksInBrickConf(useBrick).catch(handleHttpError);
11904
12068
  var brick = getCurrentRunTimeBrick(useBrick, tplTagName, data);
11905
- var expanded = useBrick.brick === formRenderer ? (requireSuspense ? AsyncExpandCustomForm : ExpandCustomForm)(useBrick.properties.formData, useBrick, false) : expandTemplateInUseBrick(useBrick, tplTagName, brick, requireSuspense);
12069
+ var expanded = useBrick.brick === formRenderer ? (requireSuspense ? AsyncExpandCustomForm : ExpandCustomForm)(typeof useBrick.properties.formData === "string" ? JSON.parse(useBrick.properties.formData) : useBrick.properties.formData, useBrick, false) : expandTemplateInUseBrick(useBrick, tplTagName, brick, requireSuspense);
11906
12070
  if (requireSuspense) {
11907
12071
  setExpandedBrickConf(yield expanded);
11908
12072
  setSuspenseReady(true);