@bpmn-io/form-js-viewer 0.8.0-alpha.0 → 0.8.0-alpha.1
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 +1 -3
- package/dist/index.cjs +116 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.es.js +117 -46
- package/dist/index.es.js.map +1 -1
- package/dist/types/Form.d.ts +3 -3
- package/dist/types/render/Renderer.d.ts +2 -2
- package/dist/types/render/components/Util.d.ts +2 -0
- package/dist/types/render/components/form-fields/Checkbox.d.ts +3 -0
- package/dist/types/render/components/form-fields/Checklist.d.ts +2 -0
- package/dist/types/render/components/form-fields/Number.d.ts +3 -0
- package/dist/types/render/components/form-fields/Radio.d.ts +2 -0
- package/dist/types/render/components/form-fields/Select.d.ts +2 -0
- package/dist/types/render/components/form-fields/Taglist.d.ts +2 -0
- package/dist/types/render/components/form-fields/Textfield.d.ts +3 -0
- package/dist/types/render/components/index.d.ts +1 -1
- package/dist/types/util/index.d.ts +8 -0
- package/dist/types/util/injector.d.ts +2 -1
- package/package.json +3 -3
package/dist/assets/form-js.css
CHANGED
|
@@ -189,9 +189,7 @@
|
|
|
189
189
|
.fjs-container .fjs-button[type='reset']:focus,
|
|
190
190
|
.fjs-container .fjs-textarea:focus,
|
|
191
191
|
.fjs-container .fjs-select:focus {
|
|
192
|
-
outline:
|
|
193
|
-
padding: 7px;
|
|
194
|
-
border-width: 2px;
|
|
192
|
+
outline: var(--color-borders) solid 1px;
|
|
195
193
|
}
|
|
196
194
|
|
|
197
195
|
.fjs-container .fjs-button[type='submit']:focus {
|
package/dist/index.cjs
CHANGED
|
@@ -601,45 +601,8 @@ class FormFieldRegistry {
|
|
|
601
601
|
FormFieldRegistry.$inject = ['eventBus'];
|
|
602
602
|
|
|
603
603
|
function createInjector(bootstrapModules) {
|
|
604
|
-
const
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
function hasModule(module) {
|
|
608
|
-
return modules.includes(module);
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
function addModule(module) {
|
|
612
|
-
modules.push(module);
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
function visit(module) {
|
|
616
|
-
if (hasModule(module)) {
|
|
617
|
-
return;
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
(module.__depends__ || []).forEach(visit);
|
|
621
|
-
|
|
622
|
-
if (hasModule(module)) {
|
|
623
|
-
return;
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
addModule(module);
|
|
627
|
-
(module.__init__ || []).forEach(function (component) {
|
|
628
|
-
components.push(component);
|
|
629
|
-
});
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
bootstrapModules.forEach(visit);
|
|
633
|
-
const injector = new didi.Injector(modules);
|
|
634
|
-
components.forEach(function (component) {
|
|
635
|
-
try {
|
|
636
|
-
injector[typeof component === 'string' ? 'get' : 'invoke'](component);
|
|
637
|
-
} catch (err) {
|
|
638
|
-
console.error('Failed to instantiate component');
|
|
639
|
-
console.error(err.stack);
|
|
640
|
-
throw err;
|
|
641
|
-
}
|
|
642
|
-
});
|
|
604
|
+
const injector = new didi.Injector(bootstrapModules);
|
|
605
|
+
injector.init();
|
|
643
606
|
return injector;
|
|
644
607
|
}
|
|
645
608
|
|
|
@@ -702,6 +665,41 @@ function generateIdForType(type) {
|
|
|
702
665
|
function clone(data, replacer) {
|
|
703
666
|
return JSON.parse(JSON.stringify(data, replacer));
|
|
704
667
|
}
|
|
668
|
+
/**
|
|
669
|
+
* Parse the schema for input variables a form might make use of
|
|
670
|
+
*
|
|
671
|
+
* @param {any} schema
|
|
672
|
+
*
|
|
673
|
+
* @return {string[]}
|
|
674
|
+
*/
|
|
675
|
+
|
|
676
|
+
function getSchemaVariables(schema) {
|
|
677
|
+
if (!schema.components) {
|
|
678
|
+
return [];
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
return schema.components.reduce((variables, component) => {
|
|
682
|
+
const {
|
|
683
|
+
key,
|
|
684
|
+
valuesKey,
|
|
685
|
+
type
|
|
686
|
+
} = component;
|
|
687
|
+
|
|
688
|
+
if (['text', 'button'].includes(type)) {
|
|
689
|
+
return variables;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
if (key) {
|
|
693
|
+
variables = [...variables, key];
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
if (valuesKey && !variables.includes(valuesKey)) {
|
|
697
|
+
variables = [...variables, valuesKey];
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
return variables;
|
|
701
|
+
}, []);
|
|
702
|
+
}
|
|
705
703
|
|
|
706
704
|
class Importer {
|
|
707
705
|
/**
|
|
@@ -726,7 +724,7 @@ class Importer {
|
|
|
726
724
|
|
|
727
725
|
|
|
728
726
|
importSchema(schema, data = {}) {
|
|
729
|
-
// TODO: Add warnings
|
|
727
|
+
// TODO: Add warnings - https://github.com/bpmn-io/form-js/issues/289
|
|
730
728
|
const warnings = [];
|
|
731
729
|
|
|
732
730
|
try {
|
|
@@ -834,8 +832,21 @@ class Importer {
|
|
|
834
832
|
|
|
835
833
|
|
|
836
834
|
if (_path) {
|
|
835
|
+
const fieldImplementation = this._formFields.get(type);
|
|
836
|
+
|
|
837
|
+
let valueData = minDash.get(data, _path);
|
|
838
|
+
|
|
839
|
+
if (!minDash.isUndefined(valueData) && fieldImplementation.sanitizeValue) {
|
|
840
|
+
valueData = fieldImplementation.sanitizeValue({
|
|
841
|
+
formField,
|
|
842
|
+
data,
|
|
843
|
+
value: valueData
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
const initialFieldValue = !minDash.isUndefined(valueData) ? valueData : !minDash.isUndefined(defaultValue) ? defaultValue : fieldImplementation.emptyValue;
|
|
837
848
|
importedData = { ...importedData,
|
|
838
|
-
[_path[0]]:
|
|
849
|
+
[_path[0]]: initialFieldValue
|
|
839
850
|
};
|
|
840
851
|
}
|
|
841
852
|
|
|
@@ -999,6 +1010,46 @@ function safeMarkdown(markdown) {
|
|
|
999
1010
|
const html = markdownToHTML(markdown);
|
|
1000
1011
|
return sanitizeHTML(html);
|
|
1001
1012
|
}
|
|
1013
|
+
function sanitizeSingleSelectValue(options) {
|
|
1014
|
+
const {
|
|
1015
|
+
formField,
|
|
1016
|
+
data,
|
|
1017
|
+
value
|
|
1018
|
+
} = options;
|
|
1019
|
+
const {
|
|
1020
|
+
valuesKey,
|
|
1021
|
+
values
|
|
1022
|
+
} = formField;
|
|
1023
|
+
|
|
1024
|
+
try {
|
|
1025
|
+
const validValues = (valuesKey ? minDash.get(data, [valuesKey]) : values).map(v => v.value) || [];
|
|
1026
|
+
return validValues.includes(value) ? value : null;
|
|
1027
|
+
} catch (error) {
|
|
1028
|
+
// use default value in case of formatting error
|
|
1029
|
+
// TODO(@Skaiir): log a warning when this happens - https://github.com/bpmn-io/form-js/issues/289
|
|
1030
|
+
return null;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
function sanitizeMultiSelectValue(options) {
|
|
1034
|
+
const {
|
|
1035
|
+
formField,
|
|
1036
|
+
data,
|
|
1037
|
+
value
|
|
1038
|
+
} = options;
|
|
1039
|
+
const {
|
|
1040
|
+
valuesKey,
|
|
1041
|
+
values
|
|
1042
|
+
} = formField;
|
|
1043
|
+
|
|
1044
|
+
try {
|
|
1045
|
+
const validValues = (valuesKey ? minDash.get(data, [valuesKey]) : values).map(v => v.value) || [];
|
|
1046
|
+
return value.filter(v => validValues.includes(v));
|
|
1047
|
+
} catch (error) {
|
|
1048
|
+
// use default value in case of formatting error
|
|
1049
|
+
// TODO(@Skaiir): log a warning when this happens - https://github.com/bpmn-io/form-js/issues/289
|
|
1050
|
+
return [];
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1002
1053
|
|
|
1003
1054
|
const type$8 = 'button';
|
|
1004
1055
|
function Button(props) {
|
|
@@ -1167,6 +1218,10 @@ Checkbox.label = 'Checkbox';
|
|
|
1167
1218
|
Checkbox.keyed = true;
|
|
1168
1219
|
Checkbox.emptyValue = false;
|
|
1169
1220
|
|
|
1221
|
+
Checkbox.sanitizeValue = ({
|
|
1222
|
+
value
|
|
1223
|
+
}) => value === true;
|
|
1224
|
+
|
|
1170
1225
|
function useService (type, strict) {
|
|
1171
1226
|
const {
|
|
1172
1227
|
getService
|
|
@@ -1319,6 +1374,7 @@ Checklist.type = type$6;
|
|
|
1319
1374
|
Checklist.label = 'Checklist';
|
|
1320
1375
|
Checklist.keyed = true;
|
|
1321
1376
|
Checklist.emptyValue = [];
|
|
1377
|
+
Checklist.sanitizeValue = sanitizeMultiSelectValue;
|
|
1322
1378
|
|
|
1323
1379
|
const noop$1 = () => false;
|
|
1324
1380
|
|
|
@@ -1549,10 +1605,11 @@ function Number(props) {
|
|
|
1549
1605
|
const onChange = ({
|
|
1550
1606
|
target
|
|
1551
1607
|
}) => {
|
|
1552
|
-
const parsedValue = parseInt(target.value, 10);
|
|
1553
1608
|
props.onChange({
|
|
1554
1609
|
field,
|
|
1555
|
-
value:
|
|
1610
|
+
value: Number.sanitizeValue({
|
|
1611
|
+
value: target.value
|
|
1612
|
+
})
|
|
1556
1613
|
});
|
|
1557
1614
|
};
|
|
1558
1615
|
|
|
@@ -1585,6 +1642,13 @@ Number.create = function (options = {}) {
|
|
|
1585
1642
|
};
|
|
1586
1643
|
};
|
|
1587
1644
|
|
|
1645
|
+
Number.sanitizeValue = ({
|
|
1646
|
+
value
|
|
1647
|
+
}) => {
|
|
1648
|
+
const parsedValue = parseInt(value, 10);
|
|
1649
|
+
return isNaN(parsedValue) ? null : parsedValue;
|
|
1650
|
+
};
|
|
1651
|
+
|
|
1588
1652
|
Number.type = type$5;
|
|
1589
1653
|
Number.keyed = true;
|
|
1590
1654
|
Number.label = 'Number';
|
|
@@ -1664,6 +1728,7 @@ Radio.type = type$4;
|
|
|
1664
1728
|
Radio.label = 'Radio';
|
|
1665
1729
|
Radio.keyed = true;
|
|
1666
1730
|
Radio.emptyValue = null;
|
|
1731
|
+
Radio.sanitizeValue = sanitizeSingleSelectValue;
|
|
1667
1732
|
|
|
1668
1733
|
const type$3 = 'select';
|
|
1669
1734
|
function Select(props) {
|
|
@@ -1742,6 +1807,7 @@ Select.type = type$3;
|
|
|
1742
1807
|
Select.label = 'Select';
|
|
1743
1808
|
Select.keyed = true;
|
|
1744
1809
|
Select.emptyValue = null;
|
|
1810
|
+
Select.sanitizeValue = sanitizeSingleSelectValue;
|
|
1745
1811
|
|
|
1746
1812
|
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); }
|
|
1747
1813
|
var CloseIcon = (({
|
|
@@ -1913,7 +1979,7 @@ function Taglist(props) {
|
|
|
1913
1979
|
}, [JSON.stringify(values), options, loadState]);
|
|
1914
1980
|
hooks.useEffect(() => {
|
|
1915
1981
|
if (loadState === LOAD_STATES.LOADED) {
|
|
1916
|
-
setFilteredValues(options.filter(o => o.label && o.label.toLowerCase().includes(filter.toLowerCase()) && !values.includes(o.value)));
|
|
1982
|
+
setFilteredValues(options.filter(o => o.label && o.value && o.label.toLowerCase().includes(filter.toLowerCase()) && !values.includes(o.value)));
|
|
1917
1983
|
} else {
|
|
1918
1984
|
setFilteredValues([]);
|
|
1919
1985
|
}
|
|
@@ -2044,6 +2110,7 @@ Taglist.type = type$2;
|
|
|
2044
2110
|
Taglist.label = 'Taglist';
|
|
2045
2111
|
Taglist.keyed = true;
|
|
2046
2112
|
Taglist.emptyValue = [];
|
|
2113
|
+
Taglist.sanitizeValue = sanitizeMultiSelectValue;
|
|
2047
2114
|
|
|
2048
2115
|
const type$1 = 'text';
|
|
2049
2116
|
function Text(props) {
|
|
@@ -2133,6 +2200,10 @@ Textfield.label = 'Text Field';
|
|
|
2133
2200
|
Textfield.keyed = true;
|
|
2134
2201
|
Textfield.emptyValue = '';
|
|
2135
2202
|
|
|
2203
|
+
Textfield.sanitizeValue = ({
|
|
2204
|
+
value
|
|
2205
|
+
}) => minDash.isArray(value) || minDash.isObject(value) ? null : String(value);
|
|
2206
|
+
|
|
2136
2207
|
const formFields = [Button, Checkbox, Checklist, Default, Number, Radio, Select, Taglist, Text, Textfield];
|
|
2137
2208
|
|
|
2138
2209
|
class FormFields {
|
|
@@ -2669,6 +2740,7 @@ exports.findErrors = findErrors;
|
|
|
2669
2740
|
exports.formFields = formFields;
|
|
2670
2741
|
exports.generateIdForType = generateIdForType;
|
|
2671
2742
|
exports.generateIndexForType = generateIndexForType;
|
|
2743
|
+
exports.getSchemaVariables = getSchemaVariables;
|
|
2672
2744
|
exports.isRequired = isRequired;
|
|
2673
2745
|
exports.pathParse = pathParse;
|
|
2674
2746
|
exports.pathStringify = pathStringify;
|