@bpmn-io/form-js-editor 1.7.2 → 1.8.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.es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import Ids from 'ids';
2
- import { FormFieldRegistry as FormFieldRegistry$1, iconsByType, Label as Label$3, IFrame, Text as Text$1, Html, Table, FormFields, sanitizeImageSource, getAncestryList, FormContext, FormRenderContext, FormComponent, Importer, PathRegistry, FormLayouter, FieldFactory, FeelExpressionLanguage, OPTIONS_SOURCES, OPTIONS_SOURCES_PATHS, clone, runRecursively, getSchemaVariables, DATETIME_SUBTYPES, DATE_LABEL_PATH, TIME_LABEL_PATH, DATETIME_SUBTYPE_PATH, DATETIME_SUBTYPES_LABELS, TIME_SERIALISING_FORMAT_PATH, TIME_SERIALISING_FORMATS, TIME_INTERVAL_PATH, TIME_USE24H_PATH, DATE_DISALLOW_PAST_PATH, TIME_SERIALISINGFORMAT_LABELS, getOptionsSource, OPTIONS_SOURCES_DEFAULTS, OPTIONS_SOURCES_LABELS, SECURITY_ATTRIBUTES_DEFINITIONS, createFormContainer, createInjector, MarkdownRendererModule, schemaVersion } from '@bpmn-io/form-js-viewer';
2
+ import { FormFieldRegistry as FormFieldRegistry$1, iconsByType, Label as Label$3, IFrame, Text as Text$1, Html, Table, ExpressionField, FormFields, sanitizeImageSource, getAncestryList, FormContext, FormRenderContext, FormComponent, getScrollContainer, Importer, PathRegistry, FormLayouter, FieldFactory, FeelExpressionLanguage, OPTIONS_SOURCES, OPTIONS_SOURCES_PATHS, clone, runRecursively, getSchemaVariables, DATETIME_SUBTYPES, DATE_LABEL_PATH, TIME_LABEL_PATH, DATETIME_SUBTYPE_PATH, DATETIME_SUBTYPES_LABELS, TIME_SERIALISING_FORMAT_PATH, TIME_SERIALISING_FORMATS, TIME_INTERVAL_PATH, TIME_USE24H_PATH, DATE_DISALLOW_PAST_PATH, TIME_SERIALISINGFORMAT_LABELS, getOptionsSource, OPTIONS_SOURCES_DEFAULTS, OPTIONS_SOURCES_LABELS, SECURITY_ATTRIBUTES_DEFINITIONS, createFormContainer, createInjector, MarkdownRendererModule, schemaVersion } from '@bpmn-io/form-js-viewer';
3
3
  export { schemaVersion } from '@bpmn-io/form-js-viewer';
4
4
  import { isArray, isFunction, isNumber, bind, assign, debounce, forEach, isString, uniqueBy, isObject, get, isDefined, sortBy, find, set as set$1, reduce, without, isNil, has } from 'min-dash';
5
5
  import classnames from 'classnames';
@@ -1122,7 +1122,36 @@ function EditorTable(props) {
1122
1122
  }
1123
1123
  EditorTable.config = Table.config;
1124
1124
 
1125
- const editorFormFields = [EditorIFrame, EditorText, EditorHtml, EditorTable];
1125
+ const type = 'expression';
1126
+ function EditorExpressionField(props) {
1127
+ const {
1128
+ field
1129
+ } = props;
1130
+ const {
1131
+ expression = ''
1132
+ } = field;
1133
+ const Icon = iconsByType('expression');
1134
+ const expressionLanguage = useService$1('expressionLanguage');
1135
+ let placeholderContent = 'Expression is empty';
1136
+ if (expression.trim() && expressionLanguage.isExpression(expression)) {
1137
+ placeholderContent = 'Expression';
1138
+ }
1139
+ return jsx("div", {
1140
+ class: editorFormFieldClasses(type),
1141
+ children: jsxs("div", {
1142
+ class: "fjs-form-field-placeholder",
1143
+ children: [jsx(Icon, {
1144
+ viewBox: "0 0 54 54"
1145
+ }), placeholderContent]
1146
+ })
1147
+ });
1148
+ }
1149
+ EditorExpressionField.config = {
1150
+ ...ExpressionField.config,
1151
+ escapeGridRender: false
1152
+ };
1153
+
1154
+ const editorFormFields = [EditorIFrame, EditorText, EditorHtml, EditorTable, EditorExpressionField];
1126
1155
 
1127
1156
  class EditorFormFields extends FormFields {
1128
1157
  constructor() {
@@ -1417,7 +1446,7 @@ function getIndefiniteArticle(type) {
1417
1446
  }
1418
1447
 
1419
1448
  const PALETTE_GROUPS = [{
1420
- label: 'Basic input',
1449
+ label: 'Input',
1421
1450
  id: 'basic-input'
1422
1451
  }, {
1423
1452
  label: 'Selection',
@@ -2139,7 +2168,6 @@ function Empty(props) {
2139
2168
  }
2140
2169
  function Element$1(props) {
2141
2170
  const eventBus = useService$1('eventBus'),
2142
- formEditor = useService$1('formEditor'),
2143
2171
  formFieldRegistry = useService$1('formFieldRegistry'),
2144
2172
  formFields = useService$1('formFields'),
2145
2173
  modeling = useService$1('modeling'),
@@ -2161,18 +2189,24 @@ function Element$1(props) {
2161
2189
  function scrollIntoView({
2162
2190
  selection
2163
2191
  }) {
2164
- if (!selection || selection.id !== id || !ref.current) {
2192
+ const scrollContainer = getScrollContainer(ref.current);
2193
+ if (!selection || selection.type === 'default' || selection.id !== id || !scrollContainer || !ref.current) {
2165
2194
  return;
2166
2195
  }
2167
- const elementBounds = ref.current.getBoundingClientRect(),
2168
- containerBounds = formEditor._container.getBoundingClientRect();
2169
- if (elementBounds.top < 0 || elementBounds.top > containerBounds.bottom) {
2170
- ref.current.scrollIntoView();
2196
+ const elementBounds = ref.current.getBoundingClientRect();
2197
+ const scrollContainerBounds = scrollContainer.getBoundingClientRect();
2198
+ const isElementLarger = elementBounds.height > scrollContainerBounds.height;
2199
+ const isNotFullyVisible = elementBounds.bottom > scrollContainerBounds.bottom || elementBounds.top < scrollContainerBounds.top;
2200
+ if (isNotFullyVisible && !isElementLarger) {
2201
+ ref.current.scrollIntoView({
2202
+ behavior: 'auto',
2203
+ block: 'nearest'
2204
+ });
2171
2205
  }
2172
2206
  }
2173
2207
  eventBus.on('selection.changed', scrollIntoView);
2174
2208
  return () => eventBus.off('selection.changed', scrollIntoView);
2175
- }, [eventBus, formEditor._container, id]);
2209
+ }, [eventBus, id]);
2176
2210
  useLayoutEffect(() => {
2177
2211
  if (selection.isSelected(field)) {
2178
2212
  ref.current.focus();
@@ -2194,14 +2228,15 @@ function Element$1(props) {
2194
2228
  if (isSelected) {
2195
2229
  classes.push('fjs-editor-selected');
2196
2230
  }
2197
- if (showOutline) {
2198
- classes.push('fjs-outlined');
2231
+ const grouplike = ['group', 'dynamiclist'].includes(type);
2232
+ if (grouplike) {
2233
+ classes.push(showOutline ? 'fjs-outlined' : 'fjs-dashed-outlined');
2199
2234
  }
2200
2235
  if (hovered) {
2201
2236
  classes.push('fjs-editor-hovered');
2202
2237
  }
2203
2238
  return classes.join(' ');
2204
- }, [hovered, isSelected, props.class, showOutline]);
2239
+ }, [hovered, isSelected, props.class, showOutline, type]);
2205
2240
  const onRemove = event => {
2206
2241
  event.stopPropagation();
2207
2242
  const parentField = formFieldRegistry.get(field._parent);
@@ -5159,6 +5194,7 @@ class PaletteRenderer extends SectionModuleBase {
5159
5194
  PaletteRenderer.$inject = ['eventBus'];
5160
5195
 
5161
5196
  const PaletteModule = {
5197
+ __init__: ['palette'],
5162
5198
  palette: ['type', PaletteRenderer]
5163
5199
  };
5164
5200
 
@@ -8954,7 +8990,7 @@ function useVariables() {
8954
8990
  return getSchemaVariables(schema);
8955
8991
  }
8956
8992
 
8957
- const headerlessTypes = ['spacer', 'separator', 'html'];
8993
+ const headerlessTypes = ['spacer', 'separator', 'expression', 'html'];
8958
8994
  const PropertiesPanelHeaderProvider = {
8959
8995
  getElementLabel: field => {
8960
8996
  const {
@@ -10773,6 +10809,83 @@ const validateNumberEntries = value => {
10773
10809
  }
10774
10810
  };
10775
10811
 
10812
+ function ExpressionFieldEntries(props) {
10813
+ const {
10814
+ editField,
10815
+ field,
10816
+ id
10817
+ } = props;
10818
+ const entries = [];
10819
+ entries.push({
10820
+ id: `${id}-expression`,
10821
+ component: ExpressionFieldExpression,
10822
+ isEdited: isEdited$6,
10823
+ editField,
10824
+ field,
10825
+ isDefaultVisible: field => field.type === 'expression'
10826
+ });
10827
+ entries.push({
10828
+ id: `${id}-computeOn`,
10829
+ component: ExpressionFieldComputeOn,
10830
+ isEdited: isEdited$3,
10831
+ editField,
10832
+ field,
10833
+ isDefaultVisible: field => field.type === 'expression'
10834
+ });
10835
+ return entries;
10836
+ }
10837
+ function ExpressionFieldExpression(props) {
10838
+ const {
10839
+ editField,
10840
+ field,
10841
+ id
10842
+ } = props;
10843
+ const debounce = useService('debounce');
10844
+ const variables = useVariables().map(name => ({
10845
+ name
10846
+ }));
10847
+ const getValue = () => field.expression || '';
10848
+ const setValue = value => {
10849
+ editField(field, ['expression'], value);
10850
+ };
10851
+ return FeelEntry({
10852
+ debounce,
10853
+ description: 'Define an expression to calculate the value of this field',
10854
+ element: field,
10855
+ feel: 'required',
10856
+ getValue,
10857
+ id,
10858
+ label: 'Target value',
10859
+ setValue,
10860
+ variables
10861
+ });
10862
+ }
10863
+ function ExpressionFieldComputeOn(props) {
10864
+ const {
10865
+ editField,
10866
+ field,
10867
+ id
10868
+ } = props;
10869
+ const getValue = () => field.computeOn || '';
10870
+ const setValue = value => {
10871
+ editField(field, ['computeOn'], value);
10872
+ };
10873
+ const getOptions = () => [{
10874
+ value: 'change',
10875
+ label: 'Value changes'
10876
+ }, {
10877
+ value: 'presubmit',
10878
+ label: 'Form submission'
10879
+ }];
10880
+ return SelectEntry({
10881
+ id,
10882
+ label: 'Compute on',
10883
+ getValue,
10884
+ setValue,
10885
+ getOptions
10886
+ });
10887
+ }
10888
+
10776
10889
  function NumberSerializationEntry(props) {
10777
10890
  const {
10778
10891
  editField,
@@ -11733,14 +11846,22 @@ function Condition(props) {
11733
11846
  hide: value
11734
11847
  });
11735
11848
  };
11849
+ let label = 'Hide if';
11850
+ let description = 'Condition under which the field is hidden';
11851
+
11852
+ // special case for expression fields which do not render
11853
+ if (field.type === 'expression') {
11854
+ label = 'Deactivate if';
11855
+ description = 'Condition under which the field is deactivated';
11856
+ }
11736
11857
  return FeelEntry({
11737
11858
  debounce,
11738
- description: 'Condition under which the field is hidden',
11859
+ description,
11739
11860
  element: field,
11740
11861
  feel: 'required',
11741
11862
  getValue,
11742
11863
  id,
11743
- label: 'Hide if',
11864
+ label,
11744
11865
  setValue,
11745
11866
  variables
11746
11867
  });
@@ -12360,6 +12481,9 @@ function GeneralGroup(field, editField, getService) {
12360
12481
  }), ...NumberEntries({
12361
12482
  field,
12362
12483
  editField
12484
+ }), ...ExpressionFieldEntries({
12485
+ field,
12486
+ editField
12363
12487
  }), ...ImageSourceEntry({
12364
12488
  field,
12365
12489
  editField