@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/dist/index.esm.js CHANGED
@@ -5,10 +5,10 @@ import _asyncToGenerator$4 from '@babel/runtime/helpers/asyncToGenerator';
5
5
  import _defineProperty$2 from '@babel/runtime/helpers/defineProperty';
6
6
  import * as React from 'react';
7
7
  import React__default, { useState, useEffect, forwardRef, useRef, useImperativeHandle, useMemo, useContext, createContext } from 'react';
8
- import lodash, { set, get, difference, cloneDeep, isNil, sortBy, merge, clamp, uniqueId, orderBy, omit, isEmpty } from 'lodash';
8
+ import lodash, { set, get, difference, identity, cloneDeep, isNil, sortBy, merge, clamp, uniqueId, orderBy, omit, isEmpty } from 'lodash';
9
9
  import { toPath, computeRealRoutePath, hasOwnProperty, isObject, isEvaluable, transformAndInject, transform, trackContext, scanPermissionActionsInStoryboard, precookFunction, cook, shouldAllowRecursiveEvaluations, preevaluate, inject, deepFreeze, createProviderClass, scanRouteAliasInStoryboard, loadScript, getTemplateDepsOfStoryboard, getDllAndDepsOfStoryboard, asyncProcessStoryboard, prefetchScript, scanBricksInBrickConf, scanProcessorsInAny, getDllAndDepsByResource, resolveContextConcurrently, matchPath, asyncProcessBrick, restoreDynamicTemplates, mapCustomApisToNameAndNamespace, scanCustomApisInStoryboard } from '@next-core/brick-utils';
10
10
  import { http, HttpResponseError, HttpFetchError } from '@next-core/brick-http';
11
- import i18next from 'i18next';
11
+ import i18next, { getFixedT } from 'i18next';
12
12
  import moment from 'moment';
13
13
  import { pipes } from '@next-core/pipes';
14
14
  import { userAnalytics, apiAnalyzer } from '@next-core/easyops-analytics';
@@ -668,12 +668,12 @@ function getUrlBySegueFactory(app, segues) {
668
668
  };
669
669
  }
670
670
 
671
- function imagesFactory(app) {
671
+ function imagesFactory(appId, isBuildPush) {
672
672
  return {
673
673
  get(name) {
674
674
  var _window$PUBLIC_ROOT;
675
675
 
676
- 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);
676
+ 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);
677
677
  }
678
678
 
679
679
  };
@@ -1372,11 +1372,55 @@ function i18nText(data) {
1372
1372
  }
1373
1373
  }
1374
1374
 
1375
+ var locale$7 = {
1376
+ [K.REQUEST_FAILED]: "Request Failed",
1377
+ [K.MODAL_OK]: "Ok",
1378
+ [K.MODAL_CANCEL]: "Cancel",
1379
+ [K.SOMETHING_WENT_WRONG]: "Something went wrong!",
1380
+ [K.LOGIN_TIMEOUT_MESSAGE]: "You haven't logged in or your login session has expired. Login right now?",
1381
+ [K.NETWORK_ERROR]: "Network error, please check your network."
1382
+ };
1383
+ var en = locale$7;
1384
+
1385
+ var locale$6 = {
1386
+ [K.REQUEST_FAILED]: "请求失败",
1387
+ [K.MODAL_OK]: "确认",
1388
+ [K.MODAL_CANCEL]: "取消",
1389
+ [K.SOMETHING_WENT_WRONG]: "出现了一些问题!",
1390
+ [K.LOGIN_TIMEOUT_MESSAGE]: "您还未登录或登录信息已过期,现在重新登录?",
1391
+ [K.NETWORK_ERROR]: "网络错误,请检查您的网络连接。"
1392
+ };
1393
+ var zh = locale$6;
1394
+
1395
+ /** @internal */
1396
+
1397
+ var initI18n = () => {
1398
+ i18next.addResourceBundle("en", NS_BRICK_KIT, en);
1399
+ i18next.addResourceBundle("zh", NS_BRICK_KIT, zh);
1400
+ };
1401
+ /** @internal */
1402
+
1403
+ function getI18nNamespace(type, id) {
1404
+ return "$".concat(type, "-").concat(id);
1405
+ }
1406
+
1407
+ function registerWidgetI18n(widgetId, i18n) {
1408
+ var ns = getI18nNamespace("widget", widgetId);
1409
+ Object.entries(i18n).forEach(_ref => {
1410
+ var [lang, resources] = _ref;
1411
+ i18next.addResourceBundle(lang, ns, resources);
1412
+ });
1413
+ }
1414
+ function widgetI18nFactory(widgetId) {
1415
+ return getFixedT(null, getI18nNamespace("widget", widgetId));
1416
+ }
1417
+
1375
1418
  /** @internal */
1376
1419
 
1377
1420
  /** @internal */
1378
1421
  function StoryboardFunctionRegistryFactory() {
1379
1422
  var {
1423
+ widgetId,
1380
1424
  collectCoverage
1381
1425
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1382
1426
  var registeredFunctions = new Map(); // Use `Proxy` with a frozen target, to make a readonly function registry.
@@ -1388,7 +1432,30 @@ function StoryboardFunctionRegistryFactory() {
1388
1432
 
1389
1433
  });
1390
1434
 
1391
- function registerStoryboardFunctions(functions) {
1435
+ var builtinSupply = _objectSpread({
1436
+ // Functions can call other functions.
1437
+ FN: storyboardFunctions
1438
+ }, collectCoverage ? {
1439
+ // Fake builtin methods for tests.
1440
+ I18N: identity,
1441
+ I18N_TEXT: fakeI18nText,
1442
+ IMG: fakeImageFactory()
1443
+ } : widgetId ? {
1444
+ I18N: widgetI18nFactory(widgetId),
1445
+ I18N_TEXT: i18nText,
1446
+ IMG: widgetImagesFactory(widgetId)
1447
+ } : {
1448
+ I18N_TEXT: i18nText
1449
+ });
1450
+
1451
+ function registerStoryboardFunctions(functions, app) {
1452
+ if (app) {
1453
+ Object.assign(builtinSupply, {
1454
+ I18N: getFixedT(null, getI18nNamespace("app", app.id)),
1455
+ IMG: imagesFactory(app.id, app.isBuildPush)
1456
+ });
1457
+ }
1458
+
1392
1459
  registeredFunctions.clear();
1393
1460
 
1394
1461
  if (Array.isArray(functions)) {
@@ -1428,10 +1495,7 @@ function StoryboardFunctionRegistryFactory() {
1428
1495
  rules: {
1429
1496
  noVar: true
1430
1497
  },
1431
- globalVariables: supply(precooked.attemptToVisitGlobals, {
1432
- // Functions can call other functions.
1433
- FN: storyboardFunctions
1434
- }),
1498
+ globalVariables: supply(precooked.attemptToVisitGlobals, builtinSupply),
1435
1499
  hooks: collector && {
1436
1500
  beforeEvaluate: collector.beforeEvaluate,
1437
1501
  beforeCall: collector.beforeCall,
@@ -1456,6 +1520,19 @@ function StoryboardFunctionRegistryFactory() {
1456
1520
  };
1457
1521
  }
1458
1522
 
1523
+ function fakeI18nText(data) {
1524
+ return data === null || data === void 0 ? void 0 : data.en;
1525
+ }
1526
+
1527
+ function fakeImageFactory() {
1528
+ return {
1529
+ get(name) {
1530
+ return "mock/images/".concat(name);
1531
+ }
1532
+
1533
+ };
1534
+ }
1535
+
1459
1536
  var {
1460
1537
  storyboardFunctions,
1461
1538
  registerStoryboardFunctions
@@ -1477,7 +1554,9 @@ function registerWidgetFunctions(widgetId, functions) {
1477
1554
  var {
1478
1555
  storyboardFunctions,
1479
1556
  registerStoryboardFunctions
1480
- } = StoryboardFunctionRegistryFactory();
1557
+ } = StoryboardFunctionRegistryFactory({
1558
+ widgetId
1559
+ });
1481
1560
  widgetFunctionRegistry.set(widgetId, storyboardFunctions);
1482
1561
  registerStoryboardFunctions(functions);
1483
1562
  }
@@ -1648,7 +1727,7 @@ function evaluate(raw) {
1648
1727
  }
1649
1728
 
1650
1729
  if (attemptToVisitGlobals.has("IMG")) {
1651
- globalVariables.IMG = imagesFactory(app);
1730
+ globalVariables.IMG = imagesFactory(app.id, app.isBuildPush);
1652
1731
  }
1653
1732
 
1654
1733
  if (attemptToVisitGlobals.has("__WIDGET_IMG__")) {
@@ -1656,7 +1735,11 @@ function evaluate(raw) {
1656
1735
  }
1657
1736
 
1658
1737
  if (attemptToVisitGlobals.has("I18N")) {
1659
- globalVariables.I18N = i18next.getFixedT(null, "$app-".concat(app.id));
1738
+ globalVariables.I18N = i18next.getFixedT(null, getI18nNamespace("app", app.id));
1739
+ }
1740
+
1741
+ if (attemptToVisitGlobals.has("__WIDGET_I18N__")) {
1742
+ globalVariables.__WIDGET_I18N__ = widgetI18nFactory;
1660
1743
  }
1661
1744
 
1662
1745
  if (attemptToVisitGlobals.has("I18N_TEXT")) {
@@ -2448,6 +2531,8 @@ class Runtime {
2448
2531
 
2449
2532
  _defineProperty$2(this, "registerWidgetFunctions", registerWidgetFunctions);
2450
2533
 
2534
+ _defineProperty$2(this, "registerWidgetI18n", registerWidgetI18n);
2535
+
2451
2536
  _defineProperty$2(this, "getBasePath", getBasePath);
2452
2537
 
2453
2538
  _defineProperty$2(this, "getCurrentTheme", getCurrentTheme);
@@ -6309,7 +6394,7 @@ class Kernel {
6309
6394
 
6310
6395
  if ((_storyboard$meta = storyboard.meta) !== null && _storyboard$meta !== void 0 && _storyboard$meta.i18n) {
6311
6396
  // Prefix to avoid conflict between brick package's i18n namespace.
6312
- var i18nNamespace = "$app-".concat(storyboard.app.id); // Support any language in `meta.i18n`.
6397
+ var i18nNamespace = getI18nNamespace("app", storyboard.app.id); // Support any language in `meta.i18n`.
6313
6398
 
6314
6399
  Object.entries(storyboard.meta.i18n).forEach(_ref => {
6315
6400
  var [lang, resources] = _ref;
@@ -8959,12 +9044,13 @@ class Resolver {
8959
9044
  } else {
8960
9045
  var actualArgs = args ? ref ? args // `args` are already computed for `defineResolves`
8961
9046
  : context ? computeRealValue(args, context, true) : args : providerBrick.args || [];
9047
+ promise = _asyncToGenerator$4(function* () {
9048
+ if (useProvider) {
9049
+ actualArgs = yield getArgsOfCustomApi(useProvider, actualArgs);
9050
+ }
8962
9051
 
8963
- if (useProvider) {
8964
- actualArgs = yield getArgsOfCustomApi(useProvider, actualArgs);
8965
- }
8966
-
8967
- promise = providerBrick[method](...actualArgs);
9052
+ return providerBrick[method](...actualArgs);
9053
+ })();
8968
9054
 
8969
9055
  _this2.cache.set(cacheKey, promise);
8970
9056
  }
@@ -9032,7 +9118,7 @@ class Resolver {
9032
9118
 
9033
9119
  var _loop = function (providerBrick, interval) {
9034
9120
  var request = /*#__PURE__*/function () {
9035
- var _ref = _asyncToGenerator$4(function* () {
9121
+ var _ref2 = _asyncToGenerator$4(function* () {
9036
9122
  yield providerBrick.$refresh({
9037
9123
  ignoreErrors: interval.ignoreErrors,
9038
9124
  throwErrors: true,
@@ -9046,7 +9132,7 @@ class Resolver {
9046
9132
  });
9047
9133
 
9048
9134
  return function request() {
9049
- return _ref.apply(this, arguments);
9135
+ return _ref2.apply(this, arguments);
9050
9136
  };
9051
9137
  }();
9052
9138
 
@@ -9288,7 +9374,7 @@ class Router {
9288
9374
 
9289
9375
  _this3.kernel.registerCustomTemplatesInStoryboard(storyboard);
9290
9376
 
9291
- registerStoryboardFunctions((_storyboard$meta = storyboard.meta) === null || _storyboard$meta === void 0 ? void 0 : _storyboard$meta.functions);
9377
+ registerStoryboardFunctions((_storyboard$meta = storyboard.meta) === null || _storyboard$meta === void 0 ? void 0 : _storyboard$meta.functions, storyboard.app);
9292
9378
  }
9293
9379
 
9294
9380
  var {
@@ -9614,33 +9700,6 @@ function getRuntime() {
9614
9700
  return runtime;
9615
9701
  }
9616
9702
 
9617
- var locale$7 = {
9618
- [K.REQUEST_FAILED]: "Request Failed",
9619
- [K.MODAL_OK]: "Ok",
9620
- [K.MODAL_CANCEL]: "Cancel",
9621
- [K.SOMETHING_WENT_WRONG]: "Something went wrong!",
9622
- [K.LOGIN_TIMEOUT_MESSAGE]: "You haven't logged in or your login session has expired. Login right now?",
9623
- [K.NETWORK_ERROR]: "Network error, please check your network."
9624
- };
9625
- var en = locale$7;
9626
-
9627
- var locale$6 = {
9628
- [K.REQUEST_FAILED]: "请求失败",
9629
- [K.MODAL_OK]: "确认",
9630
- [K.MODAL_CANCEL]: "取消",
9631
- [K.SOMETHING_WENT_WRONG]: "出现了一些问题!",
9632
- [K.LOGIN_TIMEOUT_MESSAGE]: "您还未登录或登录信息已过期,现在重新登录?",
9633
- [K.NETWORK_ERROR]: "网络错误,请检查您的网络连接。"
9634
- };
9635
- var zh = locale$6;
9636
-
9637
- /** @internal */
9638
-
9639
- var initI18n = () => {
9640
- i18next.addResourceBundle("en", NS_BRICK_KIT, en);
9641
- i18next.addResourceBundle("zh", NS_BRICK_KIT, zh);
9642
- };
9643
-
9644
9703
  // Ref https://reactjs.org/docs/error-boundaries.html
9645
9704
  class LegacyErrorBoundary extends React__default.Component {
9646
9705
  constructor(props) {