@atlaskit/editor-plugin-table 12.2.5 → 12.2.7
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 +15 -0
- package/dist/cjs/ui/TableFloatingControls/NumberColumn/index.js +24 -2
- package/dist/es2019/ui/TableFloatingControls/NumberColumn/index.js +23 -1
- package/dist/esm/ui/TableFloatingControls/NumberColumn/index.js +24 -2
- package/package.json +4 -4
- package/afm-cc/tsconfig.json +0 -123
- package/afm-dev-agents/tsconfig.json +0 -123
- package/afm-jira/tsconfig.json +0 -123
- package/afm-passionfruit/tsconfig.json +0 -123
- package/afm-post-office/tsconfig.json +0 -123
- package/afm-rovo-extension/tsconfig.json +0 -123
- package/afm-townsquare/tsconfig.json +0 -123
- package/afm-volt/tsconfig.json +0 -114
- package/build/tsconfig.json +0 -23
- package/docs/0-intro.tsx +0 -57
- package/src/index.ts +0 -21
- package/src/nodeviews/ExternalDropTargets.tsx +0 -91
- package/src/nodeviews/OverflowShadowsObserver.ts +0 -156
- package/src/nodeviews/TableCell.ts +0 -134
- package/src/nodeviews/TableComponent.tsx +0 -1590
- package/src/nodeviews/TableComponentWithSharedState.tsx +0 -278
- package/src/nodeviews/TableContainer.tsx +0 -926
- package/src/nodeviews/TableNodeViewBase.ts +0 -29
- package/src/nodeviews/TableResizer.tsx +0 -884
- package/src/nodeviews/TableRow.ts +0 -830
- package/src/nodeviews/TableStickyScrollbar.ts +0 -211
- package/src/nodeviews/__mocks__/OverflowShadowsObserver.ts +0 -15
- package/src/nodeviews/__mocks__/OverridableMock.ts +0 -26
- package/src/nodeviews/table-container-styles.ts +0 -9
- package/src/nodeviews/table-node-views.ts +0 -76
- package/src/nodeviews/table.tsx +0 -530
- package/src/nodeviews/toDOM.ts +0 -244
- package/src/nodeviews/types.ts +0 -36
- package/src/nodeviews/update-overflow-shadows.ts +0 -11
- package/src/pm-plugins/analytics/actions.ts +0 -21
- package/src/pm-plugins/analytics/commands.ts +0 -47
- package/src/pm-plugins/analytics/plugin-factory.ts +0 -9
- package/src/pm-plugins/analytics/plugin-key.ts +0 -5
- package/src/pm-plugins/analytics/plugin.ts +0 -80
- package/src/pm-plugins/analytics/reducer.ts +0 -27
- package/src/pm-plugins/analytics/types.ts +0 -20
- package/src/pm-plugins/analytics/utils/moved-event.ts +0 -51
- package/src/pm-plugins/commands/clear.ts +0 -43
- package/src/pm-plugins/commands/collapse.ts +0 -17
- package/src/pm-plugins/commands/column-resize.ts +0 -478
- package/src/pm-plugins/commands/commands-with-analytics.ts +0 -715
- package/src/pm-plugins/commands/delete.ts +0 -42
- package/src/pm-plugins/commands/display-mode.ts +0 -18
- package/src/pm-plugins/commands/go-to-next-cell.ts +0 -198
- package/src/pm-plugins/commands/hover.ts +0 -242
- package/src/pm-plugins/commands/index.ts +0 -51
- package/src/pm-plugins/commands/insert.ts +0 -438
- package/src/pm-plugins/commands/misc.ts +0 -811
- package/src/pm-plugins/commands/referentiality.ts +0 -15
- package/src/pm-plugins/commands/selection.ts +0 -537
- package/src/pm-plugins/commands/sort.ts +0 -102
- package/src/pm-plugins/commands/split-cell.ts +0 -28
- package/src/pm-plugins/commands/toggle.ts +0 -109
- package/src/pm-plugins/create-plugin-config.ts +0 -17
- package/src/pm-plugins/decorations/plugin.ts +0 -107
- package/src/pm-plugins/decorations/utils/column-controls.ts +0 -91
- package/src/pm-plugins/decorations/utils/column-resizing.ts +0 -71
- package/src/pm-plugins/decorations/utils/compose-decorations.ts +0 -9
- package/src/pm-plugins/decorations/utils/types.ts +0 -16
- package/src/pm-plugins/default-table-selection.ts +0 -14
- package/src/pm-plugins/drag-and-drop/actions.ts +0 -48
- package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +0 -222
- package/src/pm-plugins/drag-and-drop/commands.ts +0 -194
- package/src/pm-plugins/drag-and-drop/consts.ts +0 -7
- package/src/pm-plugins/drag-and-drop/plugin-factory.ts +0 -33
- package/src/pm-plugins/drag-and-drop/plugin-key.ts +0 -5
- package/src/pm-plugins/drag-and-drop/plugin.ts +0 -398
- package/src/pm-plugins/drag-and-drop/reducer.ts +0 -38
- package/src/pm-plugins/drag-and-drop/types.ts +0 -18
- package/src/pm-plugins/drag-and-drop/utils/autoscrollers.ts +0 -49
- package/src/pm-plugins/drag-and-drop/utils/getDragBehaviour.ts +0 -9
- package/src/pm-plugins/drag-and-drop/utils/monitor.ts +0 -73
- package/src/pm-plugins/handlers.ts +0 -161
- package/src/pm-plugins/keymap.ts +0 -436
- package/src/pm-plugins/main.ts +0 -433
- package/src/pm-plugins/plugin-factory.ts +0 -42
- package/src/pm-plugins/plugin-key.ts +0 -8
- package/src/pm-plugins/reducer.ts +0 -145
- package/src/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -102
- package/src/pm-plugins/sticky-headers/commands.ts +0 -8
- package/src/pm-plugins/sticky-headers/plugin-key.ts +0 -5
- package/src/pm-plugins/sticky-headers/plugin-state.ts +0 -52
- package/src/pm-plugins/sticky-headers/plugin.ts +0 -12
- package/src/pm-plugins/sticky-headers/types.ts +0 -20
- package/src/pm-plugins/sticky-headers/util.ts +0 -18
- package/src/pm-plugins/table-analytics.ts +0 -100
- package/src/pm-plugins/table-local-id.ts +0 -213
- package/src/pm-plugins/table-resizing/commands.ts +0 -116
- package/src/pm-plugins/table-resizing/event-handlers.ts +0 -352
- package/src/pm-plugins/table-resizing/plugin-factory.ts +0 -29
- package/src/pm-plugins/table-resizing/plugin-key.ts +0 -5
- package/src/pm-plugins/table-resizing/plugin.ts +0 -94
- package/src/pm-plugins/table-resizing/reducer.ts +0 -37
- package/src/pm-plugins/table-resizing/utils/colgroup.ts +0 -306
- package/src/pm-plugins/table-resizing/utils/column-state.ts +0 -120
- package/src/pm-plugins/table-resizing/utils/consts.ts +0 -11
- package/src/pm-plugins/table-resizing/utils/content-width.ts +0 -118
- package/src/pm-plugins/table-resizing/utils/dom.ts +0 -132
- package/src/pm-plugins/table-resizing/utils/misc.ts +0 -282
- package/src/pm-plugins/table-resizing/utils/resize-column.ts +0 -34
- package/src/pm-plugins/table-resizing/utils/resize-logic.ts +0 -289
- package/src/pm-plugins/table-resizing/utils/resize-state.ts +0 -417
- package/src/pm-plugins/table-resizing/utils/scale-table.ts +0 -290
- package/src/pm-plugins/table-resizing/utils/types.ts +0 -25
- package/src/pm-plugins/table-resizing/utils/unit-to-number.ts +0 -1
- package/src/pm-plugins/table-selection-keymap.ts +0 -64
- package/src/pm-plugins/table-size-selector.ts +0 -39
- package/src/pm-plugins/table-width-in-comment-fix.ts +0 -113
- package/src/pm-plugins/table-width.ts +0 -153
- package/src/pm-plugins/transforms/column-width.ts +0 -249
- package/src/pm-plugins/transforms/delete-columns.ts +0 -281
- package/src/pm-plugins/transforms/delete-rows.ts +0 -154
- package/src/pm-plugins/transforms/fix-tables.ts +0 -249
- package/src/pm-plugins/transforms/merge.ts +0 -301
- package/src/pm-plugins/transforms/replace-table.ts +0 -38
- package/src/pm-plugins/transforms/split.ts +0 -90
- package/src/pm-plugins/utils/alignment.ts +0 -33
- package/src/pm-plugins/utils/analytics.ts +0 -238
- package/src/pm-plugins/utils/collapse.ts +0 -93
- package/src/pm-plugins/utils/column-controls.ts +0 -250
- package/src/pm-plugins/utils/create.ts +0 -64
- package/src/pm-plugins/utils/decoration.ts +0 -672
- package/src/pm-plugins/utils/dom.ts +0 -251
- package/src/pm-plugins/utils/drag-menu.tsx +0 -491
- package/src/pm-plugins/utils/get-allow-add-column-custom-step.ts +0 -10
- package/src/pm-plugins/utils/guidelines.ts +0 -30
- package/src/pm-plugins/utils/merged-cells.ts +0 -239
- package/src/pm-plugins/utils/nodes.ts +0 -162
- package/src/pm-plugins/utils/paste.ts +0 -386
- package/src/pm-plugins/utils/row-controls.ts +0 -211
- package/src/pm-plugins/utils/selection.ts +0 -17
- package/src/pm-plugins/utils/snapping.ts +0 -136
- package/src/pm-plugins/utils/table.ts +0 -60
- package/src/pm-plugins/utils/update-plugin-state-decorations.ts +0 -13
- package/src/pm-plugins/view-mode-sort/consts.ts +0 -3
- package/src/pm-plugins/view-mode-sort/index.ts +0 -291
- package/src/pm-plugins/view-mode-sort/plugin-key.ts +0 -7
- package/src/pm-plugins/view-mode-sort/types.ts +0 -23
- package/src/pm-plugins/view-mode-sort/utils.ts +0 -136
- package/src/tablePlugin.tsx +0 -971
- package/src/tablePluginType.ts +0 -102
- package/src/types/index.ts +0 -592
- package/src/ui/ColumnResizeWidget/index.tsx +0 -61
- package/src/ui/ContentComponent.tsx +0 -311
- package/src/ui/DragHandle/HandleIconComponent.tsx +0 -21
- package/src/ui/DragHandle/index.tsx +0 -391
- package/src/ui/DragPreview/index.tsx +0 -51
- package/src/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.tsx +0 -59
- package/src/ui/FloatingContextualButton/FixedButton.tsx +0 -203
- package/src/ui/FloatingContextualButton/index.tsx +0 -168
- package/src/ui/FloatingContextualButton/styles.ts +0 -69
- package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +0 -931
- package/src/ui/FloatingContextualMenu/index.tsx +0 -141
- package/src/ui/FloatingContextualMenu/styles.ts +0 -77
- package/src/ui/FloatingDeleteButton/DeleteButton.tsx +0 -54
- package/src/ui/FloatingDeleteButton/getPopUpOptions.ts +0 -65
- package/src/ui/FloatingDeleteButton/index.tsx +0 -383
- package/src/ui/FloatingDeleteButton/types.ts +0 -3
- package/src/ui/FloatingDragMenu/DragMenu.tsx +0 -668
- package/src/ui/FloatingDragMenu/DropdownMenu.tsx +0 -221
- package/src/ui/FloatingDragMenu/index.tsx +0 -136
- package/src/ui/FloatingDragMenu/styles.ts +0 -83
- package/src/ui/FloatingInsertButton/InsertButton.tsx +0 -263
- package/src/ui/FloatingInsertButton/getPopupOptions.ts +0 -131
- package/src/ui/FloatingInsertButton/index.tsx +0 -314
- package/src/ui/FloatingToolbarLabel/FloatingToolbarLabel.tsx +0 -31
- package/src/ui/SizeSelector/index.tsx +0 -74
- package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +0 -397
- package/src/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +0 -105
- package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +0 -63
- package/src/ui/TableFloatingColumnControls/index.tsx +0 -151
- package/src/ui/TableFloatingControls/CornerControls/ClassicCornerControls.tsx +0 -106
- package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +0 -143
- package/src/ui/TableFloatingControls/CornerControls/types.ts +0 -12
- package/src/ui/TableFloatingControls/FloatingControlsWithSelection.tsx +0 -88
- package/src/ui/TableFloatingControls/NumberColumn/index.tsx +0 -150
- package/src/ui/TableFloatingControls/RowControls/ClassicControls.tsx +0 -131
- package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +0 -429
- package/src/ui/TableFloatingControls/RowDropTarget/index.tsx +0 -96
- package/src/ui/TableFloatingControls/index.tsx +0 -275
- package/src/ui/TableFullWidthLabel/index.tsx +0 -38
- package/src/ui/common-styles.ts +0 -1218
- package/src/ui/consts.ts +0 -109
- package/src/ui/event-handlers.ts +0 -662
- package/src/ui/global-styles.tsx +0 -55
- package/src/ui/hooks/useInternalTablePluginStateSelector.ts +0 -38
- package/src/ui/icons/AddColLeftIcon.tsx +0 -37
- package/src/ui/icons/AddColRightIcon.tsx +0 -37
- package/src/ui/icons/AddRowAboveIcon.tsx +0 -22
- package/src/ui/icons/AddRowBelowIcon.tsx +0 -39
- package/src/ui/icons/DragHandleDisabledIcon.tsx +0 -25
- package/src/ui/icons/DragHandleIcon.tsx +0 -16
- package/src/ui/icons/DragInMotionIcon.tsx +0 -54
- package/src/ui/icons/MergeCellsIcon.tsx +0 -26
- package/src/ui/icons/MinimisedHandle.tsx +0 -15
- package/src/ui/icons/SortingIconWrapper.tsx +0 -43
- package/src/ui/icons/SplitCellIcon.tsx +0 -34
- package/src/ui/toolbar.tsx +0 -1153
- package/src/ui/ui-styles.ts +0 -960
- package/tsconfig.app.json +0 -135
- package/tsconfig.dev.json +0 -54
- package/tsconfig.json +0 -18
|
@@ -1,397 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @atlaskit/design-system/prefer-primitives */
|
|
2
|
-
import type { MouseEvent } from 'react';
|
|
3
|
-
import React, { useCallback, useMemo, useRef } from 'react';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
sharedPluginStateHookMigratorFactory,
|
|
7
|
-
useSharedPluginState,
|
|
8
|
-
useSharedPluginStateWithSelector,
|
|
9
|
-
} from '@atlaskit/editor-common/hooks';
|
|
10
|
-
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
11
|
-
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
12
|
-
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
13
|
-
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
14
|
-
import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
15
|
-
import { CellSelection } from '@atlaskit/editor-tables';
|
|
16
|
-
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
17
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
18
|
-
|
|
19
|
-
import {
|
|
20
|
-
clearHoverSelection,
|
|
21
|
-
hoverCell,
|
|
22
|
-
hoverColumns,
|
|
23
|
-
selectColumn,
|
|
24
|
-
selectColumns,
|
|
25
|
-
} from '../../../pm-plugins/commands';
|
|
26
|
-
import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
|
|
27
|
-
import type { TriggerType } from '../../../pm-plugins/drag-and-drop/types';
|
|
28
|
-
import { getRowsParams } from '../../../pm-plugins/utils/row-controls';
|
|
29
|
-
import { getSelectedColumnIndexes } from '../../../pm-plugins/utils/selection';
|
|
30
|
-
import type { TablePlugin } from '../../../tablePluginType';
|
|
31
|
-
import type { CellHoverMeta, HandleTypes } from '../../../types';
|
|
32
|
-
import { TableCssClassName as ClassName } from '../../../types';
|
|
33
|
-
import type { DragHandleAppearance } from '../../DragHandle';
|
|
34
|
-
import { DragHandle, DragHandleWithSharedState } from '../../DragHandle';
|
|
35
|
-
|
|
36
|
-
interface ColumnControlsProps {
|
|
37
|
-
editorView: EditorView;
|
|
38
|
-
tableActive?: boolean;
|
|
39
|
-
isInDanger?: boolean;
|
|
40
|
-
tableRef: HTMLTableElement;
|
|
41
|
-
hoveredCell?: CellHoverMeta;
|
|
42
|
-
stickyTop?: number;
|
|
43
|
-
localId?: string;
|
|
44
|
-
rowHeights?: number[];
|
|
45
|
-
colWidths?: (number | undefined)[];
|
|
46
|
-
hasHeaderColumn?: boolean;
|
|
47
|
-
isTableHovered?: boolean;
|
|
48
|
-
tableContainerWidth?: number;
|
|
49
|
-
isNumberColumnEnabled?: boolean;
|
|
50
|
-
isDragging?: boolean;
|
|
51
|
-
getScrollOffset?: () => number;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const getSelectedColumns = (selection: Selection) => {
|
|
55
|
-
if (selection instanceof CellSelection && selection.isColSelection()) {
|
|
56
|
-
const rect = getSelectionRect(selection);
|
|
57
|
-
if (!rect) {
|
|
58
|
-
return [];
|
|
59
|
-
}
|
|
60
|
-
return getSelectedColumnIndexes(rect);
|
|
61
|
-
}
|
|
62
|
-
return [];
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const useSharedState = sharedPluginStateHookMigratorFactory(
|
|
66
|
-
(api: ExtractInjectionAPI<TablePlugin> | undefined) => {
|
|
67
|
-
const { selection } = useSharedPluginStateWithSelector(api, ['selection'], (states) => ({
|
|
68
|
-
selection: states.selectionState?.selection,
|
|
69
|
-
}));
|
|
70
|
-
return {
|
|
71
|
-
selection,
|
|
72
|
-
};
|
|
73
|
-
},
|
|
74
|
-
(api: ExtractInjectionAPI<TablePlugin> | undefined) => {
|
|
75
|
-
const { selectionState } = useSharedPluginState(api, ['selection']);
|
|
76
|
-
return {
|
|
77
|
-
selection: selectionState?.selection,
|
|
78
|
-
};
|
|
79
|
-
},
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
export const ColumnControls = ({
|
|
83
|
-
editorView,
|
|
84
|
-
tableActive,
|
|
85
|
-
tableRef,
|
|
86
|
-
hoveredCell,
|
|
87
|
-
stickyTop,
|
|
88
|
-
localId,
|
|
89
|
-
isInDanger,
|
|
90
|
-
rowHeights,
|
|
91
|
-
colWidths,
|
|
92
|
-
isTableHovered,
|
|
93
|
-
tableContainerWidth,
|
|
94
|
-
isNumberColumnEnabled,
|
|
95
|
-
isDragging,
|
|
96
|
-
getScrollOffset,
|
|
97
|
-
api,
|
|
98
|
-
}: ColumnControlsProps & { api?: ExtractInjectionAPI<TablePlugin> }) => {
|
|
99
|
-
const columnControlsRef = useRef<HTMLDivElement>(null);
|
|
100
|
-
const { selection } = useSharedState(api);
|
|
101
|
-
|
|
102
|
-
const widths =
|
|
103
|
-
colWidths
|
|
104
|
-
?.map((width) =>
|
|
105
|
-
// when there is sticky header, a `margin-right: -1px` applied to `tr.sticky th` so it causes colWidths to be 1px wider
|
|
106
|
-
// we need to reduce the width by 1px to avoid misalignment of column controls.
|
|
107
|
-
width ? (stickyTop ? `${width - 2}px` : `${width - 1}px`) : '0px',
|
|
108
|
-
)
|
|
109
|
-
.join(' ') ?? '0px';
|
|
110
|
-
// TODO: ED-26961 - reusing getRowsParams here because it's generic enough to work for columns -> rename
|
|
111
|
-
const columnParams = getRowsParams(colWidths ?? []);
|
|
112
|
-
const colIndex = hoveredCell?.colIndex;
|
|
113
|
-
const selectedColIndexes = getSelectedColumns(selection || editorView.state.selection);
|
|
114
|
-
|
|
115
|
-
const firstRow = tableRef.querySelector('tr');
|
|
116
|
-
const hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
|
|
117
|
-
|
|
118
|
-
const rowControlStickyTop = 45;
|
|
119
|
-
const marginTop = hasHeaderRow && stickyTop !== undefined ? rowControlStickyTop ?? 0 : 0;
|
|
120
|
-
|
|
121
|
-
const handleClick = useCallback(
|
|
122
|
-
(event: MouseEvent) => {
|
|
123
|
-
const { state, dispatch } = editorView;
|
|
124
|
-
|
|
125
|
-
const isClickOutsideSelectedCols =
|
|
126
|
-
// Ignored via go/ees005
|
|
127
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
128
|
-
selectedColIndexes.length >= 1 && !selectedColIndexes.includes(colIndex!);
|
|
129
|
-
|
|
130
|
-
if (!selectedColIndexes || selectedColIndexes.length === 0 || isClickOutsideSelectedCols) {
|
|
131
|
-
// Ignored via go/ees005
|
|
132
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
133
|
-
selectColumn(colIndex!, event.shiftKey)(state, dispatch);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (
|
|
137
|
-
selectedColIndexes.length > 1 &&
|
|
138
|
-
// Ignored via go/ees005
|
|
139
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
140
|
-
selectedColIndexes.includes(colIndex!) &&
|
|
141
|
-
!event.shiftKey
|
|
142
|
-
) {
|
|
143
|
-
selectColumns(selectedColIndexes)(state, dispatch);
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
[colIndex, selectedColIndexes, editorView],
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
const handleMouseOver = useCallback(() => {
|
|
150
|
-
const { state, dispatch } = editorView;
|
|
151
|
-
// Ignored via go/ees005
|
|
152
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
153
|
-
hoverColumns([colIndex!])(state, dispatch);
|
|
154
|
-
}, [colIndex, editorView]);
|
|
155
|
-
|
|
156
|
-
const handleMouseMove = useCallback(
|
|
157
|
-
(e: MouseEvent) => {
|
|
158
|
-
const isParentDragControls = (e.nativeEvent.target as Element).closest(
|
|
159
|
-
`.${ClassName.DRAG_COLUMN_CONTROLS}`,
|
|
160
|
-
);
|
|
161
|
-
const colIndex = (e.nativeEvent.target as Element).getAttribute('data-start-index');
|
|
162
|
-
|
|
163
|
-
// avoid updating if event target is not related
|
|
164
|
-
if (!isParentDragControls || !colIndex) {
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// update hovered cell location
|
|
169
|
-
const { state, dispatch } = editorView;
|
|
170
|
-
if (tableActive) {
|
|
171
|
-
// For context: Whenever we mouse over a column or row drag handle, we will ALWAYS be hovering over the 0 index
|
|
172
|
-
// of the opposite dimension. For example; here when we mouse over the column drag handle then we're technically
|
|
173
|
-
// also hovering over row 0 index. And vice-versa with rows. This means we don't need to worry about knowing the
|
|
174
|
-
// current row index. We can just force it to 0.
|
|
175
|
-
hoverCell(0, Number(colIndex))(state, dispatch);
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
[editorView, tableActive],
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
const handleMouseOut = useCallback(() => {
|
|
182
|
-
if (tableActive) {
|
|
183
|
-
const { state, dispatch } = editorView;
|
|
184
|
-
clearHoverSelection()(state, dispatch);
|
|
185
|
-
}
|
|
186
|
-
}, [editorView, tableActive]);
|
|
187
|
-
|
|
188
|
-
const toggleDragMenuHandler = useCallback(
|
|
189
|
-
(
|
|
190
|
-
trigger: TriggerType,
|
|
191
|
-
event: MouseEvent<HTMLButtonElement, globalThis.MouseEvent> | undefined,
|
|
192
|
-
) => {
|
|
193
|
-
const { state, dispatch } = editorView;
|
|
194
|
-
if (event?.shiftKey) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
toggleDragMenu(undefined, 'column', colIndex, trigger)(state, dispatch);
|
|
198
|
-
},
|
|
199
|
-
[editorView, colIndex],
|
|
200
|
-
);
|
|
201
|
-
|
|
202
|
-
const colIndexes = useMemo(() => {
|
|
203
|
-
// Ignored via go/ees005
|
|
204
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
205
|
-
return [colIndex!];
|
|
206
|
-
}, [colIndex]);
|
|
207
|
-
|
|
208
|
-
if (stickyTop && columnControlsRef.current) {
|
|
209
|
-
columnControlsRef.current.scrollLeft = getScrollOffset?.() ?? 0;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const generateHandleByType = (
|
|
213
|
-
type: HandleTypes,
|
|
214
|
-
appearance: DragHandleAppearance,
|
|
215
|
-
gridColumn: string,
|
|
216
|
-
indexes: number[],
|
|
217
|
-
) => {
|
|
218
|
-
const isHover = type === 'hover';
|
|
219
|
-
const isPlaceholder = appearance === 'placeholder';
|
|
220
|
-
const previewHeight = rowHeights?.reduce((sum, cur) => sum + cur, 0) ?? 0;
|
|
221
|
-
|
|
222
|
-
const previewWidth =
|
|
223
|
-
colWidths?.reduce<number>(
|
|
224
|
-
(sum, v, i) => sum + (v ?? tableCellMinWidth) * (indexes.includes(i) ? 1 : 0),
|
|
225
|
-
0,
|
|
226
|
-
) ?? tableCellMinWidth;
|
|
227
|
-
|
|
228
|
-
return (
|
|
229
|
-
<div
|
|
230
|
-
contentEditable={false}
|
|
231
|
-
key={type}
|
|
232
|
-
style={{
|
|
233
|
-
gridColumn,
|
|
234
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
235
|
-
gridRow: '1',
|
|
236
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
237
|
-
display: 'flex',
|
|
238
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
239
|
-
justifyContent: 'center',
|
|
240
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
241
|
-
alignItems: 'center',
|
|
242
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
243
|
-
height: 'fit-content',
|
|
244
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
245
|
-
placeSelf: 'center',
|
|
246
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
247
|
-
zIndex: 99,
|
|
248
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
249
|
-
width: '100%',
|
|
250
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
251
|
-
position: 'relative',
|
|
252
|
-
}}
|
|
253
|
-
data-testid={`table-floating-column-${
|
|
254
|
-
isHover ? colIndex : isPlaceholder ? appearance : selectedColIndexes[0]
|
|
255
|
-
}-drag-handle`}
|
|
256
|
-
>
|
|
257
|
-
{fg('platform_editor_table_use_shared_state_hook_fg') ? (
|
|
258
|
-
<DragHandleWithSharedState
|
|
259
|
-
isDragMenuTarget={!isHover}
|
|
260
|
-
direction="column"
|
|
261
|
-
tableLocalId={localId || ''}
|
|
262
|
-
indexes={indexes}
|
|
263
|
-
hoveredCell={hoveredCell}
|
|
264
|
-
previewWidth={previewWidth}
|
|
265
|
-
forceDefaultHandle={!isHover}
|
|
266
|
-
previewHeight={previewHeight}
|
|
267
|
-
appearance={appearance}
|
|
268
|
-
onClick={handleClick}
|
|
269
|
-
onMouseOver={handleMouseOver}
|
|
270
|
-
onMouseOut={handleMouseOut}
|
|
271
|
-
toggleDragMenu={toggleDragMenuHandler}
|
|
272
|
-
editorView={editorView}
|
|
273
|
-
api={api}
|
|
274
|
-
/>
|
|
275
|
-
) : (
|
|
276
|
-
<DragHandle
|
|
277
|
-
isDragMenuTarget={!isHover}
|
|
278
|
-
direction="column"
|
|
279
|
-
tableLocalId={localId || ''}
|
|
280
|
-
indexes={indexes}
|
|
281
|
-
hoveredCell={hoveredCell}
|
|
282
|
-
previewWidth={previewWidth}
|
|
283
|
-
forceDefaultHandle={!isHover}
|
|
284
|
-
previewHeight={previewHeight}
|
|
285
|
-
appearance={appearance}
|
|
286
|
-
onClick={handleClick}
|
|
287
|
-
onMouseOver={handleMouseOver}
|
|
288
|
-
onMouseOut={handleMouseOut}
|
|
289
|
-
toggleDragMenu={toggleDragMenuHandler}
|
|
290
|
-
editorView={editorView}
|
|
291
|
-
/>
|
|
292
|
-
)}
|
|
293
|
-
</div>
|
|
294
|
-
);
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
const columnHandles = () => {
|
|
298
|
-
const handles = [];
|
|
299
|
-
const isColumnSelected = selectedColIndexes.length > 0;
|
|
300
|
-
const isEntireTableSelected = (colWidths || []).length > selectedColIndexes.length;
|
|
301
|
-
|
|
302
|
-
if (!tableActive) {
|
|
303
|
-
return null;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
const selectedAppearance =
|
|
307
|
-
isColumnSelected && isEntireTableSelected
|
|
308
|
-
? isInDanger
|
|
309
|
-
? 'danger'
|
|
310
|
-
: 'selected'
|
|
311
|
-
: 'placeholder';
|
|
312
|
-
|
|
313
|
-
// placeholder / selected need to always render at least one handle
|
|
314
|
-
// so it can be focused via keyboard shortcuts
|
|
315
|
-
handles.push(
|
|
316
|
-
generateHandleByType(
|
|
317
|
-
'selected',
|
|
318
|
-
selectedAppearance,
|
|
319
|
-
// always position placeholder in first column to avoid overflow issues
|
|
320
|
-
selectedAppearance === 'placeholder'
|
|
321
|
-
? '1 / span 1'
|
|
322
|
-
: `${selectedColIndexes[0] + 1} / span ${selectedColIndexes.length}`,
|
|
323
|
-
selectedColIndexes,
|
|
324
|
-
),
|
|
325
|
-
);
|
|
326
|
-
|
|
327
|
-
if (
|
|
328
|
-
hoveredCell &&
|
|
329
|
-
isTableHovered &&
|
|
330
|
-
colIndex !== undefined &&
|
|
331
|
-
!selectedColIndexes.includes(colIndex)
|
|
332
|
-
) {
|
|
333
|
-
handles.push(
|
|
334
|
-
// Ignored via go/ees005
|
|
335
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
336
|
-
generateHandleByType('hover', 'default', `${colIndex! + 1} / span 1`, colIndexes),
|
|
337
|
-
);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
return handles;
|
|
341
|
-
};
|
|
342
|
-
|
|
343
|
-
const containerWidth =
|
|
344
|
-
isNumberColumnEnabled && tableContainerWidth
|
|
345
|
-
? tableContainerWidth - akEditorTableNumberColumnWidth
|
|
346
|
-
: tableContainerWidth;
|
|
347
|
-
|
|
348
|
-
return (
|
|
349
|
-
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
350
|
-
<div
|
|
351
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
352
|
-
className={ClassName.DRAG_COLUMN_CONTROLS}
|
|
353
|
-
onMouseMove={handleMouseMove}
|
|
354
|
-
>
|
|
355
|
-
<div
|
|
356
|
-
ref={columnControlsRef}
|
|
357
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
358
|
-
className={ClassName.DRAG_COLUMN_CONTROLS_INNER}
|
|
359
|
-
data-testid="table-floating-column-controls"
|
|
360
|
-
style={{
|
|
361
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
362
|
-
gridTemplateColumns: widths,
|
|
363
|
-
// eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage/preview, @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
364
|
-
marginTop,
|
|
365
|
-
// eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage/preview
|
|
366
|
-
width: stickyTop ? containerWidth : undefined,
|
|
367
|
-
overflowX: stickyTop ? 'hidden' : 'visible',
|
|
368
|
-
pointerEvents: isDragging ? 'none' : undefined,
|
|
369
|
-
}}
|
|
370
|
-
>
|
|
371
|
-
{columnParams.map(({ startIndex, endIndex }, index) => (
|
|
372
|
-
<div
|
|
373
|
-
style={{
|
|
374
|
-
gridColumn: `${startIndex + 1} / span 1`,
|
|
375
|
-
}}
|
|
376
|
-
data-start-index={startIndex}
|
|
377
|
-
data-end-index={endIndex}
|
|
378
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
379
|
-
className={ClassName.DRAG_COLUMN_FLOATING_INSERT_DOT_WRAPPER}
|
|
380
|
-
contentEditable={false}
|
|
381
|
-
// Ignored via go/ees005
|
|
382
|
-
// eslint-disable-next-line react/no-array-index-key
|
|
383
|
-
key={index}
|
|
384
|
-
>
|
|
385
|
-
<div
|
|
386
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
387
|
-
className={ClassName.DRAG_COLUMN_FLOATING_INSERT_DOT}
|
|
388
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
389
|
-
style={columnParams.length - 1 === index ? { right: '0' } : {}}
|
|
390
|
-
/>
|
|
391
|
-
</div>
|
|
392
|
-
))}
|
|
393
|
-
{columnHandles()}
|
|
394
|
-
</div>
|
|
395
|
-
</div>
|
|
396
|
-
);
|
|
397
|
-
};
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from 'react';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
attachClosestEdge,
|
|
5
|
-
type Edge,
|
|
6
|
-
} from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
|
|
7
|
-
import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
8
|
-
|
|
9
|
-
import { getDragBehaviour } from '../../../pm-plugins/drag-and-drop/utils/getDragBehaviour';
|
|
10
|
-
import type { DraggableSourceData } from '../../../types';
|
|
11
|
-
|
|
12
|
-
interface Props {
|
|
13
|
-
index: number;
|
|
14
|
-
localId?: string;
|
|
15
|
-
width?: number;
|
|
16
|
-
height?: number;
|
|
17
|
-
marginTop?: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const ColumnDropTarget = ({ index, localId, width, height, marginTop }: Props) => {
|
|
21
|
-
const dropTargetRef = useRef<HTMLDivElement | null>(null);
|
|
22
|
-
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
if (!dropTargetRef.current) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return dropTargetForElements({
|
|
29
|
-
element: dropTargetRef.current,
|
|
30
|
-
canDrop({ source, input }) {
|
|
31
|
-
const data = source.data as DraggableSourceData;
|
|
32
|
-
const behaviour = getDragBehaviour(input);
|
|
33
|
-
|
|
34
|
-
// A move drop is limited too where it can go, however a clone can drop can go anywhere.
|
|
35
|
-
const isDropValid =
|
|
36
|
-
behaviour === 'move' ? data.indexes?.indexOf(index) === -1 : behaviour === 'clone';
|
|
37
|
-
|
|
38
|
-
return (
|
|
39
|
-
// Only draggables of row type can be dropped on this target
|
|
40
|
-
data.type === 'table-column' &&
|
|
41
|
-
// Only draggables which came from the same table can be dropped on this target
|
|
42
|
-
data.localId === localId &&
|
|
43
|
-
// Only draggables which DO NOT include this drop targets index can be dropped
|
|
44
|
-
!!data.indexes?.length &&
|
|
45
|
-
isDropValid
|
|
46
|
-
);
|
|
47
|
-
},
|
|
48
|
-
getDropEffect: ({ input }) => (getDragBehaviour(input) === 'clone' ? 'copy' : 'move'),
|
|
49
|
-
getIsSticky: () => true,
|
|
50
|
-
getData({ source, input, element }) {
|
|
51
|
-
const data = {
|
|
52
|
-
localId,
|
|
53
|
-
type: 'table-column',
|
|
54
|
-
targetIndex: index,
|
|
55
|
-
};
|
|
56
|
-
const srcData = source.data as DraggableSourceData;
|
|
57
|
-
const behaviour = getDragBehaviour(input);
|
|
58
|
-
|
|
59
|
-
// During a move op there's no point in allowing edges to be dropped on which result in no change/move to occur.
|
|
60
|
-
const allowedEdges: Edge[] =
|
|
61
|
-
behaviour === 'move'
|
|
62
|
-
? srcData.indexes?.reduce(
|
|
63
|
-
(acc, v) => {
|
|
64
|
-
if (v - index === -1) {
|
|
65
|
-
acc.shift();
|
|
66
|
-
}
|
|
67
|
-
if (v - index === 1) {
|
|
68
|
-
acc.pop();
|
|
69
|
-
}
|
|
70
|
-
return acc;
|
|
71
|
-
},
|
|
72
|
-
['left', 'right'],
|
|
73
|
-
)
|
|
74
|
-
: ['left', 'right'];
|
|
75
|
-
|
|
76
|
-
return attachClosestEdge(data, {
|
|
77
|
-
input,
|
|
78
|
-
element,
|
|
79
|
-
allowedEdges,
|
|
80
|
-
});
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
}, [index, localId]);
|
|
84
|
-
|
|
85
|
-
return (
|
|
86
|
-
<div
|
|
87
|
-
ref={dropTargetRef}
|
|
88
|
-
style={{
|
|
89
|
-
// eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage/preview
|
|
90
|
-
width: width && `${width - 1}px`,
|
|
91
|
-
// eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage/preview
|
|
92
|
-
height: height && `${height}px`,
|
|
93
|
-
// eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage/preview
|
|
94
|
-
marginTop: marginTop && `${marginTop}px`,
|
|
95
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
96
|
-
pointerEvents: 'auto',
|
|
97
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
98
|
-
flexShrink: 0,
|
|
99
|
-
}}
|
|
100
|
-
data-drop-target-index={index}
|
|
101
|
-
data-drop-target-localid={localId}
|
|
102
|
-
data-testid="table-floating-column-controls-drop-target"
|
|
103
|
-
/>
|
|
104
|
-
);
|
|
105
|
-
};
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import React, { useRef } from 'react';
|
|
2
|
-
|
|
3
|
-
import { TableCssClassName as ClassName } from '../../../types';
|
|
4
|
-
|
|
5
|
-
import { ColumnDropTarget } from './ColumnDropTarget';
|
|
6
|
-
|
|
7
|
-
interface Props {
|
|
8
|
-
tableRef: HTMLTableElement;
|
|
9
|
-
tableHeight?: number;
|
|
10
|
-
localId?: string;
|
|
11
|
-
colWidths?: (number | undefined)[];
|
|
12
|
-
isHeaderSticky?: boolean;
|
|
13
|
-
getScrollOffset?: () => number;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const ColumnDropTargets = ({
|
|
17
|
-
tableRef,
|
|
18
|
-
tableHeight,
|
|
19
|
-
localId,
|
|
20
|
-
colWidths,
|
|
21
|
-
isHeaderSticky,
|
|
22
|
-
getScrollOffset,
|
|
23
|
-
}: Props) => {
|
|
24
|
-
const dropTargetRef = useRef<HTMLDivElement>(null);
|
|
25
|
-
|
|
26
|
-
if (!tableRef) {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (isHeaderSticky && dropTargetRef.current) {
|
|
31
|
-
dropTargetRef.current.style.marginLeft = `-${getScrollOffset?.() ?? 0}px`;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return (
|
|
35
|
-
<div
|
|
36
|
-
ref={dropTargetRef}
|
|
37
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
38
|
-
className={ClassName.DRAG_COLUMN_DROP_TARGET_CONTROLS}
|
|
39
|
-
contentEditable={false}
|
|
40
|
-
>
|
|
41
|
-
<div
|
|
42
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
43
|
-
className={ClassName.DRAG_COLUMN_CONTROLS_INNER}
|
|
44
|
-
data-testid="table-floating-column-controls-drop-targets"
|
|
45
|
-
>
|
|
46
|
-
{colWidths?.map((width, index) => {
|
|
47
|
-
return (
|
|
48
|
-
<ColumnDropTarget
|
|
49
|
-
// Ignored via go/ees005
|
|
50
|
-
// eslint-disable-next-line react/no-array-index-key
|
|
51
|
-
key={index}
|
|
52
|
-
index={index}
|
|
53
|
-
localId={localId}
|
|
54
|
-
width={width}
|
|
55
|
-
height={tableHeight}
|
|
56
|
-
marginTop={0}
|
|
57
|
-
/>
|
|
58
|
-
);
|
|
59
|
-
})}
|
|
60
|
-
</div>
|
|
61
|
-
</div>
|
|
62
|
-
);
|
|
63
|
-
};
|