@formio/js 5.1.0-dev.5969.9a6e3f5 → 5.1.0-dev.5972.f3a71a8

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 (77) hide show
  1. package/dist/formio.form.js +74 -52
  2. package/dist/formio.form.min.js +1 -1
  3. package/dist/formio.full.js +77 -55
  4. package/dist/formio.full.min.js +1 -1
  5. package/dist/formio.js +3 -3
  6. package/dist/formio.min.js +1 -1
  7. package/dist/formio.utils.js +3 -3
  8. package/dist/formio.utils.min.js +1 -1
  9. package/lib/cjs/Form.js +4 -4
  10. package/lib/cjs/PDFBuilder.js +4 -4
  11. package/lib/cjs/Webform.d.ts +12 -12
  12. package/lib/cjs/Webform.js +132 -131
  13. package/lib/cjs/WebformBuilder.js +10 -10
  14. package/lib/cjs/Wizard.js +1 -1
  15. package/lib/cjs/WizardBuilder.js +1 -1
  16. package/lib/cjs/components/_classes/component/Component.js +12 -11
  17. package/lib/cjs/components/_classes/list/ListComponent.js +4 -4
  18. package/lib/cjs/components/_classes/multivalue/Multivalue.js +2 -2
  19. package/lib/cjs/components/_classes/nestedarray/NestedArrayComponent.js +3 -3
  20. package/lib/cjs/components/address/Address.js +1 -1
  21. package/lib/cjs/components/button/Button.js +6 -6
  22. package/lib/cjs/components/checkbox/Checkbox.js +1 -1
  23. package/lib/cjs/components/datagrid/DataGrid.js +1 -1
  24. package/lib/cjs/components/datetime/DateTime.js +4 -0
  25. package/lib/cjs/components/day/Day.js +4 -20
  26. package/lib/cjs/components/editgrid/EditGrid.js +4 -4
  27. package/lib/cjs/components/file/File.js +15 -15
  28. package/lib/cjs/components/form/Form.js +4 -4
  29. package/lib/cjs/components/number/Number.js +1 -1
  30. package/lib/cjs/components/recaptcha/ReCaptcha.js +2 -2
  31. package/lib/cjs/components/select/Select.js +5 -5
  32. package/lib/cjs/components/selectboxes/SelectBoxes.js +2 -2
  33. package/lib/cjs/components/signature/Signature.d.ts +1 -1
  34. package/lib/cjs/components/signature/Signature.js +2 -2
  35. package/lib/cjs/components/survey/Survey.js +2 -2
  36. package/lib/cjs/components/textarea/TextArea.js +6 -6
  37. package/lib/cjs/components/textfield/TextField.js +3 -0
  38. package/lib/cjs/formio.form.js +4 -0
  39. package/lib/cjs/translations/en.d.ts +234 -81
  40. package/lib/cjs/translations/en.js +8 -81
  41. package/lib/cjs/utils/i18n.d.ts +5 -2
  42. package/lib/cjs/utils/i18n.js +32 -5
  43. package/lib/mjs/Form.js +4 -4
  44. package/lib/mjs/PDFBuilder.js +4 -4
  45. package/lib/mjs/Webform.d.ts +12 -12
  46. package/lib/mjs/Webform.js +142 -141
  47. package/lib/mjs/WebformBuilder.js +10 -10
  48. package/lib/mjs/Wizard.js +1 -1
  49. package/lib/mjs/WizardBuilder.js +1 -1
  50. package/lib/mjs/components/_classes/component/Component.js +12 -11
  51. package/lib/mjs/components/_classes/list/ListComponent.js +4 -4
  52. package/lib/mjs/components/_classes/multivalue/Multivalue.js +2 -2
  53. package/lib/mjs/components/_classes/nestedarray/NestedArrayComponent.js +3 -3
  54. package/lib/mjs/components/address/Address.js +1 -1
  55. package/lib/mjs/components/button/Button.js +6 -6
  56. package/lib/mjs/components/checkbox/Checkbox.js +1 -1
  57. package/lib/mjs/components/datagrid/DataGrid.js +1 -1
  58. package/lib/mjs/components/datetime/DateTime.js +5 -1
  59. package/lib/mjs/components/day/Day.js +4 -20
  60. package/lib/mjs/components/editgrid/EditGrid.js +4 -4
  61. package/lib/mjs/components/file/File.js +15 -15
  62. package/lib/mjs/components/form/Form.js +4 -4
  63. package/lib/mjs/components/number/Number.js +1 -1
  64. package/lib/mjs/components/recaptcha/ReCaptcha.js +2 -2
  65. package/lib/mjs/components/select/Select.js +7 -7
  66. package/lib/mjs/components/selectboxes/SelectBoxes.js +2 -2
  67. package/lib/mjs/components/signature/Signature.d.ts +1 -1
  68. package/lib/mjs/components/signature/Signature.js +2 -2
  69. package/lib/mjs/components/survey/Survey.js +2 -2
  70. package/lib/mjs/components/textarea/TextArea.js +6 -6
  71. package/lib/mjs/components/textfield/TextField.js +3 -0
  72. package/lib/mjs/formio.form.js +4 -0
  73. package/lib/mjs/translations/en.d.ts +234 -81
  74. package/lib/mjs/translations/en.js +89 -3
  75. package/lib/mjs/utils/i18n.d.ts +5 -2
  76. package/lib/mjs/utils/i18n.js +32 -5
  77. package/package.json +3 -3
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.I18n = void 0;
7
7
  const utils_1 = require("@formio/core/utils");
8
8
  const i18n_1 = __importDefault(require("../i18n"));
9
+ const lodash_1 = require("lodash");
10
+ const core_1 = require("@formio/core");
9
11
  const i18Defaults = {};
10
12
  for (const lang in i18n_1.default.resources) {
11
13
  if (i18n_1.default.resources.hasOwnProperty(lang)) {
@@ -17,13 +19,28 @@ for (const lang in i18n_1.default.resources) {
17
19
  */
18
20
  class I18n {
19
21
  constructor(languages = {}) {
20
- this.languages = i18Defaults;
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) || {};
21
25
  this.language = 'en';
22
26
  this.currentLanguage = i18Defaults.en;
23
27
  this.setLanguages(languages);
24
28
  this.changeLanguage(this.language);
25
29
  }
26
- setLanguages(languages) {
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) {
27
44
  if (languages.resources) {
28
45
  for (const lang in languages.resources) {
29
46
  if (languages.resources.hasOwnProperty(lang)) {
@@ -50,7 +67,8 @@ class I18n {
50
67
  if (!this.languages[lang]) {
51
68
  this.languages[lang] = {};
52
69
  }
53
- this.languages[lang] = Object.assign(Object.assign({}, this.languages[lang]), languages[lang]);
70
+ this.languages[lang] = noDefaultOverride
71
+ ? Object.assign(Object.assign({}, languages[lang]), this.languages[lang]) : Object.assign(Object.assign({}, this.languages[lang]), languages[lang]);
54
72
  }
55
73
  }
56
74
  }
@@ -80,14 +98,23 @@ class I18n {
80
98
  }
81
99
  t(text, ...args) {
82
100
  var _a;
83
- if (this.currentLanguage[text]) {
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) {
84
110
  const customTranslationFieldName = (_a = args[0]) === null || _a === void 0 ? void 0 : _a.field;
85
111
  if (customTranslationFieldName && this.currentLanguage[customTranslationFieldName]) {
86
112
  args[0].field = this.currentLanguage[customTranslationFieldName];
87
113
  }
88
- return utils_1.Evaluator.interpolateString(this.currentLanguage[text], ...args);
114
+ return utils_1.Evaluator.interpolateString(currentTranslation, ...args);
89
115
  }
90
116
  return utils_1.Evaluator.interpolateString(text, ...args);
91
117
  }
92
118
  }
93
119
  exports.I18n = I18n;
120
+ I18n.languages = i18Defaults;
package/lib/mjs/Form.js CHANGED
@@ -406,10 +406,10 @@ export default class Form extends Element {
406
406
  */
407
407
  build() {
408
408
  if (!this.instance) {
409
- return Promise.reject('Form not ready. Use form.ready promise');
409
+ return Promise.reject(this.t('formNotReady'));
410
410
  }
411
411
  if (!this.element) {
412
- return Promise.reject('No DOM element for form.');
412
+ return Promise.reject(this.t('noFormElement'));
413
413
  }
414
414
  // Add temporary loader.
415
415
  const template = (this.options && this.options.template) ? this.options.template : 'bootstrap';
@@ -426,7 +426,7 @@ export default class Form extends Element {
426
426
  }
427
427
  render() {
428
428
  if (!this.instance) {
429
- return Promise.reject('Form not ready. Use form.ready promise');
429
+ return Promise.reject(this.t('formNotReady'));
430
430
  }
431
431
  return Promise.resolve(this.instance.render())
432
432
  .then((param) => {
@@ -436,7 +436,7 @@ export default class Form extends Element {
436
436
  }
437
437
  attach(element) {
438
438
  if (!this.instance) {
439
- return Promise.reject('Form not ready. Use form.ready promise');
439
+ return Promise.reject(this.t('formNotReady'));
440
440
  }
441
441
  if (this.element) {
442
442
  delete this.element.component;
@@ -196,10 +196,10 @@ export default class PDFBuilder extends WebformBuilder {
196
196
  const progress = Math.floor((event.loaded / event.total) * 100);
197
197
  this.refs.uploadProgress.style.width = `${progress}%`;
198
198
  if (progress > 98) {
199
- this.refs.uploadProgress.innerHTML = this.t('Converting PDF. Please wait.');
199
+ this.refs.uploadProgress.innerHTML = this.t('waitPdfConverting');
200
200
  }
201
201
  else {
202
- this.refs.uploadProgress.innerHTML = `${this.t('Uploading')} ${progress}%`;
202
+ this.refs.uploadProgress.innerHTML = `${this.t('uploading')} ${progress}%`;
203
203
  }
204
204
  }
205
205
  }, `${this.projectUrl}/upload`, {}, 'file')
@@ -236,7 +236,7 @@ export default class PDFBuilder extends WebformBuilder {
236
236
  return;
237
237
  }
238
238
  this.refs.uploadError.style.display = message ? '' : 'none';
239
- this.refs.uploadError.innerHTML = message;
239
+ this.refs.uploadError.innerHTML = this.t(`${message}`);
240
240
  }
241
241
  createForm(options) {
242
242
  // Instantiate the webform from the PDF class instead of Webform
@@ -464,7 +464,7 @@ export default class PDFBuilder extends WebformBuilder {
464
464
  name: 'showBuilderErrors',
465
465
  data: {
466
466
  compId: comp.component.id,
467
- errorMessage: `API Key is not unique: ${comp.key}`,
467
+ errorMessage: `${this.t('notUniqueKey')}: ${comp.key}`,
468
468
  }
469
469
  });
470
470
  }
@@ -34,10 +34,10 @@
34
34
  */
35
35
  /**
36
36
  * @typedef {object} ButtonSettings
37
- * @property {boolean} [showPrevious] - Show the "Previous" button.
38
- * @property {boolean} [showNext] - Show the "Next" button.
39
- * @property {boolean} [showCancel] - Show the "Cancel" button.
40
- * @property {boolean} [showSubmit] - Show the "Submit" button.
37
+ * @property {boolean} [showPrevious] - Show the 'Previous' button.
38
+ * @property {boolean} [showNext] - Show the 'Next' button.
39
+ * @property {boolean} [showCancel] - Show the 'Cancel' button.
40
+ * @property {boolean} [showSubmit] - Show the 'Submit' button.
41
41
  */
42
42
  /**
43
43
  * @typedef {object} FormOptions
@@ -257,7 +257,7 @@ declare class Webform extends NestedDataComponent {
257
257
  get ready(): Promise<any>;
258
258
  /**
259
259
  * Set the loading state for this form, and also show the loader spinner.
260
- * @param {boolean} loading - If this form should be "loading" or not.
260
+ * @param {boolean} loading - If this form should be 'loading' or not.
261
261
  */
262
262
  set loading(loading: boolean);
263
263
  /**
@@ -369,7 +369,7 @@ declare class Webform extends NestedDataComponent {
369
369
  hasRequiredFields(): boolean;
370
370
  /**
371
371
  * Sets a new alert to display in the error dialog of the form.
372
- * @param {string} type - The type of alert to display. "danger", "success", "warning", etc.
372
+ * @param {string} type - The type of alert to display. 'danger', 'success', 'warning', etc.
373
373
  * @param {string} message - The message to show in the alert.
374
374
  * @param {object} options - The options for the alert.
375
375
  */
@@ -547,19 +547,19 @@ export type SanitizeConfig = {
547
547
  };
548
548
  export type ButtonSettings = {
549
549
  /**
550
- * - Show the "Previous" button.
550
+ * - Show the 'Previous' button.
551
551
  */
552
552
  showPrevious?: boolean | undefined;
553
553
  /**
554
- * - Show the "Next" button.
554
+ * - Show the 'Next' button.
555
555
  */
556
556
  showNext?: boolean | undefined;
557
557
  /**
558
- * - Show the "Cancel" button.
558
+ * - Show the 'Cancel' button.
559
559
  */
560
560
  showCancel?: boolean | undefined;
561
561
  /**
562
- * - Show the "Submit" button.
562
+ * - Show the 'Submit' button.
563
563
  */
564
564
  showSubmit?: boolean | undefined;
565
565
  };
@@ -739,5 +739,5 @@ export type FormOptions = {
739
739
  */
740
740
  zoom?: number | undefined;
741
741
  };
742
- import NestedDataComponent from "./components/_classes/nesteddata/NestedDataComponent";
743
- import EventEmitter from "./EventEmitter";
742
+ import NestedDataComponent from './components/_classes/nesteddata/NestedDataComponent';
743
+ import EventEmitter from './EventEmitter';