@bpmn-io/form-js-viewer
Advanced tools
Comparing version 0.8.0-alpha.0 to 0.8.0-alpha.1
import Ids from 'ids'; | ||
import { isArray, isFunction, isNumber, bind, assign, isNil, get, isUndefined, set, isString } from 'min-dash'; | ||
import { isArray, isFunction, isNumber, bind, assign, isNil, get, isUndefined, isObject, set, isString } from 'min-dash'; | ||
import snarkdown from '@bpmn-io/snarkdown'; | ||
@@ -592,41 +592,4 @@ import { jsx, jsxs } from 'preact/jsx-runtime'; | ||
function createInjector(bootstrapModules) { | ||
const modules = [], | ||
components = []; | ||
function hasModule(module) { | ||
return modules.includes(module); | ||
} | ||
function addModule(module) { | ||
modules.push(module); | ||
} | ||
function visit(module) { | ||
if (hasModule(module)) { | ||
return; | ||
} | ||
(module.__depends__ || []).forEach(visit); | ||
if (hasModule(module)) { | ||
return; | ||
} | ||
addModule(module); | ||
(module.__init__ || []).forEach(function (component) { | ||
components.push(component); | ||
}); | ||
} | ||
bootstrapModules.forEach(visit); | ||
const injector = new Injector(modules); | ||
components.forEach(function (component) { | ||
try { | ||
injector[typeof component === 'string' ? 'get' : 'invoke'](component); | ||
} catch (err) { | ||
console.error('Failed to instantiate component'); | ||
console.error(err.stack); | ||
throw err; | ||
} | ||
}); | ||
const injector = new Injector(bootstrapModules); | ||
injector.init(); | ||
return injector; | ||
@@ -694,3 +657,38 @@ } | ||
} | ||
/** | ||
* Parse the schema for input variables a form might make use of | ||
* | ||
* @param {any} schema | ||
* | ||
* @return {string[]} | ||
*/ | ||
function getSchemaVariables(schema) { | ||
if (!schema.components) { | ||
return []; | ||
} | ||
return schema.components.reduce((variables, component) => { | ||
const { | ||
key, | ||
valuesKey, | ||
type | ||
} = component; | ||
if (['text', 'button'].includes(type)) { | ||
return variables; | ||
} | ||
if (key) { | ||
variables = [...variables, key]; | ||
} | ||
if (valuesKey && !variables.includes(valuesKey)) { | ||
variables = [...variables, valuesKey]; | ||
} | ||
return variables; | ||
}, []); | ||
} | ||
class Importer { | ||
@@ -719,3 +717,3 @@ /** | ||
importSchema(schema, data = {}) { | ||
// TODO: Add warnings | ||
// TODO: Add warnings - https://github.com/bpmn-io/form-js/issues/289 | ||
const warnings = []; | ||
@@ -828,4 +826,17 @@ | ||
if (_path) { | ||
const fieldImplementation = this._formFields.get(type); | ||
let valueData = get(data, _path); | ||
if (!isUndefined(valueData) && fieldImplementation.sanitizeValue) { | ||
valueData = fieldImplementation.sanitizeValue({ | ||
formField, | ||
data, | ||
value: valueData | ||
}); | ||
} | ||
const initialFieldValue = !isUndefined(valueData) ? valueData : !isUndefined(defaultValue) ? defaultValue : fieldImplementation.emptyValue; | ||
importedData = { ...importedData, | ||
[_path[0]]: get(data, _path, isUndefined(defaultValue) ? this._formFields.get(type).emptyValue : defaultValue) | ||
[_path[0]]: initialFieldValue | ||
}; | ||
@@ -994,3 +1005,43 @@ } | ||
} | ||
function sanitizeSingleSelectValue(options) { | ||
const { | ||
formField, | ||
data, | ||
value | ||
} = options; | ||
const { | ||
valuesKey, | ||
values | ||
} = formField; | ||
try { | ||
const validValues = (valuesKey ? get(data, [valuesKey]) : values).map(v => v.value) || []; | ||
return validValues.includes(value) ? value : null; | ||
} catch (error) { | ||
// use default value in case of formatting error | ||
// TODO(@Skaiir): log a warning when this happens - https://github.com/bpmn-io/form-js/issues/289 | ||
return null; | ||
} | ||
} | ||
function sanitizeMultiSelectValue(options) { | ||
const { | ||
formField, | ||
data, | ||
value | ||
} = options; | ||
const { | ||
valuesKey, | ||
values | ||
} = formField; | ||
try { | ||
const validValues = (valuesKey ? get(data, [valuesKey]) : values).map(v => v.value) || []; | ||
return value.filter(v => validValues.includes(v)); | ||
} catch (error) { | ||
// use default value in case of formatting error | ||
// TODO(@Skaiir): log a warning when this happens - https://github.com/bpmn-io/form-js/issues/289 | ||
return []; | ||
} | ||
} | ||
const type$8 = 'button'; | ||
@@ -1163,2 +1214,6 @@ function Button(props) { | ||
Checkbox.sanitizeValue = ({ | ||
value | ||
}) => value === true; | ||
function useService (type, strict) { | ||
@@ -1316,2 +1371,3 @@ const { | ||
Checklist.emptyValue = []; | ||
Checklist.sanitizeValue = sanitizeMultiSelectValue; | ||
@@ -1547,6 +1603,7 @@ const noop$1 = () => false; | ||
}) => { | ||
const parsedValue = parseInt(target.value, 10); | ||
props.onChange({ | ||
field, | ||
value: isNaN(parsedValue) ? null : parsedValue | ||
value: Number.sanitizeValue({ | ||
value: target.value | ||
}) | ||
}); | ||
@@ -1584,2 +1641,9 @@ }; | ||
Number.sanitizeValue = ({ | ||
value | ||
}) => { | ||
const parsedValue = parseInt(value, 10); | ||
return isNaN(parsedValue) ? null : parsedValue; | ||
}; | ||
Number.type = type$5; | ||
@@ -1664,2 +1728,3 @@ Number.keyed = true; | ||
Radio.emptyValue = null; | ||
Radio.sanitizeValue = sanitizeSingleSelectValue; | ||
@@ -1743,2 +1808,3 @@ const type$3 = 'select'; | ||
Select.emptyValue = null; | ||
Select.sanitizeValue = sanitizeSingleSelectValue; | ||
@@ -1915,3 +1981,3 @@ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
if (loadState === LOAD_STATES.LOADED) { | ||
setFilteredValues(options.filter(o => o.label && o.label.toLowerCase().includes(filter.toLowerCase()) && !values.includes(o.value))); | ||
setFilteredValues(options.filter(o => o.label && o.value && o.label.toLowerCase().includes(filter.toLowerCase()) && !values.includes(o.value))); | ||
} else { | ||
@@ -2047,2 +2113,3 @@ setFilteredValues([]); | ||
Taglist.emptyValue = []; | ||
Taglist.sanitizeValue = sanitizeMultiSelectValue; | ||
@@ -2137,2 +2204,6 @@ const type$1 = 'text'; | ||
Textfield.sanitizeValue = ({ | ||
value | ||
}) => isArray(value) || isObject(value) ? null : String(value); | ||
const formFields = [Button, Checkbox, Checklist, Default, Number, Radio, Select, Taglist, Text, Textfield]; | ||
@@ -2650,3 +2721,3 @@ | ||
export { Button, Checkbox, Checklist, Default, Form, FormComponent, FormContext, FormFieldRegistry, FormFields, FormRenderContext, Number, Radio, Select, Taglist, Text, Textfield, clone, createForm, createFormContainer, createInjector, findErrors, formFields, generateIdForType, generateIndexForType, isRequired, pathParse, pathStringify, pathsEqual, schemaVersion }; | ||
export { Button, Checkbox, Checklist, Default, Form, FormComponent, FormContext, FormFieldRegistry, FormFields, FormRenderContext, Number, Radio, Select, Taglist, Text, Textfield, clone, createForm, createFormContainer, createInjector, findErrors, formFields, generateIdForType, generateIndexForType, getSchemaVariables, isRequired, pathParse, pathStringify, pathsEqual, schemaVersion }; | ||
//# sourceMappingURL=index.es.js.map |
@@ -30,4 +30,4 @@ /** | ||
private _state; | ||
get: any; | ||
invoke: any; | ||
get: <T>(name: string, strict?: boolean) => T; | ||
invoke: <T_1>(func: (...args: unknown[]) => T_1, context: unknown, locals: import("didi").LocalsMap) => T_1; | ||
clear(): void; | ||
@@ -120,3 +120,3 @@ /** | ||
} | ||
export type Injector = any; | ||
export type Injector = import('./types').Injector; | ||
export type Data = import('./types').Data; | ||
@@ -123,0 +123,0 @@ export type Errors = import('./types').Errors; |
@@ -8,4 +8,7 @@ declare function Checkbox(props: any): import("preact").JSX.Element; | ||
export const emptyValue: boolean; | ||
export function sanitizeValue({ value }: { | ||
value: any; | ||
}): boolean; | ||
} | ||
export default Checkbox; | ||
declare const type: "checkbox"; |
@@ -8,4 +8,6 @@ declare function Checklist(props: any): import("preact").JSX.Element; | ||
export const emptyValue: any[]; | ||
export { sanitizeMultiSelectValue as sanitizeValue }; | ||
} | ||
export default Checklist; | ||
declare const type: "checklist"; | ||
import { sanitizeMultiSelectValue } from "../Util"; |
declare function Number(props: any): import("preact").JSX.Element; | ||
declare namespace Number { | ||
export function create(options?: {}): {}; | ||
export function sanitizeValue({ value }: { | ||
value: any; | ||
}): number; | ||
export { type }; | ||
@@ -5,0 +8,0 @@ export const keyed: boolean; |
@@ -8,4 +8,6 @@ declare function Radio(props: any): import("preact").JSX.Element; | ||
export const emptyValue: any; | ||
export { sanitizeSingleSelectValue as sanitizeValue }; | ||
} | ||
export default Radio; | ||
declare const type: "radio"; | ||
import { sanitizeSingleSelectValue } from "../Util"; |
@@ -8,4 +8,6 @@ declare function Select(props: any): import("preact").JSX.Element; | ||
export const emptyValue: any; | ||
export { sanitizeSingleSelectValue as sanitizeValue }; | ||
} | ||
export default Select; | ||
declare const type: "select"; | ||
import { sanitizeSingleSelectValue } from "../Util"; |
@@ -8,4 +8,6 @@ declare function Taglist(props: any): import("preact").JSX.Element; | ||
export const emptyValue: any[]; | ||
export { sanitizeMultiSelectValue as sanitizeValue }; | ||
} | ||
export default Taglist; | ||
declare const type: "taglist"; | ||
import { sanitizeMultiSelectValue } from "../Util"; |
@@ -8,4 +8,7 @@ declare function Textfield(props: any): import("preact").JSX.Element; | ||
export const emptyValue: string; | ||
export function sanitizeValue({ value }: { | ||
value: any; | ||
}): string; | ||
} | ||
export default Textfield; | ||
declare const type: "textfield"; |
@@ -1,2 +0,2 @@ | ||
export const formFields: (typeof Button | typeof Default | typeof Number | typeof Text)[]; | ||
export const formFields: (typeof Button | typeof Default | typeof Radio | typeof Text)[]; | ||
import Button from "./form-fields/Button"; | ||
@@ -3,0 +3,0 @@ import Checkbox from "./form-fields/Checkbox"; |
@@ -5,1 +5,3 @@ export function formFieldClasses(type: any, errors?: any[]): string; | ||
export function safeMarkdown(markdown: any): string; | ||
export function sanitizeSingleSelectValue(options: any): any; | ||
export function sanitizeMultiSelectValue(options: any): any; |
@@ -13,3 +13,3 @@ /** | ||
*/ | ||
declare function Renderer(config: Config, eventBus: any, form: Form, injector: any): void; | ||
declare function Renderer(config: Config, eventBus: any, form: Form, injector: Injector): void; | ||
declare namespace Renderer { | ||
@@ -22,4 +22,4 @@ const $inject: string[]; | ||
}; | ||
export type Injector = any; | ||
export type Injector = import('didi').Injector; | ||
export type EventBus = any; | ||
export type Form = import('../Form').default; |
@@ -15,3 +15,11 @@ export function findErrors(errors: any, path: any): any; | ||
export function clone<T>(data: T, replacer?: (this: any, key: string, value: any) => any): T; | ||
/** | ||
* Parse the schema for input variables a form might make use of | ||
* | ||
* @param {any} schema | ||
* | ||
* @return {string[]} | ||
*/ | ||
export function getSchemaVariables(schema: any): string[]; | ||
export * from "./injector"; | ||
export * from "./form"; |
@@ -1,1 +0,2 @@ | ||
export function createInjector(bootstrapModules: any): any; | ||
export function createInjector(bootstrapModules: any): Injector; | ||
import { Injector } from "didi"; |
{ | ||
"name": "@bpmn-io/form-js-viewer", | ||
"version": "0.8.0-alpha.0", | ||
"version": "0.8.0-alpha.1", | ||
"description": "View forms - powered by bpmn.io", | ||
@@ -43,3 +43,3 @@ "exports": { | ||
"classnames": "^2.3.1", | ||
"didi": "^5.2.1", | ||
"didi": "^8.0.1", | ||
"ids": "^1.0.0", | ||
@@ -56,3 +56,3 @@ "min-dash": "^3.7.0", | ||
], | ||
"gitHead": "ffc5f0cedcf0b9a923b34ff56e7f63a34c362cf9" | ||
"gitHead": "2be914efeefa050fb4692ac1a644557fc424917f" | ||
} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
428870
5516
0
+ Addeddidi@8.0.2(transitive)
- Removeddidi@5.2.1(transitive)
Updateddidi@^8.0.1