@bpmn-io/properties-panel 1.7.0 → 1.8.0

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
@@ -2741,6 +2741,7 @@ function TextArea(props) {
2741
2741
  * @param {Function} props.onBlur
2742
2742
  * @param {number} props.rows
2743
2743
  * @param {boolean} props.monospace
2744
+ * @param {Function} [props.validate]
2744
2745
  * @param {boolean} [props.disabled]
2745
2746
  */
2746
2747
  function TextAreaEntry(props) {
@@ -2755,12 +2756,38 @@ function TextAreaEntry(props) {
2755
2756
  rows,
2756
2757
  monospace,
2757
2758
  disabled,
2759
+ validate,
2758
2760
  onFocus,
2759
2761
  onBlur,
2760
2762
  autoResize
2761
2763
  } = props;
2762
- const value = getValue(element);
2763
- const error = useError(id);
2764
+ const [cachedInvalidValue, setCachedInvalidValue] = useState(null);
2765
+ const globalError = useError(id);
2766
+ const [localError, setLocalError] = useState(null);
2767
+ let value = getValue(element);
2768
+ const previousValue = usePrevious(value);
2769
+ useEffect(() => {
2770
+ if (isFunction(validate)) {
2771
+ const newValidationError = validate(value) || null;
2772
+ setLocalError(newValidationError);
2773
+ }
2774
+ }, [value]);
2775
+ const onInput = newValue => {
2776
+ let newValidationError = null;
2777
+ if (isFunction(validate)) {
2778
+ newValidationError = validate(newValue) || null;
2779
+ }
2780
+ if (newValidationError) {
2781
+ setCachedInvalidValue(newValue);
2782
+ } else {
2783
+ setValue(newValue);
2784
+ }
2785
+ setLocalError(newValidationError);
2786
+ };
2787
+ if (previousValue === value && localError) {
2788
+ value = cachedInvalidValue;
2789
+ }
2790
+ const error = globalError || localError;
2764
2791
  return jsxs("div", {
2765
2792
  class: classnames('bio-properties-panel-entry', error ? 'has-error' : ''),
2766
2793
  "data-entry-id": id,
@@ -2768,7 +2795,7 @@ function TextAreaEntry(props) {
2768
2795
  id: id,
2769
2796
  label: label,
2770
2797
  value: value,
2771
- onInput: setValue,
2798
+ onInput: onInput,
2772
2799
  onFocus: onFocus,
2773
2800
  onBlur: onBlur,
2774
2801
  rows: rows,