@bpmn-io/form-js-editor 0.4.4 → 0.6.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/index.es.js CHANGED
@@ -1,3 +1,4 @@
1
+ import Ids from 'ids';
1
2
  import { isArray, isFunction, isNumber, bind, assign, debounce, get, isUndefined, set, forEach, isObject, uniqueBy, isString } from 'min-dash';
2
3
  import { FormFieldRegistry as FormFieldRegistry$1, clone, Default, FormContext, FormRenderContext, FormComponent, FormFields, createFormContainer, createInjector, schemaVersion } from '@bpmn-io/form-js-viewer';
3
4
  export { schemaVersion } from '@bpmn-io/form-js-viewer';
@@ -6,7 +7,7 @@ import { useContext, useRef, useEffect, useMemo, useState, useCallback } from 'p
6
7
  import React from 'preact/compat';
7
8
  import { jsxs, jsx, Fragment } from 'preact/jsx-runtime';
8
9
  import dragula from 'dragula';
9
- import { matches, event } from 'min-dom';
10
+ import { matches, closest, event } from 'min-dom';
10
11
  import { mutate } from 'array-move';
11
12
 
12
13
  var FN_REF = '__fn';
@@ -1006,7 +1007,7 @@ function CheckboxInput(props) {
1006
1007
  };
1007
1008
 
1008
1009
  return jsxs("div", {
1009
- class: "fjs-properties-panel-textfield",
1010
+ class: "fjs-properties-panel-checkbox",
1010
1011
  children: [jsx("label", {
1011
1012
  for: prefixId(id),
1012
1013
  class: "fjs-properties-panel-label",
@@ -1061,7 +1062,7 @@ function NumberInput(props) {
1061
1062
  }
1062
1063
  }, [_onInput]);
1063
1064
  return jsxs("div", {
1064
- class: "fjs-properties-panel-textfield",
1065
+ class: "fjs-properties-panel-number",
1065
1066
  children: [jsx("label", {
1066
1067
  for: prefixId(id),
1067
1068
  class: "fjs-properties-panel-label",
@@ -1094,7 +1095,7 @@ function Select(props) {
1094
1095
  };
1095
1096
 
1096
1097
  return jsxs("div", {
1097
- class: "fjs-properties-panel-textfield",
1098
+ class: "fjs-properties-panel-select",
1098
1099
  children: [jsx("label", {
1099
1100
  for: prefixId(id),
1100
1101
  class: "fjs-properties-panel-label",
@@ -1128,7 +1129,7 @@ function Textarea(props) {
1128
1129
  _onInput(value.length ? value : undefined);
1129
1130
  }, [_onInput]);
1130
1131
  return jsxs("div", {
1131
- class: "fjs-properties-panel-textfield",
1132
+ class: "fjs-properties-panel-textarea",
1132
1133
  children: [jsx("label", {
1133
1134
  for: prefixId(id),
1134
1135
  class: "fjs-properties-panel-label",
@@ -1180,7 +1181,7 @@ function TextInput(props) {
1180
1181
  }
1181
1182
 
1182
1183
  return jsxs("div", {
1183
- class: "fjs-properties-panel-textfield",
1184
+ class: "fjs-properties-panel-text",
1184
1185
  children: [jsx("label", {
1185
1186
  for: prefixId(id),
1186
1187
  class: "fjs-properties-panel-label",
@@ -1262,6 +1263,41 @@ function NumberInputEntry(props) {
1262
1263
  });
1263
1264
  }
1264
1265
 
1266
+ function SelectEntry(props) {
1267
+ const {
1268
+ editField,
1269
+ field,
1270
+ id,
1271
+ description,
1272
+ label,
1273
+ options,
1274
+ path
1275
+ } = props;
1276
+
1277
+ const onChange = value => {
1278
+ if (editField && path) {
1279
+ editField(field, path, value);
1280
+ } else {
1281
+ props.onChange(value);
1282
+ }
1283
+ };
1284
+
1285
+ const value = path ? get(field, path, '') : props.value;
1286
+ return jsxs("div", {
1287
+ class: "fjs-properties-panel-entry",
1288
+ children: [jsx(Select, {
1289
+ id: id,
1290
+ label: label,
1291
+ onChange: onChange,
1292
+ options: options,
1293
+ value: value
1294
+ }), description && jsx("div", {
1295
+ class: "fjs-properties-panel-description",
1296
+ children: description
1297
+ })]
1298
+ });
1299
+ }
1300
+
1265
1301
  function TextareaEntry(props) {
1266
1302
  const {
1267
1303
  editField,
@@ -1472,12 +1508,6 @@ function ActionEntry(props) {
1472
1508
  editField,
1473
1509
  field
1474
1510
  } = props;
1475
-
1476
- const onChange = value => {
1477
- editField(field, 'action', value);
1478
- };
1479
-
1480
- const value = field.action;
1481
1511
  const options = [{
1482
1512
  label: 'Submit',
1483
1513
  value: 'submit'
@@ -1485,15 +1515,13 @@ function ActionEntry(props) {
1485
1515
  label: 'Reset',
1486
1516
  value: 'reset'
1487
1517
  }];
1488
- return jsx("div", {
1489
- class: "fjs-properties-panel-entry",
1490
- children: jsx(Select, {
1491
- id: "action",
1492
- label: "Action",
1493
- options: options,
1494
- onChange: onChange,
1495
- value: value
1496
- })
1518
+ return jsx(SelectEntry, {
1519
+ editField: editField,
1520
+ field: field,
1521
+ id: "action",
1522
+ label: "Action",
1523
+ options: options,
1524
+ path: ['action']
1497
1525
  });
1498
1526
  }
1499
1527
 
@@ -1547,6 +1575,113 @@ function DescriptionEntry(props) {
1547
1575
  });
1548
1576
  }
1549
1577
 
1578
+ function DefaultValueEntry(props) {
1579
+ const {
1580
+ editField,
1581
+ field
1582
+ } = props;
1583
+ const {
1584
+ defaultValue,
1585
+ type,
1586
+ values = []
1587
+ } = field;
1588
+
1589
+ if (type === 'checkbox') {
1590
+ const options = [{
1591
+ label: 'Checked',
1592
+ value: 'true'
1593
+ }, {
1594
+ label: 'Not checked',
1595
+ value: 'false'
1596
+ }];
1597
+
1598
+ const onChange = value => {
1599
+ editField(field, ['defaultValue'], parseStringToBoolean(value));
1600
+ };
1601
+
1602
+ return jsx(SelectEntry, {
1603
+ id: "defaultValue",
1604
+ label: "Default Value",
1605
+ onChange: onChange,
1606
+ options: options,
1607
+ value: parseBooleanToString(defaultValue)
1608
+ });
1609
+ }
1610
+
1611
+ if (type === 'number') {
1612
+ return jsx(NumberInputEntry, {
1613
+ editField: editField,
1614
+ field: field,
1615
+ id: "defaultValue",
1616
+ label: "Default Value",
1617
+ path: ['defaultValue']
1618
+ });
1619
+ }
1620
+
1621
+ if (type === 'radio' || type === 'select') {
1622
+ const options = [{
1623
+ label: '<none>'
1624
+ }, ...values];
1625
+
1626
+ const onChange = value => {
1627
+ editField(field, ['defaultValue'], value.length ? value : undefined);
1628
+ };
1629
+
1630
+ return jsx(SelectEntry, {
1631
+ id: "defaultValue",
1632
+ label: "Default Value",
1633
+ onChange: onChange,
1634
+ options: options,
1635
+ value: defaultValue
1636
+ });
1637
+ }
1638
+
1639
+ if (type === 'textfield') {
1640
+ return jsx(TextInputEntry, {
1641
+ editField: editField,
1642
+ field: field,
1643
+ id: "defaultValue",
1644
+ label: "Default Value",
1645
+ path: ['defaultValue']
1646
+ });
1647
+ }
1648
+ }
1649
+
1650
+ function parseStringToBoolean(value) {
1651
+ if (value === 'true') {
1652
+ return true;
1653
+ }
1654
+
1655
+ return false;
1656
+ }
1657
+
1658
+ function parseBooleanToString(value) {
1659
+ if (value === true) {
1660
+ return 'true';
1661
+ }
1662
+
1663
+ return 'false';
1664
+ }
1665
+
1666
+ function DisabledEntry(props) {
1667
+ const {
1668
+ editField,
1669
+ field
1670
+ } = props;
1671
+
1672
+ const onChange = value => {
1673
+ editField(field, 'disabled', value);
1674
+ };
1675
+
1676
+ return jsx(CheckboxInputEntry, {
1677
+ id: "disabled",
1678
+ field: field,
1679
+ label: "Disabled",
1680
+ path: ['disabled'],
1681
+ onChange: onChange
1682
+ });
1683
+ }
1684
+
1550
1685
  function IdEntry(props) {
1551
1686
  const {
1552
1687
  editField,
@@ -1730,6 +1865,13 @@ function GeneralGroup(field, editField) {
1730
1865
  }));
1731
1866
  }
1732
1867
 
1868
+ if (INPUTS.includes(type)) {
1869
+ entries.push(jsx(DefaultValueEntry, {
1870
+ editField: editField,
1871
+ field: field
1872
+ }));
1873
+ }
1874
+
1733
1875
  if (type === 'button') {
1734
1876
  entries.push(jsx(ActionEntry, {
1735
1877
  editField: editField,
@@ -1751,6 +1893,13 @@ function GeneralGroup(field, editField) {
1751
1893
  }));
1752
1894
  }
1753
1895
 
1896
+ if (INPUTS.includes(type)) {
1897
+ entries.push(jsx(DisabledEntry, {
1898
+ editField: editField,
1899
+ field: field
1900
+ }));
1901
+ }
1902
+
1754
1903
  return jsx(Group, {
1755
1904
  label: "General",
1756
1905
  children: entries.length ? entries : null
@@ -1853,7 +2002,7 @@ function ValuesGroup(field, editField) {
1853
2002
  field: field,
1854
2003
  index: index
1855
2004
  })
1856
- }, `${id}-${value.value}`);
2005
+ }, `${id}-${index}`);
1857
2006
  })
1858
2007
  });
1859
2008
  }
@@ -1892,6 +2041,7 @@ function PropertiesPanel(props) {
1892
2041
  editField,
1893
2042
  field
1894
2043
  } = props;
2044
+ const eventBus = useService('eventBus');
1895
2045
 
1896
2046
  if (!field) {
1897
2047
  return jsx("div", {
@@ -1900,8 +2050,6 @@ function PropertiesPanel(props) {
1900
2050
  });
1901
2051
  }
1902
2052
 
1903
- const eventBus = useService('eventBus');
1904
-
1905
2053
  const onFocus = () => eventBus.fire('propertiesPanel.focusin');
1906
2054
 
1907
2055
  const onBlur = () => eventBus.fire('propertiesPanel.focusout');
@@ -2175,8 +2323,9 @@ function FormEditor$1(props) {
2175
2323
  }
2176
2324
 
2177
2325
  return injector.get(type, strict);
2178
- }
2326
+ },
2179
2327
 
2328
+ formId: formEditor._id
2180
2329
  };
2181
2330
  const onSubmit = useCallback(() => {}, []);
2182
2331
  const onReset = useCallback(() => {}, []);
@@ -2652,6 +2801,7 @@ function isShift(event) {
2652
2801
 
2653
2802
  var KEYDOWN_EVENT = 'keyboard.keydown',
2654
2803
  KEYUP_EVENT = 'keyboard.keyup';
2804
+ var HANDLE_MODIFIER_ATTRIBUTE = 'input-handle-modified-keys';
2655
2805
  var DEFAULT_PRIORITY$1 = 1000;
2656
2806
  /**
2657
2807
  * A keyboard abstraction that may be activated and
@@ -2730,7 +2880,27 @@ Keyboard.prototype._keyHandler = function (event, type) {
2730
2880
  };
2731
2881
 
2732
2882
  Keyboard.prototype._isEventIgnored = function (event) {
2733
- return isInput(event.target) && !isCmd(event);
2883
+ return isInput(event.target) && this._isModifiedKeyIgnored(event);
2884
+ };
2885
+
2886
+ Keyboard.prototype._isModifiedKeyIgnored = function (event) {
2887
+ if (!isCmd(event)) {
2888
+ return true;
2889
+ }
2890
+
2891
+ var allowedModifiers = this._getAllowedModifiers(event.target);
2892
+
2893
+ return !allowedModifiers.includes(event.key);
2894
+ };
2895
+
2896
+ Keyboard.prototype._getAllowedModifiers = function (element) {
2897
+ var modifierContainer = closest(element, '[' + HANDLE_MODIFIER_ATTRIBUTE + ']', true);
2898
+
2899
+ if (!modifierContainer || this._node && !this._node.contains(modifierContainer)) {
2900
+ return [];
2901
+ }
2902
+
2903
+ return modifierContainer.getAttribute(HANDLE_MODIFIER_ATTRIBUTE).split(',');
2734
2904
  };
2735
2905
 
2736
2906
  Keyboard.prototype.bind = function (node) {
@@ -4283,6 +4453,7 @@ var SelectionModule = {
4283
4453
  selectionBehavior: ['type', SelectionBehavior]
4284
4454
  };
4285
4455
 
4456
+ const ids = new Ids([32, 36, 1]);
4286
4457
  /**
4287
4458
  * @typedef { import('./types').Injector } Injector
4288
4459
  * @typedef { import('./types').Module } Module
@@ -4307,11 +4478,20 @@ class FormEditor {
4307
4478
  * @param {FormEditorOptions} options
4308
4479
  */
4309
4480
  constructor(options = {}) {
4481
+ /**
4482
+ * @public
4483
+ * @type {String}
4484
+ */
4485
+ this._id = ids.next();
4310
4486
  /**
4311
4487
  * @private
4312
4488
  * @type {Element}
4313
4489
  */
4490
+
4314
4491
  this._container = createFormContainer();
4492
+
4493
+ this._container.setAttribute('input-handle-modified-keys', 'z,y');
4494
+
4315
4495
  const {
4316
4496
  container,
4317
4497
  exporter,
@@ -4570,10 +4750,9 @@ function exportSchema(schema, exporter, schemaVersion) {
4570
4750
 
4571
4751
  return value;
4572
4752
  });
4573
- return {
4574
- schemaVersion,
4753
+ return { ...cleanedSchema,
4575
4754
  ...exportDetails,
4576
- ...cleanedSchema
4755
+ schemaVersion
4577
4756
  };
4578
4757
  }
4579
4758