@formio/js 5.0.0-bb.dev.6 → 5.0.0-dev.5543.201e658

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 (86) hide show
  1. package/dist/fonts/bootstrap-icons.woff +0 -0
  2. package/dist/fonts/bootstrap-icons.woff2 +0 -0
  3. package/dist/formio.embed.js +1 -1
  4. package/dist/formio.embed.min.js +1 -1
  5. package/dist/formio.embed.min.js.LICENSE.txt +1 -1
  6. package/dist/formio.form.js +4089 -4088
  7. package/dist/formio.form.min.js +1 -1
  8. package/dist/formio.form.min.js.LICENSE.txt +5 -5
  9. package/dist/formio.full.css +101 -4
  10. package/dist/formio.full.js +5080 -5079
  11. package/dist/formio.full.min.css +3 -3
  12. package/dist/formio.full.min.js +1 -1
  13. package/dist/formio.full.min.js.LICENSE.txt +5 -5
  14. package/dist/formio.js +1091 -1090
  15. package/dist/formio.min.js +1 -1
  16. package/dist/formio.min.js.LICENSE.txt +2 -2
  17. package/dist/formio.utils.js +7 -7
  18. package/dist/formio.utils.min.js +1 -1
  19. package/dist/formio.utils.min.js.LICENSE.txt +3 -3
  20. package/lib/cjs/Form.js +16 -3
  21. package/lib/cjs/Webform.d.ts +1 -0
  22. package/lib/cjs/Webform.js +28 -8
  23. package/lib/cjs/WebformBuilder.js +4 -2
  24. package/lib/cjs/components/address/fixtures/comp3.js +1 -1
  25. package/lib/cjs/components/button/Button.js +7 -1
  26. package/lib/cjs/components/datagrid/fixtures/comp6.js +1 -1
  27. package/lib/cjs/components/recaptcha/ReCaptcha.d.ts +4 -3
  28. package/lib/cjs/components/recaptcha/ReCaptcha.js +44 -44
  29. package/lib/cjs/formio.form.d.ts +1 -2
  30. package/lib/cjs/formio.form.js +1 -17
  31. package/lib/cjs/providers/storage/s3.d.ts +4 -1
  32. package/lib/cjs/providers/storage/s3.js +1 -29
  33. package/lib/cjs/translations/en.d.ts +2 -0
  34. package/lib/cjs/translations/en.js +2 -0
  35. package/lib/cjs/utils/conditionOperators/IsEqualTo.js +1 -1
  36. package/lib/cjs/utils/utils.js +2 -1
  37. package/lib/cjs/validator/Validator.d.ts +1 -1
  38. package/lib/cjs/validator/rules/Select.d.ts +1 -1
  39. package/lib/mjs/Form.js +16 -3
  40. package/lib/mjs/Webform.d.ts +1 -0
  41. package/lib/mjs/Webform.js +28 -8
  42. package/lib/mjs/WebformBuilder.js +4 -2
  43. package/lib/mjs/components/address/fixtures/comp3.js +1 -1
  44. package/lib/mjs/components/button/Button.js +7 -1
  45. package/lib/mjs/components/datagrid/fixtures/comp6.js +1 -1
  46. package/lib/mjs/components/recaptcha/ReCaptcha.d.ts +4 -3
  47. package/lib/mjs/components/recaptcha/ReCaptcha.js +30 -41
  48. package/lib/mjs/formio.form.d.ts +1 -2
  49. package/lib/mjs/formio.form.js +1 -16
  50. package/lib/mjs/providers/storage/s3.d.ts +4 -1
  51. package/lib/mjs/providers/storage/s3.js +1 -6
  52. package/lib/mjs/translations/en.d.ts +2 -0
  53. package/lib/mjs/translations/en.js +2 -0
  54. package/lib/mjs/utils/conditionOperators/IsEqualTo.js +1 -1
  55. package/lib/mjs/utils/utils.js +2 -1
  56. package/lib/mjs/validator/Validator.d.ts +1 -1
  57. package/lib/mjs/validator/rules/Select.d.ts +1 -1
  58. package/package.json +5 -4
  59. package/types/builders.d.ts +7 -0
  60. package/types/components/_classes/component/component.d.ts +174 -0
  61. package/types/components/_classes/componentmodal/componentmodal.d.ts +31 -0
  62. package/types/components/_classes/field/field.d.ts +5 -0
  63. package/types/components/_classes/input/input.d.ts +30 -0
  64. package/types/components/_classes/multivalue/multivalue.d.ts +16 -0
  65. package/types/components/_classes/nested/nestedComponent.d.ts +61 -0
  66. package/types/components/_classes/widgetcomponent/widgetComponent.d.ts +6 -0
  67. package/types/components/components.d.ts +69 -0
  68. package/types/components/schema.d.ts +240 -0
  69. package/types/displays.d.ts +7 -0
  70. package/types/element.d.ts +45 -0
  71. package/types/eventEmitter.d.ts +3 -0
  72. package/types/form.d.ts +18 -0
  73. package/types/formbuilder.d.ts +6 -0
  74. package/types/formio.d.ts +121 -0
  75. package/types/index.d.ts +18 -0
  76. package/types/licenses.d.ts +7 -0
  77. package/types/providers.d.ts +8 -0
  78. package/types/rulesEngine/conjunctions.d.ts +7 -0
  79. package/types/rulesEngine/operators.d.ts +7 -0
  80. package/types/rulesEngine/quckRules.d.ts +7 -0
  81. package/types/rulesEngine/rules.d.ts +7 -0
  82. package/types/rulesEngine/transformers.d.ts +7 -0
  83. package/types/rulesEngine/valueSources.d.ts +7 -0
  84. package/types/templates.d.ts +8 -0
  85. package/types/utils.d.ts +157 -0
  86. package/types/widgets.d.ts +4 -0
@@ -10,9 +10,9 @@
10
10
  * MIT licensed
11
11
  */
12
12
 
13
- /*! @license DOMPurify 3.0.5 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.0.5/LICENSE */
13
+ /*! @license DOMPurify 3.0.9 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.0.9/LICENSE */
14
14
 
15
- /*! formiojs v5.0.0-bb.dev.5 | https://unpkg.com/formiojs@5.0.0-bb.dev.5/LICENSE.txt */
15
+ /*! formiojs v5.0.0-rc.27 | https://unpkg.com/formiojs@5.0.0-rc.27/LICENSE.txt */
16
16
 
17
17
  /**
18
18
  * @license
@@ -33,4 +33,4 @@
33
33
 
34
34
  //! moment.js
35
35
 
36
- //! version : 0.5.43
36
+ //! version : 0.5.45
package/lib/cjs/Form.js CHANGED
@@ -125,9 +125,7 @@ class Form extends Element_1.default {
125
125
  this.element.appendChild(this.loader);
126
126
  }
127
127
  else if (this.loader) {
128
- if (this.element.contains(this.loader)) {
129
- this.element.removeChild(this.loader);
130
- }
128
+ this.element.removeChild(this.loader);
131
129
  this.loader = null;
132
130
  }
133
131
  }
@@ -364,3 +362,18 @@ class Form extends Element_1.default {
364
362
  }
365
363
  }
366
364
  exports.default = Form;
365
+ // Allow simple embedding.
366
+ Formio_1.Formio.embedForm = (embed) => Form.embed(embed);
367
+ /**
368
+ * Factory that creates a new form based on the form parameters.
369
+ *
370
+ * @param element {HMTLElement} - The HTML Element to add this form to.
371
+ * @param form {string|Object} - The src of the form, or a form object.
372
+ * @param options {Object} - The options to create this form.
373
+ *
374
+ * @return {Promise} - When the form is instance is ready.
375
+ */
376
+ Formio_1.Formio.createForm = (...args) => {
377
+ return (new Form(...args)).ready;
378
+ };
379
+ Formio_1.Formio.Form = Form;
@@ -282,6 +282,7 @@ declare class Webform extends NestedDataComponent {
282
282
  * @return {Promise.<TResult>}
283
283
  */
284
284
  setSubmission(submission: any, flags?: {}): Promise<TResult>;
285
+ handleDraftError(errName: any, errDetails: any, restoreDraft: any): void;
285
286
  /**
286
287
  * Saves a submission draft.
287
288
  */
@@ -215,11 +215,13 @@ class Webform extends NestedDataComponent_1.default {
215
215
  this.language = this.i18next.language;
216
216
  // See if we need to restore the draft from a user.
217
217
  if (this.options.saveDraft && !this.options.skipDraftRestore) {
218
- const user = Formio_1.Formio.getUser();
219
- // Only restore a draft if the submission isn't explicitly set.
220
- if (user && !this.submissionSet) {
221
- this.restoreDraft(user._id);
222
- }
218
+ this.formReady.then(() => {
219
+ const user = Formio_1.Formio.getUser();
220
+ // Only restore a draft if the submission isn't explicitly set.
221
+ if (user && !this.submissionSet) {
222
+ this.restoreDraft(user._id);
223
+ }
224
+ });
223
225
  }
224
226
  this.component.clearOnHide = false;
225
227
  // Ensure the root is set to this component.
@@ -538,6 +540,10 @@ class Webform extends NestedDataComponent_1.default {
538
540
  if (form && form.properties) {
539
541
  this.options.properties = form.properties;
540
542
  }
543
+ // Use the sanitize config from the form settings or the global sanitize config if it is not provided in the options
544
+ if (!this.options.sanitizeConfig && !this.builderMode) {
545
+ this.options.sanitizeConfig = lodash_1.default.get(form, 'settings.sanitizeConfig') || lodash_1.default.get(form, 'globalSettings.sanitizeConfig');
546
+ }
541
547
  if ('schema' in form && (0, compare_versions_1.compareVersions)(form.schema, '1.x') > 0) {
542
548
  this.ready.then(() => {
543
549
  this.setAlert('alert alert-danger', 'Form schema is for a newer version, please upgrade your renderer. Some functionality may not work.');
@@ -645,6 +651,11 @@ class Webform extends NestedDataComponent_1.default {
645
651
  return this.submissionReadyResolve(submission);
646
652
  }, (err) => this.submissionReadyReject(err)).catch((err) => this.submissionReadyReject(err));
647
653
  }
654
+ handleDraftError(errName, errDetails, restoreDraft) {
655
+ const errorMessage = lodash_1.default.trim(`${this.t(errName)} ${errDetails || ''}`);
656
+ console.warn(errorMessage);
657
+ this.emit(restoreDraft ? 'restoreDraftError' : 'saveDraftError', errDetails || errorMessage);
658
+ }
648
659
  /**
649
660
  * Saves a submission draft.
650
661
  */
@@ -653,11 +664,11 @@ class Webform extends NestedDataComponent_1.default {
653
664
  return;
654
665
  }
655
666
  if (!this.formio) {
656
- console.warn(this.t('saveDraftInstanceError'));
667
+ this.handleDraftError('saveDraftInstanceError');
657
668
  return;
658
669
  }
659
670
  if (!Formio_1.Formio.getUser()) {
660
- console.warn(this.t('saveDraftAuthError'));
671
+ this.handleDraftError('saveDraftAuthError');
661
672
  return;
662
673
  }
663
674
  const draft = (0, utils_1.fastCloneDeep)(this.submission);
@@ -670,6 +681,10 @@ class Webform extends NestedDataComponent_1.default {
670
681
  this.submission._id = sub._id;
671
682
  this.savingDraft = false;
672
683
  this.emit('saveDraft', sub);
684
+ })
685
+ .catch(err => {
686
+ this.savingDraft = false;
687
+ this.handleDraftError('saveDraftError', err);
673
688
  });
674
689
  }
675
690
  }
@@ -680,7 +695,7 @@ class Webform extends NestedDataComponent_1.default {
680
695
  */
681
696
  restoreDraft(userId) {
682
697
  if (!this.formio) {
683
- console.warn(this.t('restoreDraftInstanceError'));
698
+ this.handleDraftError('restoreDraftInstanceError', null, true);
684
699
  return;
685
700
  }
686
701
  this.savingDraft = true;
@@ -702,6 +717,11 @@ class Webform extends NestedDataComponent_1.default {
702
717
  this.draftEnabled = true;
703
718
  this.savingDraft = false;
704
719
  this.emit('restoreDraft', null);
720
+ })
721
+ .catch(err => {
722
+ this.draftEnabled = true;
723
+ this.savingDraft = false;
724
+ this.handleDraftError('restoreDraftError', err, true);
705
725
  });
706
726
  }
707
727
  get schema() {
@@ -992,6 +992,7 @@ class WebformBuilder extends Component_1.default {
992
992
  }
993
993
  }
994
994
  updateComponent(component, changed) {
995
+ const sanitizeConfig = lodash_1.default.get(this.webform, 'form.settings.sanitizeConfig') || lodash_1.default.get(this.webform, 'form.globalSettings.sanitizeConfig');
995
996
  // Update the preview.
996
997
  if (this.preview) {
997
998
  this.preview.form = {
@@ -1003,13 +1004,14 @@ class WebformBuilder extends Component_1.default {
1003
1004
  'autofocus',
1004
1005
  'customConditional',
1005
1006
  ])],
1006
- config: this.options.formConfig || {}
1007
+ config: this.options.formConfig || {},
1008
+ sanitizeConfig,
1007
1009
  };
1008
1010
  const fieldsToRemoveDoubleQuotes = ['label', 'tooltip'];
1009
1011
  this.preview.form.components.forEach(component => this.replaceDoubleQuotes(component, fieldsToRemoveDoubleQuotes));
1010
1012
  const previewElement = this.componentEdit.querySelector('[ref="preview"]');
1011
1013
  if (previewElement) {
1012
- this.setContent(previewElement, this.preview.render());
1014
+ this.setContent(previewElement, this.preview.render(), null, sanitizeConfig);
1013
1015
  this.preview.attach(previewElement);
1014
1016
  }
1015
1017
  }
@@ -14,7 +14,7 @@ exports.default = {
14
14
  providerOptions: {
15
15
  params: {
16
16
  autocompleteOptions: {},
17
- key: 'AIzaSyBNL2e4MnmyPj9zN7SVAe428nCSLP1X144',
17
+ key: '',
18
18
  },
19
19
  },
20
20
  input: true,
@@ -363,9 +363,15 @@ class ButtonComponent extends Field_1.default {
363
363
  response_type: 'code',
364
364
  client_id: settings.clientId,
365
365
  redirect_uri: (settings.redirectURI && this.interpolate(settings.redirectURI)) || window.location.origin || `${window.location.protocol}//${window.location.host}`,
366
- state: settings.state,
367
366
  scope: settings.scope
368
367
  };
368
+ if (settings.state) {
369
+ params.state = settings.state;
370
+ }
371
+ else if (settings.code_challenge) {
372
+ params.code_challenge = settings.code_challenge;
373
+ params.code_challenge_method = 'S256';
374
+ }
369
375
  /*eslint-enable camelcase */
370
376
  // Needs for the correct redirection URI for the OpenID
371
377
  const originalRedirectUri = params.redirect_uri;
@@ -140,7 +140,7 @@ exports.default = {
140
140
  providerOptions: {
141
141
  params: {
142
142
  autocompleteOptions: {},
143
- key: 'AIzaSyBNL2e4MnmyPj9zN7SVAe428nCSLP1X144',
143
+ key: '',
144
144
  },
145
145
  },
146
146
  input: true,
@@ -13,11 +13,12 @@ export default class ReCaptchaComponent extends Component {
13
13
  createInput(): void;
14
14
  recaptchaApiReady: any;
15
15
  createLabel(): void;
16
- verify(actionName: any): void;
17
- recaptchaVerifiedPromise: Promise<void> | undefined;
16
+ verify(actionName: any): Promise<void>;
17
+ recaptchaVerifiedPromise: Promise<any> | undefined;
18
18
  isLoading: boolean | undefined;
19
+ loading: boolean | undefined;
19
20
  sendVerificationRequest(token: any): any;
20
- checkComponentValidity(data: any, dirty: any, row: any, options?: {}): any;
21
+ checkComponentValidity(data: any, dirty: any, row: any, options?: {}): boolean | Promise<boolean>;
21
22
  normalizeValue(newValue: any): any;
22
23
  }
23
24
  import Component from '../_classes/component/Component';
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
@@ -61,46 +70,42 @@ class ReCaptchaComponent extends Component_1.default {
61
70
  return true;
62
71
  }
63
72
  verify(actionName) {
64
- const siteKey = (0, get_1.default)(this.root.form, 'settings.recaptcha.siteKey');
65
- if (!siteKey) {
66
- console.warn('There is no Site Key specified in settings in form JSON');
67
- return;
68
- }
69
- if (!this.recaptchaApiReady) {
70
- const recaptchaApiScriptUrl = `https://www.google.com/recaptcha/api.js?render=${(0, get_1.default)(this.root.form, 'settings.recaptcha.siteKey')}`;
71
- this.recaptchaApiReady = Formio_1.Formio.requireLibrary('googleRecaptcha', 'grecaptcha', recaptchaApiScriptUrl, true);
72
- }
73
- if (this.recaptchaApiReady) {
74
- this.recaptchaVerifiedPromise = new Promise((resolve, reject) => {
75
- this.recaptchaApiReady
76
- .then(() => {
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ const siteKey = (0, get_1.default)(this.root.form, 'settings.recaptcha.siteKey');
75
+ if (!siteKey) {
76
+ console.warn('There is no Site Key specified in settings in form JSON');
77
+ return;
78
+ }
79
+ if (!this.recaptchaApiReady) {
80
+ const recaptchaApiScriptUrl = `https://www.google.com/recaptcha/api.js?render=${(0, get_1.default)(this.root.form, 'settings.recaptcha.siteKey')}`;
81
+ this.recaptchaApiReady = Formio_1.Formio.requireLibrary('googleRecaptcha', 'grecaptcha', recaptchaApiScriptUrl, true);
82
+ }
83
+ try {
84
+ yield this.recaptchaApiReady;
85
+ this.recaptchaVerifiedPromise = new Promise((resolve, reject) => {
77
86
  if (!this.isLoading) {
78
87
  this.isLoading = true;
79
- grecaptcha.ready((0, debounce_1.default)(() => {
80
- grecaptcha
81
- .execute(siteKey, {
82
- action: actionName
83
- })
84
- .then((token) => {
85
- return this.sendVerificationRequest(token).then(({ verificationResult, token }) => {
86
- this.recaptchaResult = Object.assign(Object.assign({}, verificationResult), { token });
87
- this.updateValue(this.recaptchaResult);
88
- return resolve(verificationResult);
89
- });
90
- })
91
- .catch(() => {
88
+ grecaptcha.ready((0, debounce_1.default)(() => __awaiter(this, void 0, void 0, function* () {
89
+ try {
90
+ const token = yield grecaptcha.execute(siteKey, { action: actionName });
91
+ const verificationResult = yield this.sendVerificationRequest(token);
92
+ this.recaptchaResult = Object.assign(Object.assign({}, verificationResult), { token });
93
+ this.updateValue(this.recaptchaResult);
94
+ this.isLoading = false;
95
+ return resolve(verificationResult);
96
+ }
97
+ catch (err) {
92
98
  this.isLoading = false;
93
- });
94
- }, 1000));
99
+ reject(err);
100
+ }
101
+ }), 1000));
95
102
  }
96
- })
97
- .catch(() => {
98
- return reject();
99
103
  });
100
- }).then(() => {
101
- this.isLoading = false;
102
- });
103
- }
104
+ }
105
+ catch (err) {
106
+ this.loading = false;
107
+ }
108
+ });
104
109
  }
105
110
  beforeSubmit() {
106
111
  if (this.recaptchaVerifiedPromise) {
@@ -110,14 +115,13 @@ class ReCaptchaComponent extends Component_1.default {
110
115
  return super.beforeSubmit();
111
116
  }
112
117
  sendVerificationRequest(token) {
113
- return Formio_1.Formio.makeStaticRequest(`${Formio_1.Formio.projectUrl}/recaptcha?recaptchaToken=${token}`)
114
- .then((verificationResult) => ({ verificationResult, token }));
118
+ return Formio_1.Formio.makeStaticRequest(`${Formio_1.Formio.projectUrl}/recaptcha?recaptchaToken=${token}`);
115
119
  }
116
120
  checkComponentValidity(data, dirty, row, options = {}) {
117
121
  data = data || this.rootValue;
118
122
  row = row || this.data;
119
123
  const { async = false } = options;
120
- // Verification could be async only
124
+ // Verification could be async only (which for now is only the case for server-side validation)
121
125
  if (!async) {
122
126
  return super.checkComponentValidity(data, dirty, row, options);
123
127
  }
@@ -130,12 +134,8 @@ class ReCaptchaComponent extends Component_1.default {
130
134
  this.setCustomValidity(this.t('reCaptchaTokenValidationError'));
131
135
  return Promise.resolve(false);
132
136
  }
133
- return this.hook('validateReCaptcha', componentData.token, () => Promise.resolve(true))
134
- .then((success) => success)
135
- .catch((err) => {
136
- this.setCustomValidity(this.t(err.message || err));
137
- return false;
138
- });
137
+ // Any further validation will 100% not run on the client
138
+ return Promise.resolve(true);
139
139
  }
140
140
  normalizeValue(newValue) {
141
141
  // If a recaptcha result has already been established, then do not allow it to be reset.
@@ -20,5 +20,4 @@ import Utils from './utils';
20
20
  import Form from './Form';
21
21
  import { Formio } from './Formio';
22
22
  import Licenses from './licenses';
23
- import EventEmitter from './EventEmitter';
24
- export { Components, Displays, Providers, Rules, Widgets, Templates, Conjunctions, Operators, QuickRules, Transformers, ValueSources, Utils, Form, Formio, Licenses, EventEmitter };
23
+ export { Components, Displays, Providers, Rules, Widgets, Templates, Conjunctions, Operators, QuickRules, Transformers, ValueSources, Utils, Form, Formio, Licenses };
@@ -3,7 +3,7 @@ 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
- exports.EventEmitter = exports.Licenses = exports.Formio = exports.Form = exports.Utils = exports.ValueSources = exports.Transformers = exports.QuickRules = exports.Operators = exports.Conjunctions = exports.Templates = exports.Widgets = exports.Rules = exports.Providers = exports.Displays = exports.Components = exports.useModule = exports.registerModule = void 0;
6
+ exports.Licenses = exports.Formio = exports.Form = exports.Utils = exports.ValueSources = exports.Transformers = exports.QuickRules = exports.Operators = exports.Conjunctions = exports.Templates = exports.Widgets = exports.Rules = exports.Providers = exports.Displays = exports.Components = exports.useModule = exports.registerModule = void 0;
7
7
  const lodash_1 = __importDefault(require("lodash"));
8
8
  const Formio_1 = require("./Formio");
9
9
  Object.defineProperty(exports, "Formio", { enumerable: true, get: function () { return Formio_1.Formio; } });
@@ -37,8 +37,6 @@ exports.Utils = utils_1.default;
37
37
  const Evaluator_1 = __importDefault(require("./utils/Evaluator"));
38
38
  const licenses_1 = __importDefault(require("./licenses"));
39
39
  exports.Licenses = licenses_1.default;
40
- const EventEmitter_1 = __importDefault(require("./EventEmitter"));
41
- exports.EventEmitter = EventEmitter_1.default;
42
40
  Formio_1.Formio.loadModules = (path = `${Formio_1.Formio.getApiUrl()}/externalModules.js`, name = 'externalModules') => {
43
41
  Formio_1.Formio.requireLibrary(name, name, path, true)
44
42
  .then((modules) => {
@@ -167,17 +165,3 @@ exports.useModule = useModule;
167
165
  * Formio.plugins([plugin1, plugin2, etc], options);
168
166
  */
169
167
  Formio_1.Formio.use = useModule();
170
- // Allow simple embedding.
171
- Formio_1.Formio.embedForm = (embed) => Form_1.default.embed(embed);
172
- /**
173
- * Factory that creates a new form based on the form parameters.
174
- *
175
- * @param element {HMTLElement} - The HTML Element to add this form to.
176
- * @param form {string|Object} - The src of the form, or a form object.
177
- * @param options {Object} - The options to create this form.
178
- *
179
- * @return {Promise} - When the form is instance is ready.
180
- */
181
- Formio_1.Formio.createForm = (...args) => {
182
- return (new Form_1.default(...args)).ready;
183
- };
@@ -12,7 +12,10 @@ declare function s3(formio: any): {
12
12
  }>;
13
13
  completeMultipartUpload(serverResponse: any, parts: any, multipart: any): Promise<void>;
14
14
  abortMultipartUpload(serverResponse: any): void;
15
- uploadParts(file: any, urls: any, headers: any, partSize: any, multipart: any, abortSignal: any): Promise<any[]>;
15
+ uploadParts(file: any, urls: any, headers: any, partSize: any, multipart: any, abortSignal: any): Promise<{
16
+ ETag: string;
17
+ PartNumber: number;
18
+ }[]>;
16
19
  downloadFile(file: any): any;
17
20
  deleteFile(fileInfo: any): any;
18
21
  };
@@ -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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -37,11 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
14
  Object.defineProperty(exports, "__esModule", { value: true });
38
15
  const xhr_1 = __importDefault(require("./xhr"));
39
16
  const util_1 = require("./util");
40
- const loadAbortControllerPolyfill = () => __awaiter(void 0, void 0, void 0, function* () {
41
- if (typeof AbortController === 'undefined') {
42
- yield Promise.resolve().then(() => __importStar(require('abortcontroller-polyfill/dist/polyfill-patch-fetch')));
43
- }
44
- });
17
+ const AbortController = window.AbortController || require('abortcontroller-polyfill/dist/cjs-ponyfill');
45
18
  function s3(formio) {
46
19
  return {
47
20
  uploadFile(file, fileName, dir, progressCallback, url, options, fileKey, groupPermissions, groupId, abortCallback, multipartOptions) {
@@ -52,7 +25,6 @@ function s3(formio) {
52
25
  if (response.signed) {
53
26
  if (multipartOptions && Array.isArray(response.signed)) {
54
27
  // patch abort callback
55
- yield loadAbortControllerPolyfill();
56
28
  const abortController = new AbortController();
57
29
  const abortSignal = abortController.signal;
58
30
  if (typeof abortCallback === 'function') {
@@ -57,6 +57,8 @@ declare namespace _default {
57
57
  const saveDraftInstanceError: string;
58
58
  const saveDraftAuthError: string;
59
59
  const restoreDraftInstanceError: string;
60
+ const saveDraftError: string;
61
+ const restoreDraftError: string;
60
62
  const time: string;
61
63
  const cancelButtonAriaLabel: string;
62
64
  const previousButtonAriaLabel: string;
@@ -59,6 +59,8 @@ exports.default = {
59
59
  saveDraftInstanceError: 'Cannot save draft because there is no formio instance.',
60
60
  saveDraftAuthError: 'Cannot save draft unless a user is authenticated.',
61
61
  restoreDraftInstanceError: 'Cannot restore draft because there is no formio instance.',
62
+ saveDraftError: 'Unable to save draft.',
63
+ restoreDraftError: 'Unable to restore draft.',
62
64
  time: 'Invalid time',
63
65
  cancelButtonAriaLabel: 'Cancel button. Click to reset the form',
64
66
  previousButtonAriaLabel: 'Previous button. Click to go back to the previous tab',
@@ -15,7 +15,7 @@ class IsEqualTo extends ConditionOperator_1.default {
15
15
  }
16
16
  execute({ value, comparedValue, instance, conditionComponentPath }) {
17
17
  var _a;
18
- if (value && comparedValue && typeof value !== typeof comparedValue && lodash_1.default.isString(comparedValue)) {
18
+ if ((value || value === false) && comparedValue && typeof value !== typeof comparedValue && lodash_1.default.isString(comparedValue)) {
19
19
  try {
20
20
  comparedValue = JSON.parse(comparedValue);
21
21
  }
@@ -1255,7 +1255,8 @@ function sanitize(string, options) {
1255
1255
  }
1256
1256
  // Allowd URI Regex
1257
1257
  if (options.sanitizeConfig && options.sanitizeConfig.allowedUriRegex) {
1258
- sanitizeOptions.ALLOWED_URI_REGEXP = options.sanitizeConfig.allowedUriRegex;
1258
+ const allowedUriRegex = options.sanitizeConfig.allowedUriRegex;
1259
+ sanitizeOptions.ALLOWED_URI_REGEXP = lodash_1.default.isString(allowedUriRegex) ? new RegExp(allowedUriRegex) : allowedUriRegex;
1259
1260
  }
1260
1261
  // Allow to extend the existing array of elements that are safe for URI-like values
1261
1262
  if (options.sanitizeConfig && Array.isArray(options.sanitizeConfig.addUriSafeAttr) && options.sanitizeConfig.addUriSafeAttr.length > 0) {
@@ -33,7 +33,7 @@ export class ValidationChecker {
33
33
  key: string;
34
34
  hasLabel: boolean;
35
35
  message(component: any): any;
36
- check(component: any, setting: any, value: any, data: any, index: any, row: any, async: any): any;
36
+ check(component: any, setting: any, value: any, data: any, index: any, row: any, async: any): true | Promise<any>;
37
37
  };
38
38
  min: {
39
39
  key: string;
@@ -1,5 +1,5 @@
1
1
  export default class Select extends Rule {
2
2
  defaultMessage: string;
3
- check(value: any, data: any, row: any, async: any): any;
3
+ check(value: any, data: any, row: any, async: any): true | Promise<any>;
4
4
  }
5
5
  import Rule from './Rule';
package/lib/mjs/Form.js CHANGED
@@ -97,9 +97,7 @@ export default class Form extends Element {
97
97
  this.element.appendChild(this.loader);
98
98
  }
99
99
  else if (this.loader) {
100
- if (this.element.contains(this.loader)) {
101
- this.element.removeChild(this.loader);
102
- }
100
+ this.element.removeChild(this.loader);
103
101
  this.loader = null;
104
102
  }
105
103
  }
@@ -335,3 +333,18 @@ export default class Form extends Element {
335
333
  delete this.ready;
336
334
  }
337
335
  }
336
+ // Allow simple embedding.
337
+ Formio.embedForm = (embed) => Form.embed(embed);
338
+ /**
339
+ * Factory that creates a new form based on the form parameters.
340
+ *
341
+ * @param element {HMTLElement} - The HTML Element to add this form to.
342
+ * @param form {string|Object} - The src of the form, or a form object.
343
+ * @param options {Object} - The options to create this form.
344
+ *
345
+ * @return {Promise} - When the form is instance is ready.
346
+ */
347
+ Formio.createForm = (...args) => {
348
+ return (new Form(...args)).ready;
349
+ };
350
+ Formio.Form = Form;
@@ -282,6 +282,7 @@ declare class Webform extends NestedDataComponent {
282
282
  * @return {Promise.<TResult>}
283
283
  */
284
284
  setSubmission(submission: any, flags?: {}): Promise<TResult>;
285
+ handleDraftError(errName: any, errDetails: any, restoreDraft: any): void;
285
286
  /**
286
287
  * Saves a submission draft.
287
288
  */
@@ -183,11 +183,13 @@ export default class Webform extends NestedDataComponent {
183
183
  this.language = this.i18next.language;
184
184
  // See if we need to restore the draft from a user.
185
185
  if (this.options.saveDraft && !this.options.skipDraftRestore) {
186
- const user = Formio.getUser();
187
- // Only restore a draft if the submission isn't explicitly set.
188
- if (user && !this.submissionSet) {
189
- this.restoreDraft(user._id);
190
- }
186
+ this.formReady.then(() => {
187
+ const user = Formio.getUser();
188
+ // Only restore a draft if the submission isn't explicitly set.
189
+ if (user && !this.submissionSet) {
190
+ this.restoreDraft(user._id);
191
+ }
192
+ });
191
193
  }
192
194
  this.component.clearOnHide = false;
193
195
  // Ensure the root is set to this component.
@@ -532,6 +534,10 @@ export default class Webform extends NestedDataComponent {
532
534
  if (form && form.properties) {
533
535
  this.options.properties = form.properties;
534
536
  }
537
+ // Use the sanitize config from the form settings or the global sanitize config if it is not provided in the options
538
+ if (!this.options.sanitizeConfig && !this.builderMode) {
539
+ this.options.sanitizeConfig = _.get(form, 'settings.sanitizeConfig') || _.get(form, 'globalSettings.sanitizeConfig');
540
+ }
535
541
  if ('schema' in form && compareVersions(form.schema, '1.x') > 0) {
536
542
  this.ready.then(() => {
537
543
  this.setAlert('alert alert-danger', 'Form schema is for a newer version, please upgrade your renderer. Some functionality may not work.');
@@ -645,6 +651,11 @@ export default class Webform extends NestedDataComponent {
645
651
  return this.submissionReadyResolve(submission);
646
652
  }, (err) => this.submissionReadyReject(err)).catch((err) => this.submissionReadyReject(err));
647
653
  }
654
+ handleDraftError(errName, errDetails, restoreDraft) {
655
+ const errorMessage = _.trim(`${this.t(errName)} ${errDetails || ''}`);
656
+ console.warn(errorMessage);
657
+ this.emit(restoreDraft ? 'restoreDraftError' : 'saveDraftError', errDetails || errorMessage);
658
+ }
648
659
  /**
649
660
  * Saves a submission draft.
650
661
  */
@@ -653,11 +664,11 @@ export default class Webform extends NestedDataComponent {
653
664
  return;
654
665
  }
655
666
  if (!this.formio) {
656
- console.warn(this.t('saveDraftInstanceError'));
667
+ this.handleDraftError('saveDraftInstanceError');
657
668
  return;
658
669
  }
659
670
  if (!Formio.getUser()) {
660
- console.warn(this.t('saveDraftAuthError'));
671
+ this.handleDraftError('saveDraftAuthError');
661
672
  return;
662
673
  }
663
674
  const draft = fastCloneDeep(this.submission);
@@ -670,6 +681,10 @@ export default class Webform extends NestedDataComponent {
670
681
  this.submission._id = sub._id;
671
682
  this.savingDraft = false;
672
683
  this.emit('saveDraft', sub);
684
+ })
685
+ .catch(err => {
686
+ this.savingDraft = false;
687
+ this.handleDraftError('saveDraftError', err);
673
688
  });
674
689
  }
675
690
  }
@@ -680,7 +695,7 @@ export default class Webform extends NestedDataComponent {
680
695
  */
681
696
  restoreDraft(userId) {
682
697
  if (!this.formio) {
683
- console.warn(this.t('restoreDraftInstanceError'));
698
+ this.handleDraftError('restoreDraftInstanceError', null, true);
684
699
  return;
685
700
  }
686
701
  this.savingDraft = true;
@@ -702,6 +717,11 @@ export default class Webform extends NestedDataComponent {
702
717
  this.draftEnabled = true;
703
718
  this.savingDraft = false;
704
719
  this.emit('restoreDraft', null);
720
+ })
721
+ .catch(err => {
722
+ this.draftEnabled = true;
723
+ this.savingDraft = false;
724
+ this.handleDraftError('restoreDraftError', err, true);
705
725
  });
706
726
  }
707
727
  get schema() {