@bpmn-io/properties-panel 3.41.2 → 3.41.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.js CHANGED
@@ -1964,6 +1964,7 @@ function JsonEditor(props) {
1964
1964
  * @param {boolean} [props.disabled]
1965
1965
  * @param {string} [props.placeholder]
1966
1966
  * @param {string} [props.tooltip]
1967
+ * @param {Function} [props.validate]
1967
1968
  */
1968
1969
  function JsonEditorEntry(props) {
1969
1970
  const {
@@ -1976,25 +1977,30 @@ function JsonEditorEntry(props) {
1976
1977
  setValue,
1977
1978
  disabled,
1978
1979
  placeholder,
1979
- tooltip
1980
+ tooltip,
1981
+ validate
1980
1982
  } = props;
1981
1983
  const globalError = useError(id);
1982
1984
  let value = getValue(element);
1985
+ const [localError, setLocalError] = hooks.useState(() => computeError(validate, value));
1983
1986
  const [editorValue, setEditorValue] = hooks.useState(value);
1984
1987
  hooks.useEffect(() => {
1985
1988
  if (value === editorValue) {
1986
1989
  return;
1987
1990
  }
1988
1991
  setEditorValue(value);
1989
- }, [value]);
1992
+ setLocalError(computeError(validate, value));
1993
+ }, [value, validate]);
1990
1994
  const onInput = useStaticCallback(newValue => {
1991
1995
  setEditorValue(newValue);
1992
1996
  const currentValue = getValue(element);
1993
1997
  if (newValue !== currentValue) {
1994
- setValue(newValue);
1998
+ const newValidationError = computeError(validate, newValue);
1999
+ setValue(newValue, newValidationError);
2000
+ setLocalError(newValidationError);
1995
2001
  }
1996
2002
  });
1997
- const error = globalError || validateJson(editorValue);
2003
+ const error = globalError || localError;
1998
2004
  return jsxRuntime.jsxs("div", {
1999
2005
  class: classnames('bio-properties-panel-entry', error && 'has-error'),
2000
2006
  "data-entry-id": id,
@@ -2028,6 +2034,9 @@ function isEdited$8(node) {
2028
2034
 
2029
2035
  // helpers /////////////////
2030
2036
 
2037
+ function computeError(validate, value) {
2038
+ return (minDash.isFunction(validate) ? validate(value) : null) || validateJson(value);
2039
+ }
2031
2040
  function validateJson(value) {
2032
2041
  if (!value || !value.trim()) return null;
2033
2042
  try {
@@ -2604,12 +2613,14 @@ function NumberFieldEntry(props) {
2604
2613
  }
2605
2614
  }, [value, validate]);
2606
2615
  const onInput = newValue => {
2607
- let newValidationError = null;
2608
- if (minDash.isFunction(validate)) {
2609
- newValidationError = validate(newValue) || null;
2616
+ if (newValue !== value) {
2617
+ let newValidationError = null;
2618
+ if (minDash.isFunction(validate)) {
2619
+ newValidationError = validate(newValue) || null;
2620
+ }
2621
+ setValue(newValue, newValidationError);
2622
+ setLocalError(newValidationError);
2610
2623
  }
2611
- setValue(newValue, newValidationError);
2612
- setLocalError(newValidationError);
2613
2624
  };
2614
2625
  const error = globalError || localError;
2615
2626
  return jsxRuntime.jsxs("div", {
@@ -3204,16 +3215,16 @@ function FeelEntry(props) {
3204
3215
  }, [value, validate]);
3205
3216
  const onInput = useStaticCallback(newValue => {
3206
3217
  const value = getValue(element);
3207
- let newValidationError = null;
3208
- if (minDash.isFunction(validate)) {
3209
- newValidationError = validate(newValue) || null;
3210
- }
3211
3218
 
3212
- // don't create multiple commandStack entries for the same value
3219
+ // don't create multiple commandStack entries and do validation for the same value
3213
3220
  if (newValue !== value) {
3221
+ let newValidationError = null;
3222
+ if (minDash.isFunction(validate)) {
3223
+ newValidationError = validate(newValue) || null;
3224
+ }
3214
3225
  setValue(newValue, newValidationError);
3226
+ setValidationError(newValidationError);
3215
3227
  }
3216
- setValidationError(newValidationError);
3217
3228
  });
3218
3229
  const onError = hooks.useCallback(err => {
3219
3230
  setLocalError(err);
@@ -3936,12 +3947,14 @@ function SelectEntry(props) {
3936
3947
  }
3937
3948
  }, [value, validate]);
3938
3949
  const onChange = newValue => {
3939
- let newValidationError = null;
3940
- if (minDash.isFunction(validate)) {
3941
- newValidationError = validate(newValue) || null;
3950
+ if (newValue !== value) {
3951
+ let newValidationError = null;
3952
+ if (minDash.isFunction(validate)) {
3953
+ newValidationError = validate(newValue) || null;
3954
+ }
3955
+ setValue(newValue, newValidationError);
3956
+ setLocalError(newValidationError);
3942
3957
  }
3943
- setValue(newValue, newValidationError);
3944
- setLocalError(newValidationError);
3945
3958
  };
3946
3959
  const error = globalError || localError;
3947
3960
  return jsxRuntime.jsxs("div", {
@@ -4216,14 +4229,14 @@ function TextAreaEntry(props) {
4216
4229
  }, [value, validate]);
4217
4230
  const onInput = useStaticCallback(newValue => {
4218
4231
  const value = getValue(element);
4219
- let newValidationError = null;
4220
- if (minDash.isFunction(validate)) {
4221
- newValidationError = validate(newValue) || null;
4222
- }
4223
4232
  if (newValue !== value) {
4233
+ let newValidationError = null;
4234
+ if (minDash.isFunction(validate)) {
4235
+ newValidationError = validate(newValue) || null;
4236
+ }
4224
4237
  setValue(newValue, newValidationError);
4238
+ setLocalError(newValidationError);
4225
4239
  }
4226
- setLocalError(newValidationError);
4227
4240
  });
4228
4241
  const error = globalError || localError;
4229
4242
  return jsxRuntime.jsxs("div", {
@@ -4415,14 +4428,14 @@ function TextfieldEntry(props) {
4415
4428
  }, [value, validate]);
4416
4429
  const onInput = useStaticCallback(newValue => {
4417
4430
  const value = getValue(element);
4418
- let newValidationError = null;
4419
- if (minDash.isFunction(validate)) {
4420
- newValidationError = validate(newValue) || null;
4421
- }
4422
4431
  if (newValue !== value) {
4432
+ let newValidationError = null;
4433
+ if (minDash.isFunction(validate)) {
4434
+ newValidationError = validate(newValue) || null;
4435
+ }
4423
4436
  setValue(newValue, newValidationError);
4437
+ setLocalError(newValidationError);
4424
4438
  }
4425
- setLocalError(newValidationError);
4426
4439
  });
4427
4440
  const error = globalError || localError;
4428
4441
  return jsxRuntime.jsxs("div", {