@cloud-ru/ds-table 1.0.2-preview-ad4a761f.0 → 1.0.2
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/CHANGELOG.md +4 -0
- package/README.md +3 -3
- package/dist/cjs/components/Table/Table.js +4 -12
- package/dist/cjs/components/Table/hooks/useColumnOrderByDrag/useColumnOrderByDrag.d.ts +0 -2
- package/dist/cjs/components/Table/hooks/useColumnOrderByDrag/useColumnOrderByDrag.js +3 -20
- package/dist/cjs/components/Table/hooks/useColumnSettings/utils/createColumnsSettingsOption.d.ts +2 -2
- package/dist/cjs/components/Table/hooks/useColumnSettings/utils/createColumnsSettingsOption.js +2 -2
- package/dist/cjs/components/Table/hooks/useColumnSettings/utils/index.d.ts +0 -1
- package/dist/cjs/components/Table/hooks/useColumnSettings/utils/index.js +0 -1
- package/dist/cjs/components/Table/hooks/useColumnSettings/utils/isColumnEnabledInitially.js +4 -3
- package/dist/cjs/components/Table/hooks/useColumnSettings/utils/isColumnVisibilityConfigurable.js +15 -3
- package/dist/cjs/components/Table/hooks/useColumnSettings/utils/isFilterableColumn.js +2 -4
- package/dist/cjs/components/Table/hooks/useTableScroll.js +1 -15
- package/dist/cjs/components/Table/styles.module.css +1 -19
- package/dist/cjs/components/Table/utils/index.d.ts +0 -1
- package/dist/cjs/components/Table/utils/index.js +0 -1
- package/dist/cjs/constants.d.ts +1 -1
- package/dist/cjs/constants.js +1 -1
- package/dist/cjs/helperComponents/Cells/BodyCell/BodyCell.d.ts +1 -3
- package/dist/cjs/helperComponents/Cells/BodyCell/BodyCell.js +10 -9
- package/dist/cjs/helperComponents/Cells/HeaderCell/HeaderCell.js +6 -7
- package/dist/cjs/helperComponents/Cells/HeaderCell/ResizeHandle.js +1 -1
- package/dist/cjs/helperComponents/Cells/styles.module.css +0 -3
- package/dist/cjs/helperComponents/Rows/BodyRow.js +2 -1
- package/dist/cjs/helperComponents/Rows/styles.module.css +0 -4
- package/dist/cjs/helperComponents/TableEmptyState/hooks.js +1 -0
- package/dist/cjs/helperComponents/TableEmptyState/styles.module.css +1 -3
- package/dist/cjs/hooks/index.d.ts +0 -1
- package/dist/cjs/hooks/index.js +0 -1
- package/dist/cjs/hooks/useCellSizes.d.ts +1 -0
- package/dist/cjs/hooks/useCellSizes.js +4 -1
- package/dist/cjs/locale/index.d.ts +4 -0
- package/dist/cjs/locale/index.js +2 -0
- package/dist/cjs/style.css +2 -29
- package/dist/cjs/types.d.ts +0 -1
- package/dist/esm/components/Table/Table.js +7 -15
- package/dist/esm/components/Table/hooks/useColumnOrderByDrag/useColumnOrderByDrag.d.ts +0 -2
- package/dist/esm/components/Table/hooks/useColumnOrderByDrag/useColumnOrderByDrag.js +4 -21
- package/dist/esm/components/Table/hooks/useColumnSettings/utils/createColumnsSettingsOption.d.ts +2 -2
- package/dist/esm/components/Table/hooks/useColumnSettings/utils/createColumnsSettingsOption.js +2 -2
- package/dist/esm/components/Table/hooks/useColumnSettings/utils/index.d.ts +0 -1
- package/dist/esm/components/Table/hooks/useColumnSettings/utils/index.js +0 -1
- package/dist/esm/components/Table/hooks/useColumnSettings/utils/isColumnEnabledInitially.js +4 -3
- package/dist/esm/components/Table/hooks/useColumnSettings/utils/isColumnVisibilityConfigurable.js +15 -3
- package/dist/esm/components/Table/hooks/useColumnSettings/utils/isFilterableColumn.js +2 -4
- package/dist/esm/components/Table/hooks/useTableScroll.js +1 -15
- package/dist/esm/components/Table/styles.module.css +1 -19
- package/dist/esm/components/Table/utils/index.d.ts +0 -1
- package/dist/esm/components/Table/utils/index.js +0 -1
- package/dist/esm/constants.d.ts +1 -1
- package/dist/esm/constants.js +1 -1
- package/dist/esm/helperComponents/Cells/BodyCell/BodyCell.d.ts +1 -3
- package/dist/esm/helperComponents/Cells/BodyCell/BodyCell.js +11 -10
- package/dist/esm/helperComponents/Cells/HeaderCell/HeaderCell.js +6 -7
- package/dist/esm/helperComponents/Cells/HeaderCell/ResizeHandle.js +1 -1
- package/dist/esm/helperComponents/Cells/styles.module.css +0 -3
- package/dist/esm/helperComponents/Rows/BodyRow.js +2 -1
- package/dist/esm/helperComponents/Rows/styles.module.css +0 -4
- package/dist/esm/helperComponents/TableEmptyState/hooks.js +1 -0
- package/dist/esm/helperComponents/TableEmptyState/styles.module.css +1 -3
- package/dist/esm/hooks/index.d.ts +0 -1
- package/dist/esm/hooks/index.js +0 -1
- package/dist/esm/hooks/useCellSizes.d.ts +1 -0
- package/dist/esm/hooks/useCellSizes.js +4 -1
- package/dist/esm/locale/index.d.ts +4 -0
- package/dist/esm/locale/index.js +2 -0
- package/dist/esm/style.css +2 -29
- package/dist/esm/types.d.ts +0 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +20 -21
- package/src/components/Table/Table.tsx +26 -53
- package/src/components/Table/hooks/useColumnOrderByDrag/useColumnOrderByDrag.ts +7 -31
- package/src/components/Table/hooks/useColumnSettings/utils/createColumnsSettingsOption.ts +2 -2
- package/src/components/Table/hooks/useColumnSettings/utils/index.ts +0 -1
- package/src/components/Table/hooks/useColumnSettings/utils/isColumnEnabledInitially.ts +5 -3
- package/src/components/Table/hooks/useColumnSettings/utils/isColumnVisibilityConfigurable.ts +18 -3
- package/src/components/Table/hooks/useColumnSettings/utils/isFilterableColumn.ts +2 -4
- package/src/components/Table/hooks/useTableScroll.ts +1 -21
- package/src/components/Table/styles.module.scss +1 -23
- package/src/components/Table/utils/index.ts +0 -1
- package/src/constants.ts +1 -1
- package/src/helperComponents/Cells/BodyCell/BodyCell.tsx +15 -18
- package/src/helperComponents/Cells/HeaderCell/HeaderCell.tsx +7 -10
- package/src/helperComponents/Cells/HeaderCell/ResizeHandle.tsx +2 -1
- package/src/helperComponents/Cells/styles.module.scss +0 -11
- package/src/helperComponents/Rows/BodyRow.tsx +10 -9
- package/src/helperComponents/Rows/styles.module.scss +0 -5
- package/src/helperComponents/TableEmptyState/hooks.ts +1 -0
- package/src/helperComponents/TableEmptyState/styles.module.scss +1 -5
- package/src/hooks/index.ts +0 -1
- package/src/hooks/useCellSizes.ts +5 -1
- package/src/locale/index.ts +2 -0
- package/src/types.ts +5 -3
- package/dist/cjs/components/Table/hooks/useColumnSettings/utils/getColumnSettingsMode.d.ts +0 -8
- package/dist/cjs/components/Table/hooks/useColumnSettings/utils/getColumnSettingsMode.js +0 -15
- package/dist/cjs/components/Table/utils/alignOverlayToHeader.d.ts +0 -6
- package/dist/cjs/components/Table/utils/alignOverlayToHeader.js +0 -28
- package/dist/cjs/hooks/useColumnDragTransform.d.ts +0 -15
- package/dist/cjs/hooks/useColumnDragTransform.js +0 -38
- package/dist/esm/components/Table/hooks/useColumnSettings/utils/getColumnSettingsMode.d.ts +0 -8
- package/dist/esm/components/Table/hooks/useColumnSettings/utils/getColumnSettingsMode.js +0 -11
- package/dist/esm/components/Table/utils/alignOverlayToHeader.d.ts +0 -6
- package/dist/esm/components/Table/utils/alignOverlayToHeader.js +0 -24
- package/dist/esm/hooks/useColumnDragTransform.d.ts +0 -15
- package/dist/esm/hooks/useColumnDragTransform.js +0 -35
- package/src/components/Table/hooks/useColumnSettings/utils/getColumnSettingsMode.ts +0 -18
- package/src/components/Table/utils/alignOverlayToHeader.ts +0 -36
- package/src/hooks/useColumnDragTransform.ts +0 -52
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { horizontalListSortingStrategy, SortableContext } from '@dnd-kit/sortable';
|
|
1
2
|
import { Row as TableRow } from '@tanstack/react-table';
|
|
2
3
|
import { CSSProperties, MouseEvent, useState } from 'react';
|
|
3
4
|
|
|
@@ -85,15 +86,15 @@ export function BodyRow<TData>({
|
|
|
85
86
|
{columnVirtualPadding && columnVirtualPadding.left > 0 && (
|
|
86
87
|
<div aria-hidden style={{ width: columnVirtualPadding.left, flexShrink: 0 } as CSSProperties} />
|
|
87
88
|
)}
|
|
88
|
-
{
|
|
89
|
-
<
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
/>
|
|
96
|
-
)
|
|
89
|
+
{enableColumnsOrderSortByDrag ? (
|
|
90
|
+
<SortableContext items={columnOrder} strategy={horizontalListSortingStrategy}>
|
|
91
|
+
{unpinned.map(cell => (
|
|
92
|
+
<BodyCell key={cell.id} cell={cell} rowAutoHeight={rowAutoHeight} isDraggable />
|
|
93
|
+
))}
|
|
94
|
+
</SortableContext>
|
|
95
|
+
) : (
|
|
96
|
+
unpinned.map(cell => <BodyCell key={cell.id} cell={cell} rowAutoHeight={rowAutoHeight} />)
|
|
97
|
+
)}
|
|
97
98
|
{columnVirtualPadding && columnVirtualPadding.right > 0 && (
|
|
98
99
|
<div aria-hidden style={{ width: columnVirtualPadding.right, flexShrink: 0 } as CSSProperties} />
|
|
99
100
|
)}
|
|
@@ -116,11 +116,6 @@ $row-bg-tones: (
|
|
|
116
116
|
width: $pinned-border;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
// Под шапкой строк нет — продолжать разделитель нечем, обрезаем хвост.
|
|
120
|
-
.tableHeader .rowPinnedCells::after {
|
|
121
|
-
bottom: 0;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
119
|
.rowPinnedCells[data-position='left'] {
|
|
125
120
|
left: 0;
|
|
126
121
|
}
|
|
@@ -3,10 +3,6 @@
|
|
|
3
3
|
@use '@cloud-ru/ds-figma-variables/build/scss/components/table.module' as table;
|
|
4
4
|
|
|
5
5
|
.tableEmptyStateWrapper {
|
|
6
|
-
// Живёт внутри горизонтального скролла колонок: без sticky уезжает вместе с ними.
|
|
7
|
-
position: sticky;
|
|
8
|
-
left: 0;
|
|
9
|
-
|
|
10
6
|
display: flex;
|
|
11
7
|
flex: 1 1 auto;
|
|
12
8
|
flex-direction: column;
|
|
@@ -14,7 +10,7 @@
|
|
|
14
10
|
justify-content: center;
|
|
15
11
|
|
|
16
12
|
box-sizing: border-box;
|
|
17
|
-
width:
|
|
13
|
+
width: 100%;
|
|
18
14
|
min-height: base.simple-var(table.$table, 'anatomy', 'content', 'body', 'min-height'); // 304px
|
|
19
15
|
padding: base.$sn-primitive-dimension-24;
|
|
20
16
|
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { TABLE_COLUMN_CSS_VARS } from '../constants';
|
|
|
6
6
|
|
|
7
7
|
type CellSizesOptions = {
|
|
8
8
|
isDraggable?: boolean;
|
|
9
|
+
isDragging?: boolean;
|
|
9
10
|
transform?: Transform | null;
|
|
10
11
|
};
|
|
11
12
|
|
|
@@ -14,6 +15,7 @@ export function useCellSizes<TData>(
|
|
|
14
15
|
options?: CellSizesOptions,
|
|
15
16
|
): CSSProperties {
|
|
16
17
|
const column = element.column;
|
|
18
|
+
const isDragging = options?.isDragging ?? false;
|
|
17
19
|
const transform = options?.transform ?? null;
|
|
18
20
|
|
|
19
21
|
const minWidth = column.columnDef.minSize;
|
|
@@ -31,8 +33,10 @@ export function useCellSizes<TData>(
|
|
|
31
33
|
};
|
|
32
34
|
|
|
33
35
|
if (options?.isDraggable) {
|
|
36
|
+
styles.opacity = isDragging ? 0.8 : 1;
|
|
34
37
|
styles.position = 'relative';
|
|
35
38
|
styles.transform = CSS.Translate.toString(transform);
|
|
39
|
+
styles.zIndex = isDragging ? 1 : undefined;
|
|
36
40
|
|
|
37
41
|
if (isHeaderCell) {
|
|
38
42
|
styles.whiteSpace = 'nowrap';
|
|
@@ -40,5 +44,5 @@ export function useCellSizes<TData>(
|
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
return styles;
|
|
43
|
-
}, [options?.isDraggable, flexShrink, isHeaderCell, maxWidth, minWidth, transform, width]);
|
|
47
|
+
}, [options?.isDraggable, flexShrink, isDragging, isHeaderCell, maxWidth, minWidth, transform, width]);
|
|
44
48
|
}
|
package/src/locale/index.ts
CHANGED
|
@@ -15,6 +15,7 @@ const TABLE_MESSAGES = defineMessages({
|
|
|
15
15
|
},
|
|
16
16
|
noData: {
|
|
17
17
|
title: 'No data',
|
|
18
|
+
content: 'Try refreshing the page',
|
|
18
19
|
},
|
|
19
20
|
noResults: {
|
|
20
21
|
title: 'Nothing found',
|
|
@@ -39,6 +40,7 @@ const TABLE_MESSAGES = defineMessages({
|
|
|
39
40
|
},
|
|
40
41
|
noData: {
|
|
41
42
|
title: 'Нет данных',
|
|
43
|
+
content: 'Обновите страницу',
|
|
42
44
|
},
|
|
43
45
|
noResults: {
|
|
44
46
|
title: 'Ничего не найдено',
|
package/src/types.ts
CHANGED
|
@@ -69,7 +69,6 @@ type FilterableProps = {
|
|
|
69
69
|
columnSettings?: {
|
|
70
70
|
/** Название колонки в настройках таблицы */
|
|
71
71
|
label?: string;
|
|
72
|
-
/** Поведение колонки в меню настроек. По умолчанию `defaultVisible` */
|
|
73
72
|
mode?: ColumnSettingsMode;
|
|
74
73
|
};
|
|
75
74
|
} & ({ id: string } | { accessorKey: string });
|
|
@@ -78,10 +77,13 @@ type FilterableNormalColumnDefinition<TData> = NormalColumnDefinition<TData> & F
|
|
|
78
77
|
type FilterablePinnedColumnDefinition<TData> = PinnedColumnDefinition<TData> & FilterableProps;
|
|
79
78
|
|
|
80
79
|
export type FilterableColumnDefinition<TData> =
|
|
81
|
-
FilterableNormalColumnDefinition<TData>
|
|
80
|
+
| FilterableNormalColumnDefinition<TData>
|
|
81
|
+
| FilterablePinnedColumnDefinition<TData>;
|
|
82
82
|
|
|
83
83
|
export type ColumnDefinition<TData> =
|
|
84
|
-
|
|
84
|
+
| NormalColumnDefinition<TData>
|
|
85
|
+
| PinnedColumnDefinition<TData>
|
|
86
|
+
| FilterableColumnDefinition<TData>;
|
|
85
87
|
|
|
86
88
|
export type ColumnOrder = string[];
|
|
87
89
|
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { COLUMN_SETTINGS_MODE } from '../../../../../constants';
|
|
2
|
-
import { ColumnDefinition } from '../../../../../types';
|
|
3
|
-
type ColumnSettingsMode = (typeof COLUMN_SETTINGS_MODE)[keyof typeof COLUMN_SETTINGS_MODE];
|
|
4
|
-
/** Служебные колонки (`selection` / `rowActions` / `status`) видимостью не управляются. */
|
|
5
|
-
export declare function isServiceColumn<TData extends object>(colDef: ColumnDefinition<TData>): boolean;
|
|
6
|
-
/** Режим колонки в меню настроек; без `columnSettings.mode` — `defaultVisible`. */
|
|
7
|
-
export declare function getColumnSettingsMode<TData extends object>(colDef: ColumnDefinition<TData>): ColumnSettingsMode;
|
|
8
|
-
export {};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isServiceColumn = isServiceColumn;
|
|
4
|
-
exports.getColumnSettingsMode = getColumnSettingsMode;
|
|
5
|
-
const constants_1 = require("../../../../../constants");
|
|
6
|
-
/** Служебные колонки (`selection` / `rowActions` / `status`) видимостью не управляются. */
|
|
7
|
-
function isServiceColumn(colDef) {
|
|
8
|
-
const id = 'id' in colDef ? colDef.id : undefined;
|
|
9
|
-
return Boolean(id) && constants_1.DEFAULT_COLUMNS.includes(String(id));
|
|
10
|
-
}
|
|
11
|
-
/** Режим колонки в меню настроек; без `columnSettings.mode` — `defaultVisible`. */
|
|
12
|
-
function getColumnSettingsMode(colDef) {
|
|
13
|
-
const mode = 'columnSettings' in colDef ? colDef.columnSettings?.mode : undefined;
|
|
14
|
-
return mode ?? constants_1.COLUMN_SETTINGS_MODE.DefaultVisible;
|
|
15
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Modifier } from '@dnd-kit/core';
|
|
2
|
-
/**
|
|
3
|
-
* Копию тянет наверх к шапке: `useSortable` вызывают и ячейки тела с тем же id колонки,
|
|
4
|
-
* поэтому dnd-kit считает активным узлом последнюю из них и якорит оверлей по её строке.
|
|
5
|
-
*/
|
|
6
|
-
export declare const alignOverlayToHeader: Modifier;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.alignOverlayToHeader = void 0;
|
|
4
|
-
const utils_1 = require("@cloud-ru/ds-utils");
|
|
5
|
-
const constants_1 = require("../../../constants");
|
|
6
|
-
function getHeaderCellTop(columnId) {
|
|
7
|
-
if ((0, utils_1.isBrowser)()) {
|
|
8
|
-
const headerCell = document.querySelector(`[data-test-id="${constants_1.TEST_IDS.headerCell}"][data-header-id="${CSS.escape(columnId)}"]`);
|
|
9
|
-
return headerCell?.getBoundingClientRect().top;
|
|
10
|
-
}
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Копию тянет наверх к шапке: `useSortable` вызывают и ячейки тела с тем же id колонки,
|
|
15
|
-
* поэтому dnd-kit считает активным узлом последнюю из них и якорит оверлей по её строке.
|
|
16
|
-
*/
|
|
17
|
-
const alignOverlayToHeader = ({ transform, active, activeNodeRect }) => {
|
|
18
|
-
const columnId = active?.id;
|
|
19
|
-
if (!columnId || !activeNodeRect) {
|
|
20
|
-
return transform;
|
|
21
|
-
}
|
|
22
|
-
const headerTop = getHeaderCellTop(String(columnId));
|
|
23
|
-
if (headerTop === undefined) {
|
|
24
|
-
return transform;
|
|
25
|
-
}
|
|
26
|
-
return { ...transform, y: transform.y + headerTop - activeNodeRect.top };
|
|
27
|
-
};
|
|
28
|
-
exports.alignOverlayToHeader = alignOverlayToHeader;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Transform } from '@dnd-kit/utilities';
|
|
2
|
-
import { ColumnOrder } from '../types';
|
|
3
|
-
type ColumnDragState = {
|
|
4
|
-
transform: Transform | null;
|
|
5
|
-
isDragging: boolean;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Сдвиг ячейки тела за колонкой, которую тянут за шапку.
|
|
9
|
-
*
|
|
10
|
-
* Не `useSortable`: он зарегистрировал бы ячейку в реестре dnd-kit под id колонки — тем же, что у
|
|
11
|
-
* шапки. Реестр ключуется по id, поэтому размонтирование строк удаляло запись колонки целиком и
|
|
12
|
-
* драг переставал работать.
|
|
13
|
-
*/
|
|
14
|
-
export declare function useColumnDragTransform(columnId: string, columnOrder: ColumnOrder): ColumnDragState;
|
|
15
|
-
export {};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useColumnDragTransform = useColumnDragTransform;
|
|
4
|
-
const core_1 = require("@dnd-kit/core");
|
|
5
|
-
const sortable_1 = require("@dnd-kit/sortable");
|
|
6
|
-
const react_1 = require("react");
|
|
7
|
-
/**
|
|
8
|
-
* Сдвиг ячейки тела за колонкой, которую тянут за шапку.
|
|
9
|
-
*
|
|
10
|
-
* Не `useSortable`: он зарегистрировал бы ячейку в реестре dnd-kit под id колонки — тем же, что у
|
|
11
|
-
* шапки. Реестр ключуется по id, поэтому размонтирование строк удаляло запись колонки целиком и
|
|
12
|
-
* драг переставал работать.
|
|
13
|
-
*/
|
|
14
|
-
function useColumnDragTransform(columnId, columnOrder) {
|
|
15
|
-
const { active, over, activeNodeRect, droppableRects } = (0, core_1.useDndContext)();
|
|
16
|
-
const activeId = active ? String(active.id) : undefined;
|
|
17
|
-
const overId = over ? String(over.id) : undefined;
|
|
18
|
-
const transform = (0, react_1.useMemo)(() => {
|
|
19
|
-
if (!activeId) {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
const measured = columnOrder.filter(id => droppableRects.get(id));
|
|
23
|
-
const index = measured.indexOf(columnId);
|
|
24
|
-
const activeIndex = measured.indexOf(activeId);
|
|
25
|
-
if (index < 0 || activeIndex < 0) {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
const overIndex = overId ? measured.indexOf(overId) : -1;
|
|
29
|
-
return (0, sortable_1.horizontalListSortingStrategy)({
|
|
30
|
-
rects: measured.map(id => droppableRects.get(id)),
|
|
31
|
-
activeNodeRect,
|
|
32
|
-
activeIndex,
|
|
33
|
-
overIndex: overIndex < 0 ? activeIndex : overIndex,
|
|
34
|
-
index,
|
|
35
|
-
});
|
|
36
|
-
}, [activeId, overId, columnId, columnOrder, droppableRects, activeNodeRect]);
|
|
37
|
-
return { transform, isDragging: activeId === columnId };
|
|
38
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { COLUMN_SETTINGS_MODE } from '../../../../../constants.js';
|
|
2
|
-
import { ColumnDefinition } from '../../../../../types.js';
|
|
3
|
-
type ColumnSettingsMode = (typeof COLUMN_SETTINGS_MODE)[keyof typeof COLUMN_SETTINGS_MODE];
|
|
4
|
-
/** Служебные колонки (`selection` / `rowActions` / `status`) видимостью не управляются. */
|
|
5
|
-
export declare function isServiceColumn<TData extends object>(colDef: ColumnDefinition<TData>): boolean;
|
|
6
|
-
/** Режим колонки в меню настроек; без `columnSettings.mode` — `defaultVisible`. */
|
|
7
|
-
export declare function getColumnSettingsMode<TData extends object>(colDef: ColumnDefinition<TData>): ColumnSettingsMode;
|
|
8
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { COLUMN_SETTINGS_MODE, DEFAULT_COLUMNS } from '../../../../../constants.js';
|
|
2
|
-
/** Служебные колонки (`selection` / `rowActions` / `status`) видимостью не управляются. */
|
|
3
|
-
export function isServiceColumn(colDef) {
|
|
4
|
-
const id = 'id' in colDef ? colDef.id : undefined;
|
|
5
|
-
return Boolean(id) && DEFAULT_COLUMNS.includes(String(id));
|
|
6
|
-
}
|
|
7
|
-
/** Режим колонки в меню настроек; без `columnSettings.mode` — `defaultVisible`. */
|
|
8
|
-
export function getColumnSettingsMode(colDef) {
|
|
9
|
-
const mode = 'columnSettings' in colDef ? colDef.columnSettings?.mode : undefined;
|
|
10
|
-
return mode ?? COLUMN_SETTINGS_MODE.DefaultVisible;
|
|
11
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Modifier } from '@dnd-kit/core';
|
|
2
|
-
/**
|
|
3
|
-
* Копию тянет наверх к шапке: `useSortable` вызывают и ячейки тела с тем же id колонки,
|
|
4
|
-
* поэтому dnd-kit считает активным узлом последнюю из них и якорит оверлей по её строке.
|
|
5
|
-
*/
|
|
6
|
-
export declare const alignOverlayToHeader: Modifier;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { isBrowser } from '@cloud-ru/ds-utils';
|
|
2
|
-
import { TEST_IDS } from '../../../constants.js';
|
|
3
|
-
function getHeaderCellTop(columnId) {
|
|
4
|
-
if (isBrowser()) {
|
|
5
|
-
const headerCell = document.querySelector(`[data-test-id="${TEST_IDS.headerCell}"][data-header-id="${CSS.escape(columnId)}"]`);
|
|
6
|
-
return headerCell?.getBoundingClientRect().top;
|
|
7
|
-
}
|
|
8
|
-
return undefined;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Копию тянет наверх к шапке: `useSortable` вызывают и ячейки тела с тем же id колонки,
|
|
12
|
-
* поэтому dnd-kit считает активным узлом последнюю из них и якорит оверлей по её строке.
|
|
13
|
-
*/
|
|
14
|
-
export const alignOverlayToHeader = ({ transform, active, activeNodeRect }) => {
|
|
15
|
-
const columnId = active?.id;
|
|
16
|
-
if (!columnId || !activeNodeRect) {
|
|
17
|
-
return transform;
|
|
18
|
-
}
|
|
19
|
-
const headerTop = getHeaderCellTop(String(columnId));
|
|
20
|
-
if (headerTop === undefined) {
|
|
21
|
-
return transform;
|
|
22
|
-
}
|
|
23
|
-
return { ...transform, y: transform.y + headerTop - activeNodeRect.top };
|
|
24
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Transform } from '@dnd-kit/utilities';
|
|
2
|
-
import { ColumnOrder } from '../types.js';
|
|
3
|
-
type ColumnDragState = {
|
|
4
|
-
transform: Transform | null;
|
|
5
|
-
isDragging: boolean;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Сдвиг ячейки тела за колонкой, которую тянут за шапку.
|
|
9
|
-
*
|
|
10
|
-
* Не `useSortable`: он зарегистрировал бы ячейку в реестре dnd-kit под id колонки — тем же, что у
|
|
11
|
-
* шапки. Реестр ключуется по id, поэтому размонтирование строк удаляло запись колонки целиком и
|
|
12
|
-
* драг переставал работать.
|
|
13
|
-
*/
|
|
14
|
-
export declare function useColumnDragTransform(columnId: string, columnOrder: ColumnOrder): ColumnDragState;
|
|
15
|
-
export {};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { useDndContext } from '@dnd-kit/core';
|
|
2
|
-
import { horizontalListSortingStrategy } from '@dnd-kit/sortable';
|
|
3
|
-
import { useMemo } from 'react';
|
|
4
|
-
/**
|
|
5
|
-
* Сдвиг ячейки тела за колонкой, которую тянут за шапку.
|
|
6
|
-
*
|
|
7
|
-
* Не `useSortable`: он зарегистрировал бы ячейку в реестре dnd-kit под id колонки — тем же, что у
|
|
8
|
-
* шапки. Реестр ключуется по id, поэтому размонтирование строк удаляло запись колонки целиком и
|
|
9
|
-
* драг переставал работать.
|
|
10
|
-
*/
|
|
11
|
-
export function useColumnDragTransform(columnId, columnOrder) {
|
|
12
|
-
const { active, over, activeNodeRect, droppableRects } = useDndContext();
|
|
13
|
-
const activeId = active ? String(active.id) : undefined;
|
|
14
|
-
const overId = over ? String(over.id) : undefined;
|
|
15
|
-
const transform = useMemo(() => {
|
|
16
|
-
if (!activeId) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
const measured = columnOrder.filter(id => droppableRects.get(id));
|
|
20
|
-
const index = measured.indexOf(columnId);
|
|
21
|
-
const activeIndex = measured.indexOf(activeId);
|
|
22
|
-
if (index < 0 || activeIndex < 0) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
const overIndex = overId ? measured.indexOf(overId) : -1;
|
|
26
|
-
return horizontalListSortingStrategy({
|
|
27
|
-
rects: measured.map(id => droppableRects.get(id)),
|
|
28
|
-
activeNodeRect,
|
|
29
|
-
activeIndex,
|
|
30
|
-
overIndex: overIndex < 0 ? activeIndex : overIndex,
|
|
31
|
-
index,
|
|
32
|
-
});
|
|
33
|
-
}, [activeId, overId, columnId, columnOrder, droppableRects, activeNodeRect]);
|
|
34
|
-
return { transform, isDragging: activeId === columnId };
|
|
35
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { COLUMN_SETTINGS_MODE, DEFAULT_COLUMNS } from '../../../../../constants';
|
|
2
|
-
import { ColumnDefinition } from '../../../../../types';
|
|
3
|
-
|
|
4
|
-
type ColumnSettingsMode = (typeof COLUMN_SETTINGS_MODE)[keyof typeof COLUMN_SETTINGS_MODE];
|
|
5
|
-
|
|
6
|
-
/** Служебные колонки (`selection` / `rowActions` / `status`) видимостью не управляются. */
|
|
7
|
-
export function isServiceColumn<TData extends object>(colDef: ColumnDefinition<TData>): boolean {
|
|
8
|
-
const id = 'id' in colDef ? colDef.id : undefined;
|
|
9
|
-
|
|
10
|
-
return Boolean(id) && (DEFAULT_COLUMNS as string[]).includes(String(id));
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/** Режим колонки в меню настроек; без `columnSettings.mode` — `defaultVisible`. */
|
|
14
|
-
export function getColumnSettingsMode<TData extends object>(colDef: ColumnDefinition<TData>): ColumnSettingsMode {
|
|
15
|
-
const mode = 'columnSettings' in colDef ? colDef.columnSettings?.mode : undefined;
|
|
16
|
-
|
|
17
|
-
return mode ?? COLUMN_SETTINGS_MODE.DefaultVisible;
|
|
18
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Modifier } from '@dnd-kit/core';
|
|
2
|
-
import { isBrowser } from '@cloud-ru/ds-utils';
|
|
3
|
-
|
|
4
|
-
import { TEST_IDS } from '../../../constants';
|
|
5
|
-
|
|
6
|
-
function getHeaderCellTop(columnId: string): number | undefined {
|
|
7
|
-
if (isBrowser()) {
|
|
8
|
-
const headerCell = document.querySelector(
|
|
9
|
-
`[data-test-id="${TEST_IDS.headerCell}"][data-header-id="${CSS.escape(columnId)}"]`,
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
return headerCell?.getBoundingClientRect().top;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return undefined;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Копию тянет наверх к шапке: `useSortable` вызывают и ячейки тела с тем же id колонки,
|
|
20
|
-
* поэтому dnd-kit считает активным узлом последнюю из них и якорит оверлей по её строке.
|
|
21
|
-
*/
|
|
22
|
-
export const alignOverlayToHeader: Modifier = ({ transform, active, activeNodeRect }) => {
|
|
23
|
-
const columnId = active?.id;
|
|
24
|
-
|
|
25
|
-
if (!columnId || !activeNodeRect) {
|
|
26
|
-
return transform;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const headerTop = getHeaderCellTop(String(columnId));
|
|
30
|
-
|
|
31
|
-
if (headerTop === undefined) {
|
|
32
|
-
return transform;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return { ...transform, y: transform.y + headerTop - activeNodeRect.top };
|
|
36
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { ClientRect, useDndContext } from '@dnd-kit/core';
|
|
2
|
-
import { horizontalListSortingStrategy } from '@dnd-kit/sortable';
|
|
3
|
-
import { Transform } from '@dnd-kit/utilities';
|
|
4
|
-
import { useMemo } from 'react';
|
|
5
|
-
|
|
6
|
-
import { ColumnOrder } from '../types';
|
|
7
|
-
|
|
8
|
-
type ColumnDragState = {
|
|
9
|
-
transform: Transform | null;
|
|
10
|
-
isDragging: boolean;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Сдвиг ячейки тела за колонкой, которую тянут за шапку.
|
|
15
|
-
*
|
|
16
|
-
* Не `useSortable`: он зарегистрировал бы ячейку в реестре dnd-kit под id колонки — тем же, что у
|
|
17
|
-
* шапки. Реестр ключуется по id, поэтому размонтирование строк удаляло запись колонки целиком и
|
|
18
|
-
* драг переставал работать.
|
|
19
|
-
*/
|
|
20
|
-
export function useColumnDragTransform(columnId: string, columnOrder: ColumnOrder): ColumnDragState {
|
|
21
|
-
const { active, over, activeNodeRect, droppableRects } = useDndContext();
|
|
22
|
-
|
|
23
|
-
const activeId = active ? String(active.id) : undefined;
|
|
24
|
-
const overId = over ? String(over.id) : undefined;
|
|
25
|
-
|
|
26
|
-
const transform = useMemo(() => {
|
|
27
|
-
if (!activeId) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const measured = columnOrder.filter(id => droppableRects.get(id));
|
|
32
|
-
|
|
33
|
-
const index = measured.indexOf(columnId);
|
|
34
|
-
const activeIndex = measured.indexOf(activeId);
|
|
35
|
-
|
|
36
|
-
if (index < 0 || activeIndex < 0) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const overIndex = overId ? measured.indexOf(overId) : -1;
|
|
41
|
-
|
|
42
|
-
return horizontalListSortingStrategy({
|
|
43
|
-
rects: measured.map(id => droppableRects.get(id) as ClientRect),
|
|
44
|
-
activeNodeRect,
|
|
45
|
-
activeIndex,
|
|
46
|
-
overIndex: overIndex < 0 ? activeIndex : overIndex,
|
|
47
|
-
index,
|
|
48
|
-
});
|
|
49
|
-
}, [activeId, overId, columnId, columnOrder, droppableRects, activeNodeRect]);
|
|
50
|
-
|
|
51
|
-
return { transform, isDragging: activeId === columnId };
|
|
52
|
-
}
|