@next-core/brick-kit 2.129.3 → 2.131.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.
@@ -1,14 +1,14 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('history'), require('@babel/runtime/helpers/objectSpread2'), require('@babel/runtime/helpers/objectWithoutProperties'), require('@babel/runtime/helpers/asyncToGenerator'), require('@babel/runtime/helpers/defineProperty'), require('react'), require('@next-core/brick-utils'), require('lodash'), require('@next-core/brick-http'), require('moment'), require('@next-core/pipes'), require('i18next'), require('@next-core/easyops-analytics'), require('antd'), require('@ant-design/icons'), require('js-yaml'), require('react-i18next'), require('@babel/runtime/helpers/esm/extends'), require('@next-core/illustrations'), require('@babel/runtime/helpers/decorate')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', 'history', '@babel/runtime/helpers/objectSpread2', '@babel/runtime/helpers/objectWithoutProperties', '@babel/runtime/helpers/asyncToGenerator', '@babel/runtime/helpers/defineProperty', 'react', '@next-core/brick-utils', 'lodash', '@next-core/brick-http', 'moment', '@next-core/pipes', 'i18next', '@next-core/easyops-analytics', 'antd', '@ant-design/icons', 'js-yaml', 'react-i18next', '@babel/runtime/helpers/esm/extends', '@next-core/illustrations', '@babel/runtime/helpers/decorate'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.BrickKit = {}, global.history$1, global._objectSpread, global._objectWithoutProperties, global._asyncToGenerator$4, global._defineProperty$1, global.React, global.brickUtils, global._, global.brickHttp, global.moment, global.pipes, global.i18next, global.easyopsAnalytics, global.antd, global.icons, global.yaml, global.reactI18next, global._extends, global.illustrations, global._decorate));
5
- })(this, (function (exports, history$1, _objectSpread, _objectWithoutProperties, _asyncToGenerator$4, _defineProperty$1, React, brickUtils, _, brickHttp, moment, pipes, i18next, easyopsAnalytics, antd, icons, yaml, reactI18next, _extends, illustrations, _decorate) { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.BrickKit = {}, global.history$1, global._objectSpread, global._objectWithoutProperties, global._asyncToGenerator$3, global._defineProperty$1, global.React, global.brickUtils, global._, global.brickHttp, global.moment, global.pipes, global.i18next, global.easyopsAnalytics, global.antd, global.icons, global.yaml, global.reactI18next, global._extends, global.illustrations, global._decorate));
5
+ })(this, (function (exports, history$1, _objectSpread, _objectWithoutProperties, _asyncToGenerator$3, _defineProperty$1, React, brickUtils, _, brickHttp, moment, pipes, i18next, easyopsAnalytics, antd, icons, yaml, reactI18next, _extends, illustrations, _decorate) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
9
9
  var _objectSpread__default = /*#__PURE__*/_interopDefaultLegacy(_objectSpread);
10
10
  var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
11
- var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator$4);
11
+ var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator$3);
12
12
  var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty$1);
13
13
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
14
14
  var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
@@ -444,7 +444,7 @@
444
444
  return ((_window$getComputedSt = window.getComputedStyle(el)) === null || _window$getComputedSt === void 0 ? void 0 : _window$getComputedSt.getPropertyValue(name)) || "";
445
445
  }
446
446
 
447
- function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
447
+ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
448
448
  try {
449
449
  var info = gen[key](arg);
450
450
  var value = info.value;
@@ -460,7 +460,7 @@
460
460
  }
461
461
  }
462
462
 
463
- function _asyncToGenerator$3(fn) {
463
+ function _asyncToGenerator$2(fn) {
464
464
  return function () {
465
465
  var self = this,
466
466
  args = arguments;
@@ -468,11 +468,11 @@
468
468
  var gen = fn.apply(self, args);
469
469
 
470
470
  function _next(value) {
471
- asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
471
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
472
472
  }
473
473
 
474
474
  function _throw(err) {
475
- asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
475
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
476
476
  }
477
477
 
478
478
  _next(undefined);
@@ -535,7 +535,7 @@
535
535
 
536
536
 
537
537
  var InstanceApi_getDetail = /*#__PURE__*/function () {
538
- var _ref = _asyncToGenerator$3(function* (objectId, instanceId, params, options) {
538
+ var _ref = _asyncToGenerator$2(function* (objectId, instanceId, params, options) {
539
539
  return (
540
540
  /**! @contract easyops.api.cmdb.instance.GetDetail */
541
541
  (yield brickHttp.http.get("api/gateway/cmdb.instance.GetDetail/object/".concat(objectId, "/instance/").concat(instanceId), _objectSpread2(_objectSpread2({}, options), {}, {
@@ -555,7 +555,7 @@
555
555
 
556
556
 
557
557
  var InstanceApi_postSearch = /*#__PURE__*/function () {
558
- var _ref = _asyncToGenerator$3(function* (objectId, data, options) {
558
+ var _ref = _asyncToGenerator$2(function* (objectId, data, options) {
559
559
  return (
560
560
  /**! @contract easyops.api.cmdb.instance.PostSearch */
561
561
  (yield brickHttp.http.post("api/gateway/cmdb.instance.PostSearch/object/".concat(objectId, "/instance/_search"), data, options)).data
@@ -1332,41 +1332,26 @@
1332
1332
  }
1333
1333
  }
1334
1334
 
1335
- function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
1336
- try {
1337
- var info = gen[key](arg);
1338
- var value = info.value;
1339
- } catch (error) {
1340
- reject(error);
1341
- return;
1342
- }
1343
-
1344
- if (info.done) {
1345
- resolve(value);
1346
- } else {
1347
- Promise.resolve(value).then(_next, _throw);
1348
- }
1349
- }
1335
+ /**
1336
+ * @description 获取微应用的i18n数据
1337
+ * @endpoint GET /api/v1/micro-app/i18n
1338
+ */
1350
1339
 
1351
- function _asyncToGenerator$2(fn) {
1352
- return function () {
1353
- var self = this,
1354
- args = arguments;
1355
- return new Promise(function (resolve, reject) {
1356
- var gen = fn.apply(self, args);
1357
1340
 
1358
- function _next(value) {
1359
- asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
1360
- }
1361
-
1362
- function _throw(err) {
1363
- asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
1364
- }
1341
+ var InstalledMicroAppApi_getI18NData = /*#__PURE__*/function () {
1342
+ var _ref = _asyncToGenerator__default["default"](function* (params, options) {
1343
+ return (
1344
+ /**! @contract easyops.api.micro_app.installed_micro_app.GetI18NData@1.0.0 */
1345
+ (yield brickHttp.http.get("api/gateway/micro_app.installed_micro_app.GetI18NData/api/v1/micro-app/i18n", _objectSpread__default["default"](_objectSpread__default["default"]({}, options), {}, {
1346
+ params
1347
+ }))).data
1348
+ );
1349
+ });
1365
1350
 
1366
- _next(undefined);
1367
- });
1351
+ return function InstalledMicroAppApi_getI18NData(_x, _x2) {
1352
+ return _ref.apply(this, arguments);
1368
1353
  };
1369
- }
1354
+ }();
1370
1355
  /**
1371
1356
  * @description 查询模型关联小产品列表
1372
1357
  * @endpoint LIST /api/micro_app/v1/object_micro_app
@@ -1374,9 +1359,9 @@
1374
1359
 
1375
1360
 
1376
1361
  var ObjectMicroAppApi_getObjectMicroAppList = /*#__PURE__*/function () {
1377
- var _ref = _asyncToGenerator$2(function* (options) {
1362
+ var _ref = _asyncToGenerator__default["default"](function* (options) {
1378
1363
  return (
1379
- /**! @contract easyops.api.micro_app.object_micro_app.GetObjectMicroAppList */
1364
+ /**! @contract easyops.api.micro_app.object_micro_app.GetObjectMicroAppList@1.0.0 */
1380
1365
  (yield brickHttp.http.get("api/gateway/micro_app.object_micro_app.GetObjectMicroAppList/api/micro_app/v1/object_micro_app", options)).data
1381
1366
  );
1382
1367
  });
@@ -1392,9 +1377,9 @@
1392
1377
 
1393
1378
 
1394
1379
  var PermissionApi_validatePermissions = /*#__PURE__*/function () {
1395
- var _ref = _asyncToGenerator$2(function* (data, options) {
1380
+ var _ref = _asyncToGenerator__default["default"](function* (data, options) {
1396
1381
  return (
1397
- /**! @contract easyops.api.micro_app.permission.ValidatePermissions */
1382
+ /**! @contract easyops.api.micro_app.permission.ValidatePermissions@1.0.0 */
1398
1383
  (yield brickHttp.http.post("api/gateway/micro_app.permission.ValidatePermissions/api/micro_app/v1/permission/validate", data, options)).data
1399
1384
  );
1400
1385
  });
@@ -1579,6 +1564,44 @@
1579
1564
  });
1580
1565
  }
1581
1566
 
1567
+ var misc;
1568
+ function getRuntimeMisc() {
1569
+ if (!misc) {
1570
+ misc = {
1571
+ isInIframe: false,
1572
+ isInIframeOfSameSite: false,
1573
+ isInIframeOfNext: false,
1574
+ isInIframeOfVisualBuilder: false,
1575
+ isInIframeOfLegacyConsole: false
1576
+ };
1577
+
1578
+ if (window !== window.parent) {
1579
+ misc.isInIframe = true;
1580
+
1581
+ try {
1582
+ // Handle:
1583
+ // - Previewing in visual builder by iframe.
1584
+ // - Nesting next in next.
1585
+ // - Nesting console in next.
1586
+ if (window.origin === window.parent.origin) {
1587
+ misc.isInIframeOfSameSite = true;
1588
+ var selfIsNext = getBasePath() === "/next/";
1589
+ var parentPathname = window.parent.location.pathname;
1590
+ var parentIsNext = parentPathname.startsWith("/next/");
1591
+ misc.isInIframeOfNext = (Number(selfIsNext) ^ Number(parentIsNext)) === 0;
1592
+ misc.isInIframeOfVisualBuilder = parentPathname.startsWith("".concat(parentIsNext ? "/next" : "", "/visual-builder/"));
1593
+ misc.isInIframeOfLegacyConsole = selfIsNext && !parentIsNext;
1594
+ }
1595
+ } catch (e) {// do nothing
1596
+ }
1597
+ }
1598
+
1599
+ Object.freeze(misc);
1600
+ }
1601
+
1602
+ return misc;
1603
+ }
1604
+
1582
1605
  // `GeneralGlobals` are globals which are page-state-agnostic,
1583
1606
  // thus they can be used both in storyboard expressions and functions.
1584
1607
  function getGeneralGlobals(attemptToVisitGlobals, options) {
@@ -1631,6 +1654,9 @@
1631
1654
  getCssPropertyValue: collectCoverage ? () => "" : getCssPropertyValue
1632
1655
  };
1633
1656
 
1657
+ case "RUNTIME_MISC":
1658
+ return collectCoverage ? fakeRuntimeMisc() : getRuntimeMisc();
1659
+
1634
1660
  case "console":
1635
1661
  return isStoryboardFunction ? getReadOnlyProxy(console) : undefined;
1636
1662
 
@@ -1666,6 +1692,16 @@
1666
1692
  return true;
1667
1693
  }
1668
1694
 
1695
+ function fakeRuntimeMisc() {
1696
+ return {
1697
+ isInIframe: false,
1698
+ isInIframeOfSameSite: false,
1699
+ isInIframeOfNext: false,
1700
+ isInIframeOfVisualBuilder: false,
1701
+ isInIframeOfLegacyConsole: false
1702
+ };
1703
+ }
1704
+
1669
1705
  /** @internal */
1670
1706
 
1671
1707
  /** @internal */
@@ -2004,7 +2040,7 @@
2004
2040
  }
2005
2041
 
2006
2042
  updateValue(name, value, method) {
2007
- var _item$eventTarget;
2043
+ var _item$eventTarget2;
2008
2044
 
2009
2045
  if (!this.data.has(name)) {
2010
2046
  if (this.tplContextId) {
@@ -2028,6 +2064,22 @@
2028
2064
  return;
2029
2065
  }
2030
2066
 
2067
+ if (method === "refresh") {
2068
+ if (!item.refresh) {
2069
+ throw new Error("You can not refresh the storyboard context \"".concat(name, "\" which has no resolve."));
2070
+ }
2071
+
2072
+ item.refresh().then(val => {
2073
+ var _item$eventTarget;
2074
+
2075
+ item.value = val;
2076
+ (_item$eventTarget = item.eventTarget) === null || _item$eventTarget === void 0 ? void 0 : _item$eventTarget.dispatchEvent(new CustomEvent(this.tplContextId ? "state.change" : "context.change", {
2077
+ detail: item.value
2078
+ }));
2079
+ }, handleHttpError);
2080
+ return;
2081
+ }
2082
+
2031
2083
  if (method === "replace") {
2032
2084
  item.value = value;
2033
2085
  } else {
@@ -2040,7 +2092,7 @@
2040
2092
  }
2041
2093
  }
2042
2094
 
2043
- (_item$eventTarget = item.eventTarget) === null || _item$eventTarget === void 0 ? void 0 : _item$eventTarget.dispatchEvent(new CustomEvent(this.tplContextId ? "state.change" : "context.change", {
2095
+ (_item$eventTarget2 = item.eventTarget) === null || _item$eventTarget2 === void 0 ? void 0 : _item$eventTarget2.dispatchEvent(new CustomEvent(this.tplContextId ? "state.change" : "context.change", {
2044
2096
  detail: item.value
2045
2097
  }));
2046
2098
  }
@@ -2121,30 +2173,65 @@
2121
2173
  return false;
2122
2174
  }
2123
2175
 
2124
- var isResolve = false;
2125
- var value = getDefinedTemplateState(!!storyboardContextWrapper.tplContextId, contextConf, brick);
2176
+ var isTemplateState = !!storyboardContextWrapper.tplContextId;
2177
+ var value = getDefinedTemplateState(isTemplateState, contextConf, brick);
2178
+ var refresh = null;
2179
+ var isLazyResolve = false;
2126
2180
 
2127
2181
  if (value === undefined) {
2128
2182
  if (contextConf.resolve) {
2129
2183
  if (looseCheckIf(contextConf.resolve, mergedContext)) {
2130
- isResolve = true;
2131
- var valueConf = {};
2132
- yield _internalApiGetResolver().resolveOne("reference", _objectSpread__default["default"]({
2133
- transform: "value",
2134
- transformMapArray: false
2135
- }, contextConf.resolve), valueConf, null, mergedContext);
2136
- value = valueConf.value;
2184
+ refresh = /*#__PURE__*/function () {
2185
+ var _ref = _asyncToGenerator__default["default"](function* () {
2186
+ var valueConf = {};
2187
+ yield _internalApiGetResolver().resolveOne("reference", _objectSpread__default["default"]({
2188
+ transform: "value",
2189
+ transformMapArray: false
2190
+ }, contextConf.resolve), valueConf, null, mergedContext);
2191
+ return valueConf.value;
2192
+ });
2193
+
2194
+ return function refresh() {
2195
+ return _ref.apply(this, arguments);
2196
+ };
2197
+ }();
2198
+
2199
+ isLazyResolve = contextConf.resolve.lazy;
2200
+
2201
+ if (!isLazyResolve) {
2202
+ value = yield refresh();
2203
+ }
2137
2204
  } else if (!brickUtils.hasOwnProperty(contextConf, "value")) {
2138
2205
  return false;
2139
2206
  }
2140
2207
  }
2141
2208
 
2142
- if (!isResolve && contextConf.value !== undefined) {
2209
+ if ((!refresh || isLazyResolve) && contextConf.value !== undefined) {
2210
+ // If the context has no resolve, just use its `value`.
2211
+ // Or if the resolve is ignored or lazy, use its `value` as a fallback.
2143
2212
  value = computeRealValue(contextConf.value, mergedContext, true);
2144
2213
  }
2214
+
2215
+ if (contextConf.track) {
2216
+ // Track its dependencies and auto update when each of them changed.
2217
+ var deps = (isTemplateState ? brickUtils.trackUsedState : brickUtils.trackUsedContext)(refresh ? contextConf.resolve : contextConf.value);
2218
+
2219
+ for (var dep of deps) {
2220
+ var _eventTarget;
2221
+
2222
+ var ctx = storyboardContextWrapper.get().get(dep);
2223
+ ctx === null || ctx === void 0 ? void 0 : (_eventTarget = ctx.eventTarget) === null || _eventTarget === void 0 ? void 0 : _eventTarget.addEventListener(isTemplateState ? "state.change" : "context.change", () => {
2224
+ if (refresh) {
2225
+ storyboardContextWrapper.updateValue(contextConf.name, undefined, "refresh");
2226
+ } else {
2227
+ storyboardContextWrapper.updateValue(contextConf.name, computeRealValue(contextConf.value, mergedContext, true), "replace");
2228
+ }
2229
+ });
2230
+ }
2231
+ }
2145
2232
  }
2146
2233
 
2147
- resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick);
2234
+ resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick, refresh);
2148
2235
  return true;
2149
2236
  });
2150
2237
  return _resolveNormalStoryboardContext.apply(this, arguments);
@@ -2175,12 +2262,13 @@
2175
2262
  }
2176
2263
  }
2177
2264
 
2178
- function resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick) {
2265
+ function resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick, refresh) {
2179
2266
  var newContext = {
2180
2267
  type: "free-variable",
2181
2268
  value,
2182
2269
  // This is required for tracking context, even if no `onChange` is specified.
2183
- eventTarget: new EventTarget$1()
2270
+ eventTarget: new EventTarget$1(),
2271
+ refresh
2184
2272
  };
2185
2273
 
2186
2274
  if (contextConf.onChange) {
@@ -2977,7 +3065,8 @@
2977
3065
  }
2978
3066
 
2979
3067
  var _excluded$6 = ["children"],
2980
- _excluded2$2 = ["items", "app"];
3068
+ _excluded2$2 = ["children"],
3069
+ _excluded3 = ["items", "app"];
2981
3070
  var symbolAppId = Symbol("appId");
2982
3071
  // Caching menu requests to avoid flicker.
2983
3072
  var menuCache = new Map();
@@ -3161,10 +3250,13 @@
3161
3250
  items,
3162
3251
  app
3163
3252
  } = _yield$fetchMenuById,
3164
- restMenuData = _objectWithoutProperties__default["default"](_yield$fetchMenuById, _excluded2$2);
3253
+ restMenuData = _objectWithoutProperties__default["default"](_yield$fetchMenuById, _excluded3);
3165
3254
 
3166
- var menuData = _objectSpread__default["default"](_objectSpread__default["default"]({}, yield computeRealValueWithOverrideApp(restMenuData, app[0].appId, context, kernel)), {}, {
3167
- items: yield computeMenuItemsWithOverrideApp(items, context, kernel)
3255
+ var appIds = collectOverrideApps(items, app[0].appId, context.app.id);
3256
+ yield kernel.fulfilStoryboardI18n(appIds);
3257
+
3258
+ var menuData = _objectSpread__default["default"](_objectSpread__default["default"]({}, computeRealValueWithOverrideApp(restMenuData, app[0].appId, context, kernel)), {}, {
3259
+ items: computeMenuItemsWithOverrideApp(items, context, kernel)
3168
3260
  });
3169
3261
 
3170
3262
  return {
@@ -3196,26 +3288,48 @@
3196
3288
  return _processMenu.apply(this, arguments);
3197
3289
  }
3198
3290
 
3199
- function computeMenuItemsWithOverrideApp(items, context, kernel) {
3200
- return Promise.all(items.map( /*#__PURE__*/function () {
3201
- var _ref2 = _asyncToGenerator__default["default"](function* (_ref) {
3291
+ function collectOverrideApps(items, rootAppId, contextAppId) {
3292
+ var appIds = new Set();
3293
+
3294
+ if (rootAppId !== contextAppId) {
3295
+ appIds.add(rootAppId);
3296
+ }
3297
+
3298
+ function collect(items) {
3299
+ for (var _ref of items) {
3202
3300
  var {
3203
3301
  children
3204
3302
  } = _ref,
3205
3303
  rest = _objectWithoutProperties__default["default"](_ref, _excluded$6);
3206
3304
 
3207
- return _objectSpread__default["default"](_objectSpread__default["default"]({}, yield computeRealValueWithOverrideApp(rest, rest[symbolAppId], context, kernel)), {}, {
3208
- children: children && (yield computeMenuItemsWithOverrideApp(children, context, kernel))
3209
- });
3210
- });
3305
+ var overrideAppId = rest[symbolAppId];
3211
3306
 
3212
- return function (_x16) {
3213
- return _ref2.apply(this, arguments);
3214
- };
3215
- }()));
3307
+ if (overrideAppId !== contextAppId && !appIds.has(overrideAppId) && requireOverrideApp(rest)) {
3308
+ appIds.add(overrideAppId);
3309
+ }
3310
+
3311
+ children && collect(children);
3312
+ }
3313
+ }
3314
+
3315
+ collect(items);
3316
+ return [...appIds];
3216
3317
  }
3217
3318
 
3218
- function processMenuTitle(_x17) {
3319
+ function computeMenuItemsWithOverrideApp(items, context, kernel) {
3320
+ return items.map(_ref2 => {
3321
+ var {
3322
+ children
3323
+ } = _ref2,
3324
+ rest = _objectWithoutProperties__default["default"](_ref2, _excluded2$2);
3325
+
3326
+ return _objectSpread__default["default"](_objectSpread__default["default"]({}, computeRealValueWithOverrideApp(rest, rest[symbolAppId], context, kernel)), {}, {
3327
+ children: children && computeMenuItemsWithOverrideApp(children, context, kernel)
3328
+ });
3329
+ });
3330
+ }
3331
+
3332
+ function processMenuTitle(_x16) {
3219
3333
  return _processMenuTitle.apply(this, arguments);
3220
3334
  }
3221
3335
 
@@ -3310,30 +3424,22 @@
3310
3424
  return false;
3311
3425
  }
3312
3426
 
3313
- function computeRealValueWithOverrideApp(_x18, _x19, _x20, _x21) {
3314
- return _computeRealValueWithOverrideApp.apply(this, arguments);
3315
- }
3316
-
3317
- function _computeRealValueWithOverrideApp() {
3318
- _computeRealValueWithOverrideApp = _asyncToGenerator__default["default"](function* (data, overrideAppId, context, kernel) {
3319
- var newContext = context;
3427
+ function computeRealValueWithOverrideApp(data, overrideAppId, context, kernel) {
3428
+ var newContext = context;
3320
3429
 
3321
- if (overrideAppId !== context.app.id && requireOverrideApp(data)) {
3322
- var storyboard = kernel.bootstrapData.storyboards.find(story => story.app.id === overrideAppId);
3430
+ if (overrideAppId !== context.app.id && requireOverrideApp(data)) {
3431
+ var storyboard = kernel.bootstrapData.storyboards.find(story => story.app.id === overrideAppId);
3323
3432
 
3324
- if (storyboard) {
3325
- yield kernel.fulfilStoryboard(storyboard);
3326
- newContext = _objectSpread__default["default"](_objectSpread__default["default"]({}, context), {}, {
3327
- overrideApp: storyboard.app
3328
- });
3329
- }
3433
+ if (storyboard) {
3434
+ newContext = _objectSpread__default["default"](_objectSpread__default["default"]({}, context), {}, {
3435
+ overrideApp: storyboard.app
3436
+ });
3330
3437
  }
3438
+ }
3331
3439
 
3332
- return computeRealValue(data, newContext, true, {
3333
- ignoreSymbols: true
3334
- });
3440
+ return computeRealValue(data, newContext, true, {
3441
+ ignoreSymbols: true
3335
3442
  });
3336
- return _computeRealValueWithOverrideApp.apply(this, arguments);
3337
3443
  }
3338
3444
 
3339
3445
  var lazyBrickRegistry = new Map();
@@ -6233,10 +6339,12 @@
6233
6339
 
6234
6340
  case "context.assign":
6235
6341
  case "context.replace":
6342
+ case "context.refresh":
6236
6343
  return builtinContextListenerFactory(method, handler.args, handler, context);
6237
6344
 
6238
6345
  case "state.update":
6239
- return builtinStateListenerFactory(handler.args, handler, context);
6346
+ case "state.refresh":
6347
+ return builtinStateListenerFactory(method, handler.args, handler, context);
6240
6348
 
6241
6349
  case "tpl.dispatchEvent":
6242
6350
  return builtinTplDispatchEventFactory(handler.args, handler, context);
@@ -6380,7 +6488,7 @@
6380
6488
  };
6381
6489
  }
6382
6490
 
6383
- function builtinStateListenerFactory(args, ifContainer, context) {
6491
+ function builtinStateListenerFactory(method, args, ifContainer, context) {
6384
6492
  return function (event) {
6385
6493
  if (!looseCheckIf(ifContainer, _objectSpread__default["default"](_objectSpread__default["default"]({}, context), {}, {
6386
6494
  event
@@ -6390,7 +6498,7 @@
6390
6498
 
6391
6499
  var tplContext = getTplContext(context.tplContextId);
6392
6500
  var [name, value] = argsFactory(args, context, event);
6393
- tplContext.state.updateValue(name, value, "replace");
6501
+ tplContext.state.updateValue(name, value, method === "refresh" ? method : "replace");
6394
6502
  };
6395
6503
  }
6396
6504
 
@@ -8987,7 +9095,8 @@
8987
9095
  return _asyncToGenerator__default["default"](function* () {
8988
9096
  if (window.STANDALONE_MICRO_APPS) {
8989
9097
  Object.assign(storyboard, {
8990
- $$fulfilled: true
9098
+ $$fulfilled: true,
9099
+ $$fulfilling: null
8991
9100
  });
8992
9101
 
8993
9102
  if (!window.NO_AUTH_GUARD) {
@@ -9020,7 +9129,8 @@
9020
9129
  routes,
9021
9130
  meta,
9022
9131
  app: _objectSpread__default["default"](_objectSpread__default["default"]({}, storyboard.app), app),
9023
- $$fulfilled: true
9132
+ $$fulfilled: true,
9133
+ $$fulfilling: null
9024
9134
  });
9025
9135
  }
9026
9136
 
@@ -9029,9 +9139,12 @@
9029
9139
  }
9030
9140
 
9031
9141
  postProcessStoryboard(storyboard) {
9032
- var _storyboard$meta;
9033
-
9034
9142
  storyboard.app.$$routeAliasMap = brickUtils.scanRouteAliasInStoryboard(storyboard);
9143
+ this.postProcessStoryboardI18n(storyboard);
9144
+ }
9145
+
9146
+ postProcessStoryboardI18n(storyboard) {
9147
+ var _storyboard$meta;
9035
9148
 
9036
9149
  if ((_storyboard$meta = storyboard.meta) !== null && _storyboard$meta !== void 0 && _storyboard$meta.i18n) {
9037
9150
  // Prefix to avoid conflict between brick package's i18n namespace.
@@ -9044,10 +9157,70 @@
9044
9157
  }
9045
9158
  }
9046
9159
 
9160
+ fulfilStoryboardI18n(appIds) {
9161
+ var _this7 = this;
9162
+
9163
+ return _asyncToGenerator__default["default"](function* () {
9164
+ // Ignore already fulfilled apps.
9165
+ var filteredStoryboards = appIds.map(appId => _this7.bootstrapData.storyboards.find(story => story.app.id === appId)).filter(story => story && !story.$$fulfilled && !story.$$i18nFulfilled);
9166
+
9167
+ if (window.STANDALONE_MICRO_APPS) {
9168
+ // Fallback to fullfil whole storyboard for standalone micro-apps.
9169
+ yield Promise.all(filteredStoryboards.map(story => _this7.fulfilStoryboard(story)));
9170
+ return;
9171
+ } // Do not fulfil i18n if the app is doing a whole fulfilling.
9172
+
9173
+
9174
+ var fulfilling = [];
9175
+ var filteredAppIds = [];
9176
+
9177
+ for (var story of filteredStoryboards) {
9178
+ if (story.$$fulfilling) {
9179
+ fulfilling.push(story.$$fulfilling);
9180
+ } else {
9181
+ filteredAppIds.push(story.app.id);
9182
+ }
9183
+ }
9184
+
9185
+ if (filteredAppIds.length === 0) {
9186
+ // Still wait for these whole fulfilling.
9187
+ yield Promise.all(fulfilling);
9188
+ return;
9189
+ }
9190
+
9191
+ var [{
9192
+ i18nInfo
9193
+ }] = yield Promise.all([InstalledMicroAppApi_getI18NData({
9194
+ appIds: filteredAppIds.join(",")
9195
+ }), // Still wait for these whole fulfilling.
9196
+ ...fulfilling]);
9197
+
9198
+ var _loop = function (appId, i18n) {
9199
+ var storyboard = _this7.bootstrapData.storyboards.find(story => story.app.id === appId);
9200
+
9201
+ Object.assign(storyboard, {
9202
+ meta: _objectSpread__default["default"](_objectSpread__default["default"]({}, storyboard.meta), {}, {
9203
+ i18n: i18n
9204
+ }),
9205
+ $$i18nFulfilled: true
9206
+ });
9207
+
9208
+ _this7.postProcessStoryboardI18n(storyboard);
9209
+ };
9210
+
9211
+ for (var {
9212
+ appId,
9213
+ i18n
9214
+ } of i18nInfo) {
9215
+ _loop(appId, i18n);
9216
+ }
9217
+ })();
9218
+ }
9219
+
9047
9220
  _dev_only_updateStoryboard(appId, storyboardPatch) {
9048
9221
  var storyboard = this.bootstrapData.storyboards.find(item => item.app.id === appId);
9049
9222
  Object.assign(storyboard, _objectSpread__default["default"](_objectSpread__default["default"]({}, storyboardPatch), {}, {
9050
- $$fulfilling: Promise.resolve(),
9223
+ $$fulfilling: null,
9051
9224
  $$fulfilled: true,
9052
9225
  $$registerCustomTemplateProcessed: false,
9053
9226
  $$depsProcessed: false
@@ -9057,7 +9230,8 @@
9057
9230
 
9058
9231
  _dev_only_updateTemplatePreviewSettings(appId, templateId, settings) {
9059
9232
  var {
9060
- routes
9233
+ routes,
9234
+ app
9061
9235
  } = this.bootstrapData.storyboards.find(item => item.app.id === appId);
9062
9236
  var previewPath = "${APP.homepage}/_dev_only_/template-preview/".concat(templateId);
9063
9237
  var previewRouteIndex = routes.findIndex(route => route.path === previewPath);
@@ -9067,7 +9241,8 @@
9067
9241
  brick: templateId
9068
9242
  }, _.pick(settings, "properties", "events", "lifeCycle", "context"))],
9069
9243
  menu: false,
9070
- exact: true
9244
+ exact: true,
9245
+ hybrid: app.legacy === "iframe"
9071
9246
  };
9072
9247
 
9073
9248
  if (previewRouteIndex === -1) {
@@ -9081,7 +9256,8 @@
9081
9256
  var _snippetData$bricks;
9082
9257
 
9083
9258
  var {
9084
- routes
9259
+ routes,
9260
+ app
9085
9261
  } = this.bootstrapData.storyboards.find(item => item.app.id === appId);
9086
9262
  var previewPath = "${APP.homepage}/_dev_only_/snippet-preview/".concat(snippetData.snippetId);
9087
9263
  var previewRouteIndex = routes.findIndex(route => route.path === previewPath);
@@ -9091,7 +9267,8 @@
9091
9267
  brick: "span"
9092
9268
  }],
9093
9269
  menu: false,
9094
- exact: true
9270
+ exact: true,
9271
+ hybrid: app.legacy === "iframe"
9095
9272
  };
9096
9273
 
9097
9274
  if (previewRouteIndex === -1) {
@@ -9170,7 +9347,7 @@
9170
9347
 
9171
9348
  gracefullyLoadDeps(fn) {
9172
9349
  var _arguments = arguments,
9173
- _this7 = this;
9350
+ _this8 = this;
9174
9351
 
9175
9352
  return _asyncToGenerator__default["default"](function* () {
9176
9353
  for (var _len = _arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
@@ -9184,7 +9361,7 @@
9184
9361
  // The scripts maybe stale when a user stays in page while upgrades been applied.
9185
9362
  // So we force reloading again automatically.
9186
9363
  // NOTE: reload only once to avoid a infinite loop.
9187
- yield _this7.reloadMicroApps();
9364
+ yield _this8.reloadMicroApps();
9188
9365
  yield fn(...args);
9189
9366
  } else {
9190
9367
  throw e;
@@ -9233,7 +9410,7 @@
9233
9410
  }
9234
9411
 
9235
9412
  loadDynamicBricksInBrickConf(brickConf) {
9236
- var _this8 = this;
9413
+ var _this9 = this;
9237
9414
 
9238
9415
  return _asyncToGenerator__default["default"](function* () {
9239
9416
  // Notice: `brickConf` contains runtime data,
@@ -9241,7 +9418,7 @@
9241
9418
  // which could cause stack overflow while traversing.
9242
9419
  var bricks = brickUtils.scanBricksInBrickConf(brickConf);
9243
9420
  var processors = brickUtils.scanProcessorsInAny(brickConf);
9244
- yield _this8.loadDynamicBricks(bricks, processors);
9421
+ yield _this9.loadDynamicBricks(bricks, processors);
9245
9422
  })();
9246
9423
  }
9247
9424
 
@@ -9350,10 +9527,10 @@
9350
9527
  }
9351
9528
 
9352
9529
  getMicroAppApiOrchestrationMapAsync() {
9353
- var _this9 = this;
9530
+ var _this10 = this;
9354
9531
 
9355
9532
  return _asyncToGenerator__default["default"](function* () {
9356
- return yield _this9.allMicroAppApiOrchestrationPromise;
9533
+ return yield _this10.allMicroAppApiOrchestrationPromise;
9357
9534
  })();
9358
9535
  }
9359
9536
 
@@ -9445,14 +9622,14 @@
9445
9622
  }
9446
9623
 
9447
9624
  getRelatedAppsAsync(appId) {
9448
- var _this10 = this;
9625
+ var _this11 = this;
9449
9626
 
9450
9627
  return _asyncToGenerator__default["default"](function* () {
9451
9628
  if (!appId) {
9452
9629
  return [];
9453
9630
  }
9454
9631
 
9455
- var allRelatedApps = yield _this10.allRelatedAppsPromise;
9632
+ var allRelatedApps = yield _this11.allRelatedAppsPromise;
9456
9633
  var thisApp = allRelatedApps.find(item => item.microAppId === appId);
9457
9634
 
9458
9635
  if (!thisApp) {
@@ -9464,38 +9641,38 @@
9464
9641
  }
9465
9642
 
9466
9643
  updateWorkspaceStack() {
9467
- var _this11 = this;
9644
+ var _this12 = this;
9468
9645
 
9469
9646
  return _asyncToGenerator__default["default"](function* () {
9470
- if (_this11.currentApp && _this11.currentApp.id) {
9647
+ if (_this12.currentApp && _this12.currentApp.id) {
9471
9648
  var workspace = {
9472
- appId: _this11.currentApp.id,
9473
- appName: _this11.currentApp.name,
9474
- appLocaleName: _this11.currentApp.localeName,
9475
- url: _this11.currentUrl
9649
+ appId: _this12.currentApp.id,
9650
+ appName: _this12.currentApp.name,
9651
+ appLocaleName: _this12.currentApp.localeName,
9652
+ url: _this12.currentUrl
9476
9653
  };
9477
9654
 
9478
- if (_this11.workspaceStack.length > 0) {
9479
- var previousWorkspace = _this11.workspaceStack[_this11.workspaceStack.length - 1];
9655
+ if (_this12.workspaceStack.length > 0) {
9656
+ var previousWorkspace = _this12.workspaceStack[_this12.workspaceStack.length - 1];
9480
9657
 
9481
- var _relatedApps = yield _this11.getRelatedAppsAsync(previousWorkspace.appId);
9658
+ var _relatedApps = yield _this12.getRelatedAppsAsync(previousWorkspace.appId);
9482
9659
 
9483
- if (_relatedApps.some(item => item.microAppId === _this11.currentApp.id)) {
9660
+ if (_relatedApps.some(item => item.microAppId === _this12.currentApp.id)) {
9484
9661
  Object.assign(previousWorkspace, workspace);
9485
9662
  return;
9486
9663
  }
9487
9664
  }
9488
9665
 
9489
- var relatedApps = yield _this11.getRelatedAppsAsync(_this11.currentApp.id);
9666
+ var relatedApps = yield _this12.getRelatedAppsAsync(_this12.currentApp.id);
9490
9667
 
9491
9668
  if (relatedApps.length > 0) {
9492
- _this11.workspaceStack.push(workspace);
9669
+ _this12.workspaceStack.push(workspace);
9493
9670
 
9494
9671
  return;
9495
9672
  }
9496
9673
  }
9497
9674
 
9498
- _this11.workspaceStack = [];
9675
+ _this12.workspaceStack = [];
9499
9676
  })();
9500
9677
  }
9501
9678
 
@@ -9542,22 +9719,22 @@
9542
9719
  }
9543
9720
 
9544
9721
  getProviderBrick(provider) {
9545
- var _this12 = this;
9722
+ var _this13 = this;
9546
9723
 
9547
9724
  return _asyncToGenerator__default["default"](function* () {
9548
9725
  if (isCustomApiProvider(provider)) {
9549
9726
  provider = CUSTOM_API_PROVIDER;
9550
9727
  }
9551
9728
 
9552
- if (_this12.providerRepository.has(provider)) {
9553
- return _this12.providerRepository.get(provider);
9729
+ if (_this13.providerRepository.has(provider)) {
9730
+ return _this13.providerRepository.get(provider);
9554
9731
  }
9555
9732
 
9556
9733
  if (provider === CUSTOM_API_PROVIDER && !customElements.get(provider)) {
9557
9734
  registerCustomApi();
9558
9735
  }
9559
9736
 
9560
- yield _this12.loadDynamicBricks([provider]);
9737
+ yield _this13.loadDynamicBricks([provider]);
9561
9738
 
9562
9739
  if (!customElements.get(provider)) {
9563
9740
  throw new Error("Provider not defined: \"".concat(provider, "\"."));
@@ -9565,7 +9742,7 @@
9565
9742
 
9566
9743
  var brick = document.createElement(provider);
9567
9744
 
9568
- _this12.providerRepository.set(provider, brick);
9745
+ _this13.providerRepository.set(provider, brick);
9569
9746
 
9570
9747
  return brick;
9571
9748
  })();
@@ -9737,44 +9914,6 @@
9737
9914
  return conf.type === "routes";
9738
9915
  }
9739
9916
 
9740
- var misc;
9741
- function getRuntimeMisc() {
9742
- if (!misc) {
9743
- misc = {
9744
- isInIframe: false,
9745
- isInIframeOfSameSite: false,
9746
- isInIframeOfNext: false,
9747
- isInIframeOfVisualBuilder: false,
9748
- isInIframeOfLegacyConsole: false
9749
- };
9750
-
9751
- if (window !== window.parent) {
9752
- misc.isInIframe = true;
9753
-
9754
- try {
9755
- // Handle:
9756
- // - Previewing in visual builder by iframe.
9757
- // - Nesting next in next.
9758
- // - Nesting console in next.
9759
- if (window.origin === window.parent.origin) {
9760
- misc.isInIframeOfSameSite = true;
9761
- var selfIsNext = getBasePath() === "/next/";
9762
- var parentPathname = window.parent.location.pathname;
9763
- var parentIsNext = parentPathname.startsWith("/next/");
9764
- misc.isInIframeOfNext = (Number(selfIsNext) ^ Number(parentIsNext)) === 0;
9765
- misc.isInIframeOfVisualBuilder = parentPathname.startsWith("".concat(parentIsNext ? "/next" : "", "/visual-builder/"));
9766
- misc.isInIframeOfLegacyConsole = selfIsNext && !parentIsNext;
9767
- }
9768
- } catch (e) {// do nothing
9769
- }
9770
- }
9771
-
9772
- Object.freeze(misc);
9773
- }
9774
-
9775
- return misc;
9776
- }
9777
-
9778
9917
  function getSubStoryboardByRoute(storyboard, matcher) {
9779
9918
  function getSubRoutes(routes) {
9780
9919
  return matcher(routes).map(getSubRoute);
@@ -10720,7 +10859,7 @@
10720
10859
  if (expandedBrickConf.exports) {
10721
10860
  for (var [prop, ctxName] of Object.entries(expandedBrickConf.exports)) {
10722
10861
  if (typeof ctxName === "string" && ctxName.startsWith("CTX.")) {
10723
- _this6.storyboardContextWrapper.set(ctxName.substr(4), {
10862
+ _this6.storyboardContextWrapper.set(ctxName.substring(4), {
10724
10863
  type: "brick-property",
10725
10864
  brick,
10726
10865
  prop
@@ -11299,19 +11438,33 @@
11299
11438
  }
11300
11439
  }
11301
11440
 
11302
- var cacheKey = JSON.stringify({
11303
- provider,
11304
- useProvider,
11305
- method,
11306
- args
11307
- });
11441
+ var actualArgs = args ? ref ? args // `args` are already computed for `defineResolves`
11442
+ : context ? computeRealValue(args, context, true) : args : providerBrick.args || [];
11443
+ var cacheKey;
11444
+
11445
+ try {
11446
+ // `actualArgs` may contain circular references, which makes
11447
+ // JSON stringify failed, thus we fallback to original args.
11448
+ cacheKey = JSON.stringify({
11449
+ provider,
11450
+ useProvider,
11451
+ method,
11452
+ actualArgs
11453
+ });
11454
+ } catch (e) {
11455
+ cacheKey = JSON.stringify({
11456
+ provider,
11457
+ useProvider,
11458
+ method,
11459
+ args
11460
+ });
11461
+ }
11462
+
11308
11463
  var promise;
11309
11464
 
11310
11465
  if (_this2.cache.has(cacheKey)) {
11311
11466
  promise = _this2.cache.get(cacheKey);
11312
11467
  } else {
11313
- var actualArgs = args ? ref ? args // `args` are already computed for `defineResolves`
11314
- : context ? computeRealValue(args, context, true) : args : providerBrick.args || [];
11315
11468
  promise = _asyncToGenerator__default["default"](function* () {
11316
11469
  if (useProvider) {
11317
11470
  actualArgs = yield getArgsOfCustomApi(useProvider, actualArgs);