@formio/js 5.0.0-rc.24 → 5.0.0-rc.26

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