@formio/js 5.0.0-rc.20 → 5.0.0-rc.21
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/formio.embed.css +1 -39
- package/dist/formio.embed.js +2 -90
- package/dist/formio.embed.min.js +1 -1
- package/dist/formio.embed.min.js.LICENSE.txt +1 -1
- package/dist/formio.form.js +57 -35
- package/dist/formio.form.min.js +1 -1
- package/dist/formio.form.min.js.LICENSE.txt +1 -1
- package/dist/formio.full.js +58 -36
- package/dist/formio.full.min.js +1 -1
- package/dist/formio.full.min.js.LICENSE.txt +1 -1
- package/dist/formio.js +2 -2
- package/dist/formio.min.js +1 -1
- package/dist/formio.min.js.LICENSE.txt +1 -1
- package/dist/formio.utils.js +1 -1
- package/dist/formio.utils.min.js +1 -1
- package/dist/formio.utils.min.js.LICENSE.txt +1 -1
- package/lib/cjs/CDN.d.ts +1 -0
- package/lib/cjs/CDN.js +1 -0
- package/lib/cjs/Embed.d.ts +21 -1
- package/lib/cjs/Embed.js +211 -308
- package/lib/cjs/Form.d.ts +1 -1
- package/lib/cjs/Form.js +1 -1
- package/lib/cjs/Webform.d.ts +6 -6
- package/lib/cjs/Webform.js +6 -6
- package/lib/cjs/WebformBuilder.js +1 -1
- package/lib/cjs/components/_classes/component/Component.d.ts +16 -6
- package/lib/cjs/components/_classes/component/Component.js +26 -6
- package/lib/cjs/components/_classes/nestedarray/NestedArrayComponent.d.ts +1 -0
- package/lib/cjs/components/_classes/nestedarray/NestedArrayComponent.js +4 -0
- package/lib/cjs/components/_classes/nesteddata/NestedDataComponent.d.ts +1 -0
- package/lib/cjs/components/_classes/nesteddata/NestedDataComponent.js +4 -0
- package/lib/cjs/components/address/Address.js +5 -0
- package/lib/cjs/components/button/Button.d.ts +1 -0
- package/lib/cjs/components/button/Button.js +3 -0
- package/lib/cjs/components/checkbox/Checkbox.d.ts +28 -0
- package/lib/cjs/components/checkbox/Checkbox.js +17 -2
- package/lib/cjs/components/columns/Columns.d.ts +1 -0
- package/lib/cjs/components/columns/Columns.js +3 -0
- package/lib/cjs/components/container/Container.js +3 -0
- package/lib/cjs/components/content/Content.d.ts +1 -0
- package/lib/cjs/components/content/Content.js +3 -0
- package/lib/cjs/components/datamap/DataMap.d.ts +1 -0
- package/lib/cjs/components/datamap/DataMap.js +3 -0
- package/lib/cjs/components/datetime/DateTime.d.ts +19 -0
- package/lib/cjs/components/datetime/DateTime.js +9 -10
- package/lib/cjs/components/day/Day.d.ts +21 -0
- package/lib/cjs/components/day/Day.js +8 -10
- package/lib/cjs/components/fieldset/Fieldset.d.ts +1 -0
- package/lib/cjs/components/fieldset/Fieldset.js +3 -0
- package/lib/cjs/components/file/File.d.ts +21 -1
- package/lib/cjs/components/file/File.js +15 -7
- package/lib/cjs/components/form/Form.d.ts +1 -0
- package/lib/cjs/components/form/Form.js +3 -0
- package/lib/cjs/components/html/HTML.d.ts +1 -0
- package/lib/cjs/components/html/HTML.js +3 -0
- package/lib/cjs/components/number/Number.d.ts +20 -1
- package/lib/cjs/components/number/Number.js +10 -15
- package/lib/cjs/components/panel/Panel.d.ts +1 -0
- package/lib/cjs/components/panel/Panel.js +3 -0
- package/lib/cjs/components/radio/Radio.d.ts +19 -0
- package/lib/cjs/components/radio/Radio.js +30 -0
- package/lib/cjs/components/recaptcha/ReCaptcha.d.ts +1 -0
- package/lib/cjs/components/recaptcha/ReCaptcha.js +3 -0
- package/lib/cjs/components/select/Select.d.ts +19 -1
- package/lib/cjs/components/select/Select.js +37 -3
- package/lib/cjs/components/selectboxes/SelectBoxes.d.ts +26 -1
- package/lib/cjs/components/selectboxes/SelectBoxes.js +8 -1
- package/lib/cjs/components/signature/Signature.d.ts +21 -0
- package/lib/cjs/components/signature/Signature.js +9 -1
- package/lib/cjs/components/survey/Survey.d.ts +21 -0
- package/lib/cjs/components/survey/Survey.js +7 -1
- package/lib/cjs/components/table/Table.d.ts +1 -0
- package/lib/cjs/components/table/Table.js +3 -0
- package/lib/cjs/components/tabs/Tabs.d.ts +1 -0
- package/lib/cjs/components/tabs/Tabs.js +3 -0
- package/lib/cjs/components/tags/Tags.d.ts +21 -0
- package/lib/cjs/components/tags/Tags.js +9 -1
- package/lib/cjs/components/textfield/TextField.d.ts +21 -0
- package/lib/cjs/components/textfield/TextField.js +7 -1
- package/lib/cjs/components/time/Time.d.ts +8 -1
- package/lib/cjs/components/well/Well.d.ts +1 -0
- package/lib/cjs/components/well/Well.js +3 -0
- package/lib/cjs/formio.embed.d.ts +2 -1
- package/lib/cjs/formio.embed.js +96 -1
- package/lib/cjs/formio.form.d.ts +4 -3
- package/lib/cjs/formio.form.js +17 -8
- package/lib/cjs/licenses/Licenses.d.ts +7 -0
- package/lib/cjs/licenses/Licenses.js +22 -0
- package/lib/cjs/licenses/index.d.ts +2 -0
- package/lib/cjs/licenses/index.js +7 -0
- package/lib/cjs/utils/utils.d.ts +10 -0
- package/lib/cjs/utils/utils.js +21 -1
- package/lib/mjs/CDN.d.ts +1 -0
- package/lib/mjs/CDN.js +1 -0
- package/lib/mjs/Embed.d.ts +21 -1
- package/lib/mjs/Embed.js +208 -322
- package/lib/mjs/Form.d.ts +1 -1
- package/lib/mjs/Form.js +1 -1
- package/lib/mjs/Webform.d.ts +6 -6
- package/lib/mjs/Webform.js +6 -6
- package/lib/mjs/WebformBuilder.js +1 -1
- package/lib/mjs/components/_classes/component/Component.d.ts +16 -6
- package/lib/mjs/components/_classes/component/Component.js +26 -6
- package/lib/mjs/components/_classes/nestedarray/NestedArrayComponent.d.ts +1 -0
- package/lib/mjs/components/_classes/nestedarray/NestedArrayComponent.js +4 -0
- package/lib/mjs/components/_classes/nesteddata/NestedDataComponent.d.ts +1 -0
- package/lib/mjs/components/_classes/nesteddata/NestedDataComponent.js +4 -0
- package/lib/mjs/components/address/Address.js +5 -0
- package/lib/mjs/components/button/Button.d.ts +1 -0
- package/lib/mjs/components/button/Button.js +4 -1
- package/lib/mjs/components/checkbox/Checkbox.d.ts +28 -0
- package/lib/mjs/components/checkbox/Checkbox.js +18 -3
- package/lib/mjs/components/columns/Columns.d.ts +1 -0
- package/lib/mjs/components/columns/Columns.js +3 -0
- package/lib/mjs/components/container/Container.js +4 -1
- package/lib/mjs/components/content/Content.d.ts +1 -0
- package/lib/mjs/components/content/Content.js +3 -0
- package/lib/mjs/components/datamap/DataMap.d.ts +1 -0
- package/lib/mjs/components/datamap/DataMap.js +4 -1
- package/lib/mjs/components/datetime/DateTime.d.ts +19 -0
- package/lib/mjs/components/datetime/DateTime.js +11 -12
- package/lib/mjs/components/day/Day.d.ts +21 -0
- package/lib/mjs/components/day/Day.js +12 -14
- package/lib/mjs/components/fieldset/Fieldset.d.ts +1 -0
- package/lib/mjs/components/fieldset/Fieldset.js +3 -0
- package/lib/mjs/components/file/File.d.ts +21 -1
- package/lib/mjs/components/file/File.js +16 -8
- package/lib/mjs/components/form/Form.d.ts +1 -0
- package/lib/mjs/components/form/Form.js +4 -1
- package/lib/mjs/components/html/HTML.d.ts +1 -0
- package/lib/mjs/components/html/HTML.js +3 -0
- package/lib/mjs/components/number/Number.d.ts +20 -1
- package/lib/mjs/components/number/Number.js +11 -12
- package/lib/mjs/components/panel/Panel.d.ts +1 -0
- package/lib/mjs/components/panel/Panel.js +3 -0
- package/lib/mjs/components/radio/Radio.d.ts +19 -0
- package/lib/mjs/components/radio/Radio.js +34 -1
- package/lib/mjs/components/recaptcha/ReCaptcha.d.ts +1 -0
- package/lib/mjs/components/recaptcha/ReCaptcha.js +3 -0
- package/lib/mjs/components/select/Select.d.ts +19 -1
- package/lib/mjs/components/select/Select.js +39 -5
- package/lib/mjs/components/selectboxes/SelectBoxes.d.ts +26 -1
- package/lib/mjs/components/selectboxes/SelectBoxes.js +8 -1
- package/lib/mjs/components/signature/Signature.d.ts +21 -0
- package/lib/mjs/components/signature/Signature.js +9 -1
- package/lib/mjs/components/survey/Survey.d.ts +21 -0
- package/lib/mjs/components/survey/Survey.js +8 -2
- package/lib/mjs/components/table/Table.d.ts +1 -0
- package/lib/mjs/components/table/Table.js +3 -0
- package/lib/mjs/components/tabs/Tabs.d.ts +1 -0
- package/lib/mjs/components/tabs/Tabs.js +3 -0
- package/lib/mjs/components/tags/Tags.d.ts +21 -0
- package/lib/mjs/components/tags/Tags.js +10 -2
- package/lib/mjs/components/textfield/TextField.d.ts +21 -0
- package/lib/mjs/components/textfield/TextField.js +8 -2
- package/lib/mjs/components/time/Time.d.ts +8 -1
- package/lib/mjs/components/well/Well.d.ts +1 -0
- package/lib/mjs/components/well/Well.js +3 -0
- package/lib/mjs/formio.embed.d.ts +2 -1
- package/lib/mjs/formio.embed.js +96 -2
- package/lib/mjs/formio.form.d.ts +4 -3
- package/lib/mjs/formio.form.js +16 -8
- package/lib/mjs/licenses/Licenses.d.ts +7 -0
- package/lib/mjs/licenses/Licenses.js +17 -0
- package/lib/mjs/licenses/index.d.ts +2 -0
- package/lib/mjs/licenses/index.js +2 -0
- package/lib/mjs/utils/utils.d.ts +10 -0
- package/lib/mjs/utils/utils.js +19 -0
- package/package.json +5 -1
- package/types/index.d.ts +1 -0
- package/types/licenses.d.ts +7 -0
- package/types/utils.d.ts +2 -0
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
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 */
|
14
14
|
|
15
|
-
/*! formiojs v5.0.0-rc.
|
15
|
+
/*! formiojs v5.0.0-rc.21 | https://unpkg.com/formiojs@5.0.0-rc.21/LICENSE.txt */
|
16
16
|
|
17
17
|
/**
|
18
18
|
* @license
|
package/lib/cjs/CDN.d.ts
CHANGED
package/lib/cjs/CDN.js
CHANGED
package/lib/cjs/Embed.d.ts
CHANGED
@@ -1 +1,21 @@
|
|
1
|
-
export
|
1
|
+
export class Formio {
|
2
|
+
static baseUrl: any;
|
3
|
+
static projectUrl: any;
|
4
|
+
static language: any;
|
5
|
+
static wrapper: any;
|
6
|
+
static element: any;
|
7
|
+
static config: {};
|
8
|
+
static loader: null;
|
9
|
+
static cdn: null;
|
10
|
+
static proxy: boolean;
|
11
|
+
static setBaseUrl(url: any): Promise<void>;
|
12
|
+
static setProjectUrl(url: any): Promise<void>;
|
13
|
+
static debug(...args: any[]): void;
|
14
|
+
static global(prop: any): any;
|
15
|
+
static createElement(type: any, attrs: any, children: any): any;
|
16
|
+
static addScript(src: any, name: any): Promise<any>;
|
17
|
+
static addStyles(href: any, addGlobally?: boolean): Promise<void>;
|
18
|
+
static submitDone(instance: any, submission: any): Promise<void>;
|
19
|
+
static renderForm(form: any, options: any): Promise<any>;
|
20
|
+
static createForm(element: any, form: any, options: any): Promise<any>;
|
21
|
+
}
|
package/lib/cjs/Embed.js
CHANGED
@@ -1,355 +1,258 @@
|
|
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
|
};
|
5
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.
|
7
|
-
const
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
let i = scripts.length;
|
14
|
-
const scriptName = config.scriptName || 'formio.embed.';
|
15
|
-
while (i--) {
|
16
|
-
if (scripts[i].src && (scripts[i].src.indexOf(scriptName) !== -1)) {
|
17
|
-
thisScript = scripts[i];
|
18
|
-
break;
|
19
|
-
}
|
15
|
+
exports.Formio = void 0;
|
16
|
+
const CDN_js_1 = __importDefault(require("./CDN.js"));
|
17
|
+
class Formio {
|
18
|
+
static setBaseUrl(url) {
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
20
|
+
Formio.baseUrl = url;
|
21
|
+
});
|
20
22
|
}
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
queryString.replace(/\?/g, '&').split('&').forEach((item) => {
|
25
|
-
query[item.split('=')[0]] = item.split('=')[1] && decodeURIComponent(item.split('=')[1]);
|
23
|
+
static setProjectUrl(url) {
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
25
|
+
Formio.projectUrl = url;
|
26
26
|
});
|
27
|
-
|
28
|
-
|
29
|
-
if (config.
|
30
|
-
|
27
|
+
}
|
28
|
+
static debug(...args) {
|
29
|
+
if (Formio.config.debug) {
|
30
|
+
console.log(...args);
|
31
31
|
}
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
libs.fontawesome.css = `${url}/font-awesome/${cdn.getVersion('font-awesome')}/css/font-awesome.min.css`;
|
56
|
-
libs.bootstrap.css = `${url}/bootstrap/${cdn.getVersion('bootstrap')}/css/bootstrap.min.css`;
|
32
|
+
}
|
33
|
+
static global(prop) {
|
34
|
+
const globalValue = window[prop];
|
35
|
+
if (globalValue && globalValue.proxy) {
|
36
|
+
return null;
|
37
|
+
}
|
38
|
+
Formio.debug(`Getting global ${prop}`, globalValue);
|
39
|
+
return globalValue;
|
40
|
+
}
|
41
|
+
static createElement(type, attrs, children) {
|
42
|
+
const element = document.createElement(type);
|
43
|
+
Object.keys(attrs).forEach(key => {
|
44
|
+
element.setAttribute(key, attrs[key]);
|
45
|
+
});
|
46
|
+
(children || []).forEach(child => {
|
47
|
+
element.appendChild(Formio.createElement(child.tag, child.attrs, child.children));
|
48
|
+
});
|
49
|
+
return element;
|
50
|
+
}
|
51
|
+
static addScript(src, name) {
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
53
|
+
if (!src) {
|
54
|
+
return Promise.resolve();
|
57
55
|
}
|
58
|
-
|
59
|
-
|
60
|
-
config = Object.assign({
|
61
|
-
script: query.script,
|
62
|
-
style: query.styles,
|
63
|
-
class: (query.class || 'formio-form-wrapper'),
|
64
|
-
src: query.src,
|
65
|
-
form: null,
|
66
|
-
submission: null,
|
67
|
-
project: query.project,
|
68
|
-
base: query.base,
|
69
|
-
submit: query.submit,
|
70
|
-
includeLibs: (query.libs === 'true' || query.libs === '1'),
|
71
|
-
template: query.template,
|
72
|
-
debug: (query.debug === 'true' || query.debug === '1'),
|
73
|
-
config: {},
|
74
|
-
redirect: (query.return || query.redirect),
|
75
|
-
before: () => { },
|
76
|
-
after: () => { }
|
77
|
-
}, config);
|
78
|
-
/**
|
79
|
-
* Print debug statements.
|
80
|
-
*
|
81
|
-
* @param {...any} args Arguments to pass to the console.log method.
|
82
|
-
*/
|
83
|
-
const debug = (...args) => {
|
84
|
-
if (config.debug) {
|
85
|
-
console.log(...args);
|
56
|
+
if (typeof src !== 'string' && src.length) {
|
57
|
+
return Promise.all(src.map(ref => Formio.addScript(ref)));
|
86
58
|
}
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
*
|
91
|
-
* @param {string} tag The HTMLElement to add to the wrapper or shadow dom.
|
92
|
-
* @param {Object} attrs The attributes to add to this element.
|
93
|
-
* @param {Array<Object>} children The children attached to this element.
|
94
|
-
*/
|
95
|
-
const createElement = (tag, attrs, children) => {
|
96
|
-
const element = document.createElement(tag);
|
97
|
-
for (const attr in attrs) {
|
98
|
-
if (attrs.hasOwnProperty(attr)) {
|
99
|
-
element.setAttribute(attr, attrs[attr]);
|
100
|
-
}
|
59
|
+
if (name && Formio.global(name)) {
|
60
|
+
Formio.debug(`${name} already loaded.`);
|
61
|
+
return Promise.resolve(Formio.global(name));
|
101
62
|
}
|
102
|
-
(
|
103
|
-
|
63
|
+
Formio.debug('Adding Script', src);
|
64
|
+
Formio.wrapper.appendChild(Formio.createElement('script', {
|
65
|
+
src
|
66
|
+
}));
|
67
|
+
if (!name) {
|
68
|
+
return Promise.resolve();
|
69
|
+
}
|
70
|
+
return new Promise((resolve) => {
|
71
|
+
Formio.debug(`Waiting to load ${name}`);
|
72
|
+
const wait = setInterval(() => {
|
73
|
+
if (Formio.global(name)) {
|
74
|
+
clearInterval(wait);
|
75
|
+
Formio.debug(`${name} loaded.`);
|
76
|
+
resolve(Formio.global(name));
|
77
|
+
}
|
78
|
+
}, 100);
|
104
79
|
});
|
105
|
-
return element;
|
106
|
-
};
|
107
|
-
debug('Embedding Configuration', config);
|
108
|
-
if (config.addPremiumLib) {
|
109
|
-
config.addPremiumLib(config, scriptSrc);
|
110
|
-
}
|
111
|
-
// The id for this embedded form.
|
112
|
-
const id = `formio-${Math.random().toString(36).substring(7)}`;
|
113
|
-
config.id = id;
|
114
|
-
debug('Creating form wrapper');
|
115
|
-
let wrapper = createElement('div', {
|
116
|
-
'id': `"${id}-wrapper"`
|
117
80
|
});
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
if (config.includeLibs && (typeof wrapper.attachShadow === 'function') && !config.premium) {
|
122
|
-
wrapper = wrapper.attachShadow({
|
123
|
-
mode: 'open'
|
124
|
-
});
|
125
|
-
config.config.shadowRoot = wrapper;
|
126
|
-
}
|
127
|
-
const global = (name) => {
|
128
|
-
const globalValue = window[name];
|
129
|
-
debug(`Getting global ${name}`, globalValue);
|
130
|
-
return globalValue;
|
131
|
-
};
|
132
|
-
const addStyles = (href, global) => {
|
81
|
+
}
|
82
|
+
static addStyles(href, addGlobally = false) {
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
133
84
|
if (!href) {
|
134
85
|
return;
|
135
86
|
}
|
136
87
|
if (typeof href !== 'string' && href.length) {
|
137
|
-
href.forEach(ref => addStyles(ref));
|
88
|
+
href.forEach(ref => Formio.addStyles(ref));
|
138
89
|
return;
|
139
90
|
}
|
140
|
-
debug('Adding Styles', href);
|
141
|
-
const link = createElement('link', {
|
91
|
+
Formio.debug('Adding Styles', href);
|
92
|
+
const link = Formio.createElement('link', {
|
142
93
|
rel: 'stylesheet',
|
143
94
|
href
|
144
95
|
});
|
145
|
-
if (
|
96
|
+
if (addGlobally) {
|
146
97
|
// Add globally as well.
|
147
98
|
document.head.appendChild(link);
|
148
99
|
}
|
149
|
-
wrapper.appendChild(createElement('link', {
|
100
|
+
Formio.wrapper.appendChild(Formio.createElement('link', {
|
150
101
|
rel: 'stylesheet',
|
151
102
|
href
|
152
103
|
}));
|
153
|
-
};
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
104
|
+
});
|
105
|
+
}
|
106
|
+
static submitDone(instance, submission) {
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
108
|
+
Formio.debug('Submision Complete', submission);
|
109
|
+
let returnUrl = Formio.config.redirect;
|
110
|
+
// Allow form based configuration for return url.
|
111
|
+
if (!returnUrl &&
|
112
|
+
(instance._form &&
|
113
|
+
instance._form.settings &&
|
114
|
+
(instance._form.settings.returnUrl ||
|
115
|
+
instance._form.settings.redirect))) {
|
116
|
+
Formio.debug('Return url found in form configuration');
|
117
|
+
returnUrl = instance._form.settings.returnUrl || instance._form.settings.redirect;
|
161
118
|
}
|
162
|
-
if (
|
163
|
-
|
164
|
-
|
119
|
+
if (returnUrl) {
|
120
|
+
const formSrc = instance.formio ? instance.formio.formUrl : '';
|
121
|
+
const hasQuery = !!returnUrl.match(/\?/);
|
122
|
+
const isOrigin = returnUrl.indexOf(location.origin) === 0;
|
123
|
+
returnUrl += hasQuery ? '&' : '?';
|
124
|
+
returnUrl += `sub=${submission._id}`;
|
125
|
+
if (!isOrigin && formSrc) {
|
126
|
+
returnUrl += `&form=${encodeURIComponent(formSrc)}`;
|
127
|
+
}
|
128
|
+
Formio.debug('Return URL', returnUrl);
|
129
|
+
window.location.href = returnUrl;
|
130
|
+
if (isOrigin) {
|
131
|
+
window.location.reload();
|
132
|
+
}
|
165
133
|
}
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
if (
|
171
|
-
|
172
|
-
const wait = setInterval(() => {
|
173
|
-
if (global(globalProp)) {
|
174
|
-
clearInterval(wait);
|
175
|
-
debug(`${globalProp} loaded.`);
|
176
|
-
onReady(global(globalProp));
|
177
|
-
}
|
178
|
-
}, 100);
|
134
|
+
});
|
135
|
+
}
|
136
|
+
static renderForm(form, options) {
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
138
|
+
if (Formio.config.before) {
|
139
|
+
yield Formio.config.before(Formio.FormioClass, Formio.element, Formio.config);
|
179
140
|
}
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
}
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
const formElement = createElement('div', {
|
202
|
-
class: config.class
|
141
|
+
Formio.FormioClass.license = true;
|
142
|
+
return Formio.FormioClass.createForm(Formio.element, form, Object.assign(Object.assign({}, options), { noLoader: true })).then((instance) => {
|
143
|
+
Formio.debug('Form created', instance);
|
144
|
+
// Remove the loader.
|
145
|
+
Formio.debug('Removing loader');
|
146
|
+
Formio.wrapper.removeChild(Formio.loader);
|
147
|
+
// Set the default submission data.
|
148
|
+
if (Formio.config.submission) {
|
149
|
+
Formio.debug('Setting submission', Formio.config.submission);
|
150
|
+
instance.submission = Formio.config.submission;
|
151
|
+
}
|
152
|
+
// Allow them to provide additional configs.
|
153
|
+
Formio.debug('Triggering embed event');
|
154
|
+
Formio.FormioClass.events.emit('formEmbedded', instance);
|
155
|
+
// Trigger the after handler.
|
156
|
+
if (Formio.config.after) {
|
157
|
+
Formio.debug('Calling ready callback');
|
158
|
+
Formio.config.after(instance, Formio.config);
|
159
|
+
}
|
160
|
+
return instance;
|
161
|
+
});
|
203
162
|
});
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
Formio.
|
214
|
-
Formio.
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
(instance._form.settings.returnUrl ||
|
223
|
-
instance._form.settings.redirect))) {
|
224
|
-
debug('Return url found in form configuration');
|
225
|
-
returnUrl = instance._form.settings.returnUrl || instance._form.settings.redirect;
|
226
|
-
}
|
227
|
-
if (returnUrl) {
|
228
|
-
const formSrc = instance.formio ? instance.formio.formUrl : '';
|
229
|
-
const hasQuery = !!returnUrl.match(/\?/);
|
230
|
-
const isOrigin = returnUrl.indexOf(location.origin) === 0;
|
231
|
-
returnUrl += hasQuery ? '&' : '?';
|
232
|
-
returnUrl += `sub=${submission._id}`;
|
233
|
-
if (!isOrigin && formSrc) {
|
234
|
-
returnUrl += `&form=${encodeURIComponent(formSrc)}`;
|
235
|
-
}
|
236
|
-
debug('Return URL', returnUrl);
|
237
|
-
window.location.href = returnUrl;
|
238
|
-
if (isOrigin) {
|
239
|
-
window.location.reload();
|
240
|
-
}
|
241
|
-
}
|
242
|
-
};
|
243
|
-
if (config.submit) {
|
244
|
-
instance.nosubmit = true;
|
245
|
-
}
|
246
|
-
debug('Form created', instance);
|
247
|
-
// Remove the loader.
|
248
|
-
debug('Removing loader');
|
249
|
-
wrapper.removeChild(loader);
|
250
|
-
// Set the default submission data.
|
251
|
-
if (config.submission) {
|
252
|
-
debug('Setting submission', config.submission);
|
253
|
-
instance.submission = config.submission;
|
254
|
-
}
|
255
|
-
// Allow them to provide additional configs.
|
256
|
-
debug('Triggering embed event');
|
257
|
-
Formio.events.emit('formEmbedded', instance);
|
258
|
-
debug('Calling ready callback');
|
259
|
-
config.after(instance, config);
|
260
|
-
// Configure a redirect.
|
261
|
-
instance.on('submit', (submission) => {
|
262
|
-
debug("on('submit')", submission);
|
263
|
-
if (config.submit) {
|
264
|
-
debug(`Sending submission to ${config.submit}`);
|
265
|
-
const headers = {
|
266
|
-
'content-type': 'application/json'
|
267
|
-
};
|
268
|
-
const token = Formio.getToken();
|
269
|
-
if (token) {
|
270
|
-
headers['x-jwt-token'] = token;
|
271
|
-
}
|
272
|
-
Formio.fetch(config.submit, {
|
273
|
-
body: JSON.stringify(submission),
|
274
|
-
headers: headers,
|
275
|
-
method: 'POST',
|
276
|
-
mode: 'cors',
|
277
|
-
})
|
278
|
-
.then(resp => resp.json())
|
279
|
-
.then(submission => submitDone(submission));
|
280
|
-
}
|
281
|
-
else {
|
282
|
-
submitDone(submission);
|
283
|
-
}
|
284
|
-
});
|
285
|
-
});
|
286
|
-
});
|
163
|
+
}
|
164
|
+
// eslint-disable-next-line max-statements
|
165
|
+
static createForm(element, form, options) {
|
166
|
+
return __awaiter(this, void 0, void 0, function* () {
|
167
|
+
Formio.element = element;
|
168
|
+
Formio.cdn = new CDN_js_1.default(Formio.config.cdn);
|
169
|
+
Formio.config.libs = Formio.config.libs || {
|
170
|
+
uswds: {
|
171
|
+
fa: true,
|
172
|
+
js: `${Formio.cdn.uswds}/uswds.min.js`,
|
173
|
+
css: `${Formio.cdn.uswds}/uswds.min.css`,
|
174
|
+
},
|
175
|
+
fontawesome: {
|
176
|
+
css: `${Formio.cdn['font-awesome']}/css/font-awesome.min.css`
|
177
|
+
},
|
178
|
+
bootstrap: {
|
179
|
+
css: `${Formio.cdn.bootstrap}/css/bootstrap.min.css`
|
180
|
+
}
|
287
181
|
};
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
182
|
+
Formio.config.id = Formio.config.id || `formio-${Math.random().toString(36).substring(7)}`;
|
183
|
+
// Create a new wrapper and add the element inside of a new wrapper.
|
184
|
+
Formio.wrapper = Formio.createElement('div', {
|
185
|
+
'id': `"${Formio.config.id}-wrapper"`
|
186
|
+
});
|
187
|
+
element.parentNode.insertBefore(Formio.wrapper, element);
|
188
|
+
element.parentNode.removeChild(element);
|
189
|
+
Formio.wrapper.appendChild(element);
|
190
|
+
// Load the renderer styles.
|
191
|
+
yield Formio.addStyles(Formio.config.embedCSS || `${Formio.cdn.js}/formio.embed.css`);
|
192
|
+
Formio.loader = Formio.createElement('div', {
|
193
|
+
'class': 'formio-loader'
|
194
|
+
}, [{
|
195
|
+
tag: 'div',
|
196
|
+
attrs: {
|
197
|
+
class: 'loader-wrapper'
|
198
|
+
},
|
199
|
+
children: [{
|
200
|
+
tag: 'div',
|
201
|
+
attrs: {
|
202
|
+
class: 'loader text-center'
|
203
|
+
}
|
204
|
+
}]
|
205
|
+
}]);
|
206
|
+
Formio.wrapper.appendChild(Formio.loader);
|
207
|
+
Formio.FormioClass = yield Formio.addScript(Formio.config.script || `${Formio.cdn.js}/formio.form.min.js`, 'Formio');
|
208
|
+
Formio.FormioClass.setBaseUrl(Formio.baseUrl || Formio.config.base);
|
209
|
+
Formio.FormioClass.setProjectUrl(Formio.projectUrl || Formio.config.project);
|
210
|
+
Formio.FormioClass.language = Formio.language;
|
294
211
|
// Add premium modules
|
295
|
-
if (global('premium')) {
|
296
|
-
debug('Using premium module.');
|
297
|
-
Formio.use(global('premium'));
|
212
|
+
if (Formio.global('premium')) {
|
213
|
+
Formio.debug('Using premium module.');
|
214
|
+
Formio.FormioClass.use(Formio.global('premium'));
|
298
215
|
}
|
299
|
-
if (global('vpat')) {
|
300
|
-
debug('Using vpat module.');
|
301
|
-
Formio.use(global('vpat'));
|
216
|
+
if (Formio.global('vpat')) {
|
217
|
+
Formio.debug('Using vpat module.');
|
218
|
+
Formio.FormioClass.use(Formio.global('vpat'));
|
302
219
|
}
|
303
|
-
if (config.template) {
|
304
|
-
if (config.includeLibs) {
|
305
|
-
addStyles(config.libs[config.template].css);
|
306
|
-
addScript(config.libs[config.template].js);
|
307
|
-
if (config.libs[config.template].fa) {
|
308
|
-
addStyles(config.libs.fontawesome.css, true);
|
220
|
+
if (Formio.config.template) {
|
221
|
+
if (Formio.config.includeLibs) {
|
222
|
+
yield Formio.addStyles(Formio.config.libs[Formio.config.template].css);
|
223
|
+
yield Formio.addScript(Formio.config.libs[Formio.config.template].js);
|
224
|
+
if (Formio.config.libs[Formio.config.template].fa) {
|
225
|
+
yield Formio.addStyles(Formio.config.libs.fontawesome.css, true);
|
309
226
|
}
|
310
227
|
}
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
templateSrc = `${cdn}/@formio/${config.template}@latest/dist/${config.template}.min`;
|
228
|
+
if (Formio.cdn[Formio.config.template]) {
|
229
|
+
const templateSrc = `${Formio.cdn[Formio.config.template]}/${Formio.config.template}.min`;
|
230
|
+
yield Formio.addStyles(`${templateSrc}.css`);
|
231
|
+
Formio.debug(`Using ${Formio.config.template}`);
|
232
|
+
Formio.FormioClass.use(yield Formio.addScript(`${templateSrc}.js`, Formio.config.template));
|
317
233
|
}
|
318
|
-
addStyles(`${templateSrc}.css`);
|
319
|
-
addScript(`${templateSrc}.js`, config.template, (template) => {
|
320
|
-
debug(`Using ${config.template}`);
|
321
|
-
Formio.use(template);
|
322
|
-
renderForm();
|
323
|
-
});
|
324
234
|
}
|
325
|
-
else if (global('uswds')) {
|
326
|
-
debug('Using uswds module.');
|
327
|
-
Formio.use(global('uswds'));
|
235
|
+
else if (Formio.global('uswds')) {
|
236
|
+
Formio.debug('Using uswds module.');
|
237
|
+
Formio.FormioClass.use(Formio.global('uswds'));
|
328
238
|
}
|
329
239
|
// Default bootstrap + fontawesome.
|
330
|
-
else if (config.includeLibs) {
|
331
|
-
Formio.
|
332
|
-
config.libs
|
333
|
-
addStyles(config.libs.fontawesome.css, true);
|
334
|
-
addStyles(config.libs.bootstrap.css);
|
240
|
+
else if (Formio.config.includeLibs) {
|
241
|
+
yield Formio.addStyles(Formio.config.libs.fontawesome.css, true);
|
242
|
+
yield Formio.addStyles(Formio.config.libs.bootstrap.css);
|
335
243
|
}
|
336
|
-
if (config.premium) {
|
337
|
-
addStyles(config.premium.css);
|
338
|
-
|
339
|
-
|
340
|
-
Formio.use(premium);
|
341
|
-
renderForm();
|
342
|
-
});
|
343
|
-
}
|
344
|
-
// Render the form if no template is provided.
|
345
|
-
if (!config.template && !config.premium) {
|
346
|
-
renderForm();
|
244
|
+
if (Formio.config.premium) {
|
245
|
+
yield Formio.addStyles(Formio.config.premium.css);
|
246
|
+
Formio.debug('Using premium');
|
247
|
+
Formio.FormioClass.use(yield Formio.addScript(Formio.config.premium.js, 'premium'));
|
347
248
|
}
|
249
|
+
yield Formio.addStyles(Formio.config.style || `${Formio.cdn.js}/formio.form.min.css`);
|
250
|
+
return yield Formio.renderForm(form, options);
|
348
251
|
});
|
349
252
|
}
|
350
|
-
else {
|
351
|
-
// Show an error if the script cannot be found.
|
352
|
-
document.write('<span>Could not locate the Embedded form.</span>');
|
353
|
-
}
|
354
253
|
}
|
355
|
-
|
254
|
+
Formio.config = {};
|
255
|
+
Formio.loader = null;
|
256
|
+
Formio.cdn = null;
|
257
|
+
Formio.proxy = true;
|
258
|
+
exports.Formio = Formio;
|
package/lib/cjs/Form.d.ts
CHANGED
@@ -12,7 +12,7 @@ export default class Form extends Element {
|
|
12
12
|
* @param {boolean} options.template - Provides a way to inject custom logic into the creation of every element rendered within the form.
|
13
13
|
*
|
14
14
|
* @example
|
15
|
-
* import Form from '
|
15
|
+
* import Form from '@formio/js/Form';
|
16
16
|
* const form = new Form(document.getElementById('formio'), 'https://examples.form.io/example');
|
17
17
|
* form.build();
|
18
18
|
*/
|
package/lib/cjs/Form.js
CHANGED
@@ -44,7 +44,7 @@ class Form extends Element_1.default {
|
|
44
44
|
* @param {boolean} options.template - Provides a way to inject custom logic into the creation of every element rendered within the form.
|
45
45
|
*
|
46
46
|
* @example
|
47
|
-
* import Form from '
|
47
|
+
* import Form from '@formio/js/Form';
|
48
48
|
* const form = new Form(document.getElementById('formio'), 'https://examples.form.io/example');
|
49
49
|
* form.build();
|
50
50
|
*/
|