x-ui-design 0.5.99 → 0.6.12

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
@@ -1112,42 +1112,32 @@ const FormItemChildComponent = ({
1112
1112
  ...props
1113
1113
  }) => {
1114
1114
  const formContext = useContext(FormContext);
1115
+ const animationRef = useRef(null);
1115
1116
  const [wasNormalize, setWasNormalize] = useState(false);
1116
1117
  const {
1117
1118
  getFieldsValue
1118
1119
  } = formContext || {};
1119
- const [localValue, setLocalValue] = useState(fieldValue);
1120
- useEffect(() => {
1121
- setLocalValue(fieldValue);
1122
- }, [fieldValue]);
1123
- const debounce = useCallback((func, delay = 300) => {
1124
- let timer;
1125
- return (...args) => {
1126
- clearTimeout(timer);
1127
- timer = setTimeout(() => func(...args), delay);
1128
- };
1129
- }, []);
1130
- const debouncedSetFieldValue = useMemo(() => debounce(setFieldValue, 300), [setFieldValue, debounce]);
1131
- const handleChange = (e, option) => {
1120
+ const handleChange = useCallback((e, option) => {
1132
1121
  let rawValue = e?.target ? e.target.value : e;
1133
1122
  if (normalize) {
1134
- const prevValue = localValue;
1123
+ const prevValue = fieldValue ?? props.value;
1135
1124
  const allValues = getFieldsValue?.();
1136
1125
  rawValue = normalize(rawValue, prevValue, allValues);
1137
1126
  if (rawValue === prevValue) {
1138
1127
  e.target.value = rawValue;
1139
1128
  setWasNormalize(prev => !prev);
1140
- const timeout = setTimeout(() => {
1129
+ if (animationRef.current) {
1130
+ cancelAnimationFrame(animationRef.current);
1131
+ }
1132
+ animationRef.current = requestAnimationFrame(() => {
1141
1133
  document.querySelector(`[name='${name}']`)?.focus();
1142
- clearTimeout(timeout);
1143
- }, 0);
1134
+ });
1144
1135
  return;
1145
1136
  }
1146
1137
  }
1147
- setLocalValue(rawValue);
1148
- debouncedSetFieldValue(name, rawValue, undefined, undefined, true);
1138
+ setFieldValue(name, rawValue, undefined, undefined, true);
1149
1139
  onChange?.(e, option);
1150
- };
1140
+ }, [fieldValue, props.value, name]);
1151
1141
  const injectPropsIntoFinalLeaf = child => {
1152
1142
  if (! /*#__PURE__*/isValidElement(child)) {
1153
1143
  return child;
@@ -1169,7 +1159,7 @@ const FormItemChildComponent = ({
1169
1159
  child: child,
1170
1160
  onChange: handleChange,
1171
1161
  key: `${name}_${wasNormalize}`,
1172
- value: localValue
1162
+ value: fieldValue ?? props.value
1173
1163
  }, 'dangerouslySetInnerHTML' in childProps ? {} : {
1174
1164
  __injected: true,
1175
1165
  ...(error ? {
@@ -3016,7 +3006,12 @@ const InputComponent = ({
3016
3006
  value: rawInput
3017
3007
  }
3018
3008
  };
3019
- props.onChange?.(eventWithMaskedValue);
3009
+ if (animationRef.current) {
3010
+ cancelAnimationFrame(animationRef.current);
3011
+ }
3012
+ animationRef.current = requestAnimationFrame(() => {
3013
+ props.onChange?.(eventWithMaskedValue);
3014
+ });
3020
3015
  };
3021
3016
  const handleClear = e => {
3022
3017
  if (mask) {