@tiny-codes/react-easy 1.1.2 → 1.2.0
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 +24 -0
- package/es/components/BreakLines/index.d.ts +13 -19
- package/es/components/BreakLines/index.js +2 -3
- package/es/components/BreakLines/index.js.map +1 -1
- package/es/components/ConfigProvider/context.d.ts +20 -26
- package/es/components/ConfigProvider/context.js.map +1 -1
- package/es/components/ConfigProvider/index.d.ts +5 -7
- package/es/components/ConfigProvider/index.js +2 -3
- package/es/components/ConfigProvider/index.js.map +1 -1
- package/es/components/ConfirmAction/index.d.ts +66 -89
- package/es/components/ConfirmAction/index.js +27 -18
- package/es/components/ConfirmAction/index.js.map +1 -1
- package/es/components/ContextMenu/index.d.ts +42 -0
- package/es/components/ContextMenu/index.js +188 -0
- package/es/components/ContextMenu/index.js.map +1 -0
- package/es/components/ContextMenu/style/index.d.ts +3 -0
- package/es/components/ContextMenu/style/index.js +25 -0
- package/es/components/ContextMenu/style/index.js.map +1 -0
- package/es/components/DeleteConfirmAction/index.d.ts +2 -3
- package/es/components/DeleteConfirmAction/index.js +8 -12
- package/es/components/DeleteConfirmAction/index.js.map +1 -1
- package/es/components/EditableText/form.d.ts +150 -0
- package/es/components/EditableText/form.js +359 -0
- package/es/components/EditableText/form.js.map +1 -0
- package/es/components/EditableText/index.d.ts +160 -0
- package/es/components/EditableText/index.js +222 -0
- package/es/components/EditableText/index.js.map +1 -0
- package/es/components/EditableText/style/index.d.ts +3 -0
- package/es/components/EditableText/style/index.js +76 -0
- package/es/components/EditableText/style/index.js.map +1 -0
- package/es/components/FloatDrawer/index.d.ts +89 -86
- package/es/components/FloatDrawer/index.js +43 -20
- package/es/components/FloatDrawer/index.js.map +1 -1
- package/es/components/FloatDrawer/style/index.js +42 -21
- package/es/components/FloatDrawer/style/index.js.map +1 -1
- package/es/components/Loading/index.d.ts +9 -14
- package/es/components/Loading/index.js +7 -6
- package/es/components/Loading/index.js.map +1 -1
- package/es/components/Loading/style/index.js +1 -1
- package/es/components/Loading/style/index.js.map +1 -1
- package/es/components/ModalAction/index.d.ts +98 -139
- package/es/components/ModalAction/index.js +25 -37
- package/es/components/ModalAction/index.js.map +1 -1
- package/es/components/OverflowTags/index.d.ts +30 -8
- package/es/components/OverflowTags/index.js +26 -7
- package/es/components/OverflowTags/index.js.map +1 -1
- package/es/components/OverflowTags/style/index.js +1 -1
- package/es/components/OverflowTags/style/index.js.map +1 -1
- package/es/components/index.d.ts +4 -0
- package/es/components/index.js +2 -0
- package/es/components/index.js.map +1 -1
- package/es/hooks/useRefFunction.d.ts +4 -5
- package/es/hooks/useRefFunction.js +6 -7
- package/es/hooks/useRefFunction.js.map +1 -1
- package/es/hooks/useRefValue.d.ts +2 -3
- package/es/hooks/useRefValue.js +2 -3
- package/es/hooks/useRefValue.js.map +1 -1
- package/es/hooks/useT.js +1 -2
- package/es/hooks/useT.js.map +1 -1
- package/es/hooks/useValidator.d.ts +2 -3
- package/es/hooks/useValidator.js +2 -3
- package/es/hooks/useValidator.js.map +1 -1
- package/es/hooks/useValidatorBuilder.d.ts +41 -61
- package/es/hooks/useValidatorBuilder.js +4 -6
- package/es/hooks/useValidatorBuilder.js.map +1 -1
- package/es/hooks/useValidators.d.ts +62 -83
- package/es/hooks/useValidators.js +3 -4
- package/es/hooks/useValidators.js.map +1 -1
- package/es/locales/index.d.ts +15 -0
- package/es/locales/langs/en-US.d.ts +5 -0
- package/es/locales/langs/en-US.js +5 -0
- package/es/locales/langs/en-US.js.map +1 -1
- package/es/locales/langs/zh-CN.d.ts +5 -0
- package/es/locales/langs/zh-CN.js +5 -0
- package/es/locales/langs/zh-CN.js.map +1 -1
- package/lib/components/BreakLines/index.d.ts +13 -19
- package/lib/components/BreakLines/index.js.map +2 -2
- package/lib/components/ConfigProvider/context.d.ts +20 -26
- package/lib/components/ConfigProvider/context.js.map +2 -2
- package/lib/components/ConfigProvider/index.d.ts +5 -7
- package/lib/components/ConfigProvider/index.js.map +2 -2
- package/lib/components/ConfirmAction/index.d.ts +66 -89
- package/lib/components/ConfirmAction/index.js +9 -0
- package/lib/components/ConfirmAction/index.js.map +2 -2
- package/lib/components/ContextMenu/index.d.ts +42 -0
- package/lib/components/ContextMenu/index.js +190 -0
- package/lib/components/ContextMenu/index.js.map +7 -0
- package/lib/components/ContextMenu/style/index.d.ts +3 -0
- package/lib/components/ContextMenu/style/index.js +48 -0
- package/lib/components/ContextMenu/style/index.js.map +7 -0
- package/lib/components/DeleteConfirmAction/index.d.ts +2 -3
- package/lib/components/DeleteConfirmAction/index.js.map +2 -2
- package/lib/components/EditableText/form.d.ts +150 -0
- package/lib/components/EditableText/form.js +253 -0
- package/lib/components/EditableText/form.js.map +7 -0
- package/lib/components/EditableText/index.d.ts +160 -0
- package/lib/components/EditableText/index.js +181 -0
- package/lib/components/EditableText/index.js.map +7 -0
- package/lib/components/EditableText/style/index.d.ts +3 -0
- package/lib/components/EditableText/style/index.js +118 -0
- package/lib/components/EditableText/style/index.js.map +7 -0
- package/lib/components/FloatDrawer/index.d.ts +89 -86
- package/lib/components/FloatDrawer/index.js +64 -39
- package/lib/components/FloatDrawer/index.js.map +2 -2
- package/lib/components/FloatDrawer/style/index.js +60 -23
- package/lib/components/FloatDrawer/style/index.js.map +2 -2
- package/lib/components/Loading/index.d.ts +9 -14
- package/lib/components/Loading/index.js +13 -4
- package/lib/components/Loading/index.js.map +2 -2
- package/lib/components/Loading/style/index.js +1 -1
- package/lib/components/Loading/style/index.js.map +2 -2
- package/lib/components/ModalAction/index.d.ts +98 -139
- package/lib/components/ModalAction/index.js.map +2 -2
- package/lib/components/OverflowTags/index.d.ts +30 -8
- package/lib/components/OverflowTags/index.js +7 -5
- package/lib/components/OverflowTags/index.js.map +2 -2
- package/lib/components/OverflowTags/style/index.js +1 -1
- package/lib/components/OverflowTags/style/index.js.map +2 -2
- package/lib/components/index.d.ts +4 -0
- package/lib/components/index.js +6 -0
- package/lib/components/index.js.map +2 -2
- package/lib/hooks/useRefFunction.d.ts +4 -5
- package/lib/hooks/useRefFunction.js.map +2 -2
- package/lib/hooks/useRefValue.d.ts +2 -3
- package/lib/hooks/useRefValue.js.map +2 -2
- package/lib/hooks/useT.js.map +2 -2
- package/lib/hooks/useValidator.d.ts +2 -3
- package/lib/hooks/useValidator.js.map +2 -2
- package/lib/hooks/useValidatorBuilder.d.ts +41 -61
- package/lib/hooks/useValidatorBuilder.js.map +2 -2
- package/lib/hooks/useValidators.d.ts +62 -83
- package/lib/hooks/useValidators.js.map +2 -2
- package/lib/locales/index.d.ts +15 -0
- package/lib/locales/langs/en-US.d.ts +5 -0
- package/lib/locales/langs/en-US.js +5 -0
- package/lib/locales/langs/en-US.js.map +2 -2
- package/lib/locales/langs/zh-CN.d.ts +5 -0
- package/lib/locales/langs/zh-CN.js +5 -0
- package/lib/locales/langs/zh-CN.js.map +2 -2
- package/package.json +3 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/ConfigProvider/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { type FC, type ReactNode, useEffect } from 'react';\nimport locales, { langs, resources } from '../../locales';\nimport type localesEn from '../../locales/langs/en';\nimport ReactEasyContext, { type ReactEasyContextProps } from './context';\n\nexport interface ConfigProviderProps extends ReactEasyContextProps {\n /**\n * **EN:** Custom localization resources, if `lang` exists, it will override the localization\n *
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAmD;AACnD,qBAA0C;AAE1C,qBAA6D;
|
|
4
|
+
"sourcesContent": ["import { type FC, type ReactNode, useEffect } from 'react';\nimport locales, { langs, resources } from '../../locales';\nimport type localesEn from '../../locales/langs/en';\nimport ReactEasyContext, { type ReactEasyContextProps } from './context';\n\nexport interface ConfigProviderProps extends ReactEasyContextProps {\n /**\n * - **EN:** Custom localization resources, if `lang` exists, it will override the localization\n * resources of that language, otherwise, it will add a new language\n * - **CN:** 自定义本地化资源,如果`lang`存在,则会覆盖该语言的本地化资源,否则,会添加一种新的语言\n */\n locales?: Partial<typeof localesEn>;\n children: ReactNode;\n}\n\n/**\n * - **EN:** Provide global configuration for AntdHelper\n * - **CN:** 提供AntdHelper的全局配置\n */\nconst ConfigProvider: FC<ConfigProviderProps> = (props) => {\n const { children, locales: userLocales, ...restProps } = props;\n const { lang: langInProps } = restProps;\n\n useEffect(() => {\n // Dynamically add language pack\n if (userLocales) {\n const lang = langInProps || 'en';\n if (lang && langs.includes(lang)) {\n locales.removeResourceBundle(lang, 'translation');\n locales.addResourceBundle(lang, 'translation', { ...resources[lang].translation, ...userLocales });\n } else {\n locales.addResourceBundle(lang, 'translation', { ...resources.en.translation, ...userLocales });\n }\n }\n }, [langInProps, userLocales]);\n\n useEffect(() => {\n // Set the language of the component\n locales.changeLanguage(langInProps || 'en');\n }, [langInProps]);\n\n return <ReactEasyContext.Provider value={restProps}>{children}</ReactEasyContext.Provider>;\n};\n\nexport default ConfigProvider;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAmD;AACnD,qBAA0C;AAE1C,qBAA6D;AAgB7D,IAAM,iBAA0C,CAAC,UAAU;AACzD,QAAM,EAAE,UAAU,SAAS,aAAa,GAAG,UAAU,IAAI;AACzD,QAAM,EAAE,MAAM,YAAY,IAAI;AAE9B,8BAAU,MAAM;AAEd,QAAI,aAAa;AACf,YAAM,OAAO,eAAe;AAC5B,UAAI,QAAQ,qBAAM,SAAS,IAAI,GAAG;AAChC,uBAAAA,QAAQ,qBAAqB,MAAM,aAAa;AAChD,uBAAAA,QAAQ,kBAAkB,MAAM,eAAe,EAAE,GAAG,yBAAU,IAAI,EAAE,aAAa,GAAG,YAAY,CAAC;AAAA,MACnG,OAAO;AACL,uBAAAA,QAAQ,kBAAkB,MAAM,eAAe,EAAE,GAAG,yBAAU,GAAG,aAAa,GAAG,YAAY,CAAC;AAAA,MAChG;AAAA,IACF;AAAA,EACF,GAAG,CAAC,aAAa,WAAW,CAAC;AAE7B,8BAAU,MAAM;AAEd,mBAAAA,QAAQ,eAAe,eAAe,IAAI;AAAA,EAC5C,GAAG,CAAC,WAAW,CAAC;AAEhB,SAAO,oCAAC,eAAAC,QAAiB,UAAjB,EAA0B,OAAO,aAAY,QAAS;AAChE;AAEA,IAAO,yBAAQ;",
|
|
6
6
|
"names": ["locales", "ReactEasyContext"]
|
|
7
7
|
}
|
|
@@ -6,91 +6,76 @@ import type { LinkProps } from 'antd/es/typography/Link';
|
|
|
6
6
|
import type { TextProps } from 'antd/es/typography/Text';
|
|
7
7
|
export type ConfirmActionProps<TP extends object, E extends keyof TP> = Omit<ModalFuncProps, 'onOk'> & ConfirmActionTrigger<TP, E> & {
|
|
8
8
|
/**
|
|
9
|
-
* **EN:** Whether to display in red danger mode, which will automatically affect the color of
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* - **EN:** Whether to display in red danger mode, which will automatically affect the color of
|
|
10
|
+
* the title, icon, and confirm button. Default is `false`, for DeleteConfirmAction, the
|
|
11
|
+
* defaults is `true`.
|
|
13
12
|
* - You can explicitly set `titleColor`, `iconColor`, and `okButtonProps.type` to override
|
|
14
|
-
*
|
|
15
|
-
* **CN:** 是否显示为红色危险模式,会自动影响标题、图标和确认按钮的颜色。默认`false`,DeleteConfirmAction组件的默认值为`true`。
|
|
16
|
-
*
|
|
13
|
+
* - **CN:** 是否显示为红色危险模式,会自动影响标题、图标和确认按钮的颜色。默认`false`,DeleteConfirmAction组件的默认值为`true`。
|
|
17
14
|
* - 可以显式设置`titleColor`、`iconColor`和`okButtonProps.type`来覆盖
|
|
18
15
|
*/
|
|
19
16
|
danger?: boolean;
|
|
20
17
|
/**
|
|
21
|
-
* **EN:** The color of confirm box title, default is `warning`
|
|
22
|
-
*
|
|
23
|
-
* **CN:** 弹框标题颜色,默认`warning`
|
|
18
|
+
* - **EN:** The color of confirm box title, default is `warning`
|
|
19
|
+
* - **CN:** 弹框标题颜色,默认`warning`
|
|
24
20
|
*/
|
|
25
21
|
titleColor?: TextProps['type'] | 'primary';
|
|
26
22
|
/**
|
|
27
|
-
* **EN:** The color of confirm box content
|
|
28
|
-
*
|
|
29
|
-
* **CN:** 弹框内容文本颜色
|
|
23
|
+
* - **EN:** The color of confirm box content
|
|
24
|
+
* - **CN:** 弹框内容文本颜色
|
|
30
25
|
*/
|
|
31
26
|
contentColor?: TextProps['type'] | 'primary';
|
|
32
27
|
/**
|
|
33
|
-
* **EN:** The color of confirm box title icon, default is the same as `titleColor`
|
|
34
|
-
*
|
|
35
|
-
* **CN:** 弹框标题图标颜色,默认与`titleColor`相同
|
|
28
|
+
* - **EN:** The color of confirm box title icon, default is the same as `titleColor`
|
|
29
|
+
* - **CN:** 弹框标题图标颜色,默认与`titleColor`相同
|
|
36
30
|
*/
|
|
37
31
|
iconColor?: TextProps['type'] | 'primary';
|
|
38
32
|
/**
|
|
39
|
-
* **EN:** Callback when click confirm button
|
|
40
|
-
*
|
|
41
|
-
* **CN:** 点击确认按钮的回调
|
|
33
|
+
* - **EN:** Callback when click confirm button
|
|
34
|
+
* - **CN:** 点击确认按钮的回调
|
|
42
35
|
*/
|
|
43
36
|
onOk?: (...args: Parameters<TP[E]>) => unknown | Promise<unknown>;
|
|
44
37
|
/**
|
|
45
|
-
* **EN:** Callback after confirm event, won't trigger if failed, the argument is the return
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* **CN:** 确认事件完成后的回调,失败时不会触发,参数为`onOk`的返回值
|
|
38
|
+
* - **EN:** Callback after confirm event, won't trigger if failed, the argument is the return
|
|
39
|
+
* value of `onOk`
|
|
40
|
+
* - **CN:** 确认事件完成后的回调,失败时不会触发,参数为`onOk`的返回值
|
|
49
41
|
*/
|
|
50
42
|
afterOk?: (data?: any) => void;
|
|
51
43
|
};
|
|
52
44
|
export interface ConfirmActionTrigger<TP extends object, E extends keyof TP> {
|
|
53
45
|
/**
|
|
54
|
-
* **EN:** Trigger component, trigger to show confirm box
|
|
55
|
-
*
|
|
56
|
-
* **CN:** 触发器组件,触发显示确认弹框
|
|
46
|
+
* - **EN:** Trigger component, trigger to show confirm box
|
|
47
|
+
* - **CN:** 触发器组件,触发显示确认弹框
|
|
57
48
|
*/
|
|
58
49
|
triggerComponent?: ComponentType<TP>;
|
|
59
50
|
/**
|
|
60
|
-
* **EN:** Props of trigger component
|
|
61
|
-
*
|
|
62
|
-
* **CN:** 触发器组件的Props属性
|
|
51
|
+
* - **EN:** Props of trigger component
|
|
52
|
+
* - **CN:** 触发器组件的Props属性
|
|
63
53
|
*/
|
|
64
54
|
triggerProps?: TP;
|
|
65
55
|
/**
|
|
66
|
-
* **EN:** The event name that triggers the dialog
|
|
67
|
-
*
|
|
68
|
-
* **CN:** 触发弹窗的事件名称
|
|
69
|
-
*
|
|
56
|
+
* - **EN:** The event name that triggers the dialog
|
|
57
|
+
* - **CN:** 触发弹窗的事件名称
|
|
70
58
|
* - `Button`: 'onClick'
|
|
71
59
|
* - `Switch`: 'onChange'
|
|
72
60
|
* - `Link`: 'onClick'
|
|
73
61
|
*/
|
|
74
62
|
triggerEvent?: E;
|
|
75
63
|
/**
|
|
76
|
-
* **EN:** Custom trigger content
|
|
77
|
-
*
|
|
78
|
-
* **CN:** 自定义触发器内容
|
|
64
|
+
* - **EN:** Custom trigger content
|
|
65
|
+
* - **CN:** 自定义触发器内容
|
|
79
66
|
*/
|
|
80
67
|
children?: ReactNode;
|
|
81
68
|
}
|
|
82
69
|
export type ConfirmActionRef = ReturnType<typeof confirm> & {
|
|
83
70
|
/**
|
|
84
|
-
* **EN:** Show confirm box
|
|
85
|
-
*
|
|
86
|
-
* **CN:** 显示确认弹框
|
|
71
|
+
* - **EN:** Show confirm box
|
|
72
|
+
* - **CN:** 显示确认弹框
|
|
87
73
|
*/
|
|
88
74
|
show: (props?: Parameters<ModalFunc>[0]) => ReturnType<ModalFunc>;
|
|
89
75
|
};
|
|
90
76
|
/**
|
|
91
|
-
* **EN:** Generate a confirm box component
|
|
92
|
-
*
|
|
93
|
-
* **CN:** 生成一个确认弹框组件
|
|
77
|
+
* - **EN:** Generate a confirm box component
|
|
78
|
+
* - **CN:** 生成一个确认弹框组件
|
|
94
79
|
*
|
|
95
80
|
* @param defaultProps Default props | 默认属性
|
|
96
81
|
*
|
|
@@ -103,100 +88,92 @@ export declare const genRenderer: (defaultProps: Partial<ConfirmActionProps<any,
|
|
|
103
88
|
displayName: string;
|
|
104
89
|
};
|
|
105
90
|
/**
|
|
106
|
-
* **EN:** Add default properties to the ConfirmAction component
|
|
107
|
-
*
|
|
108
|
-
* **CN:** 给ConfirmAction组件添加默认属性
|
|
91
|
+
* - **EN:** Add default properties to the ConfirmAction component
|
|
92
|
+
* - **CN:** 给ConfirmAction组件添加默认属性
|
|
109
93
|
*
|
|
110
94
|
* @param WrappedComponent ConfirmAction component | ConfirmAction组件
|
|
111
95
|
* @param defaultProps Default properties | 默认属性
|
|
112
96
|
*/
|
|
113
97
|
export declare const withDefaultConfirmActionProps: <TP extends object, E extends keyof TP>(WrappedComponent: ComponentType<PropsWithoutRef<ConfirmActionProps<TP, E>> & RefAttributes<ConfirmActionRef>>, defaultProps?: Partial<ConfirmActionProps<TP, E>>) => import("react").ForwardRefExoticComponent<Omit<ModalFuncProps, "onOk"> & ConfirmActionTrigger<TP, E> & {
|
|
114
98
|
/**
|
|
115
|
-
* **EN:** Whether to display in red danger mode, which will automatically affect the color of
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
99
|
+
* - **EN:** Whether to display in red danger mode, which will automatically affect the color of
|
|
100
|
+
* the title, icon, and confirm button. Default is `false`, for DeleteConfirmAction, the
|
|
101
|
+
* defaults is `true`.
|
|
119
102
|
* - You can explicitly set `titleColor`, `iconColor`, and `okButtonProps.type` to override
|
|
120
|
-
*
|
|
121
|
-
* **CN:** 是否显示为红色危险模式,会自动影响标题、图标和确认按钮的颜色。默认`false`,DeleteConfirmAction组件的默认值为`true`。
|
|
122
|
-
*
|
|
103
|
+
* - **CN:** 是否显示为红色危险模式,会自动影响标题、图标和确认按钮的颜色。默认`false`,DeleteConfirmAction组件的默认值为`true`。
|
|
123
104
|
* - 可以显式设置`titleColor`、`iconColor`和`okButtonProps.type`来覆盖
|
|
124
105
|
*/
|
|
125
106
|
danger?: boolean | undefined;
|
|
126
107
|
/**
|
|
127
|
-
* **EN:** The color of confirm box title, default is `warning`
|
|
128
|
-
*
|
|
129
|
-
* **CN:** 弹框标题颜色,默认`warning`
|
|
108
|
+
* - **EN:** The color of confirm box title, default is `warning`
|
|
109
|
+
* - **CN:** 弹框标题颜色,默认`warning`
|
|
130
110
|
*/
|
|
131
111
|
titleColor?: TextProps['type'] | 'primary';
|
|
132
112
|
/**
|
|
133
|
-
* **EN:** The color of confirm box content
|
|
134
|
-
*
|
|
135
|
-
* **CN:** 弹框内容文本颜色
|
|
113
|
+
* - **EN:** The color of confirm box content
|
|
114
|
+
* - **CN:** 弹框内容文本颜色
|
|
136
115
|
*/
|
|
137
116
|
contentColor?: TextProps['type'] | 'primary';
|
|
138
117
|
/**
|
|
139
|
-
* **EN:** The color of confirm box title icon, default is the same as `titleColor`
|
|
140
|
-
*
|
|
141
|
-
* **CN:** 弹框标题图标颜色,默认与`titleColor`相同
|
|
118
|
+
* - **EN:** The color of confirm box title icon, default is the same as `titleColor`
|
|
119
|
+
* - **CN:** 弹框标题图标颜色,默认与`titleColor`相同
|
|
142
120
|
*/
|
|
143
121
|
iconColor?: TextProps['type'] | 'primary';
|
|
144
122
|
/**
|
|
145
|
-
* **EN:** Callback when click confirm button
|
|
146
|
-
*
|
|
147
|
-
* **CN:** 点击确认按钮的回调
|
|
123
|
+
* - **EN:** Callback when click confirm button
|
|
124
|
+
* - **CN:** 点击确认按钮的回调
|
|
148
125
|
*/
|
|
149
126
|
onOk?: ((...args: Parameters<TP[E]>) => unknown | Promise<unknown>) | undefined;
|
|
150
127
|
/**
|
|
151
|
-
* **EN:** Callback after confirm event, won't trigger if failed, the argument is the return
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
* **CN:** 确认事件完成后的回调,失败时不会触发,参数为`onOk`的返回值
|
|
128
|
+
* - **EN:** Callback after confirm event, won't trigger if failed, the argument is the return
|
|
129
|
+
* value of `onOk`
|
|
130
|
+
* - **CN:** 确认事件完成后的回调,失败时不会触发,参数为`onOk`的返回值
|
|
155
131
|
*/
|
|
156
132
|
afterOk?: ((data?: any) => void) | undefined;
|
|
157
133
|
} & RefAttributes<ConfirmActionRef>>;
|
|
158
134
|
/**
|
|
159
|
-
* **EN:** Interface of generic type component
|
|
160
|
-
*
|
|
161
|
-
* **CN:** 泛型组件的接口
|
|
135
|
+
* - **EN:** Interface of generic type component
|
|
136
|
+
* - **CN:** 泛型组件的接口
|
|
162
137
|
*/
|
|
163
138
|
export type GenericConfirmActionInterface = <TP extends object, E extends keyof TP>(props: PropsWithoutRef<TypedConfirmActionProps<TP, E>> & RefAttributes<ConfirmActionRef>) => ReactElement;
|
|
164
139
|
/**
|
|
165
|
-
* **EN:** Interface of specific type component
|
|
166
|
-
*
|
|
167
|
-
* **CN:** 具体类型组件的接口
|
|
140
|
+
* - **EN:** Interface of specific type component
|
|
141
|
+
* - **CN:** 具体类型组件的接口
|
|
168
142
|
*/
|
|
169
143
|
export type TypedConfirmActionInterface<TP extends object, E extends keyof TP> = ComponentType<PropsWithoutRef<TypedConfirmActionProps<TP, E>> & RefAttributes<ConfirmActionRef>>;
|
|
170
144
|
/**
|
|
171
|
-
* **EN:** Props definition of specific type component
|
|
172
|
-
*
|
|
173
|
-
* **CN:** 具体类型组件的Props定义
|
|
145
|
+
* - **EN:** Props definition of specific type component
|
|
146
|
+
* - **CN:** 具体类型组件的Props定义
|
|
174
147
|
*/
|
|
175
148
|
type TypedConfirmActionProps<TP extends object, E extends keyof TP> = Omit<ConfirmActionProps<TP, E>, 'triggerComponent' | 'triggerEvent'>;
|
|
176
149
|
export type ConfirmActionWithStatic = GenericConfirmActionInterface & {
|
|
177
150
|
/**
|
|
178
|
-
* **EN:** Confirm box with button trigger
|
|
179
|
-
*
|
|
180
|
-
* **CN:** 按钮类型的确认框
|
|
151
|
+
* - **EN:** Confirm box with button trigger
|
|
152
|
+
* - **CN:** 按钮类型的确认框
|
|
181
153
|
*/
|
|
182
154
|
Button: TypedConfirmActionInterface<ButtonProps, 'onClick'>;
|
|
183
155
|
/**
|
|
184
|
-
* **EN:** Confirm box with switch trigger
|
|
185
|
-
*
|
|
186
|
-
* **CN:** 开关类型的确认框
|
|
156
|
+
* - **EN:** Confirm box with switch trigger
|
|
157
|
+
* - **CN:** 开关类型的确认框
|
|
187
158
|
*/
|
|
188
159
|
Switch: TypedConfirmActionInterface<SwitchProps, 'onChange'>;
|
|
189
160
|
/**
|
|
190
|
-
* **EN:** Confirm box with link trigger
|
|
191
|
-
*
|
|
192
|
-
* **CN:** 链接类型的确认框
|
|
161
|
+
* - **EN:** Confirm box with link trigger
|
|
162
|
+
* - **CN:** 链接类型的确认框
|
|
193
163
|
*/
|
|
194
164
|
Link: TypedConfirmActionInterface<LinkProps, 'onClick'>;
|
|
195
165
|
};
|
|
196
166
|
/**
|
|
197
|
-
* **EN:** Confirm box component with trigger
|
|
198
|
-
*
|
|
199
|
-
* **CN:** 带触发器的确认框组件
|
|
167
|
+
* - **EN:** Confirm box component with trigger
|
|
168
|
+
* - **CN:** 带触发器的确认框组件
|
|
200
169
|
*/
|
|
201
170
|
declare const ConfirmAction: ConfirmActionWithStatic;
|
|
171
|
+
/**
|
|
172
|
+
* - **EN:** Generate a confirm box component with custom trigger and default props
|
|
173
|
+
* - **CN:** 基于自定义触发器和默认属性生成一个确认弹框组件
|
|
174
|
+
*
|
|
175
|
+
* @param actionComponent Custom trigger component | 自定义触发器组件
|
|
176
|
+
* @param defaultProps Default properties of the confirm box | 确认弹框的默认属性
|
|
177
|
+
*/
|
|
178
|
+
export declare function withConfirmAction<TP extends object, E extends keyof TP>(actionComponent: ComponentType<TP>, defaultProps?: Partial<ConfirmActionProps<TP, E>> | (() => Partial<ConfirmActionProps<TP, E>>)): ComponentType<Omit<ConfirmActionProps<TP, E>, "triggerComponent"> & RefAttributes<ConfirmActionRef>>;
|
|
202
179
|
export default ConfirmAction;
|
|
@@ -31,6 +31,7 @@ var ConfirmAction_exports = {};
|
|
|
31
31
|
__export(ConfirmAction_exports, {
|
|
32
32
|
default: () => ConfirmAction_default,
|
|
33
33
|
genRenderer: () => genRenderer,
|
|
34
|
+
withConfirmAction: () => withConfirmAction,
|
|
34
35
|
withDefaultConfirmActionProps: () => withDefaultConfirmActionProps
|
|
35
36
|
});
|
|
36
37
|
module.exports = __toCommonJS(ConfirmAction_exports);
|
|
@@ -228,10 +229,18 @@ ConfirmAction.Link = withDefaultConfirmActionProps(forwarded, {
|
|
|
228
229
|
style: { whiteSpace: "nowrap" }
|
|
229
230
|
}
|
|
230
231
|
});
|
|
232
|
+
function withConfirmAction(actionComponent, defaultProps) {
|
|
233
|
+
const withTrigger = withDefaultConfirmActionProps(forwarded, {
|
|
234
|
+
triggerComponent: actionComponent,
|
|
235
|
+
...typeof defaultProps === "function" ? defaultProps() : defaultProps
|
|
236
|
+
});
|
|
237
|
+
return withTrigger;
|
|
238
|
+
}
|
|
231
239
|
var ConfirmAction_default = ConfirmAction;
|
|
232
240
|
// Annotate the CommonJS export names for ESM import in node:
|
|
233
241
|
0 && (module.exports = {
|
|
234
242
|
genRenderer,
|
|
243
|
+
withConfirmAction,
|
|
235
244
|
withDefaultConfirmActionProps
|
|
236
245
|
});
|
|
237
246
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/ConfirmAction/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import type { ComponentType, ForwardedRef, PropsWithoutRef, ReactElement, ReactNode, RefAttributes } from 'react';\nimport { forwardRef, useContext, useImperativeHandle, useRef, useState } from 'react';\nimport type { ButtonProps, ModalFuncProps, SwitchProps } from 'antd';\nimport { App, Button, Modal, Switch, Typography } from 'antd';\nimport type { ModalFunc } from 'antd/es/modal/confirm';\nimport type confirm from 'antd/es/modal/confirm';\nimport useToken from 'antd/es/theme/useToken';\nimport type { LinkProps } from 'antd/es/typography/Link';\nimport type { TextProps } from 'antd/es/typography/Text';\nimport useContextValidator from '../../hooks/useContextValidator';\nimport useLocalizedText from '../../hooks/useLocalizedText';\nimport useRefFunction from '../../hooks/useRefFunction';\nimport ReactEasyContext from '../ConfigProvider/context';\n\nexport type ConfirmActionProps<TP extends object, E extends keyof TP> = Omit<ModalFuncProps, 'onOk'> &\n ConfirmActionTrigger<TP, E> & {\n /**\n * **EN:** Whether to display in red danger mode, which will automatically affect the color of\n * the title, icon, and confirm button. Default is `false`, for DeleteConfirmAction, the\n * defaults is `true`.\n *\n * - You can explicitly set `titleColor`, `iconColor`, and `okButtonProps.type` to override\n *\n * **CN:** 是否显示为红色危险模式,会自动影响标题、图标和确认按钮的颜色。默认`false`,DeleteConfirmAction组件的默认值为`true`。\n *\n * - 可以显式设置`titleColor`、`iconColor`和`okButtonProps.type`来覆盖\n */\n danger?: boolean;\n /**\n * **EN:** The color of confirm box title, default is `warning`\n *\n * **CN:** 弹框标题颜色,默认`warning`\n */\n titleColor?: TextProps['type'] | 'primary';\n /**\n * **EN:** The color of confirm box content\n *\n * **CN:** 弹框内容文本颜色\n */\n contentColor?: TextProps['type'] | 'primary';\n /**\n * **EN:** The color of confirm box title icon, default is the same as `titleColor`\n *\n * **CN:** 弹框标题图标颜色,默认与`titleColor`相同\n */\n iconColor?: TextProps['type'] | 'primary';\n /**\n * **EN:** Callback when click confirm button\n *\n * **CN:** 点击确认按钮的回调\n */\n // @ts-expect-error: because TP[E] should be casted to function type\n onOk?: (...args: Parameters<TP[E]>) => unknown | Promise<unknown>;\n /**\n * **EN:** Callback after confirm event, won't trigger if failed, the argument is the return\n * 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 ConfirmActionTrigger<TP extends object, E extends keyof TP> {\n /**\n * **EN:** Trigger component, trigger to show confirm box\n *\n * **CN:** 触发器组件,触发显示确认弹框\n */\n triggerComponent?: ComponentType<TP>;\n /**\n * **EN:** Props of trigger component\n *\n * **CN:** 触发器组件的Props属性\n */\n triggerProps?: TP;\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 ConfirmActionRef = ReturnType<typeof confirm> & {\n /**\n * **EN:** Show confirm box\n *\n * **CN:** 显示确认弹框\n */\n show: (props?: Parameters<ModalFunc>[0]) => ReturnType<ModalFunc>;\n};\n\n/**\n * **EN:** Generate a confirm box component\n *\n * **CN:** 生成一个确认弹框组件\n *\n * @param defaultProps Default props | 默认属性\n *\n * @returns Component render method | 组件render方法\n */\nexport const genRenderer = (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n defaultProps: Partial<ConfirmActionProps<any, never>> & { confirmType: 'normal' | 'delete' }\n) => {\n const Render = <TP extends object, E extends keyof TP>(\n props: ConfirmActionProps<TP, E>,\n ref: ForwardedRef<ConfirmActionRef>\n ) => {\n const { confirmType, ...restDefaults } = defaultProps;\n const mergedProps: ConfirmActionProps<TP, E> = {\n ...restDefaults,\n ...props,\n okButtonProps: {\n ...restDefaults.okButtonProps,\n ...props.okButtonProps,\n },\n cancelButtonProps: {\n ...restDefaults.cancelButtonProps,\n ...props.cancelButtonProps,\n },\n bodyProps: {\n ...restDefaults.bodyProps,\n ...props.bodyProps,\n },\n maskProps: {\n ...restDefaults.maskProps,\n ...props.maskProps,\n },\n wrapProps: {\n ...restDefaults.wrapProps,\n ...props.wrapProps,\n },\n triggerProps: {\n ...restDefaults.triggerProps,\n ...props.triggerProps,\n style: {\n ...restDefaults.triggerProps?.style,\n ...(props.triggerProps && 'style' in props.triggerProps && typeof props.triggerProps.style === 'object'\n ? props.triggerProps.style\n : {}),\n },\n } as TP,\n };\n const context = useContext(ReactEasyContext);\n const defaultTitle = useLocalizedText(\n confirmType === 'delete' ? context.defaultDeletionConfirmTitle : context.defaultConfirmTitle\n );\n const defaultContent = useLocalizedText(\n confirmType === 'delete' ? context.defaultDeletionConfirmContent : context.defaultConfirmContent\n );\n const {\n triggerComponent: Trigger = Button,\n triggerEvent = 'onClick' as E,\n triggerProps,\n danger,\n title = defaultTitle,\n content = defaultContent,\n titleColor,\n contentColor,\n icon,\n iconColor,\n okButtonProps,\n cancelButtonProps,\n onOk,\n afterOk,\n children,\n ...restProps\n } = mergedProps;\n\n useContextValidator();\n\n const app = App.useApp();\n // @ts-expect-error: because app may return a stub object when App is not used\n const modal = app.modal?.confirm ? app.modal : Modal;\n const { localize } = useContext(ReactEasyContext);\n const [, token] = useToken();\n const [confirmApi, setConfirmApi] = useState<ReturnType<typeof confirm>>();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const triggerEventArgsRef = useRef<any[]>(undefined);\n\n const fallbackColor = danger ? 'danger' : undefined;\n // Text with color\n const coloredText = (text: ReactNode, color?: TextProps['type'] | 'primary') => {\n const textContent = typeof text === 'string' ? (localize?.(text) ?? text) : text;\n if (!color) {\n return textContent;\n }\n if (color === 'primary') {\n return <Typography.Text style={{ color: token.colorPrimary }}>{textContent}</Typography.Text>;\n }\n return textContent ? <Typography.Text type={color}>{textContent}</Typography.Text> : undefined;\n };\n\n // Show confirm box\n const showConfirm: ConfirmActionRef['show'] = useRefFunction(() => {\n const okProps: ButtonProps = {\n ...(danger ? { type: 'primary', danger: true } : {}),\n ...(okButtonProps ?? {}),\n };\n const cancelProps: ButtonProps = {\n ...(cancelButtonProps ?? {}),\n };\n const api = modal.confirm({\n title: coloredText(title, titleColor ?? fallbackColor ?? 'warning'),\n content: coloredText(content, contentColor),\n icon: coloredText(icon, iconColor ?? fallbackColor ?? 'warning'),\n autoFocusButton: null,\n okButtonProps: okProps,\n cancelButtonProps: cancelProps,\n onOk: async () => {\n try {\n api.update({\n closable: true,\n okButtonProps: {\n loading: true,\n ...okProps,\n },\n cancelButtonProps: {\n disabled: true,\n ...cancelProps,\n },\n });\n const result = await onOk?.(...((triggerEventArgsRef.current ?? []) as Parameters<typeof onOk>));\n afterOk?.(result);\n } finally {\n api.update({\n closable: false,\n okButtonProps: {\n loading: false,\n ...okProps,\n },\n cancelButtonProps: {\n disabled: false,\n ...cancelProps,\n },\n });\n }\n },\n ...restProps,\n });\n setConfirmApi(api);\n return api;\n });\n\n // Output ref\n useImperativeHandle(ref, () => ({ show: showConfirm, ...confirmApi! }), [showConfirm, confirmApi]);\n\n // Render trigger component\n return (\n <Trigger\n {...triggerProps}\n // Trigger event\n {...((triggerEvent\n ? {\n [triggerEvent]: (...args: any[]) => {\n triggerEventArgsRef.current = args;\n const api = showConfirm();\n if (triggerProps && typeof triggerProps[triggerEvent] === 'function') {\n (triggerProps[triggerEvent] as (...args: any[]) => void)(...args, { api });\n }\n },\n }\n : {}) as TP)}\n >\n {(triggerProps as { children?: ReactNode }).children ?? children}\n </Trigger>\n );\n };\n Render.displayName = 'ConfirmAction';\n return Render;\n};\n\n/**\n * **EN:** Add default properties to the ConfirmAction component\n *\n * **CN:** 给ConfirmAction组件添加默认属性\n *\n * @param WrappedComponent ConfirmAction component | ConfirmAction组件\n * @param defaultProps Default properties | 默认属性\n */\nexport const withDefaultConfirmActionProps = <TP extends object, E extends keyof TP>(\n WrappedComponent: ComponentType<PropsWithoutRef<ConfirmActionProps<TP, E>> & RefAttributes<ConfirmActionRef>>,\n defaultProps?: Partial<ConfirmActionProps<TP, E>>\n) => {\n const WithDefaultProps = forwardRef<ConfirmActionRef, ConfirmActionProps<TP, E>>((props, ref) => {\n const mergedProps: ConfirmActionProps<TP, E> = {\n ...defaultProps,\n ...props,\n triggerProps: {\n ...defaultProps?.triggerProps,\n ...props.triggerProps,\n } as TP,\n };\n return <WrappedComponent ref={ref} {...mergedProps} />;\n });\n WithDefaultProps.displayName = 'ForwardedRef(WithDefaultProps)';\n return WithDefaultProps;\n};\n\nconst renderConfirmAction = genRenderer({\n confirmType: 'normal',\n});\nconst forwarded = forwardRef(renderConfirmAction);\nforwarded.displayName = 'ForwardedRef(ConfirmAction)';\n\n/**\n * **EN:** Interface of generic type component\n *\n * **CN:** 泛型组件的接口\n */\nexport type GenericConfirmActionInterface = <TP extends object, E extends keyof TP>(\n props: PropsWithoutRef<TypedConfirmActionProps<TP, E>> & RefAttributes<ConfirmActionRef>\n) => ReactElement;\n\n/**\n * **EN:** Interface of specific type component\n *\n * **CN:** 具体类型组件的接口\n */\nexport type TypedConfirmActionInterface<TP extends object, E extends keyof TP> = ComponentType<\n PropsWithoutRef<TypedConfirmActionProps<TP, E>> & RefAttributes<ConfirmActionRef>\n>;\n\n/**\n * **EN:** Props definition of specific type component\n *\n * **CN:** 具体类型组件的Props定义\n */\ntype TypedConfirmActionProps<TP extends object, E extends keyof TP> = Omit<\n ConfirmActionProps<TP, E>,\n 'triggerComponent' | 'triggerEvent'\n>;\nexport type ConfirmActionWithStatic = GenericConfirmActionInterface & {\n /**\n * **EN:** Confirm box with button trigger\n *\n * **CN:** 按钮类型的确认框\n */\n Button: TypedConfirmActionInterface<ButtonProps, 'onClick'>;\n /**\n * **EN:** Confirm box with switch trigger\n *\n * **CN:** 开关类型的确认框\n */\n Switch: TypedConfirmActionInterface<SwitchProps, 'onChange'>;\n /**\n * **EN:** Confirm box with link trigger\n *\n * **CN:** 链接类型的确认框\n */\n Link: TypedConfirmActionInterface<LinkProps, 'onClick'>;\n};\n\n/**\n * **EN:** Confirm box component with trigger\n *\n * **CN:** 带触发器的确认框组件\n */\nconst ConfirmAction = forwarded as unknown as ConfirmActionWithStatic;\n// Type of button\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nConfirmAction.Button = withDefaultConfirmActionProps<ButtonProps, 'onClick'>(forwarded as any, {\n triggerComponent: Button,\n triggerEvent: 'onClick',\n triggerProps: {},\n});\n// Type of switch\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nConfirmAction.Switch = withDefaultConfirmActionProps<SwitchProps, 'onChange'>(forwarded as any, {\n triggerComponent: Switch,\n triggerEvent: 'onChange',\n triggerProps: {},\n});\n// Type of link\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nConfirmAction.Link = withDefaultConfirmActionProps<LinkProps, 'onClick'>(forwarded as any, {\n triggerComponent: Typography.Link,\n triggerEvent: 'onClick',\n triggerProps: {\n style: { whiteSpace: 'nowrap' },\n },\n});\n\nexport default ConfirmAction;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA8E;AAE9E,kBAAuD;AAGvD,sBAAqB;AAGrB,iCAAgC;AAChC,8BAA6B;AAC7B,4BAA2B;AAC3B,qBAA6B;
|
|
4
|
+
"sourcesContent": ["import type { ComponentType, ForwardedRef, PropsWithoutRef, ReactElement, ReactNode, RefAttributes } from 'react';\nimport { forwardRef, useContext, useImperativeHandle, useRef, useState } from 'react';\nimport type { ButtonProps, ModalFuncProps, SwitchProps } from 'antd';\nimport { App, Button, Modal, Switch, Typography } from 'antd';\nimport type { ModalFunc } from 'antd/es/modal/confirm';\nimport type confirm from 'antd/es/modal/confirm';\nimport useToken from 'antd/es/theme/useToken';\nimport type { LinkProps } from 'antd/es/typography/Link';\nimport type { TextProps } from 'antd/es/typography/Text';\nimport useContextValidator from '../../hooks/useContextValidator';\nimport useLocalizedText from '../../hooks/useLocalizedText';\nimport useRefFunction from '../../hooks/useRefFunction';\nimport ReactEasyContext from '../ConfigProvider/context';\n\nexport type ConfirmActionProps<TP extends object, E extends keyof TP> = Omit<ModalFuncProps, 'onOk'> &\n ConfirmActionTrigger<TP, E> & {\n /**\n * - **EN:** Whether to display in red danger mode, which will automatically affect the color of\n * the title, icon, and confirm button. Default is `false`, for DeleteConfirmAction, the\n * defaults is `true`.\n * - You can explicitly set `titleColor`, `iconColor`, and `okButtonProps.type` to override\n * - **CN:** 是否显示为红色危险模式,会自动影响标题、图标和确认按钮的颜色。默认`false`,DeleteConfirmAction组件的默认值为`true`。\n * - 可以显式设置`titleColor`、`iconColor`和`okButtonProps.type`来覆盖\n */\n danger?: boolean;\n /**\n * - **EN:** The color of confirm box title, default is `warning`\n * - **CN:** 弹框标题颜色,默认`warning`\n */\n titleColor?: TextProps['type'] | 'primary';\n /**\n * - **EN:** The color of confirm box content\n * - **CN:** 弹框内容文本颜色\n */\n contentColor?: TextProps['type'] | 'primary';\n /**\n * - **EN:** The color of confirm box title icon, default is the same as `titleColor`\n * - **CN:** 弹框标题图标颜色,默认与`titleColor`相同\n */\n iconColor?: TextProps['type'] | 'primary';\n /**\n * - **EN:** Callback when click confirm button\n * - **CN:** 点击确认按钮的回调\n */\n // @ts-expect-error: because TP[E] should be casted to function type\n onOk?: (...args: Parameters<TP[E]>) => unknown | Promise<unknown>;\n /**\n * - **EN:** Callback after confirm event, won't trigger if failed, the argument is the return\n * value of `onOk`\n * - **CN:** 确认事件完成后的回调,失败时不会触发,参数为`onOk`的返回值\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n afterOk?: (data?: any) => void;\n };\n\nexport interface ConfirmActionTrigger<TP extends object, E extends keyof TP> {\n /**\n * - **EN:** Trigger component, trigger to show confirm box\n * - **CN:** 触发器组件,触发显示确认弹框\n */\n triggerComponent?: ComponentType<TP>;\n /**\n * - **EN:** Props of trigger component\n * - **CN:** 触发器组件的Props属性\n */\n triggerProps?: TP;\n /**\n * - **EN:** The event name that triggers the dialog\n * - **CN:** 触发弹窗的事件名称\n * - `Button`: 'onClick'\n * - `Switch`: 'onChange'\n * - `Link`: 'onClick'\n */\n triggerEvent?: E;\n /**\n * - **EN:** Custom trigger content\n * - **CN:** 自定义触发器内容\n */\n children?: ReactNode;\n}\nexport type ConfirmActionRef = ReturnType<typeof confirm> & {\n /**\n * - **EN:** Show confirm box\n * - **CN:** 显示确认弹框\n */\n show: (props?: Parameters<ModalFunc>[0]) => ReturnType<ModalFunc>;\n};\n\n/**\n * - **EN:** Generate a confirm box component\n * - **CN:** 生成一个确认弹框组件\n *\n * @param defaultProps Default props | 默认属性\n *\n * @returns Component render method | 组件render方法\n */\nexport const genRenderer = (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n defaultProps: Partial<ConfirmActionProps<any, never>> & { confirmType: 'normal' | 'delete' }\n) => {\n const Render = <TP extends object, E extends keyof TP>(\n props: ConfirmActionProps<TP, E>,\n ref: ForwardedRef<ConfirmActionRef>\n ) => {\n const { confirmType, ...restDefaults } = defaultProps;\n const mergedProps: ConfirmActionProps<TP, E> = {\n ...restDefaults,\n ...props,\n okButtonProps: {\n ...restDefaults.okButtonProps,\n ...props.okButtonProps,\n },\n cancelButtonProps: {\n ...restDefaults.cancelButtonProps,\n ...props.cancelButtonProps,\n },\n bodyProps: {\n ...restDefaults.bodyProps,\n ...props.bodyProps,\n },\n maskProps: {\n ...restDefaults.maskProps,\n ...props.maskProps,\n },\n wrapProps: {\n ...restDefaults.wrapProps,\n ...props.wrapProps,\n },\n triggerProps: {\n ...restDefaults.triggerProps,\n ...props.triggerProps,\n style: {\n ...restDefaults.triggerProps?.style,\n ...(props.triggerProps && 'style' in props.triggerProps && typeof props.triggerProps.style === 'object'\n ? props.triggerProps.style\n : {}),\n },\n } as TP,\n };\n const context = useContext(ReactEasyContext);\n const defaultTitle = useLocalizedText(\n confirmType === 'delete' ? context.defaultDeletionConfirmTitle : context.defaultConfirmTitle\n );\n const defaultContent = useLocalizedText(\n confirmType === 'delete' ? context.defaultDeletionConfirmContent : context.defaultConfirmContent\n );\n const {\n triggerComponent: Trigger = Button,\n triggerEvent = 'onClick' as E,\n triggerProps,\n danger,\n title = defaultTitle,\n content = defaultContent,\n titleColor,\n contentColor,\n icon,\n iconColor,\n okButtonProps,\n cancelButtonProps,\n onOk,\n afterOk,\n children,\n ...restProps\n } = mergedProps;\n\n useContextValidator();\n\n const app = App.useApp();\n // @ts-expect-error: because app may return a stub object when App is not used\n const modal = app.modal?.confirm ? app.modal : Modal;\n const { localize } = useContext(ReactEasyContext);\n const [, token] = useToken();\n const [confirmApi, setConfirmApi] = useState<ReturnType<typeof confirm>>();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const triggerEventArgsRef = useRef<any[]>(undefined);\n\n const fallbackColor = danger ? 'danger' : undefined;\n // Text with color\n const coloredText = (text: ReactNode, color?: TextProps['type'] | 'primary') => {\n const textContent = typeof text === 'string' ? (localize?.(text) ?? text) : text;\n if (!color) {\n return textContent;\n }\n if (color === 'primary') {\n return <Typography.Text style={{ color: token.colorPrimary }}>{textContent}</Typography.Text>;\n }\n return textContent ? <Typography.Text type={color}>{textContent}</Typography.Text> : undefined;\n };\n\n // Show confirm box\n const showConfirm: ConfirmActionRef['show'] = useRefFunction(() => {\n const okProps: ButtonProps = {\n ...(danger ? { type: 'primary', danger: true } : {}),\n ...(okButtonProps ?? {}),\n };\n const cancelProps: ButtonProps = {\n ...(cancelButtonProps ?? {}),\n };\n const api = modal.confirm({\n title: coloredText(title, titleColor ?? fallbackColor ?? 'warning'),\n content: coloredText(content, contentColor),\n icon: coloredText(icon, iconColor ?? fallbackColor ?? 'warning'),\n autoFocusButton: null,\n okButtonProps: okProps,\n cancelButtonProps: cancelProps,\n onOk: async () => {\n try {\n api.update({\n closable: true,\n okButtonProps: {\n loading: true,\n ...okProps,\n },\n cancelButtonProps: {\n disabled: true,\n ...cancelProps,\n },\n });\n const result = await onOk?.(...((triggerEventArgsRef.current ?? []) as Parameters<typeof onOk>));\n afterOk?.(result);\n } finally {\n api.update({\n closable: false,\n okButtonProps: {\n loading: false,\n ...okProps,\n },\n cancelButtonProps: {\n disabled: false,\n ...cancelProps,\n },\n });\n }\n },\n ...restProps,\n });\n setConfirmApi(api);\n return api;\n });\n\n // Output ref\n useImperativeHandle(ref, () => ({ show: showConfirm, ...confirmApi! }), [showConfirm, confirmApi]);\n\n // Render trigger component\n return (\n <Trigger\n {...triggerProps}\n // Trigger event\n {...((triggerEvent\n ? {\n [triggerEvent]: (...args: any[]) => {\n triggerEventArgsRef.current = args;\n const api = showConfirm();\n if (triggerProps && typeof triggerProps[triggerEvent] === 'function') {\n (triggerProps[triggerEvent] as (...args: any[]) => void)(...args, { api });\n }\n },\n }\n : {}) as TP)}\n >\n {(triggerProps as { children?: ReactNode }).children ?? children}\n </Trigger>\n );\n };\n Render.displayName = 'ConfirmAction';\n return Render;\n};\n\n/**\n * - **EN:** Add default properties to the ConfirmAction component\n * - **CN:** 给ConfirmAction组件添加默认属性\n *\n * @param WrappedComponent ConfirmAction component | ConfirmAction组件\n * @param defaultProps Default properties | 默认属性\n */\nexport const withDefaultConfirmActionProps = <TP extends object, E extends keyof TP>(\n WrappedComponent: ComponentType<PropsWithoutRef<ConfirmActionProps<TP, E>> & RefAttributes<ConfirmActionRef>>,\n defaultProps?: Partial<ConfirmActionProps<TP, E>>\n) => {\n const WithDefaultProps = forwardRef<ConfirmActionRef, ConfirmActionProps<TP, E>>((props, ref) => {\n const mergedProps: ConfirmActionProps<TP, E> = {\n ...defaultProps,\n ...props,\n triggerProps: {\n ...defaultProps?.triggerProps,\n ...props.triggerProps,\n } as TP,\n };\n return <WrappedComponent ref={ref} {...mergedProps} />;\n });\n WithDefaultProps.displayName = 'ForwardedRef(WithDefaultProps)';\n return WithDefaultProps;\n};\n\nconst renderConfirmAction = genRenderer({\n confirmType: 'normal',\n});\nconst forwarded = forwardRef(renderConfirmAction);\nforwarded.displayName = 'ForwardedRef(ConfirmAction)';\n\n/**\n * - **EN:** Interface of generic type component\n * - **CN:** 泛型组件的接口\n */\nexport type GenericConfirmActionInterface = <TP extends object, E extends keyof TP>(\n props: PropsWithoutRef<TypedConfirmActionProps<TP, E>> & RefAttributes<ConfirmActionRef>\n) => ReactElement;\n\n/**\n * - **EN:** Interface of specific type component\n * - **CN:** 具体类型组件的接口\n */\nexport type TypedConfirmActionInterface<TP extends object, E extends keyof TP> = ComponentType<\n PropsWithoutRef<TypedConfirmActionProps<TP, E>> & RefAttributes<ConfirmActionRef>\n>;\n\n/**\n * - **EN:** Props definition of specific type component\n * - **CN:** 具体类型组件的Props定义\n */\ntype TypedConfirmActionProps<TP extends object, E extends keyof TP> = Omit<\n ConfirmActionProps<TP, E>,\n 'triggerComponent' | 'triggerEvent'\n>;\nexport type ConfirmActionWithStatic = GenericConfirmActionInterface & {\n /**\n * - **EN:** Confirm box with button trigger\n * - **CN:** 按钮类型的确认框\n */\n Button: TypedConfirmActionInterface<ButtonProps, 'onClick'>;\n /**\n * - **EN:** Confirm box with switch trigger\n * - **CN:** 开关类型的确认框\n */\n Switch: TypedConfirmActionInterface<SwitchProps, 'onChange'>;\n /**\n * - **EN:** Confirm box with link trigger\n * - **CN:** 链接类型的确认框\n */\n Link: TypedConfirmActionInterface<LinkProps, 'onClick'>;\n};\n\n/**\n * - **EN:** Confirm box component with trigger\n * - **CN:** 带触发器的确认框组件\n */\nconst ConfirmAction = forwarded as unknown as ConfirmActionWithStatic;\n// Type of button\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nConfirmAction.Button = withDefaultConfirmActionProps<ButtonProps, 'onClick'>(forwarded as any, {\n triggerComponent: Button,\n triggerEvent: 'onClick',\n triggerProps: {},\n});\n// Type of switch\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nConfirmAction.Switch = withDefaultConfirmActionProps<SwitchProps, 'onChange'>(forwarded as any, {\n triggerComponent: Switch,\n triggerEvent: 'onChange',\n triggerProps: {},\n});\n// Type of link\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nConfirmAction.Link = withDefaultConfirmActionProps<LinkProps, 'onClick'>(forwarded as any, {\n triggerComponent: Typography.Link,\n triggerEvent: 'onClick',\n triggerProps: {\n style: { whiteSpace: 'nowrap' },\n },\n});\n\n// todo: 实现hoc\n/**\n * - **EN:** Generate a confirm box component with custom trigger and default props\n * - **CN:** 基于自定义触发器和默认属性生成一个确认弹框组件\n *\n * @param actionComponent Custom trigger component | 自定义触发器组件\n * @param defaultProps Default properties of the confirm box | 确认弹框的默认属性\n */\nexport function withConfirmAction<TP extends object, E extends keyof TP>(\n actionComponent: ComponentType<TP>,\n defaultProps?: Partial<ConfirmActionProps<TP, E>> | (() => Partial<ConfirmActionProps<TP, E>>)\n) {\n const withTrigger = withDefaultConfirmActionProps(forwarded as unknown as TypedConfirmActionInterface<TP, E>, {\n triggerComponent: actionComponent,\n ...(typeof defaultProps === 'function' ? defaultProps() : defaultProps),\n }) as unknown as ComponentType<Omit<ConfirmActionProps<TP, E>, 'triggerComponent'> & RefAttributes<ConfirmActionRef>>;\n return withTrigger;\n}\n\nexport default ConfirmAction;\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": ["ReactEasyContext", "useLocalizedText", "useContextValidator", "useToken", "useRefFunction"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { CSSProperties, ReactNode } from 'react';
|
|
2
|
+
import type { ItemProps, MenuProps, SeparatorProps, SubMenuProps } from 'react-contexify';
|
|
3
|
+
import 'react-contexify/dist/ReactContexify.css';
|
|
4
|
+
export interface ContextMenuProps extends MenuProps {
|
|
5
|
+
/**
|
|
6
|
+
* - **EN:** Menu items to be displayed
|
|
7
|
+
* - **CN:** 要显示的菜单项
|
|
8
|
+
*/
|
|
9
|
+
items: (ContextMenuItem | ContextMenuSeparator | ContextMenuSubmenu)[] | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* - **EN:** Trigger methods to show the menu, default is `['contextMenu']`
|
|
12
|
+
* - **CN:** 触发显示菜单的方式,默认是 `['contextMenu']`
|
|
13
|
+
*/
|
|
14
|
+
trigger?: ('click' | 'doubleClick' | 'hover' | 'contextMenu')[];
|
|
15
|
+
triggerProps?: {
|
|
16
|
+
className?: string;
|
|
17
|
+
style?: CSSProperties;
|
|
18
|
+
};
|
|
19
|
+
prefixCls?: string;
|
|
20
|
+
}
|
|
21
|
+
declare const ContextMenu: import("react").ForwardRefExoticComponent<ContextMenuProps & import("react").RefAttributes<ContextMenuRef>>;
|
|
22
|
+
export interface ContextMenuRef {
|
|
23
|
+
show: (event: React.MouseEvent<HTMLElement>) => void;
|
|
24
|
+
hideAll: () => void;
|
|
25
|
+
}
|
|
26
|
+
export interface ContextMenuItem extends Omit<ItemProps, 'children' | 'keyMatcher'> {
|
|
27
|
+
key: string;
|
|
28
|
+
className?: string;
|
|
29
|
+
icon?: ReactNode;
|
|
30
|
+
label?: ReactNode;
|
|
31
|
+
shortcutKey?: Partial<Pick<KeyboardEvent, 'ctrlKey' | 'altKey' | 'shiftKey' | 'metaKey' | 'key'>> | ItemProps['keyMatcher'];
|
|
32
|
+
children?: ReactNode;
|
|
33
|
+
}
|
|
34
|
+
export interface ContextMenuSeparator extends SeparatorProps {
|
|
35
|
+
type: 'separator';
|
|
36
|
+
}
|
|
37
|
+
export interface ContextMenuSubmenu extends SubMenuProps {
|
|
38
|
+
key: string;
|
|
39
|
+
type: 'submenu';
|
|
40
|
+
items: (ContextMenuItem | ContextMenuSeparator | ContextMenuSubmenu)[];
|
|
41
|
+
}
|
|
42
|
+
export default ContextMenu;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/components/ContextMenu/index.tsx
|
|
30
|
+
var ContextMenu_exports = {};
|
|
31
|
+
__export(ContextMenu_exports, {
|
|
32
|
+
default: () => ContextMenu_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(ContextMenu_exports);
|
|
35
|
+
var import_react = require("react");
|
|
36
|
+
var import_antd = require("antd");
|
|
37
|
+
var import_classnames = __toESM(require("classnames"));
|
|
38
|
+
var import_react_contexify = require("react-contexify");
|
|
39
|
+
var import_hooks = require("../../hooks");
|
|
40
|
+
var import_style = __toESM(require("./style"));
|
|
41
|
+
var import_ReactContexify = require("react-contexify/dist/ReactContexify.css");
|
|
42
|
+
var ContextMenu = (0, import_react.forwardRef)((props, ref) => {
|
|
43
|
+
const {
|
|
44
|
+
id,
|
|
45
|
+
items,
|
|
46
|
+
trigger = ["contextMenu"],
|
|
47
|
+
triggerProps,
|
|
48
|
+
prefixCls: prefixClsInProps,
|
|
49
|
+
className,
|
|
50
|
+
children,
|
|
51
|
+
...rest
|
|
52
|
+
} = props;
|
|
53
|
+
const { getPrefixCls } = (0, import_react.useContext)(import_antd.ConfigProvider.ConfigContext);
|
|
54
|
+
const prefixCls = getPrefixCls("context-menu", prefixClsInProps);
|
|
55
|
+
const [wrapCSSVar, hashId, cssVarCls] = (0, import_style.default)(prefixCls);
|
|
56
|
+
const { show, hideAll } = (0, import_react_contexify.useContextMenu)({ id });
|
|
57
|
+
const eventNames = (0, import_react.useMemo)(
|
|
58
|
+
() => ({
|
|
59
|
+
click: ["onClick", void 0],
|
|
60
|
+
doubleClick: ["onDoubleClick", void 0],
|
|
61
|
+
hover: ["onPointerEnter", "onPointerLeave"],
|
|
62
|
+
contextMenu: ["onContextMenu", void 0]
|
|
63
|
+
}),
|
|
64
|
+
[]
|
|
65
|
+
);
|
|
66
|
+
const handleShow = (0, import_hooks.useRefFunction)(
|
|
67
|
+
(event, options) => {
|
|
68
|
+
show({
|
|
69
|
+
id,
|
|
70
|
+
event,
|
|
71
|
+
props,
|
|
72
|
+
position: options == null ? void 0 : options.position
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
const handleHideAll = (0, import_hooks.useRefFunction)(() => {
|
|
77
|
+
hideAll();
|
|
78
|
+
});
|
|
79
|
+
const eventHandlers = (0, import_react.useMemo)(() => {
|
|
80
|
+
const handlers = {};
|
|
81
|
+
if (trigger) {
|
|
82
|
+
trigger.forEach((eventType) => {
|
|
83
|
+
const [handlerName, leaveHandlerName] = eventNames[eventType];
|
|
84
|
+
handlers[handlerName] = (event) => {
|
|
85
|
+
handleShow(event);
|
|
86
|
+
};
|
|
87
|
+
if (leaveHandlerName) {
|
|
88
|
+
handlers[leaveHandlerName] = handleHideAll;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return handlers;
|
|
93
|
+
}, [eventNames, trigger]);
|
|
94
|
+
(0, import_react.useImperativeHandle)(
|
|
95
|
+
ref,
|
|
96
|
+
() => ({
|
|
97
|
+
show: handleShow,
|
|
98
|
+
hideAll: handleHideAll
|
|
99
|
+
}),
|
|
100
|
+
[]
|
|
101
|
+
);
|
|
102
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, children && wrapCSSVar(
|
|
103
|
+
/* @__PURE__ */ React.createElement(
|
|
104
|
+
"div",
|
|
105
|
+
{
|
|
106
|
+
...eventHandlers,
|
|
107
|
+
className: (0, import_classnames.default)(hashId, cssVarCls, prefixCls, `${prefixCls}-trigger`, triggerProps == null ? void 0 : triggerProps.className),
|
|
108
|
+
style: triggerProps == null ? void 0 : triggerProps.style
|
|
109
|
+
},
|
|
110
|
+
children
|
|
111
|
+
)
|
|
112
|
+
), wrapCSSVar(
|
|
113
|
+
/* @__PURE__ */ React.createElement(
|
|
114
|
+
import_react_contexify.Menu,
|
|
115
|
+
{
|
|
116
|
+
id,
|
|
117
|
+
className: (0, import_classnames.default)(
|
|
118
|
+
hashId,
|
|
119
|
+
cssVarCls,
|
|
120
|
+
prefixCls,
|
|
121
|
+
`${prefixCls}-menu`,
|
|
122
|
+
{
|
|
123
|
+
[`${prefixCls}-menu-has-items`]: !!(items == null ? void 0 : items.length)
|
|
124
|
+
},
|
|
125
|
+
className
|
|
126
|
+
),
|
|
127
|
+
...rest
|
|
128
|
+
},
|
|
129
|
+
renderItems(items, { theme: props.theme, cmpPrefixCls: prefixCls })
|
|
130
|
+
)
|
|
131
|
+
));
|
|
132
|
+
});
|
|
133
|
+
ContextMenu.displayName = "ContextMenu";
|
|
134
|
+
function renderItems(items, options) {
|
|
135
|
+
return items == null ? void 0 : items.map((item, index) => {
|
|
136
|
+
const isSeparator = "type" in item && item.type === "separator";
|
|
137
|
+
const isSubmenu = "type" in item && item.type === "submenu";
|
|
138
|
+
const menuItem = item;
|
|
139
|
+
if (isSeparator) {
|
|
140
|
+
return /* @__PURE__ */ React.createElement(import_react_contexify.Separator, { key: `[separator]:${index}` });
|
|
141
|
+
}
|
|
142
|
+
if (isSubmenu) {
|
|
143
|
+
const subMenu = item;
|
|
144
|
+
return /* @__PURE__ */ React.createElement(import_react_contexify.Submenu, { ...subMenu, key: subMenu.key }, renderItems(item.items, options));
|
|
145
|
+
}
|
|
146
|
+
return /* @__PURE__ */ React.createElement(
|
|
147
|
+
import_react_contexify.Item,
|
|
148
|
+
{
|
|
149
|
+
...menuItem,
|
|
150
|
+
keyMatcher: typeof menuItem.shortcutKey === "object" ? (e) => {
|
|
151
|
+
const shortcutKey = menuItem.shortcutKey;
|
|
152
|
+
if (shortcutKey.ctrlKey && !e.ctrlKey)
|
|
153
|
+
return false;
|
|
154
|
+
if (shortcutKey.altKey && !e.altKey)
|
|
155
|
+
return false;
|
|
156
|
+
if (shortcutKey.shiftKey && !e.shiftKey)
|
|
157
|
+
return false;
|
|
158
|
+
if (shortcutKey.metaKey && !e.metaKey)
|
|
159
|
+
return false;
|
|
160
|
+
if (!shortcutKey.key || shortcutKey.key !== e.key)
|
|
161
|
+
return false;
|
|
162
|
+
return true;
|
|
163
|
+
} : menuItem.shortcutKey,
|
|
164
|
+
key: menuItem.key
|
|
165
|
+
},
|
|
166
|
+
menuItem.children ? menuItem.children : /* @__PURE__ */ React.createElement(React.Fragment, null, menuItem.icon, /* @__PURE__ */ React.createElement("span", null, menuItem.label), typeof menuItem.shortcutKey === "object" && /* @__PURE__ */ React.createElement(import_react_contexify.RightSlot, null, getShortcutText(menuItem.shortcutKey, options)))
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function getShortcutText(event, options) {
|
|
171
|
+
const { theme, cmpPrefixCls } = options;
|
|
172
|
+
const keys = [];
|
|
173
|
+
const Keyboard = (props) => {
|
|
174
|
+
return /* @__PURE__ */ React.createElement(import_antd.ConfigProvider, { theme: { algorithm: theme === "dark" ? import_antd.theme.darkAlgorithm : void 0 } }, /* @__PURE__ */ React.createElement(import_antd.Typography.Text, { keyboard: true, className: `${cmpPrefixCls}-shortcut-key` }, props.children));
|
|
175
|
+
};
|
|
176
|
+
if (event.ctrlKey)
|
|
177
|
+
keys.push(/* @__PURE__ */ React.createElement(Keyboard, null, "^"));
|
|
178
|
+
if (event.altKey)
|
|
179
|
+
keys.push(/* @__PURE__ */ React.createElement(Keyboard, null, "⌥"));
|
|
180
|
+
if (event.shiftKey)
|
|
181
|
+
keys.push(/* @__PURE__ */ React.createElement(Keyboard, null, "⇧"));
|
|
182
|
+
if (event.metaKey)
|
|
183
|
+
keys.push(/* @__PURE__ */ React.createElement(Keyboard, null, "⌘"));
|
|
184
|
+
if (event.key) {
|
|
185
|
+
keys.push(/* @__PURE__ */ React.createElement(Keyboard, null, event.key));
|
|
186
|
+
}
|
|
187
|
+
return keys;
|
|
188
|
+
}
|
|
189
|
+
var ContextMenu_default = ContextMenu;
|
|
190
|
+
//# sourceMappingURL=index.js.map
|