@aloudata/aloudata-design 2.17.3 → 2.17.5

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.
@@ -136,14 +136,13 @@ var BaseSelect = /*#__PURE__*/React.forwardRef(function (props, ref) {
136
136
  var nextOpen = newOpen !== undefined ? newOpen : !mergedOpen;
137
137
  if (!nextOpen) {
138
138
  setShowResponsiveSelectedSection(false);
139
- setInnerSearchValue === null || setInnerSearchValue === void 0 ? void 0 : setInnerSearchValue('');
140
139
  setFocus(false);
141
140
  }
142
141
  if (mergedOpen !== nextOpen && !disabled) {
143
142
  setInnerOpen(nextOpen);
144
143
  onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(nextOpen);
145
144
  }
146
- }, [mergedOpen, disabled, setInnerSearchValue, setInnerOpen, onOpenChange]);
145
+ }, [mergedOpen, disabled, setInnerOpen, onOpenChange]);
147
146
  var _useState5 = useState(false),
148
147
  _useState6 = _slicedToArray(_useState5, 2),
149
148
  showResponsiveSelectedSection = _useState6[0],
@@ -190,18 +189,29 @@ var BaseSelect = /*#__PURE__*/React.forwardRef(function (props, ref) {
190
189
  }
191
190
  onClick === null || onClick === void 0 ? void 0 : onClick(e);
192
191
  }, [disabled, onClick]);
192
+ React.useEffect(function () {
193
+ var element = selectRef.current;
194
+ if (element) {
195
+ var handleMouseOver = function handleMouseOver() {
196
+ return setIsHover(true);
197
+ };
198
+ var handleMouseOut = function handleMouseOut() {
199
+ return setIsHover(false);
200
+ };
201
+ element.addEventListener('mouseover', handleMouseOver);
202
+ element.addEventListener('mouseout', handleMouseOut);
203
+ return function () {
204
+ element.removeEventListener('mouseover', handleMouseOver);
205
+ element.removeEventListener('mouseout', handleMouseOut);
206
+ };
207
+ }
208
+ }, []);
193
209
  return /*#__PURE__*/React.createElement("div", {
194
210
  className: mergedClassName,
195
211
  style: _objectSpread(_objectSpread({}, widthStyle), style),
196
212
  ref: selectRef,
197
213
  id: id,
198
- onClick: onSelectClick,
199
- onMouseEnter: function onMouseEnter() {
200
- setIsHover(true);
201
- },
202
- onMouseLeave: function onMouseLeave() {
203
- setIsHover(false);
204
- }
214
+ onClick: onSelectClick
205
215
  }, /*#__PURE__*/React.createElement(SelectTrigger, {
206
216
  open: !!mergedOpen,
207
217
  notFoundContent: notFoundContent,
@@ -13,6 +13,7 @@ function SearchBox(_ref) {
13
13
  className: "beta-ald-select-search-box",
14
14
  value: value,
15
15
  size: "small",
16
+ allowClear: true,
16
17
  bordered: false,
17
18
  onBlur: onBlur,
18
19
  prefix: /*#__PURE__*/React.createElement(SearchLine, {
@@ -18,7 +18,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
18
18
  import React, { forwardRef, useCallback, useContext, useMemo } from 'react';
19
19
  import useOptions, { isRawValue } from "./hooks/useOptions";
20
20
  import useMergedState from 'rc-util/lib/hooks/useMergedState';
21
- import { toArray } from "./utils/commonUtil";
21
+ import { noOpFilter, toArray } from "./utils/commonUtil";
22
22
  import useCache from "./hooks/useCache";
23
23
  import BaseSelect, { isMultiple } from "./BaseSelect";
24
24
  import { injectPropsWithOption } from "./utils/valueUtil";
@@ -33,6 +33,7 @@ export default /*#__PURE__*/forwardRef(function AldSelect(props, ref) {
33
33
  options = props.options,
34
34
  onChange = props.onChange,
35
35
  onSelect = props.onSelect,
36
+ onSearch = props.onSearch,
36
37
  onDeselect = props.onDeselect,
37
38
  labelInValue = props.labelInValue,
38
39
  filterOption = props.filterOption,
@@ -205,6 +206,12 @@ export default /*#__PURE__*/forwardRef(function AldSelect(props, ref) {
205
206
  });
206
207
  }
207
208
  };
209
+ var handleSearch = function handleSearch(value) {
210
+ setInnerSearchValue(value);
211
+ if (onSearch) {
212
+ onSearch(value);
213
+ }
214
+ };
208
215
  var selectMenu = useMemo(function () {
209
216
  return _objectSpread(_objectSpread({}, mergedMenu), {}, {
210
217
  items: (mergedMenu === null || mergedMenu === void 0 ? void 0 : mergedMenu.items) || [],
@@ -229,14 +236,16 @@ export default /*#__PURE__*/forwardRef(function AldSelect(props, ref) {
229
236
  }
230
237
  });
231
238
  }, [mergedMenu, mode, displayValues, triggerChange]);
232
- var displayMenu = useDisplayMenu(selectMenu, filterOption, innerSearchValue);
239
+ var displayMenu = useDisplayMenu(selectMenu,
240
+ // 如果用户接管了搜索,则默认不做搜索过滤
241
+ onSearch ? filterOption || noOpFilter : filterOption, innerSearchValue);
233
242
  return /*#__PURE__*/React.createElement(BaseSelect, _extends({}, props, {
234
243
  ref: ref,
235
244
  disabled: mergedDisabled,
236
245
  displayValues: displayValues,
237
246
  onDisplayValuesChange: onDisplayValuesChange,
238
- setInnerSearchValue: setInnerSearchValue,
239
- innerSearchValue: innerSearchValue,
247
+ setInnerSearchValue: handleSearch,
248
+ innerSearchValue: searchValue === undefined ? innerSearchValue : searchValue,
240
249
  onOptionSelect: onOptionSelect,
241
250
  menu: selectMenu,
242
251
  displayMenu: displayMenu
@@ -42,6 +42,7 @@ export interface ISelectProps<ValueType = any, OptionType extends BaseOptionType
42
42
  onSelect?: SelectHandler<ArrayElementType<ValueType>, OptionType>;
43
43
  onDeselect?: SelectHandler<ArrayElementType<ValueType>, OptionType>;
44
44
  notFoundContent?: React.ReactNode;
45
+ onSearch?: (value: string) => void;
45
46
  filterOption?: (inputValue: string, option: OptionType) => boolean;
46
47
  tagRender?: (props: CustomTagProps, isPreview?: boolean) => React.ReactNode;
47
48
  maxTagPlaceholder?: React.ReactNode | ((omittedValues: DisplayValueType[]) => React.ReactNode);
@@ -6,3 +6,4 @@ export declare const toString: (value: any) => string;
6
6
  /** Is client side and not jsdom */
7
7
  export declare const isBrowserClient: false | HTMLElement;
8
8
  export declare function convertOptionsToMenu(options: DefaultOptionType[], selectedKeys: React.Key[]): SelectMenuProps;
9
+ export declare function noOpFilter(): boolean;
@@ -32,4 +32,7 @@ export function convertOptionsToMenu(options, selectedKeys) {
32
32
  }),
33
33
  selectedKeys: selectedKeys
34
34
  };
35
+ }
36
+ export function noOpFilter() {
37
+ return true;
35
38
  }
@@ -13,15 +13,12 @@
13
13
  }
14
14
 
15
15
  .ant-modal-wrap {
16
- position: fixed;
17
- inset: 0;
18
- top: 0;
19
- inset-inline-end: 0;
20
- bottom: 0;
21
- inset-inline-start: 0;
22
- overflow: auto;
23
16
  outline: 0;
24
17
  z-index: 1000;
18
+ display: grid;
19
+ grid-template-rows: minmax(0, 100px) auto 1fr;
20
+ place-items: center;
21
+ height: 100vh;
25
22
  }
26
23
 
27
24
  .ant-modal.ald-modal {
@@ -34,10 +31,10 @@
34
31
  list-style: none;
35
32
  pointer-events: none;
36
33
  position: relative;
37
- top: 100px;
34
+ grid-row: 2;
35
+ top: 0;
38
36
  width: auto;
39
37
  max-width: calc(100vw - 32px);
40
- padding-bottom: 24px;
41
38
  }
42
39
 
43
40
  .ant-modal-content {
@@ -23,7 +23,7 @@ export declare function getTableColumns<TDataItem extends object>({ columns, con
23
23
  render?: ((text: any, record: TDataItem, rowIndex: number) => import("react").ReactNode) | undefined;
24
24
  ellipsis?: boolean | undefined;
25
25
  noPadding?: boolean | undefined;
26
- align?: "center" | "left" | "right" | undefined;
26
+ align?: "left" | "center" | "right" | undefined;
27
27
  fixed?: "left" | "right" | undefined;
28
28
  sortOrder?: "ascend" | "descend" | null | undefined;
29
29
  };
@@ -41,3 +41,4 @@ export declare function getNumberFromPercentageStr(str: string): number;
41
41
  export declare function isPercentage(str: string): boolean;
42
42
  export declare function prefixCls(className: string): string;
43
43
  export declare function getRowKey<TDataItem extends object>(row: TDataItem, rowKey: ITableProps<TDataItem>['rowKey'], defaultKey?: string | number): string;
44
+ export declare function hasFixedLeftColumn<TDataItem extends object>(columns: ITableColumn<TDataItem>[]): boolean;
@@ -155,4 +155,9 @@ export function getRowKey(row, rowKey, defaultKey) {
155
155
  rowKeyStr = _.get(row, rowKey);
156
156
  }
157
157
  return _.toString(rowKeyStr);
158
+ }
159
+ export function hasFixedLeftColumn(columns) {
160
+ return columns.some(function (col) {
161
+ return col.fixed === 'left';
162
+ });
158
163
  }
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { ITableProps } from '../types';
3
+ export default function useRowDnd<TDataItem extends object>(props: ITableProps<TDataItem>): IRowDndInfo<TDataItem>;
4
+ interface IRowDndInfo<TDataItem extends object> {
5
+ columns: ITableProps<TDataItem>['columns'];
6
+ getRowRef: (record: TDataItem, rowIndex: number) => React.MutableRefObject<HTMLDivElement> | undefined;
7
+ draggingRowId: string | null;
8
+ tableData: TDataItem[];
9
+ }
10
+ export {};
@@ -0,0 +1,252 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
4
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
5
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
10
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
+ import DragLightLineSvg from "../../Icon/components/DragLightLine";
12
+ import React, { useCallback, useMemo, useRef, useState } from 'react';
13
+ import { useDrag, useDrop } from 'react-dnd';
14
+ import { getEmptyImage } from 'react-dnd-html5-backend';
15
+ import { getRowKey, hasFixedLeftColumn, prefixCls } from "../helper";
16
+ // 定义拖拽项类型
17
+ var ROW_DND_TYPE = 'ALD_TABLE_ROW_DND_TYPE';
18
+ // 拖拽手柄组件
19
+ var DragHandle = function DragHandle(_ref) {
20
+ var index = _ref.index,
21
+ id = _ref.id,
22
+ onDragging = _ref.onDragging,
23
+ rowRef = _ref.rowRef,
24
+ onDragStart = _ref.onDragStart,
25
+ onDragComplete = _ref.onDragComplete;
26
+ var ref = useRef(null);
27
+
28
+ // 使用 ref 来跟踪是否已经通知拖动开始
29
+ var dragStartedRef = useRef(false);
30
+ var _useDrag = useDrag({
31
+ type: ROW_DND_TYPE,
32
+ item: function item() {
33
+ // 只在拖拽真正开始且尚未通知时触发一次
34
+ if (!dragStartedRef.current) {
35
+ // 通知开始拖动,传递行的ID
36
+ onDragStart(id);
37
+ dragStartedRef.current = true;
38
+ }
39
+ return {
40
+ index: index,
41
+ id: id
42
+ };
43
+ },
44
+ collect: function collect(monitor) {
45
+ return {
46
+ isDragging: monitor.isDragging()
47
+ };
48
+ },
49
+ end: function end() {
50
+ // 拖拽结束时清除拖动状态和重置标志
51
+ onDragComplete();
52
+ dragStartedRef.current = false;
53
+ }
54
+ }),
55
+ _useDrag2 = _slicedToArray(_useDrag, 3),
56
+ isDragging = _useDrag2[0].isDragging,
57
+ drag = _useDrag2[1],
58
+ preview = _useDrag2[2];
59
+ var _useDrop = useDrop({
60
+ accept: ROW_DND_TYPE,
61
+ // @ts-ignore - react-dnd类型定义有时与实际用法不一致
62
+ hover: function hover(item, monitor) {
63
+ // 如果有行引用并且行引用有值,使用行引用来判断位置
64
+ var dropRef = rowRef === null || rowRef === void 0 ? void 0 : rowRef.current;
65
+ if (!dropRef) {
66
+ return;
67
+ }
68
+ var dragIndex = item.index;
69
+ var hoverIndex = index;
70
+
71
+ // 如果拖动的是自己,不做任何事
72
+ if (dragIndex === hoverIndex) {
73
+ return;
74
+ }
75
+
76
+ // 确定鼠标位置
77
+ var hoverBoundingRect = dropRef.getBoundingClientRect();
78
+ var hoverMiddleY = (hoverBoundingRect.bottom - hoverBoundingRect.top) / 2;
79
+ var clientOffset = monitor.getClientOffset();
80
+ if (!clientOffset) {
81
+ return;
82
+ }
83
+ var hoverClientY = clientOffset.y - hoverBoundingRect.top;
84
+
85
+ // 向下拖动,但鼠标还没过半
86
+ if (dragIndex < hoverIndex && hoverClientY < hoverMiddleY) {
87
+ return;
88
+ }
89
+
90
+ // 向上拖动,但鼠标还没过半
91
+ if (dragIndex > hoverIndex && hoverClientY > hoverMiddleY) {
92
+ return;
93
+ }
94
+
95
+ // 执行排序
96
+ onDragging(dragIndex, hoverIndex);
97
+
98
+ // 更新拖拽项的索引,react-dnd 官方示例推荐这样做以提高性能并避免奇怪行为
99
+ item.index = hoverIndex;
100
+ }
101
+ }),
102
+ _useDrop2 = _slicedToArray(_useDrop, 2),
103
+ drop = _useDrop2[1];
104
+
105
+ // 将 drag 连接到手柄 ref 上
106
+ drag(ref);
107
+
108
+ // 设置放置目标
109
+ if (rowRef !== null && rowRef !== void 0 && rowRef.current) {
110
+ drop(rowRef.current);
111
+ }
112
+ preview(getEmptyImage());
113
+ return /*#__PURE__*/React.createElement("div", {
114
+ ref: ref,
115
+ className: prefixCls('row-dnd-item'),
116
+ style: {
117
+ cursor: 'move',
118
+ opacity: isDragging ? 0.5 : 1
119
+ }
120
+ }, /*#__PURE__*/React.createElement(DragLightLineSvg, null));
121
+ };
122
+ export default function useRowDnd(props) {
123
+ var columns = props.columns,
124
+ rowDnd = props.rowDnd,
125
+ data = props.data,
126
+ rowKey = props.rowKey;
127
+ // 跟踪当前正在拖动的行的ID
128
+ var _useState = useState(null),
129
+ _useState2 = _slicedToArray(_useState, 2),
130
+ draggingRowId = _useState2[0],
131
+ setDraggingRowId = _useState2[1];
132
+
133
+ // 为每一行创建一个 ref,使用 useMemo 缓存 Map 实例
134
+ var rowRefs = useMemo(function () {
135
+ return new Map();
136
+ }, []);
137
+
138
+ // 当拖拽过程中,临时存储数据
139
+ var _useState3 = useState(data),
140
+ _useState4 = _slicedToArray(_useState3, 2),
141
+ draggingTempData = _useState4[0],
142
+ setDraggingTempData = _useState4[1];
143
+ var tableData = useMemo(function () {
144
+ // 拖拽过程中,使用临时数据,这样外部调用方可以不用关心拖拽过程中的数据变化
145
+ if (draggingRowId) {
146
+ return draggingTempData;
147
+ }
148
+ return data;
149
+ }, [data, draggingRowId, draggingTempData]);
150
+
151
+ // 获取行的 ref,用于设置拖拽预览
152
+ var getRowRef = useCallback(function (record) {
153
+ var key = getRowKey(record, rowKey);
154
+ if (!rowRefs.has(key)) {
155
+ rowRefs.set(key, /*#__PURE__*/React.createRef());
156
+ }
157
+ return rowRefs.get(key);
158
+ }, [rowKey, rowRefs]);
159
+ var defaultInfo = useMemo(function () {
160
+ return {
161
+ columns: columns,
162
+ getRowRef: function getRowRef() {
163
+ return undefined;
164
+ },
165
+ draggingRowId: null,
166
+ tableData: data
167
+ };
168
+ }, [columns, data]);
169
+ if (!rowDnd) {
170
+ return defaultInfo;
171
+ }
172
+ if (props.expandable) {
173
+ console.error('rowDnd and expandable mode cannot be used together');
174
+ return defaultInfo;
175
+ }
176
+ if (!props.rowKey) {
177
+ // 如果rowKey没有设置,则无法进行拖拽,因为必须知道每行的唯一标识
178
+ console.error('rowKey is required in rowDnd mode');
179
+ return defaultInfo;
180
+ }
181
+ var rowDndFixed = rowDnd.fixed,
182
+ onChange = rowDnd.onChange;
183
+ var fixed = rowDndFixed || hasFixedLeftColumn(columns);
184
+ var handleDragging = function handleDragging(dragIndex, hoverIndex) {
185
+ // 使用函数式更新,确保基于最新的状态进行操作
186
+ setDraggingTempData(function (currentData) {
187
+ var newData = _toConsumableArray(currentData);
188
+
189
+ // 确保 dragIndex 在有效范围内
190
+ if (dragIndex < 0 || dragIndex >= newData.length) {
191
+ console.warn("Drag index ".concat(dragIndex, " out of bounds for data length ").concat(newData.length));
192
+ return currentData; // 返回当前状态,不作修改
193
+ }
194
+
195
+ // 保存被拖拽的行
196
+ var draggedRow = newData.splice(dragIndex, 1)[0];
197
+
198
+ // 如果因为某些原因未能获取到拖拽的行(理论上不应发生)
199
+ if (draggedRow === undefined) {
200
+ console.warn("Dragged item at index ".concat(dragIndex, " was undefined during splice."));
201
+ return currentData; // 返回当前状态,不作修改
202
+ }
203
+
204
+ // 插入到新位置
205
+ newData.splice(hoverIndex, 0, draggedRow);
206
+ return newData;
207
+ });
208
+ };
209
+
210
+ // 记录拖动开始
211
+ var handleDragStart = function handleDragStart(id) {
212
+ setDraggingRowId(id);
213
+ };
214
+
215
+ // 记录拖动结束
216
+ var handleDragComplete = function handleDragComplete() {
217
+ var draggingRow = tableData.find(function (item) {
218
+ return getRowKey(item, rowKey) === draggingRowId;
219
+ });
220
+ setDraggingRowId(null);
221
+ if (!draggingRow) {
222
+ // 不应该出现这种情况
223
+ console.error('draggingRow is not found');
224
+ return;
225
+ }
226
+ onChange(tableData, draggingRow);
227
+ };
228
+ var dndColumn = {
229
+ dataIndex: '',
230
+ title: '',
231
+ width: 48,
232
+ render: function render(text, record, rowIndex) {
233
+ var key = getRowKey(record, rowKey);
234
+ var rowRef = getRowRef(record);
235
+ return /*#__PURE__*/React.createElement(DragHandle, {
236
+ index: rowIndex,
237
+ id: key,
238
+ onDragging: handleDragging,
239
+ onDragStart: handleDragStart,
240
+ onDragComplete: handleDragComplete,
241
+ rowRef: rowRef
242
+ });
243
+ },
244
+ fixed: fixed ? 'left' : undefined
245
+ };
246
+ return {
247
+ columns: [dndColumn].concat(_toConsumableArray(columns)),
248
+ getRowRef: getRowRef,
249
+ draggingRowId: draggingRowId,
250
+ tableData: tableData
251
+ };
252
+ }
@@ -17,7 +17,7 @@ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefine
17
17
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
18
18
  import React, { useCallback, useState } from 'react';
19
19
  import Checkbox from "../../Checkbox";
20
- import { getRowKey, prefixCls } from "../helper";
20
+ import { getRowKey, hasFixedLeftColumn, prefixCls } from "../helper";
21
21
  export default function useRowSelection(props) {
22
22
  var _rowSelection$items;
23
23
  var columns = props.columns,
@@ -97,6 +97,7 @@ export default function useRowSelection(props) {
97
97
  if (!rowKey) {
98
98
  throw new Error('rowKey is required when rowSelection is enabled');
99
99
  }
100
+ var fixed = !!rowSelection.fixed || hasFixedLeftColumn(columns);
100
101
  var rowSelectionColumn = {
101
102
  dataIndex: '',
102
103
  title: /*#__PURE__*/React.createElement("div", {
@@ -115,7 +116,7 @@ export default function useRowSelection(props) {
115
116
  checked: isChecked
116
117
  }, checkboxProps)));
117
118
  },
118
- fixed: rowSelection.fixed ? 'left' : undefined
119
+ fixed: fixed ? 'left' : undefined
119
120
  };
120
121
  var selectedRowKeysInCurrPage = getDataWithoutDisabled(data, rowSelection.getCheckboxProps).map(function (record) {
121
122
  return getRowKey(record, rowKey);
@@ -17,6 +17,8 @@ import _ from 'lodash';
17
17
  import ResizeObserver from 'rc-resize-observer';
18
18
  import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useState } from 'react';
19
19
  import { Empty, Spin } from '..';
20
+ import { DndProvider } from 'react-dnd';
21
+ import { HTML5Backend } from 'react-dnd-html5-backend';
20
22
  import ExpandCell from "./components/ExpandCell";
21
23
  import Footer from "./components/Footer";
22
24
  import { getRowKey, getTableColumns, prefixCls } from "./helper";
@@ -24,6 +26,7 @@ import useExpandable, { getExpandableConfig } from "./hooks/useExpandable";
24
26
  import useFixed from "./hooks/useFixed";
25
27
  import useRowSelection from "./hooks/useRowSelection";
26
28
  import useScroll from "./hooks/useScroll";
29
+ import useRowDnd from "./hooks/useRowDnd";
27
30
  var HEADER_HEIGHT = 41;
28
31
  var FOOTER_HEIGHT = 52;
29
32
  function Table(props, ref) {
@@ -47,7 +50,8 @@ function Table(props, ref) {
47
50
  onRowClick = props.onRowClick,
48
51
  onError = props.onError,
49
52
  onSort = props.onSort,
50
- expandable = props.expandable;
53
+ expandable = props.expandable,
54
+ rowDnd = props.rowDnd;
51
55
  var _useState = useState(null),
52
56
  _useState2 = _slicedToArray(_useState, 2),
53
57
  totalSize = _useState2[0],
@@ -87,18 +91,22 @@ function Table(props, ref) {
87
91
  });
88
92
  var expandableConfig = getExpandableConfig(expandable);
89
93
  var rowSelectionInfo = useRowSelection(props);
94
+ var rowDndInfo = useRowDnd(_objectSpread(_objectSpread({}, props), {}, {
95
+ columns: rowSelectionInfo.columns,
96
+ data: expandableInfo.data
97
+ }));
90
98
  var tableColumns = useMemo(function () {
91
99
  return getTableColumns({
92
- columns: rowSelectionInfo.columns,
100
+ columns: rowDndInfo.columns,
93
101
  containerWidth: containerWidth || 0,
94
102
  onError: onError,
95
103
  onSort: onSort
96
104
  });
97
- }, [containerWidth, onError, onSort, rowSelectionInfo.columns]);
105
+ }, [containerWidth, onError, onSort, rowDndInfo.columns]);
98
106
  var tableInstance = useReactTable({
99
107
  columns: tableColumns,
100
108
  // 排除掉被折叠的行
101
- data: expandableInfo.data,
109
+ data: rowDndInfo.tableData,
102
110
  getCoreRowModel: getCoreRowModel(),
103
111
  getRowId: function getRowId(row, index) {
104
112
  return getRowKey(row, rowKey, index);
@@ -393,9 +401,18 @@ function Table(props, ref) {
393
401
  var rowNode = /*#__PURE__*/React.createElement("div", {
394
402
  key: rowId,
395
403
  "data-index": virtual ? rowData.index : rowIndex,
396
- className: classnames(prefixCls('tr'), (_classnames4 = {}, _defineProperty(_classnames4, prefixCls('row-hover'), hoverRowId === rowId), _defineProperty(_classnames4, prefixCls('no-border-tr'), isShowPagination && rowIndex === rows.length - 1), _classnames4), rowClassName(row.original, rowIndex)),
404
+ className: classnames(prefixCls('tr'), (_classnames4 = {}, _defineProperty(_classnames4, prefixCls('row-hover'), rowDndInfo.draggingRowId ? undefined : hoverRowId === rowId), _defineProperty(_classnames4, prefixCls('row-dragging'), rowDndInfo.draggingRowId === rowId), _defineProperty(_classnames4, prefixCls('no-border-tr'), isShowPagination && rowIndex === rows.length - 1), _classnames4), rowClassName(row.original, rowIndex)),
397
405
  ref: function ref(node) {
398
- return rowVirtualizer.measureElement(node);
406
+ // 将引用同时传递给 rowVirtualizer 和 rowDnd
407
+ rowVirtualizer.measureElement(node);
408
+
409
+ // 如果启用了行拖拽,则设置行引用
410
+ if (rowDnd && node) {
411
+ var rowRef = rowDndInfo.getRowRef(row.original, rowIndex);
412
+ if (rowRef) {
413
+ rowRef.current = node;
414
+ }
415
+ }
399
416
  },
400
417
  onClick: onClickRow(row.original, rowIndex),
401
418
  onMouseEnter: function onMouseEnter() {
@@ -474,6 +491,8 @@ function Table(props, ref) {
474
491
  }
475
492
  }, /*#__PURE__*/React.createElement("div", {
476
493
  className: classnames(prefixCls('main'), (_classnames7 = {}, _defineProperty(_classnames7, prefixCls('overflow-hidden'), !!y), _defineProperty(_classnames7, prefixCls('ping-left'), isPingLeft), _defineProperty(_classnames7, prefixCls('ping-right'), isPingRight), _classnames7))
477
- }, tableContent)));
494
+ }, rowDnd ? /*#__PURE__*/React.createElement(DndProvider, {
495
+ backend: HTML5Backend
496
+ }, tableContent) : tableContent)));
478
497
  }
479
498
  export default /*#__PURE__*/forwardRef(Table);
@@ -226,6 +226,12 @@
226
226
  background-color: #f9fafb;
227
227
  }
228
228
  }
229
+
230
+ &.ald-table-row-dragging {
231
+ .ald-table-td {
232
+ background-color: #f9fafb;
233
+ }
234
+ }
229
235
  }
230
236
  }
231
237
 
@@ -399,3 +405,17 @@
399
405
  flex-shrink: 0;
400
406
  flex-grow: 0;
401
407
  }
408
+
409
+ /** 行拖拽 **/
410
+ .ald-table-row-dnd-item {
411
+ display: flex;
412
+ align-items: center;
413
+ justify-content: center;
414
+ width: 100%;
415
+ height: 100%;
416
+ cursor: grab;
417
+
418
+ &:active {
419
+ cursor: grabbing;
420
+ }
421
+ }
@@ -21,6 +21,10 @@ export interface ITableProps<TDataItem extends object> {
21
21
  rowSelection?: IRowSelection<TDataItem>;
22
22
  bordered?: boolean;
23
23
  virtual?: boolean;
24
+ rowDnd?: {
25
+ fixed?: boolean;
26
+ onChange: (data: TDataItem[], dataItem: TDataItem) => void;
27
+ };
24
28
  }
25
29
  export type TRowKey<TDataItem extends object> = string | ((record: TDataItem) => string | number);
26
30
  export interface ITableCellErrorInfo {