@tiny-codes/react-easy 1.7.7 → 1.7.9
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 +18 -0
- package/es/components/ConfigProvider/index.js +8 -7
- package/es/components/ConfigProvider/index.js.map +1 -1
- package/es/components/EllipsisTypography/withEllipsisTypography.d.ts +16 -0
- package/es/components/EllipsisTypography/withEllipsisTypography.js +18 -2
- package/es/components/EllipsisTypography/withEllipsisTypography.js.map +1 -1
- package/es/components/Iconfont/createIconfont.d.ts +15 -1
- package/es/components/Iconfont/createIconfont.js.map +1 -1
- package/es/hooks/index.d.ts +3 -1
- package/es/hooks/index.js +3 -1
- package/es/hooks/index.js.map +1 -1
- package/es/hooks/useRowSelection.d.ts +55 -0
- package/es/hooks/useRowSelection.js +83 -0
- package/es/hooks/useRowSelection.js.map +1 -0
- package/lib/components/ConfigProvider/index.js +6 -2
- package/lib/components/ConfigProvider/index.js.map +2 -2
- package/lib/components/EllipsisTypography/withEllipsisTypography.d.ts +16 -0
- package/lib/components/EllipsisTypography/withEllipsisTypography.js +16 -2
- package/lib/components/EllipsisTypography/withEllipsisTypography.js.map +2 -2
- package/lib/components/Iconfont/createIconfont.d.ts +15 -1
- package/lib/components/Iconfont/createIconfont.js.map +2 -2
- package/lib/hooks/index.d.ts +3 -1
- package/lib/hooks/index.js +6 -1
- package/lib/hooks/index.js.map +2 -2
- package/lib/hooks/useRowSelection.d.ts +55 -0
- package/lib/hooks/useRowSelection.js +67 -0
- package/lib/hooks/useRowSelection.js.map +7 -0
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
## 1.7.9
|
|
6
|
+
|
|
7
|
+
2026-3-18
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
- **useRowSelection**
|
|
12
|
+
- ✨ Add `useRowSelection` hook for managing row selection in tables.
|
|
13
|
+
|
|
14
|
+
## 1.7.8
|
|
15
|
+
|
|
16
|
+
2026-3-18
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
- **EllipsisText**, **EllipsisParagraph**, **EllipsisTitle**, **EllipsisLink**
|
|
21
|
+
- ✨ add `watchResize` prop to monitor component size and adjust ellipsis accordingly.
|
|
22
|
+
|
|
5
23
|
## 1.7.7
|
|
6
24
|
|
|
7
25
|
2026-3-9
|
|
@@ -17,7 +17,7 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
|
17
17
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
18
18
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
19
19
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
20
|
-
import { useContext, useEffect, useMemo } from 'react';
|
|
20
|
+
import { useCallback, useContext, useEffect, useMemo } from 'react';
|
|
21
21
|
import { ConfigProvider as ReactConfigProvider } from 'antd';
|
|
22
22
|
import classNames from 'classnames';
|
|
23
23
|
import locales, { langs, resources } from "../../locales";
|
|
@@ -37,25 +37,26 @@ var ConfigProvider = function ConfigProvider(props) {
|
|
|
37
37
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
38
38
|
var langInProps = restProps.lang;
|
|
39
39
|
var _useContext = useContext(ReactConfigProvider.ConfigContext),
|
|
40
|
-
|
|
40
|
+
getPrefixCls = _useContext.getPrefixCls,
|
|
41
41
|
rootPrefixCls = _useContext.rootPrefixCls;
|
|
42
|
-
var prefixCls =
|
|
42
|
+
var prefixCls = getPrefixCls('react-easy', prefixClsInProps);
|
|
43
43
|
var _useStyle = useStyle(prefixCls, rootPrefixCls),
|
|
44
44
|
_useStyle2 = _slicedToArray(_useStyle, 3),
|
|
45
45
|
wrapCSSVar = _useStyle2[0],
|
|
46
46
|
hashId = _useStyle2[1],
|
|
47
47
|
cssVarCls = _useStyle2[2];
|
|
48
|
+
var getEasyPrefixCls = useCallback(function (suffixCls, customizePrefixCls) {
|
|
49
|
+
return getPrefixCls("easy-".concat(suffixCls), customizePrefixCls);
|
|
50
|
+
}, [getPrefixCls]);
|
|
48
51
|
var contextValue = useMemo(function () {
|
|
49
52
|
if (langInProps !== locales.language) {
|
|
50
53
|
locales.changeLanguage(langInProps || 'en-US');
|
|
51
54
|
}
|
|
52
55
|
return _objectSpread(_objectSpread({}, restProps), {}, {
|
|
53
|
-
getPrefixCls:
|
|
54
|
-
return _getPrefixCls("easy-".concat(suffixCls), customizePrefixCls);
|
|
55
|
-
}
|
|
56
|
+
getPrefixCls: getEasyPrefixCls
|
|
56
57
|
});
|
|
57
58
|
}, // eslint-disable-next-line @tiny-codes/react-hooks/exhaustive-deps
|
|
58
|
-
[langInProps,
|
|
59
|
+
[langInProps, getEasyPrefixCls].concat(_toConsumableArray(Object.values(restProps))));
|
|
59
60
|
useEffect(function () {
|
|
60
61
|
// Dynamically add language pack
|
|
61
62
|
if (userLocales) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useContext","useEffect","useMemo","ConfigProvider","ReactConfigProvider","classNames","locales","langs","resources","ReactEasyContext","useStyle","jsx","_jsx","props","children","userLocales","prefixClsInProps","prefixCls","className","style","restProps","_objectWithoutProperties","_excluded","langInProps","lang","_useContext","ConfigContext","getPrefixCls","rootPrefixCls","_useStyle","_useStyle2","_slicedToArray","wrapCSSVar","hashId","cssVarCls","
|
|
1
|
+
{"version":3,"names":["useCallback","useContext","useEffect","useMemo","ConfigProvider","ReactConfigProvider","classNames","locales","langs","resources","ReactEasyContext","useStyle","jsx","_jsx","props","children","userLocales","prefixClsInProps","prefixCls","className","style","restProps","_objectWithoutProperties","_excluded","langInProps","lang","_useContext","ConfigContext","getPrefixCls","rootPrefixCls","_useStyle","_useStyle2","_slicedToArray","wrapCSSVar","hashId","cssVarCls","getEasyPrefixCls","suffixCls","customizePrefixCls","concat","contextValue","language","changeLanguage","_objectSpread","_toConsumableArray","Object","values","includes","removeResourceBundle","addResourceBundle","translation","Provider","value","displayName"],"sources":["../../../src/components/ConfigProvider/index.tsx"],"sourcesContent":["import type { CSSProperties, FC, ReactNode } from 'react';\nimport { useCallback, 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 getEasyPrefixCls = useCallback(\n (suffixCls: string, customizePrefixCls?: string) => getPrefixCls(`easy-${suffixCls}`, customizePrefixCls),\n [getPrefixCls]\n );\n const contextValue = useMemo(\n () => {\n if (langInProps !== locales.language) {\n locales.changeLanguage(langInProps || 'en-US');\n }\n return {\n ...restProps,\n getPrefixCls: getEasyPrefixCls,\n };\n },\n // eslint-disable-next-line @tiny-codes/react-hooks/exhaustive-deps\n [langInProps, getEasyPrefixCls, ...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"],"mappings":";;;;;;;;;;;;;;;;;;;AACA,SAASA,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,QAAQ,OAAO;AACnE,SAASC,cAAc,IAAIC,mBAAmB,QAAQ,MAAM;AAC5D,OAAOC,UAAU,MAAM,YAAY;AACnC,OAAOC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Aa,GAAGjB,gBAAgB;AAE/C,eAAeN,cAAc"}
|
|
@@ -4,7 +4,23 @@ import type { TextProps } from 'antd/es/typography/Text';
|
|
|
4
4
|
import type { TitleProps } from 'antd/es/typography/Title';
|
|
5
5
|
declare function withEllipsisTypography<T extends TextProps | ParagraphProps | TitleProps>(Component: ComponentType<MakeEllipsisTypographyProps<T>>): (props: MakeEllipsisTypographyProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
6
6
|
export type MakeEllipsisTypographyProps<T> = Omit<T, 'children'> & {
|
|
7
|
+
/**
|
|
8
|
+
* - **EN:** The text content to display. If not provided, the children will be used.
|
|
9
|
+
* - **CN:** 要显示的文本内容。如果未提供,将使用子元素。
|
|
10
|
+
*/
|
|
7
11
|
text?: string | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* - **EN:** The children content to display. The `text` prop will take precedence if both are
|
|
14
|
+
* provided.
|
|
15
|
+
* - **CN:** 要显示的子元素内容。如果同时提供了 `text` 属性,将优先使用 `text`。
|
|
16
|
+
*/
|
|
8
17
|
children?: string | undefined | null;
|
|
18
|
+
/**
|
|
19
|
+
* - **EN:** Whether to monitor the component's size and adjust the ellipsis accordingly.
|
|
20
|
+
* - **CN:** 是否监控组件的大小并相应地调整省略号。
|
|
21
|
+
*
|
|
22
|
+
* @default true
|
|
23
|
+
*/
|
|
24
|
+
watchResize?: boolean;
|
|
9
25
|
};
|
|
10
26
|
export default withEllipsisTypography;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _excluded = ["ellipsis", "children", "text"];
|
|
1
|
+
var _excluded = ["ellipsis", "children", "text", "watchResize"];
|
|
2
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
4
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -15,6 +15,8 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
|
15
15
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
16
16
|
import { useEffect, useMemo, useState } from 'react';
|
|
17
17
|
import { Tooltip } from 'antd';
|
|
18
|
+
import { useResizeDetector } from 'react-resize-detector';
|
|
19
|
+
import { useRefFunction, useRefValue } from "../../hooks";
|
|
18
20
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
19
21
|
function withEllipsisTypography(Component) {
|
|
20
22
|
return function EllipsisText(props) {
|
|
@@ -23,6 +25,8 @@ function withEllipsisTypography(Component) {
|
|
|
23
25
|
children = props.children,
|
|
24
26
|
_props$text = props.text,
|
|
25
27
|
text = _props$text === void 0 ? children : _props$text,
|
|
28
|
+
_props$watchResize = props.watchResize,
|
|
29
|
+
watchResize = _props$watchResize === void 0 ? true : _props$watchResize,
|
|
26
30
|
rest = _objectWithoutProperties(props, _excluded);
|
|
27
31
|
var _useState = useState(false),
|
|
28
32
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -32,6 +36,7 @@ function withEllipsisTypography(Component) {
|
|
|
32
36
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
33
37
|
dom = _useState4[0],
|
|
34
38
|
setDom = _useState4[1];
|
|
39
|
+
var domRef = useRefValue(dom);
|
|
35
40
|
var isAutoEllipsis = useMemo(function () {
|
|
36
41
|
return ellipsis === true;
|
|
37
42
|
}, [ellipsis]);
|
|
@@ -47,10 +52,21 @@ function withEllipsisTypography(Component) {
|
|
|
47
52
|
var tooltipTitle = useMemo(function () {
|
|
48
53
|
return isEllipsis ? text : undefined;
|
|
49
54
|
}, [isEllipsis, text]);
|
|
55
|
+
var detectEllipsis = useRefFunction(function () {
|
|
56
|
+
return dom && setIsEllipsis(dom.scrollWidth > dom.clientWidth || dom.scrollHeight > dom.clientHeight);
|
|
57
|
+
});
|
|
58
|
+
useResizeDetector({
|
|
59
|
+
targetRef: watchResize ? domRef : undefined,
|
|
60
|
+
onResize: detectEllipsis,
|
|
61
|
+
refreshRate: 10,
|
|
62
|
+
refreshOptions: {
|
|
63
|
+
leading: false
|
|
64
|
+
}
|
|
65
|
+
});
|
|
50
66
|
useEffect(function () {
|
|
51
67
|
if (dom && isAuto) {
|
|
52
68
|
Promise.resolve().then(function () {
|
|
53
|
-
|
|
69
|
+
detectEllipsis();
|
|
54
70
|
});
|
|
55
71
|
}
|
|
56
72
|
}, [text, isAuto, dom]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useEffect","useMemo","useState","Tooltip","jsx","_jsx","withEllipsisTypography","Component","EllipsisText","props","_props$ellipsis","ellipsis","children","_props$text","text","rest","_objectWithoutProperties","_excluded","_useState","_useState2","_slicedToArray","isEllipsis","setIsEllipsis","_useState3","_useState4","dom","setDom","isAutoEllipsis","isAutoTooltip","_typeof","tooltip","isAutoTooltipTitle","title","isAuto","tooltipTitle","undefined","
|
|
1
|
+
{"version":3,"names":["useEffect","useMemo","useState","Tooltip","useResizeDetector","useRefFunction","useRefValue","jsx","_jsx","withEllipsisTypography","Component","EllipsisText","props","_props$ellipsis","ellipsis","children","_props$text","text","_props$watchResize","watchResize","rest","_objectWithoutProperties","_excluded","_useState","_useState2","_slicedToArray","isEllipsis","setIsEllipsis","_useState3","_useState4","dom","setDom","domRef","isAutoEllipsis","isAutoTooltip","_typeof","tooltip","isAutoTooltipTitle","title","isAuto","tooltipTitle","undefined","detectEllipsis","scrollWidth","clientWidth","scrollHeight","clientHeight","targetRef","onResize","refreshRate","refreshOptions","leading","Promise","resolve","then","_objectSpread","ref"],"sources":["../../../src/components/EllipsisTypography/withEllipsisTypography.tsx"],"sourcesContent":["import type { ComponentType } from 'react';\nimport { useEffect, useMemo, useState } from 'react';\nimport type { TooltipProps } from 'antd';\nimport { Tooltip } from 'antd';\nimport type { EllipsisConfig } from 'antd/es/typography/Base';\nimport type { ParagraphProps } from 'antd/es/typography/Paragraph';\nimport type { TextProps } from 'antd/es/typography/Text';\nimport type { TitleProps } from 'antd/es/typography/Title';\nimport { useResizeDetector } from 'react-resize-detector';\nimport { useRefFunction, useRefValue } from '../../hooks';\n\nfunction withEllipsisTypography<T extends TextProps | ParagraphProps | TitleProps>(\n Component: ComponentType<MakeEllipsisTypographyProps<T>>\n) {\n return function EllipsisText(props: MakeEllipsisTypographyProps<T>) {\n const { ellipsis = true, children, text = children, watchResize = true, ...rest } = props;\n const [isEllipsis, setIsEllipsis] = useState(false);\n const [dom, setDom] = useState<HTMLElement | null>(null);\n const domRef = useRefValue(dom);\n const isAutoEllipsis = useMemo(() => ellipsis === true, [ellipsis]);\n const isAutoTooltip = useMemo(() => typeof ellipsis === 'object' && ellipsis.tooltip === true, [ellipsis]);\n const isAutoTooltipTitle = useMemo(\n () =>\n typeof ellipsis === 'object' &&\n ellipsis.tooltip &&\n typeof ellipsis.tooltip === 'object' &&\n 'title' in ellipsis.tooltip &&\n ellipsis.tooltip.title === true,\n [ellipsis]\n );\n const isAuto = useMemo(\n () => isAutoEllipsis || isAutoTooltip || isAutoTooltipTitle,\n [isAutoEllipsis, isAutoTooltip, isAutoTooltipTitle]\n );\n const tooltipTitle = useMemo(() => (isEllipsis ? text : undefined), [isEllipsis, text]);\n\n const detectEllipsis = useRefFunction(\n () => dom && setIsEllipsis(dom.scrollWidth > dom.clientWidth || dom.scrollHeight > dom.clientHeight)\n );\n useResizeDetector({\n targetRef: watchResize ? domRef : undefined,\n onResize: detectEllipsis,\n refreshRate: 10,\n refreshOptions: {\n leading: false,\n },\n });\n\n useEffect(() => {\n if (dom && isAuto) {\n Promise.resolve().then(() => {\n detectEllipsis();\n });\n }\n }, [text, isAuto, dom]);\n\n return (\n <Tooltip {...((ellipsis as EllipsisConfig)?.tooltip as TooltipProps)} title={tooltipTitle}>\n <Component\n ref={setDom}\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n {...(rest as any)}\n ellipsis={\n isAutoEllipsis\n ? { tooltip: undefined }\n : isAutoTooltip\n ? {\n ...(ellipsis as EllipsisConfig),\n tooltip: undefined,\n }\n : isAutoTooltipTitle\n ? {\n ...(ellipsis as EllipsisConfig),\n tooltip: {\n ...((ellipsis as EllipsisConfig)?.tooltip as TooltipProps),\n title: undefined,\n },\n }\n : ellipsis\n }\n >\n {text}\n </Component>\n </Tooltip>\n );\n };\n}\n\nexport type MakeEllipsisTypographyProps<T> = Omit<T, 'children'> & {\n /**\n * - **EN:** The text content to display. If not provided, the children will be used.\n * - **CN:** 要显示的文本内容。如果未提供,将使用子元素。\n */\n text?: string | undefined;\n /**\n * - **EN:** The children content to display. The `text` prop will take precedence if both are\n * provided.\n * - **CN:** 要显示的子元素内容。如果同时提供了 `text` 属性,将优先使用 `text`。\n */\n children?: string | undefined | null;\n /**\n * - **EN:** Whether to monitor the component's size and adjust the ellipsis accordingly.\n * - **CN:** 是否监控组件的大小并相应地调整省略号。\n *\n * @default true\n */\n watchResize?: boolean;\n};\n\nexport default withEllipsisTypography;\n"],"mappings":";;;;;;;;;;;;;;;AACA,SAASA,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AAEpD,SAASC,OAAO,QAAQ,MAAM;AAK9B,SAASC,iBAAiB,QAAQ,uBAAuB;AACzD,SAASC,cAAc,E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AOzC,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAqBsB,OAAO;MAAmBE,KAAK,EAAEE,YAAa;MAAAzB,QAAA,eACxFP,IAAA,CAACE,SAAS,EAAA6C,aAAA,CAAAA,aAAA;QACRC,GAAG,EAAEzB;QACL;MAAA,GACKX,IAAI;QACTN,QAAQ,EACNmB,cAAc,GACV;UAAEG,OAAO,EAAEK;QAAU,CAAC,GACtBP,aAAa,GAAAqB,aAAA,CAAAA,aAAA,KAELzC,QAAQ;UACZsB,OAAO,EAAEK;QAAS,KAEpBJ,kBAAkB,GAAAkB,aAAA,CAAAA,aAAA,KAEVzC,QAAQ;UACZsB,OAAO,EAAAmB,aAAA,CAAAA,aAAA,KACAzC,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAqBsB,OAAO;YACzCE,KAAK,EAAEG;UAAS;QACjB,KAEH3B,QACT;QAAAC,QAAA,EAEAE;MAAI,EACI;IAAC,EACL,CAAC;EAEd,CAAC;AACH;AAuBA,eAAeR,sBAAsB"}
|
|
@@ -4,12 +4,26 @@ import type { IconFontProps as AntIconFontProps } from '@ant-design/icons/es/com
|
|
|
4
4
|
* - **EN:** Props for the Iconfont component
|
|
5
5
|
* - **CN:** Iconfont 组件的props
|
|
6
6
|
*/
|
|
7
|
-
export interface IconfontProps<T extends string = string> extends Omit<AntIconFontProps<T>, 'type' | 'size'> {
|
|
7
|
+
export interface IconfontProps<T extends string = string> extends Omit<AntIconFontProps<T>, 'type' | 'size' | 'spin' | 'rotate'> {
|
|
8
8
|
/**
|
|
9
9
|
* - **EN:** Icon name. Find an icon in iconfont and click `Copy Code`
|
|
10
10
|
* - **CN:** 图标名称。在 iconfont 中找到某个图标,点击`复制代码`
|
|
11
11
|
*/
|
|
12
12
|
type: T;
|
|
13
|
+
/**
|
|
14
|
+
* - **EN:** Whether the icon should spin continuously, can be used to indicate loading
|
|
15
|
+
* - **CN:** 图标是否持续旋转,可以实现 loading 的效果
|
|
16
|
+
*
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
spin?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* - **EN:** Rotate the icon by a fixed angle clockwise
|
|
22
|
+
* - **CN:** 图标顺时针旋转一个固定角度
|
|
23
|
+
*
|
|
24
|
+
* @default 0
|
|
25
|
+
*/
|
|
26
|
+
rotate?: number;
|
|
13
27
|
/**
|
|
14
28
|
* - **EN:** Icon size, an alias for `style.fontSize`
|
|
15
29
|
* - **CN:** 图标尺寸,是 `style.fontSize` 的别名
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useContext","classNames","createFromIconfontCN","ConfigProvider","jsx","_jsx","createIconfont","scriptUrl","options","_ref","_ref$iconPrefix","iconPrefix","AntdIconfont","Iconfont","props","_style$fontSize","type","className","size","style","iconProps","_objectWithoutProperties","_excluded","_useContext","ConfigContext","getPrefixCls","iconType","startsWith","concat","_objectSpread","fontSize"],"sources":["../../../src/components/Iconfont/createIconfont.tsx"],"sourcesContent":["import { type CSSProperties, type FC, useContext } from 'react';\nimport classNames from 'classnames';\nimport { createFromIconfontCN } from '@ant-design/icons';\nimport type { IconFontProps as AntIconFontProps } from '@ant-design/icons/es/components/IconFont';\nimport ConfigProvider from '../ConfigProvider';\n\n/**\n * - **EN:** Props for the Iconfont component\n * - **CN:** Iconfont 组件的props\n */\nexport interface IconfontProps<T extends string = string
|
|
1
|
+
{"version":3,"names":["useContext","classNames","createFromIconfontCN","ConfigProvider","jsx","_jsx","createIconfont","scriptUrl","options","_ref","_ref$iconPrefix","iconPrefix","AntdIconfont","Iconfont","props","_style$fontSize","type","className","size","style","iconProps","_objectWithoutProperties","_excluded","_useContext","ConfigContext","getPrefixCls","iconType","startsWith","concat","_objectSpread","fontSize"],"sources":["../../../src/components/Iconfont/createIconfont.tsx"],"sourcesContent":["import { type CSSProperties, type FC, useContext } from 'react';\nimport classNames from 'classnames';\nimport { createFromIconfontCN } from '@ant-design/icons';\nimport type { IconFontProps as AntIconFontProps } from '@ant-design/icons/es/components/IconFont';\nimport ConfigProvider from '../ConfigProvider';\n\n/**\n * - **EN:** Props for the Iconfont component\n * - **CN:** Iconfont 组件的props\n */\nexport interface IconfontProps<T extends string = string>\n extends Omit<AntIconFontProps<T>, 'type' | 'size' | 'spin' | 'rotate'> {\n /**\n * - **EN:** Icon name. Find an icon in iconfont and click `Copy Code`\n * - **CN:** 图标名称。在 iconfont 中找到某个图标,点击`复制代码`\n */\n type: T;\n /**\n * - **EN:** Whether the icon should spin continuously, can be used to indicate loading\n * - **CN:** 图标是否持续旋转,可以实现 loading 的效果\n *\n * @default false\n */\n spin?: boolean;\n /**\n * - **EN:** Rotate the icon by a fixed angle clockwise\n * - **CN:** 图标顺时针旋转一个固定角度\n *\n * @default 0\n */\n rotate?: number;\n /**\n * - **EN:** Icon size, an alias for `style.fontSize`\n * - **CN:** 图标尺寸,是 `style.fontSize` 的别名\n */\n size?: CSSProperties['fontSize'];\n}\n\n/**\n * - **EN:** Create an Iconfont component with a specified iconfont script URL.\n * - **CN:** 创建一个Iconfont组件,指定iconfont的脚本地址\n *\n * @param scriptUrl - Path to the iconfont script | 字体图标的路径\n */\nexport const createIconfont = <T extends string = string>(\n scriptUrl: string,\n options?: {\n /** Icon name prefix | 图标名称前缀 */\n iconPrefix?: string;\n }\n): FC<IconfontProps<T>> => {\n const { iconPrefix = '' } = options || {};\n const AntdIconfont = createFromIconfontCN({ scriptUrl });\n /**\n * - **EN:** Render an iconfont icon, setting the `type` prop to the iconfont icon name.\n * - **CN:** 渲染一个 iconfont 的图标,把 `type` 属性设置为 iconfont 字体的图标名\n */\n const Iconfont: FC<IconfontProps<T>> = (props) => {\n const { type, className, size, style, ...iconProps } = props;\n const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);\n const iconType = type.startsWith(iconPrefix) ? type : `${iconPrefix}-${type}`;\n\n return (\n <AntdIconfont\n type={iconType}\n className={classNames(getPrefixCls('iconfont'), className)}\n style={{\n ...style,\n fontSize: style?.fontSize ?? size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AS,EAAEhB,UAAU,CAACwB,YAAY,CAAC,UAAU,CAAC,EAAER,SAAS,CAAE;MAC3DE,KAAK,EAAAU,aAAA,CAAAA,aAAA,KACAV,KAAK;QACRW,QAAQ,GAAAf,eAAA,GAAEI,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEW,QAAQ,cAAAf,eAAA,cAAAA,eAAA,GAAIG;MAAI;IACjC,GACEE,SAAS,CACd,CAAC;EAEN,CAAC;EACD,OAAOP,QAAQ;AACjB,CAAC"}
|
package/es/hooks/index.d.ts
CHANGED
|
@@ -6,8 +6,10 @@ export * from './useMovable';
|
|
|
6
6
|
export { default as useMovable } from './useMovable';
|
|
7
7
|
export * from './useProcessingText';
|
|
8
8
|
export { default as useProcessingText } from './useProcessingText';
|
|
9
|
-
export { default as useRefValue } from './useRefValue';
|
|
10
9
|
export { default as useRefFunction } from './useRefFunction';
|
|
10
|
+
export { default as useRefValue } from './useRefValue';
|
|
11
|
+
export * from './useRowSelection';
|
|
12
|
+
export { default as useRowSelection } from './useRowSelection';
|
|
11
13
|
export * from './useSplitter';
|
|
12
14
|
export { default as useSplitter } from './useSplitter';
|
|
13
15
|
export * from './useSSE';
|
package/es/hooks/index.js
CHANGED
|
@@ -6,8 +6,10 @@ export * from "./useMovable";
|
|
|
6
6
|
export { default as useMovable } from "./useMovable";
|
|
7
7
|
export * from "./useProcessingText";
|
|
8
8
|
export { default as useProcessingText } from "./useProcessingText";
|
|
9
|
-
export { default as useRefValue } from "./useRefValue";
|
|
10
9
|
export { default as useRefFunction } from "./useRefFunction";
|
|
10
|
+
export { default as useRefValue } from "./useRefValue";
|
|
11
|
+
export * from "./useRowSelection";
|
|
12
|
+
export { default as useRowSelection } from "./useRowSelection";
|
|
11
13
|
export * from "./useSplitter";
|
|
12
14
|
export { default as useSplitter } from "./useSplitter";
|
|
13
15
|
export * from "./useSSE";
|
package/es/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["default","useAudioPlayer","useDebounce","useLocalStorage","useMovable","useProcessingText","useRefValue","
|
|
1
|
+
{"version":3,"names":["default","useAudioPlayer","useDebounce","useLocalStorage","useMovable","useProcessingText","useRefFunction","useRefValue","useRowSelection","useSplitter","useSSE","useStompSocket","useUserMedia","useValidators","useValidator","useValidatorBuilder"],"sources":["../../src/hooks/index.ts"],"sourcesContent":["export { default as useAudioPlayer } from './useAudioPlayer';\n\nexport { default as useDebounce } from './useDebounce';\n\nexport * from './useLocalStorage';\nexport { default as useLocalStorage } from './useLocalStorage';\n\nexport * from './useMovable';\nexport { default as useMovable } from './useMovable';\n\nexport * from './useProcessingText';\nexport { default as useProcessingText } from './useProcessingText';\n\nexport { default as useRefFunction } from './useRefFunction';\n\nexport { default as useRefValue } from './useRefValue';\n\nexport * from './useRowSelection';\nexport { default as useRowSelection } from './useRowSelection';\n\nexport * from './useSplitter';\nexport { default as useSplitter } from './useSplitter';\n\nexport * from './useSSE';\nexport { default as useSSE } from './useSSE';\n\nexport * from './useStompSocket';\nexport { default as useStompSocket } from './useStompSocket';\n\nexport * from './useUserMedia';\nexport { default as useUserMedia } from './useUserMedia';\n\nexport type { ValidatorRuleMap } from './useValidators';\nexport { default as useValidators } from './useValidators';\n\nexport { default as useValidator } from './useValidator';\n\nexport type { Validator, RuleRegExpFlags, ValidatorRule, BuilderOptions } from './useValidatorBuilder';\nexport { default as useValidatorBuilder } from './useValidatorBuilder';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,cAAc;AAElC,SAASD,OAAO,IAAIE,WAAW;AAE/B;AACA,SAASF,OAAO,IAAIG,eAAe;AAEnC;AACA,SAASH,OAAO,IAAII,UAAU;AAE9B;AACA,SAASJ,OAAO,IAAIK,iBAAiB;AAErC,SAASL,OAAO,IAAIM,cAAc;AAElC,SAASN,OAAO,IAAIO,WAAW;AAE/B;AACA,SAASP,OAAO,IAAIQ,eAAe;AAEnC;AACA,SAASR,OAAO,IAAIS,WAAW;AAE/B;AACA,SAAST,OAAO,IAAIU,MAAM;AAE1B;AACA,SAASV,OAAO,IAAIW,cAAc;AAElC;AACA,SAASX,OAAO,IAAIY,YAAY;AAGhC,SAASZ,OAAO,IAAIa,aAAa;AAEjC,SAASb,OAAO,IAAIc,YAAY;AAGhC,SAASd,OAAO,IAAIe,mBAAmB"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { TableRowSelection } from 'antd/es/table/interface';
|
|
2
|
+
export type UseRowSelectionOption<T extends object = Record<string, unknown>> = Omit<TableRowSelection<T>, 'preserveSelectedRowKeys' | 'selectedRowKeys' | 'onChange'> & {
|
|
3
|
+
/**
|
|
4
|
+
* - **EN:** The selected row objects.
|
|
5
|
+
* - **CN:** 选中的行对象。
|
|
6
|
+
*/
|
|
7
|
+
value?: T[];
|
|
8
|
+
/**
|
|
9
|
+
* - **EN:** Callback function triggered when the selected rows change.
|
|
10
|
+
* - **CN:** 当选中的行发生变化时触发的回调函数。
|
|
11
|
+
*
|
|
12
|
+
* @param value - The selected row objects | 选中的行对象
|
|
13
|
+
*/
|
|
14
|
+
onChange?: (value: T[]) => void;
|
|
15
|
+
/**
|
|
16
|
+
* - **EN:** The field name or function to get the key of the object. If not set, the `id` or `code`
|
|
17
|
+
* field will be used as the key by default.
|
|
18
|
+
* - **CN:** 获取对象key的字段名或函数,如果不设置,则默认使用 `id` 或 `code` 字段作为key。
|
|
19
|
+
*/
|
|
20
|
+
rowKey?: keyof T | ((item: T) => string);
|
|
21
|
+
/**
|
|
22
|
+
* - **EN:** Whether to support table selection. If set to `false`, the table row selection feature
|
|
23
|
+
* will be disabled.
|
|
24
|
+
* - **CN:** 是否支持表格选择,如果设置为`false`,则禁用table的行选择功能。
|
|
25
|
+
*
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
28
|
+
checkable?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* - **EN:** Cache of all selected objects, used to initialize the internal cache.
|
|
31
|
+
*
|
|
32
|
+
* This usage is not very common and is generally used for persistent caching outside the Table,
|
|
33
|
+
* such as saving in localStorage or, in the case of a MicroApp, saving in the main application,
|
|
34
|
+
* so that when the Table is destroyed and re-entered, it can restore all previously selected
|
|
35
|
+
* cached objects (otherwise, data across pages will be lost).
|
|
36
|
+
* - **CN:** 所有被选中对象的缓存,用于初始化内部的缓存对象。
|
|
37
|
+
*
|
|
38
|
+
* 这种用法不太常见,一般用于在Table外进行持久化缓存,例如保存在localStorage中、或作为MicroApp时保存在主应用中,
|
|
39
|
+
* 从而在Table被销毁后再次进入时能恢复之前选中的所有缓存对象(否则跨页的数据会丢失)。
|
|
40
|
+
*/
|
|
41
|
+
cache?: T[];
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* - **EN:** Generate the `rowSelection` property settings for the Table component, supporting
|
|
45
|
+
* cross-page selection. The `onChange` callback returns the selected row objects instead of the
|
|
46
|
+
* selected row keys.
|
|
47
|
+
*
|
|
48
|
+
* Use `rowKey` to specify the key of the row object. If not specified, it will try to get the `id`
|
|
49
|
+
* or `code` field from the row object as the key.
|
|
50
|
+
* - **CN:** 生成Table组件的rowSelection属性设置,支持跨页选中,`onChange`返回选中的行对象,而不是选中的行key。
|
|
51
|
+
*
|
|
52
|
+
* 使用 `rowKey` 来指定行对象的key,如果不指定,则会尝试从行对象中获取 `id` 或 `code` 字段作为key。
|
|
53
|
+
*/
|
|
54
|
+
declare function useRowSelection<T extends object = Record<string, unknown>>(options?: UseRowSelectionOption<T>): TableRowSelection<T> | undefined;
|
|
55
|
+
export default useRowSelection;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
var _excluded = ["value", "rowKey", "onChange", "checkable", "cache"];
|
|
3
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
9
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
10
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
11
|
+
/**
|
|
12
|
+
* - **EN:** Generate the `rowSelection` property settings for the Table component, supporting
|
|
13
|
+
* cross-page selection. The `onChange` callback returns the selected row objects instead of the
|
|
14
|
+
* selected row keys.
|
|
15
|
+
*
|
|
16
|
+
* Use `rowKey` to specify the key of the row object. If not specified, it will try to get the `id`
|
|
17
|
+
* or `code` field from the row object as the key.
|
|
18
|
+
* - **CN:** 生成Table组件的rowSelection属性设置,支持跨页选中,`onChange`返回选中的行对象,而不是选中的行key。
|
|
19
|
+
*
|
|
20
|
+
* 使用 `rowKey` 来指定行对象的key,如果不指定,则会尝试从行对象中获取 `id` 或 `code` 字段作为key。
|
|
21
|
+
*/
|
|
22
|
+
function useRowSelection(options) {
|
|
23
|
+
var _ref = options || {},
|
|
24
|
+
value = _ref.value,
|
|
25
|
+
rowKey = _ref.rowKey,
|
|
26
|
+
_onChange = _ref.onChange,
|
|
27
|
+
_ref$checkable = _ref.checkable,
|
|
28
|
+
checkable = _ref$checkable === void 0 ? true : _ref$checkable,
|
|
29
|
+
cache = _ref.cache,
|
|
30
|
+
restOptions = _objectWithoutProperties(_ref, _excluded);
|
|
31
|
+
var keys = useMemo(function () {
|
|
32
|
+
return value === null || value === void 0 ? void 0 : value.map(function (item) {
|
|
33
|
+
return getKey(item, rowKey);
|
|
34
|
+
});
|
|
35
|
+
}, [value, rowKey]);
|
|
36
|
+
var selectedCacheRef = useRef(new Map(cache === null || cache === void 0 ? void 0 : cache.map(function (item) {
|
|
37
|
+
return [getKey(item, rowKey), item];
|
|
38
|
+
})));
|
|
39
|
+
useEffect(function () {
|
|
40
|
+
// Remove items that no longer exist in selectedCacheRef
|
|
41
|
+
// When the parent component's directory type or domain changes, the value will be reset, and the selectedCacheRef needs to be cleared
|
|
42
|
+
selectedCacheRef.current.forEach(function (item) {
|
|
43
|
+
var itemKey = getKey(item, rowKey);
|
|
44
|
+
if (!(value || []).some(function (v) {
|
|
45
|
+
return getKey(v, rowKey) === itemKey;
|
|
46
|
+
})) {
|
|
47
|
+
selectedCacheRef.current.delete(itemKey);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}, [rowKey, value]);
|
|
51
|
+
return checkable !== false ? _objectSpread(_objectSpread({}, restOptions), {}, {
|
|
52
|
+
preserveSelectedRowKeys: true,
|
|
53
|
+
selectedRowKeys: keys,
|
|
54
|
+
onChange: function onChange(selectedKeys, selectedRows) {
|
|
55
|
+
// Remove the deselected items
|
|
56
|
+
selectedCacheRef.current.forEach(function (item) {
|
|
57
|
+
var key = getKey(item, rowKey);
|
|
58
|
+
if (!(selectedKeys !== null && selectedKeys !== void 0 && selectedKeys.includes(key))) {
|
|
59
|
+
selectedCacheRef.current.delete(key);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
// Add new selected items
|
|
63
|
+
selectedRows === null || selectedRows === void 0 || selectedRows.forEach(function (item) {
|
|
64
|
+
var key = getKey(item, rowKey);
|
|
65
|
+
selectedCacheRef.current.set(key, item);
|
|
66
|
+
});
|
|
67
|
+
_onChange === null || _onChange === void 0 || _onChange(selectedKeys.map(function (id) {
|
|
68
|
+
return selectedCacheRef.current.get(id);
|
|
69
|
+
}).filter(Boolean));
|
|
70
|
+
}
|
|
71
|
+
}) : undefined;
|
|
72
|
+
}
|
|
73
|
+
function getKey(item, keyField) {
|
|
74
|
+
if (!item) {
|
|
75
|
+
return '';
|
|
76
|
+
}
|
|
77
|
+
if (typeof keyField === 'function') {
|
|
78
|
+
return keyField(item);
|
|
79
|
+
}
|
|
80
|
+
return item[keyField] || ('id' in item ? item['id'] : '') || ('code' in item ? item['code'] : '');
|
|
81
|
+
}
|
|
82
|
+
export default useRowSelection;
|
|
83
|
+
//# sourceMappingURL=useRowSelection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useEffect","useMemo","useRef","useRowSelection","options","_ref","value","rowKey","onChange","_ref$checkable","checkable","cache","restOptions","_objectWithoutProperties","_excluded","keys","map","item","getKey","selectedCacheRef","Map","current","forEach","itemKey","some","v","delete","_objectSpread","preserveSelectedRowKeys","selectedRowKeys","selectedKeys","selectedRows","key","includes","set","id","get","filter","Boolean","undefined","keyField"],"sources":["../../src/hooks/useRowSelection.ts"],"sourcesContent":["import type { Key } from 'react';\nimport { useEffect, useMemo, useRef } from 'react';\nimport type { TableRowSelection } from 'antd/es/table/interface';\n\nexport type UseRowSelectionOption<T extends object = Record<string, unknown>> = Omit<\n TableRowSelection<T>,\n 'preserveSelectedRowKeys' | 'selectedRowKeys' | 'onChange'\n> & {\n /**\n * - **EN:** The selected row objects.\n * - **CN:** 选中的行对象。\n */\n value?: T[];\n /**\n * - **EN:** Callback function triggered when the selected rows change.\n * - **CN:** 当选中的行发生变化时触发的回调函数。\n *\n * @param value - The selected row objects | 选中的行对象\n */\n onChange?: (value: T[]) => void;\n /**\n * - **EN:** The field name or function to get the key of the object. If not set, the `id` or `code`\n * field will be used as the key by default.\n * - **CN:** 获取对象key的字段名或函数,如果不设置,则默认使用 `id` 或 `code` 字段作为key。\n */\n rowKey?: keyof T | ((item: T) => string);\n /**\n * - **EN:** Whether to support table selection. If set to `false`, the table row selection feature\n * will be disabled.\n * - **CN:** 是否支持表格选择,如果设置为`false`,则禁用table的行选择功能。\n *\n * @default true\n */\n checkable?: boolean;\n /**\n * - **EN:** Cache of all selected objects, used to initialize the internal cache.\n *\n * This usage is not very common and is generally used for persistent caching outside the Table,\n * such as saving in localStorage or, in the case of a MicroApp, saving in the main application,\n * so that when the Table is destroyed and re-entered, it can restore all previously selected\n * cached objects (otherwise, data across pages will be lost).\n * - **CN:** 所有被选中对象的缓存,用于初始化内部的缓存对象。\n *\n * 这种用法不太常见,一般用于在Table外进行持久化缓存,例如保存在localStorage中、或作为MicroApp时保存在主应用中,\n * 从而在Table被销毁后再次进入时能恢复之前选中的所有缓存对象(否则跨页的数据会丢失)。\n */\n cache?: T[];\n};\n\n/**\n * - **EN:** Generate the `rowSelection` property settings for the Table component, supporting\n * cross-page selection. The `onChange` callback returns the selected row objects instead of the\n * selected row keys.\n *\n * Use `rowKey` to specify the key of the row object. If not specified, it will try to get the `id`\n * or `code` field from the row object as the key.\n * - **CN:** 生成Table组件的rowSelection属性设置,支持跨页选中,`onChange`返回选中的行对象,而不是选中的行key。\n *\n * 使用 `rowKey` 来指定行对象的key,如果不指定,则会尝试从行对象中获取 `id` 或 `code` 字段作为key。\n */\nfunction useRowSelection<T extends object = Record<string, unknown>>(options?: UseRowSelectionOption<T>) {\n const { value, rowKey, onChange, checkable = true, cache, ...restOptions } = options || {};\n const keys = useMemo(() => value?.map((item) => getKey(item, rowKey)), [value, rowKey]);\n const selectedCacheRef = useRef(new Map(cache?.map((item) => [getKey(item, rowKey), item])));\n\n useEffect(() => {\n // Remove items that no longer exist in selectedCacheRef\n // When the parent component's directory type or domain changes, the value will be reset, and the selectedCacheRef needs to be cleared\n selectedCacheRef.current.forEach((item) => {\n const itemKey = getKey(item, rowKey);\n if (!(value || []).some((v) => getKey(v, rowKey) === itemKey)) {\n selectedCacheRef.current.delete(itemKey);\n }\n });\n }, [rowKey, value]);\n\n return checkable !== false\n ? ({\n ...restOptions,\n preserveSelectedRowKeys: true,\n selectedRowKeys: keys,\n onChange: (selectedKeys, selectedRows) => {\n // Remove the deselected items\n selectedCacheRef.current.forEach((item) => {\n const key = getKey(item, rowKey);\n if (!selectedKeys?.includes(key as Key)) {\n selectedCacheRef.current.delete(key);\n }\n });\n // Add new selected items\n selectedRows?.forEach((item) => {\n const key = getKey(item, rowKey);\n selectedCacheRef.current.set(key, item);\n });\n onChange?.(selectedKeys.map((id) => selectedCacheRef.current.get(id as string)).filter(Boolean) as T[]);\n },\n } as TableRowSelection<T>)\n : undefined;\n}\n\nfunction getKey<T extends object = Record<string, unknown>>(\n item: T,\n keyField?: keyof T | ((item: T) => string)\n): keyof T | string {\n if (!item) {\n return '';\n }\n if (typeof keyField === 'function') {\n return keyField(item);\n }\n return (\n (item[keyField!] as keyof T) ||\n ('id' in item ? (item['id'] as string) : '') ||\n ('code' in item ? (item['code'] as string) : '')\n );\n}\nexport default useRowSelection;\n"],"mappings":";;;;;;;;;AACA,SAASA,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAgDlD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,eAAeA,CAA6CC,OAAkC,EAAE;EACvG,IAAAC,IAAA,GAA6ED,OAAO,IAAI,CAAC,CAAC;IAAlFE,KAAK,GAAAD,IAAA,CAALC,KAAK;IAAEC,MAAM,GAAAF,IAAA,CAANE,MAAM;IAAEC,SAAQ,GAAAH,IAAA,CAARG,QAAQ;IAAAC,cAAA,GAAAJ,IAAA,CAAEK,SAAS;IAATA,SAAS,GAAAD,cAAA,cAAG,IAAI,GAAAA,cAAA;IAAEE,KAAK,GAAAN,IAAA,CAALM,KAAK;IAAKC,WAAW,GAAAC,wBAAA,CAAAR,IAAA,EAAAS,SAAA;EACxE,IAAMC,IAAI,GAAGd,OAAO,CAAC;IAAA,OAAMK,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEU,GAAG,CAAC,UAACC,IAAI;MAAA,OAAKC,MAAM,CAACD,IAAI,EAAEV,MAAM,CAAC;IAAA,EAAC;EAAA,GAAE,CAACD,KAAK,EAAEC,MAAM,CAAC,CAAC;EACvF,IAAMY,gBAAgB,GAAGjB,MAAM,CAAC,IAAIkB,GAAG,CAACT,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEK,GAAG,CAAC,UAACC,IAAI;IAAA,OAAK,CAACC,MAAM,CAACD,IAAI,EAAEV,MAAM,CAAC,EAAEU,IAAI,CAAC;EAAA,EAAC,CAAC,CAAC;EAE5FjB,SAAS,CAAC,YAAM;IACd;IACA;IACAmB,gBAAgB,CAACE,OAAO,CAACC,OAAO,CAAC,UAACL,IAAI,EAAK;MACzC,IAAMM,OAAO,GAAGL,MAAM,CAACD,IAAI,EAAEV,MAAM,CAAC;MACpC,IAAI,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SAAS;AACf;AAEA,SAASrB,MAAMA,CACbD,IAAO,EACPuB,QAA0C,EACxB;EAClB,IAAI,CAACvB,IAAI,EAAE;IACT,OAAO,EAAE;EACX;EACA,IAAI,OAAOuB,QAAQ,KAAK,UAAU,EAAE;IAClC,OAAOA,QAAQ,CAACvB,IAAI,CAAC;EACvB;EACA,OACGA,IAAI,CAACuB,QAAQ,CAAE,KACf,IAAI,IAAIvB,IAAI,GAAIA,IAAI,CAAC,IAAI,CAAC,GAAc,EAAE,CAAC,KAC3C,MAAM,IAAIA,IAAI,GAAIA,IAAI,CAAC,MAAM,CAAC,GAAc,EAAE,CAAC;AAEpD;AACA,eAAed,eAAe"}
|
|
@@ -44,6 +44,10 @@ 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 getEasyPrefixCls = (0, import_react.useCallback)(
|
|
48
|
+
(suffixCls, customizePrefixCls) => getPrefixCls(`easy-${suffixCls}`, customizePrefixCls),
|
|
49
|
+
[getPrefixCls]
|
|
50
|
+
);
|
|
47
51
|
const contextValue = (0, import_react.useMemo)(
|
|
48
52
|
() => {
|
|
49
53
|
if (langInProps !== import_locales.default.language) {
|
|
@@ -51,11 +55,11 @@ var ConfigProvider = (props) => {
|
|
|
51
55
|
}
|
|
52
56
|
return {
|
|
53
57
|
...restProps,
|
|
54
|
-
getPrefixCls:
|
|
58
|
+
getPrefixCls: getEasyPrefixCls
|
|
55
59
|
};
|
|
56
60
|
},
|
|
57
61
|
// eslint-disable-next-line @tiny-codes/react-hooks/exhaustive-deps
|
|
58
|
-
[langInProps,
|
|
62
|
+
[langInProps, getEasyPrefixCls, ...Object.values(restProps)]
|
|
59
63
|
);
|
|
60
64
|
(0, import_react.useEffect)(() => {
|
|
61
65
|
if (userLocales) {
|
|
@@ -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, 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:
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,
|
|
4
|
+
"sourcesContent": ["import type { CSSProperties, FC, ReactNode } from 'react';\nimport { useCallback, 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 getEasyPrefixCls = useCallback(\n (suffixCls: string, customizePrefixCls?: string) => getPrefixCls(`easy-${suffixCls}`, customizePrefixCls),\n [getPrefixCls]\n );\n const contextValue = useMemo(\n () => {\n if (langInProps !== locales.language) {\n locales.changeLanguage(langInProps || 'en-US');\n }\n return {\n ...restProps,\n getPrefixCls: getEasyPrefixCls,\n };\n },\n // eslint-disable-next-line @tiny-codes/react-hooks/exhaustive-deps\n [langInProps, getEasyPrefixCls, ...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,mBAA4D;AAC5D,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;AAC7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ps } from 'antd/es/typography/Text';
|
|
|
4
4
|
import type { TitleProps } from 'antd/es/typography/Title';
|
|
5
5
|
declare function withEllipsisTypography<T extends TextProps | ParagraphProps | TitleProps>(Component: ComponentType<MakeEllipsisTypographyProps<T>>): (props: MakeEllipsisTypographyProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
6
6
|
export type MakeEllipsisTypographyProps<T> = Omit<T, 'children'> & {
|
|
7
|
+
/**
|
|
8
|
+
* - **EN:** The text content to display. If not provided, the children will be used.
|
|
9
|
+
* - **CN:** 要显示的文本内容。如果未提供,将使用子元素。
|
|
10
|
+
*/
|
|
7
11
|
text?: string | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* - **EN:** The children content to display. The `text` prop will take precedence if both are
|
|
14
|
+
* provided.
|
|
15
|
+
* - **CN:** 要显示的子元素内容。如果同时提供了 `text` 属性,将优先使用 `text`。
|
|
16
|
+
*/
|
|
8
17
|
children?: string | undefined | null;
|
|
18
|
+
/**
|
|
19
|
+
* - **EN:** Whether to monitor the component's size and adjust the ellipsis accordingly.
|
|
20
|
+
* - **CN:** 是否监控组件的大小并相应地调整省略号。
|
|
21
|
+
*
|
|
22
|
+
* @default true
|
|
23
|
+
*/
|
|
24
|
+
watchResize?: boolean;
|
|
9
25
|
};
|
|
10
26
|
export default withEllipsisTypography;
|
|
@@ -24,11 +24,14 @@ __export(withEllipsisTypography_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(withEllipsisTypography_exports);
|
|
25
25
|
var import_react = require("react");
|
|
26
26
|
var import_antd = require("antd");
|
|
27
|
+
var import_react_resize_detector = require("react-resize-detector");
|
|
28
|
+
var import_hooks = require("../../hooks");
|
|
27
29
|
function withEllipsisTypography(Component) {
|
|
28
30
|
return function EllipsisText(props) {
|
|
29
|
-
const { ellipsis = true, children, text = children, ...rest } = props;
|
|
31
|
+
const { ellipsis = true, children, text = children, watchResize = true, ...rest } = props;
|
|
30
32
|
const [isEllipsis, setIsEllipsis] = (0, import_react.useState)(false);
|
|
31
33
|
const [dom, setDom] = (0, import_react.useState)(null);
|
|
34
|
+
const domRef = (0, import_hooks.useRefValue)(dom);
|
|
32
35
|
const isAutoEllipsis = (0, import_react.useMemo)(() => ellipsis === true, [ellipsis]);
|
|
33
36
|
const isAutoTooltip = (0, import_react.useMemo)(() => typeof ellipsis === "object" && ellipsis.tooltip === true, [ellipsis]);
|
|
34
37
|
const isAutoTooltipTitle = (0, import_react.useMemo)(
|
|
@@ -40,10 +43,21 @@ function withEllipsisTypography(Component) {
|
|
|
40
43
|
[isAutoEllipsis, isAutoTooltip, isAutoTooltipTitle]
|
|
41
44
|
);
|
|
42
45
|
const tooltipTitle = (0, import_react.useMemo)(() => isEllipsis ? text : void 0, [isEllipsis, text]);
|
|
46
|
+
const detectEllipsis = (0, import_hooks.useRefFunction)(
|
|
47
|
+
() => dom && setIsEllipsis(dom.scrollWidth > dom.clientWidth || dom.scrollHeight > dom.clientHeight)
|
|
48
|
+
);
|
|
49
|
+
(0, import_react_resize_detector.useResizeDetector)({
|
|
50
|
+
targetRef: watchResize ? domRef : void 0,
|
|
51
|
+
onResize: detectEllipsis,
|
|
52
|
+
refreshRate: 10,
|
|
53
|
+
refreshOptions: {
|
|
54
|
+
leading: false
|
|
55
|
+
}
|
|
56
|
+
});
|
|
43
57
|
(0, import_react.useEffect)(() => {
|
|
44
58
|
if (dom && isAuto) {
|
|
45
59
|
Promise.resolve().then(() => {
|
|
46
|
-
|
|
60
|
+
detectEllipsis();
|
|
47
61
|
});
|
|
48
62
|
}
|
|
49
63
|
}, [text, isAuto, dom]);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/EllipsisTypography/withEllipsisTypography.tsx"],
|
|
4
|
-
"sourcesContent": ["import type { ComponentType } from 'react';\nimport { useEffect, useMemo, useState } from 'react';\nimport type { TooltipProps } from 'antd';\nimport { Tooltip } from 'antd';\nimport type { EllipsisConfig } from 'antd/es/typography/Base';\nimport type { ParagraphProps } from 'antd/es/typography/Paragraph';\nimport type { TextProps } from 'antd/es/typography/Text';\nimport type { TitleProps } from 'antd/es/typography/Title';\n\nfunction withEllipsisTypography<T extends TextProps | ParagraphProps | TitleProps>(\n Component: ComponentType<MakeEllipsisTypographyProps<T>>\n) {\n return function EllipsisText(props: MakeEllipsisTypographyProps<T>) {\n const { ellipsis = true, children, text = children, ...rest } = props;\n const [isEllipsis, setIsEllipsis] = useState(false);\n const [dom, setDom] = useState<HTMLElement | null>(null);\n const isAutoEllipsis = useMemo(() => ellipsis === true, [ellipsis]);\n const isAutoTooltip = useMemo(() => typeof ellipsis === 'object' && ellipsis.tooltip === true, [ellipsis]);\n const isAutoTooltipTitle = useMemo(\n () =>\n typeof ellipsis === 'object' &&\n ellipsis.tooltip &&\n typeof ellipsis.tooltip === 'object' &&\n 'title' in ellipsis.tooltip &&\n ellipsis.tooltip.title === true,\n [ellipsis]\n );\n const isAuto = useMemo(\n () => isAutoEllipsis || isAutoTooltip || isAutoTooltipTitle,\n [isAutoEllipsis, isAutoTooltip, isAutoTooltipTitle]\n );\n const tooltipTitle = useMemo(() => (isEllipsis ? text : undefined), [isEllipsis, text]);\n\n useEffect(() => {\n if (dom && isAuto) {\n Promise.resolve().then(() => {\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA6C;AAE7C,kBAAwB;
|
|
4
|
+
"sourcesContent": ["import type { ComponentType } from 'react';\nimport { useEffect, useMemo, useState } from 'react';\nimport type { TooltipProps } from 'antd';\nimport { Tooltip } from 'antd';\nimport type { EllipsisConfig } from 'antd/es/typography/Base';\nimport type { ParagraphProps } from 'antd/es/typography/Paragraph';\nimport type { TextProps } from 'antd/es/typography/Text';\nimport type { TitleProps } from 'antd/es/typography/Title';\nimport { useResizeDetector } from 'react-resize-detector';\nimport { useRefFunction, useRefValue } from '../../hooks';\n\nfunction withEllipsisTypography<T extends TextProps | ParagraphProps | TitleProps>(\n Component: ComponentType<MakeEllipsisTypographyProps<T>>\n) {\n return function EllipsisText(props: MakeEllipsisTypographyProps<T>) {\n const { ellipsis = true, children, text = children, watchResize = true, ...rest } = props;\n const [isEllipsis, setIsEllipsis] = useState(false);\n const [dom, setDom] = useState<HTMLElement | null>(null);\n const domRef = useRefValue(dom);\n const isAutoEllipsis = useMemo(() => ellipsis === true, [ellipsis]);\n const isAutoTooltip = useMemo(() => typeof ellipsis === 'object' && ellipsis.tooltip === true, [ellipsis]);\n const isAutoTooltipTitle = useMemo(\n () =>\n typeof ellipsis === 'object' &&\n ellipsis.tooltip &&\n typeof ellipsis.tooltip === 'object' &&\n 'title' in ellipsis.tooltip &&\n ellipsis.tooltip.title === true,\n [ellipsis]\n );\n const isAuto = useMemo(\n () => isAutoEllipsis || isAutoTooltip || isAutoTooltipTitle,\n [isAutoEllipsis, isAutoTooltip, isAutoTooltipTitle]\n );\n const tooltipTitle = useMemo(() => (isEllipsis ? text : undefined), [isEllipsis, text]);\n\n const detectEllipsis = useRefFunction(\n () => dom && setIsEllipsis(dom.scrollWidth > dom.clientWidth || dom.scrollHeight > dom.clientHeight)\n );\n useResizeDetector({\n targetRef: watchResize ? domRef : undefined,\n onResize: detectEllipsis,\n refreshRate: 10,\n refreshOptions: {\n leading: false,\n },\n });\n\n useEffect(() => {\n if (dom && isAuto) {\n Promise.resolve().then(() => {\n detectEllipsis();\n });\n }\n }, [text, isAuto, dom]);\n\n return (\n <Tooltip {...((ellipsis as EllipsisConfig)?.tooltip as TooltipProps)} title={tooltipTitle}>\n <Component\n ref={setDom}\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n {...(rest as any)}\n ellipsis={\n isAutoEllipsis\n ? { tooltip: undefined }\n : isAutoTooltip\n ? {\n ...(ellipsis as EllipsisConfig),\n tooltip: undefined,\n }\n : isAutoTooltipTitle\n ? {\n ...(ellipsis as EllipsisConfig),\n tooltip: {\n ...((ellipsis as EllipsisConfig)?.tooltip as TooltipProps),\n title: undefined,\n },\n }\n : ellipsis\n }\n >\n {text}\n </Component>\n </Tooltip>\n );\n };\n}\n\nexport type MakeEllipsisTypographyProps<T> = Omit<T, 'children'> & {\n /**\n * - **EN:** The text content to display. If not provided, the children will be used.\n * - **CN:** 要显示的文本内容。如果未提供,将使用子元素。\n */\n text?: string | undefined;\n /**\n * - **EN:** The children content to display. The `text` prop will take precedence if both are\n * provided.\n * - **CN:** 要显示的子元素内容。如果同时提供了 `text` 属性,将优先使用 `text`。\n */\n children?: string | undefined | null;\n /**\n * - **EN:** Whether to monitor the component's size and adjust the ellipsis accordingly.\n * - **CN:** 是否监控组件的大小并相应地调整省略号。\n *\n * @default true\n */\n watchResize?: boolean;\n};\n\nexport default withEllipsisTypography;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA6C;AAE7C,kBAAwB;AAKxB,mCAAkC;AAClC,mBAA4C;AAE5C,SAAS,uBACP,WACA;AACA,SAAO,SAAS,aAAa,OAAuC;AAClE,UAAM,EAAE,WAAW,MAAM,UAAU,OAAO,UAAU,cAAc,MAAM,GAAG,KAAK,IAAI;AACpF,UAAM,CAAC,YAAY,aAAa,QAAI,uBAAS,KAAK;AAClD,UAAM,CAAC,KAAK,MAAM,QAAI,uBAA6B,IAAI;AACvD,UAAM,aAAS,0BAAY,GAAG;AAC9B,UAAM,qBAAiB,sBAAQ,MAAM,aAAa,MAAM,CAAC,QAAQ,CAAC;AAClE,UAAM,oBAAgB,sBAAQ,MAAM,OAAO,aAAa,YAAY,SAAS,YAAY,MAAM,CAAC,QAAQ,CAAC;AACzG,UAAM,yBAAqB;AAAA,MACzB,MACE,OAAO,aAAa,YACpB,SAAS,WACT,OAAO,SAAS,YAAY,YAC5B,WAAW,SAAS,WACpB,SAAS,QAAQ,UAAU;AAAA,MAC7B,CAAC,QAAQ;AAAA,IACX;AACA,UAAM,aAAS;AAAA,MACb,MAAM,kBAAkB,iBAAiB;AAAA,MACzC,CAAC,gBAAgB,eAAe,kBAAkB;AAAA,IACpD;AACA,UAAM,mBAAe,sBAAQ,MAAO,aAAa,OAAO,QAAY,CAAC,YAAY,IAAI,CAAC;AAEtF,UAAM,qBAAiB;AAAA,MACrB,MAAM,OAAO,cAAc,IAAI,cAAc,IAAI,eAAe,IAAI,eAAe,IAAI,YAAY;AAAA,IACrG;AACA,wDAAkB;AAAA,MAChB,WAAW,cAAc,SAAS;AAAA,MAClC,UAAU;AAAA,MACV,aAAa;AAAA,MACb,gBAAgB;AAAA,QACd,SAAS;AAAA,MACX;AAAA,IACF,CAAC;AAED,gCAAU,MAAM;AACd,UAAI,OAAO,QAAQ;AACjB,gBAAQ,QAAQ,EAAE,KAAK,MAAM;AAC3B,yBAAe;AAAA,QACjB,CAAC;AAAA,MACH;AAAA,IACF,GAAG,CAAC,MAAM,QAAQ,GAAG,CAAC;AAEtB,WACE,oCAAC,uBAAS,GAAK,qCAA6B,SAA0B,OAAO,gBAC3E;AAAA,MAAC;AAAA;AAAA,QACC,KAAK;AAAA,QAEJ,GAAI;AAAA,QACL,UACE,iBACI,EAAE,SAAS,OAAU,IACrB,gBACE;AAAA,UACE,GAAI;AAAA,UACJ,SAAS;AAAA,QACX,IACA,qBACE;AAAA,UACE,GAAI;AAAA,UACJ,SAAS;AAAA,YACP,GAAK,qCAA6B;AAAA,YAClC,OAAO;AAAA,UACT;AAAA,QACF,IACA;AAAA;AAAA,MAGT;AAAA,IACH,CACF;AAAA,EAEJ;AACF;AAuBA,IAAO,iCAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -4,12 +4,26 @@ import type { IconFontProps as AntIconFontProps } from '@ant-design/icons/es/com
|
|
|
4
4
|
* - **EN:** Props for the Iconfont component
|
|
5
5
|
* - **CN:** Iconfont 组件的props
|
|
6
6
|
*/
|
|
7
|
-
export interface IconfontProps<T extends string = string> extends Omit<AntIconFontProps<T>, 'type' | 'size'> {
|
|
7
|
+
export interface IconfontProps<T extends string = string> extends Omit<AntIconFontProps<T>, 'type' | 'size' | 'spin' | 'rotate'> {
|
|
8
8
|
/**
|
|
9
9
|
* - **EN:** Icon name. Find an icon in iconfont and click `Copy Code`
|
|
10
10
|
* - **CN:** 图标名称。在 iconfont 中找到某个图标,点击`复制代码`
|
|
11
11
|
*/
|
|
12
12
|
type: T;
|
|
13
|
+
/**
|
|
14
|
+
* - **EN:** Whether the icon should spin continuously, can be used to indicate loading
|
|
15
|
+
* - **CN:** 图标是否持续旋转,可以实现 loading 的效果
|
|
16
|
+
*
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
spin?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* - **EN:** Rotate the icon by a fixed angle clockwise
|
|
22
|
+
* - **CN:** 图标顺时针旋转一个固定角度
|
|
23
|
+
*
|
|
24
|
+
* @default 0
|
|
25
|
+
*/
|
|
26
|
+
rotate?: number;
|
|
13
27
|
/**
|
|
14
28
|
* - **EN:** Icon size, an alias for `style.fontSize`
|
|
15
29
|
* - **CN:** 图标尺寸,是 `style.fontSize` 的别名
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/Iconfont/createIconfont.tsx"],
|
|
4
|
-
"sourcesContent": ["import { type CSSProperties, type FC, useContext } from 'react';\nimport classNames from 'classnames';\nimport { createFromIconfontCN } from '@ant-design/icons';\nimport type { IconFontProps as AntIconFontProps } from '@ant-design/icons/es/components/IconFont';\nimport ConfigProvider from '../ConfigProvider';\n\n/**\n * - **EN:** Props for the Iconfont component\n * - **CN:** Iconfont 组件的props\n */\nexport interface IconfontProps<T extends string = string
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwD;AACxD,wBAAuB;AACvB,mBAAqC;AAErC,4BAA2B;
|
|
4
|
+
"sourcesContent": ["import { type CSSProperties, type FC, useContext } from 'react';\nimport classNames from 'classnames';\nimport { createFromIconfontCN } from '@ant-design/icons';\nimport type { IconFontProps as AntIconFontProps } from '@ant-design/icons/es/components/IconFont';\nimport ConfigProvider from '../ConfigProvider';\n\n/**\n * - **EN:** Props for the Iconfont component\n * - **CN:** Iconfont 组件的props\n */\nexport interface IconfontProps<T extends string = string>\n extends Omit<AntIconFontProps<T>, 'type' | 'size' | 'spin' | 'rotate'> {\n /**\n * - **EN:** Icon name. Find an icon in iconfont and click `Copy Code`\n * - **CN:** 图标名称。在 iconfont 中找到某个图标,点击`复制代码`\n */\n type: T;\n /**\n * - **EN:** Whether the icon should spin continuously, can be used to indicate loading\n * - **CN:** 图标是否持续旋转,可以实现 loading 的效果\n *\n * @default false\n */\n spin?: boolean;\n /**\n * - **EN:** Rotate the icon by a fixed angle clockwise\n * - **CN:** 图标顺时针旋转一个固定角度\n *\n * @default 0\n */\n rotate?: number;\n /**\n * - **EN:** Icon size, an alias for `style.fontSize`\n * - **CN:** 图标尺寸,是 `style.fontSize` 的别名\n */\n size?: CSSProperties['fontSize'];\n}\n\n/**\n * - **EN:** Create an Iconfont component with a specified iconfont script URL.\n * - **CN:** 创建一个Iconfont组件,指定iconfont的脚本地址\n *\n * @param scriptUrl - Path to the iconfont script | 字体图标的路径\n */\nexport const createIconfont = <T extends string = string>(\n scriptUrl: string,\n options?: {\n /** Icon name prefix | 图标名称前缀 */\n iconPrefix?: string;\n }\n): FC<IconfontProps<T>> => {\n const { iconPrefix = '' } = options || {};\n const AntdIconfont = createFromIconfontCN({ scriptUrl });\n /**\n * - **EN:** Render an iconfont icon, setting the `type` prop to the iconfont icon name.\n * - **CN:** 渲染一个 iconfont 的图标,把 `type` 属性设置为 iconfont 字体的图标名\n */\n const Iconfont: FC<IconfontProps<T>> = (props) => {\n const { type, className, size, style, ...iconProps } = props;\n const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);\n const iconType = type.startsWith(iconPrefix) ? type : `${iconPrefix}-${type}`;\n\n return (\n <AntdIconfont\n type={iconType}\n className={classNames(getPrefixCls('iconfont'), className)}\n style={{\n ...style,\n fontSize: style?.fontSize ?? size,\n }}\n {...iconProps}\n />\n );\n };\n return Iconfont;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwD;AACxD,wBAAuB;AACvB,mBAAqC;AAErC,4BAA2B;AAwCpB,IAAM,iBAAiB,CAC5B,WACA,YAIyB;AACzB,QAAM,EAAE,aAAa,GAAG,IAAI,WAAW,CAAC;AACxC,QAAM,mBAAe,mCAAqB,EAAE,UAAU,CAAC;AAKvD,QAAM,WAAiC,CAAC,UAAU;AAChD,UAAM,EAAE,MAAM,WAAW,MAAM,OAAO,GAAG,UAAU,IAAI;AACvD,UAAM,EAAE,aAAa,QAAI,yBAAW,sBAAAA,QAAe,aAAa;AAChE,UAAM,WAAW,KAAK,WAAW,UAAU,IAAI,OAAO,GAAG,cAAc;AAEvE,WACE;AAAA,MAAC;AAAA;AAAA,QACC,MAAM;AAAA,QACN,eAAW,kBAAAC,SAAW,aAAa,UAAU,GAAG,SAAS;AAAA,QACzD,OAAO;AAAA,UACL,GAAG;AAAA,UACH,WAAU,+BAAO,aAAY;AAAA,QAC/B;AAAA,QACC,GAAG;AAAA;AAAA,IACN;AAAA,EAEJ;AACA,SAAO;AACT;",
|
|
6
6
|
"names": ["ConfigProvider", "classNames"]
|
|
7
7
|
}
|
package/lib/hooks/index.d.ts
CHANGED
|
@@ -6,8 +6,10 @@ export * from './useMovable';
|
|
|
6
6
|
export { default as useMovable } from './useMovable';
|
|
7
7
|
export * from './useProcessingText';
|
|
8
8
|
export { default as useProcessingText } from './useProcessingText';
|
|
9
|
-
export { default as useRefValue } from './useRefValue';
|
|
10
9
|
export { default as useRefFunction } from './useRefFunction';
|
|
10
|
+
export { default as useRefValue } from './useRefValue';
|
|
11
|
+
export * from './useRowSelection';
|
|
12
|
+
export { default as useRowSelection } from './useRowSelection';
|
|
11
13
|
export * from './useSplitter';
|
|
12
14
|
export { default as useSplitter } from './useSplitter';
|
|
13
15
|
export * from './useSSE';
|
package/lib/hooks/index.js
CHANGED
|
@@ -37,6 +37,7 @@ __export(hooks_exports, {
|
|
|
37
37
|
useProcessingText: () => import_useProcessingText.default,
|
|
38
38
|
useRefFunction: () => import_useRefFunction.default,
|
|
39
39
|
useRefValue: () => import_useRefValue.default,
|
|
40
|
+
useRowSelection: () => import_useRowSelection.default,
|
|
40
41
|
useSSE: () => import_useSSE.default,
|
|
41
42
|
useSplitter: () => import_useSplitter.default,
|
|
42
43
|
useStompSocket: () => import_useStompSocket.default,
|
|
@@ -54,8 +55,10 @@ __reExport(hooks_exports, require("./useMovable"), module.exports);
|
|
|
54
55
|
var import_useMovable = __toESM(require("./useMovable"));
|
|
55
56
|
__reExport(hooks_exports, require("./useProcessingText"), module.exports);
|
|
56
57
|
var import_useProcessingText = __toESM(require("./useProcessingText"));
|
|
57
|
-
var import_useRefValue = __toESM(require("./useRefValue"));
|
|
58
58
|
var import_useRefFunction = __toESM(require("./useRefFunction"));
|
|
59
|
+
var import_useRefValue = __toESM(require("./useRefValue"));
|
|
60
|
+
__reExport(hooks_exports, require("./useRowSelection"), module.exports);
|
|
61
|
+
var import_useRowSelection = __toESM(require("./useRowSelection"));
|
|
59
62
|
__reExport(hooks_exports, require("./useSplitter"), module.exports);
|
|
60
63
|
var import_useSplitter = __toESM(require("./useSplitter"));
|
|
61
64
|
__reExport(hooks_exports, require("./useSSE"), module.exports);
|
|
@@ -76,6 +79,7 @@ var import_useValidatorBuilder = __toESM(require("./useValidatorBuilder"));
|
|
|
76
79
|
useProcessingText,
|
|
77
80
|
useRefFunction,
|
|
78
81
|
useRefValue,
|
|
82
|
+
useRowSelection,
|
|
79
83
|
useSSE,
|
|
80
84
|
useSplitter,
|
|
81
85
|
useStompSocket,
|
|
@@ -86,6 +90,7 @@ var import_useValidatorBuilder = __toESM(require("./useValidatorBuilder"));
|
|
|
86
90
|
...require("./useLocalStorage"),
|
|
87
91
|
...require("./useMovable"),
|
|
88
92
|
...require("./useProcessingText"),
|
|
93
|
+
...require("./useRowSelection"),
|
|
89
94
|
...require("./useSplitter"),
|
|
90
95
|
...require("./useSSE"),
|
|
91
96
|
...require("./useStompSocket"),
|
package/lib/hooks/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/index.ts"],
|
|
4
|
-
"sourcesContent": ["export { default as useAudioPlayer } from './useAudioPlayer';\n\nexport { default as useDebounce } from './useDebounce';\n\nexport * from './useLocalStorage';\nexport { default as useLocalStorage } from './useLocalStorage';\n\nexport * from './useMovable';\nexport { default as useMovable } from './useMovable';\n\nexport * from './useProcessingText';\nexport { default as useProcessingText } from './useProcessingText';\n\nexport { default as useRefValue } from './useRefValue';\n\nexport { default as
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA0C;AAE1C,yBAAuC;AAEvC,0BAAc,8BAJd;AAKA,6BAA2C;AAE3C,0BAAc,yBAPd;AAQA,wBAAsC;AAEtC,0BAAc,gCAVd;AAWA,+BAA6C;AAE7C,yBAAuC;AAEvC,
|
|
4
|
+
"sourcesContent": ["export { default as useAudioPlayer } from './useAudioPlayer';\n\nexport { default as useDebounce } from './useDebounce';\n\nexport * from './useLocalStorage';\nexport { default as useLocalStorage } from './useLocalStorage';\n\nexport * from './useMovable';\nexport { default as useMovable } from './useMovable';\n\nexport * from './useProcessingText';\nexport { default as useProcessingText } from './useProcessingText';\n\nexport { default as useRefFunction } from './useRefFunction';\n\nexport { default as useRefValue } from './useRefValue';\n\nexport * from './useRowSelection';\nexport { default as useRowSelection } from './useRowSelection';\n\nexport * from './useSplitter';\nexport { default as useSplitter } from './useSplitter';\n\nexport * from './useSSE';\nexport { default as useSSE } from './useSSE';\n\nexport * from './useStompSocket';\nexport { default as useStompSocket } from './useStompSocket';\n\nexport * from './useUserMedia';\nexport { default as useUserMedia } from './useUserMedia';\n\nexport type { ValidatorRuleMap } from './useValidators';\nexport { default as useValidators } from './useValidators';\n\nexport { default as useValidator } from './useValidator';\n\nexport type { Validator, RuleRegExpFlags, ValidatorRule, BuilderOptions } from './useValidatorBuilder';\nexport { default as useValidatorBuilder } from './useValidatorBuilder';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA0C;AAE1C,yBAAuC;AAEvC,0BAAc,8BAJd;AAKA,6BAA2C;AAE3C,0BAAc,yBAPd;AAQA,wBAAsC;AAEtC,0BAAc,gCAVd;AAWA,+BAA6C;AAE7C,4BAA0C;AAE1C,yBAAuC;AAEvC,0BAAc,8BAjBd;AAkBA,6BAA2C;AAE3C,0BAAc,0BApBd;AAqBA,yBAAuC;AAEvC,0BAAc,qBAvBd;AAwBA,oBAAkC;AAElC,0BAAc,6BA1Bd;AA2BA,4BAA0C;AAE1C,0BAAc,2BA7Bd;AA8BA,0BAAwC;AAGxC,2BAAyC;AAEzC,0BAAwC;AAGxC,iCAA+C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { TableRowSelection } from 'antd/es/table/interface';
|
|
2
|
+
export type UseRowSelectionOption<T extends object = Record<string, unknown>> = Omit<TableRowSelection<T>, 'preserveSelectedRowKeys' | 'selectedRowKeys' | 'onChange'> & {
|
|
3
|
+
/**
|
|
4
|
+
* - **EN:** The selected row objects.
|
|
5
|
+
* - **CN:** 选中的行对象。
|
|
6
|
+
*/
|
|
7
|
+
value?: T[];
|
|
8
|
+
/**
|
|
9
|
+
* - **EN:** Callback function triggered when the selected rows change.
|
|
10
|
+
* - **CN:** 当选中的行发生变化时触发的回调函数。
|
|
11
|
+
*
|
|
12
|
+
* @param value - The selected row objects | 选中的行对象
|
|
13
|
+
*/
|
|
14
|
+
onChange?: (value: T[]) => void;
|
|
15
|
+
/**
|
|
16
|
+
* - **EN:** The field name or function to get the key of the object. If not set, the `id` or `code`
|
|
17
|
+
* field will be used as the key by default.
|
|
18
|
+
* - **CN:** 获取对象key的字段名或函数,如果不设置,则默认使用 `id` 或 `code` 字段作为key。
|
|
19
|
+
*/
|
|
20
|
+
rowKey?: keyof T | ((item: T) => string);
|
|
21
|
+
/**
|
|
22
|
+
* - **EN:** Whether to support table selection. If set to `false`, the table row selection feature
|
|
23
|
+
* will be disabled.
|
|
24
|
+
* - **CN:** 是否支持表格选择,如果设置为`false`,则禁用table的行选择功能。
|
|
25
|
+
*
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
28
|
+
checkable?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* - **EN:** Cache of all selected objects, used to initialize the internal cache.
|
|
31
|
+
*
|
|
32
|
+
* This usage is not very common and is generally used for persistent caching outside the Table,
|
|
33
|
+
* such as saving in localStorage or, in the case of a MicroApp, saving in the main application,
|
|
34
|
+
* so that when the Table is destroyed and re-entered, it can restore all previously selected
|
|
35
|
+
* cached objects (otherwise, data across pages will be lost).
|
|
36
|
+
* - **CN:** 所有被选中对象的缓存,用于初始化内部的缓存对象。
|
|
37
|
+
*
|
|
38
|
+
* 这种用法不太常见,一般用于在Table外进行持久化缓存,例如保存在localStorage中、或作为MicroApp时保存在主应用中,
|
|
39
|
+
* 从而在Table被销毁后再次进入时能恢复之前选中的所有缓存对象(否则跨页的数据会丢失)。
|
|
40
|
+
*/
|
|
41
|
+
cache?: T[];
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* - **EN:** Generate the `rowSelection` property settings for the Table component, supporting
|
|
45
|
+
* cross-page selection. The `onChange` callback returns the selected row objects instead of the
|
|
46
|
+
* selected row keys.
|
|
47
|
+
*
|
|
48
|
+
* Use `rowKey` to specify the key of the row object. If not specified, it will try to get the `id`
|
|
49
|
+
* or `code` field from the row object as the key.
|
|
50
|
+
* - **CN:** 生成Table组件的rowSelection属性设置,支持跨页选中,`onChange`返回选中的行对象,而不是选中的行key。
|
|
51
|
+
*
|
|
52
|
+
* 使用 `rowKey` 来指定行对象的key,如果不指定,则会尝试从行对象中获取 `id` 或 `code` 字段作为key。
|
|
53
|
+
*/
|
|
54
|
+
declare function useRowSelection<T extends object = Record<string, unknown>>(options?: UseRowSelectionOption<T>): TableRowSelection<T> | undefined;
|
|
55
|
+
export default useRowSelection;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/hooks/useRowSelection.ts
|
|
20
|
+
var useRowSelection_exports = {};
|
|
21
|
+
__export(useRowSelection_exports, {
|
|
22
|
+
default: () => useRowSelection_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(useRowSelection_exports);
|
|
25
|
+
var import_react = require("react");
|
|
26
|
+
function useRowSelection(options) {
|
|
27
|
+
const { value, rowKey, onChange, checkable = true, cache, ...restOptions } = options || {};
|
|
28
|
+
const keys = (0, import_react.useMemo)(() => value == null ? void 0 : value.map((item) => getKey(item, rowKey)), [value, rowKey]);
|
|
29
|
+
const selectedCacheRef = (0, import_react.useRef)(new Map(cache == null ? void 0 : cache.map((item) => [getKey(item, rowKey), item])));
|
|
30
|
+
(0, import_react.useEffect)(() => {
|
|
31
|
+
selectedCacheRef.current.forEach((item) => {
|
|
32
|
+
const itemKey = getKey(item, rowKey);
|
|
33
|
+
if (!(value || []).some((v) => getKey(v, rowKey) === itemKey)) {
|
|
34
|
+
selectedCacheRef.current.delete(itemKey);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}, [rowKey, value]);
|
|
38
|
+
return checkable !== false ? {
|
|
39
|
+
...restOptions,
|
|
40
|
+
preserveSelectedRowKeys: true,
|
|
41
|
+
selectedRowKeys: keys,
|
|
42
|
+
onChange: (selectedKeys, selectedRows) => {
|
|
43
|
+
selectedCacheRef.current.forEach((item) => {
|
|
44
|
+
const key = getKey(item, rowKey);
|
|
45
|
+
if (!(selectedKeys == null ? void 0 : selectedKeys.includes(key))) {
|
|
46
|
+
selectedCacheRef.current.delete(key);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
selectedRows == null ? void 0 : selectedRows.forEach((item) => {
|
|
50
|
+
const key = getKey(item, rowKey);
|
|
51
|
+
selectedCacheRef.current.set(key, item);
|
|
52
|
+
});
|
|
53
|
+
onChange == null ? void 0 : onChange(selectedKeys.map((id) => selectedCacheRef.current.get(id)).filter(Boolean));
|
|
54
|
+
}
|
|
55
|
+
} : void 0;
|
|
56
|
+
}
|
|
57
|
+
function getKey(item, keyField) {
|
|
58
|
+
if (!item) {
|
|
59
|
+
return "";
|
|
60
|
+
}
|
|
61
|
+
if (typeof keyField === "function") {
|
|
62
|
+
return keyField(item);
|
|
63
|
+
}
|
|
64
|
+
return item[keyField] || ("id" in item ? item["id"] : "") || ("code" in item ? item["code"] : "");
|
|
65
|
+
}
|
|
66
|
+
var useRowSelection_default = useRowSelection;
|
|
67
|
+
//# sourceMappingURL=useRowSelection.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/hooks/useRowSelection.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Key } from 'react';\nimport { useEffect, useMemo, useRef } from 'react';\nimport type { TableRowSelection } from 'antd/es/table/interface';\n\nexport type UseRowSelectionOption<T extends object = Record<string, unknown>> = Omit<\n TableRowSelection<T>,\n 'preserveSelectedRowKeys' | 'selectedRowKeys' | 'onChange'\n> & {\n /**\n * - **EN:** The selected row objects.\n * - **CN:** 选中的行对象。\n */\n value?: T[];\n /**\n * - **EN:** Callback function triggered when the selected rows change.\n * - **CN:** 当选中的行发生变化时触发的回调函数。\n *\n * @param value - The selected row objects | 选中的行对象\n */\n onChange?: (value: T[]) => void;\n /**\n * - **EN:** The field name or function to get the key of the object. If not set, the `id` or `code`\n * field will be used as the key by default.\n * - **CN:** 获取对象key的字段名或函数,如果不设置,则默认使用 `id` 或 `code` 字段作为key。\n */\n rowKey?: keyof T | ((item: T) => string);\n /**\n * - **EN:** Whether to support table selection. If set to `false`, the table row selection feature\n * will be disabled.\n * - **CN:** 是否支持表格选择,如果设置为`false`,则禁用table的行选择功能。\n *\n * @default true\n */\n checkable?: boolean;\n /**\n * - **EN:** Cache of all selected objects, used to initialize the internal cache.\n *\n * This usage is not very common and is generally used for persistent caching outside the Table,\n * such as saving in localStorage or, in the case of a MicroApp, saving in the main application,\n * so that when the Table is destroyed and re-entered, it can restore all previously selected\n * cached objects (otherwise, data across pages will be lost).\n * - **CN:** 所有被选中对象的缓存,用于初始化内部的缓存对象。\n *\n * 这种用法不太常见,一般用于在Table外进行持久化缓存,例如保存在localStorage中、或作为MicroApp时保存在主应用中,\n * 从而在Table被销毁后再次进入时能恢复之前选中的所有缓存对象(否则跨页的数据会丢失)。\n */\n cache?: T[];\n};\n\n/**\n * - **EN:** Generate the `rowSelection` property settings for the Table component, supporting\n * cross-page selection. The `onChange` callback returns the selected row objects instead of the\n * selected row keys.\n *\n * Use `rowKey` to specify the key of the row object. If not specified, it will try to get the `id`\n * or `code` field from the row object as the key.\n * - **CN:** 生成Table组件的rowSelection属性设置,支持跨页选中,`onChange`返回选中的行对象,而不是选中的行key。\n *\n * 使用 `rowKey` 来指定行对象的key,如果不指定,则会尝试从行对象中获取 `id` 或 `code` 字段作为key。\n */\nfunction useRowSelection<T extends object = Record<string, unknown>>(options?: UseRowSelectionOption<T>) {\n const { value, rowKey, onChange, checkable = true, cache, ...restOptions } = options || {};\n const keys = useMemo(() => value?.map((item) => getKey(item, rowKey)), [value, rowKey]);\n const selectedCacheRef = useRef(new Map(cache?.map((item) => [getKey(item, rowKey), item])));\n\n useEffect(() => {\n // Remove items that no longer exist in selectedCacheRef\n // When the parent component's directory type or domain changes, the value will be reset, and the selectedCacheRef needs to be cleared\n selectedCacheRef.current.forEach((item) => {\n const itemKey = getKey(item, rowKey);\n if (!(value || []).some((v) => getKey(v, rowKey) === itemKey)) {\n selectedCacheRef.current.delete(itemKey);\n }\n });\n }, [rowKey, value]);\n\n return checkable !== false\n ? ({\n ...restOptions,\n preserveSelectedRowKeys: true,\n selectedRowKeys: keys,\n onChange: (selectedKeys, selectedRows) => {\n // Remove the deselected items\n selectedCacheRef.current.forEach((item) => {\n const key = getKey(item, rowKey);\n if (!selectedKeys?.includes(key as Key)) {\n selectedCacheRef.current.delete(key);\n }\n });\n // Add new selected items\n selectedRows?.forEach((item) => {\n const key = getKey(item, rowKey);\n selectedCacheRef.current.set(key, item);\n });\n onChange?.(selectedKeys.map((id) => selectedCacheRef.current.get(id as string)).filter(Boolean) as T[]);\n },\n } as TableRowSelection<T>)\n : undefined;\n}\n\nfunction getKey<T extends object = Record<string, unknown>>(\n item: T,\n keyField?: keyof T | ((item: T) => string)\n): keyof T | string {\n if (!item) {\n return '';\n }\n if (typeof keyField === 'function') {\n return keyField(item);\n }\n return (\n (item[keyField!] as keyof T) ||\n ('id' in item ? (item['id'] as string) : '') ||\n ('code' in item ? (item['code'] as string) : '')\n );\n}\nexport default useRowSelection;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA2C;AA2D3C,SAAS,gBAA4D,SAAoC;AACvG,QAAM,EAAE,OAAO,QAAQ,UAAU,YAAY,MAAM,OAAO,GAAG,YAAY,IAAI,WAAW,CAAC;AACzF,QAAM,WAAO,sBAAQ,MAAM,+BAAO,IAAI,CAAC,SAAS,OAAO,MAAM,MAAM,IAAI,CAAC,OAAO,MAAM,CAAC;AACtF,QAAM,uBAAmB,qBAAO,IAAI,IAAI,+BAAO,IAAI,CAAC,SAAS,CAAC,OAAO,MAAM,MAAM,GAAG,IAAI,EAAE,CAAC;AAE3F,8BAAU,MAAM;AAGd,qBAAiB,QAAQ,QAAQ,CAAC,SAAS;AACzC,YAAM,UAAU,OAAO,MAAM,MAAM;AACnC,UAAI,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,MAAM,OAAO,GAAG,MAAM,MAAM,OAAO,GAAG;AAC7D,yBAAiB,QAAQ,OAAO,OAAO;AAAA,MACzC;AAAA,IACF,CAAC;AAAA,EACH,GAAG,CAAC,QAAQ,KAAK,CAAC;AAElB,SAAO,cAAc,QAChB;AAAA,IACC,GAAG;AAAA,IACH,yBAAyB;AAAA,IACzB,iBAAiB;AAAA,IACjB,UAAU,CAAC,cAAc,iBAAiB;AAExC,uBAAiB,QAAQ,QAAQ,CAAC,SAAS;AACzC,cAAM,MAAM,OAAO,MAAM,MAAM;AAC/B,YAAI,EAAC,6CAAc,SAAS,OAAa;AACvC,2BAAiB,QAAQ,OAAO,GAAG;AAAA,QACrC;AAAA,MACF,CAAC;AAED,mDAAc,QAAQ,CAAC,SAAS;AAC9B,cAAM,MAAM,OAAO,MAAM,MAAM;AAC/B,yBAAiB,QAAQ,IAAI,KAAK,IAAI;AAAA,MACxC;AACA,2CAAW,aAAa,IAAI,CAAC,OAAO,iBAAiB,QAAQ,IAAI,EAAY,CAAC,EAAE,OAAO,OAAO;AAAA,IAChG;AAAA,EACF,IACA;AACN;AAEA,SAAS,OACP,MACA,UACkB;AAClB,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AACA,MAAI,OAAO,aAAa,YAAY;AAClC,WAAO,SAAS,IAAI;AAAA,EACtB;AACA,SACG,KAAK,QAAS,MACd,QAAQ,OAAQ,KAAK,IAAI,IAAe,QACxC,UAAU,OAAQ,KAAK,MAAM,IAAe;AAEjD;AACA,IAAO,0BAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiny-codes/react-easy",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.9",
|
|
4
4
|
"description": "Simplify React and AntDesign development with practical components and hooks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"crypto-js": "^4.2.0",
|
|
47
47
|
"lexical": "^0.33.1",
|
|
48
48
|
"react-contexify": "^6.0.0",
|
|
49
|
+
"react-resize-detector": "^12.3.0",
|
|
49
50
|
"sockjs-client": "^1.6.1"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|