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