@atlaskit/editor-plugin-table 5.7.9 → 5.8.0
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 +19 -0
- package/afm-cc/tsconfig.json +3 -0
- package/dist/cjs/commands/column-resize.js +155 -0
- package/dist/cjs/commands/go-to-next-cell.js +15 -0
- package/dist/cjs/commands/selection.js +16 -3
- package/dist/cjs/nodeviews/ExternalDropTargets.js +2 -1
- package/dist/cjs/plugin.js +2 -1
- package/dist/cjs/pm-plugins/drag-and-drop/commands.js +3 -3
- package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +2 -1
- package/dist/cjs/pm-plugins/keymap.js +9 -0
- package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +18 -7
- package/dist/cjs/pm-plugins/table-resizing/utils/index.js +6 -0
- package/dist/cjs/types.js +8 -1
- package/dist/cjs/ui/DragHandle/index.js +1 -1
- package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +187 -17
- package/dist/cjs/ui/FloatingDragMenu/index.js +4 -2
- package/dist/cjs/ui/FloatingDragMenu/styles.js +19 -0
- package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +2 -2
- package/dist/cjs/ui/TableFloatingControls/RowControls/DragControls.js +2 -2
- package/dist/cjs/ui/consts.js +2 -1
- package/dist/cjs/ui/ui-styles.js +6 -2
- package/dist/cjs/utils/decoration.js +14 -4
- package/dist/es2019/commands/column-resize.js +149 -0
- package/dist/es2019/commands/go-to-next-cell.js +13 -0
- package/dist/es2019/commands/selection.js +16 -3
- package/dist/es2019/nodeviews/ExternalDropTargets.js +2 -1
- package/dist/es2019/plugin.js +2 -1
- package/dist/es2019/pm-plugins/drag-and-drop/commands.js +3 -3
- package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +2 -1
- package/dist/es2019/pm-plugins/keymap.js +10 -1
- package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +19 -8
- package/dist/es2019/pm-plugins/table-resizing/utils/index.js +1 -1
- package/dist/es2019/types.js +8 -1
- package/dist/es2019/ui/DragHandle/index.js +1 -1
- package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +177 -7
- package/dist/es2019/ui/FloatingDragMenu/index.js +4 -2
- package/dist/es2019/ui/FloatingDragMenu/styles.js +62 -0
- package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +2 -2
- package/dist/es2019/ui/TableFloatingControls/RowControls/DragControls.js +2 -2
- package/dist/es2019/ui/consts.js +2 -1
- package/dist/es2019/ui/ui-styles.js +108 -65
- package/dist/es2019/utils/decoration.js +14 -4
- package/dist/esm/commands/column-resize.js +149 -0
- package/dist/esm/commands/go-to-next-cell.js +15 -0
- package/dist/esm/commands/selection.js +16 -3
- package/dist/esm/nodeviews/ExternalDropTargets.js +2 -1
- package/dist/esm/plugin.js +2 -1
- package/dist/esm/pm-plugins/drag-and-drop/commands.js +3 -3
- package/dist/esm/pm-plugins/drag-and-drop/plugin.js +2 -1
- package/dist/esm/pm-plugins/keymap.js +10 -1
- package/dist/esm/pm-plugins/table-resizing/event-handlers.js +19 -8
- package/dist/esm/pm-plugins/table-resizing/utils/index.js +1 -1
- package/dist/esm/types.js +8 -1
- package/dist/esm/ui/DragHandle/index.js +1 -1
- package/dist/esm/ui/FloatingDragMenu/DragMenu.js +177 -7
- package/dist/esm/ui/FloatingDragMenu/index.js +4 -2
- package/dist/esm/ui/FloatingDragMenu/styles.js +12 -0
- package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +2 -2
- package/dist/esm/ui/TableFloatingControls/RowControls/DragControls.js +2 -2
- package/dist/esm/ui/consts.js +2 -1
- package/dist/esm/ui/ui-styles.js +7 -3
- package/dist/esm/utils/decoration.js +14 -4
- package/dist/types/commands/column-resize.d.ts +5 -0
- package/dist/types/pm-plugins/drag-and-drop/commands.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/utils/index.d.ts +1 -1
- package/dist/types/types.d.ts +7 -0
- package/dist/types/ui/FloatingDragMenu/DragMenu.d.ts +1 -2
- package/dist/types/ui/FloatingDragMenu/index.d.ts +3 -2
- package/dist/types/ui/FloatingDragMenu/styles.d.ts +3 -0
- package/dist/types/ui/consts.d.ts +1 -1
- package/dist/types/utils/decoration.d.ts +2 -2
- package/dist/types-ts4.5/commands/column-resize.d.ts +5 -0
- package/dist/types-ts4.5/pm-plugins/drag-and-drop/commands.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/types.d.ts +7 -0
- package/dist/types-ts4.5/ui/FloatingDragMenu/DragMenu.d.ts +1 -2
- package/dist/types-ts4.5/ui/FloatingDragMenu/index.d.ts +3 -2
- package/dist/types-ts4.5/ui/FloatingDragMenu/styles.d.ts +3 -0
- package/dist/types-ts4.5/ui/consts.d.ts +1 -1
- package/dist/types-ts4.5/utils/decoration.d.ts +2 -2
- package/package.json +8 -4
- package/src/__tests__/unit/analytics.ts +5 -1
- package/src/__tests__/unit/ui/FloatingDragMenu.tsx +295 -0
- package/src/__tests__/unit/ui/RowDragControls.tsx +5 -4
- package/src/commands/column-resize.ts +257 -0
- package/src/commands/go-to-next-cell.ts +21 -0
- package/src/commands/selection.ts +19 -2
- package/src/nodeviews/ExternalDropTargets.tsx +1 -0
- package/src/plugin.tsx +1 -0
- package/src/pm-plugins/drag-and-drop/commands.ts +3 -2
- package/src/pm-plugins/drag-and-drop/plugin.ts +10 -4
- package/src/pm-plugins/keymap.ts +35 -0
- package/src/pm-plugins/table-resizing/event-handlers.ts +33 -21
- package/src/pm-plugins/table-resizing/utils/index.ts +1 -0
- package/src/types.ts +9 -0
- package/src/ui/DragHandle/index.tsx +1 -1
- package/src/ui/FloatingDragMenu/DragMenu.tsx +226 -7
- package/src/ui/FloatingDragMenu/index.tsx +4 -1
- package/src/ui/FloatingDragMenu/styles.ts +71 -0
- package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +35 -37
- package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +33 -33
- package/src/ui/consts.ts +6 -1
- package/src/ui/ui-styles.ts +115 -64
- package/src/utils/decoration.ts +27 -8
- package/tsconfig.app.json +3 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
2
|
+
import type {
|
|
3
|
+
Command,
|
|
4
|
+
GetEditorContainerWidth,
|
|
5
|
+
} from '@atlaskit/editor-common/types';
|
|
6
|
+
import { TableMap } from '@atlaskit/editor-tables';
|
|
7
|
+
import type {
|
|
8
|
+
CellAttributes,
|
|
9
|
+
Direction,
|
|
10
|
+
} from '@atlaskit/editor-tables/src/types';
|
|
11
|
+
import {
|
|
12
|
+
findCellClosestToPos,
|
|
13
|
+
findCellRectClosestToPos,
|
|
14
|
+
findTableClosestToPos,
|
|
15
|
+
getSelectionRect,
|
|
16
|
+
isSelectionType,
|
|
17
|
+
nextCell,
|
|
18
|
+
} from '@atlaskit/editor-tables/src/utils';
|
|
19
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
getPluginState as getTableResizingPluginState,
|
|
23
|
+
createCommand as tableResizingPluginCreateCommand,
|
|
24
|
+
} from '../pm-plugins/table-resizing/plugin-factory';
|
|
25
|
+
import {
|
|
26
|
+
currentColWidth,
|
|
27
|
+
getResizeState,
|
|
28
|
+
getTableMaxWidth,
|
|
29
|
+
resizeColumn,
|
|
30
|
+
updateControls,
|
|
31
|
+
} from '../pm-plugins/table-resizing/utils';
|
|
32
|
+
import { updateColumnWidths } from '../transforms';
|
|
33
|
+
import { getSelectedColumnIndexes } from '../utils';
|
|
34
|
+
|
|
35
|
+
import { addResizeHandleDecorations, showResizeHandleLine } from './index';
|
|
36
|
+
|
|
37
|
+
const updateResizeHandleAndStatePosition =
|
|
38
|
+
(
|
|
39
|
+
rowIndex: number,
|
|
40
|
+
columnIndex: number,
|
|
41
|
+
nextResizeHandlePos: number,
|
|
42
|
+
): Command =>
|
|
43
|
+
(state, dispatch) => {
|
|
44
|
+
addResizeHandleDecorations(rowIndex, columnIndex, true)(state, dispatch);
|
|
45
|
+
// Currently only 'right' position is used in showResizeHandleLine
|
|
46
|
+
showResizeHandleLine({
|
|
47
|
+
left: 0,
|
|
48
|
+
right: columnIndex,
|
|
49
|
+
})(state, dispatch);
|
|
50
|
+
|
|
51
|
+
tableResizingPluginCreateCommand({
|
|
52
|
+
type: 'SET_RESIZE_HANDLE_POSITION',
|
|
53
|
+
data: {
|
|
54
|
+
resizeHandlePos: nextResizeHandlePos,
|
|
55
|
+
},
|
|
56
|
+
})(state, dispatch);
|
|
57
|
+
return false;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const initiateKeyboardColumnResizing: Command = (
|
|
61
|
+
state,
|
|
62
|
+
dispatch,
|
|
63
|
+
view,
|
|
64
|
+
) => {
|
|
65
|
+
if (!getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
const { selection } = state;
|
|
69
|
+
const selectionRect = isSelectionType(selection, 'cell')
|
|
70
|
+
? getSelectionRect(selection)!
|
|
71
|
+
: findCellRectClosestToPos(selection.$from);
|
|
72
|
+
const cell = findCellClosestToPos(selection.$from);
|
|
73
|
+
|
|
74
|
+
if (selectionRect && cell && view) {
|
|
75
|
+
const cellAttrs = cell.node.attrs;
|
|
76
|
+
const width = currentColWidth(view, cell.pos, cellAttrs as CellAttributes);
|
|
77
|
+
|
|
78
|
+
updateResizeHandleAndStatePosition(
|
|
79
|
+
selectionRect.top,
|
|
80
|
+
selectionRect.right,
|
|
81
|
+
cell.pos,
|
|
82
|
+
)(state, dispatch);
|
|
83
|
+
|
|
84
|
+
tableResizingPluginCreateCommand({
|
|
85
|
+
type: 'SET_DRAGGING',
|
|
86
|
+
data: {
|
|
87
|
+
dragging: {
|
|
88
|
+
startX: 0,
|
|
89
|
+
startWidth: width,
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
})(state, dispatch);
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const activateNextResizeArea =
|
|
99
|
+
(direction: Direction): Command =>
|
|
100
|
+
(state, dispatch) => {
|
|
101
|
+
if (!getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
const { resizeHandlePos, dragging } =
|
|
105
|
+
getTableResizingPluginState(state) || {};
|
|
106
|
+
// If No resizing has initiated, skip to regular handler
|
|
107
|
+
if (!resizeHandlePos || !dragging) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const { selection } = state;
|
|
112
|
+
const cell = findCellClosestToPos(selection.$from);
|
|
113
|
+
if (!cell) {
|
|
114
|
+
// cursor position may be changed by mouse to be outside of table;
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const $currentCell = state.doc.resolve(resizeHandlePos);
|
|
119
|
+
if (!$currentCell) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const tableNode = $currentCell.node(-1);
|
|
124
|
+
const closestTable = findTableClosestToPos($currentCell);
|
|
125
|
+
const tableMap = TableMap.get(tableNode);
|
|
126
|
+
|
|
127
|
+
if (!tableNode || !closestTable || !tableMap) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const currentCellRect = tableMap.findCell(
|
|
132
|
+
$currentCell.pos - $currentCell.start(-1),
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const $nextCell = nextCell($currentCell, 'horiz', direction);
|
|
136
|
+
|
|
137
|
+
if ($nextCell) {
|
|
138
|
+
// we are somewhere in between the side columns of the table
|
|
139
|
+
const offset = $nextCell.pos - $nextCell.start(-1);
|
|
140
|
+
const rectForNextCell = tableMap.findCell(offset);
|
|
141
|
+
updateResizeHandleAndStatePosition(
|
|
142
|
+
rectForNextCell.top,
|
|
143
|
+
rectForNextCell.right,
|
|
144
|
+
$nextCell.pos,
|
|
145
|
+
)(state, dispatch);
|
|
146
|
+
} else {
|
|
147
|
+
// current position is in the one of the side columns of the table(left or right)
|
|
148
|
+
if (currentCellRect.left === 0) {
|
|
149
|
+
const lastCellInCurrentRow =
|
|
150
|
+
tableMap.positionAt(
|
|
151
|
+
currentCellRect.top,
|
|
152
|
+
tableMap.width - 1,
|
|
153
|
+
tableNode,
|
|
154
|
+
) + closestTable.start;
|
|
155
|
+
const $lastCell = state.doc.resolve(lastCellInCurrentRow);
|
|
156
|
+
|
|
157
|
+
updateResizeHandleAndStatePosition(
|
|
158
|
+
currentCellRect.top,
|
|
159
|
+
tableMap.width,
|
|
160
|
+
$lastCell.pos,
|
|
161
|
+
)(state, dispatch);
|
|
162
|
+
} else if (tableMap.width === currentCellRect.right) {
|
|
163
|
+
const firsCellInCurrentRow =
|
|
164
|
+
tableMap.positionAt(currentCellRect.top, 0, tableNode) +
|
|
165
|
+
closestTable.start;
|
|
166
|
+
const $nextCell = state.doc.resolve(firsCellInCurrentRow);
|
|
167
|
+
|
|
168
|
+
updateResizeHandleAndStatePosition(
|
|
169
|
+
currentCellRect.top,
|
|
170
|
+
1,
|
|
171
|
+
$nextCell.pos,
|
|
172
|
+
)(state, dispatch);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return true;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
export const changeColumnWidthByStep =
|
|
179
|
+
(
|
|
180
|
+
stepSize: number,
|
|
181
|
+
getEditorContainerWidth: GetEditorContainerWidth,
|
|
182
|
+
): Command =>
|
|
183
|
+
(state, dispatch, view) => {
|
|
184
|
+
if (!getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
const { resizeHandlePos, dragging } = getTableResizingPluginState(state);
|
|
188
|
+
if (!view || !resizeHandlePos || !dragging) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const $cell = state.doc.resolve(resizeHandlePos);
|
|
193
|
+
|
|
194
|
+
const tableStartPosition = $cell.start(-1);
|
|
195
|
+
const originalTable = $cell.node(-1);
|
|
196
|
+
const map = TableMap.get(originalTable);
|
|
197
|
+
const domAtPos = view.domAtPos.bind(view);
|
|
198
|
+
|
|
199
|
+
const colIndex =
|
|
200
|
+
map.colCount($cell.pos - tableStartPosition) +
|
|
201
|
+
($cell.nodeAfter ? $cell.nodeAfter.attrs.colspan : 1) -
|
|
202
|
+
1;
|
|
203
|
+
|
|
204
|
+
let dom: HTMLTableElement = domAtPos(tableStartPosition)
|
|
205
|
+
.node as HTMLTableElement;
|
|
206
|
+
|
|
207
|
+
if (dom && dom.nodeName !== 'TABLE') {
|
|
208
|
+
dom = dom.closest('table') as HTMLTableElement;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const maxSize = getTableMaxWidth({
|
|
212
|
+
table: originalTable,
|
|
213
|
+
tableStart: tableStartPosition,
|
|
214
|
+
state,
|
|
215
|
+
layout: originalTable.attrs.layout,
|
|
216
|
+
getEditorContainerWidth,
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
const initialResizeState = getResizeState({
|
|
220
|
+
minWidth: tableCellMinWidth,
|
|
221
|
+
maxSize,
|
|
222
|
+
table: originalTable,
|
|
223
|
+
tableRef: dom,
|
|
224
|
+
start: tableStartPosition,
|
|
225
|
+
domAtPos,
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
updateControls()(state);
|
|
229
|
+
|
|
230
|
+
const selectionRect = getSelectionRect(state.selection);
|
|
231
|
+
const selectedColumns = selectionRect
|
|
232
|
+
? getSelectedColumnIndexes(selectionRect)
|
|
233
|
+
: [];
|
|
234
|
+
// only selected (or selected - 1) columns should be distributed
|
|
235
|
+
const resizingSelectedColumns =
|
|
236
|
+
selectedColumns.indexOf(colIndex) > -1 ||
|
|
237
|
+
selectedColumns.indexOf(colIndex + 1) > -1;
|
|
238
|
+
const newResizeState = resizeColumn(
|
|
239
|
+
initialResizeState,
|
|
240
|
+
colIndex,
|
|
241
|
+
stepSize,
|
|
242
|
+
dom,
|
|
243
|
+
resizingSelectedColumns ? selectedColumns : undefined,
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
const tr = updateColumnWidths(
|
|
247
|
+
newResizeState,
|
|
248
|
+
originalTable,
|
|
249
|
+
tableStartPosition,
|
|
250
|
+
)(state.tr);
|
|
251
|
+
|
|
252
|
+
if (dispatch) {
|
|
253
|
+
dispatch(tr);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return true;
|
|
257
|
+
};
|
|
@@ -10,8 +10,15 @@ import {
|
|
|
10
10
|
goToNextCell as baseGotoNextCell,
|
|
11
11
|
findTable,
|
|
12
12
|
} from '@atlaskit/editor-tables/utils';
|
|
13
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
13
14
|
|
|
14
15
|
import { insertRowWithAnalytics } from '../commands-with-analytics';
|
|
16
|
+
import {
|
|
17
|
+
getPluginState as getResizePluginState,
|
|
18
|
+
createCommand as tableResizingPluginCreateCommand,
|
|
19
|
+
} from '../pm-plugins/table-resizing/plugin-factory';
|
|
20
|
+
|
|
21
|
+
import { hideResizeHandleLine } from './hover';
|
|
15
22
|
|
|
16
23
|
const TAB_FORWARD_DIRECTION = 1;
|
|
17
24
|
const TAB_BACKWARD_DIRECTION = -1;
|
|
@@ -25,6 +32,20 @@ export const goToNextCell =
|
|
|
25
32
|
return false;
|
|
26
33
|
}
|
|
27
34
|
|
|
35
|
+
if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
|
|
36
|
+
const isColumnResizing = !!getResizePluginState(state)?.dragging;
|
|
37
|
+
if (isColumnResizing) {
|
|
38
|
+
tableResizingPluginCreateCommand(
|
|
39
|
+
{
|
|
40
|
+
type: 'STOP_RESIZING',
|
|
41
|
+
},
|
|
42
|
+
(originalTr) =>
|
|
43
|
+
(state.tr || originalTr).setMeta('scrollIntoView', false),
|
|
44
|
+
)(state, dispatch);
|
|
45
|
+
hideResizeHandleLine()(state, dispatch);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
28
49
|
const map = TableMap.get(table.node);
|
|
29
50
|
const { tableCell, tableHeader } = state.schema.nodes;
|
|
30
51
|
const cell = findParentNodeOfType([tableCell, tableHeader])(
|
|
@@ -24,9 +24,11 @@ import {
|
|
|
24
24
|
isTableSelected,
|
|
25
25
|
selectedRect,
|
|
26
26
|
} from '@atlaskit/editor-tables/utils';
|
|
27
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
27
28
|
|
|
28
29
|
import { selectColumn, selectRow } from '../commands/misc';
|
|
29
30
|
import type tablePlugin from '../plugin';
|
|
31
|
+
import { getPluginState as getResizePluginState } from '../pm-plugins/table-resizing/plugin-factory';
|
|
30
32
|
import { getClosestSelectionRect } from '../toolbar';
|
|
31
33
|
|
|
32
34
|
export enum TableSelectionDirection {
|
|
@@ -289,11 +291,19 @@ const arrowLeftFromText =
|
|
|
289
291
|
const table = findTable(selection);
|
|
290
292
|
if (table) {
|
|
291
293
|
const { $from } = selection;
|
|
294
|
+
let isColumnResizing = false;
|
|
295
|
+
|
|
296
|
+
if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
|
|
297
|
+
const columResizePluginState = getResizePluginState(state) || {};
|
|
298
|
+
isColumnResizing = Boolean(columResizePluginState?.dragging);
|
|
299
|
+
}
|
|
300
|
+
|
|
292
301
|
if (
|
|
293
302
|
isSelectionAtStartOfTable($from, selection) &&
|
|
294
303
|
$from.parent.type.name === 'paragraph' &&
|
|
295
304
|
$from.depth === table.depth + 3 && // + 3 for: row, cell & paragraph nodes
|
|
296
|
-
editorSelectionAPI
|
|
305
|
+
editorSelectionAPI &&
|
|
306
|
+
!isColumnResizing
|
|
297
307
|
) {
|
|
298
308
|
const selectionState: SelectionSharedState =
|
|
299
309
|
editorSelectionAPI.sharedState.currentState() || {};
|
|
@@ -330,10 +340,17 @@ const arrowRightFromText =
|
|
|
330
340
|
const table = findTable(selection);
|
|
331
341
|
if (table) {
|
|
332
342
|
const { $to } = selection;
|
|
343
|
+
let isColumnResizing = false;
|
|
344
|
+
|
|
345
|
+
if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
|
|
346
|
+
const columResizePluginState = getResizePluginState(state) || {};
|
|
347
|
+
isColumnResizing = Boolean(columResizePluginState?.dragging);
|
|
348
|
+
}
|
|
333
349
|
if (
|
|
334
350
|
isSelectionAtEndOfTable($to, selection) &&
|
|
335
351
|
$to.parent.type.name === 'paragraph' &&
|
|
336
|
-
$to.depth === table.depth + 3 // + 3 for: row, cell & paragraph nodes
|
|
352
|
+
$to.depth === table.depth + 3 && // + 3 for: row, cell & paragraph nodes
|
|
353
|
+
!isColumnResizing
|
|
337
354
|
) {
|
|
338
355
|
// we have a text selection at end of last table cell, directly inside a top level paragraph,
|
|
339
356
|
// and want to set a full table cell selection
|
package/src/plugin.tsx
CHANGED
|
@@ -524,6 +524,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
524
524
|
getEditorContainerWidth={defaultGetEditorContainerWidth}
|
|
525
525
|
editorAnalyticsAPI={editorAnalyticsAPI}
|
|
526
526
|
stickyHeaders={stickyHeader}
|
|
527
|
+
pluginConfig={pluginConfig}
|
|
527
528
|
/>
|
|
528
529
|
)}
|
|
529
530
|
{allowControls && !isDragAndDropEnabled && !isResizing && (
|
|
@@ -41,6 +41,7 @@ export const updatePluginStateDecorations = (
|
|
|
41
41
|
export const setDropTarget = (
|
|
42
42
|
type: DropTargetType,
|
|
43
43
|
index: number,
|
|
44
|
+
hasMergedCells: boolean,
|
|
44
45
|
tr?: Transaction,
|
|
45
46
|
) =>
|
|
46
47
|
createCommand(
|
|
@@ -54,13 +55,13 @@ export const setDropTarget = (
|
|
|
54
55
|
if (type === 'column') {
|
|
55
56
|
decorationSet = updatePluginStateDecorations(
|
|
56
57
|
state,
|
|
57
|
-
createColumnInsertLine(index, state.selection),
|
|
58
|
+
createColumnInsertLine(index, state.selection, hasMergedCells),
|
|
58
59
|
TableDecorations.COLUMN_INSERT_LINE,
|
|
59
60
|
);
|
|
60
61
|
} else if (type === 'row') {
|
|
61
62
|
decorationSet = updatePluginStateDecorations(
|
|
62
63
|
state,
|
|
63
|
-
createRowInsertLine(index, state.selection),
|
|
64
|
+
createRowInsertLine(index, state.selection, hasMergedCells),
|
|
64
65
|
TableDecorations.ROW_INSERT_LINE,
|
|
65
66
|
);
|
|
66
67
|
}
|
|
@@ -163,10 +163,16 @@ export const createPlugin = (
|
|
|
163
163
|
? DropTargetType.ROW
|
|
164
164
|
: DropTargetType.COLUMN;
|
|
165
165
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
);
|
|
166
|
+
const hasMergedCells = hasMergedCellsInBetween(
|
|
167
|
+
[targetAdjustedIndex - 1, targetAdjustedIndex],
|
|
168
|
+
dropTargetType,
|
|
169
|
+
)(editorView.state.selection);
|
|
170
|
+
|
|
171
|
+
setDropTarget(
|
|
172
|
+
dropTargetType,
|
|
173
|
+
targetAdjustedIndex,
|
|
174
|
+
hasMergedCells,
|
|
175
|
+
)(editorView.state, editorView.dispatch);
|
|
170
176
|
},
|
|
171
177
|
onDrop(event) {
|
|
172
178
|
const data = getDraggableDataFromEvent(event);
|
package/src/pm-plugins/keymap.ts
CHANGED
|
@@ -13,20 +13,26 @@ import {
|
|
|
13
13
|
addRowBefore,
|
|
14
14
|
backspace,
|
|
15
15
|
bindKeymapWithCommand,
|
|
16
|
+
decreaseMediaSize,
|
|
16
17
|
deleteColumn,
|
|
17
18
|
deleteRow,
|
|
19
|
+
increaseMediaSize,
|
|
18
20
|
moveColumnLeft,
|
|
19
21
|
moveColumnRight,
|
|
22
|
+
moveLeft,
|
|
23
|
+
moveRight,
|
|
20
24
|
moveRowDown,
|
|
21
25
|
moveRowUp,
|
|
22
26
|
nextCell,
|
|
23
27
|
previousCell,
|
|
28
|
+
startColumnResizing,
|
|
24
29
|
toggleTable,
|
|
25
30
|
} from '@atlaskit/editor-common/keymaps';
|
|
26
31
|
import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
27
32
|
import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
28
33
|
import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
|
|
29
34
|
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
35
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
30
36
|
|
|
31
37
|
import {
|
|
32
38
|
createTable,
|
|
@@ -40,6 +46,11 @@ import {
|
|
|
40
46
|
deleteTableIfSelectedWithAnalytics,
|
|
41
47
|
emptyMultipleCellsWithAnalytics,
|
|
42
48
|
} from '../commands-with-analytics';
|
|
49
|
+
import {
|
|
50
|
+
activateNextResizeArea,
|
|
51
|
+
changeColumnWidthByStep,
|
|
52
|
+
initiateKeyboardColumnResizing,
|
|
53
|
+
} from '../commands/column-resize';
|
|
43
54
|
import {
|
|
44
55
|
addColumnAfter as addColumnAfterCommand,
|
|
45
56
|
addColumnBefore as addColumnBeforeCommand,
|
|
@@ -162,6 +173,30 @@ export function keymapPlugin(
|
|
|
162
173
|
);
|
|
163
174
|
}
|
|
164
175
|
|
|
176
|
+
if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
|
|
177
|
+
bindKeymapWithCommand(
|
|
178
|
+
startColumnResizing.common!,
|
|
179
|
+
initiateKeyboardColumnResizing,
|
|
180
|
+
list,
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
bindKeymapWithCommand(moveRight.common!, activateNextResizeArea(1), list);
|
|
184
|
+
|
|
185
|
+
bindKeymapWithCommand(moveLeft.common!, activateNextResizeArea(-1), list);
|
|
186
|
+
|
|
187
|
+
bindKeymapWithCommand(
|
|
188
|
+
decreaseMediaSize.common!,
|
|
189
|
+
changeColumnWidthByStep(-10, getEditorContainerWidth),
|
|
190
|
+
list,
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
bindKeymapWithCommand(
|
|
194
|
+
increaseMediaSize.common!,
|
|
195
|
+
changeColumnWidthByStep(10, getEditorContainerWidth),
|
|
196
|
+
list,
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
165
200
|
return keymap(list) as SafePlugin;
|
|
166
201
|
}
|
|
167
202
|
|
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
currentColWidth,
|
|
30
30
|
getLayoutSize,
|
|
31
31
|
getResizeState,
|
|
32
|
+
getTableMaxWidth,
|
|
32
33
|
pointsAtCell,
|
|
33
34
|
resizeColumn,
|
|
34
35
|
updateControls,
|
|
@@ -72,27 +73,38 @@ export const handleMouseDown = (
|
|
|
72
73
|
dom = dom.closest('table') as HTMLTableElement;
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
76
|
+
let maxSize;
|
|
77
|
+
if (!getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
|
|
78
|
+
const containerWidth = getEditorContainerWidth();
|
|
79
|
+
const parentWidth = getParentNodeWidth(start, state, containerWidth);
|
|
80
|
+
|
|
81
|
+
maxSize = getBooleanFF('platform.editor.custom-table-width')
|
|
82
|
+
? parentWidth ||
|
|
83
|
+
// its safe to reference table width from node as this will not have changed
|
|
84
|
+
originalTable.attrs.width ||
|
|
85
|
+
getLayoutSize(
|
|
86
|
+
dom.getAttribute('data-layout') as TableLayout,
|
|
87
|
+
containerWidth.width,
|
|
88
|
+
{},
|
|
89
|
+
)
|
|
90
|
+
: parentWidth ||
|
|
91
|
+
getLayoutSize(
|
|
92
|
+
dom.getAttribute('data-layout') as TableLayout,
|
|
93
|
+
containerWidth.width,
|
|
94
|
+
{},
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
if (originalTable.attrs.isNumberColumnEnabled) {
|
|
98
|
+
maxSize -= akEditorTableNumberColumnWidth;
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
maxSize = getTableMaxWidth({
|
|
102
|
+
table: originalTable,
|
|
103
|
+
tableStart: start,
|
|
104
|
+
state,
|
|
105
|
+
layout: originalTable.attrs.layout,
|
|
106
|
+
getEditorContainerWidth,
|
|
107
|
+
});
|
|
96
108
|
}
|
|
97
109
|
|
|
98
110
|
const resizeState = getResizeState({
|
package/src/types.ts
CHANGED
|
@@ -340,6 +340,9 @@ export const TableCssClassName = {
|
|
|
340
340
|
/** minimised handle class */
|
|
341
341
|
DRAG_HANDLE_MINIMISED: `${tablePrefixSelector}-drag-handle-minimised`,
|
|
342
342
|
|
|
343
|
+
DRAG_SUBMENU: `${tablePrefixSelector}-drag-submenu`,
|
|
344
|
+
DRAG_SUBMENU_ICON: `${tablePrefixSelector}-drag-submenu-icon`,
|
|
345
|
+
|
|
343
346
|
/** Other classes */
|
|
344
347
|
NUMBERED_COLUMN: `${tablePrefixSelector}-numbered-column`,
|
|
345
348
|
NUMBERED_COLUMN_BUTTON: `${tablePrefixSelector}-numbered-column__button`,
|
|
@@ -383,14 +386,20 @@ export const TableCssClassName = {
|
|
|
383
386
|
LAST_ITEM_IN_CELL: `${tablePrefixSelector}-last-item-in-cell`,
|
|
384
387
|
|
|
385
388
|
WITH_COLUMN_INSERT_LINE: `${tablePrefixSelector}-column-insert-line`,
|
|
389
|
+
WITH_COLUMN_INSERT_LINE_INACTIVE: `${tablePrefixSelector}-column-insert-line__inactive`,
|
|
386
390
|
WITH_FIRST_COLUMN_INSERT_LINE: `${tablePrefixSelector}-first-column-insert-line`,
|
|
391
|
+
WITH_FIRST_COLUMN_INSERT_LINE_INACTIVE: `${tablePrefixSelector}-first-column-insert-line__inactive`,
|
|
392
|
+
|
|
387
393
|
WITH_LAST_COLUMN_INSERT_LINE: `${tablePrefixSelector}-last-column-insert-line`,
|
|
394
|
+
WITH_LAST_COLUMN_INSERT_LINE_INACTIVE: `${tablePrefixSelector}-last-column-insert-line__inactive`,
|
|
388
395
|
|
|
389
396
|
WITH_RESIZE_LINE: `${tablePrefixSelector}-column-resize-line`,
|
|
390
397
|
WITH_RESIZE_LINE_LAST_COLUMN: `${tablePrefixSelector}-column-resize-line-last-column`,
|
|
391
398
|
|
|
392
399
|
WITH_ROW_INSERT_LINE: `${tablePrefixSelector}-row-insert-line`,
|
|
400
|
+
WITH_ROW_INSERT_LINE_INACTIVE: `${tablePrefixSelector}-row-insert-line__inactive`,
|
|
393
401
|
WITH_LAST_ROW_INSERT_LINE: `${tablePrefixSelector}-last-row-insert-line`,
|
|
402
|
+
WITH_LAST_ROW_INSERT_LINE_INACTIVE: `${tablePrefixSelector}-last-row-insert-line__inactive`,
|
|
394
403
|
};
|
|
395
404
|
|
|
396
405
|
export interface ToolbarMenuConfig {
|
|
@@ -153,7 +153,7 @@ export const DragHandle = ({
|
|
|
153
153
|
style={{
|
|
154
154
|
transform: direction === 'column' ? 'none' : 'rotate(90deg)',
|
|
155
155
|
}}
|
|
156
|
-
data-testid="table-
|
|
156
|
+
data-testid="table-drag-handle-button"
|
|
157
157
|
onMouseOver={onMouseOver}
|
|
158
158
|
onMouseOut={onMouseOut}
|
|
159
159
|
onMouseUp={(e) => {
|