datastake-daf 0.6.100 → 0.6.102
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/components/index.css +1 -1
- package/dist/components/index.js +2722 -226
- package/package.json +1 -1
- package/rollup.config.js +41 -83
- package/src/@daf/core/components/Dashboard/Map/helper.js +434 -439
- package/src/@daf/core/components/Dashboard/Map/storyConfig1.js +230 -233
- package/src/@daf/core/components/EditForm/components/AjaxSubGroup/index.js +0 -2
- package/src/@daf/core/components/PdfForm/components/AjaxSubGroup.js +106 -0
- package/src/@daf/core/components/PdfForm/components/ajaxSubGroupHandler.js +12 -0
- package/src/@daf/core/components/PdfForm/components/dataLinkGroupHandler.js +24 -15
- package/src/@daf/core/components/PdfForm/components/dataLinkHandler.js +51 -17
- package/src/@daf/core/components/PdfForm/index.js +208 -22
- package/src/@daf/core/components/PdfForm/storyConfig.js +464 -163
- package/src/@daf/core/components/PdfForm/style.scss +145 -3
- package/src/@daf/core/components/PdfForm/utils/fieldData.js +82 -3
- package/src/@daf/core/components/PdfForm/utils/fieldRenderer.js +14 -6
- package/src/helpers/Map.js +6 -82
- package/src/styles/_index.scss +1 -1
- package/src/styles/datastake.scss +4454 -1
- package/.vscode/settings.json +0 -13
- package/dist/style/datastake/_index.css +0 -5
- package/dist/style/datastake/datastake.css +0 -5081
- package/dist/style/datastake/fonts/Outfit-Black.ttf +0 -0
- package/dist/style/datastake/fonts/Outfit-Bold.ttf +0 -0
- package/dist/style/datastake/fonts/Outfit-ExtraBold.ttf +0 -0
- package/dist/style/datastake/fonts/Outfit-ExtraLight.ttf +0 -0
- package/dist/style/datastake/fonts/Outfit-Light.ttf +0 -0
- package/dist/style/datastake/fonts/Outfit-Medium.ttf +0 -0
- package/dist/style/datastake/fonts/Outfit-Regular.ttf +0 -0
- package/dist/style/datastake/fonts/Outfit-SemiBold.ttf +0 -0
- package/dist/style/datastake/fonts/Outfit-Thin.ttf +0 -0
- package/dist/style/datastake/fonts/outfit.css +0 -62
- package/dist/style/datastake/fonts/sf-ui-display-black-58646a6b80d5a.woff +0 -0
- package/dist/style/datastake/fonts/sf-ui-display-bold-58646a511e3d9.woff +0 -0
- package/dist/style/datastake/fonts/sf-ui-display-heavy-586470160b9e5.woff +0 -0
- package/dist/style/datastake/fonts/sf-ui-display-light-58646b33e0551.woff +0 -0
- package/dist/style/datastake/fonts/sf-ui-display-medium-58646be638f96.woff +0 -0
- package/dist/style/datastake/fonts/sf-ui-display-semibold-58646eddcae92.woff +0 -0
- package/dist/style/datastake/fonts/sf-ui-display-thin-58646e9b26e8b.woff +0 -0
- package/dist/style/datastake/fonts/sf-ui-display-ultralight-58646b19bf205.woff +0 -0
- package/dist/style/datastake/fonts/sfDisplay.css +0 -59
- package/dist/style/datastake/leaflet.css +0 -671
- package/dist/style/datastake/leaflet.markercluster.css +0 -60
- package/dist/style/style.css +0 -1
- package/src/styles/datastake/_index.css +0 -5
- package/src/styles/datastake/datastake.css +0 -5081
- package/src/styles/datastake/fonts/Outfit-Black.ttf +0 -0
- package/src/styles/datastake/fonts/Outfit-Bold.ttf +0 -0
- package/src/styles/datastake/fonts/Outfit-ExtraBold.ttf +0 -0
- package/src/styles/datastake/fonts/Outfit-ExtraLight.ttf +0 -0
- package/src/styles/datastake/fonts/Outfit-Light.ttf +0 -0
- package/src/styles/datastake/fonts/Outfit-Medium.ttf +0 -0
- package/src/styles/datastake/fonts/Outfit-Regular.ttf +0 -0
- package/src/styles/datastake/fonts/Outfit-SemiBold.ttf +0 -0
- package/src/styles/datastake/fonts/Outfit-Thin.ttf +0 -0
- package/src/styles/datastake/fonts/outfit.css +0 -62
- package/src/styles/datastake/fonts/sf-ui-display-black-58646a6b80d5a.woff +0 -0
- package/src/styles/datastake/fonts/sf-ui-display-bold-58646a511e3d9.woff +0 -0
- package/src/styles/datastake/fonts/sf-ui-display-heavy-586470160b9e5.woff +0 -0
- package/src/styles/datastake/fonts/sf-ui-display-light-58646b33e0551.woff +0 -0
- package/src/styles/datastake/fonts/sf-ui-display-medium-58646be638f96.woff +0 -0
- package/src/styles/datastake/fonts/sf-ui-display-semibold-58646eddcae92.woff +0 -0
- package/src/styles/datastake/fonts/sf-ui-display-thin-58646e9b26e8b.woff +0 -0
- package/src/styles/datastake/fonts/sf-ui-display-ultralight-58646b19bf205.woff +0 -0
- package/src/styles/datastake/fonts/sfDisplay.css +0 -59
- package/src/styles/datastake/leaflet.css +0 -671
- package/src/styles/datastake/leaflet.markercluster.css +0 -60
package/dist/components/index.js
CHANGED
|
@@ -26,7 +26,6 @@ var deepmerge = require('deepmerge');
|
|
|
26
26
|
var g2plot = require('@antv/g2plot');
|
|
27
27
|
var Tag = require('antd/es/tag');
|
|
28
28
|
var react = require('@xyflow/react');
|
|
29
|
-
var i18next = require('i18next');
|
|
30
29
|
require('leaflet.heat');
|
|
31
30
|
require('leaflet.markercluster');
|
|
32
31
|
var ReactFlow = require('react-flow-renderer');
|
|
@@ -65,7 +64,6 @@ var localeEn__default = /*#__PURE__*/_interopDefaultLegacy(localeEn);
|
|
|
65
64
|
var localeFr__default = /*#__PURE__*/_interopDefaultLegacy(localeFr);
|
|
66
65
|
var deepmerge__default = /*#__PURE__*/_interopDefaultLegacy(deepmerge);
|
|
67
66
|
var Tag__default = /*#__PURE__*/_interopDefaultLegacy(Tag);
|
|
68
|
-
var i18next__default = /*#__PURE__*/_interopDefaultLegacy(i18next);
|
|
69
67
|
var ReactFlow__default = /*#__PURE__*/_interopDefaultLegacy(ReactFlow);
|
|
70
68
|
|
|
71
69
|
function DafTheme(_ref) {
|
|
@@ -3300,15 +3298,15 @@ var versions = {};
|
|
|
3300
3298
|
var release = {};
|
|
3301
3299
|
var config$2 = {};
|
|
3302
3300
|
|
|
3303
|
-
function noop$
|
|
3301
|
+
function noop$2() {}
|
|
3304
3302
|
|
|
3305
|
-
var on = noop$
|
|
3306
|
-
var addListener = noop$
|
|
3307
|
-
var once = noop$
|
|
3308
|
-
var off = noop$
|
|
3309
|
-
var removeListener = noop$
|
|
3310
|
-
var removeAllListeners = noop$
|
|
3311
|
-
var emit = noop$
|
|
3303
|
+
var on = noop$2;
|
|
3304
|
+
var addListener = noop$2;
|
|
3305
|
+
var once = noop$2;
|
|
3306
|
+
var off = noop$2;
|
|
3307
|
+
var removeListener = noop$2;
|
|
3308
|
+
var removeAllListeners = noop$2;
|
|
3309
|
+
var emit = noop$2;
|
|
3312
3310
|
|
|
3313
3311
|
function binding(name) {
|
|
3314
3312
|
throw new Error('process.binding is not supported');
|
|
@@ -3468,7 +3466,7 @@ function isArrayBufferView(val) {
|
|
|
3468
3466
|
*
|
|
3469
3467
|
* @returns {boolean} True if value is a String, otherwise false
|
|
3470
3468
|
*/
|
|
3471
|
-
const isString = typeOfTest('string');
|
|
3469
|
+
const isString$1 = typeOfTest('string');
|
|
3472
3470
|
|
|
3473
3471
|
/**
|
|
3474
3472
|
* Determine if a value is a Function
|
|
@@ -3981,7 +3979,7 @@ const toObjectSet = (arrayOrString, delimiter) => {
|
|
|
3981
3979
|
return obj;
|
|
3982
3980
|
};
|
|
3983
3981
|
|
|
3984
|
-
const noop = () => {};
|
|
3982
|
+
const noop$1 = () => {};
|
|
3985
3983
|
|
|
3986
3984
|
const toFiniteNumber = (value, defaultValue) => {
|
|
3987
3985
|
return value != null && Number.isFinite(value = +value) ? value : defaultValue;
|
|
@@ -4090,7 +4088,7 @@ var utils$1 = {
|
|
|
4090
4088
|
isBuffer: isBuffer$1,
|
|
4091
4089
|
isFormData,
|
|
4092
4090
|
isArrayBufferView,
|
|
4093
|
-
isString,
|
|
4091
|
+
isString: isString$1,
|
|
4094
4092
|
isNumber,
|
|
4095
4093
|
isBoolean,
|
|
4096
4094
|
isObject,
|
|
@@ -4129,7 +4127,7 @@ var utils$1 = {
|
|
|
4129
4127
|
freezeMethods,
|
|
4130
4128
|
toObjectSet,
|
|
4131
4129
|
toCamelCase,
|
|
4132
|
-
noop,
|
|
4130
|
+
noop: noop$1,
|
|
4133
4131
|
toFiniteNumber,
|
|
4134
4132
|
findKey,
|
|
4135
4133
|
global: _global,
|
|
@@ -9227,7 +9225,7 @@ const propHasValue$1 = val => {
|
|
|
9227
9225
|
}
|
|
9228
9226
|
return typeof val !== 'undefined' && val !== null;
|
|
9229
9227
|
};
|
|
9230
|
-
function deepFind(obj, path) {
|
|
9228
|
+
function deepFind$1(obj, path) {
|
|
9231
9229
|
// eslint-disable-next-line no-redeclare
|
|
9232
9230
|
for (var i = 0, path = path.split('.'), len = path.length; i < len; i++) {
|
|
9233
9231
|
if (!obj || !propHasValue$1(obj[path[i]])) {
|
|
@@ -9375,20 +9373,20 @@ function showHideInput$4(input, data, repeatIndex, repeatValues) {
|
|
|
9375
9373
|
field = isRepeatable ? field.split('./')[1] : field;
|
|
9376
9374
|
if (match && field.split('.').length > 1) {
|
|
9377
9375
|
if (input.inputs) {
|
|
9378
|
-
const value = deepFind(formValue, field);
|
|
9376
|
+
const value = deepFind$1(formValue, field);
|
|
9379
9377
|
const isShown = _checkValue$1(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
9380
9378
|
return isShown;
|
|
9381
9379
|
} else {
|
|
9382
9380
|
if (isRepeatable ? !repeatValues : !formsValue) {
|
|
9383
9381
|
return false;
|
|
9384
9382
|
} else {
|
|
9385
|
-
const value = deepFind(formValue, field);
|
|
9383
|
+
const value = deepFind$1(formValue, field);
|
|
9386
9384
|
const isShown = _checkValue$1(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
9387
9385
|
return isShown;
|
|
9388
9386
|
}
|
|
9389
9387
|
}
|
|
9390
9388
|
} else {
|
|
9391
|
-
const value = deepFind(formValue, field);
|
|
9389
|
+
const value = deepFind$1(formValue, field);
|
|
9392
9390
|
if (match === 'gte') {
|
|
9393
9391
|
return Number(formValue[field]) >= Number(wantedValue);
|
|
9394
9392
|
}
|
|
@@ -9531,7 +9529,7 @@ function filterOptions$2(options, filters) {
|
|
|
9531
9529
|
} else {
|
|
9532
9530
|
const pathInsideRepeatValues = path.split('./');
|
|
9533
9531
|
isRepeatable = pathInsideRepeatValues.length > 1;
|
|
9534
|
-
value = deepFind(isRepeatable ? repeatValues : formsValue, pathInsideRepeatValues[pathInsideRepeatValues.length - 1]);
|
|
9532
|
+
value = deepFind$1(isRepeatable ? repeatValues : formsValue, pathInsideRepeatValues[pathInsideRepeatValues.length - 1]);
|
|
9535
9533
|
}
|
|
9536
9534
|
objFilter[name] = {
|
|
9537
9535
|
value,
|
|
@@ -13220,16 +13218,6 @@ const AjaxSelectRenderer = ({
|
|
|
13220
13218
|
});
|
|
13221
13219
|
};
|
|
13222
13220
|
|
|
13223
|
-
const EVENT_COLORS = {
|
|
13224
|
-
MAJOR: "#cf1322",
|
|
13225
|
-
// Red for major incidents
|
|
13226
|
-
MODERATE: "#fa8c16",
|
|
13227
|
-
// Orange for moderate incidents
|
|
13228
|
-
MINOR: "#fadb14",
|
|
13229
|
-
// Yellow for minor incidents
|
|
13230
|
-
CORRECTIVE: "#12b76a" // Green for corrective actions
|
|
13231
|
-
};
|
|
13232
|
-
|
|
13233
13221
|
/**
|
|
13234
13222
|
* Converts a latitude or longitude coordinate to degrees, minutes and seconds.
|
|
13235
13223
|
*
|
|
@@ -13258,71 +13246,14 @@ const toDegreesMinutesAndSeconds = coordinate => {
|
|
|
13258
13246
|
*/
|
|
13259
13247
|
const convertDMS = (lat, lng) => {
|
|
13260
13248
|
const latitude = toDegreesMinutesAndSeconds(lat);
|
|
13261
|
-
const latitudeCardinal = lat >= 0 ?
|
|
13249
|
+
const latitudeCardinal = lat >= 0 ? 'N' : 'S';
|
|
13262
13250
|
const longitude = toDegreesMinutesAndSeconds(lng);
|
|
13263
|
-
const longitudeCardinal = lng >= 0 ?
|
|
13251
|
+
const longitudeCardinal = lng >= 0 ? 'E' : 'W';
|
|
13264
13252
|
return [latitude + '"' + latitudeCardinal, longitude + '"' + longitudeCardinal];
|
|
13265
13253
|
};
|
|
13266
13254
|
const southWest = L__default["default"].latLng(85, -180),
|
|
13267
13255
|
northEast = L__default["default"].latLng(-85, 180),
|
|
13268
13256
|
maxBounds = L__default["default"].latLngBounds(southWest, northEast);
|
|
13269
|
-
const getEventMarkerStyle = data => {
|
|
13270
|
-
const incidents = data?.data || [];
|
|
13271
|
-
const totals = {
|
|
13272
|
-
major: incidents.filter(d => d.type === "major_incident").length,
|
|
13273
|
-
minor: incidents.filter(d => d.type === "minor_incident").length,
|
|
13274
|
-
moderate: incidents.filter(d => d.type === "moderate_incident").length,
|
|
13275
|
-
correctiveActions: incidents.filter(d => d.type === "correctiveActions").length
|
|
13276
|
-
};
|
|
13277
|
-
const total = incidents.length;
|
|
13278
|
-
let background = "#f1f1f1";
|
|
13279
|
-
if (total > 0) {
|
|
13280
|
-
// Build a dynamic array of categories with colors & percentages
|
|
13281
|
-
const categories = [{
|
|
13282
|
-
key: "major",
|
|
13283
|
-
value: totals.major,
|
|
13284
|
-
color: EVENT_COLORS.MAJOR
|
|
13285
|
-
}, {
|
|
13286
|
-
key: "moderate",
|
|
13287
|
-
value: totals.moderate,
|
|
13288
|
-
color: EVENT_COLORS.MODERATE
|
|
13289
|
-
}, {
|
|
13290
|
-
key: "minor",
|
|
13291
|
-
value: totals.minor,
|
|
13292
|
-
color: EVENT_COLORS.MINOR
|
|
13293
|
-
}, {
|
|
13294
|
-
key: "corrective",
|
|
13295
|
-
value: totals.correctiveActions,
|
|
13296
|
-
color: EVENT_COLORS.CORRECTIVE
|
|
13297
|
-
}].filter(c => c.value > 0).map(c => ({
|
|
13298
|
-
...c,
|
|
13299
|
-
perc: c.value / total * 100
|
|
13300
|
-
}));
|
|
13301
|
-
if (categories.length === 1) {
|
|
13302
|
-
background = categories[0].color;
|
|
13303
|
-
} else {
|
|
13304
|
-
const gradientStops = categories.map((cat, index) => {
|
|
13305
|
-
const stop = categories.slice(0, index).reduce((acc, c) => acc + c.perc, 0);
|
|
13306
|
-
return `${cat.color} ${Math.round(stop)}%`;
|
|
13307
|
-
});
|
|
13308
|
-
background = `radial-gradient(circle, ${gradientStops.join(", ")})`;
|
|
13309
|
-
}
|
|
13310
|
-
}
|
|
13311
|
-
let radius = 35;
|
|
13312
|
-
if (data.total > 20) {
|
|
13313
|
-
radius = 65;
|
|
13314
|
-
} else if (data.total > 10) {
|
|
13315
|
-
radius = 50;
|
|
13316
|
-
} else {
|
|
13317
|
-
radius = 40;
|
|
13318
|
-
}
|
|
13319
|
-
return {
|
|
13320
|
-
radius,
|
|
13321
|
-
background,
|
|
13322
|
-
totals,
|
|
13323
|
-
total
|
|
13324
|
-
};
|
|
13325
|
-
};
|
|
13326
13257
|
|
|
13327
13258
|
const Styles$a = dt.div`
|
|
13328
13259
|
display: flex;
|
|
@@ -13523,14 +13454,77 @@ function Geolocation$2({
|
|
|
13523
13454
|
});
|
|
13524
13455
|
}
|
|
13525
13456
|
|
|
13526
|
-
const
|
|
13457
|
+
const evaluateShowIfCondition = (condition, item) => {
|
|
13458
|
+
if (!condition || !item) return false;
|
|
13459
|
+
|
|
13460
|
+
// Handle boolean AND operations
|
|
13461
|
+
if (condition.includes(' && ')) {
|
|
13462
|
+
const andParts = condition.split(' && ');
|
|
13463
|
+
return andParts.every(part => evaluateShowIfCondition(part.trim(), item));
|
|
13464
|
+
}
|
|
13465
|
+
|
|
13466
|
+
// Handle "includes" conditions
|
|
13467
|
+
if (condition.includes(' includes ')) {
|
|
13468
|
+
const parts = condition.split(' includes ');
|
|
13469
|
+
if (parts.length === 2) {
|
|
13470
|
+
const [field, expectedValue] = parts.map(p => p.trim());
|
|
13471
|
+
const fieldValue = item[field];
|
|
13472
|
+
if (Array.isArray(fieldValue)) {
|
|
13473
|
+
return fieldValue.includes(expectedValue);
|
|
13474
|
+
}
|
|
13475
|
+
if (typeof fieldValue === 'string') {
|
|
13476
|
+
return fieldValue.split(',').map(v => v.trim()).includes(expectedValue);
|
|
13477
|
+
}
|
|
13478
|
+
return false;
|
|
13479
|
+
}
|
|
13480
|
+
}
|
|
13481
|
+
|
|
13482
|
+
// Handle "not" conditions
|
|
13483
|
+
if (condition.includes(' not ')) {
|
|
13484
|
+
const parts = condition.split(' not ');
|
|
13485
|
+
if (parts.length === 2) {
|
|
13486
|
+
const [field, expectedValue] = parts.map(p => p.trim());
|
|
13487
|
+
return item[field] !== expectedValue;
|
|
13488
|
+
}
|
|
13489
|
+
}
|
|
13490
|
+
|
|
13491
|
+
// Handle "is" conditions (existing logic)
|
|
13492
|
+
const parts = condition.split(' is ');
|
|
13493
|
+
if (parts.length === 2) {
|
|
13494
|
+
const [field, expectedValue] = parts.map(p => p.trim());
|
|
13495
|
+
return item[field] === expectedValue;
|
|
13496
|
+
}
|
|
13497
|
+
return false;
|
|
13498
|
+
};
|
|
13499
|
+
const processConditionalTableKeys = (tableKeys, item) => {
|
|
13500
|
+
const processedKeys = [];
|
|
13501
|
+
tableKeys.forEach(tableKey => {
|
|
13502
|
+
if (typeof tableKey === 'string') {
|
|
13503
|
+
processedKeys.push(tableKey);
|
|
13504
|
+
} else if (tableKey && typeof tableKey === 'object' && tableKey.content) {
|
|
13505
|
+
tableKey.content.forEach(contentItem => {
|
|
13506
|
+
if (contentItem.key) {
|
|
13507
|
+
if (!contentItem.showIf || evaluateShowIfCondition(contentItem.showIf, item)) {
|
|
13508
|
+
processedKeys.push(contentItem.key);
|
|
13509
|
+
}
|
|
13510
|
+
}
|
|
13511
|
+
});
|
|
13512
|
+
} else if (tableKey && typeof tableKey === 'object' && tableKey.key) {
|
|
13513
|
+
if (!tableKey.showIf || evaluateShowIfCondition(tableKey.showIf, item)) {
|
|
13514
|
+
processedKeys.push(tableKey.key);
|
|
13515
|
+
}
|
|
13516
|
+
}
|
|
13517
|
+
});
|
|
13518
|
+
return processedKeys;
|
|
13519
|
+
};
|
|
13520
|
+
const renderFieldData = (type, value, user, config, getApiBaseUrl = () => {}, getAppHeader = () => {}, app, allValues) => {
|
|
13527
13521
|
switch (type) {
|
|
13528
13522
|
case 'year':
|
|
13529
|
-
return renderDateFormatted(value, 'YYYY', 'en');
|
|
13523
|
+
return value !== '-' ? renderDateFormatted(value, 'YYYY', 'en') : '-';
|
|
13530
13524
|
case 'date':
|
|
13531
13525
|
{
|
|
13532
13526
|
const language = user?.language && user?.language === 'sp' ? 'es' : user?.language;
|
|
13533
|
-
return renderDateFormatted(value, 'DD MMM YYYY', language || 'en');
|
|
13527
|
+
return value !== '-' ? renderDateFormatted(value, 'DD MMM YYYY', language || 'en') : '-';
|
|
13534
13528
|
}
|
|
13535
13529
|
case 'select':
|
|
13536
13530
|
{
|
|
@@ -13538,6 +13532,13 @@ const renderFieldData = (type, value, user, config, getApiBaseUrl = () => {}, ge
|
|
|
13538
13532
|
const option = findOptions(value, options);
|
|
13539
13533
|
return option;
|
|
13540
13534
|
}
|
|
13535
|
+
case 'multiselect':
|
|
13536
|
+
{
|
|
13537
|
+
const options = config?.options || [];
|
|
13538
|
+
const _val = typeof value === 'string' ? value.split(',').map(v => v.trim()) : value;
|
|
13539
|
+
const option = findOptions(_val, options);
|
|
13540
|
+
return option.join(', ');
|
|
13541
|
+
}
|
|
13541
13542
|
case 'ajaxSelect':
|
|
13542
13543
|
return /*#__PURE__*/jsxRuntime.jsx(AjaxSelectRenderer, {
|
|
13543
13544
|
value: value,
|
|
@@ -13557,6 +13558,13 @@ const renderFieldData = (type, value, user, config, getApiBaseUrl = () => {}, ge
|
|
|
13557
13558
|
t: () => {}
|
|
13558
13559
|
});
|
|
13559
13560
|
}
|
|
13561
|
+
case 'imageUpload':
|
|
13562
|
+
case 'upload':
|
|
13563
|
+
case 'videoUpload':
|
|
13564
|
+
{
|
|
13565
|
+
const documentName = allValues?.map(item => item?.name).join(', ');
|
|
13566
|
+
return documentName;
|
|
13567
|
+
}
|
|
13560
13568
|
default:
|
|
13561
13569
|
return value;
|
|
13562
13570
|
}
|
|
@@ -13598,15 +13606,18 @@ const renderValue = ({
|
|
|
13598
13606
|
return combinedValue ? /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
13599
13607
|
className: "tree-value groupInputs-type",
|
|
13600
13608
|
children: combinedValue
|
|
13601
|
-
}) :
|
|
13609
|
+
}) : /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
13610
|
+
className: "tree-value empty",
|
|
13611
|
+
children: "-"
|
|
13612
|
+
});
|
|
13602
13613
|
}
|
|
13603
13614
|
if (hasChildren) return null;
|
|
13604
13615
|
let displayValue = '';
|
|
13605
13616
|
if (value === null || value === undefined || value === '') {
|
|
13606
|
-
displayValue = '';
|
|
13617
|
+
displayValue = '-'; // Changed from '' to '-'
|
|
13607
13618
|
} else if (typeof value === 'object' && value !== null) {
|
|
13608
13619
|
if (Array.isArray(value)) {
|
|
13609
|
-
displayValue = value.length > 0 ? value.join(', ') : '';
|
|
13620
|
+
displayValue = value.length > 0 ? value.join(', ') : '-'; // Changed from '' to '-'
|
|
13610
13621
|
} else if (value.name || value.fullName) {
|
|
13611
13622
|
displayValue = value.name || value.fullName;
|
|
13612
13623
|
} else if (value.label) {
|
|
@@ -13619,21 +13630,28 @@ const renderValue = ({
|
|
|
13619
13630
|
}
|
|
13620
13631
|
const fieldType = config?.type || 'text';
|
|
13621
13632
|
let cssClass = `tree-value ${fieldType}-type`;
|
|
13622
|
-
|
|
13623
|
-
|
|
13633
|
+
if (displayValue === '-') {
|
|
13634
|
+
cssClass += ' empty';
|
|
13635
|
+
}
|
|
13636
|
+
displayValue = renderFieldData(fieldType, displayValue, user, config, getApiBaseUrl, getAppHeader, app, value);
|
|
13637
|
+
return /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
13624
13638
|
className: cssClass,
|
|
13625
13639
|
children: displayValue
|
|
13626
|
-
})
|
|
13640
|
+
});
|
|
13627
13641
|
};
|
|
13628
13642
|
const determineHasChildren = ({
|
|
13629
13643
|
config,
|
|
13630
13644
|
level
|
|
13631
13645
|
}) => {
|
|
13632
|
-
// groupInputs should be treated as leaf nodes, not parent nodes
|
|
13633
13646
|
if (config?.type === 'groupInputs') {
|
|
13634
13647
|
return false;
|
|
13635
13648
|
}
|
|
13636
|
-
|
|
13649
|
+
if (config?.type === 'header' && config?.inputs && Object.keys(config.inputs).length > 0) {
|
|
13650
|
+
return true;
|
|
13651
|
+
}
|
|
13652
|
+
return config?.inputs || config?.type === 'group' || config?.type === 'dataLinkGroup' || config?.type === 'section' || config?.type === 'ajaxSubGroup' ||
|
|
13653
|
+
// Add this line
|
|
13654
|
+
config?.type === 'dataLink' && config?.meta?.tableKeys || level === 0 && config && typeof config === 'object' && Object.keys(config).some(key => key !== 'id' && key !== 'label' && key !== 'position' && key !== 'subTitle' && typeof config[key] === 'object' && config[key] !== null);
|
|
13637
13655
|
};
|
|
13638
13656
|
|
|
13639
13657
|
const sortByPosition = (items, getConfig) => {
|
|
@@ -13921,9 +13939,6 @@ const handleDataLinkGroupWithTableKeys = ({
|
|
|
13921
13939
|
if (!(config.type === 'dataLinkGroup' || config.type === 'dataLink')) {
|
|
13922
13940
|
return null;
|
|
13923
13941
|
}
|
|
13924
|
-
console.log({
|
|
13925
|
-
app
|
|
13926
|
-
});
|
|
13927
13942
|
if (inputConfig?.type !== 'dataLink' || !inputConfig?.meta?.tableKeys) {
|
|
13928
13943
|
const parentInputKeys = Object.keys(config.inputs || {});
|
|
13929
13944
|
const isHandledBySiblingDataLink = parentInputKeys.some(otherInputKey => {
|
|
@@ -13943,9 +13958,6 @@ const handleDataLinkGroupWithTableKeys = ({
|
|
|
13943
13958
|
}
|
|
13944
13959
|
return null;
|
|
13945
13960
|
}
|
|
13946
|
-
if (!(value && typeof value === 'object')) {
|
|
13947
|
-
return null;
|
|
13948
|
-
}
|
|
13949
13961
|
const tableKeys = inputConfig.meta.tableKeys;
|
|
13950
13962
|
const additionalTableKeys = config.meta?.additionalTableKeys || [];
|
|
13951
13963
|
[...new Set([...tableKeys, ...additionalTableKeys])];
|
|
@@ -13966,12 +13978,19 @@ const handleDataLinkGroupWithTableKeys = ({
|
|
|
13966
13978
|
const createInputsAndValues = item => {
|
|
13967
13979
|
const inputs = {};
|
|
13968
13980
|
const values = {};
|
|
13981
|
+
const uploadTypeFields = ['documents', 'links', 'pictures', 'videos'];
|
|
13982
|
+
const uploadTypeLabels = {
|
|
13983
|
+
'documents': 'File',
|
|
13984
|
+
'links': 'Link',
|
|
13985
|
+
'pictures': 'Image',
|
|
13986
|
+
'videos': 'Video'
|
|
13987
|
+
};
|
|
13969
13988
|
tableKeys.filter(tableKey => tableKey !== 'datastakeId').forEach(tableKey => {
|
|
13970
13989
|
const formInputConfig = dataLinkForm?.[tableKey] || dataLinkForm?.['identification']?.[tableKey];
|
|
13971
13990
|
if (formInputConfig) {
|
|
13972
13991
|
inputs[tableKey] = {
|
|
13973
13992
|
...formInputConfig,
|
|
13974
|
-
label: formInputConfig.label || formInputConfig.tableLabel || tableKey
|
|
13993
|
+
label: uploadTypeFields.includes(tableKey) ? uploadTypeLabels[tableKey] : formInputConfig.label || formInputConfig.tableLabel || tableKey
|
|
13975
13994
|
};
|
|
13976
13995
|
if (formInputConfig.label && typeof formInputConfig.label === 'object') {
|
|
13977
13996
|
const dynamicLabelKeys = Object.keys(formInputConfig.label);
|
|
@@ -13986,12 +14005,12 @@ const handleDataLinkGroupWithTableKeys = ({
|
|
|
13986
14005
|
}
|
|
13987
14006
|
}
|
|
13988
14007
|
}
|
|
13989
|
-
inputs[tableKey].label = resolvedLabel || Object.values(formInputConfig.label)[0] || tableKey;
|
|
14008
|
+
inputs[tableKey].label = resolvedLabel || Object.values(formInputConfig.label)[0] || (uploadTypeFields.includes(tableKey) ? uploadTypeLabels[tableKey] : tableKey);
|
|
13990
14009
|
}
|
|
13991
14010
|
values[tableKey] = item?.[tableKey];
|
|
13992
14011
|
} else {
|
|
13993
14012
|
inputs[tableKey] = {
|
|
13994
|
-
label: tableKey,
|
|
14013
|
+
label: uploadTypeFields.includes(tableKey) ? uploadTypeLabels[tableKey] : tableKey,
|
|
13995
14014
|
type: inputConfig?.type
|
|
13996
14015
|
};
|
|
13997
14016
|
values[tableKey] = item?.[tableKey];
|
|
@@ -14005,7 +14024,7 @@ const handleDataLinkGroupWithTableKeys = ({
|
|
|
14005
14024
|
const formInputConfig = dataLinkForm.identification[fieldKey];
|
|
14006
14025
|
inputs[fieldKey] = {
|
|
14007
14026
|
...formInputConfig,
|
|
14008
|
-
label: formInputConfig.label || formInputConfig.tableLabel || fieldKey
|
|
14027
|
+
label: uploadTypeFields.includes(fieldKey) ? uploadTypeLabels[fieldKey] : formInputConfig.label || formInputConfig.tableLabel || fieldKey
|
|
14009
14028
|
};
|
|
14010
14029
|
if (formInputConfig.label && typeof formInputConfig.label === 'object') {
|
|
14011
14030
|
const dynamicLabelKeys = Object.keys(formInputConfig.label);
|
|
@@ -14020,7 +14039,7 @@ const handleDataLinkGroupWithTableKeys = ({
|
|
|
14020
14039
|
}
|
|
14021
14040
|
}
|
|
14022
14041
|
}
|
|
14023
|
-
inputs[fieldKey].label = resolvedLabel || Object.values(formInputConfig.label)[0] || fieldKey;
|
|
14042
|
+
inputs[fieldKey].label = resolvedLabel || Object.values(formInputConfig.label)[0] || (uploadTypeFields.includes(fieldKey) ? uploadTypeLabels[fieldKey] : fieldKey);
|
|
14024
14043
|
}
|
|
14025
14044
|
values[fieldKey] = item?.[fieldKey];
|
|
14026
14045
|
});
|
|
@@ -14038,9 +14057,9 @@ const handleDataLinkGroupWithTableKeys = ({
|
|
|
14038
14057
|
values
|
|
14039
14058
|
} = createInputsAndValues(item);
|
|
14040
14059
|
return /*#__PURE__*/jsxRuntime.jsx(TreeNodeComponent, {
|
|
14041
|
-
nodeKey: datastakeIdValue || `
|
|
14060
|
+
nodeKey: datastakeIdValue || t(`No ID ${itemIndex + 1}`),
|
|
14042
14061
|
config: {
|
|
14043
|
-
label: datastakeIdValue || `
|
|
14062
|
+
label: datastakeIdValue || t(`No ID ${itemIndex + 1}`),
|
|
14044
14063
|
type: 'custom-datalink-group',
|
|
14045
14064
|
inputs: inputs
|
|
14046
14065
|
},
|
|
@@ -14063,9 +14082,9 @@ const handleDataLinkGroupWithTableKeys = ({
|
|
|
14063
14082
|
values
|
|
14064
14083
|
} = createInputsAndValues(value);
|
|
14065
14084
|
return /*#__PURE__*/jsxRuntime.jsx(TreeNodeComponent, {
|
|
14066
|
-
nodeKey: datastakeIdValue || '
|
|
14085
|
+
nodeKey: datastakeIdValue || t('No ID'),
|
|
14067
14086
|
config: {
|
|
14068
|
-
label: datastakeIdValue || '
|
|
14087
|
+
label: datastakeIdValue || t('No ID'),
|
|
14069
14088
|
type: 'custom-datalink-group',
|
|
14070
14089
|
inputs: inputs
|
|
14071
14090
|
},
|
|
@@ -14100,9 +14119,6 @@ const handleDataLinkWithTableKeys = ({
|
|
|
14100
14119
|
if (inputConfig?.type !== 'dataLink' || !inputConfig?.meta?.tableKeys) {
|
|
14101
14120
|
return null;
|
|
14102
14121
|
}
|
|
14103
|
-
if (!(value && typeof value === 'object')) {
|
|
14104
|
-
return null;
|
|
14105
|
-
}
|
|
14106
14122
|
const tableKeys = inputConfig.meta.tableKeys;
|
|
14107
14123
|
const isAjaxModal = React.useMemo(() => !!inputConfig?.meta?.namespace, [inputConfig]);
|
|
14108
14124
|
const ajaxModalValues = useAjaxModal$2({
|
|
@@ -14120,12 +14136,27 @@ const handleDataLinkWithTableKeys = ({
|
|
|
14120
14136
|
const createInputsAndValues = item => {
|
|
14121
14137
|
const inputs = {};
|
|
14122
14138
|
const values = {};
|
|
14123
|
-
|
|
14139
|
+
const uploadTypeFields = ['documents', 'links', 'pictures', 'videos'];
|
|
14140
|
+
const uploadTypeLabels = {
|
|
14141
|
+
'documents': 'File',
|
|
14142
|
+
'links': 'Link',
|
|
14143
|
+
'pictures': 'Image',
|
|
14144
|
+
'videos': 'Video'
|
|
14145
|
+
};
|
|
14146
|
+
const isUploadFieldEmpty = (fieldKey, itemToCheck) => {
|
|
14147
|
+
if (uploadTypeFields.includes(fieldKey)) {
|
|
14148
|
+
const itemValue = itemToCheck?.[fieldKey];
|
|
14149
|
+
return itemValue === undefined || itemValue === null || Array.isArray(itemValue) && itemValue.length === 0;
|
|
14150
|
+
}
|
|
14151
|
+
return false;
|
|
14152
|
+
};
|
|
14153
|
+
const processedTableKeys = processConditionalTableKeys(tableKeys, item);
|
|
14154
|
+
processedTableKeys.filter(tableKey => tableKey !== 'datastakeId').filter(tableKey => !isUploadFieldEmpty(tableKey, item)).forEach(tableKey => {
|
|
14124
14155
|
const formInputConfig = dataLinkForm?.[tableKey] || dataLinkForm?.['identification']?.[tableKey];
|
|
14125
14156
|
if (formInputConfig) {
|
|
14126
14157
|
inputs[tableKey] = {
|
|
14127
14158
|
...formInputConfig,
|
|
14128
|
-
label: formInputConfig.label || formInputConfig.tableLabel || tableKey
|
|
14159
|
+
label: uploadTypeFields.includes(tableKey) ? uploadTypeLabels[tableKey] : formInputConfig.label || formInputConfig.tableLabel || tableKey
|
|
14129
14160
|
};
|
|
14130
14161
|
if (formInputConfig.label && typeof formInputConfig.label === 'object') {
|
|
14131
14162
|
const dynamicLabelKeys = Object.keys(formInputConfig.label);
|
|
@@ -14140,26 +14171,31 @@ const handleDataLinkWithTableKeys = ({
|
|
|
14140
14171
|
}
|
|
14141
14172
|
}
|
|
14142
14173
|
}
|
|
14143
|
-
inputs[tableKey].label = resolvedLabel || Object.values(formInputConfig.label)[0] || tableKey;
|
|
14174
|
+
inputs[tableKey].label = resolvedLabel || Object.values(formInputConfig.label)[0] || (uploadTypeFields.includes(tableKey) ? uploadTypeLabels[tableKey] : tableKey);
|
|
14144
14175
|
}
|
|
14145
14176
|
values[tableKey] = item?.[tableKey];
|
|
14146
14177
|
} else {
|
|
14147
14178
|
inputs[tableKey] = {
|
|
14148
|
-
label: tableKey,
|
|
14179
|
+
label: uploadTypeFields.includes(tableKey) ? uploadTypeLabels[tableKey] : tableKey,
|
|
14149
14180
|
type: inputConfig?.type
|
|
14150
14181
|
};
|
|
14151
14182
|
values[tableKey] = item?.[tableKey];
|
|
14152
14183
|
}
|
|
14153
14184
|
});
|
|
14154
14185
|
if (dataLinkForm?.identification && typeof dataLinkForm.identification === 'object') {
|
|
14155
|
-
Object.keys(dataLinkForm.identification).filter(fieldKey =>
|
|
14186
|
+
Object.keys(dataLinkForm.identification).filter(fieldKey => {
|
|
14187
|
+
if (uploadTypeFields.includes(fieldKey)) {
|
|
14188
|
+
return !isUploadFieldEmpty(fieldKey, item);
|
|
14189
|
+
}
|
|
14190
|
+
return true;
|
|
14191
|
+
}).filter(fieldKey => fieldKey !== 'datastakeId' && !processedTableKeys.includes(fieldKey)).filter(fieldKey => {
|
|
14156
14192
|
const formInputConfig = dataLinkForm.identification[fieldKey];
|
|
14157
14193
|
return formInputConfig && typeof formInputConfig === 'object' && !Array.isArray(formInputConfig);
|
|
14158
14194
|
}).forEach(fieldKey => {
|
|
14159
14195
|
const formInputConfig = dataLinkForm.identification[fieldKey];
|
|
14160
14196
|
inputs[fieldKey] = {
|
|
14161
14197
|
...formInputConfig,
|
|
14162
|
-
label: formInputConfig.label || formInputConfig.tableLabel || fieldKey
|
|
14198
|
+
label: uploadTypeFields.includes(fieldKey) ? uploadTypeLabels[fieldKey] : formInputConfig.label || formInputConfig.tableLabel || fieldKey
|
|
14163
14199
|
};
|
|
14164
14200
|
if (formInputConfig.label && typeof formInputConfig.label === 'object') {
|
|
14165
14201
|
const dynamicLabelKeys = Object.keys(formInputConfig.label);
|
|
@@ -14174,7 +14210,7 @@ const handleDataLinkWithTableKeys = ({
|
|
|
14174
14210
|
}
|
|
14175
14211
|
}
|
|
14176
14212
|
}
|
|
14177
|
-
inputs[fieldKey].label = resolvedLabel || Object.values(formInputConfig.label)[0] || fieldKey;
|
|
14213
|
+
inputs[fieldKey].label = resolvedLabel || Object.values(formInputConfig.label)[0] || (uploadTypeFields.includes(fieldKey) ? uploadTypeLabels[fieldKey] : fieldKey);
|
|
14178
14214
|
}
|
|
14179
14215
|
values[fieldKey] = item?.[fieldKey];
|
|
14180
14216
|
});
|
|
@@ -14191,10 +14227,13 @@ const handleDataLinkWithTableKeys = ({
|
|
|
14191
14227
|
inputs,
|
|
14192
14228
|
values
|
|
14193
14229
|
} = createInputsAndValues(item);
|
|
14230
|
+
if (Object.keys(inputs).length === 0) {
|
|
14231
|
+
return null;
|
|
14232
|
+
}
|
|
14194
14233
|
return /*#__PURE__*/jsxRuntime.jsx(TreeNodeComponent, {
|
|
14195
|
-
nodeKey: datastakeIdValue || `
|
|
14234
|
+
nodeKey: datastakeIdValue || t(`No ID ${itemIndex + 1}`),
|
|
14196
14235
|
config: {
|
|
14197
|
-
label: datastakeIdValue || `
|
|
14236
|
+
label: datastakeIdValue || t(`No ID ${itemIndex + 1}`),
|
|
14198
14237
|
type: 'custom-datalink',
|
|
14199
14238
|
inputs: inputs
|
|
14200
14239
|
},
|
|
@@ -14216,10 +14255,13 @@ const handleDataLinkWithTableKeys = ({
|
|
|
14216
14255
|
inputs,
|
|
14217
14256
|
values
|
|
14218
14257
|
} = createInputsAndValues(value);
|
|
14258
|
+
if (Object.keys(inputs).length === 0) {
|
|
14259
|
+
return null;
|
|
14260
|
+
}
|
|
14219
14261
|
return /*#__PURE__*/jsxRuntime.jsx(TreeNodeComponent, {
|
|
14220
|
-
nodeKey: datastakeIdValue || '
|
|
14262
|
+
nodeKey: datastakeIdValue || t('No ID'),
|
|
14221
14263
|
config: {
|
|
14222
|
-
label: datastakeIdValue || '
|
|
14264
|
+
label: datastakeIdValue || t('No ID'),
|
|
14223
14265
|
type: 'custom-datalink',
|
|
14224
14266
|
inputs: inputs
|
|
14225
14267
|
},
|
|
@@ -14324,8 +14366,111 @@ const GroupInputsHandler = ({
|
|
|
14324
14366
|
}) : null;
|
|
14325
14367
|
};
|
|
14326
14368
|
|
|
14369
|
+
const AjaxSubGroup$2 = ({
|
|
14370
|
+
config,
|
|
14371
|
+
value,
|
|
14372
|
+
allData,
|
|
14373
|
+
level,
|
|
14374
|
+
t,
|
|
14375
|
+
rootForm,
|
|
14376
|
+
user,
|
|
14377
|
+
getApiBaseUrl = () => {},
|
|
14378
|
+
getAppHeader = () => {},
|
|
14379
|
+
app,
|
|
14380
|
+
TreeNodeComponent
|
|
14381
|
+
}) => {
|
|
14382
|
+
const isAjaxModal = React.useMemo(() => !!config?.meta?.namespace, [config]);
|
|
14383
|
+
const ajaxModalValues = useAjaxModal$2({
|
|
14384
|
+
name: config?.label || 'ajaxSubGroup',
|
|
14385
|
+
user,
|
|
14386
|
+
namespace: config?.meta?.namespace,
|
|
14387
|
+
skipFetch: config?.meta?.skipFetch,
|
|
14388
|
+
isAjaxModal,
|
|
14389
|
+
formScope: config?.meta?.formScope || 'modal',
|
|
14390
|
+
APP: app,
|
|
14391
|
+
apiBaseUrl: getApiBaseUrl(),
|
|
14392
|
+
_getAppHeader: getAppHeader
|
|
14393
|
+
});
|
|
14394
|
+
const ajaxForm = ajaxModalValues?.form;
|
|
14395
|
+
console.log({
|
|
14396
|
+
ajaxForm
|
|
14397
|
+
});
|
|
14398
|
+
if (ajaxModalValues.isFetching) {
|
|
14399
|
+
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
14400
|
+
className: "ajax-subgroup-loading",
|
|
14401
|
+
style: {
|
|
14402
|
+
padding: '20px',
|
|
14403
|
+
textAlign: 'center'
|
|
14404
|
+
},
|
|
14405
|
+
children: /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
14406
|
+
children: "Loading form configuration..."
|
|
14407
|
+
})
|
|
14408
|
+
});
|
|
14409
|
+
}
|
|
14410
|
+
const formInputs = Object.values(ajaxForm || {})[0] || {};
|
|
14411
|
+
console.log({
|
|
14412
|
+
formInputs
|
|
14413
|
+
});
|
|
14414
|
+
const sortedRecords = value.sort((a, b) => {
|
|
14415
|
+
const yearA = parseInt(a.meta?.year || '0');
|
|
14416
|
+
const yearB = parseInt(b.meta?.year || '0');
|
|
14417
|
+
return yearB - yearA;
|
|
14418
|
+
});
|
|
14419
|
+
const children = [];
|
|
14420
|
+
sortedRecords.forEach((record, recordIndex) => {
|
|
14421
|
+
const year = record.meta?.year || 'Unknown Year';
|
|
14422
|
+
const fieldKeys = Object.keys(formInputs).filter(inputKey => {
|
|
14423
|
+
const metadataKeys = ['id', 'label', 'position', 'subTitle'];
|
|
14424
|
+
if (metadataKeys.includes(inputKey)) {
|
|
14425
|
+
return false;
|
|
14426
|
+
}
|
|
14427
|
+
const excludedKeys = config?.meta?.excludedKeysView || [];
|
|
14428
|
+
return !excludedKeys.includes(inputKey);
|
|
14429
|
+
}).sort((a, b) => {
|
|
14430
|
+
const positionA = formInputs[a]?.position || 0;
|
|
14431
|
+
const positionB = formInputs[b]?.position || 0;
|
|
14432
|
+
return positionA - positionB;
|
|
14433
|
+
});
|
|
14434
|
+
const yearInputs = {};
|
|
14435
|
+
fieldKeys.forEach(inputKey => {
|
|
14436
|
+
yearInputs[inputKey] = formInputs[inputKey];
|
|
14437
|
+
});
|
|
14438
|
+
children.push( /*#__PURE__*/jsxRuntime.jsx(TreeNodeComponent, {
|
|
14439
|
+
nodeKey: `year-${year}`,
|
|
14440
|
+
config: {
|
|
14441
|
+
label: year,
|
|
14442
|
+
type: 'header',
|
|
14443
|
+
inputs: yearInputs,
|
|
14444
|
+
meta: {
|
|
14445
|
+
code: record.datastakeId || ''
|
|
14446
|
+
}
|
|
14447
|
+
},
|
|
14448
|
+
value: record,
|
|
14449
|
+
level: level + 1,
|
|
14450
|
+
isLast: recordIndex === sortedRecords.length - 1,
|
|
14451
|
+
t: t,
|
|
14452
|
+
rootForm: rootForm,
|
|
14453
|
+
allData: record,
|
|
14454
|
+
user: user,
|
|
14455
|
+
getApiBaseUrl: getApiBaseUrl,
|
|
14456
|
+
getAppHeader: getAppHeader,
|
|
14457
|
+
app: app
|
|
14458
|
+
}, `year-${year}`));
|
|
14459
|
+
});
|
|
14460
|
+
return children;
|
|
14461
|
+
};
|
|
14462
|
+
|
|
14463
|
+
const handleAjaxSubGroupChildren = props => {
|
|
14464
|
+
if (props.config?.type !== 'ajaxSubGroup' || !Array.isArray(props.value)) {
|
|
14465
|
+
return null;
|
|
14466
|
+
}
|
|
14467
|
+
return [/*#__PURE__*/jsxRuntime.jsx(AjaxSubGroup$2, {
|
|
14468
|
+
...props
|
|
14469
|
+
}, "ajax-subgroup")];
|
|
14470
|
+
};
|
|
14471
|
+
|
|
14327
14472
|
const TreeNode = _ref => {
|
|
14328
|
-
var _config$
|
|
14473
|
+
var _allData$meta, _config$meta2;
|
|
14329
14474
|
let {
|
|
14330
14475
|
nodeKey,
|
|
14331
14476
|
config,
|
|
@@ -14340,23 +14485,34 @@ const TreeNode = _ref => {
|
|
|
14340
14485
|
getAppHeader = () => {},
|
|
14341
14486
|
app
|
|
14342
14487
|
} = _ref;
|
|
14343
|
-
|
|
14488
|
+
if (config.showIf && !evaluateShowIfCondition(config.showIf, allData)) {
|
|
14489
|
+
return null;
|
|
14490
|
+
}
|
|
14491
|
+
const hasMetaComment = level <= 2 && (allData === null || allData === void 0 || (_allData$meta = allData.meta) === null || _allData$meta === void 0 || (_allData$meta = _allData$meta[nodeKey]) === null || _allData$meta === void 0 ? void 0 : _allData$meta.comment);
|
|
14492
|
+
const originalHasChildren = determineHasChildren({
|
|
14344
14493
|
config,
|
|
14345
14494
|
level
|
|
14346
14495
|
});
|
|
14496
|
+
const hasChildren = originalHasChildren || hasMetaComment;
|
|
14347
14497
|
const label = resolveDynamicLabel(config === null || config === void 0 ? void 0 : config.label, allData || value, nodeKey);
|
|
14348
14498
|
(config === null || config === void 0 ? void 0 : config.type) || 'field';
|
|
14349
14499
|
let renderNodeValue = () => renderValue({
|
|
14350
14500
|
value,
|
|
14351
|
-
hasChildren,
|
|
14501
|
+
hasChildren: originalHasChildren,
|
|
14352
14502
|
config,
|
|
14353
14503
|
user,
|
|
14354
14504
|
getApiBaseUrl,
|
|
14355
14505
|
getAppHeader,
|
|
14356
14506
|
app
|
|
14357
14507
|
});
|
|
14508
|
+
if (nodeKey === 'keyIncidents') {
|
|
14509
|
+
console.log({
|
|
14510
|
+
config,
|
|
14511
|
+
value,
|
|
14512
|
+
hasChildren
|
|
14513
|
+
});
|
|
14514
|
+
}
|
|
14358
14515
|
const renderChildren = () => {
|
|
14359
|
-
var _config$meta;
|
|
14360
14516
|
if (!hasChildren) return null;
|
|
14361
14517
|
let children = [];
|
|
14362
14518
|
const sectionChildren = handleSectionChildren({
|
|
@@ -14371,13 +14527,26 @@ const TreeNode = _ref => {
|
|
|
14371
14527
|
getAppHeader,
|
|
14372
14528
|
TreeNodeComponent: TreeNode
|
|
14373
14529
|
});
|
|
14374
|
-
if (
|
|
14375
|
-
|
|
14376
|
-
|
|
14377
|
-
|
|
14378
|
-
|
|
14530
|
+
if (config.type === 'ajaxSubGroup') {
|
|
14531
|
+
const ajaxSubGroupChildren = handleAjaxSubGroupChildren({
|
|
14532
|
+
config,
|
|
14533
|
+
value,
|
|
14534
|
+
allData,
|
|
14535
|
+
level,
|
|
14536
|
+
t,
|
|
14537
|
+
rootForm,
|
|
14538
|
+
user,
|
|
14539
|
+
app,
|
|
14540
|
+
getApiBaseUrl,
|
|
14541
|
+
getAppHeader,
|
|
14542
|
+
TreeNodeComponent: TreeNode
|
|
14379
14543
|
});
|
|
14380
|
-
|
|
14544
|
+
if (ajaxSubGroupChildren) {
|
|
14545
|
+
children = ajaxSubGroupChildren;
|
|
14546
|
+
}
|
|
14547
|
+
} else if (sectionChildren) {
|
|
14548
|
+
children = sectionChildren;
|
|
14549
|
+
} else if (config.type === 'dataLink') {
|
|
14381
14550
|
const singleDataLinkChildren = handleDataLinkWithTableKeys({
|
|
14382
14551
|
inputConfig: config,
|
|
14383
14552
|
inputKey: nodeKey,
|
|
@@ -14397,7 +14566,14 @@ const TreeNode = _ref => {
|
|
|
14397
14566
|
}
|
|
14398
14567
|
} else if (config !== null && config !== void 0 && config.inputs) {
|
|
14399
14568
|
if (config.type === 'dataLinkGroup' || config.type === 'dataLink') {
|
|
14400
|
-
const inputKeys = Object.keys(config.inputs).
|
|
14569
|
+
const inputKeys = Object.keys(config.inputs).filter(inputKey => {
|
|
14570
|
+
const inputConfig = config.inputs[inputKey];
|
|
14571
|
+
// Check showIf condition for input
|
|
14572
|
+
if (inputConfig !== null && inputConfig !== void 0 && inputConfig.showIf && !evaluateShowIfCondition(inputConfig.showIf, allData)) {
|
|
14573
|
+
return false;
|
|
14574
|
+
}
|
|
14575
|
+
return true;
|
|
14576
|
+
}).sort((a, b) => {
|
|
14401
14577
|
var _config$inputs$a, _config$inputs$b;
|
|
14402
14578
|
const positionA = ((_config$inputs$a = config.inputs[a]) === null || _config$inputs$a === void 0 ? void 0 : _config$inputs$a.position) || 0;
|
|
14403
14579
|
const positionB = ((_config$inputs$b = config.inputs[b]) === null || _config$inputs$b === void 0 ? void 0 : _config$inputs$b.position) || 0;
|
|
@@ -14446,8 +14622,8 @@ const TreeNode = _ref => {
|
|
|
14446
14622
|
return groupChildren;
|
|
14447
14623
|
}).flat().filter(Boolean);
|
|
14448
14624
|
} else {
|
|
14449
|
-
var _config$
|
|
14450
|
-
if (config.type === 'dataLink' && config !== null && config !== void 0 && (_config$
|
|
14625
|
+
var _config$meta;
|
|
14626
|
+
if (config.type === 'dataLink' && config !== null && config !== void 0 && (_config$meta = config.meta) !== null && _config$meta !== void 0 && _config$meta.tableKeys && !config.inputs) {
|
|
14451
14627
|
const singleDataLinkChildren = handleDataLinkWithTableKeys({
|
|
14452
14628
|
inputConfig: config,
|
|
14453
14629
|
inputKey: nodeKey,
|
|
@@ -14483,7 +14659,14 @@ const TreeNode = _ref => {
|
|
|
14483
14659
|
if (arrayChildren) {
|
|
14484
14660
|
children = arrayChildren;
|
|
14485
14661
|
} else {
|
|
14486
|
-
const inputKeys = Object.keys(config.inputs).
|
|
14662
|
+
const inputKeys = Object.keys(config.inputs).filter(inputKey => {
|
|
14663
|
+
const inputConfig = config.inputs[inputKey];
|
|
14664
|
+
// Check showIf condition for input
|
|
14665
|
+
if (inputConfig !== null && inputConfig !== void 0 && inputConfig.showIf && !evaluateShowIfCondition(inputConfig.showIf, allData)) {
|
|
14666
|
+
return false;
|
|
14667
|
+
}
|
|
14668
|
+
return true;
|
|
14669
|
+
}).sort((a, b) => {
|
|
14487
14670
|
var _config$inputs$a2, _config$inputs$b2;
|
|
14488
14671
|
const positionA = ((_config$inputs$a2 = config.inputs[a]) === null || _config$inputs$a2 === void 0 ? void 0 : _config$inputs$a2.position) || 0;
|
|
14489
14672
|
const positionB = ((_config$inputs$b2 = config.inputs[b]) === null || _config$inputs$b2 === void 0 ? void 0 : _config$inputs$b2.position) || 0;
|
|
@@ -14535,6 +14718,37 @@ const TreeNode = _ref => {
|
|
|
14535
14718
|
}
|
|
14536
14719
|
}
|
|
14537
14720
|
}
|
|
14721
|
+
|
|
14722
|
+
// Ensure children is always an array before adding meta comment
|
|
14723
|
+
if (!Array.isArray(children)) {
|
|
14724
|
+
children = children ? [children] : [];
|
|
14725
|
+
}
|
|
14726
|
+
|
|
14727
|
+
// Add meta comment as a child if it exists
|
|
14728
|
+
if (hasMetaComment) {
|
|
14729
|
+
const commentChild = /*#__PURE__*/jsxRuntime.jsx(TreeNode, {
|
|
14730
|
+
nodeKey: "comment",
|
|
14731
|
+
config: {
|
|
14732
|
+
label: "Comment",
|
|
14733
|
+
type: "field",
|
|
14734
|
+
meta: {
|
|
14735
|
+
isComment: true
|
|
14736
|
+
} // Add a marker to identify this as a comment
|
|
14737
|
+
},
|
|
14738
|
+
value: allData.meta[nodeKey].comment,
|
|
14739
|
+
level: level + 1,
|
|
14740
|
+
isLast: children.length === 0 // This will be the last child if no other children
|
|
14741
|
+
,
|
|
14742
|
+
t: t,
|
|
14743
|
+
rootForm: rootForm,
|
|
14744
|
+
allData: allData,
|
|
14745
|
+
user: user,
|
|
14746
|
+
app: app,
|
|
14747
|
+
getApiBaseUrl: getApiBaseUrl,
|
|
14748
|
+
getAppHeader: getAppHeader
|
|
14749
|
+
}, "".concat(nodeKey, "-comment"));
|
|
14750
|
+
children.push(commentChild);
|
|
14751
|
+
}
|
|
14538
14752
|
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
14539
14753
|
className: "tree-children",
|
|
14540
14754
|
children: children
|
|
@@ -14550,7 +14764,7 @@ const TreeNode = _ref => {
|
|
|
14550
14764
|
};
|
|
14551
14765
|
}
|
|
14552
14766
|
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
14553
|
-
className: "tree-node level-".concat(level, " ").concat(hasChildren ? 'parent' : 'leaf', " ").concat(isLast ? 'last' : ''),
|
|
14767
|
+
className: "tree-node level-".concat(level, " ").concat(hasChildren ? 'parent' : 'leaf', " ").concat(isLast ? 'last' : '', " ").concat(nodeKey === 'comment' ? 'comment-node' : ''),
|
|
14554
14768
|
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
14555
14769
|
className: "tree-node-content",
|
|
14556
14770
|
children: [/*#__PURE__*/jsxRuntime.jsx("div", {
|
|
@@ -14563,14 +14777,14 @@ const TreeNode = _ref => {
|
|
|
14563
14777
|
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
14564
14778
|
className: "tree-node-title",
|
|
14565
14779
|
children: [/*#__PURE__*/jsxRuntime.jsxs("span", {
|
|
14566
|
-
className: "tree-label",
|
|
14567
|
-
children: [label, !hasChildren && renderNodeValue() ? ':' : '']
|
|
14780
|
+
className: "tree-label ".concat(nodeKey === 'comment' ? 'comment-label' : ''),
|
|
14781
|
+
children: [label, !hasChildren && renderNodeValue() && !label.endsWith('?') ? ':' : '']
|
|
14568
14782
|
}), /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
14569
14783
|
className: "tree-value-container",
|
|
14570
14784
|
children: renderNodeValue()
|
|
14571
14785
|
}), /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
14572
14786
|
className: "tree-code",
|
|
14573
|
-
children: (config === null || config === void 0 || (_config$
|
|
14787
|
+
children: (config === null || config === void 0 || (_config$meta2 = config.meta) === null || _config$meta2 === void 0 ? void 0 : _config$meta2.code) || ''
|
|
14574
14788
|
})]
|
|
14575
14789
|
})]
|
|
14576
14790
|
}), renderChildren()]
|
|
@@ -14616,6 +14830,11 @@ const PdfFormContent = _ref2 => {
|
|
|
14616
14830
|
}), /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
14617
14831
|
className: "pdf-tree",
|
|
14618
14832
|
children: Object.keys(form).filter(sectionKey => {
|
|
14833
|
+
const section = form[sectionKey];
|
|
14834
|
+
// Check if section should be shown based on showIf condition
|
|
14835
|
+
if (section !== null && section !== void 0 && section.showIf && !evaluateShowIfCondition(section.showIf, data)) {
|
|
14836
|
+
return false;
|
|
14837
|
+
}
|
|
14619
14838
|
return !(sectionKey === 'id' || sectionKey === 'label' || sectionKey === 'position' || sectionKey === 'subTitle');
|
|
14620
14839
|
}).sort((a, b) => {
|
|
14621
14840
|
var _form$a, _form$b;
|
|
@@ -14662,10 +14881,92 @@ const PdfForm = _ref3 => {
|
|
|
14662
14881
|
getAppHeader = () => {},
|
|
14663
14882
|
app
|
|
14664
14883
|
} = _ref3;
|
|
14884
|
+
// Group objects under headers based on position
|
|
14885
|
+
const organizeFormByHeaders = formData => {
|
|
14886
|
+
const organizedSections = {};
|
|
14887
|
+
Object.keys(formData).forEach(sectionKey => {
|
|
14888
|
+
const section = formData[sectionKey];
|
|
14889
|
+
if (typeof section !== 'object' || !section.label) {
|
|
14890
|
+
return;
|
|
14891
|
+
}
|
|
14892
|
+
|
|
14893
|
+
// Get all objects from this section and sort by position
|
|
14894
|
+
const allObjects = Object.keys(section).filter(key => {
|
|
14895
|
+
return !(key === 'id' || key === 'label' || key === 'position' || key === 'subTitle');
|
|
14896
|
+
}).map(key => _objectSpread2({
|
|
14897
|
+
key
|
|
14898
|
+
}, section[key])).sort((a, b) => {
|
|
14899
|
+
const positionA = a.position || 0;
|
|
14900
|
+
const positionB = b.position || 0;
|
|
14901
|
+
return positionA - positionB;
|
|
14902
|
+
});
|
|
14903
|
+
|
|
14904
|
+
// Identify headers and regular objects
|
|
14905
|
+
const headers = allObjects.filter(obj => obj.type === 'header');
|
|
14906
|
+
const nonHeaders = allObjects.filter(obj => obj.type !== 'header');
|
|
14907
|
+
if (headers.length === 0) {
|
|
14908
|
+
// No headers found, keep original structure
|
|
14909
|
+
organizedSections[sectionKey] = section;
|
|
14910
|
+
return;
|
|
14911
|
+
}
|
|
14912
|
+
const organizedSection = _objectSpread2({}, section);
|
|
14913
|
+
|
|
14914
|
+
// Clear the section of its original objects
|
|
14915
|
+
Object.keys(section).forEach(key => {
|
|
14916
|
+
if (!(key === 'id' || key === 'label' || key === 'position' || key === 'subTitle')) {
|
|
14917
|
+
delete organizedSection[key];
|
|
14918
|
+
}
|
|
14919
|
+
});
|
|
14920
|
+
headers.forEach((header, index) => {
|
|
14921
|
+
const headerPosition = header.position || 0;
|
|
14922
|
+
const nextHeaderPosition = index < headers.length - 1 ? headers[index + 1].position || 0 : Infinity;
|
|
14923
|
+
|
|
14924
|
+
// Find objects that belong under this header
|
|
14925
|
+
const childrenObjects = nonHeaders.filter(obj => {
|
|
14926
|
+
const objPosition = obj.position || 0;
|
|
14927
|
+
return objPosition > headerPosition && objPosition < nextHeaderPosition;
|
|
14928
|
+
});
|
|
14929
|
+
|
|
14930
|
+
// Create the header structure with children as inputs
|
|
14931
|
+
const headerWithChildren = _objectSpread2({}, header);
|
|
14932
|
+
delete headerWithChildren.key; // Remove the key we added temporarily
|
|
14933
|
+
|
|
14934
|
+
if (childrenObjects.length > 0) {
|
|
14935
|
+
headerWithChildren.inputs = {};
|
|
14936
|
+
childrenObjects.forEach(child => {
|
|
14937
|
+
const childKey = child.key;
|
|
14938
|
+
const childData = _objectSpread2({}, child);
|
|
14939
|
+
delete childData.key; // Remove the temporary key
|
|
14940
|
+
headerWithChildren.inputs[childKey] = childData;
|
|
14941
|
+
});
|
|
14942
|
+
}
|
|
14943
|
+
organizedSection[header.key] = headerWithChildren;
|
|
14944
|
+
});
|
|
14945
|
+
|
|
14946
|
+
// Add any remaining objects that don't fall under any header
|
|
14947
|
+
const uncategorizedObjects = nonHeaders.filter(obj => {
|
|
14948
|
+
const objPosition = obj.position || 0;
|
|
14949
|
+
return !headers.some((header, index) => {
|
|
14950
|
+
const headerPosition = header.position || 0;
|
|
14951
|
+
const nextHeaderPosition = index < headers.length - 1 ? headers[index + 1].position || 0 : Infinity;
|
|
14952
|
+
return objPosition > headerPosition && objPosition < nextHeaderPosition;
|
|
14953
|
+
});
|
|
14954
|
+
});
|
|
14955
|
+
uncategorizedObjects.forEach(obj => {
|
|
14956
|
+
const objKey = obj.key;
|
|
14957
|
+
const objData = _objectSpread2({}, obj);
|
|
14958
|
+
delete objData.key;
|
|
14959
|
+
organizedSection[objKey] = objData;
|
|
14960
|
+
});
|
|
14961
|
+
organizedSections[sectionKey] = organizedSection;
|
|
14962
|
+
});
|
|
14963
|
+
return organizedSections;
|
|
14964
|
+
};
|
|
14965
|
+
const organizedForm = React.useMemo(() => organizeFormByHeaders(form), [form]);
|
|
14665
14966
|
const pdfConfig = React.useMemo(() => {
|
|
14666
14967
|
const sections = [];
|
|
14667
|
-
Object.keys(
|
|
14668
|
-
const section =
|
|
14968
|
+
Object.keys(organizedForm).forEach(sectionKey => {
|
|
14969
|
+
const section = organizedForm[sectionKey];
|
|
14669
14970
|
if (typeof section !== 'object' || !section.label) {
|
|
14670
14971
|
return;
|
|
14671
14972
|
}
|
|
@@ -14694,7 +14995,7 @@ const PdfForm = _ref3 => {
|
|
|
14694
14995
|
});
|
|
14695
14996
|
});
|
|
14696
14997
|
return sections;
|
|
14697
|
-
}, [
|
|
14998
|
+
}, [organizedForm, data, t, getApiBaseUrl, getAppHeader, app, formName, source, version]);
|
|
14698
14999
|
return /*#__PURE__*/jsxRuntime.jsx(PdfView, {
|
|
14699
15000
|
config: pdfConfig,
|
|
14700
15001
|
customClassName: "pdf-form ".concat(customClassName),
|
|
@@ -16961,6 +17262,15 @@ function StakeholderIcon({
|
|
|
16961
17262
|
});
|
|
16962
17263
|
}
|
|
16963
17264
|
|
|
17265
|
+
const EVENT_COLORS = {
|
|
17266
|
+
MAJOR: "#cf1322",
|
|
17267
|
+
// Red for major incidents
|
|
17268
|
+
MODERATE: "#fa8c16",
|
|
17269
|
+
// Orange for moderate incidents
|
|
17270
|
+
MINOR: "#fadb14",
|
|
17271
|
+
// Yellow for minor incidents
|
|
17272
|
+
CORRECTIVE: "#12b76a" // Green for corrective actions
|
|
17273
|
+
};
|
|
16964
17274
|
function useMapHelper$1({
|
|
16965
17275
|
type,
|
|
16966
17276
|
mapRef,
|
|
@@ -17057,6 +17367,11 @@ function useMapHelper$1({
|
|
|
17057
17367
|
return null;
|
|
17058
17368
|
}, [mapRef, renderMarker]);
|
|
17059
17369
|
|
|
17370
|
+
// console.log({
|
|
17371
|
+
// activeMarker,
|
|
17372
|
+
// mapMarkers,
|
|
17373
|
+
// });
|
|
17374
|
+
|
|
17060
17375
|
// Draws the marker in the map and saves it in mapMarkers state
|
|
17061
17376
|
const addIconToMapInitialy = React.useCallback((coordinates, groupName, markerName, data, maxTotal = 0, i = 0) => {
|
|
17062
17377
|
if (mapRef) {
|
|
@@ -17066,62 +17381,55 @@ function useMapHelper$1({
|
|
|
17066
17381
|
let iconSize = [25, 25];
|
|
17067
17382
|
if (type === "event") {
|
|
17068
17383
|
iconClassName = "incident rounded";
|
|
17069
|
-
|
|
17070
|
-
/* const incidents = data?.data || [];
|
|
17384
|
+
const incidents = data?.data || [];
|
|
17071
17385
|
const totals = {
|
|
17072
|
-
|
|
17073
|
-
|
|
17074
|
-
|
|
17075
|
-
|
|
17076
|
-
.length,
|
|
17386
|
+
major: incidents.filter(d => d.type === "major_incident").length,
|
|
17387
|
+
minor: incidents.filter(d => d.type === "minor_incident").length,
|
|
17388
|
+
moderate: incidents.filter(d => d.type === "moderate_incident").length,
|
|
17389
|
+
correctiveActions: incidents.filter(d => d.type === "correctiveActions").length
|
|
17077
17390
|
};
|
|
17078
17391
|
const total = incidents.length;
|
|
17079
17392
|
let background = "#f1f1f1";
|
|
17080
17393
|
if (total > 0) {
|
|
17081
|
-
|
|
17082
|
-
|
|
17083
|
-
|
|
17084
|
-
|
|
17085
|
-
|
|
17086
|
-
|
|
17087
|
-
|
|
17088
|
-
|
|
17089
|
-
|
|
17090
|
-
|
|
17091
|
-
|
|
17092
|
-
|
|
17093
|
-
|
|
17094
|
-
|
|
17095
|
-
|
|
17096
|
-
|
|
17097
|
-
|
|
17098
|
-
|
|
17099
|
-
|
|
17100
|
-
|
|
17101
|
-
|
|
17102
|
-
|
|
17103
|
-
|
|
17104
|
-
|
|
17105
|
-
|
|
17106
|
-
|
|
17107
|
-
|
|
17108
|
-
|
|
17394
|
+
// Build a dynamic array of categories with colors & percentages
|
|
17395
|
+
const categories = [{
|
|
17396
|
+
key: "major",
|
|
17397
|
+
value: totals.major,
|
|
17398
|
+
color: EVENT_COLORS.MAJOR
|
|
17399
|
+
}, {
|
|
17400
|
+
key: "moderate",
|
|
17401
|
+
value: totals.moderate,
|
|
17402
|
+
color: EVENT_COLORS.MODERATE
|
|
17403
|
+
}, {
|
|
17404
|
+
key: "minor",
|
|
17405
|
+
value: totals.minor,
|
|
17406
|
+
color: EVENT_COLORS.MINOR
|
|
17407
|
+
}, {
|
|
17408
|
+
key: "corrective",
|
|
17409
|
+
value: totals.correctiveActions,
|
|
17410
|
+
color: EVENT_COLORS.CORRECTIVE
|
|
17411
|
+
}].filter(c => c.value > 0).map(c => ({
|
|
17412
|
+
...c,
|
|
17413
|
+
perc: c.value / total * 100
|
|
17414
|
+
}));
|
|
17415
|
+
if (categories.length === 1) {
|
|
17416
|
+
background = categories[0].color;
|
|
17417
|
+
} else {
|
|
17418
|
+
const gradientStops = categories.map((cat, index) => {
|
|
17419
|
+
const stop = categories.slice(0, index).reduce((acc, c) => acc + c.perc, 0);
|
|
17420
|
+
return `${cat.color} ${Math.round(stop)}%`;
|
|
17421
|
+
});
|
|
17422
|
+
background = `radial-gradient(circle, ${gradientStops.join(", ")})`;
|
|
17423
|
+
}
|
|
17109
17424
|
}
|
|
17110
17425
|
let radius = 35;
|
|
17111
17426
|
if (data.total > 20) {
|
|
17112
|
-
|
|
17427
|
+
radius = 65;
|
|
17113
17428
|
} else if (data.total > 10) {
|
|
17114
|
-
|
|
17429
|
+
radius = 50;
|
|
17115
17430
|
} else {
|
|
17116
|
-
|
|
17431
|
+
radius = 40;
|
|
17117
17432
|
}
|
|
17118
|
-
*/
|
|
17119
|
-
|
|
17120
|
-
const {
|
|
17121
|
-
background,
|
|
17122
|
-
radius,
|
|
17123
|
-
totals
|
|
17124
|
-
} = getEventMarkerStyle(data);
|
|
17125
17433
|
innerHtml = `
|
|
17126
17434
|
<div class="main" style="background: ${background}; border: 2px solid white; width: ${radius}px; height: ${radius}px;">
|
|
17127
17435
|
<span>${data.total || 0}</span>
|
|
@@ -20265,12 +20573,12 @@ function showHideForm(form, formsValue) {
|
|
|
20265
20573
|
if (!formsValue) {
|
|
20266
20574
|
return false;
|
|
20267
20575
|
} else {
|
|
20268
|
-
const value = deepFind(formsValue, field);
|
|
20576
|
+
const value = deepFind$1(formsValue, field);
|
|
20269
20577
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formsValue : value);
|
|
20270
20578
|
return isShown;
|
|
20271
20579
|
}
|
|
20272
20580
|
} else {
|
|
20273
|
-
const value = deepFind(formsValue, field);
|
|
20581
|
+
const value = deepFind$1(formsValue, field);
|
|
20274
20582
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formsValue : value);
|
|
20275
20583
|
return isShown;
|
|
20276
20584
|
}
|
|
@@ -20502,20 +20810,20 @@ const checkCondition$3 = (condition, formsValue, repeatValues, input) => {
|
|
|
20502
20810
|
field = isRepeatable ? field.split('./')[1] : field;
|
|
20503
20811
|
if (match && field.split('.').length > 1) {
|
|
20504
20812
|
if (input.inputs) {
|
|
20505
|
-
const value = deepFind(formValue, field);
|
|
20813
|
+
const value = deepFind$1(formValue, field);
|
|
20506
20814
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
20507
20815
|
return isShown;
|
|
20508
20816
|
} else {
|
|
20509
20817
|
if (isRepeatable ? !repeatValues : !formsValue) {
|
|
20510
20818
|
return false;
|
|
20511
20819
|
} else {
|
|
20512
|
-
const value = deepFind(formValue, field);
|
|
20820
|
+
const value = deepFind$1(formValue, field);
|
|
20513
20821
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
20514
20822
|
return isShown;
|
|
20515
20823
|
}
|
|
20516
20824
|
}
|
|
20517
20825
|
} else {
|
|
20518
|
-
const value = deepFind(formValue, field);
|
|
20826
|
+
const value = deepFind$1(formValue, field);
|
|
20519
20827
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
20520
20828
|
return isShown;
|
|
20521
20829
|
}
|
|
@@ -26097,20 +26405,20 @@ const checkCondition$2 = (condition, formsValue, repeatValues, input) => {
|
|
|
26097
26405
|
field = isRepeatable ? field.split('./')[1] : field;
|
|
26098
26406
|
if (match && field.split('.').length > 1) {
|
|
26099
26407
|
if (input.inputs) {
|
|
26100
|
-
const value = deepFind(formValue, field);
|
|
26408
|
+
const value = deepFind$1(formValue, field);
|
|
26101
26409
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
26102
26410
|
return isShown;
|
|
26103
26411
|
} else {
|
|
26104
26412
|
if (isRepeatable ? !repeatValues : !formsValue) {
|
|
26105
26413
|
return false;
|
|
26106
26414
|
} else {
|
|
26107
|
-
const value = deepFind(formValue, field);
|
|
26415
|
+
const value = deepFind$1(formValue, field);
|
|
26108
26416
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
26109
26417
|
return isShown;
|
|
26110
26418
|
}
|
|
26111
26419
|
}
|
|
26112
26420
|
} else {
|
|
26113
|
-
const value = deepFind(formValue, field);
|
|
26421
|
+
const value = deepFind$1(formValue, field);
|
|
26114
26422
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
26115
26423
|
return isShown;
|
|
26116
26424
|
}
|
|
@@ -31285,16 +31593,6 @@ function AjaxSubGroup({
|
|
|
31285
31593
|
t
|
|
31286
31594
|
} = useEditContext();
|
|
31287
31595
|
const isAjaxModal = React.useMemo(() => !!form?.meta?.namespace, [form]);
|
|
31288
|
-
console.log({
|
|
31289
|
-
form,
|
|
31290
|
-
options,
|
|
31291
|
-
k,
|
|
31292
|
-
excludedKeys,
|
|
31293
|
-
values,
|
|
31294
|
-
i,
|
|
31295
|
-
formTitles,
|
|
31296
|
-
data
|
|
31297
|
-
});
|
|
31298
31596
|
const formScope = React.useMemo(() => {
|
|
31299
31597
|
const val = form.meta.formScope;
|
|
31300
31598
|
let toReturn = val;
|
|
@@ -35144,7 +35442,7 @@ const checkCondition$1 = (condition, repeatValues, formsValue) => {
|
|
|
35144
35442
|
const isNotEmpty = match === 'notEmpty';
|
|
35145
35443
|
const formValue = isRepeatable ? repeatValues : formsValue;
|
|
35146
35444
|
field = isRepeatable ? field.split('./')[1] : field;
|
|
35147
|
-
const value = deepFind(formValue, field);
|
|
35445
|
+
const value = deepFind$1(formValue, field);
|
|
35148
35446
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
35149
35447
|
return isShown;
|
|
35150
35448
|
};
|
|
@@ -35329,20 +35627,20 @@ function showHideInput$1(input, data, repeatIndex, repeatValues, inputMeta) {
|
|
|
35329
35627
|
field = isRepeatable ? field.split('./')[1] : field;
|
|
35330
35628
|
if (match && field.split('.').length > 1) {
|
|
35331
35629
|
if (input.inputs) {
|
|
35332
|
-
const value = deepFind(formValue, field);
|
|
35630
|
+
const value = deepFind$1(formValue, field);
|
|
35333
35631
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
35334
35632
|
return isShown;
|
|
35335
35633
|
} else {
|
|
35336
35634
|
if (isRepeatable ? !repeatValues : !formsValue) {
|
|
35337
35635
|
return false;
|
|
35338
35636
|
} else {
|
|
35339
|
-
const value = deepFind(formValue, field);
|
|
35637
|
+
const value = deepFind$1(formValue, field);
|
|
35340
35638
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
35341
35639
|
return isShown;
|
|
35342
35640
|
}
|
|
35343
35641
|
}
|
|
35344
35642
|
} else {
|
|
35345
|
-
const value = deepFind(formValue, field);
|
|
35643
|
+
const value = deepFind$1(formValue, field);
|
|
35346
35644
|
if (match === 'gte') {
|
|
35347
35645
|
return Number(formValue[field]) >= Number(wantedValue);
|
|
35348
35646
|
}
|
|
@@ -35488,14 +35786,14 @@ function getSubtitles$1(subtitles, position, formsValue = {}, repeatIndex, repea
|
|
|
35488
35786
|
const formValue = isRepeatable ? repeatValues : formsValue;
|
|
35489
35787
|
field = isRepeatable ? field.split('./')[1] : field;
|
|
35490
35788
|
if (match && field.split('.').length > 1) {
|
|
35491
|
-
const value = deepFind(formValue, field);
|
|
35789
|
+
const value = deepFind$1(formValue, field);
|
|
35492
35790
|
const isValid = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
35493
35791
|
if (isValid) {
|
|
35494
35792
|
newSubtitle = subtitle[subKey];
|
|
35495
35793
|
ind = subKeys.length;
|
|
35496
35794
|
}
|
|
35497
35795
|
} else {
|
|
35498
|
-
const value = deepFind(formValue, field);
|
|
35796
|
+
const value = deepFind$1(formValue, field);
|
|
35499
35797
|
const isValid = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
35500
35798
|
if (isValid) {
|
|
35501
35799
|
newSubtitle = subtitle[subKey];
|
|
@@ -38796,7 +39094,7 @@ const checkCondition = (condition, repeatValues, formsValue) => {
|
|
|
38796
39094
|
const isNotEmpty = match === 'notEmpty';
|
|
38797
39095
|
const formValue = isRepeatable ? repeatValues : formsValue;
|
|
38798
39096
|
field = isRepeatable ? field.split('./')[1] : field;
|
|
38799
|
-
const value = deepFind(formValue, field);
|
|
39097
|
+
const value = deepFind$1(formValue, field);
|
|
38800
39098
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
38801
39099
|
return isShown;
|
|
38802
39100
|
};
|
|
@@ -38813,14 +39111,14 @@ function showHideInput(input, formsValue, repeatIndex, repeatValues, setValues,
|
|
|
38813
39111
|
field = isRepeatable ? field.split('./')[1] : field;
|
|
38814
39112
|
if (match && field.split('.').length > 1) {
|
|
38815
39113
|
if (input.inputs) {
|
|
38816
|
-
const value = deepFind(formValue, field);
|
|
39114
|
+
const value = deepFind$1(formValue, field);
|
|
38817
39115
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
38818
39116
|
return isShown;
|
|
38819
39117
|
} else {
|
|
38820
39118
|
if (isRepeatable ? !repeatValues : !formsValue) {
|
|
38821
39119
|
return false;
|
|
38822
39120
|
} else {
|
|
38823
|
-
const value = deepFind(formValue, field);
|
|
39121
|
+
const value = deepFind$1(formValue, field);
|
|
38824
39122
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
38825
39123
|
return isShown;
|
|
38826
39124
|
}
|
|
@@ -38838,7 +39136,7 @@ function showHideInput(input, formsValue, repeatIndex, repeatValues, setValues,
|
|
|
38838
39136
|
if (match === 'lt') {
|
|
38839
39137
|
return Number(formValue[field]) < Number(wantedValue);
|
|
38840
39138
|
}
|
|
38841
|
-
const value = deepFind(formValue, field);
|
|
39139
|
+
const value = deepFind$1(formValue, field);
|
|
38842
39140
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
38843
39141
|
return isShown;
|
|
38844
39142
|
}
|
|
@@ -38989,14 +39287,14 @@ function getSubtitles(subtitles, position, formsValue = {}, repeatIndex, repeatV
|
|
|
38989
39287
|
const formValue = isRepeatable ? repeatValues : formsValue;
|
|
38990
39288
|
field = isRepeatable ? field.split('./')[1] : field;
|
|
38991
39289
|
if (match && field.split('.').length > 1) {
|
|
38992
|
-
const value = deepFind(formValue, field);
|
|
39290
|
+
const value = deepFind$1(formValue, field);
|
|
38993
39291
|
const isValid = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
38994
39292
|
if (isValid) {
|
|
38995
39293
|
newSubtitle = subtitle[subKey];
|
|
38996
39294
|
ind = subKeys.length;
|
|
38997
39295
|
}
|
|
38998
39296
|
} else {
|
|
38999
|
-
const value = deepFind(formValue, field);
|
|
39297
|
+
const value = deepFind$1(formValue, field);
|
|
39000
39298
|
const isValid = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
39001
39299
|
if (isValid) {
|
|
39002
39300
|
newSubtitle = subtitle[subKey];
|
|
@@ -54351,6 +54649,2204 @@ function AIQuery() {
|
|
|
54351
54649
|
return /*#__PURE__*/jsxRuntime.jsx("div", {});
|
|
54352
54650
|
}
|
|
54353
54651
|
|
|
54652
|
+
const isString = obj => typeof obj === 'string';
|
|
54653
|
+
const defer = () => {
|
|
54654
|
+
let res;
|
|
54655
|
+
let rej;
|
|
54656
|
+
const promise = new Promise((resolve, reject) => {
|
|
54657
|
+
res = resolve;
|
|
54658
|
+
rej = reject;
|
|
54659
|
+
});
|
|
54660
|
+
promise.resolve = res;
|
|
54661
|
+
promise.reject = rej;
|
|
54662
|
+
return promise;
|
|
54663
|
+
};
|
|
54664
|
+
const makeString = object => {
|
|
54665
|
+
if (object == null) return '';
|
|
54666
|
+
return '' + object;
|
|
54667
|
+
};
|
|
54668
|
+
const copy = (a, s, t) => {
|
|
54669
|
+
a.forEach(m => {
|
|
54670
|
+
if (s[m]) t[m] = s[m];
|
|
54671
|
+
});
|
|
54672
|
+
};
|
|
54673
|
+
const lastOfPathSeparatorRegExp = /###/g;
|
|
54674
|
+
const cleanKey = key => key && key.indexOf('###') > -1 ? key.replace(lastOfPathSeparatorRegExp, '.') : key;
|
|
54675
|
+
const canNotTraverseDeeper = object => !object || isString(object);
|
|
54676
|
+
const getLastOfPath = (object, path, Empty) => {
|
|
54677
|
+
const stack = !isString(path) ? path : path.split('.');
|
|
54678
|
+
let stackIndex = 0;
|
|
54679
|
+
while (stackIndex < stack.length - 1) {
|
|
54680
|
+
if (canNotTraverseDeeper(object)) return {};
|
|
54681
|
+
const key = cleanKey(stack[stackIndex]);
|
|
54682
|
+
if (!object[key] && Empty) object[key] = new Empty();
|
|
54683
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
54684
|
+
object = object[key];
|
|
54685
|
+
} else {
|
|
54686
|
+
object = {};
|
|
54687
|
+
}
|
|
54688
|
+
++stackIndex;
|
|
54689
|
+
}
|
|
54690
|
+
if (canNotTraverseDeeper(object)) return {};
|
|
54691
|
+
return {
|
|
54692
|
+
obj: object,
|
|
54693
|
+
k: cleanKey(stack[stackIndex])
|
|
54694
|
+
};
|
|
54695
|
+
};
|
|
54696
|
+
const setPath = (object, path, newValue) => {
|
|
54697
|
+
const {
|
|
54698
|
+
obj,
|
|
54699
|
+
k
|
|
54700
|
+
} = getLastOfPath(object, path, Object);
|
|
54701
|
+
if (obj !== undefined || path.length === 1) {
|
|
54702
|
+
obj[k] = newValue;
|
|
54703
|
+
return;
|
|
54704
|
+
}
|
|
54705
|
+
let e = path[path.length - 1];
|
|
54706
|
+
let p = path.slice(0, path.length - 1);
|
|
54707
|
+
let last = getLastOfPath(object, p, Object);
|
|
54708
|
+
while (last.obj === undefined && p.length) {
|
|
54709
|
+
e = `${p[p.length - 1]}.${e}`;
|
|
54710
|
+
p = p.slice(0, p.length - 1);
|
|
54711
|
+
last = getLastOfPath(object, p, Object);
|
|
54712
|
+
if (last?.obj && typeof last.obj[`${last.k}.${e}`] !== 'undefined') {
|
|
54713
|
+
last.obj = undefined;
|
|
54714
|
+
}
|
|
54715
|
+
}
|
|
54716
|
+
last.obj[`${last.k}.${e}`] = newValue;
|
|
54717
|
+
};
|
|
54718
|
+
const pushPath = (object, path, newValue, concat) => {
|
|
54719
|
+
const {
|
|
54720
|
+
obj,
|
|
54721
|
+
k
|
|
54722
|
+
} = getLastOfPath(object, path, Object);
|
|
54723
|
+
obj[k] = obj[k] || [];
|
|
54724
|
+
obj[k].push(newValue);
|
|
54725
|
+
};
|
|
54726
|
+
const getPath = (object, path) => {
|
|
54727
|
+
const {
|
|
54728
|
+
obj,
|
|
54729
|
+
k
|
|
54730
|
+
} = getLastOfPath(object, path);
|
|
54731
|
+
if (!obj) return undefined;
|
|
54732
|
+
if (!Object.prototype.hasOwnProperty.call(obj, k)) return undefined;
|
|
54733
|
+
return obj[k];
|
|
54734
|
+
};
|
|
54735
|
+
const getPathWithDefaults = (data, defaultData, key) => {
|
|
54736
|
+
const value = getPath(data, key);
|
|
54737
|
+
if (value !== undefined) {
|
|
54738
|
+
return value;
|
|
54739
|
+
}
|
|
54740
|
+
return getPath(defaultData, key);
|
|
54741
|
+
};
|
|
54742
|
+
const deepExtend = (target, source, overwrite) => {
|
|
54743
|
+
for (const prop in source) {
|
|
54744
|
+
if (prop !== '__proto__' && prop !== 'constructor') {
|
|
54745
|
+
if (prop in target) {
|
|
54746
|
+
if (isString(target[prop]) || target[prop] instanceof String || isString(source[prop]) || source[prop] instanceof String) {
|
|
54747
|
+
if (overwrite) target[prop] = source[prop];
|
|
54748
|
+
} else {
|
|
54749
|
+
deepExtend(target[prop], source[prop], overwrite);
|
|
54750
|
+
}
|
|
54751
|
+
} else {
|
|
54752
|
+
target[prop] = source[prop];
|
|
54753
|
+
}
|
|
54754
|
+
}
|
|
54755
|
+
}
|
|
54756
|
+
return target;
|
|
54757
|
+
};
|
|
54758
|
+
const regexEscape = str => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
|
|
54759
|
+
var _entityMap = {
|
|
54760
|
+
'&': '&',
|
|
54761
|
+
'<': '<',
|
|
54762
|
+
'>': '>',
|
|
54763
|
+
'"': '"',
|
|
54764
|
+
"'": ''',
|
|
54765
|
+
'/': '/'
|
|
54766
|
+
};
|
|
54767
|
+
const escape = data => {
|
|
54768
|
+
if (isString(data)) {
|
|
54769
|
+
return data.replace(/[&<>"'\/]/g, s => _entityMap[s]);
|
|
54770
|
+
}
|
|
54771
|
+
return data;
|
|
54772
|
+
};
|
|
54773
|
+
class RegExpCache {
|
|
54774
|
+
constructor(capacity) {
|
|
54775
|
+
this.capacity = capacity;
|
|
54776
|
+
this.regExpMap = new Map();
|
|
54777
|
+
this.regExpQueue = [];
|
|
54778
|
+
}
|
|
54779
|
+
getRegExp(pattern) {
|
|
54780
|
+
const regExpFromCache = this.regExpMap.get(pattern);
|
|
54781
|
+
if (regExpFromCache !== undefined) {
|
|
54782
|
+
return regExpFromCache;
|
|
54783
|
+
}
|
|
54784
|
+
const regExpNew = new RegExp(pattern);
|
|
54785
|
+
if (this.regExpQueue.length === this.capacity) {
|
|
54786
|
+
this.regExpMap.delete(this.regExpQueue.shift());
|
|
54787
|
+
}
|
|
54788
|
+
this.regExpMap.set(pattern, regExpNew);
|
|
54789
|
+
this.regExpQueue.push(pattern);
|
|
54790
|
+
return regExpNew;
|
|
54791
|
+
}
|
|
54792
|
+
}
|
|
54793
|
+
const chars = [' ', ',', '?', '!', ';'];
|
|
54794
|
+
const looksLikeObjectPathRegExpCache = new RegExpCache(20);
|
|
54795
|
+
const looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
|
|
54796
|
+
nsSeparator = nsSeparator || '';
|
|
54797
|
+
keySeparator = keySeparator || '';
|
|
54798
|
+
const possibleChars = chars.filter(c => nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0);
|
|
54799
|
+
if (possibleChars.length === 0) return true;
|
|
54800
|
+
const r = looksLikeObjectPathRegExpCache.getRegExp(`(${possibleChars.map(c => c === '?' ? '\\?' : c).join('|')})`);
|
|
54801
|
+
let matched = !r.test(key);
|
|
54802
|
+
if (!matched) {
|
|
54803
|
+
const ki = key.indexOf(keySeparator);
|
|
54804
|
+
if (ki > 0 && !r.test(key.substring(0, ki))) {
|
|
54805
|
+
matched = true;
|
|
54806
|
+
}
|
|
54807
|
+
}
|
|
54808
|
+
return matched;
|
|
54809
|
+
};
|
|
54810
|
+
const deepFind = (obj, path, keySeparator = '.') => {
|
|
54811
|
+
if (!obj) return undefined;
|
|
54812
|
+
if (obj[path]) {
|
|
54813
|
+
if (!Object.prototype.hasOwnProperty.call(obj, path)) return undefined;
|
|
54814
|
+
return obj[path];
|
|
54815
|
+
}
|
|
54816
|
+
const tokens = path.split(keySeparator);
|
|
54817
|
+
let current = obj;
|
|
54818
|
+
for (let i = 0; i < tokens.length;) {
|
|
54819
|
+
if (!current || typeof current !== 'object') {
|
|
54820
|
+
return undefined;
|
|
54821
|
+
}
|
|
54822
|
+
let next;
|
|
54823
|
+
let nextPath = '';
|
|
54824
|
+
for (let j = i; j < tokens.length; ++j) {
|
|
54825
|
+
if (j !== i) {
|
|
54826
|
+
nextPath += keySeparator;
|
|
54827
|
+
}
|
|
54828
|
+
nextPath += tokens[j];
|
|
54829
|
+
next = current[nextPath];
|
|
54830
|
+
if (next !== undefined) {
|
|
54831
|
+
if (['string', 'number', 'boolean'].indexOf(typeof next) > -1 && j < tokens.length - 1) {
|
|
54832
|
+
continue;
|
|
54833
|
+
}
|
|
54834
|
+
i += j - i + 1;
|
|
54835
|
+
break;
|
|
54836
|
+
}
|
|
54837
|
+
}
|
|
54838
|
+
current = next;
|
|
54839
|
+
}
|
|
54840
|
+
return current;
|
|
54841
|
+
};
|
|
54842
|
+
const getCleanedCode = code => code?.replace('_', '-');
|
|
54843
|
+
|
|
54844
|
+
const consoleLogger = {
|
|
54845
|
+
type: 'logger',
|
|
54846
|
+
log(args) {
|
|
54847
|
+
this.output('log', args);
|
|
54848
|
+
},
|
|
54849
|
+
warn(args) {
|
|
54850
|
+
this.output('warn', args);
|
|
54851
|
+
},
|
|
54852
|
+
error(args) {
|
|
54853
|
+
this.output('error', args);
|
|
54854
|
+
},
|
|
54855
|
+
output(type, args) {
|
|
54856
|
+
console?.[type]?.apply?.(console, args);
|
|
54857
|
+
}
|
|
54858
|
+
};
|
|
54859
|
+
class Logger {
|
|
54860
|
+
constructor(concreteLogger, options = {}) {
|
|
54861
|
+
this.init(concreteLogger, options);
|
|
54862
|
+
}
|
|
54863
|
+
init(concreteLogger, options = {}) {
|
|
54864
|
+
this.prefix = options.prefix || 'i18next:';
|
|
54865
|
+
this.logger = concreteLogger || consoleLogger;
|
|
54866
|
+
this.options = options;
|
|
54867
|
+
this.debug = options.debug;
|
|
54868
|
+
}
|
|
54869
|
+
log(...args) {
|
|
54870
|
+
return this.forward(args, 'log', '', true);
|
|
54871
|
+
}
|
|
54872
|
+
warn(...args) {
|
|
54873
|
+
return this.forward(args, 'warn', '', true);
|
|
54874
|
+
}
|
|
54875
|
+
error(...args) {
|
|
54876
|
+
return this.forward(args, 'error', '');
|
|
54877
|
+
}
|
|
54878
|
+
deprecate(...args) {
|
|
54879
|
+
return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
|
|
54880
|
+
}
|
|
54881
|
+
forward(args, lvl, prefix, debugOnly) {
|
|
54882
|
+
if (debugOnly && !this.debug) return null;
|
|
54883
|
+
if (isString(args[0])) args[0] = `${prefix}${this.prefix} ${args[0]}`;
|
|
54884
|
+
return this.logger[lvl](args);
|
|
54885
|
+
}
|
|
54886
|
+
create(moduleName) {
|
|
54887
|
+
return new Logger(this.logger, {
|
|
54888
|
+
...{
|
|
54889
|
+
prefix: `${this.prefix}:${moduleName}:`
|
|
54890
|
+
},
|
|
54891
|
+
...this.options
|
|
54892
|
+
});
|
|
54893
|
+
}
|
|
54894
|
+
clone(options) {
|
|
54895
|
+
options = options || this.options;
|
|
54896
|
+
options.prefix = options.prefix || this.prefix;
|
|
54897
|
+
return new Logger(this.logger, options);
|
|
54898
|
+
}
|
|
54899
|
+
}
|
|
54900
|
+
var baseLogger = new Logger();
|
|
54901
|
+
|
|
54902
|
+
class EventEmitter {
|
|
54903
|
+
constructor() {
|
|
54904
|
+
this.observers = {};
|
|
54905
|
+
}
|
|
54906
|
+
on(events, listener) {
|
|
54907
|
+
events.split(' ').forEach(event => {
|
|
54908
|
+
if (!this.observers[event]) this.observers[event] = new Map();
|
|
54909
|
+
const numListeners = this.observers[event].get(listener) || 0;
|
|
54910
|
+
this.observers[event].set(listener, numListeners + 1);
|
|
54911
|
+
});
|
|
54912
|
+
return this;
|
|
54913
|
+
}
|
|
54914
|
+
off(event, listener) {
|
|
54915
|
+
if (!this.observers[event]) return;
|
|
54916
|
+
if (!listener) {
|
|
54917
|
+
delete this.observers[event];
|
|
54918
|
+
return;
|
|
54919
|
+
}
|
|
54920
|
+
this.observers[event].delete(listener);
|
|
54921
|
+
}
|
|
54922
|
+
emit(event, ...args) {
|
|
54923
|
+
if (this.observers[event]) {
|
|
54924
|
+
const cloned = Array.from(this.observers[event].entries());
|
|
54925
|
+
cloned.forEach(([observer, numTimesAdded]) => {
|
|
54926
|
+
for (let i = 0; i < numTimesAdded; i++) {
|
|
54927
|
+
observer(...args);
|
|
54928
|
+
}
|
|
54929
|
+
});
|
|
54930
|
+
}
|
|
54931
|
+
if (this.observers['*']) {
|
|
54932
|
+
const cloned = Array.from(this.observers['*'].entries());
|
|
54933
|
+
cloned.forEach(([observer, numTimesAdded]) => {
|
|
54934
|
+
for (let i = 0; i < numTimesAdded; i++) {
|
|
54935
|
+
observer.apply(observer, [event, ...args]);
|
|
54936
|
+
}
|
|
54937
|
+
});
|
|
54938
|
+
}
|
|
54939
|
+
}
|
|
54940
|
+
}
|
|
54941
|
+
|
|
54942
|
+
class ResourceStore extends EventEmitter {
|
|
54943
|
+
constructor(data, options = {
|
|
54944
|
+
ns: ['translation'],
|
|
54945
|
+
defaultNS: 'translation'
|
|
54946
|
+
}) {
|
|
54947
|
+
super();
|
|
54948
|
+
this.data = data || {};
|
|
54949
|
+
this.options = options;
|
|
54950
|
+
if (this.options.keySeparator === undefined) {
|
|
54951
|
+
this.options.keySeparator = '.';
|
|
54952
|
+
}
|
|
54953
|
+
if (this.options.ignoreJSONStructure === undefined) {
|
|
54954
|
+
this.options.ignoreJSONStructure = true;
|
|
54955
|
+
}
|
|
54956
|
+
}
|
|
54957
|
+
addNamespaces(ns) {
|
|
54958
|
+
if (this.options.ns.indexOf(ns) < 0) {
|
|
54959
|
+
this.options.ns.push(ns);
|
|
54960
|
+
}
|
|
54961
|
+
}
|
|
54962
|
+
removeNamespaces(ns) {
|
|
54963
|
+
const index = this.options.ns.indexOf(ns);
|
|
54964
|
+
if (index > -1) {
|
|
54965
|
+
this.options.ns.splice(index, 1);
|
|
54966
|
+
}
|
|
54967
|
+
}
|
|
54968
|
+
getResource(lng, ns, key, options = {}) {
|
|
54969
|
+
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
54970
|
+
const ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
54971
|
+
let path;
|
|
54972
|
+
if (lng.indexOf('.') > -1) {
|
|
54973
|
+
path = lng.split('.');
|
|
54974
|
+
} else {
|
|
54975
|
+
path = [lng, ns];
|
|
54976
|
+
if (key) {
|
|
54977
|
+
if (Array.isArray(key)) {
|
|
54978
|
+
path.push(...key);
|
|
54979
|
+
} else if (isString(key) && keySeparator) {
|
|
54980
|
+
path.push(...key.split(keySeparator));
|
|
54981
|
+
} else {
|
|
54982
|
+
path.push(key);
|
|
54983
|
+
}
|
|
54984
|
+
}
|
|
54985
|
+
}
|
|
54986
|
+
const result = getPath(this.data, path);
|
|
54987
|
+
if (!result && !ns && !key && lng.indexOf('.') > -1) {
|
|
54988
|
+
lng = path[0];
|
|
54989
|
+
ns = path[1];
|
|
54990
|
+
key = path.slice(2).join('.');
|
|
54991
|
+
}
|
|
54992
|
+
if (result || !ignoreJSONStructure || !isString(key)) return result;
|
|
54993
|
+
return deepFind(this.data?.[lng]?.[ns], key, keySeparator);
|
|
54994
|
+
}
|
|
54995
|
+
addResource(lng, ns, key, value, options = {
|
|
54996
|
+
silent: false
|
|
54997
|
+
}) {
|
|
54998
|
+
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
54999
|
+
let path = [lng, ns];
|
|
55000
|
+
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
55001
|
+
if (lng.indexOf('.') > -1) {
|
|
55002
|
+
path = lng.split('.');
|
|
55003
|
+
value = ns;
|
|
55004
|
+
ns = path[1];
|
|
55005
|
+
}
|
|
55006
|
+
this.addNamespaces(ns);
|
|
55007
|
+
setPath(this.data, path, value);
|
|
55008
|
+
if (!options.silent) this.emit('added', lng, ns, key, value);
|
|
55009
|
+
}
|
|
55010
|
+
addResources(lng, ns, resources, options = {
|
|
55011
|
+
silent: false
|
|
55012
|
+
}) {
|
|
55013
|
+
for (const m in resources) {
|
|
55014
|
+
if (isString(resources[m]) || Array.isArray(resources[m])) this.addResource(lng, ns, m, resources[m], {
|
|
55015
|
+
silent: true
|
|
55016
|
+
});
|
|
55017
|
+
}
|
|
55018
|
+
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
55019
|
+
}
|
|
55020
|
+
addResourceBundle(lng, ns, resources, deep, overwrite, options = {
|
|
55021
|
+
silent: false,
|
|
55022
|
+
skipCopy: false
|
|
55023
|
+
}) {
|
|
55024
|
+
let path = [lng, ns];
|
|
55025
|
+
if (lng.indexOf('.') > -1) {
|
|
55026
|
+
path = lng.split('.');
|
|
55027
|
+
deep = resources;
|
|
55028
|
+
resources = ns;
|
|
55029
|
+
ns = path[1];
|
|
55030
|
+
}
|
|
55031
|
+
this.addNamespaces(ns);
|
|
55032
|
+
let pack = getPath(this.data, path) || {};
|
|
55033
|
+
if (!options.skipCopy) resources = JSON.parse(JSON.stringify(resources));
|
|
55034
|
+
if (deep) {
|
|
55035
|
+
deepExtend(pack, resources, overwrite);
|
|
55036
|
+
} else {
|
|
55037
|
+
pack = {
|
|
55038
|
+
...pack,
|
|
55039
|
+
...resources
|
|
55040
|
+
};
|
|
55041
|
+
}
|
|
55042
|
+
setPath(this.data, path, pack);
|
|
55043
|
+
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
55044
|
+
}
|
|
55045
|
+
removeResourceBundle(lng, ns) {
|
|
55046
|
+
if (this.hasResourceBundle(lng, ns)) {
|
|
55047
|
+
delete this.data[lng][ns];
|
|
55048
|
+
}
|
|
55049
|
+
this.removeNamespaces(ns);
|
|
55050
|
+
this.emit('removed', lng, ns);
|
|
55051
|
+
}
|
|
55052
|
+
hasResourceBundle(lng, ns) {
|
|
55053
|
+
return this.getResource(lng, ns) !== undefined;
|
|
55054
|
+
}
|
|
55055
|
+
getResourceBundle(lng, ns) {
|
|
55056
|
+
if (!ns) ns = this.options.defaultNS;
|
|
55057
|
+
return this.getResource(lng, ns);
|
|
55058
|
+
}
|
|
55059
|
+
getDataByLanguage(lng) {
|
|
55060
|
+
return this.data[lng];
|
|
55061
|
+
}
|
|
55062
|
+
hasLanguageSomeTranslations(lng) {
|
|
55063
|
+
const data = this.getDataByLanguage(lng);
|
|
55064
|
+
const n = data && Object.keys(data) || [];
|
|
55065
|
+
return !!n.find(v => data[v] && Object.keys(data[v]).length > 0);
|
|
55066
|
+
}
|
|
55067
|
+
toJSON() {
|
|
55068
|
+
return this.data;
|
|
55069
|
+
}
|
|
55070
|
+
}
|
|
55071
|
+
|
|
55072
|
+
var postProcessor = {
|
|
55073
|
+
processors: {},
|
|
55074
|
+
addPostProcessor(module) {
|
|
55075
|
+
this.processors[module.name] = module;
|
|
55076
|
+
},
|
|
55077
|
+
handle(processors, value, key, options, translator) {
|
|
55078
|
+
processors.forEach(processor => {
|
|
55079
|
+
value = this.processors[processor]?.process(value, key, options, translator) ?? value;
|
|
55080
|
+
});
|
|
55081
|
+
return value;
|
|
55082
|
+
}
|
|
55083
|
+
};
|
|
55084
|
+
|
|
55085
|
+
const PATH_KEY = Symbol('i18next/PATH_KEY');
|
|
55086
|
+
function createProxy() {
|
|
55087
|
+
const state = [];
|
|
55088
|
+
const handler = Object.create(null);
|
|
55089
|
+
let proxy;
|
|
55090
|
+
handler.get = (target, key) => {
|
|
55091
|
+
proxy?.revoke?.();
|
|
55092
|
+
if (key === PATH_KEY) return state;
|
|
55093
|
+
state.push(key);
|
|
55094
|
+
proxy = Proxy.revocable(target, handler);
|
|
55095
|
+
return proxy.proxy;
|
|
55096
|
+
};
|
|
55097
|
+
return Proxy.revocable(Object.create(null), handler).proxy;
|
|
55098
|
+
}
|
|
55099
|
+
function keysFromSelector(selector, opts) {
|
|
55100
|
+
const {
|
|
55101
|
+
[PATH_KEY]: path
|
|
55102
|
+
} = selector(createProxy());
|
|
55103
|
+
return path.join(opts?.keySeparator ?? '.');
|
|
55104
|
+
}
|
|
55105
|
+
|
|
55106
|
+
const checkedLoadedFor = {};
|
|
55107
|
+
const shouldHandleAsObject = res => !isString(res) && typeof res !== 'boolean' && typeof res !== 'number';
|
|
55108
|
+
class Translator extends EventEmitter {
|
|
55109
|
+
constructor(services, options = {}) {
|
|
55110
|
+
super();
|
|
55111
|
+
copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector', 'i18nFormat', 'utils'], services, this);
|
|
55112
|
+
this.options = options;
|
|
55113
|
+
if (this.options.keySeparator === undefined) {
|
|
55114
|
+
this.options.keySeparator = '.';
|
|
55115
|
+
}
|
|
55116
|
+
this.logger = baseLogger.create('translator');
|
|
55117
|
+
}
|
|
55118
|
+
changeLanguage(lng) {
|
|
55119
|
+
if (lng) this.language = lng;
|
|
55120
|
+
}
|
|
55121
|
+
exists(key, o = {
|
|
55122
|
+
interpolation: {}
|
|
55123
|
+
}) {
|
|
55124
|
+
const opt = {
|
|
55125
|
+
...o
|
|
55126
|
+
};
|
|
55127
|
+
if (key == null) return false;
|
|
55128
|
+
const resolved = this.resolve(key, opt);
|
|
55129
|
+
return resolved?.res !== undefined;
|
|
55130
|
+
}
|
|
55131
|
+
extractFromKey(key, opt) {
|
|
55132
|
+
let nsSeparator = opt.nsSeparator !== undefined ? opt.nsSeparator : this.options.nsSeparator;
|
|
55133
|
+
if (nsSeparator === undefined) nsSeparator = ':';
|
|
55134
|
+
const keySeparator = opt.keySeparator !== undefined ? opt.keySeparator : this.options.keySeparator;
|
|
55135
|
+
let namespaces = opt.ns || this.options.defaultNS || [];
|
|
55136
|
+
const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
|
|
55137
|
+
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !opt.keySeparator && !this.options.userDefinedNsSeparator && !opt.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
55138
|
+
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
55139
|
+
const m = key.match(this.interpolator.nestingRegexp);
|
|
55140
|
+
if (m && m.length > 0) {
|
|
55141
|
+
return {
|
|
55142
|
+
key,
|
|
55143
|
+
namespaces: isString(namespaces) ? [namespaces] : namespaces
|
|
55144
|
+
};
|
|
55145
|
+
}
|
|
55146
|
+
const parts = key.split(nsSeparator);
|
|
55147
|
+
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
|
|
55148
|
+
key = parts.join(keySeparator);
|
|
55149
|
+
}
|
|
55150
|
+
return {
|
|
55151
|
+
key,
|
|
55152
|
+
namespaces: isString(namespaces) ? [namespaces] : namespaces
|
|
55153
|
+
};
|
|
55154
|
+
}
|
|
55155
|
+
translate(keys, o, lastKey) {
|
|
55156
|
+
let opt = typeof o === 'object' ? {
|
|
55157
|
+
...o
|
|
55158
|
+
} : o;
|
|
55159
|
+
if (typeof opt !== 'object' && this.options.overloadTranslationOptionHandler) {
|
|
55160
|
+
opt = this.options.overloadTranslationOptionHandler(arguments);
|
|
55161
|
+
}
|
|
55162
|
+
if (typeof opt === 'object') opt = {
|
|
55163
|
+
...opt
|
|
55164
|
+
};
|
|
55165
|
+
if (!opt) opt = {};
|
|
55166
|
+
if (keys == null) return '';
|
|
55167
|
+
if (typeof keys === 'function') keys = keysFromSelector(keys, {
|
|
55168
|
+
...this.options,
|
|
55169
|
+
...opt
|
|
55170
|
+
});
|
|
55171
|
+
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
55172
|
+
const returnDetails = opt.returnDetails !== undefined ? opt.returnDetails : this.options.returnDetails;
|
|
55173
|
+
const keySeparator = opt.keySeparator !== undefined ? opt.keySeparator : this.options.keySeparator;
|
|
55174
|
+
const {
|
|
55175
|
+
key,
|
|
55176
|
+
namespaces
|
|
55177
|
+
} = this.extractFromKey(keys[keys.length - 1], opt);
|
|
55178
|
+
const namespace = namespaces[namespaces.length - 1];
|
|
55179
|
+
let nsSeparator = opt.nsSeparator !== undefined ? opt.nsSeparator : this.options.nsSeparator;
|
|
55180
|
+
if (nsSeparator === undefined) nsSeparator = ':';
|
|
55181
|
+
const lng = opt.lng || this.language;
|
|
55182
|
+
const appendNamespaceToCIMode = opt.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
55183
|
+
if (lng?.toLowerCase() === 'cimode') {
|
|
55184
|
+
if (appendNamespaceToCIMode) {
|
|
55185
|
+
if (returnDetails) {
|
|
55186
|
+
return {
|
|
55187
|
+
res: `${namespace}${nsSeparator}${key}`,
|
|
55188
|
+
usedKey: key,
|
|
55189
|
+
exactUsedKey: key,
|
|
55190
|
+
usedLng: lng,
|
|
55191
|
+
usedNS: namespace,
|
|
55192
|
+
usedParams: this.getUsedParamsDetails(opt)
|
|
55193
|
+
};
|
|
55194
|
+
}
|
|
55195
|
+
return `${namespace}${nsSeparator}${key}`;
|
|
55196
|
+
}
|
|
55197
|
+
if (returnDetails) {
|
|
55198
|
+
return {
|
|
55199
|
+
res: key,
|
|
55200
|
+
usedKey: key,
|
|
55201
|
+
exactUsedKey: key,
|
|
55202
|
+
usedLng: lng,
|
|
55203
|
+
usedNS: namespace,
|
|
55204
|
+
usedParams: this.getUsedParamsDetails(opt)
|
|
55205
|
+
};
|
|
55206
|
+
}
|
|
55207
|
+
return key;
|
|
55208
|
+
}
|
|
55209
|
+
const resolved = this.resolve(keys, opt);
|
|
55210
|
+
let res = resolved?.res;
|
|
55211
|
+
const resUsedKey = resolved?.usedKey || key;
|
|
55212
|
+
const resExactUsedKey = resolved?.exactUsedKey || key;
|
|
55213
|
+
const noObject = ['[object Number]', '[object Function]', '[object RegExp]'];
|
|
55214
|
+
const joinArrays = opt.joinArrays !== undefined ? opt.joinArrays : this.options.joinArrays;
|
|
55215
|
+
const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
55216
|
+
const needsPluralHandling = opt.count !== undefined && !isString(opt.count);
|
|
55217
|
+
const hasDefaultValue = Translator.hasDefaultValue(opt);
|
|
55218
|
+
const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, opt) : '';
|
|
55219
|
+
const defaultValueSuffixOrdinalFallback = opt.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, {
|
|
55220
|
+
ordinal: false
|
|
55221
|
+
}) : '';
|
|
55222
|
+
const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
|
|
55223
|
+
const defaultValue = needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] || opt[`defaultValue${defaultValueSuffix}`] || opt[`defaultValue${defaultValueSuffixOrdinalFallback}`] || opt.defaultValue;
|
|
55224
|
+
let resForObjHndl = res;
|
|
55225
|
+
if (handleAsObjectInI18nFormat && !res && hasDefaultValue) {
|
|
55226
|
+
resForObjHndl = defaultValue;
|
|
55227
|
+
}
|
|
55228
|
+
const handleAsObject = shouldHandleAsObject(resForObjHndl);
|
|
55229
|
+
const resType = Object.prototype.toString.apply(resForObjHndl);
|
|
55230
|
+
if (handleAsObjectInI18nFormat && resForObjHndl && handleAsObject && noObject.indexOf(resType) < 0 && !(isString(joinArrays) && Array.isArray(resForObjHndl))) {
|
|
55231
|
+
if (!opt.returnObjects && !this.options.returnObjects) {
|
|
55232
|
+
if (!this.options.returnedObjectHandler) {
|
|
55233
|
+
this.logger.warn('accessing an object - but returnObjects options is not enabled!');
|
|
55234
|
+
}
|
|
55235
|
+
const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, resForObjHndl, {
|
|
55236
|
+
...opt,
|
|
55237
|
+
ns: namespaces
|
|
55238
|
+
}) : `key '${key} (${this.language})' returned an object instead of string.`;
|
|
55239
|
+
if (returnDetails) {
|
|
55240
|
+
resolved.res = r;
|
|
55241
|
+
resolved.usedParams = this.getUsedParamsDetails(opt);
|
|
55242
|
+
return resolved;
|
|
55243
|
+
}
|
|
55244
|
+
return r;
|
|
55245
|
+
}
|
|
55246
|
+
if (keySeparator) {
|
|
55247
|
+
const resTypeIsArray = Array.isArray(resForObjHndl);
|
|
55248
|
+
const copy = resTypeIsArray ? [] : {};
|
|
55249
|
+
const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
55250
|
+
for (const m in resForObjHndl) {
|
|
55251
|
+
if (Object.prototype.hasOwnProperty.call(resForObjHndl, m)) {
|
|
55252
|
+
const deepKey = `${newKeyToUse}${keySeparator}${m}`;
|
|
55253
|
+
if (hasDefaultValue && !res) {
|
|
55254
|
+
copy[m] = this.translate(deepKey, {
|
|
55255
|
+
...opt,
|
|
55256
|
+
defaultValue: shouldHandleAsObject(defaultValue) ? defaultValue[m] : undefined,
|
|
55257
|
+
...{
|
|
55258
|
+
joinArrays: false,
|
|
55259
|
+
ns: namespaces
|
|
55260
|
+
}
|
|
55261
|
+
});
|
|
55262
|
+
} else {
|
|
55263
|
+
copy[m] = this.translate(deepKey, {
|
|
55264
|
+
...opt,
|
|
55265
|
+
...{
|
|
55266
|
+
joinArrays: false,
|
|
55267
|
+
ns: namespaces
|
|
55268
|
+
}
|
|
55269
|
+
});
|
|
55270
|
+
}
|
|
55271
|
+
if (copy[m] === deepKey) copy[m] = resForObjHndl[m];
|
|
55272
|
+
}
|
|
55273
|
+
}
|
|
55274
|
+
res = copy;
|
|
55275
|
+
}
|
|
55276
|
+
} else if (handleAsObjectInI18nFormat && isString(joinArrays) && Array.isArray(res)) {
|
|
55277
|
+
res = res.join(joinArrays);
|
|
55278
|
+
if (res) res = this.extendTranslation(res, keys, opt, lastKey);
|
|
55279
|
+
} else {
|
|
55280
|
+
let usedDefault = false;
|
|
55281
|
+
let usedKey = false;
|
|
55282
|
+
if (!this.isValidLookup(res) && hasDefaultValue) {
|
|
55283
|
+
usedDefault = true;
|
|
55284
|
+
res = defaultValue;
|
|
55285
|
+
}
|
|
55286
|
+
if (!this.isValidLookup(res)) {
|
|
55287
|
+
usedKey = true;
|
|
55288
|
+
res = key;
|
|
55289
|
+
}
|
|
55290
|
+
const missingKeyNoValueFallbackToKey = opt.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
|
|
55291
|
+
const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? undefined : res;
|
|
55292
|
+
const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
55293
|
+
if (usedKey || usedDefault || updateMissing) {
|
|
55294
|
+
this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? defaultValue : res);
|
|
55295
|
+
if (keySeparator) {
|
|
55296
|
+
const fk = this.resolve(key, {
|
|
55297
|
+
...opt,
|
|
55298
|
+
keySeparator: false
|
|
55299
|
+
});
|
|
55300
|
+
if (fk && fk.res) this.logger.warn('Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.');
|
|
55301
|
+
}
|
|
55302
|
+
let lngs = [];
|
|
55303
|
+
const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, opt.lng || this.language);
|
|
55304
|
+
if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) {
|
|
55305
|
+
for (let i = 0; i < fallbackLngs.length; i++) {
|
|
55306
|
+
lngs.push(fallbackLngs[i]);
|
|
55307
|
+
}
|
|
55308
|
+
} else if (this.options.saveMissingTo === 'all') {
|
|
55309
|
+
lngs = this.languageUtils.toResolveHierarchy(opt.lng || this.language);
|
|
55310
|
+
} else {
|
|
55311
|
+
lngs.push(opt.lng || this.language);
|
|
55312
|
+
}
|
|
55313
|
+
const send = (l, k, specificDefaultValue) => {
|
|
55314
|
+
const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
55315
|
+
if (this.options.missingKeyHandler) {
|
|
55316
|
+
this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, opt);
|
|
55317
|
+
} else if (this.backendConnector?.saveMissing) {
|
|
55318
|
+
this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, opt);
|
|
55319
|
+
}
|
|
55320
|
+
this.emit('missingKey', l, namespace, k, res);
|
|
55321
|
+
};
|
|
55322
|
+
if (this.options.saveMissing) {
|
|
55323
|
+
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
55324
|
+
lngs.forEach(language => {
|
|
55325
|
+
const suffixes = this.pluralResolver.getSuffixes(language, opt);
|
|
55326
|
+
if (needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.indexOf(`${this.options.pluralSeparator}zero`) < 0) {
|
|
55327
|
+
suffixes.push(`${this.options.pluralSeparator}zero`);
|
|
55328
|
+
}
|
|
55329
|
+
suffixes.forEach(suffix => {
|
|
55330
|
+
send([language], key + suffix, opt[`defaultValue${suffix}`] || defaultValue);
|
|
55331
|
+
});
|
|
55332
|
+
});
|
|
55333
|
+
} else {
|
|
55334
|
+
send(lngs, key, defaultValue);
|
|
55335
|
+
}
|
|
55336
|
+
}
|
|
55337
|
+
}
|
|
55338
|
+
res = this.extendTranslation(res, keys, opt, resolved, lastKey);
|
|
55339
|
+
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) {
|
|
55340
|
+
res = `${namespace}${nsSeparator}${key}`;
|
|
55341
|
+
}
|
|
55342
|
+
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
|
|
55343
|
+
res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}${nsSeparator}${key}` : key, usedDefault ? res : undefined, opt);
|
|
55344
|
+
}
|
|
55345
|
+
}
|
|
55346
|
+
if (returnDetails) {
|
|
55347
|
+
resolved.res = res;
|
|
55348
|
+
resolved.usedParams = this.getUsedParamsDetails(opt);
|
|
55349
|
+
return resolved;
|
|
55350
|
+
}
|
|
55351
|
+
return res;
|
|
55352
|
+
}
|
|
55353
|
+
extendTranslation(res, key, opt, resolved, lastKey) {
|
|
55354
|
+
if (this.i18nFormat?.parse) {
|
|
55355
|
+
res = this.i18nFormat.parse(res, {
|
|
55356
|
+
...this.options.interpolation.defaultVariables,
|
|
55357
|
+
...opt
|
|
55358
|
+
}, opt.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
|
|
55359
|
+
resolved
|
|
55360
|
+
});
|
|
55361
|
+
} else if (!opt.skipInterpolation) {
|
|
55362
|
+
if (opt.interpolation) this.interpolator.init({
|
|
55363
|
+
...opt,
|
|
55364
|
+
...{
|
|
55365
|
+
interpolation: {
|
|
55366
|
+
...this.options.interpolation,
|
|
55367
|
+
...opt.interpolation
|
|
55368
|
+
}
|
|
55369
|
+
}
|
|
55370
|
+
});
|
|
55371
|
+
const skipOnVariables = isString(res) && (opt?.interpolation?.skipOnVariables !== undefined ? opt.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
55372
|
+
let nestBef;
|
|
55373
|
+
if (skipOnVariables) {
|
|
55374
|
+
const nb = res.match(this.interpolator.nestingRegexp);
|
|
55375
|
+
nestBef = nb && nb.length;
|
|
55376
|
+
}
|
|
55377
|
+
let data = opt.replace && !isString(opt.replace) ? opt.replace : opt;
|
|
55378
|
+
if (this.options.interpolation.defaultVariables) data = {
|
|
55379
|
+
...this.options.interpolation.defaultVariables,
|
|
55380
|
+
...data
|
|
55381
|
+
};
|
|
55382
|
+
res = this.interpolator.interpolate(res, data, opt.lng || this.language || resolved.usedLng, opt);
|
|
55383
|
+
if (skipOnVariables) {
|
|
55384
|
+
const na = res.match(this.interpolator.nestingRegexp);
|
|
55385
|
+
const nestAft = na && na.length;
|
|
55386
|
+
if (nestBef < nestAft) opt.nest = false;
|
|
55387
|
+
}
|
|
55388
|
+
if (!opt.lng && resolved && resolved.res) opt.lng = this.language || resolved.usedLng;
|
|
55389
|
+
if (opt.nest !== false) res = this.interpolator.nest(res, (...args) => {
|
|
55390
|
+
if (lastKey?.[0] === args[0] && !opt.context) {
|
|
55391
|
+
this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
|
|
55392
|
+
return null;
|
|
55393
|
+
}
|
|
55394
|
+
return this.translate(...args, key);
|
|
55395
|
+
}, opt);
|
|
55396
|
+
if (opt.interpolation) this.interpolator.reset();
|
|
55397
|
+
}
|
|
55398
|
+
const postProcess = opt.postProcess || this.options.postProcess;
|
|
55399
|
+
const postProcessorNames = isString(postProcess) ? [postProcess] : postProcess;
|
|
55400
|
+
if (res != null && postProcessorNames?.length && opt.applyPostProcessor !== false) {
|
|
55401
|
+
res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
|
|
55402
|
+
i18nResolved: {
|
|
55403
|
+
...resolved,
|
|
55404
|
+
usedParams: this.getUsedParamsDetails(opt)
|
|
55405
|
+
},
|
|
55406
|
+
...opt
|
|
55407
|
+
} : opt, this);
|
|
55408
|
+
}
|
|
55409
|
+
return res;
|
|
55410
|
+
}
|
|
55411
|
+
resolve(keys, opt = {}) {
|
|
55412
|
+
let found;
|
|
55413
|
+
let usedKey;
|
|
55414
|
+
let exactUsedKey;
|
|
55415
|
+
let usedLng;
|
|
55416
|
+
let usedNS;
|
|
55417
|
+
if (isString(keys)) keys = [keys];
|
|
55418
|
+
keys.forEach(k => {
|
|
55419
|
+
if (this.isValidLookup(found)) return;
|
|
55420
|
+
const extracted = this.extractFromKey(k, opt);
|
|
55421
|
+
const key = extracted.key;
|
|
55422
|
+
usedKey = key;
|
|
55423
|
+
let namespaces = extracted.namespaces;
|
|
55424
|
+
if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
|
|
55425
|
+
const needsPluralHandling = opt.count !== undefined && !isString(opt.count);
|
|
55426
|
+
const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
|
|
55427
|
+
const needsContextHandling = opt.context !== undefined && (isString(opt.context) || typeof opt.context === 'number') && opt.context !== '';
|
|
55428
|
+
const codes = opt.lngs ? opt.lngs : this.languageUtils.toResolveHierarchy(opt.lng || this.language, opt.fallbackLng);
|
|
55429
|
+
namespaces.forEach(ns => {
|
|
55430
|
+
if (this.isValidLookup(found)) return;
|
|
55431
|
+
usedNS = ns;
|
|
55432
|
+
if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils?.hasLoadedNamespace && !this.utils?.hasLoadedNamespace(usedNS)) {
|
|
55433
|
+
checkedLoadedFor[`${codes[0]}-${ns}`] = true;
|
|
55434
|
+
this.logger.warn(`key "${usedKey}" for languages "${codes.join(', ')}" won't get resolved as namespace "${usedNS}" was not yet loaded`, 'This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!');
|
|
55435
|
+
}
|
|
55436
|
+
codes.forEach(code => {
|
|
55437
|
+
if (this.isValidLookup(found)) return;
|
|
55438
|
+
usedLng = code;
|
|
55439
|
+
const finalKeys = [key];
|
|
55440
|
+
if (this.i18nFormat?.addLookupKeys) {
|
|
55441
|
+
this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, opt);
|
|
55442
|
+
} else {
|
|
55443
|
+
let pluralSuffix;
|
|
55444
|
+
if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, opt.count, opt);
|
|
55445
|
+
const zeroSuffix = `${this.options.pluralSeparator}zero`;
|
|
55446
|
+
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
|
|
55447
|
+
if (needsPluralHandling) {
|
|
55448
|
+
if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
55449
|
+
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
55450
|
+
}
|
|
55451
|
+
finalKeys.push(key + pluralSuffix);
|
|
55452
|
+
if (needsZeroSuffixLookup) {
|
|
55453
|
+
finalKeys.push(key + zeroSuffix);
|
|
55454
|
+
}
|
|
55455
|
+
}
|
|
55456
|
+
if (needsContextHandling) {
|
|
55457
|
+
const contextKey = `${key}${this.options.contextSeparator || '_'}${opt.context}`;
|
|
55458
|
+
finalKeys.push(contextKey);
|
|
55459
|
+
if (needsPluralHandling) {
|
|
55460
|
+
if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
55461
|
+
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
55462
|
+
}
|
|
55463
|
+
finalKeys.push(contextKey + pluralSuffix);
|
|
55464
|
+
if (needsZeroSuffixLookup) {
|
|
55465
|
+
finalKeys.push(contextKey + zeroSuffix);
|
|
55466
|
+
}
|
|
55467
|
+
}
|
|
55468
|
+
}
|
|
55469
|
+
}
|
|
55470
|
+
let possibleKey;
|
|
55471
|
+
while (possibleKey = finalKeys.pop()) {
|
|
55472
|
+
if (!this.isValidLookup(found)) {
|
|
55473
|
+
exactUsedKey = possibleKey;
|
|
55474
|
+
found = this.getResource(code, ns, possibleKey, opt);
|
|
55475
|
+
}
|
|
55476
|
+
}
|
|
55477
|
+
});
|
|
55478
|
+
});
|
|
55479
|
+
});
|
|
55480
|
+
return {
|
|
55481
|
+
res: found,
|
|
55482
|
+
usedKey,
|
|
55483
|
+
exactUsedKey,
|
|
55484
|
+
usedLng,
|
|
55485
|
+
usedNS
|
|
55486
|
+
};
|
|
55487
|
+
}
|
|
55488
|
+
isValidLookup(res) {
|
|
55489
|
+
return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === '');
|
|
55490
|
+
}
|
|
55491
|
+
getResource(code, ns, key, options = {}) {
|
|
55492
|
+
if (this.i18nFormat?.getResource) return this.i18nFormat.getResource(code, ns, key, options);
|
|
55493
|
+
return this.resourceStore.getResource(code, ns, key, options);
|
|
55494
|
+
}
|
|
55495
|
+
getUsedParamsDetails(options = {}) {
|
|
55496
|
+
const optionsKeys = ['defaultValue', 'ordinal', 'context', 'replace', 'lng', 'lngs', 'fallbackLng', 'ns', 'keySeparator', 'nsSeparator', 'returnObjects', 'returnDetails', 'joinArrays', 'postProcess', 'interpolation'];
|
|
55497
|
+
const useOptionsReplaceForData = options.replace && !isString(options.replace);
|
|
55498
|
+
let data = useOptionsReplaceForData ? options.replace : options;
|
|
55499
|
+
if (useOptionsReplaceForData && typeof options.count !== 'undefined') {
|
|
55500
|
+
data.count = options.count;
|
|
55501
|
+
}
|
|
55502
|
+
if (this.options.interpolation.defaultVariables) {
|
|
55503
|
+
data = {
|
|
55504
|
+
...this.options.interpolation.defaultVariables,
|
|
55505
|
+
...data
|
|
55506
|
+
};
|
|
55507
|
+
}
|
|
55508
|
+
if (!useOptionsReplaceForData) {
|
|
55509
|
+
data = {
|
|
55510
|
+
...data
|
|
55511
|
+
};
|
|
55512
|
+
for (const key of optionsKeys) {
|
|
55513
|
+
delete data[key];
|
|
55514
|
+
}
|
|
55515
|
+
}
|
|
55516
|
+
return data;
|
|
55517
|
+
}
|
|
55518
|
+
static hasDefaultValue(options) {
|
|
55519
|
+
const prefix = 'defaultValue';
|
|
55520
|
+
for (const option in options) {
|
|
55521
|
+
if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && undefined !== options[option]) {
|
|
55522
|
+
return true;
|
|
55523
|
+
}
|
|
55524
|
+
}
|
|
55525
|
+
return false;
|
|
55526
|
+
}
|
|
55527
|
+
}
|
|
55528
|
+
|
|
55529
|
+
class LanguageUtil {
|
|
55530
|
+
constructor(options) {
|
|
55531
|
+
this.options = options;
|
|
55532
|
+
this.supportedLngs = this.options.supportedLngs || false;
|
|
55533
|
+
this.logger = baseLogger.create('languageUtils');
|
|
55534
|
+
}
|
|
55535
|
+
getScriptPartFromCode(code) {
|
|
55536
|
+
code = getCleanedCode(code);
|
|
55537
|
+
if (!code || code.indexOf('-') < 0) return null;
|
|
55538
|
+
const p = code.split('-');
|
|
55539
|
+
if (p.length === 2) return null;
|
|
55540
|
+
p.pop();
|
|
55541
|
+
if (p[p.length - 1].toLowerCase() === 'x') return null;
|
|
55542
|
+
return this.formatLanguageCode(p.join('-'));
|
|
55543
|
+
}
|
|
55544
|
+
getLanguagePartFromCode(code) {
|
|
55545
|
+
code = getCleanedCode(code);
|
|
55546
|
+
if (!code || code.indexOf('-') < 0) return code;
|
|
55547
|
+
const p = code.split('-');
|
|
55548
|
+
return this.formatLanguageCode(p[0]);
|
|
55549
|
+
}
|
|
55550
|
+
formatLanguageCode(code) {
|
|
55551
|
+
if (isString(code) && code.indexOf('-') > -1) {
|
|
55552
|
+
let formattedCode;
|
|
55553
|
+
try {
|
|
55554
|
+
formattedCode = Intl.getCanonicalLocales(code)[0];
|
|
55555
|
+
} catch (e) {}
|
|
55556
|
+
if (formattedCode && this.options.lowerCaseLng) {
|
|
55557
|
+
formattedCode = formattedCode.toLowerCase();
|
|
55558
|
+
}
|
|
55559
|
+
if (formattedCode) return formattedCode;
|
|
55560
|
+
if (this.options.lowerCaseLng) {
|
|
55561
|
+
return code.toLowerCase();
|
|
55562
|
+
}
|
|
55563
|
+
return code;
|
|
55564
|
+
}
|
|
55565
|
+
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
|
|
55566
|
+
}
|
|
55567
|
+
isSupportedCode(code) {
|
|
55568
|
+
if (this.options.load === 'languageOnly' || this.options.nonExplicitSupportedLngs) {
|
|
55569
|
+
code = this.getLanguagePartFromCode(code);
|
|
55570
|
+
}
|
|
55571
|
+
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
|
|
55572
|
+
}
|
|
55573
|
+
getBestMatchFromCodes(codes) {
|
|
55574
|
+
if (!codes) return null;
|
|
55575
|
+
let found;
|
|
55576
|
+
codes.forEach(code => {
|
|
55577
|
+
if (found) return;
|
|
55578
|
+
const cleanedLng = this.formatLanguageCode(code);
|
|
55579
|
+
if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
|
|
55580
|
+
});
|
|
55581
|
+
if (!found && this.options.supportedLngs) {
|
|
55582
|
+
codes.forEach(code => {
|
|
55583
|
+
if (found) return;
|
|
55584
|
+
const lngScOnly = this.getScriptPartFromCode(code);
|
|
55585
|
+
if (this.isSupportedCode(lngScOnly)) return found = lngScOnly;
|
|
55586
|
+
const lngOnly = this.getLanguagePartFromCode(code);
|
|
55587
|
+
if (this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
55588
|
+
found = this.options.supportedLngs.find(supportedLng => {
|
|
55589
|
+
if (supportedLng === lngOnly) return supportedLng;
|
|
55590
|
+
if (supportedLng.indexOf('-') < 0 && lngOnly.indexOf('-') < 0) return;
|
|
55591
|
+
if (supportedLng.indexOf('-') > 0 && lngOnly.indexOf('-') < 0 && supportedLng.substring(0, supportedLng.indexOf('-')) === lngOnly) return supportedLng;
|
|
55592
|
+
if (supportedLng.indexOf(lngOnly) === 0 && lngOnly.length > 1) return supportedLng;
|
|
55593
|
+
});
|
|
55594
|
+
});
|
|
55595
|
+
}
|
|
55596
|
+
if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
|
|
55597
|
+
return found;
|
|
55598
|
+
}
|
|
55599
|
+
getFallbackCodes(fallbacks, code) {
|
|
55600
|
+
if (!fallbacks) return [];
|
|
55601
|
+
if (typeof fallbacks === 'function') fallbacks = fallbacks(code);
|
|
55602
|
+
if (isString(fallbacks)) fallbacks = [fallbacks];
|
|
55603
|
+
if (Array.isArray(fallbacks)) return fallbacks;
|
|
55604
|
+
if (!code) return fallbacks.default || [];
|
|
55605
|
+
let found = fallbacks[code];
|
|
55606
|
+
if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
|
|
55607
|
+
if (!found) found = fallbacks[this.formatLanguageCode(code)];
|
|
55608
|
+
if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
55609
|
+
if (!found) found = fallbacks.default;
|
|
55610
|
+
return found || [];
|
|
55611
|
+
}
|
|
55612
|
+
toResolveHierarchy(code, fallbackCode) {
|
|
55613
|
+
const fallbackCodes = this.getFallbackCodes((fallbackCode === false ? [] : fallbackCode) || this.options.fallbackLng || [], code);
|
|
55614
|
+
const codes = [];
|
|
55615
|
+
const addCode = c => {
|
|
55616
|
+
if (!c) return;
|
|
55617
|
+
if (this.isSupportedCode(c)) {
|
|
55618
|
+
codes.push(c);
|
|
55619
|
+
} else {
|
|
55620
|
+
this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
|
|
55621
|
+
}
|
|
55622
|
+
};
|
|
55623
|
+
if (isString(code) && (code.indexOf('-') > -1 || code.indexOf('_') > -1)) {
|
|
55624
|
+
if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code));
|
|
55625
|
+
if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code));
|
|
55626
|
+
if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code));
|
|
55627
|
+
} else if (isString(code)) {
|
|
55628
|
+
addCode(this.formatLanguageCode(code));
|
|
55629
|
+
}
|
|
55630
|
+
fallbackCodes.forEach(fc => {
|
|
55631
|
+
if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
|
|
55632
|
+
});
|
|
55633
|
+
return codes;
|
|
55634
|
+
}
|
|
55635
|
+
}
|
|
55636
|
+
|
|
55637
|
+
const suffixesOrder = {
|
|
55638
|
+
zero: 0,
|
|
55639
|
+
one: 1,
|
|
55640
|
+
two: 2,
|
|
55641
|
+
few: 3,
|
|
55642
|
+
many: 4,
|
|
55643
|
+
other: 5
|
|
55644
|
+
};
|
|
55645
|
+
const dummyRule = {
|
|
55646
|
+
select: count => count === 1 ? 'one' : 'other',
|
|
55647
|
+
resolvedOptions: () => ({
|
|
55648
|
+
pluralCategories: ['one', 'other']
|
|
55649
|
+
})
|
|
55650
|
+
};
|
|
55651
|
+
class PluralResolver {
|
|
55652
|
+
constructor(languageUtils, options = {}) {
|
|
55653
|
+
this.languageUtils = languageUtils;
|
|
55654
|
+
this.options = options;
|
|
55655
|
+
this.logger = baseLogger.create('pluralResolver');
|
|
55656
|
+
this.pluralRulesCache = {};
|
|
55657
|
+
}
|
|
55658
|
+
addRule(lng, obj) {
|
|
55659
|
+
this.rules[lng] = obj;
|
|
55660
|
+
}
|
|
55661
|
+
clearCache() {
|
|
55662
|
+
this.pluralRulesCache = {};
|
|
55663
|
+
}
|
|
55664
|
+
getRule(code, options = {}) {
|
|
55665
|
+
const cleanedCode = getCleanedCode(code === 'dev' ? 'en' : code);
|
|
55666
|
+
const type = options.ordinal ? 'ordinal' : 'cardinal';
|
|
55667
|
+
const cacheKey = JSON.stringify({
|
|
55668
|
+
cleanedCode,
|
|
55669
|
+
type
|
|
55670
|
+
});
|
|
55671
|
+
if (cacheKey in this.pluralRulesCache) {
|
|
55672
|
+
return this.pluralRulesCache[cacheKey];
|
|
55673
|
+
}
|
|
55674
|
+
let rule;
|
|
55675
|
+
try {
|
|
55676
|
+
rule = new Intl.PluralRules(cleanedCode, {
|
|
55677
|
+
type
|
|
55678
|
+
});
|
|
55679
|
+
} catch (err) {
|
|
55680
|
+
if (!Intl) {
|
|
55681
|
+
this.logger.error('No Intl support, please use an Intl polyfill!');
|
|
55682
|
+
return dummyRule;
|
|
55683
|
+
}
|
|
55684
|
+
if (!code.match(/-|_/)) return dummyRule;
|
|
55685
|
+
const lngPart = this.languageUtils.getLanguagePartFromCode(code);
|
|
55686
|
+
rule = this.getRule(lngPart, options);
|
|
55687
|
+
}
|
|
55688
|
+
this.pluralRulesCache[cacheKey] = rule;
|
|
55689
|
+
return rule;
|
|
55690
|
+
}
|
|
55691
|
+
needsPlural(code, options = {}) {
|
|
55692
|
+
let rule = this.getRule(code, options);
|
|
55693
|
+
if (!rule) rule = this.getRule('dev', options);
|
|
55694
|
+
return rule?.resolvedOptions().pluralCategories.length > 1;
|
|
55695
|
+
}
|
|
55696
|
+
getPluralFormsOfKey(code, key, options = {}) {
|
|
55697
|
+
return this.getSuffixes(code, options).map(suffix => `${key}${suffix}`);
|
|
55698
|
+
}
|
|
55699
|
+
getSuffixes(code, options = {}) {
|
|
55700
|
+
let rule = this.getRule(code, options);
|
|
55701
|
+
if (!rule) rule = this.getRule('dev', options);
|
|
55702
|
+
if (!rule) return [];
|
|
55703
|
+
return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map(pluralCategory => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${pluralCategory}`);
|
|
55704
|
+
}
|
|
55705
|
+
getSuffix(code, count, options = {}) {
|
|
55706
|
+
const rule = this.getRule(code, options);
|
|
55707
|
+
if (rule) {
|
|
55708
|
+
return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${rule.select(count)}`;
|
|
55709
|
+
}
|
|
55710
|
+
this.logger.warn(`no plural rule found for: ${code}`);
|
|
55711
|
+
return this.getSuffix('dev', count, options);
|
|
55712
|
+
}
|
|
55713
|
+
}
|
|
55714
|
+
|
|
55715
|
+
const deepFindWithDefaults = (data, defaultData, key, keySeparator = '.', ignoreJSONStructure = true) => {
|
|
55716
|
+
let path = getPathWithDefaults(data, defaultData, key);
|
|
55717
|
+
if (!path && ignoreJSONStructure && isString(key)) {
|
|
55718
|
+
path = deepFind(data, key, keySeparator);
|
|
55719
|
+
if (path === undefined) path = deepFind(defaultData, key, keySeparator);
|
|
55720
|
+
}
|
|
55721
|
+
return path;
|
|
55722
|
+
};
|
|
55723
|
+
const regexSafe = val => val.replace(/\$/g, '$$$$');
|
|
55724
|
+
class Interpolator {
|
|
55725
|
+
constructor(options = {}) {
|
|
55726
|
+
this.logger = baseLogger.create('interpolator');
|
|
55727
|
+
this.options = options;
|
|
55728
|
+
this.format = options?.interpolation?.format || (value => value);
|
|
55729
|
+
this.init(options);
|
|
55730
|
+
}
|
|
55731
|
+
init(options = {}) {
|
|
55732
|
+
if (!options.interpolation) options.interpolation = {
|
|
55733
|
+
escapeValue: true
|
|
55734
|
+
};
|
|
55735
|
+
const {
|
|
55736
|
+
escape: escape$1,
|
|
55737
|
+
escapeValue,
|
|
55738
|
+
useRawValueToEscape,
|
|
55739
|
+
prefix,
|
|
55740
|
+
prefixEscaped,
|
|
55741
|
+
suffix,
|
|
55742
|
+
suffixEscaped,
|
|
55743
|
+
formatSeparator,
|
|
55744
|
+
unescapeSuffix,
|
|
55745
|
+
unescapePrefix,
|
|
55746
|
+
nestingPrefix,
|
|
55747
|
+
nestingPrefixEscaped,
|
|
55748
|
+
nestingSuffix,
|
|
55749
|
+
nestingSuffixEscaped,
|
|
55750
|
+
nestingOptionsSeparator,
|
|
55751
|
+
maxReplaces,
|
|
55752
|
+
alwaysFormat
|
|
55753
|
+
} = options.interpolation;
|
|
55754
|
+
this.escape = escape$1 !== undefined ? escape$1 : escape;
|
|
55755
|
+
this.escapeValue = escapeValue !== undefined ? escapeValue : true;
|
|
55756
|
+
this.useRawValueToEscape = useRawValueToEscape !== undefined ? useRawValueToEscape : false;
|
|
55757
|
+
this.prefix = prefix ? regexEscape(prefix) : prefixEscaped || '{{';
|
|
55758
|
+
this.suffix = suffix ? regexEscape(suffix) : suffixEscaped || '}}';
|
|
55759
|
+
this.formatSeparator = formatSeparator || ',';
|
|
55760
|
+
this.unescapePrefix = unescapeSuffix ? '' : unescapePrefix || '-';
|
|
55761
|
+
this.unescapeSuffix = this.unescapePrefix ? '' : unescapeSuffix || '';
|
|
55762
|
+
this.nestingPrefix = nestingPrefix ? regexEscape(nestingPrefix) : nestingPrefixEscaped || regexEscape('$t(');
|
|
55763
|
+
this.nestingSuffix = nestingSuffix ? regexEscape(nestingSuffix) : nestingSuffixEscaped || regexEscape(')');
|
|
55764
|
+
this.nestingOptionsSeparator = nestingOptionsSeparator || ',';
|
|
55765
|
+
this.maxReplaces = maxReplaces || 1000;
|
|
55766
|
+
this.alwaysFormat = alwaysFormat !== undefined ? alwaysFormat : false;
|
|
55767
|
+
this.resetRegExp();
|
|
55768
|
+
}
|
|
55769
|
+
reset() {
|
|
55770
|
+
if (this.options) this.init(this.options);
|
|
55771
|
+
}
|
|
55772
|
+
resetRegExp() {
|
|
55773
|
+
const getOrResetRegExp = (existingRegExp, pattern) => {
|
|
55774
|
+
if (existingRegExp?.source === pattern) {
|
|
55775
|
+
existingRegExp.lastIndex = 0;
|
|
55776
|
+
return existingRegExp;
|
|
55777
|
+
}
|
|
55778
|
+
return new RegExp(pattern, 'g');
|
|
55779
|
+
};
|
|
55780
|
+
this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
|
|
55781
|
+
this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
|
|
55782
|
+
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}((?:[^()"']+|"[^"]*"|'[^']*'|\\((?:[^()]|"[^"]*"|'[^']*')*\\))*?)${this.nestingSuffix}`);
|
|
55783
|
+
}
|
|
55784
|
+
interpolate(str, data, lng, options) {
|
|
55785
|
+
let match;
|
|
55786
|
+
let value;
|
|
55787
|
+
let replaces;
|
|
55788
|
+
const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
55789
|
+
const handleFormat = key => {
|
|
55790
|
+
if (key.indexOf(this.formatSeparator) < 0) {
|
|
55791
|
+
const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
|
|
55792
|
+
return this.alwaysFormat ? this.format(path, undefined, lng, {
|
|
55793
|
+
...options,
|
|
55794
|
+
...data,
|
|
55795
|
+
interpolationkey: key
|
|
55796
|
+
}) : path;
|
|
55797
|
+
}
|
|
55798
|
+
const p = key.split(this.formatSeparator);
|
|
55799
|
+
const k = p.shift().trim();
|
|
55800
|
+
const f = p.join(this.formatSeparator).trim();
|
|
55801
|
+
return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
|
|
55802
|
+
...options,
|
|
55803
|
+
...data,
|
|
55804
|
+
interpolationkey: k
|
|
55805
|
+
});
|
|
55806
|
+
};
|
|
55807
|
+
this.resetRegExp();
|
|
55808
|
+
const missingInterpolationHandler = options?.missingInterpolationHandler || this.options.missingInterpolationHandler;
|
|
55809
|
+
const skipOnVariables = options?.interpolation?.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
|
|
55810
|
+
const todos = [{
|
|
55811
|
+
regex: this.regexpUnescape,
|
|
55812
|
+
safeValue: val => regexSafe(val)
|
|
55813
|
+
}, {
|
|
55814
|
+
regex: this.regexp,
|
|
55815
|
+
safeValue: val => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
|
|
55816
|
+
}];
|
|
55817
|
+
todos.forEach(todo => {
|
|
55818
|
+
replaces = 0;
|
|
55819
|
+
while (match = todo.regex.exec(str)) {
|
|
55820
|
+
const matchedVar = match[1].trim();
|
|
55821
|
+
value = handleFormat(matchedVar);
|
|
55822
|
+
if (value === undefined) {
|
|
55823
|
+
if (typeof missingInterpolationHandler === 'function') {
|
|
55824
|
+
const temp = missingInterpolationHandler(str, match, options);
|
|
55825
|
+
value = isString(temp) ? temp : '';
|
|
55826
|
+
} else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
|
|
55827
|
+
value = '';
|
|
55828
|
+
} else if (skipOnVariables) {
|
|
55829
|
+
value = match[0];
|
|
55830
|
+
continue;
|
|
55831
|
+
} else {
|
|
55832
|
+
this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
|
|
55833
|
+
value = '';
|
|
55834
|
+
}
|
|
55835
|
+
} else if (!isString(value) && !this.useRawValueToEscape) {
|
|
55836
|
+
value = makeString(value);
|
|
55837
|
+
}
|
|
55838
|
+
const safeValue = todo.safeValue(value);
|
|
55839
|
+
str = str.replace(match[0], safeValue);
|
|
55840
|
+
if (skipOnVariables) {
|
|
55841
|
+
todo.regex.lastIndex += value.length;
|
|
55842
|
+
todo.regex.lastIndex -= match[0].length;
|
|
55843
|
+
} else {
|
|
55844
|
+
todo.regex.lastIndex = 0;
|
|
55845
|
+
}
|
|
55846
|
+
replaces++;
|
|
55847
|
+
if (replaces >= this.maxReplaces) {
|
|
55848
|
+
break;
|
|
55849
|
+
}
|
|
55850
|
+
}
|
|
55851
|
+
});
|
|
55852
|
+
return str;
|
|
55853
|
+
}
|
|
55854
|
+
nest(str, fc, options = {}) {
|
|
55855
|
+
let match;
|
|
55856
|
+
let value;
|
|
55857
|
+
let clonedOptions;
|
|
55858
|
+
const handleHasOptions = (key, inheritedOptions) => {
|
|
55859
|
+
const sep = this.nestingOptionsSeparator;
|
|
55860
|
+
if (key.indexOf(sep) < 0) return key;
|
|
55861
|
+
const c = key.split(new RegExp(`${sep}[ ]*{`));
|
|
55862
|
+
let optionsString = `{${c[1]}`;
|
|
55863
|
+
key = c[0];
|
|
55864
|
+
optionsString = this.interpolate(optionsString, clonedOptions);
|
|
55865
|
+
const matchedSingleQuotes = optionsString.match(/'/g);
|
|
55866
|
+
const matchedDoubleQuotes = optionsString.match(/"/g);
|
|
55867
|
+
if ((matchedSingleQuotes?.length ?? 0) % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
|
|
55868
|
+
optionsString = optionsString.replace(/'/g, '"');
|
|
55869
|
+
}
|
|
55870
|
+
try {
|
|
55871
|
+
clonedOptions = JSON.parse(optionsString);
|
|
55872
|
+
if (inheritedOptions) clonedOptions = {
|
|
55873
|
+
...inheritedOptions,
|
|
55874
|
+
...clonedOptions
|
|
55875
|
+
};
|
|
55876
|
+
} catch (e) {
|
|
55877
|
+
this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
|
|
55878
|
+
return `${key}${sep}${optionsString}`;
|
|
55879
|
+
}
|
|
55880
|
+
if (clonedOptions.defaultValue && clonedOptions.defaultValue.indexOf(this.prefix) > -1) delete clonedOptions.defaultValue;
|
|
55881
|
+
return key;
|
|
55882
|
+
};
|
|
55883
|
+
while (match = this.nestingRegexp.exec(str)) {
|
|
55884
|
+
let formatters = [];
|
|
55885
|
+
clonedOptions = {
|
|
55886
|
+
...options
|
|
55887
|
+
};
|
|
55888
|
+
clonedOptions = clonedOptions.replace && !isString(clonedOptions.replace) ? clonedOptions.replace : clonedOptions;
|
|
55889
|
+
clonedOptions.applyPostProcessor = false;
|
|
55890
|
+
delete clonedOptions.defaultValue;
|
|
55891
|
+
const keyEndIndex = /{.*}/.test(match[1]) ? match[1].lastIndexOf('}') + 1 : match[1].indexOf(this.formatSeparator);
|
|
55892
|
+
if (keyEndIndex !== -1) {
|
|
55893
|
+
formatters = match[1].slice(keyEndIndex).split(this.formatSeparator).map(elem => elem.trim()).filter(Boolean);
|
|
55894
|
+
match[1] = match[1].slice(0, keyEndIndex);
|
|
55895
|
+
}
|
|
55896
|
+
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
55897
|
+
if (value && match[0] === str && !isString(value)) return value;
|
|
55898
|
+
if (!isString(value)) value = makeString(value);
|
|
55899
|
+
if (!value) {
|
|
55900
|
+
this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
|
|
55901
|
+
value = '';
|
|
55902
|
+
}
|
|
55903
|
+
if (formatters.length) {
|
|
55904
|
+
value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
|
|
55905
|
+
...options,
|
|
55906
|
+
interpolationkey: match[1].trim()
|
|
55907
|
+
}), value.trim());
|
|
55908
|
+
}
|
|
55909
|
+
str = str.replace(match[0], value);
|
|
55910
|
+
this.regexp.lastIndex = 0;
|
|
55911
|
+
}
|
|
55912
|
+
return str;
|
|
55913
|
+
}
|
|
55914
|
+
}
|
|
55915
|
+
|
|
55916
|
+
const parseFormatStr = formatStr => {
|
|
55917
|
+
let formatName = formatStr.toLowerCase().trim();
|
|
55918
|
+
const formatOptions = {};
|
|
55919
|
+
if (formatStr.indexOf('(') > -1) {
|
|
55920
|
+
const p = formatStr.split('(');
|
|
55921
|
+
formatName = p[0].toLowerCase().trim();
|
|
55922
|
+
const optStr = p[1].substring(0, p[1].length - 1);
|
|
55923
|
+
if (formatName === 'currency' && optStr.indexOf(':') < 0) {
|
|
55924
|
+
if (!formatOptions.currency) formatOptions.currency = optStr.trim();
|
|
55925
|
+
} else if (formatName === 'relativetime' && optStr.indexOf(':') < 0) {
|
|
55926
|
+
if (!formatOptions.range) formatOptions.range = optStr.trim();
|
|
55927
|
+
} else {
|
|
55928
|
+
const opts = optStr.split(';');
|
|
55929
|
+
opts.forEach(opt => {
|
|
55930
|
+
if (opt) {
|
|
55931
|
+
const [key, ...rest] = opt.split(':');
|
|
55932
|
+
const val = rest.join(':').trim().replace(/^'+|'+$/g, '');
|
|
55933
|
+
const trimmedKey = key.trim();
|
|
55934
|
+
if (!formatOptions[trimmedKey]) formatOptions[trimmedKey] = val;
|
|
55935
|
+
if (val === 'false') formatOptions[trimmedKey] = false;
|
|
55936
|
+
if (val === 'true') formatOptions[trimmedKey] = true;
|
|
55937
|
+
if (!isNaN(val)) formatOptions[trimmedKey] = parseInt(val, 10);
|
|
55938
|
+
}
|
|
55939
|
+
});
|
|
55940
|
+
}
|
|
55941
|
+
}
|
|
55942
|
+
return {
|
|
55943
|
+
formatName,
|
|
55944
|
+
formatOptions
|
|
55945
|
+
};
|
|
55946
|
+
};
|
|
55947
|
+
const createCachedFormatter = fn => {
|
|
55948
|
+
const cache = {};
|
|
55949
|
+
return (v, l, o) => {
|
|
55950
|
+
let optForCache = o;
|
|
55951
|
+
if (o && o.interpolationkey && o.formatParams && o.formatParams[o.interpolationkey] && o[o.interpolationkey]) {
|
|
55952
|
+
optForCache = {
|
|
55953
|
+
...optForCache,
|
|
55954
|
+
[o.interpolationkey]: undefined
|
|
55955
|
+
};
|
|
55956
|
+
}
|
|
55957
|
+
const key = l + JSON.stringify(optForCache);
|
|
55958
|
+
let frm = cache[key];
|
|
55959
|
+
if (!frm) {
|
|
55960
|
+
frm = fn(getCleanedCode(l), o);
|
|
55961
|
+
cache[key] = frm;
|
|
55962
|
+
}
|
|
55963
|
+
return frm(v);
|
|
55964
|
+
};
|
|
55965
|
+
};
|
|
55966
|
+
const createNonCachedFormatter = fn => (v, l, o) => fn(getCleanedCode(l), o)(v);
|
|
55967
|
+
class Formatter {
|
|
55968
|
+
constructor(options = {}) {
|
|
55969
|
+
this.logger = baseLogger.create('formatter');
|
|
55970
|
+
this.options = options;
|
|
55971
|
+
this.init(options);
|
|
55972
|
+
}
|
|
55973
|
+
init(services, options = {
|
|
55974
|
+
interpolation: {}
|
|
55975
|
+
}) {
|
|
55976
|
+
this.formatSeparator = options.interpolation.formatSeparator || ',';
|
|
55977
|
+
const cf = options.cacheInBuiltFormats ? createCachedFormatter : createNonCachedFormatter;
|
|
55978
|
+
this.formats = {
|
|
55979
|
+
number: cf((lng, opt) => {
|
|
55980
|
+
const formatter = new Intl.NumberFormat(lng, {
|
|
55981
|
+
...opt
|
|
55982
|
+
});
|
|
55983
|
+
return val => formatter.format(val);
|
|
55984
|
+
}),
|
|
55985
|
+
currency: cf((lng, opt) => {
|
|
55986
|
+
const formatter = new Intl.NumberFormat(lng, {
|
|
55987
|
+
...opt,
|
|
55988
|
+
style: 'currency'
|
|
55989
|
+
});
|
|
55990
|
+
return val => formatter.format(val);
|
|
55991
|
+
}),
|
|
55992
|
+
datetime: cf((lng, opt) => {
|
|
55993
|
+
const formatter = new Intl.DateTimeFormat(lng, {
|
|
55994
|
+
...opt
|
|
55995
|
+
});
|
|
55996
|
+
return val => formatter.format(val);
|
|
55997
|
+
}),
|
|
55998
|
+
relativetime: cf((lng, opt) => {
|
|
55999
|
+
const formatter = new Intl.RelativeTimeFormat(lng, {
|
|
56000
|
+
...opt
|
|
56001
|
+
});
|
|
56002
|
+
return val => formatter.format(val, opt.range || 'day');
|
|
56003
|
+
}),
|
|
56004
|
+
list: cf((lng, opt) => {
|
|
56005
|
+
const formatter = new Intl.ListFormat(lng, {
|
|
56006
|
+
...opt
|
|
56007
|
+
});
|
|
56008
|
+
return val => formatter.format(val);
|
|
56009
|
+
})
|
|
56010
|
+
};
|
|
56011
|
+
}
|
|
56012
|
+
add(name, fc) {
|
|
56013
|
+
this.formats[name.toLowerCase().trim()] = fc;
|
|
56014
|
+
}
|
|
56015
|
+
addCached(name, fc) {
|
|
56016
|
+
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
56017
|
+
}
|
|
56018
|
+
format(value, format, lng, options = {}) {
|
|
56019
|
+
const formats = format.split(this.formatSeparator);
|
|
56020
|
+
if (formats.length > 1 && formats[0].indexOf('(') > 1 && formats[0].indexOf(')') < 0 && formats.find(f => f.indexOf(')') > -1)) {
|
|
56021
|
+
const lastIndex = formats.findIndex(f => f.indexOf(')') > -1);
|
|
56022
|
+
formats[0] = [formats[0], ...formats.splice(1, lastIndex)].join(this.formatSeparator);
|
|
56023
|
+
}
|
|
56024
|
+
const result = formats.reduce((mem, f) => {
|
|
56025
|
+
const {
|
|
56026
|
+
formatName,
|
|
56027
|
+
formatOptions
|
|
56028
|
+
} = parseFormatStr(f);
|
|
56029
|
+
if (this.formats[formatName]) {
|
|
56030
|
+
let formatted = mem;
|
|
56031
|
+
try {
|
|
56032
|
+
const valOptions = options?.formatParams?.[options.interpolationkey] || {};
|
|
56033
|
+
const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
|
|
56034
|
+
formatted = this.formats[formatName](mem, l, {
|
|
56035
|
+
...formatOptions,
|
|
56036
|
+
...options,
|
|
56037
|
+
...valOptions
|
|
56038
|
+
});
|
|
56039
|
+
} catch (error) {
|
|
56040
|
+
this.logger.warn(error);
|
|
56041
|
+
}
|
|
56042
|
+
return formatted;
|
|
56043
|
+
} else {
|
|
56044
|
+
this.logger.warn(`there was no format function for ${formatName}`);
|
|
56045
|
+
}
|
|
56046
|
+
return mem;
|
|
56047
|
+
}, value);
|
|
56048
|
+
return result;
|
|
56049
|
+
}
|
|
56050
|
+
}
|
|
56051
|
+
|
|
56052
|
+
const removePending = (q, name) => {
|
|
56053
|
+
if (q.pending[name] !== undefined) {
|
|
56054
|
+
delete q.pending[name];
|
|
56055
|
+
q.pendingCount--;
|
|
56056
|
+
}
|
|
56057
|
+
};
|
|
56058
|
+
class Connector extends EventEmitter {
|
|
56059
|
+
constructor(backend, store, services, options = {}) {
|
|
56060
|
+
super();
|
|
56061
|
+
this.backend = backend;
|
|
56062
|
+
this.store = store;
|
|
56063
|
+
this.services = services;
|
|
56064
|
+
this.languageUtils = services.languageUtils;
|
|
56065
|
+
this.options = options;
|
|
56066
|
+
this.logger = baseLogger.create('backendConnector');
|
|
56067
|
+
this.waitingReads = [];
|
|
56068
|
+
this.maxParallelReads = options.maxParallelReads || 10;
|
|
56069
|
+
this.readingCalls = 0;
|
|
56070
|
+
this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
|
|
56071
|
+
this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
|
|
56072
|
+
this.state = {};
|
|
56073
|
+
this.queue = [];
|
|
56074
|
+
this.backend?.init?.(services, options.backend, options);
|
|
56075
|
+
}
|
|
56076
|
+
queueLoad(languages, namespaces, options, callback) {
|
|
56077
|
+
const toLoad = {};
|
|
56078
|
+
const pending = {};
|
|
56079
|
+
const toLoadLanguages = {};
|
|
56080
|
+
const toLoadNamespaces = {};
|
|
56081
|
+
languages.forEach(lng => {
|
|
56082
|
+
let hasAllNamespaces = true;
|
|
56083
|
+
namespaces.forEach(ns => {
|
|
56084
|
+
const name = `${lng}|${ns}`;
|
|
56085
|
+
if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
|
|
56086
|
+
this.state[name] = 2;
|
|
56087
|
+
} else if (this.state[name] < 0) ; else if (this.state[name] === 1) {
|
|
56088
|
+
if (pending[name] === undefined) pending[name] = true;
|
|
56089
|
+
} else {
|
|
56090
|
+
this.state[name] = 1;
|
|
56091
|
+
hasAllNamespaces = false;
|
|
56092
|
+
if (pending[name] === undefined) pending[name] = true;
|
|
56093
|
+
if (toLoad[name] === undefined) toLoad[name] = true;
|
|
56094
|
+
if (toLoadNamespaces[ns] === undefined) toLoadNamespaces[ns] = true;
|
|
56095
|
+
}
|
|
56096
|
+
});
|
|
56097
|
+
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
56098
|
+
});
|
|
56099
|
+
if (Object.keys(toLoad).length || Object.keys(pending).length) {
|
|
56100
|
+
this.queue.push({
|
|
56101
|
+
pending,
|
|
56102
|
+
pendingCount: Object.keys(pending).length,
|
|
56103
|
+
loaded: {},
|
|
56104
|
+
errors: [],
|
|
56105
|
+
callback
|
|
56106
|
+
});
|
|
56107
|
+
}
|
|
56108
|
+
return {
|
|
56109
|
+
toLoad: Object.keys(toLoad),
|
|
56110
|
+
pending: Object.keys(pending),
|
|
56111
|
+
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
56112
|
+
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
56113
|
+
};
|
|
56114
|
+
}
|
|
56115
|
+
loaded(name, err, data) {
|
|
56116
|
+
const s = name.split('|');
|
|
56117
|
+
const lng = s[0];
|
|
56118
|
+
const ns = s[1];
|
|
56119
|
+
if (err) this.emit('failedLoading', lng, ns, err);
|
|
56120
|
+
if (!err && data) {
|
|
56121
|
+
this.store.addResourceBundle(lng, ns, data, undefined, undefined, {
|
|
56122
|
+
skipCopy: true
|
|
56123
|
+
});
|
|
56124
|
+
}
|
|
56125
|
+
this.state[name] = err ? -1 : 2;
|
|
56126
|
+
if (err && data) this.state[name] = 0;
|
|
56127
|
+
const loaded = {};
|
|
56128
|
+
this.queue.forEach(q => {
|
|
56129
|
+
pushPath(q.loaded, [lng], ns);
|
|
56130
|
+
removePending(q, name);
|
|
56131
|
+
if (err) q.errors.push(err);
|
|
56132
|
+
if (q.pendingCount === 0 && !q.done) {
|
|
56133
|
+
Object.keys(q.loaded).forEach(l => {
|
|
56134
|
+
if (!loaded[l]) loaded[l] = {};
|
|
56135
|
+
const loadedKeys = q.loaded[l];
|
|
56136
|
+
if (loadedKeys.length) {
|
|
56137
|
+
loadedKeys.forEach(n => {
|
|
56138
|
+
if (loaded[l][n] === undefined) loaded[l][n] = true;
|
|
56139
|
+
});
|
|
56140
|
+
}
|
|
56141
|
+
});
|
|
56142
|
+
q.done = true;
|
|
56143
|
+
if (q.errors.length) {
|
|
56144
|
+
q.callback(q.errors);
|
|
56145
|
+
} else {
|
|
56146
|
+
q.callback();
|
|
56147
|
+
}
|
|
56148
|
+
}
|
|
56149
|
+
});
|
|
56150
|
+
this.emit('loaded', loaded);
|
|
56151
|
+
this.queue = this.queue.filter(q => !q.done);
|
|
56152
|
+
}
|
|
56153
|
+
read(lng, ns, fcName, tried = 0, wait = this.retryTimeout, callback) {
|
|
56154
|
+
if (!lng.length) return callback(null, {});
|
|
56155
|
+
if (this.readingCalls >= this.maxParallelReads) {
|
|
56156
|
+
this.waitingReads.push({
|
|
56157
|
+
lng,
|
|
56158
|
+
ns,
|
|
56159
|
+
fcName,
|
|
56160
|
+
tried,
|
|
56161
|
+
wait,
|
|
56162
|
+
callback
|
|
56163
|
+
});
|
|
56164
|
+
return;
|
|
56165
|
+
}
|
|
56166
|
+
this.readingCalls++;
|
|
56167
|
+
const resolver = (err, data) => {
|
|
56168
|
+
this.readingCalls--;
|
|
56169
|
+
if (this.waitingReads.length > 0) {
|
|
56170
|
+
const next = this.waitingReads.shift();
|
|
56171
|
+
this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
56172
|
+
}
|
|
56173
|
+
if (err && data && tried < this.maxRetries) {
|
|
56174
|
+
setTimeout(() => {
|
|
56175
|
+
this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
56176
|
+
}, wait);
|
|
56177
|
+
return;
|
|
56178
|
+
}
|
|
56179
|
+
callback(err, data);
|
|
56180
|
+
};
|
|
56181
|
+
const fc = this.backend[fcName].bind(this.backend);
|
|
56182
|
+
if (fc.length === 2) {
|
|
56183
|
+
try {
|
|
56184
|
+
const r = fc(lng, ns);
|
|
56185
|
+
if (r && typeof r.then === 'function') {
|
|
56186
|
+
r.then(data => resolver(null, data)).catch(resolver);
|
|
56187
|
+
} else {
|
|
56188
|
+
resolver(null, r);
|
|
56189
|
+
}
|
|
56190
|
+
} catch (err) {
|
|
56191
|
+
resolver(err);
|
|
56192
|
+
}
|
|
56193
|
+
return;
|
|
56194
|
+
}
|
|
56195
|
+
return fc(lng, ns, resolver);
|
|
56196
|
+
}
|
|
56197
|
+
prepareLoading(languages, namespaces, options = {}, callback) {
|
|
56198
|
+
if (!this.backend) {
|
|
56199
|
+
this.logger.warn('No backend was added via i18next.use. Will not load resources.');
|
|
56200
|
+
return callback && callback();
|
|
56201
|
+
}
|
|
56202
|
+
if (isString(languages)) languages = this.languageUtils.toResolveHierarchy(languages);
|
|
56203
|
+
if (isString(namespaces)) namespaces = [namespaces];
|
|
56204
|
+
const toLoad = this.queueLoad(languages, namespaces, options, callback);
|
|
56205
|
+
if (!toLoad.toLoad.length) {
|
|
56206
|
+
if (!toLoad.pending.length) callback();
|
|
56207
|
+
return null;
|
|
56208
|
+
}
|
|
56209
|
+
toLoad.toLoad.forEach(name => {
|
|
56210
|
+
this.loadOne(name);
|
|
56211
|
+
});
|
|
56212
|
+
}
|
|
56213
|
+
load(languages, namespaces, callback) {
|
|
56214
|
+
this.prepareLoading(languages, namespaces, {}, callback);
|
|
56215
|
+
}
|
|
56216
|
+
reload(languages, namespaces, callback) {
|
|
56217
|
+
this.prepareLoading(languages, namespaces, {
|
|
56218
|
+
reload: true
|
|
56219
|
+
}, callback);
|
|
56220
|
+
}
|
|
56221
|
+
loadOne(name, prefix = '') {
|
|
56222
|
+
const s = name.split('|');
|
|
56223
|
+
const lng = s[0];
|
|
56224
|
+
const ns = s[1];
|
|
56225
|
+
this.read(lng, ns, 'read', undefined, undefined, (err, data) => {
|
|
56226
|
+
if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
|
|
56227
|
+
if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
|
|
56228
|
+
this.loaded(name, err, data);
|
|
56229
|
+
});
|
|
56230
|
+
}
|
|
56231
|
+
saveMissing(languages, namespace, key, fallbackValue, isUpdate, options = {}, clb = () => {}) {
|
|
56232
|
+
if (this.services?.utils?.hasLoadedNamespace && !this.services?.utils?.hasLoadedNamespace(namespace)) {
|
|
56233
|
+
this.logger.warn(`did not save key "${key}" as the namespace "${namespace}" was not yet loaded`, 'This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!');
|
|
56234
|
+
return;
|
|
56235
|
+
}
|
|
56236
|
+
if (key === undefined || key === null || key === '') return;
|
|
56237
|
+
if (this.backend?.create) {
|
|
56238
|
+
const opts = {
|
|
56239
|
+
...options,
|
|
56240
|
+
isUpdate
|
|
56241
|
+
};
|
|
56242
|
+
const fc = this.backend.create.bind(this.backend);
|
|
56243
|
+
if (fc.length < 6) {
|
|
56244
|
+
try {
|
|
56245
|
+
let r;
|
|
56246
|
+
if (fc.length === 5) {
|
|
56247
|
+
r = fc(languages, namespace, key, fallbackValue, opts);
|
|
56248
|
+
} else {
|
|
56249
|
+
r = fc(languages, namespace, key, fallbackValue);
|
|
56250
|
+
}
|
|
56251
|
+
if (r && typeof r.then === 'function') {
|
|
56252
|
+
r.then(data => clb(null, data)).catch(clb);
|
|
56253
|
+
} else {
|
|
56254
|
+
clb(null, r);
|
|
56255
|
+
}
|
|
56256
|
+
} catch (err) {
|
|
56257
|
+
clb(err);
|
|
56258
|
+
}
|
|
56259
|
+
} else {
|
|
56260
|
+
fc(languages, namespace, key, fallbackValue, clb, opts);
|
|
56261
|
+
}
|
|
56262
|
+
}
|
|
56263
|
+
if (!languages || !languages[0]) return;
|
|
56264
|
+
this.store.addResource(languages[0], namespace, key, fallbackValue);
|
|
56265
|
+
}
|
|
56266
|
+
}
|
|
56267
|
+
|
|
56268
|
+
const get = () => ({
|
|
56269
|
+
debug: false,
|
|
56270
|
+
initAsync: true,
|
|
56271
|
+
ns: ['translation'],
|
|
56272
|
+
defaultNS: ['translation'],
|
|
56273
|
+
fallbackLng: ['dev'],
|
|
56274
|
+
fallbackNS: false,
|
|
56275
|
+
supportedLngs: false,
|
|
56276
|
+
nonExplicitSupportedLngs: false,
|
|
56277
|
+
load: 'all',
|
|
56278
|
+
preload: false,
|
|
56279
|
+
simplifyPluralSuffix: true,
|
|
56280
|
+
keySeparator: '.',
|
|
56281
|
+
nsSeparator: ':',
|
|
56282
|
+
pluralSeparator: '_',
|
|
56283
|
+
contextSeparator: '_',
|
|
56284
|
+
partialBundledLanguages: false,
|
|
56285
|
+
saveMissing: false,
|
|
56286
|
+
updateMissing: false,
|
|
56287
|
+
saveMissingTo: 'fallback',
|
|
56288
|
+
saveMissingPlurals: true,
|
|
56289
|
+
missingKeyHandler: false,
|
|
56290
|
+
missingInterpolationHandler: false,
|
|
56291
|
+
postProcess: false,
|
|
56292
|
+
postProcessPassResolved: false,
|
|
56293
|
+
returnNull: false,
|
|
56294
|
+
returnEmptyString: true,
|
|
56295
|
+
returnObjects: false,
|
|
56296
|
+
joinArrays: false,
|
|
56297
|
+
returnedObjectHandler: false,
|
|
56298
|
+
parseMissingKeyHandler: false,
|
|
56299
|
+
appendNamespaceToMissingKey: false,
|
|
56300
|
+
appendNamespaceToCIMode: false,
|
|
56301
|
+
overloadTranslationOptionHandler: args => {
|
|
56302
|
+
let ret = {};
|
|
56303
|
+
if (typeof args[1] === 'object') ret = args[1];
|
|
56304
|
+
if (isString(args[1])) ret.defaultValue = args[1];
|
|
56305
|
+
if (isString(args[2])) ret.tDescription = args[2];
|
|
56306
|
+
if (typeof args[2] === 'object' || typeof args[3] === 'object') {
|
|
56307
|
+
const options = args[3] || args[2];
|
|
56308
|
+
Object.keys(options).forEach(key => {
|
|
56309
|
+
ret[key] = options[key];
|
|
56310
|
+
});
|
|
56311
|
+
}
|
|
56312
|
+
return ret;
|
|
56313
|
+
},
|
|
56314
|
+
interpolation: {
|
|
56315
|
+
escapeValue: true,
|
|
56316
|
+
format: value => value,
|
|
56317
|
+
prefix: '{{',
|
|
56318
|
+
suffix: '}}',
|
|
56319
|
+
formatSeparator: ',',
|
|
56320
|
+
unescapePrefix: '-',
|
|
56321
|
+
nestingPrefix: '$t(',
|
|
56322
|
+
nestingSuffix: ')',
|
|
56323
|
+
nestingOptionsSeparator: ',',
|
|
56324
|
+
maxReplaces: 1000,
|
|
56325
|
+
skipOnVariables: true
|
|
56326
|
+
},
|
|
56327
|
+
cacheInBuiltFormats: true
|
|
56328
|
+
});
|
|
56329
|
+
const transformOptions = options => {
|
|
56330
|
+
if (isString(options.ns)) options.ns = [options.ns];
|
|
56331
|
+
if (isString(options.fallbackLng)) options.fallbackLng = [options.fallbackLng];
|
|
56332
|
+
if (isString(options.fallbackNS)) options.fallbackNS = [options.fallbackNS];
|
|
56333
|
+
if (options.supportedLngs?.indexOf?.('cimode') < 0) {
|
|
56334
|
+
options.supportedLngs = options.supportedLngs.concat(['cimode']);
|
|
56335
|
+
}
|
|
56336
|
+
if (typeof options.initImmediate === 'boolean') options.initAsync = options.initImmediate;
|
|
56337
|
+
return options;
|
|
56338
|
+
};
|
|
56339
|
+
|
|
56340
|
+
const noop = () => {};
|
|
56341
|
+
const bindMemberFunctions = inst => {
|
|
56342
|
+
const mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
|
|
56343
|
+
mems.forEach(mem => {
|
|
56344
|
+
if (typeof inst[mem] === 'function') {
|
|
56345
|
+
inst[mem] = inst[mem].bind(inst);
|
|
56346
|
+
}
|
|
56347
|
+
});
|
|
56348
|
+
};
|
|
56349
|
+
class I18n extends EventEmitter {
|
|
56350
|
+
constructor(options = {}, callback) {
|
|
56351
|
+
super();
|
|
56352
|
+
this.options = transformOptions(options);
|
|
56353
|
+
this.services = {};
|
|
56354
|
+
this.logger = baseLogger;
|
|
56355
|
+
this.modules = {
|
|
56356
|
+
external: []
|
|
56357
|
+
};
|
|
56358
|
+
bindMemberFunctions(this);
|
|
56359
|
+
if (callback && !this.isInitialized && !options.isClone) {
|
|
56360
|
+
if (!this.options.initAsync) {
|
|
56361
|
+
this.init(options, callback);
|
|
56362
|
+
return this;
|
|
56363
|
+
}
|
|
56364
|
+
setTimeout(() => {
|
|
56365
|
+
this.init(options, callback);
|
|
56366
|
+
}, 0);
|
|
56367
|
+
}
|
|
56368
|
+
}
|
|
56369
|
+
init(options = {}, callback) {
|
|
56370
|
+
this.isInitializing = true;
|
|
56371
|
+
if (typeof options === 'function') {
|
|
56372
|
+
callback = options;
|
|
56373
|
+
options = {};
|
|
56374
|
+
}
|
|
56375
|
+
if (options.defaultNS == null && options.ns) {
|
|
56376
|
+
if (isString(options.ns)) {
|
|
56377
|
+
options.defaultNS = options.ns;
|
|
56378
|
+
} else if (options.ns.indexOf('translation') < 0) {
|
|
56379
|
+
options.defaultNS = options.ns[0];
|
|
56380
|
+
}
|
|
56381
|
+
}
|
|
56382
|
+
const defOpts = get();
|
|
56383
|
+
this.options = {
|
|
56384
|
+
...defOpts,
|
|
56385
|
+
...this.options,
|
|
56386
|
+
...transformOptions(options)
|
|
56387
|
+
};
|
|
56388
|
+
this.options.interpolation = {
|
|
56389
|
+
...defOpts.interpolation,
|
|
56390
|
+
...this.options.interpolation
|
|
56391
|
+
};
|
|
56392
|
+
if (options.keySeparator !== undefined) {
|
|
56393
|
+
this.options.userDefinedKeySeparator = options.keySeparator;
|
|
56394
|
+
}
|
|
56395
|
+
if (options.nsSeparator !== undefined) {
|
|
56396
|
+
this.options.userDefinedNsSeparator = options.nsSeparator;
|
|
56397
|
+
}
|
|
56398
|
+
const createClassOnDemand = ClassOrObject => {
|
|
56399
|
+
if (!ClassOrObject) return null;
|
|
56400
|
+
if (typeof ClassOrObject === 'function') return new ClassOrObject();
|
|
56401
|
+
return ClassOrObject;
|
|
56402
|
+
};
|
|
56403
|
+
if (!this.options.isClone) {
|
|
56404
|
+
if (this.modules.logger) {
|
|
56405
|
+
baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
|
|
56406
|
+
} else {
|
|
56407
|
+
baseLogger.init(null, this.options);
|
|
56408
|
+
}
|
|
56409
|
+
let formatter;
|
|
56410
|
+
if (this.modules.formatter) {
|
|
56411
|
+
formatter = this.modules.formatter;
|
|
56412
|
+
} else {
|
|
56413
|
+
formatter = Formatter;
|
|
56414
|
+
}
|
|
56415
|
+
const lu = new LanguageUtil(this.options);
|
|
56416
|
+
this.store = new ResourceStore(this.options.resources, this.options);
|
|
56417
|
+
const s = this.services;
|
|
56418
|
+
s.logger = baseLogger;
|
|
56419
|
+
s.resourceStore = this.store;
|
|
56420
|
+
s.languageUtils = lu;
|
|
56421
|
+
s.pluralResolver = new PluralResolver(lu, {
|
|
56422
|
+
prepend: this.options.pluralSeparator,
|
|
56423
|
+
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
56424
|
+
});
|
|
56425
|
+
const usingLegacyFormatFunction = this.options.interpolation.format && this.options.interpolation.format !== defOpts.interpolation.format;
|
|
56426
|
+
if (usingLegacyFormatFunction) {
|
|
56427
|
+
this.logger.deprecate(`init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting`);
|
|
56428
|
+
}
|
|
56429
|
+
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
|
|
56430
|
+
s.formatter = createClassOnDemand(formatter);
|
|
56431
|
+
if (s.formatter.init) s.formatter.init(s, this.options);
|
|
56432
|
+
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
56433
|
+
}
|
|
56434
|
+
s.interpolator = new Interpolator(this.options);
|
|
56435
|
+
s.utils = {
|
|
56436
|
+
hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
|
|
56437
|
+
};
|
|
56438
|
+
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
56439
|
+
s.backendConnector.on('*', (event, ...args) => {
|
|
56440
|
+
this.emit(event, ...args);
|
|
56441
|
+
});
|
|
56442
|
+
if (this.modules.languageDetector) {
|
|
56443
|
+
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
56444
|
+
if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
|
|
56445
|
+
}
|
|
56446
|
+
if (this.modules.i18nFormat) {
|
|
56447
|
+
s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
|
|
56448
|
+
if (s.i18nFormat.init) s.i18nFormat.init(this);
|
|
56449
|
+
}
|
|
56450
|
+
this.translator = new Translator(this.services, this.options);
|
|
56451
|
+
this.translator.on('*', (event, ...args) => {
|
|
56452
|
+
this.emit(event, ...args);
|
|
56453
|
+
});
|
|
56454
|
+
this.modules.external.forEach(m => {
|
|
56455
|
+
if (m.init) m.init(this);
|
|
56456
|
+
});
|
|
56457
|
+
}
|
|
56458
|
+
this.format = this.options.interpolation.format;
|
|
56459
|
+
if (!callback) callback = noop;
|
|
56460
|
+
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
56461
|
+
const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
56462
|
+
if (codes.length > 0 && codes[0] !== 'dev') this.options.lng = codes[0];
|
|
56463
|
+
}
|
|
56464
|
+
if (!this.services.languageDetector && !this.options.lng) {
|
|
56465
|
+
this.logger.warn('init: no languageDetector is used and no lng is defined');
|
|
56466
|
+
}
|
|
56467
|
+
const storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
|
|
56468
|
+
storeApi.forEach(fcName => {
|
|
56469
|
+
this[fcName] = (...args) => this.store[fcName](...args);
|
|
56470
|
+
});
|
|
56471
|
+
const storeApiChained = ['addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle'];
|
|
56472
|
+
storeApiChained.forEach(fcName => {
|
|
56473
|
+
this[fcName] = (...args) => {
|
|
56474
|
+
this.store[fcName](...args);
|
|
56475
|
+
return this;
|
|
56476
|
+
};
|
|
56477
|
+
});
|
|
56478
|
+
const deferred = defer();
|
|
56479
|
+
const load = () => {
|
|
56480
|
+
const finish = (err, t) => {
|
|
56481
|
+
this.isInitializing = false;
|
|
56482
|
+
if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn('init: i18next is already initialized. You should call init just once!');
|
|
56483
|
+
this.isInitialized = true;
|
|
56484
|
+
if (!this.options.isClone) this.logger.log('initialized', this.options);
|
|
56485
|
+
this.emit('initialized', this.options);
|
|
56486
|
+
deferred.resolve(t);
|
|
56487
|
+
callback(err, t);
|
|
56488
|
+
};
|
|
56489
|
+
if (this.languages && !this.isInitialized) return finish(null, this.t.bind(this));
|
|
56490
|
+
this.changeLanguage(this.options.lng, finish);
|
|
56491
|
+
};
|
|
56492
|
+
if (this.options.resources || !this.options.initAsync) {
|
|
56493
|
+
load();
|
|
56494
|
+
} else {
|
|
56495
|
+
setTimeout(load, 0);
|
|
56496
|
+
}
|
|
56497
|
+
return deferred;
|
|
56498
|
+
}
|
|
56499
|
+
loadResources(language, callback = noop) {
|
|
56500
|
+
let usedCallback = callback;
|
|
56501
|
+
const usedLng = isString(language) ? language : this.language;
|
|
56502
|
+
if (typeof language === 'function') usedCallback = language;
|
|
56503
|
+
if (!this.options.resources || this.options.partialBundledLanguages) {
|
|
56504
|
+
if (usedLng?.toLowerCase() === 'cimode' && (!this.options.preload || this.options.preload.length === 0)) return usedCallback();
|
|
56505
|
+
const toLoad = [];
|
|
56506
|
+
const append = lng => {
|
|
56507
|
+
if (!lng) return;
|
|
56508
|
+
if (lng === 'cimode') return;
|
|
56509
|
+
const lngs = this.services.languageUtils.toResolveHierarchy(lng);
|
|
56510
|
+
lngs.forEach(l => {
|
|
56511
|
+
if (l === 'cimode') return;
|
|
56512
|
+
if (toLoad.indexOf(l) < 0) toLoad.push(l);
|
|
56513
|
+
});
|
|
56514
|
+
};
|
|
56515
|
+
if (!usedLng) {
|
|
56516
|
+
const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
56517
|
+
fallbacks.forEach(l => append(l));
|
|
56518
|
+
} else {
|
|
56519
|
+
append(usedLng);
|
|
56520
|
+
}
|
|
56521
|
+
this.options.preload?.forEach?.(l => append(l));
|
|
56522
|
+
this.services.backendConnector.load(toLoad, this.options.ns, e => {
|
|
56523
|
+
if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
|
|
56524
|
+
usedCallback(e);
|
|
56525
|
+
});
|
|
56526
|
+
} else {
|
|
56527
|
+
usedCallback(null);
|
|
56528
|
+
}
|
|
56529
|
+
}
|
|
56530
|
+
reloadResources(lngs, ns, callback) {
|
|
56531
|
+
const deferred = defer();
|
|
56532
|
+
if (typeof lngs === 'function') {
|
|
56533
|
+
callback = lngs;
|
|
56534
|
+
lngs = undefined;
|
|
56535
|
+
}
|
|
56536
|
+
if (typeof ns === 'function') {
|
|
56537
|
+
callback = ns;
|
|
56538
|
+
ns = undefined;
|
|
56539
|
+
}
|
|
56540
|
+
if (!lngs) lngs = this.languages;
|
|
56541
|
+
if (!ns) ns = this.options.ns;
|
|
56542
|
+
if (!callback) callback = noop;
|
|
56543
|
+
this.services.backendConnector.reload(lngs, ns, err => {
|
|
56544
|
+
deferred.resolve();
|
|
56545
|
+
callback(err);
|
|
56546
|
+
});
|
|
56547
|
+
return deferred;
|
|
56548
|
+
}
|
|
56549
|
+
use(module) {
|
|
56550
|
+
if (!module) throw new Error('You are passing an undefined module! Please check the object you are passing to i18next.use()');
|
|
56551
|
+
if (!module.type) throw new Error('You are passing a wrong module! Please check the object you are passing to i18next.use()');
|
|
56552
|
+
if (module.type === 'backend') {
|
|
56553
|
+
this.modules.backend = module;
|
|
56554
|
+
}
|
|
56555
|
+
if (module.type === 'logger' || module.log && module.warn && module.error) {
|
|
56556
|
+
this.modules.logger = module;
|
|
56557
|
+
}
|
|
56558
|
+
if (module.type === 'languageDetector') {
|
|
56559
|
+
this.modules.languageDetector = module;
|
|
56560
|
+
}
|
|
56561
|
+
if (module.type === 'i18nFormat') {
|
|
56562
|
+
this.modules.i18nFormat = module;
|
|
56563
|
+
}
|
|
56564
|
+
if (module.type === 'postProcessor') {
|
|
56565
|
+
postProcessor.addPostProcessor(module);
|
|
56566
|
+
}
|
|
56567
|
+
if (module.type === 'formatter') {
|
|
56568
|
+
this.modules.formatter = module;
|
|
56569
|
+
}
|
|
56570
|
+
if (module.type === '3rdParty') {
|
|
56571
|
+
this.modules.external.push(module);
|
|
56572
|
+
}
|
|
56573
|
+
return this;
|
|
56574
|
+
}
|
|
56575
|
+
setResolvedLanguage(l) {
|
|
56576
|
+
if (!l || !this.languages) return;
|
|
56577
|
+
if (['cimode', 'dev'].indexOf(l) > -1) return;
|
|
56578
|
+
for (let li = 0; li < this.languages.length; li++) {
|
|
56579
|
+
const lngInLngs = this.languages[li];
|
|
56580
|
+
if (['cimode', 'dev'].indexOf(lngInLngs) > -1) continue;
|
|
56581
|
+
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
56582
|
+
this.resolvedLanguage = lngInLngs;
|
|
56583
|
+
break;
|
|
56584
|
+
}
|
|
56585
|
+
}
|
|
56586
|
+
if (!this.resolvedLanguage && this.languages.indexOf(l) < 0 && this.store.hasLanguageSomeTranslations(l)) {
|
|
56587
|
+
this.resolvedLanguage = l;
|
|
56588
|
+
this.languages.unshift(l);
|
|
56589
|
+
}
|
|
56590
|
+
}
|
|
56591
|
+
changeLanguage(lng, callback) {
|
|
56592
|
+
this.isLanguageChangingTo = lng;
|
|
56593
|
+
const deferred = defer();
|
|
56594
|
+
this.emit('languageChanging', lng);
|
|
56595
|
+
const setLngProps = l => {
|
|
56596
|
+
this.language = l;
|
|
56597
|
+
this.languages = this.services.languageUtils.toResolveHierarchy(l);
|
|
56598
|
+
this.resolvedLanguage = undefined;
|
|
56599
|
+
this.setResolvedLanguage(l);
|
|
56600
|
+
};
|
|
56601
|
+
const done = (err, l) => {
|
|
56602
|
+
if (l) {
|
|
56603
|
+
if (this.isLanguageChangingTo === lng) {
|
|
56604
|
+
setLngProps(l);
|
|
56605
|
+
this.translator.changeLanguage(l);
|
|
56606
|
+
this.isLanguageChangingTo = undefined;
|
|
56607
|
+
this.emit('languageChanged', l);
|
|
56608
|
+
this.logger.log('languageChanged', l);
|
|
56609
|
+
}
|
|
56610
|
+
} else {
|
|
56611
|
+
this.isLanguageChangingTo = undefined;
|
|
56612
|
+
}
|
|
56613
|
+
deferred.resolve((...args) => this.t(...args));
|
|
56614
|
+
if (callback) callback(err, (...args) => this.t(...args));
|
|
56615
|
+
};
|
|
56616
|
+
const setLng = lngs => {
|
|
56617
|
+
if (!lng && !lngs && this.services.languageDetector) lngs = [];
|
|
56618
|
+
const fl = isString(lngs) ? lngs : lngs && lngs[0];
|
|
56619
|
+
const l = this.store.hasLanguageSomeTranslations(fl) ? fl : this.services.languageUtils.getBestMatchFromCodes(isString(lngs) ? [lngs] : lngs);
|
|
56620
|
+
if (l) {
|
|
56621
|
+
if (!this.language) {
|
|
56622
|
+
setLngProps(l);
|
|
56623
|
+
}
|
|
56624
|
+
if (!this.translator.language) this.translator.changeLanguage(l);
|
|
56625
|
+
this.services.languageDetector?.cacheUserLanguage?.(l);
|
|
56626
|
+
}
|
|
56627
|
+
this.loadResources(l, err => {
|
|
56628
|
+
done(err, l);
|
|
56629
|
+
});
|
|
56630
|
+
};
|
|
56631
|
+
if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
|
|
56632
|
+
setLng(this.services.languageDetector.detect());
|
|
56633
|
+
} else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
|
|
56634
|
+
if (this.services.languageDetector.detect.length === 0) {
|
|
56635
|
+
this.services.languageDetector.detect().then(setLng);
|
|
56636
|
+
} else {
|
|
56637
|
+
this.services.languageDetector.detect(setLng);
|
|
56638
|
+
}
|
|
56639
|
+
} else {
|
|
56640
|
+
setLng(lng);
|
|
56641
|
+
}
|
|
56642
|
+
return deferred;
|
|
56643
|
+
}
|
|
56644
|
+
getFixedT(lng, ns, keyPrefix) {
|
|
56645
|
+
const fixedT = (key, opts, ...rest) => {
|
|
56646
|
+
let o;
|
|
56647
|
+
if (typeof opts !== 'object') {
|
|
56648
|
+
o = this.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
56649
|
+
} else {
|
|
56650
|
+
o = {
|
|
56651
|
+
...opts
|
|
56652
|
+
};
|
|
56653
|
+
}
|
|
56654
|
+
o.lng = o.lng || fixedT.lng;
|
|
56655
|
+
o.lngs = o.lngs || fixedT.lngs;
|
|
56656
|
+
o.ns = o.ns || fixedT.ns;
|
|
56657
|
+
if (o.keyPrefix !== '') o.keyPrefix = o.keyPrefix || keyPrefix || fixedT.keyPrefix;
|
|
56658
|
+
const keySeparator = this.options.keySeparator || '.';
|
|
56659
|
+
let resultKey;
|
|
56660
|
+
if (o.keyPrefix && Array.isArray(key)) {
|
|
56661
|
+
resultKey = key.map(k => {
|
|
56662
|
+
if (typeof k === 'function') k = keysFromSelector(k, {
|
|
56663
|
+
...this.options,
|
|
56664
|
+
...opts
|
|
56665
|
+
});
|
|
56666
|
+
return `${o.keyPrefix}${keySeparator}${k}`;
|
|
56667
|
+
});
|
|
56668
|
+
} else {
|
|
56669
|
+
if (typeof key === 'function') key = keysFromSelector(key, {
|
|
56670
|
+
...this.options,
|
|
56671
|
+
...opts
|
|
56672
|
+
});
|
|
56673
|
+
resultKey = o.keyPrefix ? `${o.keyPrefix}${keySeparator}${key}` : key;
|
|
56674
|
+
}
|
|
56675
|
+
return this.t(resultKey, o);
|
|
56676
|
+
};
|
|
56677
|
+
if (isString(lng)) {
|
|
56678
|
+
fixedT.lng = lng;
|
|
56679
|
+
} else {
|
|
56680
|
+
fixedT.lngs = lng;
|
|
56681
|
+
}
|
|
56682
|
+
fixedT.ns = ns;
|
|
56683
|
+
fixedT.keyPrefix = keyPrefix;
|
|
56684
|
+
return fixedT;
|
|
56685
|
+
}
|
|
56686
|
+
t(...args) {
|
|
56687
|
+
return this.translator?.translate(...args);
|
|
56688
|
+
}
|
|
56689
|
+
exists(...args) {
|
|
56690
|
+
return this.translator?.exists(...args);
|
|
56691
|
+
}
|
|
56692
|
+
setDefaultNamespace(ns) {
|
|
56693
|
+
this.options.defaultNS = ns;
|
|
56694
|
+
}
|
|
56695
|
+
hasLoadedNamespace(ns, options = {}) {
|
|
56696
|
+
if (!this.isInitialized) {
|
|
56697
|
+
this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
|
|
56698
|
+
return false;
|
|
56699
|
+
}
|
|
56700
|
+
if (!this.languages || !this.languages.length) {
|
|
56701
|
+
this.logger.warn('hasLoadedNamespace: i18n.languages were undefined or empty', this.languages);
|
|
56702
|
+
return false;
|
|
56703
|
+
}
|
|
56704
|
+
const lng = options.lng || this.resolvedLanguage || this.languages[0];
|
|
56705
|
+
const fallbackLng = this.options ? this.options.fallbackLng : false;
|
|
56706
|
+
const lastLng = this.languages[this.languages.length - 1];
|
|
56707
|
+
if (lng.toLowerCase() === 'cimode') return true;
|
|
56708
|
+
const loadNotPending = (l, n) => {
|
|
56709
|
+
const loadState = this.services.backendConnector.state[`${l}|${n}`];
|
|
56710
|
+
return loadState === -1 || loadState === 0 || loadState === 2;
|
|
56711
|
+
};
|
|
56712
|
+
if (options.precheck) {
|
|
56713
|
+
const preResult = options.precheck(this, loadNotPending);
|
|
56714
|
+
if (preResult !== undefined) return preResult;
|
|
56715
|
+
}
|
|
56716
|
+
if (this.hasResourceBundle(lng, ns)) return true;
|
|
56717
|
+
if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
|
|
56718
|
+
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
56719
|
+
return false;
|
|
56720
|
+
}
|
|
56721
|
+
loadNamespaces(ns, callback) {
|
|
56722
|
+
const deferred = defer();
|
|
56723
|
+
if (!this.options.ns) {
|
|
56724
|
+
if (callback) callback();
|
|
56725
|
+
return Promise.resolve();
|
|
56726
|
+
}
|
|
56727
|
+
if (isString(ns)) ns = [ns];
|
|
56728
|
+
ns.forEach(n => {
|
|
56729
|
+
if (this.options.ns.indexOf(n) < 0) this.options.ns.push(n);
|
|
56730
|
+
});
|
|
56731
|
+
this.loadResources(err => {
|
|
56732
|
+
deferred.resolve();
|
|
56733
|
+
if (callback) callback(err);
|
|
56734
|
+
});
|
|
56735
|
+
return deferred;
|
|
56736
|
+
}
|
|
56737
|
+
loadLanguages(lngs, callback) {
|
|
56738
|
+
const deferred = defer();
|
|
56739
|
+
if (isString(lngs)) lngs = [lngs];
|
|
56740
|
+
const preloaded = this.options.preload || [];
|
|
56741
|
+
const newLngs = lngs.filter(lng => preloaded.indexOf(lng) < 0 && this.services.languageUtils.isSupportedCode(lng));
|
|
56742
|
+
if (!newLngs.length) {
|
|
56743
|
+
if (callback) callback();
|
|
56744
|
+
return Promise.resolve();
|
|
56745
|
+
}
|
|
56746
|
+
this.options.preload = preloaded.concat(newLngs);
|
|
56747
|
+
this.loadResources(err => {
|
|
56748
|
+
deferred.resolve();
|
|
56749
|
+
if (callback) callback(err);
|
|
56750
|
+
});
|
|
56751
|
+
return deferred;
|
|
56752
|
+
}
|
|
56753
|
+
dir(lng) {
|
|
56754
|
+
if (!lng) lng = this.resolvedLanguage || (this.languages?.length > 0 ? this.languages[0] : this.language);
|
|
56755
|
+
if (!lng) return 'rtl';
|
|
56756
|
+
try {
|
|
56757
|
+
const l = new Intl.Locale(lng);
|
|
56758
|
+
if (l && l.getTextInfo) {
|
|
56759
|
+
const ti = l.getTextInfo();
|
|
56760
|
+
if (ti && ti.direction) return ti.direction;
|
|
56761
|
+
}
|
|
56762
|
+
} catch (e) {}
|
|
56763
|
+
const rtlLngs = ['ar', 'shu', 'sqr', 'ssh', 'xaa', 'yhd', 'yud', 'aao', 'abh', 'abv', 'acm', 'acq', 'acw', 'acx', 'acy', 'adf', 'ads', 'aeb', 'aec', 'afb', 'ajp', 'apc', 'apd', 'arb', 'arq', 'ars', 'ary', 'arz', 'auz', 'avl', 'ayh', 'ayl', 'ayn', 'ayp', 'bbz', 'pga', 'he', 'iw', 'ps', 'pbt', 'pbu', 'pst', 'prp', 'prd', 'ug', 'ur', 'ydd', 'yds', 'yih', 'ji', 'yi', 'hbo', 'men', 'xmn', 'fa', 'jpr', 'peo', 'pes', 'prs', 'dv', 'sam', 'ckb'];
|
|
56764
|
+
const languageUtils = this.services?.languageUtils || new LanguageUtil(get());
|
|
56765
|
+
if (lng.toLowerCase().indexOf('-latn') > 1) return 'ltr';
|
|
56766
|
+
return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
|
|
56767
|
+
}
|
|
56768
|
+
static createInstance(options = {}, callback) {
|
|
56769
|
+
return new I18n(options, callback);
|
|
56770
|
+
}
|
|
56771
|
+
cloneInstance(options = {}, callback = noop) {
|
|
56772
|
+
const forkResourceStore = options.forkResourceStore;
|
|
56773
|
+
if (forkResourceStore) delete options.forkResourceStore;
|
|
56774
|
+
const mergedOptions = {
|
|
56775
|
+
...this.options,
|
|
56776
|
+
...options,
|
|
56777
|
+
...{
|
|
56778
|
+
isClone: true
|
|
56779
|
+
}
|
|
56780
|
+
};
|
|
56781
|
+
const clone = new I18n(mergedOptions);
|
|
56782
|
+
if (options.debug !== undefined || options.prefix !== undefined) {
|
|
56783
|
+
clone.logger = clone.logger.clone(options);
|
|
56784
|
+
}
|
|
56785
|
+
const membersToCopy = ['store', 'services', 'language'];
|
|
56786
|
+
membersToCopy.forEach(m => {
|
|
56787
|
+
clone[m] = this[m];
|
|
56788
|
+
});
|
|
56789
|
+
clone.services = {
|
|
56790
|
+
...this.services
|
|
56791
|
+
};
|
|
56792
|
+
clone.services.utils = {
|
|
56793
|
+
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
56794
|
+
};
|
|
56795
|
+
if (forkResourceStore) {
|
|
56796
|
+
const clonedData = Object.keys(this.store.data).reduce((prev, l) => {
|
|
56797
|
+
prev[l] = {
|
|
56798
|
+
...this.store.data[l]
|
|
56799
|
+
};
|
|
56800
|
+
prev[l] = Object.keys(prev[l]).reduce((acc, n) => {
|
|
56801
|
+
acc[n] = {
|
|
56802
|
+
...prev[l][n]
|
|
56803
|
+
};
|
|
56804
|
+
return acc;
|
|
56805
|
+
}, prev[l]);
|
|
56806
|
+
return prev;
|
|
56807
|
+
}, {});
|
|
56808
|
+
clone.store = new ResourceStore(clonedData, mergedOptions);
|
|
56809
|
+
clone.services.resourceStore = clone.store;
|
|
56810
|
+
}
|
|
56811
|
+
clone.translator = new Translator(clone.services, mergedOptions);
|
|
56812
|
+
clone.translator.on('*', (event, ...args) => {
|
|
56813
|
+
clone.emit(event, ...args);
|
|
56814
|
+
});
|
|
56815
|
+
clone.init(mergedOptions, callback);
|
|
56816
|
+
clone.translator.options = mergedOptions;
|
|
56817
|
+
clone.translator.backendConnector.services.utils = {
|
|
56818
|
+
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
56819
|
+
};
|
|
56820
|
+
return clone;
|
|
56821
|
+
}
|
|
56822
|
+
toJSON() {
|
|
56823
|
+
return {
|
|
56824
|
+
options: this.options,
|
|
56825
|
+
store: this.store,
|
|
56826
|
+
language: this.language,
|
|
56827
|
+
languages: this.languages,
|
|
56828
|
+
resolvedLanguage: this.resolvedLanguage
|
|
56829
|
+
};
|
|
56830
|
+
}
|
|
56831
|
+
}
|
|
56832
|
+
const instance = I18n.createInstance();
|
|
56833
|
+
instance.createInstance = I18n.createInstance;
|
|
56834
|
+
|
|
56835
|
+
instance.createInstance;
|
|
56836
|
+
instance.dir;
|
|
56837
|
+
instance.init;
|
|
56838
|
+
instance.loadResources;
|
|
56839
|
+
instance.reloadResources;
|
|
56840
|
+
instance.use;
|
|
56841
|
+
instance.changeLanguage;
|
|
56842
|
+
instance.getFixedT;
|
|
56843
|
+
instance.t;
|
|
56844
|
+
instance.exists;
|
|
56845
|
+
instance.setDefaultNamespace;
|
|
56846
|
+
instance.hasLoadedNamespace;
|
|
56847
|
+
instance.loadNamespaces;
|
|
56848
|
+
instance.loadLanguages;
|
|
56849
|
+
|
|
54354
56850
|
const selectFiltersConfig$6 = {
|
|
54355
56851
|
category: {
|
|
54356
56852
|
type: 'select',
|
|
@@ -54892,7 +57388,7 @@ function Entities({
|
|
|
54892
57388
|
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
54893
57389
|
className: "flex flex-column flex-1",
|
|
54894
57390
|
children: [/*#__PURE__*/jsxRuntime.jsx(SelectFilters, {
|
|
54895
|
-
language:
|
|
57391
|
+
language: instance.language,
|
|
54896
57392
|
t: t,
|
|
54897
57393
|
options: selectOptions,
|
|
54898
57394
|
filtersConfig: selectFiltersConfig$6,
|
|
@@ -55984,7 +58480,7 @@ function Locations({
|
|
|
55984
58480
|
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
55985
58481
|
className: "flex flex-column flex-1",
|
|
55986
58482
|
children: [/*#__PURE__*/jsxRuntime.jsx(SelectFilters, {
|
|
55987
|
-
language:
|
|
58483
|
+
language: instance.language,
|
|
55988
58484
|
t: t,
|
|
55989
58485
|
options: selectOptions,
|
|
55990
58486
|
filtersConfig: selectFiltersConfig$5,
|