@bpmn-io/form-js-editor 0.6.1 → 0.7.2
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/index.cjs +220 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.es.js +221 -23
- package/dist/index.es.js.map +1 -1
- package/dist/types/FormEditor.d.ts +16 -6
- package/dist/types/render/components/properties-panel/entries/CustomValueEntry.d.ts +1 -0
- package/dist/types/render/components/properties-panel/entries/index.d.ts +1 -0
- package/dist/types/render/components/properties-panel/groups/CustomValuesGroup.d.ts +10 -0
- package/dist/types/render/components/properties-panel/groups/index.d.ts +1 -0
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var formJsViewer = require('@bpmn-io/form-js-viewer');
|
|
5
6
|
var Ids = require('ids');
|
|
6
7
|
var minDash = require('min-dash');
|
|
7
|
-
var formJsViewer = require('@bpmn-io/form-js-viewer');
|
|
8
8
|
var preact = require('preact');
|
|
9
9
|
var hooks$1 = require('preact/hooks');
|
|
10
10
|
var React = require('preact/compat');
|
|
@@ -1165,7 +1165,7 @@ function TextInput(props) {
|
|
|
1165
1165
|
const prevValue = usePrevious(value);
|
|
1166
1166
|
const [cachedValue, setCachedValue] = hooks$1.useState(null);
|
|
1167
1167
|
const [error, setError] = hooks$1.useState(null);
|
|
1168
|
-
hooks$1.useEffect(() => setError(validate(value)), [value]);
|
|
1168
|
+
hooks$1.useEffect(() => setError(validate(value)), [validate, value]);
|
|
1169
1169
|
const onInput = useDebounce(event => {
|
|
1170
1170
|
const value = event.target.value;
|
|
1171
1171
|
const error = validate(value);
|
|
@@ -1679,7 +1679,7 @@ function DisabledEntry(props) {
|
|
|
1679
1679
|
} = props;
|
|
1680
1680
|
|
|
1681
1681
|
const onChange = value => {
|
|
1682
|
-
editField(field, 'disabled', value);
|
|
1682
|
+
editField(field, ['disabled'], value);
|
|
1683
1683
|
};
|
|
1684
1684
|
|
|
1685
1685
|
return jsxRuntime.jsx(CheckboxInputEntry, {
|
|
@@ -1815,9 +1815,18 @@ function ValueEntry(props) {
|
|
|
1815
1815
|
const {
|
|
1816
1816
|
editField,
|
|
1817
1817
|
field,
|
|
1818
|
-
index
|
|
1818
|
+
index,
|
|
1819
|
+
validate
|
|
1819
1820
|
} = props;
|
|
1820
1821
|
|
|
1822
|
+
const getLabel = () => {
|
|
1823
|
+
return minDash.get(field, ['values', index, 'label']);
|
|
1824
|
+
};
|
|
1825
|
+
|
|
1826
|
+
const getValue = () => {
|
|
1827
|
+
return minDash.get(field, ['values', index, 'value']);
|
|
1828
|
+
};
|
|
1829
|
+
|
|
1821
1830
|
const onChange = key => {
|
|
1822
1831
|
const values = minDash.get(field, ['values']);
|
|
1823
1832
|
return value => {
|
|
@@ -1830,14 +1839,93 @@ function ValueEntry(props) {
|
|
|
1830
1839
|
id: `value-label-${index}`,
|
|
1831
1840
|
label: "Label",
|
|
1832
1841
|
onChange: onChange('label'),
|
|
1833
|
-
value:
|
|
1842
|
+
value: getLabel()
|
|
1843
|
+
}), jsxRuntime.jsx(TextInputEntry, {
|
|
1844
|
+
id: `value-value-${index}`,
|
|
1845
|
+
label: "Value",
|
|
1846
|
+
onChange: onChange('value'),
|
|
1847
|
+
value: getValue(),
|
|
1848
|
+
validate: validate(getValue())
|
|
1849
|
+
})]
|
|
1850
|
+
});
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
function CustomValueEntry(props) {
|
|
1854
|
+
const {
|
|
1855
|
+
editField,
|
|
1856
|
+
field,
|
|
1857
|
+
index,
|
|
1858
|
+
validate
|
|
1859
|
+
} = props;
|
|
1860
|
+
|
|
1861
|
+
const getKey = () => {
|
|
1862
|
+
return Object.keys(minDash.get(field, ['properties']))[index];
|
|
1863
|
+
};
|
|
1864
|
+
|
|
1865
|
+
const getValue = () => {
|
|
1866
|
+
return minDash.get(field, ['properties', getKey()]);
|
|
1867
|
+
};
|
|
1868
|
+
|
|
1869
|
+
const onChange = key => {
|
|
1870
|
+
const properties = minDash.get(field, ['properties']);
|
|
1871
|
+
return value => {
|
|
1872
|
+
if (key === 'value') {
|
|
1873
|
+
editField(field, 'properties', updateValue(properties, getKey(), value));
|
|
1874
|
+
} else if (key === 'key') {
|
|
1875
|
+
editField(field, 'properties', updateKey(properties, getKey(), value));
|
|
1876
|
+
}
|
|
1877
|
+
};
|
|
1878
|
+
};
|
|
1879
|
+
|
|
1880
|
+
return jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1881
|
+
children: [jsxRuntime.jsx(TextInputEntry, {
|
|
1882
|
+
id: `value-key-${index}`,
|
|
1883
|
+
label: "Key",
|
|
1884
|
+
onChange: onChange('key'),
|
|
1885
|
+
value: getKey(),
|
|
1886
|
+
validate: validate(getKey())
|
|
1834
1887
|
}), jsxRuntime.jsx(TextInputEntry, {
|
|
1835
1888
|
id: `value-value-${index}`,
|
|
1836
1889
|
label: "Value",
|
|
1837
1890
|
onChange: onChange('value'),
|
|
1838
|
-
value:
|
|
1891
|
+
value: getValue()
|
|
1839
1892
|
})]
|
|
1840
1893
|
});
|
|
1894
|
+
} // helpers //////////
|
|
1895
|
+
|
|
1896
|
+
/**
|
|
1897
|
+
* Returns copy of object with updated value.
|
|
1898
|
+
*
|
|
1899
|
+
* @param {Object} properties
|
|
1900
|
+
* @param {string} key
|
|
1901
|
+
* @param {string} value
|
|
1902
|
+
*
|
|
1903
|
+
* @returns {Object}
|
|
1904
|
+
*/
|
|
1905
|
+
|
|
1906
|
+
function updateValue(properties, key, value) {
|
|
1907
|
+
return { ...properties,
|
|
1908
|
+
[key]: value
|
|
1909
|
+
};
|
|
1910
|
+
}
|
|
1911
|
+
/**
|
|
1912
|
+
* Returns copy of object with updated key.
|
|
1913
|
+
*
|
|
1914
|
+
* @param {Object} properties
|
|
1915
|
+
* @param {string} oldKey
|
|
1916
|
+
* @param {string} newKey
|
|
1917
|
+
*
|
|
1918
|
+
* @returns {Object}
|
|
1919
|
+
*/
|
|
1920
|
+
|
|
1921
|
+
|
|
1922
|
+
function updateKey(properties, oldKey, newKey) {
|
|
1923
|
+
return Object.entries(properties).reduce((newProperties, entry) => {
|
|
1924
|
+
const [key, value] = entry;
|
|
1925
|
+
return { ...newProperties,
|
|
1926
|
+
[key === oldKey ? newKey : key]: value
|
|
1927
|
+
};
|
|
1928
|
+
}, {});
|
|
1841
1929
|
}
|
|
1842
1930
|
|
|
1843
1931
|
function GeneralGroup(field, editField) {
|
|
@@ -1948,10 +2036,10 @@ function ValidationGroup(field, editField) {
|
|
|
1948
2036
|
onChange: onChange('maxLength'),
|
|
1949
2037
|
value: minDash.get(field, ['validate', 'maxLength'])
|
|
1950
2038
|
}), jsxRuntime.jsx(TextInputEntry, {
|
|
1951
|
-
id: "
|
|
2039
|
+
id: "pattern",
|
|
1952
2040
|
label: "Regular Expression Pattern",
|
|
1953
|
-
onChange: onChange('
|
|
1954
|
-
value: minDash.get(field, ['validate', '
|
|
2041
|
+
onChange: onChange('pattern'),
|
|
2042
|
+
value: minDash.get(field, ['validate', 'pattern'])
|
|
1955
2043
|
}));
|
|
1956
2044
|
}
|
|
1957
2045
|
|
|
@@ -1982,13 +2070,32 @@ function ValuesGroup(field, editField) {
|
|
|
1982
2070
|
} = field;
|
|
1983
2071
|
|
|
1984
2072
|
const addEntry = () => {
|
|
2073
|
+
const index = values.length + 1;
|
|
1985
2074
|
const entry = {
|
|
1986
|
-
label:
|
|
1987
|
-
value:
|
|
2075
|
+
label: `Value ${index}`,
|
|
2076
|
+
value: `value${index}`
|
|
1988
2077
|
};
|
|
1989
2078
|
editField(field, ['values'], arrayAdd$1(values, values.length, entry));
|
|
1990
2079
|
};
|
|
1991
2080
|
|
|
2081
|
+
const validateFactory = key => {
|
|
2082
|
+
return value => {
|
|
2083
|
+
if (value === key) {
|
|
2084
|
+
return;
|
|
2085
|
+
}
|
|
2086
|
+
|
|
2087
|
+
if (minDash.isUndefined(value) || !value.length) {
|
|
2088
|
+
return 'Must not be empty.';
|
|
2089
|
+
}
|
|
2090
|
+
|
|
2091
|
+
const isValueAssigned = values.find(entry => entry.value === value);
|
|
2092
|
+
|
|
2093
|
+
if (isValueAssigned) {
|
|
2094
|
+
return 'Must be unique.';
|
|
2095
|
+
}
|
|
2096
|
+
};
|
|
2097
|
+
};
|
|
2098
|
+
|
|
1992
2099
|
const hasEntries = values.length > 0;
|
|
1993
2100
|
return jsxRuntime.jsx(Group, {
|
|
1994
2101
|
label: "Values",
|
|
@@ -2009,13 +2116,92 @@ function ValuesGroup(field, editField) {
|
|
|
2009
2116
|
children: jsxRuntime.jsx(ValueEntry, {
|
|
2010
2117
|
editField: editField,
|
|
2011
2118
|
field: field,
|
|
2012
|
-
index: index
|
|
2119
|
+
index: index,
|
|
2120
|
+
validate: validateFactory
|
|
2013
2121
|
})
|
|
2014
2122
|
}, `${id}-${index}`);
|
|
2015
2123
|
})
|
|
2016
2124
|
});
|
|
2017
2125
|
}
|
|
2018
2126
|
|
|
2127
|
+
function CustomValuesGroup(field, editField) {
|
|
2128
|
+
const {
|
|
2129
|
+
id,
|
|
2130
|
+
properties = {}
|
|
2131
|
+
} = field;
|
|
2132
|
+
|
|
2133
|
+
const addEntry = () => {
|
|
2134
|
+
const index = Object.keys(properties).length + 1;
|
|
2135
|
+
const key = `key${index}`,
|
|
2136
|
+
value = 'value';
|
|
2137
|
+
editField(field, ['properties'], { ...properties,
|
|
2138
|
+
[key]: value
|
|
2139
|
+
});
|
|
2140
|
+
};
|
|
2141
|
+
|
|
2142
|
+
const validateFactory = key => {
|
|
2143
|
+
return value => {
|
|
2144
|
+
if (value === key) {
|
|
2145
|
+
return;
|
|
2146
|
+
}
|
|
2147
|
+
|
|
2148
|
+
if (minDash.isUndefined(value) || !value.length) {
|
|
2149
|
+
return 'Must not be empty.';
|
|
2150
|
+
}
|
|
2151
|
+
|
|
2152
|
+
if (minDash.has(properties, value)) {
|
|
2153
|
+
return 'Must be unique.';
|
|
2154
|
+
}
|
|
2155
|
+
};
|
|
2156
|
+
};
|
|
2157
|
+
|
|
2158
|
+
const hasEntries = Object.keys(properties).length > 0;
|
|
2159
|
+
return jsxRuntime.jsx(Group, {
|
|
2160
|
+
label: "Custom Properties",
|
|
2161
|
+
addEntry: addEntry,
|
|
2162
|
+
hasEntries: hasEntries,
|
|
2163
|
+
children: Object.keys(properties).map((key, index) => {
|
|
2164
|
+
const removeEntry = () => {
|
|
2165
|
+
editField(field, ['properties'], removeKey(properties, key));
|
|
2166
|
+
};
|
|
2167
|
+
|
|
2168
|
+
return jsxRuntime.jsx(CollapsibleEntry, {
|
|
2169
|
+
label: key,
|
|
2170
|
+
removeEntry: removeEntry,
|
|
2171
|
+
children: jsxRuntime.jsx(CustomValueEntry, {
|
|
2172
|
+
editField: editField,
|
|
2173
|
+
field: field,
|
|
2174
|
+
index: index,
|
|
2175
|
+
validate: validateFactory
|
|
2176
|
+
})
|
|
2177
|
+
}, `${id}-${index}`);
|
|
2178
|
+
})
|
|
2179
|
+
});
|
|
2180
|
+
} // helpers //////////
|
|
2181
|
+
|
|
2182
|
+
/**
|
|
2183
|
+
* Returns copy of object without key.
|
|
2184
|
+
*
|
|
2185
|
+
* @param {Object} properties
|
|
2186
|
+
* @param {string} oldKey
|
|
2187
|
+
*
|
|
2188
|
+
* @returns {Object}
|
|
2189
|
+
*/
|
|
2190
|
+
|
|
2191
|
+
function removeKey(properties, oldKey) {
|
|
2192
|
+
return Object.entries(properties).reduce((newProperties, entry) => {
|
|
2193
|
+
const [key, value] = entry;
|
|
2194
|
+
|
|
2195
|
+
if (key === oldKey) {
|
|
2196
|
+
return newProperties;
|
|
2197
|
+
}
|
|
2198
|
+
|
|
2199
|
+
return { ...newProperties,
|
|
2200
|
+
[key]: value
|
|
2201
|
+
};
|
|
2202
|
+
}, {});
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2019
2205
|
const labelsByType = {
|
|
2020
2206
|
button: 'BUTTON',
|
|
2021
2207
|
checkbox: 'CHECKBOX',
|
|
@@ -2042,6 +2228,10 @@ function getGroups(field, editField) {
|
|
|
2042
2228
|
groups.push(ValidationGroup(field, editField));
|
|
2043
2229
|
}
|
|
2044
2230
|
|
|
2231
|
+
if (type !== 'default') {
|
|
2232
|
+
groups.push(CustomValuesGroup(field, editField));
|
|
2233
|
+
}
|
|
2234
|
+
|
|
2045
2235
|
return groups;
|
|
2046
2236
|
}
|
|
2047
2237
|
|
|
@@ -4475,6 +4665,10 @@ const ids = new Ids__default['default']([32, 36, 1]);
|
|
|
4475
4665
|
* properties: FormEditorProperties,
|
|
4476
4666
|
* schema: Schema
|
|
4477
4667
|
* } } State
|
|
4668
|
+
*
|
|
4669
|
+
* @typedef { (type:string, priority:number, handler:Function) => void } OnEventWithPriority
|
|
4670
|
+
* @typedef { (type:string, handler:Function) => void } OnEventWithOutPriority
|
|
4671
|
+
* @typedef { OnEventWithPriority & OnEventWithOutPriority } OnEventType
|
|
4478
4672
|
*/
|
|
4479
4673
|
|
|
4480
4674
|
/**
|
|
@@ -4487,10 +4681,16 @@ class FormEditor {
|
|
|
4487
4681
|
* @param {FormEditorOptions} options
|
|
4488
4682
|
*/
|
|
4489
4683
|
constructor(options = {}) {
|
|
4684
|
+
/**
|
|
4685
|
+
* @public
|
|
4686
|
+
* @type {OnEventType}
|
|
4687
|
+
*/
|
|
4688
|
+
this.on = this._onEvent;
|
|
4490
4689
|
/**
|
|
4491
4690
|
* @public
|
|
4492
4691
|
* @type {String}
|
|
4493
4692
|
*/
|
|
4693
|
+
|
|
4494
4694
|
this._id = ids.next();
|
|
4495
4695
|
/**
|
|
4496
4696
|
* @private
|
|
@@ -4663,16 +4863,6 @@ class FormEditor {
|
|
|
4663
4863
|
properties
|
|
4664
4864
|
});
|
|
4665
4865
|
}
|
|
4666
|
-
/**
|
|
4667
|
-
* @param {string} type
|
|
4668
|
-
* @param {number} priority
|
|
4669
|
-
* @param {Function} handler
|
|
4670
|
-
*/
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
on(type, priority, handler) {
|
|
4674
|
-
this.get('eventBus').on(type, priority, handler);
|
|
4675
|
-
}
|
|
4676
4866
|
/**
|
|
4677
4867
|
* @param {string} type
|
|
4678
4868
|
* @param {Function} handler
|
|
@@ -4745,6 +4935,14 @@ class FormEditor {
|
|
|
4745
4935
|
_getModules() {
|
|
4746
4936
|
return [ModelingModule, EditorActionsModule, KeyboardModule, SelectionModule];
|
|
4747
4937
|
}
|
|
4938
|
+
/**
|
|
4939
|
+
* @internal
|
|
4940
|
+
*/
|
|
4941
|
+
|
|
4942
|
+
|
|
4943
|
+
_onEvent(type, priority, handler) {
|
|
4944
|
+
this.get('eventBus').on(type, priority, handler);
|
|
4945
|
+
}
|
|
4748
4946
|
|
|
4749
4947
|
} // helpers //////////
|
|
4750
4948
|
|