@bpmn-io/properties-panel 3.29.0 → 3.29.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/dist/index.js CHANGED
@@ -429,7 +429,7 @@ function useDebounce(callback, debounceFn) {
429
429
  // make sure previous call is not stalled
430
430
  hooks.useEffect(() => {
431
431
  return () => {
432
- debouncedCallback.flush?.();
432
+ debouncedCallback.cancel?.();
433
433
  };
434
434
  }, [debouncedCallback]);
435
435
  return debouncedCallback;
@@ -2164,50 +2164,6 @@ function prefixId$6(id) {
2164
2164
  return `bio-properties-panel-${id}`;
2165
2165
  }
2166
2166
 
2167
- function TextInput({
2168
- debounce,
2169
- element,
2170
- id,
2171
- getValue,
2172
- onBlur,
2173
- setValue,
2174
- validate,
2175
- Component,
2176
- ...props
2177
- }) {
2178
- const modelValue = getValue(element);
2179
- const setModelValue = hooks.useCallback((newValue, error) => {
2180
- if (minDash.isFunction(validate)) {
2181
- error = validate(newValue) || null;
2182
- }
2183
- setValue(newValue, error);
2184
- }, [setValue, validate]);
2185
- const debouncedSetValue = useDebounce(setModelValue, debounce);
2186
- const handleInput = hooks.useCallback(newValue => {
2187
- if (newValue !== modelValue) {
2188
- debouncedSetValue(newValue);
2189
- }
2190
- }, [modelValue, debouncedSetValue]);
2191
- const handleBlur = hooks.useCallback(value => {
2192
- const newValue = value.trim?.() || value;
2193
- if (newValue !== modelValue) {
2194
- setModelValue(newValue);
2195
- }
2196
- if (minDash.isFunction(onBlur)) {
2197
- onBlur(newValue);
2198
- }
2199
- }, [modelValue, setModelValue]);
2200
- return jsxRuntime.jsx(Component, {
2201
- ...props,
2202
- debounce: debounce,
2203
- element: element,
2204
- id: id,
2205
- onInput: handleInput,
2206
- onBlur: handleBlur,
2207
- value: modelValue
2208
- });
2209
- }
2210
-
2211
2167
  const noop$2 = () => {};
2212
2168
 
2213
2169
  /**
@@ -2236,6 +2192,7 @@ const noop$2 = () => {};
2236
2192
  */
2237
2193
  function FeelTextfield(props) {
2238
2194
  const {
2195
+ debounce,
2239
2196
  id,
2240
2197
  element,
2241
2198
  label,
@@ -2270,11 +2227,16 @@ function FeelTextfield(props) {
2270
2227
  const position = hasFocus ? document.activeElement.selectionStart : Infinity;
2271
2228
  _setFocus(position + offset);
2272
2229
  };
2230
+
2231
+ /**
2232
+ * @type { import('min-dash').DebouncedFunction }
2233
+ */
2234
+ const handleInputCallback = useDebounce(onInput, debounce);
2273
2235
  const handleInput = newValue => {
2274
2236
  // we don't commit empty FEEL expressions,
2275
2237
  // but instead serialize them as <undefined>
2276
2238
  const newModelValue = newValue === '' || newValue === '=' ? undefined : newValue;
2277
- onInput(newModelValue);
2239
+ handleInputCallback(newModelValue);
2278
2240
  };
2279
2241
  const handleFeelToggle = useStaticCallback(() => {
2280
2242
  if (feel === 'required') {
@@ -2302,8 +2264,14 @@ function FeelTextfield(props) {
2302
2264
  setFocus(-1);
2303
2265
  }
2304
2266
  };
2305
- const handleOnBlur = () => {
2306
- onBlur?.(localValue);
2267
+ const handleOnBlur = e => {
2268
+ const trimmedValue = e.target.value.trim();
2269
+
2270
+ // trim and commit on blur
2271
+ onInput(trimmedValue);
2272
+ if (onBlur) {
2273
+ onBlur(e);
2274
+ }
2307
2275
  };
2308
2276
  const handleLint = useStaticCallback((lint = []) => {
2309
2277
  const syntaxError = lint.some(report => report.type === 'Syntax Error');
@@ -2700,28 +2668,46 @@ function FeelEntry(props) {
2700
2668
  placeholder,
2701
2669
  tooltip
2702
2670
  } = props;
2671
+ const [validationError, setValidationError] = hooks.useState(null);
2703
2672
  const [localError, setLocalError] = hooks.useState(null);
2704
- const value = getValue(element);
2705
- const validationError = validate?.(value) || null;
2673
+ let value = getValue(element);
2674
+ hooks.useEffect(() => {
2675
+ if (minDash.isFunction(validate)) {
2676
+ const newValidationError = validate(value) || null;
2677
+ setValidationError(newValidationError);
2678
+ }
2679
+ }, [value, validate]);
2680
+ const onInput = useStaticCallback(newValue => {
2681
+ const value = getValue(element);
2682
+ let newValidationError = null;
2683
+ if (minDash.isFunction(validate)) {
2684
+ newValidationError = validate(newValue) || null;
2685
+ }
2686
+
2687
+ // don't create multiple commandStack entries for the same value
2688
+ if (newValue !== value) {
2689
+ setValue(newValue, newValidationError);
2690
+ }
2691
+ setValidationError(newValidationError);
2692
+ });
2693
+ const onError = hooks.useCallback(err => {
2694
+ setLocalError(err);
2695
+ }, []);
2706
2696
  const temporaryError = useError(id);
2707
2697
  const error = temporaryError || localError || validationError;
2708
2698
  return jsxRuntime.jsxs("div", {
2709
2699
  class: classnames(props.class, 'bio-properties-panel-entry', error ? 'has-error' : ''),
2710
2700
  "data-entry-id": id,
2711
- children: [preact.createElement(TextInput, {
2701
+ children: [preact.createElement(FeelTextfield, {
2712
2702
  ...props,
2713
- Component: FeelTextfield,
2714
- element: element,
2715
- getValue: getValue,
2716
2703
  debounce: debounce,
2717
- setValue: setValue,
2718
- validate: validate,
2719
2704
  disabled: disabled,
2720
2705
  feel: feel,
2721
2706
  id: id,
2722
2707
  key: element,
2723
2708
  label: label,
2724
- onError: setLocalError,
2709
+ onInput: onInput,
2710
+ onError: onError,
2725
2711
  onFocus: onFocus,
2726
2712
  onBlur: onBlur,
2727
2713
  placeholder: placeholder,
@@ -3469,8 +3455,14 @@ function TextArea(props) {
3469
3455
  setLocalValue(e.target.value);
3470
3456
  handleInput(e.target.value);
3471
3457
  };
3472
- const handleOnBlur = () => {
3473
- onBlur?.(localValue);
3458
+ const handleOnBlur = e => {
3459
+ const trimmedValue = e.target.value.trim();
3460
+
3461
+ // trim and commit on blur
3462
+ onInput(trimmedValue);
3463
+ if (onBlur) {
3464
+ onBlur(e);
3465
+ }
3474
3466
  };
3475
3467
  hooks.useLayoutEffect(() => {
3476
3468
  autoResize && resizeToContents(ref.current);
@@ -3548,21 +3540,35 @@ function TextAreaEntry(props) {
3548
3540
  autoResize,
3549
3541
  tooltip
3550
3542
  } = props;
3551
- const value = getValue(element);
3552
3543
  const globalError = useError(id);
3553
- const localError = validate?.(value) || null;
3544
+ const [localError, setLocalError] = hooks.useState(null);
3545
+ let value = getValue(element);
3546
+ hooks.useEffect(() => {
3547
+ if (minDash.isFunction(validate)) {
3548
+ const newValidationError = validate(value) || null;
3549
+ setLocalError(newValidationError);
3550
+ }
3551
+ }, [value, validate]);
3552
+ const onInput = useStaticCallback(newValue => {
3553
+ const value = getValue(element);
3554
+ let newValidationError = null;
3555
+ if (minDash.isFunction(validate)) {
3556
+ newValidationError = validate(newValue) || null;
3557
+ }
3558
+ if (newValue !== value) {
3559
+ setValue(newValue, newValidationError);
3560
+ }
3561
+ setLocalError(newValidationError);
3562
+ });
3554
3563
  const error = globalError || localError;
3555
3564
  return jsxRuntime.jsxs("div", {
3556
3565
  class: classnames('bio-properties-panel-entry', error ? 'has-error' : ''),
3557
3566
  "data-entry-id": id,
3558
- children: [jsxRuntime.jsx(TextInput, {
3559
- Component: TextArea,
3560
- getValue: getValue,
3561
- setValue: setValue,
3562
- validate: validate,
3567
+ children: [jsxRuntime.jsx(TextArea, {
3563
3568
  id: id,
3564
3569
  label: label,
3565
3570
  value: value,
3571
+ onInput: onInput,
3566
3572
  onFocus: onFocus,
3567
3573
  onBlur: onBlur,
3568
3574
  rows: rows,
@@ -3595,6 +3601,7 @@ function prefixId$2(id) {
3595
3601
 
3596
3602
  function Textfield(props) {
3597
3603
  const {
3604
+ debounce,
3598
3605
  disabled = false,
3599
3606
  id,
3600
3607
  label,
@@ -3607,12 +3614,23 @@ function Textfield(props) {
3607
3614
  } = props;
3608
3615
  const [localValue, setLocalValue] = hooks.useState(value || '');
3609
3616
  const ref = useShowEntryEvent(id);
3610
- const handleOnBlur = () => {
3611
- onBlur?.(localValue);
3617
+
3618
+ /**
3619
+ * @type { import('min-dash').DebouncedFunction }
3620
+ */
3621
+ const handleInputCallback = useDebounce(onInput, debounce);
3622
+ const handleOnBlur = e => {
3623
+ const trimmedValue = e.target.value.trim();
3624
+
3625
+ // trim and commit on blur
3626
+ onInput(trimmedValue);
3627
+ if (onBlur) {
3628
+ onBlur(e);
3629
+ }
3612
3630
  };
3613
3631
  const handleInput = newValue => {
3614
3632
  const newModelValue = newValue === '' ? undefined : newValue;
3615
- onInput(newModelValue);
3633
+ handleInputCallback(newModelValue);
3616
3634
  };
3617
3635
  const handleLocalInput = e => {
3618
3636
  if (e.target.value === localValue) {
@@ -3687,25 +3705,39 @@ function TextfieldEntry(props) {
3687
3705
  placeholder,
3688
3706
  tooltip
3689
3707
  } = props;
3690
- const value = getValue(element);
3691
3708
  const globalError = useError(id);
3692
- const localError = validate?.(value) || null;
3709
+ const [localError, setLocalError] = hooks.useState(null);
3710
+ let value = getValue(element);
3711
+ hooks.useEffect(() => {
3712
+ if (minDash.isFunction(validate)) {
3713
+ const newValidationError = validate(value) || null;
3714
+ setLocalError(newValidationError);
3715
+ }
3716
+ }, [value, validate]);
3717
+ const onInput = useStaticCallback(newValue => {
3718
+ const value = getValue(element);
3719
+ let newValidationError = null;
3720
+ if (minDash.isFunction(validate)) {
3721
+ newValidationError = validate(newValue) || null;
3722
+ }
3723
+ if (newValue !== value) {
3724
+ setValue(newValue, newValidationError);
3725
+ }
3726
+ setLocalError(newValidationError);
3727
+ });
3693
3728
  const error = globalError || localError;
3694
3729
  return jsxRuntime.jsxs("div", {
3695
3730
  class: classnames('bio-properties-panel-entry', error ? 'has-error' : ''),
3696
3731
  "data-entry-id": id,
3697
- children: [jsxRuntime.jsx(TextInput, {
3698
- Component: Textfield,
3732
+ children: [jsxRuntime.jsx(Textfield, {
3699
3733
  debounce: debounce,
3700
3734
  disabled: disabled,
3701
- getValue: getValue,
3702
3735
  id: id,
3703
3736
  label: label,
3737
+ onInput: onInput,
3704
3738
  onFocus: onFocus,
3705
3739
  onBlur: onBlur,
3706
3740
  placeholder: placeholder,
3707
- setValue: setValue,
3708
- validate: validate,
3709
3741
  value: value,
3710
3742
  tooltip: tooltip,
3711
3743
  element: element