@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.
Files changed (168) hide show
  1. package/README.md +7 -0
  2. package/dist/formio.builder.css +1 -0
  3. package/dist/formio.builder.min.css +1 -1
  4. package/dist/formio.form.css +1 -0
  5. package/dist/formio.form.js +116 -149
  6. package/dist/formio.form.min.css +1 -1
  7. package/dist/formio.form.min.js +1 -1
  8. package/dist/formio.full.css +1 -0
  9. package/dist/formio.full.js +123 -156
  10. package/dist/formio.full.min.css +1 -1
  11. package/dist/formio.full.min.js +1 -1
  12. package/dist/formio.js +65 -54
  13. package/dist/formio.min.js +1 -1
  14. package/dist/formio.utils.js +76 -76
  15. package/dist/formio.utils.min.js +1 -1
  16. package/lib/cjs/Element.d.ts +2 -1
  17. package/lib/cjs/Element.js +18 -39
  18. package/lib/cjs/EventEmitter.js +2 -25
  19. package/lib/cjs/Form.js +2 -25
  20. package/lib/cjs/PDF.js +1 -1
  21. package/lib/cjs/PDFBuilder.d.ts +1 -0
  22. package/lib/cjs/PDFBuilder.js +10 -11
  23. package/lib/cjs/Webform.d.ts +2 -2
  24. package/lib/cjs/Webform.js +9 -9
  25. package/lib/cjs/WebformBuilder.d.ts +1 -1
  26. package/lib/cjs/WebformBuilder.js +45 -21
  27. package/lib/cjs/Wizard.d.ts +1 -2
  28. package/lib/cjs/Wizard.js +18 -24
  29. package/lib/cjs/WizardBuilder.js +1 -1
  30. package/lib/cjs/components/_classes/component/Component.d.ts +0 -1
  31. package/lib/cjs/components/_classes/component/Component.js +55 -62
  32. package/lib/cjs/components/_classes/component/editForm/Component.edit.conditional.js +1 -1
  33. package/lib/cjs/components/_classes/component/editForm/Component.edit.logic.js +1 -1
  34. package/lib/cjs/components/_classes/componentModal/ComponentModal.js +1 -1
  35. package/lib/cjs/components/_classes/input/Input.d.ts +1 -1
  36. package/lib/cjs/components/_classes/input/Input.js +3 -3
  37. package/lib/cjs/components/_classes/list/ListComponent.js +1 -1
  38. package/lib/cjs/components/_classes/nested/NestedComponent.js +7 -7
  39. package/lib/cjs/components/_classes/nestedarray/NestedArrayComponent.js +1 -1
  40. package/lib/cjs/components/_classes/nesteddata/NestedDataComponent.js +1 -1
  41. package/lib/cjs/components/address/Address.js +1 -1
  42. package/lib/cjs/components/alert/Alert.js +1 -1
  43. package/lib/cjs/components/button/Button.js +1 -1
  44. package/lib/cjs/components/checkbox/Checkbox.js +1 -1
  45. package/lib/cjs/components/container/Container.js +1 -1
  46. package/lib/cjs/components/currency/Currency.js +1 -1
  47. package/lib/cjs/components/datagrid/DataGrid.js +1 -1
  48. package/lib/cjs/components/datamap/DataMap.js +7 -2
  49. package/lib/cjs/components/datetime/DateTime.d.ts +1 -1
  50. package/lib/cjs/components/datetime/DateTime.js +15 -13
  51. package/lib/cjs/components/day/Day.js +2 -2
  52. package/lib/cjs/components/editgrid/EditGrid.js +1 -1
  53. package/lib/cjs/components/editgrid/editForm/EditGrid.edit.display.js +1 -1
  54. package/lib/cjs/components/fieldset/Fieldset.js +1 -0
  55. package/lib/cjs/components/file/File.js +1 -1
  56. package/lib/cjs/components/form/Form.js +14 -2
  57. package/lib/cjs/components/form/editForm/Form.edit.form.js +4 -3
  58. package/lib/cjs/components/number/Number.js +1 -1
  59. package/lib/cjs/components/panel/Panel.js +1 -1
  60. package/lib/cjs/components/radio/Radio.d.ts +8 -0
  61. package/lib/cjs/components/radio/Radio.js +16 -6
  62. package/lib/cjs/components/recaptcha/editForm/ReCaptcha.edit.display.js +1 -1
  63. package/lib/cjs/components/select/Select.js +7 -3
  64. package/lib/cjs/components/select/editForm/Select.edit.data.js +1 -1
  65. package/lib/cjs/components/selectboxes/SelectBoxes.d.ts +6 -0
  66. package/lib/cjs/components/selectboxes/SelectBoxes.js +1 -1
  67. package/lib/cjs/components/signature/Signature.js +1 -1
  68. package/lib/cjs/components/survey/Survey.js +1 -1
  69. package/lib/cjs/components/tags/Tags.js +1 -1
  70. package/lib/cjs/components/textarea/TextArea.js +9 -4
  71. package/lib/cjs/components/textfield/TextField.js +13 -31
  72. package/lib/cjs/components/time/Time.js +1 -1
  73. package/lib/cjs/formio.form.js +5 -5
  74. package/lib/cjs/providers/storage/uploadAdapter.js +1 -1
  75. package/lib/cjs/translations/en.d.ts +1 -232
  76. package/lib/cjs/translations/en.js +4 -2
  77. package/lib/cjs/utils/Evaluator.d.ts +20 -6
  78. package/lib/cjs/utils/Evaluator.js +38 -15
  79. package/lib/cjs/utils/builder.js +5 -5
  80. package/lib/cjs/utils/conditionOperators/IsEqualTo.js +3 -3
  81. package/lib/cjs/utils/formUtils.d.ts +2 -2
  82. package/lib/cjs/utils/index.d.ts +169 -2
  83. package/lib/cjs/utils/index.js +22 -2
  84. package/lib/cjs/utils/utils.d.ts +22 -37
  85. package/lib/cjs/utils/utils.js +64 -135
  86. package/lib/cjs/widgets/CalendarWidget.d.ts +1 -8
  87. package/lib/cjs/widgets/CalendarWidget.js +17 -43
  88. package/lib/mjs/Element.d.ts +2 -1
  89. package/lib/mjs/Element.js +11 -9
  90. package/lib/mjs/EventEmitter.js +2 -2
  91. package/lib/mjs/Form.js +1 -1
  92. package/lib/mjs/PDF.js +1 -1
  93. package/lib/mjs/PDFBuilder.d.ts +1 -0
  94. package/lib/mjs/PDFBuilder.js +9 -10
  95. package/lib/mjs/Webform.d.ts +2 -2
  96. package/lib/mjs/Webform.js +7 -7
  97. package/lib/mjs/WebformBuilder.d.ts +1 -1
  98. package/lib/mjs/WebformBuilder.js +36 -13
  99. package/lib/mjs/Wizard.d.ts +1 -2
  100. package/lib/mjs/Wizard.js +17 -23
  101. package/lib/mjs/WizardBuilder.js +1 -1
  102. package/lib/mjs/components/_classes/component/Component.d.ts +0 -1
  103. package/lib/mjs/components/_classes/component/Component.js +28 -12
  104. package/lib/mjs/components/_classes/component/editForm/Component.edit.conditional.js +1 -1
  105. package/lib/mjs/components/_classes/component/editForm/Component.edit.logic.js +1 -1
  106. package/lib/mjs/components/_classes/componentModal/ComponentModal.js +1 -1
  107. package/lib/mjs/components/_classes/input/Input.d.ts +1 -1
  108. package/lib/mjs/components/_classes/input/Input.js +3 -3
  109. package/lib/mjs/components/_classes/list/ListComponent.js +1 -1
  110. package/lib/mjs/components/_classes/nested/NestedComponent.js +7 -7
  111. package/lib/mjs/components/_classes/nestedarray/NestedArrayComponent.js +1 -1
  112. package/lib/mjs/components/_classes/nesteddata/NestedDataComponent.js +1 -1
  113. package/lib/mjs/components/address/Address.js +1 -1
  114. package/lib/mjs/components/alert/Alert.js +1 -1
  115. package/lib/mjs/components/button/Button.js +1 -1
  116. package/lib/mjs/components/checkbox/Checkbox.js +1 -1
  117. package/lib/mjs/components/container/Container.js +1 -1
  118. package/lib/mjs/components/currency/Currency.js +1 -1
  119. package/lib/mjs/components/datagrid/DataGrid.js +1 -1
  120. package/lib/mjs/components/datamap/DataMap.js +7 -2
  121. package/lib/mjs/components/datetime/DateTime.d.ts +1 -1
  122. package/lib/mjs/components/datetime/DateTime.js +15 -13
  123. package/lib/mjs/components/day/Day.js +2 -2
  124. package/lib/mjs/components/editgrid/EditGrid.js +1 -1
  125. package/lib/mjs/components/editgrid/editForm/EditGrid.edit.display.js +1 -1
  126. package/lib/mjs/components/fieldset/Fieldset.js +1 -0
  127. package/lib/mjs/components/file/File.js +1 -1
  128. package/lib/mjs/components/form/Form.js +13 -2
  129. package/lib/mjs/components/form/editForm/Form.edit.form.js +3 -2
  130. package/lib/mjs/components/number/Number.js +1 -1
  131. package/lib/mjs/components/panel/Panel.js +1 -1
  132. package/lib/mjs/components/radio/Radio.d.ts +8 -0
  133. package/lib/mjs/components/radio/Radio.js +16 -6
  134. package/lib/mjs/components/recaptcha/editForm/ReCaptcha.edit.display.js +1 -1
  135. package/lib/mjs/components/select/Select.js +7 -3
  136. package/lib/mjs/components/select/editForm/Select.edit.data.js +1 -1
  137. package/lib/mjs/components/selectboxes/SelectBoxes.d.ts +6 -0
  138. package/lib/mjs/components/selectboxes/SelectBoxes.js +1 -1
  139. package/lib/mjs/components/signature/Signature.js +1 -1
  140. package/lib/mjs/components/survey/Survey.js +1 -1
  141. package/lib/mjs/components/tags/Tags.js +1 -1
  142. package/lib/mjs/components/textarea/TextArea.js +9 -4
  143. package/lib/mjs/components/textfield/TextField.js +7 -2
  144. package/lib/mjs/components/time/Time.js +1 -1
  145. package/lib/mjs/formio.form.js +3 -3
  146. package/lib/mjs/providers/storage/uploadAdapter.js +1 -1
  147. package/lib/mjs/translations/en.d.ts +1 -232
  148. package/lib/mjs/translations/en.js +8 -47
  149. package/lib/mjs/utils/Evaluator.d.ts +20 -6
  150. package/lib/mjs/utils/Evaluator.js +31 -13
  151. package/lib/mjs/utils/builder.js +1 -1
  152. package/lib/mjs/utils/conditionOperators/IsEqualTo.js +1 -1
  153. package/lib/mjs/utils/formUtils.d.ts +2 -2
  154. package/lib/mjs/utils/index.d.ts +169 -2
  155. package/lib/mjs/utils/index.js +18 -1
  156. package/lib/mjs/utils/utils.d.ts +22 -37
  157. package/lib/mjs/utils/utils.js +57 -109
  158. package/lib/mjs/widgets/CalendarWidget.d.ts +1 -8
  159. package/lib/mjs/widgets/CalendarWidget.js +17 -43
  160. package/package.json +5 -3
  161. package/lib/cjs/i18n.d.ts +0 -13
  162. package/lib/cjs/i18n.js +0 -19
  163. package/lib/cjs/utils/i18n.d.ts +0 -19
  164. package/lib/cjs/utils/i18n.js +0 -120
  165. package/lib/mjs/i18n.d.ts +0 -13
  166. package/lib/mjs/i18n.js +0 -14
  167. package/lib/mjs/utils/i18n.d.ts +0 -19
  168. 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: any): string;
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 = convertFormatToMoment(this.valueFormat);
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 momentDate(date, this.valueFormat, this.timezone).format(convertFormatToMoment(format));
221
+ return dayjsDate(date, this.valueFormat, this.timezone).format(convertFormatToDayjs(format));
245
222
  }
246
- return moment(date).format(convertFormatToMoment(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(this.timezonesUrl, value, convertFormatToMoment(this.settings.format), this.timezone, convertFormatToMoment(this.valueMomentFormat)) : value;
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
- if (this.component.type === 'textfield' && !hasEncodedTimezone(value)) {
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 && !zonesLoading) {
289
- this.calendar.setDate(momentDate(value, this.valueFormat, this.timezone).format(), false);
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, convertFormatToMoment(valueFormat)).format(convertFormatToMoment(valueFormat));
280
+ return moment(value, convertFormatToDayjs(valueFormat)).format(convertFormatToDayjs(valueFormat));
307
281
  }
308
- return formatDate(this.timezonesUrl, value, inputFormat, this.timezone, convertFormatToMoment(valueFormat));
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, convertFormatToMoment(this.valueFormat)).toDate() : inputValue;
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.loadZones() || this.settings.skipOffset) {
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(this.timezonesUrl, Flatpickr.formatDate.bind(Flatpickr), new Date(this.componentValue), format, this.timezone);
430
+ return formatOffset(Flatpickr.formatDate.bind(Flatpickr), new Date(this.componentValue), format, this.timezone);
457
431
  }
458
- return formatOffset(this.timezonesUrl, Flatpickr.formatDate.bind(Flatpickr), date, format, this.timezone);
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.6109.79f22ad",
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": "v2.4.0-dev.232.d91b1e4",
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
- };
@@ -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
- }