@formio/js 5.1.0-dev.6040.debc859 → 5.1.0-dev.6042.6e62a7a

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.
Files changed (150) hide show
  1. package/Changelog.md +140 -6
  2. package/dist/formio.form.js +591 -580
  3. package/dist/formio.form.min.js +1 -1
  4. package/dist/formio.full.js +613 -602
  5. package/dist/formio.full.min.js +1 -1
  6. package/dist/formio.js +47 -14
  7. package/dist/formio.min.js +1 -1
  8. package/dist/formio.utils.js +48 -15
  9. package/dist/formio.utils.min.js +1 -1
  10. package/lib/cjs/Element.d.ts +2 -1
  11. package/lib/cjs/Element.js +6 -4
  12. package/lib/cjs/Webform.d.ts +2 -2
  13. package/lib/cjs/Webform.js +9 -9
  14. package/lib/cjs/WebformBuilder.js +5 -1
  15. package/lib/cjs/Wizard.d.ts +1 -0
  16. package/lib/cjs/Wizard.js +23 -3
  17. package/lib/cjs/components/_classes/component/Component.d.ts +50 -15
  18. package/lib/cjs/components/_classes/component/Component.js +153 -69
  19. package/lib/cjs/components/_classes/component/editForm/Component.edit.data.js +19 -0
  20. package/lib/cjs/components/_classes/component/editForm/utils.js +1 -1
  21. package/lib/cjs/components/_classes/list/ListComponent.js +2 -2
  22. package/lib/cjs/components/_classes/nested/NestedComponent.d.ts +0 -1
  23. package/lib/cjs/components/_classes/nested/NestedComponent.form.js +13 -0
  24. package/lib/cjs/components/_classes/nested/NestedComponent.js +10 -18
  25. package/lib/cjs/components/_classes/nesteddata/NestedDataComponent.d.ts +0 -2
  26. package/lib/cjs/components/_classes/nesteddata/NestedDataComponent.js +0 -11
  27. package/lib/cjs/components/address/Address.d.ts +9 -0
  28. package/lib/cjs/components/address/Address.js +31 -8
  29. package/lib/cjs/components/address/editForm/Address.edit.display.d.ts +4 -0
  30. package/lib/cjs/components/address/editForm/Address.edit.display.js +1 -0
  31. package/lib/cjs/components/address/editForm/Address.edit.provider.js +8 -8
  32. package/lib/cjs/components/content/editForm/Content.edit.display.js +8 -0
  33. package/lib/cjs/components/currency/editForm/Currency.edit.display.js +12 -0
  34. package/lib/cjs/components/datagrid/DataGrid.js +0 -3
  35. package/lib/cjs/components/datamap/DataMap.js +2 -6
  36. package/lib/cjs/components/datetime/editForm/DateTime.edit.validation.d.ts +66 -15
  37. package/lib/cjs/components/datetime/editForm/DateTime.edit.validation.js +68 -47
  38. package/lib/cjs/components/day/editForm/Day.edit.display.js +8 -0
  39. package/lib/cjs/components/editgrid/EditGrid.js +3 -13
  40. package/lib/cjs/components/email/editForm/Email.edit.display.js +12 -0
  41. package/lib/cjs/components/fieldset/editForm/Fieldset.edit.display.js +8 -0
  42. package/lib/cjs/components/file/File.js +7 -2
  43. package/lib/cjs/components/file/editForm/File.edit.file.d.ts +13 -0
  44. package/lib/cjs/components/file/editForm/File.edit.file.js +1 -0
  45. package/lib/cjs/components/form/Form.d.ts +0 -1
  46. package/lib/cjs/components/form/Form.js +18 -22
  47. package/lib/cjs/components/hidden/editForm/Hidden.edit.display.js +8 -0
  48. package/lib/cjs/components/html/HTML.js +1 -2
  49. package/lib/cjs/components/html/editForm/HTML.edit.display.js +8 -0
  50. package/lib/cjs/components/number/editForm/Number.edit.display.js +12 -0
  51. package/lib/cjs/components/password/editForm/Password.edit.display.js +13 -1
  52. package/lib/cjs/components/phonenumber/PhoneNumber.form.js +9 -1
  53. package/lib/cjs/components/radio/Radio.js +1 -1
  54. package/lib/cjs/components/select/Select.js +1 -1
  55. package/lib/cjs/components/select/editForm/Select.edit.data.d.ts +68 -110
  56. package/lib/cjs/components/select/editForm/Select.edit.data.js +2 -37
  57. package/lib/cjs/components/selectboxes/SelectBoxes.js +3 -0
  58. package/lib/cjs/components/survey/Survey.js +1 -1
  59. package/lib/cjs/components/tabs/Tabs.js +1 -0
  60. package/lib/cjs/components/tabs/editForm/Tabs.edit.display.js +8 -0
  61. package/lib/cjs/components/textarea/TextArea.js +9 -1
  62. package/lib/cjs/components/textarea/editForm/TextArea.edit.display.js +12 -0
  63. package/lib/cjs/components/textfield/TextField.js +2 -2
  64. package/lib/cjs/components/unknown/Unknown.form.d.ts +2 -1
  65. package/lib/cjs/components/unknown/Unknown.form.js +13 -9
  66. package/lib/cjs/components/url/editForm/Url.edit.display.js +12 -0
  67. package/lib/cjs/components/well/editForm/Well.edit.display.js +8 -0
  68. package/lib/cjs/formio.form.js +2 -2
  69. package/lib/cjs/providers/storage/uploadAdapter.js +5 -3
  70. package/lib/cjs/translations/en.d.ts +1 -234
  71. package/lib/cjs/translations/en.js +4 -2
  72. package/lib/cjs/utils/formUtils.d.ts +2 -2
  73. package/lib/cjs/utils/utils.d.ts +9 -8
  74. package/lib/cjs/utils/utils.js +18 -23
  75. package/lib/cjs/widgets/CalendarWidget.js +6 -1
  76. package/lib/mjs/Element.d.ts +2 -1
  77. package/lib/mjs/Element.js +6 -4
  78. package/lib/mjs/Webform.d.ts +2 -2
  79. package/lib/mjs/Webform.js +9 -9
  80. package/lib/mjs/WebformBuilder.js +5 -1
  81. package/lib/mjs/Wizard.d.ts +1 -0
  82. package/lib/mjs/Wizard.js +22 -2
  83. package/lib/mjs/components/_classes/component/Component.d.ts +50 -15
  84. package/lib/mjs/components/_classes/component/Component.js +154 -70
  85. package/lib/mjs/components/_classes/component/editForm/Component.edit.data.js +19 -0
  86. package/lib/mjs/components/_classes/component/editForm/utils.js +1 -1
  87. package/lib/mjs/components/_classes/list/ListComponent.js +2 -2
  88. package/lib/mjs/components/_classes/nested/NestedComponent.d.ts +0 -1
  89. package/lib/mjs/components/_classes/nested/NestedComponent.form.js +13 -0
  90. package/lib/mjs/components/_classes/nested/NestedComponent.js +10 -18
  91. package/lib/mjs/components/_classes/nesteddata/NestedDataComponent.d.ts +0 -2
  92. package/lib/mjs/components/_classes/nesteddata/NestedDataComponent.js +0 -11
  93. package/lib/mjs/components/address/Address.d.ts +9 -0
  94. package/lib/mjs/components/address/Address.js +31 -8
  95. package/lib/mjs/components/address/editForm/Address.edit.display.d.ts +4 -0
  96. package/lib/mjs/components/address/editForm/Address.edit.display.js +1 -0
  97. package/lib/mjs/components/address/editForm/Address.edit.provider.js +8 -8
  98. package/lib/mjs/components/content/editForm/Content.edit.display.js +8 -0
  99. package/lib/mjs/components/currency/editForm/Currency.edit.display.js +12 -0
  100. package/lib/mjs/components/datagrid/DataGrid.js +0 -3
  101. package/lib/mjs/components/datamap/DataMap.js +2 -6
  102. package/lib/mjs/components/datetime/editForm/DateTime.edit.validation.d.ts +66 -15
  103. package/lib/mjs/components/datetime/editForm/DateTime.edit.validation.js +68 -47
  104. package/lib/mjs/components/day/editForm/Day.edit.display.js +8 -0
  105. package/lib/mjs/components/editgrid/EditGrid.js +3 -12
  106. package/lib/mjs/components/email/editForm/Email.edit.display.js +12 -0
  107. package/lib/mjs/components/fieldset/editForm/Fieldset.edit.display.js +8 -0
  108. package/lib/mjs/components/file/File.js +7 -2
  109. package/lib/mjs/components/file/editForm/File.edit.file.d.ts +13 -0
  110. package/lib/mjs/components/file/editForm/File.edit.file.js +1 -0
  111. package/lib/mjs/components/form/Form.d.ts +0 -1
  112. package/lib/mjs/components/form/Form.js +18 -22
  113. package/lib/mjs/components/hidden/editForm/Hidden.edit.display.js +8 -0
  114. package/lib/mjs/components/html/HTML.js +1 -2
  115. package/lib/mjs/components/html/editForm/HTML.edit.display.js +8 -0
  116. package/lib/mjs/components/number/editForm/Number.edit.display.js +12 -0
  117. package/lib/mjs/components/password/editForm/Password.edit.display.js +13 -1
  118. package/lib/mjs/components/phonenumber/PhoneNumber.form.js +9 -1
  119. package/lib/mjs/components/radio/Radio.js +1 -1
  120. package/lib/mjs/components/select/Select.js +1 -1
  121. package/lib/mjs/components/select/editForm/Select.edit.data.d.ts +68 -110
  122. package/lib/mjs/components/select/editForm/Select.edit.data.js +2 -37
  123. package/lib/mjs/components/selectboxes/SelectBoxes.js +3 -0
  124. package/lib/mjs/components/survey/Survey.js +1 -1
  125. package/lib/mjs/components/tabs/Tabs.js +1 -0
  126. package/lib/mjs/components/tabs/editForm/Tabs.edit.display.js +8 -0
  127. package/lib/mjs/components/textarea/TextArea.js +9 -1
  128. package/lib/mjs/components/textarea/editForm/TextArea.edit.display.js +12 -0
  129. package/lib/mjs/components/textfield/TextField.js +2 -2
  130. package/lib/mjs/components/unknown/Unknown.form.d.ts +2 -1
  131. package/lib/mjs/components/unknown/Unknown.form.js +13 -9
  132. package/lib/mjs/components/url/editForm/Url.edit.display.js +12 -0
  133. package/lib/mjs/components/well/editForm/Well.edit.display.js +8 -0
  134. package/lib/mjs/formio.form.js +1 -1
  135. package/lib/mjs/providers/storage/uploadAdapter.js +5 -3
  136. package/lib/mjs/translations/en.d.ts +1 -234
  137. package/lib/mjs/translations/en.js +5 -47
  138. package/lib/mjs/utils/formUtils.d.ts +2 -2
  139. package/lib/mjs/utils/utils.d.ts +9 -8
  140. package/lib/mjs/utils/utils.js +16 -21
  141. package/lib/mjs/widgets/CalendarWidget.js +7 -2
  142. package/package.json +2 -2
  143. package/lib/cjs/i18n.d.ts +0 -13
  144. package/lib/cjs/i18n.js +0 -19
  145. package/lib/cjs/utils/i18n.d.ts +0 -19
  146. package/lib/cjs/utils/i18n.js +0 -120
  147. package/lib/mjs/i18n.d.ts +0 -13
  148. package/lib/mjs/i18n.js +0 -14
  149. package/lib/mjs/utils/i18n.d.ts +0 -19
  150. package/lib/mjs/utils/i18n.js +0 -112
@@ -8,6 +8,7 @@ import dompurify from 'dompurify';
8
8
  import { getValue } from './formUtils';
9
9
  import { Evaluator } from './Evaluator';
10
10
  import ConditionOperators from './conditionOperators';
11
+ import { convertShowToBoolean } from '@formio/core';
11
12
  const interpolate = Evaluator.interpolate;
12
13
  export * from './formUtils';
13
14
  // Configure JsonLogic
@@ -236,7 +237,7 @@ export function checkSimpleConditional(component, condition, row, data, instance
236
237
  default:
237
238
  result = _.every(conditionsResult.flat(), res => !!res);
238
239
  }
239
- return show ? result : !result;
240
+ return convertShowToBoolean(show) ? result : !result;
240
241
  }
241
242
  }
242
243
  /**
@@ -1502,26 +1503,6 @@ export function isPromise(value) {
1502
1503
  && typeof value.then === 'function'
1503
1504
  && Object.prototype.toString.call(value) === '[object Promise]';
1504
1505
  }
1505
- /**
1506
- * Determines if the component has a scoping parent in tree (a component which scopes its children and manages its
1507
- * changes by itself, e.g. EditGrid)
1508
- * @param {Component} componentInstance - The component to check for the scoping parent.
1509
- * @param {boolean} firstPass - Whether it is the first pass of the function
1510
- * @returns {boolean|*} - TRUE if the component has a scoping parent; FALSE otherwise
1511
- */
1512
- export function isInsideScopingComponent(componentInstance, firstPass = true) {
1513
- if (!firstPass && componentInstance?.hasScopedChildren) {
1514
- return true;
1515
- }
1516
- const dataParent = getDataParentComponent(componentInstance);
1517
- if (dataParent?.hasScopedChildren) {
1518
- return true;
1519
- }
1520
- else if (dataParent?.parent) {
1521
- return isInsideScopingComponent(dataParent.parent, false);
1522
- }
1523
- return false;
1524
- }
1525
1506
  /**
1526
1507
  * Returns all the focusable elements within the provided dom element.
1527
1508
  * @param {HTMLElement} element - The element to get the focusable elements from.
@@ -1573,3 +1554,17 @@ export const interpolateErrors = (component, errors, interpolateFn) => {
1573
1554
  return { ...error, message: unescapeHTML(interpolateFn(toInterpolate, context)), context: { ...context } };
1574
1555
  });
1575
1556
  };
1557
+ /**
1558
+ * Checks if a string has timezone information encoded in it
1559
+ * Example: 2024-01-01T00:00:00Z -> true
1560
+ * Example: 2024-01-01T00:00:00+03:00 -> true
1561
+ * Example: 2011-05-03T00:00:00 -> false
1562
+ * @param {string} value the string value to check
1563
+ * @returns {boolean} if value has encoded timezone
1564
+ */
1565
+ export function hasEncodedTimezone(value) {
1566
+ if (typeof value !== 'string') {
1567
+ return false;
1568
+ }
1569
+ return (value.substring(value.length - 1) === 'z' || value.substring(value.length - 1) === 'Z' || value.match(/[+|-][0-9]{2}:[0-9]{2}$/));
1570
+ }
@@ -1,6 +1,6 @@
1
1
  import { Formio } from '../Formio';
2
2
  import InputWidget from './InputWidget';
3
- import { convertFormatToFlatpickr, convertFormatToMask, convertFormatToMoment, formatDate, formatOffset, getBrowserInfo, getDateSetting, getLocaleDateFormatInfo, momentDate, zonesLoaded, shouldLoadZones, loadZones, } from '../utils/utils';
3
+ import { convertFormatToFlatpickr, convertFormatToMask, convertFormatToMoment, formatDate, formatOffset, getBrowserInfo, getDateSetting, getLocaleDateFormatInfo, momentDate, zonesLoaded, shouldLoadZones, loadZones, hasEncodedTimezone, } from '../utils/utils';
4
4
  import moment from 'moment';
5
5
  import _ from 'lodash';
6
6
  const DEFAULT_FORMAT = 'yyyy-MM-dd hh:mm a';
@@ -278,6 +278,11 @@ export default class CalendarWidget extends InputWidget {
278
278
  value = value ? formatDate(this.timezonesUrl, value, convertFormatToMoment(this.settings.format), this.timezone, convertFormatToMoment(this.valueMomentFormat)) : value;
279
279
  return super.setValue(value);
280
280
  }
281
+ // If the component is a textfield that does not have timezone information included in the string value then skip
282
+ // the timezone offset
283
+ if (this.component.type === 'textfield' && !hasEncodedTimezone(value)) {
284
+ this.settings.skipOffset = true;
285
+ }
281
286
  const zonesLoading = this.loadZones();
282
287
  if (value) {
283
288
  if (!saveAsText && this.settings.readOnly && !zonesLoading) {
@@ -443,7 +448,7 @@ export default class CalendarWidget extends InputWidget {
443
448
  return (date, format) => {
444
449
  // Only format this if this is the altFormat and the form is readOnly.
445
450
  if (this.settings.readOnly && (format === this.settings.altFormat)) {
446
- if (!this.settings.enableTime || this.loadZones()) {
451
+ if (!this.settings.enableTime || this.loadZones() || this.settings.skipOffset) {
447
452
  return Flatpickr.formatDate(date, format);
448
453
  }
449
454
  const currentValue = new Date(this.getValue());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.1.0-dev.6040.debc859",
3
+ "version": "5.1.0-dev.6042.6e62a7a",
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": "v2.4.0-dev.2",
84
+ "@formio/core": "2.4.0-dev.235.b497e17",
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",
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
- };
@@ -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
- }
@@ -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
- };
@@ -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
- }
@@ -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
- }