Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@
},
"dependencies": {
"@rc-component/async-validator": "^5.1.0",
"@rc-component/util": "^1.6.2",
"@rc-component/util": "^1.11.1",
"clsx": "^2.1.1"
},
"devDependencies": {
"@rc-component/father-plugin": "^2.0.1",
"@rc-component/father-plugin": "^2.2.0",
"@rc-component/np": "^1.0.2",
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/react": "^16.0.0",
Expand Down
4 changes: 1 addition & 3 deletions src/Field.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import toChildrenArray from '@rc-component/util/lib/Children/toArray';
import isEqual from '@rc-component/util/lib/isEqual';
import warning from '@rc-component/util/lib/warning';
import { isEqual, toArray as toChildrenArray, warning } from '@rc-component/util';
import * as React from 'react';
import FieldContext, { HOOK_MARK } from './FieldContext';
import type {
Expand Down
2 changes: 1 addition & 1 deletion src/FieldContext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import warning from '@rc-component/util/lib/warning';
import { warning } from '@rc-component/util';
import * as React from 'react';
import type { InternalFormInstance } from './interface';

Expand Down
2 changes: 1 addition & 1 deletion src/List.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import warning from '@rc-component/util/lib/warning';
import { warning } from '@rc-component/util';
import type {
InternalNamePath,
NamePath,
Expand Down
3 changes: 1 addition & 2 deletions src/hooks/useForm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { merge } from '@rc-component/util/lib/utils/set';
import warning from '@rc-component/util/lib/warning';
import { merge, warning } from '@rc-component/util';
import * as React from 'react';
import { HOOK_MARK } from '../FieldContext';
import type {
Expand Down
3 changes: 1 addition & 2 deletions src/hooks/useWatch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import warning from '@rc-component/util/lib/warning';
import { useEvent, warning } from '@rc-component/util';
import { useContext, useEffect, useMemo, useRef, useState } from 'react';
import FieldContext, { HOOK_MARK } from '../FieldContext';
import type {
Expand All @@ -10,7 +10,6 @@ import type {
} from '../interface';
import { isFormInstance } from '../utils/typeUtil';
import { getNamePath, getValue } from '../utils/valueUtil';
import { useEvent } from '@rc-component/util';

type ReturnPromise<T> = T extends Promise<infer ValueType> ? ValueType : never;
type GetGeneric<TForm extends FormInstance> = ReturnPromise<ReturnType<TForm['validateFields']>>;
Expand Down
21 changes: 19 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import type { FormRef, FormInstance } from './interface';
import type { FormRef } from './interface';
import Field from './Field';
import List from './List';
import useForm from './hooks/useForm';
Expand Down Expand Up @@ -33,6 +33,23 @@ RefForm.useWatch = useWatch;

export { Field, List, useForm, FormProvider, FieldContext, ListContext, useWatch };

export type { FormProps, FormInstance, FormRef };
export type { FieldProps } from './Field';
export type { FormProviderProps } from './FormContext';
export type {
FormInstance,
FormRef,
InternalNamePath,
Meta,
NamePath,
Rule,
RuleObject,
RuleRender,
Store,
StoreValue,
ValidateErrorEntity,
ValidateMessages,
ValidatorRule,
} from './interface';
Comment on lines +38 to +52
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

建议在此处补充导出更多常用的类型,例如 FieldData, Callbacks, ValidateOptions, ValidateFieldsRuleType。这些类型在外部(如 antd)使用时非常常见,统一从根入口导出可以提升开发体验并保持 API 的完整性。

Suggested change
export type {
FormInstance,
FormRef,
InternalNamePath,
Meta,
NamePath,
Rule,
RuleObject,
RuleRender,
Store,
StoreValue,
ValidateErrorEntity,
ValidateMessages,
ValidatorRule,
} from './interface';
export type {
FormInstance,
FormRef,
InternalNamePath,
Meta,
NamePath,
Rule,
RuleObject,
RuleRender,
Store,
StoreValue,
ValidateErrorEntity,
ValidateMessages,
ValidatorRule,
FieldData,
Callbacks,
ValidateOptions,
ValidateFields,
RuleType,
} from './interface';

export type { FormProps };

export default RefForm;
2 changes: 1 addition & 1 deletion src/utils/delayUtil.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { macroTask } from '../hooks/useNotifyWatch';
import raf from '@rc-component/util/lib/raf';
import { raf } from '@rc-component/util';

export default async function delayFrame() {
return new Promise<void>(resolve => {
Expand Down
3 changes: 1 addition & 2 deletions src/utils/validateUtil.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import RawAsyncValidator from '@rc-component/async-validator';
import * as React from 'react';
import warning from '@rc-component/util/lib/warning';
import { merge, warning } from '@rc-component/util';
import type {
InternalNamePath,
InternalValidateOptions,
Expand All @@ -9,7 +9,6 @@ import type {
RuleError,
} from '../interface';
import { defaultValidateMessages } from './messages';
import { merge } from '@rc-component/util/lib/utils/set';

// Remove incorrect original ts define
const AsyncValidator: any = RawAsyncValidator;
Expand Down
3 changes: 1 addition & 2 deletions src/utils/valueUtil.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import getValue from '@rc-component/util/lib/utils/get';
import setValue from '@rc-component/util/lib/utils/set';
import { get as getValue, set as setValue } from '@rc-component/util';
import type { InternalNamePath, NamePath, Store, EventArgs } from '../interface';
import { toArray } from './typeUtil';

Expand Down
2 changes: 1 addition & 1 deletion tests/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { act, fireEvent, render } from '@testing-library/react';
import { resetWarned } from '@rc-component/util/lib/warning';
import { resetWarned } from '@rc-component/util';
import React from 'react';
import type { FormInstance } from '../src';
import Form, { Field, useForm } from '../src';
Expand Down
4 changes: 1 addition & 3 deletions tests/initialValue.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { act, fireEvent, render } from '@testing-library/react';
import { resetWarned } from '@rc-component/util/lib/warning';
import { resetWarned } from '@rc-component/util';
import React, { useState } from 'react';
import Form, { Field, List, useForm, type FormInstance } from '../src';
import { changeValue, getInput } from './common';
Expand Down Expand Up @@ -166,11 +166,9 @@ describe('Form.InitialValues', () => {
fireEvent.click(container.querySelector('button'));
expect(formValue.users[0].last).toEqual('bbb');


fireEvent.click(container.querySelector('button'));
expect(formValue.users[0].last).toEqual('bbb');


fireEvent.click(container.querySelector('button'));

expect(container.querySelector<HTMLInputElement>('.first-name-input').value).toEqual('aaa');
Expand Down
2 changes: 1 addition & 1 deletion tests/list.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import { fireEvent, render, act } from '@testing-library/react';
import { resetWarned } from '@rc-component/util/lib/warning';
import { resetWarned } from '@rc-component/util';
import Form, { Field, List } from '../src';
import type { FormProps } from '../src';
import type { ListField, ListOperations, ListProps } from '../src/List';
Expand Down
Loading