@mezzanine-ui/react 0.13.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Table/Table.d.ts +8 -2
- package/Table/Table.js +38 -23
- package/Table/TableBodyRow.js +19 -15
- package/Table/TableContext.d.ts +4 -1
- package/Table/draggable/useTableDraggable.d.ts +14 -0
- package/Table/draggable/useTableDraggable.js +63 -0
- package/Table/index.d.ts +2 -0
- package/Table/index.js +2 -0
- package/Table/sorting/useTableSorting.d.ts +2 -0
- package/Table/sorting/useTableSorting.js +1 -1
- package/index.d.ts +2 -1
- package/index.js +3 -0
- package/package.json +6 -4
- package/utils/array-move.d.ts +1 -0
- package/utils/array-move.js +13 -0
package/Table/Table.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { TableColumn, TableComponents, TableDataSource, TableRowSelection, TableExpandable, TableFetchMore, TablePagination as TablePaginationType, TableRefresh as TableRefreshType, ExpandRowBySources, TableScrolling } from '@mezzanine-ui/core/table';
|
|
2
|
+
import { TableColumn, TableComponents, TableDataSource, TableRowSelection, TableExpandable, TableFetchMore, TablePagination as TablePaginationType, TableRefresh as TableRefreshType, ExpandRowBySources, TableScrolling, TableDraggable } from '@mezzanine-ui/core/table';
|
|
3
3
|
import { EmptyProps } from '../Empty';
|
|
4
4
|
import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
|
|
5
|
-
export interface TableBaseProps<T> extends Omit<NativeElementPropsWithoutKeyAndRef<'div'>, 'role'> {
|
|
5
|
+
export interface TableBaseProps<T> extends Omit<NativeElementPropsWithoutKeyAndRef<'div'>, 'role' | 'draggable'> {
|
|
6
6
|
/**
|
|
7
7
|
* customized body className
|
|
8
8
|
*/
|
|
@@ -28,6 +28,12 @@ export interface TableBaseProps<T> extends Omit<NativeElementPropsWithoutKeyAndR
|
|
|
28
28
|
* Notice that each source should contain `key` or `id` prop as data primary key.
|
|
29
29
|
*/
|
|
30
30
|
dataSource: TableDataSource[];
|
|
31
|
+
/**
|
|
32
|
+
* Draggable table row. This feature allows sort items by mouse dragging. Not supported when `fetchMore` is enabled and also buggy when use finger touch (mobile device).
|
|
33
|
+
* When `draggable.enabled` is true, draggable will be enabled.
|
|
34
|
+
* `draggable.onDragEnd` return new dataSource for you
|
|
35
|
+
*/
|
|
36
|
+
draggable?: TableDraggable;
|
|
31
37
|
/**
|
|
32
38
|
* props exported from `<Empty />` component.
|
|
33
39
|
*/
|
package/Table/Table.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
-
import { forwardRef, useRef, useMemo } from 'react';
|
|
2
|
+
import { forwardRef, useRef, useMemo, Fragment } from 'react';
|
|
3
|
+
import { DragDropContext, Droppable } from 'react-beautiful-dnd';
|
|
3
4
|
import { tableClasses } from '@mezzanine-ui/core/table';
|
|
4
5
|
import { TableContext, TableDataContext, TableComponentContext } from './TableContext.js';
|
|
5
6
|
import TableHeader from './TableHeader.js';
|
|
@@ -10,14 +11,16 @@ import { useTableRowSelection } from './rowSelection/useTableRowSelection.js';
|
|
|
10
11
|
import { useTableSorting } from './sorting/useTableSorting.js';
|
|
11
12
|
import { useTableLoading } from './useTableLoading.js';
|
|
12
13
|
import { useTableFetchMore } from './useTableFetchMore.js';
|
|
14
|
+
import { useTableDraggable } from './draggable/useTableDraggable.js';
|
|
13
15
|
import useTableScroll from './useTableScroll.js';
|
|
14
16
|
import { useComposeRefs } from '../hooks/useComposeRefs.js';
|
|
17
|
+
import { composeRefs } from '../utils/composeRefs.js';
|
|
15
18
|
import Loading from '../Loading/Loading.js';
|
|
16
19
|
import cx from 'clsx';
|
|
17
20
|
|
|
18
21
|
const Table = forwardRef(function Table(props, ref) {
|
|
19
22
|
var _a;
|
|
20
|
-
const { bodyClassName, bodyRowClassName, className, columns, components, dataSource: dataSourceProp, emptyProps, expandable: expandableProp, fetchMore: fetchMoreProp, headerClassName, loading: loadingProp, loadingTip = '資料載入中...', pagination: paginationProp, refresh: refreshProp, rowSelection: rowSelectionProp, scroll: scrollProp, scrollContainerClassName, ...rest } = props;
|
|
23
|
+
const { bodyClassName, bodyRowClassName, className, columns, components, dataSource: dataSourceProp, draggable: draggableProp, emptyProps, expandable: expandableProp, fetchMore: fetchMoreProp, headerClassName, loading: loadingProp, loadingTip = '資料載入中...', pagination: paginationProp, refresh: refreshProp, rowSelection: rowSelectionProp, scroll: scrollProp, scrollContainerClassName, ...rest } = props;
|
|
21
24
|
const bodyRef = useRef(null);
|
|
22
25
|
/** Feature rowSelection */
|
|
23
26
|
const [selectedRowKeys, setSelectedRowKey] = useTableRowSelection({
|
|
@@ -35,7 +38,7 @@ const Table = forwardRef(function Table(props, ref) {
|
|
|
35
38
|
setSelectedRowKey,
|
|
36
39
|
]);
|
|
37
40
|
/** Feature sorting */
|
|
38
|
-
const [dataSource, onSort, { sortedOn, sortedType, onResetAll }] = useTableSorting({
|
|
41
|
+
const [dataSource, onSort, { sortedOn, sortedType, onResetAll, setDataSource, }] = useTableSorting({
|
|
39
42
|
dataSource: dataSourceProp,
|
|
40
43
|
});
|
|
41
44
|
/** Feature loading */
|
|
@@ -64,6 +67,12 @@ const Table = forwardRef(function Table(props, ref) {
|
|
|
64
67
|
loading,
|
|
65
68
|
scrollBarSize: 4,
|
|
66
69
|
});
|
|
70
|
+
/** Feature drag and drop */
|
|
71
|
+
const { draggingId, onBeforeDragStart, onDragEnd, } = useTableDraggable({
|
|
72
|
+
dataSource,
|
|
73
|
+
setDataSource,
|
|
74
|
+
draggable: draggableProp,
|
|
75
|
+
});
|
|
67
76
|
/** context */
|
|
68
77
|
const tableContextValue = useMemo(() => {
|
|
69
78
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
@@ -98,6 +107,10 @@ const Table = forwardRef(function Table(props, ref) {
|
|
|
98
107
|
},
|
|
99
108
|
} : undefined,
|
|
100
109
|
scroll: scrollProp,
|
|
110
|
+
draggable: draggableProp ? {
|
|
111
|
+
...draggableProp,
|
|
112
|
+
draggingId,
|
|
113
|
+
} : undefined,
|
|
101
114
|
});
|
|
102
115
|
}, [
|
|
103
116
|
dataSource,
|
|
@@ -116,6 +129,8 @@ const Table = forwardRef(function Table(props, ref) {
|
|
|
116
129
|
paginationProp,
|
|
117
130
|
isHorizontalScrolling,
|
|
118
131
|
scrollProp,
|
|
132
|
+
draggableProp,
|
|
133
|
+
draggingId,
|
|
119
134
|
]);
|
|
120
135
|
const tableDataContextValue = useMemo(() => ({
|
|
121
136
|
columns,
|
|
@@ -128,26 +143,26 @@ const Table = forwardRef(function Table(props, ref) {
|
|
|
128
143
|
});
|
|
129
144
|
}, [(_a = components === null || components === void 0 ? void 0 : components.body) === null || _a === void 0 ? void 0 : _a.cell]);
|
|
130
145
|
const tableRefs = useComposeRefs([ref, scrollBody.target]);
|
|
131
|
-
return (jsx(TableContext.Provider, { value: tableContextValue, children: jsx(TableDataContext.Provider, { value: tableDataContextValue, children: jsx(TableComponentContext.Provider, { value: tableComponentContextValue, children:
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
146
|
+
return (jsx(TableContext.Provider, { value: tableContextValue, children: jsx(TableDataContext.Provider, { value: tableDataContextValue, children: jsx(TableComponentContext.Provider, { value: tableComponentContextValue, children: jsx(DragDropContext, { onBeforeDragStart: onBeforeDragStart, onDragEnd: onDragEnd, children: jsx(Loading, { loading: loading, stretch: true, tip: loadingTip, overlayProps: {
|
|
147
|
+
className: tableClasses.loading,
|
|
148
|
+
}, children: jsx(Droppable, { droppableId: "mzn-table-dnd", isDropDisabled: !(draggableProp === null || draggableProp === void 0 ? void 0 : draggableProp.enabled), children: (provided) => (jsxs(Fragment, { children: [jsx("div", { ...provided.droppableProps, ref: composeRefs([scrollBody.ref, provided.innerRef]), className: cx(tableClasses.scrollContainer, scrollContainerClassName), onScroll: scrollBody.onScroll, style: tableContextValue.scroll ? {
|
|
149
|
+
'--table-scroll-x': tableContextValue.scroll.x
|
|
150
|
+
? `${tableContextValue.scroll.x}px`
|
|
151
|
+
: '100%',
|
|
152
|
+
'--table-scroll-y': tableContextValue.scroll.y
|
|
153
|
+
? `${tableContextValue.scroll.y}px`
|
|
154
|
+
: 'unset',
|
|
155
|
+
} : undefined, children: jsxs("table", { ref: tableRefs, ...rest, className: cx(tableClasses.host, className), children: [isRefreshShow ? (jsx("tbody", { children: jsx("tr", { children: jsx("td", { children: jsx(TableRefresh, { onClick: refreshProp.onClick }) }) }) })) : null, jsx(TableHeader, { className: headerClassName }), jsx(TableBody, { ref: bodyRef, className: bodyClassName, rowClassName: bodyRowClassName }), jsx("tbody", { children: provided.placeholder })] }) }), paginationProp ? (jsx(TablePagination, { bodyRef: bodyRef })) : null, jsx("div", { ref: scrollElement.trackRef, style: scrollElement.trackStyle, onMouseDown: scrollElement.onMouseDown, onMouseUp: scrollElement.onMouseUp, role: "button", tabIndex: -1, className: "mzn-table-scroll-bar-track", children: jsx("div", { style: {
|
|
156
|
+
width: '100%',
|
|
157
|
+
height: '100%',
|
|
158
|
+
position: 'relative',
|
|
159
|
+
}, children: jsx("div", { ref: scrollElement.ref, onMouseDown: scrollElement.onMouseDown, onMouseUp: scrollElement.onMouseUp, onMouseEnter: scrollElement.onMouseEnter, onMouseLeave: scrollElement.onMouseLeave, role: "button", style: scrollElement.style, tabIndex: -1, className: "mzn-table-scroll-bar", children: jsx("div", { style: {
|
|
160
|
+
width: `${scrollElement.scrollBarSize}px`,
|
|
161
|
+
height: '100%',
|
|
162
|
+
borderRadius: '10px',
|
|
163
|
+
backgroundColor: '#7d7d7d',
|
|
164
|
+
transition: '0.1s',
|
|
165
|
+
} }) }) }) })] })) }) }) }) }) }) }));
|
|
151
166
|
});
|
|
152
167
|
var Table$1 = Table;
|
|
153
168
|
|
package/Table/TableBodyRow.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { forwardRef, useContext, useState, useMemo, Fragment } from 'react';
|
|
3
3
|
import { tableClasses, getColumnStyle, getCellStyle } from '@mezzanine-ui/core/table';
|
|
4
|
+
import { Draggable } from 'react-beautiful-dnd';
|
|
4
5
|
import get from 'lodash/get';
|
|
5
6
|
import { TableContext, TableDataContext } from './TableContext.js';
|
|
6
7
|
import TableCell from './TableCell.js';
|
|
@@ -9,11 +10,12 @@ import TableRowSelection from './rowSelection/TableRowSelection.js';
|
|
|
9
10
|
import TableExpandable from './expandable/TableExpandable.js';
|
|
10
11
|
import TableEditRenderWrapper from './editable/TableEditRenderWrapper.js';
|
|
11
12
|
import AccordionDetails from '../Accordion/AccordionDetails.js';
|
|
13
|
+
import { composeRefs } from '../utils/composeRefs.js';
|
|
12
14
|
import cx from 'clsx';
|
|
13
15
|
|
|
14
16
|
const TableBodyRow = forwardRef(function TableBodyRow(props, ref) {
|
|
15
17
|
const { className, rowData, rowIndex, ...rest } = props;
|
|
16
|
-
const { rowSelection, expanding, isHorizontalScrolling, scroll, } = useContext(TableContext) || {};
|
|
18
|
+
const { rowSelection, expanding, isHorizontalScrolling, scroll, draggable, } = useContext(TableContext) || {};
|
|
17
19
|
const { columns, } = useContext(TableDataContext) || {};
|
|
18
20
|
/** Feature rowSelection */
|
|
19
21
|
const [selected, setSelected] = useState(false);
|
|
@@ -39,20 +41,22 @@ const TableBodyRow = forwardRef(function TableBodyRow(props, ref) {
|
|
|
39
41
|
expanding,
|
|
40
42
|
scroll === null || scroll === void 0 ? void 0 : scroll.fixedFirstColumn,
|
|
41
43
|
]);
|
|
42
|
-
return (jsxs(Fragment, { children: [jsxs("tr", { ...rest, ref: ref, className: cx(tableClasses.bodyRow, {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
44
|
+
return (jsxs(Fragment, { children: [jsx(Draggable, { index: rowIndex, draggableId: rowData.key || rowData.id, isDragDisabled: !(draggable === null || draggable === void 0 ? void 0 : draggable.enabled), children: (draggableProvided) => (jsxs("tr", { ...rest, ...draggableProvided.draggableProps, ...draggableProvided.dragHandleProps, ref: composeRefs([ref, draggableProvided.innerRef]), className: cx(tableClasses.bodyRow, {
|
|
45
|
+
[tableClasses.bodyRowHighlight]: selected || expanded,
|
|
46
|
+
[tableClasses.bodyRowDragging]: (draggable === null || draggable === void 0 ? void 0 : draggable.draggingId)
|
|
47
|
+
&& draggable.draggingId === (rowData.key || rowData.id),
|
|
48
|
+
}, className), children: [rowSelection ? (jsx("td", { className: tableClasses.bodyRowCellWrapper, style: {
|
|
49
|
+
flex: 'unset',
|
|
50
|
+
minWidth: 'unset',
|
|
51
|
+
}, children: jsx(TableRowSelection, { rowKey: (rowData.key || rowData.id), setChecked: (status) => setSelected(status), showDropdownIcon: false }) })) : null, expanding ? (jsx("td", { className: tableClasses.bodyRowCellWrapper, style: {
|
|
52
|
+
flex: 'unset',
|
|
53
|
+
minWidth: 'unset',
|
|
54
|
+
}, children: jsx(TableExpandable, { expandable: isExpandable, expanded: expanded, setExpanded: setExpanded, onExpand: (status) => { var _a; return (_a = expanding.onExpand) === null || _a === void 0 ? void 0 : _a.call(expanding, rowData, status); } }) })) : null, (columns !== null && columns !== void 0 ? columns : []).map((column, idx) => {
|
|
55
|
+
var _a, _b, _c, _d;
|
|
56
|
+
const ellipsis = !!(get(rowData, column.dataIndex)) && ((_a = column.ellipsis) !== null && _a !== void 0 ? _a : true);
|
|
57
|
+
const tooltipTitle = ((_c = (_b = column.renderTooltipTitle) === null || _b === void 0 ? void 0 : _b.call(column, rowData)) !== null && _c !== void 0 ? _c : get(rowData, column.dataIndex));
|
|
58
|
+
return (jsx("td", { className: cx(tableClasses.bodyRowCellWrapper, isFirstColumnShouldSticky && idx === 0 && tableClasses.bodyRowCellWrapperFixed, isFirstColumnShouldSticky && idx === 0 && isHorizontalScrolling && tableClasses.bodyRowCellWrapperFixedStuck, column.bodyClassName), style: getColumnStyle(column), children: jsx(TableEditRenderWrapper, { ...column, rowData: rowData, children: jsx(TableCell, { ellipsis: ellipsis, forceShownTooltipWhenHovered: column.forceShownTooltipWhenHovered, style: getCellStyle(column), tooltipTitle: tooltipTitle, children: ((_d = column.render) === null || _d === void 0 ? void 0 : _d.call(column, rowData, rowIndex, column)) || get(rowData, column.dataIndex) }) }) }, `${column.dataIndex}-${column.title}`));
|
|
59
|
+
})] })) }, rowData.key || rowData.id), renderedExpandedContent ? (jsx("tr", { children: jsx("td", { style: { padding: 0 }, children: jsx(AccordionDetails, { className: cx(expanding.className, tableClasses.bodyRowExpandedTableWrapper), expanded: expanded, children: (renderedExpandedContent === null || renderedExpandedContent === void 0 ? void 0 : renderedExpandedContent.dataSource) ? (jsx(TableExpandedTable, { renderedExpandedContent: renderedExpandedContent })) : renderedExpandedContent }) }) })) : null] }));
|
|
56
60
|
});
|
|
57
61
|
var TableBodyRow$1 = TableBodyRow;
|
|
58
62
|
|
package/Table/TableContext.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { TableRowSelection, TableColumn, TableExpandable, TablePagination, TableDataSource, TableRecord, ExpandRowBySources, TableScrolling } from '@mezzanine-ui/core/table';
|
|
2
|
+
import { TableRowSelection, TableColumn, TableExpandable, TablePagination, TableDataSource, TableRecord, ExpandRowBySources, TableScrolling, TableDraggable } from '@mezzanine-ui/core/table';
|
|
3
3
|
import { EmptyProps } from '../Empty';
|
|
4
4
|
/** typeof rowSelection */
|
|
5
5
|
export interface RowSelectionContext extends Pick<TableRowSelection, 'actions'> {
|
|
@@ -36,6 +36,9 @@ export interface TableContextProps {
|
|
|
36
36
|
fetchMore?: FetchMoreContext;
|
|
37
37
|
pagination?: TablePagination;
|
|
38
38
|
scroll?: TableScrolling;
|
|
39
|
+
draggable?: TableDraggable & {
|
|
40
|
+
draggingId: string;
|
|
41
|
+
};
|
|
39
42
|
}
|
|
40
43
|
export declare const TableContext: import("react").Context<TableContextProps | null>;
|
|
41
44
|
export interface TableDataContextProps {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import { TableDataSource, TableDraggable } from '@mezzanine-ui/core/table';
|
|
3
|
+
export interface UseTableDraggable {
|
|
4
|
+
dataSource: TableDataSource[];
|
|
5
|
+
setDataSource: Dispatch<SetStateAction<TableDataSource[]>>;
|
|
6
|
+
draggable?: TableDraggable;
|
|
7
|
+
}
|
|
8
|
+
export declare function useTableDraggable(props: UseTableDraggable): {
|
|
9
|
+
draggingId: string;
|
|
10
|
+
onBeforeDragStart: (e: {
|
|
11
|
+
draggableId: SetStateAction<string>;
|
|
12
|
+
}) => void;
|
|
13
|
+
onDragEnd: import("react-beautiful-dnd").OnDragEndResponder;
|
|
14
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useRef, useState, useEffect, useCallback } from 'react';
|
|
2
|
+
import isEqual from 'lodash/isEqual';
|
|
3
|
+
import debounce from 'lodash/debounce';
|
|
4
|
+
import { arrayMove } from '../../utils/array-move.js';
|
|
5
|
+
import { usePreviousValue } from '../../hooks/usePreviousValue.js';
|
|
6
|
+
|
|
7
|
+
function useTableDraggable(props) {
|
|
8
|
+
const { dataSource, setDataSource, draggable } = props;
|
|
9
|
+
const resultSnapshot = useRef(null);
|
|
10
|
+
const dataSnapShot = useRef(dataSource);
|
|
11
|
+
const isDragging = useRef(false);
|
|
12
|
+
const [draggingId, setDraggingId] = useState('');
|
|
13
|
+
const prevDataSource = usePreviousValue(dataSource);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!isEqual(prevDataSource, dataSource)) {
|
|
16
|
+
dataSnapShot.current = dataSource;
|
|
17
|
+
}
|
|
18
|
+
}, [prevDataSource, dataSource]);
|
|
19
|
+
const onBeforeDragStart = useCallback((e) => {
|
|
20
|
+
isDragging.current = true;
|
|
21
|
+
setDraggingId(e.draggableId);
|
|
22
|
+
}, []);
|
|
23
|
+
const onDragEnd = useCallback(async (result, id) => {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
resultSnapshot.current = [result, id];
|
|
26
|
+
isDragging.current = false;
|
|
27
|
+
setDraggingId('');
|
|
28
|
+
const temp = [...dataSnapShot.current];
|
|
29
|
+
const from = result.source.index;
|
|
30
|
+
const to = (_b = (_a = result.destination) === null || _a === void 0 ? void 0 : _a.index) !== null && _b !== void 0 ? _b : from;
|
|
31
|
+
const newData = arrayMove(temp, from, to);
|
|
32
|
+
dataSnapShot.current = newData;
|
|
33
|
+
setDataSource(newData);
|
|
34
|
+
}, [setDataSource]);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (!(draggable === null || draggable === void 0 ? void 0 : draggable.enabled))
|
|
37
|
+
return () => { };
|
|
38
|
+
async function onMouseUp() {
|
|
39
|
+
var _a, _b, _c;
|
|
40
|
+
if (isDragging.current)
|
|
41
|
+
return;
|
|
42
|
+
const args = resultSnapshot.current;
|
|
43
|
+
resultSnapshot.current = null;
|
|
44
|
+
if (!(args === null || args === void 0 ? void 0 : args[0]) || ((_a = args === null || args === void 0 ? void 0 : args[0]) === null || _a === void 0 ? void 0 : _a.source.index) === ((_c = (_b = args === null || args === void 0 ? void 0 : args[0]) === null || _b === void 0 ? void 0 : _b.destination) === null || _c === void 0 ? void 0 : _c.index))
|
|
45
|
+
return;
|
|
46
|
+
if ((draggable === null || draggable === void 0 ? void 0 : draggable.onDragEnd) && args) {
|
|
47
|
+
draggable.onDragEnd(Array.from(dataSnapShot.current));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const debouncedOnMouseUp = debounce(onMouseUp, 500);
|
|
51
|
+
window.addEventListener('mouseup', debouncedOnMouseUp, false);
|
|
52
|
+
return () => {
|
|
53
|
+
window.removeEventListener('mouseup', debouncedOnMouseUp, false);
|
|
54
|
+
};
|
|
55
|
+
}, [draggable]);
|
|
56
|
+
return {
|
|
57
|
+
draggingId,
|
|
58
|
+
onBeforeDragStart,
|
|
59
|
+
onDragEnd,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { useTableDraggable };
|
package/Table/index.d.ts
CHANGED
|
@@ -2,3 +2,5 @@ export { TableProps, default, } from './Table';
|
|
|
2
2
|
export { TableRefreshProps, default as TableRefresh, } from './refresh/TableRefresh';
|
|
3
3
|
export { TableCellProps, default as TableCell, } from './TableCell';
|
|
4
4
|
export { EditableBodyCellProps, } from './editable/TableEditRenderWrapper';
|
|
5
|
+
export { useTableDraggable, } from './draggable/useTableDraggable';
|
|
6
|
+
export { default as useTableScroll, } from './useTableScroll';
|
package/Table/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { default } from './Table.js';
|
|
2
2
|
export { default as TableRefresh } from './refresh/TableRefresh.js';
|
|
3
3
|
export { default as TableCell } from './TableCell.js';
|
|
4
|
+
export { useTableDraggable } from './draggable/useTableDraggable.js';
|
|
5
|
+
export { default as useTableScroll } from './useTableScroll.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { TableDataSource, TableColumn, TableRecord } from '@mezzanine-ui/core/table';
|
|
2
3
|
export interface UseTableSorting {
|
|
3
4
|
dataSource: TableDataSource[];
|
|
@@ -7,4 +8,5 @@ export declare function useTableSorting(props: UseTableSorting): readonly [Table
|
|
|
7
8
|
readonly sortedOn: string;
|
|
8
9
|
readonly sortedType: SortedType;
|
|
9
10
|
readonly onResetAll: () => void;
|
|
11
|
+
readonly setDataSource: import("react").Dispatch<import("react").SetStateAction<TableDataSource[]>>;
|
|
10
12
|
}];
|
|
@@ -107,7 +107,7 @@ function useTableSorting(props) {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
});
|
|
110
|
-
return [dataSource, onChange, { sortedOn, sortedType, onResetAll }];
|
|
110
|
+
return [dataSource, onChange, { sortedOn, sortedType, onResetAll, setDataSource }];
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
export { useTableSorting };
|
package/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './utils/getElement';
|
|
|
4
4
|
export * from './utils/jsx-types';
|
|
5
5
|
export * from './utils/general';
|
|
6
6
|
export * from './utils/scroll-lock';
|
|
7
|
+
export * from './utils/array-move';
|
|
7
8
|
export * from './hooks/useClickAway';
|
|
8
9
|
export * from './hooks/useComposeRefs';
|
|
9
10
|
export * from './hooks/useDocumentEscapeKeyDown';
|
|
@@ -51,7 +52,7 @@ export { AccordionProps, AccordionSummaryProps, AccordionSummary, AccordionDetai
|
|
|
51
52
|
export { BadgeContainerProps, BadgeContainer, BadgeProps, default as Badge, } from './Badge';
|
|
52
53
|
export { CardProps, CardActionsProps, CardActions, default as Card, } from './Card';
|
|
53
54
|
export { EmptyProps, default as Empty, } from './Empty';
|
|
54
|
-
export { TableProps, TableRefreshProps, TableRefresh, default as Table, } from './Table';
|
|
55
|
+
export { TableProps, TableRefreshProps, TableRefresh, useTableDraggable, useTableScroll, default as Table, } from './Table';
|
|
55
56
|
export { TagSize, TagProps, default as Tag, } from './Tag';
|
|
56
57
|
export { usePagination, PaginationItemProps, PaginationItemType, PaginationItem, PaginationJumperProps, PaginationJumper, PaginationPageSizeProps, PaginationPageSize, PaginationProps, default as Pagination, } from './Pagination';
|
|
57
58
|
export { TreeNodeProp, TreeNodeData, TreeNodeEntity, TreeNodeEntities, TreeNodeRefsShape, TreeNodeRefs, TreeExpandControl, uniqueArray, toggleValue, toggleValueWithStatusControl, traverseTree, UseTreeExpandedValueProps, useTreeExpandedValue, GetTreeNodeEntitiesProps, getTreeNodeEntities, TreeNodeElementProps, TreeNodeProps, TreeNode, TreeNodeListElementProps, TreeNodeListProps, TreeNodeList, TreeProps, default as Tree, } from './Tree';
|
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { composeRefs } from './utils/composeRefs.js';
|
|
2
2
|
export { getElement } from './utils/getElement.js';
|
|
3
3
|
export { allowBodyScroll, lockBodyScroll } from './utils/scroll-lock.js';
|
|
4
|
+
export { arrayMove } from './utils/array-move.js';
|
|
4
5
|
export { useClickAway } from './hooks/useClickAway.js';
|
|
5
6
|
export { useComposeRefs } from './hooks/useComposeRefs.js';
|
|
6
7
|
export { useDocumentEscapeKeyDown } from './hooks/useDocumentEscapeKeyDown.js';
|
|
@@ -23,6 +24,7 @@ export { useSelectValueControl } from './Form/useSelectValueControl.js';
|
|
|
23
24
|
export { useSwitchControlValue } from './Form/useSwitchControlValue.js';
|
|
24
25
|
export { IconButton } from './Button/index.js';
|
|
25
26
|
export { default as Typography } from './Typography/Typography.js';
|
|
27
|
+
export { default as useTableScroll } from './Table/useTableScroll.js';
|
|
26
28
|
export { default as useModalContainer } from './Modal/useModalContainer.js';
|
|
27
29
|
export { default as Transition } from './Transition/Transition.js';
|
|
28
30
|
export { default as ConfigProvider } from './Provider/ConfigProvider.js';
|
|
@@ -57,6 +59,7 @@ export { default as CardActions } from './Card/CardActions.js';
|
|
|
57
59
|
export { default as Card } from './Card/Card.js';
|
|
58
60
|
export { default as Empty } from './Empty/Empty.js';
|
|
59
61
|
export { default as TableRefresh } from './Table/refresh/TableRefresh.js';
|
|
62
|
+
export { useTableDraggable } from './Table/draggable/useTableDraggable.js';
|
|
60
63
|
export { default as Table } from './Table/Table.js';
|
|
61
64
|
export { default as Tag } from './Tag/Tag.js';
|
|
62
65
|
export { usePagination } from './Pagination/usePagination.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mezzanine-ui/react",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"description": "React components for mezzanine-ui",
|
|
5
5
|
"author": "Mezzanine",
|
|
6
6
|
"repository": {
|
|
@@ -31,13 +31,14 @@
|
|
|
31
31
|
"react-dom": "^18.2.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@mezzanine-ui/core": "^0.13.
|
|
35
|
-
"@mezzanine-ui/icons": "^0.13.
|
|
36
|
-
"@mezzanine-ui/system": "^0.13.
|
|
34
|
+
"@mezzanine-ui/core": "^0.13.1",
|
|
35
|
+
"@mezzanine-ui/icons": "^0.13.1",
|
|
36
|
+
"@mezzanine-ui/system": "^0.13.1",
|
|
37
37
|
"@popperjs/core": "^2.11.6",
|
|
38
38
|
"@types/react-transition-group": "^4.4.5",
|
|
39
39
|
"clsx": "^1.2.1",
|
|
40
40
|
"lodash": "^4.17.21",
|
|
41
|
+
"react-beautiful-dnd": "^13.1.1",
|
|
41
42
|
"react-popper": "^2.3.0",
|
|
42
43
|
"react-transition-group": "^4.4.5",
|
|
43
44
|
"tslib": "^2.4.1"
|
|
@@ -49,6 +50,7 @@
|
|
|
49
50
|
"@types/lodash": "^4.14.188",
|
|
50
51
|
"@types/moment": "^2.13.0",
|
|
51
52
|
"@types/react": "^18.0.25",
|
|
53
|
+
"@types/react-beautiful-dnd": "^13.1.4",
|
|
52
54
|
"@types/react-dom": "^18.0.8",
|
|
53
55
|
"@types/react-test-renderer": "^18.0.0",
|
|
54
56
|
"chromatic": "^6.11.4",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function arrayMove(arr: any[], old_index: number, new_index: number): any[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function arrayMove(arr, old_index, new_index) {
|
|
2
|
+
const temp = arr.slice(0);
|
|
3
|
+
if (new_index >= temp.length) {
|
|
4
|
+
let k = new_index - temp.length + 1;
|
|
5
|
+
while ((k -= 1)) {
|
|
6
|
+
temp.push();
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
temp.splice(new_index, 0, temp.splice(old_index, 1)[0]);
|
|
10
|
+
return temp;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { arrayMove };
|