datastake-daf 0.6.101 → 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 +2700 -207
- package/package.json +1 -1
- 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/@daf/core/components/_style.scss +1 -2
- package/src/index.js +0 -1
- package/src/@daf/core/components/ProgressTabs/ProgressTabs.stories.js +0 -118
- package/src/@daf/core/components/ProgressTabs/_index.scss +0 -100
- package/src/@daf/core/components/ProgressTabs/demo.jsx +0 -167
- package/src/@daf/core/components/ProgressTabs/index.jsx +0 -69
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) {
|
|
@@ -3065,7 +3063,7 @@ const config$3 = {
|
|
|
3065
3063
|
Integration: config$4
|
|
3066
3064
|
};
|
|
3067
3065
|
|
|
3068
|
-
const _excluded$
|
|
3066
|
+
const _excluded$o = ["width", "height", "size", "name", "fill"];
|
|
3069
3067
|
const CustomIcon = _ref => {
|
|
3070
3068
|
let {
|
|
3071
3069
|
width = 14,
|
|
@@ -3074,7 +3072,7 @@ const CustomIcon = _ref => {
|
|
|
3074
3072
|
name = "",
|
|
3075
3073
|
fill = "none"
|
|
3076
3074
|
} = _ref,
|
|
3077
|
-
props = _objectWithoutProperties(_ref, _excluded$
|
|
3075
|
+
props = _objectWithoutProperties(_ref, _excluded$o);
|
|
3078
3076
|
const conf = config$3[name];
|
|
3079
3077
|
if (conf) {
|
|
3080
3078
|
return /*#__PURE__*/jsxRuntime.jsx("svg", _objectSpread2(_objectSpread2({}, props), {}, {
|
|
@@ -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]])) {
|
|
@@ -9276,7 +9274,7 @@ createCommonjsModule(function (module, exports) {
|
|
|
9276
9274
|
!function(e,n){module.exports=n();}(commonjsGlobal,(function(){return {name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(e){var n=["th","st","nd","rd"],t=e%100;return "["+e+(n[(t-20)%10]||n[t]||n[0])+"]"}}}));
|
|
9277
9275
|
});
|
|
9278
9276
|
|
|
9279
|
-
const _excluded$
|
|
9277
|
+
const _excluded$n = ["view", "module", "scope", "form", "meta"];
|
|
9280
9278
|
dayjs__default["default"].extend(customParseFormat);
|
|
9281
9279
|
dayjs__default["default"].extend(utc);
|
|
9282
9280
|
dayjs__default["default"].extend(utc);
|
|
@@ -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,
|
|
@@ -9650,7 +9648,7 @@ const filterCreateData = data => {
|
|
|
9650
9648
|
form,
|
|
9651
9649
|
meta
|
|
9652
9650
|
} = data,
|
|
9653
|
-
rest = _objectWithoutProperties(data, _excluded$
|
|
9651
|
+
rest = _objectWithoutProperties(data, _excluded$n);
|
|
9654
9652
|
const _meta = isObjectEmpty(meta) ? undefined : meta;
|
|
9655
9653
|
return _objectSpread2(_objectSpread2({}, rest), {}, {
|
|
9656
9654
|
meta: _meta
|
|
@@ -10035,7 +10033,7 @@ SelectFilters.propTypes = {
|
|
|
10035
10033
|
apiUrl: PropTypes__default["default"].string
|
|
10036
10034
|
};
|
|
10037
10035
|
|
|
10038
|
-
const _excluded$
|
|
10036
|
+
const _excluded$m = ["columns", "data", "defaultFilters", "style", "pagination", "loading", "onChange", "onFilterChange", "selectOptions", "filtersConfig", "rowSelection", "setShowFilters", "rowKey", "showFilters", "hideOnLoading", "sourcesKey", "className", "projects", "t", "selectedProject", "sourceId", "projectSources", "language", "scrollX", "apiUrl", "app", "doEmptyRows"];
|
|
10039
10037
|
function DAFTable(_ref) {
|
|
10040
10038
|
let {
|
|
10041
10039
|
columns = [],
|
|
@@ -10066,7 +10064,7 @@ function DAFTable(_ref) {
|
|
|
10066
10064
|
app,
|
|
10067
10065
|
doEmptyRows
|
|
10068
10066
|
} = _ref,
|
|
10069
|
-
rest = _objectWithoutProperties(_ref, _excluded$
|
|
10067
|
+
rest = _objectWithoutProperties(_ref, _excluded$m);
|
|
10070
10068
|
const [source, setSource] = React.useState([]);
|
|
10071
10069
|
const projectData = (projects || []).find(p => p.id === selectedProject);
|
|
10072
10070
|
const [filtersInit, setFiltersInit] = React.useState(!loading);
|
|
@@ -10788,7 +10786,7 @@ Pagination.propTypes = {
|
|
|
10788
10786
|
isMobile: PropTypes__default["default"].bool
|
|
10789
10787
|
};
|
|
10790
10788
|
|
|
10791
|
-
const _excluded$
|
|
10789
|
+
const _excluded$l = ["size", "maxHeight", "dataSource", "columns", "pagination"];
|
|
10792
10790
|
function StickyTable(_ref) {
|
|
10793
10791
|
let {
|
|
10794
10792
|
size = null,
|
|
@@ -10797,7 +10795,7 @@ function StickyTable(_ref) {
|
|
|
10797
10795
|
columns = {},
|
|
10798
10796
|
pagination = false
|
|
10799
10797
|
} = _ref,
|
|
10800
|
-
props = _objectWithoutProperties(_ref, _excluded$
|
|
10798
|
+
props = _objectWithoutProperties(_ref, _excluded$l);
|
|
10801
10799
|
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
10802
10800
|
className: "daf-sticky-table",
|
|
10803
10801
|
children: /*#__PURE__*/jsxRuntime.jsx(antd.Table, _objectSpread2(_objectSpread2({}, props), {}, {
|
|
@@ -11489,12 +11487,12 @@ const Style$H = dt.div`
|
|
|
11489
11487
|
}
|
|
11490
11488
|
`;
|
|
11491
11489
|
|
|
11492
|
-
const _excluded$
|
|
11490
|
+
const _excluded$k = ["children"];
|
|
11493
11491
|
const BorderedButton = _ref => {
|
|
11494
11492
|
let {
|
|
11495
11493
|
children
|
|
11496
11494
|
} = _ref,
|
|
11497
|
-
props = _objectWithoutProperties(_ref, _excluded$
|
|
11495
|
+
props = _objectWithoutProperties(_ref, _excluded$k);
|
|
11498
11496
|
return /*#__PURE__*/jsxRuntime.jsx(Style$H, {
|
|
11499
11497
|
className: "d-btn-cont",
|
|
11500
11498
|
children: /*#__PURE__*/jsxRuntime.jsx(antd.Button, _objectSpread2(_objectSpread2({}, props), {}, {
|
|
@@ -11634,12 +11632,12 @@ Badge.propTypes = {
|
|
|
11634
11632
|
props: PropTypes__default["default"].object
|
|
11635
11633
|
};
|
|
11636
11634
|
|
|
11637
|
-
const _excluded$
|
|
11635
|
+
const _excluded$j = ["icon"];
|
|
11638
11636
|
function GetIcon(_ref) {
|
|
11639
11637
|
let {
|
|
11640
11638
|
icon
|
|
11641
11639
|
} = _ref,
|
|
11642
|
-
props = _objectWithoutProperties(_ref, _excluded$
|
|
11640
|
+
props = _objectWithoutProperties(_ref, _excluded$j);
|
|
11643
11641
|
let Icon = Icons__namespace.CloseOutlined;
|
|
11644
11642
|
if (Icons__namespace[icon]) {
|
|
11645
11643
|
Icon = Icons__namespace[icon];
|
|
@@ -11961,7 +11959,7 @@ GoToSelect.propTypes = {
|
|
|
11961
11959
|
t: PropTypes__default["default"].func
|
|
11962
11960
|
};
|
|
11963
11961
|
|
|
11964
|
-
const _excluded$
|
|
11962
|
+
const _excluded$i = ["options", "defaultSelected", "onChange", "textWhenMultiple", "withCount", "oneAlwaysSelected", "canUnselectLast", "isAvatarGroup", "maxAvatarCount", "dropDownWidth", "topAvatarValue", "isSingle", "selectionType"];
|
|
11965
11963
|
const {
|
|
11966
11964
|
useToken: useToken$i
|
|
11967
11965
|
} = antd.theme;
|
|
@@ -12054,7 +12052,7 @@ function Multiselect(_ref) {
|
|
|
12054
12052
|
isSingle = false,
|
|
12055
12053
|
selectionType = SELECTION_TYPES.DEFAULT
|
|
12056
12054
|
} = _ref,
|
|
12057
|
-
restProps = _objectWithoutProperties(_ref, _excluded$
|
|
12055
|
+
restProps = _objectWithoutProperties(_ref, _excluded$i);
|
|
12058
12056
|
const {
|
|
12059
12057
|
token
|
|
12060
12058
|
} = useToken$i();
|
|
@@ -12721,7 +12719,7 @@ DAFHeader.propTypes = {
|
|
|
12721
12719
|
downloadDisabled: PropTypes__default["default"].any
|
|
12722
12720
|
};
|
|
12723
12721
|
|
|
12724
|
-
const _excluded$
|
|
12722
|
+
const _excluded$h = ["tabs", "onChange", "value", "className"];
|
|
12725
12723
|
function TabsHeader(_ref) {
|
|
12726
12724
|
let {
|
|
12727
12725
|
tabs = [],
|
|
@@ -12729,7 +12727,7 @@ function TabsHeader(_ref) {
|
|
|
12729
12727
|
value = '',
|
|
12730
12728
|
className = 'mt-2'
|
|
12731
12729
|
} = _ref,
|
|
12732
|
-
rest = _objectWithoutProperties(_ref, _excluded$
|
|
12730
|
+
rest = _objectWithoutProperties(_ref, _excluded$h);
|
|
12733
12731
|
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
12734
12732
|
className: formatClassname(['daf-tabs-header pl-6 pr-6', className]),
|
|
12735
12733
|
children: /*#__PURE__*/jsxRuntime.jsx(antd.Tabs, _objectSpread2({
|
|
@@ -12826,7 +12824,7 @@ DrawerHeader.propTypes = {
|
|
|
12826
12824
|
tabsConfig: PropTypes__default["default"].any
|
|
12827
12825
|
};
|
|
12828
12826
|
|
|
12829
|
-
const _excluded$
|
|
12827
|
+
const _excluded$g = ["label", "onClick", "icon", "type", "tooltip", "disabled", "loading", "style", "className"];
|
|
12830
12828
|
const useFooter = _ref => {
|
|
12831
12829
|
let {
|
|
12832
12830
|
leftContent,
|
|
@@ -12861,7 +12859,7 @@ const useFooter = _ref => {
|
|
|
12861
12859
|
style = {},
|
|
12862
12860
|
className = ""
|
|
12863
12861
|
} = button,
|
|
12864
|
-
restProps = _objectWithoutProperties(button, _excluded$
|
|
12862
|
+
restProps = _objectWithoutProperties(button, _excluded$g);
|
|
12865
12863
|
return /*#__PURE__*/jsxRuntime.jsx(DafButton, _objectSpread2({
|
|
12866
12864
|
content: label,
|
|
12867
12865
|
type: type,
|
|
@@ -13456,14 +13454,77 @@ function Geolocation$2({
|
|
|
13456
13454
|
});
|
|
13457
13455
|
}
|
|
13458
13456
|
|
|
13459
|
-
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) => {
|
|
13460
13521
|
switch (type) {
|
|
13461
13522
|
case 'year':
|
|
13462
|
-
return renderDateFormatted(value, 'YYYY', 'en');
|
|
13523
|
+
return value !== '-' ? renderDateFormatted(value, 'YYYY', 'en') : '-';
|
|
13463
13524
|
case 'date':
|
|
13464
13525
|
{
|
|
13465
13526
|
const language = user?.language && user?.language === 'sp' ? 'es' : user?.language;
|
|
13466
|
-
return renderDateFormatted(value, 'DD MMM YYYY', language || 'en');
|
|
13527
|
+
return value !== '-' ? renderDateFormatted(value, 'DD MMM YYYY', language || 'en') : '-';
|
|
13467
13528
|
}
|
|
13468
13529
|
case 'select':
|
|
13469
13530
|
{
|
|
@@ -13471,6 +13532,13 @@ const renderFieldData = (type, value, user, config, getApiBaseUrl = () => {}, ge
|
|
|
13471
13532
|
const option = findOptions(value, options);
|
|
13472
13533
|
return option;
|
|
13473
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
|
+
}
|
|
13474
13542
|
case 'ajaxSelect':
|
|
13475
13543
|
return /*#__PURE__*/jsxRuntime.jsx(AjaxSelectRenderer, {
|
|
13476
13544
|
value: value,
|
|
@@ -13490,6 +13558,13 @@ const renderFieldData = (type, value, user, config, getApiBaseUrl = () => {}, ge
|
|
|
13490
13558
|
t: () => {}
|
|
13491
13559
|
});
|
|
13492
13560
|
}
|
|
13561
|
+
case 'imageUpload':
|
|
13562
|
+
case 'upload':
|
|
13563
|
+
case 'videoUpload':
|
|
13564
|
+
{
|
|
13565
|
+
const documentName = allValues?.map(item => item?.name).join(', ');
|
|
13566
|
+
return documentName;
|
|
13567
|
+
}
|
|
13493
13568
|
default:
|
|
13494
13569
|
return value;
|
|
13495
13570
|
}
|
|
@@ -13531,15 +13606,18 @@ const renderValue = ({
|
|
|
13531
13606
|
return combinedValue ? /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
13532
13607
|
className: "tree-value groupInputs-type",
|
|
13533
13608
|
children: combinedValue
|
|
13534
|
-
}) :
|
|
13609
|
+
}) : /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
13610
|
+
className: "tree-value empty",
|
|
13611
|
+
children: "-"
|
|
13612
|
+
});
|
|
13535
13613
|
}
|
|
13536
13614
|
if (hasChildren) return null;
|
|
13537
13615
|
let displayValue = '';
|
|
13538
13616
|
if (value === null || value === undefined || value === '') {
|
|
13539
|
-
displayValue = '';
|
|
13617
|
+
displayValue = '-'; // Changed from '' to '-'
|
|
13540
13618
|
} else if (typeof value === 'object' && value !== null) {
|
|
13541
13619
|
if (Array.isArray(value)) {
|
|
13542
|
-
displayValue = value.length > 0 ? value.join(', ') : '';
|
|
13620
|
+
displayValue = value.length > 0 ? value.join(', ') : '-'; // Changed from '' to '-'
|
|
13543
13621
|
} else if (value.name || value.fullName) {
|
|
13544
13622
|
displayValue = value.name || value.fullName;
|
|
13545
13623
|
} else if (value.label) {
|
|
@@ -13552,21 +13630,28 @@ const renderValue = ({
|
|
|
13552
13630
|
}
|
|
13553
13631
|
const fieldType = config?.type || 'text';
|
|
13554
13632
|
let cssClass = `tree-value ${fieldType}-type`;
|
|
13555
|
-
|
|
13556
|
-
|
|
13633
|
+
if (displayValue === '-') {
|
|
13634
|
+
cssClass += ' empty';
|
|
13635
|
+
}
|
|
13636
|
+
displayValue = renderFieldData(fieldType, displayValue, user, config, getApiBaseUrl, getAppHeader, app, value);
|
|
13637
|
+
return /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
13557
13638
|
className: cssClass,
|
|
13558
13639
|
children: displayValue
|
|
13559
|
-
})
|
|
13640
|
+
});
|
|
13560
13641
|
};
|
|
13561
13642
|
const determineHasChildren = ({
|
|
13562
13643
|
config,
|
|
13563
13644
|
level
|
|
13564
13645
|
}) => {
|
|
13565
|
-
// groupInputs should be treated as leaf nodes, not parent nodes
|
|
13566
13646
|
if (config?.type === 'groupInputs') {
|
|
13567
13647
|
return false;
|
|
13568
13648
|
}
|
|
13569
|
-
|
|
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);
|
|
13570
13655
|
};
|
|
13571
13656
|
|
|
13572
13657
|
const sortByPosition = (items, getConfig) => {
|
|
@@ -13854,9 +13939,6 @@ const handleDataLinkGroupWithTableKeys = ({
|
|
|
13854
13939
|
if (!(config.type === 'dataLinkGroup' || config.type === 'dataLink')) {
|
|
13855
13940
|
return null;
|
|
13856
13941
|
}
|
|
13857
|
-
console.log({
|
|
13858
|
-
app
|
|
13859
|
-
});
|
|
13860
13942
|
if (inputConfig?.type !== 'dataLink' || !inputConfig?.meta?.tableKeys) {
|
|
13861
13943
|
const parentInputKeys = Object.keys(config.inputs || {});
|
|
13862
13944
|
const isHandledBySiblingDataLink = parentInputKeys.some(otherInputKey => {
|
|
@@ -13876,9 +13958,6 @@ const handleDataLinkGroupWithTableKeys = ({
|
|
|
13876
13958
|
}
|
|
13877
13959
|
return null;
|
|
13878
13960
|
}
|
|
13879
|
-
if (!(value && typeof value === 'object')) {
|
|
13880
|
-
return null;
|
|
13881
|
-
}
|
|
13882
13961
|
const tableKeys = inputConfig.meta.tableKeys;
|
|
13883
13962
|
const additionalTableKeys = config.meta?.additionalTableKeys || [];
|
|
13884
13963
|
[...new Set([...tableKeys, ...additionalTableKeys])];
|
|
@@ -13899,12 +13978,19 @@ const handleDataLinkGroupWithTableKeys = ({
|
|
|
13899
13978
|
const createInputsAndValues = item => {
|
|
13900
13979
|
const inputs = {};
|
|
13901
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
|
+
};
|
|
13902
13988
|
tableKeys.filter(tableKey => tableKey !== 'datastakeId').forEach(tableKey => {
|
|
13903
13989
|
const formInputConfig = dataLinkForm?.[tableKey] || dataLinkForm?.['identification']?.[tableKey];
|
|
13904
13990
|
if (formInputConfig) {
|
|
13905
13991
|
inputs[tableKey] = {
|
|
13906
13992
|
...formInputConfig,
|
|
13907
|
-
label: formInputConfig.label || formInputConfig.tableLabel || tableKey
|
|
13993
|
+
label: uploadTypeFields.includes(tableKey) ? uploadTypeLabels[tableKey] : formInputConfig.label || formInputConfig.tableLabel || tableKey
|
|
13908
13994
|
};
|
|
13909
13995
|
if (formInputConfig.label && typeof formInputConfig.label === 'object') {
|
|
13910
13996
|
const dynamicLabelKeys = Object.keys(formInputConfig.label);
|
|
@@ -13919,12 +14005,12 @@ const handleDataLinkGroupWithTableKeys = ({
|
|
|
13919
14005
|
}
|
|
13920
14006
|
}
|
|
13921
14007
|
}
|
|
13922
|
-
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);
|
|
13923
14009
|
}
|
|
13924
14010
|
values[tableKey] = item?.[tableKey];
|
|
13925
14011
|
} else {
|
|
13926
14012
|
inputs[tableKey] = {
|
|
13927
|
-
label: tableKey,
|
|
14013
|
+
label: uploadTypeFields.includes(tableKey) ? uploadTypeLabels[tableKey] : tableKey,
|
|
13928
14014
|
type: inputConfig?.type
|
|
13929
14015
|
};
|
|
13930
14016
|
values[tableKey] = item?.[tableKey];
|
|
@@ -13938,7 +14024,7 @@ const handleDataLinkGroupWithTableKeys = ({
|
|
|
13938
14024
|
const formInputConfig = dataLinkForm.identification[fieldKey];
|
|
13939
14025
|
inputs[fieldKey] = {
|
|
13940
14026
|
...formInputConfig,
|
|
13941
|
-
label: formInputConfig.label || formInputConfig.tableLabel || fieldKey
|
|
14027
|
+
label: uploadTypeFields.includes(fieldKey) ? uploadTypeLabels[fieldKey] : formInputConfig.label || formInputConfig.tableLabel || fieldKey
|
|
13942
14028
|
};
|
|
13943
14029
|
if (formInputConfig.label && typeof formInputConfig.label === 'object') {
|
|
13944
14030
|
const dynamicLabelKeys = Object.keys(formInputConfig.label);
|
|
@@ -13953,7 +14039,7 @@ const handleDataLinkGroupWithTableKeys = ({
|
|
|
13953
14039
|
}
|
|
13954
14040
|
}
|
|
13955
14041
|
}
|
|
13956
|
-
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);
|
|
13957
14043
|
}
|
|
13958
14044
|
values[fieldKey] = item?.[fieldKey];
|
|
13959
14045
|
});
|
|
@@ -13971,9 +14057,9 @@ const handleDataLinkGroupWithTableKeys = ({
|
|
|
13971
14057
|
values
|
|
13972
14058
|
} = createInputsAndValues(item);
|
|
13973
14059
|
return /*#__PURE__*/jsxRuntime.jsx(TreeNodeComponent, {
|
|
13974
|
-
nodeKey: datastakeIdValue || `
|
|
14060
|
+
nodeKey: datastakeIdValue || t(`No ID ${itemIndex + 1}`),
|
|
13975
14061
|
config: {
|
|
13976
|
-
label: datastakeIdValue || `
|
|
14062
|
+
label: datastakeIdValue || t(`No ID ${itemIndex + 1}`),
|
|
13977
14063
|
type: 'custom-datalink-group',
|
|
13978
14064
|
inputs: inputs
|
|
13979
14065
|
},
|
|
@@ -13996,9 +14082,9 @@ const handleDataLinkGroupWithTableKeys = ({
|
|
|
13996
14082
|
values
|
|
13997
14083
|
} = createInputsAndValues(value);
|
|
13998
14084
|
return /*#__PURE__*/jsxRuntime.jsx(TreeNodeComponent, {
|
|
13999
|
-
nodeKey: datastakeIdValue || '
|
|
14085
|
+
nodeKey: datastakeIdValue || t('No ID'),
|
|
14000
14086
|
config: {
|
|
14001
|
-
label: datastakeIdValue || '
|
|
14087
|
+
label: datastakeIdValue || t('No ID'),
|
|
14002
14088
|
type: 'custom-datalink-group',
|
|
14003
14089
|
inputs: inputs
|
|
14004
14090
|
},
|
|
@@ -14033,9 +14119,6 @@ const handleDataLinkWithTableKeys = ({
|
|
|
14033
14119
|
if (inputConfig?.type !== 'dataLink' || !inputConfig?.meta?.tableKeys) {
|
|
14034
14120
|
return null;
|
|
14035
14121
|
}
|
|
14036
|
-
if (!(value && typeof value === 'object')) {
|
|
14037
|
-
return null;
|
|
14038
|
-
}
|
|
14039
14122
|
const tableKeys = inputConfig.meta.tableKeys;
|
|
14040
14123
|
const isAjaxModal = React.useMemo(() => !!inputConfig?.meta?.namespace, [inputConfig]);
|
|
14041
14124
|
const ajaxModalValues = useAjaxModal$2({
|
|
@@ -14053,12 +14136,27 @@ const handleDataLinkWithTableKeys = ({
|
|
|
14053
14136
|
const createInputsAndValues = item => {
|
|
14054
14137
|
const inputs = {};
|
|
14055
14138
|
const values = {};
|
|
14056
|
-
|
|
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 => {
|
|
14057
14155
|
const formInputConfig = dataLinkForm?.[tableKey] || dataLinkForm?.['identification']?.[tableKey];
|
|
14058
14156
|
if (formInputConfig) {
|
|
14059
14157
|
inputs[tableKey] = {
|
|
14060
14158
|
...formInputConfig,
|
|
14061
|
-
label: formInputConfig.label || formInputConfig.tableLabel || tableKey
|
|
14159
|
+
label: uploadTypeFields.includes(tableKey) ? uploadTypeLabels[tableKey] : formInputConfig.label || formInputConfig.tableLabel || tableKey
|
|
14062
14160
|
};
|
|
14063
14161
|
if (formInputConfig.label && typeof formInputConfig.label === 'object') {
|
|
14064
14162
|
const dynamicLabelKeys = Object.keys(formInputConfig.label);
|
|
@@ -14073,26 +14171,31 @@ const handleDataLinkWithTableKeys = ({
|
|
|
14073
14171
|
}
|
|
14074
14172
|
}
|
|
14075
14173
|
}
|
|
14076
|
-
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);
|
|
14077
14175
|
}
|
|
14078
14176
|
values[tableKey] = item?.[tableKey];
|
|
14079
14177
|
} else {
|
|
14080
14178
|
inputs[tableKey] = {
|
|
14081
|
-
label: tableKey,
|
|
14179
|
+
label: uploadTypeFields.includes(tableKey) ? uploadTypeLabels[tableKey] : tableKey,
|
|
14082
14180
|
type: inputConfig?.type
|
|
14083
14181
|
};
|
|
14084
14182
|
values[tableKey] = item?.[tableKey];
|
|
14085
14183
|
}
|
|
14086
14184
|
});
|
|
14087
14185
|
if (dataLinkForm?.identification && typeof dataLinkForm.identification === 'object') {
|
|
14088
|
-
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 => {
|
|
14089
14192
|
const formInputConfig = dataLinkForm.identification[fieldKey];
|
|
14090
14193
|
return formInputConfig && typeof formInputConfig === 'object' && !Array.isArray(formInputConfig);
|
|
14091
14194
|
}).forEach(fieldKey => {
|
|
14092
14195
|
const formInputConfig = dataLinkForm.identification[fieldKey];
|
|
14093
14196
|
inputs[fieldKey] = {
|
|
14094
14197
|
...formInputConfig,
|
|
14095
|
-
label: formInputConfig.label || formInputConfig.tableLabel || fieldKey
|
|
14198
|
+
label: uploadTypeFields.includes(fieldKey) ? uploadTypeLabels[fieldKey] : formInputConfig.label || formInputConfig.tableLabel || fieldKey
|
|
14096
14199
|
};
|
|
14097
14200
|
if (formInputConfig.label && typeof formInputConfig.label === 'object') {
|
|
14098
14201
|
const dynamicLabelKeys = Object.keys(formInputConfig.label);
|
|
@@ -14107,7 +14210,7 @@ const handleDataLinkWithTableKeys = ({
|
|
|
14107
14210
|
}
|
|
14108
14211
|
}
|
|
14109
14212
|
}
|
|
14110
|
-
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);
|
|
14111
14214
|
}
|
|
14112
14215
|
values[fieldKey] = item?.[fieldKey];
|
|
14113
14216
|
});
|
|
@@ -14124,10 +14227,13 @@ const handleDataLinkWithTableKeys = ({
|
|
|
14124
14227
|
inputs,
|
|
14125
14228
|
values
|
|
14126
14229
|
} = createInputsAndValues(item);
|
|
14230
|
+
if (Object.keys(inputs).length === 0) {
|
|
14231
|
+
return null;
|
|
14232
|
+
}
|
|
14127
14233
|
return /*#__PURE__*/jsxRuntime.jsx(TreeNodeComponent, {
|
|
14128
|
-
nodeKey: datastakeIdValue || `
|
|
14234
|
+
nodeKey: datastakeIdValue || t(`No ID ${itemIndex + 1}`),
|
|
14129
14235
|
config: {
|
|
14130
|
-
label: datastakeIdValue || `
|
|
14236
|
+
label: datastakeIdValue || t(`No ID ${itemIndex + 1}`),
|
|
14131
14237
|
type: 'custom-datalink',
|
|
14132
14238
|
inputs: inputs
|
|
14133
14239
|
},
|
|
@@ -14149,10 +14255,13 @@ const handleDataLinkWithTableKeys = ({
|
|
|
14149
14255
|
inputs,
|
|
14150
14256
|
values
|
|
14151
14257
|
} = createInputsAndValues(value);
|
|
14258
|
+
if (Object.keys(inputs).length === 0) {
|
|
14259
|
+
return null;
|
|
14260
|
+
}
|
|
14152
14261
|
return /*#__PURE__*/jsxRuntime.jsx(TreeNodeComponent, {
|
|
14153
|
-
nodeKey: datastakeIdValue || '
|
|
14262
|
+
nodeKey: datastakeIdValue || t('No ID'),
|
|
14154
14263
|
config: {
|
|
14155
|
-
label: datastakeIdValue || '
|
|
14264
|
+
label: datastakeIdValue || t('No ID'),
|
|
14156
14265
|
type: 'custom-datalink',
|
|
14157
14266
|
inputs: inputs
|
|
14158
14267
|
},
|
|
@@ -14257,8 +14366,111 @@ const GroupInputsHandler = ({
|
|
|
14257
14366
|
}) : null;
|
|
14258
14367
|
};
|
|
14259
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
|
+
|
|
14260
14472
|
const TreeNode = _ref => {
|
|
14261
|
-
var _config$
|
|
14473
|
+
var _allData$meta, _config$meta2;
|
|
14262
14474
|
let {
|
|
14263
14475
|
nodeKey,
|
|
14264
14476
|
config,
|
|
@@ -14273,23 +14485,34 @@ const TreeNode = _ref => {
|
|
|
14273
14485
|
getAppHeader = () => {},
|
|
14274
14486
|
app
|
|
14275
14487
|
} = _ref;
|
|
14276
|
-
|
|
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({
|
|
14277
14493
|
config,
|
|
14278
14494
|
level
|
|
14279
14495
|
});
|
|
14496
|
+
const hasChildren = originalHasChildren || hasMetaComment;
|
|
14280
14497
|
const label = resolveDynamicLabel(config === null || config === void 0 ? void 0 : config.label, allData || value, nodeKey);
|
|
14281
14498
|
(config === null || config === void 0 ? void 0 : config.type) || 'field';
|
|
14282
14499
|
let renderNodeValue = () => renderValue({
|
|
14283
14500
|
value,
|
|
14284
|
-
hasChildren,
|
|
14501
|
+
hasChildren: originalHasChildren,
|
|
14285
14502
|
config,
|
|
14286
14503
|
user,
|
|
14287
14504
|
getApiBaseUrl,
|
|
14288
14505
|
getAppHeader,
|
|
14289
14506
|
app
|
|
14290
14507
|
});
|
|
14508
|
+
if (nodeKey === 'keyIncidents') {
|
|
14509
|
+
console.log({
|
|
14510
|
+
config,
|
|
14511
|
+
value,
|
|
14512
|
+
hasChildren
|
|
14513
|
+
});
|
|
14514
|
+
}
|
|
14291
14515
|
const renderChildren = () => {
|
|
14292
|
-
var _config$meta;
|
|
14293
14516
|
if (!hasChildren) return null;
|
|
14294
14517
|
let children = [];
|
|
14295
14518
|
const sectionChildren = handleSectionChildren({
|
|
@@ -14304,13 +14527,26 @@ const TreeNode = _ref => {
|
|
|
14304
14527
|
getAppHeader,
|
|
14305
14528
|
TreeNodeComponent: TreeNode
|
|
14306
14529
|
});
|
|
14307
|
-
if (
|
|
14308
|
-
|
|
14309
|
-
|
|
14310
|
-
|
|
14311
|
-
|
|
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
|
|
14312
14543
|
});
|
|
14313
|
-
|
|
14544
|
+
if (ajaxSubGroupChildren) {
|
|
14545
|
+
children = ajaxSubGroupChildren;
|
|
14546
|
+
}
|
|
14547
|
+
} else if (sectionChildren) {
|
|
14548
|
+
children = sectionChildren;
|
|
14549
|
+
} else if (config.type === 'dataLink') {
|
|
14314
14550
|
const singleDataLinkChildren = handleDataLinkWithTableKeys({
|
|
14315
14551
|
inputConfig: config,
|
|
14316
14552
|
inputKey: nodeKey,
|
|
@@ -14330,7 +14566,14 @@ const TreeNode = _ref => {
|
|
|
14330
14566
|
}
|
|
14331
14567
|
} else if (config !== null && config !== void 0 && config.inputs) {
|
|
14332
14568
|
if (config.type === 'dataLinkGroup' || config.type === 'dataLink') {
|
|
14333
|
-
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) => {
|
|
14334
14577
|
var _config$inputs$a, _config$inputs$b;
|
|
14335
14578
|
const positionA = ((_config$inputs$a = config.inputs[a]) === null || _config$inputs$a === void 0 ? void 0 : _config$inputs$a.position) || 0;
|
|
14336
14579
|
const positionB = ((_config$inputs$b = config.inputs[b]) === null || _config$inputs$b === void 0 ? void 0 : _config$inputs$b.position) || 0;
|
|
@@ -14379,8 +14622,8 @@ const TreeNode = _ref => {
|
|
|
14379
14622
|
return groupChildren;
|
|
14380
14623
|
}).flat().filter(Boolean);
|
|
14381
14624
|
} else {
|
|
14382
|
-
var _config$
|
|
14383
|
-
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) {
|
|
14384
14627
|
const singleDataLinkChildren = handleDataLinkWithTableKeys({
|
|
14385
14628
|
inputConfig: config,
|
|
14386
14629
|
inputKey: nodeKey,
|
|
@@ -14416,7 +14659,14 @@ const TreeNode = _ref => {
|
|
|
14416
14659
|
if (arrayChildren) {
|
|
14417
14660
|
children = arrayChildren;
|
|
14418
14661
|
} else {
|
|
14419
|
-
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) => {
|
|
14420
14670
|
var _config$inputs$a2, _config$inputs$b2;
|
|
14421
14671
|
const positionA = ((_config$inputs$a2 = config.inputs[a]) === null || _config$inputs$a2 === void 0 ? void 0 : _config$inputs$a2.position) || 0;
|
|
14422
14672
|
const positionB = ((_config$inputs$b2 = config.inputs[b]) === null || _config$inputs$b2 === void 0 ? void 0 : _config$inputs$b2.position) || 0;
|
|
@@ -14468,6 +14718,37 @@ const TreeNode = _ref => {
|
|
|
14468
14718
|
}
|
|
14469
14719
|
}
|
|
14470
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
|
+
}
|
|
14471
14752
|
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
14472
14753
|
className: "tree-children",
|
|
14473
14754
|
children: children
|
|
@@ -14483,7 +14764,7 @@ const TreeNode = _ref => {
|
|
|
14483
14764
|
};
|
|
14484
14765
|
}
|
|
14485
14766
|
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
14486
|
-
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' : ''),
|
|
14487
14768
|
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
14488
14769
|
className: "tree-node-content",
|
|
14489
14770
|
children: [/*#__PURE__*/jsxRuntime.jsx("div", {
|
|
@@ -14496,14 +14777,14 @@ const TreeNode = _ref => {
|
|
|
14496
14777
|
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
14497
14778
|
className: "tree-node-title",
|
|
14498
14779
|
children: [/*#__PURE__*/jsxRuntime.jsxs("span", {
|
|
14499
|
-
className: "tree-label",
|
|
14500
|
-
children: [label, !hasChildren && renderNodeValue() ? ':' : '']
|
|
14780
|
+
className: "tree-label ".concat(nodeKey === 'comment' ? 'comment-label' : ''),
|
|
14781
|
+
children: [label, !hasChildren && renderNodeValue() && !label.endsWith('?') ? ':' : '']
|
|
14501
14782
|
}), /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
14502
14783
|
className: "tree-value-container",
|
|
14503
14784
|
children: renderNodeValue()
|
|
14504
14785
|
}), /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
14505
14786
|
className: "tree-code",
|
|
14506
|
-
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) || ''
|
|
14507
14788
|
})]
|
|
14508
14789
|
})]
|
|
14509
14790
|
}), renderChildren()]
|
|
@@ -14549,6 +14830,11 @@ const PdfFormContent = _ref2 => {
|
|
|
14549
14830
|
}), /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
14550
14831
|
className: "pdf-tree",
|
|
14551
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
|
+
}
|
|
14552
14838
|
return !(sectionKey === 'id' || sectionKey === 'label' || sectionKey === 'position' || sectionKey === 'subTitle');
|
|
14553
14839
|
}).sort((a, b) => {
|
|
14554
14840
|
var _form$a, _form$b;
|
|
@@ -14595,10 +14881,92 @@ const PdfForm = _ref3 => {
|
|
|
14595
14881
|
getAppHeader = () => {},
|
|
14596
14882
|
app
|
|
14597
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]);
|
|
14598
14966
|
const pdfConfig = React.useMemo(() => {
|
|
14599
14967
|
const sections = [];
|
|
14600
|
-
Object.keys(
|
|
14601
|
-
const section =
|
|
14968
|
+
Object.keys(organizedForm).forEach(sectionKey => {
|
|
14969
|
+
const section = organizedForm[sectionKey];
|
|
14602
14970
|
if (typeof section !== 'object' || !section.label) {
|
|
14603
14971
|
return;
|
|
14604
14972
|
}
|
|
@@ -14627,7 +14995,7 @@ const PdfForm = _ref3 => {
|
|
|
14627
14995
|
});
|
|
14628
14996
|
});
|
|
14629
14997
|
return sections;
|
|
14630
|
-
}, [
|
|
14998
|
+
}, [organizedForm, data, t, getApiBaseUrl, getAppHeader, app, formName, source, version]);
|
|
14631
14999
|
return /*#__PURE__*/jsxRuntime.jsx(PdfView, {
|
|
14632
15000
|
config: pdfConfig,
|
|
14633
15001
|
customClassName: "pdf-form ".concat(customClassName),
|
|
@@ -14839,7 +15207,7 @@ Widget.propTypes = {
|
|
|
14839
15207
|
onExpandChange: PropTypes__default["default"].func
|
|
14840
15208
|
};
|
|
14841
15209
|
|
|
14842
|
-
const _excluded$
|
|
15210
|
+
const _excluded$f = ["loading", "title", "image", "description", "imgAlt", "noDescriptionText"];
|
|
14843
15211
|
function ImageWidget(_ref) {
|
|
14844
15212
|
let {
|
|
14845
15213
|
loading = false,
|
|
@@ -14849,7 +15217,7 @@ function ImageWidget(_ref) {
|
|
|
14849
15217
|
imgAlt,
|
|
14850
15218
|
noDescriptionText
|
|
14851
15219
|
} = _ref,
|
|
14852
|
-
props = _objectWithoutProperties(_ref, _excluded$
|
|
15220
|
+
props = _objectWithoutProperties(_ref, _excluded$f);
|
|
14853
15221
|
return /*#__PURE__*/jsxRuntime.jsx(Widget, _objectSpread2(_objectSpread2({
|
|
14854
15222
|
loading: loading,
|
|
14855
15223
|
title: title,
|
|
@@ -14906,7 +15274,7 @@ function ImageWidget(_ref) {
|
|
|
14906
15274
|
}
|
|
14907
15275
|
|
|
14908
15276
|
var _templateObject$9;
|
|
14909
|
-
const _excluded$
|
|
15277
|
+
const _excluded$e = ["title", "loading", "data", "current", "defaultActiveTab", "widgetClassname", "className", "direction"];
|
|
14910
15278
|
function FlowWidget(_ref) {
|
|
14911
15279
|
let {
|
|
14912
15280
|
title,
|
|
@@ -14918,7 +15286,7 @@ function FlowWidget(_ref) {
|
|
|
14918
15286
|
className,
|
|
14919
15287
|
direction = "horizontal"
|
|
14920
15288
|
} = _ref,
|
|
14921
|
-
rest = _objectWithoutProperties(_ref, _excluded$
|
|
15289
|
+
rest = _objectWithoutProperties(_ref, _excluded$e);
|
|
14922
15290
|
const [activeTab, setActiveTab] = React.useState();
|
|
14923
15291
|
React.useEffect(() => {
|
|
14924
15292
|
if (defaultActiveTab) {
|
|
@@ -19500,14 +19868,14 @@ const MapConfig = ({
|
|
|
19500
19868
|
});
|
|
19501
19869
|
};
|
|
19502
19870
|
|
|
19503
|
-
const _excluded$
|
|
19871
|
+
const _excluded$d = ["config", "title", "loading"];
|
|
19504
19872
|
const Details = _ref => {
|
|
19505
19873
|
let {
|
|
19506
19874
|
config = [],
|
|
19507
19875
|
title,
|
|
19508
19876
|
loading = false
|
|
19509
19877
|
} = _ref,
|
|
19510
|
-
rest = _objectWithoutProperties(_ref, _excluded$
|
|
19878
|
+
rest = _objectWithoutProperties(_ref, _excluded$d);
|
|
19511
19879
|
return /*#__PURE__*/jsxRuntime.jsx(Widget, _objectSpread2(_objectSpread2({
|
|
19512
19880
|
className: "with-border-header h-w-btn-header card",
|
|
19513
19881
|
loading: loading,
|
|
@@ -19523,14 +19891,14 @@ const Details = _ref => {
|
|
|
19523
19891
|
}));
|
|
19524
19892
|
};
|
|
19525
19893
|
|
|
19526
|
-
const _excluded$
|
|
19894
|
+
const _excluded$c = ["config", "title", "loading"];
|
|
19527
19895
|
const KeyIndicatorsDetails = _ref => {
|
|
19528
19896
|
let {
|
|
19529
19897
|
config,
|
|
19530
19898
|
title,
|
|
19531
19899
|
loading = false
|
|
19532
19900
|
} = _ref,
|
|
19533
|
-
rest = _objectWithoutProperties(_ref, _excluded$
|
|
19901
|
+
rest = _objectWithoutProperties(_ref, _excluded$c);
|
|
19534
19902
|
return /*#__PURE__*/jsxRuntime.jsx(Widget, _objectSpread2(_objectSpread2({
|
|
19535
19903
|
className: "with-border-header h-w-btn-header",
|
|
19536
19904
|
title: title,
|
|
@@ -19560,7 +19928,7 @@ const Style$x = dt.div`
|
|
|
19560
19928
|
}
|
|
19561
19929
|
`;
|
|
19562
19930
|
|
|
19563
|
-
const _excluded$
|
|
19931
|
+
const _excluded$b = ["children", "config", "detailsTitle", "firstColumnWidth"];
|
|
19564
19932
|
const DetailsSection = _ref => {
|
|
19565
19933
|
let {
|
|
19566
19934
|
children,
|
|
@@ -19568,7 +19936,7 @@ const DetailsSection = _ref => {
|
|
|
19568
19936
|
detailsTitle,
|
|
19569
19937
|
firstColumnWidth = "250px"
|
|
19570
19938
|
} = _ref,
|
|
19571
|
-
rest = _objectWithoutProperties(_ref, _excluded$
|
|
19939
|
+
rest = _objectWithoutProperties(_ref, _excluded$b);
|
|
19572
19940
|
return /*#__PURE__*/jsxRuntime.jsx(Style$x, {
|
|
19573
19941
|
firstColumnWidth: firstColumnWidth,
|
|
19574
19942
|
children: /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
@@ -20205,12 +20573,12 @@ function showHideForm(form, formsValue) {
|
|
|
20205
20573
|
if (!formsValue) {
|
|
20206
20574
|
return false;
|
|
20207
20575
|
} else {
|
|
20208
|
-
const value = deepFind(formsValue, field);
|
|
20576
|
+
const value = deepFind$1(formsValue, field);
|
|
20209
20577
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formsValue : value);
|
|
20210
20578
|
return isShown;
|
|
20211
20579
|
}
|
|
20212
20580
|
} else {
|
|
20213
|
-
const value = deepFind(formsValue, field);
|
|
20581
|
+
const value = deepFind$1(formsValue, field);
|
|
20214
20582
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formsValue : value);
|
|
20215
20583
|
return isShown;
|
|
20216
20584
|
}
|
|
@@ -20442,20 +20810,20 @@ const checkCondition$3 = (condition, formsValue, repeatValues, input) => {
|
|
|
20442
20810
|
field = isRepeatable ? field.split('./')[1] : field;
|
|
20443
20811
|
if (match && field.split('.').length > 1) {
|
|
20444
20812
|
if (input.inputs) {
|
|
20445
|
-
const value = deepFind(formValue, field);
|
|
20813
|
+
const value = deepFind$1(formValue, field);
|
|
20446
20814
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
20447
20815
|
return isShown;
|
|
20448
20816
|
} else {
|
|
20449
20817
|
if (isRepeatable ? !repeatValues : !formsValue) {
|
|
20450
20818
|
return false;
|
|
20451
20819
|
} else {
|
|
20452
|
-
const value = deepFind(formValue, field);
|
|
20820
|
+
const value = deepFind$1(formValue, field);
|
|
20453
20821
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
20454
20822
|
return isShown;
|
|
20455
20823
|
}
|
|
20456
20824
|
}
|
|
20457
20825
|
} else {
|
|
20458
|
-
const value = deepFind(formValue, field);
|
|
20826
|
+
const value = deepFind$1(formValue, field);
|
|
20459
20827
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
20460
20828
|
return isShown;
|
|
20461
20829
|
}
|
|
@@ -24892,7 +25260,7 @@ const RepeatableModals = ({
|
|
|
24892
25260
|
}) : null;
|
|
24893
25261
|
};
|
|
24894
25262
|
|
|
24895
|
-
const _excluded$
|
|
25263
|
+
const _excluded$a = ["viewGroup"],
|
|
24896
25264
|
_excluded2 = ["label", "icon", "position"];
|
|
24897
25265
|
const Content = _ref => {
|
|
24898
25266
|
let {
|
|
@@ -24960,7 +25328,7 @@ const Content = _ref => {
|
|
|
24960
25328
|
if (groups[gKey].viewGroup === key) {
|
|
24961
25329
|
// eslint-disable-next-line no-unused-vars
|
|
24962
25330
|
const _groups$gKey = groups[gKey],
|
|
24963
|
-
gCfg = _objectWithoutProperties(_groups$gKey, _excluded$
|
|
25331
|
+
gCfg = _objectWithoutProperties(_groups$gKey, _excluded$a);
|
|
24964
25332
|
items[gKey] = gCfg;
|
|
24965
25333
|
}
|
|
24966
25334
|
return items;
|
|
@@ -26037,20 +26405,20 @@ const checkCondition$2 = (condition, formsValue, repeatValues, input) => {
|
|
|
26037
26405
|
field = isRepeatable ? field.split('./')[1] : field;
|
|
26038
26406
|
if (match && field.split('.').length > 1) {
|
|
26039
26407
|
if (input.inputs) {
|
|
26040
|
-
const value = deepFind(formValue, field);
|
|
26408
|
+
const value = deepFind$1(formValue, field);
|
|
26041
26409
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
26042
26410
|
return isShown;
|
|
26043
26411
|
} else {
|
|
26044
26412
|
if (isRepeatable ? !repeatValues : !formsValue) {
|
|
26045
26413
|
return false;
|
|
26046
26414
|
} else {
|
|
26047
|
-
const value = deepFind(formValue, field);
|
|
26415
|
+
const value = deepFind$1(formValue, field);
|
|
26048
26416
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
26049
26417
|
return isShown;
|
|
26050
26418
|
}
|
|
26051
26419
|
}
|
|
26052
26420
|
} else {
|
|
26053
|
-
const value = deepFind(formValue, field);
|
|
26421
|
+
const value = deepFind$1(formValue, field);
|
|
26054
26422
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
26055
26423
|
return isShown;
|
|
26056
26424
|
}
|
|
@@ -31225,16 +31593,6 @@ function AjaxSubGroup({
|
|
|
31225
31593
|
t
|
|
31226
31594
|
} = useEditContext();
|
|
31227
31595
|
const isAjaxModal = React.useMemo(() => !!form?.meta?.namespace, [form]);
|
|
31228
|
-
console.log({
|
|
31229
|
-
form,
|
|
31230
|
-
options,
|
|
31231
|
-
k,
|
|
31232
|
-
excludedKeys,
|
|
31233
|
-
values,
|
|
31234
|
-
i,
|
|
31235
|
-
formTitles,
|
|
31236
|
-
data
|
|
31237
|
-
});
|
|
31238
31596
|
const formScope = React.useMemo(() => {
|
|
31239
31597
|
const val = form.meta.formScope;
|
|
31240
31598
|
let toReturn = val;
|
|
@@ -35084,7 +35442,7 @@ const checkCondition$1 = (condition, repeatValues, formsValue) => {
|
|
|
35084
35442
|
const isNotEmpty = match === 'notEmpty';
|
|
35085
35443
|
const formValue = isRepeatable ? repeatValues : formsValue;
|
|
35086
35444
|
field = isRepeatable ? field.split('./')[1] : field;
|
|
35087
|
-
const value = deepFind(formValue, field);
|
|
35445
|
+
const value = deepFind$1(formValue, field);
|
|
35088
35446
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
35089
35447
|
return isShown;
|
|
35090
35448
|
};
|
|
@@ -35269,20 +35627,20 @@ function showHideInput$1(input, data, repeatIndex, repeatValues, inputMeta) {
|
|
|
35269
35627
|
field = isRepeatable ? field.split('./')[1] : field;
|
|
35270
35628
|
if (match && field.split('.').length > 1) {
|
|
35271
35629
|
if (input.inputs) {
|
|
35272
|
-
const value = deepFind(formValue, field);
|
|
35630
|
+
const value = deepFind$1(formValue, field);
|
|
35273
35631
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
35274
35632
|
return isShown;
|
|
35275
35633
|
} else {
|
|
35276
35634
|
if (isRepeatable ? !repeatValues : !formsValue) {
|
|
35277
35635
|
return false;
|
|
35278
35636
|
} else {
|
|
35279
|
-
const value = deepFind(formValue, field);
|
|
35637
|
+
const value = deepFind$1(formValue, field);
|
|
35280
35638
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
35281
35639
|
return isShown;
|
|
35282
35640
|
}
|
|
35283
35641
|
}
|
|
35284
35642
|
} else {
|
|
35285
|
-
const value = deepFind(formValue, field);
|
|
35643
|
+
const value = deepFind$1(formValue, field);
|
|
35286
35644
|
if (match === 'gte') {
|
|
35287
35645
|
return Number(formValue[field]) >= Number(wantedValue);
|
|
35288
35646
|
}
|
|
@@ -35428,14 +35786,14 @@ function getSubtitles$1(subtitles, position, formsValue = {}, repeatIndex, repea
|
|
|
35428
35786
|
const formValue = isRepeatable ? repeatValues : formsValue;
|
|
35429
35787
|
field = isRepeatable ? field.split('./')[1] : field;
|
|
35430
35788
|
if (match && field.split('.').length > 1) {
|
|
35431
|
-
const value = deepFind(formValue, field);
|
|
35789
|
+
const value = deepFind$1(formValue, field);
|
|
35432
35790
|
const isValid = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
35433
35791
|
if (isValid) {
|
|
35434
35792
|
newSubtitle = subtitle[subKey];
|
|
35435
35793
|
ind = subKeys.length;
|
|
35436
35794
|
}
|
|
35437
35795
|
} else {
|
|
35438
|
-
const value = deepFind(formValue, field);
|
|
35796
|
+
const value = deepFind$1(formValue, field);
|
|
35439
35797
|
const isValid = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
35440
35798
|
if (isValid) {
|
|
35441
35799
|
newSubtitle = subtitle[subKey];
|
|
@@ -38736,7 +39094,7 @@ const checkCondition = (condition, repeatValues, formsValue) => {
|
|
|
38736
39094
|
const isNotEmpty = match === 'notEmpty';
|
|
38737
39095
|
const formValue = isRepeatable ? repeatValues : formsValue;
|
|
38738
39096
|
field = isRepeatable ? field.split('./')[1] : field;
|
|
38739
|
-
const value = deepFind(formValue, field);
|
|
39097
|
+
const value = deepFind$1(formValue, field);
|
|
38740
39098
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
38741
39099
|
return isShown;
|
|
38742
39100
|
};
|
|
@@ -38753,14 +39111,14 @@ function showHideInput(input, formsValue, repeatIndex, repeatValues, setValues,
|
|
|
38753
39111
|
field = isRepeatable ? field.split('./')[1] : field;
|
|
38754
39112
|
if (match && field.split('.').length > 1) {
|
|
38755
39113
|
if (input.inputs) {
|
|
38756
|
-
const value = deepFind(formValue, field);
|
|
39114
|
+
const value = deepFind$1(formValue, field);
|
|
38757
39115
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
38758
39116
|
return isShown;
|
|
38759
39117
|
} else {
|
|
38760
39118
|
if (isRepeatable ? !repeatValues : !formsValue) {
|
|
38761
39119
|
return false;
|
|
38762
39120
|
} else {
|
|
38763
|
-
const value = deepFind(formValue, field);
|
|
39121
|
+
const value = deepFind$1(formValue, field);
|
|
38764
39122
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
38765
39123
|
return isShown;
|
|
38766
39124
|
}
|
|
@@ -38778,7 +39136,7 @@ function showHideInput(input, formsValue, repeatIndex, repeatValues, setValues,
|
|
|
38778
39136
|
if (match === 'lt') {
|
|
38779
39137
|
return Number(formValue[field]) < Number(wantedValue);
|
|
38780
39138
|
}
|
|
38781
|
-
const value = deepFind(formValue, field);
|
|
39139
|
+
const value = deepFind$1(formValue, field);
|
|
38782
39140
|
const isShown = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
38783
39141
|
return isShown;
|
|
38784
39142
|
}
|
|
@@ -38929,14 +39287,14 @@ function getSubtitles(subtitles, position, formsValue = {}, repeatIndex, repeatV
|
|
|
38929
39287
|
const formValue = isRepeatable ? repeatValues : formsValue;
|
|
38930
39288
|
field = isRepeatable ? field.split('./')[1] : field;
|
|
38931
39289
|
if (match && field.split('.').length > 1) {
|
|
38932
|
-
const value = deepFind(formValue, field);
|
|
39290
|
+
const value = deepFind$1(formValue, field);
|
|
38933
39291
|
const isValid = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
38934
39292
|
if (isValid) {
|
|
38935
39293
|
newSubtitle = subtitle[subKey];
|
|
38936
39294
|
ind = subKeys.length;
|
|
38937
39295
|
}
|
|
38938
39296
|
} else {
|
|
38939
|
-
const value = deepFind(formValue, field);
|
|
39297
|
+
const value = deepFind$1(formValue, field);
|
|
38940
39298
|
const isValid = _checkValue(isNotEmpty ? field : wantedValue, match, isNotEmpty ? formValue : value);
|
|
38941
39299
|
if (isValid) {
|
|
38942
39300
|
newSubtitle = subtitle[subKey];
|
|
@@ -41075,7 +41433,7 @@ const getGrouContent = (form, values, i, formId, excludedKeys, getData, setValue
|
|
|
41075
41433
|
});
|
|
41076
41434
|
};
|
|
41077
41435
|
|
|
41078
|
-
const _excluded$
|
|
41436
|
+
const _excluded$9 = ["icon"];
|
|
41079
41437
|
function DynamicForm(_ref) {
|
|
41080
41438
|
var _data$meta;
|
|
41081
41439
|
let {
|
|
@@ -41630,7 +41988,7 @@ function DynamicForm(_ref) {
|
|
|
41630
41988
|
let {
|
|
41631
41989
|
icon: Icon
|
|
41632
41990
|
} = _ref3,
|
|
41633
|
-
form = _objectWithoutProperties(_ref3, _excluded$
|
|
41991
|
+
form = _objectWithoutProperties(_ref3, _excluded$9);
|
|
41634
41992
|
return /*#__PURE__*/jsxRuntime.jsxs(antd.Button, {
|
|
41635
41993
|
type: "link",
|
|
41636
41994
|
size: "large",
|
|
@@ -41936,68 +42294,6 @@ const SideIcon = _ref3 => {
|
|
|
41936
42294
|
});
|
|
41937
42295
|
};
|
|
41938
42296
|
|
|
41939
|
-
const _excluded$9 = ["value", "options", "onChange", "className", "width"];
|
|
41940
|
-
const ProgressTabs = _ref => {
|
|
41941
|
-
let {
|
|
41942
|
-
value = 'setup',
|
|
41943
|
-
options = [{
|
|
41944
|
-
label: 'Set Up',
|
|
41945
|
-
value: 'setup'
|
|
41946
|
-
}, {
|
|
41947
|
-
label: 'Project Scan',
|
|
41948
|
-
value: 'scan'
|
|
41949
|
-
}, {
|
|
41950
|
-
label: 'Review & Submission',
|
|
41951
|
-
value: 'review'
|
|
41952
|
-
}, {
|
|
41953
|
-
label: 'Submission Status',
|
|
41954
|
-
value: 'status'
|
|
41955
|
-
}],
|
|
41956
|
-
onChange = () => {},
|
|
41957
|
-
className = '',
|
|
41958
|
-
width = '100%'
|
|
41959
|
-
} = _ref,
|
|
41960
|
-
rest = _objectWithoutProperties(_ref, _excluded$9);
|
|
41961
|
-
// Transform options to include icons and handle disabled state
|
|
41962
|
-
const transformedOptions = options.map(option => _objectSpread2(_objectSpread2({}, option), {}, {
|
|
41963
|
-
label: /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
41964
|
-
className: "progress-tabs__option-content",
|
|
41965
|
-
children: [/*#__PURE__*/jsxRuntime.jsx("span", {
|
|
41966
|
-
className: "progress-tabs__label",
|
|
41967
|
-
children: option.label
|
|
41968
|
-
}), option.icon && /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
41969
|
-
className: "progress-tabs__icon",
|
|
41970
|
-
children: option.icon
|
|
41971
|
-
})]
|
|
41972
|
-
}),
|
|
41973
|
-
disabled: option.isDisabled || false
|
|
41974
|
-
}));
|
|
41975
|
-
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
41976
|
-
className: "progress-tabs ".concat(className),
|
|
41977
|
-
style: {
|
|
41978
|
-
width
|
|
41979
|
-
},
|
|
41980
|
-
children: /*#__PURE__*/jsxRuntime.jsx(antd.Segmented, _objectSpread2({
|
|
41981
|
-
value: value,
|
|
41982
|
-
options: transformedOptions,
|
|
41983
|
-
onChange: onChange,
|
|
41984
|
-
className: "progress-tabs__segmented"
|
|
41985
|
-
}, rest))
|
|
41986
|
-
});
|
|
41987
|
-
};
|
|
41988
|
-
ProgressTabs.propTypes = {
|
|
41989
|
-
value: PropTypes__default["default"].string,
|
|
41990
|
-
options: PropTypes__default["default"].arrayOf(PropTypes__default["default"].shape({
|
|
41991
|
-
label: PropTypes__default["default"].string.isRequired,
|
|
41992
|
-
value: PropTypes__default["default"].string.isRequired,
|
|
41993
|
-
isDisabled: PropTypes__default["default"].bool,
|
|
41994
|
-
icon: PropTypes__default["default"].node
|
|
41995
|
-
})),
|
|
41996
|
-
onChange: PropTypes__default["default"].func,
|
|
41997
|
-
className: PropTypes__default["default"].string,
|
|
41998
|
-
width: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].number])
|
|
41999
|
-
};
|
|
42000
|
-
|
|
42001
42297
|
const defaultData = {
|
|
42002
42298
|
overview: {
|
|
42003
42299
|
consolidated: {
|
|
@@ -54353,6 +54649,2204 @@ function AIQuery() {
|
|
|
54353
54649
|
return /*#__PURE__*/jsxRuntime.jsx("div", {});
|
|
54354
54650
|
}
|
|
54355
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
|
+
|
|
54356
56850
|
const selectFiltersConfig$6 = {
|
|
54357
56851
|
category: {
|
|
54358
56852
|
type: 'select',
|
|
@@ -54894,7 +57388,7 @@ function Entities({
|
|
|
54894
57388
|
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
54895
57389
|
className: "flex flex-column flex-1",
|
|
54896
57390
|
children: [/*#__PURE__*/jsxRuntime.jsx(SelectFilters, {
|
|
54897
|
-
language:
|
|
57391
|
+
language: instance.language,
|
|
54898
57392
|
t: t,
|
|
54899
57393
|
options: selectOptions,
|
|
54900
57394
|
filtersConfig: selectFiltersConfig$6,
|
|
@@ -55986,7 +58480,7 @@ function Locations({
|
|
|
55986
58480
|
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
55987
58481
|
className: "flex flex-column flex-1",
|
|
55988
58482
|
children: [/*#__PURE__*/jsxRuntime.jsx(SelectFilters, {
|
|
55989
|
-
language:
|
|
58483
|
+
language: instance.language,
|
|
55990
58484
|
t: t,
|
|
55991
58485
|
options: selectOptions,
|
|
55992
58486
|
filtersConfig: selectFiltersConfig$5,
|
|
@@ -59132,7 +61626,6 @@ exports.PieChart = Chart;
|
|
|
59132
61626
|
exports.PieChartTooltip = Tooltip;
|
|
59133
61627
|
exports.ProgressBar = ProgressBar;
|
|
59134
61628
|
exports.ProgressBarSideIcon = SideIcon;
|
|
59135
|
-
exports.ProgressTabs = ProgressTabs;
|
|
59136
61629
|
exports.ProjectVisualisationAlert = Alert;
|
|
59137
61630
|
exports.ProjectVisualisationFooter = Footer;
|
|
59138
61631
|
exports.ProjectVisualisationHeader = Header;
|