@tiny-codes/react-easy 1.0.6 → 1.0.8
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/CHANGELOG.md +16 -0
- package/es/components/ConfirmAction/index.d.ts +1 -45
- package/es/components/FloatDrawer/index.d.ts +173 -0
- package/es/components/FloatDrawer/index.js +173 -0
- package/es/components/FloatDrawer/index.js.map +1 -0
- package/es/components/FloatDrawer/style/index.d.ts +3 -0
- package/es/components/FloatDrawer/style/index.js +151 -0
- package/es/components/FloatDrawer/style/index.js.map +1 -0
- package/es/components/ModalAction/index.d.ts +3 -32
- package/es/components/ModalAction/index.js +8 -5
- package/es/components/ModalAction/index.js.map +1 -1
- package/es/components/index.d.ts +2 -0
- package/es/components/index.js +1 -0
- package/es/components/index.js.map +1 -1
- package/es/utils/color.d.ts +8 -0
- package/es/utils/color.js +45 -0
- package/es/utils/color.js.map +1 -0
- package/es/utils/index.d.ts +1 -0
- package/es/utils/index.js +1 -1
- package/es/utils/index.js.map +1 -1
- package/lib/components/ConfirmAction/index.d.ts +1 -45
- package/lib/components/FloatDrawer/index.d.ts +173 -0
- package/lib/components/FloatDrawer/index.js +193 -0
- package/lib/components/FloatDrawer/index.js.map +7 -0
- package/lib/components/FloatDrawer/style/index.d.ts +3 -0
- package/lib/components/FloatDrawer/style/index.js +211 -0
- package/lib/components/FloatDrawer/style/index.js.map +7 -0
- package/lib/components/ModalAction/index.d.ts +3 -32
- package/lib/components/ModalAction/index.js +6 -4
- package/lib/components/ModalAction/index.js.map +2 -2
- package/lib/components/index.d.ts +2 -0
- package/lib/components/index.js +3 -0
- package/lib/components/index.js.map +2 -2
- package/lib/utils/color.d.ts +8 -0
- package/lib/utils/color.js +53 -0
- package/lib/utils/color.js.map +7 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +23 -0
- package/lib/utils/index.js.map +3 -3
- package/package.json +4 -3
|
@@ -70,11 +70,11 @@ export interface FormCompPropsConstraint<FD> {
|
|
|
70
70
|
*/
|
|
71
71
|
...triggerEventData: any[]) => unknown | Promise<unknown>) => void;
|
|
72
72
|
/**
|
|
73
|
-
* **EN:** Listen to the open and close status of the dialog. When `
|
|
73
|
+
* **EN:** Listen to the open and close status of the dialog. When `destroyOnHidden` is set to
|
|
74
74
|
* false, the form component instance is cached, and the dialog can only be listened to in this
|
|
75
75
|
* way
|
|
76
76
|
*
|
|
77
|
-
* **CN:** 监听弹框打开关闭状态。当`
|
|
77
|
+
* **CN:** 监听弹框打开关闭状态。当`destroyOnHidden`设置为false时,表单组件实例被缓存,只能通过这种方式监听弹框
|
|
78
78
|
*
|
|
79
79
|
* @param handler Event handler | 事件处理函数
|
|
80
80
|
*/
|
|
@@ -160,36 +160,7 @@ export declare const genModalActionRenderer: (defaultProps: Partial<ModalActionP
|
|
|
160
160
|
* @param WrappedComponent ModalAction component | ModalAction组件
|
|
161
161
|
* @param defaultProps Default properties | 默认属性
|
|
162
162
|
*/
|
|
163
|
-
export declare const withDefaultModalActionProps: <FD extends object, CP extends FormCompPropsConstraint<FD>, TP extends object, E extends keyof TP, CRef extends object>(WrappedComponent: ComponentType<Omit<ModalProps, "onOk"> & ModalActionTrigger<FD, CP, TP, E> & {
|
|
164
|
-
/**
|
|
165
|
-
* **EN:** Form editing component, do not use the Form component inside the component, the form
|
|
166
|
-
* component and form instance are automatically created by the parent component
|
|
167
|
-
*
|
|
168
|
-
* **CN:** 表单编辑组件,组件内部不要使用Form组件,表单组件及表单实例由父组件自动创建
|
|
169
|
-
*/
|
|
170
|
-
formComp: ComponentType<CP & RefAttributes<CRef>>;
|
|
171
|
-
/**
|
|
172
|
-
* **EN:** Props of the form editing component
|
|
173
|
-
*
|
|
174
|
-
* **CN:** 表单编辑组件的Props属性
|
|
175
|
-
*/
|
|
176
|
-
formProps?: Omit<CP, keyof FormCompPropsConstraint<FD_1>> | undefined;
|
|
177
|
-
/**
|
|
178
|
-
* **EN:** The callback when clicks the confirmation button, support asynchronous saving, return
|
|
179
|
-
* `SubmitWithoutClosingSymbol` can prevent the dialog from closing, return other values will be
|
|
180
|
-
* passed to the `afterOk` event, if any
|
|
181
|
-
*
|
|
182
|
-
* **CN:** 点击确认按钮的回调,支持异步保存,返回`SubmitWithoutClosingSymbol`可以阻止弹框关闭,返回其他值会传递给`afterOk`事件,如果有的话
|
|
183
|
-
*/
|
|
184
|
-
onOk?: ((formData: FD, ...args: Parameters<TP[E]>) => unknown | Promise<unknown>) | undefined;
|
|
185
|
-
/**
|
|
186
|
-
* **EN:** The callback after the confirmation event is completed, it will not be triggered when
|
|
187
|
-
* it fails, the parameter is the return value of `onOk`
|
|
188
|
-
*
|
|
189
|
-
* **CN:** 确认事件完成后的回调,失败时不会触发,参数为`onOk`的返回值
|
|
190
|
-
*/
|
|
191
|
-
afterOk?: ((data?: any) => void) | undefined;
|
|
192
|
-
} & RefAttributes<ModalActionRef<CRef>>>, defaultProps?: Partial<ModalActionProps<FD, CP, TP, E, CRef>> | (() => Partial<ModalActionProps<FD, CP, TP, E, CRef>>) | undefined) => import("react").ForwardRefExoticComponent<Omit<ModalProps, "onOk"> & ModalActionTrigger<FD, CP, TP, E> & {
|
|
163
|
+
export declare const withDefaultModalActionProps: <FD extends object, CP extends FormCompPropsConstraint<FD>, TP extends object, E extends keyof TP, CRef extends object>(WrappedComponent: ComponentType<ModalActionProps<FD, CP, TP, E, CRef> & RefAttributes<ModalActionRef<CRef>>>, defaultProps?: Partial<ModalActionProps<FD, CP, TP, E, CRef>> | (() => Partial<ModalActionProps<FD, CP, TP, E, CRef>>)) => import("react").ForwardRefExoticComponent<Omit<ModalProps, "onOk"> & ModalActionTrigger<FD, CP, TP, E> & {
|
|
193
164
|
/**
|
|
194
165
|
* **EN:** Form editing component, do not use the Form component inside the component, the form
|
|
195
166
|
* component and form instance are automatically created by the parent component
|
|
@@ -54,11 +54,12 @@ var genModalActionRenderer = (defaultProps) => {
|
|
|
54
54
|
triggerProps,
|
|
55
55
|
open: openInProps,
|
|
56
56
|
destroyOnClose = true,
|
|
57
|
+
destroyOnHidden = true,
|
|
57
58
|
maskClosable = false,
|
|
58
59
|
onOk,
|
|
59
60
|
afterOk,
|
|
60
61
|
onCancel,
|
|
61
|
-
|
|
62
|
+
afterClose,
|
|
62
63
|
children,
|
|
63
64
|
...restProps
|
|
64
65
|
} = mergedProps;
|
|
@@ -73,7 +74,7 @@ var genModalActionRenderer = (defaultProps) => {
|
|
|
73
74
|
const formRef = (0, import_react.useRef)(form);
|
|
74
75
|
formRef.current = form;
|
|
75
76
|
const destroyOnCloseRef = (0, import_react.useRef)(destroyOnClose);
|
|
76
|
-
destroyOnCloseRef.current = destroyOnClose;
|
|
77
|
+
destroyOnCloseRef.current = destroyOnClose || destroyOnHidden;
|
|
77
78
|
const openListenerRef = (0, import_react.useRef)(void 0);
|
|
78
79
|
(0, import_react.useEffect)(() => {
|
|
79
80
|
if (openInProps) {
|
|
@@ -145,6 +146,7 @@ var genModalActionRenderer = (defaultProps) => {
|
|
|
145
146
|
open,
|
|
146
147
|
confirmLoading: isSaving,
|
|
147
148
|
destroyOnClose,
|
|
149
|
+
destroyOnHidden,
|
|
148
150
|
maskClosable,
|
|
149
151
|
onOk: async (e) => {
|
|
150
152
|
var _a;
|
|
@@ -181,9 +183,9 @@ var genModalActionRenderer = (defaultProps) => {
|
|
|
181
183
|
hideModal();
|
|
182
184
|
onCancel == null ? void 0 : onCancel(e);
|
|
183
185
|
},
|
|
184
|
-
|
|
186
|
+
afterClose: () => {
|
|
185
187
|
hideModal();
|
|
186
|
-
|
|
188
|
+
afterClose == null ? void 0 : afterClose();
|
|
187
189
|
},
|
|
188
190
|
...restProps
|
|
189
191
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/ModalAction/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import type { ComponentType, FC, ForwardedRef, ReactElement, ReactNode, RefAttributes } from 'react';\nimport { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';\nimport type { ButtonProps, FormInstance, ModalProps, SwitchProps } from 'antd';\nimport { Button, Form, Modal, Switch, Typography } from 'antd';\nimport type { LinkProps } from 'antd/es/typography/Link';\nimport { isForwardRef } from 'react-is';\nimport useContextValidator from '../../hooks/useContextValidator';\n\n/**\n * **EN:** Symbol for not closing the dialog when submitting the form, which takes effect when\n * returning in the `onSave` event of the editing form component\n *\n * **CN:** 提交表单时不关闭弹框的Symbol,在编辑表单组件的`onSave`事件中返回时生效\n */\nexport const SubmitWithoutClosingSymbol = Symbol('[SubmitWithoutClose]');\n\nexport type ModalActionProps<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n> = Omit<ModalProps, 'onOk'> &\n ModalActionTrigger<FD, CP, TP, E> & {\n /**\n * **EN:** Form editing component, do not use the Form component inside the component, the form\n * component and form instance are automatically created by the parent component\n *\n * **CN:** 表单编辑组件,组件内部不要使用Form组件,表单组件及表单实例由父组件自动创建\n */\n formComp: ComponentType<CP & RefAttributes<CRef>>;\n /**\n * **EN:** Props of the form editing component\n *\n * **CN:** 表单编辑组件的Props属性\n */\n formProps?: Omit<CP, keyof FormCompPropsConstraint<FD>>;\n /**\n * **EN:** The callback when clicks the confirmation button, support asynchronous saving, return\n * `SubmitWithoutClosingSymbol` can prevent the dialog from closing, return other values will be\n * passed to the `afterOk` event, if any\n *\n * **CN:** 点击确认按钮的回调,支持异步保存,返回`SubmitWithoutClosingSymbol`可以阻止弹框关闭,返回其他值会传递给`afterOk`事件,如果有的话\n */\n onOk?: (\n formData: FD,\n // @ts-expect-error: because TP[E] should be a function type\n ...args: Parameters<TP[E]>\n ) => unknown | Promise<unknown>;\n /**\n * **EN:** The callback after the confirmation event is completed, it will not be triggered when\n * it fails, the parameter is the return value of `onOk`\n *\n * **CN:** 确认事件完成后的回调,失败时不会触发,参数为`onOk`的返回值\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n afterOk?: (data?: any) => void;\n };\n\nexport interface FormCompPropsConstraint<FD> {\n /**\n * **EN:** Automatically generated form instance, use this form instance in FormComp, do not\n * create a new instance\n *\n * **CN:** 自动生成的表单实例,编辑表单要使用这个表单实例,不要新创建实例\n */\n form: FormInstance<FD>;\n /**\n * **EN:** Register the form save event, the callback function passed in will be called when the\n * confirm button is clicked, support asynchronous saving\n *\n * **CN:** 注册表单保存事件,传入的回调函数会在点击确认按钮时被调用,支持异步保存\n *\n * @param handler Event handler | 事件处理函数\n */\n onSave: (\n handler: (\n /**\n * **EN:** Form data\n *\n * **CN:** 表单数据\n */\n formData: FD,\n /**\n * **EN:** Trigger click event data, for example, for the `Switch` type trigger, you can get\n * the value of the switch; for the `Button` type trigger, you can get the click event object\n * of the button\n *\n * **CN:** 触发器点击的事件数据,例如,对于`Switch`类型的触发器,可以获取点击开关的值;对于`Button`类型的触发器,可以获取按钮的点击事件对象\n */\n ...triggerEventData: any[]\n ) => unknown | Promise<unknown>\n ) => void;\n /**\n * **EN:** Listen to the open and close status of the dialog. When `destroyOnClose` is set to\n * false, the form component instance is cached, and the dialog can only be listened to in this\n * way\n *\n * **CN:** 监听弹框打开关闭状态。当`destroyOnClose`设置为false时,表单组件实例被缓存,只能通过这种方式监听弹框\n *\n * @param handler Event handler | 事件处理函数\n */\n onOpenChange: (handler: ModalProps['afterOpenChange']) => void;\n /**\n * **EN:** Set the dialog open status\n *\n * **CN:** 设置弹框打开状态\n *\n * @param open Whether is open or not | 弹窗是否打开\n */\n setOpen: (open: boolean) => void;\n /**\n * **EN:** Modify the properties of the dialog, such as title, width, button properties, etc.\n *\n * **CN:** 修改弹窗的属性,例如标题、宽度,按钮属性等\n */\n updateModalProps: (props: Partial<ModalProps>) => void;\n /**\n * **EN:** Trigger click event data, for example, for the `Switch` type trigger, you can get the\n * value of the switch; for the `Button` type trigger, you can get the click event object of the\n * button\n *\n * **CN:** 触发器点击的事件数据,例如,对于`Switch`类型的触发器,可以获取点击开关的值,对于`Button`类型的触发器,可以获取按钮的点击事件对象\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n triggerEventData?: any[];\n}\n\nexport interface ModalActionTrigger<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n> {\n /**\n * **EN:** Trigger component, click to show the dialog\n *\n * **CN:** 弹窗触发器组件,点击触发显示弹框\n */\n triggerComponent?: ComponentType<TP> | FC<TP>;\n /**\n * **EN:** Props of the trigger component\n *\n * **CN:** 触发器组件的Props属性\n */\n triggerProps?: TP & {\n /**\n * **EN:** Set a custom function to determine whether to show the trigger button\n *\n * **CN:** 设置一个自定义函数,用于判断是否显示触发器按钮\n *\n * @default true\n *\n * @param formProps Form component props | 表单组件的props\n */\n show?: boolean | ((formProps?: Omit<CP, keyof FormCompPropsConstraint<FD>>) => boolean);\n };\n /**\n * **EN:** The event name that triggers the dialog\n *\n * **CN:** 触发弹窗的事件名称\n *\n * - `Button`: 'onClick'\n * - `Switch`: 'onChange'\n * - `Link`: 'onClick'\n */\n triggerEvent?: E;\n /**\n * **EN:** Custom trigger content\n *\n * **CN:** 自定义触发器内容\n */\n children?: ReactNode;\n}\nexport type ModalActionRef<R> = R & {\n /**\n * **EN:** Show the dialog\n *\n * **CN:** 显示弹框\n */\n show: () => void;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const genModalActionRenderer = (defaultProps: Partial<ModalActionProps<any, any, any, never, never>>) => {\n const ModalActionRenderer = <\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n >(\n props: ModalActionProps<FD, CP, TP, E, CRef>,\n ref: ForwardedRef<ModalActionRef<CRef>>\n ) => {\n const [userModalProps, setUserModalProps] = useState<Partial<ModalProps>>({});\n let mergedProps = mergeProps<FD, CP, TP, E, CRef>(defaultProps, props);\n mergedProps = mergeProps(mergedProps, userModalProps as typeof props);\n const {\n formComp,\n formProps,\n triggerComponent: Trigger = Button,\n triggerEvent = 'onClick' as E,\n triggerProps,\n open: openInProps,\n destroyOnClose = true,\n maskClosable = false,\n onOk,\n afterOk,\n onCancel,\n onClose,\n children,\n ...restProps\n } = mergedProps;\n useContextValidator();\n const FormComp = formComp as ComponentType<FormCompPropsConstraint<FD> & RefAttributes<CRef>>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const triggerEventArgsRef = useRef<any[]>(undefined);\n const [open, setOpen] = useState(false);\n const saveFuncRef = useRef<(formData: FD, ...args: any[]) => unknown>(undefined);\n const [isSaving, setIsSaving] = useState(false);\n const [formCompRef, setFormCompRef] = useState<CRef | null>(null);\n const [form, setForm] = useState<FormInstance<FD>>();\n const formRef = useRef<FormInstance<FD>>(form);\n formRef.current = form;\n const destroyOnCloseRef = useRef(destroyOnClose);\n destroyOnCloseRef.current = destroyOnClose;\n const openListenerRef = useRef<ModalProps['afterOpenChange']>(undefined);\n\n // Listen to the open props changes\n useEffect(() => {\n if (openInProps) {\n setOpen(openInProps);\n }\n }, [openInProps]);\n\n // Reset the form after closed\n useEffect(() => {\n if (!destroyOnCloseRef.current && open && formRef.current) {\n formRef.current.resetFields();\n }\n }, [open]);\n\n // show trigger\n const showInProps = triggerProps?.show;\n const showTrigger = useMemo(() => {\n if (typeof showInProps === 'boolean') {\n return showInProps;\n } else if (typeof showInProps === 'function') {\n return showInProps(formProps);\n }\n return true;\n }, [showInProps, formProps]);\n\n // Show the dialog\n const showModal = useCallback(() => {\n setOpen(true);\n openListenerRef.current?.(true);\n }, []);\n // Hide the dialog\n const hideModal = useCallback(() => {\n setOpen(false);\n openListenerRef.current?.(false);\n }, []);\n // Set the dialog status listener\n const setOpenListener = useCallback(\n (listener: ModalProps['afterOpenChange']) => {\n openListenerRef.current = listener;\n // Call once when initialized\n openListenerRef.current?.(open);\n },\n [open]\n );\n // Receive the onSave callback method passed by the form component\n const setOnSaveHandler: FormCompPropsConstraint<FD>['onSave'] = useCallback((handler) => {\n saveFuncRef.current = handler;\n }, []);\n // Set the dialog status and trigger the onOpenChange event of the form component\n const handleSetOpen = useCallback((open: boolean) => {\n setOpen(open);\n openListenerRef.current?.(open);\n }, []);\n\n // Output ref\n useImperativeHandle(ref, () => ({ ...formCompRef, show: showModal }) as ModalActionRef<CRef>, [\n formCompRef,\n showModal,\n ]);\n\n // Render the trigger component\n return (\n <>\n {showTrigger && (\n <Trigger\n {...triggerProps}\n // Trigger event\n {...((triggerEvent\n ? {\n [triggerEvent]: (...args: any[]) => {\n triggerEventArgsRef.current = args;\n showModal();\n if (triggerProps && typeof triggerProps[triggerEvent] === 'function') {\n (triggerProps[triggerEvent] as (...args: any[]) => void)(...args);\n }\n },\n }\n : {}) as TP)}\n >\n {(triggerProps as { children?: ReactNode }).children ?? children}\n </Trigger>\n )}\n <Modal\n open={open}\n confirmLoading={isSaving}\n destroyOnClose={destroyOnClose}\n maskClosable={maskClosable}\n onOk={async (e) => {\n let formData: FD;\n try {\n formData = (await form?.validateFields()) as FD;\n } catch (e) {\n // Validation error, should not throw error\n return;\n }\n if (Object.keys(formData).length === 0) {\n console.warn(\n 'form.getFieldsValue() is empty. Please use the form instance passed to formComp instead of creating the form instance yourself.'\n );\n }\n try {\n setIsSaving(true);\n // First call onSave of the form component\n let result = await saveFuncRef.current?.(formData, ...(triggerEventArgsRef.current ?? []));\n // The onSave of the form component has the ability to prevent the dialog from closing\n if (result === SubmitWithoutClosingSymbol) {\n throw new Error('SubmitWithoutClosing');\n }\n // Then call onOk of the dialog, support asynchronous, and will pass the return value of onSave, if any\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n result = await onOk?.((result as FD) ?? formData, ...((triggerEventArgsRef.current ?? []) as any));\n // onOk also has the ability to prevent the dialog from closing\n if (result === SubmitWithoutClosingSymbol) {\n throw new Error('SubmitWithoutClosing');\n }\n // If onOK is successful, close the dialog and trigger the afterOk event\n hideModal();\n afterOk?.(result);\n } catch (error) {\n console.error(error);\n } finally {\n setIsSaving(false);\n }\n }}\n onCancel={async (e) => {\n hideModal();\n onCancel?.(e);\n }}\n onClose={(e) => {\n hideModal();\n onClose?.(e);\n }}\n {...restProps}\n >\n <FormCreator<FD> onCreate={setForm} />\n {form && (\n <FormComp\n ref={isForwardRef(FormComp) ? setFormCompRef : undefined}\n {...formProps}\n form={form}\n onOpenChange={setOpenListener}\n onSave={setOnSaveHandler}\n triggerEventData={triggerEventArgsRef.current}\n setOpen={handleSetOpen}\n updateModalProps={setUserModalProps}\n />\n )}\n </Modal>\n </>\n );\n };\n return ModalActionRenderer;\n};\n\nfunction mergeProps<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n>(first?: Partial<ModalActionProps<FD, CP, TP, E, CRef>>, second?: Partial<ModalActionProps<FD, CP, TP, E, CRef>>) {\n return {\n ...first,\n ...second,\n okButtonProps: {\n ...first?.okButtonProps,\n ...second?.okButtonProps,\n },\n cancelButtonProps: {\n ...first?.cancelButtonProps,\n ...second?.cancelButtonProps,\n },\n bodyProps: {\n ...first?.bodyProps,\n ...second?.bodyProps,\n },\n maskProps: {\n ...first?.maskProps,\n ...second?.maskProps,\n },\n wrapProps: {\n ...first?.wrapProps,\n ...second?.wrapProps,\n },\n triggerProps: {\n ...first?.triggerProps,\n ...second?.triggerProps,\n style: {\n ...(first?.triggerProps && 'style' in first.triggerProps && typeof first.triggerProps.style === 'object'\n ? first.triggerProps.style\n : {}),\n ...(second?.triggerProps && 'style' in second.triggerProps && typeof second.triggerProps.style === 'object'\n ? second.triggerProps.style\n : {}),\n },\n },\n } as unknown as ModalActionProps<FD, CP, TP, E, CRef>;\n}\n\nfunction FormCreator<FD extends object>(props: { onCreate: (form: FormInstance<FD> | undefined) => void }) {\n const { onCreate } = props;\n const onCreateRef = useRef(onCreate);\n onCreateRef.current = onCreate;\n const [form] = Form.useForm<FD>();\n\n // output ref\n useEffect(() => {\n onCreateRef.current(form);\n return () => {\n onCreateRef.current(undefined);\n };\n }, [form]);\n\n return null;\n}\n\n/**\n * **EN:** Add default properties to the ModalAction component\n *\n * **CN:** 给ModalAction组件添加默认属性\n *\n * @param WrappedComponent ModalAction component | ModalAction组件\n * @param defaultProps Default properties | 默认属性\n */\nexport const withDefaultModalActionProps = <\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n>(\n WrappedComponent: ComponentType<ModalActionProps<FD, CP, TP, E, CRef> & RefAttributes<ModalActionRef<CRef>>>,\n defaultProps?: Partial<ModalActionProps<FD, CP, TP, E, CRef>> | (() => Partial<ModalActionProps<FD, CP, TP, E, CRef>>)\n) => {\n const WithDefaultProps = forwardRef<ModalActionRef<CRef>, ModalActionProps<FD, CP, TP, E, CRef>>((props, ref) => {\n const useDefaultProps = typeof defaultProps === 'function' ? defaultProps : () => defaultProps;\n const defaults = useDefaultProps();\n const mergedProps = mergeProps(defaults, props);\n WithDefaultProps.displayName = 'ForwardedRef(WithDefaultProps)';\n return <WrappedComponent ref={ref} {...mergedProps} />;\n });\n return WithDefaultProps;\n};\n\nconst renderModalAction = genModalActionRenderer({});\nconst forwardedModalAction = forwardRef(renderModalAction);\nforwardedModalAction.displayName = 'ForwardedRef(ModalAction)';\n/**\n * **EN:** ModalAction component type\n *\n * **CN:** ModalAction组件的类型\n */\nexport type ModalActionInterface<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n> = ComponentType<ModalActionProps<FD, CP, TP, E, CRef> & RefAttributes<ModalActionRef<CRef>>>;\n/**\n * **EN:** ModalAction component with generic type\n *\n * **CN:** ModalAction泛型组件的类型\n */\nexport type GenericModalActionInterface = <\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n>(\n props: ModalActionProps<FD, CP, TP, E, CRef> & RefAttributes<ModalActionRef<CRef>>\n) => ReactElement;\n/**\n * **EN:** ModalAction with specified trigger type (specified form component)\n *\n * **CN:** 已指定Trigger类型的ModalAction(并且已指定表单组件)\n */\ntype ModalActionWithTrigger<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n OMIT extends string = never,\n> = ComponentType<\n Omit<ModalActionProps<FD, CP, TP, E, CRef>, 'triggerComponent' | 'triggerEvent' | OMIT> &\n RefAttributes<ModalActionRef<CRef>>\n>;\n\n/**\n * **EN:** ModalAction with specified trigger type (unspecified form component, keep generic)\n *\n * **CN:** 已指定Trigger类型的ModalAction(未指定表单组件,保持泛型)\n */\ntype GenericModalActionWithTrigger<TP extends object, E extends keyof TP, OMIT extends string = never> = <\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n CRef extends object,\n>(\n props: Omit<ModalActionProps<FD, CP, TP, E, CRef>, 'triggerComponent' | 'triggerEvent' | OMIT> &\n RefAttributes<ModalActionRef<CRef>>\n) => ReactElement;\n\n/**\n * **EN:** Built-in trigger types (specified form components)\n *\n * **CN:** 内置的几种触发器类型(已指定表单组件)\n */\ninterface TypedTriggers<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n CRef extends object,\n OMIT extends string = never,\n> {\n /**\n * **EN:** Dialog with button type trigger\n *\n * **CN:** 按钮类型的弹窗\n */\n Button: ModalActionWithTrigger<FD, CP, ButtonProps, 'onClick', CRef, 'triggerComponent' | 'triggerEvent' | OMIT>;\n /**\n * **EN:** Dialog with switch type trigger\n *\n * **CN:** 开关类型的弹窗\n */\n Switch: ModalActionWithTrigger<FD, CP, SwitchProps, 'onChange', CRef, 'triggerComponent' | 'triggerEvent' | OMIT>;\n /**\n * **EN:** Dialog with link type trigger\n *\n * **CN:** 链接类型的弹窗\n */\n Link: ModalActionWithTrigger<FD, CP, LinkProps, 'onClick', CRef, 'triggerComponent' | 'triggerEvent' | OMIT>;\n}\n/**\n * **EN:** Built-in trigger types (generic types, unspecified form components)\n *\n * **CN:** 内置的几种触发器类型(泛型类型,未指定表单组件)\n */\ninterface GenericTypedTriggers<OMIT extends string = never> {\n /**\n * **EN:** Dialog with button type trigger\n *\n * **CN:** 按钮类型的弹窗\n */\n Button: GenericModalActionWithTrigger<ButtonProps, 'onClick', 'triggerComponent' | 'triggerEvent' | OMIT>;\n /**\n * **EN:** Dialog with switch type trigger\n *\n * **CN:** 开关类型的弹窗\n */\n Switch: GenericModalActionWithTrigger<SwitchProps, 'onChange', 'triggerComponent' | 'triggerEvent' | OMIT>;\n /**\n * **EN:** Dialog with link type trigger\n *\n * **CN:** 链接类型的弹窗\n */\n Link: GenericModalActionWithTrigger<LinkProps, 'onClick', 'triggerComponent' | 'triggerEvent' | OMIT>;\n}\ntype WithGenericTriggers<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n CRef extends object,\n OMIT extends string = never,\n> = (<TP extends object, E extends keyof TP>(\n props: Omit<ModalActionProps<FD, CP, TP, E, CRef>, OMIT> & RefAttributes<ModalActionRef<CRef>>\n) => ReactElement) &\n (CP extends never ? GenericTypedTriggers<OMIT> : TypedTriggers<FD, CP, CRef, OMIT>);\n\n/**\n * **EN:** Add trigger types to the ModalAction component\n *\n * **CN:** 给ModalAction组件添加子触发器类型\n */\nconst addTriggers = <\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n OuterTP extends object,\n OuterE extends keyof OuterTP,\n CRef extends object,\n OMIT extends string = never,\n>(\n comp: ComponentType<ModalActionProps<FD, CP, OuterTP, OuterE, CRef> & RefAttributes<ModalActionRef<CRef>>>\n) => {\n const patchedComp = comp as WithGenericTriggers<FD, CP, CRef, OMIT>;\n // Type of button trigger\n patchedComp.Button = withDefaultModalActionProps(comp as ModalActionInterface<FD, CP, ButtonProps, 'onClick', CRef>, {\n triggerComponent: Button,\n triggerEvent: 'onClick',\n triggerProps: {},\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n }) as any;\n // Type of switch trigger\n patchedComp.Switch = withDefaultModalActionProps(\n comp as ModalActionInterface<FD, CP, SwitchProps, 'onChange', CRef>,\n {\n triggerComponent: Switch,\n triggerEvent: 'onChange',\n triggerProps: {},\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ) as any;\n // Type of link trigger\n patchedComp.Link = withDefaultModalActionProps(comp as ModalActionInterface<FD, CP, LinkProps, 'onClick', CRef>, {\n triggerComponent: Typography.Link,\n triggerEvent: 'onClick',\n triggerProps: {\n style: { whiteSpace: 'nowrap' },\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n }) as any;\n return patchedComp;\n};\n\n/**\n * **EN:** Dialog component with trigger\n *\n * **CN:** 带触发器的弹窗组件\n */\nconst ModalAction = addTriggers(forwardedModalAction);\n\n/**\n * **EN:** Dialog component with trigger\n *\n * **CN:** 带触发器的弹窗组件\n */\nexport type ModalActionWithStatic = typeof ModalAction & {\n /**\n * **EN:** Symbol for not closing the dialog when submitting the form, which takes effect when\n * returning in the `onSave` event of the editing form component\n *\n * **CN:** 提交表单时不关闭弹框的Symbol,在编辑表单组件的`onSave`事件中返回时生效\n */\n SubmitWithoutClosing: symbol;\n};\n(ModalAction as ModalActionWithStatic).SubmitWithoutClosing = SubmitWithoutClosingSymbol;\n\n/**\n * **EN:** Generate a dialog component based on the editing form component\n *\n * **CN:** 基于编辑表单组件生成一个弹框组件\n *\n * @param formComp Component of dialog content | 弹窗内容组件\n * @param defaultProps Default properties of the dialog | 弹窗的默认属性\n */\nexport function withModalAction<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n OuterTP extends object,\n OuterE extends keyof OuterTP,\n CRef extends object,\n>(\n formComp: ComponentType<CP & FormCompPropsConstraint<FD> & RefAttributes<CRef>>,\n defaultProps?:\n | Partial<ModalActionProps<FD, CP, OuterTP, OuterE, CRef>>\n | (() => Partial<ModalActionProps<FD, CP, OuterTP, OuterE, CRef>>)\n) {\n const withForm = withDefaultModalActionProps(\n forwardedModalAction as unknown as ModalActionInterface<FD, CP, OuterTP, OuterE, CRef>,\n () => {\n const useDefaultProps = typeof defaultProps === 'function' ? defaultProps : () => defaultProps;\n const defaults = useDefaultProps();\n return {\n formComp,\n ...defaults,\n };\n }\n ) as unknown as <TP extends object, E extends keyof TP>(\n props: Omit<ModalActionProps<FD, CP, TP, E, CRef>, 'formComp'> & RefAttributes<ModalActionRef<CRef>>\n ) => ReactElement;\n return addTriggers<FD, CP, OuterTP, OuterE, CRef, 'formComp'>(withForm);\n}\n\nexport default ModalAction as ModalActionWithStatic;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAmG;AAEnG,kBAAwD;AAExD,sBAA6B;AAC7B,iCAAgC;AAQzB,IAAM,6BAA6B,OAAO,sBAAsB;AA0KhE,IAAM,yBAAyB,CAAC,iBAAyE;AAC9G,QAAM,sBAAsB,CAO1B,OACA,QACG;AACH,UAAM,CAAC,gBAAgB,iBAAiB,QAAI,uBAA8B,CAAC,CAAC;AAC5E,QAAI,cAAc,WAAgC,cAAc,KAAK;AACrE,kBAAc,WAAW,aAAa,cAA8B;AACpE,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA,kBAAkB,UAAU;AAAA,MAC5B,eAAe;AAAA,MACf;AAAA,MACA,MAAM;AAAA,MACN,iBAAiB;AAAA,MACjB,eAAe;AAAA,MACf;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IACL,IAAI;AACJ,mCAAAA,SAAoB;AACpB,UAAM,WAAW;AAEjB,UAAM,0BAAsB,qBAAc,MAAS;AACnD,UAAM,CAAC,MAAM,OAAO,QAAI,uBAAS,KAAK;AACtC,UAAM,kBAAc,qBAAkD,MAAS;AAC/E,UAAM,CAAC,UAAU,WAAW,QAAI,uBAAS,KAAK;AAC9C,UAAM,CAAC,aAAa,cAAc,QAAI,uBAAsB,IAAI;AAChE,UAAM,CAAC,MAAM,OAAO,QAAI,uBAA2B;AACnD,UAAM,cAAU,qBAAyB,IAAI;AAC7C,YAAQ,UAAU;AAClB,UAAM,wBAAoB,qBAAO,cAAc;AAC/C,sBAAkB,UAAU;
|
|
4
|
+
"sourcesContent": ["import type { ComponentType, FC, ForwardedRef, ReactElement, ReactNode, RefAttributes } from 'react';\nimport { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';\nimport type { ButtonProps, FormInstance, ModalProps, SwitchProps } from 'antd';\nimport { Button, Form, Modal, Switch, Typography } from 'antd';\nimport type { LinkProps } from 'antd/es/typography/Link';\nimport { isForwardRef } from 'react-is';\nimport useContextValidator from '../../hooks/useContextValidator';\n\n/**\n * **EN:** Symbol for not closing the dialog when submitting the form, which takes effect when\n * returning in the `onSave` event of the editing form component\n *\n * **CN:** 提交表单时不关闭弹框的Symbol,在编辑表单组件的`onSave`事件中返回时生效\n */\nexport const SubmitWithoutClosingSymbol = Symbol('[SubmitWithoutClose]');\n\nexport type ModalActionProps<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n> = Omit<ModalProps, 'onOk'> &\n ModalActionTrigger<FD, CP, TP, E> & {\n /**\n * **EN:** Form editing component, do not use the Form component inside the component, the form\n * component and form instance are automatically created by the parent component\n *\n * **CN:** 表单编辑组件,组件内部不要使用Form组件,表单组件及表单实例由父组件自动创建\n */\n formComp: ComponentType<CP & RefAttributes<CRef>>;\n /**\n * **EN:** Props of the form editing component\n *\n * **CN:** 表单编辑组件的Props属性\n */\n formProps?: Omit<CP, keyof FormCompPropsConstraint<FD>>;\n /**\n * **EN:** The callback when clicks the confirmation button, support asynchronous saving, return\n * `SubmitWithoutClosingSymbol` can prevent the dialog from closing, return other values will be\n * passed to the `afterOk` event, if any\n *\n * **CN:** 点击确认按钮的回调,支持异步保存,返回`SubmitWithoutClosingSymbol`可以阻止弹框关闭,返回其他值会传递给`afterOk`事件,如果有的话\n */\n onOk?: (\n formData: FD,\n // @ts-expect-error: because TP[E] should be a function type\n ...args: Parameters<TP[E]>\n ) => unknown | Promise<unknown>;\n /**\n * **EN:** The callback after the confirmation event is completed, it will not be triggered when\n * it fails, the parameter is the return value of `onOk`\n *\n * **CN:** 确认事件完成后的回调,失败时不会触发,参数为`onOk`的返回值\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n afterOk?: (data?: any) => void;\n };\n\nexport interface FormCompPropsConstraint<FD> {\n /**\n * **EN:** Automatically generated form instance, use this form instance in FormComp, do not\n * create a new instance\n *\n * **CN:** 自动生成的表单实例,编辑表单要使用这个表单实例,不要新创建实例\n */\n form: FormInstance<FD>;\n /**\n * **EN:** Register the form save event, the callback function passed in will be called when the\n * confirm button is clicked, support asynchronous saving\n *\n * **CN:** 注册表单保存事件,传入的回调函数会在点击确认按钮时被调用,支持异步保存\n *\n * @param handler Event handler | 事件处理函数\n */\n onSave: (\n handler: (\n /**\n * **EN:** Form data\n *\n * **CN:** 表单数据\n */\n formData: FD,\n /**\n * **EN:** Trigger click event data, for example, for the `Switch` type trigger, you can get\n * the value of the switch; for the `Button` type trigger, you can get the click event object\n * of the button\n *\n * **CN:** 触发器点击的事件数据,例如,对于`Switch`类型的触发器,可以获取点击开关的值;对于`Button`类型的触发器,可以获取按钮的点击事件对象\n */\n ...triggerEventData: any[]\n ) => unknown | Promise<unknown>\n ) => void;\n /**\n * **EN:** Listen to the open and close status of the dialog. When `destroyOnHidden` is set to\n * false, the form component instance is cached, and the dialog can only be listened to in this\n * way\n *\n * **CN:** 监听弹框打开关闭状态。当`destroyOnHidden`设置为false时,表单组件实例被缓存,只能通过这种方式监听弹框\n *\n * @param handler Event handler | 事件处理函数\n */\n onOpenChange: (handler: ModalProps['afterOpenChange']) => void;\n /**\n * **EN:** Set the dialog open status\n *\n * **CN:** 设置弹框打开状态\n *\n * @param open Whether is open or not | 弹窗是否打开\n */\n setOpen: (open: boolean) => void;\n /**\n * **EN:** Modify the properties of the dialog, such as title, width, button properties, etc.\n *\n * **CN:** 修改弹窗的属性,例如标题、宽度,按钮属性等\n */\n updateModalProps: (props: Partial<ModalProps>) => void;\n /**\n * **EN:** Trigger click event data, for example, for the `Switch` type trigger, you can get the\n * value of the switch; for the `Button` type trigger, you can get the click event object of the\n * button\n *\n * **CN:** 触发器点击的事件数据,例如,对于`Switch`类型的触发器,可以获取点击开关的值,对于`Button`类型的触发器,可以获取按钮的点击事件对象\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n triggerEventData?: any[];\n}\n\nexport interface ModalActionTrigger<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n> {\n /**\n * **EN:** Trigger component, click to show the dialog\n *\n * **CN:** 弹窗触发器组件,点击触发显示弹框\n */\n triggerComponent?: ComponentType<TP> | FC<TP>;\n /**\n * **EN:** Props of the trigger component\n *\n * **CN:** 触发器组件的Props属性\n */\n triggerProps?: TP & {\n /**\n * **EN:** Set a custom function to determine whether to show the trigger button\n *\n * **CN:** 设置一个自定义函数,用于判断是否显示触发器按钮\n *\n * @default true\n *\n * @param formProps Form component props | 表单组件的props\n */\n show?: boolean | ((formProps?: Omit<CP, keyof FormCompPropsConstraint<FD>>) => boolean);\n };\n /**\n * **EN:** The event name that triggers the dialog\n *\n * **CN:** 触发弹窗的事件名称\n *\n * - `Button`: 'onClick'\n * - `Switch`: 'onChange'\n * - `Link`: 'onClick'\n */\n triggerEvent?: E;\n /**\n * **EN:** Custom trigger content\n *\n * **CN:** 自定义触发器内容\n */\n children?: ReactNode;\n}\nexport type ModalActionRef<R> = R & {\n /**\n * **EN:** Show the dialog\n *\n * **CN:** 显示弹框\n */\n show: () => void;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const genModalActionRenderer = (defaultProps: Partial<ModalActionProps<any, any, any, never, never>>) => {\n const ModalActionRenderer = <\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n >(\n props: ModalActionProps<FD, CP, TP, E, CRef>,\n ref: ForwardedRef<ModalActionRef<CRef>>\n ) => {\n const [userModalProps, setUserModalProps] = useState<Partial<ModalProps>>({});\n let mergedProps = mergeProps<FD, CP, TP, E, CRef>(defaultProps, props);\n mergedProps = mergeProps(mergedProps, userModalProps as typeof props);\n const {\n formComp,\n formProps,\n triggerComponent: Trigger = Button,\n triggerEvent = 'onClick' as E,\n triggerProps,\n open: openInProps,\n destroyOnClose = true,\n destroyOnHidden = true,\n maskClosable = false,\n onOk,\n afterOk,\n onCancel,\n afterClose,\n children,\n ...restProps\n } = mergedProps;\n useContextValidator();\n const FormComp = formComp as ComponentType<FormCompPropsConstraint<FD> & RefAttributes<CRef>>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const triggerEventArgsRef = useRef<any[]>(undefined);\n const [open, setOpen] = useState(false);\n const saveFuncRef = useRef<(formData: FD, ...args: any[]) => unknown>(undefined);\n const [isSaving, setIsSaving] = useState(false);\n const [formCompRef, setFormCompRef] = useState<CRef | null>(null);\n const [form, setForm] = useState<FormInstance<FD>>();\n const formRef = useRef<FormInstance<FD>>(form);\n formRef.current = form;\n const destroyOnCloseRef = useRef(destroyOnClose);\n destroyOnCloseRef.current = destroyOnClose || destroyOnHidden;\n const openListenerRef = useRef<ModalProps['afterOpenChange']>(undefined);\n\n // Listen to the open props changes\n useEffect(() => {\n if (openInProps) {\n setOpen(openInProps);\n }\n }, [openInProps]);\n\n // Reset the form after closed\n useEffect(() => {\n if (!destroyOnCloseRef.current && open && formRef.current) {\n formRef.current.resetFields();\n }\n }, [open]);\n\n // show trigger\n const showInProps = triggerProps?.show;\n const showTrigger = useMemo(() => {\n if (typeof showInProps === 'boolean') {\n return showInProps;\n } else if (typeof showInProps === 'function') {\n return showInProps(formProps);\n }\n return true;\n }, [showInProps, formProps]);\n\n // Show the dialog\n const showModal = useCallback(() => {\n setOpen(true);\n openListenerRef.current?.(true);\n }, []);\n // Hide the dialog\n const hideModal = useCallback(() => {\n setOpen(false);\n openListenerRef.current?.(false);\n }, []);\n // Set the dialog status listener\n const setOpenListener = useCallback(\n (listener: ModalProps['afterOpenChange']) => {\n openListenerRef.current = listener;\n // Call once when initialized\n openListenerRef.current?.(open);\n },\n [open]\n );\n // Receive the onSave callback method passed by the form component\n const setOnSaveHandler: FormCompPropsConstraint<FD>['onSave'] = useCallback((handler) => {\n saveFuncRef.current = handler;\n }, []);\n // Set the dialog status and trigger the onOpenChange event of the form component\n const handleSetOpen = useCallback((open: boolean) => {\n setOpen(open);\n openListenerRef.current?.(open);\n }, []);\n\n // Output ref\n useImperativeHandle(ref, () => ({ ...formCompRef, show: showModal }) as ModalActionRef<CRef>, [\n formCompRef,\n showModal,\n ]);\n\n // Render the trigger component\n return (\n <>\n {showTrigger && (\n <Trigger\n {...triggerProps}\n // Trigger event\n {...((triggerEvent\n ? {\n [triggerEvent]: (...args: any[]) => {\n triggerEventArgsRef.current = args;\n showModal();\n if (triggerProps && typeof triggerProps[triggerEvent] === 'function') {\n (triggerProps[triggerEvent] as (...args: any[]) => void)(...args);\n }\n },\n }\n : {}) as TP)}\n >\n {(triggerProps as { children?: ReactNode }).children ?? children}\n </Trigger>\n )}\n <Modal\n open={open}\n confirmLoading={isSaving}\n destroyOnClose={destroyOnClose}\n destroyOnHidden={destroyOnHidden}\n maskClosable={maskClosable}\n onOk={async (e) => {\n let formData: FD;\n try {\n formData = (await form?.validateFields()) as FD;\n } catch (e) {\n // Validation error, should not throw error\n return;\n }\n if (Object.keys(formData).length === 0) {\n console.warn(\n 'form.getFieldsValue() is empty. Please use the form instance passed to formComp instead of creating the form instance yourself.'\n );\n }\n try {\n setIsSaving(true);\n // First call onSave of the form component\n let result = await saveFuncRef.current?.(formData, ...(triggerEventArgsRef.current ?? []));\n // The onSave of the form component has the ability to prevent the dialog from closing\n if (result === SubmitWithoutClosingSymbol) {\n throw new Error('SubmitWithoutClosing');\n }\n // Then call onOk of the dialog, support asynchronous, and will pass the return value of onSave, if any\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n result = await onOk?.((result as FD) ?? formData, ...((triggerEventArgsRef.current ?? []) as any));\n // onOk also has the ability to prevent the dialog from closing\n if (result === SubmitWithoutClosingSymbol) {\n throw new Error('SubmitWithoutClosing');\n }\n // If onOK is successful, close the dialog and trigger the afterOk event\n hideModal();\n afterOk?.(result);\n } catch (error) {\n console.error(error);\n } finally {\n setIsSaving(false);\n }\n }}\n onCancel={async (e) => {\n hideModal();\n onCancel?.(e);\n }}\n afterClose={() => {\n hideModal();\n afterClose?.();\n }}\n {...restProps}\n >\n <FormCreator<FD> onCreate={setForm} />\n {form && (\n <FormComp\n ref={isForwardRef(FormComp) ? setFormCompRef : undefined}\n {...formProps}\n form={form}\n onOpenChange={setOpenListener}\n onSave={setOnSaveHandler}\n triggerEventData={triggerEventArgsRef.current}\n setOpen={handleSetOpen}\n updateModalProps={setUserModalProps}\n />\n )}\n </Modal>\n </>\n );\n };\n return ModalActionRenderer;\n};\n\nfunction mergeProps<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n>(first?: Partial<ModalActionProps<FD, CP, TP, E, CRef>>, second?: Partial<ModalActionProps<FD, CP, TP, E, CRef>>) {\n return {\n ...first,\n ...second,\n okButtonProps: {\n ...first?.okButtonProps,\n ...second?.okButtonProps,\n },\n cancelButtonProps: {\n ...first?.cancelButtonProps,\n ...second?.cancelButtonProps,\n },\n bodyProps: {\n ...first?.bodyProps,\n ...second?.bodyProps,\n },\n maskProps: {\n ...first?.maskProps,\n ...second?.maskProps,\n },\n wrapProps: {\n ...first?.wrapProps,\n ...second?.wrapProps,\n },\n triggerProps: {\n ...first?.triggerProps,\n ...second?.triggerProps,\n style: {\n ...(first?.triggerProps && 'style' in first.triggerProps && typeof first.triggerProps.style === 'object'\n ? first.triggerProps.style\n : {}),\n ...(second?.triggerProps && 'style' in second.triggerProps && typeof second.triggerProps.style === 'object'\n ? second.triggerProps.style\n : {}),\n },\n },\n } as unknown as ModalActionProps<FD, CP, TP, E, CRef>;\n}\n\nfunction FormCreator<FD extends object>(props: { onCreate: (form: FormInstance<FD> | undefined) => void }) {\n const { onCreate } = props;\n const onCreateRef = useRef(onCreate);\n onCreateRef.current = onCreate;\n const [form] = Form.useForm<FD>();\n\n // output ref\n useEffect(() => {\n onCreateRef.current(form);\n return () => {\n onCreateRef.current(undefined);\n };\n }, [form]);\n\n return null;\n}\n\n/**\n * **EN:** Add default properties to the ModalAction component\n *\n * **CN:** 给ModalAction组件添加默认属性\n *\n * @param WrappedComponent ModalAction component | ModalAction组件\n * @param defaultProps Default properties | 默认属性\n */\nexport const withDefaultModalActionProps = <\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n>(\n WrappedComponent: ComponentType<ModalActionProps<FD, CP, TP, E, CRef> & RefAttributes<ModalActionRef<CRef>>>,\n defaultProps?: Partial<ModalActionProps<FD, CP, TP, E, CRef>> | (() => Partial<ModalActionProps<FD, CP, TP, E, CRef>>)\n) => {\n const WithDefaultProps = forwardRef<ModalActionRef<CRef>, ModalActionProps<FD, CP, TP, E, CRef>>((props, ref) => {\n const useDefaultProps = typeof defaultProps === 'function' ? defaultProps : () => defaultProps;\n const defaults = useDefaultProps();\n const mergedProps = mergeProps(defaults, props);\n WithDefaultProps.displayName = 'ForwardedRef(WithDefaultProps)';\n return <WrappedComponent ref={ref} {...mergedProps} />;\n });\n return WithDefaultProps;\n};\n\nconst renderModalAction = genModalActionRenderer({});\nconst forwardedModalAction = forwardRef(renderModalAction);\nforwardedModalAction.displayName = 'ForwardedRef(ModalAction)';\n/**\n * **EN:** ModalAction component type\n *\n * **CN:** ModalAction组件的类型\n */\nexport type ModalActionInterface<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n> = ComponentType<ModalActionProps<FD, CP, TP, E, CRef> & RefAttributes<ModalActionRef<CRef>>>;\n/**\n * **EN:** ModalAction component with generic type\n *\n * **CN:** ModalAction泛型组件的类型\n */\nexport type GenericModalActionInterface = <\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n>(\n props: ModalActionProps<FD, CP, TP, E, CRef> & RefAttributes<ModalActionRef<CRef>>\n) => ReactElement;\n/**\n * **EN:** ModalAction with specified trigger type (specified form component)\n *\n * **CN:** 已指定Trigger类型的ModalAction(并且已指定表单组件)\n */\ntype ModalActionWithTrigger<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n OMIT extends string = never,\n> = ComponentType<\n Omit<ModalActionProps<FD, CP, TP, E, CRef>, 'triggerComponent' | 'triggerEvent' | OMIT> &\n RefAttributes<ModalActionRef<CRef>>\n>;\n\n/**\n * **EN:** ModalAction with specified trigger type (unspecified form component, keep generic)\n *\n * **CN:** 已指定Trigger类型的ModalAction(未指定表单组件,保持泛型)\n */\ntype GenericModalActionWithTrigger<TP extends object, E extends keyof TP, OMIT extends string = never> = <\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n CRef extends object,\n>(\n props: Omit<ModalActionProps<FD, CP, TP, E, CRef>, 'triggerComponent' | 'triggerEvent' | OMIT> &\n RefAttributes<ModalActionRef<CRef>>\n) => ReactElement;\n\n/**\n * **EN:** Built-in trigger types (specified form components)\n *\n * **CN:** 内置的几种触发器类型(已指定表单组件)\n */\ninterface TypedTriggers<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n CRef extends object,\n OMIT extends string = never,\n> {\n /**\n * **EN:** Dialog with button type trigger\n *\n * **CN:** 按钮类型的弹窗\n */\n Button: ModalActionWithTrigger<FD, CP, ButtonProps, 'onClick', CRef, 'triggerComponent' | 'triggerEvent' | OMIT>;\n /**\n * **EN:** Dialog with switch type trigger\n *\n * **CN:** 开关类型的弹窗\n */\n Switch: ModalActionWithTrigger<FD, CP, SwitchProps, 'onChange', CRef, 'triggerComponent' | 'triggerEvent' | OMIT>;\n /**\n * **EN:** Dialog with link type trigger\n *\n * **CN:** 链接类型的弹窗\n */\n Link: ModalActionWithTrigger<FD, CP, LinkProps, 'onClick', CRef, 'triggerComponent' | 'triggerEvent' | OMIT>;\n}\n/**\n * **EN:** Built-in trigger types (generic types, unspecified form components)\n *\n * **CN:** 内置的几种触发器类型(泛型类型,未指定表单组件)\n */\ninterface GenericTypedTriggers<OMIT extends string = never> {\n /**\n * **EN:** Dialog with button type trigger\n *\n * **CN:** 按钮类型的弹窗\n */\n Button: GenericModalActionWithTrigger<ButtonProps, 'onClick', 'triggerComponent' | 'triggerEvent' | OMIT>;\n /**\n * **EN:** Dialog with switch type trigger\n *\n * **CN:** 开关类型的弹窗\n */\n Switch: GenericModalActionWithTrigger<SwitchProps, 'onChange', 'triggerComponent' | 'triggerEvent' | OMIT>;\n /**\n * **EN:** Dialog with link type trigger\n *\n * **CN:** 链接类型的弹窗\n */\n Link: GenericModalActionWithTrigger<LinkProps, 'onClick', 'triggerComponent' | 'triggerEvent' | OMIT>;\n}\ntype WithGenericTriggers<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n CRef extends object,\n OMIT extends string = never,\n> = (<TP extends object, E extends keyof TP>(\n props: Omit<ModalActionProps<FD, CP, TP, E, CRef>, OMIT> & RefAttributes<ModalActionRef<CRef>>\n) => ReactElement) &\n (CP extends never ? GenericTypedTriggers<OMIT> : TypedTriggers<FD, CP, CRef, OMIT>);\n\n/**\n * **EN:** Add trigger types to the ModalAction component\n *\n * **CN:** 给ModalAction组件添加子触发器类型\n */\nconst addTriggers = <\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n OuterTP extends object,\n OuterE extends keyof OuterTP,\n CRef extends object,\n OMIT extends string = never,\n>(\n comp: ComponentType<ModalActionProps<FD, CP, OuterTP, OuterE, CRef> & RefAttributes<ModalActionRef<CRef>>>\n) => {\n const patchedComp = comp as WithGenericTriggers<FD, CP, CRef, OMIT>;\n // Type of button trigger\n patchedComp.Button = withDefaultModalActionProps(comp as ModalActionInterface<FD, CP, ButtonProps, 'onClick', CRef>, {\n triggerComponent: Button,\n triggerEvent: 'onClick',\n triggerProps: {},\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n }) as any;\n // Type of switch trigger\n patchedComp.Switch = withDefaultModalActionProps(\n comp as ModalActionInterface<FD, CP, SwitchProps, 'onChange', CRef>,\n {\n triggerComponent: Switch,\n triggerEvent: 'onChange',\n triggerProps: {},\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ) as any;\n // Type of link trigger\n patchedComp.Link = withDefaultModalActionProps(comp as ModalActionInterface<FD, CP, LinkProps, 'onClick', CRef>, {\n triggerComponent: Typography.Link,\n triggerEvent: 'onClick',\n triggerProps: {\n style: { whiteSpace: 'nowrap' },\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n }) as any;\n return patchedComp;\n};\n\n/**\n * **EN:** Dialog component with trigger\n *\n * **CN:** 带触发器的弹窗组件\n */\nconst ModalAction = addTriggers(forwardedModalAction);\n\n/**\n * **EN:** Dialog component with trigger\n *\n * **CN:** 带触发器的弹窗组件\n */\nexport type ModalActionWithStatic = typeof ModalAction & {\n /**\n * **EN:** Symbol for not closing the dialog when submitting the form, which takes effect when\n * returning in the `onSave` event of the editing form component\n *\n * **CN:** 提交表单时不关闭弹框的Symbol,在编辑表单组件的`onSave`事件中返回时生效\n */\n SubmitWithoutClosing: symbol;\n};\n(ModalAction as ModalActionWithStatic).SubmitWithoutClosing = SubmitWithoutClosingSymbol;\n\n/**\n * **EN:** Generate a dialog component based on the editing form component\n *\n * **CN:** 基于编辑表单组件生成一个弹框组件\n *\n * @param formComp Component of dialog content | 弹窗内容组件\n * @param defaultProps Default properties of the dialog | 弹窗的默认属性\n */\nexport function withModalAction<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n OuterTP extends object,\n OuterE extends keyof OuterTP,\n CRef extends object,\n>(\n formComp: ComponentType<CP & FormCompPropsConstraint<FD> & RefAttributes<CRef>>,\n defaultProps?:\n | Partial<ModalActionProps<FD, CP, OuterTP, OuterE, CRef>>\n | (() => Partial<ModalActionProps<FD, CP, OuterTP, OuterE, CRef>>)\n) {\n const withForm = withDefaultModalActionProps(\n forwardedModalAction as unknown as ModalActionInterface<FD, CP, OuterTP, OuterE, CRef>,\n () => {\n const useDefaultProps = typeof defaultProps === 'function' ? defaultProps : () => defaultProps;\n const defaults = useDefaultProps();\n return {\n formComp,\n ...defaults,\n };\n }\n ) as unknown as <TP extends object, E extends keyof TP>(\n props: Omit<ModalActionProps<FD, CP, TP, E, CRef>, 'formComp'> & RefAttributes<ModalActionRef<CRef>>\n ) => ReactElement;\n return addTriggers<FD, CP, OuterTP, OuterE, CRef, 'formComp'>(withForm);\n}\n\nexport default ModalAction as ModalActionWithStatic;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAmG;AAEnG,kBAAwD;AAExD,sBAA6B;AAC7B,iCAAgC;AAQzB,IAAM,6BAA6B,OAAO,sBAAsB;AA0KhE,IAAM,yBAAyB,CAAC,iBAAyE;AAC9G,QAAM,sBAAsB,CAO1B,OACA,QACG;AACH,UAAM,CAAC,gBAAgB,iBAAiB,QAAI,uBAA8B,CAAC,CAAC;AAC5E,QAAI,cAAc,WAAgC,cAAc,KAAK;AACrE,kBAAc,WAAW,aAAa,cAA8B;AACpE,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA,kBAAkB,UAAU;AAAA,MAC5B,eAAe;AAAA,MACf;AAAA,MACA,MAAM;AAAA,MACN,iBAAiB;AAAA,MACjB,kBAAkB;AAAA,MAClB,eAAe;AAAA,MACf;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IACL,IAAI;AACJ,mCAAAA,SAAoB;AACpB,UAAM,WAAW;AAEjB,UAAM,0BAAsB,qBAA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AAAA,MACd,cAAc,CAAC;AAAA,IACjB;AAAA;AAAA,EAEF;AAEA,cAAY,OAAO,4BAA4B,MAAkE;AAAA,IAC/G,kBAAkB,uBAAW;AAAA,IAC7B,cAAc;AAAA,IACd,cAAc;AAAA,MACZ,OAAO,EAAE,YAAY,SAAS;AAAA,IAChC;AAAA;AAAA,EAEF,CAAC;AACD,SAAO;AACT;AAOA,IAAM,cAAc,YAAY,oBAAoB;AAgBnD,YAAsC,uBAAuB;AAUvD,SAAS,gBAOd,UACA,cAGA;AACA,QAAM,WAAW;AAAA,IACf;AAAA,IACA,MAAM;AACJ,YAAM,kBAAkB,OAAO,iBAAiB,aAAa,eAAe,MAAM;AAClF,YAAM,WAAW,gBAAgB;AACjC,aAAO;AAAA,QACL;AAAA,QACA,GAAG;AAAA,MACL;AAAA,IACF;AAAA,EACF;AAGA,SAAO,YAAuD,QAAQ;AACxE;AAEA,IAAO,sBAAQ;",
|
|
6
6
|
"names": ["useContextValidator", "open", "e"]
|
|
7
7
|
}
|
|
@@ -8,6 +8,8 @@ export type { ConfirmActionProps, ConfirmActionTrigger, ConfirmActionRef } from
|
|
|
8
8
|
export { withDefaultConfirmActionProps } from './ConfirmAction';
|
|
9
9
|
export { default as ConfirmAction } from './ConfirmAction';
|
|
10
10
|
export { default as DeleteConfirmAction } from './DeleteConfirmAction';
|
|
11
|
+
export type { FloatDrawerProps } from './FloatDrawer';
|
|
12
|
+
export { default as FloatDrawer } from './FloatDrawer';
|
|
11
13
|
export type { ModalActionProps, FormCompPropsConstraint, ModalActionTrigger, ModalActionRef } from './ModalAction';
|
|
12
14
|
export { withDefaultModalActionProps, withModalAction } from './ModalAction';
|
|
13
15
|
export { default as ModalAction } from './ModalAction';
|
package/lib/components/index.js
CHANGED
|
@@ -33,6 +33,7 @@ __export(components_exports, {
|
|
|
33
33
|
ConfigProvider: () => import_ConfigProvider.default,
|
|
34
34
|
ConfirmAction: () => import_ConfirmAction2.default,
|
|
35
35
|
DeleteConfirmAction: () => import_DeleteConfirmAction.default,
|
|
36
|
+
FloatDrawer: () => import_FloatDrawer.default,
|
|
36
37
|
ModalAction: () => import_ModalAction2.default,
|
|
37
38
|
ReactEasyContext: () => import_context.default,
|
|
38
39
|
withDefaultConfirmActionProps: () => import_ConfirmAction.withDefaultConfirmActionProps,
|
|
@@ -46,6 +47,7 @@ var import_context = __toESM(require("./ConfigProvider/context"));
|
|
|
46
47
|
var import_ConfirmAction = require("./ConfirmAction");
|
|
47
48
|
var import_ConfirmAction2 = __toESM(require("./ConfirmAction"));
|
|
48
49
|
var import_DeleteConfirmAction = __toESM(require("./DeleteConfirmAction"));
|
|
50
|
+
var import_FloatDrawer = __toESM(require("./FloatDrawer"));
|
|
49
51
|
var import_ModalAction = require("./ModalAction");
|
|
50
52
|
var import_ModalAction2 = __toESM(require("./ModalAction"));
|
|
51
53
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -54,6 +56,7 @@ var import_ModalAction2 = __toESM(require("./ModalAction"));
|
|
|
54
56
|
ConfigProvider,
|
|
55
57
|
ConfirmAction,
|
|
56
58
|
DeleteConfirmAction,
|
|
59
|
+
FloatDrawer,
|
|
57
60
|
ModalAction,
|
|
58
61
|
ReactEasyContext,
|
|
59
62
|
withDefaultConfirmActionProps,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/components/index.tsx"],
|
|
4
|
-
"sourcesContent": ["export type { BreakLinesProps } from './BreakLines';\nexport { default as BreakLines } from './BreakLines';\n\nexport type { ConfigProviderProps } from './ConfigProvider';\nexport { default as ConfigProvider } from './ConfigProvider';\nexport type { ReactEasyContextProps } from './ConfigProvider/context';\nexport { default as ReactEasyContext } from './ConfigProvider/context';\n\nexport type { ConfirmActionProps, ConfirmActionTrigger, ConfirmActionRef } from './ConfirmAction';\nexport { withDefaultConfirmActionProps } from './ConfirmAction';\nexport { default as ConfirmAction } from './ConfirmAction';\n\n// export * from './DeleteConfirmAction';\nexport { default as DeleteConfirmAction } from './DeleteConfirmAction';\n\nexport type { ModalActionProps, FormCompPropsConstraint, ModalActionTrigger, ModalActionRef } from './ModalAction';\nexport { withDefaultModalActionProps, withModalAction } from './ModalAction';\nexport { default as ModalAction } from './ModalAction';\n\n// export * from '../utils';\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,wBAAsC;AAGtC,4BAA0C;AAE1C,qBAA4C;AAG5C,2BAA8C;AAC9C,IAAAA,wBAAyC;AAGzC,iCAA+C;AAG/C,yBAA6D;AAC7D,IAAAC,sBAAuC;",
|
|
4
|
+
"sourcesContent": ["export type { BreakLinesProps } from './BreakLines';\nexport { default as BreakLines } from './BreakLines';\n\nexport type { ConfigProviderProps } from './ConfigProvider';\nexport { default as ConfigProvider } from './ConfigProvider';\nexport type { ReactEasyContextProps } from './ConfigProvider/context';\nexport { default as ReactEasyContext } from './ConfigProvider/context';\n\nexport type { ConfirmActionProps, ConfirmActionTrigger, ConfirmActionRef } from './ConfirmAction';\nexport { withDefaultConfirmActionProps } from './ConfirmAction';\nexport { default as ConfirmAction } from './ConfirmAction';\n\n// export * from './DeleteConfirmAction';\nexport { default as DeleteConfirmAction } from './DeleteConfirmAction';\n\nexport type { FloatDrawerProps } from './FloatDrawer';\nexport { default as FloatDrawer } from './FloatDrawer';\n\nexport type { ModalActionProps, FormCompPropsConstraint, ModalActionTrigger, ModalActionRef } from './ModalAction';\nexport { withDefaultModalActionProps, withModalAction } from './ModalAction';\nexport { default as ModalAction } from './ModalAction';\n\n// export * from '../utils';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,wBAAsC;AAGtC,4BAA0C;AAE1C,qBAA4C;AAG5C,2BAA8C;AAC9C,IAAAA,wBAAyC;AAGzC,iCAA+C;AAG/C,yBAAuC;AAGvC,yBAA6D;AAC7D,IAAAC,sBAAuC;",
|
|
6
6
|
"names": ["import_ConfirmAction", "import_ModalAction"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/utils/color.ts
|
|
20
|
+
var color_exports = {};
|
|
21
|
+
__export(color_exports, {
|
|
22
|
+
getColorLuminance: () => getColorLuminance
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(color_exports);
|
|
25
|
+
function getColorLuminance(color) {
|
|
26
|
+
var _a;
|
|
27
|
+
let r = 0, g = 0, b = 0;
|
|
28
|
+
if (color.startsWith("#")) {
|
|
29
|
+
let hex = color.substring(1);
|
|
30
|
+
if (hex.length === 3) {
|
|
31
|
+
hex = hex.split("").map((c) => c + c).join("");
|
|
32
|
+
}
|
|
33
|
+
r = parseInt(hex.substring(0, 2), 16);
|
|
34
|
+
g = parseInt(hex.substring(2, 4), 16);
|
|
35
|
+
b = parseInt(hex.substring(4, 6), 16);
|
|
36
|
+
} else if (color.startsWith("rgb")) {
|
|
37
|
+
const values = ((_a = color.match(/\d+/g)) == null ? void 0 : _a.map(Number)) || [];
|
|
38
|
+
[r, g, b] = values;
|
|
39
|
+
}
|
|
40
|
+
r = r / 255;
|
|
41
|
+
g = g / 255;
|
|
42
|
+
b = b / 255;
|
|
43
|
+
r = r <= 0.03928 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4);
|
|
44
|
+
g = g <= 0.03928 ? g / 12.92 : Math.pow((g + 0.055) / 1.055, 2.4);
|
|
45
|
+
b = b <= 0.03928 ? b / 12.92 : Math.pow((b + 0.055) / 1.055, 2.4);
|
|
46
|
+
const luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
47
|
+
return luminance;
|
|
48
|
+
}
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
getColorLuminance
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=color.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/color.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Get the luminance of a color (0, 1) to determine if it is light or dark.\n *\n * @param color - The color to get the luminance for\n *\n * @returns The luminance of the color\n */\nexport function getColorLuminance(color: string): number {\n let r = 0,\n g = 0,\n b = 0;\n\n if (color.startsWith('#')) {\n let hex = color.substring(1);\n if (hex.length === 3) {\n hex = hex\n .split('')\n .map((c) => c + c)\n .join('');\n }\n r = parseInt(hex.substring(0, 2), 16);\n g = parseInt(hex.substring(2, 4), 16);\n b = parseInt(hex.substring(4, 6), 16);\n } else if (color.startsWith('rgb')) {\n const values = color.match(/\\d+/g)?.map(Number) || [];\n [r, g, b] = values;\n }\n r = r / 255;\n g = g / 255;\n b = b / 255;\n\n r = r <= 0.03928 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4);\n g = g <= 0.03928 ? g / 12.92 : Math.pow((g + 0.055) / 1.055, 2.4);\n b = b <= 0.03928 ? b / 12.92 : Math.pow((b + 0.055) / 1.055, 2.4);\n\n const luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b;\n\n return luminance;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,SAAS,kBAAkB,OAAuB;AAPzD;AAQE,MAAI,IAAI,GACN,IAAI,GACJ,IAAI;AAEN,MAAI,MAAM,WAAW,GAAG,GAAG;AACzB,QAAI,MAAM,MAAM,UAAU,CAAC;AAC3B,QAAI,IAAI,WAAW,GAAG;AACpB,YAAM,IACH,MAAM,EAAE,EACR,IAAI,CAAC,MAAM,IAAI,CAAC,EAChB,KAAK,EAAE;AAAA,IACZ;AACA,QAAI,SAAS,IAAI,UAAU,GAAG,CAAC,GAAG,EAAE;AACpC,QAAI,SAAS,IAAI,UAAU,GAAG,CAAC,GAAG,EAAE;AACpC,QAAI,SAAS,IAAI,UAAU,GAAG,CAAC,GAAG,EAAE;AAAA,EACtC,WAAW,MAAM,WAAW,KAAK,GAAG;AAClC,UAAM,WAAS,WAAM,MAAM,MAAM,MAAlB,mBAAqB,IAAI,YAAW,CAAC;AACpD,KAAC,GAAG,GAAG,CAAC,IAAI;AAAA,EACd;AACA,MAAI,IAAI;AACR,MAAI,IAAI;AACR,MAAI,IAAI;AAER,MAAI,KAAK,UAAU,IAAI,QAAQ,KAAK,KAAK,IAAI,SAAS,OAAO,GAAG;AAChE,MAAI,KAAK,UAAU,IAAI,QAAQ,KAAK,KAAK,IAAI,SAAS,OAAO,GAAG;AAChE,MAAI,KAAK,UAAU,IAAI,QAAQ,KAAK,KAAK,IAAI,SAAS,OAAO,GAAG;AAEhE,QAAM,YAAY,SAAS,IAAI,SAAS,IAAI,SAAS;AAErD,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './color';
|
package/lib/utils/index.js
CHANGED
|
@@ -1 +1,24 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/utils/index.ts
|
|
17
|
+
var utils_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(utils_exports);
|
|
19
|
+
__reExport(utils_exports, require("./color"), module.exports);
|
|
20
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
21
|
+
0 && (module.exports = {
|
|
22
|
+
...require("./color")
|
|
23
|
+
});
|
|
1
24
|
//# sourceMappingURL=index.js.map
|
package/lib/utils/index.js.map
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiny-codes/react-easy",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Helps you use React and AntDesign more easily",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"README.zh-CN.md"
|
|
31
31
|
],
|
|
32
32
|
"scripts": {
|
|
33
|
-
"prepare": "husky",
|
|
34
33
|
"build": "father build",
|
|
34
|
+
"prepare": "husky",
|
|
35
35
|
"prepublishOnly": "npm run build"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
@@ -39,8 +39,9 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@tiny-codes/code-style-all-in-one": "^1.1.5",
|
|
42
|
+
"@tiny-codes/eslint-plugin-react-hooks": "^4.6.0",
|
|
42
43
|
"@types/jest": "^29.5.14",
|
|
43
|
-
"@types/node": "^22.
|
|
44
|
+
"@types/node": "^22.15.32",
|
|
44
45
|
"@types/react": "^19.0.12",
|
|
45
46
|
"@types/react-dom": "^19.0.4",
|
|
46
47
|
"@types/react-is": "^19.0.0",
|