@formio/js 5.1.0-dev.6042.18ef5d3 → 5.1.0-dev.6042.603237d

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 (156) hide show
  1. package/Changelog.md +57 -402
  2. package/README.md +7 -0
  3. package/dist/formio.builder.css +1 -0
  4. package/dist/formio.builder.min.css +1 -1
  5. package/dist/formio.form.css +1 -0
  6. package/dist/formio.form.js +104 -126
  7. package/dist/formio.form.min.css +1 -1
  8. package/dist/formio.form.min.js +1 -1
  9. package/dist/formio.form.min.js.LICENSE.txt +3 -1
  10. package/dist/formio.full.css +1 -0
  11. package/dist/formio.full.js +111 -133
  12. package/dist/formio.full.min.css +1 -1
  13. package/dist/formio.full.min.js +1 -1
  14. package/dist/formio.full.min.js.LICENSE.txt +3 -1
  15. package/dist/formio.js +53 -64
  16. package/dist/formio.min.js +1 -1
  17. package/dist/formio.utils.js +66 -77
  18. package/dist/formio.utils.min.js +1 -1
  19. package/dist/formio.utils.min.js.LICENSE.txt +3 -1
  20. package/lib/cjs/Element.js +13 -36
  21. package/lib/cjs/EventEmitter.js +2 -25
  22. package/lib/cjs/Form.js +2 -25
  23. package/lib/cjs/PDF.js +1 -1
  24. package/lib/cjs/PDFBuilder.js +4 -5
  25. package/lib/cjs/Webform.js +8 -7
  26. package/lib/cjs/WebformBuilder.d.ts +1 -0
  27. package/lib/cjs/WebformBuilder.js +40 -14
  28. package/lib/cjs/Wizard.d.ts +1 -2
  29. package/lib/cjs/Wizard.js +18 -24
  30. package/lib/cjs/WizardBuilder.js +1 -1
  31. package/lib/cjs/components/_classes/component/Component.d.ts +26 -2
  32. package/lib/cjs/components/_classes/component/Component.js +97 -88
  33. package/lib/cjs/components/_classes/component/editForm/Component.edit.conditional.js +1 -1
  34. package/lib/cjs/components/_classes/component/editForm/Component.edit.logic.js +1 -1
  35. package/lib/cjs/components/_classes/componentModal/ComponentModal.js +1 -1
  36. package/lib/cjs/components/_classes/input/Input.js +1 -1
  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.d.ts +1 -1
  44. package/lib/cjs/components/button/Button.js +7 -11
  45. package/lib/cjs/components/checkbox/Checkbox.js +1 -1
  46. package/lib/cjs/components/container/Container.js +1 -1
  47. package/lib/cjs/components/currency/Currency.js +1 -1
  48. package/lib/cjs/components/datagrid/DataGrid.js +5 -1
  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/file/File.js +5 -6
  55. package/lib/cjs/components/form/Form.d.ts +0 -1
  56. package/lib/cjs/components/form/Form.js +26 -22
  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 +4 -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 +3 -3
  72. package/lib/cjs/components/textfield/TextField.js +9 -32
  73. package/lib/cjs/components/time/Time.js +1 -1
  74. package/lib/cjs/formio.form.js +3 -3
  75. package/lib/cjs/providers/storage/uploadAdapter.js +3 -3
  76. package/lib/cjs/translations/en.js +1 -1
  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 +31 -37
  85. package/lib/cjs/utils/utils.js +79 -135
  86. package/lib/cjs/widgets/CalendarWidget.d.ts +1 -8
  87. package/lib/cjs/widgets/CalendarWidget.js +19 -40
  88. package/lib/mjs/Element.js +6 -6
  89. package/lib/mjs/EventEmitter.js +2 -2
  90. package/lib/mjs/Form.js +1 -1
  91. package/lib/mjs/PDF.js +1 -1
  92. package/lib/mjs/PDFBuilder.js +1 -2
  93. package/lib/mjs/Webform.js +6 -5
  94. package/lib/mjs/WebformBuilder.d.ts +1 -0
  95. package/lib/mjs/WebformBuilder.js +32 -7
  96. package/lib/mjs/Wizard.d.ts +1 -2
  97. package/lib/mjs/Wizard.js +17 -23
  98. package/lib/mjs/WizardBuilder.js +1 -1
  99. package/lib/mjs/components/_classes/component/Component.d.ts +26 -2
  100. package/lib/mjs/components/_classes/component/Component.js +70 -38
  101. package/lib/mjs/components/_classes/component/editForm/Component.edit.conditional.js +1 -1
  102. package/lib/mjs/components/_classes/component/editForm/Component.edit.logic.js +1 -1
  103. package/lib/mjs/components/_classes/componentModal/ComponentModal.js +1 -1
  104. package/lib/mjs/components/_classes/input/Input.js +1 -1
  105. package/lib/mjs/components/_classes/list/ListComponent.js +1 -1
  106. package/lib/mjs/components/_classes/nested/NestedComponent.js +7 -7
  107. package/lib/mjs/components/_classes/nestedarray/NestedArrayComponent.js +1 -1
  108. package/lib/mjs/components/_classes/nesteddata/NestedDataComponent.js +1 -1
  109. package/lib/mjs/components/address/Address.js +1 -1
  110. package/lib/mjs/components/alert/Alert.js +1 -1
  111. package/lib/mjs/components/button/Button.d.ts +1 -1
  112. package/lib/mjs/components/button/Button.js +7 -10
  113. package/lib/mjs/components/checkbox/Checkbox.js +1 -1
  114. package/lib/mjs/components/container/Container.js +1 -1
  115. package/lib/mjs/components/currency/Currency.js +1 -1
  116. package/lib/mjs/components/datagrid/DataGrid.js +5 -1
  117. package/lib/mjs/components/datetime/DateTime.d.ts +1 -1
  118. package/lib/mjs/components/datetime/DateTime.js +15 -13
  119. package/lib/mjs/components/day/Day.js +2 -2
  120. package/lib/mjs/components/editgrid/EditGrid.js +1 -1
  121. package/lib/mjs/components/editgrid/editForm/EditGrid.edit.display.js +1 -1
  122. package/lib/mjs/components/file/File.js +5 -6
  123. package/lib/mjs/components/form/Form.d.ts +0 -1
  124. package/lib/mjs/components/form/Form.js +25 -22
  125. package/lib/mjs/components/form/editForm/Form.edit.form.js +3 -2
  126. package/lib/mjs/components/number/Number.js +1 -1
  127. package/lib/mjs/components/panel/Panel.js +1 -1
  128. package/lib/mjs/components/radio/Radio.d.ts +8 -0
  129. package/lib/mjs/components/radio/Radio.js +16 -6
  130. package/lib/mjs/components/recaptcha/editForm/ReCaptcha.edit.display.js +1 -1
  131. package/lib/mjs/components/select/Select.d.ts +1 -0
  132. package/lib/mjs/components/select/Select.js +20 -4
  133. package/lib/mjs/components/select/editForm/Select.edit.data.js +1 -1
  134. package/lib/mjs/components/selectboxes/SelectBoxes.d.ts +6 -0
  135. package/lib/mjs/components/selectboxes/SelectBoxes.js +4 -1
  136. package/lib/mjs/components/signature/Signature.js +1 -1
  137. package/lib/mjs/components/survey/Survey.js +1 -1
  138. package/lib/mjs/components/tags/Tags.js +1 -1
  139. package/lib/mjs/components/textarea/TextArea.js +3 -3
  140. package/lib/mjs/components/textfield/TextField.js +3 -3
  141. package/lib/mjs/components/time/Time.js +1 -1
  142. package/lib/mjs/formio.form.js +2 -2
  143. package/lib/mjs/providers/storage/uploadAdapter.js +3 -3
  144. package/lib/mjs/translations/en.js +3 -0
  145. package/lib/mjs/utils/Evaluator.d.ts +20 -6
  146. package/lib/mjs/utils/Evaluator.js +31 -13
  147. package/lib/mjs/utils/builder.js +1 -1
  148. package/lib/mjs/utils/conditionOperators/IsEqualTo.js +1 -1
  149. package/lib/mjs/utils/formUtils.d.ts +2 -2
  150. package/lib/mjs/utils/index.d.ts +169 -2
  151. package/lib/mjs/utils/index.js +18 -1
  152. package/lib/mjs/utils/utils.d.ts +31 -37
  153. package/lib/mjs/utils/utils.js +71 -109
  154. package/lib/mjs/widgets/CalendarWidget.d.ts +1 -8
  155. package/lib/mjs/widgets/CalendarWidget.js +19 -40
  156. package/package.json +8 -6
@@ -3,11 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const Formio_1 = require("../Formio");
7
- const InputWidget_1 = __importDefault(require("./InputWidget"));
8
- const utils_1 = require("../utils/utils");
9
6
  const moment_1 = __importDefault(require("moment"));
10
7
  const lodash_1 = __importDefault(require("lodash"));
8
+ const Formio_1 = require("../Formio");
9
+ const InputWidget_1 = __importDefault(require("./InputWidget"));
10
+ const utils_1 = require("../utils");
11
11
  const DEFAULT_FORMAT = 'yyyy-MM-dd hh:mm a';
12
12
  const ISO_8601_FORMAT = 'yyyy-MM-ddTHH:mm:ssZ';
13
13
  const isIEBrowser = (0, utils_1.getBrowserInfo)().ie;
@@ -51,29 +51,6 @@ class CalendarWidget extends InputWidget_1.default {
51
51
  else if (this.settings.time_24hr) {
52
52
  this.settings.format = this.settings.format.replace(/hh:mm a$/g, 'HH:mm');
53
53
  }
54
- this.zoneLoading = false;
55
- this.timezonesUrl = `${Formio_1.Formio.cdn['moment-timezone']}/data/packed/latest.json`;
56
- }
57
- /**
58
- * Load the timezones.
59
- * @returns {boolean} TRUE if the zones are loading, FALSE otherwise.
60
- */
61
- loadZones() {
62
- const timezone = this.timezone;
63
- if (this.zoneLoading) {
64
- return true;
65
- }
66
- if (!(0, utils_1.zonesLoaded)() && (0, utils_1.shouldLoadZones)(timezone)) {
67
- this.zoneLoading = true;
68
- (0, utils_1.loadZones)(this.timezonesUrl, timezone).then(() => {
69
- this.zoneLoading = false;
70
- this.emit('redraw');
71
- });
72
- // Return zones are loading.
73
- return true;
74
- }
75
- // Zones are already loaded.
76
- return false;
77
54
  }
78
55
  attach(input) {
79
56
  var _a;
@@ -85,7 +62,7 @@ class CalendarWidget extends InputWidget_1.default {
85
62
  };
86
63
  this.closedOn = 0;
87
64
  this.valueFormat = (this.settings.saveAs === 'date') ? ISO_8601_FORMAT : this.settings.dateFormat || ISO_8601_FORMAT;
88
- this.valueMomentFormat = (0, utils_1.convertFormatToMoment)(this.valueFormat);
65
+ this.valueMomentFormat = (0, utils_1.convertFormatToDayjs)(this.valueFormat);
89
66
  const isReadOnly = this.settings.readOnly;
90
67
  this.settings.minDate = isReadOnly ? null : (0, utils_1.getDateSetting)(this.settings.minDate);
91
68
  this.settings.maxDate = isReadOnly ? null : (0, utils_1.getDateSetting)(this.settings.maxDate);
@@ -249,9 +226,9 @@ class CalendarWidget extends InputWidget_1.default {
249
226
  */
250
227
  getDateValue(date, format, useTimezone) {
251
228
  if (useTimezone) {
252
- return (0, utils_1.momentDate)(date, this.valueFormat, this.timezone).format((0, utils_1.convertFormatToMoment)(format));
229
+ return (0, utils_1.dayjsDate)(date, this.valueFormat, this.timezone).format((0, utils_1.convertFormatToDayjs)(format));
253
230
  }
254
- return (0, moment_1.default)(date).format((0, utils_1.convertFormatToMoment)(format));
231
+ return (0, moment_1.default)(date).format((0, utils_1.convertFormatToDayjs)(format));
255
232
  }
256
233
  /**
257
234
  * Return the value of the selected date.
@@ -283,13 +260,15 @@ class CalendarWidget extends InputWidget_1.default {
283
260
  setValue(value) {
284
261
  const saveAsText = (this.settings.saveAs === 'text');
285
262
  if (!this.calendar) {
286
- value = value ? (0, utils_1.formatDate)(this.timezonesUrl, value, (0, utils_1.convertFormatToMoment)(this.settings.format), this.timezone, (0, utils_1.convertFormatToMoment)(this.valueMomentFormat)) : value;
263
+ value = value ? (0, utils_1.formatDate)(value, (0, utils_1.convertFormatToDayjs)(this.settings.format), this.timezone, (0, utils_1.convertFormatToDayjs)(this.valueMomentFormat)) : value;
287
264
  return super.setValue(value);
288
265
  }
289
- const zonesLoading = this.loadZones();
266
+ // If the component is a textfield that does not have timezone information included in the string value then skip
267
+ // the timezone offset
268
+ this.settings.skipOffset = this.component.type === 'textfield' && !(0, utils_1.hasEncodedTimezone)(value);
290
269
  if (value) {
291
- if (!saveAsText && this.settings.readOnly && !zonesLoading) {
292
- this.calendar.setDate((0, utils_1.momentDate)(value, this.valueFormat, this.timezone).format(), false);
270
+ if (!saveAsText && this.settings.readOnly) {
271
+ this.calendar.setDate((0, utils_1.dayjsDate)(value, this.valueFormat, this.timezone).format(), false);
293
272
  }
294
273
  else if (this.isValueISO8601(value)) {
295
274
  this.calendar.setDate(value, false);
@@ -302,13 +281,13 @@ class CalendarWidget extends InputWidget_1.default {
302
281
  this.calendar.clear(false);
303
282
  }
304
283
  }
305
- getValueAsString(value, format) {
284
+ getValueAsString(value, format = '') {
306
285
  const inputFormat = format || this.dateFormat;
307
286
  const valueFormat = this.calendar ? this.valueFormat : this.settings.dateFormat;
308
287
  if (this.settings.saveAs === 'text' && this.componentInstance.parent && !this.settings.readOnly) {
309
- return (0, moment_1.default)(value, (0, utils_1.convertFormatToMoment)(valueFormat)).format((0, utils_1.convertFormatToMoment)(valueFormat));
288
+ return (0, moment_1.default)(value, (0, utils_1.convertFormatToDayjs)(valueFormat)).format((0, utils_1.convertFormatToDayjs)(valueFormat));
310
289
  }
311
- return (0, utils_1.formatDate)(this.timezonesUrl, value, inputFormat, this.timezone, (0, utils_1.convertFormatToMoment)(valueFormat));
290
+ return (0, utils_1.formatDate)(value, inputFormat, this.timezone, (0, utils_1.convertFormatToDayjs)(valueFormat));
312
291
  }
313
292
  setErrorClasses(hasErrors) {
314
293
  if (!this.input) {
@@ -401,7 +380,7 @@ class CalendarWidget extends InputWidget_1.default {
401
380
  const relatedTarget = event.relatedTarget ? event.relatedTarget : activeElement;
402
381
  if (!(isIEBrowser && !relatedTarget) && !this.isCalendarElement(relatedTarget)) {
403
382
  const inputValue = this.calendar.input.value;
404
- const dateValue = inputValue ? (0, moment_1.default)(this.calendar.input.value, (0, utils_1.convertFormatToMoment)(this.valueFormat)).toDate() : inputValue;
383
+ const dateValue = inputValue ? (0, moment_1.default)(this.calendar.input.value, (0, utils_1.convertFormatToDayjs)(this.valueFormat)).toDate() : inputValue;
405
384
  this.calendar.setDate(dateValue, true, this.settings.altFormat);
406
385
  }
407
386
  else if (!this.calendar.input.value && this.calendar.config.noCalendar) {
@@ -453,14 +432,14 @@ class CalendarWidget extends InputWidget_1.default {
453
432
  return (date, format) => {
454
433
  // Only format this if this is the altFormat and the form is readOnly.
455
434
  if (this.settings.readOnly && (format === this.settings.altFormat)) {
456
- if (!this.settings.enableTime || this.loadZones()) {
435
+ if (!this.settings.enableTime || this.settings.skipOffset) {
457
436
  return Flatpickr.formatDate(date, format);
458
437
  }
459
438
  const currentValue = new Date(this.getValue());
460
439
  if (currentValue.toString() === date.toString()) {
461
- return (0, utils_1.formatOffset)(this.timezonesUrl, Flatpickr.formatDate.bind(Flatpickr), new Date(this.componentValue), format, this.timezone);
440
+ return (0, utils_1.formatOffset)(Flatpickr.formatDate.bind(Flatpickr), new Date(this.componentValue), format, this.timezone);
462
441
  }
463
- return (0, utils_1.formatOffset)(this.timezonesUrl, Flatpickr.formatDate.bind(Flatpickr), date, format, this.timezone);
442
+ return (0, utils_1.formatOffset)(Flatpickr.formatDate.bind(Flatpickr), date, format, this.timezone);
464
443
  }
465
444
  return Flatpickr.formatDate(date, format);
466
445
  };
@@ -1,10 +1,10 @@
1
- import EventEmitter from './EventEmitter';
2
- import { Formio } from './Formio';
3
- import * as FormioUtils from './utils/utils';
4
- import { I18n } from '@formio/core';
5
1
  import _ from 'lodash';
6
2
  import moment from 'moment';
7
3
  import maskInput from '@formio/vanilla-text-mask';
4
+ import EventEmitter from './EventEmitter';
5
+ import { Formio } from './Formio';
6
+ import FormioUtils from './utils';
7
+ import { I18n } from '@formio/core';
8
8
  import enTranslation from './translations/en';
9
9
  /**
10
10
  * The root component for all elements within the Form.io renderer.
@@ -525,9 +525,9 @@ export default class Element {
525
525
  if (this.component.filter === string && !this.options.building) {
526
526
  const evalContext = this.evalContext(data);
527
527
  evalContext.data = _.mapValues(evalContext.data, (val) => _.isString(val) ? encodeURIComponent(val) : val);
528
- return FormioUtils.interpolate(string, evalContext, options);
528
+ return FormioUtils.Evaluator.interpolate(string, evalContext, options);
529
529
  }
530
- return FormioUtils.interpolate(string, this.evalContext(data), options);
530
+ return FormioUtils.Evaluator.interpolate(string, this.evalContext(data), options);
531
531
  }
532
532
  /**
533
533
  * Performs an evaluation using the evaluation context of this component.
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter as EventEmitter3 } from 'eventemitter3';
2
- import * as utils from './utils/utils';
2
+ import { observeOverload } from './utils';
3
3
  export default class EventEmitter extends EventEmitter3 {
4
4
  constructor(conf = {}) {
5
5
  const { loadLimit = 1000, eventsSafeInterval = 300 } = conf;
@@ -7,7 +7,7 @@ export default class EventEmitter extends EventEmitter3 {
7
7
  const overloadHandler = () => {
8
8
  console.warn(`There were more than ${loadLimit} events emitted in ${eventsSafeInterval} ms. It might be caused by events' infinite loop`, this.id);
9
9
  };
10
- const dispatch = utils.observeOverload(overloadHandler, {
10
+ const dispatch = observeOverload(overloadHandler, {
11
11
  limit: loadLimit,
12
12
  delay: eventsSafeInterval
13
13
  });
package/lib/mjs/Form.js CHANGED
@@ -2,7 +2,7 @@ import Element from './Element';
2
2
  import { Formio } from './Formio';
3
3
  import Displays from './displays';
4
4
  import templates from './templates';
5
- import * as FormioUtils from './utils/utils';
5
+ import FormioUtils from './utils';
6
6
  export default class Form extends Element {
7
7
  /**
8
8
  * Represents a JSON value.
package/lib/mjs/PDF.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Formio } from './Formio';
2
2
  import Webform from './Webform';
3
- import { fastCloneDeep, eachComponent } from './utils/utils';
3
+ import { fastCloneDeep, eachComponent } from './utils';
4
4
  export default class PDF extends Webform {
5
5
  constructor(element, options) {
6
6
  options.display = 'pdf';
@@ -1,8 +1,7 @@
1
1
  import _ from 'lodash';
2
2
  import { Formio } from './Formio';
3
3
  import WebformBuilder from './WebformBuilder';
4
- import { fastCloneDeep, getElementRect, getBrowserInfo } from './utils/utils';
5
- import { eachComponent } from './utils/formUtils';
4
+ import { fastCloneDeep, getElementRect, getBrowserInfo, eachComponent } from './utils';
6
5
  import BuilderUtils from './utils/builder';
7
6
  import PDF from './PDF';
8
7
  export default class PDFBuilder extends WebformBuilder {
@@ -1,13 +1,12 @@
1
1
  import _ from 'lodash';
2
- import moment from 'moment';
3
2
  import { compareVersions } from 'compare-versions';
4
3
  import EventEmitter from './EventEmitter';
5
4
  import enTranslation from './translations/en';
6
5
  import { Formio } from './Formio';
7
6
  import Components from './components/Components';
8
7
  import NestedDataComponent from './components/_classes/nesteddata/NestedDataComponent';
9
- import { fastCloneDeep, currentTimezone, unescapeHTML, getStringFromComponentPath, convertStringToHTMLElement, getArrayFromComponentPath, } from './utils/utils';
10
- import { eachComponent } from './utils/formUtils';
8
+ import { fastCloneDeep, currentTimezone, unescapeHTML, getStringFromComponentPath, convertStringToHTMLElement, getArrayFromComponentPath, eachComponent } from './utils';
9
+ import dayjs from "dayjs";
11
10
  // We need this here because dragula pulls in CustomEvent class that requires global to exist.
12
11
  if (typeof window !== 'undefined' && typeof window.global === 'undefined') {
13
12
  window.global = window;
@@ -659,7 +658,9 @@ export default class Webform extends NestedDataComponent {
659
658
  const rebuild = this.rebuild() || Promise.resolve();
660
659
  return rebuild.then(() => {
661
660
  this.emit('formLoad', form);
662
- this.triggerCaptcha();
661
+ if (!this.options.server) {
662
+ this.triggerCaptcha();
663
+ }
663
664
  // Make sure to trigger onChange after a render event occurs to speed up form rendering.
664
665
  setTimeout(() => {
665
666
  this.onChange(flags);
@@ -1315,7 +1316,7 @@ export default class Webform extends NestedDataComponent {
1315
1316
  submission.metadata = submission.metadata || {};
1316
1317
  _.defaults(submission.metadata, {
1317
1318
  timezone: _.get(this, '_submission.metadata.timezone', currentTimezone()),
1318
- offset: parseInt(_.get(this, '_submission.metadata.offset', moment().utcOffset()), 10),
1319
+ offset: parseInt(_.get(this, '_submission.metadata.offset', dayjs().utcOffset()), 10),
1319
1320
  origin: document.location.origin,
1320
1321
  referrer: document.referrer,
1321
1322
  browserName: navigator.appName,
@@ -77,6 +77,7 @@ export default class WebformBuilder extends Component {
77
77
  removeComponent(component: any, parent: any, original: any, componentInstance: any): boolean | undefined;
78
78
  replaceDoubleQuotes(data: any, fieldsToRemoveDoubleQuotes?: any[]): any;
79
79
  updateComponent(component: any, changed: any): void;
80
+ originalDefaultValue: any;
80
81
  findRepeatablePaths(): any[];
81
82
  highlightInvalidComponents(): void;
82
83
  /**
@@ -3,8 +3,7 @@ import Component from './components/_classes/component/Component';
3
3
  import tippy from 'tippy.js';
4
4
  import Components from './components/Components';
5
5
  import { Formio } from './Formio';
6
- import { fastCloneDeep, bootstrapVersion, getArrayFromComponentPath, getStringFromComponentPath } from './utils/utils';
7
- import { eachComponent, getComponent } from './utils/formUtils';
6
+ import { fastCloneDeep, bootstrapVersion, getArrayFromComponentPath, getStringFromComponentPath, eachComponent, getComponent, componentInfo } from './utils';
8
7
  import BuilderUtils from './utils/builder';
9
8
  import _ from 'lodash';
10
9
  import autoScroll from 'dom-autoscroller';
@@ -1054,6 +1053,16 @@ export default class WebformBuilder extends Component {
1054
1053
  'fields.month.required',
1055
1054
  'fields.year.required',
1056
1055
  ]));
1056
+ if (defaultValueComponent.component.components) {
1057
+ if (!this.originalDefaultValue) {
1058
+ this.originalDefaultValue = fastCloneDeep(defaultValueComponent.component);
1059
+ }
1060
+ eachComponent(defaultValueComponent.component.components, (comp => {
1061
+ if (comp.validate?.required) {
1062
+ comp.validate.required = false;
1063
+ }
1064
+ }));
1065
+ }
1057
1066
  const parentComponent = defaultValueComponent.parent;
1058
1067
  let tabIndex = -1;
1059
1068
  let index = -1;
@@ -1103,11 +1112,14 @@ export default class WebformBuilder extends Component {
1103
1112
  const repeatablePaths = [];
1104
1113
  const keys = new Map();
1105
1114
  eachComponent(this.form.components, (comp, path, components, parent, paths) => {
1106
- if (keys.has(paths.dataPath)) {
1107
- repeatablePaths.push(paths.dataPath);
1108
- }
1109
- else {
1110
- keys.set(paths.dataPath, true);
1115
+ const isLayout = componentInfo(comp).layout;
1116
+ if (!isLayout) {
1117
+ if (keys.has(paths.dataPath)) {
1118
+ repeatablePaths.push(paths.dataPath);
1119
+ }
1120
+ else {
1121
+ keys.set(paths.dataPath, true);
1122
+ }
1111
1123
  }
1112
1124
  }, true);
1113
1125
  return repeatablePaths;
@@ -1115,12 +1127,22 @@ export default class WebformBuilder extends Component {
1115
1127
  highlightInvalidComponents() {
1116
1128
  const repeatablePaths = this.findRepeatablePaths();
1117
1129
  let hasInvalidComponents = false;
1130
+ // Matches anything expect letters and '_' at the beginning of the key and anything except of letters, numbers,
1131
+ // '-', '.' and '_' in the rest of the key
1132
+ const badCharacters = /^[^A-Za-z_]+|[^A-Za-z0-9\-._]+/g;
1118
1133
  this.webform.everyComponent((comp) => {
1119
1134
  const path = comp.path;
1120
1135
  if (repeatablePaths.includes(path)) {
1121
1136
  comp.setCustomValidity(this.t('apiKey', { key: comp.key }));
1122
1137
  hasInvalidComponents = true;
1123
1138
  }
1139
+ else if (comp.key.replace(badCharacters, '') === '') {
1140
+ comp.setCustomValidity(this.t('apiKeyNotValid', { key: comp.key }));
1141
+ hasInvalidComponents = true;
1142
+ }
1143
+ else {
1144
+ comp.setCustomValidity();
1145
+ }
1124
1146
  });
1125
1147
  this.emit('builderFormValidityChange', hasInvalidComponents);
1126
1148
  }
@@ -1145,6 +1167,9 @@ export default class WebformBuilder extends Component {
1145
1167
  if (index !== -1) {
1146
1168
  let submissionData = this.editForm.submission.data;
1147
1169
  submissionData = submissionData.componentJson || submissionData;
1170
+ if (submissionData.components && this.originalDefaultValue) {
1171
+ submissionData.components = this.originalDefaultValue.components;
1172
+ }
1148
1173
  const fieldsToRemoveDoubleQuotes = ['label', 'tooltip'];
1149
1174
  this.replaceDoubleQuotes(submissionData, fieldsToRemoveDoubleQuotes);
1150
1175
  this.hook('beforeSaveComponentSettings', submissionData);
@@ -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/mjs/Wizard.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import _ from 'lodash';
2
2
  import Webform from './Webform';
3
3
  import { Formio } from './Formio';
4
- import { fastCloneDeep, checkCondition, firstNonNil, uniqueKey, eachComponent, } from './utils/utils';
4
+ import { fastCloneDeep, checkCondition, firstNonNil, uniqueKey, eachComponent, } from './utils';
5
5
  export default class Wizard extends Webform {
6
6
  /**
7
7
  * Constructor for wizard-based forms.
@@ -29,7 +29,6 @@ export default class Wizard extends Webform {
29
29
  this.originalComponents = [];
30
30
  this.page = 0;
31
31
  this.currentPanel = null;
32
- this.currentPanels = null;
33
32
  this.currentNextPage = 0;
34
33
  this._seenPages = [0];
35
34
  this.subWizards = [];
@@ -48,12 +47,12 @@ export default class Wizard extends Webform {
48
47
  }
49
48
  getPages(args = {}) {
50
49
  const { all = false } = args;
51
- const pages = this.hasExtraPages ? this.components : this.pages;
50
+ const pages = this.hasSubWizards ? this.components : this.pages;
52
51
  const filteredPages = pages
53
52
  .filter(all ? _.identity : (p, index) => this._seenPages.includes(index));
54
53
  return filteredPages;
55
54
  }
56
- get hasExtraPages() {
55
+ get hasSubWizards() {
57
56
  return !_.isEmpty(this.subWizards);
58
57
  }
59
58
  get data() {
@@ -177,9 +176,9 @@ export default class Wizard extends Webform {
177
176
  }
178
177
  render() {
179
178
  const ctx = this.renderContext;
180
- if (this.component.key) {
181
- ctx.panels.map(panel => {
182
- if (panel.key === this.component.key) {
179
+ if (this.component.id) {
180
+ ctx.panels.forEach(panel => {
181
+ if (panel.id === this.component.id) {
183
182
  this.currentPanel = panel;
184
183
  ctx.wizardPageTooltip = this.getFormattedTooltip(panel.tooltip);
185
184
  }
@@ -580,7 +579,7 @@ export default class Wizard extends Webform {
580
579
  this.pageFieldLogic(num);
581
580
  this.getNextPage();
582
581
  let parentNum = num;
583
- if (this.hasExtraPages) {
582
+ if (this.hasSubWizards) {
584
583
  const pageFromPages = this.pages[num];
585
584
  const pageFromComponents = this.components[num];
586
585
  if (!pageFromComponents || pageFromPages?.id !== pageFromComponents.id) {
@@ -869,23 +868,18 @@ export default class Wizard extends Webform {
869
868
  this.showErrors(errors, true, true);
870
869
  }
871
870
  // If the pages change, need to redraw the header.
872
- let currentPanels;
873
- let panels;
871
+ const currentPanels = this.pages;
872
+ // calling this.establishPages() updates/mutates this.pages to be the current pages
873
+ this.establishPages();
874
+ const newPanels = this.pages;
874
875
  const currentNextPage = this.currentNextPage;
875
- if (this.hasExtraPages) {
876
- currentPanels = this.pages.map(page => page.component.key);
877
- this.establishPages();
878
- panels = this.pages.map(page => page.component.key);
879
- }
880
- else {
881
- currentPanels = this.currentPanels || this.pages.map(page => page.component.key);
882
- panels = this.establishPages().map(panel => panel.key);
883
- this.currentPanels = panels;
884
- if (this.currentPanel?.key && this.currentPanels?.length) {
885
- this.setPage(this.currentPanels.findIndex(panel => panel === this.currentPanel.key));
886
- }
876
+ const panelsUpdated = !_.isEqual(newPanels, currentPanels);
877
+ if (this.currentPanel?.id && this.pages.length && (!this.hasSubWizards || (this.hasSubWizards && panelsUpdated))) {
878
+ const newIndex = this.pages.findIndex(page => page.id === this.currentPanel.id);
879
+ if (newIndex !== -1)
880
+ this.setPage(newIndex);
887
881
  }
888
- if (!_.isEqual(panels, currentPanels) || (flags && flags.fromSubmission)) {
882
+ if (panelsUpdated || (flags && flags.fromSubmission)) {
889
883
  this.redrawHeader();
890
884
  }
891
885
  // If the next page changes, then make sure to redraw navigation.
@@ -2,7 +2,7 @@ import WebformBuilder from './WebformBuilder';
2
2
  import Webform from './Webform';
3
3
  import BuilderUtils from './utils/builder';
4
4
  import _ from 'lodash';
5
- import { fastCloneDeep } from './utils/utils';
5
+ import { fastCloneDeep } from './utils';
6
6
  export default class WizardBuilder extends WebformBuilder {
7
7
  constructor() {
8
8
  let element, options;
@@ -163,8 +163,17 @@ declare class Component extends Element {
163
163
  */
164
164
  info: any;
165
165
  get componentsMap(): object;
166
+ /**
167
+ * Returns if the parent should conditionally clear.
168
+ * @returns {boolean} - If the parent should conditionally clear.
169
+ */
166
170
  parentShouldConditionallyClear(): boolean;
167
171
  parentConditionallyHidden(): boolean;
172
+ /**
173
+ * Returns true if any of the parents default their component "hidden" property to true.
174
+ * @returns {boolean} - If any parent defaults the hidden property to true.
175
+ */
176
+ anyParentDefaultsHidden(): boolean;
168
177
  set data(value: any);
169
178
  get data(): any;
170
179
  mergeSchema(component?: {}): any;
@@ -228,8 +237,23 @@ declare class Component extends Element {
228
237
  get visible(): boolean;
229
238
  get logicallyHidden(): any;
230
239
  _logicallyHidden: any;
231
- shouldConditionallyClear(skipParent?: boolean): boolean;
232
- conditionallyHidden(skipParent?: boolean): boolean;
240
+ /**
241
+ * Determines if the component should clear its value when the root form is pristine.
242
+ * @returns {boolean} - If the component should clear its value when the root form is pristine.
243
+ */
244
+ shouldConditionallyClearOnPristine(): boolean;
245
+ /**
246
+ * Returns if the component should clear its value when conditionally hidden.
247
+ * @returns {boolean} - If the component should clear its value when conditionally hidden.
248
+ */
249
+ shouldConditionallyClear(): boolean;
250
+ _conditionallyClear: boolean | undefined;
251
+ /**
252
+ * Returns if the component is conditionally hidden.
253
+ * @returns {boolean} - If the component is conditionally hidden.
254
+ */
255
+ conditionallyHidden(): boolean;
256
+ _conditionallyHidden: boolean | undefined;
233
257
  set currentForm(instance: any);
234
258
  get currentForm(): any;
235
259
  _currentForm: any;