@kne/table-page 0.1.30 → 0.1.32

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.
@@ -1,1886 +1,94 @@
1
1
  import '@kne/table-view/dist/index.css';
2
2
  import '@kne/scroll-loader/dist/index.css';
3
3
  import { withFetch } from '@kne/react-fetch';
4
- import { Checkbox, Row, Col, Input, List, Tooltip, Button, Collapse, Popover, Empty, Table as Table$1, Radio, Tabs, Dropdown, Segmented, Pagination, Spin, Skeleton } from 'antd';
5
- import { HolderOutlined, RedoOutlined, SettingOutlined, LoadingOutlined, CaretRightOutlined, DownOutlined, MinusSquareOutlined, TableOutlined, AppstoreOutlined } from '@ant-design/icons';
4
+ import { Tabs, Dropdown, Button, Segmented, Pagination, Spin, Skeleton } from 'antd';
5
+ import { DownOutlined, MinusSquareOutlined, TableOutlined, AppstoreOutlined } from '@ant-design/icons';
6
6
  import { SearchInput, FilterLines, FilterOuter, FilterValueDisplay, getFilterValue } from '@kne/react-filter';
7
7
  import ScrollLoader from '@kne/scroll-loader';
8
- import { useState, useMemo, useRef, useCallback, useEffect, useLayoutEffect, forwardRef, useImperativeHandle } from 'react';
8
+ import { isRenderMobileActive, Table, TableView, resolveColumns, globalParams } from '@kne/table-view';
9
+ export { CHECK_RELATION, RENDER_TYPE_NAMES, SIZE_NAMES, Table, default as TableView, buildClearSelectAllKeys, buildSelectAllKeys, buildTreeFromList, buildTreeKeyMaps, calcArgs, collectExpandableKeys, computeColumnsDisplay, computeColumnsValue, computeDisplay, defaultFormat, flattenAllTree, flattenVisibleTree, formatView, getColumnEllipsis, getColumnLayout, getColumnRender, getGridTemplateColumns, getRenderTypeDimensions, getRenderTypeNames, getStatusType, getTagColor, getTreeBreadcrumbItems, getTreeCheckState, globalParams, hasAnyTreeSelected, hasColumnSpan, hasColumnWidth, isAllTreeSelected, isOptionsColumn, isRenderMobileActive, isTreeDataType, mergeTreeChildren, nodeCanExpand, normalizeParentKeys, normalizeTreeData, parseColumnWidth, parseRenderType, preset, renderCellContent, renderStatusItem, renderTagItem, renderTagList, resolveCheckRelation, resolveColumn, resolveColumnDimensions, resolveColumns, resolveRenderMobile, resolveRenderType, sortDataSource, tableLocalApis, toggleExpandedKey, toggleTreeCheck, useSelectedRow, useSort, useTableConfig, wrapColumnHeaderTitle } from '@kne/table-view';
9
10
  import classnames from 'classnames';
10
11
  import get from 'lodash/get';
11
- import { TableView as TableView$1, isOptionsColumn, parseColumnWidth, isTreeDataType, normalizeTreeData, collectExpandableKeys, buildTreeKeyMaps, nodeCanExpand, isRenderMobileActive, resolveColumns, resolveCheckRelation, flattenVisibleTree, getTreeSelectionColumnWidth, toggleExpandedKey, getTreeCheckState, useSelectedRow, useSort, wrapColumnHeaderTitle, isAllTreeSelected, hasAnyTreeSelected, buildSelectAllKeys, buildClearSelectAllKeys, toggleTreeCheck, renderColumnTitle, getColumnEllipsis, computeColumnsValue, renderCellContent, computeDisplay, globalParams } from '@kne/table-view';
12
- export { CHECK_RELATION, RENDER_TYPE_NAMES, SIZE_NAMES, buildClearSelectAllKeys, buildSelectAllKeys, buildTreeFromList, buildTreeKeyMaps, calcArgs, collectExpandableKeys, computeColumnsDisplay, computeColumnsValue, computeDisplay, defaultFormat, flattenAllTree, flattenVisibleTree, formatView, getColumnEllipsis, getColumnLayout, getColumnRender, getGridTemplateColumns, getRenderTypeDimensions, getRenderTypeNames, getStatusType, getTagColor, getTreeBreadcrumbItems, getTreeCheckState, globalParams, hasAnyTreeSelected, hasColumnSpan, hasColumnWidth, isAllTreeSelected, isOptionsColumn, isRenderMobileActive, isTreeDataType, mergeTreeChildren, nodeCanExpand, normalizeParentKeys, normalizeTreeData, parseColumnWidth, parseRenderType, preset, renderCellContent, renderStatusItem, renderTagItem, renderTagList, resolveCheckRelation, resolveColumn, resolveColumnDimensions, resolveColumns, resolveRenderMobile, resolveRenderType, sortDataSource, toggleExpandedKey, toggleTreeCheck, useSelectedRow, useSort, wrapColumnHeaderTitle } from '@kne/table-view';
13
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
14
- import { isEmpty } from '@kne/is-empty';
15
- import { useIsMobile, usePopupContainer } from '@kne/responsive-utils';
16
- import useRefCallback from '@kne/use-ref-callback';
17
- import transform from 'lodash/transform';
18
- import pick from 'lodash/pick';
19
- import findLastIndex from 'lodash/findLastIndex';
20
- import isEqual from 'lodash/isEqual';
21
- import { useDebouncedCallback } from 'use-debounce';
22
- import groupBy from 'lodash/groupBy';
23
- import { ReactSortable } from 'react-sortablejs';
24
- import cloneDeep from 'lodash/cloneDeep';
25
- import { createWithIntlProvider, useIntl } from '@kne/react-intl';
26
- import filterZhCN from '@kne/react-filter/dist/locale/zh-CN';
27
- import filterEnUS from '@kne/react-filter/dist/locale/en-US';
28
- import StickyScroller, { isDocumentScrollContainer, getViewportRect } from '@kne/react-sticky-scroller';
29
- import useControlValue from '@kne/use-control-value';
30
- import '@kne/react-sticky-scroller/dist/index.css';
31
- import '@kne/button-group/dist/index.css';
32
- import '@kne/react-filter/dist/index.css';
33
- import ButtonGroup from '@kne/button-group';
34
-
35
- function _extends() {
36
- return _extends = Object.assign ? Object.assign.bind() : function (n) {
37
- for (var e = 1; e < arguments.length; e++) {
38
- var t = arguments[e];
39
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
40
- }
41
- return n;
42
- }, _extends.apply(null, arguments);
43
- }
44
- function _objectWithoutPropertiesLoose(r, e) {
45
- if (null == r) return {};
46
- var t = {};
47
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
48
- if (-1 !== e.indexOf(n)) continue;
49
- t[n] = r[n];
50
- }
51
- return t;
52
- }
53
-
54
- const _excluded$4 = ["renderMobile"];
55
- const TableView = _ref => {
56
- let {
57
- renderMobile = true
58
- } = _ref,
59
- props = _objectWithoutPropertiesLoose(_ref, _excluded$4);
60
- return /*#__PURE__*/jsx(TableView$1, _extends({
61
- renderMobile: renderMobile
62
- }, props));
63
- };
64
- TableView.Header = TableView$1.Header;
65
- TableView.useSelectedRow = TableView$1.useSelectedRow;
66
- TableView.useSort = TableView$1.useSort;
67
- TableView.sortDataSource = TableView$1.sortDataSource;
68
-
69
- var style$2 = {"table":"kne-table-page_awa1L","is-size-small":"kne-table-page_C1bom","is-size-large":"kne-table-page_xEu6c","is-selected-all":"kne-table-page_692q3","is-selected":"kne-table-page_IWgjl","is-disabled":"kne-table-page_YUG4k","has-summary":"kne-table-page_Cb-du","has-group-header":"kne-table-page_7qTC5","is-sticky":"kne-table-page_jGzIR","is-sticky-scroll-y":"kne-table-page_P6lxG","is-sticky-viewport":"kne-table-page_Kr-p6","col-content":"kne-table-page_CWr3V","empty":"kne-table-page_BoatL","table-cell":"kne-table-page_HPmr3","selection-col":"kne-table-page_D7YhS","tree-expand-col":"kne-table-page_gG4Je","is-tree-table":"kne-table-page_-sVbY","radio-col":"kne-table-page_df9z3","tree-selection-content":"kne-table-page_21SJy","tree-indent":"kne-table-page_S2ObB","tree-expand":"kne-table-page_gbOhK","is-expanded":"kne-table-page_tPfuu","is-loading":"kne-table-page_ySG8v","tree-leaf-placeholder":"kne-table-page_lJF37","tree-selection-control":"kne-table-page_MFctL","is-computed":"kne-table-page_ZA1Je","is-resize":"kne-table-page_CA0uL","is-mobile-render":"kne-table-page_Jy4md","column-resize-guide":"kne-table-page_JARA2"};
70
-
71
- const getColumnConfig = (config, columnName, field, defaultValue) => {
72
- const columnConfig = config == null ? void 0 : config[columnName];
73
- if (columnConfig != null && columnConfig[field] !== undefined) {
74
- return columnConfig[field];
75
- }
76
- const legacyValue = get(config, `${columnName}.${field}`);
77
- return legacyValue === undefined ? defaultValue : legacyValue;
78
- };
79
- const setColumnConfig = (config, columnName, updates) => {
80
- return Object.assign({}, config, {
81
- [columnName]: Object.assign({}, config == null ? void 0 : config[columnName], updates)
82
- });
83
- };
84
-
85
- var configStyle = {"cell-resize-bar":"kne-table-page_PNaAP","table-changer-setting":"kne-table-page_B0U-O","is-active":"kne-table-page_vHrQo","table-config-header":"kne-table-page_Zp8MN","table-config-header-title":"kne-table-page_Pc6jR","columns-control-content":"kne-table-page_saJmr","columns-control-content-title":"kne-table-page_YmHni","columns-control-content-scroller":"kne-table-page_rgqWB","columns-control-sortable-list":"kne-table-page_JRcBW","columns-control-content-footer":"kne-table-page_nLwW1","columns-control-content-input":"kne-table-page_9qyJs","columns-control-content-list":"kne-table-page_Sslzr","columns-control-content-item":"kne-table-page_7CamD","is-drag":"kne-table-page_X18rq","columns-control-content-item-icon":"kne-table-page_Eab-e","columns-control-overlay":"kne-table-page_eT4HV","header-col":"kne-table-page_bjDly","header-cell-inner":"kne-table-page_9FKgD"};
86
-
87
- const locale$1 = {
88
- TotalText: '共',
89
- ItemText: '条',
90
- UnnamedColumn: '未命名列',
91
- EditTable: '编辑表格',
92
- RestoreDefault: '恢复默认',
93
- VisibleInfo: '显示的信息',
94
- HiddenInfo: '隐藏的信息',
95
- Search: '搜索',
96
- BatchOperations: '批量操作',
97
- BatchOperationsWithCount: '已选:{count}条',
98
- Cancel: '取消',
99
- Confirm: '确定',
100
- All: '全部',
101
- SwitchToCardView: '切换为卡片视图',
102
- SwitchToTableView: '切换为表格视图'
103
- };
104
-
105
- const locale = {
106
- TotalText: 'Total',
107
- ItemText: 'items',
108
- UnnamedColumn: 'Unnamed',
109
- EditTable: 'Edit Table',
110
- RestoreDefault: 'Restore Default',
111
- VisibleInfo: 'Visible Columns',
112
- HiddenInfo: 'Hidden Columns',
113
- Search: 'Search',
114
- BatchOperations: 'Batch Actions',
115
- BatchOperationsWithCount: 'Selected: {count}',
116
- Cancel: 'Cancel',
117
- Confirm: 'Confirm',
118
- All: 'All',
119
- SwitchToCardView: 'Switch to card view',
120
- SwitchToTableView: 'Switch to table view'
121
- };
122
-
123
- const withLocale = createWithIntlProvider({
124
- defaultLocale: 'zh-CN',
125
- messages: {
126
- 'zh-CN': _extends({}, filterZhCN, locale$1),
127
- 'en-US': _extends({}, filterEnUS, locale)
128
- },
129
- namespace: 'table-page'
130
- });
131
-
132
- const ColumnsControlContent = withLocale(({
133
- close,
134
- onConfirm,
135
- columns,
136
- config: defaultValue
137
- }) => {
138
- const {
139
- formatMessage
140
- } = useIntl();
141
- const [config, onChange] = useState(defaultValue || {});
142
- const [searchText, setSearchText] = useState('');
143
- const [confirmLoading, setConfirmLoading] = useState(false);
144
- const [scrollEl, setScrollEl] = useState(null);
145
- const {
146
- leftFixedColumns,
147
- rightFixedColumns,
148
- visibleColumns,
149
- hiddenColumns
150
- } = useMemo(() => {
151
- return transform(Object.assign({
152
- leftFixedColumns: [],
153
- rightFixedColumns: [],
154
- visibleColumns: [],
155
- hiddenColumns: []
156
- }, groupBy(columns, item => {
157
- if (item.fixed === 'right') {
158
- return 'rightFixedColumns';
159
- }
160
- if (item.fixed === true || item.fixed === 'left') {
161
- return 'leftFixedColumns';
162
- }
163
- return getColumnConfig(config, item.name, 'visible') !== true && item.hidden || getColumnConfig(config, item.name, 'visible') === false ? 'hiddenColumns' : 'visibleColumns';
164
- })), (result, value, key) => {
165
- result[key] = value.sort((a, b) => getColumnConfig(config, a.name, 'rank', 0) - getColumnConfig(config, b.name, 'rank', 0));
166
- }, {});
167
- }, [columns, config]);
168
- const sortableVisibleColumns = useMemo(() => {
169
- return visibleColumns.map(column => Object.assign({}, column, {
170
- id: column.name
171
- }));
172
- }, [visibleColumns]);
173
- const handlerColumnsChange = columnsState => {
174
- const newConfig = cloneDeep(config);
175
- const columnsList = [].concat(columnsState.leftFixedColumns, columnsState.visibleColumns, columnsState.rightFixedColumns);
176
- (columnsState.hiddenColumns || []).forEach(col => {
177
- Object.assign(newConfig, setColumnConfig(newConfig, col.name, {
178
- visible: false
179
- }));
180
- });
181
- columnsList.forEach((col, index) => {
182
- Object.assign(newConfig, setColumnConfig(newConfig, col.name, {
183
- rank: index + 1
184
- }));
185
- });
186
- onChange(newConfig);
187
- };
188
- const renderColumn = item => {
189
- return /*#__PURE__*/jsxs(Fragment, {
190
- children: [item.titleText || item.title || formatMessage({
191
- id: 'UnnamedColumn'
192
- }), item.groupHeader && item.groupHeader.length > 0 ? `(${item.groupHeader.map(({
193
- title
194
- }) => title).join('-')})` : '']
195
- });
196
- };
197
- const collapseItems = useMemo(() => {
198
- return [{
199
- key: 'active',
200
- label: formatMessage({
201
- id: 'VisibleInfo'
202
- }),
203
- children: /*#__PURE__*/jsxs("div", {
204
- className: configStyle['columns-control-content-list'],
205
- children: [leftFixedColumns.map((item, index) => /*#__PURE__*/jsx("div", {
206
- className: configStyle['columns-control-content-item'],
207
- children: /*#__PURE__*/jsx(Checkbox, {
208
- checked: true,
209
- disabled: true,
210
- children: renderColumn(item)
211
- })
212
- }, item.name || `left-${index}`)), /*#__PURE__*/jsx(ReactSortable, {
213
- tag: "div",
214
- className: configStyle['columns-control-sortable-list'],
215
- list: sortableVisibleColumns,
216
- filter: ".ignore-elements",
217
- dragClass: "table-page-sortable-drag",
218
- ghostClass: "table-page-sortable-ghost",
219
- chosenClass: "table-page-sortable-chosen",
220
- forceFallback: true,
221
- fallbackOnBody: true,
222
- scroll: scrollEl || true,
223
- bubbleScroll: true,
224
- setList: nextVisibleColumns => {
225
- handlerColumnsChange({
226
- leftFixedColumns,
227
- visibleColumns: nextVisibleColumns,
228
- hiddenColumns,
229
- rightFixedColumns
230
- });
231
- },
232
- animation: 300,
233
- delayOnTouchStart: true,
234
- delay: 2,
235
- children: sortableVisibleColumns.map(item => /*#__PURE__*/jsxs("div", {
236
- className: classnames(configStyle['columns-control-content-item'], configStyle['is-drag']),
237
- children: [/*#__PURE__*/jsx(HolderOutlined, {
238
- className: configStyle['columns-control-content-item-icon']
239
- }), /*#__PURE__*/jsx(Checkbox, {
240
- checked: true,
241
- disabled: item.fixed || leftFixedColumns.length + visibleColumns.length + rightFixedColumns.length <= 1,
242
- onChange: e => {
243
- e.stopPropagation();
244
- e.preventDefault();
245
- const newConfig = Object.assign({}, config);
246
- newConfig[item.name] = Object.assign({}, newConfig[item.name], {
247
- visible: false
248
- });
249
- onChange(newConfig);
250
- },
251
- children: renderColumn(item)
252
- })]
253
- }, item.id))
254
- }), rightFixedColumns.map((item, index) => /*#__PURE__*/jsx("div", {
255
- className: configStyle['columns-control-content-item'],
256
- children: /*#__PURE__*/jsx(Checkbox, {
257
- checked: true,
258
- disabled: true,
259
- children: item.titleText || item.title || formatMessage({
260
- id: 'UnnamedColumn'
261
- })
262
- })
263
- }, item.name || `right-${index}`))]
264
- })
265
- }, {
266
- key: 'un-active',
267
- label: /*#__PURE__*/jsxs(Row, {
268
- wrap: false,
269
- justify: "space-between",
270
- children: [/*#__PURE__*/jsx(Col, {
271
- children: formatMessage({
272
- id: 'HiddenInfo'
273
- })
274
- }), /*#__PURE__*/jsx(Col, {
275
- onClick: e => {
276
- e.stopPropagation();
277
- e.preventDefault();
278
- },
279
- children: /*#__PURE__*/jsx(Input.Search, {
280
- placeholder: formatMessage({
281
- id: 'Search'
282
- }),
283
- onSearch: value => setSearchText(value),
284
- className: configStyle['columns-control-content-input'],
285
- size: "small",
286
- allowClear: true
287
- })
288
- })]
289
- }),
290
- children: /*#__PURE__*/jsx(List, {
291
- dataSource: hiddenColumns.filter(item => {
292
- const title = item.titleText || item.title;
293
- return typeof title === 'string' && title.indexOf(searchText) > -1;
294
- }),
295
- renderItem: item => /*#__PURE__*/jsx(List.Item, {
296
- className: configStyle['columns-control-content-item'],
297
- children: /*#__PURE__*/jsx(Checkbox, {
298
- checked: false,
299
- onChange: e => {
300
- e.stopPropagation();
301
- e.preventDefault();
302
- const newConfig = Object.assign({}, config);
303
- newConfig[item.name] = Object.assign({}, newConfig[item.name], {
304
- visible: true
305
- });
306
- onChange(newConfig);
307
- },
308
- children: item.titleText || item.title || formatMessage({
309
- id: 'UnnamedColumn'
310
- })
311
- })
312
- }, item.name)
313
- })
314
- }];
315
- }, [config, formatMessage, hiddenColumns, leftFixedColumns, onChange, rightFixedColumns, scrollEl, searchText, sortableVisibleColumns, visibleColumns.length]);
316
- return /*#__PURE__*/jsxs("div", {
317
- className: configStyle['columns-control-content'],
318
- children: [/*#__PURE__*/jsx("div", {
319
- className: configStyle['columns-control-content-title'],
320
- children: /*#__PURE__*/jsxs(Row, {
321
- align: "middle",
322
- justify: "space-between",
323
- children: [/*#__PURE__*/jsx(Col, {
324
- children: formatMessage({
325
- id: 'EditTable'
326
- })
327
- }), /*#__PURE__*/jsx(Col, {
328
- children: /*#__PURE__*/jsx(Tooltip, {
329
- title: formatMessage({
330
- id: 'RestoreDefault'
331
- }),
332
- children: /*#__PURE__*/jsx(Button, {
333
- type: "text",
334
- icon: /*#__PURE__*/jsx(RedoOutlined, {}),
335
- onClick: async () => {
336
- onConfirm && (await onConfirm({}));
337
- close();
338
- }
339
- })
340
- })
341
- })]
342
- })
343
- }), /*#__PURE__*/jsx("div", {
344
- className: configStyle['columns-control-content-scroller'],
345
- ref: setScrollEl,
346
- children: /*#__PURE__*/jsx(Collapse, {
347
- defaultActiveKey: ['active', 'un-active'],
348
- ghost: true,
349
- bordered: true,
350
- items: collapseItems
351
- })
352
- }), /*#__PURE__*/jsxs(Row, {
353
- className: configStyle['columns-control-content-footer'],
354
- justify: "end",
355
- gutter: 10,
356
- children: [/*#__PURE__*/jsx(Col, {
357
- children: /*#__PURE__*/jsx(Button, {
358
- size: "small",
359
- onClick: () => {
360
- onChange(defaultValue || {});
361
- close();
362
- },
363
- children: formatMessage({
364
- id: 'Cancel'
365
- })
366
- })
367
- }), /*#__PURE__*/jsx(Col, {
368
- children: /*#__PURE__*/jsx(Button, {
369
- type: "primary",
370
- size: "small",
371
- loading: confirmLoading,
372
- onClick: async () => {
373
- setConfirmLoading(true);
374
- try {
375
- onConfirm && (await onConfirm(config));
376
- close();
377
- } finally {
378
- setConfirmLoading(false);
379
- }
380
- },
381
- children: formatMessage({
382
- id: 'Confirm'
383
- })
384
- })
385
- })]
386
- })]
387
- });
388
- });
389
-
390
- const storageKey = 'TABLE_PAGE_TABLE_CONFIG';
391
- const readStorage = () => {
392
- try {
393
- return JSON.parse(localStorage.getItem(storageKey) || '{}');
394
- } catch (_unused) {
395
- return {};
396
- }
397
- };
398
- const writeStorage = data => {
399
- try {
400
- localStorage.setItem(storageKey, JSON.stringify(data));
401
- } catch (_unused2) {
402
- // ignore quota errors
403
- }
404
- };
405
- const getData = name => {
406
- if (!name) {
407
- return {};
408
- }
409
- return get(readStorage(), name, {});
410
- };
411
- const setData = (name, data) => {
412
- if (!name) {
413
- return;
414
- }
415
- writeStorage(Object.assign({}, readStorage(), {
416
- [name]: data
417
- }));
418
- };
419
- const tableLocalApis = {
420
- getData,
421
- setData
422
- };
423
-
424
- const TABLE_CONFIG_COLUMN_EXTRA_WIDTH = 48;
425
-
426
- const DEFAULT_WIDTH = 160;
427
- const DEFAULT_MIN = 80;
428
- const DEFAULT_MAX = 600;
429
- const getColumnSize = column => {
430
- var _column$min, _column$max;
431
- const width = parseColumnWidth(column.width) || DEFAULT_WIDTH;
432
- return {
433
- width,
434
- min: (_column$min = column.min) != null ? _column$min : DEFAULT_MIN,
435
- max: (_column$max = column.max) != null ? _column$max : DEFAULT_MAX
436
- };
437
- };
438
- const getConfigColumnExtraWidth = (index, columnCount, controllerOpen) => {
439
- if (!controllerOpen || index !== columnCount - 1) {
440
- return 0;
441
- }
442
- return TABLE_CONFIG_COLUMN_EXTRA_WIDTH;
443
- };
444
- const withConfigColumnExtra = (contentWidth, index, columnCount, controllerOpen) => {
445
- return contentWidth + getConfigColumnExtraWidth(index, columnCount, controllerOpen);
446
- };
447
- const TableConfigButton = ({
448
- title,
449
- columns,
450
- config,
451
- setConfig
452
- }) => {
453
- const [open, setOpen] = useState(false);
454
- return /*#__PURE__*/jsxs(Row, {
455
- wrap: false,
456
- align: "middle",
457
- className: configStyle['table-config-header'],
458
- children: [/*#__PURE__*/jsx(Col, {
459
- flex: 1,
460
- className: configStyle['table-config-header-title'],
461
- children: title
462
- }), /*#__PURE__*/jsx(Col, {
463
- flex: "none",
464
- children: /*#__PURE__*/jsx(Popover, {
465
- open: open,
466
- onOpenChange: setOpen,
467
- trigger: "click",
468
- placement: "bottomLeft",
469
- rootClassName: configStyle['columns-control-overlay'],
470
- styles: {
471
- container: {
472
- padding: 0
473
- }
474
- },
475
- content: /*#__PURE__*/jsx(ColumnsControlContent, {
476
- columns: columns,
477
- config: config,
478
- close: () => setOpen(false),
479
- onConfirm: newConfig => {
480
- setConfig(configValue => {
481
- return transform(newConfig, (result, value, key) => {
482
- result[key] = Object.assign({}, configValue[key], pick(value, ['visible', 'rank']));
483
- }, {});
484
- });
485
- }
486
- }),
487
- children: /*#__PURE__*/jsx("span", {
488
- className: classnames(configStyle['table-changer-setting'], open && configStyle['is-active']),
489
- children: /*#__PURE__*/jsx(SettingOutlined, {})
490
- })
491
- })
492
- })]
493
- });
494
- };
495
- const useTableConfig = ({
496
- columns,
497
- name,
498
- controllerOpen: _controllerOpen = true,
499
- tableWidth: _tableWidth = 0,
500
- rowKey,
501
- tableServerApis: _tableServerApis = tableLocalApis
502
- }) => {
503
- const [currentMoveColumnIndex, setCurrentMoveColumnIndex] = useState(null);
504
- const currentMoveColumnIndexRef = useRef(currentMoveColumnIndex);
505
- currentMoveColumnIndexRef.current = currentMoveColumnIndex;
506
- const currentMoveColumnRef = useRef(null);
507
- const startPointRef = useRef(null);
508
- const [config, setConfigBase] = useState({});
509
- const saveConfig = useDebouncedCallback((tableName, target) => {
510
- _tableServerApis == null || _tableServerApis.setData(tableName, target);
511
- }, 500);
512
- const setConfig = useCallback(newConfig => {
513
- setConfigBase(prevConfig => {
514
- const target = typeof newConfig === 'function' ? newConfig(prevConfig) : newConfig;
515
- if (name && _controllerOpen) {
516
- saveConfig(name, target);
517
- }
518
- return target;
519
- });
520
- }, [name, _controllerOpen, saveConfig]);
521
- useEffect(() => {
522
- if (name && _controllerOpen) {
523
- setConfigBase(Object.assign({}, _tableServerApis.getData(name)));
524
- }
525
- }, [name, _controllerOpen, _tableServerApis]);
526
- const visibleColumns = useMemo(() => {
527
- return columns.filter(col => !(getColumnConfig(config, col.name, 'visible') === false || getColumnConfig(config, col.name, 'visible') !== true && col.hidden === true)).sort((a, b) => {
528
- const computedIndex = item => getColumnConfig(config, item.name, 'rank', 0) + (item.fixed === 'left' || item.fixed === true ? -10000 : 0) + (item.fixed === 'right' ? 10000 : 0);
529
- return computedIndex(a) - computedIndex(b);
530
- });
531
- }, [columns, config]);
532
- const columnCount = visibleColumns.length;
533
- const hasFixedColumn = useMemo(() => visibleColumns.some(col => col.fixed === 'right' || col.fixed === 'left' || col.fixed === true), [visibleColumns]);
534
- const lastNotFixedColumnIndex = useMemo(() => {
535
- return findLastIndex(visibleColumns, col => col.fixed !== 'right' && !isOptionsColumn(col));
536
- }, [visibleColumns]);
537
- const totalWidth = useMemo(() => {
538
- return visibleColumns.reduce((sum, col, index) => {
539
- const {
540
- width
541
- } = getColumnSize(col);
542
- const contentWidth = getColumnConfig(config, col.name, 'width') || width;
543
- return sum + withConfigColumnExtra(contentWidth, index, columnCount, _controllerOpen);
544
- }, 0);
545
- }, [visibleColumns, config, columnCount, _controllerOpen]);
546
- const computedRealWidth = useCallback(({
547
- width,
548
- index
549
- }) => {
550
- const contentWidth = width;
551
- if (currentMoveColumnIndex !== null && currentMoveColumnIndex === index) {
552
- return withConfigColumnExtra(contentWidth, index, columnCount, _controllerOpen);
553
- }
554
- if (hasFixedColumn || lastNotFixedColumnIndex !== index) {
555
- return withConfigColumnExtra(contentWidth, index, columnCount, _controllerOpen);
556
- }
557
- return withConfigColumnExtra(contentWidth, index, columnCount, _controllerOpen) + Math.max(_tableWidth - totalWidth - 2, 0);
558
- }, [hasFixedColumn, lastNotFixedColumnIndex, _tableWidth, totalWidth, currentMoveColumnIndex, columnCount, _controllerOpen]);
559
- const getConfigWidth = useCallback(column => {
560
- const {
561
- width,
562
- min,
563
- max
564
- } = getColumnSize(column);
565
- const currentWidth = Math.min(Math.max(getColumnConfig(config, column.name, 'width') || width, min), max);
566
- return {
567
- currentWidth,
568
- min,
569
- max
570
- };
571
- }, [config]);
572
- const resizeBarRender = useCallback((column, index) => {
573
- return /*#__PURE__*/jsx("span", {
574
- className: classnames(configStyle['cell-resize-bar'], 'table-cell-resize-bar'),
575
- onMouseDown: e => {
576
- e.stopPropagation();
577
- const {
578
- currentWidth,
579
- min,
580
- max
581
- } = getConfigWidth(column);
582
- currentMoveColumnRef.current = Object.assign({}, column, {
583
- index,
584
- width: currentWidth,
585
- min,
586
- max
587
- });
588
- startPointRef.current = e.clientX;
589
- setCurrentMoveColumnIndex(index);
590
- },
591
- children: /*#__PURE__*/jsx(HolderOutlined, {})
592
- });
593
- }, [getConfigWidth]);
594
- const resize = useRefCallback(delta => {
595
- if (currentMoveColumnIndexRef.current === null || !currentMoveColumnRef.current) {
596
- return;
597
- }
598
- const {
599
- name: colName,
600
- width,
601
- min,
602
- max
603
- } = currentMoveColumnRef.current;
604
- const currentWidth = Math.min(Math.max(width + delta, min), max);
605
- if (currentWidth < min) {
606
- return;
607
- }
608
- setConfig(prevConfig => Object.assign({}, prevConfig, {
609
- [colName]: Object.assign({}, prevConfig[colName], {
610
- width: currentWidth
611
- })
612
- }));
613
- });
614
- const renderColumnTitle = useCallback((title, column, index, {
615
- withResize: _withResize = true,
616
- withConfig: _withConfig = false
617
- } = {}) => {
618
- const titleNode = _withConfig ? /*#__PURE__*/jsx(TableConfigButton, {
619
- title: title,
620
- columns: columns,
621
- config: config,
622
- setConfig: setConfig
623
- }) : title;
624
- const content = /*#__PURE__*/jsxs(Fragment, {
625
- children: [titleNode, _withResize && _controllerOpen && resizeBarRender(column, index)]
626
- });
627
- if (!_withResize || !_controllerOpen) {
628
- return content;
629
- }
630
- return /*#__PURE__*/jsx("span", {
631
- className: configStyle['header-cell-inner'],
632
- children: content
633
- });
634
- }, [columns, config, _controllerOpen, resizeBarRender, setConfig]);
635
- const getHeaderCellClassName = useCallback(index => classnames(configStyle['header-col'], {
636
- 'is-moving': currentMoveColumnIndexRef.current === index
637
- }), []);
638
- const computedColumnProps = useCallback((column, index, {
639
- title
640
- }) => {
641
- const {
642
- currentWidth
643
- } = getConfigWidth(column);
644
- const realWidth = computedRealWidth({
645
- width: currentWidth,
646
- index
647
- });
648
- const isLastColumn = index === columnCount - 1;
649
- const movingClass = () => ({
650
- className: classnames({
651
- 'is-moving': currentMoveColumnIndex === index,
652
- 'has-config-btn': isLastColumn && _controllerOpen
653
- })
654
- });
655
- return {
656
- onHeaderCell: movingClass,
657
- onCell: movingClass,
658
- width: realWidth,
659
- shouldCellUpdate: (record, prevRecord) => {
660
- const itemKey = typeof rowKey === 'function' ? rowKey(record) : record[rowKey];
661
- const prevItemKey = typeof rowKey === 'function' ? rowKey(prevRecord) : prevRecord[rowKey];
662
- return currentMoveColumnIndexRef.current === null || currentMoveColumnIndexRef.current === index || !(itemKey === prevItemKey && isEqual(record[column.name], prevRecord[column.name]));
663
- },
664
- title: renderColumnTitle(title, column, index, {
665
- withResize: true,
666
- withConfig: isLastColumn && _controllerOpen
667
- })
668
- };
669
- }, [columnCount, _controllerOpen, computedRealWidth, getConfigWidth, renderColumnTitle, rowKey, currentMoveColumnIndex]);
670
- useEffect(() => {
671
- const handlerCancelResize = () => {
672
- setCurrentMoveColumnIndex(null);
673
- startPointRef.current = null;
674
- currentMoveColumnRef.current = null;
675
- };
676
- const handlerResize = e => {
677
- if (currentMoveColumnIndexRef.current === null || currentMoveColumnRef.current === null || startPointRef.current === null) {
678
- return;
679
- }
680
- resize(e.clientX - startPointRef.current);
681
- };
682
- document.documentElement.addEventListener('mouseup', handlerCancelResize, true);
683
- document.documentElement.addEventListener('mousemove', handlerResize, true);
684
- return () => {
685
- document.documentElement.removeEventListener('mouseup', handlerCancelResize, true);
686
- document.documentElement.removeEventListener('mousemove', handlerResize, true);
687
- };
688
- }, [resize]);
689
- return {
690
- visibleColumns,
691
- columnsConfig: config,
692
- setConfig,
693
- currentMoveColumnIndex,
694
- totalWidth,
695
- hasFixedColumn,
696
- computedColumnProps,
697
- renderColumnTitle,
698
- getHeaderCellClassName,
699
- getConfigWidth,
700
- computedRealWidth,
701
- resizeBarRender
702
- };
703
- };
704
-
705
- const useGroupHeader = columns => {
706
- return useMemo(() => {
707
- const groupHeaderColumns = columns.filter(item => item.groupHeader && item.groupHeader.length > 0);
708
- if (groupHeaderColumns.length > 0) {
709
- const newColumns = columns.slice(0);
710
- const group = [];
711
- const appendGroupHeader = column => {
712
- const {
713
- groupHeader
714
- } = column;
715
- if (!(groupHeader && groupHeader.length > 0)) {
716
- return;
717
- }
718
- const columnIndex = newColumns.indexOf(column);
719
- const core = (groupHeader, groupList) => {
720
- const [targetHeader, ...otherHeader] = groupHeader;
721
- let currentGroup = groupList.find(item => item.name === targetHeader.name);
722
- if (!currentGroup) {
723
- currentGroup = Object.assign({
724
- startIndex: columnIndex
725
- }, targetHeader, {
726
- children: []
727
- });
728
- groupList.push(currentGroup);
729
- }
730
- if (otherHeader.length > 0) {
731
- core(otherHeader, currentGroup.children);
732
- } else {
733
- currentGroup.children.push(column);
734
- }
735
- };
736
- core(groupHeader, group);
737
- newColumns.splice(columnIndex, 1);
738
- };
739
- groupHeaderColumns.forEach(appendGroupHeader);
740
- group.forEach((groupColumn, index) => {
741
- newColumns.splice(groupColumn.startIndex + index, 0, groupColumn);
742
- });
743
- return {
744
- columns: newColumns,
745
- hasGroupHeader: true
746
- };
747
- }
748
- return {
749
- columns,
750
- hasGroupHeader: false
751
- };
752
- }, [columns]);
753
- };
754
-
755
- const useElementWidth = ref => {
756
- const [width, setWidth] = useState(0);
757
- useEffect(() => {
758
- const el = ref.current;
759
- if (!el) {
760
- return;
761
- }
762
- const update = () => setWidth(el.clientWidth);
763
- const resizeObserver = new ResizeObserver(update);
764
- resizeObserver.observe(el);
765
- update();
766
- return () => resizeObserver.disconnect();
767
- }, [ref]);
768
- return width;
769
- };
770
-
771
- const parsePixelValue = value => {
772
- const num = parseFloat(value);
773
- return Number.isNaN(num) ? 0 : num;
774
- };
775
- const normalizeScrollTopInsetCSSValue = value => {
776
- if (value == null) {
777
- return undefined;
778
- }
779
- if (typeof value === 'number') {
780
- return `${value}px`;
781
- }
782
- return String(value);
783
- };
784
- const resolveScrollTopInset = (scrollTopInset, stickyOffset) => scrollTopInset != null ? scrollTopInset : stickyOffset;
785
- const parseInsetPixels = (inset, element) => {
786
- if (inset == null) {
787
- return 0;
788
- }
789
- if (typeof inset === 'number') {
790
- return inset;
791
- }
792
- if (typeof inset === 'string') {
793
- const trimmed = inset.trim();
794
- if (trimmed.endsWith('px')) {
795
- return parsePixelValue(trimmed);
796
- }
797
- const variableMatch = trimmed.match(/var\(\s*(--[^,\s)]+)/);
798
- if (variableMatch) {
799
- return readCssVariableLength(element, variableMatch[1], '0px');
800
- }
801
- }
802
- return 0;
803
- };
804
- const readScrollTopInsetPixels = element => {
805
- const fromVar = readCssVariableLength(element, '--scroll-top-inset', '0px') || readCssVariableLength(element, '--sticky-offset', '0px') || readCssVariableLength(element, '--nav-height', '0px');
806
- return fromVar;
807
- };
808
- const getTableElement = root => {
809
- if (!root) {
810
- return null;
811
- }
812
- return root.querySelector('.info-page-table') || root;
813
- };
814
- const getScrollAnchorElement = (root, {
815
- preferToolbar: _preferToolbar = false
816
- } = {}) => {
817
- if (!root) {
818
- return null;
819
- }
820
- if (_preferToolbar) {
821
- return root.querySelector('.table-page-toolbar-section') || root.querySelector('.table-with-toolbar') || getTableElement(root);
822
- }
823
- return getTableElement(root);
824
- };
825
- const readCssVariableLength = (element, variableName, fallback = '0px') => {
826
- if (typeof document === 'undefined') {
827
- return 0;
828
- }
829
- const host = element || document.documentElement;
830
- const probe = document.createElement('div');
831
- probe.style.cssText = 'position:absolute;visibility:hidden;pointer-events:none;height:0;width:0;overflow:hidden;';
832
- probe.style.marginTop = `var(${variableName}, ${fallback})`;
833
- host.appendChild(probe);
834
- const value = parsePixelValue(getComputedStyle(probe).marginTop);
835
- host.removeChild(probe);
836
- return value;
837
- };
838
- const resolveScrollContainer = (element, getScrollContainer) => {
839
- const explicitContainer = typeof getScrollContainer === 'function' ? getScrollContainer() : null;
840
- if (explicitContainer) {
841
- return explicitContainer;
842
- }
843
- let parent = element == null ? void 0 : element.parentElement;
844
- while (parent) {
845
- const {
846
- overflowY
847
- } = getComputedStyle(parent);
848
- if (/(auto|scroll|overlay)/.test(overflowY) && parent.scrollHeight > parent.clientHeight + 1) {
849
- return parent;
850
- }
851
- parent = parent.parentElement;
852
- }
853
- return document.scrollingElement || document.documentElement;
854
- };
855
- const scrollToElement = (element, {
856
- offsetTop: _offsetTop = 0,
857
- getScrollContainer
858
- } = {}) => {
859
- const scrollContainer = resolveScrollContainer(element, getScrollContainer);
860
- const targetRect = element.getBoundingClientRect();
861
- if (scrollContainer === document.scrollingElement || scrollContainer === document.documentElement || scrollContainer === document.body) {
862
- const scrollTop = window.pageYOffset + targetRect.top - _offsetTop;
863
- window.scrollTo({
864
- top: Math.max(0, scrollTop),
865
- behavior: 'auto'
866
- });
867
- return;
868
- }
869
- const containerRect = scrollContainer.getBoundingClientRect();
870
- const nextScrollTop = scrollContainer.scrollTop + targetRect.top - containerRect.top - _offsetTop;
871
- scrollContainer.scrollTo({
872
- top: Math.max(0, nextScrollTop),
873
- behavior: 'auto'
874
- });
875
- };
876
- const scrollAnchorIntoView = (root, {
877
- getScrollContainer,
878
- preferToolbar: _preferToolbar2 = false
879
- } = {}) => {
880
- const target = getScrollAnchorElement(root, {
881
- preferToolbar: _preferToolbar2
882
- });
883
- if (!target) {
884
- return;
885
- }
886
- const offsetTop = readScrollTopInsetPixels(target);
887
- requestAnimationFrame(() => {
888
- requestAnimationFrame(() => {
889
- if (isTopEdgeInViewport(target, offsetTop, getScrollContainer)) {
890
- return;
891
- }
892
- scrollToElement(target, {
893
- offsetTop,
894
- getScrollContainer
895
- });
896
- });
897
- });
898
- };
899
- const isTopEdgeInViewport = (element, scrollMarginTop = 0, getScrollContainer) => {
900
- if (!element) {
901
- return true;
902
- }
903
- const rect = element.getBoundingClientRect();
904
- const explicitContainer = typeof getScrollContainer === 'function' ? getScrollContainer() : null;
905
- if (!isDocumentScrollContainer(explicitContainer)) {
906
- const containerRect = explicitContainer.getBoundingClientRect();
907
- const _viewportTop = containerRect.top + scrollMarginTop;
908
- return rect.top >= _viewportTop && rect.top < containerRect.bottom;
909
- }
910
- const viewport = getViewportRect();
911
- const viewportTop = viewport.top + scrollMarginTop;
912
- return rect.top >= viewportTop && rect.top < viewport.bottom;
913
- };
914
-
915
- /** 叶子去掉空 children,懒加载节点保留 [],避免 antd 把所有节点当成可展开 */
916
- const prepareAntdTreeNodes = (nodes, {
917
- childrenKey: _childrenKey = 'children',
918
- hasChildrenKey: _hasChildrenKey = 'hasChildren'
919
- } = {}) => (nodes || []).map(item => {
920
- const children = get(item, _childrenKey);
921
- const next = Object.assign({}, item);
922
- if (Array.isArray(children) && children.length > 0) {
923
- next[_childrenKey] = prepareAntdTreeNodes(children, {
924
- childrenKey: _childrenKey,
925
- hasChildrenKey: _hasChildrenKey
926
- });
927
- return next;
928
- }
929
- if (get(item, _hasChildrenKey) === true) {
930
- next[_childrenKey] = [];
931
- return next;
932
- }
933
- if (Object.prototype.hasOwnProperty.call(next, _childrenKey)) {
934
- delete next[_childrenKey];
935
- }
936
- return next;
937
- });
938
- const prepareAntdTreeData = (dataSource, {
939
- dataType: _dataType = 'list',
940
- rowKey: _rowKey = 'id',
941
- parentKey: _parentKey = 'parentId',
942
- childrenKey: _childrenKey2 = 'children',
943
- hasChildrenKey: _hasChildrenKey2 = 'hasChildren'
944
- } = {}) => {
945
- const isTree = isTreeDataType(_dataType);
946
- if (!isTree) {
947
- return {
948
- isTree: false,
949
- treeData: dataSource,
950
- expandableKeys: [],
951
- treeKeyMaps: null
952
- };
953
- }
954
- const tree = normalizeTreeData(dataSource, {
955
- dataType: _dataType,
956
- rowKey: _rowKey,
957
- parentKey: _parentKey,
958
- childrenKey: _childrenKey2
959
- });
960
- const treeData = prepareAntdTreeNodes(tree, {
961
- childrenKey: _childrenKey2,
962
- hasChildrenKey: _hasChildrenKey2
963
- });
964
- const expandableKeys = collectExpandableKeys(treeData, {
965
- rowKey: _rowKey,
966
- childrenKey: _childrenKey2,
967
- hasChildrenKey: _hasChildrenKey2
968
- });
969
- const treeKeyMaps = buildTreeKeyMaps(treeData, {
970
- rowKey: _rowKey,
971
- childrenKey: _childrenKey2
972
- });
973
- return {
974
- isTree: true,
975
- treeData,
976
- expandableKeys,
977
- treeKeyMaps
978
- };
979
- };
980
- const resolveExpandedRowKeys = (expandedKeys, expandableKeys = []) => {
981
- if (expandedKeys === true) {
982
- return expandableKeys.slice();
983
- }
984
- if (expandedKeys === false || expandedKeys == null) {
985
- return [];
986
- }
987
- return Array.isArray(expandedKeys) ? expandedKeys.slice() : [];
988
- };
989
- const shouldLoadTreeChildren = (item, {
990
- key,
991
- childrenKey: _childrenKey3 = 'children',
992
- hasChildrenKey: _hasChildrenKey3 = 'hasChildren',
993
- loadingKeys,
994
- loadedKeys
995
- }) => {
996
- if (get(item, _hasChildrenKey3) !== true) {
997
- return false;
998
- }
999
- const children = get(item, _childrenKey3);
1000
- if (Array.isArray(children) && children.length > 0) {
1001
- return false;
1002
- }
1003
- if (loadingKeys != null && loadingKeys.has != null && loadingKeys.has(key) || loadedKeys != null && loadedKeys.has != null && loadedKeys.has(key)) {
1004
- return false;
1005
- }
1006
- return nodeCanExpand(item, {
1007
- childrenKey: _childrenKey3,
1008
- hasChildrenKey: _hasChildrenKey3
1009
- });
1010
- };
1011
-
1012
- const TreeExpandContent = ({
1013
- level: _level = 0,
1014
- indentSize: _indentSize = 16,
1015
- hasChildren,
1016
- expanded,
1017
- loading,
1018
- onExpand,
1019
- selection,
1020
- className
1021
- }) => /*#__PURE__*/jsxs("span", {
1022
- className: classnames(style$2['tree-selection-content'], className, 'info-page-table-col-content'),
1023
- children: [/*#__PURE__*/jsx("span", {
1024
- className: style$2['tree-indent'],
1025
- style: {
1026
- width: _level * _indentSize,
1027
- minWidth: _level * _indentSize
1028
- }
1029
- }), hasChildren ? /*#__PURE__*/jsx("button", {
1030
- type: "button",
1031
- className: classnames(style$2['tree-expand'], {
1032
- [style$2['is-expanded']]: expanded && !loading,
1033
- [style$2['is-loading']]: loading
1034
- }),
1035
- "aria-expanded": !!expanded,
1036
- disabled: !!loading,
1037
- onClick: event => {
1038
- event.stopPropagation();
1039
- if (loading) {
1040
- return;
1041
- }
1042
- onExpand == null || onExpand(event);
1043
- },
1044
- children: loading ? /*#__PURE__*/jsx(LoadingOutlined, {
1045
- spin: true
1046
- }) : /*#__PURE__*/jsx(CaretRightOutlined, {})
1047
- }) : /*#__PURE__*/jsx("span", {
1048
- className: style$2['tree-leaf-placeholder']
1049
- }), selection ? /*#__PURE__*/jsx("span", {
1050
- className: style$2['tree-selection-control'],
1051
- children: selection
1052
- }) : null]
1053
- });
1054
-
1055
- const _excluded$3 = ["className", "dataSource", "columns", "rowKey", "rowSelection", "valueIsEmpty", "emptyIsPlaceholder", "placeholder", "empty", "onRowSelect", "render", "renderMobile", "context", "sticky", "scrollTopInset", "stickyOffset", "getStickyContainer", "headerStyle", "pagination", "sortRender", "mobileSortToolbar", "name", "controllerOpen", "tableServerApis", "scroll", "summary", "size", "dataType", "parentKey", "childrenKey", "hasChildrenKey", "treeTitleKey", "onLoadChildren", "expandedKeys", "defaultExpandedKeys", "onExpandedKeysChange", "indentSize"],
1056
- _excluded2$2 = ["y"],
1057
- _excluded3$2 = ["getContainer"];
1058
- const mapJustifyToAlign = justify => {
1059
- if (justify === 'center') {
1060
- return 'center';
1061
- }
1062
- if (justify === 'flex-end') {
1063
- return 'right';
1064
- }
1065
- return 'left';
1066
- };
1067
- const resolveRowKey = (rowKey, record) => get(record, typeof rowKey === 'function' ? rowKey(record) : rowKey);
1068
- const toAntdWidth = width => {
1069
- if (width == null) {
1070
- return undefined;
1071
- }
1072
- if (typeof width === 'number') {
1073
- return width;
1074
- }
1075
- const parsed = parseColumnWidth(width);
1076
- return parsed || width;
1077
- };
1078
- const toAntdFixed = fixed => {
1079
- if (fixed === 'right') {
1080
- return 'right';
1081
- }
1082
- if (fixed === true || fixed === 'left') {
1083
- return 'left';
1084
- }
1085
- return undefined;
1086
- };
1087
- const getColCellStyle = column => ({
1088
- textAlign: mapJustifyToAlign(column.justify),
1089
- verticalAlign: column.align === 'middle' ? 'middle' : column.align === 'bottom' ? 'bottom' : 'top'
1090
- });
1091
- const getAntCellClassName = (...extra) => classnames(style$2['table-cell'], 'info-page-table-col', ...extra);
1092
- const wrapColContent = node => /*#__PURE__*/jsx("span", {
1093
- className: style$2['col-content'],
1094
- children: node
1095
- });
1096
- const Table = p => {
1097
- const tableRef = useRef(null);
1098
- const tableWidth = useElementWidth(tableRef);
1099
- // controllerOpen 默认 true:需等列宽计算;骨架屏等场景显式 false 时可立即渲染
1100
- const [isLayout, setIsLayout] = useState(() => p.controllerOpen !== false);
1101
- const isMobile = useIsMobile();
1102
- const props = Object.assign({}, {
1103
- rowKey: 'id',
1104
- valueIsEmpty: isEmpty,
1105
- placeholder: '-',
1106
- emptyIsPlaceholder: true,
1107
- empty: /*#__PURE__*/jsx(Empty, {}),
1108
- controllerOpen: true,
1109
- dataType: 'list',
1110
- parentKey: 'parentId',
1111
- childrenKey: 'children',
1112
- hasChildrenKey: 'hasChildren',
1113
- treeTitleKey: 'name',
1114
- defaultExpandedKeys: false,
1115
- indentSize: 16
1116
- }, p);
1117
- const {
1118
- className,
1119
- dataSource,
1120
- columns: columnsProp,
1121
- rowKey,
1122
- rowSelection,
1123
- valueIsEmpty,
1124
- emptyIsPlaceholder,
1125
- placeholder,
1126
- empty,
1127
- onRowSelect,
1128
- render,
1129
- renderMobile = true,
1130
- context,
1131
- sticky,
1132
- scrollTopInset,
1133
- stickyOffset,
1134
- getStickyContainer,
1135
- headerStyle,
1136
- pagination = false,
1137
- sortRender,
1138
- mobileSortToolbar,
1139
- name,
1140
- controllerOpen,
1141
- tableServerApis,
1142
- scroll,
1143
- summary,
1144
- size,
1145
- dataType,
1146
- parentKey,
1147
- childrenKey,
1148
- hasChildrenKey,
1149
- treeTitleKey,
1150
- onLoadChildren,
1151
- expandedKeys: expandedKeysProp,
1152
- defaultExpandedKeys,
1153
- onExpandedKeysChange,
1154
- indentSize
1155
- } = props,
1156
- others = _objectWithoutPropertiesLoose(props, _excluded$3);
1157
- const sizeClassName = size === 'small' ? style$2['is-size-small'] : size === 'large' ? style$2['is-size-large'] : null;
1158
- const useMobileRender = isRenderMobileActive(renderMobile, isMobile);
1159
- const isExpandedControlled = Object.prototype.hasOwnProperty.call(p, 'expandedKeys');
1160
- const [innerExpandedKeys, setInnerExpandedKeys] = useState(defaultExpandedKeys);
1161
- const expandedKeys = isExpandedControlled ? expandedKeysProp : innerExpandedKeys;
1162
- const [loadingKeys, setLoadingKeys] = useState(() => new Set());
1163
- const loadedKeysRef = useRef(new Set());
1164
- const columns = useMemo(() => resolveColumns(columnsProp), [columnsProp]);
1165
- const {
1166
- isTree,
1167
- treeData,
1168
- expandableKeys,
1169
- treeKeyMaps
1170
- } = useMemo(() => prepareAntdTreeData(dataSource, {
1171
- dataType,
1172
- rowKey,
1173
- parentKey,
1174
- childrenKey,
1175
- hasChildrenKey
1176
- }), [dataSource, dataType, rowKey, parentKey, childrenKey, hasChildrenKey]);
1177
- const checkRelation = resolveCheckRelation(rowSelection == null ? void 0 : rowSelection.checkRelation, {
1178
- isTree,
1179
- selectionType: rowSelection == null ? void 0 : rowSelection.type
1180
- });
1181
- const tableDataSource = isTree ? treeData : dataSource;
1182
- const handleExpandedChange = useCallback(nextKeys => {
1183
- if (!isExpandedControlled) {
1184
- setInnerExpandedKeys(nextKeys);
1185
- }
1186
- onExpandedKeysChange && onExpandedKeysChange(nextKeys);
1187
- }, [isExpandedControlled, onExpandedKeysChange]);
1188
- const clearLoadingKey = key => {
1189
- setLoadingKeys(prev => {
1190
- if (!prev.has(key)) {
1191
- return prev;
1192
- }
1193
- const next = new Set(prev);
1194
- next.delete(key);
1195
- return next;
1196
- });
1197
- };
1198
- const handleLoadChildren = useCallback(record => {
1199
- if (typeof onLoadChildren !== 'function') {
1200
- return;
1201
- }
1202
- const key = resolveRowKey(rowKey, record);
1203
- if (!shouldLoadTreeChildren(record, {
1204
- key,
1205
- childrenKey,
1206
- hasChildrenKey,
1207
- loadingKeys,
1208
- loadedKeys: loadedKeysRef.current
1209
- })) {
1210
- return;
1211
- }
1212
- setLoadingKeys(prev => new Set(prev).add(key));
1213
- Promise.resolve(onLoadChildren(record, {
1214
- key
1215
- })).catch(() => {}).finally(() => {
1216
- loadedKeysRef.current.add(key);
1217
- clearLoadingKey(key);
1218
- });
1219
- }, [onLoadChildren, rowKey, childrenKey, hasChildrenKey, loadingKeys]);
1220
- const expandedRowKeys = useMemo(() => isTree ? resolveExpandedRowKeys(expandedKeys, expandableKeys) : undefined, [isTree, expandedKeys, expandableKeys]);
1221
- const maxTreeLevel = useMemo(() => {
1222
- if (!isTree) {
1223
- return 0;
1224
- }
1225
- const displayRows = flattenVisibleTree(treeData, {
1226
- rowKey,
1227
- childrenKey,
1228
- hasChildrenKey,
1229
- expandedKeys
1230
- });
1231
- return displayRows.reduce((max, row) => Math.max(max, row.level || 0), 0);
1232
- }, [isTree, treeData, rowKey, childrenKey, hasChildrenKey, expandedKeys]);
1233
- const selectionColumnWidth = useMemo(() => getTreeSelectionColumnWidth({
1234
- indentSize,
1235
- maxLevel: maxTreeLevel,
1236
- rowSelection,
1237
- isTree
1238
- }), [indentSize, maxTreeLevel, rowSelection, isTree]);
1239
- // antd 单元格会裁剪 overflow,树形选择列多留 2px 避免 checkbox 右边框被切
1240
- const antdSelectionColumnWidth = isTree && selectionColumnWidth > 0 ? selectionColumnWidth + 2 : selectionColumnWidth;
1241
- const handleToggleExpand = useCallback((key, record) => {
1242
- const wasExpanded = (expandedRowKeys || []).indexOf(key) > -1;
1243
- const nextKeys = toggleExpandedKey(expandedKeys, key, expandableKeys);
1244
- handleExpandedChange(nextKeys);
1245
- if (!wasExpanded) {
1246
- handleLoadChildren(record);
1247
- }
1248
- }, [expandedRowKeys, expandedKeys, expandableKeys, handleExpandedChange, handleLoadChildren]);
1249
- const getTreeRowMeta = useCallback(record => {
1250
- var _treeKeyMaps$getAnces;
1251
- const key = resolveRowKey(rowKey, record);
1252
- const level = (treeKeyMaps == null || (_treeKeyMaps$getAnces = treeKeyMaps.getAncestorKeys(key)) == null ? void 0 : _treeKeyMaps$getAnces.length) || 0;
1253
- return {
1254
- key,
1255
- level,
1256
- hasChildren: nodeCanExpand(record, {
1257
- childrenKey,
1258
- hasChildrenKey
1259
- }),
1260
- expanded: (expandedRowKeys || []).indexOf(key) > -1
1261
- };
1262
- }, [rowKey, treeKeyMaps, childrenKey, hasChildrenKey, expandedRowKeys]);
1263
- const antdExpandable = useMemo(() => {
1264
- if (!isTree) {
1265
- return others.expandable;
1266
- }
1267
- // 隐藏 antd 默认展开列,改用与 TableView 一致的自绘三角
1268
- return Object.assign({}, others.expandable, {
1269
- childrenColumnName: childrenKey,
1270
- showExpandColumn: false,
1271
- expandIcon: () => null,
1272
- indentSize: 0,
1273
- expandedRowKeys,
1274
- onExpandedRowsChange: keys => {
1275
- var _others$expandable;
1276
- (_others$expandable = others.expandable) == null || _others$expandable.onExpandedRowsChange == null || _others$expandable.onExpandedRowsChange(keys);
1277
- handleExpandedChange(keys);
1278
- }
1279
- });
1280
- }, [isTree, others.expandable, childrenKey, expandedRowKeys, handleExpandedChange]);
1281
- useEffect(() => {
1282
- if (tableWidth) {
1283
- setTimeout(() => setIsLayout(false), 0);
1284
- }
1285
- }, [tableWidth]);
1286
- const {
1287
- visibleColumns,
1288
- columnsConfig,
1289
- currentMoveColumnIndex,
1290
- totalWidth,
1291
- computedColumnProps,
1292
- hasFixedColumn
1293
- } = useTableConfig({
1294
- columns,
1295
- name,
1296
- controllerOpen,
1297
- tableWidth,
1298
- rowKey,
1299
- tableServerApis
1300
- });
1301
- const [resizeGuideStyle, setResizeGuideStyle] = useState(null);
1302
- const updateResizeGuide = useCallback(() => {
1303
- var _barRect$right;
1304
- if (currentMoveColumnIndex === null || !tableRef.current) {
1305
- setResizeGuideStyle(null);
1306
- return;
1307
- }
1308
- const root = tableRef.current;
1309
- const headerCell = root.querySelector('.ant-table-thead .ant-table-cell.is-moving');
1310
- const tableContainer = root.querySelector('.ant-table-container');
1311
- if (!headerCell || !tableContainer) {
1312
- setResizeGuideStyle(null);
1313
- return;
1314
- }
1315
- const wrapperRect = root.getBoundingClientRect();
1316
- const headerRect = headerCell.getBoundingClientRect();
1317
- const resizeBar = headerCell.querySelector('.table-cell-resize-bar');
1318
- const barRect = resizeBar == null ? void 0 : resizeBar.getBoundingClientRect();
1319
- const containerRect = tableContainer.getBoundingClientRect();
1320
- setResizeGuideStyle({
1321
- left: Math.round(((_barRect$right = barRect == null ? void 0 : barRect.right) != null ? _barRect$right : headerRect.right) - wrapperRect.left),
1322
- top: Math.round(containerRect.top - wrapperRect.top),
1323
- height: Math.round(containerRect.height)
1324
- });
1325
- }, [currentMoveColumnIndex]);
1326
- useLayoutEffect(() => {
1327
- updateResizeGuide();
1328
- }, [updateResizeGuide, columnsConfig, tableWidth, dataSource, isLayout]);
1329
- useEffect(() => {
1330
- if (currentMoveColumnIndex === null) {
1331
- return;
1332
- }
1333
- const handleUpdate = () => updateResizeGuide();
1334
- window.addEventListener('mousemove', handleUpdate);
1335
- window.addEventListener('scroll', handleUpdate, true);
1336
- const resizeObserver = new ResizeObserver(handleUpdate);
1337
- if (tableRef.current) {
1338
- resizeObserver.observe(tableRef.current);
1339
- }
1340
- return () => {
1341
- window.removeEventListener('mousemove', handleUpdate);
1342
- window.removeEventListener('scroll', handleUpdate, true);
1343
- resizeObserver.disconnect();
1344
- };
1345
- }, [currentMoveColumnIndex, updateResizeGuide]);
1346
- const targetColumns = useMemo(() => visibleColumns.map((column, index) => Object.assign({}, column, {
1347
- __index: index
1348
- })), [visibleColumns]);
1349
- const {
1350
- columns: groupedColumns,
1351
- hasGroupHeader
1352
- } = useGroupHeader(targetColumns);
1353
- const antdColumns = useMemo(() => {
1354
- const buildLeafColumn = (column, index) => {
1355
- const {
1356
- name: colName,
1357
- title,
1358
- width,
1359
- align,
1360
- justify,
1361
- fixed
1362
- } = column;
1363
- const baseColumn = {
1364
- key: colName,
1365
- dataIndex: colName,
1366
- title: /*#__PURE__*/jsx("span", {
1367
- className: style$2['col-content'],
1368
- children: renderColumnTitle(title, column, sortRender)
1369
- }),
1370
- width: toAntdWidth(width),
1371
- fixed: toAntdFixed(fixed),
1372
- align: mapJustifyToAlign(justify),
1373
- ellipsis: getColumnEllipsis(column),
1374
- onHeaderCell: () => ({
1375
- className: getAntCellClassName(),
1376
- style: getColCellStyle(column)
1377
- }),
1378
- onCell: () => ({
1379
- className: getAntCellClassName(),
1380
- style: getColCellStyle(column)
1381
- }),
1382
- render: (_, record) => {
1383
- const [computedColumn] = computeColumnsValue({
1384
- columns: [column],
1385
- emptyIsPlaceholder,
1386
- valueIsEmpty,
1387
- removeEmpty: false,
1388
- dataSource: record,
1389
- placeholder,
1390
- context
1391
- });
1392
- if (!computedColumn) {
1393
- return null;
1394
- }
1395
- return renderCellContent(computeDisplay({
1396
- column: computedColumn,
1397
- placeholder,
1398
- dataSource: record,
1399
- context
1400
- }), computedColumn, style$2['col-content']);
1401
- }
1402
- };
1403
- if (!controllerOpen) {
1404
- return baseColumn;
1405
- }
1406
- const configProps = computedColumnProps(column, index, {
1407
- title: /*#__PURE__*/jsx("span", {
1408
- className: style$2['col-content'],
1409
- children: renderColumnTitle(title, column, sortRender)
1410
- })
1411
- });
1412
- const antdFixed = toAntdFixed(fixed);
1413
- return Object.assign({}, baseColumn, configProps, {
1414
- width: configProps.width,
1415
- fixed: antdFixed,
1416
- onHeaderCell: () => ({
1417
- className: getAntCellClassName(configProps.onHeaderCell == null ? void 0 : configProps.onHeaderCell().className),
1418
- style: getColCellStyle(column)
1419
- }),
1420
- onCell: () => ({
1421
- className: getAntCellClassName(configProps.onCell == null ? void 0 : configProps.onCell().className),
1422
- style: getColCellStyle(column)
1423
- })
1424
- });
1425
- };
1426
- const mapColumn = column => {
1427
- if (column.children && column.children.length > 0) {
1428
- return {
1429
- key: column.name,
1430
- title: /*#__PURE__*/jsx("span", {
1431
- className: style$2['col-content'],
1432
- children: wrapColumnHeaderTitle(column.title)
1433
- }),
1434
- onHeaderCell: () => ({
1435
- className: getAntCellClassName(),
1436
- style: {
1437
- textAlign: 'center',
1438
- verticalAlign: 'middle'
1439
- }
1440
- }),
1441
- children: column.children.map(mapColumn)
1442
- };
1443
- }
1444
- return buildLeafColumn(column, column.__index);
1445
- };
1446
- const mapped = groupedColumns.map(mapColumn);
1447
- if (!isTree || rowSelection) {
1448
- return mapped;
1449
- }
1450
- const expandColumn = {
1451
- key: '__tree_expand__',
1452
- width: antdSelectionColumnWidth,
1453
- fixed: hasFixedColumn ? 'left' : undefined,
1454
- title: /*#__PURE__*/jsx(TreeExpandContent, {
1455
- level: 0,
1456
- indentSize: indentSize,
1457
- hasChildren: false
1458
- }),
1459
- onHeaderCell: () => ({
1460
- className: getAntCellClassName(style$2['tree-expand-col'])
1461
- }),
1462
- onCell: () => ({
1463
- className: getAntCellClassName(style$2['tree-expand-col'])
1464
- }),
1465
- render: (_, record) => {
1466
- const meta = getTreeRowMeta(record);
1467
- return /*#__PURE__*/jsx(TreeExpandContent, {
1468
- level: meta.level,
1469
- indentSize: indentSize,
1470
- hasChildren: meta.hasChildren,
1471
- expanded: meta.expanded,
1472
- loading: loadingKeys.has(meta.key),
1473
- onExpand: () => handleToggleExpand(meta.key, record)
1474
- });
1475
- }
1476
- };
1477
- return [expandColumn, ...mapped];
1478
- }, [groupedColumns, context, emptyIsPlaceholder, placeholder, sortRender, valueIsEmpty, controllerOpen, computedColumnProps, currentMoveColumnIndex, isTree, rowSelection, antdSelectionColumnWidth, hasFixedColumn, indentSize, getTreeRowMeta, loadingKeys, handleToggleExpand]);
1479
- const antdRowSelection = useMemo(() => {
1480
- if (!rowSelection) {
1481
- return undefined;
1482
- }
1483
- const getRowKey = record => resolveRowKey(rowKey, record);
1484
- // 全选判断/操作只针对可勾选行,排除 disabled
1485
- const allKeys = isTree ? ((treeKeyMaps == null ? void 0 : treeKeyMaps.allKeys) || []).filter(key => {
1486
- var _treeKeyMaps$nodeMap$;
1487
- return !((_treeKeyMaps$nodeMap$ = treeKeyMaps.nodeMap.get(key)) != null && _treeKeyMaps$nodeMap$.disabled);
1488
- }) : (dataSource || []).filter(item => !item.disabled).map(getRowKey);
1489
- const useTreeCheck = isTree && rowSelection.type === 'checkbox' && checkRelation !== 'independent' && treeKeyMaps;
1490
- const renderSelectAllNode = () => {
1491
- if (rowSelection.type !== 'checkbox') {
1492
- return null;
1493
- }
1494
- if (!rowSelection.allowSelectedAll) {
1495
- return /*#__PURE__*/jsx(Checkbox, {
1496
- style: {
1497
- visibility: 'hidden'
1498
- }
1499
- });
1500
- }
1501
- if (useTreeCheck) {
1502
- const _checkedAll = rowSelection.isSelectedAll ? true : isAllTreeSelected({
1503
- mode: checkRelation,
1504
- maps: treeKeyMaps,
1505
- selectedKeys: rowSelection.selectedRowKeys
1506
- });
1507
- const _indeterminate = rowSelection.isSelectedAll ? false : !_checkedAll && hasAnyTreeSelected({
1508
- mode: checkRelation,
1509
- maps: treeKeyMaps,
1510
- selectedKeys: rowSelection.selectedRowKeys
1511
- });
1512
- return /*#__PURE__*/jsx(Checkbox, {
1513
- checked: _checkedAll,
1514
- indeterminate: _indeterminate,
1515
- onChange: e => {
1516
- const checked = e.target.checked;
1517
- if (typeof rowSelection.onIsSelectAllChange === 'function') {
1518
- rowSelection.onIsSelectAllChange(checked);
1519
- return;
1520
- }
1521
- const existing = rowSelection.selectedRowKeys || [];
1522
- rowSelection.onChange(checked ? buildSelectAllKeys({
1523
- mode: checkRelation,
1524
- maps: treeKeyMaps,
1525
- existingKeys: existing
1526
- }) : buildClearSelectAllKeys({
1527
- mode: checkRelation,
1528
- maps: treeKeyMaps,
1529
- existingKeys: existing
1530
- }), undefined, {
1531
- context,
1532
- checked
1533
- });
1534
- }
1535
- });
1536
- }
1537
- const checkedAll = rowSelection.isSelectedAll || allKeys.length > 0 && allKeys.every(key => (rowSelection.selectedRowKeys || []).indexOf(key) > -1);
1538
- const indeterminate = !checkedAll && allKeys.some(key => (rowSelection.selectedRowKeys || []).indexOf(key) > -1);
1539
- return /*#__PURE__*/jsx(Checkbox, {
1540
- checked: checkedAll,
1541
- indeterminate: indeterminate,
1542
- onChange: e => {
1543
- const checked = e.target.checked;
1544
- if (typeof rowSelection.onIsSelectAllChange === 'function') {
1545
- rowSelection.onIsSelectAllChange(checked);
1546
- return;
1547
- }
1548
- const existing = rowSelection.selectedRowKeys || [];
1549
- if (!checked) {
1550
- rowSelection.onChange(existing.filter(key => allKeys.indexOf(key) === -1), undefined, {
1551
- context,
1552
- checked: false
1553
- });
1554
- return;
1555
- }
1556
- if (allKeys.length === 0) {
1557
- return;
1558
- }
1559
- const merged = existing.slice();
1560
- allKeys.forEach(key => {
1561
- if (merged.indexOf(key) === -1) {
1562
- merged.push(key);
1563
- }
1564
- });
1565
- rowSelection.onChange(merged, undefined, {
1566
- context,
1567
- checked: true
1568
- });
1569
- }
1570
- });
1571
- };
1572
- const renderTreeSelectionControl = record => {
1573
- const id = getRowKey(record);
1574
- if (rowSelection.type === 'checkbox') {
1575
- const state = useTreeCheck ? getTreeCheckState(id, rowSelection.selectedRowKeys, checkRelation, treeKeyMaps) : {
1576
- checked: (rowSelection.selectedRowKeys || []).indexOf(id) > -1,
1577
- indeterminate: false
1578
- };
1579
- return /*#__PURE__*/jsx(Checkbox, {
1580
- disabled: record.disabled || rowSelection.isSelectedAll,
1581
- checked: rowSelection.isSelectedAll && !record.disabled || state.checked,
1582
- indeterminate: !rowSelection.isSelectedAll && !!state.indeterminate,
1583
- onChange: e => {
1584
- const nextChecked = e.target.checked;
1585
- if (useTreeCheck) {
1586
- const nextKeys = toggleTreeCheck({
1587
- key: id,
1588
- checked: nextChecked,
1589
- selectedKeys: rowSelection.selectedRowKeys || [],
1590
- mode: checkRelation,
1591
- maps: treeKeyMaps
1592
- });
1593
- rowSelection.onChange(nextKeys, id, {
1594
- context,
1595
- checked: nextChecked
1596
- });
1597
- return;
1598
- }
1599
- const selectedRowKeys = (rowSelection.selectedRowKeys || []).slice();
1600
- if (nextChecked) {
1601
- if (selectedRowKeys.indexOf(id) === -1) {
1602
- selectedRowKeys.push(id);
1603
- }
1604
- } else {
1605
- const index = selectedRowKeys.indexOf(id);
1606
- if (index > -1) {
1607
- selectedRowKeys.splice(index, 1);
1608
- }
1609
- }
1610
- rowSelection.onChange(selectedRowKeys, id, {
1611
- context,
1612
- checked: nextChecked
1613
- });
1614
- }
1615
- });
1616
- }
1617
- if (rowSelection.type === 'radio') {
1618
- const checked = (rowSelection.selectedRowKeys || [])[0] === id;
1619
- return /*#__PURE__*/jsx(Radio, {
1620
- disabled: record.disabled,
1621
- checked: checked,
1622
- onChange: () => {
1623
- rowSelection.onChange(checked ? [] : [id], id, {
1624
- context,
1625
- checked: !checked
1626
- });
1627
- }
1628
- });
1629
- }
1630
- return null;
1631
- };
1632
- if (isTree) {
1633
- const selectAllNode = rowSelection.type === 'checkbox' ? renderSelectAllNode() : null;
1634
- return _extends({
1635
- type: rowSelection.type === 'radio' ? 'radio' : 'checkbox',
1636
- preserveSelectedRowKeys: true,
1637
- checkStrictly: true,
1638
- hideSelectAll: true,
1639
- columnWidth: antdSelectionColumnWidth
1640
- }, hasFixedColumn ? {
1641
- fixed: 'left'
1642
- } : {}, {
1643
- selectedRowKeys: rowSelection.isSelectedAll ? allKeys : rowSelection.selectedRowKeys,
1644
- onChange: () => {},
1645
- getCheckboxProps: record => ({
1646
- disabled: record.disabled || rowSelection.isSelectedAll
1647
- }),
1648
- columnTitle: /*#__PURE__*/jsx(TreeExpandContent, {
1649
- level: 0,
1650
- indentSize: indentSize,
1651
- hasChildren: false,
1652
- selection: selectAllNode
1653
- }),
1654
- renderCell: (checked, record) => {
1655
- const meta = getTreeRowMeta(record);
1656
- return /*#__PURE__*/jsx(TreeExpandContent, {
1657
- level: meta.level,
1658
- indentSize: indentSize,
1659
- hasChildren: meta.hasChildren,
1660
- expanded: meta.expanded,
1661
- loading: loadingKeys.has(meta.key),
1662
- onExpand: () => handleToggleExpand(meta.key, record),
1663
- selection: renderTreeSelectionControl(record)
1664
- });
1665
- },
1666
- onCell: () => ({
1667
- className: getAntCellClassName(style$2['selection-col'])
1668
- })
1669
- });
1670
- }
1671
- return _extends({
1672
- type: rowSelection.type === 'radio' ? 'radio' : 'checkbox',
1673
- preserveSelectedRowKeys: true,
1674
- hideSelectAll: true
1675
- }, hasFixedColumn ? {
1676
- fixed: 'left'
1677
- } : {}, {
1678
- selectedRowKeys: rowSelection.isSelectedAll ? allKeys : rowSelection.selectedRowKeys,
1679
- onChange: (selectedRowKeys, selectedRows) => {
1680
- const currentKey = selectedRows.length > 0 ? getRowKey(selectedRows[selectedRows.length - 1]) : selectedRowKeys[selectedRowKeys.length - 1];
1681
- const checked = selectedRowKeys.indexOf(currentKey) > -1;
1682
- rowSelection.onChange(selectedRowKeys, currentKey, {
1683
- context,
1684
- checked
1685
- });
1686
- },
1687
- getCheckboxProps: record => ({
1688
- disabled: record.disabled || rowSelection.isSelectedAll
1689
- })
1690
- }, rowSelection.type === 'checkbox' ? {
1691
- columnWidth: antdSelectionColumnWidth || 48,
1692
- columnTitle: wrapColContent(renderSelectAllNode()),
1693
- renderCell: (checked, record, index, originNode) => wrapColContent(originNode),
1694
- onCell: () => ({
1695
- className: getAntCellClassName(style$2['selection-col'])
1696
- })
1697
- } : {
1698
- columnWidth: antdSelectionColumnWidth || 48,
1699
- renderCell: (checked, record, index, originNode) => wrapColContent(originNode),
1700
- onCell: () => ({
1701
- className: getAntCellClassName(style$2['radio-col'])
1702
- })
1703
- });
1704
- }, [context, dataSource, rowKey, rowSelection, hasFixedColumn, isTree, treeKeyMaps, checkRelation, antdSelectionColumnWidth, indentSize, getTreeRowMeta, loadingKeys, handleToggleExpand]);
1705
- const hasData = Array.isArray(tableDataSource) && tableDataSource.length > 0;
1706
- const tableScroll = useMemo(() => {
1707
- let x;
1708
- if (hasFixedColumn) {
1709
- x = totalWidth;
1710
- } else if (controllerOpen) {
1711
- x = Math.max(tableWidth, totalWidth);
1712
- } else if (tableWidth && totalWidth > tableWidth) {
1713
- // controllerOpen 关闭时列总宽超出容器也要开启横向滚动,避免列溢出
1714
- x = totalWidth;
1715
- }
1716
- if (x != null && isTree && antdSelectionColumnWidth) {
1717
- x += antdSelectionColumnWidth;
1718
- }
1719
- const nextScroll = Object.assign({}, x != null ? {
1720
- x
1721
- } : {}, scroll);
1722
- if (!hasData && nextScroll.y != null) {
1723
- const rest = _objectWithoutPropertiesLoose(nextScroll, _excluded2$2);
1724
- return rest;
1725
- }
1726
- return nextScroll;
1727
- }, [hasFixedColumn, controllerOpen, totalWidth, tableWidth, scroll, hasData, isTree, antdSelectionColumnWidth]);
1728
- const hasScrollY = hasData && (scroll == null ? void 0 : scroll.y) != null && (scroll == null ? void 0 : scroll.y) !== false;
1729
- const isStickyViewport = !!sticky && !hasScrollY;
1730
- const resolvedScrollTopInset = resolveScrollTopInset(scrollTopInset, stickyOffset);
1731
- const stickyGetContainer = useMemo(() => {
1732
- if (!getStickyContainer || hasScrollY) {
1733
- return undefined;
1734
- }
1735
- return () => getStickyContainer() || window;
1736
- }, [getStickyContainer, hasScrollY]);
1737
- const parsedScrollTopInset = useMemo(() => {
1738
- if (!sticky || hasScrollY) {
1739
- return 0;
1740
- }
1741
- return parseInsetPixels(resolvedScrollTopInset, tableRef.current);
1742
- }, [sticky, hasScrollY, resolvedScrollTopInset, isLayout, dataSource]);
1743
- const antdSticky = useMemo(() => {
1744
- if (!sticky) {
1745
- return undefined;
1746
- }
1747
- const config = typeof sticky === 'object' ? Object.assign({}, sticky) : {};
1748
- if (hasScrollY) {
1749
- const scrollSticky = _objectWithoutPropertiesLoose(config, _excluded3$2);
1750
- return Object.assign({
1751
- offsetHeader: 0
1752
- }, scrollSticky);
1753
- }
1754
- return Object.assign({
1755
- offsetHeader: parsedScrollTopInset
1756
- }, config, stickyGetContainer ? {
1757
- getContainer: stickyGetContainer
1758
- } : null);
1759
- }, [sticky, stickyGetContainer, hasScrollY, parsedScrollTopInset]);
1760
- const tableWrapperStyle = useMemo(() => {
1761
- const next = {};
1762
- const cssValue = normalizeScrollTopInsetCSSValue(resolvedScrollTopInset);
1763
- if (cssValue) {
1764
- next['--scroll-top-inset'] = cssValue;
1765
- }
1766
- if (antdSelectionColumnWidth) {
1767
- next['--selection-col-width'] = `${antdSelectionColumnWidth}px`;
12
+ import useRefCallback from '@kne/use-ref-callback';
13
+ import useControlValue from '@kne/use-control-value';
14
+ import { useMemo, useState, useRef, useEffect, forwardRef, useImperativeHandle } from 'react';
15
+ import { createWithIntlProvider, useIntl } from '@kne/react-intl';
16
+ import { usePopupContainer, useIsMobile } from '@kne/responsive-utils';
17
+ import filterZhCN from '@kne/react-filter/dist/locale/zh-CN';
18
+ import filterEnUS from '@kne/react-filter/dist/locale/en-US';
19
+ import StickyScroller, { isDocumentScrollContainer, getViewportRect } from '@kne/react-sticky-scroller';
20
+ import '@kne/react-sticky-scroller/dist/index.css';
21
+ import '@kne/button-group/dist/index.css';
22
+ import '@kne/react-filter/dist/index.css';
23
+ import ButtonGroup from '@kne/button-group';
24
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
25
+
26
+ function _extends() {
27
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
28
+ for (var e = 1; e < arguments.length; e++) {
29
+ var t = arguments[e];
30
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
1768
31
  }
1769
- return Object.keys(next).length > 0 ? next : undefined;
1770
- }, [resolvedScrollTopInset, antdSelectionColumnWidth]);
1771
- const useTreeCheckForRow = isTree && (rowSelection == null ? void 0 : rowSelection.type) === 'checkbox' && checkRelation !== 'independent' && treeKeyMaps;
1772
- if (useMobileRender) {
1773
- return /*#__PURE__*/jsx(TableView, _extends({}, others, {
1774
- className: classnames(className, style$2['is-mobile-render']),
1775
- dataSource: dataSource,
1776
- columns: visibleColumns,
1777
- rowKey: rowKey,
1778
- rowSelection: rowSelection,
1779
- valueIsEmpty: valueIsEmpty,
1780
- emptyIsPlaceholder: emptyIsPlaceholder,
1781
- placeholder: placeholder,
1782
- empty: empty,
1783
- onRowSelect: onRowSelect,
1784
- renderMobile: renderMobile,
1785
- context: context,
1786
- sortRender: sortRender,
1787
- mobileSortToolbar: mobileSortToolbar,
1788
- size: size,
1789
- dataType: dataType,
1790
- parentKey: parentKey,
1791
- childrenKey: childrenKey,
1792
- hasChildrenKey: hasChildrenKey,
1793
- treeTitleKey: treeTitleKey,
1794
- onLoadChildren: onLoadChildren,
1795
- expandedKeys: expandedKeysProp,
1796
- defaultExpandedKeys: defaultExpandedKeys,
1797
- onExpandedKeysChange: onExpandedKeysChange,
1798
- indentSize: indentSize
1799
- }));
1800
- }
1801
- const tableElement = /*#__PURE__*/jsx(Table$1, _extends({}, others, {
1802
- showHeader: true,
1803
- dataSource: tableDataSource,
1804
- columns: antdColumns,
1805
- rowKey: typeof rowKey === 'function' ? rowKey : record => get(record, rowKey),
1806
- rowSelection: antdRowSelection,
1807
- expandable: antdExpandable,
1808
- pagination: pagination,
1809
- summary: typeof summary === 'function' ? (pageData, ...args) => summary(pageData, ...args) : undefined,
1810
- sticky: antdSticky,
1811
- tableLayout: controllerOpen || hasFixedColumn ? 'fixed' : undefined,
1812
- scroll: tableScroll,
1813
- onHeaderRow: () => ({
1814
- className: 'info-page-table-header',
1815
- style: headerStyle
1816
- }),
1817
- locale: {
1818
- emptyText: /*#__PURE__*/jsx("div", {
1819
- className: style$2['empty'],
1820
- children: empty
1821
- })
1822
- },
1823
- rowClassName: record => {
1824
- var _treeKeyMaps$getAnces2;
1825
- const id = resolveRowKey(rowKey, record);
1826
- const level = isTree ? (treeKeyMaps == null || (_treeKeyMaps$getAnces2 = treeKeyMaps.getAncestorKeys(id)) == null ? void 0 : _treeKeyMaps$getAnces2.length) || 0 : 0;
1827
- const isChecked = useTreeCheckForRow ? getTreeCheckState(id, rowSelection == null ? void 0 : rowSelection.selectedRowKeys, checkRelation, treeKeyMaps).checked : (rowSelection == null ? void 0 : rowSelection.selectedRowKeys) && rowSelection.selectedRowKeys.indexOf(id) > -1;
1828
- return classnames('info-page-table-row', {
1829
- [style$2['is-selected-all']]: rowSelection == null ? void 0 : rowSelection.isSelectedAll,
1830
- [style$2['is-selected']]: isChecked,
1831
- [style$2['is-disabled']]: record.disabled,
1832
- [style$2['is-tree']]: isTree,
1833
- [style$2['is-tree-child']]: isTree && level > 0
1834
- });
1835
- },
1836
- onRow: onRowSelect ? record => ({
1837
- onClick: () => {
1838
- if (record.disabled) {
1839
- return;
1840
- }
1841
- onRowSelect(record, {
1842
- columns: visibleColumns,
1843
- dataSource
1844
- });
1845
- }
1846
- }) : undefined
1847
- }));
1848
- const wrappedTable = /*#__PURE__*/jsxs("div", {
1849
- ref: tableRef,
1850
- className: classnames(style$2['table'], 'info-page-table', sizeClassName, className, {
1851
- [style$2['is-resize']]: currentMoveColumnIndex !== null,
1852
- [style$2['is-computed']]: isLayout,
1853
- [style$2['has-group-header']]: hasGroupHeader,
1854
- [style$2['has-summary']]: typeof summary === 'function',
1855
- [style$2['is-sticky']]: !!sticky,
1856
- [style$2['is-sticky-scroll-y']]: !!sticky && hasScrollY,
1857
- [style$2['is-sticky-viewport']]: isStickyViewport,
1858
- [style$2['is-tree-table']]: isTree
1859
- }),
1860
- style: tableWrapperStyle,
1861
- children: [/*#__PURE__*/jsx("div", {
1862
- className: "info-page-table-body",
1863
- children: !isLayout && tableElement
1864
- }), currentMoveColumnIndex !== null && resizeGuideStyle && /*#__PURE__*/jsx("span", {
1865
- className: style$2['column-resize-guide'],
1866
- style: resizeGuideStyle,
1867
- "aria-hidden": true
1868
- })]
1869
- });
1870
- if (typeof render === 'function') {
1871
- return render(_extends({}, others, {
1872
- header: null,
1873
- renderBody: () => wrappedTable
1874
- }));
32
+ return n;
33
+ }, _extends.apply(null, arguments);
34
+ }
35
+ function _objectWithoutPropertiesLoose(r, e) {
36
+ if (null == r) return {};
37
+ var t = {};
38
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
39
+ if (-1 !== e.indexOf(n)) continue;
40
+ t[n] = r[n];
1875
41
  }
1876
- return wrappedTable;
1877
- };
1878
- Table.useSelectedRow = useSelectedRow;
1879
- Table.useSort = useSort;
1880
- Table.sortDataSource = useSort.sortDataSource;
42
+ return t;
43
+ }
1881
44
 
1882
45
  var style$1 = {"table-page":"kne-table-page_ut9rJ","fetch-stack":"kne-table-page_dpy7d","toolbar-height-reserve":"kne-table-page_daceW","table-page-tabs-outer":"kne-table-page_IowJl","table-content":"kne-table-page_dxN6N","table-with-toolbar":"kne-table-page_sf06r","is-sticky":"kne-table-page_7lYyk","is-loading-shell":"kne-table-page_LY8zA","is-mobile-render":"kne-table-page_D6KGb","has-summary":"kne-table-page_IRdzb","table-cell-skeleton":"kne-table-page_--DrO","table-skeleton-spin":"kne-table-page_cZ1zq","table-in-toolbar":"kne-table-page_sawIT","is-card-mode":"kne-table-page_kH6wM","is-card-render":"kne-table-page_-WbMN","card-mode-toggle":"kne-table-page_ostpI","mobile-load-more":"kne-table-page_UqVnb","pagination":"kne-table-page_DSTEf","total_text":"kne-table-page_pJhKr"};
1883
46
 
47
+ const locale$1 = {
48
+ TotalText: '共',
49
+ ItemText: '条',
50
+ UnnamedColumn: '未命名列',
51
+ EditTable: '编辑表格',
52
+ RestoreDefault: '恢复默认',
53
+ VisibleInfo: '显示的信息',
54
+ HiddenInfo: '隐藏的信息',
55
+ Search: '搜索',
56
+ BatchOperations: '批量操作',
57
+ BatchOperationsWithCount: '已选:{count}条',
58
+ Cancel: '取消',
59
+ Confirm: '确定',
60
+ All: '全部',
61
+ SwitchToCardView: '切换为卡片视图',
62
+ SwitchToTableView: '切换为表格视图'
63
+ };
64
+
65
+ const locale = {
66
+ TotalText: 'Total',
67
+ ItemText: 'items',
68
+ UnnamedColumn: 'Unnamed',
69
+ EditTable: 'Edit Table',
70
+ RestoreDefault: 'Restore Default',
71
+ VisibleInfo: 'Visible Columns',
72
+ HiddenInfo: 'Hidden Columns',
73
+ Search: 'Search',
74
+ BatchOperations: 'Batch Actions',
75
+ BatchOperationsWithCount: 'Selected: {count}',
76
+ Cancel: 'Cancel',
77
+ Confirm: 'Confirm',
78
+ All: 'All',
79
+ SwitchToCardView: 'Switch to card view',
80
+ SwitchToTableView: 'Switch to table view'
81
+ };
82
+
83
+ const withLocale = createWithIntlProvider({
84
+ defaultLocale: 'zh-CN',
85
+ messages: {
86
+ 'zh-CN': _extends({}, filterZhCN, locale$1),
87
+ 'en-US': _extends({}, filterEnUS, locale)
88
+ },
89
+ namespace: 'table-page'
90
+ });
91
+
1884
92
  const _excluded$2 = ["size", "moreType", "showLength", "list", "getPopupContainer"];
1885
93
  const hasButtonGroupList = buttonGroup => Array.isArray(buttonGroup == null ? void 0 : buttonGroup.list) && buttonGroup.list.length > 0;
1886
94
  const normalizeButtonGroupList = (list, defaultSize) => {
@@ -2275,6 +483,131 @@ const TableToolbar = ({
2275
483
  });
2276
484
  };
2277
485
 
486
+ const parsePixelValue = value => {
487
+ const num = parseFloat(value);
488
+ return Number.isNaN(num) ? 0 : num;
489
+ };
490
+ const normalizeScrollTopInsetCSSValue = value => {
491
+ if (value == null) {
492
+ return undefined;
493
+ }
494
+ if (typeof value === 'number') {
495
+ return `${value}px`;
496
+ }
497
+ return String(value);
498
+ };
499
+ const resolveScrollTopInset = (scrollTopInset, stickyOffset) => scrollTopInset != null ? scrollTopInset : stickyOffset;
500
+ const readScrollTopInsetPixels = element => {
501
+ const fromVar = readCssVariableLength(element, '--scroll-top-inset', '0px') || readCssVariableLength(element, '--sticky-offset', '0px') || readCssVariableLength(element, '--nav-height', '0px');
502
+ return fromVar;
503
+ };
504
+ const getTableElement = root => {
505
+ if (!root) {
506
+ return null;
507
+ }
508
+ return root.querySelector('.info-page-table') || root;
509
+ };
510
+ const getScrollAnchorElement = (root, {
511
+ preferToolbar: _preferToolbar = false
512
+ } = {}) => {
513
+ if (!root) {
514
+ return null;
515
+ }
516
+ if (_preferToolbar) {
517
+ return root.querySelector('.table-page-toolbar-section') || root.querySelector('.table-with-toolbar') || getTableElement(root);
518
+ }
519
+ return getTableElement(root);
520
+ };
521
+ const readCssVariableLength = (element, variableName, fallback = '0px') => {
522
+ if (typeof document === 'undefined') {
523
+ return 0;
524
+ }
525
+ const host = element || document.documentElement;
526
+ const probe = document.createElement('div');
527
+ probe.style.cssText = 'position:absolute;visibility:hidden;pointer-events:none;height:0;width:0;overflow:hidden;';
528
+ probe.style.marginTop = `var(${variableName}, ${fallback})`;
529
+ host.appendChild(probe);
530
+ const value = parsePixelValue(getComputedStyle(probe).marginTop);
531
+ host.removeChild(probe);
532
+ return value;
533
+ };
534
+ const resolveScrollContainer = (element, getScrollContainer) => {
535
+ const explicitContainer = typeof getScrollContainer === 'function' ? getScrollContainer() : null;
536
+ if (explicitContainer) {
537
+ return explicitContainer;
538
+ }
539
+ let parent = element == null ? void 0 : element.parentElement;
540
+ while (parent) {
541
+ const {
542
+ overflowY
543
+ } = getComputedStyle(parent);
544
+ if (/(auto|scroll|overlay)/.test(overflowY) && parent.scrollHeight > parent.clientHeight + 1) {
545
+ return parent;
546
+ }
547
+ parent = parent.parentElement;
548
+ }
549
+ return document.scrollingElement || document.documentElement;
550
+ };
551
+ const scrollToElement = (element, {
552
+ offsetTop: _offsetTop = 0,
553
+ getScrollContainer
554
+ } = {}) => {
555
+ const scrollContainer = resolveScrollContainer(element, getScrollContainer);
556
+ const targetRect = element.getBoundingClientRect();
557
+ if (scrollContainer === document.scrollingElement || scrollContainer === document.documentElement || scrollContainer === document.body) {
558
+ const scrollTop = window.pageYOffset + targetRect.top - _offsetTop;
559
+ window.scrollTo({
560
+ top: Math.max(0, scrollTop),
561
+ behavior: 'auto'
562
+ });
563
+ return;
564
+ }
565
+ const containerRect = scrollContainer.getBoundingClientRect();
566
+ const nextScrollTop = scrollContainer.scrollTop + targetRect.top - containerRect.top - _offsetTop;
567
+ scrollContainer.scrollTo({
568
+ top: Math.max(0, nextScrollTop),
569
+ behavior: 'auto'
570
+ });
571
+ };
572
+ const scrollAnchorIntoView = (root, {
573
+ getScrollContainer,
574
+ preferToolbar: _preferToolbar2 = false
575
+ } = {}) => {
576
+ const target = getScrollAnchorElement(root, {
577
+ preferToolbar: _preferToolbar2
578
+ });
579
+ if (!target) {
580
+ return;
581
+ }
582
+ const offsetTop = readScrollTopInsetPixels(target);
583
+ requestAnimationFrame(() => {
584
+ requestAnimationFrame(() => {
585
+ if (isTopEdgeInViewport(target, offsetTop, getScrollContainer)) {
586
+ return;
587
+ }
588
+ scrollToElement(target, {
589
+ offsetTop,
590
+ getScrollContainer
591
+ });
592
+ });
593
+ });
594
+ };
595
+ const isTopEdgeInViewport = (element, scrollMarginTop = 0, getScrollContainer) => {
596
+ if (!element) {
597
+ return true;
598
+ }
599
+ const rect = element.getBoundingClientRect();
600
+ const explicitContainer = typeof getScrollContainer === 'function' ? getScrollContainer() : null;
601
+ if (!isDocumentScrollContainer(explicitContainer)) {
602
+ const containerRect = explicitContainer.getBoundingClientRect();
603
+ const _viewportTop = containerRect.top + scrollMarginTop;
604
+ return rect.top >= _viewportTop && rect.top < containerRect.bottom;
605
+ }
606
+ const viewport = getViewportRect();
607
+ const viewportTop = viewport.top + scrollMarginTop;
608
+ return rect.top >= viewportTop && rect.top < viewport.bottom;
609
+ };
610
+
2278
611
  /**
2279
612
  * 与 @kne/react-filter useSearchParamsValue 内部解析保持一致(不从该包导出)。
2280
613
  *
@@ -3425,5 +1758,5 @@ const TablePage = /*#__PURE__*/forwardRef((_ref6, ref) => {
3425
1758
  }));
3426
1759
  });
3427
1760
 
3428
- export { Table, TableView, TablePage as default, tableLocalApis, useTableConfig };
1761
+ export { TablePage as default };
3429
1762
  //# sourceMappingURL=index.modern.js.map