@bpmn-io/form-js-viewer 1.8.1 → 1.8.3

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
@@ -8,7 +8,7 @@ import { createContext, createElement, Fragment as Fragment$1, render } from 'pr
8
8
  import isEqual from 'lodash/isEqual';
9
9
  import flatpickr from 'flatpickr';
10
10
  import * as React from 'preact/compat';
11
- import { useEffect as useEffect$1, createPortal } from 'preact/compat';
11
+ import { createPortal } from 'preact/compat';
12
12
  import DOMPurify from 'dompurify';
13
13
  import { Injector } from 'didi';
14
14
  import { parseExpression, parseUnaryTests, evaluate, unaryTest } from 'feelin';
@@ -1300,17 +1300,6 @@ function useFlushDebounce(func) {
1300
1300
  return [debounceFunc, flushFunc];
1301
1301
  }
1302
1302
 
1303
- function useEffectOnChange(value, callback, dependencies = []) {
1304
- const previousValue = usePrevious(value);
1305
- useEffect$1(() => {
1306
- if (value !== previousValue) {
1307
- callback();
1308
- }
1309
-
1310
- // eslint-disable-next-line react-hooks/exhaustive-deps
1311
- }, [value, ...dependencies]);
1312
- }
1313
-
1314
1303
  /**
1315
1304
  * Template a string reactively based on form data. If the string is not a template, it is returned as is.
1316
1305
  * Memoised to minimize re-renders
@@ -1501,6 +1490,18 @@ function formatTimezoneOffset(minutes) {
1501
1490
  function isInvalidDateString(value) {
1502
1491
  return isNaN(new Date(Date.parse(value)).getTime());
1503
1492
  }
1493
+ function getNullDateTime() {
1494
+ return {
1495
+ date: new Date(Date.parse(null)),
1496
+ time: null
1497
+ };
1498
+ }
1499
+ function isValidDate(date) {
1500
+ return date && !isNaN(date.getTime());
1501
+ }
1502
+ function isValidTime(time) {
1503
+ return !isNaN(parseInt(time));
1504
+ }
1504
1505
  function _getSignedPaddedHours(minutes) {
1505
1506
  if (minutes > 0) {
1506
1507
  return '-' + _getZeroPaddedString(Math.floor(minutes / 60));
@@ -1991,7 +1992,8 @@ function FormField(props) {
1991
1992
  };
1992
1993
  }, [eventBus, viewerCommands]);
1993
1994
  useEffect(() => {
1994
- if (initialValidationTrigger && initialValue) {
1995
+ const hasInitialValue = initialValue && !isEqual(initialValue, []);
1996
+ if (initialValidationTrigger && hasInitialValue) {
1995
1997
  setInitialValidationTrigger(false);
1996
1998
  viewerCommands.updateFieldValidation(field, initialValue, indexes);
1997
1999
  }
@@ -2795,14 +2797,8 @@ function Datetime(props) {
2795
2797
  formId
2796
2798
  } = useContext(FormContext);
2797
2799
  const dateTimeGroupRef = useRef();
2798
- const getNullDateTime = () => ({
2799
- date: new Date(Date.parse(null)),
2800
- time: null
2801
- });
2802
2800
  const [dateTime, setDateTime] = useState(getNullDateTime());
2803
2801
  const [dateTimeUpdateRequest, setDateTimeUpdateRequest] = useState(null);
2804
- const isValidDate = date => date && !isNaN(date.getTime());
2805
- const isValidTime = time => !isNaN(parseInt(time));
2806
2802
  const useDatePicker = useMemo(() => subtype === DATETIME_SUBTYPES.DATE || subtype === DATETIME_SUBTYPES.DATETIME, [subtype]);
2807
2803
  const useTimePicker = useMemo(() => subtype === DATETIME_SUBTYPES.TIME || subtype === DATETIME_SUBTYPES.DATETIME, [subtype]);
2808
2804
  const onDateTimeBlur = useCallback(e => {
@@ -2857,11 +2853,14 @@ function Datetime(props) {
2857
2853
  } else if (subtype === DATETIME_SUBTYPES.DATETIME && isValidDate(date) && isValidTime(time)) {
2858
2854
  newDateTimeValue = serializeDateTime(date, time, timeSerializingFormat);
2859
2855
  }
2856
+ if (value === newDateTimeValue) {
2857
+ return;
2858
+ }
2860
2859
  onChange({
2861
2860
  value: newDateTimeValue,
2862
2861
  field
2863
2862
  });
2864
- }, [field, onChange, subtype, timeSerializingFormat]);
2863
+ }, [value, field, onChange, subtype, timeSerializingFormat]);
2865
2864
  useEffect(() => {
2866
2865
  if (dateTimeUpdateRequest) {
2867
2866
  if (dateTimeUpdateRequest.refreshOnly) {
@@ -4928,7 +4927,7 @@ function Html(props) {
4928
4927
  Html.config = {
4929
4928
  type: type$4,
4930
4929
  keyed: false,
4931
- label: 'HTML',
4930
+ label: 'HTML view',
4932
4931
  group: 'presentation',
4933
4932
  create: (options = {}) => ({
4934
4933
  content: '',
@@ -4940,7 +4939,8 @@ const type$3 = 'expression';
4940
4939
  function ExpressionField(props) {
4941
4940
  const {
4942
4941
  field,
4943
- onChange
4942
+ onChange,
4943
+ value
4944
4944
  } = props;
4945
4945
  const {
4946
4946
  computeOn,
@@ -4955,12 +4955,12 @@ function ExpressionField(props) {
4955
4955
  value: evaluationMemo
4956
4956
  });
4957
4957
  }, [field, evaluationMemo, onChange]);
4958
- useEffectOnChange(evaluationMemo, () => {
4959
- if (computeOn !== 'change') {
4958
+ useEffect(() => {
4959
+ if (computeOn !== 'change' || evaluationMemo === value) {
4960
4960
  return;
4961
4961
  }
4962
4962
  sendValue();
4963
- }, [computeOn, sendValue]);
4963
+ }, [computeOn, evaluationMemo, sendValue, value]);
4964
4964
  useEffect(() => {
4965
4965
  if (computeOn === 'presubmit') {
4966
4966
  eventBus.on('presubmit', sendValue);
@@ -4974,6 +4974,7 @@ ExpressionField.config = {
4974
4974
  label: 'Expression',
4975
4975
  group: 'basic-input',
4976
4976
  keyed: true,
4977
+ emptyValue: null,
4977
4978
  escapeGridRender: true,
4978
4979
  create: (options = {}) => ({
4979
4980
  computeOn: 'change',