@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/assets/form-js.css
CHANGED
|
@@ -2,45 +2,42 @@
|
|
|
2
2
|
* Theming
|
|
3
3
|
*/
|
|
4
4
|
.fjs-container {
|
|
5
|
-
--color-
|
|
6
|
-
--color-
|
|
7
|
-
--color-
|
|
8
|
-
--color-
|
|
9
|
-
--color-
|
|
10
|
-
--color-
|
|
11
|
-
--color-
|
|
12
|
-
--color-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
--color-
|
|
16
|
-
--color-
|
|
17
|
-
--color-
|
|
18
|
-
--color-
|
|
19
|
-
|
|
20
|
-
--color-
|
|
21
|
-
|
|
22
|
-
--color-
|
|
23
|
-
--color-
|
|
24
|
-
--color-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
--color-
|
|
28
|
-
--color-
|
|
29
|
-
|
|
30
|
-
--color-black: #000000;
|
|
31
|
-
--color-white: #ffffff;
|
|
5
|
+
--color-grey-225-10-15: hsl(225, 10%, 15%);
|
|
6
|
+
--color-grey-225-10-35: hsl(225, 10%, 35%);
|
|
7
|
+
--color-grey-225-10-55: hsl(225, 10%, 55%);
|
|
8
|
+
--color-grey-225-10-75: hsl(225, 10%, 75%);
|
|
9
|
+
--color-grey-225-10-80: hsl(225, 10%, 80%);
|
|
10
|
+
--color-grey-225-10-85: hsl(225, 10%, 85%);
|
|
11
|
+
--color-grey-225-10-90: hsl(225, 10%, 90%);
|
|
12
|
+
--color-grey-225-10-95: hsl(225, 10%, 95%);
|
|
13
|
+
--color-grey-225-10-97: hsl(225, 10%, 97%);
|
|
14
|
+
|
|
15
|
+
--color-blue-205-100-45: hsl(205, 100%, 45%);
|
|
16
|
+
--color-blue-205-100-50: hsl(205, 100%, 50%);
|
|
17
|
+
--color-blue-205-100-80: hsl(205, 100%, 80%);
|
|
18
|
+
--color-blue-205-100-95: hsl(205, 100%, 95%);
|
|
19
|
+
|
|
20
|
+
--color-green-150-86-44: hsl(150, 86%, 44%);
|
|
21
|
+
|
|
22
|
+
--color-red-360-100-40: hsl(360, 100%, 40%);
|
|
23
|
+
--color-red-360-100-45: hsl(360, 100%, 45%);
|
|
24
|
+
--color-red-360-100-92: hsl(360, 100%, 92%);
|
|
25
|
+
--color-red-360-100-97: hsl(360, 100%, 97%);
|
|
26
|
+
|
|
27
|
+
--color-white: hsl(0, 0%, 100%);
|
|
28
|
+
--color-black: hsl(0, 0%, 0%);
|
|
32
29
|
|
|
33
30
|
--color-background: var(--color-white);
|
|
34
|
-
--color-background-disabled: var(--color-
|
|
35
|
-
--color-text: var(--color-grey-
|
|
36
|
-
--color-text-light: var(--color-grey-
|
|
37
|
-
--color-text-lighter: var(--color-grey-
|
|
31
|
+
--color-background-disabled: var(--color-grey-225-10-95);
|
|
32
|
+
--color-text: var(--color-grey-225-10-15);
|
|
33
|
+
--color-text-light: var(--color-grey-225-10-35);
|
|
34
|
+
--color-text-lighter: var(--color-grey-225-10-55);
|
|
38
35
|
--color-text-inverted: var(--color-white);
|
|
39
|
-
--color-borders: var(--color-grey-
|
|
40
|
-
--color-borders-disabled: var(--color-
|
|
41
|
-
--color-warning: var(--color-red-
|
|
42
|
-
--color-accent: var(--color-blue-
|
|
43
|
-
--color-accent-dark: var(--color-blue-
|
|
36
|
+
--color-borders: var(--color-grey-225-10-55);
|
|
37
|
+
--color-borders-disabled: var(--color-grey-225-10-75);
|
|
38
|
+
--color-warning: var(--color-red-360-100-45);
|
|
39
|
+
--color-accent: var(--color-blue-205-100-45);
|
|
40
|
+
--color-accent-dark: var(--color-blue-205-100-45);
|
|
44
41
|
|
|
45
42
|
--font-family: 'IBM Plex Sans', sans-serif;
|
|
46
43
|
|
|
@@ -108,7 +105,7 @@
|
|
|
108
105
|
font-style: italic;
|
|
109
106
|
letter-spacing: .25px;
|
|
110
107
|
|
|
111
|
-
color: var(--color-text-
|
|
108
|
+
color: var(--color-text-lighter);
|
|
112
109
|
}
|
|
113
110
|
|
|
114
111
|
.fjs-container .fjs-form-field-label {
|
|
@@ -217,6 +214,7 @@
|
|
|
217
214
|
}
|
|
218
215
|
|
|
219
216
|
.fjs-container .fjs-form-field.fjs-has-errors .fjs-input,
|
|
217
|
+
.fjs-container .fjs-form-field.fjs-has-errors .fjs-select,
|
|
220
218
|
.fjs-container .fjs-form-field.fjs-has-errors .fjs-textarea {
|
|
221
219
|
border-color: var(--color-warning);
|
|
222
220
|
}
|
|
@@ -236,5 +234,5 @@
|
|
|
236
234
|
}
|
|
237
235
|
|
|
238
236
|
.fjs-container .fjs-form-field-text a {
|
|
239
|
-
color: var(--color-blue-
|
|
237
|
+
color: var(--color-blue-205-100-45);
|
|
240
238
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -610,7 +610,7 @@ class Validator {
|
|
|
610
610
|
errors = [...errors, `Field must match pattern ${validate.pattern}.`];
|
|
611
611
|
}
|
|
612
612
|
|
|
613
|
-
if (validate.required && (
|
|
613
|
+
if (validate.required && (minDash.isNil(value) || value === '')) {
|
|
614
614
|
errors = [...errors, 'Field is required.'];
|
|
615
615
|
}
|
|
616
616
|
|
|
@@ -726,8 +726,8 @@ class Importer {
|
|
|
726
726
|
const warnings = [];
|
|
727
727
|
|
|
728
728
|
try {
|
|
729
|
-
const
|
|
730
|
-
|
|
729
|
+
const importedSchema = this.importFormField(clone(schema)),
|
|
730
|
+
importedData = this.importData(clone(data));
|
|
731
731
|
return {
|
|
732
732
|
warnings,
|
|
733
733
|
schema: importedSchema,
|
|
@@ -740,14 +740,13 @@ class Importer {
|
|
|
740
740
|
}
|
|
741
741
|
/**
|
|
742
742
|
* @param {any} formField
|
|
743
|
-
* @param {Object} [data]
|
|
744
743
|
* @param {string} [parentId]
|
|
745
744
|
*
|
|
746
|
-
* @return {any}
|
|
745
|
+
* @return {any} importedField
|
|
747
746
|
*/
|
|
748
747
|
|
|
749
748
|
|
|
750
|
-
importFormField(formField,
|
|
749
|
+
importFormField(formField, parentId) {
|
|
751
750
|
const {
|
|
752
751
|
components,
|
|
753
752
|
key,
|
|
@@ -770,10 +769,13 @@ class Importer {
|
|
|
770
769
|
throw new Error(`form field with key <${key}> already exists`);
|
|
771
770
|
}
|
|
772
771
|
|
|
773
|
-
this._formFieldRegistry._keys.claim(key, formField); //
|
|
772
|
+
this._formFieldRegistry._keys.claim(key, formField); // TODO: buttons should not have key
|
|
774
773
|
|
|
775
774
|
|
|
776
|
-
|
|
775
|
+
if (type !== 'button') {
|
|
776
|
+
// set form field path
|
|
777
|
+
formField._path = [key];
|
|
778
|
+
}
|
|
777
779
|
}
|
|
778
780
|
|
|
779
781
|
if (id) {
|
|
@@ -791,17 +793,44 @@ class Importer {
|
|
|
791
793
|
this._formFieldRegistry.add(formField);
|
|
792
794
|
|
|
793
795
|
if (components) {
|
|
794
|
-
this.importFormFields(components,
|
|
796
|
+
this.importFormFields(components, id);
|
|
795
797
|
}
|
|
796
798
|
|
|
797
799
|
return formField;
|
|
798
800
|
}
|
|
799
801
|
|
|
800
|
-
importFormFields(components,
|
|
802
|
+
importFormFields(components, parentId) {
|
|
801
803
|
components.forEach(component => {
|
|
802
|
-
this.importFormField(component,
|
|
804
|
+
this.importFormField(component, parentId);
|
|
803
805
|
});
|
|
804
806
|
}
|
|
807
|
+
/**
|
|
808
|
+
* @param {Object} data
|
|
809
|
+
*
|
|
810
|
+
* @return {Object} importedData
|
|
811
|
+
*/
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
importData(data) {
|
|
815
|
+
return this._formFieldRegistry.getAll().reduce((importedData, formField) => {
|
|
816
|
+
const {
|
|
817
|
+
defaultValue,
|
|
818
|
+
_path,
|
|
819
|
+
type
|
|
820
|
+
} = formField;
|
|
821
|
+
|
|
822
|
+
if (!_path) {
|
|
823
|
+
return importedData;
|
|
824
|
+
} // (1) try to get value from data
|
|
825
|
+
// (2) try to get default value from form field
|
|
826
|
+
// (3) get empty value from form field
|
|
827
|
+
|
|
828
|
+
|
|
829
|
+
return { ...importedData,
|
|
830
|
+
[_path[0]]: minDash.get(data, _path, minDash.isUndefined(defaultValue) ? this._formFields.get(type).emptyValue : defaultValue)
|
|
831
|
+
};
|
|
832
|
+
}, {});
|
|
833
|
+
}
|
|
805
834
|
|
|
806
835
|
}
|
|
807
836
|
Importer.$inject = ['formFieldRegistry', 'formFields'];
|
|
@@ -1125,6 +1154,7 @@ Checkbox.create = function (options = {}) {
|
|
|
1125
1154
|
Checkbox.type = type$5;
|
|
1126
1155
|
Checkbox.label = 'Checkbox';
|
|
1127
1156
|
Checkbox.keyed = true;
|
|
1157
|
+
Checkbox.emptyValue = false;
|
|
1128
1158
|
|
|
1129
1159
|
function useService (type, strict) {
|
|
1130
1160
|
const {
|
|
@@ -1365,7 +1395,7 @@ function Number(props) {
|
|
|
1365
1395
|
const parsedValue = parseInt(target.value, 10);
|
|
1366
1396
|
props.onChange({
|
|
1367
1397
|
field,
|
|
1368
|
-
value: isNaN(parsedValue) ?
|
|
1398
|
+
value: isNaN(parsedValue) ? null : parsedValue
|
|
1369
1399
|
});
|
|
1370
1400
|
};
|
|
1371
1401
|
|
|
@@ -1401,6 +1431,7 @@ Number.create = function (options = {}) {
|
|
|
1401
1431
|
Number.type = type$4;
|
|
1402
1432
|
Number.keyed = true;
|
|
1403
1433
|
Number.label = 'Number';
|
|
1434
|
+
Number.emptyValue = null;
|
|
1404
1435
|
|
|
1405
1436
|
const type$3 = 'radio';
|
|
1406
1437
|
function Radio(props) {
|
|
@@ -1471,6 +1502,7 @@ Radio.create = function (options = {}) {
|
|
|
1471
1502
|
Radio.type = type$3;
|
|
1472
1503
|
Radio.label = 'Radio';
|
|
1473
1504
|
Radio.keyed = true;
|
|
1505
|
+
Radio.emptyValue = null;
|
|
1474
1506
|
|
|
1475
1507
|
const type$2 = 'select';
|
|
1476
1508
|
function Select(props) {
|
|
@@ -1496,7 +1528,7 @@ function Select(props) {
|
|
|
1496
1528
|
}) => {
|
|
1497
1529
|
props.onChange({
|
|
1498
1530
|
field,
|
|
1499
|
-
value: target.value === '' ?
|
|
1531
|
+
value: target.value === '' ? null : target.value
|
|
1500
1532
|
});
|
|
1501
1533
|
};
|
|
1502
1534
|
|
|
@@ -1544,6 +1576,7 @@ Select.create = function (options = {}) {
|
|
|
1544
1576
|
Select.type = type$2;
|
|
1545
1577
|
Select.label = 'Select';
|
|
1546
1578
|
Select.keyed = true;
|
|
1579
|
+
Select.emptyValue = null;
|
|
1547
1580
|
|
|
1548
1581
|
const type$1 = 'text';
|
|
1549
1582
|
function Text(props) {
|
|
@@ -1631,6 +1664,7 @@ Textfield.create = function (options = {}) {
|
|
|
1631
1664
|
Textfield.type = type;
|
|
1632
1665
|
Textfield.label = 'Text Field';
|
|
1633
1666
|
Textfield.keyed = true;
|
|
1667
|
+
Textfield.emptyValue = '';
|
|
1634
1668
|
|
|
1635
1669
|
const formFields = [Button, Checkbox, Default, Number, Radio, Select, Text, Textfield];
|
|
1636
1670
|
|
|
@@ -1872,21 +1906,22 @@ class Form {
|
|
|
1872
1906
|
throw new Error('form is read-only');
|
|
1873
1907
|
}
|
|
1874
1908
|
|
|
1875
|
-
const formFieldRegistry = this.get('formFieldRegistry');
|
|
1876
|
-
|
|
1909
|
+
const formFieldRegistry = this.get('formFieldRegistry');
|
|
1877
1910
|
const data = formFieldRegistry.getAll().reduce((data, field) => {
|
|
1878
1911
|
const {
|
|
1879
1912
|
disabled,
|
|
1880
1913
|
_path
|
|
1881
|
-
} = field;
|
|
1914
|
+
} = field; // do not submit disabled form fields
|
|
1882
1915
|
|
|
1883
|
-
if (disabled) {
|
|
1884
|
-
|
|
1885
|
-
minDash.set(data, _path, undefined);
|
|
1916
|
+
if (disabled || !_path) {
|
|
1917
|
+
return data;
|
|
1886
1918
|
}
|
|
1887
1919
|
|
|
1888
|
-
|
|
1889
|
-
|
|
1920
|
+
const value = minDash.get(this._getState().data, _path);
|
|
1921
|
+
return { ...data,
|
|
1922
|
+
[_path[0]]: value
|
|
1923
|
+
};
|
|
1924
|
+
}, {});
|
|
1890
1925
|
const errors = this.validate();
|
|
1891
1926
|
|
|
1892
1927
|
this._emit('submit', {
|
|
@@ -2110,7 +2145,7 @@ class Form {
|
|
|
2110
2145
|
|
|
2111
2146
|
}
|
|
2112
2147
|
|
|
2113
|
-
const schemaVersion =
|
|
2148
|
+
const schemaVersion = 3;
|
|
2114
2149
|
/**
|
|
2115
2150
|
* @typedef { import('./types').CreateFormOptions } CreateFormOptions
|
|
2116
2151
|
*/
|