@atlaskit/editor-plugin-table 7.13.0 → 7.13.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 +18 -0
- package/dist/cjs/commands/insert.js +6 -4
- package/dist/cjs/commands-with-analytics.js +4 -2
- package/dist/cjs/plugin.js +4 -2
- package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +10 -3
- package/dist/cjs/pm-plugins/table-resizing/utils/index.js +6 -0
- package/dist/cjs/pm-plugins/table-resizing/utils/misc.js +8 -1
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +51 -34
- package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +11 -7
- package/dist/cjs/ui/FloatingContextualMenu/index.js +4 -2
- package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +3 -2
- package/dist/cjs/ui/FloatingDragMenu/index.js +7 -2
- package/dist/cjs/ui/FloatingInsertButton/index.js +10 -4
- package/dist/cjs/utils/drag-menu.js +3 -2
- package/dist/es2019/commands/insert.js +6 -6
- package/dist/es2019/commands-with-analytics.js +4 -4
- package/dist/es2019/plugin.js +4 -2
- package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +11 -4
- package/dist/es2019/pm-plugins/table-resizing/utils/index.js +1 -1
- package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +7 -0
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +49 -34
- package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +7 -3
- package/dist/es2019/ui/FloatingContextualMenu/index.js +4 -2
- package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +3 -2
- package/dist/es2019/ui/FloatingDragMenu/index.js +7 -2
- package/dist/es2019/ui/FloatingInsertButton/index.js +10 -4
- package/dist/es2019/utils/drag-menu.js +3 -3
- package/dist/esm/commands/insert.js +6 -4
- package/dist/esm/commands-with-analytics.js +4 -2
- package/dist/esm/plugin.js +4 -2
- package/dist/esm/pm-plugins/table-resizing/event-handlers.js +11 -4
- package/dist/esm/pm-plugins/table-resizing/utils/index.js +1 -1
- package/dist/esm/pm-plugins/table-resizing/utils/misc.js +7 -0
- package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +50 -33
- package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +11 -7
- package/dist/esm/ui/FloatingContextualMenu/index.js +4 -2
- package/dist/esm/ui/FloatingDragMenu/DragMenu.js +3 -2
- package/dist/esm/ui/FloatingDragMenu/index.js +7 -2
- package/dist/esm/ui/FloatingInsertButton/index.js +10 -4
- package/dist/esm/utils/drag-menu.js +3 -2
- package/dist/types/commands/insert.d.ts +3 -3
- package/dist/types/commands-with-analytics.d.ts +2 -2
- package/dist/types/pm-plugins/table-resizing/utils/index.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/utils/misc.d.ts +1 -0
- package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -0
- package/dist/types/ui/FloatingContextualMenu/index.d.ts +1 -1
- package/dist/types/ui/FloatingDragMenu/DragMenu.d.ts +2 -1
- package/dist/types/ui/FloatingDragMenu/index.d.ts +3 -2
- package/dist/types/ui/FloatingInsertButton/index.d.ts +2 -1
- package/dist/types/utils/drag-menu.d.ts +1 -1
- package/dist/types-ts4.5/commands/insert.d.ts +3 -3
- package/dist/types-ts4.5/commands-with-analytics.d.ts +2 -2
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/misc.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -0
- package/dist/types-ts4.5/ui/FloatingContextualMenu/index.d.ts +1 -1
- package/dist/types-ts4.5/ui/FloatingDragMenu/DragMenu.d.ts +2 -1
- package/dist/types-ts4.5/ui/FloatingDragMenu/index.d.ts +3 -2
- package/dist/types-ts4.5/ui/FloatingInsertButton/index.d.ts +2 -1
- package/dist/types-ts4.5/utils/drag-menu.d.ts +1 -1
- package/package.json +2 -2
- package/src/commands/insert.ts +16 -6
- package/src/commands-with-analytics.ts +13 -3
- package/src/plugin.tsx +8 -0
- package/src/pm-plugins/table-resizing/event-handlers.ts +43 -21
- package/src/pm-plugins/table-resizing/utils/index.ts +1 -1
- package/src/pm-plugins/table-resizing/utils/misc.ts +11 -0
- package/src/pm-plugins/table-resizing/utils/resize-column.ts +85 -65
- package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +21 -8
- package/src/ui/FloatingContextualMenu/index.tsx +2 -0
- package/src/ui/FloatingDragMenu/DragMenu.tsx +3 -0
- package/src/ui/FloatingDragMenu/index.tsx +11 -1
- package/src/ui/FloatingInsertButton/index.tsx +38 -11
- package/src/utils/drag-menu.ts +17 -11
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
getTableMaxWidth,
|
|
33
33
|
pointsAtCell,
|
|
34
34
|
resizeColumn,
|
|
35
|
+
resizeColumnAndTable,
|
|
35
36
|
updateControls,
|
|
36
37
|
} from './utils';
|
|
37
38
|
|
|
@@ -197,22 +198,31 @@ export const handleMouseDown = (
|
|
|
197
198
|
shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
198
199
|
}
|
|
199
200
|
|
|
200
|
-
const newResizeState = resizeColumn(
|
|
201
|
-
resizeState,
|
|
202
|
-
colIndex,
|
|
203
|
-
clientX - startX,
|
|
204
|
-
dom,
|
|
205
|
-
originalTable,
|
|
206
|
-
resizingSelectedColumns ? selectedColumns : undefined,
|
|
207
|
-
shouldScale,
|
|
208
|
-
);
|
|
209
|
-
|
|
210
201
|
const resizedDelta = clientX - startX;
|
|
211
202
|
|
|
212
|
-
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
213
|
-
|
|
214
203
|
if (getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
|
|
204
|
+
const newResizeState = resizeColumnAndTable(
|
|
205
|
+
resizeState,
|
|
206
|
+
colIndex,
|
|
207
|
+
clientX - startX,
|
|
208
|
+
dom,
|
|
209
|
+
originalTable,
|
|
210
|
+
resizingSelectedColumns ? selectedColumns : undefined,
|
|
211
|
+
shouldScale,
|
|
212
|
+
);
|
|
213
|
+
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
215
214
|
tr.setNodeAttribute(start - 1, 'width', newResizeState.tableWidth);
|
|
215
|
+
} else {
|
|
216
|
+
const newResizeState = resizeColumn(
|
|
217
|
+
resizeState,
|
|
218
|
+
colIndex,
|
|
219
|
+
clientX - startX,
|
|
220
|
+
dom,
|
|
221
|
+
originalTable,
|
|
222
|
+
resizingSelectedColumns ? selectedColumns : undefined,
|
|
223
|
+
shouldScale,
|
|
224
|
+
);
|
|
225
|
+
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
216
226
|
}
|
|
217
227
|
|
|
218
228
|
if (colIndex === map.width - 1) {
|
|
@@ -300,15 +310,27 @@ export const handleMouseDown = (
|
|
|
300
310
|
shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
301
311
|
}
|
|
302
312
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
313
|
+
if (getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
|
|
314
|
+
resizeColumnAndTable(
|
|
315
|
+
resizeState,
|
|
316
|
+
colIndex,
|
|
317
|
+
clientX - dragging.startX,
|
|
318
|
+
dom,
|
|
319
|
+
table,
|
|
320
|
+
undefined,
|
|
321
|
+
shouldScale,
|
|
322
|
+
);
|
|
323
|
+
} else {
|
|
324
|
+
resizeColumn(
|
|
325
|
+
resizeState,
|
|
326
|
+
colIndex,
|
|
327
|
+
clientX - dragging.startX,
|
|
328
|
+
dom,
|
|
329
|
+
table,
|
|
330
|
+
undefined,
|
|
331
|
+
shouldScale,
|
|
332
|
+
);
|
|
333
|
+
}
|
|
312
334
|
|
|
313
335
|
updateControls()(state);
|
|
314
336
|
}
|
|
@@ -42,7 +42,7 @@ export {
|
|
|
42
42
|
} from './scale-table';
|
|
43
43
|
export type { ScaleOptions } from './scale-table';
|
|
44
44
|
export type { ResizeState, ResizeStateWithAnalytics } from './types';
|
|
45
|
-
export { resizeColumn } from './resize-column';
|
|
45
|
+
export { resizeColumn, resizeColumnAndTable } from './resize-column';
|
|
46
46
|
export {
|
|
47
47
|
COLUMN_MIN_WIDTH,
|
|
48
48
|
TABLE_MAX_WIDTH,
|
|
@@ -167,3 +167,14 @@ export const getTableScalingPercent = (
|
|
|
167
167
|
scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
|
|
168
168
|
return Math.min(scalePercent, 1);
|
|
169
169
|
};
|
|
170
|
+
|
|
171
|
+
export const getStaticTableScalingPercent = (
|
|
172
|
+
table: PMNode,
|
|
173
|
+
tableRenderWidth: number,
|
|
174
|
+
) => {
|
|
175
|
+
const tableWidth = getTableContainerElementWidth(table);
|
|
176
|
+
// minus 1 here to avoid any 1px scroll in Firefox
|
|
177
|
+
let scalePercent = (tableRenderWidth - 1) / tableWidth;
|
|
178
|
+
scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
|
|
179
|
+
return Math.min(scalePercent, 1);
|
|
180
|
+
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Resize a given column by an amount from the current state
|
|
2
2
|
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
4
3
|
|
|
5
4
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
6
5
|
|
|
@@ -18,79 +17,100 @@ export const resizeColumn = (
|
|
|
18
17
|
selectedColumns?: number[],
|
|
19
18
|
isTableScalingEnabled = false,
|
|
20
19
|
): ResizeState => {
|
|
21
|
-
// If table resize to show overflowed content, we need to re calculate the resize amount because now offset = amount amount instead of amount * 2
|
|
22
20
|
let scalePercent = 1;
|
|
23
|
-
let resizeAmount
|
|
24
|
-
|
|
25
|
-
if (getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
|
|
26
|
-
// when table initially not overflow, but enter overflow, we need to calculate the resize amount by two part, before and after overflow, before overflow should be double, after should not be double.
|
|
27
|
-
const tableWidth = tableRef?.clientWidth;
|
|
28
|
-
const tableContainerWidth = tableRef?.closest('.resizer-item')?.clientWidth;
|
|
29
|
-
|
|
30
|
-
const isOverflowed = !!(
|
|
31
|
-
tableWidth &&
|
|
32
|
-
tableContainerWidth &&
|
|
33
|
-
tableWidth > tableContainerWidth
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
resizeAmount = amount * 2;
|
|
37
|
-
|
|
38
|
-
if (isOverflowed) {
|
|
39
|
-
resizeAmount =
|
|
40
|
-
amount < 0
|
|
41
|
-
? amount
|
|
42
|
-
: resizeAmount -
|
|
43
|
-
(tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2;
|
|
44
|
-
} else {
|
|
45
|
-
resizeAmount =
|
|
46
|
-
amount > 0 && tableContainerWidth
|
|
47
|
-
? resizeAmount -
|
|
48
|
-
(tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2
|
|
49
|
-
: resizeAmount;
|
|
50
|
-
}
|
|
51
|
-
} else {
|
|
52
|
-
resizeAmount = amount;
|
|
53
|
-
}
|
|
21
|
+
let resizeAmount = amount;
|
|
54
22
|
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
isTableScalingEnabled &&
|
|
58
|
-
!getBooleanFF('platform.editor.table.colum-resizing-improvements')
|
|
59
|
-
) {
|
|
23
|
+
if (isTableScalingEnabled) {
|
|
60
24
|
scalePercent = getTableScalingPercent(tableNode, tableRef);
|
|
61
25
|
resizeAmount = amount / scalePercent;
|
|
62
26
|
}
|
|
63
27
|
|
|
64
|
-
const newState =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
: resizeState;
|
|
73
|
-
|
|
74
|
-
getBooleanFF('platform.editor.table.colum-resizing-improvements')
|
|
75
|
-
? updateColgroup(newState, tableRef, tableNode, false)
|
|
76
|
-
: updateColgroup(newState, tableRef, tableNode, isTableScalingEnabled);
|
|
77
|
-
|
|
78
|
-
if (getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
|
|
79
|
-
// use the difference in width from affected column to update overall table width
|
|
80
|
-
const delta =
|
|
81
|
-
newState.cols[colIndex].width - resizeState.cols[colIndex].width;
|
|
82
|
-
|
|
83
|
-
updateTable(delta, tableRef, tableNode);
|
|
84
|
-
return {
|
|
85
|
-
...newState,
|
|
86
|
-
tableWidth: resizeState.tableWidth + delta,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
28
|
+
const newState =
|
|
29
|
+
resizeAmount > 0
|
|
30
|
+
? growColumn(resizeState, colIndex, resizeAmount, selectedColumns)
|
|
31
|
+
: resizeAmount < 0
|
|
32
|
+
? shrinkColumn(resizeState, colIndex, resizeAmount, selectedColumns)
|
|
33
|
+
: resizeState;
|
|
34
|
+
|
|
35
|
+
updateColgroup(newState, tableRef, tableNode, isTableScalingEnabled);
|
|
89
36
|
|
|
90
37
|
return newState;
|
|
91
38
|
};
|
|
92
39
|
|
|
93
|
-
|
|
40
|
+
// try not scale table during resize
|
|
41
|
+
export const resizeColumnAndTable = (
|
|
42
|
+
resizeState: ResizeState,
|
|
43
|
+
colIndex: number,
|
|
44
|
+
amount: number,
|
|
45
|
+
tableRef: HTMLElement,
|
|
46
|
+
tableNode: PmNode,
|
|
47
|
+
selectedColumns?: number[],
|
|
48
|
+
isTableScalingEnabled = false,
|
|
49
|
+
originalTableWidth?: number,
|
|
50
|
+
): ResizeState => {
|
|
51
|
+
// TODO: can we use document state, and apply scaling factor?
|
|
52
|
+
const tableWidth = tableRef.clientWidth;
|
|
53
|
+
const tableContainerWidth = tableRef.closest(
|
|
54
|
+
'.pm-table-container',
|
|
55
|
+
)?.clientWidth;
|
|
56
|
+
|
|
57
|
+
const isOverflowed = !!(
|
|
58
|
+
tableWidth &&
|
|
59
|
+
tableContainerWidth &&
|
|
60
|
+
tableWidth > tableContainerWidth
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
let resizeAmount = amount * 2;
|
|
64
|
+
|
|
65
|
+
// todo: reimplement - use getTableScalingPercentFrozen to get scaled percent before table width changes dynamically
|
|
66
|
+
// let scalePercent = 1;
|
|
67
|
+
// if (isTableScalingEnabled) {
|
|
68
|
+
// import from ./misc
|
|
69
|
+
// scalePercent = getStaticTableScalingPercent(
|
|
70
|
+
// tableNode,
|
|
71
|
+
// originalTableWidth || resizeState.maxSize,
|
|
72
|
+
// );
|
|
73
|
+
// resizeAmount = amount / scalePercent;
|
|
74
|
+
// }
|
|
75
|
+
|
|
76
|
+
// need to look at the resize amount and try to adjust the colgroups
|
|
77
|
+
if (isOverflowed) {
|
|
78
|
+
resizeAmount =
|
|
79
|
+
amount < 0
|
|
80
|
+
? amount
|
|
81
|
+
: resizeAmount -
|
|
82
|
+
(tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2;
|
|
83
|
+
} else {
|
|
84
|
+
resizeAmount =
|
|
85
|
+
amount > 0 && tableContainerWidth
|
|
86
|
+
? resizeAmount -
|
|
87
|
+
(tableNode.attrs.width + resizeAmount - tableContainerWidth) / 2
|
|
88
|
+
: resizeAmount;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const newState = updateAffectedColumn(resizeState, colIndex, resizeAmount);
|
|
92
|
+
|
|
93
|
+
// this function only updates the colgroup in DOM, it reverses the scalePercent
|
|
94
|
+
// todo: change isScalingEnabled to true when reimplementing scaling
|
|
95
|
+
updateColgroup(newState, tableRef, tableNode, false);
|
|
96
|
+
|
|
97
|
+
// use the difference in width from affected column to update overall table width
|
|
98
|
+
const delta =
|
|
99
|
+
newState.cols[colIndex].width - resizeState.cols[colIndex].width;
|
|
100
|
+
|
|
101
|
+
if (!isOverflowed) {
|
|
102
|
+
updateTablePreview(delta, tableRef, tableNode);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
...newState,
|
|
107
|
+
tableWidth: isOverflowed
|
|
108
|
+
? tableContainerWidth
|
|
109
|
+
: resizeState.tableWidth + delta,
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const updateTablePreview = (
|
|
94
114
|
resizeAmount: number,
|
|
95
115
|
tableRef: HTMLElement | null,
|
|
96
116
|
tableNode: PmNode,
|
|
@@ -101,7 +121,7 @@ const updateTable = (
|
|
|
101
121
|
);
|
|
102
122
|
const resizingItem = resizingContainer?.querySelector('.resizer-item');
|
|
103
123
|
|
|
104
|
-
if (
|
|
124
|
+
if (resizingItem) {
|
|
105
125
|
const newWidth = `${currentWidth + resizeAmount}px`;
|
|
106
126
|
if (tableRef) {
|
|
107
127
|
tableRef.style.width = newWidth;
|
|
@@ -539,12 +539,17 @@ export class ContextualMenu extends Component<
|
|
|
539
539
|
selectionRect,
|
|
540
540
|
editorAnalyticsAPI,
|
|
541
541
|
getEditorContainerWidth,
|
|
542
|
+
getEditorFeatureFlags,
|
|
542
543
|
} = this.props;
|
|
543
544
|
// TargetCellPosition could be outdated: https://product-fabric.atlassian.net/browse/ED-8129
|
|
544
545
|
const { state, dispatch } = editorView;
|
|
545
546
|
const { targetCellPosition, isTableScalingEnabled = false } =
|
|
546
547
|
getPluginState(state);
|
|
547
548
|
|
|
549
|
+
const { tableDuplicateCellColouring = false } = getEditorFeatureFlags
|
|
550
|
+
? getEditorFeatureFlags()
|
|
551
|
+
: {};
|
|
552
|
+
|
|
548
553
|
switch (item.value.name) {
|
|
549
554
|
case 'sort_column_desc':
|
|
550
555
|
sortColumnWithAnalytics(editorAnalyticsAPI)(
|
|
@@ -602,17 +607,25 @@ export class ContextualMenu extends Component<
|
|
|
602
607
|
this.toggleOpen();
|
|
603
608
|
break;
|
|
604
609
|
case 'insert_column':
|
|
605
|
-
insertColumnWithAnalytics(
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
610
|
+
insertColumnWithAnalytics(
|
|
611
|
+
editorAnalyticsAPI,
|
|
612
|
+
isTableScalingEnabled,
|
|
613
|
+
tableDuplicateCellColouring,
|
|
614
|
+
)(INPUT_METHOD.CONTEXT_MENU, selectionRect.right)(
|
|
615
|
+
state,
|
|
616
|
+
dispatch,
|
|
617
|
+
editorView,
|
|
618
|
+
);
|
|
609
619
|
this.toggleOpen();
|
|
610
620
|
break;
|
|
611
621
|
case 'insert_row':
|
|
612
|
-
insertRowWithAnalytics(editorAnalyticsAPI)(
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
622
|
+
insertRowWithAnalytics(editorAnalyticsAPI, tableDuplicateCellColouring)(
|
|
623
|
+
INPUT_METHOD.CONTEXT_MENU,
|
|
624
|
+
{
|
|
625
|
+
index: selectionRect.bottom,
|
|
626
|
+
moveCursorToInsertedRow: true,
|
|
627
|
+
},
|
|
628
|
+
)(state, dispatch);
|
|
616
629
|
this.toggleOpen();
|
|
617
630
|
break;
|
|
618
631
|
case 'delete_column':
|
|
@@ -53,6 +53,7 @@ const FloatingContextualMenu = ({
|
|
|
53
53
|
pluginConfig,
|
|
54
54
|
editorAnalyticsAPI,
|
|
55
55
|
getEditorContainerWidth,
|
|
56
|
+
getEditorFeatureFlags,
|
|
56
57
|
}: Props) => {
|
|
57
58
|
// TargetCellPosition could be outdated: https://product-fabric.atlassian.net/browse/ED-8129
|
|
58
59
|
const { targetCellPosition, isDragAndDropEnabled } = getPluginState(
|
|
@@ -122,6 +123,7 @@ const FloatingContextualMenu = ({
|
|
|
122
123
|
boundariesElement={boundariesElement}
|
|
123
124
|
editorAnalyticsAPI={editorAnalyticsAPI}
|
|
124
125
|
getEditorContainerWidth={getEditorContainerWidth}
|
|
126
|
+
getEditorFeatureFlags={getEditorFeatureFlags}
|
|
125
127
|
/>
|
|
126
128
|
</div>
|
|
127
129
|
</Popup>
|
|
@@ -102,6 +102,7 @@ type DragMenuProps = {
|
|
|
102
102
|
boundariesElement?: HTMLElement;
|
|
103
103
|
scrollableElement?: HTMLElement;
|
|
104
104
|
isTableScalingEnabled?: boolean;
|
|
105
|
+
tableDuplicateCellColouring?: boolean;
|
|
105
106
|
};
|
|
106
107
|
|
|
107
108
|
type PluralOptionType = 'noOfCols' | 'noOfRows' | 'noOfCells' | null;
|
|
@@ -281,6 +282,7 @@ export const DragMenu = React.memo(
|
|
|
281
282
|
scrollableElement,
|
|
282
283
|
boundariesElement,
|
|
283
284
|
isTableScalingEnabled,
|
|
285
|
+
tableDuplicateCellColouring,
|
|
284
286
|
}: DragMenuProps & WrappedComponentProps) => {
|
|
285
287
|
const { state, dispatch } = editorView;
|
|
286
288
|
const { selection } = state;
|
|
@@ -324,6 +326,7 @@ export const DragMenu = React.memo(
|
|
|
324
326
|
editorAnalyticsAPI,
|
|
325
327
|
pluginConfig?.isHeaderRowRequired,
|
|
326
328
|
isTableScalingEnabled,
|
|
329
|
+
tableDuplicateCellColouring,
|
|
327
330
|
);
|
|
328
331
|
|
|
329
332
|
const { menuItems, menuCallback } = convertToDropdownItems(
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
3
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
GetEditorContainerWidth,
|
|
6
|
+
GetEditorFeatureFlags,
|
|
7
|
+
} from '@atlaskit/editor-common/types';
|
|
5
8
|
import { Popup } from '@atlaskit/editor-common/ui';
|
|
6
9
|
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
7
10
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
@@ -33,6 +36,7 @@ export interface Props {
|
|
|
33
36
|
stickyHeaders?: RowStickyState;
|
|
34
37
|
pluginConfig?: PluginConfig;
|
|
35
38
|
isTableScalingEnabled?: boolean;
|
|
39
|
+
getEditorFeatureFlags?: GetEditorFeatureFlags;
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
const FloatingDragMenu = ({
|
|
@@ -50,6 +54,7 @@ const FloatingDragMenu = ({
|
|
|
50
54
|
stickyHeaders,
|
|
51
55
|
pluginConfig,
|
|
52
56
|
isTableScalingEnabled,
|
|
57
|
+
getEditorFeatureFlags,
|
|
53
58
|
}: Props) => {
|
|
54
59
|
if (
|
|
55
60
|
!isOpen ||
|
|
@@ -74,6 +79,10 @@ const FloatingDragMenu = ({
|
|
|
74
79
|
return null;
|
|
75
80
|
}
|
|
76
81
|
|
|
82
|
+
const { tableDuplicateCellColouring = false } = getEditorFeatureFlags
|
|
83
|
+
? getEditorFeatureFlags()
|
|
84
|
+
: {};
|
|
85
|
+
|
|
77
86
|
return (
|
|
78
87
|
<Popup
|
|
79
88
|
alignX={direction === 'row' ? 'right' : undefined}
|
|
@@ -113,6 +122,7 @@ const FloatingDragMenu = ({
|
|
|
113
122
|
boundariesElement={boundariesElement}
|
|
114
123
|
scrollableElement={scrollableElement}
|
|
115
124
|
isTableScalingEnabled={isTableScalingEnabled}
|
|
125
|
+
tableDuplicateCellColouring={tableDuplicateCellColouring}
|
|
116
126
|
/>
|
|
117
127
|
</Popup>
|
|
118
128
|
);
|
|
@@ -15,7 +15,10 @@ import {
|
|
|
15
15
|
EVENT_TYPE,
|
|
16
16
|
INPUT_METHOD,
|
|
17
17
|
} from '@atlaskit/editor-common/analytics';
|
|
18
|
-
import type {
|
|
18
|
+
import type {
|
|
19
|
+
GetEditorContainerWidth,
|
|
20
|
+
GetEditorFeatureFlags,
|
|
21
|
+
} from '@atlaskit/editor-common/types';
|
|
19
22
|
import { Popup } from '@atlaskit/editor-common/ui';
|
|
20
23
|
import { closestElement } from '@atlaskit/editor-common/utils';
|
|
21
24
|
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
@@ -53,6 +56,7 @@ export interface Props {
|
|
|
53
56
|
hasStickyHeaders?: boolean;
|
|
54
57
|
dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
|
|
55
58
|
editorAnalyticsAPI?: EditorAnalyticsAPI;
|
|
59
|
+
getEditorFeatureFlags?: GetEditorFeatureFlags;
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
export class FloatingInsertButton extends React.Component<
|
|
@@ -94,8 +98,8 @@ export class FloatingInsertButton extends React.Component<
|
|
|
94
98
|
typeof insertColumnButtonIndex !== 'undefined'
|
|
95
99
|
? 'column'
|
|
96
100
|
: typeof insertRowButtonIndex !== 'undefined'
|
|
97
|
-
|
|
98
|
-
|
|
101
|
+
? 'row'
|
|
102
|
+
: null;
|
|
99
103
|
|
|
100
104
|
if (!tableNode || !tableRef || !type) {
|
|
101
105
|
return null;
|
|
@@ -261,13 +265,23 @@ export class FloatingInsertButton extends React.Component<
|
|
|
261
265
|
}
|
|
262
266
|
|
|
263
267
|
private insertRow(event: React.SyntheticEvent) {
|
|
264
|
-
const {
|
|
268
|
+
const {
|
|
269
|
+
editorView,
|
|
270
|
+
insertRowButtonIndex,
|
|
271
|
+
editorAnalyticsAPI,
|
|
272
|
+
getEditorFeatureFlags,
|
|
273
|
+
} = this.props;
|
|
265
274
|
|
|
266
275
|
if (typeof insertRowButtonIndex !== 'undefined') {
|
|
267
276
|
event.preventDefault();
|
|
268
277
|
|
|
269
278
|
const { state, dispatch } = editorView;
|
|
270
|
-
|
|
279
|
+
const featureFlags = !!getEditorFeatureFlags && getEditorFeatureFlags();
|
|
280
|
+
|
|
281
|
+
insertRowWithAnalytics(
|
|
282
|
+
editorAnalyticsAPI,
|
|
283
|
+
featureFlags && featureFlags.tableDuplicateCellColouring,
|
|
284
|
+
)(INPUT_METHOD.BUTTON, {
|
|
271
285
|
index: insertRowButtonIndex,
|
|
272
286
|
moveCursorToInsertedRow: true,
|
|
273
287
|
})(state, dispatch);
|
|
@@ -275,8 +289,12 @@ export class FloatingInsertButton extends React.Component<
|
|
|
275
289
|
}
|
|
276
290
|
|
|
277
291
|
private insertColumn(event: React.SyntheticEvent) {
|
|
278
|
-
const {
|
|
279
|
-
|
|
292
|
+
const {
|
|
293
|
+
editorView,
|
|
294
|
+
insertColumnButtonIndex,
|
|
295
|
+
editorAnalyticsAPI,
|
|
296
|
+
getEditorFeatureFlags,
|
|
297
|
+
} = this.props;
|
|
280
298
|
|
|
281
299
|
if (typeof insertColumnButtonIndex !== 'undefined') {
|
|
282
300
|
event.preventDefault();
|
|
@@ -285,11 +303,20 @@ export class FloatingInsertButton extends React.Component<
|
|
|
285
303
|
editorView.state,
|
|
286
304
|
);
|
|
287
305
|
|
|
306
|
+
const { tableDuplicateCellColouring = false } = getEditorFeatureFlags
|
|
307
|
+
? getEditorFeatureFlags()
|
|
308
|
+
: {};
|
|
309
|
+
|
|
288
310
|
const { state, dispatch } = editorView;
|
|
289
|
-
insertColumnWithAnalytics(
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
311
|
+
insertColumnWithAnalytics(
|
|
312
|
+
editorAnalyticsAPI,
|
|
313
|
+
isTableScalingEnabled,
|
|
314
|
+
tableDuplicateCellColouring,
|
|
315
|
+
)(INPUT_METHOD.BUTTON, insertColumnButtonIndex)(
|
|
316
|
+
state,
|
|
317
|
+
dispatch,
|
|
318
|
+
editorView,
|
|
319
|
+
);
|
|
293
320
|
}
|
|
294
321
|
}
|
|
295
322
|
}
|
package/src/utils/drag-menu.ts
CHANGED
|
@@ -177,6 +177,7 @@ export const getDragMenuConfig = (
|
|
|
177
177
|
editorAnalyticsAPI?: EditorAnalyticsAPI,
|
|
178
178
|
isHeaderRowRequired?: boolean,
|
|
179
179
|
isTableScalingEnabled = false,
|
|
180
|
+
tableDuplicateCellColouring = false,
|
|
180
181
|
): DragMenuConfig[] => {
|
|
181
182
|
const addOptions =
|
|
182
183
|
direction === 'row'
|
|
@@ -303,18 +304,23 @@ export const getDragMenuConfig = (
|
|
|
303
304
|
icon,
|
|
304
305
|
onClick: (state: EditorState, dispatch?: CommandDispatch) => {
|
|
305
306
|
if (direction === 'row') {
|
|
306
|
-
insertRowWithAnalytics(
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
)(state, dispatch);
|
|
307
|
+
insertRowWithAnalytics(
|
|
308
|
+
editorAnalyticsAPI,
|
|
309
|
+
tableDuplicateCellColouring,
|
|
310
|
+
)(INPUT_METHOD.TABLE_CONTEXT_MENU, {
|
|
311
|
+
index: (index ?? 0) + offset,
|
|
312
|
+
moveCursorToInsertedRow: true,
|
|
313
|
+
})(state, dispatch);
|
|
313
314
|
} else {
|
|
314
|
-
insertColumnWithAnalytics(
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
315
|
+
insertColumnWithAnalytics(
|
|
316
|
+
editorAnalyticsAPI,
|
|
317
|
+
isTableScalingEnabled,
|
|
318
|
+
tableDuplicateCellColouring,
|
|
319
|
+
)(INPUT_METHOD.TABLE_CONTEXT_MENU, (index ?? 0) + offset)(
|
|
320
|
+
state,
|
|
321
|
+
dispatch,
|
|
322
|
+
editorView,
|
|
323
|
+
);
|
|
318
324
|
}
|
|
319
325
|
return true;
|
|
320
326
|
},
|