@formio/js 5.1.0-dev.6108.401a61f → 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 (170) 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.d.ts +1 -0
  64. package/lib/cjs/components/select/Select.js +20 -4
  65. package/lib/cjs/components/select/editForm/Select.edit.data.js +1 -1
  66. package/lib/cjs/components/selectboxes/SelectBoxes.d.ts +6 -0
  67. package/lib/cjs/components/selectboxes/SelectBoxes.js +1 -1
  68. package/lib/cjs/components/signature/Signature.js +1 -1
  69. package/lib/cjs/components/survey/Survey.js +1 -1
  70. package/lib/cjs/components/tags/Tags.js +1 -1
  71. package/lib/cjs/components/textarea/TextArea.js +9 -4
  72. package/lib/cjs/components/textfield/TextField.js +13 -31
  73. package/lib/cjs/components/time/Time.js +1 -1
  74. package/lib/cjs/formio.form.js +5 -5
  75. package/lib/cjs/providers/storage/uploadAdapter.js +1 -1
  76. package/lib/cjs/translations/en.d.ts +1 -232
  77. package/lib/cjs/translations/en.js +4 -2
  78. package/lib/cjs/utils/Evaluator.d.ts +20 -6
  79. package/lib/cjs/utils/Evaluator.js +38 -15
  80. package/lib/cjs/utils/builder.js +5 -5
  81. package/lib/cjs/utils/conditionOperators/IsEqualTo.js +3 -3
  82. package/lib/cjs/utils/formUtils.d.ts +2 -2
  83. package/lib/cjs/utils/index.d.ts +169 -2
  84. package/lib/cjs/utils/index.js +22 -2
  85. package/lib/cjs/utils/utils.d.ts +22 -37
  86. package/lib/cjs/utils/utils.js +64 -135
  87. package/lib/cjs/widgets/CalendarWidget.d.ts +1 -8
  88. package/lib/cjs/widgets/CalendarWidget.js +17 -43
  89. package/lib/mjs/Element.d.ts +2 -1
  90. package/lib/mjs/Element.js +11 -9
  91. package/lib/mjs/EventEmitter.js +2 -2
  92. package/lib/mjs/Form.js +1 -1
  93. package/lib/mjs/PDF.js +1 -1
  94. package/lib/mjs/PDFBuilder.d.ts +1 -0
  95. package/lib/mjs/PDFBuilder.js +9 -10
  96. package/lib/mjs/Webform.d.ts +2 -2
  97. package/lib/mjs/Webform.js +7 -7
  98. package/lib/mjs/WebformBuilder.d.ts +1 -1
  99. package/lib/mjs/WebformBuilder.js +36 -13
  100. package/lib/mjs/Wizard.d.ts +1 -2
  101. package/lib/mjs/Wizard.js +17 -23
  102. package/lib/mjs/WizardBuilder.js +1 -1
  103. package/lib/mjs/components/_classes/component/Component.d.ts +0 -1
  104. package/lib/mjs/components/_classes/component/Component.js +28 -12
  105. package/lib/mjs/components/_classes/component/editForm/Component.edit.conditional.js +1 -1
  106. package/lib/mjs/components/_classes/component/editForm/Component.edit.logic.js +1 -1
  107. package/lib/mjs/components/_classes/componentModal/ComponentModal.js +1 -1
  108. package/lib/mjs/components/_classes/input/Input.d.ts +1 -1
  109. package/lib/mjs/components/_classes/input/Input.js +3 -3
  110. package/lib/mjs/components/_classes/list/ListComponent.js +1 -1
  111. package/lib/mjs/components/_classes/nested/NestedComponent.js +7 -7
  112. package/lib/mjs/components/_classes/nestedarray/NestedArrayComponent.js +1 -1
  113. package/lib/mjs/components/_classes/nesteddata/NestedDataComponent.js +1 -1
  114. package/lib/mjs/components/address/Address.js +1 -1
  115. package/lib/mjs/components/alert/Alert.js +1 -1
  116. package/lib/mjs/components/button/Button.js +1 -1
  117. package/lib/mjs/components/checkbox/Checkbox.js +1 -1
  118. package/lib/mjs/components/container/Container.js +1 -1
  119. package/lib/mjs/components/currency/Currency.js +1 -1
  120. package/lib/mjs/components/datagrid/DataGrid.js +1 -1
  121. package/lib/mjs/components/datamap/DataMap.js +7 -2
  122. package/lib/mjs/components/datetime/DateTime.d.ts +1 -1
  123. package/lib/mjs/components/datetime/DateTime.js +15 -13
  124. package/lib/mjs/components/day/Day.js +2 -2
  125. package/lib/mjs/components/editgrid/EditGrid.js +1 -1
  126. package/lib/mjs/components/editgrid/editForm/EditGrid.edit.display.js +1 -1
  127. package/lib/mjs/components/fieldset/Fieldset.js +1 -0
  128. package/lib/mjs/components/file/File.js +1 -1
  129. package/lib/mjs/components/form/Form.js +13 -2
  130. package/lib/mjs/components/form/editForm/Form.edit.form.js +3 -2
  131. package/lib/mjs/components/number/Number.js +1 -1
  132. package/lib/mjs/components/panel/Panel.js +1 -1
  133. package/lib/mjs/components/radio/Radio.d.ts +8 -0
  134. package/lib/mjs/components/radio/Radio.js +16 -6
  135. package/lib/mjs/components/recaptcha/editForm/ReCaptcha.edit.display.js +1 -1
  136. package/lib/mjs/components/select/Select.d.ts +1 -0
  137. package/lib/mjs/components/select/Select.js +20 -4
  138. package/lib/mjs/components/select/editForm/Select.edit.data.js +1 -1
  139. package/lib/mjs/components/selectboxes/SelectBoxes.d.ts +6 -0
  140. package/lib/mjs/components/selectboxes/SelectBoxes.js +1 -1
  141. package/lib/mjs/components/signature/Signature.js +1 -1
  142. package/lib/mjs/components/survey/Survey.js +1 -1
  143. package/lib/mjs/components/tags/Tags.js +1 -1
  144. package/lib/mjs/components/textarea/TextArea.js +9 -4
  145. package/lib/mjs/components/textfield/TextField.js +7 -2
  146. package/lib/mjs/components/time/Time.js +1 -1
  147. package/lib/mjs/formio.form.js +3 -3
  148. package/lib/mjs/providers/storage/uploadAdapter.js +1 -1
  149. package/lib/mjs/translations/en.d.ts +1 -232
  150. package/lib/mjs/translations/en.js +8 -47
  151. package/lib/mjs/utils/Evaluator.d.ts +20 -6
  152. package/lib/mjs/utils/Evaluator.js +31 -13
  153. package/lib/mjs/utils/builder.js +1 -1
  154. package/lib/mjs/utils/conditionOperators/IsEqualTo.js +1 -1
  155. package/lib/mjs/utils/formUtils.d.ts +2 -2
  156. package/lib/mjs/utils/index.d.ts +169 -2
  157. package/lib/mjs/utils/index.js +18 -1
  158. package/lib/mjs/utils/utils.d.ts +22 -37
  159. package/lib/mjs/utils/utils.js +57 -109
  160. package/lib/mjs/widgets/CalendarWidget.d.ts +1 -8
  161. package/lib/mjs/widgets/CalendarWidget.js +17 -43
  162. package/package.json +5 -5
  163. package/lib/cjs/i18n.d.ts +0 -13
  164. package/lib/cjs/i18n.js +0 -19
  165. package/lib/cjs/utils/i18n.d.ts +0 -19
  166. package/lib/cjs/utils/i18n.js +0 -120
  167. package/lib/mjs/i18n.d.ts +0 -13
  168. package/lib/mjs/i18n.js +0 -14
  169. package/lib/mjs/utils/i18n.d.ts +0 -19
  170. package/lib/mjs/utils/i18n.js +0 -112
@@ -170,10 +170,11 @@ export default class Element {
170
170
  /**
171
171
  * Translate a text using the i18n system.
172
172
  * @param {string|Array<string>} text - The i18n identifier.
173
+ * @param {any} data - contextual data object containing data, component, row, etc.
173
174
  * @param {...any} args - The arguments to pass to the i18n translation.
174
175
  * @returns {string} - The translated text.
175
176
  */
176
- t(text: string | Array<string>, ...args: any[]): string;
177
+ t(text: string | Array<string>, data: any, ...args: any[]): string;
177
178
  /**
178
179
  * Alias to create a text node.
179
180
  * @param {string} text - The text to create.
@@ -1,38 +1,16 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
4
  };
28
5
  Object.defineProperty(exports, "__esModule", { value: true });
29
- const EventEmitter_1 = __importDefault(require("./EventEmitter"));
30
- const Formio_1 = require("./Formio");
31
- const FormioUtils = __importStar(require("./utils/utils"));
32
- const i18n_1 = require("./utils/i18n");
33
6
  const lodash_1 = __importDefault(require("lodash"));
34
7
  const moment_1 = __importDefault(require("moment"));
35
8
  const vanilla_text_mask_1 = __importDefault(require("@formio/vanilla-text-mask"));
9
+ const EventEmitter_1 = __importDefault(require("./EventEmitter"));
10
+ const Formio_1 = require("./Formio");
11
+ const utils_1 = __importDefault(require("./utils"));
12
+ const core_1 = require("@formio/core");
13
+ const en_1 = __importDefault(require("./translations/en"));
36
14
  /**
37
15
  * The root component for all elements within the Form.io renderer.
38
16
  */
@@ -56,7 +34,7 @@ class Element {
56
34
  * can also be provided from the component.id value passed into the constructor.
57
35
  * @type {string}
58
36
  */
59
- this.id = FormioUtils.getRandomComponentId();
37
+ this.id = utils_1.default.getRandomComponentId();
60
38
  /**
61
39
  * An array of event handlers so that the destry command can deregister them.
62
40
  * @type {Array}
@@ -67,7 +45,7 @@ class Element {
67
45
  if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.language) {
68
46
  this.options.i18n.language = this.options.language;
69
47
  }
70
- this.options.i18next = this.i18next = this.options.i18next || i18n_1.I18n.init(this.options.i18n);
48
+ this.options.i18next = this.i18next = this.options.i18next || core_1.I18n.init(Object.assign({ en: en_1.default }, this.options.i18n));
71
49
  /**
72
50
  * An instance of the EventEmitter class to handle the emitting and registration of events.
73
51
  * @type {EventEmitter}
@@ -385,7 +363,7 @@ class Element {
385
363
  */
386
364
  setInputMask(input, inputMask, usePlaceholder) {
387
365
  if (input && inputMask) {
388
- const mask = FormioUtils.getInputMask(inputMask, this.placeholderChar);
366
+ const mask = utils_1.default.getInputMask(inputMask, this.placeholderChar);
389
367
  this.defaultMask = mask;
390
368
  try {
391
369
  //destroy previous mask
@@ -415,11 +393,12 @@ class Element {
415
393
  /**
416
394
  * Translate a text using the i18n system.
417
395
  * @param {string|Array<string>} text - The i18n identifier.
396
+ * @param {any} data - contextual data object containing data, component, row, etc.
418
397
  * @param {...any} args - The arguments to pass to the i18n translation.
419
398
  * @returns {string} - The translated text.
420
399
  */
421
- t(text, ...args) {
422
- return this.i18next ? this.i18next.t(text, ...args) : text;
400
+ t(text, data, ...args) {
401
+ return this.i18next ? this.i18next.t(text, data, ...args) : text;
423
402
  }
424
403
  /**
425
404
  * Alias to create a text node.
@@ -522,8 +501,8 @@ class Element {
522
501
  var _a;
523
502
  return Object.assign({
524
503
  _: lodash_1.default,
525
- utils: FormioUtils,
526
- util: FormioUtils,
504
+ utils: utils_1.default,
505
+ util: utils_1.default,
527
506
  user: Formio_1.Formio.getUser(),
528
507
  moment: moment_1.default,
529
508
  instance: this,
@@ -548,15 +527,15 @@ class Element {
548
527
  */
549
528
  interpolate(string, data, options = {}) {
550
529
  if (typeof string !== 'function' && (this.component.content || this.component.html)
551
- && !FormioUtils.Evaluator.templateSettings.interpolate.test(string)) {
552
- string = FormioUtils.translateHTMLTemplate(String(string), (value) => this.t(value));
530
+ && !utils_1.default.Evaluator.templateSettings.interpolate.test(string)) {
531
+ string = utils_1.default.translateHTMLTemplate(String(string), (value) => this.t(value));
553
532
  }
554
533
  if (this.component.filter === string && !this.options.building) {
555
534
  const evalContext = this.evalContext(data);
556
535
  evalContext.data = lodash_1.default.mapValues(evalContext.data, (val) => lodash_1.default.isString(val) ? encodeURIComponent(val) : val);
557
- return FormioUtils.interpolate(string, evalContext, options);
536
+ return utils_1.default.Evaluator.interpolate(string, evalContext, options);
558
537
  }
559
- return FormioUtils.interpolate(string, this.evalContext(data), options);
538
+ return utils_1.default.Evaluator.interpolate(string, this.evalContext(data), options);
560
539
  }
561
540
  /**
562
541
  * Performs an evaluation using the evaluation context of this component.
@@ -568,7 +547,7 @@ class Element {
568
547
  * @returns {*} - The result of the evaluation.
569
548
  */
570
549
  evaluate(func, args, ret, interpolate, options = {}) {
571
- return FormioUtils.evaluate(func, this.evalContext(args), ret, interpolate, options);
550
+ return utils_1.default.evaluate(func, this.evalContext(args), ret, interpolate, options);
572
551
  }
573
552
  /**
574
553
  * Allow for options to hook into the functionality of this renderer.
@@ -1,30 +1,7 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
3
  const eventemitter3_1 = require("eventemitter3");
27
- const utils = __importStar(require("./utils/utils"));
4
+ const utils_1 = require("./utils");
28
5
  class EventEmitter extends eventemitter3_1.EventEmitter {
29
6
  constructor(conf = {}) {
30
7
  const { loadLimit = 1000, eventsSafeInterval = 300 } = conf;
@@ -38,7 +15,7 @@ class EventEmitter extends eventemitter3_1.EventEmitter {
38
15
  const overloadHandler = () => {
39
16
  console.warn(`There were more than ${loadLimit} events emitted in ${eventsSafeInterval} ms. It might be caused by events' infinite loop`, this.id);
40
17
  };
41
- const dispatch = utils.observeOverload(overloadHandler, {
18
+ const dispatch = (0, utils_1.observeOverload)(overloadHandler, {
42
19
  limit: loadLimit,
43
20
  delay: eventsSafeInterval
44
21
  });
package/lib/cjs/Form.js CHANGED
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
4
  };
@@ -30,7 +7,7 @@ const Element_1 = __importDefault(require("./Element"));
30
7
  const Formio_1 = require("./Formio");
31
8
  const displays_1 = __importDefault(require("./displays"));
32
9
  const templates_1 = __importDefault(require("./templates"));
33
- const FormioUtils = __importStar(require("./utils/utils"));
10
+ const utils_1 = __importDefault(require("./utils"));
34
11
  class Form extends Element_1.default {
35
12
  constructor(elementOrForm, formOrOptions, options = {}) {
36
13
  let element, form, formOptions;
@@ -324,7 +301,7 @@ class Form extends Element_1.default {
324
301
  if (this.options.sanitize === false && !forceSanitize) {
325
302
  return dirty;
326
303
  }
327
- return FormioUtils.sanitize(dirty, this.options);
304
+ return utils_1.default.sanitize(dirty, this.options);
328
305
  }
329
306
  setContent(element, content, forceSanitize) {
330
307
  if (element instanceof HTMLElement) {
package/lib/cjs/PDF.js CHANGED
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const Formio_1 = require("./Formio");
7
7
  const Webform_1 = __importDefault(require("./Webform"));
8
- const utils_1 = require("./utils/utils");
8
+ const utils_1 = require("./utils");
9
9
  class PDF extends Webform_1.default {
10
10
  constructor(element, options) {
11
11
  options.display = 'pdf';
@@ -51,5 +51,6 @@ export default class PDFBuilder extends WebformBuilder {
51
51
  onDropzoneDrop(e: any): boolean;
52
52
  dropEvent: any;
53
53
  onDragEnd(e: any): void;
54
+ repeatablePathsComps: any[] | undefined;
54
55
  }
55
56
  import WebformBuilder from './WebformBuilder';
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const lodash_1 = __importDefault(require("lodash"));
7
7
  const Formio_1 = require("./Formio");
8
8
  const WebformBuilder_1 = __importDefault(require("./WebformBuilder"));
9
- const utils_1 = require("./utils/utils");
10
- const formUtils_1 = require("./utils/formUtils");
9
+ const utils_1 = require("./utils");
11
10
  const builder_1 = __importDefault(require("./utils/builder"));
12
11
  const PDF_1 = __importDefault(require("./PDF"));
13
12
  class PDFBuilder extends WebformBuilder_1.default {
@@ -272,7 +271,7 @@ class PDFBuilder extends WebformBuilder_1.default {
272
271
  getParentContainer(component) {
273
272
  let container = [];
274
273
  let originalComponent = null;
275
- (0, formUtils_1.eachComponent)(this.webform._form.components, (comp, path, components) => {
274
+ (0, utils_1.eachComponent)(this.webform._form.components, (comp, path, components) => {
276
275
  if (comp.id === component.component.id) {
277
276
  container = components;
278
277
  originalComponent = comp;
@@ -452,21 +451,21 @@ class PDFBuilder extends WebformBuilder_1.default {
452
451
  e.target.style.cursor = 'default';
453
452
  }
454
453
  highlightInvalidComponents() {
455
- const repeatablePaths = this.findRepeatablePaths();
454
+ const repeatablePathsComps = this.findComponentsWithRepeatablePaths();
456
455
  // update elements which path was duplicated if any pathes have been changed
457
- if (!lodash_1.default.isEqual(this.repeatablePaths, repeatablePaths)) {
458
- (0, formUtils_1.eachComponent)(this.webform.getComponents(), (comp, path) => {
459
- if (this.repeatablePaths.includes(path)) {
456
+ if (!lodash_1.default.isEqual(this.repeatablePathsComps, repeatablePathsComps)) {
457
+ (0, utils_1.eachComponent)(this.webform.getComponents(), (comp) => {
458
+ if (this.repeatablePathsComps.includes(comp.component)) {
460
459
  this.webform.postMessage({ name: 'updateElement', data: comp.component });
461
460
  }
462
461
  });
463
- this.repeatablePaths = repeatablePaths;
462
+ this.repeatablePathsComps = repeatablePathsComps;
464
463
  }
465
- if (!repeatablePaths.length) {
464
+ if (!repeatablePathsComps.length) {
466
465
  return;
467
466
  }
468
- (0, formUtils_1.eachComponent)(this.webform.getComponents(), (comp, path) => {
469
- if (this.repeatablePaths.includes(path)) {
467
+ (0, utils_1.eachComponent)(this.webform.getComponents(), (comp) => {
468
+ if (this.repeatablePathsComps.includes(comp)) {
470
469
  this.webform.postMessage({
471
470
  name: 'showBuilderErrors',
472
471
  data: {
@@ -45,7 +45,7 @@
45
45
  * @property {number} [saveDraftThrottle] - The throttle for the save draft feature.
46
46
  * @property {boolean} [readOnly] - Set this form to readOnly.
47
47
  * @property {boolean} [noAlerts] - Disable the alerts dialog.
48
- * @property {{[key: string]: string}} [i18n] - The translation file for this rendering.
48
+ * @property {{[key: string]: string}} [enTranslation] - The translation file for this rendering.
49
49
  * @property {string} [template] - Custom logic for creation of elements.
50
50
  * @property {boolean} [noDefaults] - Exclude default values from the settings.
51
51
  * @property {any} [fileService] - The file service for this form.
@@ -586,7 +586,7 @@ export type FormOptions = {
586
586
  /**
587
587
  * - The translation file for this rendering.
588
588
  */
589
- i18n?: {
589
+ enTranslation?: {
590
590
  [key: string]: string;
591
591
  } | undefined;
592
592
  /**
@@ -4,15 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const lodash_1 = __importDefault(require("lodash"));
7
- const moment_1 = __importDefault(require("moment"));
8
7
  const compare_versions_1 = require("compare-versions");
9
8
  const EventEmitter_1 = __importDefault(require("./EventEmitter"));
10
- const i18n_1 = __importDefault(require("./i18n"));
9
+ const en_1 = __importDefault(require("./translations/en"));
11
10
  const Formio_1 = require("./Formio");
12
11
  const Components_1 = __importDefault(require("./components/Components"));
13
12
  const NestedDataComponent_1 = __importDefault(require("./components/_classes/nesteddata/NestedDataComponent"));
14
- const utils_1 = require("./utils/utils");
15
- const formUtils_1 = require("./utils/formUtils");
13
+ const utils_1 = require("./utils");
14
+ const dayjs_1 = __importDefault(require("dayjs"));
16
15
  // We need this here because dragula pulls in CustomEvent class that requires global to exist.
17
16
  if (typeof window !== 'undefined' && typeof window.global === 'undefined') {
18
17
  window.global = window;
@@ -100,7 +99,7 @@ function getOptions(options) {
100
99
  * @property {number} [saveDraftThrottle] - The throttle for the save draft feature.
101
100
  * @property {boolean} [readOnly] - Set this form to readOnly.
102
101
  * @property {boolean} [noAlerts] - Disable the alerts dialog.
103
- * @property {{[key: string]: string}} [i18n] - The translation file for this rendering.
102
+ * @property {{[key: string]: string}} [enTranslation] - The translation file for this rendering.
104
103
  * @property {string} [template] - Custom logic for creation of elements.
105
104
  * @property {boolean} [noDefaults] - Exclude default values from the settings.
106
105
  * @property {any} [fileService] - The file service for this form.
@@ -370,7 +369,7 @@ class Webform extends NestedDataComponent_1.default {
370
369
  */
371
370
  addLanguage(code, lang, active = false) {
372
371
  if (this.i18next) {
373
- var translations = lodash_1.default.assign((0, utils_1.fastCloneDeep)(i18n_1.default.resources.en.translation), lang);
372
+ var translations = lodash_1.default.assign((0, utils_1.fastCloneDeep)(en_1.default), lang);
374
373
  this.i18next.addResourceBundle(code, 'translation', translations, true, true);
375
374
  if (active) {
376
375
  this.language = code;
@@ -992,7 +991,7 @@ class Webform extends NestedDataComponent_1.default {
992
991
  }
993
992
  hasRequiredFields() {
994
993
  let result = false;
995
- (0, formUtils_1.eachComponent)(this.form.components, (component) => {
994
+ (0, utils_1.eachComponent)(this.form.components, (component) => {
996
995
  if (component.validate.required) {
997
996
  result = true;
998
997
  return true;
@@ -1314,13 +1313,14 @@ class Webform extends NestedDataComponent_1.default {
1314
1313
  submission.metadata = submission.metadata || {};
1315
1314
  lodash_1.default.defaults(submission.metadata, {
1316
1315
  timezone: lodash_1.default.get(this, '_submission.metadata.timezone', (0, utils_1.currentTimezone)()),
1317
- offset: parseInt(lodash_1.default.get(this, '_submission.metadata.offset', (0, moment_1.default)().utcOffset()), 10),
1316
+ offset: parseInt(lodash_1.default.get(this, '_submission.metadata.offset', (0, dayjs_1.default)().utcOffset()), 10),
1318
1317
  origin: document.location.origin,
1319
1318
  referrer: document.referrer,
1320
1319
  browserName: navigator.appName,
1321
1320
  userAgent: navigator.userAgent,
1322
1321
  pathName: window.location.pathname,
1323
1322
  onLine: navigator.onLine,
1323
+ language: this.language,
1324
1324
  });
1325
1325
  }
1326
1326
  submitForm(options = {}, local = false) {
@@ -1538,7 +1538,7 @@ class Webform extends NestedDataComponent_1.default {
1538
1538
  return;
1539
1539
  }
1540
1540
  const captchaComponent = [];
1541
- (0, formUtils_1.eachComponent)(components || this.components, (component) => {
1541
+ (0, utils_1.eachComponent)(components || this.components, (component) => {
1542
1542
  if (/^(re)?captcha$/.test(component.type) && component.component.eventType === 'formLoad') {
1543
1543
  captchaComponent.push(component);
1544
1544
  }
@@ -78,7 +78,7 @@ export default class WebformBuilder extends Component {
78
78
  replaceDoubleQuotes(data: any, fieldsToRemoveDoubleQuotes?: any[]): any;
79
79
  updateComponent(component: any, changed: any): void;
80
80
  originalDefaultValue: any;
81
- findRepeatablePaths(): any[];
81
+ findComponentsWithRepeatablePaths(): any[];
82
82
  highlightInvalidComponents(): void;
83
83
  /**
84
84
  * Called when a new component is saved.
@@ -8,8 +8,7 @@ const Component_1 = __importDefault(require("./components/_classes/component/Com
8
8
  const tippy_js_1 = __importDefault(require("tippy.js"));
9
9
  const Components_1 = __importDefault(require("./components/Components"));
10
10
  const Formio_1 = require("./Formio");
11
- const utils_1 = require("./utils/utils");
12
- const formUtils_1 = require("./utils/formUtils");
11
+ const utils_1 = require("./utils");
13
12
  const builder_1 = __importDefault(require("./utils/builder"));
14
13
  const lodash_1 = __importDefault(require("lodash"));
15
14
  const dom_autoscroller_1 = __importDefault(require("dom-autoscroller"));
@@ -284,7 +283,7 @@ class WebformBuilder extends Component_1.default {
284
283
  componentOrder: [],
285
284
  default: index === 0,
286
285
  };
287
- (0, formUtils_1.eachComponent)(resource.components, (component) => {
286
+ (0, utils_1.eachComponent)(resource.components, (component) => {
288
287
  if (component.type === 'button')
289
288
  return;
290
289
  if (this.options &&
@@ -450,7 +449,7 @@ class WebformBuilder extends Component_1.default {
450
449
  return [...componentSchema.components, componentSchema];
451
450
  }
452
451
  // Get the namespace component so we have the original object.
453
- const namespaceComponent = (0, formUtils_1.getComponent)(this.form.components, namespaceKey, true);
452
+ const namespaceComponent = (0, utils_1.getComponent)(this.form.components, namespaceKey, true);
454
453
  return namespaceComponent ? namespaceComponent.components : comp.components;
455
454
  }
456
455
  recurseNamespace(component) {
@@ -812,7 +811,7 @@ class WebformBuilder extends Component_1.default {
812
811
  const draggableComponent = ((_a = this.groups[group]) === null || _a === void 0 ? void 0 : _a.components[compKey]) || {};
813
812
  if (draggableComponent.disableSiblings || draggableComponent.uniqueComponent) {
814
813
  let isCompAlreadyExists = false;
815
- (0, formUtils_1.eachComponent)(this.webform.components, (component) => {
814
+ (0, utils_1.eachComponent)(this.webform.components, (component) => {
816
815
  if ((draggableComponent.disableSiblings && component.type === draggableComponent.schema.type) ||
817
816
  (draggableComponent.uniqueComponent && component.component.key === draggableComponent.schema.key)) {
818
817
  isCompAlreadyExists = true;
@@ -947,7 +946,7 @@ class WebformBuilder extends Component_1.default {
947
946
  //populate isEnabled for captcha form settings
948
947
  let isCaptchaEnabled = false;
949
948
  if (this.form.components) {
950
- (0, formUtils_1.eachComponent)(form.components, component => {
949
+ (0, utils_1.eachComponent)(form.components, component => {
951
950
  if (isCaptchaEnabled) {
952
951
  return;
953
952
  }
@@ -1042,7 +1041,7 @@ class WebformBuilder extends Component_1.default {
1042
1041
  }
1043
1042
  }
1044
1043
  // Change the "default value" field to be reflective of this component.
1045
- const defaultValueComponent = (0, formUtils_1.getComponent)(this.editForm.components, 'defaultValue', true);
1044
+ const defaultValueComponent = (0, utils_1.getComponent)(this.editForm.components, 'defaultValue', true);
1046
1045
  if (defaultValueComponent && component.type !== 'hidden') {
1047
1046
  const defaultChanged = changed && ((changed.component && changed.component.key === 'defaultValue')
1048
1047
  || (changed.instance && defaultValueComponent.hasComponent && defaultValueComponent.hasComponent(changed.instance)));
@@ -1074,7 +1073,7 @@ class WebformBuilder extends Component_1.default {
1074
1073
  if (!this.originalDefaultValue) {
1075
1074
  this.originalDefaultValue = (0, utils_1.fastCloneDeep)(defaultValueComponent.component);
1076
1075
  }
1077
- (0, formUtils_1.eachComponent)(defaultValueComponent.component.components, (comp => {
1076
+ (0, utils_1.eachComponent)(defaultValueComponent.component.components, (comp => {
1078
1077
  var _a;
1079
1078
  if ((_a = comp.validate) === null || _a === void 0 ? void 0 : _a.required) {
1080
1079
  comp.validate.required = false;
@@ -1126,28 +1125,53 @@ class WebformBuilder extends Component_1.default {
1126
1125
  // Called when we update a component.
1127
1126
  this.emit('updateComponent', component);
1128
1127
  }
1129
- findRepeatablePaths() {
1130
- const repeatablePaths = [];
1128
+ findComponentsWithRepeatablePaths() {
1129
+ const repeatablePaths = {};
1131
1130
  const keys = new Map();
1132
- (0, formUtils_1.eachComponent)(this.form.components, (comp, path, components, parent, paths) => {
1133
- if (keys.has(paths.dataPath)) {
1134
- repeatablePaths.push(paths.dataPath);
1135
- }
1136
- else {
1137
- keys.set(paths.dataPath, true);
1131
+ (0, utils_1.eachComponent)(this.form.components, (comp, path, components, parent, paths) => {
1132
+ var _a, _b;
1133
+ const isRadioCheckbox = comp.type === 'checkbox' && comp.inputType === 'radio';
1134
+ const isLayout = (0, utils_1.componentInfo)(comp).layout;
1135
+ if (!isLayout) {
1136
+ if (keys.has(paths.dataPath)) {
1137
+ const onlyRadioCheckboxes = ((_a = repeatablePaths[paths.dataPath]) === null || _a === void 0 ? void 0 : _a.onlyRadioCheckboxes) === false ? false : isRadioCheckbox;
1138
+ repeatablePaths[paths.dataPath] = {
1139
+ comps: [...(((_b = repeatablePaths[paths.dataPath]) === null || _b === void 0 ? void 0 : _b.comps) || []), keys.get(paths.dataPath), comp],
1140
+ onlyRadioCheckboxes,
1141
+ };
1142
+ }
1143
+ else {
1144
+ keys.set(paths.dataPath, comp);
1145
+ }
1138
1146
  }
1139
1147
  }, true);
1140
- return repeatablePaths;
1148
+ const componentsWithRepeatablePaths = [];
1149
+ Object.keys(repeatablePaths).forEach((path) => {
1150
+ const { comps, onlyRadioCheckboxes } = repeatablePaths[path];
1151
+ if (!onlyRadioCheckboxes) {
1152
+ componentsWithRepeatablePaths.push(...comps);
1153
+ }
1154
+ });
1155
+ return componentsWithRepeatablePaths;
1141
1156
  }
1142
1157
  highlightInvalidComponents() {
1143
- const repeatablePaths = this.findRepeatablePaths();
1158
+ const repeatablePathsComps = this.findComponentsWithRepeatablePaths();
1144
1159
  let hasInvalidComponents = false;
1160
+ // Matches anything expect letters and '_' at the beginning of the key and anything except of letters, numbers,
1161
+ // '-', '.' and '_' in the rest of the key
1162
+ const badCharacters = /^[^A-Za-z_]+|[^A-Za-z0-9\-._]+/g;
1145
1163
  this.webform.everyComponent((comp) => {
1146
- const path = comp.path;
1147
- if (repeatablePaths.includes(path)) {
1164
+ if (repeatablePathsComps.includes(comp.component)) {
1148
1165
  comp.setCustomValidity(this.t('apiKey', { key: comp.key }));
1149
1166
  hasInvalidComponents = true;
1150
1167
  }
1168
+ else if (comp.key.replace(badCharacters, '') === '') {
1169
+ comp.setCustomValidity(this.t('apiKeyNotValid', { key: comp.key }));
1170
+ hasInvalidComponents = true;
1171
+ }
1172
+ else {
1173
+ comp.setCustomValidity();
1174
+ }
1151
1175
  });
1152
1176
  this.emit('builderFormValidityChange', hasInvalidComponents);
1153
1177
  }
@@ -1641,7 +1665,7 @@ class WebformBuilder extends Component_1.default {
1641
1665
  if (!Components_1.default.components[type === 'custom' ? 'unknown' : type]) {
1642
1666
  return false;
1643
1667
  }
1644
- const editTabs = (0, formUtils_1.getComponent)(Components_1.default.components[type === 'custom' ? 'unknown' : type].editForm().components, 'tabs', true).components;
1668
+ const editTabs = (0, utils_1.getComponent)(Components_1.default.components[type === 'custom' ? 'unknown' : type].editForm().components, 'tabs', true).components;
1645
1669
  const hiddenEditTabs = lodash_1.default.filter(lodash_1.default.get(this.options, `editForm.${type}`, []), 'ignore');
1646
1670
  return lodash_1.default.intersectionBy(editTabs, hiddenEditTabs, 'key').length !== editTabs.length;
1647
1671
  }
@@ -6,7 +6,6 @@ declare class Wizard extends Webform {
6
6
  originalComponents: any[];
7
7
  page: number;
8
8
  currentPanel: any;
9
- currentPanels: any[] | null;
10
9
  currentNextPage: number;
11
10
  _seenPages: number[];
12
11
  subWizards: any[];
@@ -17,7 +16,7 @@ declare class Wizard extends Webform {
17
16
  originalOptions: any;
18
17
  isLastPage(): any;
19
18
  getPages(args?: {}): any[];
20
- get hasExtraPages(): boolean;
19
+ get hasSubWizards(): boolean;
21
20
  get localData(): any;
22
21
  get wizardKey(): string;
23
22
  set wizard(form: object);
package/lib/cjs/Wizard.js CHANGED
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const lodash_1 = __importDefault(require("lodash"));
7
7
  const Webform_1 = __importDefault(require("./Webform"));
8
8
  const Formio_1 = require("./Formio");
9
- const utils_1 = require("./utils/utils");
9
+ const utils_1 = require("./utils");
10
10
  class Wizard extends Webform_1.default {
11
11
  /**
12
12
  * Constructor for wizard-based forms.
@@ -34,7 +34,6 @@ class Wizard extends Webform_1.default {
34
34
  this.originalComponents = [];
35
35
  this.page = 0;
36
36
  this.currentPanel = null;
37
- this.currentPanels = null;
38
37
  this.currentNextPage = 0;
39
38
  this._seenPages = [0];
40
39
  this.subWizards = [];
@@ -53,12 +52,12 @@ class Wizard extends Webform_1.default {
53
52
  }
54
53
  getPages(args = {}) {
55
54
  const { all = false } = args;
56
- const pages = this.hasExtraPages ? this.components : this.pages;
55
+ const pages = this.hasSubWizards ? this.components : this.pages;
57
56
  const filteredPages = pages
58
57
  .filter(all ? lodash_1.default.identity : (p, index) => this._seenPages.includes(index));
59
58
  return filteredPages;
60
59
  }
61
- get hasExtraPages() {
60
+ get hasSubWizards() {
62
61
  return !lodash_1.default.isEmpty(this.subWizards);
63
62
  }
64
63
  get data() {
@@ -187,9 +186,9 @@ class Wizard extends Webform_1.default {
187
186
  }
188
187
  render() {
189
188
  const ctx = this.renderContext;
190
- if (this.component.key) {
191
- ctx.panels.map(panel => {
192
- if (panel.key === this.component.key) {
189
+ if (this.component.id) {
190
+ ctx.panels.forEach(panel => {
191
+ if (panel.id === this.component.id) {
193
192
  this.currentPanel = panel;
194
193
  ctx.wizardPageTooltip = this.getFormattedTooltip(panel.tooltip);
195
194
  }
@@ -587,7 +586,7 @@ class Wizard extends Webform_1.default {
587
586
  this.pageFieldLogic(num);
588
587
  this.getNextPage();
589
588
  let parentNum = num;
590
- if (this.hasExtraPages) {
589
+ if (this.hasSubWizards) {
591
590
  const pageFromPages = this.pages[num];
592
591
  const pageFromComponents = this.components[num];
593
592
  if (!pageFromComponents || (pageFromPages === null || pageFromPages === void 0 ? void 0 : pageFromPages.id) !== pageFromComponents.id) {
@@ -873,7 +872,7 @@ class Wizard extends Webform_1.default {
873
872
  }
874
873
  }
875
874
  onChange(flags, changed, modified, changes) {
876
- var _a, _b;
875
+ var _a;
877
876
  super.onChange(flags, changed, modified, changes);
878
877
  // The onChange loop doesn't need all components for wizards
879
878
  const errors = this.submitted ? this.validate(this.localData, { dirty: true }) : this.validateCurrentPage();
@@ -881,23 +880,18 @@ class Wizard extends Webform_1.default {
881
880
  this.showErrors(errors, true, true);
882
881
  }
883
882
  // If the pages change, need to redraw the header.
884
- let currentPanels;
885
- let panels;
883
+ const currentPanels = this.pages;
884
+ // calling this.establishPages() updates/mutates this.pages to be the current pages
885
+ this.establishPages();
886
+ const newPanels = this.pages;
886
887
  const currentNextPage = this.currentNextPage;
887
- if (this.hasExtraPages) {
888
- currentPanels = this.pages.map(page => page.component.key);
889
- this.establishPages();
890
- panels = this.pages.map(page => page.component.key);
891
- }
892
- else {
893
- currentPanels = this.currentPanels || this.pages.map(page => page.component.key);
894
- panels = this.establishPages().map(panel => panel.key);
895
- this.currentPanels = panels;
896
- if (((_a = this.currentPanel) === null || _a === void 0 ? void 0 : _a.key) && ((_b = this.currentPanels) === null || _b === void 0 ? void 0 : _b.length)) {
897
- this.setPage(this.currentPanels.findIndex(panel => panel === this.currentPanel.key));
898
- }
888
+ const panelsUpdated = !lodash_1.default.isEqual(newPanels, currentPanels);
889
+ if (((_a = this.currentPanel) === null || _a === void 0 ? void 0 : _a.id) && this.pages.length && (!this.hasSubWizards || (this.hasSubWizards && panelsUpdated))) {
890
+ const newIndex = this.pages.findIndex(page => page.id === this.currentPanel.id);
891
+ if (newIndex !== -1)
892
+ this.setPage(newIndex);
899
893
  }
900
- if (!lodash_1.default.isEqual(panels, currentPanels) || (flags && flags.fromSubmission)) {
894
+ if (panelsUpdated || (flags && flags.fromSubmission)) {
901
895
  this.redrawHeader();
902
896
  }
903
897
  // If the next page changes, then make sure to redraw navigation.