bj-web-components 0.2.26 → 0.2.28

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 (109) hide show
  1. package/dist/favicon.ico +0 -0
  2. package/dist/file.svg +1 -0
  3. package/dist/globe.svg +1 -0
  4. package/dist/index.d.ts +1141 -0
  5. package/dist/index.js +51 -0
  6. package/dist/index.mjs +51 -0
  7. package/dist/miniapp.d.ts +1 -0
  8. package/dist/miniapp.js +1 -0
  9. package/dist/miniapp.mjs +1 -0
  10. package/dist/mobile.d.ts +1 -0
  11. package/dist/mobile.js +1 -0
  12. package/dist/mobile.mjs +1 -0
  13. package/dist/next.svg +1 -0
  14. package/dist/react.d.ts +1 -0
  15. package/dist/react.js +1 -0
  16. package/dist/react.mjs +1 -0
  17. package/dist/shared.d.ts +1 -0
  18. package/dist/shared.js +1 -0
  19. package/dist/shared.mjs +1 -0
  20. package/dist/style.css +3744 -0
  21. package/dist/vercel.svg +1 -0
  22. package/dist/web/BasicInput/BInput.js +208 -0
  23. package/dist/web/BasicInput/BInput.mjs +209 -0
  24. package/dist/web/BasicInput/utils.js +47 -0
  25. package/dist/web/BasicInput/utils.mjs +47 -0
  26. package/dist/web/CategoryDropdown/CategoryDropdown.js +307 -0
  27. package/dist/web/CategoryDropdown/CategoryDropdown.mjs +308 -0
  28. package/dist/web/CheckBox/BCheckBox.js +116 -0
  29. package/dist/web/CheckBox/BCheckBox.mjs +117 -0
  30. package/dist/web/CheckBox/Group.js +73 -0
  31. package/dist/web/CheckBox/Group.mjs +74 -0
  32. package/dist/web/CheckBox/context.js +5 -0
  33. package/dist/web/CheckBox/context.mjs +5 -0
  34. package/dist/web/CheckBox/index.js +8 -0
  35. package/dist/web/CheckBox/index.mjs +8 -0
  36. package/dist/web/Dropdown/BDropdown.js +186 -0
  37. package/dist/web/Dropdown/BDropdown.mjs +186 -0
  38. package/dist/web/EmptyInputBox/EmptyInputBox.js +77 -0
  39. package/dist/web/EmptyInputBox/EmptyInputBox.mjs +78 -0
  40. package/dist/web/FileCard/FileCard.js +157 -0
  41. package/dist/web/FileCard/FileCard.mjs +158 -0
  42. package/dist/web/Icon/Icon.js +9 -0
  43. package/dist/web/Icon/Icon.mjs +10 -0
  44. package/dist/web/Input/Input.js +181 -0
  45. package/dist/web/Input/Input.mjs +182 -0
  46. package/dist/web/InputNumber/BInputNumber.js +311 -0
  47. package/dist/web/InputNumber/BInputNumber.mjs +312 -0
  48. package/dist/web/InputNumber/StepHandler.js +69 -0
  49. package/dist/web/InputNumber/StepHandler.mjs +70 -0
  50. package/dist/web/InputNumber/hooks/useCursor.js +40 -0
  51. package/dist/web/InputNumber/hooks/useCursor.mjs +41 -0
  52. package/dist/web/InputNumber/hooks/useFrame.js +12 -0
  53. package/dist/web/InputNumber/hooks/useFrame.mjs +13 -0
  54. package/dist/web/InputNumber/utils/decimal.js +147 -0
  55. package/dist/web/InputNumber/utils/decimal.mjs +147 -0
  56. package/dist/web/Modal/Modal.js +84 -0
  57. package/dist/web/Modal/Modal.mjs +85 -0
  58. package/dist/web/OverlayScrollbar/BOverlayScrollbar.js +232 -0
  59. package/dist/web/OverlayScrollbar/BOverlayScrollbar.mjs +233 -0
  60. package/dist/web/Pagination/Pagination.js +328 -0
  61. package/dist/web/Pagination/Pagination.mjs +329 -0
  62. package/dist/web/ProductField/ProductField.js +272 -0
  63. package/dist/web/ProductField/ProductField.mjs +273 -0
  64. package/dist/web/ProductField/arrow-up.svg.js +3 -0
  65. package/dist/web/ProductField/arrow-up.svg.mjs +4 -0
  66. package/dist/web/ProductField/checkbox-no.svg.js +3 -0
  67. package/dist/web/ProductField/checkbox-no.svg.mjs +4 -0
  68. package/dist/web/ProductField/checkbox-ok.svg.js +3 -0
  69. package/dist/web/ProductField/checkbox-ok.svg.mjs +4 -0
  70. package/dist/web/ProductField/no_data_light.svg.js +3 -0
  71. package/dist/web/ProductField/no_data_light.svg.mjs +4 -0
  72. package/dist/web/ProductField/search.svg.js +3 -0
  73. package/dist/web/ProductField/search.svg.mjs +4 -0
  74. package/dist/web/ProductField/sort.svg.js +3 -0
  75. package/dist/web/ProductField/sort.svg.mjs +4 -0
  76. package/dist/web/SkuInputCard/SkuInputCard.js +276 -0
  77. package/dist/web/SkuInputCard/SkuInputCard.mjs +277 -0
  78. package/dist/web/SkuInputCard/spin_loading_red.gif.js +3 -0
  79. package/dist/web/SkuInputCard/spin_loading_red.gif.mjs +4 -0
  80. package/dist/web/Switch/Switch.js +70 -0
  81. package/dist/web/Switch/Switch.mjs +71 -0
  82. package/dist/web/Table/BTable.js +950 -0
  83. package/dist/web/Table/BTable.mjs +950 -0
  84. package/dist/web/Table/Column.js +5 -0
  85. package/dist/web/Table/Column.mjs +6 -0
  86. package/dist/web/Table/ColumnGroup.js +5 -0
  87. package/dist/web/Table/ColumnGroup.mjs +6 -0
  88. package/dist/web/Table/utils/columns.js +48 -0
  89. package/dist/web/Table/utils/columns.mjs +48 -0
  90. package/dist/web/Table/utils/sortFilter.js +84 -0
  91. package/dist/web/Table/utils/sortFilter.mjs +84 -0
  92. package/dist/web/Tabs/BTabs.js +150 -0
  93. package/dist/web/Tabs/BTabs.mjs +150 -0
  94. package/dist/web/Tabs/TabPane.js +8 -0
  95. package/dist/web/Tabs/TabPane.mjs +8 -0
  96. package/dist/web/Tooltip/ConfirmTooltip.js +26 -0
  97. package/dist/web/Tooltip/ConfirmTooltip.mjs +27 -0
  98. package/dist/web/Tooltip/ContentTooltip.js +94 -0
  99. package/dist/web/Tooltip/ContentTooltip.mjs +95 -0
  100. package/dist/web/Tooltip/ProgressTooltip.js +36 -0
  101. package/dist/web/Tooltip/ProgressTooltip.mjs +37 -0
  102. package/dist/web/Tooltip/TooltipWrapper.js +12 -0
  103. package/dist/web/Tooltip/TooltipWrapper.mjs +13 -0
  104. package/dist/web/Tooltip/useAutoPlacement.js +41 -0
  105. package/dist/web/Tooltip/useAutoPlacement.mjs +41 -0
  106. package/dist/web.d.ts +1141 -0
  107. package/dist/web.js +51 -0
  108. package/dist/web.mjs +51 -0
  109. package/package.json +1 -1
@@ -0,0 +1,950 @@
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { useRef, useMemo, useState, useEffect, createElement, isValidElement } from "react";
3
+ import { createPortal } from "react-dom";
4
+ import Pagination from "../Pagination/Pagination.mjs";
5
+ import BuIcon from "../Icon/Icon.mjs";
6
+ /* empty css */
7
+ import BTooltip from "../Tooltip/ContentTooltip.mjs";
8
+ import TooltipWrapper from "../Tooltip/TooltipWrapper.mjs";
9
+ import { BCheckBox as CompoundBCheckBox } from "../CheckBox/index.mjs";
10
+ import { BDropdown } from "../Dropdown/BDropdown.mjs";
11
+ import BOverlayScrollbar from "../OverlayScrollbar/BOverlayScrollbar.mjs";
12
+ import loadingIndicator from "../SkuInputCard/spin_loading_red.gif.mjs";
13
+ import defaultEmptyImage from "../ProductField/no_data_light.svg.mjs";
14
+ import Column from "./Column.mjs";
15
+ import ColumnGroup from "./ColumnGroup.mjs";
16
+ import { getColumnKey, filterRecords, sortRecords, renderColumnTitle, getNextSortOrder, getSorterResult } from "./utils/sortFilter.mjs";
17
+ import { convertChildrenToColumns, flattenColumns, buildHeaderRows } from "./utils/columns.mjs";
18
+ /* empty css */
19
+ const FILTER_SEARCH_DEBOUNCE_MS = 300;
20
+ const SCROLL_EDGE_THRESHOLD = 1;
21
+ function classNames(...values) {
22
+ return values.filter(Boolean).join(" ");
23
+ }
24
+ function getValue(record, dataIndex) {
25
+ if (dataIndex === void 0) {
26
+ return void 0;
27
+ }
28
+ const path = Array.isArray(dataIndex) ? dataIndex : [dataIndex];
29
+ return path.reduce((value, key) => {
30
+ if (value === null || value === void 0 || typeof value !== "object") {
31
+ return void 0;
32
+ }
33
+ return value[key];
34
+ }, record);
35
+ }
36
+ function getRowKey(record, index, rowKey) {
37
+ if (typeof rowKey === "function") {
38
+ return rowKey(record, index);
39
+ }
40
+ if (rowKey) {
41
+ const value = record[String(rowKey)];
42
+ if (typeof value === "string" || typeof value === "number") {
43
+ return value;
44
+ }
45
+ }
46
+ return index;
47
+ }
48
+ function getPageCount(total, pageSize) {
49
+ return Math.max(1, Math.ceil(total / pageSize));
50
+ }
51
+ function isRenderedCell(value) {
52
+ return Boolean(value && typeof value === "object" && !isValidElement(value) && "props" in value);
53
+ }
54
+ function defaultFilterSearch(input, item) {
55
+ const searchableText = typeof item.text === "string" || typeof item.text === "number" ? String(item.text) : String(item.value);
56
+ return searchableText.toLocaleLowerCase().includes(input.toLocaleLowerCase());
57
+ }
58
+ function SelectionControl({
59
+ checked,
60
+ disabled,
61
+ label,
62
+ name,
63
+ onChange,
64
+ type = "checkbox"
65
+ }) {
66
+ if (type === "checkbox") {
67
+ return /* @__PURE__ */ jsx(
68
+ CompoundBCheckBox,
69
+ {
70
+ "aria-label": label,
71
+ checked,
72
+ className: "bj-table__selection-checkbox",
73
+ disabled,
74
+ name,
75
+ onChange,
76
+ skipGroup: true
77
+ }
78
+ );
79
+ }
80
+ return /* @__PURE__ */ jsxs("label", { className: classNames("bj-table__selection-control", checked && "bj-table__selection-control--checked", disabled && "bj-table__selection-control--disabled"), children: [
81
+ /* @__PURE__ */ jsx(
82
+ "input",
83
+ {
84
+ "aria-label": label,
85
+ checked,
86
+ className: "bj-table__selection-input",
87
+ disabled,
88
+ name,
89
+ onChange,
90
+ type
91
+ }
92
+ ),
93
+ /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "bj-table__selection-box", children: checked && /* @__PURE__ */ jsx(BuIcon, { className: "bj-table__selection-check-icon", type: "icon-a-dagouxi" }) })
94
+ ] });
95
+ }
96
+ function BTable({
97
+ columns,
98
+ dataSource = [],
99
+ rowKey,
100
+ preserveSelectedRowKeys = false,
101
+ rowSelection,
102
+ pagination = false,
103
+ loading = false,
104
+ bordered = true,
105
+ size = "middle",
106
+ showHeader = true,
107
+ emptyText,
108
+ emptyImage = defaultEmptyImage,
109
+ emptyHeight,
110
+ t = (text) => text,
111
+ className,
112
+ style,
113
+ rowClassName,
114
+ sortDirections = ["ascend", "descend", null],
115
+ onChange,
116
+ children,
117
+ title,
118
+ footer,
119
+ summary,
120
+ tableLayout,
121
+ components,
122
+ onRow,
123
+ onHeaderRow,
124
+ id,
125
+ scroll,
126
+ locale,
127
+ groupCollapse
128
+ }) {
129
+ var _a, _b, _c;
130
+ const tableRootRef = useRef(null);
131
+ const tableScrollRef = useRef(null);
132
+ const mergedColumns = useMemo(
133
+ () => columns ?? convertChildrenToColumns(children),
134
+ [children, columns]
135
+ );
136
+ const leafColumns = useMemo(() => flattenColumns(mergedColumns), [mergedColumns]);
137
+ const headerRows = useMemo(() => buildHeaderRows(mergedColumns), [mergedColumns]);
138
+ const [uncontrolledSelectedKeys, setUncontrolledSelectedKeys] = useState(
139
+ (rowSelection == null ? void 0 : rowSelection.defaultSelectedRowKeys) ?? []
140
+ );
141
+ const [uncontrolledCurrent, setUncontrolledCurrent] = useState(
142
+ pagination ? pagination.defaultCurrent ?? 1 : 1
143
+ );
144
+ const [uncontrolledPageSize, setUncontrolledPageSize] = useState(
145
+ pagination ? pagination.defaultPageSize ?? 10 : 10
146
+ );
147
+ const [uncontrolledSortOrders, setUncontrolledSortOrders] = useState(
148
+ () => new Map(leafColumns.flatMap((column, index) => {
149
+ if (!column.defaultSortOrder) return [];
150
+ return [[getColumnKey(column, index), column.defaultSortOrder]];
151
+ }))
152
+ );
153
+ const [uncontrolledFilters, setUncontrolledFilters] = useState(
154
+ () => new Map(leafColumns.flatMap((column, index) => {
155
+ if (column.defaultFilteredValue === void 0) return [];
156
+ return [[getColumnKey(column, index), column.defaultFilteredValue]];
157
+ }))
158
+ );
159
+ const [uncontrolledExpandedGroupKeys, setUncontrolledExpandedGroupKeys] = useState(
160
+ (groupCollapse == null ? void 0 : groupCollapse.defaultExpandedKeys) ? [...groupCollapse.defaultExpandedKeys] : []
161
+ );
162
+ const [openFilterKey, setOpenFilterKey] = useState(null);
163
+ const [draftFilters, setDraftFilters] = useState(/* @__PURE__ */ new Map());
164
+ const [hoveredBadgeKey, setHoveredBadgeKey] = useState(null);
165
+ const tableInstanceIdRef = useRef(`btable-${Math.random().toString(36).slice(2, 10)}`);
166
+ const tableInstanceId = tableInstanceIdRef.current;
167
+ const [filterAnchor, setFilterAnchor] = useState(null);
168
+ const [filterPopupPosition, setFilterPopupPosition] = useState(null);
169
+ const [filterSearchInput, setFilterSearchInput] = useState("");
170
+ const [debouncedFilterSearch, setDebouncedFilterSearch] = useState("");
171
+ const [requestedFilterOptions, setRequestedFilterOptions] = useState();
172
+ const filterRequestIdRef = useRef(0);
173
+ const ignoreNextPaginationChangeRef = useRef(false);
174
+ const [horizontalInsets, setHorizontalInsets] = useState({ start: 0, end: 0 });
175
+ const [scrollPing, setScrollPing] = useState({ start: false, end: false });
176
+ const paginationConfig = pagination || void 0;
177
+ const pageSize = (paginationConfig == null ? void 0 : paginationConfig.pageSize) ?? uncontrolledPageSize;
178
+ const selectedKeys = (rowSelection == null ? void 0 : rowSelection.selectedRowKeys) ?? uncontrolledSelectedKeys;
179
+ const activeColumns = leafColumns;
180
+ const fixedLayoutSignature = `${activeColumns.map((column) => `${String(column.fixed ?? "")}:${String(column.width ?? "")}`).join("|")}|${rowSelection ? String(rowSelection.columnWidth ?? "") : "-"}|${String((scroll == null ? void 0 : scroll.x) ?? "")}|${String(tableLayout ?? "")}`;
181
+ const isFixedLeftColumn = (column) => Boolean(column && (column.fixed === "left" || column.fixed === true));
182
+ const isFixedRightColumn = (column) => Boolean(column && column.fixed === "right");
183
+ const sortOrders = new Map(uncontrolledSortOrders);
184
+ const activeFilters = new Map(uncontrolledFilters);
185
+ activeColumns.forEach((rawColumn, index) => {
186
+ if ("children" in rawColumn) return;
187
+ const key = getColumnKey(rawColumn, index);
188
+ if (rawColumn.sortOrder !== void 0) sortOrders.set(key, rawColumn.sortOrder);
189
+ if (rawColumn.filteredValue !== void 0) activeFilters.set(key, rawColumn.filteredValue);
190
+ });
191
+ const filteredData = useMemo(
192
+ () => filterRecords(dataSource, activeColumns, activeFilters),
193
+ [activeColumns, activeFilters, dataSource]
194
+ );
195
+ const processedData = useMemo(
196
+ () => sortRecords(filteredData, activeColumns, sortOrders),
197
+ [activeColumns, filteredData, sortOrders]
198
+ );
199
+ const total = (paginationConfig == null ? void 0 : paginationConfig.total) ?? processedData.length;
200
+ const pageCount = getPageCount(total, pageSize);
201
+ const current = Math.min((paginationConfig == null ? void 0 : paginationConfig.current) ?? uncontrolledCurrent, pageCount);
202
+ const expandedGroupKeys = (groupCollapse == null ? void 0 : groupCollapse.expandedKeys) ?? uncontrolledExpandedGroupKeys;
203
+ const isGroupRow = (record, index) => (groupCollapse == null ? void 0 : groupCollapse.isGroupRow) ? groupCollapse.isGroupRow(record, index) : Boolean(record.isGroup);
204
+ const getGroupKey = (record, index) => (groupCollapse == null ? void 0 : groupCollapse.groupKey) ? groupCollapse.groupKey(record, index) : record.groupId;
205
+ const getChildrenKeys = (record, index) => (groupCollapse == null ? void 0 : groupCollapse.childrenKeys) ? groupCollapse.childrenKeys(record, index) : record.childrenIds ?? [];
206
+ const toggleGroup = (record, index) => {
207
+ var _a2;
208
+ const key = getGroupKey(record, index);
209
+ const expanded = expandedGroupKeys.includes(key);
210
+ const nextKeys = expanded ? expandedGroupKeys.filter((expandedKey) => expandedKey !== key) : [...expandedGroupKeys, key];
211
+ if ((groupCollapse == null ? void 0 : groupCollapse.expandedKeys) === void 0) setUncontrolledExpandedGroupKeys(nextKeys);
212
+ (_a2 = groupCollapse == null ? void 0 : groupCollapse.onExpandedKeysChange) == null ? void 0 : _a2.call(groupCollapse, nextKeys, record, !expanded);
213
+ };
214
+ useEffect(() => {
215
+ if (current !== uncontrolledCurrent && (paginationConfig == null ? void 0 : paginationConfig.current) === void 0) {
216
+ setUncontrolledCurrent(current);
217
+ }
218
+ }, [current, paginationConfig == null ? void 0 : paginationConfig.current, uncontrolledCurrent]);
219
+ useEffect(() => {
220
+ if (!filterAnchor || openFilterKey === null) {
221
+ setFilterPopupPosition(null);
222
+ return;
223
+ }
224
+ const updatePosition = () => {
225
+ const rect = filterAnchor.getBoundingClientRect();
226
+ setFilterPopupPosition({ left: rect.left, top: rect.bottom + 4 });
227
+ };
228
+ updatePosition();
229
+ document.addEventListener("scroll", updatePosition, true);
230
+ window.addEventListener("resize", updatePosition);
231
+ return () => {
232
+ document.removeEventListener("scroll", updatePosition, true);
233
+ window.removeEventListener("resize", updatePosition);
234
+ };
235
+ }, [filterAnchor, openFilterKey]);
236
+ useEffect(() => {
237
+ if (openFilterKey === null) return;
238
+ const handleOutsideClick = (event) => {
239
+ const target = event.target;
240
+ if ((filterAnchor == null ? void 0 : filterAnchor.contains(target)) || target.closest(".bj-table__filter-dropdown")) return;
241
+ setOpenFilterKey(null);
242
+ setFilterAnchor(null);
243
+ };
244
+ document.addEventListener("mousedown", handleOutsideClick);
245
+ return () => document.removeEventListener("mousedown", handleOutsideClick);
246
+ }, [filterAnchor, openFilterKey]);
247
+ useEffect(() => {
248
+ const timer = window.setTimeout(
249
+ () => setDebouncedFilterSearch(filterSearchInput.trim()),
250
+ FILTER_SEARCH_DEBOUNCE_MS
251
+ );
252
+ return () => window.clearTimeout(timer);
253
+ }, [filterSearchInput]);
254
+ useEffect(() => {
255
+ if (openFilterKey === null) return;
256
+ const openColumn = leafColumns.find((column, index) => getColumnKey(column, index) === openFilterKey);
257
+ if (!openColumn || "children" in openColumn || !openColumn.filterRequest) return;
258
+ const requestId = ++filterRequestIdRef.current;
259
+ Promise.resolve().then(() => openColumn.filterRequest(debouncedFilterSearch)).then(
260
+ (options) => {
261
+ if (filterRequestIdRef.current === requestId) setRequestedFilterOptions(options);
262
+ },
263
+ () => {
264
+ if (filterRequestIdRef.current === requestId) setRequestedFilterOptions([]);
265
+ }
266
+ );
267
+ }, [debouncedFilterSearch, leafColumns, openFilterKey]);
268
+ const visibleRecords = useMemo(() => {
269
+ if (!paginationConfig || paginationConfig.serverPagination) {
270
+ return processedData.map((record, index) => ({ record, index })).filter(({ record, index }) => {
271
+ if (!groupCollapse || isGroupRow(record, index)) return true;
272
+ const childKey = getRowKey(record, index, rowKey);
273
+ return processedData.some(
274
+ (group, groupIndex) => isGroupRow(group, groupIndex) && expandedGroupKeys.includes(getGroupKey(group, groupIndex)) && getChildrenKeys(group, groupIndex).includes(childKey)
275
+ );
276
+ });
277
+ }
278
+ const start = (current - 1) * pageSize;
279
+ return processedData.slice(start, start + pageSize).map((record, index) => ({
280
+ record,
281
+ index: start + index
282
+ })).filter(({ record, index }) => {
283
+ if (!groupCollapse || isGroupRow(record, index)) return true;
284
+ const childKey = getRowKey(record, index, rowKey);
285
+ return processedData.some(
286
+ (group, groupIndex) => isGroupRow(group, groupIndex) && expandedGroupKeys.includes(getGroupKey(group, groupIndex)) && getChildrenKeys(group, groupIndex).includes(childKey)
287
+ );
288
+ });
289
+ }, [current, expandedGroupKeys, groupCollapse, pageSize, paginationConfig, processedData, rowKey]);
290
+ const visibleSelectionKeys = useMemo(
291
+ () => visibleRecords.map(({ record, index }) => getRowKey(record, index, rowKey)),
292
+ [rowKey, visibleRecords]
293
+ );
294
+ const selectedKeySignature = selectedKeys.map(String).join("|");
295
+ const visibleKeySignature = visibleSelectionKeys.map(String).join("|");
296
+ useEffect(() => {
297
+ var _a2;
298
+ if (!rowSelection || preserveSelectedRowKeys || selectedKeys.length === 0) return;
299
+ const visibleKeySet = new Set(visibleSelectionKeys);
300
+ const nextSelectedKeys = selectedKeys.filter((key) => visibleKeySet.has(key));
301
+ if (nextSelectedKeys.length === selectedKeys.length) return;
302
+ if (rowSelection.selectedRowKeys === void 0) {
303
+ setUncontrolledSelectedKeys(nextSelectedKeys);
304
+ }
305
+ const nextSelectedKeySet = new Set(nextSelectedKeys);
306
+ const nextSelectedRows = visibleRecords.filter(({ record, index }) => nextSelectedKeySet.has(getRowKey(record, index, rowKey))).map(({ record }) => record);
307
+ (_a2 = rowSelection.onChange) == null ? void 0 : _a2.call(rowSelection, nextSelectedKeys, nextSelectedRows, { type: "multiple" });
308
+ }, [preserveSelectedRowKeys, rowSelection, rowKey, selectedKeySignature, visibleKeySignature, visibleRecords]);
309
+ useEffect(() => {
310
+ const element = tableScrollRef.current;
311
+ if (!element || !(scroll == null ? void 0 : scroll.x)) {
312
+ setHorizontalInsets((previous) => previous.start === 0 && previous.end === 0 ? previous : { start: 0, end: 0 });
313
+ setScrollPing((previous) => previous.start || previous.end ? { start: false, end: false } : previous);
314
+ return;
315
+ }
316
+ const measure = () => {
317
+ const layoutRow = element.querySelector(".bj-table__header .bj-table__header-row") ?? element.querySelector(".bj-table__body .bj-table__row");
318
+ let start = 0;
319
+ let end = 0;
320
+ if (layoutRow) {
321
+ Array.from(layoutRow.children).forEach((cell) => {
322
+ const width = cell.getBoundingClientRect().width;
323
+ if (cell.classList.contains("bj-table__cell--fixed-right")) {
324
+ end += width;
325
+ } else if (cell.classList.contains("bj-table__cell--fixed-left") || cell.classList.contains("bj-table__selection-cell--fixed")) {
326
+ start += width;
327
+ }
328
+ });
329
+ const borderWidth = element.clientLeft;
330
+ if (start > 0) start += borderWidth;
331
+ if (end > 0) end = Math.max(end - borderWidth, 0);
332
+ }
333
+ setHorizontalInsets((previous) => previous.start === start && previous.end === end ? previous : { start, end });
334
+ };
335
+ const syncPing = () => {
336
+ const maxScroll = element.scrollWidth - element.clientWidth;
337
+ const scrollable = maxScroll > SCROLL_EDGE_THRESHOLD;
338
+ const next = {
339
+ start: scrollable && element.scrollLeft > SCROLL_EDGE_THRESHOLD,
340
+ end: scrollable && element.scrollLeft < maxScroll - SCROLL_EDGE_THRESHOLD
341
+ };
342
+ setScrollPing((previous) => previous.start === next.start && previous.end === next.end ? previous : next);
343
+ };
344
+ const sync = () => {
345
+ measure();
346
+ syncPing();
347
+ };
348
+ sync();
349
+ element.addEventListener("scroll", syncPing, { passive: true });
350
+ const observer = new ResizeObserver(sync);
351
+ observer.observe(element);
352
+ if (element.firstElementChild) observer.observe(element.firstElementChild);
353
+ return () => {
354
+ element.removeEventListener("scroll", syncPing);
355
+ observer.disconnect();
356
+ };
357
+ }, [fixedLayoutSignature, scroll == null ? void 0 : scroll.x, showHeader, visibleRecords.length]);
358
+ const emitChange = (action, nextSortOrders = sortOrders, nextFilters = activeFilters, nextCurrent = current, nextPageSize = pageSize) => {
359
+ const filterInfo = Object.fromEntries(nextFilters);
360
+ const nextFilteredData = filterRecords(dataSource, activeColumns, nextFilters);
361
+ const nextProcessedData = sortRecords(nextFilteredData, activeColumns, nextSortOrders);
362
+ onChange == null ? void 0 : onChange(
363
+ { ...paginationConfig, current: nextCurrent, pageSize: nextPageSize, total: (paginationConfig == null ? void 0 : paginationConfig.total) ?? nextProcessedData.length },
364
+ filterInfo,
365
+ getSorterResult(activeColumns, nextSortOrders),
366
+ { action, currentDataSource: nextProcessedData }
367
+ );
368
+ };
369
+ const changeSorter = (column, index) => {
370
+ if (!column.sorter) return;
371
+ const key = getColumnKey(column, index);
372
+ const nextOrder = getNextSortOrder(sortOrders.get(key) ?? null, column.sortDirections ?? sortDirections);
373
+ const nextOrders = /* @__PURE__ */ new Map();
374
+ nextOrders.set(key, nextOrder);
375
+ if (column.sortOrder === void 0) setUncontrolledSortOrders(nextOrders);
376
+ emitChange("sort", nextOrders);
377
+ };
378
+ const confirmFilter = (column, index, selectedKeys2) => {
379
+ const key = getColumnKey(column, index);
380
+ const nextFilters = new Map(activeFilters);
381
+ nextFilters.set(key, selectedKeys2);
382
+ if (column.filteredValue === void 0) setUncontrolledFilters(nextFilters);
383
+ setOpenFilterKey(null);
384
+ if ((paginationConfig == null ? void 0 : paginationConfig.current) === void 0) setUncontrolledCurrent(1);
385
+ emitChange("filter", sortOrders, nextFilters, 1);
386
+ };
387
+ const resetFilter = (column, index) => {
388
+ const key = getColumnKey(column, index);
389
+ const nextKeys = column.filterResetToDefaultFilteredValue ? column.defaultFilteredValue ?? [] : [];
390
+ setDraftFilters((filters) => new Map(filters).set(key, nextKeys));
391
+ };
392
+ const toggleFilter = (column, index, anchor) => {
393
+ var _a2, _b2, _c2, _d;
394
+ const key = getColumnKey(column, index);
395
+ if (openFilterKey === key) {
396
+ setOpenFilterKey(null);
397
+ setFilterAnchor(null);
398
+ (_a2 = column.onFilterDropdownOpenChange) == null ? void 0 : _a2.call(column, false);
399
+ (_b2 = column.onFilterDropdownVisibleChange) == null ? void 0 : _b2.call(column, false);
400
+ return;
401
+ }
402
+ setFilterSearchInput("");
403
+ setDebouncedFilterSearch("");
404
+ setRequestedFilterOptions(void 0);
405
+ setDraftFilters((filters) => new Map(filters).set(key, activeFilters.get(key) ?? []));
406
+ setOpenFilterKey(key);
407
+ if (anchor) setFilterAnchor(anchor);
408
+ (_c2 = column.onFilterDropdownOpenChange) == null ? void 0 : _c2.call(column, true);
409
+ (_d = column.onFilterDropdownVisibleChange) == null ? void 0 : _d.call(column, true);
410
+ };
411
+ const renderHeaderCell = (column, index) => {
412
+ var _a2, _b2;
413
+ const key = getColumnKey(column, index);
414
+ const badgeId = `bj-table-badge-${tableInstanceId}-${String(key).replace(/[^a-zA-Z0-9_-]/g, "-")}`;
415
+ const sortOrder = sortOrders.get(key) ?? null;
416
+ const filteredKeys = activeFilters.get(key) ?? [];
417
+ const draftKeys = draftFilters.get(key) ?? filteredKeys;
418
+ const isFilterOpen = column.filterDropdownOpen ?? column.filterDropdownVisible ?? openFilterKey === key;
419
+ const isFiltered = column.filtered || filteredKeys.length > 0;
420
+ const sortIconType = sortOrder === "ascend" ? "icon-a-zhengxumian" : sortOrder === "descend" ? "icon-a-daoxumian" : "icon-a-weipaixumian";
421
+ const title2 = renderColumnTitle(column.title, {
422
+ sortOrder,
423
+ sortColumn: sortOrder ? column : void 0,
424
+ sortColumns: sortOrder ? [{ column, order: sortOrder }] : [],
425
+ filters: Object.fromEntries(activeFilters)
426
+ });
427
+ const customFilterContent = typeof column.filterDropdown === "function" ? column.filterDropdown({
428
+ prefixCls: "bj-table",
429
+ selectedKeys: draftKeys.filter((value) => typeof value !== "boolean"),
430
+ setSelectedKeys: (keys) => setDraftFilters((filters) => new Map(filters).set(key, keys)),
431
+ confirm: (options) => {
432
+ confirmFilter(column, index, draftFilters.get(key) ?? draftKeys);
433
+ if ((options == null ? void 0 : options.closeDropdown) === false) setOpenFilterKey(key);
434
+ },
435
+ clearFilters: (options) => {
436
+ const nextKeys = column.filterResetToDefaultFilteredValue ? column.defaultFilteredValue ?? [] : [];
437
+ setDraftFilters((filters) => new Map(filters).set(key, nextKeys));
438
+ if ((options == null ? void 0 : options.confirm) === true) confirmFilter(column, index, nextKeys);
439
+ if ((options == null ? void 0 : options.closeDropdown) === false || (options == null ? void 0 : options.confirm) !== true) setOpenFilterKey(key);
440
+ },
441
+ filters: column.filters,
442
+ close: () => setOpenFilterKey(null),
443
+ visible: isFilterOpen
444
+ }) : column.filterDropdown;
445
+ const filterOptions = column.filterRequest ? requestedFilterOptions ?? [] : column.filters ?? [];
446
+ const visibleFilterOptions = debouncedFilterSearch && !column.filterRequest ? filterOptions.filter((option) => typeof column.filterSearch === "function" ? column.filterSearch(debouncedFilterSearch, option) : defaultFilterSearch(debouncedFilterSearch, option)) : filterOptions;
447
+ const showFilterSearch = Boolean(column.filterSearch || column.filterRequest);
448
+ const headerContent = /* @__PURE__ */ jsxs("div", { className: classNames("bj-table__column-header", column.sorter && "bj-table__column-header--sortable"), children: [
449
+ column.badge !== void 0 && /* @__PURE__ */ jsx(
450
+ "span",
451
+ {
452
+ "aria-label": "表头提示",
453
+ className: "bj-table__column-badge-trigger",
454
+ id: badgeId,
455
+ onBlur: () => setHoveredBadgeKey(null),
456
+ onClick: (event) => event.stopPropagation(),
457
+ onFocus: () => setHoveredBadgeKey(key),
458
+ onKeyDown: (event) => event.stopPropagation(),
459
+ onMouseEnter: () => setHoveredBadgeKey(key),
460
+ onMouseLeave: () => setHoveredBadgeKey(null),
461
+ role: "button",
462
+ tabIndex: 0,
463
+ children: /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "bj-table__column-badge-shape" })
464
+ }
465
+ ),
466
+ /* @__PURE__ */ jsxs("div", { className: "bj-table__column-title", children: [
467
+ /* @__PURE__ */ jsx("span", { className: "bj-table__column-title-content", children: title2 }),
468
+ column.sorter && /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "bj-table__column-sorter", children: /* @__PURE__ */ jsx(BuIcon, { className: "bj-table__column-sorter-icon", type: sortIconType }) })
469
+ ] }),
470
+ (column.filters || column.filterDropdown) && /* @__PURE__ */ jsxs("div", { className: "bj-table__filter", children: [
471
+ /* @__PURE__ */ jsx(
472
+ "button",
473
+ {
474
+ "aria-expanded": isFilterOpen,
475
+ "aria-label": "筛选",
476
+ className: classNames("bj-table__filter-trigger", isFiltered && "bj-table__filter-trigger--active"),
477
+ onClick: (event) => {
478
+ event.stopPropagation();
479
+ toggleFilter(column, index);
480
+ },
481
+ type: "button",
482
+ children: typeof column.filterIcon === "function" ? column.filterIcon(isFiltered) : column.filterIcon ?? /* @__PURE__ */ jsx(
483
+ BuIcon,
484
+ {
485
+ className: "bj-table__filter-icon",
486
+ type: isFiltered ? "icon-shaixuan-daidian" : "icon-a-shaixuanxi"
487
+ }
488
+ )
489
+ }
490
+ ),
491
+ isFilterOpen && filterPopupPosition && typeof document !== "undefined" && createPortal(
492
+ /* @__PURE__ */ jsx(
493
+ "div",
494
+ {
495
+ className: "bj-table__filter-dropdown",
496
+ onClick: (event) => event.stopPropagation(),
497
+ role: "dialog",
498
+ style: { left: filterPopupPosition.left, top: filterPopupPosition.top },
499
+ children: customFilterContent ?? /* @__PURE__ */ jsx(
500
+ BDropdown,
501
+ {
502
+ ...column.filterDropdownProps,
503
+ emptyText: (locale == null ? void 0 : locale.filterEmptyText) ?? t("暂无结果"),
504
+ multiple: column.filterMultiple !== false,
505
+ onChange: (nextKeys, option) => {
506
+ var _a3, _b3;
507
+ setDraftFilters((filters) => new Map(filters).set(key, nextKeys));
508
+ (_b3 = (_a3 = column.filterDropdownProps) == null ? void 0 : _a3.onChange) == null ? void 0 : _b3.call(_a3, nextKeys, option);
509
+ },
510
+ onConfirm: (nextKeys) => {
511
+ var _a3, _b3;
512
+ confirmFilter(column, index, nextKeys);
513
+ (_b3 = (_a3 = column.filterDropdownProps) == null ? void 0 : _a3.onConfirm) == null ? void 0 : _b3.call(_a3, nextKeys);
514
+ },
515
+ onReset: () => {
516
+ var _a3, _b3;
517
+ resetFilter(column, index);
518
+ (_b3 = (_a3 = column.filterDropdownProps) == null ? void 0 : _a3.onReset) == null ? void 0 : _b3.call(_a3);
519
+ },
520
+ onSearch: (nextSearchValue) => {
521
+ var _a3, _b3;
522
+ setFilterSearchInput(nextSearchValue);
523
+ (_b3 = (_a3 = column.filterDropdownProps) == null ? void 0 : _a3.onSearch) == null ? void 0 : _b3.call(_a3, nextSearchValue);
524
+ },
525
+ options: visibleFilterOptions.map((option) => ({
526
+ label: option.text,
527
+ description: option.description,
528
+ value: option.value
529
+ })),
530
+ searchable: ((_a2 = column.filterDropdownProps) == null ? void 0 : _a2.searchable) ?? showFilterSearch,
531
+ searchPlaceholder: ((_b2 = column.filterDropdownProps) == null ? void 0 : _b2.searchPlaceholder) ?? (column.filterRequest ? t("请输入搜索内容") : (locale == null ? void 0 : locale.filterSearchPlaceholder) ?? t("搜索")),
532
+ searchValue: filterSearchInput,
533
+ t,
534
+ value: draftKeys
535
+ }
536
+ )
537
+ }
538
+ ),
539
+ document.body
540
+ )
541
+ ] })
542
+ ] });
543
+ return column.badge !== void 0 ? /* @__PURE__ */ jsxs(
544
+ TooltipWrapper,
545
+ {
546
+ className: "bj-table__column-tooltip-wrapper",
547
+ children: [
548
+ /* @__PURE__ */ jsx("div", { className: "bj-table__column-tooltip-trigger", children: headerContent }),
549
+ hoveredBadgeKey === key && /* @__PURE__ */ jsx(
550
+ BTooltip,
551
+ {
552
+ className: "bj-table__column-tooltip",
553
+ content: column.badge,
554
+ getAnchorElement: () => document.getElementById(badgeId),
555
+ getPopupContainer: () => document.body,
556
+ placement: "top"
557
+ }
558
+ )
559
+ ]
560
+ }
561
+ ) : headerContent;
562
+ };
563
+ const updateSelection = (nextSelectedKeys, selection, selectedRecord) => {
564
+ var _a2, _b2;
565
+ if (selection.selectedRowKeys === void 0) {
566
+ setUncontrolledSelectedKeys(nextSelectedKeys);
567
+ }
568
+ const selectedKeySet = new Set(nextSelectedKeys);
569
+ const selectedRows = dataSource.filter(
570
+ (record, index) => selectedKeySet.has(getRowKey(record, index, rowKey))
571
+ );
572
+ (_a2 = selection.onChange) == null ? void 0 : _a2.call(selection, nextSelectedKeys, selectedRows);
573
+ if (selectedRecord) {
574
+ (_b2 = selection.onSelect) == null ? void 0 : _b2.call(
575
+ selection,
576
+ selectedRecord,
577
+ selectedKeySet.has(getRowKey(selectedRecord, dataSource.indexOf(selectedRecord), rowKey)),
578
+ selectedRows
579
+ );
580
+ }
581
+ };
582
+ const toggleRow = (record, index) => {
583
+ if (!rowSelection) {
584
+ return;
585
+ }
586
+ const key = getRowKey(record, index, rowKey);
587
+ const selected = selectedKeys.includes(key);
588
+ const nextSelectedKeys = rowSelection.type === "radio" ? selected ? [] : [key] : selected ? selectedKeys.filter((selectedKey) => selectedKey !== key) : [...selectedKeys, key];
589
+ updateSelection(nextSelectedKeys, rowSelection, record);
590
+ };
591
+ const selectableVisibleRecords = visibleRecords.filter(
592
+ ({ record }) => {
593
+ var _a2;
594
+ return !((_a2 = rowSelection == null ? void 0 : rowSelection.getCheckboxProps) == null ? void 0 : _a2.call(rowSelection, record).disabled);
595
+ }
596
+ );
597
+ const selectableVisibleKeys = selectableVisibleRecords.map(
598
+ ({ record, index }) => getRowKey(record, index, rowKey)
599
+ );
600
+ const allVisibleSelected = selectableVisibleKeys.length > 0 && selectableVisibleKeys.every((key) => selectedKeys.includes(key));
601
+ const toggleAll = () => {
602
+ var _a2;
603
+ if (!rowSelection || rowSelection.type === "radio") {
604
+ return;
605
+ }
606
+ const visibleKeySet = new Set(selectableVisibleKeys);
607
+ const nextSelectedKeys = allVisibleSelected ? selectedKeys.filter((key) => !visibleKeySet.has(key)) : Array.from(/* @__PURE__ */ new Set([...selectedKeys, ...selectableVisibleKeys]));
608
+ updateSelection(nextSelectedKeys, rowSelection);
609
+ new Set(nextSelectedKeys);
610
+ (_a2 = rowSelection.onSelectAll) == null ? void 0 : _a2.call(
611
+ rowSelection,
612
+ !allVisibleSelected,
613
+ selectableVisibleRecords.map(({ record }) => record)
614
+ );
615
+ };
616
+ const changePage = (nextPage) => {
617
+ var _a2;
618
+ if (!paginationConfig || nextPage < 1 || nextPage > pageCount || nextPage === current) {
619
+ return;
620
+ }
621
+ if (paginationConfig.current === void 0) {
622
+ setUncontrolledCurrent(nextPage);
623
+ }
624
+ (_a2 = paginationConfig.onChange) == null ? void 0 : _a2.call(paginationConfig, nextPage, pageSize);
625
+ emitChange("paginate", sortOrders, activeFilters, nextPage);
626
+ };
627
+ const changePageSize = (nextPageSize) => {
628
+ var _a2, _b2;
629
+ if (!paginationConfig || nextPageSize === pageSize) {
630
+ return;
631
+ }
632
+ const nextCurrent = 1;
633
+ ignoreNextPaginationChangeRef.current = true;
634
+ if (paginationConfig.pageSize === void 0) {
635
+ setUncontrolledPageSize(nextPageSize);
636
+ }
637
+ if (paginationConfig.current === void 0) {
638
+ setUncontrolledCurrent(nextCurrent);
639
+ }
640
+ (_a2 = paginationConfig.onShowSizeChange) == null ? void 0 : _a2.call(paginationConfig, nextCurrent, nextPageSize);
641
+ (_b2 = paginationConfig.onChange) == null ? void 0 : _b2.call(paginationConfig, nextCurrent, nextPageSize);
642
+ emitChange("paginate", sortOrders, activeFilters, nextCurrent, nextPageSize);
643
+ };
644
+ const columnCount = activeColumns.length + (rowSelection ? 1 : 0);
645
+ const selectionColumnWidth = (rowSelection == null ? void 0 : rowSelection.columnWidth) ?? 48;
646
+ const getColumnWidth = (column) => typeof column.width === "number" ? column.width : 0;
647
+ const getFixedStyle = (column, columnIndex) => {
648
+ const fixed = column.fixed === true ? "left" : column.fixed;
649
+ if (fixed === "left") {
650
+ const left = activeColumns.slice(0, columnIndex).reduce((offset, current2) => offset + getColumnWidth(current2), rowSelection && typeof selectionColumnWidth === "number" ? selectionColumnWidth : 0);
651
+ return { position: "sticky", left, zIndex: 2 };
652
+ }
653
+ if (fixed === "right") {
654
+ const right = activeColumns.slice(columnIndex + 1).reduce((offset, current2) => offset + getColumnWidth(current2), 0);
655
+ return { position: "sticky", right, zIndex: 2 };
656
+ }
657
+ return {};
658
+ };
659
+ const scrollTableStyle = (scroll == null ? void 0 : scroll.x) ? {
660
+ width: scroll.x === true ? "max-content" : scroll.x,
661
+ minWidth: "100%",
662
+ tableLayout: tableLayout ?? "fixed"
663
+ } : { tableLayout };
664
+ const TableComponent = (components == null ? void 0 : components.table) ?? "table";
665
+ const HeaderWrapper = ((_a = components == null ? void 0 : components.header) == null ? void 0 : _a.wrapper) ?? "thead";
666
+ const HeaderRow = ((_b = components == null ? void 0 : components.header) == null ? void 0 : _b.row) ?? "tr";
667
+ const HeaderCell = ((_c = components == null ? void 0 : components.header) == null ? void 0 : _c.cell) ?? "th";
668
+ const bodyComponents = typeof (components == null ? void 0 : components.body) === "object" ? components.body : void 0;
669
+ const BodyWrapper = (bodyComponents == null ? void 0 : bodyComponents.wrapper) ?? "tbody";
670
+ const BodyRow = (bodyComponents == null ? void 0 : bodyComponents.row) ?? "tr";
671
+ const BodyCell = (bodyComponents == null ? void 0 : bodyComponents.cell) ?? "td";
672
+ const resolvedEmptyText = typeof emptyText === "function" ? emptyText() : emptyText ?? t("暂无数据");
673
+ const resolvedEmptyImage = typeof emptyImage === "string" ? /* @__PURE__ */ jsx("img", { alt: "", className: "bj-table__empty-image", src: emptyImage }) : emptyImage;
674
+ return /* @__PURE__ */ jsxs(
675
+ "div",
676
+ {
677
+ id,
678
+ ref: tableRootRef,
679
+ className: classNames(
680
+ "bj-table",
681
+ bordered && "bj-table--bordered",
682
+ `bj-table--${size}`,
683
+ loading && "bj-table--loading",
684
+ processedData.length === 0 && "bj-table--empty",
685
+ scrollPing.start && "bj-table--ping-left",
686
+ scrollPing.end && "bj-table--ping-right",
687
+ className
688
+ ),
689
+ style,
690
+ children: [
691
+ title && /* @__PURE__ */ jsx("div", { className: "bj-table__title", children: title(processedData) }),
692
+ /* @__PURE__ */ jsxs("div", { className: "bj-table__viewport", children: [
693
+ /* @__PURE__ */ jsx(
694
+ "div",
695
+ {
696
+ className: classNames("bj-table__scroll", Boolean((scroll == null ? void 0 : scroll.x) || (scroll == null ? void 0 : scroll.y)) && "bj-overlay-scrollbar-hidden"),
697
+ ref: tableScrollRef,
698
+ style: { maxHeight: scroll == null ? void 0 : scroll.y },
699
+ children: /* @__PURE__ */ jsxs(TableComponent, { className: "bj-table__native-table", style: scrollTableStyle, children: [
700
+ activeColumns.some((column) => column.width) && /* @__PURE__ */ jsxs("colgroup", { children: [
701
+ rowSelection && /* @__PURE__ */ jsx("col", { className: "bj-table__selection-col", style: { width: selectionColumnWidth } }),
702
+ activeColumns.map((column, index) => /* @__PURE__ */ jsx("col", { style: { width: column.width } }, column.key ?? index))
703
+ ] }),
704
+ showHeader && /* @__PURE__ */ jsx(HeaderWrapper, { className: "bj-table__header", children: headerRows.map((headerRow, rowIndex) => /* @__PURE__ */ jsxs(HeaderRow, { className: "bj-table__header-row", ...onHeaderRow == null ? void 0 : onHeaderRow(activeColumns, rowIndex), children: [
705
+ rowSelection && rowIndex === 0 && /* @__PURE__ */ jsxs(
706
+ HeaderCell,
707
+ {
708
+ className: classNames(
709
+ "bj-table__header-cell",
710
+ "bj-table__selection-cell",
711
+ Boolean(scroll == null ? void 0 : scroll.x) && "bj-table__selection-cell--fixed",
712
+ // 选择列就是最后一个左固定区域时,由它承担左侧渐变阴影
713
+ Boolean(scroll == null ? void 0 : scroll.x) && !isFixedLeftColumn(activeColumns[0]) && "bj-table__cell--fixed-left-last"
714
+ ),
715
+ rowSpan: headerRows.length,
716
+ scope: "col",
717
+ style: { width: selectionColumnWidth },
718
+ children: [
719
+ rowSelection.type !== "radio" && /* @__PURE__ */ jsx(
720
+ SelectionControl,
721
+ {
722
+ checked: allVisibleSelected,
723
+ disabled: selectableVisibleKeys.length === 0,
724
+ onChange: toggleAll,
725
+ label: "选择当前页所有行"
726
+ }
727
+ ),
728
+ rowSelection.columnTitle
729
+ ]
730
+ }
731
+ ),
732
+ headerRow.map(({ column: rawColumn, colSpan, rowSpan }, index) => {
733
+ var _a2, _b2;
734
+ const column = rawColumn;
735
+ const leafIndex = activeColumns.indexOf(column);
736
+ const interactionIndex = leafIndex >= 0 ? leafIndex : index;
737
+ const isFilterable = !("children" in rawColumn) && Boolean(column.filters || column.filterDropdown);
738
+ const isSortable = !("children" in rawColumn) && Boolean(column.sorter);
739
+ const triggerHeaderAction = () => {
740
+ if (isFilterable) {
741
+ toggleFilter(column, interactionIndex);
742
+ } else if (isSortable) {
743
+ changeSorter(column, interactionIndex);
744
+ }
745
+ };
746
+ return /* @__PURE__ */ createElement(
747
+ HeaderCell,
748
+ {
749
+ ...(_a2 = column.onHeaderCell) == null ? void 0 : _a2.call(column, rawColumn, index),
750
+ "aria-label": typeof column.title === "string" ? column.title : void 0,
751
+ "aria-sort": isSortable ? sortOrders.get(getColumnKey(column, interactionIndex)) === "ascend" ? "ascending" : sortOrders.get(getColumnKey(column, interactionIndex)) === "descend" ? "descending" : "none" : void 0,
752
+ className: classNames(
753
+ "bj-table__header-cell",
754
+ ((_b2 = activeColumns[interactionIndex + 1]) == null ? void 0 : _b2.fixed) === "right" && "bj-table__cell--before-fixed-right",
755
+ column.fixed && "bj-table__cell--fixed",
756
+ isFixedLeftColumn(column) && "bj-table__cell--fixed-left",
757
+ isFixedLeftColumn(column) && !isFixedLeftColumn(activeColumns[interactionIndex + 1]) && "bj-table__cell--fixed-left-last",
758
+ isFixedRightColumn(column) && "bj-table__cell--fixed-right",
759
+ isFixedRightColumn(column) && !isFixedRightColumn(activeColumns[interactionIndex - 1]) && "bj-table__cell--fixed-right-first",
760
+ column.sorter && "bj-table__header-cell--sortable",
761
+ isFilterable && "bj-table__header-cell--filterable",
762
+ sortOrders.get(getColumnKey(column, interactionIndex)) && "bj-table__header-cell--sorted",
763
+ column.className
764
+ ),
765
+ colSpan,
766
+ key: column.key ?? String(column.dataIndex ?? index),
767
+ onClick: (event) => {
768
+ var _a3, _b3, _c2;
769
+ (_c2 = (_b3 = (_a3 = column.onHeaderCell) == null ? void 0 : _a3.call(column, rawColumn, index)) == null ? void 0 : _b3.onClick) == null ? void 0 : _c2.call(_b3, event);
770
+ if (event.target.closest(".bj-table__filter-dropdown")) return;
771
+ if (isFilterable) {
772
+ toggleFilter(column, interactionIndex, event.currentTarget);
773
+ } else {
774
+ triggerHeaderAction();
775
+ }
776
+ },
777
+ onKeyDown: (event) => {
778
+ var _a3, _b3, _c2;
779
+ (_c2 = (_b3 = (_a3 = column.onHeaderCell) == null ? void 0 : _a3.call(column, rawColumn, index)) == null ? void 0 : _b3.onKeyDown) == null ? void 0 : _c2.call(_b3, event);
780
+ if (event.target.closest(".bj-table__filter-dropdown")) return;
781
+ if (event.key === "Enter" || event.key === " ") {
782
+ event.preventDefault();
783
+ if (isFilterable) {
784
+ toggleFilter(column, interactionIndex, event.currentTarget);
785
+ } else {
786
+ triggerHeaderAction();
787
+ }
788
+ }
789
+ },
790
+ rowSpan,
791
+ scope: "col",
792
+ style: { textAlign: column.align, ...getFixedStyle(column, interactionIndex) },
793
+ tabIndex: isFilterable || isSortable ? 0 : void 0
794
+ },
795
+ "children" in rawColumn ? renderColumnTitle(rawColumn.title, { filters: Object.fromEntries(activeFilters) }) : renderHeaderCell(column, interactionIndex)
796
+ );
797
+ })
798
+ ] }, rowIndex)) }),
799
+ /* @__PURE__ */ jsx(BodyWrapper, { className: "bj-table__body", children: visibleRecords.length > 0 ? visibleRecords.map(({ record, index }) => {
800
+ var _a2;
801
+ const key = getRowKey(record, index, rowKey);
802
+ const groupRow = isGroupRow(record, index);
803
+ const isDisabled = ((_a2 = rowSelection == null ? void 0 : rowSelection.getCheckboxProps) == null ? void 0 : _a2.call(rowSelection, record).disabled) ?? false;
804
+ const isSelected = selectedKeys.includes(key);
805
+ const resolvedRowClassName = typeof rowClassName === "function" ? rowClassName(record, index, 0) : rowClassName;
806
+ return /* @__PURE__ */ createElement(
807
+ BodyRow,
808
+ {
809
+ ...onRow == null ? void 0 : onRow(record, index),
810
+ className: classNames("bj-table__row", groupRow && "bj-table__row--group", isSelected && "bj-table__row--selected", resolvedRowClassName),
811
+ key
812
+ },
813
+ rowSelection && !groupRow && /* @__PURE__ */ jsx(
814
+ BodyCell,
815
+ {
816
+ className: classNames(
817
+ "bj-table__cell",
818
+ "bj-table__selection-cell",
819
+ Boolean(scroll == null ? void 0 : scroll.x) && "bj-table__selection-cell--fixed",
820
+ // 选择列就是最后一个左固定区域时,由它承担左侧渐变阴影
821
+ Boolean(scroll == null ? void 0 : scroll.x) && !isFixedLeftColumn(activeColumns[0]) && "bj-table__cell--fixed-left-last"
822
+ ),
823
+ style: { width: selectionColumnWidth },
824
+ children: /* @__PURE__ */ jsx(
825
+ SelectionControl,
826
+ {
827
+ checked: isSelected,
828
+ disabled: isDisabled,
829
+ label: `选择第 ${index + 1} 行`,
830
+ name: rowSelection.type === "radio" ? "bj-table-row-selection" : void 0,
831
+ onChange: () => toggleRow(record, index),
832
+ type: rowSelection.type ?? "checkbox"
833
+ }
834
+ )
835
+ }
836
+ ),
837
+ activeColumns.map((rawColumn, columnIndex) => {
838
+ var _a3, _b2, _c2;
839
+ if (groupRow && columnIndex > 0) return null;
840
+ const column = rawColumn;
841
+ const value = getValue(record, column.dataIndex);
842
+ const rendered = column.render ? column.render(value, record, index) : value;
843
+ const renderedCell = isRenderedCell(rendered) ? rendered : void 0;
844
+ const cellProps = { ...(_a3 = column.onCell) == null ? void 0 : _a3.call(column, record, index), ...renderedCell == null ? void 0 : renderedCell.props };
845
+ const content = renderedCell ? renderedCell.children : rendered;
846
+ if (cellProps.colSpan === 0 || cellProps.rowSpan === 0) return null;
847
+ return /* @__PURE__ */ createElement(
848
+ BodyCell,
849
+ {
850
+ ...cellProps,
851
+ className: classNames(
852
+ "bj-table__cell",
853
+ ((_b2 = activeColumns[columnIndex + 1]) == null ? void 0 : _b2.fixed) === "right" && "bj-table__cell--before-fixed-right",
854
+ groupRow && "bj-table__cell--group",
855
+ column.fixed && "bj-table__cell--fixed",
856
+ isFixedLeftColumn(column) && "bj-table__cell--fixed-left",
857
+ isFixedLeftColumn(column) && !isFixedLeftColumn(activeColumns[columnIndex + 1]) && "bj-table__cell--fixed-left-last",
858
+ isFixedRightColumn(column) && "bj-table__cell--fixed-right",
859
+ isFixedRightColumn(column) && !isFixedRightColumn(activeColumns[columnIndex - 1]) && "bj-table__cell--fixed-right-first",
860
+ column.ellipsis && "bj-table__cell--ellipsis",
861
+ column.className,
862
+ cellProps.className
863
+ ),
864
+ key: column.key ?? String(column.dataIndex ?? columnIndex),
865
+ colSpan: groupRow ? columnCount : cellProps.colSpan,
866
+ style: { textAlign: column.align, ...getFixedStyle(column, columnIndex), ...cellProps.style }
867
+ },
868
+ groupRow ? ((_c2 = groupCollapse == null ? void 0 : groupCollapse.render) == null ? void 0 : _c2.call(groupCollapse, {
869
+ record,
870
+ expanded: expandedGroupKeys.includes(getGroupKey(record, index)),
871
+ onToggle: () => toggleGroup(record, index)
872
+ })) ?? content ?? "" : /* @__PURE__ */ jsx("div", { className: "bj-table__cell-content", children: content ?? "" })
873
+ );
874
+ })
875
+ );
876
+ }) : /* @__PURE__ */ jsx(BodyRow, { className: "bj-table__empty-row", children: /* @__PURE__ */ jsx(
877
+ BodyCell,
878
+ {
879
+ className: "bj-table__empty-cell",
880
+ colSpan: Math.max(columnCount, 1),
881
+ style: { height: emptyHeight }
882
+ }
883
+ ) }) }),
884
+ summary && /* @__PURE__ */ jsx("tfoot", { className: "bj-table__summary", children: summary(processedData) })
885
+ ] })
886
+ }
887
+ ),
888
+ visibleRecords.length === 0 && /* @__PURE__ */ jsx("div", { className: "bj-table__empty-overlay", children: /* @__PURE__ */ jsxs("div", { className: "bj-table__empty-content", children: [
889
+ resolvedEmptyImage && /* @__PURE__ */ jsx("div", { className: "bj-table__empty-image-wrap", children: resolvedEmptyImage }),
890
+ /* @__PURE__ */ jsx("div", { className: "bj-table__empty-text", children: resolvedEmptyText })
891
+ ] }) })
892
+ ] }),
893
+ ((scroll == null ? void 0 : scroll.x) || (scroll == null ? void 0 : scroll.y)) && /* @__PURE__ */ jsx(
894
+ BOverlayScrollbar,
895
+ {
896
+ containerRef: tableRootRef,
897
+ direction: (scroll == null ? void 0 : scroll.x) && (scroll == null ? void 0 : scroll.y) ? "both" : (scroll == null ? void 0 : scroll.x) ? "horizontal" : "vertical",
898
+ gap: 2,
899
+ horizontalInsetEnd: horizontalInsets.end,
900
+ horizontalInsetStart: horizontalInsets.start,
901
+ size: 4,
902
+ targetRef: tableScrollRef
903
+ }
904
+ ),
905
+ footer && /* @__PURE__ */ jsx("div", { className: "bj-table__footer", children: footer(processedData) }),
906
+ loading && /* @__PURE__ */ jsxs("div", { "aria-live": "polite", "aria-busy": "true", className: "bj-table__loading", role: "status", children: [
907
+ /* @__PURE__ */ jsx("img", { alt: "", className: "bj-table__loading-indicator", src: loadingIndicator }),
908
+ /* @__PURE__ */ jsx("span", { className: "bj-table__loading-text", children: "加载中..." })
909
+ ] }),
910
+ paginationConfig && processedData.length > 0 && /* @__PURE__ */ jsx("div", { className: "bj-table__pagination", children: /* @__PURE__ */ jsx(
911
+ Pagination,
912
+ {
913
+ align: "end",
914
+ disabled: loading || paginationConfig.disabled,
915
+ current,
916
+ defaultCurrent: paginationConfig.defaultCurrent,
917
+ defaultPageSize: paginationConfig.defaultPageSize,
918
+ dropdownClassName: paginationConfig.dropdownClassName,
919
+ hideOnSinglePage: paginationConfig.hideOnSinglePage,
920
+ onChange: (nextPage) => {
921
+ if (ignoreNextPaginationChangeRef.current) {
922
+ ignoreNextPaginationChangeRef.current = false;
923
+ return;
924
+ }
925
+ changePage(nextPage);
926
+ },
927
+ onShowSizeChange: (_, nextPageSize) => changePageSize(nextPageSize),
928
+ pageSize,
929
+ pageSizeOptions: paginationConfig.pageSizeOptions,
930
+ popupPlacement: paginationConfig.popupPlacement,
931
+ resolvePopupPlacement: paginationConfig.resolvePopupPlacement,
932
+ showQuickJumper: paginationConfig.showQuickJumper,
933
+ showSizeChanger: paginationConfig.showSizeChanger,
934
+ showTotal: paginationConfig.showTotal,
935
+ simple: paginationConfig.simple,
936
+ size: paginationConfig.size,
937
+ t: paginationConfig.t ?? t,
938
+ total
939
+ }
940
+ ) })
941
+ ]
942
+ }
943
+ );
944
+ }
945
+ const CompoundBTable = BTable;
946
+ CompoundBTable.Column = Column;
947
+ CompoundBTable.ColumnGroup = ColumnGroup;
948
+ export {
949
+ CompoundBTable as BTable
950
+ };