@bpmn-io/form-js-editor 0.5.0 → 0.7.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/index.cjs CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var Ids = require('ids');
5
6
  var minDash = require('min-dash');
6
7
  var formJsViewer = require('@bpmn-io/form-js-viewer');
7
8
  var preact = require('preact');
@@ -14,6 +15,7 @@ var arrayMove = require('array-move');
14
15
 
15
16
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
17
 
18
+ var Ids__default = /*#__PURE__*/_interopDefaultLegacy(Ids);
17
19
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
18
20
  var dragula__default = /*#__PURE__*/_interopDefaultLegacy(dragula);
19
21
 
@@ -1014,7 +1016,7 @@ function CheckboxInput(props) {
1014
1016
  };
1015
1017
 
1016
1018
  return jsxRuntime.jsxs("div", {
1017
- class: "fjs-properties-panel-textfield",
1019
+ class: "fjs-properties-panel-checkbox",
1018
1020
  children: [jsxRuntime.jsx("label", {
1019
1021
  for: prefixId(id),
1020
1022
  class: "fjs-properties-panel-label",
@@ -1069,7 +1071,7 @@ function NumberInput(props) {
1069
1071
  }
1070
1072
  }, [_onInput]);
1071
1073
  return jsxRuntime.jsxs("div", {
1072
- class: "fjs-properties-panel-textfield",
1074
+ class: "fjs-properties-panel-number",
1073
1075
  children: [jsxRuntime.jsx("label", {
1074
1076
  for: prefixId(id),
1075
1077
  class: "fjs-properties-panel-label",
@@ -1102,7 +1104,7 @@ function Select(props) {
1102
1104
  };
1103
1105
 
1104
1106
  return jsxRuntime.jsxs("div", {
1105
- class: "fjs-properties-panel-textfield",
1107
+ class: "fjs-properties-panel-select",
1106
1108
  children: [jsxRuntime.jsx("label", {
1107
1109
  for: prefixId(id),
1108
1110
  class: "fjs-properties-panel-label",
@@ -1136,7 +1138,7 @@ function Textarea(props) {
1136
1138
  _onInput(value.length ? value : undefined);
1137
1139
  }, [_onInput]);
1138
1140
  return jsxRuntime.jsxs("div", {
1139
- class: "fjs-properties-panel-textfield",
1141
+ class: "fjs-properties-panel-textarea",
1140
1142
  children: [jsxRuntime.jsx("label", {
1141
1143
  for: prefixId(id),
1142
1144
  class: "fjs-properties-panel-label",
@@ -1163,7 +1165,7 @@ function TextInput(props) {
1163
1165
  const prevValue = usePrevious(value);
1164
1166
  const [cachedValue, setCachedValue] = hooks$1.useState(null);
1165
1167
  const [error, setError] = hooks$1.useState(null);
1166
- hooks$1.useEffect(() => setError(validate(value)), [value]);
1168
+ hooks$1.useEffect(() => setError(validate(value)), [validate, value]);
1167
1169
  const onInput = useDebounce(event => {
1168
1170
  const value = event.target.value;
1169
1171
  const error = validate(value);
@@ -1188,7 +1190,7 @@ function TextInput(props) {
1188
1190
  }
1189
1191
 
1190
1192
  return jsxRuntime.jsxs("div", {
1191
- class: "fjs-properties-panel-textfield",
1193
+ class: "fjs-properties-panel-text",
1192
1194
  children: [jsxRuntime.jsx("label", {
1193
1195
  for: prefixId(id),
1194
1196
  class: "fjs-properties-panel-label",
@@ -1270,6 +1272,41 @@ function NumberInputEntry(props) {
1270
1272
  });
1271
1273
  }
1272
1274
 
1275
+ function SelectEntry(props) {
1276
+ const {
1277
+ editField,
1278
+ field,
1279
+ id,
1280
+ description,
1281
+ label,
1282
+ options,
1283
+ path
1284
+ } = props;
1285
+
1286
+ const onChange = value => {
1287
+ if (editField && path) {
1288
+ editField(field, path, value);
1289
+ } else {
1290
+ props.onChange(value);
1291
+ }
1292
+ };
1293
+
1294
+ const value = path ? minDash.get(field, path, '') : props.value;
1295
+ return jsxRuntime.jsxs("div", {
1296
+ class: "fjs-properties-panel-entry",
1297
+ children: [jsxRuntime.jsx(Select, {
1298
+ id: id,
1299
+ label: label,
1300
+ onChange: onChange,
1301
+ options: options,
1302
+ value: value
1303
+ }), description && jsxRuntime.jsx("div", {
1304
+ class: "fjs-properties-panel-description",
1305
+ children: description
1306
+ })]
1307
+ });
1308
+ }
1309
+
1273
1310
  function TextareaEntry(props) {
1274
1311
  const {
1275
1312
  editField,
@@ -1480,12 +1517,6 @@ function ActionEntry(props) {
1480
1517
  editField,
1481
1518
  field
1482
1519
  } = props;
1483
-
1484
- const onChange = value => {
1485
- editField(field, 'action', value);
1486
- };
1487
-
1488
- const value = field.action;
1489
1520
  const options = [{
1490
1521
  label: 'Submit',
1491
1522
  value: 'submit'
@@ -1493,15 +1524,13 @@ function ActionEntry(props) {
1493
1524
  label: 'Reset',
1494
1525
  value: 'reset'
1495
1526
  }];
1496
- return jsxRuntime.jsx("div", {
1497
- class: "fjs-properties-panel-entry",
1498
- children: jsxRuntime.jsx(Select, {
1499
- id: "action",
1500
- label: "Action",
1501
- options: options,
1502
- onChange: onChange,
1503
- value: value
1504
- })
1527
+ return jsxRuntime.jsx(SelectEntry, {
1528
+ editField: editField,
1529
+ field: field,
1530
+ id: "action",
1531
+ label: "Action",
1532
+ options: options,
1533
+ path: ['action']
1505
1534
  });
1506
1535
  }
1507
1536
 
@@ -1555,6 +1584,94 @@ function DescriptionEntry(props) {
1555
1584
  });
1556
1585
  }
1557
1586
 
1587
+ function DefaultValueEntry(props) {
1588
+ const {
1589
+ editField,
1590
+ field
1591
+ } = props;
1592
+ const {
1593
+ defaultValue,
1594
+ type,
1595
+ values = []
1596
+ } = field;
1597
+
1598
+ if (type === 'checkbox') {
1599
+ const options = [{
1600
+ label: 'Checked',
1601
+ value: 'true'
1602
+ }, {
1603
+ label: 'Not checked',
1604
+ value: 'false'
1605
+ }];
1606
+
1607
+ const onChange = value => {
1608
+ editField(field, ['defaultValue'], parseStringToBoolean(value));
1609
+ };
1610
+
1611
+ return jsxRuntime.jsx(SelectEntry, {
1612
+ id: "defaultValue",
1613
+ label: "Default Value",
1614
+ onChange: onChange,
1615
+ options: options,
1616
+ value: parseBooleanToString(defaultValue)
1617
+ });
1618
+ }
1619
+
1620
+ if (type === 'number') {
1621
+ return jsxRuntime.jsx(NumberInputEntry, {
1622
+ editField: editField,
1623
+ field: field,
1624
+ id: "defaultValue",
1625
+ label: "Default Value",
1626
+ path: ['defaultValue']
1627
+ });
1628
+ }
1629
+
1630
+ if (type === 'radio' || type === 'select') {
1631
+ const options = [{
1632
+ label: '<none>'
1633
+ }, ...values];
1634
+
1635
+ const onChange = value => {
1636
+ editField(field, ['defaultValue'], value.length ? value : undefined);
1637
+ };
1638
+
1639
+ return jsxRuntime.jsx(SelectEntry, {
1640
+ id: "defaultValue",
1641
+ label: "Default Value",
1642
+ onChange: onChange,
1643
+ options: options,
1644
+ value: defaultValue
1645
+ });
1646
+ }
1647
+
1648
+ if (type === 'textfield') {
1649
+ return jsxRuntime.jsx(TextInputEntry, {
1650
+ editField: editField,
1651
+ field: field,
1652
+ id: "defaultValue",
1653
+ label: "Default Value",
1654
+ path: ['defaultValue']
1655
+ });
1656
+ }
1657
+ }
1658
+
1659
+ function parseStringToBoolean(value) {
1660
+ if (value === 'true') {
1661
+ return true;
1662
+ }
1663
+
1664
+ return false;
1665
+ }
1666
+
1667
+ function parseBooleanToString(value) {
1668
+ if (value === true) {
1669
+ return 'true';
1670
+ }
1671
+
1672
+ return 'false';
1673
+ }
1674
+
1558
1675
  function DisabledEntry(props) {
1559
1676
  const {
1560
1677
  editField,
@@ -1698,9 +1815,18 @@ function ValueEntry(props) {
1698
1815
  const {
1699
1816
  editField,
1700
1817
  field,
1701
- index
1818
+ index,
1819
+ validate
1702
1820
  } = props;
1703
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
+
1704
1830
  const onChange = key => {
1705
1831
  const values = minDash.get(field, ['values']);
1706
1832
  return value => {
@@ -1713,14 +1839,93 @@ function ValueEntry(props) {
1713
1839
  id: `value-label-${index}`,
1714
1840
  label: "Label",
1715
1841
  onChange: onChange('label'),
1716
- value: minDash.get(field, ['values', index, 'label'])
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())
1717
1887
  }), jsxRuntime.jsx(TextInputEntry, {
1718
1888
  id: `value-value-${index}`,
1719
1889
  label: "Value",
1720
1890
  onChange: onChange('value'),
1721
- value: minDash.get(field, ['values', index, 'value'])
1891
+ value: getValue()
1722
1892
  })]
1723
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
+ }, {});
1724
1929
  }
1725
1930
 
1726
1931
  function GeneralGroup(field, editField) {
@@ -1757,6 +1962,13 @@ function GeneralGroup(field, editField) {
1757
1962
  }));
1758
1963
  }
1759
1964
 
1965
+ if (INPUTS.includes(type)) {
1966
+ entries.push(jsxRuntime.jsx(DefaultValueEntry, {
1967
+ editField: editField,
1968
+ field: field
1969
+ }));
1970
+ }
1971
+
1760
1972
  if (type === 'button') {
1761
1973
  entries.push(jsxRuntime.jsx(ActionEntry, {
1762
1974
  editField: editField,
@@ -1858,13 +2070,32 @@ function ValuesGroup(field, editField) {
1858
2070
  } = field;
1859
2071
 
1860
2072
  const addEntry = () => {
2073
+ const index = values.length + 1;
1861
2074
  const entry = {
1862
- label: 'Value',
1863
- value: 'value'
2075
+ label: `Value ${index}`,
2076
+ value: `value${index}`
1864
2077
  };
1865
2078
  editField(field, ['values'], arrayAdd$1(values, values.length, entry));
1866
2079
  };
1867
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
+
1868
2099
  const hasEntries = values.length > 0;
1869
2100
  return jsxRuntime.jsx(Group, {
1870
2101
  label: "Values",
@@ -1885,11 +2116,90 @@ function ValuesGroup(field, editField) {
1885
2116
  children: jsxRuntime.jsx(ValueEntry, {
1886
2117
  editField: editField,
1887
2118
  field: field,
1888
- index: index
2119
+ index: index,
2120
+ validate: validateFactory
2121
+ })
2122
+ }, `${id}-${index}`);
2123
+ })
2124
+ });
2125
+ }
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
1889
2176
  })
1890
- }, `${id}-${value.value}`);
2177
+ }, `${id}-${index}`);
1891
2178
  })
1892
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
+ }, {});
1893
2203
  }
1894
2204
 
1895
2205
  const labelsByType = {
@@ -1918,6 +2228,10 @@ function getGroups(field, editField) {
1918
2228
  groups.push(ValidationGroup(field, editField));
1919
2229
  }
1920
2230
 
2231
+ if (type !== 'default') {
2232
+ groups.push(CustomValuesGroup(field, editField));
2233
+ }
2234
+
1921
2235
  return groups;
1922
2236
  }
1923
2237
 
@@ -2208,8 +2522,9 @@ function FormEditor$1(props) {
2208
2522
  }
2209
2523
 
2210
2524
  return injector.get(type, strict);
2211
- }
2525
+ },
2212
2526
 
2527
+ formId: formEditor._id
2213
2528
  };
2214
2529
  const onSubmit = hooks$1.useCallback(() => {}, []);
2215
2530
  const onReset = hooks$1.useCallback(() => {}, []);
@@ -2685,6 +3000,7 @@ function isShift(event) {
2685
3000
 
2686
3001
  var KEYDOWN_EVENT = 'keyboard.keydown',
2687
3002
  KEYUP_EVENT = 'keyboard.keyup';
3003
+ var HANDLE_MODIFIER_ATTRIBUTE = 'input-handle-modified-keys';
2688
3004
  var DEFAULT_PRIORITY$1 = 1000;
2689
3005
  /**
2690
3006
  * A keyboard abstraction that may be activated and
@@ -2763,7 +3079,27 @@ Keyboard.prototype._keyHandler = function (event, type) {
2763
3079
  };
2764
3080
 
2765
3081
  Keyboard.prototype._isEventIgnored = function (event) {
2766
- return isInput(event.target) && !isCmd(event);
3082
+ return isInput(event.target) && this._isModifiedKeyIgnored(event);
3083
+ };
3084
+
3085
+ Keyboard.prototype._isModifiedKeyIgnored = function (event) {
3086
+ if (!isCmd(event)) {
3087
+ return true;
3088
+ }
3089
+
3090
+ var allowedModifiers = this._getAllowedModifiers(event.target);
3091
+
3092
+ return !allowedModifiers.includes(event.key);
3093
+ };
3094
+
3095
+ Keyboard.prototype._getAllowedModifiers = function (element) {
3096
+ var modifierContainer = minDom.closest(element, '[' + HANDLE_MODIFIER_ATTRIBUTE + ']', true);
3097
+
3098
+ if (!modifierContainer || this._node && !this._node.contains(modifierContainer)) {
3099
+ return [];
3100
+ }
3101
+
3102
+ return modifierContainer.getAttribute(HANDLE_MODIFIER_ATTRIBUTE).split(',');
2767
3103
  };
2768
3104
 
2769
3105
  Keyboard.prototype.bind = function (node) {
@@ -4316,6 +4652,7 @@ var SelectionModule = {
4316
4652
  selectionBehavior: ['type', SelectionBehavior]
4317
4653
  };
4318
4654
 
4655
+ const ids = new Ids__default['default']([32, 36, 1]);
4319
4656
  /**
4320
4657
  * @typedef { import('./types').Injector } Injector
4321
4658
  * @typedef { import('./types').Module } Module
@@ -4340,11 +4677,20 @@ class FormEditor {
4340
4677
  * @param {FormEditorOptions} options
4341
4678
  */
4342
4679
  constructor(options = {}) {
4680
+ /**
4681
+ * @public
4682
+ * @type {String}
4683
+ */
4684
+ this._id = ids.next();
4343
4685
  /**
4344
4686
  * @private
4345
4687
  * @type {Element}
4346
4688
  */
4689
+
4347
4690
  this._container = formJsViewer.createFormContainer();
4691
+
4692
+ this._container.setAttribute('input-handle-modified-keys', 'z,y');
4693
+
4348
4694
  const {
4349
4695
  container,
4350
4696
  exporter,
@@ -4603,10 +4949,9 @@ function exportSchema(schema, exporter, schemaVersion) {
4603
4949
 
4604
4950
  return value;
4605
4951
  });
4606
- return {
4607
- schemaVersion,
4952
+ return { ...cleanedSchema,
4608
4953
  ...exportDetails,
4609
- ...cleanedSchema
4954
+ schemaVersion
4610
4955
  };
4611
4956
  }
4612
4957