@event-chat/antd-item 0.2.2
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/LICENSE +21 -0
- package/README.md +23 -0
- package/dist/FormEvent.d.ts +11 -0
- package/dist/FormEvent.d.ts.map +1 -0
- package/dist/FormEvent.js +72 -0
- package/dist/FormInput.d.ts +15 -0
- package/dist/FormInput.d.ts.map +1 -0
- package/dist/FormInput.js +41 -0
- package/dist/FormItem.d.ts +11 -0
- package/dist/FormItem.d.ts.map +1 -0
- package/dist/FormItem.js +29 -0
- package/dist/FormList.d.ts +11 -0
- package/dist/FormList.d.ts.map +1 -0
- package/dist/FormList.js +46 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/utils.d.ts +48 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +75 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 快乐的小萌新
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Rslib project
|
|
2
|
+
|
|
3
|
+
## Setup
|
|
4
|
+
|
|
5
|
+
Install the dependencies:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Get started
|
|
12
|
+
|
|
13
|
+
Build the library:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm run build
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Build the library in watch mode:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm run dev
|
|
23
|
+
```
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FormProps as FormRawProps } from 'antd';
|
|
2
|
+
import { PropsWithChildren } from 'react';
|
|
3
|
+
import { FormEventInstance } from './utils';
|
|
4
|
+
declare const FormEvent: <ValuesType, Name extends string, Group extends string | undefined = undefined>({ children, form, group, name, ...props }: PropsWithChildren<FormProps<ValuesType, Name, Group>>) => import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
export default FormEvent;
|
|
6
|
+
interface FormProps<ValuesType, Name extends string, Group extends string | undefined = undefined> extends Omit<FormRawProps<ValuesType>, 'form'> {
|
|
7
|
+
form?: FormEventInstance<Name, Group>;
|
|
8
|
+
group?: Group;
|
|
9
|
+
name?: Name;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=FormEvent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormEvent.d.ts","sourceRoot":"","sources":["../src/FormEvent.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,MAAM,CAAC;AACjD,OAAO,EAAM,iBAAiB,EAAiB,MAAM,OAAO,CAAC;AAC7D,OAAO,EAGL,iBAAiB,EAIlB,MAAM,SAAS,CAAC;AAoCjB,QAAA,MAAM,SAAS,GAAI,UAAU,EAAE,IAAI,SAAS,MAAM,EAAE,KAAK,SAAS,MAAM,GAAG,SAAS,GAAG,SAAS,EAAE,2CAM/F,iBAAiB,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,4CAuBvD,CAAC;AAEF,eAAe,SAAS,CAAC;AAGzB,UAAU,SAAS,CACjB,UAAU,EACV,IAAI,SAAS,MAAM,EACnB,KAAK,SAAS,MAAM,GAAG,SAAS,GAAG,SAAS,CAC5C,SAAQ,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC9C,IAAI,CAAC,EAAE,iBAAiB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACtC,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,IAAI,CAAC,EAAE,IAAI,CAAC;CACb"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { memo, useMemo } from "react";
|
|
3
|
+
import { FormEventContext, getStringValue, useForm, useFormCom } from "./utils.js";
|
|
4
|
+
const FormProviderInner = ({ children, group, name, emit })=>/*#__PURE__*/ jsx(FormEventContext.Provider, {
|
|
5
|
+
value: {
|
|
6
|
+
group,
|
|
7
|
+
name,
|
|
8
|
+
emit
|
|
9
|
+
},
|
|
10
|
+
children: children
|
|
11
|
+
});
|
|
12
|
+
const FormProvider = /*#__PURE__*/ memo(FormProviderInner);
|
|
13
|
+
const FormInitialization = ({ children, form, group, name, ...props })=>{
|
|
14
|
+
const Form = useFormCom();
|
|
15
|
+
const [formInstance] = useForm({
|
|
16
|
+
group,
|
|
17
|
+
name
|
|
18
|
+
}, form);
|
|
19
|
+
return /*#__PURE__*/ jsx(Form, {
|
|
20
|
+
...props,
|
|
21
|
+
form: formInstance,
|
|
22
|
+
name: formInstance.name,
|
|
23
|
+
children: /*#__PURE__*/ jsx(FormProvider, {
|
|
24
|
+
group: formInstance.group,
|
|
25
|
+
name: formInstance.name,
|
|
26
|
+
emit: formInstance.emit,
|
|
27
|
+
children: children
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
const FormEvent = ({ children, form, group, name, ...props })=>{
|
|
32
|
+
const formName = useMemo(()=>getStringValue([
|
|
33
|
+
name,
|
|
34
|
+
form?.name
|
|
35
|
+
]), [
|
|
36
|
+
form?.name,
|
|
37
|
+
name
|
|
38
|
+
]);
|
|
39
|
+
const formGroup = useMemo(()=>getStringValue([
|
|
40
|
+
form?.group,
|
|
41
|
+
group
|
|
42
|
+
]), [
|
|
43
|
+
form?.group,
|
|
44
|
+
group
|
|
45
|
+
]);
|
|
46
|
+
const Form = useFormCom();
|
|
47
|
+
if (form?.emit && form.name && form.name === formName) {
|
|
48
|
+
const { focusField, ...formIns } = form;
|
|
49
|
+
return /*#__PURE__*/ jsx(Form, {
|
|
50
|
+
...props,
|
|
51
|
+
form: {
|
|
52
|
+
...formIns,
|
|
53
|
+
focusField: focusField ?? (()=>{})
|
|
54
|
+
},
|
|
55
|
+
children: /*#__PURE__*/ jsx(FormProvider, {
|
|
56
|
+
group: formGroup,
|
|
57
|
+
name: formName,
|
|
58
|
+
emit: form.emit,
|
|
59
|
+
children: children
|
|
60
|
+
})
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return /*#__PURE__*/ jsx(FormInitialization, {
|
|
64
|
+
...props,
|
|
65
|
+
form: form,
|
|
66
|
+
group: formGroup,
|
|
67
|
+
name: formName,
|
|
68
|
+
children: children
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
const src_FormEvent = FormEvent;
|
|
72
|
+
export { src_FormEvent as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { EventChatOptions, NamepathType, useEventChat } from '@event-chat/core';
|
|
2
|
+
import { ForwardedRef } from 'react';
|
|
3
|
+
import { ZodType } from 'zod';
|
|
4
|
+
declare const InputInner: <Schema extends ZodType | undefined = undefined, Type extends string | undefined = undefined>({ async, name, schema, type, callback, debug, onChange }: FormInputProps<Schema, Type>, ref?: ForwardedRef<HTMLInputElement>) => import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
declare const FormInput: (<Schema extends ZodType | undefined = undefined, Type extends string | undefined = undefined>(props: FormInputProps<Schema, Type> & {
|
|
6
|
+
ref?: ForwardedRef<HTMLInputElement>;
|
|
7
|
+
}) => ReturnType<typeof InputInner>) & {
|
|
8
|
+
displayName?: string;
|
|
9
|
+
};
|
|
10
|
+
export default FormInput;
|
|
11
|
+
export interface FormInputProps<Schema extends ZodType | undefined = undefined, Type extends string | undefined = undefined> extends Omit<EventChatOptions<NamepathType, Schema, string, Type, undefined>, 'group' | 'token'> {
|
|
12
|
+
name?: NamepathType;
|
|
13
|
+
onChange?: (value: Parameters<NonNullable<EventChatOptions<NamepathType, Schema, string, Type, undefined>['callback']>>[0]['detail'], options: ReturnType<typeof useEventChat>) => void;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=FormInput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormInput.d.ts","sourceRoot":"","sources":["../src/FormInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAe,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC7F,OAAO,EAAE,YAAY,EAAuB,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAO9B,QAAA,MAAM,UAAU,GACd,MAAM,SAAS,OAAO,GAAG,SAAS,GAAG,SAAS,EAC9C,IAAI,SAAS,MAAM,GAAG,SAAS,GAAG,SAAS,EAE3C,0DAA0D,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,EACtF,MAAM,YAAY,CAAC,gBAAgB,CAAC,4CAyBrC,CAAC;AAEF,QAAA,MAAM,SAAS,EAA6B,CAAC,CAC3C,MAAM,SAAS,OAAO,GAAG,SAAS,GAAG,SAAS,EAC9C,IAAI,SAAS,MAAM,GAAG,SAAS,GAAG,SAAS,EAE3C,KAAK,EAAE,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,YAAY,CAAC,gBAAgB,CAAC,CAAA;CAAE,KAC3E,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC,GAAG;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAM/D,eAAe,SAAS,CAAC;AAEzB,MAAM,WAAW,cAAc,CAC7B,MAAM,SAAS,OAAO,GAAG,SAAS,GAAG,SAAS,EAC9C,IAAI,SAAS,MAAM,GAAG,SAAS,GAAG,SAAS,CAC3C,SAAQ,IAAI,CAAC,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;IAChG,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,QAAQ,CAAC,EAAE,CACT,KAAK,EAAE,UAAU,CACf,WAAW,CAAC,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,UAAU,CAAC,CAAC,CACzF,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EACd,OAAO,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,KACrC,IAAI,CAAC;CACX"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createToken, useEventChat } from "@event-chat/core";
|
|
3
|
+
import { forwardRef, useMemo } from "react";
|
|
4
|
+
import { useFormEvent } from "./utils.js";
|
|
5
|
+
const isDefined = (value)=>void 0 !== value;
|
|
6
|
+
const convertPath = (path)=>('object' == typeof path ? [
|
|
7
|
+
...path
|
|
8
|
+
] : [
|
|
9
|
+
path
|
|
10
|
+
]).filter(isDefined);
|
|
11
|
+
const InputInner = ({ async, name, schema, type, callback, debug, onChange }, ref)=>{
|
|
12
|
+
const { group, parent } = useFormEvent();
|
|
13
|
+
const formName = useMemo(()=>{
|
|
14
|
+
const itemName = convertPath(name);
|
|
15
|
+
const namePaths = convertPath(parent).concat(itemName);
|
|
16
|
+
return (0 === namePaths.length ? [
|
|
17
|
+
createToken('input-name')
|
|
18
|
+
] : void 0) ?? (1 === namePaths.length && 'object' != typeof name ? name ?? namePaths : namePaths);
|
|
19
|
+
}, [
|
|
20
|
+
name,
|
|
21
|
+
parent
|
|
22
|
+
]);
|
|
23
|
+
const result = useEventChat(formName, {
|
|
24
|
+
callback: (record)=>{
|
|
25
|
+
callback?.(record);
|
|
26
|
+
onChange?.(record.detail, result);
|
|
27
|
+
},
|
|
28
|
+
async,
|
|
29
|
+
group,
|
|
30
|
+
schema,
|
|
31
|
+
type,
|
|
32
|
+
debug
|
|
33
|
+
});
|
|
34
|
+
return /*#__PURE__*/ jsx("input", {
|
|
35
|
+
ref: ref
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
const FormInput = /*#__PURE__*/ forwardRef(InputInner);
|
|
39
|
+
if ('production' !== process.env.NODE_ENV) FormInput.displayName = 'FormInput';
|
|
40
|
+
const src_FormInput = FormInput;
|
|
41
|
+
export { src_FormInput as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FormItemProps as FormItemRawProps } from 'antd';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { ZodType } from 'zod';
|
|
4
|
+
import { FormInputProps } from './FormInput';
|
|
5
|
+
import { FormInsType } from './utils';
|
|
6
|
+
declare const FormItem: <Schema extends ZodType | undefined = undefined, Type extends string | undefined = undefined>({ async, children, schema, type, callback, debug, onChange, ...props }: FormItemProps<Schema, Type>) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export default FormItem;
|
|
8
|
+
interface FormItemProps<Schema extends ZodType | undefined = undefined, Type extends string | undefined = undefined> extends Omit<FormItemRawProps, 'children' | 'name'>, FormInputProps<Schema, Type> {
|
|
9
|
+
children?: ReactNode | ((form: FormInsType) => ReactNode);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=FormItem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormItem.d.ts","sourceRoot":"","sources":["../src/FormItem.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,IAAI,gBAAgB,EAAE,MAAM,MAAM,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAC9B,OAAkB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,WAAW,EAA2B,MAAM,SAAS,CAAC;AAE/D,QAAA,MAAM,QAAQ,GACZ,MAAM,SAAS,OAAO,GAAG,SAAS,GAAG,SAAS,EAC9C,IAAI,SAAS,MAAM,GAAG,SAAS,GAAG,SAAS,EAC3C,wEASC,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,4CAoB7B,CAAC;AAEF,eAAe,QAAQ,CAAC;AAExB,UAAU,aAAa,CACrB,MAAM,SAAS,OAAO,GAAG,SAAS,GAAG,SAAS,EAC9C,IAAI,SAAS,MAAM,GAAG,SAAS,GAAG,SAAS,CAE3C,SAAQ,IAAI,CAAC,gBAAgB,EAAE,UAAU,GAAG,MAAM,CAAC,EAAE,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC;IACjF,QAAQ,CAAC,EAAE,SAAS,GAAG,CAAC,CAAC,IAAI,EAAE,WAAW,KAAK,SAAS,CAAC,CAAC;CAC3D"}
|
package/dist/FormItem.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import FormInput from "./FormInput.js";
|
|
3
|
+
import { convertName, useFormCom } from "./utils.js";
|
|
4
|
+
const FormItem = ({ async, children, schema, type, callback, debug, onChange, ...props })=>{
|
|
5
|
+
const Form = useFormCom();
|
|
6
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
7
|
+
children: [
|
|
8
|
+
/*#__PURE__*/ jsx(Form.Item, {
|
|
9
|
+
...props,
|
|
10
|
+
children: children
|
|
11
|
+
}),
|
|
12
|
+
props.name && /*#__PURE__*/ jsx(Form.Item, {
|
|
13
|
+
name: convertName(props.name),
|
|
14
|
+
hidden: true,
|
|
15
|
+
children: /*#__PURE__*/ jsx(FormInput, {
|
|
16
|
+
async: async,
|
|
17
|
+
name: props.name,
|
|
18
|
+
schema: schema,
|
|
19
|
+
type: type,
|
|
20
|
+
callback: callback,
|
|
21
|
+
debug: debug,
|
|
22
|
+
onChange: onChange
|
|
23
|
+
})
|
|
24
|
+
})
|
|
25
|
+
]
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const src_FormItem = FormItem;
|
|
29
|
+
export { src_FormItem as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NamepathType } from '@event-chat/core';
|
|
2
|
+
import { ComponentProps } from 'react';
|
|
3
|
+
import { ZodType } from 'zod';
|
|
4
|
+
import { FormInputProps } from './FormInput';
|
|
5
|
+
import { FormBaseInstance } from './utils';
|
|
6
|
+
declare const FormList: <Schema extends ZodType | undefined = undefined, Type extends string | undefined = undefined>({ async, name, schema, type, callback, children, debug, onChange, ...props }: FormListProps<Schema, Type>) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export default FormList;
|
|
8
|
+
interface FormListProps<Schema extends ZodType | undefined = undefined, Type extends string | undefined = undefined> extends Omit<ComponentProps<NonNullable<FormBaseInstance['List']>>, 'name'>, Omit<FormInputProps<Schema, Type>, 'name'> {
|
|
9
|
+
name: NamepathType;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=FormList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormList.d.ts","sourceRoot":"","sources":["../src/FormList.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,cAAc,EAA+B,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAC9B,OAAkB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAA2D,MAAM,SAAS,CAAC;AAUpG,QAAA,MAAM,QAAQ,GACZ,MAAM,SAAS,OAAO,GAAG,SAAS,GAAG,SAAS,EAC9C,IAAI,SAAS,MAAM,GAAG,SAAS,GAAG,SAAS,EAC3C,8EAUC,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,4CAsB7B,CAAC;AAEF,eAAe,QAAQ,CAAC;AAIxB,UAAU,aAAa,CACrB,MAAM,SAAS,OAAO,GAAG,SAAS,GAAG,SAAS,EAC9C,IAAI,SAAS,MAAM,GAAG,SAAS,GAAG,SAAS,CAE3C,SACE,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EACnE,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAC5C,IAAI,EAAE,YAAY,CAAC;CACpB"}
|
package/dist/FormList.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { memo } from "react";
|
|
3
|
+
import FormInput from "./FormInput.js";
|
|
4
|
+
import { FormEventContext, convertName, useFormCom, useFormEvent } from "./utils.js";
|
|
5
|
+
const FormListInner = ({ children, name: parent })=>{
|
|
6
|
+
const record = useFormEvent();
|
|
7
|
+
return /*#__PURE__*/ jsx(FormEventContext.Provider, {
|
|
8
|
+
value: {
|
|
9
|
+
...record,
|
|
10
|
+
parent
|
|
11
|
+
},
|
|
12
|
+
children: children
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
const ListItem = /*#__PURE__*/ memo(FormListInner);
|
|
16
|
+
const FormList = ({ async, name, schema, type, callback, children, debug, onChange, ...props })=>{
|
|
17
|
+
const Form = useFormCom();
|
|
18
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
19
|
+
children: [
|
|
20
|
+
/*#__PURE__*/ jsx(Form.List, {
|
|
21
|
+
...props,
|
|
22
|
+
name: 'object' == typeof name ? [
|
|
23
|
+
...name
|
|
24
|
+
] : name,
|
|
25
|
+
children: (fields, options, metas)=>/*#__PURE__*/ jsx(ListItem, {
|
|
26
|
+
name: name,
|
|
27
|
+
children: children(fields, options, metas)
|
|
28
|
+
})
|
|
29
|
+
}),
|
|
30
|
+
/*#__PURE__*/ jsx(Form.Item, {
|
|
31
|
+
name: convertName(name),
|
|
32
|
+
children: /*#__PURE__*/ jsx(FormInput, {
|
|
33
|
+
async: async,
|
|
34
|
+
name: convertName(name),
|
|
35
|
+
schema: schema,
|
|
36
|
+
type: type,
|
|
37
|
+
callback: callback,
|
|
38
|
+
debug: debug,
|
|
39
|
+
onChange: onChange
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
]
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
const src_FormList = FormList;
|
|
46
|
+
export { src_FormList as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import FormEventInner from './FormEvent';
|
|
2
|
+
import { FormBaseInstance } from './utils';
|
|
3
|
+
declare const observer: (FormCom: FormBaseInstance) => void;
|
|
4
|
+
declare const FormEvent: typeof FormEventInner & {
|
|
5
|
+
observer: typeof observer;
|
|
6
|
+
};
|
|
7
|
+
export { FormEvent };
|
|
8
|
+
export { default as FormItem } from './FormItem';
|
|
9
|
+
export { default as FormList } from './FormList';
|
|
10
|
+
export * from './utils';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,aAAa,CAAC;AACzC,OAAO,EAAW,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEpD,QAAA,MAAM,QAAQ,GAAI,SAAS,gBAAgB,KAAG,IAE7C,CAAC;AAEF,QAAA,MAAM,SAAS,EAAE,OAAO,cAAc,GAAG;IAAE,QAAQ,EAAE,OAAO,QAAQ,CAAA;CAKnE,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,CAAC;AACrB,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,cAAc,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import FormEvent from "./FormEvent.js";
|
|
2
|
+
import { AntdCom } from "./utils.js";
|
|
3
|
+
import FormItem from "./FormItem.js";
|
|
4
|
+
import FormList from "./FormList.js";
|
|
5
|
+
export * from "./utils.js";
|
|
6
|
+
const observer = (FormCom)=>{
|
|
7
|
+
AntdCom.form = FormCom;
|
|
8
|
+
};
|
|
9
|
+
const src_FormEvent = Object.assign(FormEvent, {
|
|
10
|
+
observer
|
|
11
|
+
});
|
|
12
|
+
export { src_FormEvent as FormEvent, FormItem, FormList };
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { EventDetailType, NamepathType } from '@event-chat/core';
|
|
2
|
+
import { Form, FormItemProps } from 'antd';
|
|
3
|
+
import { ComponentProps, FC, ReactNode } from 'react';
|
|
4
|
+
export declare const AntdCom: {
|
|
5
|
+
form?: FormBaseInstance;
|
|
6
|
+
};
|
|
7
|
+
export declare const FormEventContext: import("react").Context<FormEventContextInstance>;
|
|
8
|
+
export declare const getStringValue: <T extends NamepathType | undefined>(values: T[]) => T | undefined;
|
|
9
|
+
export declare const convertName: (path?: NamepathType) => string | number | (string | number)[] | undefined;
|
|
10
|
+
export declare const useForm: <Name extends NamepathType, Group extends string | undefined = undefined>(options?: FormOptions<Name, Group>, formInit?: FormEventInstance<Name, Group>) => readonly [import("antd").FormInstance<unknown> & {
|
|
11
|
+
group: Group | undefined;
|
|
12
|
+
name: string | Name;
|
|
13
|
+
emit: <Detail, CustomName extends NamepathType>(detail: Omit<EventDetailType<Detail, CustomName>, "group" | "id" | "origin" | "type">) => void;
|
|
14
|
+
}];
|
|
15
|
+
export declare const useFormInstance: <ValueType>() => Omit<import("antd").FormInstance<ValueType>, "focusField"> & {
|
|
16
|
+
focusField?: NonNullable<ComponentProps<typeof Form>["form"]>["focusField"];
|
|
17
|
+
} & {
|
|
18
|
+
group: string | undefined;
|
|
19
|
+
name: NamepathType | undefined;
|
|
20
|
+
emit: (<Detail, CustomName extends NamepathType>(record: Omit<EventDetailType<Detail, CustomName>, "group" | "id" | "origin" | "type">) => void) | undefined;
|
|
21
|
+
};
|
|
22
|
+
export declare const useFormCom: () => FormBaseInstance;
|
|
23
|
+
export declare const useFormEvent: () => FormEventContextInstance;
|
|
24
|
+
export interface FormEventContextInstance {
|
|
25
|
+
group?: string;
|
|
26
|
+
name?: NamepathType;
|
|
27
|
+
parent?: NamepathType;
|
|
28
|
+
emit?: <Detail, CustomName extends NamepathType>(record: Omit<EventDetailType<Detail, CustomName>, 'group' | 'id' | 'origin' | 'type'>) => void;
|
|
29
|
+
}
|
|
30
|
+
export interface FormEventInstance<Name extends NamepathType, Group extends string | undefined = undefined> extends FormInsType, FormOptions<Name, Group> {
|
|
31
|
+
emit?: <Detail, CustomName extends NamepathType>(record: Omit<EventDetailType<Detail, CustomName>, 'group' | 'id' | 'origin' | 'type'>) => void;
|
|
32
|
+
}
|
|
33
|
+
type FormOptions<Name extends NamepathType, Group extends string | undefined = undefined> = {
|
|
34
|
+
group?: Group;
|
|
35
|
+
name?: Name;
|
|
36
|
+
};
|
|
37
|
+
export interface FormBaseInstance extends FC<Pick<ComponentProps<typeof Form>, 'children' | 'form' | 'name'>> {
|
|
38
|
+
Item: FC<Pick<FormItemProps, 'hidden' | 'name'> & {
|
|
39
|
+
children?: ReactNode | ((form: FormInsType) => ReactNode);
|
|
40
|
+
}>;
|
|
41
|
+
List: FC<Pick<ComponentProps<typeof Form.List>, 'children' | 'name'>>;
|
|
42
|
+
useFormInstance: <Value>() => FormInsType<Value>;
|
|
43
|
+
}
|
|
44
|
+
export type FormInsType<ValueType = unknown> = Omit<NonNullable<ComponentProps<typeof Form<ValueType>>['form']>, 'focusField'> & {
|
|
45
|
+
focusField?: NonNullable<ComponentProps<typeof Form>['form']>['focusField'];
|
|
46
|
+
};
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"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"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createToken, useEventChat } from "@event-chat/core";
|
|
2
|
+
import { Form } from "antd";
|
|
3
|
+
import { createContext, useContext, useMemo } from "react";
|
|
4
|
+
import zod from "zod";
|
|
5
|
+
const AntdCom = {};
|
|
6
|
+
const FormEventContext = createContext({});
|
|
7
|
+
const getStringValue = (values)=>values.find((item)=>void 0 !== item && (!Array.isArray(item) || item.length > 0));
|
|
8
|
+
const convertName = (path)=>'object' == typeof path ? [
|
|
9
|
+
...path
|
|
10
|
+
] : path;
|
|
11
|
+
const useForm = (options, formInit)=>{
|
|
12
|
+
const { group, name, focusField } = formInit ?? {};
|
|
13
|
+
const [form] = Form.useForm(formInit ? {
|
|
14
|
+
...formInit,
|
|
15
|
+
focusField: focusField ?? (()=>{})
|
|
16
|
+
} : void 0);
|
|
17
|
+
const formName = useMemo(()=>getStringValue([
|
|
18
|
+
name,
|
|
19
|
+
options?.name
|
|
20
|
+
]) ?? createToken('form-event'), [
|
|
21
|
+
name,
|
|
22
|
+
options?.name
|
|
23
|
+
]);
|
|
24
|
+
const groupName = useMemo(()=>getStringValue([
|
|
25
|
+
group,
|
|
26
|
+
options?.group
|
|
27
|
+
]), [
|
|
28
|
+
group,
|
|
29
|
+
options?.group
|
|
30
|
+
]);
|
|
31
|
+
const { emit } = useEventChat(formName, {
|
|
32
|
+
schema: zod.array(zod.object({
|
|
33
|
+
name: zod.union([
|
|
34
|
+
zod.string(),
|
|
35
|
+
zod.number(),
|
|
36
|
+
zod.array(zod.union([
|
|
37
|
+
zod.string(),
|
|
38
|
+
zod.number()
|
|
39
|
+
]))
|
|
40
|
+
]),
|
|
41
|
+
value: zod.unknown()
|
|
42
|
+
})),
|
|
43
|
+
callback: ({ detail })=>detail.forEach((item)=>{
|
|
44
|
+
emit({
|
|
45
|
+
detail: item.value,
|
|
46
|
+
name: item.name
|
|
47
|
+
});
|
|
48
|
+
}),
|
|
49
|
+
group: groupName
|
|
50
|
+
});
|
|
51
|
+
const formInstance = Object.assign(form, {
|
|
52
|
+
group: groupName,
|
|
53
|
+
name: formName,
|
|
54
|
+
emit
|
|
55
|
+
});
|
|
56
|
+
return [
|
|
57
|
+
formInstance
|
|
58
|
+
];
|
|
59
|
+
};
|
|
60
|
+
const useFormInstance = ()=>{
|
|
61
|
+
const FormCom = useFormCom();
|
|
62
|
+
const form = FormCom.useFormInstance();
|
|
63
|
+
const { group, name, emit } = useFormEvent();
|
|
64
|
+
return Object.assign(form, {
|
|
65
|
+
group,
|
|
66
|
+
name,
|
|
67
|
+
emit
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
const useFormCom = ()=>AntdCom.form ?? Form;
|
|
71
|
+
const useFormEvent = ()=>{
|
|
72
|
+
const record = useContext(FormEventContext);
|
|
73
|
+
return record;
|
|
74
|
+
};
|
|
75
|
+
export { AntdCom, FormEventContext, convertName, getStringValue, useForm, useFormCom, useFormEvent, useFormInstance };
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@event-chat/antd-item",
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@rslib/core": "^0.18.4",
|
|
18
|
+
"@rstest/core": "^0.7.1",
|
|
19
|
+
"@rstest/coverage-istanbul": "^0.1.3",
|
|
20
|
+
"@storybook/addon-docs": "^10.1.4",
|
|
21
|
+
"@storybook/addon-onboarding": "^10.1.4",
|
|
22
|
+
"@storybook/react": "^10.1.4",
|
|
23
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
24
|
+
"@testing-library/react": "^16.3.0",
|
|
25
|
+
"antd": "^6.1.3",
|
|
26
|
+
"jsdom": "^26.1.0",
|
|
27
|
+
"storybook": "^10.1.4",
|
|
28
|
+
"storybook-addon-rslib": "^3.1.0",
|
|
29
|
+
"storybook-react-rsbuild": "^3.1.0",
|
|
30
|
+
"tsd": "^0.33.0",
|
|
31
|
+
"typescript-eslint": "^8.48.0",
|
|
32
|
+
"@event-chat/core": "0.2.1"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@event-chat/core": "*",
|
|
36
|
+
"antd": "^4.0.0 || ^5.0.0 || ^6.0.0",
|
|
37
|
+
"react": ">=18.0.0",
|
|
38
|
+
"react-dom": ">=18.0.0",
|
|
39
|
+
"zod": "^3.0.0 || ^4.0.0"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "rslib build",
|
|
43
|
+
"build:storybook": "storybook build",
|
|
44
|
+
"dev": "rslib build --watch",
|
|
45
|
+
"format": "prettier --write \"src/**/*.{ts,tsx,js,jsx}\"",
|
|
46
|
+
"format:check": "prettier --check \"src/**/*.{ts,tsx,js,jsx}\"",
|
|
47
|
+
"lint": "eslint \"src/**/*.{ts,tsx,js,jsx}\"",
|
|
48
|
+
"lint:fix": "eslint \"src/**/*.{ts,tsx,js,jsx}\" --fix",
|
|
49
|
+
"storybook": "storybook dev",
|
|
50
|
+
"test": "rstest",
|
|
51
|
+
"test:all": "tsd && rstest --coverage",
|
|
52
|
+
"test:coverage": "rstest --coverage",
|
|
53
|
+
"test:type": "tsd"
|
|
54
|
+
}
|
|
55
|
+
}
|