@bpmn-io/form-js-editor 1.10.0 → 1.10.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/README.md CHANGED
@@ -14,6 +14,7 @@ npm install @bpmn-io/form-js-editor
14
14
  import { FormEditor } from '@bpmn-io/form-js-editor';
15
15
 
16
16
  const schema = {
17
+ type: 'default',
17
18
  components: [
18
19
  {
19
20
  key: 'creditor',
@@ -1986,6 +1986,12 @@ textarea.bio-properties-panel-input {
1986
1986
  white-space: pre-wrap;
1987
1987
  }
1988
1988
 
1989
+ .bio-properties-panel-tooltip-content h1 {
1990
+ font-size: var(--text-size-base);
1991
+ font-weight: bold;
1992
+ margin: 0;
1993
+ }
1994
+
1989
1995
  .bio-properties-panel-tooltip-content code,
1990
1996
  .bio-properties-panel-tooltip-content pre {
1991
1997
  color: var(--description-color);
@@ -1183,6 +1183,12 @@ textarea.bio-properties-panel-input {
1183
1183
  white-space: pre-wrap;
1184
1184
  }
1185
1185
 
1186
+ .bio-properties-panel-tooltip-content h1 {
1187
+ font-size: var(--text-size-base);
1188
+ font-weight: bold;
1189
+ margin: 0;
1190
+ }
1191
+
1186
1192
  .bio-properties-panel-tooltip-content code,
1187
1193
  .bio-properties-panel-tooltip-content pre {
1188
1194
  color: var(--description-color);
package/dist/index.cjs CHANGED
@@ -877,7 +877,7 @@ function useDebounce(fn) {
877
877
  }
878
878
 
879
879
  var _path$5;
880
- function _extends$5() { _extends$5 = Object.assign ? Object.assign.bind() : 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$5.apply(this, arguments); }
880
+ function _extends$5() { return _extends$5 = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends$5.apply(null, arguments); }
881
881
  var SvgClose = function SvgClose(props) {
882
882
  return /*#__PURE__*/React__namespace.createElement("svg", _extends$5({
883
883
  xmlns: "http://www.w3.org/2000/svg",
@@ -892,7 +892,7 @@ var SvgClose = function SvgClose(props) {
892
892
  };
893
893
 
894
894
  var _path$4, _path2$1;
895
- function _extends$4() { _extends$4 = Object.assign ? Object.assign.bind() : 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$4.apply(this, arguments); }
895
+ function _extends$4() { return _extends$4 = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends$4.apply(null, arguments); }
896
896
  var SvgDelete = function SvgDelete(props) {
897
897
  return /*#__PURE__*/React__namespace.createElement("svg", _extends$4({
898
898
  xmlns: "http://www.w3.org/2000/svg",
@@ -925,7 +925,7 @@ var SvgDelete = function SvgDelete(props) {
925
925
  };
926
926
 
927
927
  var _path$3;
928
- function _extends$3() { _extends$3 = Object.assign ? Object.assign.bind() : 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$3.apply(this, arguments); }
928
+ function _extends$3() { return _extends$3 = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends$3.apply(null, arguments); }
929
929
  var SvgDraggable = function SvgDraggable(props) {
930
930
  return /*#__PURE__*/React__namespace.createElement("svg", _extends$3({
931
931
  xmlns: "http://www.w3.org/2000/svg",
@@ -945,7 +945,7 @@ var SvgDraggable = function SvgDraggable(props) {
945
945
  };
946
946
 
947
947
  var _path$2;
948
- function _extends$2() { _extends$2 = Object.assign ? Object.assign.bind() : 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$2.apply(this, arguments); }
948
+ function _extends$2() { return _extends$2 = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends$2.apply(null, arguments); }
949
949
  var SvgSearch = function SvgSearch(props) {
950
950
  return /*#__PURE__*/React__namespace.createElement("svg", _extends$2({
951
951
  xmlns: "http://www.w3.org/2000/svg",
@@ -959,7 +959,7 @@ var SvgSearch = function SvgSearch(props) {
959
959
  };
960
960
 
961
961
  var _path$1, _rect, _mask, _path2, _path3, _path4, _path5, _path6;
962
- function _extends$1() { _extends$1 = Object.assign ? Object.assign.bind() : 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$1.apply(this, arguments); }
962
+ function _extends$1() { return _extends$1 = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends$1.apply(null, arguments); }
963
963
  var SvgEmptyForm = function SvgEmptyForm(props) {
964
964
  return /*#__PURE__*/React__namespace.createElement("svg", _extends$1({
965
965
  xmlns: "http://www.w3.org/2000/svg",
@@ -4691,7 +4691,7 @@ class MoveFormFieldHandler {
4691
4691
  updateRow(formField, targetRow ? targetRow.id : this._formLayouter.nextRowId());
4692
4692
 
4693
4693
  // (2) Move form field
4694
- arrayMove.mutate(minDash.get(schema, sourcePath), sourceIndex, targetIndex);
4694
+ arrayMove.arrayMoveMutable(minDash.get(schema, sourcePath), sourceIndex, targetIndex);
4695
4695
 
4696
4696
  // (3) Update internal paths of new form field and its siblings (and their children)
4697
4697
  minDash.get(schema, sourcePath).forEach((formField, index) => updatePath(this._formFieldRegistry, formField, index));
@@ -5893,6 +5893,23 @@ function useStaticCallback(callback) {
5893
5893
  callbackRef.current = callback;
5894
5894
  return hooks.useCallback((...args) => callbackRef.current(...args), []);
5895
5895
  }
5896
+ function useElementVisible(element) {
5897
+ const [visible, setVisible] = hooks.useState(!!element && !!element.clientHeight);
5898
+ hooks.useLayoutEffect(() => {
5899
+ if (!element) return;
5900
+ const resizeObserver = new ResizeObserver(([entry]) => {
5901
+ requestAnimationFrame(() => {
5902
+ const newVisible = !!entry.contentRect.height;
5903
+ if (newVisible !== visible) {
5904
+ setVisible(newVisible);
5905
+ }
5906
+ });
5907
+ });
5908
+ resizeObserver.observe(element);
5909
+ return () => resizeObserver.disconnect();
5910
+ }, [element, visible]);
5911
+ return visible;
5912
+ }
5896
5913
  function Group(props) {
5897
5914
  const {
5898
5915
  element,
@@ -8080,6 +8097,28 @@ function useUpdateLayoutEffect(effect, deps) {
8080
8097
  }
8081
8098
  }, deps);
8082
8099
  }
8100
+
8101
+ /**
8102
+ * @typedef { {
8103
+ * [key: string]: string;
8104
+ * } } TranslateReplacements
8105
+ */
8106
+
8107
+ /**
8108
+ * A simple translation stub to be used for multi-language support.
8109
+ * Can be easily replaced with a more sophisticated solution.
8110
+ *
8111
+ * @param {string} template to interpolate
8112
+ * @param {TranslateReplacements} [replacements] a map with substitutes
8113
+ *
8114
+ * @return {string} the translated string
8115
+ */
8116
+ function translateFallback(template, replacements) {
8117
+ replacements = replacements || {};
8118
+ return template.replace(/{([^}]+)}/g, function (_, key) {
8119
+ return replacements[key] || '{' + key + '}';
8120
+ });
8121
+ }
8083
8122
  function CollapsibleEntry(props) {
8084
8123
  const {
8085
8124
  element,
@@ -8087,7 +8126,8 @@ function CollapsibleEntry(props) {
8087
8126
  id,
8088
8127
  label,
8089
8128
  open: shouldOpen,
8090
- remove
8129
+ remove,
8130
+ translate = translateFallback
8091
8131
  } = props;
8092
8132
  const [open, setOpen] = hooks.useState(shouldOpen);
8093
8133
  const toggleOpen = () => setOpen(!open);
@@ -8103,9 +8143,7 @@ function CollapsibleEntry(props) {
8103
8143
  }
8104
8144
  }, [onShow, setOpen])
8105
8145
  };
8106
-
8107
- // todo(pinussilvestrus): translate once we have a translate mechanism for the core
8108
- const placeholderLabel = '<empty>';
8146
+ const placeholderLabel = translate('<empty>');
8109
8147
  return jsxRuntime.jsxs("div", {
8110
8148
  "data-entry-id": id,
8111
8149
  class: classnames('bio-properties-panel-collapsible-entry', open ? 'open' : ''),
@@ -8118,14 +8156,14 @@ function CollapsibleEntry(props) {
8118
8156
  children: label || placeholderLabel
8119
8157
  }), jsxRuntime.jsx("button", {
8120
8158
  type: "button",
8121
- title: "Toggle list item",
8159
+ title: translate('Toggle list item'),
8122
8160
  class: "bio-properties-panel-arrow bio-properties-panel-collapsible-entry-arrow",
8123
8161
  children: jsxRuntime.jsx(ArrowIcon, {
8124
8162
  class: open ? 'bio-properties-panel-arrow-down' : 'bio-properties-panel-arrow-right'
8125
8163
  })
8126
8164
  }), remove ? jsxRuntime.jsx("button", {
8127
8165
  type: "button",
8128
- title: "Delete item",
8166
+ title: translate('Delete item'),
8129
8167
  class: "bio-properties-panel-remove-entry",
8130
8168
  onClick: remove,
8131
8169
  children: jsxRuntime.jsx(DeleteIcon, {})
@@ -8152,7 +8190,8 @@ function CollapsibleEntry(props) {
8152
8190
  function ListItem(props) {
8153
8191
  const {
8154
8192
  autoFocusEntry,
8155
- autoOpen
8193
+ autoOpen,
8194
+ translate = translateFallback
8156
8195
  } = props;
8157
8196
 
8158
8197
  // focus specified entry on auto open
@@ -8174,7 +8213,8 @@ function ListItem(props) {
8174
8213
  class: "bio-properties-panel-list-item",
8175
8214
  children: jsxRuntime.jsx(CollapsibleEntry, {
8176
8215
  ...props,
8177
- open: autoOpen
8216
+ open: autoOpen,
8217
+ translate: translate
8178
8218
  })
8179
8219
  });
8180
8220
  }
@@ -8190,7 +8230,8 @@ function ListGroup(props) {
8190
8230
  id,
8191
8231
  items,
8192
8232
  label,
8193
- shouldOpen = true
8233
+ shouldOpen = false,
8234
+ translate = translateFallback
8194
8235
  } = props;
8195
8236
  hooks.useEffect(() => {
8196
8237
  if (props.shouldSort != undefined) {
@@ -8198,57 +8239,25 @@ function ListGroup(props) {
8198
8239
  }
8199
8240
  }, [props.shouldSort]);
8200
8241
  const groupRef = hooks.useRef(null);
8201
- const [open, setOpen] = useLayoutState(['groups', id, 'open'], false);
8242
+ const [open, setOpen] = useLayoutState(['groups', id, 'open'], shouldOpen);
8202
8243
  const [sticky, setSticky] = hooks.useState(false);
8203
8244
  const onShow = hooks.useCallback(() => setOpen(true), [setOpen]);
8204
8245
  const [localItems, setLocalItems] = hooks.useState([]);
8205
- const [newlyAddedItemIds, setNewlyAddedItemIds] = hooks.useState([]);
8206
8246
 
8207
8247
  // Flag to mark that add button was clicked in the last render cycle
8208
8248
  const [addTriggered, setAddTriggered] = hooks.useState(false);
8209
8249
  const prevElement = usePrevious(element);
8210
- const elementChanged = element !== prevElement;
8211
- const shouldHandleEffects = !elementChanged && shouldOpen;
8212
-
8213
- // (0) delay setting items
8214
- //
8215
- // We need to this to align the render cycles of items
8216
- // with the detection of newly added items.
8217
- // This is important, because the autoOpen property can
8218
- // only set per list item on its very first render.
8219
- hooks.useEffect(() => {
8220
- setLocalItems(items);
8221
- }, [items]);
8250
+ const toggleOpen = hooks.useCallback(() => setOpen(!open), [open]);
8251
+ const openItemIds = element === prevElement && open && addTriggered ? getNewItemIds(items, localItems) : [];
8222
8252
 
8223
- // (1) handle auto opening when items were added
8253
+ // reset local state after items changed
8224
8254
  hooks.useEffect(() => {
8225
- // reset addTriggered flag
8255
+ setLocalItems(items);
8226
8256
  setAddTriggered(false);
8227
- if (shouldHandleEffects && localItems) {
8228
- if (addTriggered) {
8229
- const previousItemIds = localItems.map(item => item.id);
8230
- const currentItemsIds = items.map(item => item.id);
8231
- const newItemIds = currentItemsIds.filter(itemId => !previousItemIds.includes(itemId));
8232
-
8233
- // open if not open, configured and triggered by add button
8234
- //
8235
- // TODO(marstamm): remove once we refactor layout handling for listGroups.
8236
- // Ideally, opening should be handled as part of the `add` callback and
8237
- // not be a concern for the ListGroup component.
8238
- if (!open && shouldOpen && newItemIds.length > 0) {
8239
- toggleOpen();
8240
- }
8241
- setNewlyAddedItemIds(newItemIds);
8242
- } else {
8243
- // ignore newly added items that do not result from a triggered add
8244
- setNewlyAddedItemIds([]);
8245
- }
8246
- }
8247
- }, [items, open, shouldHandleEffects, addTriggered, localItems]);
8257
+ }, [items]);
8248
8258
 
8249
8259
  // set css class when group is sticky to top
8250
8260
  useStickyIntersectionObserver(groupRef, 'div.bio-properties-panel-scroll-container', setSticky);
8251
- const toggleOpen = () => setOpen(!open);
8252
8261
  const hasItems = !!items.length;
8253
8262
  const propertiesPanelContext = {
8254
8263
  ...hooks.useContext(LayoutContext),
@@ -8256,6 +8265,7 @@ function ListGroup(props) {
8256
8265
  };
8257
8266
  const handleAddClick = e => {
8258
8267
  setAddTriggered(true);
8268
+ setOpen(true);
8259
8269
  add(e);
8260
8270
  };
8261
8271
  const allErrors = useErrors();
@@ -8292,20 +8302,22 @@ function ListGroup(props) {
8292
8302
  class: "bio-properties-panel-group-header-buttons",
8293
8303
  children: [add ? jsxRuntime.jsxs("button", {
8294
8304
  type: "button",
8295
- title: "Create new list item",
8305
+ title: translate('Create new list item'),
8296
8306
  class: "bio-properties-panel-group-header-button bio-properties-panel-add-entry",
8297
8307
  onClick: handleAddClick,
8298
8308
  children: [jsxRuntime.jsx(CreateIcon, {}), !hasItems ? jsxRuntime.jsx("span", {
8299
8309
  class: "bio-properties-panel-add-entry-label",
8300
- children: "Create"
8310
+ children: translate('Create')
8301
8311
  }) : null]
8302
8312
  }) : null, hasItems ? jsxRuntime.jsx("div", {
8303
- title: `List contains ${items.length} item${items.length != 1 ? 's' : ''}`,
8313
+ title: translate(`List contains {numOfItems} item${items.length != 1 ? 's' : ''}`, {
8314
+ numOfItems: items.length
8315
+ }),
8304
8316
  class: classnames('bio-properties-panel-list-badge', hasError ? 'bio-properties-panel-list-badge--error' : ''),
8305
8317
  children: items.length
8306
8318
  }) : null, hasItems ? jsxRuntime.jsx("button", {
8307
8319
  type: "button",
8308
- title: "Toggle section",
8320
+ title: translate('Toggle section'),
8309
8321
  class: "bio-properties-panel-group-header-button bio-properties-panel-arrow",
8310
8322
  children: jsxRuntime.jsx(ArrowIcon, {
8311
8323
  class: open ? 'bio-properties-panel-arrow-down' : 'bio-properties-panel-arrow-right'
@@ -8316,7 +8328,7 @@ function ListGroup(props) {
8316
8328
  class: classnames('bio-properties-panel-list', open && hasItems ? 'open' : ''),
8317
8329
  children: jsxRuntime.jsx(LayoutContext.Provider, {
8318
8330
  value: propertiesPanelContext,
8319
- children: localItems.map((item, index) => {
8331
+ children: items.map((item, index) => {
8320
8332
  if (!item) {
8321
8333
  return;
8322
8334
  }
@@ -8325,20 +8337,27 @@ function ListGroup(props) {
8325
8337
  } = item;
8326
8338
 
8327
8339
  // if item was added, open it
8328
- // Existing items will not be affected as autoOpen is only applied on first render
8329
- const autoOpen = newlyAddedItemIds.includes(item.id);
8340
+ // existing items will not be affected as autoOpen
8341
+ // is only applied on first render
8342
+ const autoOpen = openItemIds.includes(item.id);
8330
8343
  return preact.createElement(ListItem, {
8331
8344
  ...item,
8332
8345
  autoOpen: autoOpen,
8333
8346
  element: element,
8334
8347
  index: index,
8335
- key: id
8348
+ key: id,
8349
+ translate: translate
8336
8350
  });
8337
8351
  })
8338
8352
  })
8339
8353
  })]
8340
8354
  });
8341
8355
  }
8356
+ function getNewItemIds(newItems, oldItems) {
8357
+ const newIds = newItems.map(item => item.id);
8358
+ const oldIds = oldItems.map(item => item.id);
8359
+ return newIds.filter(itemId => !oldIds.includes(itemId));
8360
+ }
8342
8361
  function Checkbox(props) {
8343
8362
  const {
8344
8363
  id,
@@ -8624,13 +8643,14 @@ function TextArea(props) {
8624
8643
  monospace,
8625
8644
  onFocus,
8626
8645
  onBlur,
8627
- autoResize,
8646
+ autoResize = true,
8628
8647
  placeholder,
8629
8648
  rows = autoResize ? 1 : 2,
8630
8649
  tooltip
8631
8650
  } = props;
8632
8651
  const [localValue, setLocalValue] = hooks.useState(value);
8633
8652
  const ref = useShowEntryEvent(id);
8653
+ const visible = useElementVisible(ref.current);
8634
8654
  const handleInputCallback = hooks.useMemo(() => {
8635
8655
  return debounce(target => onInput(target.value.length ? target.value : undefined));
8636
8656
  }, [onInput, debounce]);
@@ -8642,6 +8662,9 @@ function TextArea(props) {
8642
8662
  hooks.useLayoutEffect(() => {
8643
8663
  autoResize && resizeToContents(ref.current);
8644
8664
  }, []);
8665
+ hooks.useLayoutEffect(() => {
8666
+ visible && autoResize && resizeToContents(ref.current);
8667
+ }, [visible]);
8645
8668
  hooks.useEffect(() => {
8646
8669
  if (value === localValue) {
8647
8670
  return;
@@ -13356,7 +13379,7 @@ const RenderInjectionModule = {
13356
13379
  };
13357
13380
 
13358
13381
  var _path;
13359
- function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }
13382
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
13360
13383
  var SvgRepeat = function SvgRepeat(props) {
13361
13384
  return /*#__PURE__*/React__namespace.createElement("svg", _extends({
13362
13385
  xmlns: "http://www.w3.org/2000/svg",