x-ui-design 0.3.94 → 0.3.97

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.
@@ -89,7 +89,7 @@ export interface FormInstance {
89
89
  setFieldValue: (name: string, value: RuleTypes) => void;
90
90
  getFieldValue: (name: string) => RuleTypes;
91
91
  validateFields: (nameList?: string[]) => Promise<boolean>;
92
- setFieldsValue: (values: Partial<Record<string, RuleTypes>>) => void;
92
+ setFieldsValue: (values: Partial<Record<string, RuleTypes>>, reset?: boolean | null | undefined) => void;
93
93
  getFieldsValue: (nameList?: string[]) => Record<string, RuleTypes>;
94
94
  isFieldTouched: (name: string) => boolean;
95
95
  getFieldsError: () => Pick<FieldError, 'errors' | 'name'>[];
package/dist/index.esm.js CHANGED
@@ -675,8 +675,8 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
675
675
  });
676
676
  }
677
677
  }
678
- function setFieldsValue(values) {
679
- Object.entries(values).forEach(([name, value]) => setFieldValue(name, value));
678
+ function setFieldsValue(values, reset) {
679
+ Object.entries(values).forEach(([name, value]) => setFieldValue(name, value, undefined, reset));
680
680
  }
681
681
  function setFields(fields) {
682
682
  fields.forEach(({
@@ -2738,31 +2738,25 @@ const InputComponent = /*#__PURE__*/forwardRef(({
2738
2738
  }
2739
2739
  }));
2740
2740
  useEffect(() => {
2741
- setInternalValue(mask ? applyMask(stripMask(`${value ?? ''}`, mask), mask) : `${value ?? ''}`);
2742
- }, [value, mask]);
2741
+ setInternalValue(mask ? applyMask(stripMask(`${value ?? ''}`, mask, maskChar), mask, maskChar) : `${value ?? ''}`);
2742
+ }, [value, mask, maskChar]);
2743
2743
  const handleChange = e => {
2744
2744
  const inputEl = inputRef.current;
2745
2745
  if (!inputEl) return;
2746
2746
  const rawInput = e.target.value;
2747
- const prevCaretPos = inputEl.selectionStart ?? rawInput.length;
2747
+ let nextCaret = inputEl.selectionStart ?? rawInput.length;
2748
2748
  const raw = mask ? rawInput.replace(maskRegex, '') : rawInput;
2749
- const masked = mask ? applyMask(raw, mask) : rawInput;
2749
+ const masked = mask ? applyMask(raw, mask, maskChar) : rawInput;
2750
2750
  setInternalValue(masked);
2751
2751
  if (mask) {
2752
2752
  requestAnimationFrame(() => {
2753
2753
  if (!inputEl) return;
2754
- let nextCaret = prevCaretPos;
2755
2754
  const isBackspace = lastKeyPressed.current === 'Backspace';
2756
2755
  const isDelete = lastKeyPressed.current === 'Delete';
2757
- if (isBackspace || isDelete) {
2758
- if (mask.includes(masked[nextCaret - 1])) {
2756
+ while (mask.includes(masked[nextCaret - 1])) {
2757
+ if (isBackspace || isDelete) {
2759
2758
  nextCaret--;
2760
- }
2761
- } else {
2762
- if (mask.includes(masked[nextCaret - 1])) {
2763
- nextCaret++;
2764
- }
2765
- while (nextCaret < masked.length && mask[nextCaret] !== maskChar) {
2759
+ } else {
2766
2760
  nextCaret++;
2767
2761
  }
2768
2762
  }