@tiny-codes/react-easy 1.7.6 → 1.7.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -1
- package/es/components/ColumnSetting/index.js +2 -1
- package/es/components/ColumnSetting/index.js.map +1 -1
- package/es/components/ConfigProvider/context.d.ts +36 -0
- package/es/components/ConfigProvider/context.js +1 -0
- package/es/components/ConfigProvider/context.js.map +1 -1
- package/es/components/ConfigProvider/index.d.ts +5 -3
- package/es/components/ConfigProvider/index.js +13 -7
- 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.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/index.js +3 -2
- package/es/components/EditableText/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/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 +42 -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.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/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/useSplitter.d.ts +52 -9
- package/es/hooks/useSplitter.js +69 -39
- package/es/hooks/useSplitter.js.map +1 -1
- package/lib/components/ColumnSetting/index.js +2 -1
- package/lib/components/ColumnSetting/index.js.map +3 -3
- package/lib/components/ConfigProvider/context.d.ts +36 -0
- package/lib/components/ConfigProvider/context.js +1 -0
- package/lib/components/ConfigProvider/context.js.map +2 -2
- package/lib/components/ConfigProvider/index.d.ts +5 -3
- package/lib/components/ConfigProvider/index.js +10 -2
- 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.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/index.js +3 -2
- package/lib/components/EditableText/index.js.map +3 -3
- 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/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 +42 -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.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/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/useSplitter.d.ts +52 -9
- package/lib/hooks/useSplitter.js +56 -26
- package/lib/hooks/useSplitter.js.map +3 -3
- package/package.json +2 -1
package/es/hooks/useSplitter.js
CHANGED
|
@@ -10,13 +10,15 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
10
10
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
11
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
12
12
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
-
import { useEffect, useState } from 'react';
|
|
14
|
-
import
|
|
13
|
+
import { useContext, useEffect, useState } from 'react';
|
|
14
|
+
import names from 'classnames';
|
|
15
|
+
import { ConfigProvider } from "../components";
|
|
16
|
+
import useStyle from "./style/useSplitter";
|
|
15
17
|
import useRefValue from "./useRefValue";
|
|
16
18
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
19
|
var useSplitter = function useSplitter(props) {
|
|
18
20
|
var _ref = props || {},
|
|
19
|
-
|
|
21
|
+
containerFromProps = _ref.container,
|
|
20
22
|
defaultRatio = _ref.defaultRatio,
|
|
21
23
|
_ref$minRatio = _ref.minRatio,
|
|
22
24
|
minRatio = _ref$minRatio === void 0 ? 0.15 : _ref$minRatio,
|
|
@@ -25,31 +27,50 @@ var useSplitter = function useSplitter(props) {
|
|
|
25
27
|
_ref$direction = _ref.direction,
|
|
26
28
|
direction = _ref$direction === void 0 ? 'vertical' : _ref$direction,
|
|
27
29
|
_ref$splitterWidth = _ref.splitterWidth,
|
|
28
|
-
splitterWidth = _ref$splitterWidth === void 0 ?
|
|
30
|
+
splitterWidth = _ref$splitterWidth === void 0 ? 1 : _ref$splitterWidth,
|
|
29
31
|
className = _ref.className,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
classNames = _ref.classNames,
|
|
33
|
+
styles = _ref.styles,
|
|
34
|
+
prefixClsInProps = _ref.prefixCls,
|
|
35
|
+
style = _ref.style,
|
|
36
|
+
onChange = _ref.onChange;
|
|
37
|
+
var _useContext = useContext(ConfigProvider.ConfigContext),
|
|
38
|
+
getPrefixCls = _useContext.getPrefixCls;
|
|
39
|
+
var prefixCls = getPrefixCls('splitter', prefixClsInProps);
|
|
40
|
+
var _useStyle = useStyle(prefixCls),
|
|
41
|
+
_useStyle2 = _slicedToArray(_useStyle, 3),
|
|
42
|
+
wrapCSSVar = _useStyle2[0],
|
|
43
|
+
hashId = _useStyle2[1],
|
|
44
|
+
cssVarCls = _useStyle2[2];
|
|
33
45
|
var directionRef = useRefValue(direction);
|
|
34
|
-
var _useState = useState(
|
|
46
|
+
var _useState = useState(null),
|
|
35
47
|
_useState2 = _slicedToArray(_useState, 2),
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var
|
|
39
|
-
var _useState3 = useState(container && defaultRatio ? ((container === null || container === void 0 ? void 0 : container.clientWidth) || 0) * defaultRatio : undefined),
|
|
48
|
+
splitterRef = _useState2[0],
|
|
49
|
+
setSplitterRef = _useState2[1];
|
|
50
|
+
var _useState3 = useState(containerFromProps),
|
|
40
51
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var _useState5 = useState(
|
|
52
|
+
container = _useState4[0],
|
|
53
|
+
setContainer = _useState4[1];
|
|
54
|
+
var _useState5 = useState(defaultRatio),
|
|
44
55
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
percent = _useState6[0],
|
|
57
|
+
setPercent = _useState6[1];
|
|
58
|
+
var percentRef = useRefValue(percent);
|
|
59
|
+
var onChangeRef = useRefValue(onChange);
|
|
60
|
+
var _useState7 = useState(container && defaultRatio ? ((container === null || container === void 0 ? void 0 : container.clientWidth) || 0) * defaultRatio : undefined),
|
|
61
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
62
|
+
width = _useState8[0],
|
|
63
|
+
setWidth = _useState8[1];
|
|
64
|
+
var _useState9 = useState(false),
|
|
65
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
66
|
+
dragging = _useState10[0],
|
|
67
|
+
setDragging = _useState10[1];
|
|
47
68
|
var minRatioRef = useRefValue(minRatio);
|
|
48
69
|
var maxRatioRef = useRefValue(maxRatio);
|
|
49
|
-
var
|
|
50
|
-
|
|
51
|
-
isOver =
|
|
52
|
-
setIsOver =
|
|
70
|
+
var _useState11 = useState(false),
|
|
71
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
72
|
+
isOver = _useState12[0],
|
|
73
|
+
setIsOver = _useState12[1];
|
|
53
74
|
useEffect(function () {
|
|
54
75
|
if (!dragging) return;
|
|
55
76
|
var onMove = function onMove(e) {
|
|
@@ -57,15 +78,19 @@ var useSplitter = function useSplitter(props) {
|
|
|
57
78
|
if (!el) return;
|
|
58
79
|
var rect = el.getBoundingClientRect();
|
|
59
80
|
if (direction === 'vertical') {
|
|
81
|
+
var _onChangeRef$current;
|
|
60
82
|
var x = e.clientX - rect.left;
|
|
61
|
-
var
|
|
62
|
-
setPercent(
|
|
83
|
+
var _ratio = Math.max(minRatioRef.current, Math.min(maxRatioRef.current, x / rect.width));
|
|
84
|
+
setPercent(_ratio);
|
|
63
85
|
setWidth(x);
|
|
86
|
+
(_onChangeRef$current = onChangeRef.current) === null || _onChangeRef$current === void 0 || _onChangeRef$current.call(onChangeRef, _ratio);
|
|
64
87
|
} else {
|
|
88
|
+
var _onChangeRef$current2;
|
|
65
89
|
var y = e.clientY - rect.top;
|
|
66
|
-
var
|
|
67
|
-
setPercent(
|
|
90
|
+
var _ratio2 = Math.max(minRatioRef.current, Math.min(maxRatioRef.current, y / rect.height));
|
|
91
|
+
setPercent(_ratio2);
|
|
68
92
|
setWidth(y);
|
|
93
|
+
(_onChangeRef$current2 = onChangeRef.current) === null || _onChangeRef$current2 === void 0 || _onChangeRef$current2.call(onChangeRef, _ratio2);
|
|
69
94
|
}
|
|
70
95
|
// prevent text selection while dragging
|
|
71
96
|
e.preventDefault();
|
|
@@ -82,6 +107,11 @@ var useSplitter = function useSplitter(props) {
|
|
|
82
107
|
window.removeEventListener('mouseup', onUp);
|
|
83
108
|
};
|
|
84
109
|
}, [container, dragging, direction, minRatioRef, maxRatioRef]);
|
|
110
|
+
useEffect(function () {
|
|
111
|
+
var _ref2;
|
|
112
|
+
var containerDom = (_ref2 = containerFromProps !== null && containerFromProps !== void 0 ? containerFromProps : splitterRef === null || splitterRef === void 0 ? void 0 : splitterRef.parentElement) !== null && _ref2 !== void 0 ? _ref2 : undefined;
|
|
113
|
+
setContainer(containerDom);
|
|
114
|
+
}, [containerFromProps, splitterRef]);
|
|
85
115
|
|
|
86
116
|
// Initialize percent and width on mount
|
|
87
117
|
useEffect(function () {
|
|
@@ -89,25 +119,21 @@ var useSplitter = function useSplitter(props) {
|
|
|
89
119
|
var rect = container.getBoundingClientRect();
|
|
90
120
|
setPercent(defaultRatio);
|
|
91
121
|
if (directionRef.current === 'vertical') {
|
|
122
|
+
var _onChangeRef$current3;
|
|
92
123
|
setWidth(rect.width * defaultRatio);
|
|
124
|
+
(_onChangeRef$current3 = onChangeRef.current) === null || _onChangeRef$current3 === void 0 || _onChangeRef$current3.call(onChangeRef, defaultRatio);
|
|
93
125
|
} else {
|
|
126
|
+
var _onChangeRef$current4;
|
|
94
127
|
setWidth(rect.height * defaultRatio);
|
|
128
|
+
(_onChangeRef$current4 = onChangeRef.current) === null || _onChangeRef$current4 === void 0 || _onChangeRef$current4.call(onChangeRef, defaultRatio);
|
|
95
129
|
}
|
|
96
130
|
}
|
|
97
131
|
}, [defaultRatio, container]);
|
|
98
132
|
var vertical = direction === 'vertical';
|
|
99
|
-
var dom = /*#__PURE__*/_jsx("div", {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
width: vertical ? splitterWidth : '100%',
|
|
104
|
-
height: vertical ? 'auto' : splitterWidth,
|
|
105
|
-
cursor: vertical ? 'col-resize' : 'row-resize',
|
|
106
|
-
background: dragging ? token.colorPrimaryHover : isOver ? token.colorPrimaryActive : token.colorBorder,
|
|
107
|
-
margin: vertical ? '0 4px' : '4px 0',
|
|
108
|
-
borderRadius: 4,
|
|
109
|
-
userSelect: 'none'
|
|
110
|
-
}, style),
|
|
133
|
+
var dom = wrapCSSVar( /*#__PURE__*/_jsx("div", {
|
|
134
|
+
ref: setSplitterRef,
|
|
135
|
+
className: names(hashId, cssVarCls, prefixCls, className, isOver ? names("".concat(prefixCls, "-hover"), classNames === null || classNames === void 0 ? void 0 : classNames.hover) : undefined, dragging ? names("".concat(prefixCls, "-dragging"), classNames === null || classNames === void 0 ? void 0 : classNames.dragging) : undefined, _defineProperty(_defineProperty({}, "".concat(prefixCls, "-vertical"), vertical), "".concat(prefixCls, "-horizontal"), !vertical)),
|
|
136
|
+
style: _objectSpread(_defineProperty({}, "--splitter-width", splitterWidth ? "".concat(splitterWidth, "px") : undefined), style),
|
|
111
137
|
onMouseDown: function onMouseDown() {
|
|
112
138
|
return setDragging(true);
|
|
113
139
|
},
|
|
@@ -119,8 +145,12 @@ var useSplitter = function useSplitter(props) {
|
|
|
119
145
|
},
|
|
120
146
|
role: "separator",
|
|
121
147
|
"aria-orientation": vertical ? 'vertical' : 'horizontal',
|
|
122
|
-
"aria-label": "Resize"
|
|
123
|
-
|
|
148
|
+
"aria-label": "Resize",
|
|
149
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
150
|
+
className: names("".concat(prefixCls, "-handle"), classNames === null || classNames === void 0 ? void 0 : classNames.handle),
|
|
151
|
+
style: styles === null || styles === void 0 ? void 0 : styles.handle
|
|
152
|
+
})
|
|
153
|
+
}));
|
|
124
154
|
return {
|
|
125
155
|
dom: dom,
|
|
126
156
|
percent: percent,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useEffect","useState","theme","useRefValue","jsx","_jsx","useSplitter","props","_ref","container","defaultRatio","_ref$minRatio","minRatio","_ref$maxRatio","maxRatio","_ref$direction","direction","_ref$splitterWidth","splitterWidth","className","style","_theme$useToken","useToken","token","directionRef","_useState","_useState2","_slicedToArray","percent","setPercent","percentRef","_useState3","clientWidth","undefined","_useState4","width","setWidth","_useState5","_useState6","dragging","setDragging","minRatioRef","maxRatioRef","_useState7","_useState8","isOver","setIsOver","onMove","e","el","rect","getBoundingClientRect","x","clientX","left","ratio","Math","max","current","min","y","clientY","top","height","preventDefault","onUp","window","addEventListener","once","removeEventListener","vertical","dom","_objectSpread","flex","cursor","background","colorPrimaryHover","colorPrimaryActive","colorBorder","margin","borderRadius","userSelect","onMouseDown","onMouseEnter","onMouseLeave","role"],"sources":["../../src/hooks/useSplitter.tsx"],"sourcesContent":["import { type CSSProperties, useEffect, useState } from 'react';\nimport { theme } from 'antd';\nimport useRefValue from './useRefValue';\n\nexport interface UseSplitterProps {\n /**\n * - **EN:** Split direction. vertical = left/right; horizontal = top/bottom.\n * - **ZH:** 分割方向。vertical 表示左右分割;horizontal 表示上下分割。\n *\n * @default 'vertical'\n */\n direction?: 'vertical' | 'horizontal';\n /**\n * - **EN:** The container element reference.\n * - **ZH:** 容器元素的引用。\n */\n container: HTMLDivElement | null | undefined;\n /**\n * - **EN:** Default ratio of the left/top pane (0~1).\n * - **ZH:** 左侧/顶部面板的默认比例 (0~1)。\n *\n * @default 0.32\n */\n defaultRatio?: number;\n /**\n * - **EN:** Minimum ratio of the left/top pane (0~1).\n * - **ZH:** 左侧/顶部面板的最小比例 (0~1)。\n *\n * @default 0.15\n */\n minRatio?: number;\n /**\n * - **EN:** Maximum ratio of the left/top pane (0~1).\n * - **ZH:** 左侧/顶部面板的最大比例 (0~1)。\n *\n * @default 0.85\n */\n maxRatio?: number;\n /**\n * - **EN:** Width of the splitter in pixels.\n * - **ZH:** 分割条的宽度,单位为像素。\n *\n * @default 2\n */\n splitterWidth?: number;\n /** Additional class name for the splitter element */\n className?: string;\n /** Additional style for the splitter element */\n style?: CSSProperties;\n}\n\nconst useSplitter = (props: UseSplitterProps) => {\n const {\n container,\n defaultRatio,\n minRatio = 0.15,\n maxRatio = 1 - minRatio,\n direction = 'vertical',\n splitterWidth = 2,\n className,\n style,\n } = props || {};\n const { token } = theme.useToken();\n const directionRef = useRefValue(direction);\n const [percent, setPercent] = useState(defaultRatio);\n const percentRef = useRefValue(percent);\n const [width, setWidth] = useState(\n container && defaultRatio ? (container?.clientWidth || 0) * defaultRatio : undefined\n );\n const [dragging, setDragging] = useState(false);\n const minRatioRef = useRefValue(minRatio);\n const maxRatioRef = useRefValue(maxRatio);\n const [isOver, setIsOver] = useState(false);\n\n useEffect(() => {\n if (!dragging) return;\n const onMove = (e: MouseEvent) => {\n const el = container;\n if (!el) return;\n const rect = el.getBoundingClientRect();\n if (direction === 'vertical') {\n const x = e.clientX - rect.left;\n const ratio = Math.max(minRatioRef.current, Math.min(maxRatioRef.current, x / rect.width));\n setPercent(ratio);\n setWidth(x);\n } else {\n const y = e.clientY - rect.top;\n const ratio = Math.max(minRatioRef.current, Math.min(maxRatioRef.current, y / rect.height));\n setPercent(ratio);\n setWidth(y);\n }\n // prevent text selection while dragging\n e.preventDefault();\n };\n const onUp = () => setDragging(false);\n window.addEventListener('mousemove', onMove);\n window.addEventListener('mouseup', onUp, { once: true });\n\n return () => {\n window.removeEventListener('mousemove', onMove);\n window.removeEventListener('mouseup', onUp);\n };\n }, [container, dragging, direction, minRatioRef, maxRatioRef]);\n\n // Initialize percent and width on mount\n useEffect(() => {\n if (defaultRatio && container && percentRef.current == null) {\n const rect = container.getBoundingClientRect();\n setPercent(defaultRatio);\n if (directionRef.current === 'vertical') {\n setWidth(rect.width * defaultRatio);\n } else {\n setWidth(rect.height * defaultRatio);\n }\n }\n }, [defaultRatio, container]);\n\n const vertical = direction === 'vertical';\n const dom = (\n <div\n className={className}\n style={{\n flex: 'none',\n width: vertical ? splitterWidth : '100%',\n height: vertical ? 'auto' : splitterWidth,\n cursor: vertical ? 'col-resize' : 'row-resize',\n background: dragging ? token.colorPrimaryHover : isOver ? token.colorPrimaryActive : token.colorBorder,\n margin: vertical ? '0 4px' : '4px 0',\n borderRadius: 4,\n userSelect: 'none',\n ...style,\n }}\n onMouseDown={() => setDragging(true)}\n onMouseEnter={() => setIsOver(true)}\n onMouseLeave={() => setIsOver(false)}\n role=\"separator\"\n aria-orientation={vertical ? 'vertical' : 'horizontal'}\n aria-label=\"Resize\"\n />\n );\n\n return {\n dom,\n percent,\n width,\n dragging,\n direction,\n };\n};\n\nexport default useSplitter;\n"],"mappings":";;;;;;;;;;;;AAAA,SAA6BA,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAC/D,SAASC,KAAK,QAAQ,MAAM;AAC5B,OAAOC,WAAW;AAAsB,SAAAC,GAAA,IAAAC,IAAA;AAiDx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,gBACPlE,IAAA;IACEc,SAAS,EAAEA,SAAU;IACrBC,KAAK,EAAAoD,aAAA;MACHC,IAAI,EAAE,MAAM;MACZtC,KAAK,EAAEmC,QAAQ,GAAGpD,aAAa,GAAG,MAAM;MACxC6C,MAAM,EAAEO,QAAQ,GAAG,MAAM,GAAGpD,aAAa;MACzCwD,MAAM,EAAEJ,QAAQ,GAAG,YAAY,GAAG,YAAY;MAC9CK,UAAU,EAAEpC,QAAQ,GAAGhB,KAAK,CAACqD,iBAAiB,GAAG/B,MAAM,GAAGtB,KAAK,CAACsD,kBAAkB,GAAGtD,KAAK,CAACuD,WAAW;MACtGC,MAAM,EAAET,QAAQ,GAAG,OAAO,GAAG,OAAO;MACpCU,YAAY,EAAE,CAAC;MACfC,UAAU,EAAE;IAAM,GACf7D,KAAK,CACR;IACF8D,WAAW,EAAE,SAAAA,YAAA;MAAA,OAAM1C,WAAW,CAAC,IAAI,CAAC;IAAA,CAAC;IACrC2C,YAAY,EAAE,SAAAA,aAAA;MAAA,OAAMrC,SAAS,CAAC,IAAI,CAAC;IAAA,CAAC;IACpCsC,YAAY,EAAE,SAAAA,aAAA;MAAA,OAAMtC,SAAS,CAAC,KAAK,CAAC;IAAA,CAAC;IACrCuC,IAAI,EAAC,WAAW;IAChB,oBAAkBf,QAAQ,GAAG,UAAU,GAAG,YAAa;IACvD,cAAW;EAAQ,CACpB,CACF;EAED,OAAO;IACLC,GAAG,EAAHA,GAAG;IACH3C,OAAO,EAAPA,OAAO;IACPO,KAAK,EAALA,KAAK;IACLI,QAAQ,EAARA,QAAQ;IACRvB,SAAS,EAATA;EACF,CAAC;AACH,CAAC;AAED,eAAeV,WAAW"}
|
|
1
|
+
{"version":3,"names":["useContext","useEffect","useState","names","ConfigProvider","useStyle","useRefValue","jsx","_jsx","useSplitter","props","_ref","containerFromProps","container","defaultRatio","_ref$minRatio","minRatio","_ref$maxRatio","maxRatio","_ref$direction","direction","_ref$splitterWidth","splitterWidth","className","classNames","styles","prefixClsInProps","prefixCls","style","onChange","_useContext","ConfigContext","getPrefixCls","_useStyle","_useStyle2","_slicedToArray","wrapCSSVar","hashId","cssVarCls","directionRef","_useState","_useState2","splitterRef","setSplitterRef","_useState3","_useState4","setContainer","_useState5","_useState6","percent","setPercent","percentRef","onChangeRef","_useState7","clientWidth","undefined","_useState8","width","setWidth","_useState9","_useState10","dragging","setDragging","minRatioRef","maxRatioRef","_useState11","_useState12","isOver","setIsOver","onMove","e","el","rect","getBoundingClientRect","_onChangeRef$current","x","clientX","left","ratio","Math","max","current","min","call","_onChangeRef$current2","y","clientY","top","height","preventDefault","onUp","window","addEventListener","once","removeEventListener","_ref2","containerDom","parentElement","_onChangeRef$current3","_onChangeRef$current4","vertical","dom","ref","concat","hover","_defineProperty","_objectSpread","onMouseDown","onMouseEnter","onMouseLeave","role","children","handle"],"sources":["../../src/hooks/useSplitter.tsx"],"sourcesContent":["import { type CSSProperties, useContext, useEffect, useState } from 'react';\nimport names from 'classnames';\nimport { ConfigProvider } from '../components';\nimport useStyle from './style/useSplitter';\nimport useRefValue from './useRefValue';\n\nexport interface UseSplitterProps {\n /**\n * - **EN:** Split direction. vertical = left/right; horizontal = top/bottom.\n * - **CN:** 分割方向。vertical 表示左右分割;horizontal 表示上下分割。\n *\n * @default 'vertical'\n */\n direction?: 'vertical' | 'horizontal';\n /**\n * - **EN:** Parent container element. If not specified, the parent container of the `dom` element\n * will be used automatically.\n * - **CN:** 父容器元素,如果不指定,则自动使用 `dom` 元素的父容器\n */\n container?: HTMLDivElement | null | undefined;\n /**\n * - **EN:** Default ratio of the left/top pane (0~1).\n * - **CN:** 左侧/顶部面板的默认比例 (0~1)。\n *\n * @default 0.32\n */\n defaultRatio?: number;\n /**\n * - **EN:** Minimum ratio of the left/top pane (0~1).\n * - **CN:** 左侧/顶部面板的最小比例 (0~1)。\n *\n * @default 0.15\n */\n minRatio?: number;\n /**\n * - **EN:** Maximum ratio of the left/top pane (0~1).\n * - **CN:** 左侧/顶部面板的最大比例 (0~1)。\n *\n * @default 0.85\n */\n maxRatio?: number;\n /**\n * - **EN:** Width of the splitter in pixels.\n * - **CN:** 分割条的宽度,单位为像素。\n *\n * @default 2\n */\n splitterWidth?: number;\n /** Additional class name for the splitter element */\n className?: string;\n /** Additional style for the splitter element */\n style?: CSSProperties;\n /**\n * - **EN:** Custom prefix for the component's CSS class.\n * - **CN:** 组件的自定义 CSS 类前缀。\n */\n prefixCls?: string;\n /**\n * - **EN:** Semantic class names\n * - **CN:** 语义化类名\n */\n classNames?: {\n /**\n * - **EN:** Class name applied when the splitter is hovered.\n * - **CN:** 分割条悬停时应用的类名。\n */\n hover?: string;\n /**\n * - **EN:** Class name applied when the splitter is being dragged.\n * - **CN:** 分割条拖动时应用的类名。\n */\n dragging?: string;\n /**\n * - **EN:** Class name applied to the splitter handle.\n * - **CN:** 分割条手柄的类名。\n */\n handle?: string;\n };\n /**\n * - **EN:** Semantic styles\n * - **CN:** 语义化样式\n */\n styles?: {\n /**\n * - **EN:** Custom styles for the splitter handle.\n * - **CN:** 分割条手柄的自定义样式。\n */\n handle?: CSSProperties;\n };\n /**\n * - **EN:** Callback function when the splitter ratio changes.\n * - **CN:** 分割比例变化时的回调函数。\n */\n onChange?: (ratio?: number) => void;\n}\n\nconst useSplitter = (props: UseSplitterProps) => {\n const {\n container: containerFromProps,\n defaultRatio,\n minRatio = 0.15,\n maxRatio = 1 - minRatio,\n direction = 'vertical',\n splitterWidth = 1,\n className,\n classNames,\n styles,\n prefixCls: prefixClsInProps,\n style,\n onChange,\n } = props || {};\n const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);\n const prefixCls = getPrefixCls('splitter', prefixClsInProps);\n const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);\n const directionRef = useRefValue(direction);\n const [splitterRef, setSplitterRef] = useState<HTMLDivElement | null>(null);\n const [container, setContainer] = useState(containerFromProps);\n const [percent, setPercent] = useState(defaultRatio);\n const percentRef = useRefValue(percent);\n const onChangeRef = useRefValue(onChange);\n const [width, setWidth] = useState(\n container && defaultRatio ? (container?.clientWidth || 0) * defaultRatio : undefined\n );\n const [dragging, setDragging] = useState(false);\n const minRatioRef = useRefValue(minRatio);\n const maxRatioRef = useRefValue(maxRatio);\n const [isOver, setIsOver] = useState(false);\n\n useEffect(() => {\n if (!dragging) return;\n const onMove = (e: MouseEvent) => {\n const el = container;\n if (!el) return;\n const rect = el.getBoundingClientRect();\n if (direction === 'vertical') {\n const x = e.clientX - rect.left;\n const ratio = Math.max(minRatioRef.current, Math.min(maxRatioRef.current, x / rect.width));\n setPercent(ratio);\n setWidth(x);\n onChangeRef.current?.(ratio);\n } else {\n const y = e.clientY - rect.top;\n const ratio = Math.max(minRatioRef.current, Math.min(maxRatioRef.current, y / rect.height));\n setPercent(ratio);\n setWidth(y);\n onChangeRef.current?.(ratio);\n }\n // prevent text selection while dragging\n e.preventDefault();\n };\n const onUp = () => setDragging(false);\n window.addEventListener('mousemove', onMove);\n window.addEventListener('mouseup', onUp, { once: true });\n\n return () => {\n window.removeEventListener('mousemove', onMove);\n window.removeEventListener('mouseup', onUp);\n };\n }, [container, dragging, direction, minRatioRef, maxRatioRef]);\n\n useEffect(() => {\n const containerDom = containerFromProps ?? (splitterRef?.parentElement as HTMLDivElement | undefined) ?? undefined;\n setContainer(containerDom);\n }, [containerFromProps, splitterRef]);\n\n // Initialize percent and width on mount\n useEffect(() => {\n if (defaultRatio && container && percentRef.current == null) {\n const rect = container.getBoundingClientRect();\n setPercent(defaultRatio);\n if (directionRef.current === 'vertical') {\n setWidth(rect.width * defaultRatio);\n onChangeRef.current?.(defaultRatio);\n } else {\n setWidth(rect.height * defaultRatio);\n onChangeRef.current?.(defaultRatio);\n }\n }\n }, [defaultRatio, container]);\n\n const vertical = direction === 'vertical';\n const dom = wrapCSSVar(\n <div\n ref={setSplitterRef}\n className={names(\n hashId,\n cssVarCls,\n prefixCls,\n className,\n isOver ? names(`${prefixCls}-hover`, classNames?.hover) : undefined,\n dragging ? names(`${prefixCls}-dragging`, classNames?.dragging) : undefined,\n {\n [`${prefixCls}-vertical`]: vertical,\n [`${prefixCls}-horizontal`]: !vertical,\n }\n )}\n style={{\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [`--splitter-width` as any]: splitterWidth ? `${splitterWidth}px` : undefined,\n ...style,\n }}\n onMouseDown={() => setDragging(true)}\n onMouseEnter={() => setIsOver(true)}\n onMouseLeave={() => setIsOver(false)}\n role=\"separator\"\n aria-orientation={vertical ? 'vertical' : 'horizontal'}\n aria-label=\"Resize\"\n >\n <div className={names(`${prefixCls}-handle`, classNames?.handle)} style={styles?.handle}></div>\n </div>\n );\n\n return {\n dom,\n percent,\n width,\n dragging,\n direction,\n };\n};\n\nexport default useSplitter;\n"],"mappings":";;;;;;;;;;;;AAAA,SAA6BA,UAAU,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAC3E,OAAOC,KAAK,MAAM,YAAY;AAC9B,SAASC,cAAc;AACvB,OAAOC,QAAQ;AACf,OAAOC,WAAW;AAAsB,SAAAC,GAAA,IAAAC,IAAA;AA4FxC,IAAMC,WAAW,GAAG,SAAdA,WAAWA,CAAIC,KAAuB,EAAK;EAC/C,IAAAC,IAAA,GAaID,KAAK,IAAI,CAAC,CAAC;IAZFE,kBAAkB,GAAAD,IAAA,CAA7BE,SAAS;IACTC,YAAY,GAAAH,IAAA,CAAZG,YAAY;IAAAC,aAAA,GAAAJ,IAAA,CACZK,QAAQ;IAARA,QAAQ,GAAAD,aAAA,cAAG,IAAI,GAAAA,aAAA;IAAAE,aAAA,GAAAN,IAAA,CACfO,QAAQ;IAARA,QAAQ,GAAAD,aAAA,cAAG,CAAC,GAAGD,QAAQ,GAAAC,aAAA;IAAAE,cAAA,GAAAR,IAAA,CACvBS,SAAS;IAATA,SAAS,GAAAD,cAAA,cAAG,UAAU,GAAAA,cAAA;IAAAE,kBAAA,GAAAV,IAAA,CACtBW,aAAa;IAAbA,aAAa,GAAAD,kBAAA,cAAG,CAAC,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APA,OAAO;IACPQ,KAAK,EAALA,KAAK;IACLI,QAAQ,EAARA,QAAQ;IACRzC,SAAS,EAATA;EACF,CAAC;AACH,CAAC;AAED,eAAeX,WAAW"}
|
|
@@ -39,6 +39,7 @@ var import_icons = require("@ant-design/icons");
|
|
|
39
39
|
var import_hooks = require("../../hooks");
|
|
40
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,7 +54,7 @@ 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
60
|
const [open, setOpen] = (0, import_react.useState)(false);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/ColumnSetting/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useContext, useEffect, useMemo, useState } from 'react';\nimport { Button, Checkbox,
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAyD;AACzD,
|
|
6
|
-
"names": ["useStyle", "useT", "useLocalStorage", "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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cAAc;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,8 +1,14 @@
|
|
|
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'
|
|
@@ -20,6 +26,36 @@ export interface ReactEasyContextProps {
|
|
|
20
26
|
* @returns Localized text | 本地化文本
|
|
21
27
|
*/
|
|
22
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;
|
|
23
59
|
/**
|
|
24
60
|
* - **EN:** Global configuration for `ConfirmAction` component, which can be used to set default
|
|
25
61
|
* modal title and content for all `ConfirmAction` components in the application.
|
|
@@ -25,6 +25,7 @@ __export(context_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(context_exports);
|
|
26
26
|
var import_react = require("react");
|
|
27
27
|
var defaultContextValue = {
|
|
28
|
+
getPrefixCls: void 0,
|
|
28
29
|
lang: "en-US"
|
|
29
30
|
};
|
|
30
31
|
var ReactEasyContext = (0, import_react.createContext)(defaultContextValue);
|
|
@@ -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 * @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 `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-US',\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,7 +1,7 @@
|
|
|
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
5
|
/**
|
|
6
6
|
* - **EN:** Child elements of the ConfigProvider
|
|
7
7
|
* - **CN:** ConfigProvider 的子元素
|
|
@@ -33,5 +33,7 @@ export interface ConfigProviderProps extends ReactEasyContextProps {
|
|
|
33
33
|
* - **EN:** Provide global configuration for AntdHelper
|
|
34
34
|
* - **CN:** 提供AntdHelper的全局配置
|
|
35
35
|
*/
|
|
36
|
-
declare const ConfigProvider: FC<ConfigProviderProps
|
|
36
|
+
declare const ConfigProvider: FC<ConfigProviderProps> & {
|
|
37
|
+
ConfigContext: typeof ReactEasyContext;
|
|
38
|
+
};
|
|
37
39
|
export default ConfigProvider;
|
|
@@ -44,15 +44,22 @@ 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) {
|
|
50
54
|
import_locales.default.changeLanguage(langInProps || "en-US");
|
|
51
55
|
}
|
|
52
|
-
return
|
|
56
|
+
return {
|
|
57
|
+
...restProps,
|
|
58
|
+
getPrefixCls: getEasyPrefixCls
|
|
59
|
+
};
|
|
53
60
|
},
|
|
54
61
|
// eslint-disable-next-line @tiny-codes/react-hooks/exhaustive-deps
|
|
55
|
-
[langInProps, ...Object.values(restProps)]
|
|
62
|
+
[langInProps, getEasyPrefixCls, ...Object.values(restProps)]
|
|
56
63
|
);
|
|
57
64
|
(0, import_react.useEffect)(() => {
|
|
58
65
|
if (userLocales) {
|
|
@@ -70,5 +77,6 @@ var ConfigProvider = (props) => {
|
|
|
70
77
|
);
|
|
71
78
|
};
|
|
72
79
|
ConfigProvider.displayName = "ReactEasyConfigProvider";
|
|
80
|
+
ConfigProvider.ConfigContext = import_context.default;
|
|
73
81
|
var ConfigProvider_default = ConfigProvider;
|
|
74
82
|
//# 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, 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 ReactEasyContextProps {\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> = (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 restProps;\n },\n // eslint-disable-next-line @tiny-codes/react-hooks/exhaustive-deps\n [langInProps, ...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';\n\nexport default ConfigProvider;\n"],
|
|
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;AAC7D,QAAM,CAAC,YAAY,QAAQ,SAAS,QAAI,aAAAC,SAAS,WAAW,aAAa;AACzE,QAAM,uBAAmB;AAAA,IACvB,CAAC,WAAmB,uBAAgC,aAAa,QAAQ,aAAa,kBAAkB;AAAA,IACxG,CAAC,YAAY;AAAA,EACf;AACA,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;AAAA,MAChB;AAAA,IACF;AAAA;AAAA,IAEA,CAAC,aAAa,kBAAkB,GAAG,OAAO,OAAO,SAAS,CAAC;AAAA,EAC7D;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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,YACF;AAAA,YACA,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
|
}
|
|
@@ -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 });
|