@next-core/brick-kit 2.132.2 → 2.133.2

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
@@ -1586,6 +1586,7 @@ function getIndividualGlobal(variableName, _ref) {
1586
1586
  collectCoverage,
1587
1587
  widgetId,
1588
1588
  app,
1589
+ appendI18nNamespace,
1589
1590
  storyboardFunctions,
1590
1591
  isStoryboardFunction
1591
1592
  } = _ref;
@@ -1601,7 +1602,7 @@ function getIndividualGlobal(variableName, _ref) {
1601
1602
  return collectCoverage ? fakeImageFactory() : widgetId ? widgetImagesFactory(widgetId) : imagesFactory(app.id, app.isBuildPush);
1602
1603
 
1603
1604
  case "I18N":
1604
- return collectCoverage ? identity : widgetId ? widgetI18nFactory(widgetId) : getFixedT(null, getI18nNamespace("app", app.id));
1605
+ return collectCoverage ? identity : widgetId ? widgetI18nFactory(widgetId) : getFixedT(null, [appendI18nNamespace, getI18nNamespace("app", app.id)].filter(Boolean));
1605
1606
 
1606
1607
  case "I18N_TEXT":
1607
1608
  return collectCoverage ? fakeI18nText : i18nText;
@@ -2581,7 +2582,8 @@ function evaluate(raw) {
2581
2582
 
2582
2583
  Object.assign(globalVariables, getGeneralGlobals(precooked.attemptToVisitGlobals, {
2583
2584
  storyboardFunctions,
2584
- app
2585
+ app,
2586
+ appendI18nNamespace: runtimeContext.appendI18nNamespace
2585
2587
  }));
2586
2588
 
2587
2589
  try {
@@ -2896,7 +2898,7 @@ var computeRealValue = (value, context, injectDeep, internalOptions) => {
2896
2898
 
2897
2899
  if (preEvaluated || isEvaluable(value)) {
2898
2900
  var runtimeContext = {};
2899
- var keys = ["event", "tplContextId", "overrideApp"];
2901
+ var keys = ["event", "tplContextId", "overrideApp", "appendI18nNamespace"];
2900
2902
 
2901
2903
  for (var key of keys) {
2902
2904
  if (context !== null && context !== void 0 && context[key]) {
@@ -3018,6 +3020,7 @@ var _excluded$6 = ["children"],
3018
3020
  _excluded2$2 = ["children"],
3019
3021
  _excluded3 = ["items", "app"];
3020
3022
  var symbolAppId = Symbol("appId");
3023
+ var symbolMenuI18nNamespace = Symbol("menuI18nNamespace");
3021
3024
  // Caching menu requests to avoid flicker.
3022
3025
  var menuCache = new Map();
3023
3026
  var menuTitleCache = new Map();
@@ -3091,6 +3094,7 @@ function _fetchMenuById() {
3091
3094
  dynamicItems: true,
3092
3095
  itemsResolve: true,
3093
3096
  items: true,
3097
+ i18n: true,
3094
3098
  "items.children": true,
3095
3099
  "app.appId": true
3096
3100
  },
@@ -3128,10 +3132,23 @@ function mergeMenu(menuList) {
3128
3132
 
3129
3133
  var validMenuList = [];
3130
3134
  var injectWithMenus = new Map();
3135
+ var menuWithI18n = new WeakMap();
3131
3136
 
3132
3137
  for (var menu of menuList) {
3133
3138
  var _menu$items;
3134
3139
 
3140
+ if (menu.i18n) {
3141
+ (function () {
3142
+ var menuI18nNamespace = getI18nNamespace("menu", "".concat(menu.menuId, "~").concat(menu.app[0].appId, "+").concat(menu.instanceId)); // Support any language in `meta.i18n`.
3143
+
3144
+ Object.entries(menu.i18n).forEach(_ref => {
3145
+ var [lang, resources] = _ref;
3146
+ i18next.addResourceBundle(lang, menuI18nNamespace, resources);
3147
+ });
3148
+ menuWithI18n.set(menu, menuI18nNamespace);
3149
+ })();
3150
+ }
3151
+
3135
3152
  if (((_menu$items = menu.items) === null || _menu$items === void 0 ? void 0 : _menu$items.length) > 0) {
3136
3153
  if (menu.type === "inject" && menu.injectMenuGroupId) {
3137
3154
  var injectingMenus = injectWithMenus.get(menu.injectMenuGroupId);
@@ -3149,11 +3166,12 @@ function mergeMenu(menuList) {
3149
3166
  }
3150
3167
 
3151
3168
  return _objectSpread(_objectSpread({}, mainMenu), {}, {
3152
- items: validMenuList.flatMap(menu => processGroupInject(menu.items, menu, injectWithMenus))
3169
+ items: validMenuList.flatMap(menu => processGroupInject(menu.items, menu, injectWithMenus, menuWithI18n)),
3170
+ [symbolMenuI18nNamespace]: menuWithI18n.get(mainMenu)
3153
3171
  });
3154
3172
  }
3155
3173
 
3156
- function processGroupInject(items, menu, injectWithMenus) {
3174
+ function processGroupInject(items, menu, injectWithMenus, menuWithI18n) {
3157
3175
  return items === null || items === void 0 ? void 0 : items.map(item => {
3158
3176
  var _processGroupInject;
3159
3177
 
@@ -3165,8 +3183,9 @@ function processGroupInject(items, menu, injectWithMenus) {
3165
3183
  }
3166
3184
 
3167
3185
  return _objectSpread(_objectSpread({}, item), {}, {
3168
- children: ((_processGroupInject = processGroupInject(item.children, menu, injectWithMenus)) !== null && _processGroupInject !== void 0 ? _processGroupInject : []).concat(foundInjectingMenus ? foundInjectingMenus.flatMap(injectingMenu => processGroupInject(injectingMenu.items, injectingMenu, injectWithMenus)) : []),
3169
- [symbolAppId]: menu.app[0].appId
3186
+ children: ((_processGroupInject = processGroupInject(item.children, menu, injectWithMenus, menuWithI18n)) !== null && _processGroupInject !== void 0 ? _processGroupInject : []).concat(foundInjectingMenus ? foundInjectingMenus.flatMap(injectingMenu => processGroupInject(injectingMenu.items, injectingMenu, injectWithMenus, menuWithI18n)) : []),
3187
+ [symbolAppId]: menu.app[0].appId,
3188
+ [symbolMenuI18nNamespace]: menuWithI18n.get(menu)
3170
3189
  });
3171
3190
  });
3172
3191
  }
@@ -3202,10 +3221,17 @@ function _processMenu() {
3202
3221
  } = _yield$fetchMenuById,
3203
3222
  restMenuData = _objectWithoutProperties(_yield$fetchMenuById, _excluded3);
3204
3223
 
3205
- var appIds = collectOverrideApps(items, app[0].appId, context.app.id);
3206
- yield kernel.fulfilStoryboardI18n(appIds);
3224
+ var appsRequireI18nFulfilled = new Set();
3225
+ var rootAppId = app[0].appId;
3226
+
3227
+ if (rootAppId !== context.app.id && !restMenuData[symbolMenuI18nNamespace]) {
3228
+ appsRequireI18nFulfilled.add(rootAppId);
3229
+ }
3230
+
3231
+ collectAppsRequireI18nFulfilled(items, context.app.id, appsRequireI18nFulfilled);
3232
+ yield kernel.fulfilStoryboardI18n([...appsRequireI18nFulfilled]);
3207
3233
 
3208
- var menuData = _objectSpread(_objectSpread({}, computeRealValueWithOverrideApp(restMenuData, app[0].appId, context, kernel)), {}, {
3234
+ var menuData = _objectSpread(_objectSpread({}, computeRealValueWithOverrideApp(restMenuData, rootAppId, context, kernel)), {}, {
3209
3235
  items: computeMenuItemsWithOverrideApp(items, context, kernel)
3210
3236
  });
3211
3237
 
@@ -3238,23 +3264,17 @@ function _processMenu() {
3238
3264
  return _processMenu.apply(this, arguments);
3239
3265
  }
3240
3266
 
3241
- function collectOverrideApps(items, rootAppId, contextAppId) {
3242
- var appIds = new Set();
3243
-
3244
- if (rootAppId !== contextAppId) {
3245
- appIds.add(rootAppId);
3246
- }
3247
-
3267
+ function collectAppsRequireI18nFulfilled(items, contextAppId, appIds) {
3248
3268
  function collect(items) {
3249
- for (var _ref of items) {
3269
+ for (var _ref2 of items) {
3250
3270
  var {
3251
3271
  children
3252
- } = _ref,
3253
- rest = _objectWithoutProperties(_ref, _excluded$6);
3272
+ } = _ref2,
3273
+ rest = _objectWithoutProperties(_ref2, _excluded$6);
3254
3274
 
3255
3275
  var overrideAppId = rest[symbolAppId];
3256
3276
 
3257
- if (overrideAppId !== contextAppId && !appIds.has(overrideAppId) && requireOverrideApp(rest)) {
3277
+ if (!rest[symbolMenuI18nNamespace] && overrideAppId !== contextAppId && !appIds.has(overrideAppId) && attemptToVisit(rest, ["I18N"])) {
3258
3278
  appIds.add(overrideAppId);
3259
3279
  }
3260
3280
 
@@ -3263,15 +3283,14 @@ function collectOverrideApps(items, rootAppId, contextAppId) {
3263
3283
  }
3264
3284
 
3265
3285
  collect(items);
3266
- return [...appIds];
3267
3286
  }
3268
3287
 
3269
3288
  function computeMenuItemsWithOverrideApp(items, context, kernel) {
3270
- return items.map(_ref2 => {
3289
+ return items.map(_ref3 => {
3271
3290
  var {
3272
3291
  children
3273
- } = _ref2,
3274
- rest = _objectWithoutProperties(_ref2, _excluded2$2);
3292
+ } = _ref3,
3293
+ rest = _objectWithoutProperties(_ref3, _excluded2$2);
3275
3294
 
3276
3295
  return _objectSpread(_objectSpread({}, computeRealValueWithOverrideApp(rest, rest[symbolAppId], context, kernel)), {}, {
3277
3296
  children: children && computeMenuItemsWithOverrideApp(children, context, kernel)
@@ -3339,25 +3358,24 @@ function sortMenuItems(list) {
3339
3358
  return (_item$sort = item.sort) !== null && _item$sort !== void 0 ? _item$sort : -Infinity;
3340
3359
  });
3341
3360
  }
3342
-
3343
- var overriddenGlobals = ["APP", "I18N"];
3344
3361
  /**
3345
3362
  * If the menu contains evaluations which use `APP` or `I18N`,
3346
3363
  * we have to override app in context when computing real values.
3347
3364
  */
3348
3365
 
3349
- function requireOverrideApp(data) {
3350
- var memo = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new WeakSet();
3366
+
3367
+ function attemptToVisit(data, globals) {
3368
+ var memo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new WeakSet();
3351
3369
 
3352
3370
  if (typeof data === "string") {
3353
3371
  if (isEvaluable(data)) {
3354
- if (overriddenGlobals.some(key => data.includes(key))) {
3372
+ if (globals.some(key => data.includes(key))) {
3355
3373
  var {
3356
3374
  attemptToVisitGlobals
3357
3375
  } = preevaluate(data);
3358
- return overriddenGlobals.some(key => attemptToVisitGlobals.has(key));
3376
+ return globals.some(key => attemptToVisitGlobals.has(key));
3359
3377
  }
3360
- } else {
3378
+ } else if (globals.includes("APP")) {
3361
3379
  return /\${\s*APP\s*\./.test(data);
3362
3380
  }
3363
3381
  } else if (isObject(data)) {
@@ -3368,7 +3386,7 @@ function requireOverrideApp(data) {
3368
3386
  }
3369
3387
 
3370
3388
  memo.add(data);
3371
- return (Array.isArray(data) ? data : Object.values(data)).some(item => requireOverrideApp(item, memo));
3389
+ return (Array.isArray(data) ? data : Object.values(data)).some(item => attemptToVisit(item, globals, memo));
3372
3390
  }
3373
3391
 
3374
3392
  return false;
@@ -3377,13 +3395,18 @@ function requireOverrideApp(data) {
3377
3395
  function computeRealValueWithOverrideApp(data, overrideAppId, context, kernel) {
3378
3396
  var newContext = context;
3379
3397
 
3380
- if (overrideAppId !== context.app.id && requireOverrideApp(data)) {
3398
+ if (overrideAppId !== context.app.id && attemptToVisit(data, ["APP", "I18N"])) {
3381
3399
  var storyboard = kernel.bootstrapData.storyboards.find(story => story.app.id === overrideAppId);
3400
+ /* istanbul ignore else: non-productive case */
3382
3401
 
3383
3402
  if (storyboard) {
3384
3403
  newContext = _objectSpread(_objectSpread({}, context), {}, {
3385
- overrideApp: storyboard.app
3404
+ overrideApp: storyboard.app,
3405
+ appendI18nNamespace: data[symbolMenuI18nNamespace]
3386
3406
  });
3407
+ } else {
3408
+ // eslint-disable-next-line no-console
3409
+ console.error("The app which injects menu was not found:", overrideAppId);
3387
3410
  }
3388
3411
  }
3389
3412