@bpmn-io/properties-panel 3.27.5 → 3.27.7

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
@@ -1972,6 +1972,50 @@ 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
+
1975
2019
  const noop$2 = () => {};
1976
2020
 
1977
2021
  /**
@@ -2001,7 +2045,6 @@ const noop$2 = () => {};
2001
2045
 
2002
2046
  function FeelTextfieldComponent(props) {
2003
2047
  const {
2004
- debounce,
2005
2048
  id,
2006
2049
  element,
2007
2050
  label,
@@ -2037,16 +2080,11 @@ function FeelTextfieldComponent(props) {
2037
2080
  const position = hasFocus ? document.activeElement.selectionStart : Infinity;
2038
2081
  _setFocus(position + offset);
2039
2082
  };
2040
-
2041
- /**
2042
- * @type { import('min-dash').DebouncedFunction }
2043
- */
2044
- const handleInputCallback = useDebounce(onInput, debounce);
2045
2083
  const handleInput = newValue => {
2046
2084
  // we don't commit empty FEEL expressions,
2047
2085
  // but instead serialize them as <undefined>
2048
2086
  const newModelValue = newValue === '' || newValue === '=' ? undefined : newValue;
2049
- handleInputCallback(newModelValue);
2087
+ onInput(newModelValue);
2050
2088
  };
2051
2089
  const handleFeelToggle = useStaticCallback(() => {
2052
2090
  if (feel === 'required') {
@@ -2074,14 +2112,8 @@ function FeelTextfieldComponent(props) {
2074
2112
  setFocus(-1);
2075
2113
  }
2076
2114
  };
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
- }
2115
+ const handleOnBlur = () => {
2116
+ onBlur?.(localValue);
2085
2117
  };
2086
2118
  const handleLint = useStaticCallback((lint = []) => {
2087
2119
  const syntaxError = lint.some(report => report.type === 'Syntax Error');
@@ -2468,46 +2500,28 @@ function FeelEntry(props) {
2468
2500
  placeholder,
2469
2501
  tooltip
2470
2502
  } = props;
2471
- const [validationError, setValidationError] = hooks.useState(null);
2472
2503
  const [localError, setLocalError] = hooks.useState(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 = hooks.useCallback(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
- }, [element, getValue, setValue, validate]);
2493
- const onError = hooks.useCallback(err => {
2494
- setLocalError(err);
2495
- }, []);
2504
+ const value = getValue(element);
2505
+ const validationError = validate?.(value) || null;
2496
2506
  const temporaryError = useError(id);
2497
2507
  const error = temporaryError || localError || validationError;
2498
2508
  return jsxRuntime.jsxs("div", {
2499
2509
  class: classnames(props.class, 'bio-properties-panel-entry', error ? 'has-error' : ''),
2500
2510
  "data-entry-id": id,
2501
- children: [preact.createElement(FeelTextfield, {
2511
+ children: [preact.createElement(TextInput, {
2502
2512
  ...props,
2513
+ Component: FeelTextfield,
2514
+ element: element,
2515
+ getValue: getValue,
2503
2516
  debounce: debounce,
2517
+ setValue: setValue,
2518
+ validate: validate,
2504
2519
  disabled: disabled,
2505
2520
  feel: feel,
2506
2521
  id: id,
2507
2522
  key: element,
2508
2523
  label: label,
2509
- onInput: onInput,
2510
- onError: onError,
2524
+ onError: setLocalError,
2511
2525
  onFocus: onFocus,
2512
2526
  onBlur: onBlur,
2513
2527
  placeholder: placeholder,
@@ -4043,14 +4057,8 @@ function TextArea(props) {
4043
4057
  setLocalValue(e.target.value);
4044
4058
  handleInput(e.target.value);
4045
4059
  };
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
- }
4060
+ const handleOnBlur = () => {
4061
+ onBlur?.(localValue);
4054
4062
  };
4055
4063
  hooks.useLayoutEffect(() => {
4056
4064
  autoResize && resizeToContents(ref.current);
@@ -4128,35 +4136,21 @@ function TextAreaEntry(props) {
4128
4136
  autoResize,
4129
4137
  tooltip
4130
4138
  } = props;
4139
+ const value = getValue(element);
4131
4140
  const globalError = useError(id);
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 = hooks.useCallback(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
- }, [element, getValue, setValue, validate]);
4141
+ const localError = validate?.(value) || null;
4151
4142
  const error = globalError || localError;
4152
4143
  return jsxRuntime.jsxs("div", {
4153
4144
  class: classnames('bio-properties-panel-entry', error ? 'has-error' : ''),
4154
4145
  "data-entry-id": id,
4155
- children: [jsxRuntime.jsx(TextArea, {
4146
+ children: [jsxRuntime.jsx(TextInput, {
4147
+ Component: TextArea,
4148
+ getValue: getValue,
4149
+ setValue: setValue,
4150
+ validate: validate,
4156
4151
  id: id,
4157
4152
  label: label,
4158
4153
  value: value,
4159
- onInput: onInput,
4160
4154
  onFocus: onFocus,
4161
4155
  onBlur: onBlur,
4162
4156
  rows: rows,
@@ -4189,7 +4183,6 @@ function prefixId$1(id) {
4189
4183
 
4190
4184
  function Textfield(props) {
4191
4185
  const {
4192
- debounce,
4193
4186
  disabled = false,
4194
4187
  id,
4195
4188
  label,
@@ -4202,23 +4195,12 @@ function Textfield(props) {
4202
4195
  } = props;
4203
4196
  const [localValue, setLocalValue] = hooks.useState(value || '');
4204
4197
  const ref = useShowEntryEvent(id);
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
- }
4198
+ const handleOnBlur = () => {
4199
+ onBlur?.(localValue);
4218
4200
  };
4219
4201
  const handleInput = newValue => {
4220
4202
  const newModelValue = newValue === '' ? undefined : newValue;
4221
- handleInputCallback(newModelValue);
4203
+ onInput(newModelValue);
4222
4204
  };
4223
4205
  const handleLocalInput = e => {
4224
4206
  if (e.target.value === localValue) {
@@ -4293,39 +4275,25 @@ function TextfieldEntry(props) {
4293
4275
  placeholder,
4294
4276
  tooltip
4295
4277
  } = props;
4278
+ const value = getValue(element);
4296
4279
  const globalError = useError(id);
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 = hooks.useCallback(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
- }, [element, getValue, setValue, validate]);
4280
+ const localError = validate?.(value) || null;
4316
4281
  const error = globalError || localError;
4317
4282
  return jsxRuntime.jsxs("div", {
4318
4283
  class: classnames('bio-properties-panel-entry', error ? 'has-error' : ''),
4319
4284
  "data-entry-id": id,
4320
- children: [jsxRuntime.jsx(Textfield, {
4285
+ children: [jsxRuntime.jsx(TextInput, {
4286
+ Component: Textfield,
4321
4287
  debounce: debounce,
4322
4288
  disabled: disabled,
4289
+ getValue: getValue,
4323
4290
  id: id,
4324
4291
  label: label,
4325
- onInput: onInput,
4326
4292
  onFocus: onFocus,
4327
4293
  onBlur: onBlur,
4328
4294
  placeholder: placeholder,
4295
+ setValue: setValue,
4296
+ validate: validate,
4329
4297
  value: value,
4330
4298
  tooltip: tooltip,
4331
4299
  element: element
@@ -4349,7 +4317,7 @@ function prefixId(id) {
4349
4317
  return `bio-properties-panel-${id}`;
4350
4318
  }
4351
4319
 
4352
- const DEFAULT_DEBOUNCE_TIME = 300;
4320
+ const DEFAULT_DEBOUNCE_TIME = 600;
4353
4321
 
4354
4322
  /**
4355
4323
  * Creates a debounced version of a function, delaying its execution based on `debounceDelay`.