@formio/js 5.0.0-rc.25 → 5.0.0-rc.27
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/formio.builder.css +10 -0
- package/dist/formio.builder.min.css +1 -1
- package/dist/formio.embed.css +1 -1
- package/dist/formio.embed.js +1 -1
- package/dist/formio.embed.min.css +1 -1
- package/dist/formio.embed.min.js +1 -1
- package/dist/formio.embed.min.js.LICENSE.txt +1 -1
- package/dist/formio.form.css +10 -0
- package/dist/formio.form.js +2 -2
- package/dist/formio.form.min.css +1 -1
- package/dist/formio.form.min.js +1 -1
- package/dist/formio.form.min.js.LICENSE.txt +1 -1
- package/dist/formio.full.css +10 -0
- package/dist/formio.full.js +2 -2
- package/dist/formio.full.min.css +1 -1
- package/dist/formio.full.min.js +1 -1
- package/dist/formio.full.min.js.LICENSE.txt +1 -1
- package/dist/formio.js +1 -1
- package/dist/formio.min.js +1 -1
- package/dist/formio.min.js.LICENSE.txt +1 -1
- package/dist/formio.utils.min.js.LICENSE.txt +1 -1
- package/lib/cjs/Embed.d.ts +26 -6
- package/lib/cjs/Embed.js +91 -37
- package/lib/cjs/Wizard.js +8 -9
- package/lib/cjs/formio.embed.js +1 -0
- package/lib/mjs/Embed.d.ts +26 -6
- package/lib/mjs/Embed.js +88 -38
- package/lib/mjs/Wizard.js +8 -9
- package/lib/mjs/formio.embed.js +1 -0
- package/package.json +2 -1
@@ -1,6 +1,6 @@
|
|
1
1
|
/*! @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 */
|
2
2
|
|
3
|
-
/*! formiojs v5.0.0-rc.
|
3
|
+
/*! formiojs v5.0.0-rc.27 | https://unpkg.com/formiojs@5.0.0-rc.27/LICENSE.txt */
|
4
4
|
|
5
5
|
/**
|
6
6
|
* @license
|
@@ -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.27 | https://unpkg.com/formiojs@5.0.0-rc.27/LICENSE.txt */
|
16
16
|
|
17
17
|
/**
|
18
18
|
* @license
|
package/lib/cjs/Embed.d.ts
CHANGED
@@ -2,22 +2,42 @@ export class Formio {
|
|
2
2
|
static baseUrl: any;
|
3
3
|
static projectUrl: any;
|
4
4
|
static language: any;
|
5
|
-
static wrapper: any;
|
6
|
-
static element: any;
|
7
5
|
static config: {};
|
8
|
-
static loader: null;
|
9
6
|
static cdn: null;
|
10
7
|
static proxy: boolean;
|
8
|
+
static version: string;
|
11
9
|
static setBaseUrl(url: any): Promise<void>;
|
12
10
|
static setProjectUrl(url: any): Promise<void>;
|
13
11
|
static debug(...args: any[]): void;
|
12
|
+
static clearCache(): void;
|
14
13
|
static global(prop: any): any;
|
15
14
|
static createElement(type: any, attrs: any, children: any): any;
|
16
|
-
static addScript(src: any, name: any): Promise<any>;
|
17
|
-
static addStyles(href: any): Promise<void>;
|
15
|
+
static addScript(wrapper: any, src: any, name: any): Promise<any>;
|
16
|
+
static addStyles(wrapper: any, href: any): Promise<void>;
|
18
17
|
static submitDone(instance: any, submission: any): Promise<void>;
|
19
18
|
static formioScript(script: any, builder: any): any;
|
20
|
-
static init(element: any, builder?: boolean): Promise<
|
19
|
+
static init(element: any, builder?: boolean): Promise<any>;
|
21
20
|
static createForm(element: any, form: any, options: any): Promise<any>;
|
22
21
|
static builder(element: any, form: any, options: any): Promise<any>;
|
23
22
|
}
|
23
|
+
export namespace Formio {
|
24
|
+
export { Form };
|
25
|
+
export { FormBuilder };
|
26
|
+
}
|
27
|
+
export class Form {
|
28
|
+
constructor(element: any, form: any, options: any);
|
29
|
+
form: any;
|
30
|
+
element: any;
|
31
|
+
options: any;
|
32
|
+
instance: {
|
33
|
+
proxy: boolean;
|
34
|
+
ready: Promise<any> | undefined;
|
35
|
+
destroy: () => void;
|
36
|
+
};
|
37
|
+
init(): void;
|
38
|
+
ready: Promise<any> | undefined;
|
39
|
+
create(): Promise<any>;
|
40
|
+
setDisplay(display: any): Promise<any> | undefined;
|
41
|
+
}
|
42
|
+
export class FormBuilder extends Form {
|
43
|
+
}
|
package/lib/cjs/Embed.js
CHANGED
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
13
|
};
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
exports.Formio = void 0;
|
15
|
+
exports.FormBuilder = exports.Form = exports.Formio = void 0;
|
16
16
|
const CDN_js_1 = __importDefault(require("./CDN.js"));
|
17
17
|
class Formio {
|
18
18
|
static setBaseUrl(url) {
|
@@ -30,6 +30,11 @@ class Formio {
|
|
30
30
|
console.log(...args);
|
31
31
|
}
|
32
32
|
}
|
33
|
+
static clearCache() {
|
34
|
+
if (Formio.FormioClass) {
|
35
|
+
Formio.FormioClass.clearCache();
|
36
|
+
}
|
37
|
+
}
|
33
38
|
static global(prop) {
|
34
39
|
const globalValue = window[prop];
|
35
40
|
if (globalValue && globalValue.proxy) {
|
@@ -48,20 +53,20 @@ class Formio {
|
|
48
53
|
});
|
49
54
|
return element;
|
50
55
|
}
|
51
|
-
static addScript(src, name) {
|
56
|
+
static addScript(wrapper, src, name) {
|
52
57
|
return __awaiter(this, void 0, void 0, function* () {
|
53
58
|
if (!src) {
|
54
59
|
return Promise.resolve();
|
55
60
|
}
|
56
61
|
if (typeof src !== 'string' && src.length) {
|
57
|
-
return Promise.all(src.map(ref => Formio.addScript(ref)));
|
62
|
+
return Promise.all(src.map(ref => Formio.addScript(wrapper, ref)));
|
58
63
|
}
|
59
64
|
if (name && Formio.global(name)) {
|
60
65
|
Formio.debug(`${name} already loaded.`);
|
61
66
|
return Promise.resolve(Formio.global(name));
|
62
67
|
}
|
63
68
|
Formio.debug('Adding Script', src);
|
64
|
-
|
69
|
+
wrapper.appendChild(Formio.createElement('script', {
|
65
70
|
src
|
66
71
|
}));
|
67
72
|
if (!name) {
|
@@ -79,17 +84,17 @@ class Formio {
|
|
79
84
|
});
|
80
85
|
});
|
81
86
|
}
|
82
|
-
static addStyles(href) {
|
87
|
+
static addStyles(wrapper, href) {
|
83
88
|
return __awaiter(this, void 0, void 0, function* () {
|
84
89
|
if (!href) {
|
85
90
|
return;
|
86
91
|
}
|
87
92
|
if (typeof href !== 'string' && href.length) {
|
88
|
-
href.forEach(ref => Formio.addStyles(ref));
|
93
|
+
href.forEach(ref => Formio.addStyles(wrapper, ref));
|
89
94
|
return;
|
90
95
|
}
|
91
96
|
Formio.debug('Adding Styles', href);
|
92
|
-
|
97
|
+
wrapper.appendChild(Formio.createElement('link', {
|
93
98
|
rel: 'stylesheet',
|
94
99
|
href
|
95
100
|
}));
|
@@ -98,6 +103,10 @@ class Formio {
|
|
98
103
|
static submitDone(instance, submission) {
|
99
104
|
return __awaiter(this, void 0, void 0, function* () {
|
100
105
|
Formio.debug('Submision Complete', submission);
|
106
|
+
const successMessage = (Formio.config.success || '').toString();
|
107
|
+
if (successMessage && successMessage.toLowerCase() !== 'false' && instance.element) {
|
108
|
+
instance.element.innerHTML = `<div class="alert-success" role="alert">${successMessage}</div>`;
|
109
|
+
}
|
101
110
|
let returnUrl = Formio.config.redirect;
|
102
111
|
// Allow form based configuration for return url.
|
103
112
|
if (!returnUrl &&
|
@@ -127,12 +136,15 @@ class Formio {
|
|
127
136
|
}
|
128
137
|
// Return the full script if the builder is being used.
|
129
138
|
static formioScript(script, builder) {
|
130
|
-
|
139
|
+
if (Formio.fullAdded || builder) {
|
140
|
+
Formio.fullAdded = true;
|
141
|
+
return script.replace('formio.form', 'formio.full');
|
142
|
+
}
|
143
|
+
return script;
|
131
144
|
}
|
132
145
|
// eslint-disable-next-line max-statements
|
133
146
|
static init(element, builder = false) {
|
134
147
|
return __awaiter(this, void 0, void 0, function* () {
|
135
|
-
Formio.element = element;
|
136
148
|
Formio.cdn = new CDN_js_1.default(Formio.config.cdn);
|
137
149
|
Formio.config.libs = Formio.config.libs || {
|
138
150
|
uswds: {
|
@@ -147,17 +159,18 @@ class Formio {
|
|
147
159
|
css: `${Formio.cdn.bootstrap}/css/bootstrap.min.css`
|
148
160
|
}
|
149
161
|
};
|
150
|
-
|
162
|
+
const id = Formio.config.id || `formio-${Math.random().toString(36).substring(7)}`;
|
151
163
|
// Create a new wrapper and add the element inside of a new wrapper.
|
152
|
-
|
153
|
-
'id': `"${
|
164
|
+
const wrapper = Formio.createElement('div', {
|
165
|
+
'id': `"${id}-wrapper"`
|
154
166
|
});
|
155
|
-
element.parentNode.insertBefore(
|
167
|
+
element.parentNode.insertBefore(wrapper, element);
|
156
168
|
element.parentNode.removeChild(element);
|
157
|
-
|
169
|
+
wrapper.appendChild(element);
|
158
170
|
// Load the renderer styles.
|
159
|
-
yield Formio.addStyles(Formio.config.embedCSS || `${Formio.cdn.js}/formio.embed.css`);
|
160
|
-
|
171
|
+
yield Formio.addStyles(wrapper, Formio.config.embedCSS || `${Formio.cdn.js}/formio.embed.css`);
|
172
|
+
// Add a loader.
|
173
|
+
wrapper.appendChild(Formio.createElement('div', {
|
161
174
|
'class': 'formio-loader'
|
162
175
|
}, [{
|
163
176
|
tag: 'div',
|
@@ -170,9 +183,8 @@ class Formio {
|
|
170
183
|
class: 'loader text-center'
|
171
184
|
}
|
172
185
|
}]
|
173
|
-
}]);
|
174
|
-
Formio.wrapper.
|
175
|
-
Formio.FormioClass = yield Formio.addScript(Formio.formioScript(Formio.config.script || `${Formio.cdn.js}/formio.form.min.js`, builder), 'Formio');
|
186
|
+
}]));
|
187
|
+
Formio.FormioClass = yield Formio.addScript(wrapper, Formio.formioScript(Formio.config.script || `${Formio.cdn.js}/formio.form.min.js`, builder), 'Formio');
|
176
188
|
Formio.FormioClass.setBaseUrl(Formio.baseUrl || Formio.config.base);
|
177
189
|
Formio.FormioClass.setProjectUrl(Formio.projectUrl || Formio.config.project);
|
178
190
|
Formio.FormioClass.language = Formio.language;
|
@@ -187,17 +199,17 @@ class Formio {
|
|
187
199
|
}
|
188
200
|
if (Formio.config.template) {
|
189
201
|
if (Formio.config.includeLibs) {
|
190
|
-
yield Formio.addStyles(Formio.config.libs[Formio.config.template].css);
|
191
|
-
yield Formio.addScript(Formio.config.libs[Formio.config.template].js);
|
202
|
+
yield Formio.addStyles(wrapper, Formio.config.libs[Formio.config.template].css);
|
203
|
+
yield Formio.addScript(wrapper, Formio.config.libs[Formio.config.template].js);
|
192
204
|
if (Formio.config.libs[Formio.config.template].fa) {
|
193
|
-
yield Formio.addStyles(Formio.config.libs.fontawesome.css);
|
205
|
+
yield Formio.addStyles(wrapper, Formio.config.libs.fontawesome.css);
|
194
206
|
}
|
195
207
|
}
|
196
208
|
if (Formio.cdn[Formio.config.template]) {
|
197
209
|
const templateSrc = `${Formio.cdn[Formio.config.template]}/${Formio.config.template}.min`;
|
198
|
-
yield Formio.addStyles(`${templateSrc}.css`);
|
210
|
+
yield Formio.addStyles(wrapper, `${templateSrc}.css`);
|
199
211
|
Formio.debug(`Using ${Formio.config.template}`);
|
200
|
-
Formio.FormioClass.use(yield Formio.addScript(`${templateSrc}.js`, Formio.config.template));
|
212
|
+
Formio.FormioClass.use(yield Formio.addScript(wrapper, `${templateSrc}.js`, Formio.config.template));
|
201
213
|
}
|
202
214
|
}
|
203
215
|
else if (Formio.global('uswds')) {
|
@@ -206,29 +218,30 @@ class Formio {
|
|
206
218
|
}
|
207
219
|
// Default bootstrap + fontawesome.
|
208
220
|
else if (Formio.config.includeLibs) {
|
209
|
-
yield Formio.addStyles(Formio.config.libs.fontawesome.css);
|
210
|
-
yield Formio.addStyles(Formio.config.libs.bootstrap.css);
|
221
|
+
yield Formio.addStyles(wrapper, Formio.config.libs.fontawesome.css);
|
222
|
+
yield Formio.addStyles(wrapper, Formio.config.libs.bootstrap.css);
|
211
223
|
}
|
212
224
|
if (Formio.config.premium) {
|
213
|
-
yield Formio.addStyles(Formio.config.premium.css);
|
225
|
+
yield Formio.addStyles(wrapper, Formio.config.premium.css);
|
214
226
|
Formio.debug('Using premium');
|
215
|
-
Formio.FormioClass.use(yield Formio.addScript(Formio.config.premium.js, 'premium'));
|
227
|
+
Formio.FormioClass.use(yield Formio.addScript(wrapper, Formio.config.premium.js, 'premium'));
|
216
228
|
}
|
217
|
-
yield Formio.addStyles(Formio.formioScript(Formio.config.style || `${Formio.cdn.js}/formio.form.min.css`, builder));
|
229
|
+
yield Formio.addStyles(wrapper, Formio.formioScript(Formio.config.style || `${Formio.cdn.js}/formio.form.min.css`, builder));
|
218
230
|
if (Formio.config.before) {
|
219
|
-
yield Formio.config.before(Formio.FormioClass,
|
231
|
+
yield Formio.config.before(Formio.FormioClass, element, Formio.config);
|
220
232
|
}
|
221
233
|
Formio.FormioClass.license = true;
|
234
|
+
return wrapper;
|
222
235
|
});
|
223
236
|
}
|
224
237
|
static createForm(element, form, options) {
|
225
238
|
return __awaiter(this, void 0, void 0, function* () {
|
226
|
-
yield Formio.init(element);
|
227
|
-
return Formio.FormioClass.createForm(
|
239
|
+
const wrapper = yield Formio.init(element);
|
240
|
+
return Formio.FormioClass.createForm(element, form, Object.assign(Object.assign({}, options), { noLoader: true })).then((instance) => {
|
228
241
|
Formio.debug('Form created', instance);
|
229
242
|
// Remove the loader.
|
230
243
|
Formio.debug('Removing loader');
|
231
|
-
|
244
|
+
wrapper.removeChild(wrapper.querySelector('.formio-loader'));
|
232
245
|
// Set the default submission data.
|
233
246
|
if (Formio.config.submission) {
|
234
247
|
Formio.debug('Setting submission', Formio.config.submission);
|
@@ -248,11 +261,11 @@ class Formio {
|
|
248
261
|
}
|
249
262
|
static builder(element, form, options) {
|
250
263
|
return __awaiter(this, void 0, void 0, function* () {
|
251
|
-
yield Formio.init(element, true);
|
252
|
-
return Formio.FormioClass.builder(
|
264
|
+
const wrapper = yield Formio.init(element, true);
|
265
|
+
return Formio.FormioClass.builder(element, form, options).then((instance) => {
|
253
266
|
Formio.debug('Builder created', instance);
|
254
267
|
Formio.debug('Removing loader');
|
255
|
-
|
268
|
+
wrapper.removeChild(wrapper.querySelector('.formio-loader'));
|
256
269
|
Formio.debug('Triggering embed event');
|
257
270
|
Formio.FormioClass.events.emit('builderEmbedded', instance);
|
258
271
|
if (Formio.config.after) {
|
@@ -265,7 +278,48 @@ class Formio {
|
|
265
278
|
}
|
266
279
|
}
|
267
280
|
Formio.config = {};
|
268
|
-
Formio.loader = null;
|
269
281
|
Formio.cdn = null;
|
270
282
|
Formio.proxy = true;
|
283
|
+
Formio.version = 'FORMIO_VERSION';
|
271
284
|
exports.Formio = Formio;
|
285
|
+
class Form {
|
286
|
+
constructor(element, form, options) {
|
287
|
+
this.form = form;
|
288
|
+
this.element = element;
|
289
|
+
this.options = options || {};
|
290
|
+
this.init();
|
291
|
+
this.instance = {
|
292
|
+
proxy: true,
|
293
|
+
ready: this.ready,
|
294
|
+
destroy: () => { }
|
295
|
+
};
|
296
|
+
}
|
297
|
+
init() {
|
298
|
+
this.element.innerHTML = '';
|
299
|
+
this.ready = this.create().then((instance) => {
|
300
|
+
this.instance = instance;
|
301
|
+
this.form = instance.form;
|
302
|
+
return instance;
|
303
|
+
});
|
304
|
+
}
|
305
|
+
create() {
|
306
|
+
return Formio.createForm(this.element, this.form, this.options);
|
307
|
+
}
|
308
|
+
setDisplay(display) {
|
309
|
+
if (this.instance.proxy) {
|
310
|
+
return this.ready;
|
311
|
+
}
|
312
|
+
this.form.display = display;
|
313
|
+
this.init();
|
314
|
+
return this.ready;
|
315
|
+
}
|
316
|
+
}
|
317
|
+
exports.Form = Form;
|
318
|
+
class FormBuilder extends Form {
|
319
|
+
create() {
|
320
|
+
return Formio.builder(this.element, this.form, this.options);
|
321
|
+
}
|
322
|
+
}
|
323
|
+
exports.FormBuilder = FormBuilder;
|
324
|
+
Formio.Form = Form;
|
325
|
+
Formio.FormBuilder = FormBuilder;
|
package/lib/cjs/Wizard.js
CHANGED
@@ -778,22 +778,21 @@ class Wizard extends Webform_1.default {
|
|
778
778
|
}
|
779
779
|
}
|
780
780
|
setValue(submission, flags = {}, ignoreEstablishment) {
|
781
|
-
this._submission = submission;
|
782
|
-
if ((flags && flags.fromSubmission && (this.options.readOnly || this.editMode) && !this.isHtmlRenderMode()) ||
|
783
|
-
(flags && flags.fromSubmission && (this.prefixComps.length || this.suffixComps.length) && submission._id) ||
|
784
|
-
(this.options.server && (this.prefixComps.length || this.suffixComps.length))) {
|
785
|
-
this._data = submission.data;
|
786
|
-
}
|
787
|
-
if (!ignoreEstablishment) {
|
788
|
-
this.establishPages(submission.data);
|
789
|
-
}
|
790
781
|
const changed = this.getPages({ all: true }).reduce((changed, page) => {
|
791
782
|
return this.setNestedValue(page, submission.data, flags, changed) || changed;
|
792
783
|
}, false);
|
784
|
+
if (!flags.sanitize) {
|
785
|
+
this.mergeData(this.data, submission.data);
|
786
|
+
}
|
793
787
|
if (changed) {
|
794
788
|
this.pageFieldLogic(this.page);
|
795
789
|
}
|
796
790
|
this.setEditMode(submission);
|
791
|
+
submission.data = this.data;
|
792
|
+
this._submission = submission;
|
793
|
+
if (!ignoreEstablishment) {
|
794
|
+
this.establishPages(submission.data);
|
795
|
+
}
|
797
796
|
return changed;
|
798
797
|
}
|
799
798
|
isClickable(page, index) {
|
package/lib/cjs/formio.embed.js
CHANGED
@@ -43,6 +43,7 @@ if (thisScript) {
|
|
43
43
|
config: {},
|
44
44
|
redirect: (query.return || query.redirect),
|
45
45
|
embedCSS: (`${config.updatePath ? config.updatePath() : scriptSrc}/formio.embed.css`),
|
46
|
+
success: query.success || 'Thank you for your submission!',
|
46
47
|
before: null,
|
47
48
|
after: null
|
48
49
|
}, config);
|
package/lib/mjs/Embed.d.ts
CHANGED
@@ -2,22 +2,42 @@ export class Formio {
|
|
2
2
|
static baseUrl: any;
|
3
3
|
static projectUrl: any;
|
4
4
|
static language: any;
|
5
|
-
static wrapper: any;
|
6
|
-
static element: any;
|
7
5
|
static config: {};
|
8
|
-
static loader: null;
|
9
6
|
static cdn: null;
|
10
7
|
static proxy: boolean;
|
8
|
+
static version: string;
|
11
9
|
static setBaseUrl(url: any): Promise<void>;
|
12
10
|
static setProjectUrl(url: any): Promise<void>;
|
13
11
|
static debug(...args: any[]): void;
|
12
|
+
static clearCache(): void;
|
14
13
|
static global(prop: any): any;
|
15
14
|
static createElement(type: any, attrs: any, children: any): any;
|
16
|
-
static addScript(src: any, name: any): Promise<any>;
|
17
|
-
static addStyles(href: any): Promise<void>;
|
15
|
+
static addScript(wrapper: any, src: any, name: any): Promise<any>;
|
16
|
+
static addStyles(wrapper: any, href: any): Promise<void>;
|
18
17
|
static submitDone(instance: any, submission: any): Promise<void>;
|
19
18
|
static formioScript(script: any, builder: any): any;
|
20
|
-
static init(element: any, builder?: boolean): Promise<
|
19
|
+
static init(element: any, builder?: boolean): Promise<any>;
|
21
20
|
static createForm(element: any, form: any, options: any): Promise<any>;
|
22
21
|
static builder(element: any, form: any, options: any): Promise<any>;
|
23
22
|
}
|
23
|
+
export namespace Formio {
|
24
|
+
export { Form };
|
25
|
+
export { FormBuilder };
|
26
|
+
}
|
27
|
+
export class Form {
|
28
|
+
constructor(element: any, form: any, options: any);
|
29
|
+
form: any;
|
30
|
+
element: any;
|
31
|
+
options: any;
|
32
|
+
instance: {
|
33
|
+
proxy: boolean;
|
34
|
+
ready: Promise<any> | undefined;
|
35
|
+
destroy: () => void;
|
36
|
+
};
|
37
|
+
init(): void;
|
38
|
+
ready: Promise<any> | undefined;
|
39
|
+
create(): Promise<any>;
|
40
|
+
setDisplay(display: any): Promise<any> | undefined;
|
41
|
+
}
|
42
|
+
export class FormBuilder extends Form {
|
43
|
+
}
|
package/lib/mjs/Embed.js
CHANGED
@@ -3,12 +3,10 @@ class Formio {
|
|
3
3
|
static baseUrl;
|
4
4
|
static projectUrl;
|
5
5
|
static language;
|
6
|
-
static wrapper;
|
7
|
-
static element;
|
8
6
|
static config = {};
|
9
|
-
static loader = null;
|
10
7
|
static cdn = null;
|
11
8
|
static proxy = true;
|
9
|
+
static version = 'FORMIO_VERSION';
|
12
10
|
static async setBaseUrl(url) {
|
13
11
|
Formio.baseUrl = url;
|
14
12
|
}
|
@@ -20,6 +18,11 @@ class Formio {
|
|
20
18
|
console.log(...args);
|
21
19
|
}
|
22
20
|
}
|
21
|
+
static clearCache() {
|
22
|
+
if (Formio.FormioClass) {
|
23
|
+
Formio.FormioClass.clearCache();
|
24
|
+
}
|
25
|
+
}
|
23
26
|
static global(prop) {
|
24
27
|
const globalValue = window[prop];
|
25
28
|
if (globalValue && globalValue.proxy) {
|
@@ -38,19 +41,19 @@ class Formio {
|
|
38
41
|
});
|
39
42
|
return element;
|
40
43
|
}
|
41
|
-
static async addScript(src, name) {
|
44
|
+
static async addScript(wrapper, src, name) {
|
42
45
|
if (!src) {
|
43
46
|
return Promise.resolve();
|
44
47
|
}
|
45
48
|
if (typeof src !== 'string' && src.length) {
|
46
|
-
return Promise.all(src.map(ref => Formio.addScript(ref)));
|
49
|
+
return Promise.all(src.map(ref => Formio.addScript(wrapper, ref)));
|
47
50
|
}
|
48
51
|
if (name && Formio.global(name)) {
|
49
52
|
Formio.debug(`${name} already loaded.`);
|
50
53
|
return Promise.resolve(Formio.global(name));
|
51
54
|
}
|
52
55
|
Formio.debug('Adding Script', src);
|
53
|
-
|
56
|
+
wrapper.appendChild(Formio.createElement('script', {
|
54
57
|
src
|
55
58
|
}));
|
56
59
|
if (!name) {
|
@@ -67,22 +70,26 @@ class Formio {
|
|
67
70
|
}, 100);
|
68
71
|
});
|
69
72
|
}
|
70
|
-
static async addStyles(href) {
|
73
|
+
static async addStyles(wrapper, href) {
|
71
74
|
if (!href) {
|
72
75
|
return;
|
73
76
|
}
|
74
77
|
if (typeof href !== 'string' && href.length) {
|
75
|
-
href.forEach(ref => Formio.addStyles(ref));
|
78
|
+
href.forEach(ref => Formio.addStyles(wrapper, ref));
|
76
79
|
return;
|
77
80
|
}
|
78
81
|
Formio.debug('Adding Styles', href);
|
79
|
-
|
82
|
+
wrapper.appendChild(Formio.createElement('link', {
|
80
83
|
rel: 'stylesheet',
|
81
84
|
href
|
82
85
|
}));
|
83
86
|
}
|
84
87
|
static async submitDone(instance, submission) {
|
85
88
|
Formio.debug('Submision Complete', submission);
|
89
|
+
const successMessage = (Formio.config.success || '').toString();
|
90
|
+
if (successMessage && successMessage.toLowerCase() !== 'false' && instance.element) {
|
91
|
+
instance.element.innerHTML = `<div class="alert-success" role="alert">${successMessage}</div>`;
|
92
|
+
}
|
86
93
|
let returnUrl = Formio.config.redirect;
|
87
94
|
// Allow form based configuration for return url.
|
88
95
|
if (!returnUrl &&
|
@@ -111,11 +118,14 @@ class Formio {
|
|
111
118
|
}
|
112
119
|
// Return the full script if the builder is being used.
|
113
120
|
static formioScript(script, builder) {
|
114
|
-
|
121
|
+
if (Formio.fullAdded || builder) {
|
122
|
+
Formio.fullAdded = true;
|
123
|
+
return script.replace('formio.form', 'formio.full');
|
124
|
+
}
|
125
|
+
return script;
|
115
126
|
}
|
116
127
|
// eslint-disable-next-line max-statements
|
117
128
|
static async init(element, builder = false) {
|
118
|
-
Formio.element = element;
|
119
129
|
Formio.cdn = new CDN(Formio.config.cdn);
|
120
130
|
Formio.config.libs = Formio.config.libs || {
|
121
131
|
uswds: {
|
@@ -130,17 +140,18 @@ class Formio {
|
|
130
140
|
css: `${Formio.cdn.bootstrap}/css/bootstrap.min.css`
|
131
141
|
}
|
132
142
|
};
|
133
|
-
|
143
|
+
const id = Formio.config.id || `formio-${Math.random().toString(36).substring(7)}`;
|
134
144
|
// Create a new wrapper and add the element inside of a new wrapper.
|
135
|
-
|
136
|
-
'id': `"${
|
145
|
+
const wrapper = Formio.createElement('div', {
|
146
|
+
'id': `"${id}-wrapper"`
|
137
147
|
});
|
138
|
-
element.parentNode.insertBefore(
|
148
|
+
element.parentNode.insertBefore(wrapper, element);
|
139
149
|
element.parentNode.removeChild(element);
|
140
|
-
|
150
|
+
wrapper.appendChild(element);
|
141
151
|
// Load the renderer styles.
|
142
|
-
await Formio.addStyles(Formio.config.embedCSS || `${Formio.cdn.js}/formio.embed.css`);
|
143
|
-
|
152
|
+
await Formio.addStyles(wrapper, Formio.config.embedCSS || `${Formio.cdn.js}/formio.embed.css`);
|
153
|
+
// Add a loader.
|
154
|
+
wrapper.appendChild(Formio.createElement('div', {
|
144
155
|
'class': 'formio-loader'
|
145
156
|
}, [{
|
146
157
|
tag: 'div',
|
@@ -153,9 +164,8 @@ class Formio {
|
|
153
164
|
class: 'loader text-center'
|
154
165
|
}
|
155
166
|
}]
|
156
|
-
}]);
|
157
|
-
Formio.wrapper.
|
158
|
-
Formio.FormioClass = await Formio.addScript(Formio.formioScript(Formio.config.script || `${Formio.cdn.js}/formio.form.min.js`, builder), 'Formio');
|
167
|
+
}]));
|
168
|
+
Formio.FormioClass = await Formio.addScript(wrapper, Formio.formioScript(Formio.config.script || `${Formio.cdn.js}/formio.form.min.js`, builder), 'Formio');
|
159
169
|
Formio.FormioClass.setBaseUrl(Formio.baseUrl || Formio.config.base);
|
160
170
|
Formio.FormioClass.setProjectUrl(Formio.projectUrl || Formio.config.project);
|
161
171
|
Formio.FormioClass.language = Formio.language;
|
@@ -170,17 +180,17 @@ class Formio {
|
|
170
180
|
}
|
171
181
|
if (Formio.config.template) {
|
172
182
|
if (Formio.config.includeLibs) {
|
173
|
-
await Formio.addStyles(Formio.config.libs[Formio.config.template].css);
|
174
|
-
await Formio.addScript(Formio.config.libs[Formio.config.template].js);
|
183
|
+
await Formio.addStyles(wrapper, Formio.config.libs[Formio.config.template].css);
|
184
|
+
await Formio.addScript(wrapper, Formio.config.libs[Formio.config.template].js);
|
175
185
|
if (Formio.config.libs[Formio.config.template].fa) {
|
176
|
-
await Formio.addStyles(Formio.config.libs.fontawesome.css);
|
186
|
+
await Formio.addStyles(wrapper, Formio.config.libs.fontawesome.css);
|
177
187
|
}
|
178
188
|
}
|
179
189
|
if (Formio.cdn[Formio.config.template]) {
|
180
190
|
const templateSrc = `${Formio.cdn[Formio.config.template]}/${Formio.config.template}.min`;
|
181
|
-
await Formio.addStyles(`${templateSrc}.css`);
|
191
|
+
await Formio.addStyles(wrapper, `${templateSrc}.css`);
|
182
192
|
Formio.debug(`Using ${Formio.config.template}`);
|
183
|
-
Formio.FormioClass.use(await Formio.addScript(`${templateSrc}.js`, Formio.config.template));
|
193
|
+
Formio.FormioClass.use(await Formio.addScript(wrapper, `${templateSrc}.js`, Formio.config.template));
|
184
194
|
}
|
185
195
|
}
|
186
196
|
else if (Formio.global('uswds')) {
|
@@ -189,30 +199,31 @@ class Formio {
|
|
189
199
|
}
|
190
200
|
// Default bootstrap + fontawesome.
|
191
201
|
else if (Formio.config.includeLibs) {
|
192
|
-
await Formio.addStyles(Formio.config.libs.fontawesome.css);
|
193
|
-
await Formio.addStyles(Formio.config.libs.bootstrap.css);
|
202
|
+
await Formio.addStyles(wrapper, Formio.config.libs.fontawesome.css);
|
203
|
+
await Formio.addStyles(wrapper, Formio.config.libs.bootstrap.css);
|
194
204
|
}
|
195
205
|
if (Formio.config.premium) {
|
196
|
-
await Formio.addStyles(Formio.config.premium.css);
|
206
|
+
await Formio.addStyles(wrapper, Formio.config.premium.css);
|
197
207
|
Formio.debug('Using premium');
|
198
|
-
Formio.FormioClass.use(await Formio.addScript(Formio.config.premium.js, 'premium'));
|
208
|
+
Formio.FormioClass.use(await Formio.addScript(wrapper, Formio.config.premium.js, 'premium'));
|
199
209
|
}
|
200
|
-
await Formio.addStyles(Formio.formioScript(Formio.config.style || `${Formio.cdn.js}/formio.form.min.css`, builder));
|
210
|
+
await Formio.addStyles(wrapper, Formio.formioScript(Formio.config.style || `${Formio.cdn.js}/formio.form.min.css`, builder));
|
201
211
|
if (Formio.config.before) {
|
202
|
-
await Formio.config.before(Formio.FormioClass,
|
212
|
+
await Formio.config.before(Formio.FormioClass, element, Formio.config);
|
203
213
|
}
|
204
214
|
Formio.FormioClass.license = true;
|
215
|
+
return wrapper;
|
205
216
|
}
|
206
217
|
static async createForm(element, form, options) {
|
207
|
-
await Formio.init(element);
|
208
|
-
return Formio.FormioClass.createForm(
|
218
|
+
const wrapper = await Formio.init(element);
|
219
|
+
return Formio.FormioClass.createForm(element, form, {
|
209
220
|
...options,
|
210
221
|
...{ noLoader: true }
|
211
222
|
}).then((instance) => {
|
212
223
|
Formio.debug('Form created', instance);
|
213
224
|
// Remove the loader.
|
214
225
|
Formio.debug('Removing loader');
|
215
|
-
|
226
|
+
wrapper.removeChild(wrapper.querySelector('.formio-loader'));
|
216
227
|
// Set the default submission data.
|
217
228
|
if (Formio.config.submission) {
|
218
229
|
Formio.debug('Setting submission', Formio.config.submission);
|
@@ -230,11 +241,11 @@ class Formio {
|
|
230
241
|
});
|
231
242
|
}
|
232
243
|
static async builder(element, form, options) {
|
233
|
-
await Formio.init(element, true);
|
234
|
-
return Formio.FormioClass.builder(
|
244
|
+
const wrapper = await Formio.init(element, true);
|
245
|
+
return Formio.FormioClass.builder(element, form, options).then((instance) => {
|
235
246
|
Formio.debug('Builder created', instance);
|
236
247
|
Formio.debug('Removing loader');
|
237
|
-
|
248
|
+
wrapper.removeChild(wrapper.querySelector('.formio-loader'));
|
238
249
|
Formio.debug('Triggering embed event');
|
239
250
|
Formio.FormioClass.events.emit('builderEmbedded', instance);
|
240
251
|
if (Formio.config.after) {
|
@@ -246,3 +257,42 @@ class Formio {
|
|
246
257
|
}
|
247
258
|
}
|
248
259
|
export { Formio };
|
260
|
+
export class Form {
|
261
|
+
constructor(element, form, options) {
|
262
|
+
this.form = form;
|
263
|
+
this.element = element;
|
264
|
+
this.options = options || {};
|
265
|
+
this.init();
|
266
|
+
this.instance = {
|
267
|
+
proxy: true,
|
268
|
+
ready: this.ready,
|
269
|
+
destroy: () => { }
|
270
|
+
};
|
271
|
+
}
|
272
|
+
init() {
|
273
|
+
this.element.innerHTML = '';
|
274
|
+
this.ready = this.create().then((instance) => {
|
275
|
+
this.instance = instance;
|
276
|
+
this.form = instance.form;
|
277
|
+
return instance;
|
278
|
+
});
|
279
|
+
}
|
280
|
+
create() {
|
281
|
+
return Formio.createForm(this.element, this.form, this.options);
|
282
|
+
}
|
283
|
+
setDisplay(display) {
|
284
|
+
if (this.instance.proxy) {
|
285
|
+
return this.ready;
|
286
|
+
}
|
287
|
+
this.form.display = display;
|
288
|
+
this.init();
|
289
|
+
return this.ready;
|
290
|
+
}
|
291
|
+
}
|
292
|
+
export class FormBuilder extends Form {
|
293
|
+
create() {
|
294
|
+
return Formio.builder(this.element, this.form, this.options);
|
295
|
+
}
|
296
|
+
}
|
297
|
+
Formio.Form = Form;
|
298
|
+
Formio.FormBuilder = FormBuilder;
|