@bpmn-io/properties-panel 3.27.5 → 3.27.6

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.esm.js CHANGED
@@ -1951,6 +1951,50 @@ function prefixId$6(id) {
1951
1951
  return `bio-properties-panel-${id}`;
1952
1952
  }
1953
1953
 
1954
+ function TextInput({
1955
+ debounce,
1956
+ element,
1957
+ id,
1958
+ getValue,
1959
+ onBlur,
1960
+ setValue,
1961
+ validate,
1962
+ Component,
1963
+ ...props
1964
+ }) {
1965
+ const modelValue = getValue(element);
1966
+ const setModelValue = useCallback((newValue, error) => {
1967
+ if (isFunction(validate)) {
1968
+ error = validate(newValue) || null;
1969
+ }
1970
+ setValue(newValue, error);
1971
+ }, [setValue, validate]);
1972
+ const debouncedSetValue = useDebounce(setModelValue, debounce);
1973
+ const handleInput = useCallback(newValue => {
1974
+ if (newValue !== modelValue) {
1975
+ debouncedSetValue(newValue);
1976
+ }
1977
+ }, [modelValue, debouncedSetValue]);
1978
+ const handleBlur = useCallback(value => {
1979
+ const newValue = value.trim?.() || value;
1980
+ if (newValue !== modelValue) {
1981
+ setModelValue(newValue);
1982
+ }
1983
+ if (isFunction(onBlur)) {
1984
+ onBlur(newValue);
1985
+ }
1986
+ }, [modelValue, setModelValue]);
1987
+ return jsx(Component, {
1988
+ ...props,
1989
+ debounce: debounce,
1990
+ element: element,
1991
+ id: id,
1992
+ onInput: handleInput,
1993
+ onBlur: handleBlur,
1994
+ value: modelValue
1995
+ });
1996
+ }
1997
+
1954
1998
  const noop$2 = () => {};
1955
1999
 
1956
2000
  /**
@@ -1980,7 +2024,6 @@ const noop$2 = () => {};
1980
2024
 
1981
2025
  function FeelTextfieldComponent(props) {
1982
2026
  const {
1983
- debounce,
1984
2027
  id,
1985
2028
  element,
1986
2029
  label,
@@ -2016,16 +2059,11 @@ function FeelTextfieldComponent(props) {
2016
2059
  const position = hasFocus ? document.activeElement.selectionStart : Infinity;
2017
2060
  _setFocus(position + offset);
2018
2061
  };
2019
-
2020
- /**
2021
- * @type { import('min-dash').DebouncedFunction }
2022
- */
2023
- const handleInputCallback = useDebounce(onInput, debounce);
2024
2062
  const handleInput = newValue => {
2025
2063
  // we don't commit empty FEEL expressions,
2026
2064
  // but instead serialize them as <undefined>
2027
2065
  const newModelValue = newValue === '' || newValue === '=' ? undefined : newValue;
2028
- handleInputCallback(newModelValue);
2066
+ onInput(newModelValue);
2029
2067
  };
2030
2068
  const handleFeelToggle = useStaticCallback(() => {
2031
2069
  if (feel === 'required') {
@@ -2053,14 +2091,8 @@ function FeelTextfieldComponent(props) {
2053
2091
  setFocus(-1);
2054
2092
  }
2055
2093
  };
2056
- const handleOnBlur = e => {
2057
- const trimmedValue = e.target.value.trim();
2058
-
2059
- // trim and commit on blur
2060
- onInput(trimmedValue);
2061
- if (onBlur) {
2062
- onBlur(e);
2063
- }
2094
+ const handleOnBlur = () => {
2095
+ onBlur?.(localValue);
2064
2096
  };
2065
2097
  const handleLint = useStaticCallback((lint = []) => {
2066
2098
  const syntaxError = lint.some(report => report.type === 'Syntax Error');
@@ -2447,46 +2479,28 @@ function FeelEntry(props) {
2447
2479
  placeholder,
2448
2480
  tooltip
2449
2481
  } = props;
2450
- const [validationError, setValidationError] = useState(null);
2451
2482
  const [localError, setLocalError] = useState(null);
2452
- let value = getValue(element);
2453
- useEffect(() => {
2454
- if (isFunction(validate)) {
2455
- const newValidationError = validate(value) || null;
2456
- setValidationError(newValidationError);
2457
- }
2458
- }, [value, validate]);
2459
- const onInput = useCallback(newValue => {
2460
- const value = getValue(element);
2461
- let newValidationError = null;
2462
- if (isFunction(validate)) {
2463
- newValidationError = validate(newValue) || null;
2464
- }
2465
-
2466
- // don't create multiple commandStack entries for the same value
2467
- if (newValue !== value) {
2468
- setValue(newValue, newValidationError);
2469
- }
2470
- setValidationError(newValidationError);
2471
- }, [element, getValue, setValue, validate]);
2472
- const onError = useCallback(err => {
2473
- setLocalError(err);
2474
- }, []);
2483
+ const value = getValue(element);
2484
+ const validationError = validate?.(value) || null;
2475
2485
  const temporaryError = useError(id);
2476
2486
  const error = temporaryError || localError || validationError;
2477
2487
  return jsxs("div", {
2478
2488
  class: classnames(props.class, 'bio-properties-panel-entry', error ? 'has-error' : ''),
2479
2489
  "data-entry-id": id,
2480
- children: [createElement(FeelTextfield, {
2490
+ children: [createElement(TextInput, {
2481
2491
  ...props,
2492
+ Component: FeelTextfield,
2493
+ element: element,
2494
+ getValue: getValue,
2482
2495
  debounce: debounce,
2496
+ setValue: setValue,
2497
+ validate: validate,
2483
2498
  disabled: disabled,
2484
2499
  feel: feel,
2485
2500
  id: id,
2486
2501
  key: element,
2487
2502
  label: label,
2488
- onInput: onInput,
2489
- onError: onError,
2503
+ onError: setLocalError,
2490
2504
  onFocus: onFocus,
2491
2505
  onBlur: onBlur,
2492
2506
  placeholder: placeholder,
@@ -4022,14 +4036,8 @@ function TextArea(props) {
4022
4036
  setLocalValue(e.target.value);
4023
4037
  handleInput(e.target.value);
4024
4038
  };
4025
- const handleOnBlur = e => {
4026
- const trimmedValue = e.target.value.trim();
4027
-
4028
- // trim and commit on blur
4029
- onInput(trimmedValue);
4030
- if (onBlur) {
4031
- onBlur(e);
4032
- }
4039
+ const handleOnBlur = () => {
4040
+ onBlur?.(localValue);
4033
4041
  };
4034
4042
  useLayoutEffect(() => {
4035
4043
  autoResize && resizeToContents(ref.current);
@@ -4107,35 +4115,21 @@ function TextAreaEntry(props) {
4107
4115
  autoResize,
4108
4116
  tooltip
4109
4117
  } = props;
4118
+ const value = getValue(element);
4110
4119
  const globalError = useError(id);
4111
- const [localError, setLocalError] = useState(null);
4112
- let value = getValue(element);
4113
- useEffect(() => {
4114
- if (isFunction(validate)) {
4115
- const newValidationError = validate(value) || null;
4116
- setLocalError(newValidationError);
4117
- }
4118
- }, [value, validate]);
4119
- const onInput = useCallback(newValue => {
4120
- const value = getValue(element);
4121
- let newValidationError = null;
4122
- if (isFunction(validate)) {
4123
- newValidationError = validate(newValue) || null;
4124
- }
4125
- if (newValue !== value) {
4126
- setValue(newValue, newValidationError);
4127
- }
4128
- setLocalError(newValidationError);
4129
- }, [element, getValue, setValue, validate]);
4120
+ const localError = validate?.(value) || null;
4130
4121
  const error = globalError || localError;
4131
4122
  return jsxs("div", {
4132
4123
  class: classnames('bio-properties-panel-entry', error ? 'has-error' : ''),
4133
4124
  "data-entry-id": id,
4134
- children: [jsx(TextArea, {
4125
+ children: [jsx(TextInput, {
4126
+ Component: TextArea,
4127
+ getValue: getValue,
4128
+ setValue: setValue,
4129
+ validate: validate,
4135
4130
  id: id,
4136
4131
  label: label,
4137
4132
  value: value,
4138
- onInput: onInput,
4139
4133
  onFocus: onFocus,
4140
4134
  onBlur: onBlur,
4141
4135
  rows: rows,
@@ -4168,7 +4162,6 @@ function prefixId$1(id) {
4168
4162
 
4169
4163
  function Textfield(props) {
4170
4164
  const {
4171
- debounce,
4172
4165
  disabled = false,
4173
4166
  id,
4174
4167
  label,
@@ -4181,23 +4174,12 @@ function Textfield(props) {
4181
4174
  } = props;
4182
4175
  const [localValue, setLocalValue] = useState(value || '');
4183
4176
  const ref = useShowEntryEvent(id);
4184
-
4185
- /**
4186
- * @type { import('min-dash').DebouncedFunction }
4187
- */
4188
- const handleInputCallback = useDebounce(onInput, debounce);
4189
- const handleOnBlur = e => {
4190
- const trimmedValue = e.target.value.trim();
4191
-
4192
- // trim and commit on blur
4193
- onInput(trimmedValue);
4194
- if (onBlur) {
4195
- onBlur(e);
4196
- }
4177
+ const handleOnBlur = () => {
4178
+ onBlur?.(localValue);
4197
4179
  };
4198
4180
  const handleInput = newValue => {
4199
4181
  const newModelValue = newValue === '' ? undefined : newValue;
4200
- handleInputCallback(newModelValue);
4182
+ onInput(newModelValue);
4201
4183
  };
4202
4184
  const handleLocalInput = e => {
4203
4185
  if (e.target.value === localValue) {
@@ -4272,39 +4254,25 @@ function TextfieldEntry(props) {
4272
4254
  placeholder,
4273
4255
  tooltip
4274
4256
  } = props;
4257
+ const value = getValue(element);
4275
4258
  const globalError = useError(id);
4276
- const [localError, setLocalError] = useState(null);
4277
- let value = getValue(element);
4278
- useEffect(() => {
4279
- if (isFunction(validate)) {
4280
- const newValidationError = validate(value) || null;
4281
- setLocalError(newValidationError);
4282
- }
4283
- }, [value, validate]);
4284
- const onInput = useCallback(newValue => {
4285
- const value = getValue(element);
4286
- let newValidationError = null;
4287
- if (isFunction(validate)) {
4288
- newValidationError = validate(newValue) || null;
4289
- }
4290
- if (newValue !== value) {
4291
- setValue(newValue, newValidationError);
4292
- }
4293
- setLocalError(newValidationError);
4294
- }, [element, getValue, setValue, validate]);
4259
+ const localError = validate?.(value) || null;
4295
4260
  const error = globalError || localError;
4296
4261
  return jsxs("div", {
4297
4262
  class: classnames('bio-properties-panel-entry', error ? 'has-error' : ''),
4298
4263
  "data-entry-id": id,
4299
- children: [jsx(Textfield, {
4264
+ children: [jsx(TextInput, {
4265
+ Component: Textfield,
4300
4266
  debounce: debounce,
4301
4267
  disabled: disabled,
4268
+ getValue: getValue,
4302
4269
  id: id,
4303
4270
  label: label,
4304
- onInput: onInput,
4305
4271
  onFocus: onFocus,
4306
4272
  onBlur: onBlur,
4307
4273
  placeholder: placeholder,
4274
+ setValue: setValue,
4275
+ validate: validate,
4308
4276
  value: value,
4309
4277
  tooltip: tooltip,
4310
4278
  element: element