@bpmn-io/form-js-viewer
Advanced tools
Comparing version 0.5.1 to 0.6.0
import Ids from 'ids'; | ||
import { isArray, isFunction, isNumber, bind, assign, get, set, isString } from 'min-dash'; | ||
import { isArray, isFunction, isNumber, bind, assign, isNil, get, isUndefined, set, isString } from 'min-dash'; | ||
import snarkdown from '@bpmn-io/snarkdown'; | ||
@@ -603,3 +603,3 @@ import { jsx, jsxs } from 'preact/jsx-runtime'; | ||
if (validate.required && (typeof value === 'undefined' || value === '')) { | ||
if (validate.required && (isNil(value) || value === '')) { | ||
errors = [...errors, 'Field is required.']; | ||
@@ -720,4 +720,4 @@ } | ||
try { | ||
const importedData = clone(data); | ||
const importedSchema = this.importFormField(clone(schema), importedData); | ||
const importedSchema = this.importFormField(clone(schema)), | ||
importedData = this.importData(clone(data)); | ||
return { | ||
@@ -735,10 +735,9 @@ warnings, | ||
* @param {any} formField | ||
* @param {Object} [data] | ||
* @param {string} [parentId] | ||
* | ||
* @return {any} field | ||
* @return {any} importedField | ||
*/ | ||
importFormField(formField, data = {}, parentId) { | ||
importFormField(formField, parentId) { | ||
const { | ||
@@ -766,6 +765,9 @@ components, | ||
this._formFieldRegistry._keys.claim(key, formField); // set form field path | ||
this._formFieldRegistry._keys.claim(key, formField); // TODO: buttons should not have key | ||
formField._path = [key]; | ||
if (type !== 'button') { | ||
// set form field path | ||
formField._path = [key]; | ||
} | ||
} | ||
@@ -788,3 +790,3 @@ | ||
if (components) { | ||
this.importFormFields(components, data, id); | ||
this.importFormFields(components, id); | ||
} | ||
@@ -795,8 +797,35 @@ | ||
importFormFields(components, data = {}, parentId) { | ||
importFormFields(components, parentId) { | ||
components.forEach(component => { | ||
this.importFormField(component, data, parentId); | ||
this.importFormField(component, parentId); | ||
}); | ||
} | ||
/** | ||
* @param {Object} data | ||
* | ||
* @return {Object} importedData | ||
*/ | ||
importData(data) { | ||
return this._formFieldRegistry.getAll().reduce((importedData, formField) => { | ||
const { | ||
defaultValue, | ||
_path, | ||
type | ||
} = formField; | ||
if (!_path) { | ||
return importedData; | ||
} // (1) try to get value from data | ||
// (2) try to get default value from form field | ||
// (3) get empty value from form field | ||
return { ...importedData, | ||
[_path[0]]: get(data, _path, isUndefined(defaultValue) ? this._formFields.get(type).emptyValue : defaultValue) | ||
}; | ||
}, {}); | ||
} | ||
} | ||
@@ -1124,2 +1153,3 @@ Importer.$inject = ['formFieldRegistry', 'formFields']; | ||
Checkbox.keyed = true; | ||
Checkbox.emptyValue = false; | ||
@@ -1365,3 +1395,3 @@ function useService (type, strict) { | ||
field, | ||
value: isNaN(parsedValue) ? undefined : parsedValue | ||
value: isNaN(parsedValue) ? null : parsedValue | ||
}); | ||
@@ -1402,2 +1432,3 @@ }; | ||
Number.label = 'Number'; | ||
Number.emptyValue = null; | ||
@@ -1473,2 +1504,3 @@ const type$3 = 'radio'; | ||
Radio.keyed = true; | ||
Radio.emptyValue = null; | ||
@@ -1499,3 +1531,3 @@ const type$2 = 'select'; | ||
field, | ||
value: target.value === '' ? undefined : target.value | ||
value: target.value === '' ? null : target.value | ||
}); | ||
@@ -1548,2 +1580,3 @@ }; | ||
Select.keyed = true; | ||
Select.emptyValue = null; | ||
@@ -1636,2 +1669,3 @@ const type$1 = 'text'; | ||
Textfield.keyed = true; | ||
Textfield.emptyValue = ''; | ||
@@ -1878,4 +1912,3 @@ const formFields = [Button, Checkbox, Default, Number, Radio, Select, Text, Textfield]; | ||
const formFieldRegistry = this.get('formFieldRegistry'); // do not submit disabled form fields | ||
const formFieldRegistry = this.get('formFieldRegistry'); | ||
const data = formFieldRegistry.getAll().reduce((data, field) => { | ||
@@ -1885,11 +1918,13 @@ const { | ||
_path | ||
} = field; | ||
} = field; // do not submit disabled form fields | ||
if (disabled) { | ||
// strip disabled field value | ||
set(data, _path, undefined); | ||
if (disabled || !_path) { | ||
return data; | ||
} | ||
return data; | ||
}, clone(this._getState().data)); | ||
const value = get(this._getState().data, _path); | ||
return { ...data, | ||
[_path[0]]: value | ||
}; | ||
}, {}); | ||
const errors = this.validate(); | ||
@@ -2118,3 +2153,3 @@ | ||
const schemaVersion = 2; | ||
const schemaVersion = 3; | ||
/** | ||
@@ -2121,0 +2156,0 @@ * @typedef { import('./types').CreateFormOptions } CreateFormOptions |
export {}; |
@@ -0,0 +0,0 @@ declare class FormFieldRegistry { |
@@ -0,0 +0,0 @@ export { FormFieldRegistry }; |
export default class Validator { | ||
validateField(field: any, value: any): any[]; | ||
} |
@@ -0,0 +0,0 @@ /** |
@@ -27,9 +27,14 @@ declare class Importer { | ||
* @param {any} formField | ||
* @param {Object} [data] | ||
* @param {string} [parentId] | ||
* | ||
* @return {any} field | ||
* @return {any} importedField | ||
*/ | ||
importFormField(formField: any, data?: any, parentId?: string): any; | ||
importFormFields(components: any, data: {}, parentId: any): void; | ||
importFormField(formField: any, parentId?: string): any; | ||
importFormFields(components: any, parentId: any): void; | ||
/** | ||
* @param {Object} data | ||
* | ||
* @return {Object} importedData | ||
*/ | ||
importData(data: any): any; | ||
} | ||
@@ -36,0 +41,0 @@ declare namespace Importer { |
@@ -0,0 +0,0 @@ declare namespace _default { |
@@ -17,3 +17,3 @@ /** | ||
import Form from "./Form"; | ||
export const schemaVersion: 2; | ||
export const schemaVersion: 3; | ||
export { Form }; |
export default function Description(props: any): import("preact").JSX.Element; |
export default function Errors(props: any): import("preact").JSX.Element; |
@@ -0,0 +0,0 @@ declare function Button(props: any): import("preact").JSX.Element; |
@@ -7,4 +7,5 @@ declare function Checkbox(props: any): import("preact").JSX.Element; | ||
export const keyed: boolean; | ||
export const emptyValue: boolean; | ||
} | ||
export default Checkbox; | ||
declare const type: "checkbox"; |
@@ -0,0 +0,0 @@ declare function Default(props: any): import("preact").JSX.Element; |
@@ -7,4 +7,5 @@ declare function Number(props: any): import("preact").JSX.Element; | ||
export const label: string; | ||
export const emptyValue: any; | ||
} | ||
export default Number; | ||
declare const type: "number"; |
@@ -12,4 +12,5 @@ declare function Radio(props: any): import("preact").JSX.Element; | ||
export const keyed: boolean; | ||
export const emptyValue: any; | ||
} | ||
export default Radio; | ||
declare const type: "radio"; |
@@ -12,4 +12,5 @@ declare function Select(props: any): import("preact").JSX.Element; | ||
export const keyed: boolean; | ||
export const emptyValue: any; | ||
} | ||
export default Select; | ||
declare const type: "select"; |
@@ -0,0 +0,0 @@ declare function Text(props: any): import("preact").JSX.Element; |
@@ -7,4 +7,5 @@ declare function Textfield(props: any): import("preact").JSX.Element; | ||
export const keyed: boolean; | ||
export const emptyValue: string; | ||
} | ||
export default Textfield; | ||
declare const type: "textfield"; |
export default function FormComponent(props: any): import("preact").JSX.Element; |
export default function FormField(props: any): import("preact").JSX.Element; |
@@ -1,2 +0,2 @@ | ||
export const formFields: (typeof Checkbox | typeof Default | typeof Text)[]; | ||
export const formFields: (typeof Button | typeof Default | typeof Number | typeof Text)[]; | ||
import Button from "./form-fields/Button"; | ||
@@ -3,0 +3,0 @@ import Checkbox from "./form-fields/Checkbox"; |
export default function Label(props: any): import("preact").JSX.Element; |
export default function PoweredBy(props: any): import("preact").JSX.Element; |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ export function formFieldClasses(type: any, errors?: any[]): string; |
@@ -0,0 +0,0 @@ export default FormContext; |
@@ -0,0 +0,0 @@ export default FormRenderContext; |
export { default as FormRenderContext } from "./FormRenderContext"; | ||
export { default as FormContext } from "./FormContext"; |
@@ -0,0 +0,0 @@ export default class FormFields { |
export default function _default(type: any, strict: any): any; |
@@ -0,0 +0,0 @@ export { FormFields }; |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ export function findErrors(errors: any, path: any): any; |
export function createInjector(bootstrapModules: any): any; |
{ | ||
"name": "@bpmn-io/form-js-viewer", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"description": "View forms - powered by bpmn.io", | ||
@@ -54,3 +54,3 @@ "exports": { | ||
], | ||
"gitHead": "48fb3d4ffb270518592377c79ddbad1474859566" | ||
"gitHead": "37498a3b4097c4905deb3ee6f0ccd35935a9001a" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
325956
4362