@bpmn-io/form-js-viewer 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/form-js.css +36 -38
- package/dist/index.cjs +57 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.es.js +58 -23
- package/dist/index.es.js.map +1 -1
- package/dist/types/Form.d.ts +130 -130
- package/dist/types/core/EventBus.d.ts +1 -1
- package/dist/types/core/FormFieldRegistry.d.ts +17 -17
- package/dist/types/core/Validator.d.ts +3 -3
- package/dist/types/core/index.d.ts +16 -16
- package/dist/types/import/Importer.d.ts +43 -38
- package/dist/types/import/index.d.ts +5 -5
- package/dist/types/index.d.ts +18 -18
- package/dist/types/render/FormFields.d.ts +5 -5
- package/dist/types/render/Renderer.d.ts +23 -23
- package/dist/types/render/components/Description.d.ts +1 -1
- package/dist/types/render/components/Errors.d.ts +1 -1
- package/dist/types/render/components/FormComponent.d.ts +1 -1
- package/dist/types/render/components/FormField.d.ts +1 -1
- package/dist/types/render/components/Label.d.ts +1 -1
- package/dist/types/render/components/PoweredBy.d.ts +1 -1
- package/dist/types/render/components/Sanitizer.d.ts +7 -7
- package/dist/types/render/components/Util.d.ts +4 -4
- package/dist/types/render/components/form-fields/Button.d.ts +11 -11
- package/dist/types/render/components/form-fields/Checkbox.d.ts +10 -9
- package/dist/types/render/components/form-fields/Default.d.ts +9 -9
- package/dist/types/render/components/form-fields/Number.d.ts +10 -9
- package/dist/types/render/components/form-fields/Radio.d.ts +15 -14
- package/dist/types/render/components/form-fields/Select.d.ts +15 -14
- package/dist/types/render/components/form-fields/Text.d.ts +10 -10
- package/dist/types/render/components/form-fields/Textfield.d.ts +10 -9
- package/dist/types/render/components/index.d.ts +11 -11
- package/dist/types/render/context/FormContext.d.ts +12 -12
- package/dist/types/render/context/FormRenderContext.d.ts +6 -6
- package/dist/types/render/context/index.d.ts +2 -2
- package/dist/types/render/hooks/useService.d.ts +1 -1
- package/dist/types/render/index.d.ts +11 -11
- package/dist/types/util/form.d.ts +6 -6
- package/dist/types/util/index.d.ts +16 -16
- package/dist/types/util/injector.d.ts +1 -1
- package/package.json +2 -2
package/dist/index.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Ids from 'ids';
|
|
2
|
-
import { isArray, isFunction, isNumber, bind, assign, get, set, isString } from 'min-dash';
|
|
2
|
+
import { isArray, isFunction, isNumber, bind, assign, isNil, get, isUndefined, set, isString } from 'min-dash';
|
|
3
3
|
import snarkdown from '@bpmn-io/snarkdown';
|
|
4
4
|
import { jsx, jsxs } from 'preact/jsx-runtime';
|
|
5
5
|
import { useContext, useState, useCallback } from 'preact/hooks';
|
|
@@ -600,7 +600,7 @@ class Validator {
|
|
|
600
600
|
errors = [...errors, `Field must match pattern ${validate.pattern}.`];
|
|
601
601
|
}
|
|
602
602
|
|
|
603
|
-
if (validate.required && (
|
|
603
|
+
if (validate.required && (isNil(value) || value === '')) {
|
|
604
604
|
errors = [...errors, 'Field is required.'];
|
|
605
605
|
}
|
|
606
606
|
|
|
@@ -716,8 +716,8 @@ class Importer {
|
|
|
716
716
|
const warnings = [];
|
|
717
717
|
|
|
718
718
|
try {
|
|
719
|
-
const
|
|
720
|
-
|
|
719
|
+
const importedSchema = this.importFormField(clone(schema)),
|
|
720
|
+
importedData = this.importData(clone(data));
|
|
721
721
|
return {
|
|
722
722
|
warnings,
|
|
723
723
|
schema: importedSchema,
|
|
@@ -730,14 +730,13 @@ class Importer {
|
|
|
730
730
|
}
|
|
731
731
|
/**
|
|
732
732
|
* @param {any} formField
|
|
733
|
-
* @param {Object} [data]
|
|
734
733
|
* @param {string} [parentId]
|
|
735
734
|
*
|
|
736
|
-
* @return {any}
|
|
735
|
+
* @return {any} importedField
|
|
737
736
|
*/
|
|
738
737
|
|
|
739
738
|
|
|
740
|
-
importFormField(formField,
|
|
739
|
+
importFormField(formField, parentId) {
|
|
741
740
|
const {
|
|
742
741
|
components,
|
|
743
742
|
key,
|
|
@@ -760,10 +759,13 @@ class Importer {
|
|
|
760
759
|
throw new Error(`form field with key <${key}> already exists`);
|
|
761
760
|
}
|
|
762
761
|
|
|
763
|
-
this._formFieldRegistry._keys.claim(key, formField); //
|
|
762
|
+
this._formFieldRegistry._keys.claim(key, formField); // TODO: buttons should not have key
|
|
764
763
|
|
|
765
764
|
|
|
766
|
-
|
|
765
|
+
if (type !== 'button') {
|
|
766
|
+
// set form field path
|
|
767
|
+
formField._path = [key];
|
|
768
|
+
}
|
|
767
769
|
}
|
|
768
770
|
|
|
769
771
|
if (id) {
|
|
@@ -781,17 +783,44 @@ class Importer {
|
|
|
781
783
|
this._formFieldRegistry.add(formField);
|
|
782
784
|
|
|
783
785
|
if (components) {
|
|
784
|
-
this.importFormFields(components,
|
|
786
|
+
this.importFormFields(components, id);
|
|
785
787
|
}
|
|
786
788
|
|
|
787
789
|
return formField;
|
|
788
790
|
}
|
|
789
791
|
|
|
790
|
-
importFormFields(components,
|
|
792
|
+
importFormFields(components, parentId) {
|
|
791
793
|
components.forEach(component => {
|
|
792
|
-
this.importFormField(component,
|
|
794
|
+
this.importFormField(component, parentId);
|
|
793
795
|
});
|
|
794
796
|
}
|
|
797
|
+
/**
|
|
798
|
+
* @param {Object} data
|
|
799
|
+
*
|
|
800
|
+
* @return {Object} importedData
|
|
801
|
+
*/
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
importData(data) {
|
|
805
|
+
return this._formFieldRegistry.getAll().reduce((importedData, formField) => {
|
|
806
|
+
const {
|
|
807
|
+
defaultValue,
|
|
808
|
+
_path,
|
|
809
|
+
type
|
|
810
|
+
} = formField;
|
|
811
|
+
|
|
812
|
+
if (!_path) {
|
|
813
|
+
return importedData;
|
|
814
|
+
} // (1) try to get value from data
|
|
815
|
+
// (2) try to get default value from form field
|
|
816
|
+
// (3) get empty value from form field
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
return { ...importedData,
|
|
820
|
+
[_path[0]]: get(data, _path, isUndefined(defaultValue) ? this._formFields.get(type).emptyValue : defaultValue)
|
|
821
|
+
};
|
|
822
|
+
}, {});
|
|
823
|
+
}
|
|
795
824
|
|
|
796
825
|
}
|
|
797
826
|
Importer.$inject = ['formFieldRegistry', 'formFields'];
|
|
@@ -1115,6 +1144,7 @@ Checkbox.create = function (options = {}) {
|
|
|
1115
1144
|
Checkbox.type = type$5;
|
|
1116
1145
|
Checkbox.label = 'Checkbox';
|
|
1117
1146
|
Checkbox.keyed = true;
|
|
1147
|
+
Checkbox.emptyValue = false;
|
|
1118
1148
|
|
|
1119
1149
|
function useService (type, strict) {
|
|
1120
1150
|
const {
|
|
@@ -1355,7 +1385,7 @@ function Number(props) {
|
|
|
1355
1385
|
const parsedValue = parseInt(target.value, 10);
|
|
1356
1386
|
props.onChange({
|
|
1357
1387
|
field,
|
|
1358
|
-
value: isNaN(parsedValue) ?
|
|
1388
|
+
value: isNaN(parsedValue) ? null : parsedValue
|
|
1359
1389
|
});
|
|
1360
1390
|
};
|
|
1361
1391
|
|
|
@@ -1391,6 +1421,7 @@ Number.create = function (options = {}) {
|
|
|
1391
1421
|
Number.type = type$4;
|
|
1392
1422
|
Number.keyed = true;
|
|
1393
1423
|
Number.label = 'Number';
|
|
1424
|
+
Number.emptyValue = null;
|
|
1394
1425
|
|
|
1395
1426
|
const type$3 = 'radio';
|
|
1396
1427
|
function Radio(props) {
|
|
@@ -1461,6 +1492,7 @@ Radio.create = function (options = {}) {
|
|
|
1461
1492
|
Radio.type = type$3;
|
|
1462
1493
|
Radio.label = 'Radio';
|
|
1463
1494
|
Radio.keyed = true;
|
|
1495
|
+
Radio.emptyValue = null;
|
|
1464
1496
|
|
|
1465
1497
|
const type$2 = 'select';
|
|
1466
1498
|
function Select(props) {
|
|
@@ -1486,7 +1518,7 @@ function Select(props) {
|
|
|
1486
1518
|
}) => {
|
|
1487
1519
|
props.onChange({
|
|
1488
1520
|
field,
|
|
1489
|
-
value: target.value === '' ?
|
|
1521
|
+
value: target.value === '' ? null : target.value
|
|
1490
1522
|
});
|
|
1491
1523
|
};
|
|
1492
1524
|
|
|
@@ -1534,6 +1566,7 @@ Select.create = function (options = {}) {
|
|
|
1534
1566
|
Select.type = type$2;
|
|
1535
1567
|
Select.label = 'Select';
|
|
1536
1568
|
Select.keyed = true;
|
|
1569
|
+
Select.emptyValue = null;
|
|
1537
1570
|
|
|
1538
1571
|
const type$1 = 'text';
|
|
1539
1572
|
function Text(props) {
|
|
@@ -1621,6 +1654,7 @@ Textfield.create = function (options = {}) {
|
|
|
1621
1654
|
Textfield.type = type;
|
|
1622
1655
|
Textfield.label = 'Text Field';
|
|
1623
1656
|
Textfield.keyed = true;
|
|
1657
|
+
Textfield.emptyValue = '';
|
|
1624
1658
|
|
|
1625
1659
|
const formFields = [Button, Checkbox, Default, Number, Radio, Select, Text, Textfield];
|
|
1626
1660
|
|
|
@@ -1862,21 +1896,22 @@ class Form {
|
|
|
1862
1896
|
throw new Error('form is read-only');
|
|
1863
1897
|
}
|
|
1864
1898
|
|
|
1865
|
-
const formFieldRegistry = this.get('formFieldRegistry');
|
|
1866
|
-
|
|
1899
|
+
const formFieldRegistry = this.get('formFieldRegistry');
|
|
1867
1900
|
const data = formFieldRegistry.getAll().reduce((data, field) => {
|
|
1868
1901
|
const {
|
|
1869
1902
|
disabled,
|
|
1870
1903
|
_path
|
|
1871
|
-
} = field;
|
|
1904
|
+
} = field; // do not submit disabled form fields
|
|
1872
1905
|
|
|
1873
|
-
if (disabled) {
|
|
1874
|
-
|
|
1875
|
-
set(data, _path, undefined);
|
|
1906
|
+
if (disabled || !_path) {
|
|
1907
|
+
return data;
|
|
1876
1908
|
}
|
|
1877
1909
|
|
|
1878
|
-
|
|
1879
|
-
|
|
1910
|
+
const value = get(this._getState().data, _path);
|
|
1911
|
+
return { ...data,
|
|
1912
|
+
[_path[0]]: value
|
|
1913
|
+
};
|
|
1914
|
+
}, {});
|
|
1880
1915
|
const errors = this.validate();
|
|
1881
1916
|
|
|
1882
1917
|
this._emit('submit', {
|
|
@@ -2100,7 +2135,7 @@ class Form {
|
|
|
2100
2135
|
|
|
2101
2136
|
}
|
|
2102
2137
|
|
|
2103
|
-
const schemaVersion =
|
|
2138
|
+
const schemaVersion = 3;
|
|
2104
2139
|
/**
|
|
2105
2140
|
* @typedef { import('./types').CreateFormOptions } CreateFormOptions
|
|
2106
2141
|
*/
|