Skip to content

Commit

Permalink
Fixed tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
travist committed Oct 16, 2023
1 parent 3ba9a9c commit 0789e81
Show file tree
Hide file tree
Showing 14 changed files with 213 additions and 175 deletions.
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
"version": "5.0.0-rc.28",
"description": "JavaScript powered Forms with JSON Form Builder",
"main": "lib/cjs/index.js",
"module": "lib/mjs/index.js",
"exports": {
".": {
"import": "./lib/mjs/index.js",
"import": "./lib/cjs/index.js",
"require": "./lib/cjs/index.js"
},
"./sdk": {
"import": "./lib/mjs/Formio.js",
"import": "./lib/cjs/Formio.js",
"require": "./lib/cjs/Formio.js"
},
"./utils": {
"import": "./lib/mjs/utils/index.js",
"import": "./lib/cjs/utils/index.js",
"require": "./lib/cjs/utils/index.js"
},
"./form": {
"import": "./lib/mjs/formio.form.js",
"import": "./lib/cjs/formio.form.js",
"require": "./lib/cjs/formio.form.js"
},
"./embed": {
"import": "./lib/mjs/formio.embed.js",
"require": "./lib/cjs/formio.embed.js"
}
"import": "./lib/cjs/Embed.js",
"require": "./lib/cjs/Embed.js"
},
"./dist/*": "./dist/*"
},
"types": "index.d.ts",
"files": [
Expand Down Expand Up @@ -80,7 +80,7 @@
"dependencies": {
"@formio/bootstrap": "^3.0.0-rc.13",
"@formio/choices.js": "^10.2.0",
"@formio/core": "^1.3.0-rc.19",
"@formio/core": "^1.3.0-rc.21",
"@formio/text-mask-addons": "^3.8.0-formio.2",
"@formio/vanilla-text-mask": "^5.1.1-formio.1",
"autocompleter": "^8.0.4",
Expand Down
4 changes: 2 additions & 2 deletions src/CDN.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// like Formio.cdn.ace === 'http://cdn.form.io/ace/1.4.12'.
// For latest version use empty string
class CDN {
constructor(baseUrl) {
constructor(baseUrl, overrides = {}) {
this.baseUrl = baseUrl || 'https://cdn.form.io';
this.overrides = {};
this.overrides = overrides;
this.libs = {
'js': '',
'ace': '1.4.12',
Expand Down
83 changes: 70 additions & 13 deletions src/Embed.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,52 @@
import CDN from './CDN.js';
export class Formio {
static FormioClass = null;
static baseUrl;
static projectUrl;
static pathType;
static language;
static config = {};
static cdn = null;
static proxy = true;
static cdn = new CDN();
static modules = [];
static icons = '';
static formioReady = new Promise((ready, reject) => {
Formio._formioReady = ready;
Formio._formioReadyReject = reject;
});
static version = 'FORMIO_VERSION';
static async setBaseUrl(url) {
static setBaseUrl(url, norecurse) {
Formio.baseUrl = url;
if (!norecurse && Formio.FormioClass) {
Formio.FormioClass.setBaseUrl(url);
}
}

static setApiUrl(url, norecurse) {
Formio.baseUrl = url;
if (!norecurse && Formio.FormioClass) {
Formio.FormioClass.setApiUrl(url);
}
}

static setProjectUrl(url, norecurse) {
Formio.projectUrl = url;
if (!norecurse && Formio.FormioClass) {
Formio.FormioClass.setProjectUrl(url);
}
}
static async setProjectUrl(url) {

static setAppUrl(url, norecurse) {
Formio.projectUrl = url;
if (!norecurse && Formio.FormioClass) {
Formio.FormioClass.setAppUrl(url);
}
}

static setPathType(type, norecurse) {
Formio.pathType = type;
if (!norecurse && Formio.FormioClass) {
Formio.FormioClass.setPathType(type);
}
}

static debug(...args) {
Expand All @@ -26,15 +61,24 @@ export class Formio {
}
}

static global(prop) {
static global(prop, flag = '') {
const globalValue = window[prop];
if (globalValue && globalValue.proxy) {
if (flag && globalValue && !globalValue[flag]) {
return null;
}
Formio.debug(`Getting global ${prop}`, globalValue);
return globalValue;
}

static use(module) {
if (Formio.FormioClass && Formio.FormioClass.isRenderer) {
Formio.FormioClass.use(module);
}
else {
Formio.modules.push(module);
}
}

static createElement(type, attrs, children) {
const element = document.createElement(type);
Object.keys(attrs).forEach(key => {
Expand All @@ -46,14 +90,14 @@ export class Formio {
return element;
}

static async addScript(wrapper, src, name) {
static async addScript(wrapper, src, name, flag = '') {
if (!src) {
return Promise.resolve();
}
if (typeof src !== 'string' && src.length) {
return Promise.all(src.map(ref => Formio.addScript(wrapper, ref)));
}
if (name && Formio.global(name)) {
if (name && Formio.global(name, flag)) {
Formio.debug(`${name} already loaded.`);
return Promise.resolve(Formio.global(name));
}
Expand All @@ -67,7 +111,7 @@ export class Formio {
return new Promise((resolve) => {
Formio.debug(`Waiting to load ${name}`);
const wait = setInterval(() => {
if (Formio.global(name)) {
if (Formio.global(name, flag)) {
clearInterval(wait);
Formio.debug(`${name} loaded.`);
resolve(Formio.global(name));
Expand Down Expand Up @@ -143,7 +187,7 @@ export class Formio {

// eslint-disable-next-line max-statements
static async init(element, options = {}, builder = false) {
Formio.cdn = new CDN(Formio.config.cdn);
Formio.cdn = new CDN(Formio.config.cdn, Formio.config.cdnUrls || {});
Formio.config.libs = Formio.config.libs || {
uswds: {
fa: true,
Expand Down Expand Up @@ -199,11 +243,23 @@ export class Formio {
Formio.FormioClass = await Formio.addScript(
wrapper,
Formio.formioScript(Formio.config.script || `${Formio.cdn.js}/${renderer}.js`, builder),
'Formio'
'Formio',
builder ? 'isBuilder' : 'isRenderer'
);
Formio.FormioClass.setBaseUrl(Formio.baseUrl || Formio.config.base);
Formio.FormioClass.setProjectUrl(Formio.projectUrl || Formio.config.project);
Formio.FormioClass.setBaseUrl(options.baseUrl || Formio.baseUrl || Formio.config.base);
Formio.FormioClass.setProjectUrl(options.projectUrl || Formio.projectUrl || Formio.config.project);
Formio.FormioClass.language = Formio.language;
Formio.modules.forEach((module) => {
Formio.FormioClass.use(module);
});

if (Formio.icons) {
Formio.FormioClass.icons = Formio.icons;
}

if (Formio.pathType) {
Formio.FormioClass.setPathType(Formio.pathType);
}

// Add premium modules
if (Formio.global('premium')) {
Expand Down Expand Up @@ -252,6 +308,7 @@ export class Formio {
await Formio.config.before(Formio.FormioClass, element, Formio.config);
}
Formio.FormioClass.license = true;
Formio._formioReady(Formio.FormioClass);
return wrapper;
}

Expand Down
Loading

0 comments on commit 0789e81

Please sign in to comment.