@formio/js 5.1.0-dev.6109.79f22ad → 5.1.0-dev.6112.06b0f26
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/README.md +7 -0
- package/dist/formio.builder.css +1 -0
- package/dist/formio.builder.min.css +1 -1
- package/dist/formio.form.css +1 -0
- package/dist/formio.form.js +116 -149
- package/dist/formio.form.min.css +1 -1
- package/dist/formio.form.min.js +1 -1
- package/dist/formio.full.css +1 -0
- package/dist/formio.full.js +123 -156
- package/dist/formio.full.min.css +1 -1
- package/dist/formio.full.min.js +1 -1
- package/dist/formio.js +65 -54
- package/dist/formio.min.js +1 -1
- package/dist/formio.utils.js +76 -76
- package/dist/formio.utils.min.js +1 -1
- package/lib/cjs/Element.d.ts +2 -1
- package/lib/cjs/Element.js +18 -39
- package/lib/cjs/EventEmitter.js +2 -25
- package/lib/cjs/Form.js +2 -25
- package/lib/cjs/PDF.js +1 -1
- package/lib/cjs/PDFBuilder.d.ts +1 -0
- package/lib/cjs/PDFBuilder.js +10 -11
- package/lib/cjs/Webform.d.ts +2 -2
- package/lib/cjs/Webform.js +9 -9
- package/lib/cjs/WebformBuilder.d.ts +1 -1
- package/lib/cjs/WebformBuilder.js +45 -21
- package/lib/cjs/Wizard.d.ts +1 -2
- package/lib/cjs/Wizard.js +18 -24
- package/lib/cjs/WizardBuilder.js +1 -1
- package/lib/cjs/components/_classes/component/Component.d.ts +0 -1
- package/lib/cjs/components/_classes/component/Component.js +55 -62
- package/lib/cjs/components/_classes/component/editForm/Component.edit.conditional.js +1 -1
- package/lib/cjs/components/_classes/component/editForm/Component.edit.logic.js +1 -1
- package/lib/cjs/components/_classes/componentModal/ComponentModal.js +1 -1
- package/lib/cjs/components/_classes/input/Input.d.ts +1 -1
- package/lib/cjs/components/_classes/input/Input.js +3 -3
- package/lib/cjs/components/_classes/list/ListComponent.js +1 -1
- package/lib/cjs/components/_classes/nested/NestedComponent.js +7 -7
- package/lib/cjs/components/_classes/nestedarray/NestedArrayComponent.js +1 -1
- package/lib/cjs/components/_classes/nesteddata/NestedDataComponent.js +1 -1
- package/lib/cjs/components/address/Address.js +1 -1
- package/lib/cjs/components/alert/Alert.js +1 -1
- package/lib/cjs/components/button/Button.js +1 -1
- package/lib/cjs/components/checkbox/Checkbox.js +1 -1
- package/lib/cjs/components/container/Container.js +1 -1
- package/lib/cjs/components/currency/Currency.js +1 -1
- package/lib/cjs/components/datagrid/DataGrid.js +1 -1
- package/lib/cjs/components/datamap/DataMap.js +7 -2
- package/lib/cjs/components/datetime/DateTime.d.ts +1 -1
- package/lib/cjs/components/datetime/DateTime.js +15 -13
- package/lib/cjs/components/day/Day.js +2 -2
- package/lib/cjs/components/editgrid/EditGrid.js +1 -1
- package/lib/cjs/components/editgrid/editForm/EditGrid.edit.display.js +1 -1
- package/lib/cjs/components/fieldset/Fieldset.js +1 -0
- package/lib/cjs/components/file/File.js +1 -1
- package/lib/cjs/components/form/Form.js +14 -2
- package/lib/cjs/components/form/editForm/Form.edit.form.js +4 -3
- package/lib/cjs/components/number/Number.js +1 -1
- package/lib/cjs/components/panel/Panel.js +1 -1
- package/lib/cjs/components/radio/Radio.d.ts +8 -0
- package/lib/cjs/components/radio/Radio.js +16 -6
- package/lib/cjs/components/recaptcha/editForm/ReCaptcha.edit.display.js +1 -1
- package/lib/cjs/components/select/Select.js +7 -3
- package/lib/cjs/components/select/editForm/Select.edit.data.js +1 -1
- package/lib/cjs/components/selectboxes/SelectBoxes.d.ts +6 -0
- package/lib/cjs/components/selectboxes/SelectBoxes.js +1 -1
- package/lib/cjs/components/signature/Signature.js +1 -1
- package/lib/cjs/components/survey/Survey.js +1 -1
- package/lib/cjs/components/tags/Tags.js +1 -1
- package/lib/cjs/components/textarea/TextArea.js +9 -4
- package/lib/cjs/components/textfield/TextField.js +13 -31
- package/lib/cjs/components/time/Time.js +1 -1
- package/lib/cjs/formio.form.js +5 -5
- package/lib/cjs/providers/storage/uploadAdapter.js +1 -1
- package/lib/cjs/translations/en.d.ts +1 -232
- package/lib/cjs/translations/en.js +4 -2
- package/lib/cjs/utils/Evaluator.d.ts +20 -6
- package/lib/cjs/utils/Evaluator.js +38 -15
- package/lib/cjs/utils/builder.js +5 -5
- package/lib/cjs/utils/conditionOperators/IsEqualTo.js +3 -3
- package/lib/cjs/utils/formUtils.d.ts +2 -2
- package/lib/cjs/utils/index.d.ts +169 -2
- package/lib/cjs/utils/index.js +22 -2
- package/lib/cjs/utils/utils.d.ts +22 -37
- package/lib/cjs/utils/utils.js +64 -135
- package/lib/cjs/widgets/CalendarWidget.d.ts +1 -8
- package/lib/cjs/widgets/CalendarWidget.js +17 -43
- package/lib/mjs/Element.d.ts +2 -1
- package/lib/mjs/Element.js +11 -9
- package/lib/mjs/EventEmitter.js +2 -2
- package/lib/mjs/Form.js +1 -1
- package/lib/mjs/PDF.js +1 -1
- package/lib/mjs/PDFBuilder.d.ts +1 -0
- package/lib/mjs/PDFBuilder.js +9 -10
- package/lib/mjs/Webform.d.ts +2 -2
- package/lib/mjs/Webform.js +7 -7
- package/lib/mjs/WebformBuilder.d.ts +1 -1
- package/lib/mjs/WebformBuilder.js +36 -13
- package/lib/mjs/Wizard.d.ts +1 -2
- package/lib/mjs/Wizard.js +17 -23
- package/lib/mjs/WizardBuilder.js +1 -1
- package/lib/mjs/components/_classes/component/Component.d.ts +0 -1
- package/lib/mjs/components/_classes/component/Component.js +28 -12
- package/lib/mjs/components/_classes/component/editForm/Component.edit.conditional.js +1 -1
- package/lib/mjs/components/_classes/component/editForm/Component.edit.logic.js +1 -1
- package/lib/mjs/components/_classes/componentModal/ComponentModal.js +1 -1
- package/lib/mjs/components/_classes/input/Input.d.ts +1 -1
- package/lib/mjs/components/_classes/input/Input.js +3 -3
- package/lib/mjs/components/_classes/list/ListComponent.js +1 -1
- package/lib/mjs/components/_classes/nested/NestedComponent.js +7 -7
- package/lib/mjs/components/_classes/nestedarray/NestedArrayComponent.js +1 -1
- package/lib/mjs/components/_classes/nesteddata/NestedDataComponent.js +1 -1
- package/lib/mjs/components/address/Address.js +1 -1
- package/lib/mjs/components/alert/Alert.js +1 -1
- package/lib/mjs/components/button/Button.js +1 -1
- package/lib/mjs/components/checkbox/Checkbox.js +1 -1
- package/lib/mjs/components/container/Container.js +1 -1
- package/lib/mjs/components/currency/Currency.js +1 -1
- package/lib/mjs/components/datagrid/DataGrid.js +1 -1
- package/lib/mjs/components/datamap/DataMap.js +7 -2
- package/lib/mjs/components/datetime/DateTime.d.ts +1 -1
- package/lib/mjs/components/datetime/DateTime.js +15 -13
- package/lib/mjs/components/day/Day.js +2 -2
- package/lib/mjs/components/editgrid/EditGrid.js +1 -1
- package/lib/mjs/components/editgrid/editForm/EditGrid.edit.display.js +1 -1
- package/lib/mjs/components/fieldset/Fieldset.js +1 -0
- package/lib/mjs/components/file/File.js +1 -1
- package/lib/mjs/components/form/Form.js +13 -2
- package/lib/mjs/components/form/editForm/Form.edit.form.js +3 -2
- package/lib/mjs/components/number/Number.js +1 -1
- package/lib/mjs/components/panel/Panel.js +1 -1
- package/lib/mjs/components/radio/Radio.d.ts +8 -0
- package/lib/mjs/components/radio/Radio.js +16 -6
- package/lib/mjs/components/recaptcha/editForm/ReCaptcha.edit.display.js +1 -1
- package/lib/mjs/components/select/Select.js +7 -3
- package/lib/mjs/components/select/editForm/Select.edit.data.js +1 -1
- package/lib/mjs/components/selectboxes/SelectBoxes.d.ts +6 -0
- package/lib/mjs/components/selectboxes/SelectBoxes.js +1 -1
- package/lib/mjs/components/signature/Signature.js +1 -1
- package/lib/mjs/components/survey/Survey.js +1 -1
- package/lib/mjs/components/tags/Tags.js +1 -1
- package/lib/mjs/components/textarea/TextArea.js +9 -4
- package/lib/mjs/components/textfield/TextField.js +7 -2
- package/lib/mjs/components/time/Time.js +1 -1
- package/lib/mjs/formio.form.js +3 -3
- package/lib/mjs/providers/storage/uploadAdapter.js +1 -1
- package/lib/mjs/translations/en.d.ts +1 -232
- package/lib/mjs/translations/en.js +8 -47
- package/lib/mjs/utils/Evaluator.d.ts +20 -6
- package/lib/mjs/utils/Evaluator.js +31 -13
- package/lib/mjs/utils/builder.js +1 -1
- package/lib/mjs/utils/conditionOperators/IsEqualTo.js +1 -1
- package/lib/mjs/utils/formUtils.d.ts +2 -2
- package/lib/mjs/utils/index.d.ts +169 -2
- package/lib/mjs/utils/index.js +18 -1
- package/lib/mjs/utils/utils.d.ts +22 -37
- package/lib/mjs/utils/utils.js +57 -109
- package/lib/mjs/widgets/CalendarWidget.d.ts +1 -8
- package/lib/mjs/widgets/CalendarWidget.js +17 -43
- package/package.json +5 -3
- package/lib/cjs/i18n.d.ts +0 -13
- package/lib/cjs/i18n.js +0 -19
- package/lib/cjs/utils/i18n.d.ts +0 -19
- package/lib/cjs/utils/i18n.js +0 -120
- package/lib/mjs/i18n.d.ts +0 -13
- package/lib/mjs/i18n.js +0 -14
- package/lib/mjs/utils/i18n.d.ts +0 -19
- package/lib/mjs/utils/i18n.js +0 -112
@@ -22,13 +22,6 @@ export default class CalendarWidget extends InputWidget {
|
|
22
22
|
minDate: string;
|
23
23
|
maxDate: string;
|
24
24
|
};
|
25
|
-
zoneLoading: boolean;
|
26
|
-
timezonesUrl: string;
|
27
|
-
/**
|
28
|
-
* Load the timezones.
|
29
|
-
* @returns {boolean} TRUE if the zones are loading, FALSE otherwise.
|
30
|
-
*/
|
31
|
-
loadZones(): boolean;
|
32
25
|
attach(input: any): Promise<any>;
|
33
26
|
defaultFormat: {
|
34
27
|
date: string;
|
@@ -84,7 +77,7 @@ export default class CalendarWidget extends InputWidget {
|
|
84
77
|
* @returns {void}
|
85
78
|
*/
|
86
79
|
setValue(value: any): void;
|
87
|
-
getValueAsString(value: any, format
|
80
|
+
getValueAsString(value: any, format?: string): string;
|
88
81
|
setErrorClasses(hasErrors: any): void;
|
89
82
|
isCalendarElement(element: any): any;
|
90
83
|
initFlatpickr(Flatpickr: any): void;
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { Formio } from '../Formio';
|
2
|
-
import InputWidget from './InputWidget';
|
3
|
-
import { convertFormatToFlatpickr, convertFormatToMask, convertFormatToMoment, formatDate, formatOffset, getBrowserInfo, getDateSetting, getLocaleDateFormatInfo, momentDate, zonesLoaded, shouldLoadZones, loadZones, hasEncodedTimezone, } from '../utils/utils';
|
4
1
|
import moment from 'moment';
|
5
2
|
import _ from 'lodash';
|
3
|
+
import { Formio } from '../Formio';
|
4
|
+
import InputWidget from './InputWidget';
|
5
|
+
import { convertFormatToFlatpickr, convertFormatToMask, convertFormatToDayjs, formatDate, formatOffset, getBrowserInfo, getDateSetting, getLocaleDateFormatInfo, hasEncodedTimezone, dayjsDate } from '../utils';
|
6
6
|
const DEFAULT_FORMAT = 'yyyy-MM-dd hh:mm a';
|
7
7
|
const ISO_8601_FORMAT = 'yyyy-MM-ddTHH:mm:ssZ';
|
8
8
|
const isIEBrowser = getBrowserInfo().ie;
|
@@ -46,29 +46,6 @@ export default class CalendarWidget extends InputWidget {
|
|
46
46
|
else if (this.settings.time_24hr) {
|
47
47
|
this.settings.format = this.settings.format.replace(/hh:mm a$/g, 'HH:mm');
|
48
48
|
}
|
49
|
-
this.zoneLoading = false;
|
50
|
-
this.timezonesUrl = `${Formio.cdn['moment-timezone']}/data/packed/latest.json`;
|
51
|
-
}
|
52
|
-
/**
|
53
|
-
* Load the timezones.
|
54
|
-
* @returns {boolean} TRUE if the zones are loading, FALSE otherwise.
|
55
|
-
*/
|
56
|
-
loadZones() {
|
57
|
-
const timezone = this.timezone;
|
58
|
-
if (this.zoneLoading) {
|
59
|
-
return true;
|
60
|
-
}
|
61
|
-
if (!zonesLoaded() && shouldLoadZones(timezone)) {
|
62
|
-
this.zoneLoading = true;
|
63
|
-
loadZones(this.timezonesUrl, timezone).then(() => {
|
64
|
-
this.zoneLoading = false;
|
65
|
-
this.emit('redraw');
|
66
|
-
});
|
67
|
-
// Return zones are loading.
|
68
|
-
return true;
|
69
|
-
}
|
70
|
-
// Zones are already loaded.
|
71
|
-
return false;
|
72
49
|
}
|
73
50
|
attach(input) {
|
74
51
|
const superAttach = super.attach(input);
|
@@ -79,7 +56,7 @@ export default class CalendarWidget extends InputWidget {
|
|
79
56
|
};
|
80
57
|
this.closedOn = 0;
|
81
58
|
this.valueFormat = (this.settings.saveAs === 'date') ? ISO_8601_FORMAT : this.settings.dateFormat || ISO_8601_FORMAT;
|
82
|
-
this.valueMomentFormat =
|
59
|
+
this.valueMomentFormat = convertFormatToDayjs(this.valueFormat);
|
83
60
|
const isReadOnly = this.settings.readOnly;
|
84
61
|
this.settings.minDate = isReadOnly ? null : getDateSetting(this.settings.minDate);
|
85
62
|
this.settings.maxDate = isReadOnly ? null : getDateSetting(this.settings.maxDate);
|
@@ -241,9 +218,9 @@ export default class CalendarWidget extends InputWidget {
|
|
241
218
|
*/
|
242
219
|
getDateValue(date, format, useTimezone) {
|
243
220
|
if (useTimezone) {
|
244
|
-
return
|
221
|
+
return dayjsDate(date, this.valueFormat, this.timezone).format(convertFormatToDayjs(format));
|
245
222
|
}
|
246
|
-
return moment(date).format(
|
223
|
+
return moment(date).format(convertFormatToDayjs(format));
|
247
224
|
}
|
248
225
|
/**
|
249
226
|
* Return the value of the selected date.
|
@@ -275,18 +252,15 @@ export default class CalendarWidget extends InputWidget {
|
|
275
252
|
setValue(value) {
|
276
253
|
const saveAsText = (this.settings.saveAs === 'text');
|
277
254
|
if (!this.calendar) {
|
278
|
-
value = value ? formatDate(
|
255
|
+
value = value ? formatDate(value, convertFormatToDayjs(this.settings.format), this.timezone, convertFormatToDayjs(this.valueMomentFormat)) : value;
|
279
256
|
return super.setValue(value);
|
280
257
|
}
|
281
258
|
// If the component is a textfield that does not have timezone information included in the string value then skip
|
282
259
|
// the timezone offset
|
283
|
-
|
284
|
-
this.settings.skipOffset = true;
|
285
|
-
}
|
286
|
-
const zonesLoading = this.loadZones();
|
260
|
+
this.settings.skipOffset = this.component.type === 'textfield' && !hasEncodedTimezone(value);
|
287
261
|
if (value) {
|
288
|
-
if (!saveAsText && this.settings.readOnly
|
289
|
-
this.calendar.setDate(
|
262
|
+
if (!saveAsText && this.settings.readOnly) {
|
263
|
+
this.calendar.setDate(dayjsDate(value, this.valueFormat, this.timezone).format(), false);
|
290
264
|
}
|
291
265
|
else if (this.isValueISO8601(value)) {
|
292
266
|
this.calendar.setDate(value, false);
|
@@ -299,13 +273,13 @@ export default class CalendarWidget extends InputWidget {
|
|
299
273
|
this.calendar.clear(false);
|
300
274
|
}
|
301
275
|
}
|
302
|
-
getValueAsString(value, format) {
|
276
|
+
getValueAsString(value, format = '') {
|
303
277
|
const inputFormat = format || this.dateFormat;
|
304
278
|
const valueFormat = this.calendar ? this.valueFormat : this.settings.dateFormat;
|
305
279
|
if (this.settings.saveAs === 'text' && this.componentInstance.parent && !this.settings.readOnly) {
|
306
|
-
return moment(value,
|
280
|
+
return moment(value, convertFormatToDayjs(valueFormat)).format(convertFormatToDayjs(valueFormat));
|
307
281
|
}
|
308
|
-
return formatDate(
|
282
|
+
return formatDate(value, inputFormat, this.timezone, convertFormatToDayjs(valueFormat));
|
309
283
|
}
|
310
284
|
setErrorClasses(hasErrors) {
|
311
285
|
if (!this.input) {
|
@@ -396,7 +370,7 @@ export default class CalendarWidget extends InputWidget {
|
|
396
370
|
const relatedTarget = event.relatedTarget ? event.relatedTarget : activeElement;
|
397
371
|
if (!(isIEBrowser && !relatedTarget) && !this.isCalendarElement(relatedTarget)) {
|
398
372
|
const inputValue = this.calendar.input.value;
|
399
|
-
const dateValue = inputValue ? moment(this.calendar.input.value,
|
373
|
+
const dateValue = inputValue ? moment(this.calendar.input.value, convertFormatToDayjs(this.valueFormat)).toDate() : inputValue;
|
400
374
|
this.calendar.setDate(dateValue, true, this.settings.altFormat);
|
401
375
|
}
|
402
376
|
else if (!this.calendar.input.value && this.calendar.config.noCalendar) {
|
@@ -448,14 +422,14 @@ export default class CalendarWidget extends InputWidget {
|
|
448
422
|
return (date, format) => {
|
449
423
|
// Only format this if this is the altFormat and the form is readOnly.
|
450
424
|
if (this.settings.readOnly && (format === this.settings.altFormat)) {
|
451
|
-
if (!this.settings.enableTime || this.
|
425
|
+
if (!this.settings.enableTime || this.settings.skipOffset) {
|
452
426
|
return Flatpickr.formatDate(date, format);
|
453
427
|
}
|
454
428
|
const currentValue = new Date(this.getValue());
|
455
429
|
if (currentValue.toString() === date.toString()) {
|
456
|
-
return formatOffset(
|
430
|
+
return formatOffset(Flatpickr.formatDate.bind(Flatpickr), new Date(this.componentValue), format, this.timezone);
|
457
431
|
}
|
458
|
-
return formatOffset(
|
432
|
+
return formatOffset(Flatpickr.formatDate.bind(Flatpickr), date, format, this.timezone);
|
459
433
|
}
|
460
434
|
return Flatpickr.formatDate(date, format);
|
461
435
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@formio/js",
|
3
|
-
"version": "5.1.0-dev.
|
3
|
+
"version": "5.1.0-dev.6112.06b0f26",
|
4
4
|
"description": "JavaScript powered Forms with JSON Form Builder",
|
5
5
|
"main": "lib/cjs/index.js",
|
6
6
|
"exports": {
|
@@ -81,7 +81,7 @@
|
|
81
81
|
"homepage": "https://github.com/formio/formio.js#readme",
|
82
82
|
"dependencies": {
|
83
83
|
"@formio/bootstrap": "v3.0.0-dev.121.085d187",
|
84
|
-
"@formio/core": "
|
84
|
+
"@formio/core": "2.4.0-dev.267.2866472",
|
85
85
|
"@formio/text-mask-addons": "3.8.0-formio.4",
|
86
86
|
"@formio/vanilla-text-mask": "^5.1.1-formio.1",
|
87
87
|
"abortcontroller-polyfill": "^1.7.5",
|
@@ -92,6 +92,7 @@
|
|
92
92
|
"choices.js": "^11.0.6",
|
93
93
|
"compare-versions": "^6.1.1",
|
94
94
|
"core-js": "^3.37.1",
|
95
|
+
"dayjs": "^1.11.13",
|
95
96
|
"dialog-polyfill": "^0.5.6",
|
96
97
|
"dom-autoscroller": "^2.3.4",
|
97
98
|
"dompurify": "^3.2.5",
|
@@ -175,7 +176,8 @@
|
|
175
176
|
"webpack-bundle-analyzer": "^4.10.2",
|
176
177
|
"webpack-cli": "^5.1.1",
|
177
178
|
"webpack-node-externals": "^3.0.0",
|
178
|
-
"webpack-stream": "^7.0.0"
|
179
|
+
"webpack-stream": "^7.0.0",
|
180
|
+
"zx": "^8.5.4"
|
179
181
|
},
|
180
182
|
"nyc": {
|
181
183
|
"check-coverage": true,
|
package/lib/cjs/i18n.d.ts
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
declare namespace _default {
|
2
|
-
let lng: string;
|
3
|
-
let nsSeparator: string;
|
4
|
-
let keySeparator: string;
|
5
|
-
let pluralSeparator: string;
|
6
|
-
let contextSeparator: string;
|
7
|
-
namespace resources {
|
8
|
-
namespace en {
|
9
|
-
let translation: any;
|
10
|
-
}
|
11
|
-
}
|
12
|
-
}
|
13
|
-
export default _default;
|
package/lib/cjs/i18n.js
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
const en_1 = __importDefault(require("./translations/en"));
|
7
|
-
const utils_1 = require("./utils/utils");
|
8
|
-
exports.default = {
|
9
|
-
lng: 'en',
|
10
|
-
nsSeparator: '::',
|
11
|
-
keySeparator: '.|.',
|
12
|
-
pluralSeparator: '._.',
|
13
|
-
contextSeparator: '._.',
|
14
|
-
resources: {
|
15
|
-
en: {
|
16
|
-
translation: (0, utils_1.fastCloneDeep)(en_1.default)
|
17
|
-
}
|
18
|
-
}
|
19
|
-
};
|
package/lib/cjs/utils/i18n.d.ts
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* This file is used to mimic the i18n library interface.
|
3
|
-
*/
|
4
|
-
export class I18n {
|
5
|
-
static languages: {};
|
6
|
-
static setDefaultTranslations(languages: any): void;
|
7
|
-
static init(languages?: {}): I18n;
|
8
|
-
static createInstance(): I18n;
|
9
|
-
constructor(languages?: {});
|
10
|
-
languages: any;
|
11
|
-
defaultKeys: any;
|
12
|
-
language: string;
|
13
|
-
currentLanguage: any;
|
14
|
-
setLanguages(languages: any, noDefaultOverride: any): void;
|
15
|
-
dir(lang?: string): "rtl" | "ltr";
|
16
|
-
changeLanguage(language: any, ready?: null): void;
|
17
|
-
addResourceBundle(language: any, type: any, strings: any): void;
|
18
|
-
t(text: any, ...args: any[]): any;
|
19
|
-
}
|
package/lib/cjs/utils/i18n.js
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.I18n = void 0;
|
7
|
-
const utils_1 = require("@formio/core/utils");
|
8
|
-
const i18n_1 = __importDefault(require("../i18n"));
|
9
|
-
const lodash_1 = require("lodash");
|
10
|
-
const core_1 = require("@formio/core");
|
11
|
-
const i18Defaults = {};
|
12
|
-
for (const lang in i18n_1.default.resources) {
|
13
|
-
if (i18n_1.default.resources.hasOwnProperty(lang)) {
|
14
|
-
i18Defaults[lang] = i18n_1.default.resources[lang].translation;
|
15
|
-
}
|
16
|
-
}
|
17
|
-
/**
|
18
|
-
* This file is used to mimic the i18n library interface.
|
19
|
-
*/
|
20
|
-
class I18n {
|
21
|
-
constructor(languages = {}) {
|
22
|
-
var _a;
|
23
|
-
this.languages = (0, core_1.fastCloneDeep)(I18n.languages || {});
|
24
|
-
this.defaultKeys = ((_a = I18n.languages) === null || _a === void 0 ? void 0 : _a.en) || {};
|
25
|
-
this.language = 'en';
|
26
|
-
this.currentLanguage = i18Defaults.en;
|
27
|
-
this.setLanguages(languages);
|
28
|
-
this.changeLanguage(this.language);
|
29
|
-
}
|
30
|
-
static setDefaultTranslations(languages) {
|
31
|
-
if ((0, lodash_1.isEmpty)(languages)) {
|
32
|
-
return;
|
33
|
-
}
|
34
|
-
for (const lang in languages) {
|
35
|
-
if (lang !== 'language' && languages.hasOwnProperty(lang)) {
|
36
|
-
if (!this.languages[lang]) {
|
37
|
-
this.languages[lang] = {};
|
38
|
-
}
|
39
|
-
this.languages[lang] = Object.assign(Object.assign({}, languages[lang]), this.languages[lang]);
|
40
|
-
}
|
41
|
-
}
|
42
|
-
}
|
43
|
-
setLanguages(languages, noDefaultOverride) {
|
44
|
-
if (languages.resources) {
|
45
|
-
for (const lang in languages.resources) {
|
46
|
-
if (languages.resources.hasOwnProperty(lang)) {
|
47
|
-
languages[lang] = languages.resources[lang].translation;
|
48
|
-
}
|
49
|
-
}
|
50
|
-
delete languages.resources;
|
51
|
-
}
|
52
|
-
if (languages.lng) {
|
53
|
-
languages.language = languages.lng;
|
54
|
-
delete languages.lng;
|
55
|
-
}
|
56
|
-
// Do not use these configurations.
|
57
|
-
delete languages.nsSeparator;
|
58
|
-
delete languages.keySeparator;
|
59
|
-
delete languages.pluralSeparator;
|
60
|
-
delete languages.contextSeparator;
|
61
|
-
// Now establish the languages default.
|
62
|
-
if (languages.language) {
|
63
|
-
this.language = languages.language;
|
64
|
-
}
|
65
|
-
for (const lang in languages) {
|
66
|
-
if (lang !== 'language' && languages.hasOwnProperty(lang)) {
|
67
|
-
if (!this.languages[lang]) {
|
68
|
-
this.languages[lang] = {};
|
69
|
-
}
|
70
|
-
this.languages[lang] = noDefaultOverride
|
71
|
-
? Object.assign(Object.assign({}, languages[lang]), this.languages[lang]) : Object.assign(Object.assign({}, this.languages[lang]), languages[lang]);
|
72
|
-
}
|
73
|
-
}
|
74
|
-
}
|
75
|
-
static init(languages = {}) {
|
76
|
-
return new I18n(languages);
|
77
|
-
}
|
78
|
-
dir(lang = '') {
|
79
|
-
lang = lang || this.language;
|
80
|
-
const rtls = ['ar', 'he', 'fa', 'ps', 'ur'];
|
81
|
-
return rtls.includes(lang) ? 'rtl' : 'ltr';
|
82
|
-
}
|
83
|
-
static createInstance() {
|
84
|
-
return new I18n();
|
85
|
-
}
|
86
|
-
changeLanguage(language, ready = null) {
|
87
|
-
if (!this.languages[language]) {
|
88
|
-
language = 'en';
|
89
|
-
}
|
90
|
-
this.language = language;
|
91
|
-
this.currentLanguage = this.languages[language] ? this.languages[language] : {};
|
92
|
-
if (ready) {
|
93
|
-
ready();
|
94
|
-
}
|
95
|
-
}
|
96
|
-
addResourceBundle(language, type, strings) {
|
97
|
-
this.languages[language] = strings;
|
98
|
-
}
|
99
|
-
t(text, ...args) {
|
100
|
-
var _a;
|
101
|
-
let currentTranslation = this.currentLanguage[text];
|
102
|
-
// provide compatibility with cases where the entire phrase is used as a key
|
103
|
-
// get the phrase that is possibly being used as a key
|
104
|
-
const defaultKey = this.defaultKeys[text];
|
105
|
-
if (defaultKey && this.currentLanguage[defaultKey]) {
|
106
|
-
// get translation using the phrase as a key
|
107
|
-
currentTranslation = this.currentLanguage[defaultKey];
|
108
|
-
}
|
109
|
-
if (currentTranslation) {
|
110
|
-
const customTranslationFieldName = (_a = args[0]) === null || _a === void 0 ? void 0 : _a.field;
|
111
|
-
if (customTranslationFieldName && this.currentLanguage[customTranslationFieldName]) {
|
112
|
-
args[0].field = this.currentLanguage[customTranslationFieldName];
|
113
|
-
}
|
114
|
-
return utils_1.Evaluator.interpolateString(currentTranslation, ...args);
|
115
|
-
}
|
116
|
-
return utils_1.Evaluator.interpolateString(text, ...args);
|
117
|
-
}
|
118
|
-
}
|
119
|
-
exports.I18n = I18n;
|
120
|
-
I18n.languages = i18Defaults;
|
package/lib/mjs/i18n.d.ts
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
declare namespace _default {
|
2
|
-
let lng: string;
|
3
|
-
let nsSeparator: string;
|
4
|
-
let keySeparator: string;
|
5
|
-
let pluralSeparator: string;
|
6
|
-
let contextSeparator: string;
|
7
|
-
namespace resources {
|
8
|
-
namespace en {
|
9
|
-
let translation: any;
|
10
|
-
}
|
11
|
-
}
|
12
|
-
}
|
13
|
-
export default _default;
|
package/lib/mjs/i18n.js
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
import enTranslation from './translations/en';
|
2
|
-
import { fastCloneDeep } from './utils/utils';
|
3
|
-
export default {
|
4
|
-
lng: 'en',
|
5
|
-
nsSeparator: '::',
|
6
|
-
keySeparator: '.|.',
|
7
|
-
pluralSeparator: '._.',
|
8
|
-
contextSeparator: '._.',
|
9
|
-
resources: {
|
10
|
-
en: {
|
11
|
-
translation: fastCloneDeep(enTranslation)
|
12
|
-
}
|
13
|
-
}
|
14
|
-
};
|
package/lib/mjs/utils/i18n.d.ts
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* This file is used to mimic the i18n library interface.
|
3
|
-
*/
|
4
|
-
export class I18n {
|
5
|
-
static languages: {};
|
6
|
-
static setDefaultTranslations(languages: any): void;
|
7
|
-
static init(languages?: {}): I18n;
|
8
|
-
static createInstance(): I18n;
|
9
|
-
constructor(languages?: {});
|
10
|
-
languages: any;
|
11
|
-
defaultKeys: any;
|
12
|
-
language: string;
|
13
|
-
currentLanguage: any;
|
14
|
-
setLanguages(languages: any, noDefaultOverride: any): void;
|
15
|
-
dir(lang?: string): "rtl" | "ltr";
|
16
|
-
changeLanguage(language: any, ready?: null): void;
|
17
|
-
addResourceBundle(language: any, type: any, strings: any): void;
|
18
|
-
t(text: any, ...args: any[]): any;
|
19
|
-
}
|
package/lib/mjs/utils/i18n.js
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
import { Evaluator } from '@formio/core/utils';
|
2
|
-
import i18n from '../i18n';
|
3
|
-
import { isEmpty } from 'lodash';
|
4
|
-
import { fastCloneDeep } from '@formio/core';
|
5
|
-
const i18Defaults = {};
|
6
|
-
for (const lang in i18n.resources) {
|
7
|
-
if (i18n.resources.hasOwnProperty(lang)) {
|
8
|
-
i18Defaults[lang] = i18n.resources[lang].translation;
|
9
|
-
}
|
10
|
-
}
|
11
|
-
/**
|
12
|
-
* This file is used to mimic the i18n library interface.
|
13
|
-
*/
|
14
|
-
export class I18n {
|
15
|
-
static languages = i18Defaults;
|
16
|
-
languages = fastCloneDeep(I18n.languages || {});
|
17
|
-
defaultKeys = I18n.languages?.en || {};
|
18
|
-
language = 'en';
|
19
|
-
currentLanguage = i18Defaults.en;
|
20
|
-
constructor(languages = {}) {
|
21
|
-
this.setLanguages(languages);
|
22
|
-
this.changeLanguage(this.language);
|
23
|
-
}
|
24
|
-
static setDefaultTranslations(languages) {
|
25
|
-
if (isEmpty(languages)) {
|
26
|
-
return;
|
27
|
-
}
|
28
|
-
for (const lang in languages) {
|
29
|
-
if (lang !== 'language' && languages.hasOwnProperty(lang)) {
|
30
|
-
if (!this.languages[lang]) {
|
31
|
-
this.languages[lang] = {};
|
32
|
-
}
|
33
|
-
this.languages[lang] = { ...languages[lang], ...this.languages[lang], };
|
34
|
-
}
|
35
|
-
}
|
36
|
-
}
|
37
|
-
setLanguages(languages, noDefaultOverride) {
|
38
|
-
if (languages.resources) {
|
39
|
-
for (const lang in languages.resources) {
|
40
|
-
if (languages.resources.hasOwnProperty(lang)) {
|
41
|
-
languages[lang] = languages.resources[lang].translation;
|
42
|
-
}
|
43
|
-
}
|
44
|
-
delete languages.resources;
|
45
|
-
}
|
46
|
-
if (languages.lng) {
|
47
|
-
languages.language = languages.lng;
|
48
|
-
delete languages.lng;
|
49
|
-
}
|
50
|
-
// Do not use these configurations.
|
51
|
-
delete languages.nsSeparator;
|
52
|
-
delete languages.keySeparator;
|
53
|
-
delete languages.pluralSeparator;
|
54
|
-
delete languages.contextSeparator;
|
55
|
-
// Now establish the languages default.
|
56
|
-
if (languages.language) {
|
57
|
-
this.language = languages.language;
|
58
|
-
}
|
59
|
-
for (const lang in languages) {
|
60
|
-
if (lang !== 'language' && languages.hasOwnProperty(lang)) {
|
61
|
-
if (!this.languages[lang]) {
|
62
|
-
this.languages[lang] = {};
|
63
|
-
}
|
64
|
-
this.languages[lang] = noDefaultOverride
|
65
|
-
? { ...languages[lang], ...this.languages[lang] }
|
66
|
-
: { ...this.languages[lang], ...languages[lang] };
|
67
|
-
}
|
68
|
-
}
|
69
|
-
}
|
70
|
-
static init(languages = {}) {
|
71
|
-
return new I18n(languages);
|
72
|
-
}
|
73
|
-
dir(lang = '') {
|
74
|
-
lang = lang || this.language;
|
75
|
-
const rtls = ['ar', 'he', 'fa', 'ps', 'ur'];
|
76
|
-
return rtls.includes(lang) ? 'rtl' : 'ltr';
|
77
|
-
}
|
78
|
-
static createInstance() {
|
79
|
-
return new I18n();
|
80
|
-
}
|
81
|
-
changeLanguage(language, ready = null) {
|
82
|
-
if (!this.languages[language]) {
|
83
|
-
language = 'en';
|
84
|
-
}
|
85
|
-
this.language = language;
|
86
|
-
this.currentLanguage = this.languages[language] ? this.languages[language] : {};
|
87
|
-
if (ready) {
|
88
|
-
ready();
|
89
|
-
}
|
90
|
-
}
|
91
|
-
addResourceBundle(language, type, strings) {
|
92
|
-
this.languages[language] = strings;
|
93
|
-
}
|
94
|
-
t(text, ...args) {
|
95
|
-
let currentTranslation = this.currentLanguage[text];
|
96
|
-
// provide compatibility with cases where the entire phrase is used as a key
|
97
|
-
// get the phrase that is possibly being used as a key
|
98
|
-
const defaultKey = this.defaultKeys[text];
|
99
|
-
if (defaultKey && this.currentLanguage[defaultKey]) {
|
100
|
-
// get translation using the phrase as a key
|
101
|
-
currentTranslation = this.currentLanguage[defaultKey];
|
102
|
-
}
|
103
|
-
if (currentTranslation) {
|
104
|
-
const customTranslationFieldName = args[0]?.field;
|
105
|
-
if (customTranslationFieldName && this.currentLanguage[customTranslationFieldName]) {
|
106
|
-
args[0].field = this.currentLanguage[customTranslationFieldName];
|
107
|
-
}
|
108
|
-
return Evaluator.interpolateString(currentTranslation, ...args);
|
109
|
-
}
|
110
|
-
return Evaluator.interpolateString(text, ...args);
|
111
|
-
}
|
112
|
-
}
|