@cloud-ru/ds-table 1.0.2-preview-cd0cd6fb.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.js +4 -4
- 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/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/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.js +4 -4
- 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/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/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 +2 -5
- 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/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/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/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/src/components/Table/hooks/useColumnSettings/utils/getColumnSettingsMode.ts +0 -18
- package/src/components/Table/utils/alignOverlayToHeader.ts +0 -36
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloud-ru/ds-table",
|
|
3
|
-
"version": "1.0.2
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Таблица данных: клиентская Table, серверная ServerTable и preset-обёртки с упрощённым API.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -48,26 +48,25 @@
|
|
|
48
48
|
"@tanstack/react-table": "^8.21.3",
|
|
49
49
|
"@tanstack/react-virtual": "^3.14.8",
|
|
50
50
|
"classnames": "^2.5.1",
|
|
51
|
-
"@cloud-ru/ds-adaptive": "1.0.0",
|
|
52
|
-
"@cloud-ru/ds-button": "1.0.0",
|
|
53
|
-
"@cloud-ru/ds-card": "1.0.1
|
|
54
|
-
"@cloud-ru/ds-
|
|
55
|
-
"@cloud-ru/ds-
|
|
56
|
-
"@cloud-ru/ds-info-block": "1.0.0",
|
|
57
|
-
"@cloud-ru/ds-
|
|
58
|
-
"@cloud-ru/ds-
|
|
59
|
-
"@cloud-ru/ds-locale": "1.0.0",
|
|
60
|
-
"@cloud-ru/ds-
|
|
61
|
-
"@cloud-ru/ds-
|
|
62
|
-
"@cloud-ru/ds-
|
|
63
|
-
"@cloud-ru/ds-
|
|
64
|
-
"@cloud-ru/ds-
|
|
65
|
-
"@cloud-ru/ds-
|
|
66
|
-
"@cloud-ru/ds-
|
|
67
|
-
"@cloud-ru/ds-
|
|
68
|
-
"@cloud-ru/ds-
|
|
69
|
-
"@cloud-ru/ds-
|
|
70
|
-
"@cloud-ru/ds-utils": "1.0.0"
|
|
51
|
+
"@cloud-ru/ds-adaptive": "^1.0.0",
|
|
52
|
+
"@cloud-ru/ds-button": "^1.0.0",
|
|
53
|
+
"@cloud-ru/ds-card": "^1.0.1",
|
|
54
|
+
"@cloud-ru/ds-icons": "^1.0.0",
|
|
55
|
+
"@cloud-ru/ds-chips": "^1.0.1",
|
|
56
|
+
"@cloud-ru/ds-info-block": "^1.0.0",
|
|
57
|
+
"@cloud-ru/ds-list": "^1.1.0",
|
|
58
|
+
"@cloud-ru/ds-materials": "^1.0.0",
|
|
59
|
+
"@cloud-ru/ds-locale": "^1.0.0",
|
|
60
|
+
"@cloud-ru/ds-pagination": "^1.0.0",
|
|
61
|
+
"@cloud-ru/ds-skeleton": "^1.0.0",
|
|
62
|
+
"@cloud-ru/ds-theme": "^1.0.0",
|
|
63
|
+
"@cloud-ru/ds-scroll": "^1.0.0",
|
|
64
|
+
"@cloud-ru/ds-status": "^1.0.0",
|
|
65
|
+
"@cloud-ru/ds-toolbar": "^1.0.2",
|
|
66
|
+
"@cloud-ru/ds-utils": "^1.0.0",
|
|
67
|
+
"@cloud-ru/ds-toggles": "^1.0.0",
|
|
68
|
+
"@cloud-ru/ds-truncate-string": "^1.0.0",
|
|
69
|
+
"@cloud-ru/ds-tooltip": "^1.0.0"
|
|
71
70
|
},
|
|
72
71
|
"publishConfig": {
|
|
73
72
|
"access": "public"
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { DndContext
|
|
1
|
+
import { DndContext } from '@dnd-kit/core';
|
|
2
2
|
import { isMobileLayout, LayoutPresets, mergePresets, useAdaptiveLayout, useLayoutDefaults } from '@cloud-ru/ds-adaptive';
|
|
3
3
|
import { FiltersState } from '@cloud-ru/ds-chips';
|
|
4
|
-
import { DragPreview } from '@cloud-ru/ds-drag-and-drop';
|
|
5
4
|
import { BACKGROUND_PREDEFINED_FILL } from '@cloud-ru/ds-materials';
|
|
6
5
|
import { useThemeClassnames } from '@cloud-ru/ds-theme';
|
|
7
6
|
import { ToolbarPersistConfig } from '@cloud-ru/ds-toolbar';
|
|
8
7
|
import { extractSupportProps } from '@cloud-ru/ds-utils';
|
|
9
|
-
import { flexRender } from '@tanstack/react-table';
|
|
10
8
|
import cn from 'classnames';
|
|
11
9
|
import { CSSProperties, ReactNode, Ref, RefObject, useEffect, useMemo } from 'react';
|
|
12
10
|
|
|
@@ -16,7 +14,6 @@ import {
|
|
|
16
14
|
DEFAULT_ROW_SELECTION,
|
|
17
15
|
DEFAULT_SORTING,
|
|
18
16
|
DEFAULT_VIEW,
|
|
19
|
-
TABLE_COLUMN_CSS_VARS,
|
|
20
17
|
VIEW,
|
|
21
18
|
} from '../../constants';
|
|
22
19
|
import { CellAutoResizeContext, TableContext, useCellAutoResizeController } from '../../contexts';
|
|
@@ -56,7 +53,7 @@ import {
|
|
|
56
53
|
} from './hooks';
|
|
57
54
|
import { isFilterableColumn } from './hooks/useColumnSettings/utils';
|
|
58
55
|
import styles from './styles.module.scss';
|
|
59
|
-
import {
|
|
56
|
+
import { getColumnIdentifier, getPinnedGroups } from './utils';
|
|
60
57
|
|
|
61
58
|
const TABLE_CONTENT_ACRYLIC = getControlsAcrylicAttrs(BACKGROUND_PREDEFINED_FILL.NeutralBackground1Level);
|
|
62
59
|
|
|
@@ -255,12 +252,11 @@ export function Table<TData extends object, TFilters extends FiltersState = Reco
|
|
|
255
252
|
}
|
|
256
253
|
}, [areColumnsSettingsEnabled, enabledColumns, hideableColumnIds, onSortingChange, sorting]);
|
|
257
254
|
|
|
258
|
-
const { columnOrder, setColumnOrder, dndContextProps, enableColumnsOrderSortByDrag
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
});
|
|
255
|
+
const { columnOrder, setColumnOrder, dndContextProps, enableColumnsOrderSortByDrag } = useColumnOrderByDrag({
|
|
256
|
+
tableColumns: allTableColumns,
|
|
257
|
+
savedState,
|
|
258
|
+
columnSettings: columnsSettingsProp,
|
|
259
|
+
});
|
|
264
260
|
|
|
265
261
|
const manualPagination = infiniteLoading || manualPaginationProp;
|
|
266
262
|
const columnsSettings = useMemo(() => getColumnsSettings(columnOrder), [columnOrder, getColumnsSettings]);
|
|
@@ -470,25 +466,6 @@ export function Table<TData extends object, TFilters extends FiltersState = Reco
|
|
|
470
466
|
showHeader &&
|
|
471
467
|
(isLoadingState || centerRows.length > 0 || filteredTopRows.length > 0 || (isEmptyBody && !dataError));
|
|
472
468
|
|
|
473
|
-
const draggingHeader = draggingColumnId
|
|
474
|
-
? table.getFlatHeaders().find(header => header.column.id === draggingColumnId)
|
|
475
|
-
: undefined;
|
|
476
|
-
|
|
477
|
-
// Копия колонки едет за курсором в портале: внутри скролла она растила бы его ширину
|
|
478
|
-
// и ныряла под закреплённые колонки.
|
|
479
|
-
const draggingColumnPreview = (
|
|
480
|
-
<DragOverlay dropAnimation={null} modifiers={[alignOverlayToHeader]}>
|
|
481
|
-
{draggingHeader ? (
|
|
482
|
-
<DragPreview
|
|
483
|
-
className={styles.columnDragPreview}
|
|
484
|
-
style={{ width: `var(${TABLE_COLUMN_CSS_VARS.size(draggingHeader.column.id)})` } as CSSProperties}
|
|
485
|
-
>
|
|
486
|
-
{flexRender(draggingHeader.column.columnDef.header, draggingHeader.getContext())}
|
|
487
|
-
</DragPreview>
|
|
488
|
-
) : null}
|
|
489
|
-
</DragOverlay>
|
|
490
|
-
);
|
|
491
|
-
|
|
492
469
|
const tableHeaderElement = showTableHeader ? (
|
|
493
470
|
<HeaderRow
|
|
494
471
|
rowAutoHeight={rowAutoHeight}
|
|
@@ -618,7 +595,7 @@ export function Table<TData extends object, TFilters extends FiltersState = Reco
|
|
|
618
595
|
const tableScrollContent = (
|
|
619
596
|
<div className={styles.body} data-empty-body={isEmptyBody || undefined} style={columnSizes.vars as CSSProperties}>
|
|
620
597
|
<CellAutoResizeContext.Provider value={{ updateCellMap, removeCellFromMap }}>
|
|
621
|
-
{tableScrollRows}
|
|
598
|
+
<DndContext {...dndContextProps}>{tableScrollRows}</DndContext>
|
|
622
599
|
</CellAutoResizeContext.Provider>
|
|
623
600
|
</div>
|
|
624
601
|
);
|
|
@@ -626,7 +603,7 @@ export function Table<TData extends object, TFilters extends FiltersState = Reco
|
|
|
626
603
|
const tableContentWithProviders = (
|
|
627
604
|
<div className={styles.body} data-empty-body={isEmptyBody || undefined} style={columnSizes.vars as CSSProperties}>
|
|
628
605
|
<CellAutoResizeContext.Provider value={{ updateCellMap, removeCellFromMap }}>
|
|
629
|
-
{tableBody}
|
|
606
|
+
<DndContext {...dndContextProps}>{tableBody}</DndContext>
|
|
630
607
|
</CellAutoResizeContext.Provider>
|
|
631
608
|
</div>
|
|
632
609
|
);
|
|
@@ -747,27 +724,23 @@ export function Table<TData extends object, TFilters extends FiltersState = Reco
|
|
|
747
724
|
</div>
|
|
748
725
|
) : null}
|
|
749
726
|
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
{
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
>
|
|
768
|
-
{scrollContent}
|
|
769
|
-
</TableScrollHost>
|
|
770
|
-
</DndContext>
|
|
727
|
+
<TableScrollHost
|
|
728
|
+
view={view}
|
|
729
|
+
isMobile={isMobile}
|
|
730
|
+
isCardsView={isCardsView}
|
|
731
|
+
usePageStickyHeader={usePageStickyHeader}
|
|
732
|
+
scrollOverflow={scrollOverflow}
|
|
733
|
+
scrollPaddingAbsolute={scrollPaddingAbsolute}
|
|
734
|
+
internalScrollRef={internalScrollRef}
|
|
735
|
+
scrollRef={scrollRef as Ref<HTMLDivElement>}
|
|
736
|
+
scrollContainerRef={scrollContainerRef as RefObject<HTMLDivElement>}
|
|
737
|
+
handleScrollInitialized={handleScrollInitialized}
|
|
738
|
+
syncHeaderHorizontalScroll={syncHeaderHorizontalScroll}
|
|
739
|
+
tableHeaderElement={tableHeaderElement}
|
|
740
|
+
columnSizeVars={columnSizes.vars as CSSProperties}
|
|
741
|
+
>
|
|
742
|
+
{scrollContent}
|
|
743
|
+
</TableScrollHost>
|
|
771
744
|
{!isCardsView && outline ? <span className={styles.contentBorder} aria-hidden /> : null}
|
|
772
745
|
</div>
|
|
773
746
|
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
closestCenter,
|
|
3
|
-
CollisionDetection,
|
|
4
3
|
DndContextProps,
|
|
5
4
|
DragEndEvent,
|
|
6
|
-
|
|
5
|
+
KeyboardSensor,
|
|
7
6
|
MouseSensor,
|
|
8
7
|
TouchSensor,
|
|
9
8
|
useSensor,
|
|
@@ -40,11 +39,8 @@ export function useColumnOrderByDrag<TData extends object>({
|
|
|
40
39
|
setColumnOrder: Dispatch<SetStateAction<string[]>>;
|
|
41
40
|
dndContextProps: DndContextProps;
|
|
42
41
|
enableColumnsOrderSortByDrag: boolean;
|
|
43
|
-
/** Колонка под курсором прямо сейчас: по ней рендерится копия в портале. */
|
|
44
|
-
draggingColumnId?: string;
|
|
45
42
|
} {
|
|
46
43
|
const [columnOrder, setColumnOrderState] = useState<string[]>(() => prepareInitialState(tableColumns, savedState));
|
|
47
|
-
const [draggingColumnId, setDraggingColumnId] = useState<string>();
|
|
48
44
|
|
|
49
45
|
useEffect(() => {
|
|
50
46
|
setColumnOrderState(prev => {
|
|
@@ -82,18 +78,8 @@ export function useColumnOrderByDrag<TData extends object>({
|
|
|
82
78
|
[columnOrder, savedState],
|
|
83
79
|
);
|
|
84
80
|
|
|
85
|
-
const handleDragStart = useCallback(({ active }: DragStartEvent) => {
|
|
86
|
-
setDraggingColumnId(String(active.id));
|
|
87
|
-
}, []);
|
|
88
|
-
|
|
89
|
-
const handleDragCancel = useCallback(() => {
|
|
90
|
-
setDraggingColumnId(undefined);
|
|
91
|
-
}, []);
|
|
92
|
-
|
|
93
81
|
const handleDragEnd = useCallback(
|
|
94
82
|
({ active, over }: DragEndEvent) => {
|
|
95
|
-
setDraggingColumnId(undefined);
|
|
96
|
-
|
|
97
83
|
if (!active || !over) {
|
|
98
84
|
return;
|
|
99
85
|
}
|
|
@@ -119,19 +105,12 @@ export function useColumnOrderByDrag<TData extends object>({
|
|
|
119
105
|
[columnOrder, setColumnOrder],
|
|
120
106
|
);
|
|
121
107
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
closestCenter({
|
|
127
|
-
...args,
|
|
128
|
-
droppableContainers: args.droppableContainers.filter(container => columnOrder.includes(String(container.id))),
|
|
129
|
-
}),
|
|
130
|
-
[columnOrder],
|
|
108
|
+
const sensors = useSensors(
|
|
109
|
+
useSensor(MouseSensor, draggingOptions),
|
|
110
|
+
useSensor(TouchSensor, {}),
|
|
111
|
+
useSensor(KeyboardSensor, {}),
|
|
131
112
|
);
|
|
132
113
|
|
|
133
|
-
const sensors = useSensors(useSensor(MouseSensor, draggingOptions), useSensor(TouchSensor, {}));
|
|
134
|
-
|
|
135
114
|
const enableColumnsOrderSortByDrag = Boolean(columnSettings?.enableDrag);
|
|
136
115
|
|
|
137
116
|
const dndContextProps = useMemo<DndContextProps>(() => {
|
|
@@ -140,20 +119,17 @@ export function useColumnOrderByDrag<TData extends object>({
|
|
|
140
119
|
}
|
|
141
120
|
|
|
142
121
|
return {
|
|
143
|
-
collisionDetection,
|
|
122
|
+
collisionDetection: closestCenter,
|
|
144
123
|
modifiers: [restrictToHorizontalAxis],
|
|
145
|
-
onDragStart: handleDragStart,
|
|
146
|
-
onDragCancel: handleDragCancel,
|
|
147
124
|
onDragEnd: handleDragEnd,
|
|
148
125
|
sensors,
|
|
149
126
|
};
|
|
150
|
-
}, [
|
|
127
|
+
}, [enableColumnsOrderSortByDrag, handleDragEnd, sensors]);
|
|
151
128
|
|
|
152
129
|
return {
|
|
153
130
|
columnOrder,
|
|
154
131
|
setColumnOrder,
|
|
155
132
|
dndContextProps,
|
|
156
133
|
enableColumnsOrderSortByDrag,
|
|
157
|
-
draggingColumnId,
|
|
158
134
|
};
|
|
159
135
|
}
|
|
@@ -10,7 +10,7 @@ const SETTINGS_MENU_EXCLUDED_IDS = new Set<string>([DefaultColumns.Selection, De
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Колонка попадает в меню настроек: есть id/accessorKey и это не selection/row-actions.
|
|
13
|
-
* Включая `mode: locked` (
|
|
13
|
+
* Включая `mode: locked` и колонки без `columnSettings` (они рендерятся disabled).
|
|
14
14
|
*/
|
|
15
15
|
export function isColumnsSettingsMenuItem<TData extends object>(colDef: ColumnDefinition<TData>): boolean {
|
|
16
16
|
if (!('id' in colDef || 'accessorKey' in colDef)) {
|
|
@@ -39,7 +39,7 @@ function getColumnsSettingsOptionLabel<TData extends object>(columnDefinition: C
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
|
-
* Пункт меню настроек колонок. Неактивные (`mode: locked`
|
|
42
|
+
* Пункт меню настроек колонок. Неактивные (нет `columnSettings` / `mode: locked`) —
|
|
43
43
|
* `disabled` + всегда включённый switch (`checked: true`); драг при этом остаётся
|
|
44
44
|
* доступным. Видимость через `enabledColumns` не управляется.
|
|
45
45
|
*/
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { COLUMN_SETTINGS_MODE } from '../../../../../constants';
|
|
2
1
|
import { ColumnDefinition } from '../../../../../types';
|
|
3
|
-
import { getColumnSettingsMode } from './getColumnSettingsMode';
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* Проверка на то, должна ли колонка быть включена по умолчанию
|
|
7
5
|
* @function isColumnEnabledInitially
|
|
8
6
|
*/
|
|
9
7
|
export function isColumnEnabledInitially<TData extends object>(colDef: ColumnDefinition<TData>): boolean {
|
|
10
|
-
|
|
8
|
+
if ('columnSettings' in colDef && colDef.columnSettings !== undefined) {
|
|
9
|
+
return colDef.columnSettings?.mode !== 'defaultHidden';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return true;
|
|
11
13
|
}
|
package/src/components/Table/hooks/useColumnSettings/utils/isColumnVisibilityConfigurable.ts
CHANGED
|
@@ -1,11 +1,26 @@
|
|
|
1
|
-
import { COLUMN_SETTINGS_MODE } from '../../../../../constants';
|
|
2
1
|
import { ColumnDefinition } from '../../../../../types';
|
|
3
|
-
import { getColumnSettingsMode } from './getColumnSettingsMode';
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* Проверка на то, должна ли колонка отображаться в настройках колонок
|
|
7
5
|
* @function isColumnVisibilityConfigurable
|
|
8
6
|
*/
|
|
9
7
|
export function isColumnVisibilityConfigurable<TData extends object>(colDef: ColumnDefinition<TData>): boolean {
|
|
10
|
-
|
|
8
|
+
if ('columnSettings' in colDef && colDef.columnSettings !== undefined) {
|
|
9
|
+
const { mode } = colDef.columnSettings;
|
|
10
|
+
|
|
11
|
+
if (!mode) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
switch (mode) {
|
|
16
|
+
case 'locked':
|
|
17
|
+
return false;
|
|
18
|
+
case 'defaultVisible':
|
|
19
|
+
case 'defaultHidden':
|
|
20
|
+
default:
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return true;
|
|
11
26
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { COLUMN_SETTINGS_MODE } from '../../../../../constants';
|
|
2
1
|
import { ColumnDefinition, FilterableColumnDefinition } from '../../../../../types';
|
|
3
|
-
import { getColumnSettingsMode, isServiceColumn } from './getColumnSettingsMode';
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* Проверка на то, должна ли колонка отображаться в таблице
|
|
@@ -11,7 +9,7 @@ export function isFilterableColumn<TData extends object>(
|
|
|
11
9
|
): colDef is FilterableColumnDefinition<TData> {
|
|
12
10
|
return (
|
|
13
11
|
('id' in colDef || 'accessorKey' in colDef) &&
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
'columnSettings' in colDef &&
|
|
13
|
+
colDef.columnSettings?.mode !== 'locked'
|
|
16
14
|
);
|
|
17
15
|
}
|
|
@@ -67,6 +67,7 @@ export function useTableScroll({
|
|
|
67
67
|
|
|
68
68
|
if (!usePageStickyHeader) {
|
|
69
69
|
wrapper?.style.removeProperty(TABLE_CSS_VARS.headerScrollLeft);
|
|
70
|
+
wrapper?.style.removeProperty(TABLE_CSS_VARS.viewportWidth);
|
|
70
71
|
|
|
71
72
|
return;
|
|
72
73
|
}
|
|
@@ -85,27 +86,6 @@ export function useTableScroll({
|
|
|
85
86
|
return () => observer.disconnect();
|
|
86
87
|
}, [usePageStickyHeader, isScrollReady, columnSizeVars, syncHeaderHorizontalScroll, view, isLoadingState]);
|
|
87
88
|
|
|
88
|
-
// Ширина вьюпорта нужна не только sticky-шапке: по ней центрируется пустое состояние.
|
|
89
|
-
useLayoutEffect(() => {
|
|
90
|
-
const wrapper = wrapperRef.current;
|
|
91
|
-
const viewport = internalScrollRef.current;
|
|
92
|
-
|
|
93
|
-
if (!wrapper || !viewport) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const syncViewportWidth = () => {
|
|
98
|
-
wrapper.style.setProperty(TABLE_CSS_VARS.viewportWidth, `${viewport.clientWidth}px`);
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
syncViewportWidth();
|
|
102
|
-
|
|
103
|
-
const observer = new ResizeObserver(syncViewportWidth);
|
|
104
|
-
observer.observe(viewport);
|
|
105
|
-
|
|
106
|
-
return () => observer.disconnect();
|
|
107
|
-
}, [isScrollReady, usePageStickyHeader, view, isCardsView, isLoadingState]);
|
|
108
|
-
|
|
109
89
|
useLayoutEffect(() => {
|
|
110
90
|
if (!usePageStickyHeader || !showToolbar) {
|
|
111
91
|
wrapperRef.current?.style.removeProperty(TABLE_CSS_VARS.stickyToolbarOffset);
|
|
@@ -334,8 +334,7 @@ $divider-width: base.simple-var(
|
|
|
334
334
|
flex-direction: column;
|
|
335
335
|
|
|
336
336
|
width: 100%;
|
|
337
|
-
|
|
338
|
-
min-width: max-content;
|
|
337
|
+
min-width: 0;
|
|
339
338
|
min-height: 100%;
|
|
340
339
|
}
|
|
341
340
|
|
|
@@ -509,24 +508,3 @@ $divider-width: base.simple-var(
|
|
|
509
508
|
width: 100%;
|
|
510
509
|
max-width: 100%;
|
|
511
510
|
}
|
|
512
|
-
|
|
513
|
-
// Копия колонки под курсором (DragOverlay + DragPreview): паддинги ячейки шапки.
|
|
514
|
-
// Живёт в портале, вне DOM таблицы, поэтому типографику и цвет заголовка
|
|
515
|
-
// (в сетке они приходят от предков) задаём здесь явно.
|
|
516
|
-
.columnDragPreview {
|
|
517
|
-
display: flex;
|
|
518
|
-
align-items: center;
|
|
519
|
-
|
|
520
|
-
box-sizing: border-box;
|
|
521
|
-
height: base.simple-var(table.$table, 'anatomy', 'content', 'tableCell', 'min-height');
|
|
522
|
-
padding: base.simple-var(table.$table, 'anatomy', 'content', 'tableHead', 'padding-top')
|
|
523
|
-
base.simple-var(table.$table, 'anatomy', 'content', 'tableHead', 'padding-right')
|
|
524
|
-
base.simple-var(table.$table, 'anatomy', 'content', 'tableHead', 'padding-bottom')
|
|
525
|
-
base.simple-var(table.$table, 'anatomy', 'content', 'tableHead', 'padding-left');
|
|
526
|
-
border-radius: table.$sn-table-anatomy-content-borderRadius;
|
|
527
|
-
|
|
528
|
-
color: base.$sn-theme-color-available-version-textTertiary;
|
|
529
|
-
white-space: nowrap;
|
|
530
|
-
|
|
531
|
-
@include base.composite-var(base.$sn-regular-body-m);
|
|
532
|
-
}
|
package/src/constants.ts
CHANGED
|
@@ -13,7 +13,7 @@ export const COLUMN_ALIGN = {
|
|
|
13
13
|
export const COLUMN_SETTINGS_MODE = {
|
|
14
14
|
/** В меню настроек `Switch` заблокирован, колонка всегда видима */
|
|
15
15
|
Locked: 'locked',
|
|
16
|
-
/** В меню, по умолчанию
|
|
16
|
+
/** В меню, по умолчанию включена */
|
|
17
17
|
DefaultVisible: 'defaultVisible',
|
|
18
18
|
/** В меню, по умолчанию выключена */
|
|
19
19
|
DefaultHidden: 'defaultHidden',
|
|
@@ -18,7 +18,6 @@ type BodyCellProps<TData> = Omit<CellProps, 'style' | 'children'> & {
|
|
|
18
18
|
type BodyCellViewProps<TData> = Omit<BodyCellProps<TData>, 'isDraggable'> & {
|
|
19
19
|
style: CSSProperties;
|
|
20
20
|
setNodeRef?: (node: HTMLDivElement | null) => void;
|
|
21
|
-
isDragging?: boolean;
|
|
22
21
|
};
|
|
23
22
|
function BodyCellView<TData>({
|
|
24
23
|
cell,
|
|
@@ -26,7 +25,6 @@ function BodyCellView<TData>({
|
|
|
26
25
|
rowAutoHeight,
|
|
27
26
|
style,
|
|
28
27
|
setNodeRef,
|
|
29
|
-
isDragging,
|
|
30
28
|
...props
|
|
31
29
|
}: BodyCellViewProps<TData>) {
|
|
32
30
|
const columnDef = cell.column.columnDef as ColumnDefinition<TData>;
|
|
@@ -41,7 +39,6 @@ function BodyCellView<TData>({
|
|
|
41
39
|
data-align={columnDef.align}
|
|
42
40
|
data-no-padding={columnDef.noBodyCellPadding || undefined}
|
|
43
41
|
data-column-id={cell.column.id}
|
|
44
|
-
data-dragging={isDragging || undefined}
|
|
45
42
|
data-test-id={TEST_IDS.bodyCell}
|
|
46
43
|
>
|
|
47
44
|
{flexRender(columnDef.cell, cell.getContext())}
|
|
@@ -57,9 +54,9 @@ function StaticBodyCell<TData>(props: Omit<BodyCellProps<TData>, 'isDraggable'>)
|
|
|
57
54
|
|
|
58
55
|
function DraggableBodyCell<TData>(props: Omit<BodyCellProps<TData>, 'isDraggable'>) {
|
|
59
56
|
const { setNodeRef, isDragging, transform } = useSortable({ id: props.cell.column.id });
|
|
60
|
-
const style = useCellSizes(props.cell, { isDraggable: true, transform });
|
|
57
|
+
const style = useCellSizes(props.cell, { isDraggable: true, isDragging, transform });
|
|
61
58
|
|
|
62
|
-
return <BodyCellView {...props} style={style} setNodeRef={setNodeRef}
|
|
59
|
+
return <BodyCellView {...props} style={style} setNodeRef={setNodeRef} />;
|
|
63
60
|
}
|
|
64
61
|
|
|
65
62
|
export function BodyCell<TData>({ isDraggable, ...props }: BodyCellProps<TData>) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useSortable } from '@dnd-kit/sortable';
|
|
2
|
-
import { DRAG_MODE, DragGhost } from '@cloud-ru/ds-drag-and-drop';
|
|
3
2
|
import { TruncateString } from '@cloud-ru/ds-truncate-string';
|
|
4
3
|
import { flexRender, Header } from '@tanstack/react-table';
|
|
5
4
|
import cn from 'classnames';
|
|
@@ -36,8 +35,8 @@ export function HeaderCell<TData>({
|
|
|
36
35
|
const columnSizingInfo = header.getContext().table.getState().columnSizingInfo;
|
|
37
36
|
const isSomeColumnResizing = columnSizingInfo.isResizingColumn;
|
|
38
37
|
const columnDef = header.column.columnDef as ColumnDefinition<TData>;
|
|
39
|
-
const { listeners, setNodeRef, isDragging, transform } = useSortable({ id: header.column.id });
|
|
40
|
-
const style = useCellSizes(header, { isDraggable, transform });
|
|
38
|
+
const { attributes, listeners, setNodeRef, isDragging, transform } = useSortable({ id: header.column.id });
|
|
39
|
+
const style = useCellSizes(header, { isDraggable, isDragging, transform });
|
|
41
40
|
|
|
42
41
|
const sortingHandler = (e: MouseEvent) => {
|
|
43
42
|
if (isSomeColumnResizing) return;
|
|
@@ -52,8 +51,8 @@ export function HeaderCell<TData>({
|
|
|
52
51
|
return {};
|
|
53
52
|
}
|
|
54
53
|
|
|
55
|
-
return listeners;
|
|
56
|
-
}, [header.column.id, isDraggable, listeners]);
|
|
54
|
+
return { ...attributes, ...listeners };
|
|
55
|
+
}, [attributes, header.column.id, isDraggable, listeners]);
|
|
57
56
|
|
|
58
57
|
return (
|
|
59
58
|
<Cell
|
|
@@ -66,7 +65,6 @@ export function HeaderCell<TData>({
|
|
|
66
65
|
data-test-id={TEST_IDS.headerCell}
|
|
67
66
|
data-header-id={header.id}
|
|
68
67
|
data-resizing={isResizing || undefined}
|
|
69
|
-
data-dragging={(isDraggable && isDragging) || undefined}
|
|
70
68
|
data-pin-position={pinPosition || undefined}
|
|
71
69
|
data-row-auto-height={rowAutoHeight || undefined}
|
|
72
70
|
role='columnheader'
|
|
@@ -79,10 +77,9 @@ export function HeaderCell<TData>({
|
|
|
79
77
|
cellRef.current = element;
|
|
80
78
|
}}
|
|
81
79
|
>
|
|
82
|
-
<
|
|
83
|
-
dragging={isDraggable && isDragging}
|
|
84
|
-
mode={DRAG_MODE.Dynamic}
|
|
80
|
+
<div
|
|
85
81
|
className={styles.tableHeaderCellDragWrapper}
|
|
82
|
+
data-dragging={(isDraggable && isDragging) || undefined}
|
|
86
83
|
{...draggableProps}
|
|
87
84
|
>
|
|
88
85
|
<div className={styles.tableHeaderCellMain} data-align={columnDef.headerAlign || undefined}>
|
|
@@ -105,7 +102,7 @@ export function HeaderCell<TData>({
|
|
|
105
102
|
</div>
|
|
106
103
|
)}
|
|
107
104
|
</div>
|
|
108
|
-
</
|
|
105
|
+
</div>
|
|
109
106
|
{Boolean(isResizable) && <ResizeHandle header={header} cellRef={cellRef} />}
|
|
110
107
|
</Cell>
|
|
111
108
|
);
|
|
@@ -53,7 +53,8 @@ export function ResizeHandle<TData>({ header, cellRef }: ResizeHandleProps<TData
|
|
|
53
53
|
return (
|
|
54
54
|
<>
|
|
55
55
|
<div
|
|
56
|
-
|
|
56
|
+
role='button'
|
|
57
|
+
tabIndex={0}
|
|
57
58
|
className={cn(styles.tableHeaderIcon, styles.tableHeaderResizeHandle)}
|
|
58
59
|
data-resizing={isResizing || undefined}
|
|
59
60
|
onMouseDown={handleMouseDown}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
@use '@cloud-ru/ds-figma-variables/build/scss/styles/styles.module' as base;
|
|
2
|
-
@use '@cloud-ru/ds-figma-variables/build/scss/components/table.module' as table;
|
|
3
|
-
|
|
4
|
-
// Та же толщина, что у строковых разделителей таблицы.
|
|
5
|
-
$drag-rail: base.simple-var(table.$table, 'anatomy', 'content', 'tableLine', 'background', 'interaction', 'width');
|
|
6
2
|
|
|
7
3
|
.tableCell {
|
|
8
4
|
@include base.composite-var(base.$sn-regular-body-m);
|
|
@@ -14,11 +10,4 @@ $drag-rail: base.simple-var(table.$table, 'anatomy', 'content', 'tableLine', 'ba
|
|
|
14
10
|
width: 100%;
|
|
15
11
|
|
|
16
12
|
background-color: transparent;
|
|
17
|
-
|
|
18
|
-
// `box-shadow`, а не `border`: ширина ячейки не должна меняться в момент захвата.
|
|
19
|
-
&[data-dragging] {
|
|
20
|
-
box-shadow:
|
|
21
|
-
inset #{$drag-rail} 0 0 0 base.$sn-theme-color-available-borderColor,
|
|
22
|
-
inset calc(-1 * #{$drag-rail}) 0 0 0 base.$sn-theme-color-available-borderColor;
|
|
23
|
-
}
|
|
24
13
|
}
|
|
@@ -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
|
}
|