@bpmn-io/properties-panel 3.27.3 → 3.27.5

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
@@ -423,6 +423,18 @@ function useDescriptionContext(id, element) {
423
423
  return getDescriptionForId(id, element);
424
424
  }
425
425
 
426
+ function useDebounce(callback, debounceFn) {
427
+ const debouncedCallback = hooks.useCallback(debounceFn(callback), [callback, debounceFn]);
428
+
429
+ // make sure previous call is not stalled
430
+ hooks.useEffect(() => {
431
+ return () => {
432
+ debouncedCallback.flush?.();
433
+ };
434
+ }, [debouncedCallback]);
435
+ return debouncedCallback;
436
+ }
437
+
426
438
  function useError(id) {
427
439
  const {
428
440
  errors
@@ -2029,11 +2041,7 @@ function FeelTextfieldComponent(props) {
2029
2041
  /**
2030
2042
  * @type { import('min-dash').DebouncedFunction }
2031
2043
  */
2032
- const handleInputCallback = hooks.useMemo(() => {
2033
- return debounce(newValue => {
2034
- onInput(newValue);
2035
- });
2036
- }, [onInput, debounce]);
2044
+ const handleInputCallback = useDebounce(onInput, debounce);
2037
2045
  const handleInput = newValue => {
2038
2046
  // we don't commit empty FEEL expressions,
2039
2047
  // but instead serialize them as <undefined>
@@ -2067,14 +2075,10 @@ function FeelTextfieldComponent(props) {
2067
2075
  }
2068
2076
  };
2069
2077
  const handleOnBlur = e => {
2070
- const value = e.target.value;
2078
+ const trimmedValue = e.target.value.trim();
2071
2079
 
2072
- // we trim the value, if it is needed
2073
- // and update input accordingly
2074
- if (value.trim() !== value) {
2075
- setLocalValue(value.trim());
2076
- handleInput(value.trim());
2077
- }
2080
+ // trim and commit on blur
2081
+ onInput(trimmedValue);
2078
2082
  if (onBlur) {
2079
2083
  onBlur(e);
2080
2084
  }
@@ -2485,7 +2489,7 @@ function FeelEntry(props) {
2485
2489
  setValue(newValue, newValidationError);
2486
2490
  }
2487
2491
  setValidationError(newValidationError);
2488
- }, [element]);
2492
+ }, [element, getValue, setValue, validate]);
2489
2493
  const onError = hooks.useCallback(err => {
2490
2494
  setLocalError(err);
2491
2495
  }, []);
@@ -4026,11 +4030,7 @@ function TextArea(props) {
4026
4030
  /**
4027
4031
  * @type { import('min-dash').DebouncedFunction }
4028
4032
  */
4029
- const handleInputCallback = hooks.useMemo(() => {
4030
- return debounce(newValue => {
4031
- onInput(newValue);
4032
- });
4033
- }, [onInput, debounce]);
4033
+ const handleInputCallback = useDebounce(onInput, debounce);
4034
4034
  const handleInput = newValue => {
4035
4035
  const newModelValue = newValue === '' ? undefined : newValue;
4036
4036
  handleInputCallback(newModelValue);
@@ -4044,11 +4044,10 @@ function TextArea(props) {
4044
4044
  handleInput(e.target.value);
4045
4045
  };
4046
4046
  const handleOnBlur = e => {
4047
- const value = e.target.value;
4048
- if (value.trim() !== value) {
4049
- setLocalValue(value.trim());
4050
- handleInput(value.trim());
4051
- }
4047
+ const trimmedValue = e.target.value.trim();
4048
+
4049
+ // trim and commit on blur
4050
+ onInput(trimmedValue);
4052
4051
  if (onBlur) {
4053
4052
  onBlur(e);
4054
4053
  }
@@ -4148,7 +4147,7 @@ function TextAreaEntry(props) {
4148
4147
  setValue(newValue, newValidationError);
4149
4148
  }
4150
4149
  setLocalError(newValidationError);
4151
- }, [element]);
4150
+ }, [element, getValue, setValue, validate]);
4152
4151
  const error = globalError || localError;
4153
4152
  return jsxRuntime.jsxs("div", {
4154
4153
  class: classnames('bio-properties-panel-entry', error ? 'has-error' : ''),
@@ -4207,17 +4206,12 @@ function Textfield(props) {
4207
4206
  /**
4208
4207
  * @type { import('min-dash').DebouncedFunction }
4209
4208
  */
4210
- const handleInputCallback = hooks.useMemo(() => {
4211
- return debounce(newValue => {
4212
- onInput(newValue);
4213
- });
4214
- }, [onInput, debounce]);
4209
+ const handleInputCallback = useDebounce(onInput, debounce);
4215
4210
  const handleOnBlur = e => {
4216
- const value = e.target.value;
4217
- if (value.trim() !== value) {
4218
- setLocalValue(value.trim());
4219
- handleInput(value.trim());
4220
- }
4211
+ const trimmedValue = e.target.value.trim();
4212
+
4213
+ // trim and commit on blur
4214
+ onInput(trimmedValue);
4221
4215
  if (onBlur) {
4222
4216
  onBlur(e);
4223
4217
  }
@@ -4318,7 +4312,7 @@ function TextfieldEntry(props) {
4318
4312
  setValue(newValue, newValidationError);
4319
4313
  }
4320
4314
  setLocalError(newValidationError);
4321
- }, [element]);
4315
+ }, [element, getValue, setValue, validate]);
4322
4316
  const error = globalError || localError;
4323
4317
  return jsxRuntime.jsxs("div", {
4324
4318
  class: classnames('bio-properties-panel-entry', error ? 'has-error' : ''),
@@ -4489,6 +4483,7 @@ exports.isTemplatingEntryEdited = isEdited$4;
4489
4483
  exports.isTextAreaEntryEdited = isEdited$1;
4490
4484
  exports.isTextFieldEntryEdited = isEdited;
4491
4485
  exports.isToggleSwitchEntryEdited = isEdited$8;
4486
+ exports.useDebounce = useDebounce;
4492
4487
  exports.useDescriptionContext = useDescriptionContext;
4493
4488
  exports.useElementVisible = useElementVisible;
4494
4489
  exports.useError = useError;