x-ui-design 0.6.12 → 0.6.13

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
@@ -1,5 +1,5 @@
1
1
  import require$$1 from 'react/jsx-runtime';
2
- import React, { useRef, useState, Children, isValidElement, Fragment, Suspense, useContext, useMemo, useEffect, useCallback, createContext, useImperativeHandle, useLayoutEffect } from 'react';
2
+ import React, { useRef, useState, Children, isValidElement, Fragment, Suspense, useContext, useMemo, useEffect, createContext, useImperativeHandle, useCallback, useLayoutEffect } from 'react';
3
3
  import { createPortal } from 'react-dom';
4
4
  import ReactDOMServer from 'react-dom/server';
5
5
 
@@ -974,6 +974,17 @@ function flattenChildren(children) {
974
974
  var css_248z$l = ".xUi-form-item{display:flex;position:relative}.xUi-form-item.noStyle{display:inline-flex;margin-bottom:0}.xUi-form-item-label{align-items:center;color:var(--xui-text-color);display:flex;font-size:var(--xui-font-size-md);font-weight:500;line-height:20px;margin-bottom:4px}.xUi-form-item-error{color:var(--xui-error-color);display:block;font-size:var(--xui-font-size-xs);line-height:16px;margin-bottom:8px;margin-top:4px;min-height:16px;position:relative;right:0;text-align:end;user-select:none}.xUi-form-item-required{color:var(--xui-error-color);display:inline-block;font-size:var(--xui-font-size-md);line-height:1;margin-left:4px;margin-right:4px}.xUi-form-item.horizontal{align-items:center;flex-direction:row;gap:4px}.xUi-form-item.vertical{align-self:flex-start;flex-direction:column}.xUi-form-item .xUi-input-container{width:-webkit-fill-available}";
975
975
  styleInject(css_248z$l);
976
976
 
977
+ const debounce = (func, delay) => {
978
+ let timeoutId = null;
979
+ return (...args) => {
980
+ if (timeoutId) {
981
+ clearTimeout(timeoutId);
982
+ }
983
+ timeoutId = setTimeout(() => {
984
+ func(...args);
985
+ }, delay);
986
+ };
987
+ };
977
988
  const FormItem$1 = ({
978
989
  prefixCls = prefixClsFormItem,
979
990
  name,
@@ -1112,12 +1123,14 @@ const FormItemChildComponent = ({
1112
1123
  ...props
1113
1124
  }) => {
1114
1125
  const formContext = useContext(FormContext);
1115
- const animationRef = useRef(null);
1116
1126
  const [wasNormalize, setWasNormalize] = useState(false);
1117
1127
  const {
1118
1128
  getFieldsValue
1119
1129
  } = formContext || {};
1120
- const handleChange = useCallback((e, option) => {
1130
+ const debouncedSetFieldValue = useRef(debounce((name, value) => {
1131
+ setFieldValue(name, value, undefined, undefined, true);
1132
+ }, 200)).current;
1133
+ const handleChange = (e, option) => {
1121
1134
  let rawValue = e?.target ? e.target.value : e;
1122
1135
  if (normalize) {
1123
1136
  const prevValue = fieldValue ?? props.value;
@@ -1126,18 +1139,16 @@ const FormItemChildComponent = ({
1126
1139
  if (rawValue === prevValue) {
1127
1140
  e.target.value = rawValue;
1128
1141
  setWasNormalize(prev => !prev);
1129
- if (animationRef.current) {
1130
- cancelAnimationFrame(animationRef.current);
1131
- }
1132
- animationRef.current = requestAnimationFrame(() => {
1142
+ const timeout = setTimeout(() => {
1133
1143
  document.querySelector(`[name='${name}']`)?.focus();
1134
- });
1144
+ clearTimeout(timeout);
1145
+ }, 0);
1135
1146
  return;
1136
1147
  }
1137
1148
  }
1138
- setFieldValue(name, rawValue, undefined, undefined, true);
1149
+ debouncedSetFieldValue(name, rawValue);
1139
1150
  onChange?.(e, option);
1140
- }, [fieldValue, props.value, name]);
1151
+ };
1141
1152
  const injectPropsIntoFinalLeaf = child => {
1142
1153
  if (! /*#__PURE__*/isValidElement(child)) {
1143
1154
  return child;
@@ -3006,12 +3017,7 @@ const InputComponent = ({
3006
3017
  value: rawInput
3007
3018
  }
3008
3019
  };
3009
- if (animationRef.current) {
3010
- cancelAnimationFrame(animationRef.current);
3011
- }
3012
- animationRef.current = requestAnimationFrame(() => {
3013
- props.onChange?.(eventWithMaskedValue);
3014
- });
3020
+ props.onChange?.(eventWithMaskedValue);
3015
3021
  };
3016
3022
  const handleClear = e => {
3017
3023
  if (mask) {