@bpmn-io/properties-panel 3.27.7 → 3.27.8

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;
@@ -1972,50 +1972,6 @@ function prefixId$6(id) {
1972
1972
  return `bio-properties-panel-${id}`;
1973
1973
  }
1974
1974
 
1975
- function TextInput({
1976
- debounce,
1977
- element,
1978
- id,
1979
- getValue,
1980
- onBlur,
1981
- setValue,
1982
- validate,
1983
- Component,
1984
- ...props
1985
- }) {
1986
- const modelValue = getValue(element);
1987
- const setModelValue = hooks.useCallback((newValue, error) => {
1988
- if (minDash.isFunction(validate)) {
1989
- error = validate(newValue) || null;
1990
- }
1991
- setValue(newValue, error);
1992
- }, [setValue, validate]);
1993
- const debouncedSetValue = useDebounce(setModelValue, debounce);
1994
- const handleInput = hooks.useCallback(newValue => {
1995
- if (newValue !== modelValue) {
1996
- debouncedSetValue(newValue);
1997
- }
1998
- }, [modelValue, debouncedSetValue]);
1999
- const handleBlur = hooks.useCallback(value => {
2000
- const newValue = value.trim?.() || value;
2001
- if (newValue !== modelValue) {
2002
- setModelValue(newValue);
2003
- }
2004
- if (minDash.isFunction(onBlur)) {
2005
- onBlur(newValue);
2006
- }
2007
- }, [modelValue, setModelValue]);
2008
- return jsxRuntime.jsx(Component, {
2009
- ...props,
2010
- debounce: debounce,
2011
- element: element,
2012
- id: id,
2013
- onInput: handleInput,
2014
- onBlur: handleBlur,
2015
- value: modelValue
2016
- });
2017
- }
2018
-
2019
1975
  const noop$2 = () => {};
2020
1976
 
2021
1977
  /**
@@ -2045,6 +2001,7 @@ const noop$2 = () => {};
2045
2001
 
2046
2002
  function FeelTextfieldComponent(props) {
2047
2003
  const {
2004
+ debounce,
2048
2005
  id,
2049
2006
  element,
2050
2007
  label,
@@ -2080,11 +2037,16 @@ function FeelTextfieldComponent(props) {
2080
2037
  const position = hasFocus ? document.activeElement.selectionStart : Infinity;
2081
2038
  _setFocus(position + offset);
2082
2039
  };
2040
+
2041
+ /**
2042
+ * @type { import('min-dash').DebouncedFunction }
2043
+ */
2044
+ const handleInputCallback = useDebounce(onInput, debounce);
2083
2045
  const handleInput = newValue => {
2084
2046
  // we don't commit empty FEEL expressions,
2085
2047
  // but instead serialize them as <undefined>
2086
2048
  const newModelValue = newValue === '' || newValue === '=' ? undefined : newValue;
2087
- onInput(newModelValue);
2049
+ handleInputCallback(newModelValue);
2088
2050
  };
2089
2051
  const handleFeelToggle = useStaticCallback(() => {
2090
2052
  if (feel === 'required') {
@@ -2112,8 +2074,14 @@ function FeelTextfieldComponent(props) {
2112
2074
  setFocus(-1);
2113
2075
  }
2114
2076
  };
2115
- const handleOnBlur = () => {
2116
- onBlur?.(localValue);
2077
+ const handleOnBlur = e => {
2078
+ const trimmedValue = e.target.value.trim();
2079
+
2080
+ // trim and commit on blur
2081
+ onInput(trimmedValue);
2082
+ if (onBlur) {
2083
+ onBlur(e);
2084
+ }
2117
2085
  };
2118
2086
  const handleLint = useStaticCallback((lint = []) => {
2119
2087
  const syntaxError = lint.some(report => report.type === 'Syntax Error');
@@ -2500,28 +2468,46 @@ function FeelEntry(props) {
2500
2468
  placeholder,
2501
2469
  tooltip
2502
2470
  } = props;
2471
+ const [validationError, setValidationError] = hooks.useState(null);
2503
2472
  const [localError, setLocalError] = hooks.useState(null);
2504
- const value = getValue(element);
2505
- const validationError = validate?.(value) || null;
2473
+ let value = getValue(element);
2474
+ hooks.useEffect(() => {
2475
+ if (minDash.isFunction(validate)) {
2476
+ const newValidationError = validate(value) || null;
2477
+ setValidationError(newValidationError);
2478
+ }
2479
+ }, [value, validate]);
2480
+ const onInput = useStaticCallback(newValue => {
2481
+ const value = getValue(element);
2482
+ let newValidationError = null;
2483
+ if (minDash.isFunction(validate)) {
2484
+ newValidationError = validate(newValue) || null;
2485
+ }
2486
+
2487
+ // don't create multiple commandStack entries for the same value
2488
+ if (newValue !== value) {
2489
+ setValue(newValue, newValidationError);
2490
+ }
2491
+ setValidationError(newValidationError);
2492
+ });
2493
+ const onError = hooks.useCallback(err => {
2494
+ setLocalError(err);
2495
+ }, []);
2506
2496
  const temporaryError = useError(id);
2507
2497
  const error = temporaryError || localError || validationError;
2508
2498
  return jsxRuntime.jsxs("div", {
2509
2499
  class: classnames(props.class, 'bio-properties-panel-entry', error ? 'has-error' : ''),
2510
2500
  "data-entry-id": id,
2511
- children: [preact.createElement(TextInput, {
2501
+ children: [preact.createElement(FeelTextfield, {
2512
2502
  ...props,
2513
- Component: FeelTextfield,
2514
- element: element,
2515
- getValue: getValue,
2516
2503
  debounce: debounce,
2517
- setValue: setValue,
2518
- validate: validate,
2519
2504
  disabled: disabled,
2520
2505
  feel: feel,
2521
2506
  id: id,
2522
2507
  key: element,
2523
2508
  label: label,
2524
- onError: setLocalError,
2509
+ onInput: onInput,
2510
+ onError: onError,
2525
2511
  onFocus: onFocus,
2526
2512
  onBlur: onBlur,
2527
2513
  placeholder: placeholder,
@@ -4057,8 +4043,14 @@ function TextArea(props) {
4057
4043
  setLocalValue(e.target.value);
4058
4044
  handleInput(e.target.value);
4059
4045
  };
4060
- const handleOnBlur = () => {
4061
- onBlur?.(localValue);
4046
+ const handleOnBlur = e => {
4047
+ const trimmedValue = e.target.value.trim();
4048
+
4049
+ // trim and commit on blur
4050
+ onInput(trimmedValue);
4051
+ if (onBlur) {
4052
+ onBlur(e);
4053
+ }
4062
4054
  };
4063
4055
  hooks.useLayoutEffect(() => {
4064
4056
  autoResize && resizeToContents(ref.current);
@@ -4136,21 +4128,35 @@ function TextAreaEntry(props) {
4136
4128
  autoResize,
4137
4129
  tooltip
4138
4130
  } = props;
4139
- const value = getValue(element);
4140
4131
  const globalError = useError(id);
4141
- const localError = validate?.(value) || null;
4132
+ const [localError, setLocalError] = hooks.useState(null);
4133
+ let value = getValue(element);
4134
+ hooks.useEffect(() => {
4135
+ if (minDash.isFunction(validate)) {
4136
+ const newValidationError = validate(value) || null;
4137
+ setLocalError(newValidationError);
4138
+ }
4139
+ }, [value, validate]);
4140
+ const onInput = useStaticCallback(newValue => {
4141
+ const value = getValue(element);
4142
+ let newValidationError = null;
4143
+ if (minDash.isFunction(validate)) {
4144
+ newValidationError = validate(newValue) || null;
4145
+ }
4146
+ if (newValue !== value) {
4147
+ setValue(newValue, newValidationError);
4148
+ }
4149
+ setLocalError(newValidationError);
4150
+ });
4142
4151
  const error = globalError || localError;
4143
4152
  return jsxRuntime.jsxs("div", {
4144
4153
  class: classnames('bio-properties-panel-entry', error ? 'has-error' : ''),
4145
4154
  "data-entry-id": id,
4146
- children: [jsxRuntime.jsx(TextInput, {
4147
- Component: TextArea,
4148
- getValue: getValue,
4149
- setValue: setValue,
4150
- validate: validate,
4155
+ children: [jsxRuntime.jsx(TextArea, {
4151
4156
  id: id,
4152
4157
  label: label,
4153
4158
  value: value,
4159
+ onInput: onInput,
4154
4160
  onFocus: onFocus,
4155
4161
  onBlur: onBlur,
4156
4162
  rows: rows,
@@ -4183,6 +4189,7 @@ function prefixId$1(id) {
4183
4189
 
4184
4190
  function Textfield(props) {
4185
4191
  const {
4192
+ debounce,
4186
4193
  disabled = false,
4187
4194
  id,
4188
4195
  label,
@@ -4195,12 +4202,23 @@ function Textfield(props) {
4195
4202
  } = props;
4196
4203
  const [localValue, setLocalValue] = hooks.useState(value || '');
4197
4204
  const ref = useShowEntryEvent(id);
4198
- const handleOnBlur = () => {
4199
- onBlur?.(localValue);
4205
+
4206
+ /**
4207
+ * @type { import('min-dash').DebouncedFunction }
4208
+ */
4209
+ const handleInputCallback = useDebounce(onInput, debounce);
4210
+ const handleOnBlur = e => {
4211
+ const trimmedValue = e.target.value.trim();
4212
+
4213
+ // trim and commit on blur
4214
+ onInput(trimmedValue);
4215
+ if (onBlur) {
4216
+ onBlur(e);
4217
+ }
4200
4218
  };
4201
4219
  const handleInput = newValue => {
4202
4220
  const newModelValue = newValue === '' ? undefined : newValue;
4203
- onInput(newModelValue);
4221
+ handleInputCallback(newModelValue);
4204
4222
  };
4205
4223
  const handleLocalInput = e => {
4206
4224
  if (e.target.value === localValue) {
@@ -4275,25 +4293,39 @@ function TextfieldEntry(props) {
4275
4293
  placeholder,
4276
4294
  tooltip
4277
4295
  } = props;
4278
- const value = getValue(element);
4279
4296
  const globalError = useError(id);
4280
- const localError = validate?.(value) || null;
4297
+ const [localError, setLocalError] = hooks.useState(null);
4298
+ let value = getValue(element);
4299
+ hooks.useEffect(() => {
4300
+ if (minDash.isFunction(validate)) {
4301
+ const newValidationError = validate(value) || null;
4302
+ setLocalError(newValidationError);
4303
+ }
4304
+ }, [value, validate]);
4305
+ const onInput = useStaticCallback(newValue => {
4306
+ const value = getValue(element);
4307
+ let newValidationError = null;
4308
+ if (minDash.isFunction(validate)) {
4309
+ newValidationError = validate(newValue) || null;
4310
+ }
4311
+ if (newValue !== value) {
4312
+ setValue(newValue, newValidationError);
4313
+ }
4314
+ setLocalError(newValidationError);
4315
+ });
4281
4316
  const error = globalError || localError;
4282
4317
  return jsxRuntime.jsxs("div", {
4283
4318
  class: classnames('bio-properties-panel-entry', error ? 'has-error' : ''),
4284
4319
  "data-entry-id": id,
4285
- children: [jsxRuntime.jsx(TextInput, {
4286
- Component: Textfield,
4320
+ children: [jsxRuntime.jsx(Textfield, {
4287
4321
  debounce: debounce,
4288
4322
  disabled: disabled,
4289
- getValue: getValue,
4290
4323
  id: id,
4291
4324
  label: label,
4325
+ onInput: onInput,
4292
4326
  onFocus: onFocus,
4293
4327
  onBlur: onBlur,
4294
4328
  placeholder: placeholder,
4295
- setValue: setValue,
4296
- validate: validate,
4297
4329
  value: value,
4298
4330
  tooltip: tooltip,
4299
4331
  element: element