@tiny-codes/react-easy 1.7.4 → 1.7.6
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 +25 -0
- package/es/components/Animation/Pulse/index.d.ts +18 -2
- package/es/components/Animation/Pulse/index.js +1 -1
- package/es/components/Animation/Pulse/index.js.map +1 -1
- package/es/components/BreakLines/index.d.ts +7 -7
- package/es/components/BreakLines/index.js.map +1 -1
- package/es/components/ColumnSetting/index.d.ts +7 -2
- package/es/components/ColumnSetting/index.js +27 -16
- package/es/components/ColumnSetting/index.js.map +1 -1
- package/es/components/ConfigProvider/context.d.ts +2 -0
- package/es/components/ConfigProvider/context.js +1 -1
- package/es/components/ConfigProvider/context.js.map +1 -1
- package/es/components/ConfigProvider/index.d.ts +17 -1
- package/es/components/ConfigProvider/index.js +15 -8
- package/es/components/ConfigProvider/index.js.map +1 -1
- package/es/components/ContextMenu/index.d.ts +16 -0
- package/es/components/ContextMenu/index.js.map +1 -1
- package/es/components/EditableText/form.d.ts +4 -0
- package/es/components/EditableText/form.js.map +1 -1
- package/es/components/EditableText/index.d.ts +6 -2
- package/es/components/EditableText/index.js.map +1 -1
- package/es/components/EllipsisTypography/EllipsisLink.d.ts +19 -0
- package/es/components/EllipsisTypography/EllipsisLink.js +19 -0
- package/es/components/EllipsisTypography/EllipsisLink.js.map +1 -0
- package/es/components/FloatDrawer/index.d.ts +10 -0
- package/es/components/FloatDrawer/index.js.map +1 -1
- package/es/components/OverflowTags/index.d.ts +2 -0
- package/es/components/OverflowTags/index.js.map +1 -1
- package/es/components/index.d.ts +2 -0
- package/es/components/index.js +2 -0
- package/es/components/index.js.map +1 -1
- package/es/hooks/index.d.ts +2 -0
- package/es/hooks/index.js +2 -0
- package/es/hooks/index.js.map +1 -1
- package/es/hooks/useLocalStorage.d.ts +16 -0
- package/es/hooks/useLocalStorage.js +115 -0
- package/es/hooks/useLocalStorage.js.map +1 -0
- package/es/hooks/useMovable.js +2 -2
- package/es/hooks/useMovable.js.map +1 -1
- package/es/locales/index.js +1 -1
- package/es/locales/index.js.map +1 -1
- package/es/utils/math.d.ts +11 -3
- package/es/utils/math.js +62 -9
- package/es/utils/math.js.map +1 -1
- package/lib/components/Animation/Pulse/index.d.ts +18 -2
- package/lib/components/Animation/Pulse/index.js +0 -5
- package/lib/components/Animation/Pulse/index.js.map +2 -2
- package/lib/components/BreakLines/index.d.ts +7 -7
- package/lib/components/BreakLines/index.js.map +1 -1
- package/lib/components/ColumnSetting/index.d.ts +7 -2
- package/lib/components/ColumnSetting/index.js +18 -14
- package/lib/components/ColumnSetting/index.js.map +3 -3
- package/lib/components/ConfigProvider/context.d.ts +2 -0
- package/lib/components/ConfigProvider/context.js +1 -1
- package/lib/components/ConfigProvider/context.js.map +2 -2
- package/lib/components/ConfigProvider/index.d.ts +17 -1
- package/lib/components/ConfigProvider/index.js +13 -6
- package/lib/components/ConfigProvider/index.js.map +2 -2
- package/lib/components/ContextMenu/index.d.ts +16 -0
- package/lib/components/ContextMenu/index.js.map +2 -2
- package/lib/components/EditableText/form.d.ts +4 -0
- package/lib/components/EditableText/form.js.map +2 -2
- package/lib/components/EditableText/index.d.ts +6 -2
- package/lib/components/EditableText/index.js.map +2 -2
- package/lib/components/EllipsisTypography/EllipsisLink.d.ts +19 -0
- package/lib/components/EllipsisTypography/EllipsisLink.js +39 -0
- package/lib/components/EllipsisTypography/EllipsisLink.js.map +7 -0
- package/lib/components/FloatDrawer/index.d.ts +10 -0
- package/lib/components/FloatDrawer/index.js.map +2 -2
- package/lib/components/OverflowTags/index.d.ts +2 -0
- package/lib/components/OverflowTags/index.js.map +2 -2
- package/lib/components/index.d.ts +2 -0
- package/lib/components/index.js +6 -1
- package/lib/components/index.js.map +2 -2
- package/lib/hooks/index.d.ts +2 -0
- package/lib/hooks/index.js +5 -0
- package/lib/hooks/index.js.map +2 -2
- package/lib/hooks/useLocalStorage.d.ts +16 -0
- package/lib/hooks/useLocalStorage.js +120 -0
- package/lib/hooks/useLocalStorage.js.map +7 -0
- package/lib/hooks/useMovable.js +2 -2
- package/lib/hooks/useMovable.js.map +3 -3
- package/lib/locales/index.js +1 -1
- package/lib/locales/index.js.map +1 -1
- package/lib/utils/math.d.ts +11 -3
- package/lib/utils/math.js +43 -8
- package/lib/utils/math.js.map +3 -3
- package/package.json +14 -7
package/es/utils/math.js
CHANGED
|
@@ -1,21 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* **EN**: Generate a random number
|
|
2
|
+
* **EN**: Generate a random decimal number between 0 and 1
|
|
3
3
|
*
|
|
4
|
-
* **CN**:
|
|
4
|
+
* **CN**: 生成一个0~1之间的小数
|
|
5
|
+
*
|
|
6
|
+
* @returns The generated random number | 生成的随机数
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* **EN**: Generate a random integer within a specified range (inclusive on both ends)
|
|
11
|
+
*
|
|
12
|
+
* **CN**: 生成指定范围(两端包含)内的随机整数
|
|
5
13
|
*
|
|
6
14
|
* @param min The minimum value (inclusive) | 最小值(包含)
|
|
7
15
|
* @param max The maximum value (inclusive) | 最大值(包含)
|
|
8
16
|
*
|
|
9
|
-
* @returns The generated random
|
|
17
|
+
* @returns The generated random integer | 生成的随机整数
|
|
10
18
|
*/
|
|
19
|
+
|
|
11
20
|
export function random(min, max) {
|
|
12
21
|
var _process$versions, _nodeCrypto, _nodeCrypto2;
|
|
22
|
+
if (min == null && max == null) {
|
|
23
|
+
return randomLikeMath();
|
|
24
|
+
}
|
|
25
|
+
if (min == null || max == null) {
|
|
26
|
+
throw new TypeError('Both min and max must be provided');
|
|
27
|
+
}
|
|
13
28
|
if (!Number.isFinite(min) || !Number.isFinite(max)) {
|
|
14
29
|
throw new TypeError('min and max must be finite numbers');
|
|
15
30
|
}
|
|
16
31
|
if (Math.floor(min) !== min || Math.floor(max) !== max) {
|
|
17
32
|
throw new TypeError('min and max must be integers');
|
|
18
33
|
}
|
|
34
|
+
var globalThat = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : {};
|
|
19
35
|
if (min > max) {
|
|
20
36
|
var _ref = [max, min];
|
|
21
37
|
min = _ref[0];
|
|
@@ -29,7 +45,7 @@ export function random(min, max) {
|
|
|
29
45
|
try {
|
|
30
46
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
31
47
|
nodeCrypto = require('crypto');
|
|
32
|
-
} catch (
|
|
48
|
+
} catch (error) {
|
|
33
49
|
// ignore
|
|
34
50
|
}
|
|
35
51
|
}
|
|
@@ -41,12 +57,12 @@ export function random(min, max) {
|
|
|
41
57
|
|
|
42
58
|
// 2. Web Crypto (Browsers or Node 19+ webcrypto)
|
|
43
59
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
-
var webCrypto =
|
|
60
|
+
var webCrypto = globalThat.crypto || ((_nodeCrypto2 = nodeCrypto) === null || _nodeCrypto2 === void 0 ? void 0 : _nodeCrypto2.webcrypto);
|
|
45
61
|
if (webCrypto !== null && webCrypto !== void 0 && webCrypto.getRandomValues) {
|
|
46
62
|
var range = max - min + 1;
|
|
47
63
|
if (range <= 0) return min;
|
|
48
64
|
|
|
49
|
-
//
|
|
65
|
+
// Use rejection sampling to avoid the slight bias caused by (2^32 % range).
|
|
50
66
|
var maxUint32 = 0xffffffff;
|
|
51
67
|
var limit = Math.floor((maxUint32 + 1) / range) * range;
|
|
52
68
|
var arr = new Uint32Array(1);
|
|
@@ -58,8 +74,45 @@ export function random(min, max) {
|
|
|
58
74
|
return min + v % range;
|
|
59
75
|
}
|
|
60
76
|
|
|
61
|
-
// 3. Fallback
|
|
62
|
-
|
|
63
|
-
|
|
77
|
+
// 3. Fallback
|
|
78
|
+
return randomLikeMath();
|
|
79
|
+
}
|
|
80
|
+
function randomLikeMath() {
|
|
81
|
+
var _process$versions2;
|
|
82
|
+
var globalThat = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : {};
|
|
83
|
+
// Browser / Node(with webcrypto)
|
|
84
|
+
var cryptoObj = globalThat.crypto;
|
|
85
|
+
if (cryptoObj !== null && cryptoObj !== void 0 && cryptoObj.getRandomValues) {
|
|
86
|
+
var buf = new Uint32Array(2);
|
|
87
|
+
cryptoObj.getRandomValues(buf);
|
|
88
|
+
|
|
89
|
+
// 53-bit precision, mapped to [0, 1)
|
|
90
|
+
var high = buf[0] >>> 5; // 27 bits
|
|
91
|
+
var low = buf[1] >>> 6; // 26 bits
|
|
92
|
+
return (high * 67108864 + low) / 9007199254740992; // 2^53
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Old Node fallback (No webcrypto)
|
|
96
|
+
// Use eval('require') to avoid "require is not defined" error during browser bundling
|
|
97
|
+
var req = typeof process !== 'undefined' && (_process$versions2 = process.versions) !== null && _process$versions2 !== void 0 && _process$versions2.node && typeof globalThat.require === 'function' ? globalThat.require : function () {
|
|
98
|
+
try {
|
|
99
|
+
// eslint-disable-next-line no-eval
|
|
100
|
+
return eval('require');
|
|
101
|
+
} catch (error) {
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
}();
|
|
105
|
+
if (!req) {
|
|
106
|
+
throw new Error('No secure random source available in this environment');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
110
|
+
var nodeCrypto = req('crypto');
|
|
111
|
+
if (typeof nodeCrypto.randomBytes !== 'function') {
|
|
112
|
+
throw new Error('No secure random source available in this environment');
|
|
113
|
+
}
|
|
114
|
+
var b = nodeCrypto.randomBytes(7); // 56 bits
|
|
115
|
+
var x = (b[0] & 0x1f) * Math.pow(2, 48) + b[1] * Math.pow(2, 40) + b[2] * Math.pow(2, 32) + b[3] * Math.pow(2, 24) + b[4] * Math.pow(2, 16) + b[5] * Math.pow(2, 8) + b[6];
|
|
116
|
+
return x / 9007199254740992; // 2^53 => [0,1)
|
|
64
117
|
}
|
|
65
118
|
//# sourceMappingURL=math.js.map
|
package/es/utils/math.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["random","min","max","_process$versions","_nodeCrypto","_nodeCrypto2","
|
|
1
|
+
{"version":3,"names":["random","min","max","_process$versions","_nodeCrypto","_nodeCrypto2","randomLikeMath","TypeError","Number","isFinite","Math","floor","globalThat","globalThis","window","global","_ref","nodeCrypto","process","versions","node","require","error","randomInt","webCrypto","crypto","webcrypto","getRandomValues","range","maxUint32","limit","arr","Uint32Array","v","_process$versions2","cryptoObj","buf","high","low","req","eval","undefined","Error","randomBytes","b","x","pow"],"sources":["../../src/utils/math.ts"],"sourcesContent":["/**\n * **EN**: Generate a random decimal number between 0 and 1\n *\n * **CN**: 生成一个0~1之间的小数\n *\n * @returns The generated random number | 生成的随机数\n */\nexport function random(): number;\n/**\n * **EN**: Generate a random integer within a specified range (inclusive on both ends)\n *\n * **CN**: 生成指定范围(两端包含)内的随机整数\n *\n * @param min The minimum value (inclusive) | 最小值(包含)\n * @param max The maximum value (inclusive) | 最大值(包含)\n *\n * @returns The generated random integer | 生成的随机整数\n */\nexport function random(min: number, max: number): number;\nexport function random(min?: number, max?: number): number {\n if (min == null && max == null) {\n return randomLikeMath();\n }\n if (min == null || max == null) {\n throw new TypeError('Both min and max must be provided');\n }\n if (!Number.isFinite(min) || !Number.isFinite(max)) {\n throw new TypeError('min and max must be finite numbers');\n }\n if (Math.floor(min) !== min || Math.floor(max) !== max) {\n throw new TypeError('min and max must be integers');\n }\n const globalThat =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : ({} as typeof globalThis);\n if (min > max) {\n [min, max] = [max, min];\n }\n\n // Try to require Node.js crypto\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let nodeCrypto: any;\n if (typeof process !== 'undefined' && process.versions?.node) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n nodeCrypto = require('crypto');\n } catch (error) {\n // ignore\n }\n }\n\n // 1. Node.js crypto.randomInt\n if (nodeCrypto?.randomInt) {\n return nodeCrypto.randomInt(min, max + 1);\n }\n\n // 2. Web Crypto (Browsers or Node 19+ webcrypto)\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const webCrypto: Crypto | undefined = globalThat.crypto || nodeCrypto?.webcrypto;\n\n if (webCrypto?.getRandomValues) {\n const range = max - min + 1;\n if (range <= 0) return min;\n\n // Use rejection sampling to avoid the slight bias caused by (2^32 % range).\n const maxUint32 = 0xffffffff;\n const limit = Math.floor((maxUint32 + 1) / range) * range;\n const arr = new Uint32Array(1);\n let v: number;\n do {\n webCrypto.getRandomValues(arr);\n v = arr[0];\n } while (v >= limit);\n return min + (v % range);\n }\n\n // 3. Fallback\n return randomLikeMath();\n}\n\nfunction randomLikeMath(): number {\n const globalThat =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : ({} as typeof globalThis);\n // Browser / Node(with webcrypto)\n const cryptoObj = globalThat.crypto;\n if (cryptoObj?.getRandomValues) {\n const buf = new Uint32Array(2);\n cryptoObj.getRandomValues(buf);\n\n // 53-bit precision, mapped to [0, 1)\n const high = buf[0] >>> 5; // 27 bits\n const low = buf[1] >>> 6; // 26 bits\n return (high * 67108864 + low) / 9007199254740992; // 2^53\n }\n\n // Old Node fallback (No webcrypto)\n // Use eval('require') to avoid \"require is not defined\" error during browser bundling\n const req: NodeRequire | undefined =\n typeof process !== 'undefined' &&\n process.versions?.node &&\n typeof (globalThat as unknown as { require?: unknown }).require === 'function'\n ? (globalThat as unknown as { require: NodeRequire }).require\n : (() => {\n try {\n // eslint-disable-next-line no-eval\n return eval('require') as NodeRequire;\n } catch (error) {\n return undefined;\n }\n })();\n\n if (!req) {\n throw new Error('No secure random source available in this environment');\n }\n\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const nodeCrypto = req('crypto') as { randomBytes?: (size: number) => Uint8Array };\n if (typeof nodeCrypto.randomBytes !== 'function') {\n throw new Error('No secure random source available in this environment');\n }\n\n const b = nodeCrypto.randomBytes(7); // 56 bits\n const x =\n (b[0] & 0x1f) * 2 ** 48 + b[1] * 2 ** 40 + b[2] * 2 ** 32 + b[3] * 2 ** 24 + b[4] * 2 ** 16 + b[5] * 2 ** 8 + b[6];\n\n return x / 9007199254740992; // 2^53 => [0,1)\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,SAASA,MAAMA,CAACC,GAAY,EAAEC,GAAY,EAAU;EAAA,IAAAC,iBAAA,EAAAC,WAAA,EAAAC,YAAA;EACzD,IAAIJ,GAAG,IAAI,IAAI,IAAIC,GAAG,IAAI,IAAI,EAAE;IAC9B,OAAOI,cAAc,CAAC,CAAC;EACzB;EACA,IAAIL,GAAG,IAAI,IAAI,IAAIC,GAAG,IAAI,IAAI,EAAE;IAC9B,MAAM,IAAIK,SAAS,CAAC,mCAAmC,CAAC;EAC1D;EACA,IAAI,CAACC,MAAM,CAACC,QAAQ,CAACR,GAAG,CAAC,IAAI,CAACO,MAAM,CAACC,QAAQ,CAACP,GAAG,CAAC,EAAE;IAClD,MAAM,IAAIK,SAAS,CAAC,oCAAoC,CAAC;EAC3D;EACA,IAAIG,IAAI,CAACC,KAAK,CAACV,GAAG,CAAC,KAAKA,GAAG,IAAIS,IAAI,CAACC,KAAK,CAACT,GAAG,CAAC,KAAKA,GAAG,EAAE;IACtD,MAAM,IAAIK,SAAS,CAAC,8BAA8B,CAAC;EACrD;EACA,IAAMK,UAAU,GACd,OAAOC,UAAU,KAAK,WAAW,GAC7BA,UAAU,GACV,OAAOC,MAAM,KAAK,WAAW,GAC3BA,MAAM,GACN,OAAOC,MAAM,KAAK,WAAW,GAC3BA,MAAM,GACL,CAAC,CAAuB;EACnC,IAAId,GAAG,GAAGC,GAAG,E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CAAC;EAC1E;;EAEA;EACA,IAAMzB,UAAU,GAAGsB,GAAG,CAAC,QAAQ,CAAmD;EAClF,IAAI,OAAOtB,UAAU,CAAC0B,WAAW,KAAK,UAAU,EAAE;IAChD,MAAM,IAAID,KAAK,CAAC,uDAAuD,CAAC;EAC1E;EAEA,IAAME,CAAC,GAAG3B,UAAU,CAAC0B,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;EACrC,IAAME,CAAC,GACL,CAACD,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,IAAAlC,IAAA,CAAAoC,GAAA,CAAI,CAAC,EAAI,EAAE,IAAGF,CAAC,CAAC,CAAC,CAAC,GAAAlC,IAAA,CAAAoC,GAAA,CAAG,CAAC,EAAI,EAAE,IAAGF,CAAC,CAAC,CAAC,CAAC,GAAAlC,IAAA,CAAAoC,GAAA,CAAG,CAAC,EAAI,EAAE,IAAGF,CAAC,CAAC,CAAC,CAAC,GAAAlC,IAAA,CAAAoC,GAAA,CAAG,CAAC,EAAI,EAAE,IAAGF,CAAC,CAAC,CAAC,CAAC,GAAAlC,IAAA,CAAAoC,GAAA,CAAG,CAAC,EAAI,EAAE,IAAGF,CAAC,CAAC,CAAC,CAAC,GAAAlC,IAAA,CAAAoC,GAAA,CAAG,CAAC,EAAI,CAAC,IAAGF,CAAC,CAAC,CAAC,CAAC;EAEpH,OAAOC,CAAC,GAAG,gBAAgB,CAAC,CAAC;AAC/B"}
|
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
import type { CSSProperties, FC } from 'react';
|
|
2
2
|
export interface PulseAnimationProps {
|
|
3
|
+
/**
|
|
4
|
+
* - **EN:** Custom class name for the root element
|
|
5
|
+
* - **CN:** 根元素的自定义类名
|
|
6
|
+
*/
|
|
3
7
|
className?: string;
|
|
8
|
+
/**
|
|
9
|
+
* - **EN:** Custom styles for the root element
|
|
10
|
+
* - **CN:** 根元素的自定义样式
|
|
11
|
+
*/
|
|
4
12
|
style?: CSSProperties;
|
|
13
|
+
/**
|
|
14
|
+
* - **EN:** Custom styles for the pulse bars
|
|
15
|
+
* - **CN:** 心跳条的自定义样式
|
|
16
|
+
*/
|
|
5
17
|
barStyle?: CSSProperties;
|
|
18
|
+
/**
|
|
19
|
+
* - **EN:** Custom prefix for the component's CSS class.
|
|
20
|
+
* - **CN:** 组件的自定义 CSS 类前缀。
|
|
21
|
+
*/
|
|
6
22
|
prefixCls?: string;
|
|
7
23
|
/**
|
|
8
24
|
* - **EN:** Number of bars, default is `24`
|
|
9
|
-
* - **CN:**
|
|
25
|
+
* - **CN:** 心跳条数量,默认`24`
|
|
10
26
|
*/
|
|
11
27
|
bars?: number;
|
|
12
28
|
/**
|
|
@@ -48,5 +64,5 @@ export interface PulseAnimationProps {
|
|
|
48
64
|
*
|
|
49
65
|
* > 使用 `token.AnimationPulse` 来全局配置 `barMinSize` 和 `barMaxSize` 属性
|
|
50
66
|
*/
|
|
51
|
-
|
|
67
|
+
declare const PulseAnimation: FC<PulseAnimationProps>;
|
|
52
68
|
export default PulseAnimation;
|
|
@@ -29,7 +29,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
// src/components/Animation/Pulse/index.tsx
|
|
30
30
|
var Pulse_exports = {};
|
|
31
31
|
__export(Pulse_exports, {
|
|
32
|
-
PulseAnimation: () => PulseAnimation,
|
|
33
32
|
default: () => Pulse_default
|
|
34
33
|
});
|
|
35
34
|
module.exports = __toCommonJS(Pulse_exports);
|
|
@@ -81,8 +80,4 @@ var PulseAnimation = (props) => {
|
|
|
81
80
|
);
|
|
82
81
|
};
|
|
83
82
|
var Pulse_default = PulseAnimation;
|
|
84
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
-
0 && (module.exports = {
|
|
86
|
-
PulseAnimation
|
|
87
|
-
});
|
|
88
83
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/components/Animation/Pulse/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import type { CSSProperties, FC } from 'react';\nimport { useContext, useMemo } from 'react';\nimport { ConfigProvider } from 'antd';\nimport classNames from 'classnames';\nimport useStyle from './style';\n\nexport interface PulseAnimationProps {\n className?: string;\n style?: CSSProperties;\n barStyle?: CSSProperties;\n prefixCls?: string;\n /**\n * - **EN:** Number of bars, default is `24`\n * - **CN:**
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import type { CSSProperties, FC } from 'react';\nimport { useContext, useMemo } from 'react';\nimport { ConfigProvider } from 'antd';\nimport classNames from 'classnames';\nimport useStyle from './style';\n\nexport interface PulseAnimationProps {\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 styles for the pulse bars\n * - **CN:** 心跳条的自定义样式\n */\n barStyle?: CSSProperties;\n /**\n * - **EN:** Custom prefix for the component's CSS class.\n * - **CN:** 组件的自定义 CSS 类前缀。\n */\n prefixCls?: string;\n /**\n * - **EN:** Number of bars, default is `24`\n * - **CN:** 心跳条数量,默认`24`\n */\n\n bars?: number;\n /**\n * - **EN:** Gap between bars, default is `4px`\n * - **CN:** 心跳柱子间隙,默认`4px`\n */\n barGap?: CSSProperties['gap'];\n /**\n * - **EN:** Background color of the bars, default is theme's `colorFillSecondary`\n * - **CN:** 心跳柱子背景色,默认主题的 `colorFillSecondary`\n */\n barColor?: CSSProperties['backgroundColor'];\n /**\n * - **EN:** Minimum height of the bar, default is `10%`\n * - **CN:** 心跳柱子最小高度,默认`10%`\n */\n // barMinSize?: CSSProperties['height'];\n /**\n * - **EN:** Maximum height of the bar, default is `90%`\n * - **CN:** 心跳柱子最大高度,默认`90%`\n */\n // barMaxSize?: CSSProperties['height'];\n /**\n * - **EN:** Animation duration in seconds, default is `1.6` seconds\n * - **CN:** 动画持续时间,单位秒,默认`1.6`秒\n */\n duration?: number;\n /**\n * - **EN:** Animation delay rate, the delay between bars is calculated based on `{bars *\n * delayRate}`, default is `0.09`\n * - **CN:** 动画延迟的百分比,根据 `{bars * delayRate}` 计算柱子之间的延迟,默认 `0.09`\n */\n delayRate?: number;\n}\n\n/**\n * - **EN:** Pulse animation component, used to indicate loading or processing state\n *\n * > Use `token.AnimationPulse` to globally configure `barMinSize` and `barMaxSize` properties\n *\n * - **CN:** 脉动动画组件,用于表示加载或处理状态\n *\n * > 使用 `token.AnimationPulse` 来全局配置 `barMinSize` 和 `barMaxSize` 属性\n */\nconst PulseAnimation: FC<PulseAnimationProps> = (props) => {\n const {\n bars = 8,\n barGap,\n barColor,\n duration,\n delayRate = 0.09,\n prefixCls: prefixClsInProps,\n className,\n style,\n barStyle,\n } = props;\n const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);\n const prefixCls = getPrefixCls('animation-pulse', prefixClsInProps);\n const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);\n const array = useMemo(() => Array.from({ length: bars }), [bars]);\n\n return wrapCSSVar(\n <div\n className={classNames(prefixCls, hashId, cssVarCls, className)}\n style={{\n gridTemplateColumns: `repeat(${array.length}, 1fr)`,\n gap: barGap,\n ...style,\n }}\n >\n {array.map((_, i) => (\n <div\n // eslint-disable-next-line react/no-array-index-key\n key={i}\n className={`${prefixCls}-bar`}\n style={{\n animationDuration: duration != null ? `${duration}s` : undefined,\n animationDelay: `${(i % array.length) * delayRate}s`,\n backgroundColor: barColor != null ? barColor : undefined,\n ...barStyle,\n }}\n />\n ))}\n </div>\n );\n};\n\nexport default PulseAnimation;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAoC;AACpC,kBAA+B;AAC/B,wBAAuB;AACvB,mBAAqB;AAuErB,IAAM,iBAA0C,CAAC,UAAU;AACzD,QAAM;AAAA,IACJ,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY;AAAA,IACZ,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AACJ,QAAM,EAAE,aAAa,QAAI,yBAAW,2BAAe,aAAa;AAChE,QAAM,YAAY,aAAa,mBAAmB,gBAAgB;AAClE,QAAM,CAAC,YAAY,QAAQ,SAAS,QAAI,aAAAA,SAAS,SAAS;AAC1D,QAAM,YAAQ,sBAAQ,MAAM,MAAM,KAAK,EAAE,QAAQ,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;AAEhE,SAAO;AAAA,IACL;AAAA,MAAC;AAAA;AAAA,QACC,eAAW,kBAAAC,SAAW,WAAW,QAAQ,WAAW,SAAS;AAAA,QAC7D,OAAO;AAAA,UACL,qBAAqB,UAAU,MAAM;AAAA,UACrC,KAAK;AAAA,UACL,GAAG;AAAA,QACL;AAAA;AAAA,MAEC,MAAM,IAAI,CAAC,GAAG,MACb;AAAA,QAAC;AAAA;AAAA,UAEC,KAAK;AAAA,UACL,WAAW,GAAG;AAAA,UACd,OAAO;AAAA,YACL,mBAAmB,YAAY,OAAO,GAAG,cAAc;AAAA,YACvD,gBAAgB,GAAI,IAAI,MAAM,SAAU;AAAA,YACxC,iBAAiB,YAAY,OAAO,WAAW;AAAA,YAC/C,GAAG;AAAA,UACL;AAAA;AAAA,MACF,CACD;AAAA,IACH;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;",
|
|
6
6
|
"names": ["useStyle", "classNames"]
|
|
7
7
|
}
|
|
@@ -6,26 +6,26 @@ export interface BreakLinesProps {
|
|
|
6
6
|
*/
|
|
7
7
|
value: string | undefined;
|
|
8
8
|
/**
|
|
9
|
-
* - **EN:** Whether
|
|
10
|
-
* - **CN:**
|
|
9
|
+
* - **EN:** Whether the line break conversion is enabled
|
|
10
|
+
* - **CN:** 是否启用换行转换
|
|
11
11
|
*
|
|
12
12
|
* @default true
|
|
13
13
|
*/
|
|
14
14
|
enabled?: boolean;
|
|
15
15
|
/**
|
|
16
|
-
* - **EN:**
|
|
17
|
-
* - **CN:**
|
|
16
|
+
* - **EN:** The end-of-line character to use for splitting lines
|
|
17
|
+
* - **CN:** 用于分割行的行结束字符
|
|
18
18
|
*
|
|
19
19
|
* @default '\n'
|
|
20
20
|
*/
|
|
21
21
|
EOL?: string;
|
|
22
22
|
/**
|
|
23
|
-
* - **
|
|
24
|
-
* - **
|
|
23
|
+
* - **EN:** The HTML tag to use for rendering the content
|
|
24
|
+
* - **CN:** 用于渲染内容的 HTML 标签
|
|
25
25
|
*
|
|
26
26
|
* @default false
|
|
27
27
|
*/
|
|
28
|
-
tagName?: 'span' | 'div' | 'i' | 'pre' | (string & {})
|
|
28
|
+
tagName?: false | 'span' | 'div' | 'i' | 'pre' | (string & {});
|
|
29
29
|
/**
|
|
30
30
|
* - **EN:** The CSS class name of the dom node, if `tagName` is set to false, this property is
|
|
31
31
|
* invalid
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/BreakLines/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { createElement, type FC, Fragment, type ReactNode } from 'react';\n\nexport interface BreakLinesProps {\n /**\n * - **EN:** Text content\n * - **CN:** 文本内容\n */\n value: string | undefined;\n /**\n * - **EN:** Whether
|
|
4
|
+
"sourcesContent": ["import { createElement, type FC, Fragment, type ReactNode } from 'react';\n\nexport interface BreakLinesProps {\n /**\n * - **EN:** Text content\n * - **CN:** 文本内容\n */\n value: string | undefined;\n /**\n * - **EN:** Whether the line break conversion is enabled\n * - **CN:** 是否启用换行转换\n *\n * @default true\n */\n enabled?: boolean;\n /**\n * - **EN:** The end-of-line character to use for splitting lines\n * - **CN:** 用于分割行的行结束字符\n *\n * @default '\\n'\n */\n EOL?: string;\n /**\n * - **EN:** The HTML tag to use for rendering the content\n * - **CN:** 用于渲染内容的 HTML 标签\n *\n * @default false\n */\n // eslint-disable-next-line @typescript-eslint/ban-types\n tagName?: false | 'span' | 'div' | 'i' | 'pre' | (string & {});\n /**\n * - **EN:** The CSS class name of the dom node, if `tagName` is set to false, this property is\n * invalid\n * - **CN:** dom节点的css类名,如果`tagName`设置为false,则此属性无效\n */\n className?: string;\n}\n\n/**\n * - **EN:** Output a piece of text, keeping line breaks\n * - **CN:** 输出一段文本,保留换行符\n *\n * @example\n * <BreakLines value=\"hello \\n world\" />;\n * // hello <br/> world\n */\nconst BreakLines: FC<BreakLinesProps> = (props) => {\n const { value, className, tagName = false, enabled = true, EOL = '\\n' } = props;\n\n let content: ReactNode;\n if (value) {\n if (enabled) {\n if (value.includes(EOL)) {\n const segments = value?.split(EOL);\n content = segments.map((str, i) => (\n // eslint-disable-next-line react/no-array-index-key\n <Fragment key={`${str}:${i}`}>\n {str}\n {i !== segments.length - 1 && <br />}\n </Fragment>\n ));\n } else {\n content = value;\n }\n } else {\n content = value;\n }\n } else {\n content = value;\n }\n\n if (tagName) {\n return createElement(tagName, { className }, content);\n } else {\n return <>{content}</>;\n }\n};\n\nexport default BreakLines;\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiE;AA8CjE,IAAM,aAAkC,CAAC,UAAU;AACjD,QAAM,EAAE,OAAO,WAAW,UAAU,OAAO,UAAU,MAAM,MAAM,KAAK,IAAI;AAE1E,MAAI;AACJ,MAAI,OAAO;AACT,QAAI,SAAS;AACX,UAAI,MAAM,SAAS,GAAG,GAAG;AACvB,cAAM,WAAW,+BAAO,MAAM;AAC9B,kBAAU,SAAS,IAAI,CAAC,KAAK;AAAA;AAAA,UAE3B,oCAAC,yBAAS,KAAK,GAAG,OAAO,OACtB,KACA,MAAM,SAAS,SAAS,KAAK,oCAAC,UAAG,CACpC;AAAA,SACD;AAAA,MACH,OAAO;AACL,kBAAU;AAAA,MACZ;AAAA,IACF,OAAO;AACL,gBAAU;AAAA,IACZ;AAAA,EACF,OAAO;AACL,cAAU;AAAA,EACZ;AAEA,MAAI,SAAS;AACX,eAAO,4BAAc,SAAS,EAAE,UAAU,GAAG,OAAO;AAAA,EACtD,OAAO;AACL,WAAO,0DAAG,OAAQ;AAAA,EACpB;AACF;AAEA,IAAO,qBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -13,8 +13,9 @@ export interface ColumnSettingProps<T extends ColumnSettingItem = ColumnSettingI
|
|
|
13
13
|
*/
|
|
14
14
|
onChange?: (nextColumns: T[]) => void;
|
|
15
15
|
/**
|
|
16
|
-
* - **EN:**
|
|
17
|
-
*
|
|
16
|
+
* - **EN:** Set a local storage key for persisting column settings. If not set, local storage is
|
|
17
|
+
* not enabled.
|
|
18
|
+
* - **CN:** 设置一个本地存储的键值,用于持久化保存列设置。如果未设置,则不启用本地存储。
|
|
18
19
|
*/
|
|
19
20
|
storageKey?: string;
|
|
20
21
|
/**
|
|
@@ -47,6 +48,10 @@ export interface ColumnSettingProps<T extends ColumnSettingItem = ColumnSettingI
|
|
|
47
48
|
* - **CN:** “重置”按钮的属性。
|
|
48
49
|
*/
|
|
49
50
|
resetProps?: ButtonProps;
|
|
51
|
+
/**
|
|
52
|
+
* - **EN:** Custom prefix for the component's CSS class.
|
|
53
|
+
* - **CN:** 组件的自定义 CSS 类前缀。
|
|
54
|
+
*/
|
|
50
55
|
prefixCls?: string;
|
|
51
56
|
}
|
|
52
57
|
/**
|
|
@@ -35,9 +35,9 @@ module.exports = __toCommonJS(ColumnSetting_exports);
|
|
|
35
35
|
var import_react = require("react");
|
|
36
36
|
var import_antd = require("antd");
|
|
37
37
|
var import_classnames = __toESM(require("classnames"));
|
|
38
|
-
var import_react_use = require("react-use");
|
|
39
38
|
var import_icons = require("@ant-design/icons");
|
|
40
39
|
var import_hooks = require("../../hooks");
|
|
40
|
+
var import_useLocalStorage = __toESM(require("../../hooks/useLocalStorage"));
|
|
41
41
|
var import_useT = __toESM(require("../../hooks/useT"));
|
|
42
42
|
var import_style = __toESM(require("./style"));
|
|
43
43
|
function ColumnSetting(props) {
|
|
@@ -56,19 +56,16 @@ function ColumnSetting(props) {
|
|
|
56
56
|
const { getPrefixCls } = (0, import_react.useContext)(import_antd.ConfigProvider.ConfigContext);
|
|
57
57
|
const prefixCls = getPrefixCls("column-setting", prefixClsInProps);
|
|
58
58
|
const [wrapCSSVar, hashId, cssVarCls] = (0, import_style.default)(prefixCls);
|
|
59
|
-
const initialSelectedRef = (0, import_react.useRef)(normalizeToSelectedKeys(columns));
|
|
60
59
|
const [open, setOpen] = (0, import_react.useState)(false);
|
|
61
|
-
const [selectedKeys, setSelectedKeys] = (0, import_react.useState)(initialSelectedRef.current);
|
|
62
60
|
const t = (0, import_useT.default)();
|
|
63
|
-
const [selectedKeysFromStorage, setSelectedKeysFromStorage] = (0,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
);
|
|
61
|
+
const [selectedKeysFromStorage, setSelectedKeysFromStorage] = (0, import_useLocalStorage.default)(storageKey, []);
|
|
62
|
+
const [initialKeys, setInitialKeys] = (0, import_react.useState)(selectedKeysFromStorage ?? []);
|
|
63
|
+
const [selectedKeys, setSelectedKeys] = (0, import_react.useState)(initialKeys);
|
|
67
64
|
const storageRef = (0, import_hooks.useRefValue)(storageKey);
|
|
68
65
|
const selectedKeysFromStorageRef = (0, import_hooks.useRefValue)(selectedKeysFromStorage);
|
|
69
66
|
const hasChange = (0, import_react.useMemo)(() => {
|
|
70
|
-
return [...selectedKeys].sort().join(",") !==
|
|
71
|
-
}, [selectedKeys]);
|
|
67
|
+
return [...selectedKeys].sort().join(",") !== initialKeys.join(",");
|
|
68
|
+
}, [selectedKeys, initialKeys]);
|
|
72
69
|
const keys = (0, import_react.useMemo)(() => columns.map((c, i) => String(getColKey(c, i))), [columns]);
|
|
73
70
|
const allSelectableKeys = (0, import_react.useMemo)(
|
|
74
71
|
() => columns.map((c, i) => ({ k: String(getColKey(c, i)), disabled: !!c.disabled })).filter((x) => !x.disabled).map((x) => x.k),
|
|
@@ -108,19 +105,26 @@ function ColumnSetting(props) {
|
|
|
108
105
|
change(ensured, true);
|
|
109
106
|
};
|
|
110
107
|
const handleReset = () => {
|
|
111
|
-
const next =
|
|
108
|
+
const next = initialKeys.length > 0 ? initialKeys : [keys[0]];
|
|
112
109
|
change(next, true);
|
|
113
110
|
};
|
|
111
|
+
const handleOpenChange = (nextOpen) => {
|
|
112
|
+
setOpen(nextOpen);
|
|
113
|
+
if (nextOpen) {
|
|
114
|
+
setInitialKeys(normalizeToSelectedKeys(columns));
|
|
115
|
+
} else {
|
|
116
|
+
setInitialKeys([]);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
114
119
|
(0, import_react.useEffect)(() => {
|
|
115
120
|
const next = normalizeToSelectedKeys(columns);
|
|
116
|
-
initialSelectedRef.current = next;
|
|
117
121
|
change(next, false);
|
|
118
122
|
}, [columns]);
|
|
119
123
|
(0, import_react.useEffect)(() => {
|
|
120
|
-
if (storageRef.current && selectedKeysFromStorageRef.current && selectedKeysFromStorageRef.current.join(",") !==
|
|
124
|
+
if (storageRef.current && selectedKeysFromStorageRef.current && selectedKeysFromStorageRef.current.join(",") !== initialKeys.join(",")) {
|
|
121
125
|
change(selectedKeysFromStorageRef.current, true);
|
|
122
126
|
}
|
|
123
|
-
}, []);
|
|
127
|
+
}, [initialKeys]);
|
|
124
128
|
const dropdownRender = () => /* @__PURE__ */ React.createElement(
|
|
125
129
|
"div",
|
|
126
130
|
{
|
|
@@ -188,7 +192,7 @@ function ColumnSetting(props) {
|
|
|
188
192
|
import_antd.Dropdown,
|
|
189
193
|
{
|
|
190
194
|
open,
|
|
191
|
-
onOpenChange:
|
|
195
|
+
onOpenChange: handleOpenChange,
|
|
192
196
|
trigger: ["click"],
|
|
193
197
|
dropdownRender,
|
|
194
198
|
popupRender: dropdownRender,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/ColumnSetting/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useContext, useEffect, useMemo,
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
6
|
-
"names": ["useStyle", "useT", "classNames"]
|
|
4
|
+
"sourcesContent": ["import { useContext, useEffect, useMemo, useState } from 'react';\nimport { Button, Checkbox, ConfigProvider, 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 useStyle from './style';\n\nexport interface ColumnSettingProps<T extends ColumnSettingItem = ColumnSettingItem> {\n /**\n * - **EN:** The columns to be displayed in the column setting.\n * - **CN:** 列设置中要显示的列。\n */\n columns: T[];\n /**\n * - **EN:** Callback function triggered when the selected columns change.\n * - **CN:** 选中列变化时触发的回调函数。\n */\n onChange?: (nextColumns: T[]) => void;\n /**\n * - **EN:** Set a local storage key for persisting column settings. If not set, local storage is\n * not enabled.\n * - **CN:** 设置一个本地存储的键值,用于持久化保存列设置。如果未设置,则不启用本地存储。\n */\n storageKey?: string;\n /**\n * - **EN:** Function to render custom column titles.\n * - **CN:** 自定义列标题的渲染函数。\n */\n renderColumnTitle?: (col: ColumnSettingItem, index: number) => React.ReactNode;\n /**\n * - **EN:** Props for the button that triggers the dropdown.\n * - **CN:** 触发下拉菜单的按钮属性。\n */\n triggerProps?: ButtonProps;\n /**\n * - **EN:** Props for the dropdown component.\n * - **CN:** 下拉菜单组件的属性。\n */\n dropdownProps?: DropdownProps;\n /**\n * - **EN:** Props for the dropdown popup container.\n * - **CN:** 下拉菜单弹出层容器的属性。\n */\n popupProps?: React.HTMLAttributes<HTMLDivElement>;\n /**\n * - **EN:** Props for the \"Check All\" button.\n * - **CN:** “全选”按钮的属性。\n */\n checkAllProps?: ButtonProps;\n /**\n * - **EN:** Props for the \"Reset\" button.\n * - **CN:** “重置”按钮的属性。\n */\n resetProps?: ButtonProps;\n /**\n * - **EN:** Custom prefix for the component's CSS class.\n * - **CN:** 组件的自定义 CSS 类前缀。\n */\n prefixCls?: string;\n}\n\n/**\n * - **EN:** A component for configuring table column visibility.\n * - **CN:** 用于配置表格列可见性的组件。\n */\nfunction ColumnSetting<T extends ColumnSettingItem = ColumnSettingItem>(props: ColumnSettingProps<T>) {\n const {\n columns,\n storageKey,\n triggerProps,\n dropdownProps,\n popupProps,\n prefixCls: prefixClsInProps,\n checkAllProps,\n resetProps,\n onChange,\n renderColumnTitle,\n } = props;\n const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);\n const prefixCls = getPrefixCls('column-setting', prefixClsInProps);\n const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);\n const [open, setOpen] = useState(false);\n const t = useT();\n const [selectedKeysFromStorage, setSelectedKeysFromStorage] = useLocalStorage<string[]>(storageKey, []);\n const [initialKeys, setInitialKeys] = useState<string[]>(selectedKeysFromStorage ?? []);\n const [selectedKeys, setSelectedKeys] = useState<string[]>(initialKeys);\n const storageRef = useRefValue(storageKey);\n const selectedKeysFromStorageRef = useRefValue(selectedKeysFromStorage);\n const hasChange = useMemo(() => {\n return [...selectedKeys].sort().join(',') !== initialKeys.join(',');\n }, [selectedKeys, initialKeys]);\n\n // Compute keys and selectable keys\n const keys = useMemo(() => columns.map((c, i) => String(getColKey(c, i))), [columns]);\n const allSelectableKeys = useMemo(\n () =>\n columns\n .map((c, i) => ({ k: String(getColKey(c, i)), disabled: !!c.disabled }))\n .filter((x) => !x.disabled)\n .map((x) => x.k),\n [columns]\n );\n const isAllChecked = allSelectableKeys.length > 0 && allSelectableKeys.every((k) => selectedKeys.includes(k));\n const isIndeterminate = selectedKeys.length > 0 && !isAllChecked;\n\n // Fire change event when selectedKeysFromStorage changes\n const change = useRefFunction((nextSelected: string[], fireEvent?: boolean) => {\n setSelectedKeys(nextSelected);\n if (storageKey) {\n setSelectedKeysFromStorage(nextSelected);\n }\n if (fireEvent) {\n const next = columns.map((col, i) => {\n const k = String(getColKey(col, i));\n const visible = nextSelected.includes(k);\n return { ...col, hidden: !visible } as T;\n });\n onChange?.(next as T[]);\n }\n });\n\n // Toggle one column change\n const toggleOne = (key: string, checked: boolean) => {\n const next = new Set(selectedKeys);\n if (checked) {\n next.add(key);\n } else {\n // Keep at least one visible column\n if (selectedKeys.length <= 1) return;\n next.delete(key);\n }\n const nextArr = Array.from(next);\n change(nextArr, true);\n };\n\n // Toggle all columns change\n const handleCheckAll = (checked: boolean) => {\n const nextArr = checked\n ? Array.from(new Set([...selectedKeys, ...allSelectableKeys]))\n : selectedKeys.filter((k) => !allSelectableKeys.includes(k)).slice(0, 1);\n const ensured = checked ? nextArr : nextArr.length > 0 ? nextArr : [keys[0]];\n change(ensured, true);\n };\n\n // Reset to initial selected columns\n const handleReset = () => {\n const next = initialKeys.length > 0 ? initialKeys : [keys[0]];\n change(next, true);\n };\n\n const handleOpenChange = (nextOpen: boolean) => {\n setOpen(nextOpen);\n if (nextOpen) {\n setInitialKeys(normalizeToSelectedKeys(columns));\n } else {\n setInitialKeys([]);\n }\n };\n\n // Sync when columns change\n useEffect(() => {\n const next = normalizeToSelectedKeys(columns);\n change(next, false);\n }, [columns]);\n\n // Fire change on mount if storage exists and differs from initial values\n useEffect(() => {\n if (\n storageRef.current &&\n selectedKeysFromStorageRef.current &&\n selectedKeysFromStorageRef.current.join(',') !== initialKeys.join(',')\n ) {\n change(selectedKeysFromStorageRef.current, true);\n }\n }, [initialKeys]);\n\n const dropdownRender = () => (\n <div\n {...popupProps}\n className={classNames(`${prefixCls}-popup`, popupProps?.className)}\n onClick={(e) => {\n e.stopPropagation();\n popupProps?.onClick?.(e);\n }}\n >\n <Typography.Text className={`${prefixCls}-popup-title`}>{t('components.ColumnSetting.title')}</Typography.Text>\n <Space direction=\"vertical\" className={`${prefixCls}-column-list`} size={12}>\n {columns.map((col, idx) => {\n const k = String(getColKey(col, idx));\n const label = col.title ?? col.dataIndex ?? k;\n const checked = selectedKeys.includes(k);\n const disabled = !!col.disabled;\n const disableUncheck = !disabled && checked && selectedKeys.length <= 1; // 禁止取消最后一个\n return (\n <Checkbox\n key={k}\n className={`${prefixCls}-column-item`}\n disabled={disabled || disableUncheck}\n checked={checked}\n onChange={(e) => toggleOne(k, e.target.checked)}\n >\n <span className={`${prefixCls}-column-item-title`}>{renderColumnTitle?.(col, idx) ?? label}</span>\n </Checkbox>\n );\n })}\n </Space>\n <Divider className={`${prefixCls}-divider`} />\n <div className={`${prefixCls}-footer`}>\n <Button\n type=\"text\"\n {...checkAllProps}\n className={classNames(`${prefixCls}-select-all`, checkAllProps?.className)}\n onClick={(e) => {\n handleCheckAll(!isAllChecked);\n checkAllProps?.onClick?.(e);\n }}\n >\n <Checkbox checked={isAllChecked} indeterminate={isIndeterminate}></Checkbox>\n {t('components.ColumnSetting.selectAll')}\n </Button>\n <Button\n type=\"text\"\n icon={<ReloadOutlined />}\n disabled={!hasChange}\n {...resetProps}\n className={classNames(`${prefixCls}-reset`, resetProps?.className)}\n onClick={(e) => {\n handleReset();\n resetProps?.onClick?.(e);\n }}\n >\n {t('components.ColumnSetting.reset')}\n </Button>\n </div>\n </div>\n );\n\n return wrapCSSVar(\n <Dropdown\n open={open}\n onOpenChange={handleOpenChange}\n trigger={['click']}\n dropdownRender={dropdownRender} // To be compatible with lower versions of antd\n popupRender={dropdownRender}\n placement=\"bottomRight\"\n {...dropdownProps}\n rootClassName={classNames(hashId, cssVarCls, prefixCls, `${prefixCls}-dropdown`, dropdownProps?.className)}\n >\n <Button\n icon={<SettingOutlined />}\n {...triggerProps}\n className={classNames(hashId, cssVarCls, prefixCls, `${prefixCls}-trigger`, triggerProps?.className)}\n />\n </Dropdown>\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface ColumnSettingItem<T = any> extends ColumnType<T> {\n /**\n * - **EN:** Disable toggling visibility for this column.\n * - **CN:** 禁止切换此列的可见性。\n */\n disabled?: boolean;\n}\n\nfunction getColKey(col: ColumnType, idx: number): React.Key {\n return col.key ?? (col.dataIndex as string) ?? idx;\n}\n\nfunction normalizeToSelectedKeys(cols: ColumnType[]): string[] {\n return cols\n .map((c, i) => ({ key: String(getColKey(c, i)), hidden: !!c.hidden }))\n .filter((c) => !c.hidden)\n .map((c) => c.key)\n .sort();\n}\n\nexport default ColumnSetting;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAyD;AACzD,kBAAuF;AAGvF,wBAAuB;AACvB,mBAAgD;AAChD,mBAA4C;AAC5C,6BAA4B;AAC5B,kBAAiB;AACjB,mBAAqB;AA4DrB,SAAS,cAA+D,OAA8B;AACpG,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AACJ,QAAM,EAAE,aAAa,QAAI,yBAAW,2BAAe,aAAa;AAChE,QAAM,YAAY,aAAa,kBAAkB,gBAAgB;AACjE,QAAM,CAAC,YAAY,QAAQ,SAAS,QAAI,aAAAA,SAAS,SAAS;AAC1D,QAAM,CAAC,MAAM,OAAO,QAAI,uBAAS,KAAK;AACtC,QAAM,QAAI,YAAAC,SAAK;AACf,QAAM,CAAC,yBAAyB,0BAA0B,QAAI,uBAAAC,SAA0B,YAAY,CAAC,CAAC;AACtG,QAAM,CAAC,aAAa,cAAc,QAAI,uBAAmB,2BAA2B,CAAC,CAAC;AACtF,QAAM,CAAC,cAAc,eAAe,QAAI,uBAAmB,WAAW;AACtE,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AA,QACL,MAAM,oCAAC,iCAAe;AAAA,QACtB,UAAU,CAAC;AAAA,QACV,GAAG;AAAA,QACJ,eAAW,kBAAAA,SAAW,GAAG,mBAAmB,yCAAY,SAAS;AAAA,QACjE,SAAS,CAAC,MAAM;AAtO1B;AAuOY,sBAAY;AACZ,yDAAY,YAAZ,oCAAsB;AAAA,QACxB;AAAA;AAAA,MAEC,EAAE,gCAAgC;AAAA,IACrC,CACF;AAAA,EACF;AAGF,SAAO;AAAA,IACL;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA,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": ["useStyle", "useT", "useLocalStorage", "classNames"]
|
|
7
7
|
}
|
|
@@ -25,7 +25,7 @@ __export(context_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(context_exports);
|
|
26
26
|
var import_react = require("react");
|
|
27
27
|
var defaultContextValue = {
|
|
28
|
-
lang: "en"
|
|
28
|
+
lang: "en-US"
|
|
29
29
|
};
|
|
30
30
|
var ReactEasyContext = (0, import_react.createContext)(defaultContextValue);
|
|
31
31
|
var context_default = ReactEasyContext;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/ConfigProvider/context.tsx"],
|
|
4
|
-
"sourcesContent": ["import { createContext, type ReactNode } from 'react';\nimport type { Langs } from '../../locales';\nimport type { ConfirmActionProps } from '../ConfirmAction';\nimport type { ModalActionProps } from '../ModalAction';\n\nexport interface ReactEasyContextProps {\n /**\n * - **EN:** Language of the component, used for global configuration, can be 'en-US' or 'zh-CN'\n * - **CN:** 组件的语言,用于全局配置,可以是'en-US'或'zh-CN'\n */\n lang?: Langs;\n /**\n * - **EN:** Get localized text\n * - **CN:** 获取本地化文本\n *\n * @param key Normal text or key of local resource | 普通文本或本地资源的键值\n * @param args Parameters of the localized text | 本地化文本的参数\n *\n * @returns Localized text | 本地化文本\n */\n localize?: <T>(key: T, args?: Record<string, unknown>) => ReactNode;\n\n /**\n * - **EN:** Global configuration for `ConfirmAction` component, which can be used to set default\n * modal title and content for all `ConfirmAction` components in the application.\n * - **CN:** `ConfirmAction`组件的全局配置,可以用来设置应用中所有`ConfirmAction`组件的默认模态框标题和内容。\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ConfirmAction?: ConfirmActionProps<any, never>;\n /** @deprecated Use `ConfirmAction.title` instead */\n defaultConfirmTitle?: ReactNode;\n /** @deprecated Use `ConfirmAction.content` instead */\n defaultConfirmContent?: ReactNode;\n\n /**\n * - **EN:** Global configuration for `DeleteConfirmAction` component, which can be used to set\n * default modal title and content for all `DeleteConfirmAction` components in the application.\n * - **CN:** `DeleteConfirmAction`组件的全局配置,可以用来设置应用中所有`DeleteConfirmAction`组件的默认模态框标题和内容。\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n DeletionConfirmAction?: ConfirmActionProps<any, never>;\n /** @deprecated Use `DeletionConfirmAction.title` instead */\n defaultDeletionConfirmTitle?: ReactNode;\n /** @deprecated Use `DeletionConfirmAction.content` instead */\n defaultDeletionConfirmContent?: ReactNode;\n\n /**\n * - **EN:** Global configuration for `ModalAction` component, which can be used to set default\n * modal title and content for all `ModalAction` components in the application.\n * - **CN:** `ModalAction`组件的全局配置,可以用来设置应用中所有`ModalAction`组件的默认模态框标题和内容。\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ModalAction?: Partial<ModalActionProps<any, any, any, any, any>>;\n}\n\nexport const defaultContextValue: ReactEasyContextProps = {\n lang: 'en',\n};\n\nconst ReactEasyContext = createContext<ReactEasyContextProps>(defaultContextValue);\n\nexport default ReactEasyContext;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA8C;
|
|
4
|
+
"sourcesContent": ["import { createContext, type ReactNode } from 'react';\nimport type { Langs } from '../../locales';\nimport type { 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;AAyDvC,IAAM,sBAA6C;AAAA,EACxD,MAAM;AACR;AAEA,IAAM,uBAAmB,4BAAqC,mBAAmB;AAEjF,IAAO,kBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,8 +2,25 @@ import type { CSSProperties, FC, ReactNode } from 'react';
|
|
|
2
2
|
import type localesEn from '../../locales/langs/en';
|
|
3
3
|
import { type ReactEasyContextProps } from './context';
|
|
4
4
|
export interface ConfigProviderProps extends ReactEasyContextProps {
|
|
5
|
+
/**
|
|
6
|
+
* - **EN:** Child elements of the ConfigProvider
|
|
7
|
+
* - **CN:** ConfigProvider 的子元素
|
|
8
|
+
*/
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
/**
|
|
11
|
+
* - **EN:** Custom prefix for the component's CSS class.
|
|
12
|
+
* - **CN:** 组件的自定义 CSS 类前缀。
|
|
13
|
+
*/
|
|
5
14
|
prefixCls?: string;
|
|
15
|
+
/**
|
|
16
|
+
* - **EN:** Custom class name for the root element
|
|
17
|
+
* - **CN:** 根元素的自定义类名
|
|
18
|
+
*/
|
|
6
19
|
className?: string;
|
|
20
|
+
/**
|
|
21
|
+
* - **EN:** Custom styles for the root element
|
|
22
|
+
* - **CN:** 根元素的自定义样式
|
|
23
|
+
*/
|
|
7
24
|
style?: CSSProperties;
|
|
8
25
|
/**
|
|
9
26
|
* - **EN:** Custom localization resources, if `lang` exists, it will override the localization
|
|
@@ -11,7 +28,6 @@ export interface ConfigProviderProps extends ReactEasyContextProps {
|
|
|
11
28
|
* - **CN:** 自定义本地化资源,如果`lang`存在,则会覆盖该语言的本地化资源,否则,会添加一种新的语言
|
|
12
29
|
*/
|
|
13
30
|
locales?: Partial<typeof localesEn>;
|
|
14
|
-
children: ReactNode;
|
|
15
31
|
}
|
|
16
32
|
/**
|
|
17
33
|
* - **EN:** Provide global configuration for AntdHelper
|
|
@@ -44,22 +44,29 @@ var ConfigProvider = (props) => {
|
|
|
44
44
|
const { getPrefixCls, rootPrefixCls } = (0, import_react.useContext)(import_antd.ConfigProvider.ConfigContext);
|
|
45
45
|
const prefixCls = getPrefixCls("react-easy", prefixClsInProps);
|
|
46
46
|
const [wrapCSSVar, hashId, cssVarCls] = (0, import_style.default)(prefixCls, rootPrefixCls);
|
|
47
|
+
const contextValue = (0, import_react.useMemo)(
|
|
48
|
+
() => {
|
|
49
|
+
if (langInProps !== import_locales.default.language) {
|
|
50
|
+
import_locales.default.changeLanguage(langInProps || "en-US");
|
|
51
|
+
}
|
|
52
|
+
return restProps;
|
|
53
|
+
},
|
|
54
|
+
// eslint-disable-next-line @tiny-codes/react-hooks/exhaustive-deps
|
|
55
|
+
[langInProps, ...Object.values(restProps)]
|
|
56
|
+
);
|
|
47
57
|
(0, import_react.useEffect)(() => {
|
|
48
58
|
if (userLocales) {
|
|
49
|
-
const lang = langInProps || "en";
|
|
59
|
+
const lang = langInProps || "en-US";
|
|
50
60
|
if (lang && import_locales.langs.includes(lang)) {
|
|
51
61
|
import_locales.default.removeResourceBundle(lang, "translation");
|
|
52
62
|
import_locales.default.addResourceBundle(lang, "translation", { ...import_locales.resources[lang].translation, ...userLocales });
|
|
53
63
|
} else {
|
|
54
|
-
import_locales.default.addResourceBundle(lang, "translation", { ...import_locales.resources
|
|
64
|
+
import_locales.default.addResourceBundle(lang, "translation", { ...import_locales.resources["en-US"].translation, ...userLocales });
|
|
55
65
|
}
|
|
56
66
|
}
|
|
57
67
|
}, [langInProps, userLocales]);
|
|
58
|
-
(0, import_react.useEffect)(() => {
|
|
59
|
-
import_locales.default.changeLanguage(langInProps || "en");
|
|
60
|
-
}, [langInProps]);
|
|
61
68
|
return wrapCSSVar(
|
|
62
|
-
/* @__PURE__ */ React.createElement(import_context.default.Provider, { value:
|
|
69
|
+
/* @__PURE__ */ React.createElement(import_context.default.Provider, { value: contextValue }, /* @__PURE__ */ React.createElement("div", { className: (0, import_classnames.default)(hashId, cssVarCls, prefixCls, className), style }, children))
|
|
63
70
|
);
|
|
64
71
|
};
|
|
65
72
|
ConfigProvider.displayName = "ReactEasyConfigProvider";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/ConfigProvider/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import type { CSSProperties, FC, ReactNode } from 'react';\nimport { useContext, useEffect } from 'react';\nimport { ConfigProvider as ReactConfigProvider } from 'antd';\nimport classNames from 'classnames';\nimport locales, { langs, resources } from '../../locales';\nimport type localesEn from '../../locales/langs/en';\nimport ReactEasyContext, { type ReactEasyContextProps } from './context';\nimport useStyle from './style';\n\nexport interface ConfigProviderProps extends ReactEasyContextProps {\n prefixCls?: string;\n className?: string;\n style?: CSSProperties;\n /**\n * - **EN:** Custom localization resources, if `lang` exists, it will override the localization\n * resources of that language, otherwise, it will add a new language\n * - **CN:** 自定义本地化资源,如果`lang`存在,则会覆盖该语言的本地化资源,否则,会添加一种新的语言\n */\n locales?: Partial<typeof localesEn>;\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,
|
|
4
|
+
"sourcesContent": ["import type { CSSProperties, FC, ReactNode } from 'react';\nimport { useContext, useEffect, useMemo } from 'react';\nimport { ConfigProvider as ReactConfigProvider } from 'antd';\nimport classNames from 'classnames';\nimport locales, { langs, resources } from '../../locales';\nimport type localesEn from '../../locales/langs/en';\nimport ReactEasyContext, { type ReactEasyContextProps } from './context';\nimport useStyle from './style';\n\nexport interface ConfigProviderProps extends 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,mBAA+C;AAC/C,kBAAsD;AACtD,wBAAuB;AACvB,qBAA0C;AAE1C,qBAA6D;AAC7D,mBAAqB;AAmCrB,IAAM,iBAA0C,CAAC,UAAU;AACzD,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,cA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