@tiny-codes/react-easy 1.7.5 → 1.7.7
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 +30 -0
- package/es/components/Animation/Pulse/index.d.ts +18 -2
- package/es/components/Animation/Pulse/index.js +1 -1
- package/es/components/Animation/Pulse/index.js.map +1 -1
- package/es/components/BreakLines/index.d.ts +7 -7
- package/es/components/BreakLines/index.js.map +1 -1
- package/es/components/ColumnSetting/index.d.ts +7 -2
- package/es/components/ColumnSetting/index.js +29 -17
- package/es/components/ColumnSetting/index.js.map +1 -1
- package/es/components/ConfigProvider/context.d.ts +38 -0
- package/es/components/ConfigProvider/context.js +2 -1
- package/es/components/ConfigProvider/context.js.map +1 -1
- package/es/components/ConfigProvider/index.d.ts +22 -4
- package/es/components/ConfigProvider/index.js +22 -10
- package/es/components/ConfigProvider/index.js.map +1 -1
- package/es/components/ConfigProvider/style/index.js +1 -1
- package/es/components/ConfigProvider/style/index.js.map +1 -1
- package/es/components/ContextMenu/index.d.ts +16 -0
- package/es/components/ContextMenu/index.js +3 -2
- package/es/components/ContextMenu/index.js.map +1 -1
- package/es/components/ContextMenu/style/index.js.map +1 -1
- package/es/components/DeleteConfirmAction/withDeleteConfirmAction.d.ts +3 -3
- package/es/components/EditableText/form.d.ts +4 -0
- package/es/components/EditableText/form.js.map +1 -1
- package/es/components/EditableText/index.d.ts +6 -2
- package/es/components/EditableText/index.js +3 -2
- package/es/components/EditableText/index.js.map +1 -1
- package/es/components/FloatDrawer/index.d.ts +10 -0
- package/es/components/FloatDrawer/index.js +3 -2
- package/es/components/FloatDrawer/index.js.map +1 -1
- package/es/components/FloatDrawer/style/index.js +1 -1
- package/es/components/FloatDrawer/style/index.js.map +1 -1
- package/es/components/Iconfont/createIconfont.d.ts +28 -0
- package/es/components/Iconfont/createIconfont.js +57 -0
- package/es/components/Iconfont/createIconfont.js.map +1 -0
- package/es/components/Iconfont/index.d.ts +1 -0
- package/es/components/Iconfont/index.js +2 -0
- package/es/components/Iconfont/index.js.map +1 -0
- package/es/components/Loading/index.js +3 -2
- 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/OverflowTags/index.d.ts +2 -0
- package/es/components/OverflowTags/index.js +3 -2
- 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 +1 -0
- package/es/components/index.js +1 -0
- package/es/components/index.js.map +1 -1
- package/es/hooks/index.d.ts +2 -0
- package/es/hooks/index.js +2 -0
- package/es/hooks/index.js.map +1 -1
- package/es/hooks/style/useSplitter.d.ts +3 -0
- package/es/hooks/style/useSplitter.js +40 -0
- package/es/hooks/style/useSplitter.js.map +1 -0
- package/es/hooks/useLocalStorage.d.ts +16 -0
- package/es/hooks/useLocalStorage.js +115 -0
- package/es/hooks/useLocalStorage.js.map +1 -0
- package/es/hooks/useMovable.js +2 -2
- package/es/hooks/useMovable.js.map +1 -1
- package/es/hooks/useSplitter.d.ts +52 -9
- package/es/hooks/useSplitter.js +69 -39
- package/es/hooks/useSplitter.js.map +1 -1
- package/es/locales/index.js +1 -1
- package/es/locales/index.js.map +1 -1
- package/es/utils/math.d.ts +11 -3
- package/es/utils/math.js +62 -9
- package/es/utils/math.js.map +1 -1
- package/lib/components/Animation/Pulse/index.d.ts +18 -2
- package/lib/components/Animation/Pulse/index.js +0 -5
- package/lib/components/Animation/Pulse/index.js.map +2 -2
- package/lib/components/BreakLines/index.d.ts +7 -7
- package/lib/components/BreakLines/index.js.map +1 -1
- package/lib/components/ColumnSetting/index.d.ts +7 -2
- package/lib/components/ColumnSetting/index.js +20 -15
- package/lib/components/ColumnSetting/index.js.map +3 -3
- package/lib/components/ConfigProvider/context.d.ts +38 -0
- package/lib/components/ConfigProvider/context.js +2 -1
- package/lib/components/ConfigProvider/context.js.map +2 -2
- package/lib/components/ConfigProvider/index.d.ts +22 -4
- package/lib/components/ConfigProvider/index.js +17 -6
- package/lib/components/ConfigProvider/index.js.map +2 -2
- package/lib/components/ConfigProvider/style/index.js +1 -1
- package/lib/components/ConfigProvider/style/index.js.map +2 -2
- package/lib/components/ContextMenu/index.d.ts +16 -0
- package/lib/components/ContextMenu/index.js +2 -1
- package/lib/components/ContextMenu/index.js.map +3 -3
- package/lib/components/ContextMenu/style/index.js.map +2 -2
- package/lib/components/DeleteConfirmAction/withDeleteConfirmAction.d.ts +3 -3
- package/lib/components/EditableText/form.d.ts +4 -0
- package/lib/components/EditableText/form.js.map +2 -2
- package/lib/components/EditableText/index.d.ts +6 -2
- package/lib/components/EditableText/index.js +3 -2
- package/lib/components/EditableText/index.js.map +3 -3
- package/lib/components/FloatDrawer/index.d.ts +10 -0
- package/lib/components/FloatDrawer/index.js +3 -2
- package/lib/components/FloatDrawer/index.js.map +3 -3
- package/lib/components/FloatDrawer/style/index.js +1 -1
- package/lib/components/FloatDrawer/style/index.js.map +2 -2
- package/lib/components/Iconfont/createIconfont.d.ts +28 -0
- package/lib/components/Iconfont/createIconfont.js +65 -0
- package/lib/components/Iconfont/createIconfont.js.map +7 -0
- package/lib/components/Iconfont/index.d.ts +1 -0
- package/lib/components/Iconfont/index.js +24 -0
- package/lib/components/Iconfont/index.js.map +7 -0
- package/lib/components/Loading/index.js +3 -2
- package/lib/components/Loading/index.js.map +3 -3
- package/lib/components/Loading/style/index.js +1 -1
- package/lib/components/Loading/style/index.js.map +2 -2
- package/lib/components/OverflowTags/index.d.ts +2 -0
- package/lib/components/OverflowTags/index.js +3 -2
- package/lib/components/OverflowTags/index.js.map +3 -3
- 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 +1 -0
- package/lib/components/index.js +3 -1
- package/lib/components/index.js.map +2 -2
- package/lib/hooks/index.d.ts +2 -0
- package/lib/hooks/index.js +5 -0
- package/lib/hooks/index.js.map +2 -2
- package/lib/hooks/style/useSplitter.d.ts +3 -0
- package/lib/hooks/style/useSplitter.js +72 -0
- package/lib/hooks/style/useSplitter.js.map +7 -0
- package/lib/hooks/useLocalStorage.d.ts +16 -0
- package/lib/hooks/useLocalStorage.js +120 -0
- package/lib/hooks/useLocalStorage.js.map +7 -0
- package/lib/hooks/useMovable.js +2 -2
- package/lib/hooks/useMovable.js.map +3 -3
- package/lib/hooks/useSplitter.d.ts +52 -9
- package/lib/hooks/useSplitter.js +56 -26
- package/lib/hooks/useSplitter.js.map +3 -3
- package/lib/locales/index.js +1 -1
- package/lib/locales/index.js.map +1 -1
- package/lib/utils/math.d.ts +11 -3
- package/lib/utils/math.js +43 -8
- package/lib/utils/math.js.map +3 -3
- package/package.json +14 -7
|
@@ -6,26 +6,26 @@ export interface BreakLinesProps {
|
|
|
6
6
|
*/
|
|
7
7
|
value: string | undefined;
|
|
8
8
|
/**
|
|
9
|
-
* - **EN:** Whether
|
|
10
|
-
* - **CN:**
|
|
9
|
+
* - **EN:** Whether the line break conversion is enabled
|
|
10
|
+
* - **CN:** 是否启用换行转换
|
|
11
11
|
*
|
|
12
12
|
* @default true
|
|
13
13
|
*/
|
|
14
14
|
enabled?: boolean;
|
|
15
15
|
/**
|
|
16
|
-
* - **EN:**
|
|
17
|
-
* - **CN:**
|
|
16
|
+
* - **EN:** The end-of-line character to use for splitting lines
|
|
17
|
+
* - **CN:** 用于分割行的行结束字符
|
|
18
18
|
*
|
|
19
19
|
* @default '\n'
|
|
20
20
|
*/
|
|
21
21
|
EOL?: string;
|
|
22
22
|
/**
|
|
23
|
-
* - **
|
|
24
|
-
* - **
|
|
23
|
+
* - **EN:** The HTML tag to use for rendering the content
|
|
24
|
+
* - **CN:** 用于渲染内容的 HTML 标签
|
|
25
25
|
*
|
|
26
26
|
* @default false
|
|
27
27
|
*/
|
|
28
|
-
tagName?: 'span' | 'div' | 'i' | 'pre' | (string & {})
|
|
28
|
+
tagName?: false | 'span' | 'div' | 'i' | 'pre' | (string & {});
|
|
29
29
|
/**
|
|
30
30
|
* - **EN:** The CSS class name of the dom node, if `tagName` is set to false, this property is
|
|
31
31
|
* invalid
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/BreakLines/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { createElement, type FC, Fragment, type ReactNode } from 'react';\n\nexport interface BreakLinesProps {\n /**\n * - **EN:** Text content\n * - **CN:** 文本内容\n */\n value: string | undefined;\n /**\n * - **EN:** Whether
|
|
4
|
+
"sourcesContent": ["import { createElement, type FC, Fragment, type ReactNode } from 'react';\n\nexport interface BreakLinesProps {\n /**\n * - **EN:** Text content\n * - **CN:** 文本内容\n */\n value: string | undefined;\n /**\n * - **EN:** Whether the line break conversion is enabled\n * - **CN:** 是否启用换行转换\n *\n * @default true\n */\n enabled?: boolean;\n /**\n * - **EN:** The end-of-line character to use for splitting lines\n * - **CN:** 用于分割行的行结束字符\n *\n * @default '\\n'\n */\n EOL?: string;\n /**\n * - **EN:** The HTML tag to use for rendering the content\n * - **CN:** 用于渲染内容的 HTML 标签\n *\n * @default false\n */\n // eslint-disable-next-line @typescript-eslint/ban-types\n tagName?: false | 'span' | 'div' | 'i' | 'pre' | (string & {});\n /**\n * - **EN:** The CSS class name of the dom node, if `tagName` is set to false, this property is\n * invalid\n * - **CN:** dom节点的css类名,如果`tagName`设置为false,则此属性无效\n */\n className?: string;\n}\n\n/**\n * - **EN:** Output a piece of text, keeping line breaks\n * - **CN:** 输出一段文本,保留换行符\n *\n * @example\n * <BreakLines value=\"hello \\n world\" />;\n * // hello <br/> world\n */\nconst BreakLines: FC<BreakLinesProps> = (props) => {\n const { value, className, tagName = false, enabled = true, EOL = '\\n' } = props;\n\n let content: ReactNode;\n if (value) {\n if (enabled) {\n if (value.includes(EOL)) {\n const segments = value?.split(EOL);\n content = segments.map((str, i) => (\n // eslint-disable-next-line react/no-array-index-key\n <Fragment key={`${str}:${i}`}>\n {str}\n {i !== segments.length - 1 && <br />}\n </Fragment>\n ));\n } else {\n content = value;\n }\n } else {\n content = value;\n }\n } else {\n content = value;\n }\n\n if (tagName) {\n return createElement(tagName, { className }, content);\n } else {\n return <>{content}</>;\n }\n};\n\nexport default BreakLines;\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiE;AA8CjE,IAAM,aAAkC,CAAC,UAAU;AACjD,QAAM,EAAE,OAAO,WAAW,UAAU,OAAO,UAAU,MAAM,MAAM,KAAK,IAAI;AAE1E,MAAI;AACJ,MAAI,OAAO;AACT,QAAI,SAAS;AACX,UAAI,MAAM,SAAS,GAAG,GAAG;AACvB,cAAM,WAAW,+BAAO,MAAM;AAC9B,kBAAU,SAAS,IAAI,CAAC,KAAK;AAAA;AAAA,UAE3B,oCAAC,yBAAS,KAAK,GAAG,OAAO,OACtB,KACA,MAAM,SAAS,SAAS,KAAK,oCAAC,UAAG,CACpC;AAAA,SACD;AAAA,MACH,OAAO;AACL,kBAAU;AAAA,MACZ;AAAA,IACF,OAAO;AACL,gBAAU;AAAA,IACZ;AAAA,EACF,OAAO;AACL,cAAU;AAAA,EACZ;AAEA,MAAI,SAAS;AACX,eAAO,4BAAc,SAAS,EAAE,UAAU,GAAG,OAAO;AAAA,EACtD,OAAO;AACL,WAAO,0DAAG,OAAQ;AAAA,EACpB;AACF;AAEA,IAAO,qBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -13,8 +13,9 @@ export interface ColumnSettingProps<T extends ColumnSettingItem = ColumnSettingI
|
|
|
13
13
|
*/
|
|
14
14
|
onChange?: (nextColumns: T[]) => void;
|
|
15
15
|
/**
|
|
16
|
-
* - **EN:**
|
|
17
|
-
*
|
|
16
|
+
* - **EN:** Set a local storage key for persisting column settings. If not set, local storage is
|
|
17
|
+
* not enabled.
|
|
18
|
+
* - **CN:** 设置一个本地存储的键值,用于持久化保存列设置。如果未设置,则不启用本地存储。
|
|
18
19
|
*/
|
|
19
20
|
storageKey?: string;
|
|
20
21
|
/**
|
|
@@ -47,6 +48,10 @@ export interface ColumnSettingProps<T extends ColumnSettingItem = ColumnSettingI
|
|
|
47
48
|
* - **CN:** “重置”按钮的属性。
|
|
48
49
|
*/
|
|
49
50
|
resetProps?: ButtonProps;
|
|
51
|
+
/**
|
|
52
|
+
* - **EN:** Custom prefix for the component's CSS class.
|
|
53
|
+
* - **CN:** 组件的自定义 CSS 类前缀。
|
|
54
|
+
*/
|
|
50
55
|
prefixCls?: string;
|
|
51
56
|
}
|
|
52
57
|
/**
|
|
@@ -35,10 +35,11 @@ module.exports = __toCommonJS(ColumnSetting_exports);
|
|
|
35
35
|
var import_react = require("react");
|
|
36
36
|
var import_antd = require("antd");
|
|
37
37
|
var import_classnames = __toESM(require("classnames"));
|
|
38
|
-
var import_react_use = require("react-use");
|
|
39
38
|
var import_icons = require("@ant-design/icons");
|
|
40
39
|
var import_hooks = require("../../hooks");
|
|
40
|
+
var import_useLocalStorage = __toESM(require("../../hooks/useLocalStorage"));
|
|
41
41
|
var import_useT = __toESM(require("../../hooks/useT"));
|
|
42
|
+
var import_ConfigProvider = __toESM(require("../ConfigProvider"));
|
|
42
43
|
var import_style = __toESM(require("./style"));
|
|
43
44
|
function ColumnSetting(props) {
|
|
44
45
|
const {
|
|
@@ -53,22 +54,19 @@ function ColumnSetting(props) {
|
|
|
53
54
|
onChange,
|
|
54
55
|
renderColumnTitle
|
|
55
56
|
} = props;
|
|
56
|
-
const { getPrefixCls } = (0, import_react.useContext)(
|
|
57
|
+
const { getPrefixCls } = (0, import_react.useContext)(import_ConfigProvider.default.ConfigContext);
|
|
57
58
|
const prefixCls = getPrefixCls("column-setting", prefixClsInProps);
|
|
58
59
|
const [wrapCSSVar, hashId, cssVarCls] = (0, import_style.default)(prefixCls);
|
|
59
|
-
const initialSelectedRef = (0, import_react.useRef)(normalizeToSelectedKeys(columns));
|
|
60
60
|
const [open, setOpen] = (0, import_react.useState)(false);
|
|
61
|
-
const [selectedKeys, setSelectedKeys] = (0, import_react.useState)(initialSelectedRef.current);
|
|
62
61
|
const t = (0, import_useT.default)();
|
|
63
|
-
const [selectedKeysFromStorage, setSelectedKeysFromStorage] = (0,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
);
|
|
62
|
+
const [selectedKeysFromStorage, setSelectedKeysFromStorage] = (0, import_useLocalStorage.default)(storageKey, []);
|
|
63
|
+
const [initialKeys, setInitialKeys] = (0, import_react.useState)(selectedKeysFromStorage ?? []);
|
|
64
|
+
const [selectedKeys, setSelectedKeys] = (0, import_react.useState)(initialKeys);
|
|
67
65
|
const storageRef = (0, import_hooks.useRefValue)(storageKey);
|
|
68
66
|
const selectedKeysFromStorageRef = (0, import_hooks.useRefValue)(selectedKeysFromStorage);
|
|
69
67
|
const hasChange = (0, import_react.useMemo)(() => {
|
|
70
|
-
return [...selectedKeys].sort().join(",") !==
|
|
71
|
-
}, [selectedKeys]);
|
|
68
|
+
return [...selectedKeys].sort().join(",") !== initialKeys.join(",");
|
|
69
|
+
}, [selectedKeys, initialKeys]);
|
|
72
70
|
const keys = (0, import_react.useMemo)(() => columns.map((c, i) => String(getColKey(c, i))), [columns]);
|
|
73
71
|
const allSelectableKeys = (0, import_react.useMemo)(
|
|
74
72
|
() => columns.map((c, i) => ({ k: String(getColKey(c, i)), disabled: !!c.disabled })).filter((x) => !x.disabled).map((x) => x.k),
|
|
@@ -108,19 +106,26 @@ function ColumnSetting(props) {
|
|
|
108
106
|
change(ensured, true);
|
|
109
107
|
};
|
|
110
108
|
const handleReset = () => {
|
|
111
|
-
const next =
|
|
109
|
+
const next = initialKeys.length > 0 ? initialKeys : [keys[0]];
|
|
112
110
|
change(next, true);
|
|
113
111
|
};
|
|
112
|
+
const handleOpenChange = (nextOpen) => {
|
|
113
|
+
setOpen(nextOpen);
|
|
114
|
+
if (nextOpen) {
|
|
115
|
+
setInitialKeys(normalizeToSelectedKeys(columns));
|
|
116
|
+
} else {
|
|
117
|
+
setInitialKeys([]);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
114
120
|
(0, import_react.useEffect)(() => {
|
|
115
121
|
const next = normalizeToSelectedKeys(columns);
|
|
116
|
-
initialSelectedRef.current = next;
|
|
117
122
|
change(next, false);
|
|
118
123
|
}, [columns]);
|
|
119
124
|
(0, import_react.useEffect)(() => {
|
|
120
|
-
if (storageRef.current && selectedKeysFromStorageRef.current && selectedKeysFromStorageRef.current.join(",") !==
|
|
125
|
+
if (storageRef.current && selectedKeysFromStorageRef.current && selectedKeysFromStorageRef.current.join(",") !== initialKeys.join(",")) {
|
|
121
126
|
change(selectedKeysFromStorageRef.current, true);
|
|
122
127
|
}
|
|
123
|
-
}, []);
|
|
128
|
+
}, [initialKeys]);
|
|
124
129
|
const dropdownRender = () => /* @__PURE__ */ React.createElement(
|
|
125
130
|
"div",
|
|
126
131
|
{
|
|
@@ -188,7 +193,7 @@ function ColumnSetting(props) {
|
|
|
188
193
|
import_antd.Dropdown,
|
|
189
194
|
{
|
|
190
195
|
open,
|
|
191
|
-
onOpenChange:
|
|
196
|
+
onOpenChange: handleOpenChange,
|
|
192
197
|
trigger: ["click"],
|
|
193
198
|
dropdownRender,
|
|
194
199
|
popupRender: dropdownRender,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/ColumnSetting/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useContext, useEffect, useMemo,
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
6
|
-
"names": ["useStyle", "useT", "classNames"]
|
|
4
|
+
"sourcesContent": ["import { useContext, useEffect, useMemo, useState } from 'react';\nimport { Button, Checkbox, Divider, Dropdown, Space, Typography } from 'antd';\nimport type { ButtonProps, DropdownProps } from 'antd';\nimport type { ColumnType } from 'antd/es/table';\nimport classNames from 'classnames';\nimport { ReloadOutlined, SettingOutlined } from '@ant-design/icons';\nimport { useRefFunction, useRefValue } from '../../hooks';\nimport useLocalStorage from '../../hooks/useLocalStorage';\nimport useT from '../../hooks/useT';\nimport ConfigProvider from '../ConfigProvider';\nimport useStyle from './style';\n\nexport interface ColumnSettingProps<T extends ColumnSettingItem = ColumnSettingItem> {\n /**\n * - **EN:** The columns to be displayed in the column setting.\n * - **CN:** 列设置中要显示的列。\n */\n columns: T[];\n /**\n * - **EN:** Callback function triggered when the selected columns change.\n * - **CN:** 选中列变化时触发的回调函数。\n */\n onChange?: (nextColumns: T[]) => void;\n /**\n * - **EN:** Set a local storage key for persisting column settings. If not set, local storage is\n * not enabled.\n * - **CN:** 设置一个本地存储的键值,用于持久化保存列设置。如果未设置,则不启用本地存储。\n */\n storageKey?: string;\n /**\n * - **EN:** Function to render custom column titles.\n * - **CN:** 自定义列标题的渲染函数。\n */\n renderColumnTitle?: (col: ColumnSettingItem, index: number) => React.ReactNode;\n /**\n * - **EN:** Props for the button that triggers the dropdown.\n * - **CN:** 触发下拉菜单的按钮属性。\n */\n triggerProps?: ButtonProps;\n /**\n * - **EN:** Props for the dropdown component.\n * - **CN:** 下拉菜单组件的属性。\n */\n dropdownProps?: DropdownProps;\n /**\n * - **EN:** Props for the dropdown popup container.\n * - **CN:** 下拉菜单弹出层容器的属性。\n */\n popupProps?: React.HTMLAttributes<HTMLDivElement>;\n /**\n * - **EN:** Props for the \"Check All\" button.\n * - **CN:** “全选”按钮的属性。\n */\n checkAllProps?: ButtonProps;\n /**\n * - **EN:** Props for the \"Reset\" button.\n * - **CN:** “重置”按钮的属性。\n */\n resetProps?: ButtonProps;\n /**\n * - **EN:** Custom prefix for the component's CSS class.\n * - **CN:** 组件的自定义 CSS 类前缀。\n */\n prefixCls?: string;\n}\n\n/**\n * - **EN:** A component for configuring table column visibility.\n * - **CN:** 用于配置表格列可见性的组件。\n */\nfunction ColumnSetting<T extends ColumnSettingItem = ColumnSettingItem>(props: ColumnSettingProps<T>) {\n const {\n columns,\n storageKey,\n triggerProps,\n dropdownProps,\n popupProps,\n prefixCls: prefixClsInProps,\n checkAllProps,\n resetProps,\n onChange,\n renderColumnTitle,\n } = props;\n const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);\n const prefixCls = getPrefixCls('column-setting', prefixClsInProps);\n const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);\n const [open, setOpen] = useState(false);\n const t = useT();\n const [selectedKeysFromStorage, setSelectedKeysFromStorage] = useLocalStorage<string[]>(storageKey, []);\n const [initialKeys, setInitialKeys] = useState<string[]>(selectedKeysFromStorage ?? []);\n const [selectedKeys, setSelectedKeys] = useState<string[]>(initialKeys);\n const storageRef = useRefValue(storageKey);\n const selectedKeysFromStorageRef = useRefValue(selectedKeysFromStorage);\n const hasChange = useMemo(() => {\n return [...selectedKeys].sort().join(',') !== initialKeys.join(',');\n }, [selectedKeys, initialKeys]);\n\n // Compute keys and selectable keys\n const keys = useMemo(() => columns.map((c, i) => String(getColKey(c, i))), [columns]);\n const allSelectableKeys = useMemo(\n () =>\n columns\n .map((c, i) => ({ k: String(getColKey(c, i)), disabled: !!c.disabled }))\n .filter((x) => !x.disabled)\n .map((x) => x.k),\n [columns]\n );\n const isAllChecked = allSelectableKeys.length > 0 && allSelectableKeys.every((k) => selectedKeys.includes(k));\n const isIndeterminate = selectedKeys.length > 0 && !isAllChecked;\n\n // Fire change event when selectedKeysFromStorage changes\n const change = useRefFunction((nextSelected: string[], fireEvent?: boolean) => {\n setSelectedKeys(nextSelected);\n if (storageKey) {\n setSelectedKeysFromStorage(nextSelected);\n }\n if (fireEvent) {\n const next = columns.map((col, i) => {\n const k = String(getColKey(col, i));\n const visible = nextSelected.includes(k);\n return { ...col, hidden: !visible } as T;\n });\n onChange?.(next as T[]);\n }\n });\n\n // Toggle one column change\n const toggleOne = (key: string, checked: boolean) => {\n const next = new Set(selectedKeys);\n if (checked) {\n next.add(key);\n } else {\n // Keep at least one visible column\n if (selectedKeys.length <= 1) return;\n next.delete(key);\n }\n const nextArr = Array.from(next);\n change(nextArr, true);\n };\n\n // Toggle all columns change\n const handleCheckAll = (checked: boolean) => {\n const nextArr = checked\n ? Array.from(new Set([...selectedKeys, ...allSelectableKeys]))\n : selectedKeys.filter((k) => !allSelectableKeys.includes(k)).slice(0, 1);\n const ensured = checked ? nextArr : nextArr.length > 0 ? nextArr : [keys[0]];\n change(ensured, true);\n };\n\n // Reset to initial selected columns\n const handleReset = () => {\n const next = initialKeys.length > 0 ? initialKeys : [keys[0]];\n change(next, true);\n };\n\n const handleOpenChange = (nextOpen: boolean) => {\n setOpen(nextOpen);\n if (nextOpen) {\n setInitialKeys(normalizeToSelectedKeys(columns));\n } else {\n setInitialKeys([]);\n }\n };\n\n // Sync when columns change\n useEffect(() => {\n const next = normalizeToSelectedKeys(columns);\n change(next, false);\n }, [columns]);\n\n // Fire change on mount if storage exists and differs from initial values\n useEffect(() => {\n if (\n storageRef.current &&\n selectedKeysFromStorageRef.current &&\n selectedKeysFromStorageRef.current.join(',') !== initialKeys.join(',')\n ) {\n change(selectedKeysFromStorageRef.current, true);\n }\n }, [initialKeys]);\n\n const dropdownRender = () => (\n <div\n {...popupProps}\n className={classNames(`${prefixCls}-popup`, popupProps?.className)}\n onClick={(e) => {\n e.stopPropagation();\n popupProps?.onClick?.(e);\n }}\n >\n <Typography.Text className={`${prefixCls}-popup-title`}>{t('components.ColumnSetting.title')}</Typography.Text>\n <Space direction=\"vertical\" className={`${prefixCls}-column-list`} size={12}>\n {columns.map((col, idx) => {\n const k = String(getColKey(col, idx));\n const label = col.title ?? col.dataIndex ?? k;\n const checked = selectedKeys.includes(k);\n const disabled = !!col.disabled;\n const disableUncheck = !disabled && checked && selectedKeys.length <= 1; // 禁止取消最后一个\n return (\n <Checkbox\n key={k}\n className={`${prefixCls}-column-item`}\n disabled={disabled || disableUncheck}\n checked={checked}\n onChange={(e) => toggleOne(k, e.target.checked)}\n >\n <span className={`${prefixCls}-column-item-title`}>{renderColumnTitle?.(col, idx) ?? label}</span>\n </Checkbox>\n );\n })}\n </Space>\n <Divider className={`${prefixCls}-divider`} />\n <div className={`${prefixCls}-footer`}>\n <Button\n type=\"text\"\n {...checkAllProps}\n className={classNames(`${prefixCls}-select-all`, checkAllProps?.className)}\n onClick={(e) => {\n handleCheckAll(!isAllChecked);\n checkAllProps?.onClick?.(e);\n }}\n >\n <Checkbox checked={isAllChecked} indeterminate={isIndeterminate}></Checkbox>\n {t('components.ColumnSetting.selectAll')}\n </Button>\n <Button\n type=\"text\"\n icon={<ReloadOutlined />}\n disabled={!hasChange}\n {...resetProps}\n className={classNames(`${prefixCls}-reset`, resetProps?.className)}\n onClick={(e) => {\n handleReset();\n resetProps?.onClick?.(e);\n }}\n >\n {t('components.ColumnSetting.reset')}\n </Button>\n </div>\n </div>\n );\n\n return wrapCSSVar(\n <Dropdown\n open={open}\n onOpenChange={handleOpenChange}\n trigger={['click']}\n dropdownRender={dropdownRender} // To be compatible with lower versions of antd\n popupRender={dropdownRender}\n placement=\"bottomRight\"\n {...dropdownProps}\n rootClassName={classNames(hashId, cssVarCls, prefixCls, `${prefixCls}-dropdown`, dropdownProps?.className)}\n >\n <Button\n icon={<SettingOutlined />}\n {...triggerProps}\n className={classNames(hashId, cssVarCls, prefixCls, `${prefixCls}-trigger`, triggerProps?.className)}\n />\n </Dropdown>\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface ColumnSettingItem<T = any> extends ColumnType<T> {\n /**\n * - **EN:** Disable toggling visibility for this column.\n * - **CN:** 禁止切换此列的可见性。\n */\n disabled?: boolean;\n}\n\nfunction getColKey(col: ColumnType, idx: number): React.Key {\n return col.key ?? (col.dataIndex as string) ?? idx;\n}\n\nfunction normalizeToSelectedKeys(cols: ColumnType[]): string[] {\n return cols\n .map((c, i) => ({ key: String(getColKey(c, i)), hidden: !!c.hidden }))\n .filter((c) => !c.hidden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;AAAA,QACd,SAAS,CAAC,OAAO;AAAA,QACjB;AAAA,QACA,aAAa;AAAA,QACb,WAAU;AAAA,QACT,GAAG;AAAA,QACJ,mBAAe,kBAAAA,SAAW,QAAQ,WAAW,WAAW,GAAG,sBAAsB,+CAAe,SAAS;AAAA;AAAA,MAEzG;AAAA,QAAC;AAAA;AAAA,UACC,MAAM,oCAAC,kCAAgB;AAAA,UACtB,GAAG;AAAA,UACJ,eAAW,kBAAAA,SAAW,QAAQ,WAAW,WAAW,GAAG,qBAAqB,6CAAc,SAAS;AAAA;AAAA,MACrG;AAAA,IACF;AAAA,EACF;AACF;AAWA,SAAS,UAAU,KAAiB,KAAwB;AAC1D,SAAO,IAAI,OAAQ,IAAI,aAAwB;AACjD;AAEA,SAAS,wBAAwB,MAA8B;AAC7D,SAAO,KACJ,IAAI,CAAC,GAAG,OAAO,EAAE,KAAK,OAAO,UAAU,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,EACpE,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,EACvB,IAAI,CAAC,MAAM,EAAE,GAAG,EAChB,KAAK;AACV;AAEA,IAAO,wBAAQ;",
|
|
6
|
+
"names": ["ConfigProvider", "useStyle", "useT", "useLocalStorage", "classNames"]
|
|
7
7
|
}
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import type { Langs } from '../../locales';
|
|
3
|
+
import type { PulseAnimationProps } from '../Animation/Pulse';
|
|
4
|
+
import type { BreakLinesProps } from '../BreakLines';
|
|
5
|
+
import type { ColumnSettingProps } from '../ColumnSetting';
|
|
3
6
|
import type { ConfirmActionProps } from '../ConfirmAction';
|
|
7
|
+
import type { ContextMenuProps } from '../ContextMenu';
|
|
8
|
+
import type { EditableTextProps } from '../EditableText';
|
|
4
9
|
import type { ModalActionProps } from '../ModalAction';
|
|
5
10
|
export interface ReactEasyContextProps {
|
|
11
|
+
getPrefixCls: (suffixCls: string, customizePrefixCls?: string) => string;
|
|
6
12
|
/**
|
|
7
13
|
* - **EN:** Language of the component, used for global configuration, can be 'en-US' or 'zh-CN'
|
|
8
14
|
* - **CN:** 组件的语言,用于全局配置,可以是'en-US'或'zh-CN'
|
|
15
|
+
*
|
|
16
|
+
* @default 'en-US'
|
|
9
17
|
*/
|
|
10
18
|
lang?: Langs;
|
|
11
19
|
/**
|
|
@@ -18,6 +26,36 @@ export interface ReactEasyContextProps {
|
|
|
18
26
|
* @returns Localized text | 本地化文本
|
|
19
27
|
*/
|
|
20
28
|
localize?: <T>(key: T, args?: Record<string, unknown>) => ReactNode;
|
|
29
|
+
/**
|
|
30
|
+
* - **EN:** Global configuration for `PulseAnimation` component, which can be used to set default
|
|
31
|
+
* animation properties for all `PulseAnimation` components in the application.
|
|
32
|
+
* - **CN:** `PulseAnimation`组件的全局配置,可以用来设置应用中所有`PulseAnimation`组件的默认动画属性。
|
|
33
|
+
*/
|
|
34
|
+
PulseAnimation?: PulseAnimationProps;
|
|
35
|
+
/**
|
|
36
|
+
* - **EN:** Global configuration for `BreakLines` component, which can be used to set default
|
|
37
|
+
* properties for all `BreakLines` components in the application.
|
|
38
|
+
* - **CN:** `BreakLines`组件的全局配置,可以用来设置应用中所有`BreakLines`组件的默认属性。
|
|
39
|
+
*/
|
|
40
|
+
BreakLines?: BreakLinesProps;
|
|
41
|
+
/**
|
|
42
|
+
* - **EN:** Global configuration for `ColumnSetting` component, which can be used to set default
|
|
43
|
+
* properties for all `ColumnSetting` components in the application.
|
|
44
|
+
* - **CN:** `ColumnSetting`组件的全局配置,可以用来设置应用中所有`ColumnSetting`组件的默认属性。
|
|
45
|
+
*/
|
|
46
|
+
ColumnSetting?: ColumnSettingProps;
|
|
47
|
+
/**
|
|
48
|
+
* - **EN:** Global configuration for `ContextMenu` component, which can be used to set default
|
|
49
|
+
* properties for all `ContextMenu` components in the application.
|
|
50
|
+
* - **CN:** `ContextMenu`组件的全局配置,可以用来设置应用中所有`ContextMenu`组件的默认属性。
|
|
51
|
+
*/
|
|
52
|
+
ContextMenu?: ContextMenuProps;
|
|
53
|
+
/**
|
|
54
|
+
* - **EN:** Global configuration for `EditableText` component, which can be used to set default
|
|
55
|
+
* properties for all `EditableText` components in the application.
|
|
56
|
+
* - **CN:** `EditableText`组件的全局配置,可以用来设置应用中所有`EditableText`组件的默认属性。
|
|
57
|
+
*/
|
|
58
|
+
EditableText?: EditableTextProps;
|
|
21
59
|
/**
|
|
22
60
|
* - **EN:** Global configuration for `ConfirmAction` component, which can be used to set default
|
|
23
61
|
* modal title and content for all `ConfirmAction` components in the application.
|
|
@@ -25,7 +25,8 @@ __export(context_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(context_exports);
|
|
26
26
|
var import_react = require("react");
|
|
27
27
|
var defaultContextValue = {
|
|
28
|
-
|
|
28
|
+
getPrefixCls: void 0,
|
|
29
|
+
lang: "en-US"
|
|
29
30
|
};
|
|
30
31
|
var ReactEasyContext = (0, import_react.createContext)(defaultContextValue);
|
|
31
32
|
var context_default = ReactEasyContext;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/ConfigProvider/context.tsx"],
|
|
4
|
-
"sourcesContent": ["import { createContext, type ReactNode } from 'react';\nimport type { Langs } from '../../locales';\nimport type { ConfirmActionProps } from '../ConfirmAction';\nimport type { ModalActionProps } from '../ModalAction';\n\nexport interface ReactEasyContextProps {\n /**\n * - **EN:** Language of the component, used for global configuration, can be 'en-US' or 'zh-CN'\n * - **CN:** 组件的语言,用于全局配置,可以是'en-US'或'zh-CN'\n */\n lang?: Langs;\n /**\n * - **EN:** Get localized text\n * - **CN:** 获取本地化文本\n *\n * @param key Normal text or key of local resource | 普通文本或本地资源的键值\n * @param args Parameters of the localized text | 本地化文本的参数\n *\n * @returns Localized text | 本地化文本\n */\n localize?: <T>(key: T, args?: Record<string, unknown>) => ReactNode;\n\n /**\n * - **EN:** Global configuration for `ConfirmAction` component, which can be used to set default\n * modal title and content for all `ConfirmAction` components in the application.\n * - **CN:** `ConfirmAction`组件的全局配置,可以用来设置应用中所有`ConfirmAction`组件的默认模态框标题和内容。\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ConfirmAction?: ConfirmActionProps<any, never>;\n /** @deprecated Use `ConfirmAction.title` instead */\n defaultConfirmTitle?: ReactNode;\n /** @deprecated Use `ConfirmAction.content` instead */\n defaultConfirmContent?: ReactNode;\n\n /**\n * - **EN:** Global configuration for `DeleteConfirmAction` component, which can be used to set\n * default modal title and content for all `DeleteConfirmAction` components in the application.\n * - **CN:** `DeleteConfirmAction`组件的全局配置,可以用来设置应用中所有`DeleteConfirmAction`组件的默认模态框标题和内容。\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n DeletionConfirmAction?: ConfirmActionProps<any, never>;\n /** @deprecated Use `DeletionConfirmAction.title` instead */\n defaultDeletionConfirmTitle?: ReactNode;\n /** @deprecated Use `DeletionConfirmAction.content` instead */\n defaultDeletionConfirmContent?: ReactNode;\n\n /**\n * - **EN:** Global configuration for `ModalAction` component, which can be used to set default\n * modal title and content for all `ModalAction` components in the application.\n * - **CN:** `ModalAction`组件的全局配置,可以用来设置应用中所有`ModalAction`组件的默认模态框标题和内容。\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ModalAction?: Partial<ModalActionProps<any, any, any, any, any>>;\n}\n\nexport const defaultContextValue: ReactEasyContextProps = {\n lang: 'en',\n};\n\nconst ReactEasyContext = createContext<ReactEasyContextProps>(defaultContextValue);\n\nexport default ReactEasyContext;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA8C;
|
|
4
|
+
"sourcesContent": ["import { createContext, type ReactNode } from 'react';\nimport type { Langs } from '../../locales';\nimport type { PulseAnimationProps } from '../Animation/Pulse';\nimport type { BreakLinesProps } from '../BreakLines';\nimport type { ColumnSettingProps } from '../ColumnSetting';\nimport type { ConfirmActionProps } from '../ConfirmAction';\nimport type { ContextMenuProps } from '../ContextMenu';\nimport type { EditableTextProps } from '../EditableText';\nimport type { ModalActionProps } from '../ModalAction';\n\nexport interface ReactEasyContextProps {\n getPrefixCls: (suffixCls: string, customizePrefixCls?: string) => string;\n /**\n * - **EN:** Language of the component, used for global configuration, can be 'en-US' or 'zh-CN'\n * - **CN:** 组件的语言,用于全局配置,可以是'en-US'或'zh-CN'\n *\n * @default 'en-US'\n */\n lang?: Langs;\n /**\n * - **EN:** Get localized text\n * - **CN:** 获取本地化文本\n *\n * @param key Normal text or key of local resource | 普通文本或本地资源的键值\n * @param args Parameters of the localized text | 本地化文本的参数\n *\n * @returns Localized text | 本地化文本\n */\n localize?: <T>(key: T, args?: Record<string, unknown>) => ReactNode;\n\n /**\n * - **EN:** Global configuration for `PulseAnimation` component, which can be used to set default\n * animation properties for all `PulseAnimation` components in the application.\n * - **CN:** `PulseAnimation`组件的全局配置,可以用来设置应用中所有`PulseAnimation`组件的默认动画属性。\n */\n PulseAnimation?: PulseAnimationProps;\n /**\n * - **EN:** Global configuration for `BreakLines` component, which can be used to set default\n * properties for all `BreakLines` components in the application.\n * - **CN:** `BreakLines`组件的全局配置,可以用来设置应用中所有`BreakLines`组件的默认属性。\n */\n BreakLines?: BreakLinesProps;\n /**\n * - **EN:** Global configuration for `ColumnSetting` component, which can be used to set default\n * properties for all `ColumnSetting` components in the application.\n * - **CN:** `ColumnSetting`组件的全局配置,可以用来设置应用中所有`ColumnSetting`组件的默认属性。\n */\n ColumnSetting?: ColumnSettingProps;\n /**\n * - **EN:** Global configuration for `ContextMenu` component, which can be used to set default\n * properties for all `ContextMenu` components in the application.\n * - **CN:** `ContextMenu`组件的全局配置,可以用来设置应用中所有`ContextMenu`组件的默认属性。\n */\n ContextMenu?: ContextMenuProps;\n /**\n * - **EN:** Global configuration for `EditableText` component, which can be used to set default\n * properties for all `EditableText` components in the application.\n * - **CN:** `EditableText`组件的全局配置,可以用来设置应用中所有`EditableText`组件的默认属性。\n */\n EditableText?: EditableTextProps;\n\n /**\n * - **EN:** Global configuration for `ConfirmAction` component, which can be used to set default\n * modal title and content for all `ConfirmAction` components in the application.\n * - **CN:** `ConfirmAction`组件的全局配置,可以用来设置应用中所有`ConfirmAction`组件的默认模态框标题和内容。\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ConfirmAction?: ConfirmActionProps<any, never>;\n /** @deprecated Use `ConfirmAction.title` instead */\n defaultConfirmTitle?: ReactNode;\n /** @deprecated Use `ConfirmAction.content` instead */\n defaultConfirmContent?: ReactNode;\n\n /**\n * - **EN:** Global configuration for `DeleteConfirmAction` component, which can be used to set\n * default modal title and content for all `DeleteConfirmAction` components in the application.\n * - **CN:** `DeleteConfirmAction`组件的全局配置,可以用来设置应用中所有`DeleteConfirmAction`组件的默认模态框标题和内容。\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n DeletionConfirmAction?: ConfirmActionProps<any, never>;\n /** @deprecated Use `DeletionConfirmAction.title` instead */\n defaultDeletionConfirmTitle?: ReactNode;\n /** @deprecated Use `DeletionConfirmAction.content` instead */\n defaultDeletionConfirmContent?: ReactNode;\n\n /**\n * - **EN:** Global configuration for `ModalAction` component, which can be used to set default\n * modal title and content for all `ModalAction` components in the application.\n * - **CN:** `ModalAction`组件的全局配置,可以用来设置应用中所有`ModalAction`组件的默认模态框标题和内容。\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ModalAction?: Partial<ModalActionProps<any, any, any, any, any>>;\n}\n\nexport const defaultContextValue: ReactEasyContextProps = {\n getPrefixCls: undefined!,\n lang: 'en-US',\n};\n\nconst ReactEasyContext = createContext<ReactEasyContextProps>(defaultContextValue);\n\nexport default ReactEasyContext;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA8C;AA8FvC,IAAM,sBAA6C;AAAA,EACxD,cAAc;AAAA,EACd,MAAM;AACR;AAEA,IAAM,uBAAmB,4BAAqC,mBAAmB;AAEjF,IAAO,kBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
import type { CSSProperties, FC, ReactNode } from 'react';
|
|
2
2
|
import type localesEn from '../../locales/langs/en';
|
|
3
|
-
import { type ReactEasyContextProps } from './context';
|
|
4
|
-
export interface ConfigProviderProps extends ReactEasyContextProps {
|
|
3
|
+
import ReactEasyContext, { type ReactEasyContextProps } from './context';
|
|
4
|
+
export interface ConfigProviderProps extends Omit<ReactEasyContextProps, 'getPrefixCls'> {
|
|
5
|
+
/**
|
|
6
|
+
* - **EN:** Child elements of the ConfigProvider
|
|
7
|
+
* - **CN:** ConfigProvider 的子元素
|
|
8
|
+
*/
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
/**
|
|
11
|
+
* - **EN:** Custom prefix for the component's CSS class.
|
|
12
|
+
* - **CN:** 组件的自定义 CSS 类前缀。
|
|
13
|
+
*/
|
|
5
14
|
prefixCls?: string;
|
|
15
|
+
/**
|
|
16
|
+
* - **EN:** Custom class name for the root element
|
|
17
|
+
* - **CN:** 根元素的自定义类名
|
|
18
|
+
*/
|
|
6
19
|
className?: string;
|
|
20
|
+
/**
|
|
21
|
+
* - **EN:** Custom styles for the root element
|
|
22
|
+
* - **CN:** 根元素的自定义样式
|
|
23
|
+
*/
|
|
7
24
|
style?: CSSProperties;
|
|
8
25
|
/**
|
|
9
26
|
* - **EN:** Custom localization resources, if `lang` exists, it will override the localization
|
|
@@ -11,11 +28,12 @@ export interface ConfigProviderProps extends ReactEasyContextProps {
|
|
|
11
28
|
* - **CN:** 自定义本地化资源,如果`lang`存在,则会覆盖该语言的本地化资源,否则,会添加一种新的语言
|
|
12
29
|
*/
|
|
13
30
|
locales?: Partial<typeof localesEn>;
|
|
14
|
-
children: ReactNode;
|
|
15
31
|
}
|
|
16
32
|
/**
|
|
17
33
|
* - **EN:** Provide global configuration for AntdHelper
|
|
18
34
|
* - **CN:** 提供AntdHelper的全局配置
|
|
19
35
|
*/
|
|
20
|
-
declare const ConfigProvider: FC<ConfigProviderProps
|
|
36
|
+
declare const ConfigProvider: FC<ConfigProviderProps> & {
|
|
37
|
+
ConfigContext: typeof ReactEasyContext;
|
|
38
|
+
};
|
|
21
39
|
export default ConfigProvider;
|
|
@@ -44,24 +44,35 @@ var ConfigProvider = (props) => {
|
|
|
44
44
|
const { getPrefixCls, rootPrefixCls } = (0, import_react.useContext)(import_antd.ConfigProvider.ConfigContext);
|
|
45
45
|
const prefixCls = getPrefixCls("react-easy", prefixClsInProps);
|
|
46
46
|
const [wrapCSSVar, hashId, cssVarCls] = (0, import_style.default)(prefixCls, rootPrefixCls);
|
|
47
|
+
const contextValue = (0, import_react.useMemo)(
|
|
48
|
+
() => {
|
|
49
|
+
if (langInProps !== import_locales.default.language) {
|
|
50
|
+
import_locales.default.changeLanguage(langInProps || "en-US");
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
...restProps,
|
|
54
|
+
getPrefixCls: (suffixCls, customizePrefixCls) => getPrefixCls(`easy-${suffixCls}`, customizePrefixCls)
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
// eslint-disable-next-line @tiny-codes/react-hooks/exhaustive-deps
|
|
58
|
+
[langInProps, getPrefixCls, ...Object.values(restProps)]
|
|
59
|
+
);
|
|
47
60
|
(0, import_react.useEffect)(() => {
|
|
48
61
|
if (userLocales) {
|
|
49
|
-
const lang = langInProps || "en";
|
|
62
|
+
const lang = langInProps || "en-US";
|
|
50
63
|
if (lang && import_locales.langs.includes(lang)) {
|
|
51
64
|
import_locales.default.removeResourceBundle(lang, "translation");
|
|
52
65
|
import_locales.default.addResourceBundle(lang, "translation", { ...import_locales.resources[lang].translation, ...userLocales });
|
|
53
66
|
} else {
|
|
54
|
-
import_locales.default.addResourceBundle(lang, "translation", { ...import_locales.resources
|
|
67
|
+
import_locales.default.addResourceBundle(lang, "translation", { ...import_locales.resources["en-US"].translation, ...userLocales });
|
|
55
68
|
}
|
|
56
69
|
}
|
|
57
70
|
}, [langInProps, userLocales]);
|
|
58
|
-
(0, import_react.useEffect)(() => {
|
|
59
|
-
import_locales.default.changeLanguage(langInProps || "en");
|
|
60
|
-
}, [langInProps]);
|
|
61
71
|
return wrapCSSVar(
|
|
62
|
-
/* @__PURE__ */ React.createElement(import_context.default.Provider, { value:
|
|
72
|
+
/* @__PURE__ */ React.createElement(import_context.default.Provider, { value: contextValue }, /* @__PURE__ */ React.createElement("div", { className: (0, import_classnames.default)(hashId, cssVarCls, prefixCls, className), style }, children))
|
|
63
73
|
);
|
|
64
74
|
};
|
|
65
75
|
ConfigProvider.displayName = "ReactEasyConfigProvider";
|
|
76
|
+
ConfigProvider.ConfigContext = import_context.default;
|
|
66
77
|
var ConfigProvider_default = ConfigProvider;
|
|
67
78
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/ConfigProvider/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import type { CSSProperties, FC, ReactNode } from 'react';\nimport { useContext, useEffect } from 'react';\nimport { ConfigProvider as ReactConfigProvider } from 'antd';\nimport classNames from 'classnames';\nimport locales, { langs, resources } from '../../locales';\nimport type localesEn from '../../locales/langs/en';\nimport ReactEasyContext, { type ReactEasyContextProps } from './context';\nimport useStyle from './style';\n\nexport interface ConfigProviderProps extends ReactEasyContextProps {\n prefixCls?: string;\n className?: string;\n style?: CSSProperties;\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
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,
|
|
4
|
+
"sourcesContent": ["import type { CSSProperties, FC, ReactNode } from 'react';\nimport { useContext, useEffect, useMemo } from 'react';\nimport { ConfigProvider as ReactConfigProvider } from 'antd';\nimport classNames from 'classnames';\nimport locales, { langs, resources } from '../../locales';\nimport type localesEn from '../../locales/langs/en';\nimport ReactEasyContext, { type ReactEasyContextProps } from './context';\nimport useStyle from './style';\n\nexport interface ConfigProviderProps extends Omit<ReactEasyContextProps, 'getPrefixCls'> {\n /**\n * - **EN:** Child elements of the ConfigProvider\n * - **CN:** ConfigProvider 的子元素\n */\n children: ReactNode;\n /**\n * - **EN:** Custom prefix for the component's CSS class.\n * - **CN:** 组件的自定义 CSS 类前缀。\n */\n prefixCls?: string;\n /**\n * - **EN:** Custom class name for the root element\n * - **CN:** 根元素的自定义类名\n */\n className?: string;\n /**\n * - **EN:** Custom styles for the root element\n * - **CN:** 根元素的自定义样式\n */\n style?: CSSProperties;\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}\n\n/**\n * - **EN:** Provide global configuration for AntdHelper\n * - **CN:** 提供AntdHelper的全局配置\n */\nconst ConfigProvider: FC<ConfigProviderProps> & { ConfigContext: typeof ReactEasyContext } = (props) => {\n const { children, locales: userLocales, prefixCls: prefixClsInProps, className, style, ...restProps } = props;\n const { lang: langInProps } = restProps;\n const { getPrefixCls, rootPrefixCls } = useContext(ReactConfigProvider.ConfigContext);\n const prefixCls = getPrefixCls('react-easy', prefixClsInProps);\n const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls, rootPrefixCls);\n const contextValue = useMemo(\n () => {\n if (langInProps !== locales.language) {\n locales.changeLanguage(langInProps || 'en-US');\n }\n return {\n ...restProps,\n getPrefixCls: (suffixCls: string, customizePrefixCls?: string) =>\n getPrefixCls(`easy-${suffixCls}`, customizePrefixCls),\n };\n },\n // eslint-disable-next-line @tiny-codes/react-hooks/exhaustive-deps\n [langInProps, getPrefixCls, ...Object.values(restProps)]\n );\n\n useEffect(() => {\n // Dynamically add language pack\n if (userLocales) {\n const lang = langInProps || 'en-US';\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-US'].translation, ...userLocales });\n }\n }\n }, [langInProps, userLocales]);\n\n return wrapCSSVar(\n <ReactEasyContext.Provider value={contextValue}>\n <div className={classNames(hashId, cssVarCls, prefixCls, className)} style={style}>\n {children}\n </div>\n </ReactEasyContext.Provider>\n );\n};\nConfigProvider.displayName = 'ReactEasyConfigProvider';\nConfigProvider.ConfigContext = ReactEasyContext;\n\nexport default ConfigProvider;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA+C;AAC/C,kBAAsD;AACtD,wBAAuB;AACvB,qBAA0C;AAE1C,qBAA6D;AAC7D,mBAAqB;AAmCrB,IAAM,iBAAuF,CAAC,UAAU;AACtG,QAAM,EAAE,UAAU,SAAS,aAAa,WAAW,kBAAkB,WAAW,OAAO,GAAG,UAAU,IAAI;AACxG,QAAM,EAAE,MAAM,YAAY,IAAI;AAC9B,QAAM,EAAE,cAAc,cAAc,QAAI,yBAAW,YAAAA,eAAoB,aAAa;AACpF,QAAM,YAAY,aAAa,cAAc,gBAAgB;AAC7D,QAAM,CAAC,YAAY,QAAQ,SAAS,QAAI,aAAAC,SAAS,WAAW,aAAa;AACzE,QAAM,mBAAe;AAAA,IACnB,MAAM;AACJ,UAAI,gBAAgB,eAAAC,QAAQ,UAAU;AACpC,uBAAAA,QAAQ,eAAe,eAAe,OAAO;AAAA,MAC/C;AACA,aAAO;AAAA,QACL,GAAG;AAAA,QACH,cAAc,CAAC,WAAmB,uBAChC,aAAa,QAAQ,aAAa,kBAAkB;AAAA,MACxD;AAAA,IACF;AAAA;AAAA,IAEA,CAAC,aAAa,cAAc,GAAG,OAAO,OAAO,SAAS,CAAC;AAAA,EACzD;AAEA,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,OAAO,EAAE,aAAa,GAAG,YAAY,CAAC;AAAA,MACtG;AAAA,IACF;AAAA,EACF,GAAG,CAAC,aAAa,WAAW,CAAC;AAE7B,SAAO;AAAA,IACL,oCAAC,eAAAC,QAAiB,UAAjB,EAA0B,OAAO,gBAChC,oCAAC,SAAI,eAAW,kBAAAC,SAAW,QAAQ,WAAW,WAAW,SAAS,GAAG,SAClE,QACH,CACF;AAAA,EACF;AACF;AACA,eAAe,cAAc;AAC7B,eAAe,gBAAgB,eAAAD;AAE/B,IAAO,yBAAQ;",
|
|
6
6
|
"names": ["ReactConfigProvider", "useStyle", "locales", "ReactEasyContext", "classNames"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/components/ConfigProvider/style/index.ts"],
|
|
4
|
-
"sourcesContent": ["import { genStyleHooks } from 'antd/es/theme/internal';\nimport type { AliasToken, GenerateStyle } from 'antd/es/theme/internal';\nimport type { CSSObject } from '@ant-design/cssinjs';\nimport type { FullToken } from '@ant-design/cssinjs-utils';\n\ntype
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA8B;AAO9B,IAAM,
|
|
4
|
+
"sourcesContent": ["import { genStyleHooks } from 'antd/es/theme/internal';\nimport type { AliasToken, GenerateStyle } from 'antd/es/theme/internal';\nimport type { CSSObject } from '@ant-design/cssinjs';\nimport type { FullToken } from '@ant-design/cssinjs-utils';\n\ntype ConfigProviderToken = FullToken<{ ''?: object }, AliasToken, ''>;\n\nconst genStyle: GenerateStyle<ConfigProviderToken> = (token): CSSObject => {\n const { componentCls } = token;\n return {\n [componentCls]: {\n width: '100%',\n height: '100%',\n flex: 'auto',\n minWidth: 0,\n minHeight: 0,\n\n '.easy-full-height-table': {\n height: '100%',\n\n [`& > ${token.antCls}-spin-nested-loading`]: {\n height: '100%',\n\n [`& > div > ${token.antCls}-spin`]: {\n maxHeight: '100%',\n },\n\n [`& > ${token.antCls}-spin-container`]: {\n display: 'flex',\n flexDirection: 'column',\n height: '100%',\n\n [`& > ${token.antCls}-table`]: {\n display: 'flex',\n flex: 'auto',\n flexDirection: 'column',\n width: '100%',\n minHeight: 0,\n\n [`& > ${token.antCls}-table-container`]: {\n flex: 'auto',\n minHeight: 0,\n\n [`& > ${token.antCls}-table-content`]: {\n maxHeight: '100%',\n // 把容器再多撑高1px,否则会始终显示纵向滚动条\n paddingBottom: 1,\n // 自动显示纵向滚动条\n // stylelint-disable-next-line declaration-no-important\n overflow: 'auto !important',\n\n '& > table': {\n height: '100%',\n\n [`${token.antCls}-table-thead`]: {\n position: 'sticky',\n top: 0,\n zIndex: 10,\n },\n\n td: {\n // 当嵌套表格时,还原所有full-height样式,防止子表格受影响\n '.easy-full-height-table': {\n height: 'auto',\n },\n },\n },\n },\n },\n },\n [`& > ${token.antCls}-table${token.antCls}-table-empty`]: {\n [`& > ${token.antCls}-table-container`]: {\n [`& > ${token.antCls}-table-content`]: {\n height: '100%',\n },\n },\n },\n\n [`& > ${token.antCls}-table-pagination`]: {\n flex: 'none',\n marginBottom: 0,\n },\n },\n },\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ACA,CAAC,OAAO,MAAM,eAAe,MAAM,oBAAoB,GAAG;AAAA,cACxD,CAAC,OAAO,MAAM,wBAAwB,GAAG;AAAA,gBACvC,CAAC,OAAO,MAAM,sBAAsB,GAAG;AAAA,kBACrC,QAAQ;AAAA,gBACV;AAAA,cACF;AAAA,YACF;AAAA,YAEA,CAAC,OAAO,MAAM,yBAAyB,GAAG;AAAA,cACxC,MAAM;AAAA,cACN,cAAc;AAAA,YAChB;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAO,oBAAQ,+BAAc,kBAA2B,QAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -12,10 +12,26 @@ export interface ContextMenuProps extends MenuProps {
|
|
|
12
12
|
* - **CN:** 触发显示菜单的方式,默认是 `['contextMenu']`
|
|
13
13
|
*/
|
|
14
14
|
trigger?: ('click' | 'doubleClick' | 'hover' | 'contextMenu')[];
|
|
15
|
+
/**
|
|
16
|
+
* - **EN:** Custom properties for the trigger element
|
|
17
|
+
* - **CN:** 触发元素的自定义属性
|
|
18
|
+
*/
|
|
15
19
|
triggerProps?: {
|
|
20
|
+
/**
|
|
21
|
+
* - **EN:** Custom class name for the trigger element
|
|
22
|
+
* - **CN:** 触发元素的自定义类名
|
|
23
|
+
*/
|
|
16
24
|
className?: string;
|
|
25
|
+
/**
|
|
26
|
+
* - **EN:** Custom styles for the trigger element
|
|
27
|
+
* - **CN:** 触发元素的自定义样式
|
|
28
|
+
*/
|
|
17
29
|
style?: CSSProperties;
|
|
18
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* - **EN:** Custom prefix for the component's CSS class.
|
|
33
|
+
* - **CN:** 组件的自定义 CSS 类前缀。
|
|
34
|
+
*/
|
|
19
35
|
prefixCls?: string;
|
|
20
36
|
}
|
|
21
37
|
declare const ContextMenu: import("react").ForwardRefExoticComponent<ContextMenuProps & import("react").RefAttributes<ContextMenuRef>>;
|
|
@@ -37,6 +37,7 @@ var import_antd = require("antd");
|
|
|
37
37
|
var import_classnames = __toESM(require("classnames"));
|
|
38
38
|
var import_react_contexify = require("react-contexify");
|
|
39
39
|
var import_hooks = require("../../hooks");
|
|
40
|
+
var import_ConfigProvider = __toESM(require("../ConfigProvider"));
|
|
40
41
|
var import_style = __toESM(require("./style"));
|
|
41
42
|
var import_ReactContexify = require("react-contexify/dist/ReactContexify.css");
|
|
42
43
|
var ContextMenu = (0, import_react.forwardRef)((props, ref) => {
|
|
@@ -50,7 +51,7 @@ var ContextMenu = (0, import_react.forwardRef)((props, ref) => {
|
|
|
50
51
|
children,
|
|
51
52
|
...rest
|
|
52
53
|
} = props;
|
|
53
|
-
const { getPrefixCls } = (0, import_react.useContext)(
|
|
54
|
+
const { getPrefixCls } = (0, import_react.useContext)(import_ConfigProvider.default.ConfigContext);
|
|
54
55
|
const prefixCls = getPrefixCls("context-menu", prefixClsInProps);
|
|
55
56
|
const [wrapCSSVar, hashId, cssVarCls] = (0, import_style.default)(prefixCls);
|
|
56
57
|
const { show, hideAll } = (0, import_react_contexify.useContextMenu)({ id });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/ContextMenu/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import type { CSSProperties, ReactNode } from 'react';\nimport { forwardRef, useContext, useImperativeHandle, useMemo } from 'react';\nimport { theme as AntdTheme,
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAqE;AACrE,
|
|
6
|
-
"names": ["useStyle", "classNames", "AntdTheme"]
|
|
4
|
+
"sourcesContent": ["import type { CSSProperties, ReactNode } from 'react';\nimport { forwardRef, useContext, useImperativeHandle, useMemo } from 'react';\nimport { ConfigProvider as AntConfigProvider, theme as AntdTheme, Typography } from 'antd';\nimport classNames from 'classnames';\nimport type { ItemProps, MenuProps, SeparatorProps, ShowContextMenuParams, SubMenuProps } from 'react-contexify';\nimport { Item, Menu, RightSlot, Separator, Submenu, useContextMenu } from 'react-contexify';\nimport { useRefFunction } from '../../hooks';\nimport ConfigProvider from '../ConfigProvider';\nimport useStyle from './style';\nimport 'react-contexify/dist/ReactContexify.css';\n\nexport interface ContextMenuProps extends MenuProps {\n /**\n * - **EN:** Menu items to be displayed\n * - **CN:** 要显示的菜单项\n */\n items: (ContextMenuItem | ContextMenuSeparator | ContextMenuSubmenu)[] | undefined;\n /**\n * - **EN:** Trigger methods to show the menu, default is `['contextMenu']`\n * - **CN:** 触发显示菜单的方式,默认是 `['contextMenu']`\n */\n trigger?: ('click' | 'doubleClick' | 'hover' | 'contextMenu')[];\n /**\n * - **EN:** Custom properties for the trigger element\n * - **CN:** 触发元素的自定义属性\n */\n triggerProps?: {\n /**\n * - **EN:** Custom class name for the trigger element\n * - **CN:** 触发元素的自定义类名\n */\n className?: string;\n /**\n * - **EN:** Custom styles for the trigger element\n * - **CN:** 触发元素的自定义样式\n */\n style?: CSSProperties;\n };\n /**\n * - **EN:** Custom prefix for the component's CSS class.\n * - **CN:** 组件的自定义 CSS 类前缀。\n */\n prefixCls?: string;\n}\n// 上下文菜单组件\nconst ContextMenu = forwardRef<ContextMenuRef, ContextMenuProps>((props, ref) => {\n const {\n id,\n items,\n trigger = ['contextMenu'],\n triggerProps,\n prefixCls: prefixClsInProps,\n className,\n children,\n ...rest\n } = props;\n const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);\n const prefixCls = getPrefixCls('context-menu', prefixClsInProps);\n const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);\n const { show, hideAll } = useContextMenu({ id });\n const eventNames = useMemo<Record<NonNullable<ContextMenuProps['trigger']>[number], [string, string | undefined]>>(\n () => ({\n click: ['onClick', undefined],\n doubleClick: ['onDoubleClick', undefined],\n hover: ['onPointerEnter', 'onPointerLeave'],\n contextMenu: ['onContextMenu', undefined],\n }),\n []\n );\n\n // Show context menu handler\n const handleShow = useRefFunction(\n (event: React.MouseEvent<HTMLElement>, options?: Pick<ShowContextMenuParams, 'position'>) => {\n show({\n id,\n event,\n props,\n position: options?.position,\n });\n }\n );\n // Hide all context menus handler\n const handleHideAll = useRefFunction(() => {\n hideAll();\n });\n const eventHandlers = useMemo(() => {\n const handlers: Record<string, (event: React.MouseEvent<HTMLElement>) => void> = {};\n if (trigger) {\n trigger.forEach((eventType) => {\n const [handlerName, leaveHandlerName] = eventNames[eventType];\n handlers[handlerName] = (event: React.MouseEvent<HTMLElement>) => {\n handleShow(event);\n };\n if (leaveHandlerName) {\n handlers[leaveHandlerName] = handleHideAll;\n }\n });\n }\n return handlers;\n }, [eventNames, trigger]);\n\n // Expose show and hideAll methods to the ref\n useImperativeHandle(\n ref,\n () => ({\n show: handleShow,\n hideAll: handleHideAll,\n }),\n []\n );\n\n return (\n <>\n {children &&\n wrapCSSVar(\n <div\n {...eventHandlers}\n className={classNames(hashId, cssVarCls, prefixCls, `${prefixCls}-trigger`, triggerProps?.className)}\n style={triggerProps?.style}\n >\n {children}\n </div>\n )}\n {wrapCSSVar(\n <Menu\n id={id}\n className={classNames(\n hashId,\n cssVarCls,\n prefixCls,\n `${prefixCls}-menu`,\n {\n [`${prefixCls}-menu-has-items`]: !!items?.length,\n },\n className\n )}\n {...rest}\n >\n {renderItems(items, { theme: props.theme, cmpPrefixCls: prefixCls })}\n </Menu>\n )}\n </>\n );\n});\nContextMenu.displayName = 'ContextMenu';\n\n// Render menu items\nfunction renderItems(\n items: (ContextMenuItem | ContextMenuSeparator | ContextMenuSubmenu)[] | undefined,\n options: Pick<ContextMenuProps, 'theme'> & { cmpPrefixCls: string }\n): ReactNode[] | undefined {\n return items?.map((item, index) => {\n const isSeparator = 'type' in item && item.type === 'separator';\n const isSubmenu = 'type' in item && item.type === 'submenu';\n const menuItem = item as ContextMenuItem;\n\n if (isSeparator) {\n // eslint-disable-next-line react/no-array-index-key\n return <Separator key={`[separator]:${index}`} />;\n }\n\n if (isSubmenu) {\n const subMenu = item as ContextMenuSubmenu;\n return (\n <Submenu {...subMenu} key={subMenu.key}>\n {renderItems(item.items, options)}\n </Submenu>\n );\n }\n\n return (\n <Item\n {...menuItem}\n keyMatcher={\n typeof menuItem.shortcutKey === 'object'\n ? (e) => {\n const shortcutKey = menuItem.shortcutKey as Partial<KeyboardEvent>;\n if (shortcutKey.ctrlKey && !e.ctrlKey) return false;\n if (shortcutKey.altKey && !e.altKey) return false;\n if (shortcutKey.shiftKey && !e.shiftKey) return false;\n if (shortcutKey.metaKey && !e.metaKey) return false;\n if (!shortcutKey.key || shortcutKey.key !== e.key) return false;\n return true;\n }\n : menuItem.shortcutKey\n }\n key={menuItem.key}\n >\n {menuItem.children ? (\n menuItem.children\n ) : (\n <>\n {menuItem.icon}\n <span>{menuItem.label}</span>\n {typeof menuItem.shortcutKey === 'object' && (\n <RightSlot>{getShortcutText(menuItem.shortcutKey, options)}</RightSlot>\n )}\n </>\n )}\n </Item>\n );\n });\n}\n\nfunction getShortcutText(\n event: Partial<Pick<KeyboardEvent, 'ctrlKey' | 'altKey' | 'shiftKey' | 'metaKey' | 'key'>>,\n options: Pick<ContextMenuProps, 'theme'> & { cmpPrefixCls: string }\n): ReactNode[] {\n const { theme, cmpPrefixCls } = options;\n const keys: ReactNode[] = [];\n const Keyboard = (props: { children: ReactNode }) => {\n return (\n <AntConfigProvider theme={{ algorithm: theme === 'dark' ? AntdTheme.darkAlgorithm : undefined }}>\n <Typography.Text keyboard className={`${cmpPrefixCls}-shortcut-key`}>\n {props.children}\n </Typography.Text>\n </AntConfigProvider>\n );\n };\n if (event.ctrlKey) keys.push(<Keyboard>^</Keyboard>);\n if (event.altKey) keys.push(<Keyboard>⌥</Keyboard>);\n if (event.shiftKey) keys.push(<Keyboard>⇧</Keyboard>);\n if (event.metaKey) keys.push(<Keyboard>⌘</Keyboard>);\n if (event.key) {\n keys.push(<Keyboard>{event.key}</Keyboard>);\n }\n return keys;\n}\n\nexport interface ContextMenuRef {\n show: (event: React.MouseEvent<HTMLElement>) => void;\n hideAll: () => void;\n}\n\nexport interface ContextMenuItem extends Omit<ItemProps, 'children' | 'keyMatcher'> {\n key: string;\n className?: string;\n icon?: ReactNode;\n label?: ReactNode;\n shortcutKey?:\n | Partial<Pick<KeyboardEvent, 'ctrlKey' | 'altKey' | 'shiftKey' | 'metaKey' | 'key'>>\n | ItemProps['keyMatcher'];\n children?: ReactNode;\n}\n\nexport interface ContextMenuSeparator extends SeparatorProps {\n type: 'separator';\n}\n\nexport interface ContextMenuSubmenu extends SubMenuProps {\n key: string;\n type: 'submenu';\n items: (ContextMenuItem | ContextMenuSeparator | ContextMenuSubmenu)[];\n}\n\nexport default ContextMenu;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAqE;AACrE,kBAAoF;AACpF,wBAAuB;AAEvB,6BAA0E;AAC1E,mBAA+B;AAC/B,4BAA2B;AAC3B,mBAAqB;AACrB,4BAAO;AAoCP,IAAM,kBAAc,yBAA6C,CAAC,OAAO,QAAQ;AAC/E,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,UAAU,CAAC,aAAa;AAAA,IACxB;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL,IAAI;AACJ,QAAM,EAAE,aAAa,QAAI,yBAAW,sBAAAA,QAAe,aAAa;AAChE,QAAM,YAAY,aAAa,gBAAgB,gBAAgB;AAC/D,QAAM,CAAC,YAAY,QAAQ,SAAS,QAAI,aAAAC,SAAS,SAAS;AAC1D,QAAM,EAAE,MAAM,QAAQ,QAAI,uCAAe,EAAE,GAAG,CAAC;AAC/C,QAAM,iBAAa;AAAA,IACjB,OAAO;AAAA,MACL,OAAO,CAAC,WAAW,MAAS;AAAA,MAC5B,aAAa,CAAC,iBAAiB,MAAS;AAAA,MACxC,OAAO,CAAC,kBAAkB,gBAAgB;AAAA,MAC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