@are-visual/virtual-table 0.0.1

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 (46) hide show
  1. package/README.md +548 -0
  2. package/index.d.ts +311 -0
  3. package/index.esm.js +1771 -0
  4. package/index.esm.js.map +1 -0
  5. package/middleware/column-resize/index.d.ts +19 -0
  6. package/middleware/column-resize/index.js +130 -0
  7. package/middleware/column-resize/index.js.map +1 -0
  8. package/middleware/column-resize/styles.css +8 -0
  9. package/middleware/column-resize/styles.scss +10 -0
  10. package/middleware/empty/index.d.ts +10 -0
  11. package/middleware/empty/index.js +73 -0
  12. package/middleware/empty/index.js.map +1 -0
  13. package/middleware/expandable/index.d.ts +37 -0
  14. package/middleware/expandable/index.js +239 -0
  15. package/middleware/expandable/index.js.map +1 -0
  16. package/middleware/expandable/styles.css +49 -0
  17. package/middleware/expandable/styles.scss +73 -0
  18. package/middleware/horizontal-scroll-bar/index.d.ts +15 -0
  19. package/middleware/horizontal-scroll-bar/index.js +90 -0
  20. package/middleware/horizontal-scroll-bar/index.js.map +1 -0
  21. package/middleware/horizontal-scroll-bar/styles.css +11 -0
  22. package/middleware/horizontal-scroll-bar/styles.scss +13 -0
  23. package/middleware/loading/index.d.ts +7 -0
  24. package/middleware/loading/index.js +73 -0
  25. package/middleware/loading/index.js.map +1 -0
  26. package/middleware/loading/styles.css +17 -0
  27. package/middleware/loading/styles.scss +27 -0
  28. package/middleware/selection/index.d.ts +47 -0
  29. package/middleware/selection/index.js +282 -0
  30. package/middleware/selection/index.js.map +1 -0
  31. package/middleware/selection/styles.css +13 -0
  32. package/middleware/selection/styles.scss +20 -0
  33. package/middleware/summary/index.d.ts +36 -0
  34. package/middleware/summary/index.js +203 -0
  35. package/middleware/summary/index.js.map +1 -0
  36. package/middleware/summary/styles.css +36 -0
  37. package/middleware/summary/styles.scss +45 -0
  38. package/middleware/utils/getScrollbarSize.d.ts +5 -0
  39. package/middleware/utils/getScrollbarSize.js +15 -0
  40. package/middleware/utils/getScrollbarSize.js.map +1 -0
  41. package/middleware/utils/useControllableValue.d.ts +16 -0
  42. package/middleware/utils/useControllableValue.js +28 -0
  43. package/middleware/utils/useControllableValue.js.map +1 -0
  44. package/package.json +34 -0
  45. package/styles/table.css +142 -0
  46. package/styles/table.scss +186 -0
@@ -0,0 +1,73 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { createMiddleware, onResize } from '@are-visual/virtual-table';
3
+ import { useState, useEffect, useMemo } from 'react';
4
+
5
+ function useTableLoading(ctx, options) {
6
+ const {
7
+ loading = false
8
+ } = options ?? {};
9
+ const {
10
+ columns: rawColumns,
11
+ estimatedRowHeight,
12
+ headerWrapperRef,
13
+ getScroller
14
+ } = ctx;
15
+ const [count, setCount] = useState(10);
16
+ useEffect(() => {
17
+ const header = headerWrapperRef.current;
18
+ const container = getScroller();
19
+ if (container == null) return;
20
+ return onResize(container, _ref => {
21
+ let {
22
+ height
23
+ } = _ref;
24
+ const headerHeight = header?.offsetHeight ?? 0;
25
+ setCount(Math.ceil((height - headerHeight) / estimatedRowHeight));
26
+ });
27
+ }, [getScroller, headerWrapperRef, estimatedRowHeight]);
28
+ const fakeDataSource = useMemo(() => {
29
+ return Array.from({
30
+ length: count
31
+ }, (_, index) => {
32
+ return {
33
+ key: index
34
+ };
35
+ });
36
+ }, [count]);
37
+ const columns = useMemo(() => {
38
+ if (!loading) {
39
+ return rawColumns;
40
+ }
41
+ return rawColumns.map(column => {
42
+ return {
43
+ ...column,
44
+ onCell() {
45
+ return {
46
+ className: 'virtual-table-loading-cell',
47
+ style: {
48
+ height: estimatedRowHeight
49
+ }
50
+ };
51
+ },
52
+ render() {
53
+ return jsx("div", {
54
+ className: "virtual-table-loading-skeleton"
55
+ });
56
+ }
57
+ };
58
+ });
59
+ }, [loading, rawColumns, estimatedRowHeight]);
60
+ if (!loading) {
61
+ return ctx;
62
+ }
63
+ return {
64
+ ...ctx,
65
+ columns,
66
+ rowKey: 'key',
67
+ dataSource: fakeDataSource
68
+ };
69
+ }
70
+ const tableLoading = createMiddleware(useTableLoading);
71
+
72
+ export { tableLoading };
73
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../packages/virtual-table/src/middleware/loading/index.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { ColumnType, MiddlewareContext, MiddlewareResult } from '@are-visual/virtual-table'\nimport { createMiddleware, onResize } from '@are-visual/virtual-table'\nimport { useEffect, useMemo, useState } from 'react'\n\nfunction useTableLoading<T = any>(\n ctx: MiddlewareContext<T>,\n options?: { loading?: boolean },\n): MiddlewareResult<T> {\n const { loading = false } = options ?? {}\n const { columns: rawColumns, estimatedRowHeight, headerWrapperRef, getScroller } = ctx\n\n const [count, setCount] = useState(10)\n\n useEffect(() => {\n const header = headerWrapperRef.current\n const container = getScroller()\n if (container == null) return\n return onResize(container, ({ height }) => {\n const headerHeight = header?.offsetHeight ?? 0\n setCount(Math.ceil((height - headerHeight) / estimatedRowHeight))\n })\n }, [getScroller, headerWrapperRef, estimatedRowHeight])\n\n const fakeDataSource = useMemo(() => {\n return Array.from({ length: count }, (_, index) => {\n return { key: index }\n }) as T[]\n }, [count])\n\n const columns = useMemo((): ColumnType<T>[] => {\n if (!loading) {\n return rawColumns\n }\n\n return rawColumns.map((column): ColumnType<T> => {\n return {\n ...column,\n onCell() {\n return { className: 'virtual-table-loading-cell', style: { height: estimatedRowHeight } }\n },\n render() {\n return <div className=\"virtual-table-loading-skeleton\" />\n },\n }\n })\n }, [loading, rawColumns, estimatedRowHeight])\n\n if (!loading) {\n return ctx\n }\n\n return {\n ...ctx,\n columns,\n rowKey: 'key',\n dataSource: fakeDataSource,\n }\n}\n\nexport const tableLoading = createMiddleware(useTableLoading)\n"],"names":["useTableLoading","ctx","options","loading","columns","rawColumns","estimatedRowHeight","headerWrapperRef","getScroller","count","setCount","useState","useEffect","header","current","container","onResize","_ref","height","headerHeight","offsetHeight","Math","ceil","fakeDataSource","useMemo","Array","from","length","_","index","key","map","column","onCell","className","style","render","_jsx","rowKey","dataSource","tableLoading","createMiddleware"],"mappings":";;;;AAKA,SAASA,eAAeA,CACtBC,GAAyB,EACzBC,OAA+B,EAAA;EAE/B,MAAM;AAAEC,IAAAA,OAAO,GAAG;GAAO,GAAGD,OAAO,IAAI,EAAE;EACzC,MAAM;AAAEE,IAAAA,OAAO,EAAEC,UAAU;IAAEC,kBAAkB;IAAEC,gBAAgB;AAAEC,IAAAA;AAAa,GAAA,GAAGP,GAAG;EAEtF,MAAM,CAACQ,KAAK,EAAEC,QAAQ,CAAC,GAAGC,QAAQ,CAAC,EAAE,CAAC;AAEtCC,EAAAA,SAAS,CAAC,MAAK;AACb,IAAA,MAAMC,MAAM,GAAGN,gBAAgB,CAACO,OAAO;AACvC,IAAA,MAAMC,SAAS,GAAGP,WAAW,EAAE;IAC/B,IAAIO,SAAS,IAAI,IAAI,EAAE;AACvB,IAAA,OAAOC,QAAQ,CAACD,SAAS,EAAEE,IAAA,IAAe;MAAA,IAAd;AAAEC,QAAAA;AAAQ,OAAA,GAAAD,IAAA;AACpC,MAAA,MAAME,YAAY,GAAGN,MAAM,EAAEO,YAAY,IAAI,CAAC;AAC9CV,MAAAA,QAAQ,CAACW,IAAI,CAACC,IAAI,CAAC,CAACJ,MAAM,GAAGC,YAAY,IAAIb,kBAAkB,CAAC,CAAC;AACnE,KAAC,CAAC;GACH,EAAE,CAACE,WAAW,EAAED,gBAAgB,EAAED,kBAAkB,CAAC,CAAC;AAEvD,EAAA,MAAMiB,cAAc,GAAGC,OAAO,CAAC,MAAK;IAClC,OAAOC,KAAK,CAACC,IAAI,CAAC;AAAEC,MAAAA,MAAM,EAAElB;AAAK,KAAE,EAAE,CAACmB,CAAC,EAAEC,KAAK,KAAI;MAChD,OAAO;AAAEC,QAAAA,GAAG,EAAED;OAAO;AACvB,KAAC,CAAQ;AACX,GAAC,EAAE,CAACpB,KAAK,CAAC,CAAC;AAEX,EAAA,MAAML,OAAO,GAAGoB,OAAO,CAAC,MAAsB;IAC5C,IAAI,CAACrB,OAAO,EAAE;AACZ,MAAA,OAAOE,UAAU;AACnB;AAEA,IAAA,OAAOA,UAAU,CAAC0B,GAAG,CAAEC,MAAM,IAAmB;MAC9C,OAAO;AACL,QAAA,GAAGA,MAAM;AACTC,QAAAA,MAAMA,GAAA;UACJ,OAAO;AAAEC,YAAAA,SAAS,EAAE,4BAA4B;AAAEC,YAAAA,KAAK,EAAE;AAAEjB,cAAAA,MAAM,EAAEZ;AAAkB;WAAI;SAC1F;AACD8B,QAAAA,MAAMA,GAAA;UACJ,OAAOC,GAAK,CAAA,KAAA,EAAA;AAAAH,YAAAA,SAAS,EAAC;YAAmC;AAC3D;OACD;AACH,KAAC,CAAC;GACH,EAAE,CAAC/B,OAAO,EAAEE,UAAU,EAAEC,kBAAkB,CAAC,CAAC;EAE7C,IAAI,CAACH,OAAO,EAAE;AACZ,IAAA,OAAOF,GAAG;AACZ;EAEA,OAAO;AACL,IAAA,GAAGA,GAAG;IACNG,OAAO;AACPkC,IAAAA,MAAM,EAAE,KAAK;AACbC,IAAAA,UAAU,EAAEhB;GACb;AACH;MAEaiB,YAAY,GAAGC,gBAAgB,CAACzC,eAAe;;;;"}
@@ -0,0 +1,17 @@
1
+ .virtual-table-loading-skeleton {
2
+ width: 100%;
3
+ min-height: 12px;
4
+ border-radius: 999px;
5
+ background: linear-gradient(90deg, var(--master-skeleton-color, hsla(0, 0%, 74.5%, 0.2)) 25%, var(--master-skeleton-flash, hsla(0, 0%, 50.6%, 0.24)) 37%, var(--master-skeleton-color, hsla(0, 0%, 74.5%, 0.2)) 63%);
6
+ background-size: 400% 100%;
7
+ animation: virtual-table-skeleton-animation 3s ease infinite;
8
+ }
9
+
10
+ @keyframes virtual-table-skeleton-animation {
11
+ from {
12
+ background-position: 100% 50%;
13
+ }
14
+ to {
15
+ background-position: 0 50%;
16
+ }
17
+ }
@@ -0,0 +1,27 @@
1
+ $master-skeleton-color: var(--master-skeleton-color, hsla(0, 0%, 74.5%, 0.2));
2
+ $master-skeleton-flash: var(--master-skeleton-flash, hsla(0, 0%, 50.6%, 0.24));
3
+
4
+ .virtual-table-loading {
5
+ &-skeleton {
6
+ width: 100%;
7
+ min-height: 12px;
8
+ border-radius: 999px;
9
+ background: linear-gradient(
10
+ 90deg,
11
+ $master-skeleton-color 25%,
12
+ $master-skeleton-flash 37%,
13
+ $master-skeleton-color 63%
14
+ );
15
+ background-size: 400% 100%;
16
+ animation: virtual-table-skeleton-animation 3s ease infinite;
17
+ }
18
+ }
19
+
20
+ @keyframes virtual-table-skeleton-animation {
21
+ from {
22
+ background-position: 100% 50%;
23
+ }
24
+ to {
25
+ background-position: 0 50%;
26
+ }
27
+ }
@@ -0,0 +1,47 @@
1
+ import * as _are_visual_virtual_table from '@are-visual/virtual-table';
2
+ import { ColumnExtra } from '@are-visual/virtual-table';
3
+ import { HTMLAttributes, TdHTMLAttributes, Key, ComponentType, ReactNode } from 'react';
4
+
5
+ type RowSelectMethod = 'all' | 'none' | 'invert' | 'single' | 'multiple';
6
+ type SelectionSelectFn<T = any> = (record: T, selected: boolean, selectedRows: T[], nativeEvent: Event) => void;
7
+ type GetComponentProps<DataType> = (data: DataType, index?: number) => HTMLAttributes<any> & TdHTMLAttributes<any>;
8
+ type SelectionColumnTitleProps = SelectionProps & {
9
+ allKeys: Key[];
10
+ onClear: () => void;
11
+ onSelectAll: () => void;
12
+ onSelectInvert: () => void;
13
+ };
14
+ interface TableRowSelection<T = any> {
15
+ component?: ComponentType<SelectionProps>;
16
+ /** Keep the selection keys in list even the key not exist in `dataSource` anymore */
17
+ preserveSelectedRowKeys?: boolean;
18
+ multiple?: boolean;
19
+ selectedRowKeys?: Key[];
20
+ defaultSelectedRowKeys?: Key[];
21
+ onChange?: (selectedRowKeys: Key[], selectedRows: T[], info: {
22
+ type: RowSelectMethod;
23
+ }) => void;
24
+ getSelectionProps?: (record: T) => SelectionProps & Record<string, unknown>;
25
+ onSelect?: SelectionSelectFn<T>;
26
+ hideSelectAll?: boolean;
27
+ fixed?: boolean;
28
+ columnWidth?: string | number;
29
+ columnTitle?: ReactNode | ((checkboxNode: ReactNode, props: SelectionColumnTitleProps) => ReactNode);
30
+ renderCell?: (value: boolean, record: T, index: number, originNode: ReactNode) => ReactNode;
31
+ onCell?: GetComponentProps<T>;
32
+ extraColumnProps?: ColumnExtra;
33
+ }
34
+ interface SelectionProps {
35
+ multiple?: boolean;
36
+ value?: boolean;
37
+ onChange?: (nextValue: boolean, e: Event) => void;
38
+ indeterminate?: boolean;
39
+ disabled?: boolean;
40
+ }
41
+
42
+ /**
43
+ * 为 Table 实现多选、单选功能,不传入 options 则是禁用插件
44
+ */
45
+ declare const tableSelection: <T = any>(options?: TableRowSelection<T> | undefined) => _are_visual_virtual_table.Middleware<T>;
46
+
47
+ export { type GetComponentProps, type RowSelectMethod, type SelectionColumnTitleProps, type SelectionProps, type SelectionSelectFn, type TableRowSelection, tableSelection };
@@ -0,0 +1,282 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { createMiddleware, useShallowMemo, useStableFn } from '@are-visual/virtual-table';
3
+ import { useControllableValue } from '@are-visual/virtual-table/middleware/utils/useControllableValue';
4
+ import { forwardRef, useRef, useEffect, createElement, useCallback, useMemo, isValidElement } from 'react';
5
+ import { useMergedRef } from '@are-visual/virtual-table/utils/ref';
6
+ import clsx from 'clsx';
7
+
8
+ function Selection(props, ref) {
9
+ const {
10
+ className,
11
+ multiple,
12
+ indeterminate,
13
+ value = false,
14
+ onChange,
15
+ component,
16
+ ...rest
17
+ } = props;
18
+ const isCustomComponent = component != null;
19
+ const inputNode = useRef(null);
20
+ useEffect(() => {
21
+ if (isCustomComponent) return;
22
+ const input = inputNode.current;
23
+ if (input == null) return;
24
+ input.indeterminate = !!indeterminate;
25
+ }, [isCustomComponent, indeterminate]);
26
+ const mergedRef = useMergedRef(inputNode, ref);
27
+ if (isCustomComponent) {
28
+ return /*#__PURE__*/createElement(component, props);
29
+ }
30
+ return jsx("input", {
31
+ ...rest,
32
+ ref: mergedRef,
33
+ className: clsx('virtual-table-selection', className),
34
+ type: multiple ? 'checkbox' : 'radio',
35
+ checked: value,
36
+ onChange: e => {
37
+ onChange?.(e.target.checked, e.nativeEvent);
38
+ }
39
+ });
40
+ }
41
+ var Selection$1 = /*#__PURE__*/forwardRef(Selection);
42
+
43
+ const SELECTION_COLUMN_KEY = 'VirtualTable.SELECTION_COLUMN';
44
+ const EMPTY_ARR = [];
45
+ function useSelection(ctx, options) {
46
+ const disablePlugin = options == null;
47
+ const {
48
+ columns: rawColumns
49
+ } = ctx;
50
+ const rowKey = ctx.rowKey;
51
+ const dataSource = disablePlugin ? EMPTY_ARR : ctx.dataSource;
52
+ const {
53
+ defaultSelectedRowKeys,
54
+ component,
55
+ preserveSelectedRowKeys,
56
+ multiple = true,
57
+ getSelectionProps,
58
+ onSelect,
59
+ hideSelectAll = false,
60
+ fixed,
61
+ columnWidth,
62
+ columnTitle,
63
+ extraColumnProps,
64
+ // checkStrictly 属性使用场景:
65
+ // const dataSource = [{ key: 1, name: "张三", children: [{ key: 1.1, name: "李四" }] }]
66
+ // dataSource 中含有 children 属性,antd Table 组件会显示为“树形”结构,Table 左侧会新增一个展开按钮,点击后会显示“李四”的数据
67
+ // 勾选“张三”的时候,会把对应 children 全部选中。如果 checkStrictly=false 则不选中。
68
+ // checkStrictly: _checkStrictly,
69
+ renderCell,
70
+ onCell
71
+ } = options ?? {};
72
+ const [selectedRowKeys = [], setSelectedRowKeys] = useControllableValue(options ?? {}, {
73
+ defaultValue: defaultSelectedRowKeys,
74
+ valuePropName: 'selectedRowKeys',
75
+ trigger: 'onChange'
76
+ });
77
+ const rowClassName = useCallback(record => {
78
+ const key = record[rowKey];
79
+ const checked = selectedRowKeys.includes(key);
80
+ return checked ? 'virtual-table-row-selected' : '';
81
+ }, [rowKey, selectedRowKeys]);
82
+ const selectionPropsList = useShallowMemo(() => {
83
+ return dataSource.map(row => {
84
+ if (!getSelectionProps) return {};
85
+ return getSelectionProps(row);
86
+ });
87
+ });
88
+ // 当有某一行数据 Checkbox disabled 时,过滤它
89
+ const allKeys = useShallowMemo(() => {
90
+ return dataSource.filter((_data, index) => !selectionPropsList[index].disabled).map(x => x[rowKey]);
91
+ });
92
+ // preserveSelectedRowKeys=true 时,勾选过的数据,都会在这里存一份
93
+ const cache = useRef(new Map());
94
+ const allDisabled = !selectionPropsList.some(item => !item.disabled);
95
+ const getRowsByKeys = useStableFn(keys => {
96
+ const result = [];
97
+ keys.forEach(key => {
98
+ let value = dataSource.find(row => row[rowKey] === key);
99
+ // 在 cache 中还是找不到对应的数据,就放弃寻找,填入一个 undefined(与 antd 默认表现一致)
100
+ // 场景: selectedRowKeys 中有一个在 dataSource 中不存在的 key,用这个 key 是找不到数据的
101
+ if (value == null && preserveSelectedRowKeys) {
102
+ value = cache.current.get(key);
103
+ }
104
+ if (value == null && !preserveSelectedRowKeys) return;
105
+ result.push(value);
106
+ });
107
+ return result;
108
+ });
109
+ const prevSelectedIndex = useRef(null);
110
+ const mergeColumns = useMemo(() => {
111
+ if (disablePlugin) {
112
+ return rawColumns;
113
+ }
114
+ const isSelected = selectedRowKeys.length > 0;
115
+ const indeterminate = isSelected && allKeys.length > selectedRowKeys.length;
116
+ const isSelectedAll = isSelected ? allKeys.length > 0 && allKeys.every(key => selectedRowKeys.includes(key)) : false;
117
+ const shakeDeadKeys = keys => {
118
+ const unionKeys = new Set(keys);
119
+ if (!preserveSelectedRowKeys) {
120
+ return Array.from(unionKeys).filter(key => {
121
+ return allKeys.includes(key);
122
+ });
123
+ }
124
+ return Array.from(unionKeys);
125
+ };
126
+ const multipleSelect = (currentIndex, nextChecked) => {
127
+ const index = prevSelectedIndex.current ?? currentIndex;
128
+ const startIndex = Math.min(index, currentIndex);
129
+ const endIndex = Math.max(index, currentIndex);
130
+ const rangeKeys = allKeys.slice(startIndex, endIndex + 1);
131
+ const shouldSelected = rangeKeys.some(rangeKey => !selectedRowKeys.includes(rangeKey));
132
+ prevSelectedIndex.current = shouldSelected ? endIndex : null;
133
+ const keys = nextChecked ? shakeDeadKeys([...selectedRowKeys, ...rangeKeys]) : shakeDeadKeys(selectedRowKeys.filter(x => !rangeKeys.includes(x)));
134
+ const rows = getRowsByKeys(keys);
135
+ setSelectedRowKeys(keys, rows, {
136
+ type: 'multiple'
137
+ });
138
+ };
139
+ const onSelectAll = () => {
140
+ const keys = shakeDeadKeys([...selectedRowKeys, ...allKeys]);
141
+ const rows = getRowsByKeys(keys);
142
+ setSelectedRowKeys(keys, rows, {
143
+ type: 'all'
144
+ });
145
+ };
146
+ const onSelectInvert = () => {
147
+ const keys = allKeys.filter(key => !selectedRowKeys.includes(key));
148
+ const rows = getRowsByKeys(keys);
149
+ setSelectedRowKeys(keys, rows, {
150
+ type: 'invert'
151
+ });
152
+ };
153
+ const onClearAll = () => {
154
+ setSelectedRowKeys([], [], {
155
+ type: 'none'
156
+ });
157
+ };
158
+ const columnTitleProps = {
159
+ indeterminate,
160
+ value: isSelectedAll,
161
+ disabled: allDisabled,
162
+ multiple,
163
+ onChange: checked => {
164
+ if (checked) {
165
+ onSelectAll();
166
+ } else {
167
+ onClearAll();
168
+ }
169
+ },
170
+ onClear: onClearAll,
171
+ onSelectAll,
172
+ onSelectInvert,
173
+ allKeys
174
+ };
175
+ const onCreateTitle = () => {
176
+ if (!multiple) {
177
+ if (/*#__PURE__*/isValidElement(columnTitle)) {
178
+ return columnTitle;
179
+ }
180
+ if (typeof columnTitle === 'function') {
181
+ return columnTitle(undefined, columnTitleProps);
182
+ }
183
+ return null;
184
+ }
185
+ let title = jsx("div", {
186
+ className: "virtual-table-selection",
187
+ children: jsx(Selection$1, {
188
+ component: component,
189
+ multiple: multiple,
190
+ value: isSelectedAll,
191
+ indeterminate: indeterminate,
192
+ disabled: allDisabled,
193
+ onChange: checked => {
194
+ if (checked) {
195
+ onSelectAll();
196
+ } else {
197
+ onClearAll();
198
+ }
199
+ }
200
+ })
201
+ });
202
+ if (/*#__PURE__*/isValidElement(columnTitle)) {
203
+ title = columnTitle;
204
+ } else if (typeof columnTitle === 'function') {
205
+ title = columnTitle(title, columnTitleProps);
206
+ }
207
+ return title;
208
+ };
209
+ const column = {
210
+ ...extraColumnProps,
211
+ title: hideSelectAll ? undefined : onCreateTitle(),
212
+ width: columnWidth ?? 32,
213
+ align: 'center',
214
+ fixed: fixed ? 'left' : undefined,
215
+ key: SELECTION_COLUMN_KEY,
216
+ render(_value, record, index) {
217
+ const key = record[rowKey];
218
+ const checked = selectedRowKeys.includes(key);
219
+ const extraProps = selectionPropsList[index];
220
+ const updateCache = () => {
221
+ if (preserveSelectedRowKeys) {
222
+ cache.current.set(key, record);
223
+ }
224
+ };
225
+ const node = jsx(Selection$1, {
226
+ ...extraProps,
227
+ component: component,
228
+ value: checked,
229
+ multiple: multiple,
230
+ onChange: (nextChecked, e) => {
231
+ updateCache();
232
+ if (multiple && e.shiftKey) {
233
+ multipleSelect(index, nextChecked);
234
+ return;
235
+ }
236
+ if (nextChecked) {
237
+ prevSelectedIndex.current = index;
238
+ } else {
239
+ prevSelectedIndex.current = null;
240
+ }
241
+ let keys = [key];
242
+ if (multiple) {
243
+ keys = nextChecked ? shakeDeadKeys([...selectedRowKeys, key]) : shakeDeadKeys(selectedRowKeys.filter(x => x !== key));
244
+ }
245
+ const rows = getRowsByKeys(keys);
246
+ // @ts-expect-error rows 并不是安全的 T[] 类型,因为有 preserveSelectedRowKeys 功能存在,在此处只能忽略类型错误
247
+ onSelect?.(record, nextChecked, rows, e);
248
+ setSelectedRowKeys(keys, rows, {
249
+ type: 'single'
250
+ });
251
+ }
252
+ });
253
+ if (typeof renderCell === 'function') {
254
+ return renderCell(checked, record, index, node);
255
+ }
256
+ return node;
257
+ },
258
+ onCell,
259
+ onHeaderCell() {
260
+ return {
261
+ className: 'virtual-table-selection-column'
262
+ };
263
+ }
264
+ };
265
+ return [column, ...rawColumns];
266
+ }, [disablePlugin, extraColumnProps, allDisabled, allKeys, columnTitle, columnWidth, fixed, getRowsByKeys, hideSelectAll, onCell, onSelect, preserveSelectedRowKeys, rawColumns, renderCell, rowKey, selectedRowKeys, selectionPropsList, setSelectedRowKeys, multiple, component]);
267
+ if (disablePlugin) {
268
+ return ctx;
269
+ }
270
+ return {
271
+ ...ctx,
272
+ rowClassName,
273
+ columns: mergeColumns
274
+ };
275
+ }
276
+ /**
277
+ * 为 Table 实现多选、单选功能,不传入 options 则是禁用插件
278
+ */
279
+ const tableSelection = createMiddleware(useSelection);
280
+
281
+ export { tableSelection };
282
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../packages/virtual-table/src/middleware/selection/selection.tsx","../../../../packages/virtual-table/src/middleware/selection/table-selection.tsx"],"sourcesContent":["import type { ComponentType, DetailedHTMLProps, ForwardedRef, InputHTMLAttributes } from 'react'\nimport type { SelectionProps as BaseProps } from './types'\nimport { useMergedRef } from '@are-visual/virtual-table/utils/ref'\nimport clsx from 'clsx'\nimport { createElement, forwardRef, useEffect, useRef } from 'react'\n\ntype InputProps = DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>\nexport interface SelectionProps extends BaseProps,\n Omit<InputProps, 'type' | 'onChange' | 'checked' | 'value' | 'defaultChecked' | 'defaultValue' | 'disabled'> {\n component?: ComponentType<BaseProps>\n}\n\nfunction Selection(props: SelectionProps, ref: ForwardedRef<HTMLInputElement>) {\n const {\n className,\n multiple,\n indeterminate,\n value = false,\n onChange,\n component,\n ...rest\n } = props\n\n const isCustomComponent = component != null\n\n const inputNode = useRef<HTMLInputElement>(null)\n\n useEffect(() => {\n if (isCustomComponent) return\n const input = inputNode.current\n if (input == null) return\n input.indeterminate = !!indeterminate\n }, [isCustomComponent, indeterminate])\n\n const mergedRef = useMergedRef(inputNode, ref)\n\n if (isCustomComponent) {\n return createElement(component, props)\n }\n\n return (\n <input\n {...rest}\n ref={mergedRef}\n className={clsx('virtual-table-selection', className)}\n type={multiple ? 'checkbox' : 'radio'}\n checked={value}\n onChange={(e) => {\n onChange?.(e.target.checked, e.nativeEvent)\n }}\n />\n )\n}\n\nexport default forwardRef(Selection)\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { AnyObject, ColumnType, MiddlewareContext, MiddlewareResult } from '@are-visual/virtual-table'\nimport type { Key, ReactNode } from 'react'\nimport type { SelectionColumnTitleProps, TableRowSelection } from './types'\n\nimport { createMiddleware, useShallowMemo, useStableFn } from '@are-visual/virtual-table'\nimport { useControllableValue } from '@are-visual/virtual-table/middleware/utils/useControllableValue'\nimport { isValidElement, useCallback, useMemo, useRef } from 'react'\nimport Selection from './selection'\n\nexport const SELECTION_COLUMN_KEY = 'VirtualTable.SELECTION_COLUMN'\n\nconst EMPTY_ARR: AnyObject[] = []\n\nexport function isSelectionColumn<T = any>(column: ColumnType<T>) {\n return column.key === SELECTION_COLUMN_KEY\n}\n\nfunction useSelection<T = any>(\n ctx: MiddlewareContext<T>,\n options?: TableRowSelection<T>,\n): MiddlewareResult<T> {\n const disablePlugin = options == null\n\n const { columns: rawColumns } = ctx\n const rowKey = ctx.rowKey as string\n const dataSource = disablePlugin ? EMPTY_ARR : (ctx.dataSource as AnyObject[])\n\n const {\n defaultSelectedRowKeys,\n\n component,\n preserveSelectedRowKeys,\n multiple = true,\n getSelectionProps,\n onSelect,\n hideSelectAll = false,\n fixed,\n columnWidth,\n columnTitle,\n\n extraColumnProps,\n\n // checkStrictly 属性使用场景:\n // const dataSource = [{ key: 1, name: \"张三\", children: [{ key: 1.1, name: \"李四\" }] }]\n // dataSource 中含有 children 属性,antd Table 组件会显示为“树形”结构,Table 左侧会新增一个展开按钮,点击后会显示“李四”的数据\n // 勾选“张三”的时候,会把对应 children 全部选中。如果 checkStrictly=false 则不选中。\n // checkStrictly: _checkStrictly,\n\n renderCell,\n onCell,\n } = options ?? {}\n\n const [selectedRowKeys = [], setSelectedRowKeys] = useControllableValue<Key[]>(\n options ?? {},\n {\n defaultValue: defaultSelectedRowKeys,\n valuePropName: 'selectedRowKeys',\n trigger: 'onChange',\n },\n )\n\n const rowClassName = useCallback((record: T) => {\n const key = (record as AnyObject)[rowKey] as Key\n const checked = selectedRowKeys.includes(key)\n return checked ? 'virtual-table-row-selected' : ''\n }, [rowKey, selectedRowKeys])\n\n const selectionPropsList = useShallowMemo(() => {\n return dataSource.map((row) => {\n if (!getSelectionProps) return {}\n return getSelectionProps(row as T)\n })\n })\n\n // 当有某一行数据 Checkbox disabled 时,过滤它\n const allKeys: Key[] = useShallowMemo(() => {\n return dataSource\n .filter((_data, index) => !selectionPropsList[index].disabled)\n .map((x) => x[rowKey] as Key)\n })\n\n // preserveSelectedRowKeys=true 时,勾选过的数据,都会在这里存一份\n const cache = useRef(new Map<Key, T>())\n\n const allDisabled = !selectionPropsList.some((item) => !item.disabled)\n\n const getRowsByKeys = useStableFn((keys: Key[]) => {\n const result: (T | undefined)[] = []\n keys.forEach((key) => {\n let value = dataSource.find((row) => row[rowKey] === key) as T | undefined\n\n // 在 cache 中还是找不到对应的数据,就放弃寻找,填入一个 undefined(与 antd 默认表现一致)\n // 场景: selectedRowKeys 中有一个在 dataSource 中不存在的 key,用这个 key 是找不到数据的\n if (value == null && preserveSelectedRowKeys) {\n value = cache.current.get(key)\n }\n\n if (value == null && !preserveSelectedRowKeys) return\n\n result.push(value)\n })\n return result\n })\n\n const prevSelectedIndex = useRef<number | null>(null)\n\n const mergeColumns = useMemo(() => {\n if (disablePlugin) {\n return rawColumns\n }\n\n const isSelected = selectedRowKeys.length > 0\n const indeterminate = isSelected && allKeys.length > selectedRowKeys.length\n const isSelectedAll = isSelected\n ? allKeys.length > 0 && allKeys.every((key) => selectedRowKeys.includes(key))\n : false\n\n const shakeDeadKeys = (keys: Key[]) => {\n const unionKeys = new Set(keys)\n if (!preserveSelectedRowKeys) {\n return Array.from(unionKeys).filter((key) => {\n return allKeys.includes(key)\n })\n }\n return Array.from(unionKeys)\n }\n\n const multipleSelect = (currentIndex: number, nextChecked: boolean) => {\n const index = prevSelectedIndex.current ?? currentIndex\n const startIndex = Math.min(index, currentIndex)\n const endIndex = Math.max(index, currentIndex)\n const rangeKeys = allKeys.slice(startIndex, endIndex + 1)\n const shouldSelected = rangeKeys.some((rangeKey) => !selectedRowKeys.includes(rangeKey))\n prevSelectedIndex.current = shouldSelected ? endIndex : null\n const keys = nextChecked\n ? shakeDeadKeys([...selectedRowKeys, ...rangeKeys])\n : shakeDeadKeys(selectedRowKeys.filter((x) => !rangeKeys.includes(x)))\n const rows = getRowsByKeys(keys)\n setSelectedRowKeys(keys, rows, { type: 'multiple' })\n }\n\n const onSelectAll = () => {\n const keys = shakeDeadKeys([...selectedRowKeys, ...allKeys])\n const rows = getRowsByKeys(keys)\n setSelectedRowKeys(keys, rows, { type: 'all' })\n }\n\n const onSelectInvert = () => {\n const keys = allKeys.filter((key) => !selectedRowKeys.includes(key))\n const rows = getRowsByKeys(keys)\n setSelectedRowKeys(keys, rows, { type: 'invert' })\n }\n\n const onClearAll = () => {\n setSelectedRowKeys([], [], { type: 'none' })\n }\n\n const columnTitleProps: SelectionColumnTitleProps = {\n indeterminate,\n value: isSelectedAll,\n disabled: allDisabled,\n multiple,\n onChange: (checked) => {\n if (checked) {\n onSelectAll()\n } else {\n onClearAll()\n }\n },\n onClear: onClearAll,\n onSelectAll,\n onSelectInvert,\n allKeys,\n }\n\n const onCreateTitle = () => {\n if (!multiple) {\n if (isValidElement(columnTitle)) {\n return columnTitle\n }\n if (typeof columnTitle === 'function') {\n return columnTitle(undefined, columnTitleProps)\n }\n return null\n }\n\n let title: ReactNode = (\n <div className=\"virtual-table-selection\">\n <Selection\n component={component}\n multiple={multiple}\n value={isSelectedAll}\n indeterminate={indeterminate}\n disabled={allDisabled}\n onChange={(checked) => {\n if (checked) {\n onSelectAll()\n } else {\n onClearAll()\n }\n }}\n />\n </div>\n )\n if (isValidElement(columnTitle)) {\n title = columnTitle\n } else if (typeof columnTitle === 'function') {\n title = columnTitle(title, columnTitleProps)\n }\n return title\n }\n\n const column: ColumnType<T> = {\n ...extraColumnProps,\n title: hideSelectAll ? undefined : onCreateTitle(),\n width: columnWidth ?? 32,\n align: 'center',\n fixed: fixed ? 'left' : undefined,\n key: SELECTION_COLUMN_KEY,\n render(_value, record, index) {\n const key = (record as AnyObject)[rowKey] as Key\n const checked = selectedRowKeys.includes(key)\n const extraProps = selectionPropsList[index]\n\n const updateCache = () => {\n if (preserveSelectedRowKeys) {\n cache.current.set(key, record)\n }\n }\n\n const node = (\n <Selection\n {...extraProps}\n component={component}\n value={checked}\n multiple={multiple}\n onChange={(nextChecked, e) => {\n updateCache()\n if (multiple && (e as PointerEvent).shiftKey) {\n multipleSelect(index, nextChecked)\n return\n }\n if (nextChecked) {\n prevSelectedIndex.current = index\n } else {\n prevSelectedIndex.current = null\n }\n let keys: Key[] = [key]\n if (multiple) {\n keys = nextChecked ? shakeDeadKeys([...selectedRowKeys, key]) : shakeDeadKeys(selectedRowKeys.filter((x) => x !== key))\n }\n const rows = getRowsByKeys(keys)\n // @ts-expect-error rows 并不是安全的 T[] 类型,因为有 preserveSelectedRowKeys 功能存在,在此处只能忽略类型错误\n onSelect?.(record, nextChecked, rows, e)\n setSelectedRowKeys(keys, rows, { type: 'single' })\n }}\n />\n )\n\n if (typeof renderCell === 'function') {\n return renderCell(checked, record, index, node)\n }\n\n return node\n },\n onCell,\n onHeaderCell() {\n return { className: 'virtual-table-selection-column' }\n },\n }\n\n return [column, ...rawColumns]\n }, [\n disablePlugin,\n extraColumnProps,\n allDisabled,\n allKeys,\n columnTitle,\n columnWidth,\n fixed,\n getRowsByKeys,\n hideSelectAll,\n onCell,\n onSelect,\n preserveSelectedRowKeys,\n rawColumns,\n renderCell,\n rowKey,\n selectedRowKeys,\n selectionPropsList,\n setSelectedRowKeys,\n multiple,\n component,\n ])\n\n if (disablePlugin) {\n return ctx\n }\n\n return {\n ...ctx,\n rowClassName,\n columns: mergeColumns,\n }\n}\n\n/**\n * 为 Table 实现多选、单选功能,不传入 options 则是禁用插件\n */\nexport const tableSelection = createMiddleware(useSelection)\n"],"names":["Selection","props","ref","className","multiple","indeterminate","value","onChange","component","rest","isCustomComponent","inputNode","useRef","useEffect","input","current","mergedRef","useMergedRef","createElement","_jsx","clsx","type","checked","e","target","nativeEvent","forwardRef","SELECTION_COLUMN_KEY","EMPTY_ARR","useSelection","ctx","options","disablePlugin","columns","rawColumns","rowKey","dataSource","defaultSelectedRowKeys","preserveSelectedRowKeys","getSelectionProps","onSelect","hideSelectAll","fixed","columnWidth","columnTitle","extraColumnProps","renderCell","onCell","selectedRowKeys","setSelectedRowKeys","useControllableValue","defaultValue","valuePropName","trigger","rowClassName","useCallback","record","key","includes","selectionPropsList","useShallowMemo","map","row","allKeys","filter","_data","index","disabled","x","cache","Map","allDisabled","some","item","getRowsByKeys","useStableFn","keys","result","forEach","find","get","push","prevSelectedIndex","mergeColumns","useMemo","isSelected","length","isSelectedAll","every","shakeDeadKeys","unionKeys","Set","Array","from","multipleSelect","currentIndex","nextChecked","startIndex","Math","min","endIndex","max","rangeKeys","slice","shouldSelected","rangeKey","rows","onSelectAll","onSelectInvert","onClearAll","columnTitleProps","onClear","onCreateTitle","isValidElement","undefined","title","children","column","width","align","render","_value","extraProps","updateCache","set","node","shiftKey","onHeaderCell","tableSelection","createMiddleware"],"mappings":";;;;;;;AAYA,SAASA,SAASA,CAACC,KAAqB,EAAEC,GAAmC,EAAA;EAC3E,MAAM;IACJC,SAAS;IACTC,QAAQ;IACRC,aAAa;AACbC,IAAAA,KAAK,GAAG,KAAK;IACbC,QAAQ;IACRC,SAAS;IACT,GAAGC;AACJ,GAAA,GAAGR,KAAK;AAET,EAAA,MAAMS,iBAAiB,GAAGF,SAAS,IAAI,IAAI;AAE3C,EAAA,MAAMG,SAAS,GAAGC,MAAM,CAAmB,IAAI,CAAC;AAEhDC,EAAAA,SAAS,CAAC,MAAK;AACb,IAAA,IAAIH,iBAAiB,EAAE;AAC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A,GAAG;IACNwB,YAAY;AACZrB,IAAAA,OAAO,EAAEkD;GACV;AACH;AAEA;;AAEG;MACU6C,cAAc,GAAGC,gBAAgB,CAACpG,YAAY;;;;"}
@@ -0,0 +1,13 @@
1
+ .virtual-table-selection {
2
+ position: relative;
3
+ display: inline-flex;
4
+ margin: 0;
5
+ }
6
+
7
+ .virtual-table-row-selected .virtual-table-cell,
8
+ .virtual-table-row-selected .virtual-table-cell.virtual-table-sticky-cell {
9
+ background-color: var(--virtual-table-row-selected-bg, #e6f4ff);
10
+ }
11
+ .virtual-table-row-selected:not(.no-hover):hover > .virtual-table-cell {
12
+ background-color: var(--virtual-table-row-selected-hover-bg, #bae0ff);
13
+ }
@@ -0,0 +1,20 @@
1
+ $virtual-table-row-selected-bg: var(--virtual-table-row-selected-bg, #e6f4ff);
2
+ $virtual-table-row-selected-hover-bg: var(--virtual-table-row-selected-hover-bg, #bae0ff);
3
+
4
+ .virtual-table-selection {
5
+ position: relative;
6
+ display: inline-flex;
7
+ margin: 0;
8
+ }
9
+
10
+ .virtual-table-row-selected {
11
+
12
+ .virtual-table-cell,
13
+ .virtual-table-cell.virtual-table-sticky-cell {
14
+ background-color: $virtual-table-row-selected-bg;
15
+ }
16
+
17
+ &:not(.no-hover):hover>.virtual-table-cell {
18
+ background-color: $virtual-table-row-selected-hover-bg;
19
+ }
20
+ }
@@ -0,0 +1,36 @@
1
+ import * as _are_visual_virtual_table from '@are-visual/virtual-table';
2
+ import { ColumnType } from '@are-visual/virtual-table';
3
+ import * as react from 'react';
4
+ import { Key, DetailedHTMLProps, HTMLAttributes, ReactNode, CSSProperties, MouseEvent, ReactElement } from 'react';
5
+ import * as react_jsx_runtime from 'react/jsx-runtime';
6
+
7
+ type NativeProps = DetailedHTMLProps<HTMLAttributes<HTMLTableCellElement>, HTMLTableCellElement>;
8
+ interface CellProps extends NativeProps, Pick<ColumnType<unknown>, 'align'> {
9
+ columnKey: Key;
10
+ colSpan?: number;
11
+ }
12
+
13
+ interface SummaryRowProps {
14
+ children?: ReactNode | ((column: ColumnType<any>, key: Key) => ReactNode);
15
+ className?: string;
16
+ style?: CSSProperties;
17
+ onClick?: (e?: MouseEvent<HTMLElement>) => void;
18
+ }
19
+
20
+ interface SummaryProps {
21
+ fixed?: boolean | 'top' | 'bottom';
22
+ children?: ReactNode;
23
+ }
24
+ declare function Summary({ children }: SummaryProps): ReactElement;
25
+ declare namespace Summary {
26
+ var Row: react.FC<SummaryRowProps>;
27
+ var Cell: react.MemoExoticComponent<(props: CellProps) => react_jsx_runtime.JSX.Element | null>;
28
+ }
29
+
30
+ interface TableSummaryOptions<T = any> {
31
+ summary: (data: readonly T[]) => ReactNode;
32
+ }
33
+
34
+ declare const tableSummary: <T = any>(options?: TableSummaryOptions<T> | undefined) => _are_visual_virtual_table.Middleware<T>;
35
+
36
+ export { Summary, type TableSummaryOptions, tableSummary };