Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expanding integration of @formio/core into renderer. #5576

Closed
wants to merge 73 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
fa7bf41
wip: add linting jsdoc etc
brendanbond Apr 19, 2024
6867afc
Upgraded dependencies.
travist Apr 23, 2024
d5654b8
Updated build.
travist Apr 23, 2024
8111e54
Merge branch 'master' of github.com:formio/formio.js into dev.tt
travist Apr 23, 2024
c337566
Updated package.
travist Apr 23, 2024
8914266
Updated version.
travist Apr 23, 2024
fbeae9a
Exporting sdk as FormioCore so it can be imported and properly tree-s…
travist Apr 23, 2024
33febf2
Properly export the Evaluator.
travist Apr 23, 2024
0c43678
Re-export methods from @formio/core for the utils functions.
travist Apr 23, 2024
7de4a8c
Update templates.
travist Apr 23, 2024
b0b7763
Re-adding findComponents.
travist Apr 23, 2024
be3876b
Version bump.
travist Apr 23, 2024
eef5b02
merge master and fix conflicts
brendanbond Apr 25, 2024
8d20d51
Adding more jsdocs.
travist Apr 25, 2024
a7039a2
replace esdoc with jsdoc
brendanbond Apr 25, 2024
06404e8
remove esdoc config file
brendanbond Apr 25, 2024
1d1efe4
lint a bunch of files and add lint yarn script
brendanbond Apr 25, 2024
b2bb269
Adding esdocs to src/Element.js
travist Apr 25, 2024
5cff9ad
jsdoc for Providers.js
Apr 25, 2024
167d9b9
update webform jsdoc types
brendanbond Apr 25, 2024
ace3ef0
minor
brendanbond Apr 25, 2024
b4777bf
fix linting errors
brendanbond Apr 25, 2024
b33f306
update types for nested component
brendanbond Apr 25, 2024
913986b
breadCrumbSettings -> breadcrumbSettings at line 142
ryanformio Apr 25, 2024
24e2e10
breadCrumbSettings -> breadcrumbSettings at line 142, resolve conflicts
ryanformio Apr 25, 2024
002fbc3
update formio.form.js jsdoc
brendanbond Apr 25, 2024
d099ec7
Merge branch 'devex/jsdoc-migration' of github.com:formio/formio.js i…
brendanbond Apr 25, 2024
e94e31e
Adding some jsdocs to src/components/_classes/component/Component.js
travist Apr 25, 2024
3f81d9b
jsdoc for address provider base class and azure address
Apr 25, 2024
24298a6
Merge branch 'devex/jsdoc-migration' of https://github.com/formio/for…
Apr 25, 2024
a158cb8
one warning left at line 16, did not want to alter constructor logic …
ryanformio Apr 25, 2024
942c165
Merge branch 'devex/jsdoc-migration' of github.com:formio/formio.js i…
ryanformio Apr 25, 2024
285eb05
Merge branch 'master' of github.com:formio/formio.js into dev.tt
travist Apr 26, 2024
9f35324
Version bump.
travist Apr 27, 2024
818de22
address provider jsdoc
May 2, 2024
b3e19b6
Adding component class docs.
travist May 2, 2024
b8d7303
Merge branch 'devex/jsdoc-migration' of github.com:formio/formio.js i…
travist May 2, 2024
8d515f8
Working on utils eslint.
travist May 2, 2024
308aa2a
WIP: update jsdoc
brendanbond May 3, 2024
78662f4
Merge branch 'master' of github.com:formio/formio.js into dev.tt
travist May 3, 2024
8c19e92
Updated build.
travist May 3, 2024
2a36250
update types to parent Form class; add builder options type
brendanbond May 6, 2024
3487ef6
Merge branch 'devex/jsdoc-migration' into dev.tt
travist May 7, 2024
1b5b070
minor update
brendanbond May 7, 2024
86ebb29
Fixed exported utils method signature.
travist May 7, 2024
3982848
merge conflicts
brendanbond May 9, 2024
5522764
Updated version.
travist May 9, 2024
2c840c4
Re-export methods from @formio/core for the utils functions.
travist Apr 23, 2024
fcaf8bd
Re-adding findComponents.
travist Apr 23, 2024
f45dbd4
Merge remote-tracking branch 'refs/remotes/origin/devex/jsdoc-migrati…
brendanbond May 9, 2024
3e0998c
JSDoc: Field.js
edwinanciani May 9, 2024
17ce188
update formbuilder options; type listcomponent and child classes
brendanbond May 9, 2024
85da5ab
Merge remote-tracking branch 'refs/remotes/origin/devex/jsdoc-migrati…
brendanbond May 9, 2024
b7cf90f
type definitions for file providers
May 9, 2024
1cc96c1
Merge branch 'devex/jsdoc-migration' of https://github.com/formio/for…
May 9, 2024
c83a783
resolve FormBuilder eslint warnings
brendanbond May 9, 2024
2dc946e
Merge remote-tracking branch 'refs/remotes/origin/devex/jsdoc-migrati…
brendanbond May 9, 2024
fd4b5e0
fix password strength linting warnings and fileProcessor lints
brendanbond May 9, 2024
3e6a8fa
whoopsie - minor typo
brendanbond May 9, 2024
ee5fe59
Updated utils docs.
travist May 9, 2024
6f7c968
Merge branch 'devex/jsdoc-migration' of github.com:formio/formio.js i…
travist May 9, 2024
ded3f65
cleaned up lint errors
May 9, 2024
f6bc550
Merge branch 'devex/jsdoc-migration' of https://github.com/formio/for…
May 9, 2024
6358b85
jsDoc added to Multvalue.js
ryanformio May 9, 2024
688c6b5
JSDoc-Update: NestedComponent.js
edwinanciani May 9, 2024
8530c59
fix linter warnings for Input, ListComponent, and Multivalue
brendanbond May 9, 2024
124fa12
fix merge conflicts
brendanbond May 9, 2024
f6e9d26
Merge branch 'devex/jsdoc-migration' of github.com:formio/formio.js i…
travist May 16, 2024
0c8518c
Updated build.
travist May 16, 2024
39dcf41
Updated version.
travist May 16, 2024
80696a1
Adding better exports.
travist May 16, 2024
0b71c4b
Merge branch 'master' of github.com:formio/formio.js into dev.tt
travist May 16, 2024
0749b1f
Fixing merge conflicts.
travist May 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion embed.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './types/Embed';
export * from './lib/cjs/InlineEmbed';
1 change: 1 addition & 0 deletions form.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/cjs/formio.form';
Binary file added formio-js-v5.0.0-rc.27.tgz
Binary file not shown.
32 changes: 18 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@formio/js",
"version": "5.0.0-rc.43",
"version": "5.0.0-rc.54",
"description": "JavaScript powered Forms with JSON Form Builder",
"main": "lib/cjs/index.js",
"exports": {
Expand All @@ -21,14 +21,18 @@
"require": "./lib/cjs/formio.form.js"
},
"./embed": {
"import": "./lib/cjs/Embed.js",
"require": "./lib/cjs/Embed.js"
"import": "./lib/cjs/InlineEmbed.js",
"require": "./lib/cjs/InlineEmbed.js"
},
"./dist/*": "./dist/*"
},
"files": [
"dist",
"lib"
"lib",
"embed.d.ts",
"form.d.ts",
"sdk.d.ts",
"utils.d.ts"
],
"pre-commit": [
"lint"
Expand Down Expand Up @@ -75,9 +79,9 @@
},
"homepage": "https://github.com/formio/formio.js#readme",
"dependencies": {
"@formio/bootstrap": "^3.0.0-rc.22",
"@formio/bootstrap": "^3.0.0-rc.24",
"@formio/choices.js": "^10.2.1",
"@formio/core": "^2.1.0-dev.tt.2",
"@formio/core": "^2.1.0-dev.tt.8",
"@formio/text-mask-addons": "^3.8.0-formio.2",
"@formio/vanilla-text-mask": "^5.1.1-formio.1",
"abortcontroller-polyfill": "^1.7.5",
Expand All @@ -86,10 +90,10 @@
"browser-cookies": "^1.2.0",
"browser-md5-file": "^1.1.1",
"compare-versions": "^6.0.0-rc.2",
"core-js": "^3.37.0",
"core-js": "^3.37.1",
"dialog-polyfill": "^0.5.6",
"dom-autoscroller": "^2.3.4",
"dompurify": "^3.1.0",
"dompurify": "^3.1.3",
"downloadjs": "^1.4.7",
"dragula": "^3.7.3",
"eventemitter3": "^5.0.1",
Expand All @@ -105,17 +109,17 @@
"lodash": "^4.17.21",
"moment": "^2.29.4",
"moment-timezone": "^0.5.44",
"quill": "^2.0.0-rc.4",
"quill": "^2.0.2",
"signature_pad": "^4.2.0",
"string-hash": "^1.1.3",
"tippy.js": "^6.3.7",
"uuid": "^9.0.0",
"vanilla-picker": "^2.12.3"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^7.6.0",
"@typescript-eslint/parser": "^7.6.0",
"ace-builds": "1.33.0",
"@typescript-eslint/eslint-plugin": "^7.9.0",
"@typescript-eslint/parser": "^7.9.0",
"ace-builds": "1.33.2",
"async-limiter": "^2.0.0",
"bootstrap-icons": "^1.10.5",
"bootswatch": "^5.3.3",
Expand All @@ -125,7 +129,7 @@
"ejs-loader": "^0.5.0",
"escape-string-regexp": "^5.0.0",
"eslint": "^8.57.0",
"eslint-plugin-jsdoc": "^48.2.3",
"eslint-plugin-jsdoc": "^48.2.5",
"fetch-mock": "^9.11.0",
"file-loader": "^6.2.0",
"flatpickr": "^4.6.13",
Expand Down Expand Up @@ -157,7 +161,7 @@
"pretty": "^2.0.0",
"pygments-css": "^1.0.0",
"raw-loader": "^4.0.2",
"sass": "^1.74.1",
"sass": "^1.77.1",
"shortcut-buttons-flatpickr": "^0.4.0",
"sinon": "^17.0.1",
"string-replace-loader": "^3.1.0",
Expand Down
1 change: 1 addition & 0 deletions sdk.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/cjs/Formio';
113 changes: 113 additions & 0 deletions src/InlineEmbed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { Formio } from './Embed';
/**
* Inline embed a form within a webpage.
* @param {*} config - Configuration to configure how the inline embed is rendered.
*/
export function embed(config = {}) {
const scripts = document.getElementsByTagName('script');
config = Object.assign({}, window.FormioConfig || {}, config);
let thisScript = null;
let i = scripts.length;
const scriptName = config.scriptName || 'formio.embed.';
while (i--) {
if (
scripts[i].src && (scripts[i].src.indexOf(scriptName) !== -1)
) {
thisScript = scripts[i];
break;
}
}

if (thisScript) {
const query = {};
const queryString = thisScript.src.replace(/^[^?]+\??/, '');
queryString.replace(/\?/g, '&').split('&').forEach((item) => {
query[item.split('=')[0]] = item.split('=')[1] && decodeURIComponent(item.split('=')[1]);
});

let scriptSrc = thisScript.src.replace(/^([^?]+).*/, '$1').split('/');
scriptSrc.pop();
if (config.formioPath) {
config.formioPath(scriptSrc);
}
scriptSrc = scriptSrc.join('/');
const debug = (query.debug === 'true' || query.debug === '1');
const renderer = debug ? 'formio.form' : 'formio.form.min';
Formio.config = Object.assign({
script: query.script || (`${config.updatePath ? config.updatePath() : scriptSrc}/${renderer}.js`),
style: query.styles || (`${config.updatePath ? config.updatePath() : scriptSrc}/${renderer}.css`),
cdn: query.cdn,
class: (query.class || 'formio-form-wrapper'),
src: query.src,
form: null,
submission: null,
project: query.project,
base: query.base || 'https://api.form.io',
submit: query.submit,
includeLibs: (query.libs === 'true' || query.libs === '1'),
template: query.template,
debug: debug,
config: {},
redirect: (query.return || query.redirect),
embedCSS: (`${config.updatePath ? config.updatePath() : scriptSrc}/formio.embed.css`),
success: query.success || 'Thank you for your submission!',
before: null,
after: null
}, config);
const form = (Formio.config.form || Formio.config.src);
if (form) {
Formio.debug('Embedding Configuration', config);
if (Formio.config.addPremiumLib) {
Formio.config.addPremiumLib(Formio.config, scriptSrc);
}

// The id for this embedded form.
Formio.config.id = `formio-${Math.random().toString(36).substring(7)}`;
Formio.debug('Creating form element');
const element = Formio.createElement('div', {
'id': Formio.config.id,
class: Formio.config.class
});

// insertAfter doesn't exist, but effect is identical.
thisScript.parentNode.insertBefore(element, thisScript.parentNode.firstElementChild.nextSibling);
Formio.createForm(element, form, Formio.config.config).then((instance) => {
if (Formio.config.submit) {
instance.nosubmit = true;
}

// Configure a redirect.
instance.on('submit', (submission) => {
Formio.debug("on('submit')", submission);
if (Formio.config.submit) {
Formio.debug(`Sending submission to ${Formio.config.submit}`);
const headers = {
'content-type': 'application/json'
};
const token = Formio.FormioClass.getToken();
if (token) {
headers['x-jwt-token'] = token;
}
Formio.FormioClass.fetch(Formio.config.submit, {
body: JSON.stringify(submission),
headers: headers,
method: 'POST',
mode: 'cors',
})
.then(resp => resp.json())
.then(submission => Formio.submitDone(instance, submission));
}
else {
Formio.submitDone(instance, submission);
}
});
});
}
}
else {
// Show an error if the script cannot be found.
document.write('<span>Could not locate the Embedded form.</span>');
}
}

export { Formio };
94 changes: 93 additions & 1 deletion src/Webform.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,98 @@ function getOptions(options) {
return options;
}

/**
* Represents a JSON value.
* @typedef {(string | number | boolean | null | JSONArray | JSONObject)} JSON
*/

/**
* Represents a JSON array.
* @typedef {Array<JSON>} JSONArray
*/

/**
* Represents a JSON object.
* @typedef {{[key: string]: JSON}} JSONObject
*/

/**
* @typedef {object} FormioHooks
* @property {Function} [beforeSubmit] - A function that is called before the form is submitted.
* @property {Function} [beforeCancel] - A function that is called before the form is canceled.
* @property {Function} [beforeNext] - A function that is called before moving to the next page in a multi-page form.
* @property {Function} [beforePrev] - A function that is called before moving to the previous page in a multi-page form.
* @property {Function} [attachComponent] - A function that is called when a component is attached to the form.
* @property {Function} [setDataValue] - A function that is called when setting the value of a data component.
* @property {Function} [addComponents] - A function that is called when adding multiple components to the form.
* @property {Function} [addComponent] - A function that is called when adding a single component to the form.
* @property {Function} [customValidation] - A function that is called for custom validation of the form.
* @property {Function} [attachWebform] - A function that is called when attaching a webform to the form.
*/

/**
* @typedef {object} SanitizeConfig
* @property {string[]} [addAttr] - The attributes to add.
* @property {string[]} [addTags] - The tags to add.
* @property {string[]} [allowedAttrs] - The allowed attributes.
* @property {string[]} [allowedTags] - The allowed tags.
* @property {string[]} [allowedUriRegex] - The allowed URI regex.
* @property {string[]} [addUriSafeAttr] - The URI safe attributes.
*/

/**
* @typedef {object} ButtonSettings
* @property {boolean} [showPrevious] - Show the "Previous" button.
* @property {boolean} [showNext] - Show the "Next" button.
* @property {boolean} [showCancel] - Show the "Cancel" button.
* @property {boolean} [showSubmit] - Show the "Submit" button.
*/

/**
* @typedef {object} FormOptions
* @property {boolean} [saveDraft] - Enable the save draft feature.
* @property {number} [saveDraftThrottle] - The throttle for the save draft feature.
* @property {boolean} [readOnly] - Set this form to readOnly.
* @property {boolean} [noAlerts] - Disable the alerts dialog.
* @property {{[key: string]: string}} [i18n] - The translation file for this rendering.
* @property {string} [template] - Custom logic for creation of elements.
* @property {boolean} [noDefaults] - Exclude default values from the settings.
* @property {any} [fileService] - The file service for this form.
* @property {EventEmitter} [events] - The EventEmitter for this form.
* @property {string} [language] - The language to render this form in.
* @property {{[key: string]: string}} [i18next] - The i18next configuration for this form.
* @property {boolean} [viewAsHtml] - View the form as raw HTML.
* @property {'form' | 'html' | 'flat' | 'builder' | 'pdf'} [renderMode] - The render mode for this form.
* @property {boolean} [highlightErrors] - Highlight any errors on the form.
* @property {string} [componentErrorClass] - The error class for components.
* @property {any} [templates] - The templates for this form.
* @property {string} [iconset] - The iconset for this form.
* @property {import('@formio/core').Component[]} [components] - The components for this form.
* @property {{[key: string]: boolean}} [disabled] - Disabled components for this form.
* @property {boolean} [showHiddenFields] - Show hidden fields.
* @property {{[key: string]: boolean}} [hide] - Hidden components for this form.
* @property {{[key: string]: boolean}} [show] - Components to show for this form.
* @property {Formio} [formio] - The Formio instance for this form.
* @property {string} [decimalSeparator] - The decimal separator for this form.
* @property {string} [thousandsSeparator] - The thousands separator for this form.
* @property {FormioHooks} [hooks] - The hooks for this form.
* @property {boolean} [alwaysDirty] - Always be dirty.
* @property {boolean} [skipDraftRestore] - Skip restoring a draft.
* @property {'form' | 'wizard' | 'pdf'} [display] - The display for this form.
* @property {string} [cdnUrl] - The CDN url for this form.
* @property {boolean} [flatten] - Flatten the form.
* @property {boolean} [sanitize] - Sanitize the form.
* @property {SanitizeConfig} [sanitizeConfig] - The sanitize configuration for this form.
* @property {ButtonSettings} [buttonSettings] - The button settings for this form.
* @property {object} [breadcrumbSettings] - The breadcrumb settings for this form.
* @property {boolean} [allowPrevious] - Allow the previous button (for Wizard forms).
* @property {string[]} [wizardButtonOrder] - The order of the buttons (for Wizard forms).
* @property {boolean} [showCheckboxBackground] - Show the checkbox background.
* @property {boolean} [inputsOnly] - Only show inputs in the form and no labels.
* @property {boolean} [building] - If we are in the process of building the form.
* @property {number} [zoom] - The zoom for PDF forms.
*/

/**
* Renders a Form.io form within the webpage.
*/
Expand Down Expand Up @@ -1600,7 +1692,7 @@ export default class Webform extends NestedDataComponent {
* @param {any} options - The options to use when submitting this form.
* @returns {Promise} - A promise when the form is done submitting.
*/
submit(before, options = {}) {
submit(before = false, options = {}) {
this.submissionInProcess = true;
if (!before) {
return this.beforeSubmit(options).then(() => this.executeSubmit(options));
Expand Down
Loading
Loading