starry-sky-ui 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +644 -0
  2. package/dist/ChatInput/index.d.ts +23 -0
  3. package/dist/ChatInput/index.d.ts.map +1 -0
  4. package/dist/ChatInput/index.js +50 -0
  5. package/dist/ChatInput/index.js.map +1 -0
  6. package/dist/ChatInput/index.scss +170 -0
  7. package/dist/ContentRenderer/index.d.ts +15 -0
  8. package/dist/ContentRenderer/index.d.ts.map +1 -0
  9. package/dist/ContentRenderer/index.js +73 -0
  10. package/dist/ContentRenderer/index.js.map +1 -0
  11. package/dist/ContentRenderer/index.scss +203 -0
  12. package/dist/Input/Textarea.d.ts +46 -0
  13. package/dist/Input/Textarea.d.ts.map +1 -0
  14. package/dist/Input/Textarea.js +42 -0
  15. package/dist/Input/Textarea.js.map +1 -0
  16. package/dist/Input/index.d.ts +57 -0
  17. package/dist/Input/index.d.ts.map +1 -0
  18. package/dist/Input/index.js +87 -0
  19. package/dist/Input/index.js.map +1 -0
  20. package/dist/Input/index.scss +498 -0
  21. package/dist/Message/index.d.ts +36 -0
  22. package/dist/Message/index.d.ts.map +1 -0
  23. package/dist/Message/index.js +184 -0
  24. package/dist/Message/index.js.map +1 -0
  25. package/dist/Message/index.scss +147 -0
  26. package/dist/Modal/index.d.ts +57 -0
  27. package/dist/Modal/index.d.ts.map +1 -0
  28. package/dist/Modal/index.js +99 -0
  29. package/dist/Modal/index.js.map +1 -0
  30. package/dist/Modal/index.scss +250 -0
  31. package/dist/Pagination/index.d.ts +37 -0
  32. package/dist/Pagination/index.d.ts.map +1 -0
  33. package/dist/Pagination/index.js +98 -0
  34. package/dist/Pagination/index.js.map +1 -0
  35. package/dist/Pagination/index.scss +393 -0
  36. package/dist/Select/index.d.ts +56 -0
  37. package/dist/Select/index.d.ts.map +1 -0
  38. package/dist/Select/index.js +153 -0
  39. package/dist/Select/index.js.map +1 -0
  40. package/dist/Select/index.scss +251 -0
  41. package/dist/Starfield/index.d.ts +20 -0
  42. package/dist/Starfield/index.d.ts.map +1 -0
  43. package/dist/Starfield/index.js +39 -0
  44. package/dist/Starfield/index.js.map +1 -0
  45. package/dist/Starfield/index.scss +61 -0
  46. package/dist/Table/index.d.ts +72 -0
  47. package/dist/Table/index.d.ts.map +1 -0
  48. package/dist/Table/index.js +192 -0
  49. package/dist/Table/index.js.map +1 -0
  50. package/dist/Table/index.scss +377 -0
  51. package/dist/index.d.ts +22 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +11 -0
  54. package/dist/index.js.map +1 -0
  55. package/dist/types.d.ts +12 -0
  56. package/dist/types.d.ts.map +1 -0
  57. package/dist/types.js +3 -0
  58. package/dist/types.js.map +1 -0
  59. package/package.json +57 -0
@@ -0,0 +1,251 @@
1
+ .select-wrapper {
2
+ position: relative;
3
+ width: 100%;
4
+ user-select: none;
5
+ display: inline-block;
6
+
7
+ // ---- 尺寸 ----
8
+ &.select-small {
9
+ .select-trigger {
10
+ padding: 0.3rem 0.6rem;
11
+ min-height: 28px;
12
+ }
13
+ .select-value,
14
+ .select-search-input {
15
+ font-size: 0.8rem;
16
+ }
17
+ }
18
+
19
+ &.select-middle {
20
+ .select-trigger {
21
+ padding: 0.7rem 1rem;
22
+ min-height: 40px;
23
+ }
24
+ .select-value,
25
+ .select-search-input {
26
+ font-size: 0.95rem;
27
+ }
28
+ }
29
+
30
+ &.select-large {
31
+ .select-trigger {
32
+ padding: 0.9rem 1.2rem;
33
+ min-height: 48px;
34
+ }
35
+ .select-value,
36
+ .select-search-input {
37
+ font-size: 1.05rem;
38
+ }
39
+ }
40
+
41
+ &.select-disabled {
42
+ opacity: 0.5;
43
+ pointer-events: none;
44
+ }
45
+ }
46
+
47
+ .select-trigger {
48
+ display: flex;
49
+ align-items: center;
50
+ justify-content: space-between;
51
+ gap: 8px;
52
+ background: rgba(255, 255, 255, 0.06);
53
+ border: 1px solid rgba(255, 255, 255, 0.12);
54
+ border-radius: 10px;
55
+ cursor: pointer;
56
+ transition: all 0.3s ease;
57
+ box-sizing: border-box;
58
+ width: 100%;
59
+ outline: none;
60
+
61
+ &:hover {
62
+ border-color: rgba(139, 92, 246, 0.4);
63
+ }
64
+
65
+ &:focus-within {
66
+ border-color: #8b5cf6;
67
+ box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
68
+ }
69
+
70
+ &.select-trigger-open {
71
+ border-color: #8b5cf6;
72
+ box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
73
+ }
74
+ }
75
+
76
+ // 无边框
77
+ .select-borderless {
78
+ .select-trigger {
79
+ border-color: transparent;
80
+ background: transparent;
81
+
82
+ &:hover {
83
+ border-color: transparent;
84
+ background: rgba(255, 255, 255, 0.04);
85
+ }
86
+ }
87
+ }
88
+
89
+ .select-value {
90
+ flex: 1;
91
+ font-size: 0.95rem;
92
+ color: #fff;
93
+ overflow: hidden;
94
+ text-overflow: ellipsis;
95
+ white-space: nowrap;
96
+
97
+ &.select-placeholder {
98
+ color: #555;
99
+ }
100
+ }
101
+
102
+ .select-search-input {
103
+ flex: 1;
104
+ border: none;
105
+ outline: none;
106
+ background: transparent;
107
+ color: #fff;
108
+ padding: 0;
109
+ min-width: 0;
110
+ font-size: 0.95rem;
111
+ line-height: inherit;
112
+
113
+ &::placeholder {
114
+ color: #555;
115
+ }
116
+
117
+ &[readonly] {
118
+ cursor: pointer;
119
+ }
120
+ }
121
+
122
+ .select-suffix {
123
+ display: flex;
124
+ align-items: center;
125
+ gap: 6px;
126
+ flex-shrink: 0;
127
+ }
128
+
129
+ .select-arrow {
130
+ flex-shrink: 0;
131
+ font-size: 0.6rem;
132
+ color: #888;
133
+ transition: transform 0.3s ease;
134
+ line-height: 1;
135
+
136
+ &.select-arrow-up {
137
+ transform: rotate(180deg);
138
+ }
139
+ }
140
+
141
+ .select-clear {
142
+ display: inline-flex;
143
+ align-items: center;
144
+ justify-content: center;
145
+ width: 16px;
146
+ height: 16px;
147
+ border-radius: 50%;
148
+ font-size: 10px;
149
+ color: #fff;
150
+ background: rgba(255, 255, 255, 0.25);
151
+ cursor: pointer;
152
+ transition: all 0.2s ease;
153
+
154
+ &:hover {
155
+ background: rgba(255, 255, 255, 0.4);
156
+ }
157
+ }
158
+
159
+ .select-dropdown {
160
+ position: absolute;
161
+ top: calc(100% + 6px);
162
+ left: 0;
163
+ right: 0;
164
+ background: rgba(30, 30, 46, 0.97);
165
+ border: 1px solid rgba(139, 92, 246, 0.25);
166
+ border-radius: 12px;
167
+ box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
168
+ backdrop-filter: blur(20px);
169
+ z-index: 1050;
170
+ max-height: 240px;
171
+ overflow-y: auto;
172
+ animation: selectFadeIn 0.2s ease;
173
+
174
+ &.select-dropdown-auto {
175
+ right: auto;
176
+ min-width: 100%;
177
+ }
178
+
179
+ &::-webkit-scrollbar {
180
+ width: 4px;
181
+ }
182
+ &::-webkit-scrollbar-track {
183
+ background: transparent;
184
+ }
185
+ &::-webkit-scrollbar-thumb {
186
+ background: rgba(139, 92, 246, 0.3);
187
+ border-radius: 2px;
188
+ }
189
+ }
190
+
191
+ .select-option {
192
+ display: flex;
193
+ align-items: center;
194
+ justify-content: space-between;
195
+ padding: 0.65rem 1rem;
196
+ font-size: 0.95rem;
197
+ color: #ccc;
198
+ cursor: pointer;
199
+ transition: all 0.2s ease;
200
+ min-height: 40px;
201
+ box-sizing: border-box;
202
+
203
+ &:hover,
204
+ &.select-option-hover {
205
+ background: rgba(139, 92, 246, 0.1);
206
+ color: #fff;
207
+ }
208
+
209
+ &.select-option-active {
210
+ color: #8b5cf6;
211
+ background: rgba(139, 92, 246, 0.08);
212
+ font-weight: 500;
213
+ }
214
+
215
+ &.select-option-disabled {
216
+ color: #555;
217
+ cursor: not-allowed;
218
+ background: transparent;
219
+ }
220
+
221
+ &:first-child {
222
+ border-radius: 12px 12px 0 0;
223
+ }
224
+ &:last-child {
225
+ border-radius: 0 0 12px 12px;
226
+ }
227
+ }
228
+
229
+ .select-check {
230
+ flex-shrink: 0;
231
+ font-size: 0.85rem;
232
+ color: #8b5cf6;
233
+ }
234
+
235
+ .select-empty {
236
+ padding: 1.5rem;
237
+ text-align: center;
238
+ color: #666;
239
+ font-size: 0.9rem;
240
+ }
241
+
242
+ @keyframes selectFadeIn {
243
+ from {
244
+ opacity: 0;
245
+ transform: translateY(-6px) scale(0.97);
246
+ }
247
+ to {
248
+ opacity: 1;
249
+ transform: translateY(0) scale(1);
250
+ }
251
+ }
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import './index.scss';
3
+ export interface StarfieldProps {
4
+ /** 星星数量 */
5
+ starCount?: number;
6
+ /** 自定义颜色列表(支持 hex / rgb 等 CSS 合法颜色值) */
7
+ starColors?: string[];
8
+ /** 闪烁动画最大延迟时间(秒) */
9
+ time?: number;
10
+ /** 自定义类名 */
11
+ className?: string;
12
+ }
13
+ /**
14
+ * 星空背景组件
15
+ * - 使用 DocumentFragment 批量追加 DOM,减少 reflow 次数
16
+ * - 使用 CSS 自定义属性传递颜色,避免动态生成大量 style 标签
17
+ */
18
+ declare const Starfield: React.FC<StarfieldProps>;
19
+ export default Starfield;
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Starfield/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAC;AACjD,OAAO,cAAc,CAAC;AAEtB,MAAM,WAAW,cAAc;IAC7B,WAAW;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wCAAwC;IACxC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,oBAAoB;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAID;;;;GAIG;AACH,QAAA,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAwCvC,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from 'react';
3
+ import './index.scss';
4
+ const STAR_TYPES = ['small', 'medium', 'large'];
5
+ /**
6
+ * 星空背景组件
7
+ * - 使用 DocumentFragment 批量追加 DOM,减少 reflow 次数
8
+ * - 使用 CSS 自定义属性传递颜色,避免动态生成大量 style 标签
9
+ */
10
+ const Starfield = ({ starCount = 350, starColors = ['#8b5cf6', '#3b82f6', '#ffffff'], time = 3, className = '', }) => {
11
+ const starfieldRef = useRef(null);
12
+ useEffect(() => {
13
+ const starfield = starfieldRef.current;
14
+ if (!starfield)
15
+ return;
16
+ // 使用 DocumentFragment 批量追加,只触发一次 reflow
17
+ const fragment = document.createDocumentFragment();
18
+ for (let i = 0; i < starCount; i++) {
19
+ const star = document.createElement('div');
20
+ const starType = STAR_TYPES[Math.floor(Math.random() * STAR_TYPES.length)];
21
+ const color = starColors[Math.floor(Math.random() * starColors.length)];
22
+ star.className = `adui-star ${starType}`;
23
+ star.style.left = `${Math.random() * 100}%`;
24
+ star.style.top = `${Math.random() * 100}%`;
25
+ star.style.animationDelay = `${Math.random() * time}s`;
26
+ // 通过 CSS 自定义属性传递颜色,避免为每种颜色生成单独 class
27
+ star.style.setProperty('--star-color', color);
28
+ star.style.setProperty('--star-glow', `${color}80`);
29
+ fragment.appendChild(star);
30
+ }
31
+ starfield.appendChild(fragment);
32
+ return () => {
33
+ starfield.innerHTML = '';
34
+ };
35
+ }, [starCount, starColors, time]);
36
+ return _jsx("div", { ref: starfieldRef, className: `adui-starfield ${className}` });
37
+ };
38
+ export default Starfield;
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Starfield/index.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC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G,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,GAAG,CAAC;YAEvD,qCAAqC;YACrC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;YAC9C,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,aAAa,EAAE,GAAG,KAAK,IAAI,CAAC,CAAC;YAEpD,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;SAC5B;QAED,SAAS,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAEhC,OAAO,GAAG,EAAE;YACV,SAAS,CAAC,SAAS,GAAG,EAAE,CAAC;QAC3B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,SAAS,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC;IAElC,OAAO,cAAK,GAAG,EAAE,YAAY,EAAE,SAAS,EAAE,kBAAkB,SAAS,EAAE,GAAI,CAAC;AAC9E,CAAC,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,61 @@
1
+ .adui-starfield {
2
+ top: 0;
3
+ left: 0;
4
+ width: 100%;
5
+ height: 100%;
6
+ z-index: 1;
7
+ overflow: hidden;
8
+ }
9
+
10
+ .adui-star {
11
+ position: absolute;
12
+ background: var(--star-color, #ffffff);
13
+ border-radius: 50%;
14
+ animation: adui-twinkle 3s infinite ease-in-out;
15
+ box-shadow: 0 0 10px var(--star-glow, rgba(255, 255, 255, 0.5));
16
+
17
+ &.small {
18
+ width: 1px;
19
+ height: 1px;
20
+ }
21
+
22
+ &.medium {
23
+ width: 2px;
24
+ height: 2px;
25
+ }
26
+
27
+ &.large {
28
+ width: 3px;
29
+ height: 3px;
30
+ }
31
+ }
32
+
33
+ @keyframes adui-twinkle {
34
+ 0%, 100% {
35
+ opacity: 0.3;
36
+ transform: scale(1);
37
+ }
38
+ 50% {
39
+ opacity: 1;
40
+ transform: scale(1.2);
41
+ }
42
+ }
43
+
44
+ @media (max-width: 768px) {
45
+ .adui-star {
46
+ &.small {
47
+ width: 0.8px;
48
+ height: 0.8px;
49
+ }
50
+
51
+ &.medium {
52
+ width: 1.5px;
53
+ height: 1.5px;
54
+ }
55
+
56
+ &.large {
57
+ width: 2px;
58
+ height: 2px;
59
+ }
60
+ }
61
+ }
@@ -0,0 +1,72 @@
1
+ import React from 'react';
2
+ import './index.scss';
3
+ export interface ColumnType<T = any> {
4
+ title: string;
5
+ dataIndex?: string;
6
+ key?: string;
7
+ render?: (value: any, record: T, index: number) => React.ReactNode;
8
+ width?: number | string;
9
+ align?: 'left' | 'center' | 'right';
10
+ sorter?: boolean | ((a: T, b: T) => number);
11
+ sortOrder?: 'ascend' | 'descend' | null;
12
+ className?: string;
13
+ fixed?: 'left' | 'right';
14
+ visible?: boolean;
15
+ minWidth?: number;
16
+ }
17
+ export interface PaginationConfig {
18
+ current?: number;
19
+ defaultCurrent?: number;
20
+ pageSize?: number;
21
+ defaultPageSize?: number;
22
+ total?: number;
23
+ showSizeChanger?: boolean;
24
+ pageSizeOptions?: number[];
25
+ showTotal?: boolean;
26
+ onChange?: (page: number, pageSize: number) => void;
27
+ simple?: boolean;
28
+ }
29
+ export interface RowSelectionType<T = any> {
30
+ selectedRowKeys?: string[];
31
+ defaultSelectedRowKeys?: string[];
32
+ onChange?: (selectedRowKeys: string[], selectedRows: T[]) => void;
33
+ getCheckboxProps?: (record: T) => {
34
+ disabled?: boolean;
35
+ };
36
+ columnWidth?: number | string;
37
+ }
38
+ export interface TableProps<T = any> {
39
+ columns: ColumnType<T>[];
40
+ dataSource: T[];
41
+ rowKey?: string | ((record: T) => string);
42
+ pagination?: false | PaginationConfig;
43
+ loading?: boolean;
44
+ emptyText?: React.ReactNode;
45
+ size?: 'small' | 'middle' | 'large';
46
+ bordered?: boolean;
47
+ showHeader?: boolean;
48
+ className?: string;
49
+ onRow?: (record: T, index: number) => {
50
+ onClick?: () => void;
51
+ style?: React.CSSProperties;
52
+ className?: string;
53
+ } | void;
54
+ rowSelection?: RowSelectionType<T>;
55
+ scroll?: {
56
+ y?: number;
57
+ };
58
+ defaultSortBy?: {
59
+ columnKey: string;
60
+ order: 'ascend' | 'descend';
61
+ };
62
+ onChange?: (pagination: {
63
+ current: number;
64
+ pageSize: number;
65
+ }, sorter: {
66
+ columnKey: string;
67
+ order: 'ascend' | 'descend' | null;
68
+ }) => void;
69
+ }
70
+ declare function Table<T extends Record<string, any>>(props: TableProps<T>): React.ReactElement;
71
+ export default Table;
72
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Table/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAC;AAC9D,OAAO,cAAc,CAAC;AAItB,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,GAAG;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,KAAK,CAAC,SAAS,CAAC;IACnE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpC,MAAM,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,MAAM,CAAC,CAAC;IAC5C,SAAS,CAAC,EAAE,QAAQ,GAAG,SAAS,GAAG,IAAI,CAAC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACzB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CA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,OAAO,CAAC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK;QAAE,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;QAAC,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACvH,YAAY,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,CAAC,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACxB,aAAa,CAAC,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,CAAA;KAAE,CAAC;IACnE,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,EAAE,MAAM,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,GAAG,IAAI,CAAA;KAAE,KAAK,IAAI,CAAC;CAC3I;AAYD,iBAAS,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,YAAY,CAmVtF;AAED,eAAe,KAAK,CAAC"}
@@ -0,0 +1,192 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ import { useState, useMemo, useCallback } from 'react';
3
+ import './index.scss';
4
+ /* ========== 工具函数 ========== */
5
+ function getRowKey(record, rowKey, index) {
6
+ var _a, _b;
7
+ if (typeof rowKey === 'function')
8
+ return rowKey(record);
9
+ if (rowKey)
10
+ return String(record[rowKey]);
11
+ return String((_b = (_a = record.key) !== null && _a !== void 0 ? _a : record.id) !== null && _b !== void 0 ? _b : index);
12
+ }
13
+ /* ========== Table 组件 ========== */
14
+ function Table(props) {
15
+ var _a, _b, _c, _d, _e, _f, _g;
16
+ const { columns: rawColumns, dataSource, rowKey, pagination: paginationProp, loading = false, emptyText = '暂无数据', size = 'large', bordered = false, showHeader = true, className = '', onRow, rowSelection, scroll, defaultSortBy, onChange, } = props;
17
+ // ---- 分页状态 ----
18
+ const defaultPageSize = typeof paginationProp === 'object' ? ((_b = (_a = paginationProp.defaultPageSize) !== null && _a !== void 0 ? _a : paginationProp.pageSize) !== null && _b !== void 0 ? _b : 10) : 10;
19
+ const defaultCurrent = typeof paginationProp === 'object' ? ((_d = (_c = paginationProp.defaultCurrent) !== null && _c !== void 0 ? _c : paginationProp.current) !== null && _d !== void 0 ? _d : 1) : 1;
20
+ const [page, setPage] = useState(defaultCurrent);
21
+ const [pageSize, setPageSize] = useState(defaultPageSize);
22
+ const controlledPage = typeof paginationProp === 'object' && paginationProp.current !== undefined ? paginationProp.current : page;
23
+ const controlledPageSize = typeof paginationProp === 'object' && paginationProp.pageSize !== undefined ? paginationProp.pageSize : pageSize;
24
+ // ---- 排序状态 ----
25
+ const [sortConfig, setSortConfig] = useState(defaultSortBy ? { columnKey: defaultSortBy.columnKey, order: defaultSortBy.order } : null);
26
+ // ---- 行选择状态 ----
27
+ const [innerSelectedKeys, setInnerSelectedKeys] = useState((_e = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.defaultSelectedRowKeys) !== null && _e !== void 0 ? _e : []);
28
+ const selectedKeys = (_f = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.selectedRowKeys) !== null && _f !== void 0 ? _f : innerSelectedKeys;
29
+ // ---- 过滤隐藏列 ----
30
+ const columns = useMemo(() => rawColumns.filter((c) => c.visible !== false), [rawColumns]);
31
+ // ---- 排序处理 ----
32
+ const sortedData = useMemo(() => {
33
+ if (!sortConfig)
34
+ return dataSource;
35
+ const col = columns.find((c) => { var _a; return ((_a = c.key) !== null && _a !== void 0 ? _a : c.dataIndex) === sortConfig.columnKey; });
36
+ if (!(col === null || col === void 0 ? void 0 : col.sorter))
37
+ return dataSource;
38
+ const fn = col.sorter;
39
+ const compare = typeof fn === 'function' ? fn : undefined;
40
+ if (!compare)
41
+ return dataSource;
42
+ return [...dataSource].sort((a, b) => {
43
+ const result = compare(a, b);
44
+ return sortConfig.order === 'ascend' ? result : -result;
45
+ });
46
+ }, [dataSource, sortConfig, columns]);
47
+ // ---- 分页计算 ----
48
+ const total = typeof paginationProp === 'object' && paginationProp.total !== undefined ? paginationProp.total : sortedData.length;
49
+ const totalPages = Math.max(1, Math.ceil(total / controlledPageSize));
50
+ const safePage = Math.min(controlledPage, totalPages);
51
+ const pagedData = useMemo(() => {
52
+ if (paginationProp === false)
53
+ return sortedData;
54
+ const start = (safePage - 1) * controlledPageSize;
55
+ return sortedData.slice(start, start + controlledPageSize);
56
+ }, [sortedData, paginationProp, safePage, controlledPageSize]);
57
+ // ---- 排序点击 ----
58
+ const handleSort = useCallback((columnKey) => {
59
+ const col = columns.find((c) => { var _a; return ((_a = c.key) !== null && _a !== void 0 ? _a : c.dataIndex) === columnKey; });
60
+ if (!(col === null || col === void 0 ? void 0 : col.sorter))
61
+ return;
62
+ let newOrder = 'ascend';
63
+ if ((sortConfig === null || sortConfig === void 0 ? void 0 : sortConfig.columnKey) === columnKey) {
64
+ if (sortConfig.order === 'ascend')
65
+ newOrder = 'descend';
66
+ else
67
+ newOrder = null;
68
+ }
69
+ const newConfig = newOrder ? { columnKey, order: newOrder } : null;
70
+ setSortConfig(newConfig);
71
+ setPage(1);
72
+ onChange === null || onChange === void 0 ? void 0 : onChange({ current: 1, pageSize: controlledPageSize }, newConfig !== null && newConfig !== void 0 ? newConfig : { columnKey: columnKey, order: null });
73
+ }, [columns, sortConfig, controlledPageSize, onChange]);
74
+ // ---- 分页跳转 ----
75
+ const goToPage = useCallback((p) => {
76
+ var _a;
77
+ if (p < 1 || p > totalPages)
78
+ return;
79
+ setPage(p);
80
+ if (paginationProp !== false && typeof paginationProp === 'object') {
81
+ (_a = paginationProp.onChange) === null || _a === void 0 ? void 0 : _a.call(paginationProp, p, controlledPageSize);
82
+ }
83
+ onChange === null || onChange === void 0 ? void 0 : onChange({ current: p, pageSize: controlledPageSize }, sortConfig !== null && sortConfig !== void 0 ? sortConfig : { columnKey: '', order: null });
84
+ }, [totalPages, paginationProp, controlledPageSize, onChange, sortConfig]);
85
+ const changePageSize = useCallback((newSize) => {
86
+ var _a;
87
+ setPageSize(newSize);
88
+ setPage(1);
89
+ if (paginationProp !== false && typeof paginationProp === 'object') {
90
+ (_a = paginationProp.onChange) === null || _a === void 0 ? void 0 : _a.call(paginationProp, 1, newSize);
91
+ }
92
+ }, [paginationProp]);
93
+ // ---- 行选择 ----
94
+ const toggleSelect = useCallback((key, record) => {
95
+ var _a, _b, _c;
96
+ if ((_b = (_a = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.getCheckboxProps) === null || _a === void 0 ? void 0 : _a.call(rowSelection, record)) === null || _b === void 0 ? void 0 : _b.disabled)
97
+ return;
98
+ const next = selectedKeys.includes(key)
99
+ ? selectedKeys.filter((k) => k !== key)
100
+ : [...selectedKeys, key];
101
+ if (!(rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.selectedRowKeys))
102
+ setInnerSelectedKeys(next);
103
+ const selectedRows = dataSource.filter((r) => next.includes(getRowKey(r, rowKey)));
104
+ (_c = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.onChange) === null || _c === void 0 ? void 0 : _c.call(rowSelection, next, selectedRows);
105
+ }, [selectedKeys, rowSelection, dataSource, rowKey]);
106
+ const toggleSelectAll = useCallback(() => {
107
+ var _a;
108
+ if (pagedData.length === 0)
109
+ return;
110
+ const allKeys = pagedData.map((r, i) => getRowKey(r, rowKey, i));
111
+ const filteredKeys = allKeys.filter((k) => {
112
+ var _a, _b;
113
+ const record = pagedData.find((r, i) => getRowKey(r, rowKey, i) === k);
114
+ return !((_b = (_a = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.getCheckboxProps) === null || _a === void 0 ? void 0 : _a.call(rowSelection, record)) === null || _b === void 0 ? void 0 : _b.disabled);
115
+ });
116
+ const allSelected = filteredKeys.every((k) => selectedKeys.includes(k));
117
+ const next = allSelected
118
+ ? selectedKeys.filter((k) => !filteredKeys.includes(k))
119
+ : [...new Set([...selectedKeys, ...filteredKeys])];
120
+ if (!(rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.selectedRowKeys))
121
+ setInnerSelectedKeys(next);
122
+ const selectedRows = dataSource.filter((r) => next.includes(getRowKey(r, rowKey)));
123
+ (_a = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.onChange) === null || _a === void 0 ? void 0 : _a.call(rowSelection, next, selectedRows);
124
+ }, [pagedData, selectedKeys, rowSelection, dataSource, rowKey]);
125
+ // ---- 渲染 ----
126
+ const showPagination = paginationProp !== false && total > 0;
127
+ const hasRowSelection = !!rowSelection;
128
+ const tableClass = [
129
+ 'adui-table',
130
+ `table-size-${size}`,
131
+ bordered ? 'table-bordered' : '',
132
+ loading ? 'table-loading' : '',
133
+ className,
134
+ ]
135
+ .filter(Boolean)
136
+ .join(' ');
137
+ const renderPagination = () => {
138
+ var _a, _b, _c, _d;
139
+ if (!showPagination)
140
+ return null;
141
+ const pag = typeof paginationProp === 'object' ? paginationProp : {};
142
+ const showSizeChanger = (_a = pag.showSizeChanger) !== null && _a !== void 0 ? _a : false;
143
+ const pageSizeOptions = (_b = pag.pageSizeOptions) !== null && _b !== void 0 ? _b : [10, 20, 50, 100];
144
+ const showTotal = (_c = pag.showTotal) !== null && _c !== void 0 ? _c : false;
145
+ const isSimple = (_d = pag.simple) !== null && _d !== void 0 ? _d : false;
146
+ const pages = [];
147
+ if (isSimple) {
148
+ pages.push(safePage);
149
+ }
150
+ else {
151
+ const range = 2;
152
+ let start = Math.max(1, safePage - range);
153
+ let end = Math.min(totalPages, safePage + range);
154
+ if (start > 1)
155
+ pages.push(1);
156
+ if (start > 2)
157
+ pages.push('...');
158
+ for (let i = start; i <= end; i++)
159
+ pages.push(i);
160
+ if (end < totalPages - 1)
161
+ pages.push('...');
162
+ if (end < totalPages)
163
+ pages.push(totalPages);
164
+ }
165
+ return (_jsxs("div", Object.assign({ className: "table-pagination" }, { children: [showTotal && _jsxs("span", Object.assign({ className: "table-pagination-total" }, { children: ["\u5171 ", total, " \u6761"] })), _jsxs("div", Object.assign({ className: "table-pagination-pages" }, { children: [_jsx("button", Object.assign({ className: "table-page-btn", disabled: safePage <= 1, onClick: () => goToPage(safePage - 1) }, { children: "\u2039" })), pages.map((p, idx) => typeof p === 'number' ? (_jsx("button", Object.assign({ className: `table-page-btn ${p === safePage ? 'active' : ''}`, onClick: () => goToPage(p) }, { children: p }), p)) : (_jsx("span", Object.assign({ className: "table-page-ellipsis" }, { children: "..." }), `e${idx}`))), _jsx("button", Object.assign({ className: "table-page-btn", disabled: safePage >= totalPages, onClick: () => goToPage(safePage + 1) }, { children: "\u203A" }))] })), showSizeChanger && (_jsx("div", Object.assign({ className: "table-page-size-changer" }, { children: _jsx("select", Object.assign({ value: controlledPageSize, onChange: (e) => changePageSize(Number(e.target.value)) }, { children: pageSizeOptions.map((s) => (_jsxs("option", Object.assign({ value: s }, { children: [s, " \u6761/\u9875"] }), s))) })) })))] })));
166
+ };
167
+ return (_jsxs("div", Object.assign({ className: tableClass }, { children: [_jsx("div", Object.assign({ className: "table-wrapper", style: (scroll === null || scroll === void 0 ? void 0 : scroll.y) ? { maxHeight: scroll.y, overflowY: 'auto' } : undefined }, { children: _jsxs("table", Object.assign({ className: "table-element" }, { children: [showHeader && (_jsx("thead", Object.assign({ className: "table-thead" }, { children: _jsxs("tr", { children: [hasRowSelection && (_jsx("th", Object.assign({ className: "table-th table-th-select", style: { width: (_g = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.columnWidth) !== null && _g !== void 0 ? _g : 40 } }, { children: _jsxs("label", Object.assign({ className: "table-checkbox-wrap" }, { children: [_jsx("input", { type: "checkbox", className: "table-checkbox", checked: pagedData.length > 0 && pagedData.every((r, i) => {
168
+ var _a, _b;
169
+ const key = getRowKey(r, rowKey, i);
170
+ const isDisabled = (_b = (_a = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.getCheckboxProps) === null || _a === void 0 ? void 0 : _a.call(rowSelection, r)) === null || _b === void 0 ? void 0 : _b.disabled;
171
+ return selectedKeys.includes(key) || isDisabled;
172
+ }), onChange: toggleSelectAll }), _jsx("span", { className: "table-checkbox-inner" })] })) }))), columns.map((col) => {
173
+ var _a, _b;
174
+ const colKey = (_b = (_a = col.key) !== null && _a !== void 0 ? _a : col.dataIndex) !== null && _b !== void 0 ? _b : '';
175
+ const canSort = !!col.sorter;
176
+ const isSorted = (sortConfig === null || sortConfig === void 0 ? void 0 : sortConfig.columnKey) === colKey;
177
+ return (_jsx("th", Object.assign({ className: `table-th ${canSort ? 'table-th-sortable' : ''}`, style: { width: col.width, minWidth: col.minWidth, textAlign: col.align }, onClick: () => canSort && handleSort(colKey) }, { children: _jsxs("span", Object.assign({ className: "table-th-inner" }, { children: [col.title, canSort && (_jsxs("span", Object.assign({ className: "table-sorter" }, { children: [_jsx("span", Object.assign({ className: `table-sorter-arrow up ${isSorted && sortConfig.order === 'ascend' ? 'active' : ''}` }, { children: "\u25B2" })), _jsx("span", Object.assign({ className: `table-sorter-arrow down ${isSorted && sortConfig.order === 'descend' ? 'active' : ''}` }, { children: "\u25BC" }))] })))] })) }), colKey));
178
+ })] }) }))), _jsxs("tbody", Object.assign({ className: "table-tbody" }, { children: [loading && (_jsx("tr", Object.assign({ className: "table-loading-row" }, { children: _jsx("td", Object.assign({ colSpan: columns.length + (hasRowSelection ? 1 : 0) }, { children: _jsxs("div", Object.assign({ className: "table-loading-mask" }, { children: [_jsx("div", { className: "table-loading-spinner" }), _jsx("span", { children: "\u52A0\u8F7D\u4E2D..." })] })) })) }))), !loading && pagedData.length === 0 && (_jsx("tr", Object.assign({ className: "table-empty-row" }, { children: _jsx("td", Object.assign({ colSpan: columns.length + (hasRowSelection ? 1 : 0) }, { children: _jsx("div", Object.assign({ className: "table-empty-text" }, { children: emptyText })) })) }))), !loading && pagedData.map((record, idx) => {
179
+ var _a, _b, _c, _d;
180
+ const key = getRowKey(record, rowKey, idx);
181
+ const rowProps = (_a = onRow === null || onRow === void 0 ? void 0 : onRow(record, idx)) !== null && _a !== void 0 ? _a : {};
182
+ const isDisabled = (_c = (_b = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.getCheckboxProps) === null || _b === void 0 ? void 0 : _b.call(rowSelection, record)) === null || _c === void 0 ? void 0 : _c.disabled;
183
+ return (_jsxs("tr", Object.assign({ className: `table-tr ${selectedKeys.includes(key) ? 'table-tr-selected' : ''} ${(_d = rowProps.className) !== null && _d !== void 0 ? _d : ''}`, onClick: rowProps.onClick, style: rowProps.style }, { children: [hasRowSelection && (_jsx("td", Object.assign({ className: "table-td table-td-select" }, { children: _jsxs("label", Object.assign({ className: `table-checkbox-wrap ${isDisabled ? 'table-checkbox-disabled' : ''}` }, { children: [_jsx("input", { type: "checkbox", className: "table-checkbox", checked: selectedKeys.includes(key), onChange: () => toggleSelect(key, record), disabled: isDisabled }), _jsx("span", { className: "table-checkbox-inner" })] })) }))), columns.map((col) => {
184
+ var _a, _b, _c;
185
+ const val = col.dataIndex ? record[col.dataIndex] : undefined;
186
+ const cellContent = col.render ? col.render(val, record, idx) : (val !== null && val !== void 0 ? val : '—');
187
+ return (_jsx("td", Object.assign({ className: `table-td ${(_a = col.className) !== null && _a !== void 0 ? _a : ''}`, style: { textAlign: col.align } }, { children: cellContent }), (_c = (_b = col.key) !== null && _b !== void 0 ? _b : col.dataIndex) !== null && _c !== void 0 ? _c : ''));
188
+ })] }), key));
189
+ })] }))] })) })), renderPagination()] })));
190
+ }
191
+ export default Table;
192
+ //# sourceMappingURL=index.js.map