@formio/js 5.1.0-dev.6011.fddfe5e → 5.1.0-dev.6017.d6efba0

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.
@@ -1539,11 +1539,11 @@ class Webform extends NestedDataComponent_1.default {
1539
1539
  return;
1540
1540
  }
1541
1541
  const captchaComponent = [];
1542
- this.eachComponent((component) => {
1542
+ (0, formUtils_1.eachComponent)(this.components, (component) => {
1543
1543
  if (/^(re)?captcha$/.test(component.type) && component.component.eventType === 'formLoad') {
1544
1544
  captchaComponent.push(component);
1545
1545
  }
1546
- });
1546
+ }, true);
1547
1547
  if (captchaComponent.length > 0) {
1548
1548
  if (this.parent) {
1549
1549
  this.parent.subFormReady.then(() => {
@@ -106,6 +106,7 @@ declare class Wizard extends Webform {
106
106
  onChange(flags: any, changed: any, modified: any, changes: any): void;
107
107
  checkValidity(data: any, dirty: any, row: any, currentPageOnly: any, childErrors?: any[]): any;
108
108
  focusOnComponent(key: any): void | Promise<void>;
109
+ triggerButtonCaptcha(page: any): void;
109
110
  }
110
111
  declare namespace Wizard {
111
112
  let setBaseUrl: any;
package/lib/cjs/Wizard.js CHANGED
@@ -669,6 +669,7 @@ class Wizard extends Webform_1.default {
669
669
  beforeSubmit() {
670
670
  const pages = this.getPages({ all: true });
671
671
  return Promise.all(pages.map((page) => {
672
+ this.triggerButtonCaptcha(page);
672
673
  page.options.beforeSubmit = true;
673
674
  return page.beforeSubmit();
674
675
  }));
@@ -941,6 +942,22 @@ class Wizard extends Webform_1.default {
941
942
  }
942
943
  return super.focusOnComponent(key);
943
944
  }
945
+ triggerButtonCaptcha(page) {
946
+ if (!page.components) {
947
+ return;
948
+ }
949
+ let captchaComponent;
950
+ page.eachComponent((component) => {
951
+ if (/^(re)?captcha$/.test(component.component.type) &&
952
+ component.component.eventType === 'buttonClick' &&
953
+ component.component.buttonKey === 'submit') {
954
+ captchaComponent = component;
955
+ }
956
+ });
957
+ if (captchaComponent) {
958
+ captchaComponent.verify(`submitClick`);
959
+ }
960
+ }
944
961
  }
945
962
  exports.default = Wizard;
946
963
  Wizard.setBaseUrl = Formio_1.Formio.setBaseUrl;
@@ -1951,15 +1951,21 @@ class Component extends Element_1.default {
1951
1951
  }
1952
1952
  // Check advanced conditions (and cache the result)
1953
1953
  const isConditionallyHidden = this.checkConditionallyHidden(data, row) || this._parentConditionallyHidden;
1954
+ let shouldClear = false;
1954
1955
  if (isConditionallyHidden !== this._conditionallyHidden) {
1955
1956
  this._conditionallyHidden = isConditionallyHidden;
1956
- this.clearOnHide();
1957
+ shouldClear = true;
1957
1958
  }
1958
1959
  // Check visibility
1959
1960
  const visible = (this.hasCondition() ? !this.conditionallyHidden : !this.component.hidden);
1960
1961
  if (this.visible !== visible) {
1961
1962
  this.visible = visible;
1962
1963
  }
1964
+ // Wait for visibility to update for nested components, so the component state is up-to-date when
1965
+ // calling clearOnHide
1966
+ if (shouldClear) {
1967
+ this.clearOnHide();
1968
+ }
1963
1969
  return visible;
1964
1970
  }
1965
1971
  /**
@@ -115,7 +115,7 @@ function s3(formio) {
115
115
  const { changeMessage } = multipart;
116
116
  changeMessage('Completing AWS S3 multipart upload...');
117
117
  const token = formio.getToken();
118
- const response = yield fetch(`${formio.formUrl}/storage/s3/multipart/complete`, {
118
+ const response = yield xhr_1.default.fetch(`${formio.formUrl}/storage/s3/multipart/complete`, {
119
119
  method: 'POST',
120
120
  headers: Object.assign({ 'Content-Type': 'application/json' }, (token ? { 'x-jwt-token': token } : {})),
121
121
  body: JSON.stringify({ parts, uploadId: serverResponse.uploadId, key: serverResponse.key })
@@ -134,7 +134,7 @@ function s3(formio) {
134
134
  abortMultipartUpload(serverResponse) {
135
135
  const { uploadId, key } = serverResponse;
136
136
  const token = formio.getToken();
137
- fetch(`${formio.formUrl}/storage/s3/multipart/abort`, {
137
+ xhr_1.default.fetch(`${formio.formUrl}/storage/s3/multipart/abort`, {
138
138
  method: 'POST',
139
139
  headers: Object.assign({ 'Content-Type': 'application/json' }, (token ? { 'x-jwt-token': token } : {})),
140
140
  body: JSON.stringify({ uploadId, key })
@@ -148,7 +148,7 @@ function s3(formio) {
148
148
  const start = i * partSize;
149
149
  const end = (i + 1) * partSize;
150
150
  const blob = i < urls.length ? file.slice(start, end) : file.slice(start);
151
- const promise = fetch(urls[i], {
151
+ const promise = xhr_1.default.fetch(urls[i], {
152
152
  method: 'PUT',
153
153
  headers,
154
154
  body: blob,
@@ -3,6 +3,7 @@ export default XHR;
3
3
  declare namespace XHR {
4
4
  function trim(text: any): any;
5
5
  function path(items: any): any;
6
+ function fetch(url: any, options: any): Promise<Response>;
6
7
  function upload(formio: any, type: any, xhrCallback: any, file: any, fileName: any, dir: any, progressCallback: any, groupPermissions: any, groupId: any, abortCallback: any, multipartOptions: any): Promise<any>;
7
8
  function makeXhrRequest(formio: any, xhrCallback: any, serverResponse: any, progressCallback: any, abortCallback: any): Promise<any>;
8
9
  }
@@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.setXhrHeaders = void 0;
16
16
  const trim_1 = __importDefault(require("lodash/trim"));
17
+ const Formio_1 = require("../../Formio");
17
18
  const setXhrHeaders = (formio, xhr) => {
18
19
  const { headers } = formio.options;
19
20
  if (headers) {
@@ -36,13 +37,17 @@ const XHR = {
36
37
  path(items) {
37
38
  return items.filter(item => !!item).map(XHR.trim).join('/');
38
39
  },
40
+ fetch(url, options) {
41
+ options = Formio_1.Formio.pluginAlter('requestOptions', options, url);
42
+ return fetch(url, options);
43
+ },
39
44
  upload(formio, type, xhrCallback, file, fileName, dir, progressCallback, groupPermissions, groupId, abortCallback, multipartOptions) {
40
45
  return __awaiter(this, void 0, void 0, function* () {
41
46
  // make request to Form.io server
42
47
  const token = formio.getToken();
43
48
  let response;
44
49
  try {
45
- response = yield fetch(`${formio.formUrl}/storage/${type}`, {
50
+ response = yield XHR.fetch(`${formio.formUrl}/storage/${type}`, {
46
51
  method: 'POST',
47
52
  headers: Object.assign({ 'Accept': 'application/json', 'Content-Type': 'application/json; charset=UTF-8' }, (token ? { 'x-jwt-token': token } : {})),
48
53
  body: JSON.stringify({
@@ -1539,11 +1539,11 @@ export default class Webform extends NestedDataComponent {
1539
1539
  return;
1540
1540
  }
1541
1541
  const captchaComponent = [];
1542
- this.eachComponent((component) => {
1542
+ eachComponent(this.components, (component) => {
1543
1543
  if (/^(re)?captcha$/.test(component.type) && component.component.eventType === 'formLoad') {
1544
1544
  captchaComponent.push(component);
1545
1545
  }
1546
- });
1546
+ }, true);
1547
1547
  if (captchaComponent.length > 0) {
1548
1548
  if (this.parent) {
1549
1549
  this.parent.subFormReady.then(() => {
@@ -106,6 +106,7 @@ declare class Wizard extends Webform {
106
106
  onChange(flags: any, changed: any, modified: any, changes: any): void;
107
107
  checkValidity(data: any, dirty: any, row: any, currentPageOnly: any, childErrors?: any[]): any;
108
108
  focusOnComponent(key: any): void | Promise<void>;
109
+ triggerButtonCaptcha(page: any): void;
109
110
  }
110
111
  declare namespace Wizard {
111
112
  let setBaseUrl: any;
package/lib/mjs/Wizard.js CHANGED
@@ -659,6 +659,7 @@ export default class Wizard extends Webform {
659
659
  beforeSubmit() {
660
660
  const pages = this.getPages({ all: true });
661
661
  return Promise.all(pages.map((page) => {
662
+ this.triggerButtonCaptcha(page);
662
663
  page.options.beforeSubmit = true;
663
664
  return page.beforeSubmit();
664
665
  }));
@@ -929,6 +930,22 @@ export default class Wizard extends Webform {
929
930
  }
930
931
  return super.focusOnComponent(key);
931
932
  }
933
+ triggerButtonCaptcha(page) {
934
+ if (!page.components) {
935
+ return;
936
+ }
937
+ let captchaComponent;
938
+ page.eachComponent((component) => {
939
+ if (/^(re)?captcha$/.test(component.component.type) &&
940
+ component.component.eventType === 'buttonClick' &&
941
+ component.component.buttonKey === 'submit') {
942
+ captchaComponent = component;
943
+ }
944
+ });
945
+ if (captchaComponent) {
946
+ captchaComponent.verify(`submitClick`);
947
+ }
948
+ }
932
949
  }
933
950
  Wizard.setBaseUrl = Formio.setBaseUrl;
934
951
  Wizard.setApiUrl = Formio.setApiUrl;
@@ -1917,15 +1917,21 @@ export default class Component extends Element {
1917
1917
  }
1918
1918
  // Check advanced conditions (and cache the result)
1919
1919
  const isConditionallyHidden = this.checkConditionallyHidden(data, row) || this._parentConditionallyHidden;
1920
+ let shouldClear = false;
1920
1921
  if (isConditionallyHidden !== this._conditionallyHidden) {
1921
1922
  this._conditionallyHidden = isConditionallyHidden;
1922
- this.clearOnHide();
1923
+ shouldClear = true;
1923
1924
  }
1924
1925
  // Check visibility
1925
1926
  const visible = (this.hasCondition() ? !this.conditionallyHidden : !this.component.hidden);
1926
1927
  if (this.visible !== visible) {
1927
1928
  this.visible = visible;
1928
1929
  }
1930
+ // Wait for visibility to update for nested components, so the component state is up-to-date when
1931
+ // calling clearOnHide
1932
+ if (shouldClear) {
1933
+ this.clearOnHide();
1934
+ }
1929
1935
  return visible;
1930
1936
  }
1931
1937
  /**
@@ -75,7 +75,7 @@ function s3(formio) {
75
75
  const { changeMessage } = multipart;
76
76
  changeMessage('Completing AWS S3 multipart upload...');
77
77
  const token = formio.getToken();
78
- const response = await fetch(`${formio.formUrl}/storage/s3/multipart/complete`, {
78
+ const response = await XHR.fetch(`${formio.formUrl}/storage/s3/multipart/complete`, {
79
79
  method: 'POST',
80
80
  headers: {
81
81
  'Content-Type': 'application/json',
@@ -96,7 +96,7 @@ function s3(formio) {
96
96
  abortMultipartUpload(serverResponse) {
97
97
  const { uploadId, key } = serverResponse;
98
98
  const token = formio.getToken();
99
- fetch(`${formio.formUrl}/storage/s3/multipart/abort`, {
99
+ XHR.fetch(`${formio.formUrl}/storage/s3/multipart/abort`, {
100
100
  method: 'POST',
101
101
  headers: {
102
102
  'Content-Type': 'application/json',
@@ -113,7 +113,7 @@ function s3(formio) {
113
113
  const start = i * partSize;
114
114
  const end = (i + 1) * partSize;
115
115
  const blob = i < urls.length ? file.slice(start, end) : file.slice(start);
116
- const promise = fetch(urls[i], {
116
+ const promise = XHR.fetch(urls[i], {
117
117
  method: 'PUT',
118
118
  headers,
119
119
  body: blob,
@@ -3,6 +3,7 @@ export default XHR;
3
3
  declare namespace XHR {
4
4
  function trim(text: any): any;
5
5
  function path(items: any): any;
6
+ function fetch(url: any, options: any): Promise<Response>;
6
7
  function upload(formio: any, type: any, xhrCallback: any, file: any, fileName: any, dir: any, progressCallback: any, groupPermissions: any, groupId: any, abortCallback: any, multipartOptions: any): Promise<any>;
7
8
  function makeXhrRequest(formio: any, xhrCallback: any, serverResponse: any, progressCallback: any, abortCallback: any): Promise<any>;
8
9
  }
@@ -1,4 +1,5 @@
1
1
  import _trim from 'lodash/trim';
2
+ import { Formio } from '../../Formio';
2
3
  export const setXhrHeaders = (formio, xhr) => {
3
4
  const { headers } = formio.options;
4
5
  if (headers) {
@@ -20,12 +21,16 @@ const XHR = {
20
21
  path(items) {
21
22
  return items.filter(item => !!item).map(XHR.trim).join('/');
22
23
  },
24
+ fetch(url, options) {
25
+ options = Formio.pluginAlter('requestOptions', options, url);
26
+ return fetch(url, options);
27
+ },
23
28
  async upload(formio, type, xhrCallback, file, fileName, dir, progressCallback, groupPermissions, groupId, abortCallback, multipartOptions) {
24
29
  // make request to Form.io server
25
30
  const token = formio.getToken();
26
31
  let response;
27
32
  try {
28
- response = await fetch(`${formio.formUrl}/storage/${type}`, {
33
+ response = await XHR.fetch(`${formio.formUrl}/storage/${type}`, {
29
34
  method: 'POST',
30
35
  headers: {
31
36
  'Accept': 'application/json',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.1.0-dev.6011.fddfe5e",
3
+ "version": "5.1.0-dev.6017.d6efba0",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {