@next-core/brick-kit 2.89.2 → 2.90.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,24 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [2.90.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.89.2...@next-core/brick-kit@2.90.0) (2021-11-26)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * fix a regression of caching resolves ([e9cd56d](https://github.com/easyops-cn/next-core/commit/e9cd56d882d0a13ee1cb13c4ed752a15f2c15bfd))
12
+
13
+
14
+ ### Features
15
+
16
+ * support i18n in storyboard functions ([5891932](https://github.com/easyops-cn/next-core/commit/589193250f22735b20e93d32c807896f4ae0932b))
17
+ * support i18n in widgets ([6020545](https://github.com/easyops-cn/next-core/commit/60205457fedbc7c000bb60b1e97729e3151be33d))
18
+ * support img in widgets ([f19ad53](https://github.com/easyops-cn/next-core/commit/f19ad5329b95c71e612f4be0ffa57b5a3d9ec570))
19
+
20
+
21
+
22
+
23
+
6
24
  ## [2.89.2](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.89.1...@next-core/brick-kit@2.89.2) (2021-11-25)
7
25
 
8
26
 
@@ -685,12 +685,12 @@
685
685
  };
686
686
  }
687
687
 
688
- function imagesFactory(app) {
688
+ function imagesFactory(appId, isBuildPush) {
689
689
  return {
690
690
  get(name) {
691
691
  var _window$PUBLIC_ROOT;
692
692
 
693
- return app.isBuildPush ? "api/gateway/object_store.object_store.GetObject/api/v1/objectStore/bucket/next-builder/object/".concat(name) : "".concat((_window$PUBLIC_ROOT = window.PUBLIC_ROOT) !== null && _window$PUBLIC_ROOT !== void 0 ? _window$PUBLIC_ROOT : "", "micro-apps/").concat(app.id, "/images/").concat(name);
693
+ return isBuildPush ? "api/gateway/object_store.object_store.GetObject/api/v1/objectStore/bucket/next-builder/object/".concat(name) : "".concat((_window$PUBLIC_ROOT = window.PUBLIC_ROOT) !== null && _window$PUBLIC_ROOT !== void 0 ? _window$PUBLIC_ROOT : "", "micro-apps/").concat(appId, "/images/").concat(name);
694
694
  }
695
695
 
696
696
  };
@@ -1389,11 +1389,55 @@
1389
1389
  }
1390
1390
  }
1391
1391
 
1392
+ var locale$7 = {
1393
+ [K.REQUEST_FAILED]: "Request Failed",
1394
+ [K.MODAL_OK]: "Ok",
1395
+ [K.MODAL_CANCEL]: "Cancel",
1396
+ [K.SOMETHING_WENT_WRONG]: "Something went wrong!",
1397
+ [K.LOGIN_TIMEOUT_MESSAGE]: "You haven't logged in or your login session has expired. Login right now?",
1398
+ [K.NETWORK_ERROR]: "Network error, please check your network."
1399
+ };
1400
+ var en = locale$7;
1401
+
1402
+ var locale$6 = {
1403
+ [K.REQUEST_FAILED]: "请求失败",
1404
+ [K.MODAL_OK]: "确认",
1405
+ [K.MODAL_CANCEL]: "取消",
1406
+ [K.SOMETHING_WENT_WRONG]: "出现了一些问题!",
1407
+ [K.LOGIN_TIMEOUT_MESSAGE]: "您还未登录或登录信息已过期,现在重新登录?",
1408
+ [K.NETWORK_ERROR]: "网络错误,请检查您的网络连接。"
1409
+ };
1410
+ var zh = locale$6;
1411
+
1412
+ /** @internal */
1413
+
1414
+ var initI18n = () => {
1415
+ i18next__default["default"].addResourceBundle("en", NS_BRICK_KIT, en);
1416
+ i18next__default["default"].addResourceBundle("zh", NS_BRICK_KIT, zh);
1417
+ };
1418
+ /** @internal */
1419
+
1420
+ function getI18nNamespace(type, id) {
1421
+ return "$".concat(type, "-").concat(id);
1422
+ }
1423
+
1424
+ function registerWidgetI18n(widgetId, i18n) {
1425
+ var ns = getI18nNamespace("widget", widgetId);
1426
+ Object.entries(i18n).forEach(_ref => {
1427
+ var [lang, resources] = _ref;
1428
+ i18next__default["default"].addResourceBundle(lang, ns, resources);
1429
+ });
1430
+ }
1431
+ function widgetI18nFactory(widgetId) {
1432
+ return i18next.getFixedT(null, getI18nNamespace("widget", widgetId));
1433
+ }
1434
+
1392
1435
  /** @internal */
1393
1436
 
1394
1437
  /** @internal */
1395
1438
  function StoryboardFunctionRegistryFactory() {
1396
1439
  var {
1440
+ widgetId,
1397
1441
  collectCoverage
1398
1442
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1399
1443
  var registeredFunctions = new Map(); // Use `Proxy` with a frozen target, to make a readonly function registry.
@@ -1405,7 +1449,30 @@
1405
1449
 
1406
1450
  });
1407
1451
 
1408
- function registerStoryboardFunctions(functions) {
1452
+ var builtinSupply = _objectSpread__default["default"]({
1453
+ // Functions can call other functions.
1454
+ FN: storyboardFunctions
1455
+ }, collectCoverage ? {
1456
+ // Fake builtin methods for tests.
1457
+ I18N: lodash.identity,
1458
+ I18N_TEXT: fakeI18nText,
1459
+ IMG: fakeImageFactory()
1460
+ } : widgetId ? {
1461
+ I18N: widgetI18nFactory(widgetId),
1462
+ I18N_TEXT: i18nText,
1463
+ IMG: widgetImagesFactory(widgetId)
1464
+ } : {
1465
+ I18N_TEXT: i18nText
1466
+ });
1467
+
1468
+ function registerStoryboardFunctions(functions, app) {
1469
+ if (app) {
1470
+ Object.assign(builtinSupply, {
1471
+ I18N: i18next.getFixedT(null, getI18nNamespace("app", app.id)),
1472
+ IMG: imagesFactory(app.id, app.isBuildPush)
1473
+ });
1474
+ }
1475
+
1409
1476
  registeredFunctions.clear();
1410
1477
 
1411
1478
  if (Array.isArray(functions)) {
@@ -1445,10 +1512,7 @@
1445
1512
  rules: {
1446
1513
  noVar: true
1447
1514
  },
1448
- globalVariables: supply(precooked.attemptToVisitGlobals, {
1449
- // Functions can call other functions.
1450
- FN: storyboardFunctions
1451
- }),
1515
+ globalVariables: supply(precooked.attemptToVisitGlobals, builtinSupply),
1452
1516
  hooks: collector && {
1453
1517
  beforeEvaluate: collector.beforeEvaluate,
1454
1518
  beforeCall: collector.beforeCall,
@@ -1473,6 +1537,19 @@
1473
1537
  };
1474
1538
  }
1475
1539
 
1540
+ function fakeI18nText(data) {
1541
+ return data === null || data === void 0 ? void 0 : data.en;
1542
+ }
1543
+
1544
+ function fakeImageFactory() {
1545
+ return {
1546
+ get(name) {
1547
+ return "mock/images/".concat(name);
1548
+ }
1549
+
1550
+ };
1551
+ }
1552
+
1476
1553
  var {
1477
1554
  storyboardFunctions,
1478
1555
  registerStoryboardFunctions
@@ -1494,7 +1571,9 @@
1494
1571
  var {
1495
1572
  storyboardFunctions,
1496
1573
  registerStoryboardFunctions
1497
- } = StoryboardFunctionRegistryFactory();
1574
+ } = StoryboardFunctionRegistryFactory({
1575
+ widgetId
1576
+ });
1498
1577
  widgetFunctionRegistry.set(widgetId, storyboardFunctions);
1499
1578
  registerStoryboardFunctions(functions);
1500
1579
  }
@@ -1665,7 +1744,7 @@
1665
1744
  }
1666
1745
 
1667
1746
  if (attemptToVisitGlobals.has("IMG")) {
1668
- globalVariables.IMG = imagesFactory(app);
1747
+ globalVariables.IMG = imagesFactory(app.id, app.isBuildPush);
1669
1748
  }
1670
1749
 
1671
1750
  if (attemptToVisitGlobals.has("__WIDGET_IMG__")) {
@@ -1673,7 +1752,11 @@
1673
1752
  }
1674
1753
 
1675
1754
  if (attemptToVisitGlobals.has("I18N")) {
1676
- globalVariables.I18N = i18next__default["default"].getFixedT(null, "$app-".concat(app.id));
1755
+ globalVariables.I18N = i18next__default["default"].getFixedT(null, getI18nNamespace("app", app.id));
1756
+ }
1757
+
1758
+ if (attemptToVisitGlobals.has("__WIDGET_I18N__")) {
1759
+ globalVariables.__WIDGET_I18N__ = widgetI18nFactory;
1677
1760
  }
1678
1761
 
1679
1762
  if (attemptToVisitGlobals.has("I18N_TEXT")) {
@@ -2465,6 +2548,8 @@
2465
2548
 
2466
2549
  _defineProperty__default["default"](this, "registerWidgetFunctions", registerWidgetFunctions);
2467
2550
 
2551
+ _defineProperty__default["default"](this, "registerWidgetI18n", registerWidgetI18n);
2552
+
2468
2553
  _defineProperty__default["default"](this, "getBasePath", getBasePath);
2469
2554
 
2470
2555
  _defineProperty__default["default"](this, "getCurrentTheme", getCurrentTheme);
@@ -6326,7 +6411,7 @@
6326
6411
 
6327
6412
  if ((_storyboard$meta = storyboard.meta) !== null && _storyboard$meta !== void 0 && _storyboard$meta.i18n) {
6328
6413
  // Prefix to avoid conflict between brick package's i18n namespace.
6329
- var i18nNamespace = "$app-".concat(storyboard.app.id); // Support any language in `meta.i18n`.
6414
+ var i18nNamespace = getI18nNamespace("app", storyboard.app.id); // Support any language in `meta.i18n`.
6330
6415
 
6331
6416
  Object.entries(storyboard.meta.i18n).forEach(_ref => {
6332
6417
  var [lang, resources] = _ref;
@@ -8976,12 +9061,13 @@
8976
9061
  } else {
8977
9062
  var actualArgs = args ? ref ? args // `args` are already computed for `defineResolves`
8978
9063
  : context ? computeRealValue(args, context, true) : args : providerBrick.args || [];
9064
+ promise = _asyncToGenerator__default["default"](function* () {
9065
+ if (useProvider) {
9066
+ actualArgs = yield getArgsOfCustomApi(useProvider, actualArgs);
9067
+ }
8979
9068
 
8980
- if (useProvider) {
8981
- actualArgs = yield getArgsOfCustomApi(useProvider, actualArgs);
8982
- }
8983
-
8984
- promise = providerBrick[method](...actualArgs);
9069
+ return providerBrick[method](...actualArgs);
9070
+ })();
8985
9071
 
8986
9072
  _this2.cache.set(cacheKey, promise);
8987
9073
  }
@@ -9049,7 +9135,7 @@
9049
9135
 
9050
9136
  var _loop = function (providerBrick, interval) {
9051
9137
  var request = /*#__PURE__*/function () {
9052
- var _ref = _asyncToGenerator__default["default"](function* () {
9138
+ var _ref2 = _asyncToGenerator__default["default"](function* () {
9053
9139
  yield providerBrick.$refresh({
9054
9140
  ignoreErrors: interval.ignoreErrors,
9055
9141
  throwErrors: true,
@@ -9063,7 +9149,7 @@
9063
9149
  });
9064
9150
 
9065
9151
  return function request() {
9066
- return _ref.apply(this, arguments);
9152
+ return _ref2.apply(this, arguments);
9067
9153
  };
9068
9154
  }();
9069
9155
 
@@ -9305,7 +9391,7 @@
9305
9391
 
9306
9392
  _this3.kernel.registerCustomTemplatesInStoryboard(storyboard);
9307
9393
 
9308
- registerStoryboardFunctions((_storyboard$meta = storyboard.meta) === null || _storyboard$meta === void 0 ? void 0 : _storyboard$meta.functions);
9394
+ registerStoryboardFunctions((_storyboard$meta = storyboard.meta) === null || _storyboard$meta === void 0 ? void 0 : _storyboard$meta.functions, storyboard.app);
9309
9395
  }
9310
9396
 
9311
9397
  var {
@@ -9631,33 +9717,6 @@
9631
9717
  return runtime;
9632
9718
  }
9633
9719
 
9634
- var locale$7 = {
9635
- [K.REQUEST_FAILED]: "Request Failed",
9636
- [K.MODAL_OK]: "Ok",
9637
- [K.MODAL_CANCEL]: "Cancel",
9638
- [K.SOMETHING_WENT_WRONG]: "Something went wrong!",
9639
- [K.LOGIN_TIMEOUT_MESSAGE]: "You haven't logged in or your login session has expired. Login right now?",
9640
- [K.NETWORK_ERROR]: "Network error, please check your network."
9641
- };
9642
- var en = locale$7;
9643
-
9644
- var locale$6 = {
9645
- [K.REQUEST_FAILED]: "请求失败",
9646
- [K.MODAL_OK]: "确认",
9647
- [K.MODAL_CANCEL]: "取消",
9648
- [K.SOMETHING_WENT_WRONG]: "出现了一些问题!",
9649
- [K.LOGIN_TIMEOUT_MESSAGE]: "您还未登录或登录信息已过期,现在重新登录?",
9650
- [K.NETWORK_ERROR]: "网络错误,请检查您的网络连接。"
9651
- };
9652
- var zh = locale$6;
9653
-
9654
- /** @internal */
9655
-
9656
- var initI18n = () => {
9657
- i18next__default["default"].addResourceBundle("en", NS_BRICK_KIT, en);
9658
- i18next__default["default"].addResourceBundle("zh", NS_BRICK_KIT, zh);
9659
- };
9660
-
9661
9720
  // Ref https://reactjs.org/docs/error-boundaries.html
9662
9721
  class LegacyErrorBoundary extends React__default["default"].Component {
9663
9722
  constructor(props) {