@atlaskit/editor-plugin-table 5.4.7 → 5.4.9

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.
Files changed (60) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/plugins/table/commands/misc.js +14 -12
  3. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +2 -4
  4. package/dist/cjs/plugins/table/pm-plugins/decorations/plugin.js +9 -3
  5. package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-controls.js +8 -3
  6. package/dist/cjs/plugins/table/types.js +2 -1
  7. package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +3 -1
  8. package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +4 -1
  9. package/dist/cjs/plugins/table/ui/common-styles.js +6 -9
  10. package/dist/cjs/plugins/table/ui/ui-styles.js +12 -16
  11. package/dist/cjs/plugins/table/utils/decoration.js +20 -25
  12. package/dist/cjs/plugins/table/utils/drag-menu.js +2 -2
  13. package/dist/es2019/plugins/table/commands/misc.js +5 -4
  14. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +2 -4
  15. package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +9 -3
  16. package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +8 -3
  17. package/dist/es2019/plugins/table/types.js +2 -1
  18. package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +4 -2
  19. package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +4 -1
  20. package/dist/es2019/plugins/table/ui/common-styles.js +20 -20
  21. package/dist/es2019/plugins/table/ui/ui-styles.js +18 -21
  22. package/dist/es2019/plugins/table/utils/decoration.js +20 -25
  23. package/dist/es2019/plugins/table/utils/drag-menu.js +2 -2
  24. package/dist/esm/plugins/table/commands/misc.js +13 -13
  25. package/dist/esm/plugins/table/nodeviews/TableComponent.js +2 -4
  26. package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +9 -3
  27. package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +8 -3
  28. package/dist/esm/plugins/table/types.js +2 -1
  29. package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +4 -2
  30. package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +4 -1
  31. package/dist/esm/plugins/table/ui/common-styles.js +6 -9
  32. package/dist/esm/plugins/table/ui/ui-styles.js +12 -16
  33. package/dist/esm/plugins/table/utils/decoration.js +20 -25
  34. package/dist/esm/plugins/table/utils/drag-menu.js +2 -2
  35. package/dist/types/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +3 -2
  36. package/dist/types/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +1 -1
  37. package/dist/types/plugins/table/pm-plugins/decorations/utils/types.d.ts +10 -4
  38. package/dist/types/plugins/table/types.d.ts +2 -1
  39. package/dist/types/plugins/table/utils/drag-menu.d.ts +1 -1
  40. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +3 -2
  41. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +1 -1
  42. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/types.d.ts +10 -4
  43. package/dist/types-ts4.5/plugins/table/types.d.ts +2 -1
  44. package/dist/types-ts4.5/plugins/table/utils/drag-menu.d.ts +1 -1
  45. package/package.json +1 -1
  46. package/src/__tests__/unit/event-handlers.ts +37 -38
  47. package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +46 -36
  48. package/src/plugins/table/commands/misc.ts +9 -7
  49. package/src/plugins/table/nodeviews/TableComponent.tsx +20 -22
  50. package/src/plugins/table/pm-plugins/decorations/plugin.ts +7 -2
  51. package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +20 -11
  52. package/src/plugins/table/pm-plugins/decorations/utils/compose-decorations.ts +2 -4
  53. package/src/plugins/table/pm-plugins/decorations/utils/types.ts +14 -7
  54. package/src/plugins/table/types.ts +2 -1
  55. package/src/plugins/table/ui/FloatingDragMenu/DragMenu.tsx +12 -1
  56. package/src/plugins/table/ui/TableFloatingControls/index.tsx +73 -67
  57. package/src/plugins/table/ui/common-styles.ts +20 -23
  58. package/src/plugins/table/ui/ui-styles.ts +18 -21
  59. package/src/plugins/table/utils/decoration.ts +27 -32
  60. package/src/plugins/table/utils/drag-menu.ts +8 -2
@@ -26,7 +26,7 @@ import {
26
26
  tdEmpty,
27
27
  tr,
28
28
  } from '@atlaskit/editor-test-helpers/doc-builder';
29
- import { ffTest } from '@atlassian/feature-flags-test-utils';
29
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
30
30
 
31
31
  import tablePlugin from '../../plugins/table-plugin';
32
32
  import {
@@ -44,6 +44,15 @@ import { getPluginState } from '../../plugins/table/pm-plugins/plugin-factory';
44
44
  import { pluginKey } from '../../plugins/table/pm-plugins/plugin-key';
45
45
  import { TableCssClassName as ClassName } from '../../plugins/table/types';
46
46
 
47
+ // Mock Feature flags instead of using ffTest because we don't use the feature flag directly
48
+ jest.mock('@atlaskit/platform-feature-flags', () => ({
49
+ getBooleanFF: jest.fn().mockImplementation(() => false),
50
+ }));
51
+
52
+ afterEach(() => {
53
+ (getBooleanFF as jest.Mock).mockReset();
54
+ });
55
+
47
56
  describe('table plugin: decorations', () => {
48
57
  const createEditor = createProsemirrorEditorFactory();
49
58
  const editor = (doc: DocBuilder) =>
@@ -263,49 +272,39 @@ describe('withCellTracking', () => {
263
272
  });
264
273
 
265
274
  describe('should fire event handler passed in', () => {
266
- ffTest(
267
- 'platform.editor.table.drag-and-drop',
268
- () => {
269
- const { editorView } = editor(
270
- doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
271
- true,
272
- );
273
- const eventHandlerSpy = jest.fn();
274
- withCellTracking(eventHandlerSpy)(editorView, {} as any);
275
-
276
- expect(eventHandlerSpy).toHaveBeenCalled();
277
- },
278
- () => {
279
- const { editorView } = editor(
280
- doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
281
- );
282
- const eventHandlerSpy = jest.fn();
283
- withCellTracking(eventHandlerSpy)(editorView, {} as any);
284
-
285
- expect(eventHandlerSpy).toHaveBeenCalled();
286
- },
275
+ (getBooleanFF as jest.Mock).mockImplementation(
276
+ (name) => name === 'platform.editor.table.drag-and-drop',
287
277
  );
278
+ const { editorView } = editor(
279
+ doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
280
+ true,
281
+ );
282
+ const eventHandlerSpy = jest.fn();
283
+ withCellTracking(eventHandlerSpy)(editorView, {} as any);
284
+
285
+ expect(eventHandlerSpy).toHaveBeenCalled();
288
286
  });
289
287
 
290
- describe('should correctly set table cell coordinates based on mouse location', () => {
291
- ffTest('platform.editor.table.drag-and-drop', () => {
292
- const { editorView, refs } = editor(
293
- doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
294
- true,
295
- );
296
- const firstCell = editorView.domAtPos(refs['<>']);
288
+ it('should correctly set table cell coordinates based on mouse location', () => {
289
+ (getBooleanFF as jest.Mock).mockImplementation(
290
+ (name) => name === 'platform.editor.table.drag-and-drop',
291
+ );
292
+ const { editorView, refs } = editor(
293
+ doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
294
+ true,
295
+ );
296
+ const firstCell = editorView.domAtPos(refs['<>']);
297
297
 
298
- const event = {
299
- target: firstCell.node,
300
- };
298
+ const event = {
299
+ target: firstCell.node,
300
+ };
301
301
 
302
- withCellTracking(jest.fn())(editorView, event as any);
302
+ withCellTracking(jest.fn())(editorView, event as any);
303
303
 
304
- const pluginState = getPluginState(editorView.state);
305
- expect(pluginState.hoveredCell).toEqual({
306
- colIndex: undefined,
307
- rowIndex: undefined,
308
- });
304
+ const pluginState = getPluginState(editorView.state);
305
+ expect(pluginState.hoveredCell).toEqual({
306
+ colIndex: undefined,
307
+ rowIndex: undefined,
309
308
  });
310
309
  });
311
310
  });
@@ -9,47 +9,57 @@ import {
9
9
  tdEmpty,
10
10
  tr,
11
11
  } from '@atlaskit/editor-test-helpers/doc-builder';
12
- import { ffTest } from '@atlassian/feature-flags-test-utils';
12
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
13
13
 
14
14
  import { buildColumnControlsDecorations } from '../../../../plugins/table/pm-plugins/decorations/utils';
15
15
  import { TableDecorations } from '../../../../plugins/table/types';
16
16
 
17
+ // Mock Feature flags instead of using ffTest because we don't use the feature flag directly
18
+ jest.mock('@atlaskit/platform-feature-flags', () => ({
19
+ getBooleanFF: jest.fn().mockImplementation(() => false),
20
+ }));
21
+
22
+ afterEach(() => {
23
+ (getBooleanFF as jest.Mock).mockReset();
24
+ });
25
+
17
26
  describe('tables: column controls decorations', () => {
18
- describe(`should return a decorationSet with 2 ${TableDecorations.COLUMN_CONTROLS_DECORATIONS} type when drag and drop disabled`, () => {
19
- ffTest(
20
- 'platform.editor.table.drag-and-drop',
21
- () => {
22
- const decorationKey = TableDecorations.COLUMN_CONTROLS_DECORATIONS;
23
- const state = createEditorState(doc(table()(tr(tdCursor, tdEmpty))));
24
- const nextDecorationSet = buildColumnControlsDecorations({
25
- decorationSet: DecorationSet.empty,
26
- tr: state.tr,
27
- });
28
-
29
- const decorations = nextDecorationSet.find(
30
- undefined,
31
- undefined,
32
- (spec: any) => spec.key.indexOf(decorationKey) > -1,
33
- );
34
-
35
- expect(decorations).toHaveLength(0);
36
- },
37
- () => {
38
- const decorationKey = TableDecorations.COLUMN_CONTROLS_DECORATIONS;
39
- const state = createEditorState(doc(table()(tr(tdCursor, tdEmpty))));
40
- const nextDecorationSet = buildColumnControlsDecorations({
41
- decorationSet: DecorationSet.empty,
42
- tr: state.tr,
43
- });
44
-
45
- const decorations = nextDecorationSet.find(
46
- undefined,
47
- undefined,
48
- (spec: any) => spec.key.indexOf(decorationKey) > -1,
49
- );
50
-
51
- expect(decorations).toHaveLength(2);
52
- },
27
+ it(`should return an empty decorationSet ${TableDecorations.COLUMN_CONTROLS_DECORATIONS} type when drag and drop is enabled`, () => {
28
+ (getBooleanFF as jest.Mock).mockImplementation(
29
+ (name) => name === 'platform.editor.table.drag-and-drop',
53
30
  );
31
+ const decorationKey = TableDecorations.COLUMN_CONTROLS_DECORATIONS;
32
+ const state = createEditorState(doc(table()(tr(tdCursor, tdEmpty))));
33
+ const nextDecorationSet = buildColumnControlsDecorations({
34
+ decorationSet: DecorationSet.empty,
35
+ tr: state.tr,
36
+ options: { isDragAndDropEnabled: true },
37
+ });
38
+
39
+ const decorations = nextDecorationSet.find(
40
+ undefined,
41
+ undefined,
42
+ (spec: any) => spec.key.indexOf(decorationKey) > -1,
43
+ );
44
+
45
+ expect(decorations).toHaveLength(0);
46
+ });
47
+
48
+ it(`should return an empty decorationSet ${TableDecorations.COLUMN_CONTROLS_DECORATIONS} type when drag and drop is disabled`, () => {
49
+ const decorationKey = TableDecorations.COLUMN_CONTROLS_DECORATIONS;
50
+ const state = createEditorState(doc(table()(tr(tdCursor, tdEmpty))));
51
+ const nextDecorationSet = buildColumnControlsDecorations({
52
+ decorationSet: DecorationSet.empty,
53
+ tr: state.tr,
54
+ options: { isDragAndDropEnabled: false },
55
+ });
56
+
57
+ const decorations = nextDecorationSet.find(
58
+ undefined,
59
+ undefined,
60
+ (spec: any) => spec.key.indexOf(decorationKey) > -1,
61
+ );
62
+
63
+ expect(decorations).toHaveLength(2);
54
64
  });
55
65
  });
@@ -1,4 +1,3 @@
1
- // #region Imports
2
1
  import type { CellAttributes } from '@atlaskit/adf-schema';
3
2
  import type { Command } from '@atlaskit/editor-common/types';
4
3
  import {
@@ -76,11 +75,7 @@ export const setTableRef = (ref?: HTMLTableElement) =>
76
75
  closestElement(tableRef, `.${ClassName.TABLE_NODE_WRAPPER}`) ||
77
76
  undefined;
78
77
  const layout = tableNode ? tableNode.attrs.layout : undefined;
79
- const decorationSet = updatePluginStateDecorations(
80
- state,
81
- createColumnControlsDecoration(state.selection),
82
- TableDecorations.COLUMN_CONTROLS_DECORATIONS,
83
- );
78
+ const { isDragAndDropEnabled } = getPluginState(state);
84
79
 
85
80
  return {
86
81
  type: 'SET_TABLE_REF',
@@ -93,7 +88,14 @@ export const setTableRef = (ref?: HTMLTableElement) =>
93
88
  isNumberColumnEnabled: checkIfNumberColumnEnabled(state.selection),
94
89
  isHeaderRowEnabled: checkIfHeaderRowEnabled(state.selection),
95
90
  isHeaderColumnEnabled: checkIfHeaderColumnEnabled(state.selection),
96
- decorationSet,
91
+ // decoration set is drawn by the decoration plugin, skip this for DnD as all controls are floating
92
+ decorationSet: !isDragAndDropEnabled
93
+ ? updatePluginStateDecorations(
94
+ state,
95
+ createColumnControlsDecoration(state.selection),
96
+ TableDecorations.COLUMN_CONTROLS_DECORATIONS,
97
+ )
98
+ : undefined,
97
99
  resizeHandleRowIndex: undefined,
98
100
  resizeHandleColumnIndex: undefined,
99
101
  },
@@ -483,28 +483,26 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
483
483
 
484
484
  const hasHeaderRow = containsHeaderRow(node);
485
485
  const rowControls = (
486
- <div className={ClassName.ROW_CONTROLS_WRAPPER}>
487
- <TableFloatingControls
488
- editorView={view}
489
- tableRef={tableRef}
490
- tableNode={node}
491
- tableActive={tableActive}
492
- hoveredRows={hoveredRows}
493
- hoveredCell={hoveredCell}
494
- isInDanger={isInDanger}
495
- isResizing={isResizing}
496
- isNumberColumnEnabled={node.attrs.isNumberColumnEnabled}
497
- isHeaderRowEnabled={isHeaderRowEnabled}
498
- isDragAndDropEnabled={isDragAndDropEnabled}
499
- ordering={ordering}
500
- isHeaderColumnEnabled={isHeaderColumnEnabled}
501
- hasHeaderRow={hasHeaderRow}
502
- // pass `selection` and `tableHeight` to control re-render
503
- selection={view.state.selection}
504
- headerRowHeight={headerRow ? headerRow.offsetHeight : undefined}
505
- stickyHeader={this.state.stickyHeader}
506
- />
507
- </div>
486
+ <TableFloatingControls
487
+ editorView={view}
488
+ tableRef={tableRef}
489
+ tableNode={node}
490
+ tableActive={tableActive}
491
+ hoveredRows={hoveredRows}
492
+ hoveredCell={hoveredCell}
493
+ isInDanger={isInDanger}
494
+ isResizing={isResizing}
495
+ isNumberColumnEnabled={node.attrs.isNumberColumnEnabled}
496
+ isHeaderRowEnabled={isHeaderRowEnabled}
497
+ isDragAndDropEnabled={isDragAndDropEnabled}
498
+ ordering={ordering}
499
+ isHeaderColumnEnabled={isHeaderColumnEnabled}
500
+ hasHeaderRow={hasHeaderRow}
501
+ // pass `selection` and `tableHeight` to control re-render
502
+ selection={view.state.selection}
503
+ headerRowHeight={headerRow ? headerRow.offsetHeight : undefined}
504
+ stickyHeader={this.state.stickyHeader}
505
+ />
508
506
  );
509
507
 
510
508
  const colControls = isDragAndDropEnabled ? (
@@ -8,7 +8,6 @@ import type {
8
8
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
9
9
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
10
10
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
11
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
12
11
 
13
12
  import { pluginKey as tablePluginKey } from '../plugin-key';
14
13
  import { pluginKey as tableWidthPluginKey } from '../table-width';
@@ -31,11 +30,13 @@ export const handleDocOrSelectionChanged = (
31
30
  ): DecorationSet => {
32
31
  const isResizing = tableWidthPluginKey.getState(newState)?.resizing;
33
32
  const wasResizing = tableWidthPluginKey.getState(oldState)?.resizing;
33
+ const { isDragAndDropEnabled = false } =
34
+ tablePluginKey.getState(newState) || {};
34
35
 
35
36
  const changedResizing = isResizing !== wasResizing;
36
37
 
37
38
  // Remove column controls when resizing and don't add column decoration controls when DnD enabled
38
- if (isResizing || getBooleanFF('platform.editor.table.drag-and-drop')) {
39
+ if (isResizing) {
39
40
  return DecorationSet.empty;
40
41
  } else if (
41
42
  tr.docChanged ||
@@ -45,6 +46,9 @@ export const handleDocOrSelectionChanged = (
45
46
  return buildColumnControlsDecorations({
46
47
  decorationSet,
47
48
  tr,
49
+ options: {
50
+ isDragAndDropEnabled,
51
+ },
48
52
  });
49
53
  } else if (tr.selectionSet) {
50
54
  const isTransactionFromMouseClick =
@@ -70,6 +74,7 @@ export const createPlugin = () => {
70
74
 
71
75
  apply: (tr, decorationSet, oldState, newState) => {
72
76
  let pluginState = decorationSet;
77
+ // main table plugin --->
73
78
  const meta = tr.getMeta(tablePluginKey);
74
79
 
75
80
  if (meta && meta.data && meta.data.decorationSet) {
@@ -17,7 +17,10 @@ import {
17
17
  } from '../../../utils/decoration';
18
18
 
19
19
  import { composeDecorations } from './compose-decorations';
20
- import type { DecorationTransformer } from './types';
20
+ import type {
21
+ BuildDecorationTransformerParams,
22
+ DecorationTransformer,
23
+ } from './types';
21
24
 
22
25
  const isColumnSelected = (tr: Transaction | ReadonlyTransaction): boolean =>
23
26
  tr.selection instanceof CellSelection && tr.selection.isColSelection();
@@ -25,13 +28,12 @@ const isColumnSelected = (tr: Transaction | ReadonlyTransaction): boolean =>
25
28
  // @see: https://product-fabric.atlassian.net/browse/ED-3796
26
29
  const removeControlsHoverDecoration: DecorationTransformer = ({
27
30
  decorationSet,
28
- }): DecorationSet =>
29
- decorationSet.remove(findControlsHoverDecoration(decorationSet));
31
+ }) => decorationSet.remove(findControlsHoverDecoration(decorationSet));
30
32
 
31
33
  const maybeUpdateColumnSelectedDecoration: DecorationTransformer = ({
32
34
  decorationSet,
33
35
  tr,
34
- }): DecorationSet => {
36
+ }) => {
35
37
  if (!isColumnSelected(tr)) {
36
38
  return decorationSet;
37
39
  }
@@ -47,10 +49,9 @@ const maybeUpdateColumnSelectedDecoration: DecorationTransformer = ({
47
49
  const maybeUpdateColumnControlsDecoration: DecorationTransformer = ({
48
50
  decorationSet,
49
51
  tr,
50
- }): DecorationSet => {
52
+ }) => {
51
53
  const table = findTable(tr.selection);
52
54
 
53
- // avoid re-drawing state if dnd decorations don't need to be updated
54
55
  if (!table) {
55
56
  return decorationSet;
56
57
  }
@@ -66,14 +67,13 @@ const maybeUpdateColumnControlsDecoration: DecorationTransformer = ({
66
67
  // @see: https://product-fabric.atlassian.net/browse/ED-7304
67
68
  const removeColumnControlsSelectedDecoration: DecorationTransformer = ({
68
69
  decorationSet,
69
- }): DecorationSet =>
70
- decorationSet.remove(findColumnControlSelectedDecoration(decorationSet));
70
+ }) => decorationSet.remove(findColumnControlSelectedDecoration(decorationSet));
71
71
 
72
72
  const hasColumnSelectedDecorations = (decorationSet: DecorationSet): boolean =>
73
73
  !!findColumnControlSelectedDecoration(decorationSet).length;
74
74
 
75
75
  export const maybeUpdateColumnControlsSelectedDecoration: DecorationTransformer =
76
- ({ decorationSet, tr }): DecorationSet => {
76
+ ({ decorationSet, tr }) => {
77
77
  if (!hasColumnSelectedDecorations(decorationSet)) {
78
78
  return decorationSet;
79
79
  }
@@ -81,10 +81,19 @@ export const maybeUpdateColumnControlsSelectedDecoration: DecorationTransformer
81
81
  return removeColumnControlsSelectedDecoration({ decorationSet, tr });
82
82
  };
83
83
 
84
- export const buildColumnControlsDecorations: DecorationTransformer = ({
84
+ export const buildColumnControlsDecorations = ({
85
85
  decorationSet,
86
86
  tr,
87
- }): DecorationSet => {
87
+ options,
88
+ }: BuildDecorationTransformerParams): DecorationSet => {
89
+ if (options.isDragAndDropEnabled) {
90
+ return composeDecorations([
91
+ removeColumnControlsSelectedDecoration,
92
+ removeControlsHoverDecoration,
93
+ maybeUpdateColumnSelectedDecoration,
94
+ ])({ decorationSet, tr });
95
+ }
96
+
88
97
  return composeDecorations([
89
98
  removeColumnControlsSelectedDecoration,
90
99
  removeControlsHoverDecoration,
@@ -1,10 +1,8 @@
1
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
2
-
3
- import { DecorationTransformer } from './types';
1
+ import type { DecorationTransformer } from './types';
4
2
 
5
3
  export const composeDecorations =
6
4
  (transformers: Array<DecorationTransformer>): DecorationTransformer =>
7
- ({ decorationSet, tr }): DecorationSet =>
5
+ ({ decorationSet, tr }) =>
8
6
  transformers.reduce(
9
7
  (decorationSet, transform) => transform({ decorationSet, tr }),
10
8
  decorationSet,
@@ -1,14 +1,21 @@
1
1
  // @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
2
- import {
2
+ import type {
3
3
  ReadonlyTransaction,
4
4
  Transaction,
5
5
  } from '@atlaskit/editor-prosemirror/state';
6
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
6
+ import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
7
 
8
- export type DecorationTransformer = ({
9
- decorationSet,
10
- tr,
11
- }: {
8
+ export type DecorationTransformer = (
9
+ params: DecorationTransformerParams,
10
+ ) => DecorationSet;
11
+
12
+ export type DecorationTransformerParams = {
12
13
  decorationSet: DecorationSet;
13
14
  tr: Transaction | ReadonlyTransaction;
14
- }) => DecorationSet;
15
+ };
16
+
17
+ export type BuildDecorationTransformerParams = DecorationTransformerParams & {
18
+ options: {
19
+ isDragAndDropEnabled: boolean;
20
+ };
21
+ };
@@ -309,7 +309,8 @@ export const TableCssClassName = {
309
309
  CORNER_CONTROLS_INSERT_COLUMN_MARKER: `${tablePrefixSelector}-corner-controls__insert-column-marker`,
310
310
  CONTROLS_CORNER_BUTTON: `${tablePrefixSelector}-corner-button`,
311
311
 
312
- /** Controls with drag handle */
312
+ /** drag and drop controls */
313
+ DRAG_ROW_CONTROLS_WRAPPER: `${tablePrefixSelector}-drag-row-controls-wrapper`,
313
314
  DRAG_ROW_CONTROLS: `${tablePrefixSelector}-drag-row-controls`,
314
315
  DRAG_ROW_FLOATING_INSERT_DOT_WRAPPER: `${tablePrefixSelector}-drag-row-floating-insert-dot-wrapper`,
315
316
  DRAG_ROW_FLOATING_INSERT_DOT: `${tablePrefixSelector}-drag-row-floating-insert-dot`,
@@ -26,7 +26,12 @@ import { clearHoverSelection, hoverColumns, hoverRows } from '../../commands';
26
26
  import { toggleDragMenu } from '../../pm-plugins/drag-and-drop/commands';
27
27
  import { getPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
28
28
  import type { PluginConfig, TableDirection } from '../../types';
29
- import { getSelectedColumnIndexes, getSelectedRowIndexes } from '../../utils';
29
+ import {
30
+ getSelectedColumnIndexes,
31
+ getSelectedRowIndexes,
32
+ hasMergedCellsInColumn,
33
+ hasMergedCellsInRow,
34
+ } from '../../utils';
30
35
  import type { DragMenuConfig } from '../../utils/drag-menu';
31
36
  import { getDragMenuConfig } from '../../utils/drag-menu';
32
37
  import { dragMenuDropdownWidth } from '../consts';
@@ -123,9 +128,15 @@ export const DragMenu = ({
123
128
  ? getSelectionRect(selection)!
124
129
  : findCellRectClosestToPos(selection.$from);
125
130
 
131
+ const hasMergedCells =
132
+ direction === 'row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
133
+
134
+ const mergedCells = index !== undefined && hasMergedCells(index)(selection);
135
+
126
136
  const dragMenuConfig = getDragMenuConfig(
127
137
  direction,
128
138
  getEditorContainerWidth,
139
+ mergedCells,
129
140
  tableMap,
130
141
  index,
131
142
  targetCellPosition,
@@ -158,75 +158,81 @@ export default class TableFloatingControls extends Component<Props, State> {
158
158
  ? stickyHeader.top
159
159
  : undefined;
160
160
 
161
+ const wrapperClassName = isDragAndDropEnabled
162
+ ? ClassName.DRAG_ROW_CONTROLS_WRAPPER
163
+ : ClassName.ROW_CONTROLS_WRAPPER;
164
+
161
165
  return (
162
- <div onMouseDown={(e) => !isDragAndDropEnabled && e.preventDefault()}>
163
- {isNumberColumnEnabled ? (
164
- <NumberColumn
165
- editorView={editorView}
166
- hoverRows={this.hoverRows}
167
- tableRef={tableRef}
168
- tableActive={tableActive}
169
- hoveredRows={hoveredRows}
170
- hasHeaderRow={hasHeaderRow}
171
- isInDanger={isInDanger}
172
- isResizing={isResizing}
173
- selectRow={this.selectRow}
174
- updateCellHoverLocation={this.updateCellHoverLocation}
175
- stickyTop={stickyTop}
176
- isDragAndDropEnabled={isDragAndDropEnabled}
177
- />
178
- ) : null}
166
+ <div className={wrapperClassName}>
167
+ <div onMouseDown={(e) => !isDragAndDropEnabled && e.preventDefault()}>
168
+ {isNumberColumnEnabled ? (
169
+ <NumberColumn
170
+ editorView={editorView}
171
+ hoverRows={this.hoverRows}
172
+ tableRef={tableRef}
173
+ tableActive={tableActive}
174
+ hoveredRows={hoveredRows}
175
+ hasHeaderRow={hasHeaderRow}
176
+ isInDanger={isInDanger}
177
+ isResizing={isResizing}
178
+ selectRow={this.selectRow}
179
+ updateCellHoverLocation={this.updateCellHoverLocation}
180
+ stickyTop={stickyTop}
181
+ isDragAndDropEnabled={isDragAndDropEnabled}
182
+ />
183
+ ) : null}
179
184
 
180
- {tableActive && (
181
- <>
182
- {isDragAndDropEnabled ? (
183
- <>
184
- <DragCornerControls
185
- editorView={editorView}
186
- tableRef={tableRef}
187
- isInDanger={isInDanger}
188
- isResizing={isResizing}
189
- />
190
- <DragControls
191
- tableRef={tableRef}
192
- tableNode={tableNode}
193
- hoveredCell={hoveredCell}
194
- editorView={editorView}
195
- tableActive={tableActive}
196
- isInDanger={isInDanger}
197
- isResizing={isResizing}
198
- tableWidth={this.state.tableWrapperWidth}
199
- hoverRows={this.hoverRows}
200
- selectRow={this.selectRow}
201
- updateCellHoverLocation={this.updateCellHoverLocation}
202
- />
203
- </>
204
- ) : (
205
- <>
206
- <CornerControls
207
- editorView={editorView}
208
- tableRef={tableRef}
209
- isInDanger={isInDanger}
210
- isResizing={isResizing}
211
- isHeaderRowEnabled={isHeaderRowEnabled}
212
- isHeaderColumnEnabled={isHeaderColumnEnabled}
213
- hoveredRows={hoveredRows}
214
- stickyTop={tableActive ? stickyTop : undefined}
215
- />
216
- <RowControls
217
- editorView={editorView}
218
- tableRef={tableRef}
219
- hoverRows={this.hoverRows}
220
- hoveredRows={hoveredRows}
221
- isInDanger={isInDanger}
222
- isResizing={isResizing}
223
- selectRow={this.selectRow}
224
- stickyTop={tableActive ? stickyTop : undefined}
225
- />
226
- </>
227
- )}
228
- </>
229
- )}
185
+ {tableActive && (
186
+ <>
187
+ {isDragAndDropEnabled ? (
188
+ <>
189
+ <DragCornerControls
190
+ editorView={editorView}
191
+ tableRef={tableRef}
192
+ isInDanger={isInDanger}
193
+ isResizing={isResizing}
194
+ />
195
+ <DragControls
196
+ tableRef={tableRef}
197
+ tableNode={tableNode}
198
+ hoveredCell={hoveredCell}
199
+ editorView={editorView}
200
+ tableActive={tableActive}
201
+ isInDanger={isInDanger}
202
+ isResizing={isResizing}
203
+ tableWidth={this.state.tableWrapperWidth}
204
+ hoverRows={this.hoverRows}
205
+ selectRow={this.selectRow}
206
+ updateCellHoverLocation={this.updateCellHoverLocation}
207
+ />
208
+ </>
209
+ ) : (
210
+ <>
211
+ <CornerControls
212
+ editorView={editorView}
213
+ tableRef={tableRef}
214
+ isInDanger={isInDanger}
215
+ isResizing={isResizing}
216
+ isHeaderRowEnabled={isHeaderRowEnabled}
217
+ isHeaderColumnEnabled={isHeaderColumnEnabled}
218
+ hoveredRows={hoveredRows}
219
+ stickyTop={tableActive ? stickyTop : undefined}
220
+ />
221
+ <RowControls
222
+ editorView={editorView}
223
+ tableRef={tableRef}
224
+ hoverRows={this.hoverRows}
225
+ hoveredRows={hoveredRows}
226
+ isInDanger={isInDanger}
227
+ isResizing={isResizing}
228
+ selectRow={this.selectRow}
229
+ stickyTop={tableActive ? stickyTop : undefined}
230
+ />
231
+ </>
232
+ )}
233
+ </>
234
+ )}
235
+ </div>
230
236
  </div>
231
237
  );
232
238
  }