@atlaskit/editor-plugin-table 5.3.0 → 5.3.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.
Files changed (186) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/plugins/table/commands/hover.js +17 -8
  3. package/dist/cjs/plugins/table/commands/index.js +6 -0
  4. package/dist/cjs/plugins/table/commands/misc.js +1 -7
  5. package/dist/cjs/plugins/table/event-handlers.js +29 -2
  6. package/dist/cjs/plugins/table/index.js +1 -1
  7. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +5 -3
  8. package/dist/cjs/plugins/table/nodeviews/table.js +4 -2
  9. package/dist/cjs/plugins/table/pm-plugins/decorations/plugin.js +7 -3
  10. package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-controls.js +7 -2
  11. package/dist/cjs/plugins/table/pm-plugins/default-table-selection.js +14 -1
  12. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +36 -7
  13. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +69 -7
  14. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
  15. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/index.js +12 -0
  16. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +59 -0
  17. package/dist/cjs/plugins/table/pm-plugins/main.js +5 -5
  18. package/dist/cjs/plugins/table/reducer.js +2 -1
  19. package/dist/cjs/plugins/table/types.js +14 -1
  20. package/dist/cjs/plugins/table/ui/DragHandle/index.js +50 -0
  21. package/dist/cjs/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +53 -14
  22. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +114 -0
  23. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +53 -0
  24. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/index.js +11 -106
  25. package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +16 -6
  26. package/dist/cjs/plugins/table/ui/common-styles.js +9 -6
  27. package/dist/cjs/plugins/table/ui/consts.js +3 -1
  28. package/dist/cjs/plugins/table/ui/ui-styles.js +21 -9
  29. package/dist/cjs/plugins/table/utils/decoration.js +111 -19
  30. package/dist/cjs/plugins/table/utils/dom.js +7 -1
  31. package/dist/cjs/plugins/table/utils/index.js +38 -1
  32. package/dist/cjs/plugins/table/utils/merged-cells.js +66 -0
  33. package/dist/es2019/plugins/table/commands/hover.js +12 -8
  34. package/dist/es2019/plugins/table/commands/index.js +1 -1
  35. package/dist/es2019/plugins/table/commands/misc.js +1 -7
  36. package/dist/es2019/plugins/table/event-handlers.js +28 -2
  37. package/dist/es2019/plugins/table/index.js +1 -1
  38. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +5 -3
  39. package/dist/es2019/plugins/table/nodeviews/table.js +4 -2
  40. package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +8 -6
  41. package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +7 -2
  42. package/dist/es2019/plugins/table/pm-plugins/default-table-selection.js +13 -0
  43. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +35 -7
  44. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +69 -4
  45. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
  46. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/index.js +1 -0
  47. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +56 -0
  48. package/dist/es2019/plugins/table/pm-plugins/main.js +6 -5
  49. package/dist/es2019/plugins/table/reducer.js +2 -1
  50. package/dist/es2019/plugins/table/types.js +14 -1
  51. package/dist/es2019/plugins/table/ui/DragHandle/index.js +41 -0
  52. package/dist/es2019/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +54 -10
  53. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +86 -0
  54. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +43 -0
  55. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/index.js +2 -88
  56. package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +17 -7
  57. package/dist/es2019/plugins/table/ui/common-styles.js +49 -13
  58. package/dist/es2019/plugins/table/ui/consts.js +2 -0
  59. package/dist/es2019/plugins/table/ui/ui-styles.js +171 -15
  60. package/dist/es2019/plugins/table/utils/decoration.js +106 -18
  61. package/dist/es2019/plugins/table/utils/dom.js +2 -0
  62. package/dist/es2019/plugins/table/utils/index.js +4 -3
  63. package/dist/es2019/plugins/table/utils/merged-cells.js +48 -0
  64. package/dist/esm/plugins/table/commands/hover.js +16 -8
  65. package/dist/esm/plugins/table/commands/index.js +1 -1
  66. package/dist/esm/plugins/table/commands/misc.js +1 -7
  67. package/dist/esm/plugins/table/event-handlers.js +29 -2
  68. package/dist/esm/plugins/table/index.js +1 -1
  69. package/dist/esm/plugins/table/nodeviews/TableComponent.js +5 -3
  70. package/dist/esm/plugins/table/nodeviews/table.js +4 -2
  71. package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +8 -6
  72. package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +7 -2
  73. package/dist/esm/plugins/table/pm-plugins/default-table-selection.js +13 -0
  74. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +36 -7
  75. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +65 -4
  76. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
  77. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/index.js +1 -0
  78. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +53 -0
  79. package/dist/esm/plugins/table/pm-plugins/main.js +7 -7
  80. package/dist/esm/plugins/table/reducer.js +2 -1
  81. package/dist/esm/plugins/table/types.js +14 -1
  82. package/dist/esm/plugins/table/ui/DragHandle/index.js +41 -0
  83. package/dist/esm/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +54 -15
  84. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +104 -0
  85. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +46 -0
  86. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/index.js +2 -104
  87. package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +17 -7
  88. package/dist/esm/plugins/table/ui/common-styles.js +11 -8
  89. package/dist/esm/plugins/table/ui/consts.js +2 -0
  90. package/dist/esm/plugins/table/ui/ui-styles.js +21 -9
  91. package/dist/esm/plugins/table/utils/decoration.js +110 -18
  92. package/dist/esm/plugins/table/utils/dom.js +6 -0
  93. package/dist/esm/plugins/table/utils/index.js +4 -3
  94. package/dist/esm/plugins/table/utils/merged-cells.js +60 -0
  95. package/dist/types/plugins/table/commands/hover.d.ts +2 -1
  96. package/dist/types/plugins/table/commands/index.d.ts +1 -1
  97. package/dist/types/plugins/table/event-handlers.d.ts +1 -0
  98. package/dist/types/plugins/table/nodeviews/types.d.ts +4 -3
  99. package/dist/types/plugins/table/pm-plugins/decorations/plugin.d.ts +2 -1
  100. package/dist/types/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +1 -1
  101. package/dist/types/plugins/table/pm-plugins/default-table-selection.d.ts +12 -0
  102. package/dist/types/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +5 -1
  103. package/dist/types/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +6 -1
  104. package/dist/types/plugins/table/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
  105. package/dist/types/plugins/table/pm-plugins/drag-and-drop/utils/monitor.d.ts +3 -0
  106. package/dist/types/plugins/table/pm-plugins/main.d.ts +1 -1
  107. package/dist/types/plugins/table/types.d.ts +35 -2
  108. package/dist/types/plugins/table/ui/DragHandle/index.d.ts +11 -0
  109. package/dist/types/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +4 -1
  110. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.d.ts +17 -0
  111. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +16 -0
  112. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +2 -17
  113. package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +3 -2
  114. package/dist/types/plugins/table/ui/consts.d.ts +2 -0
  115. package/dist/types/plugins/table/ui/ui-styles.d.ts +1 -0
  116. package/dist/types/plugins/table/utils/decoration.d.ts +4 -2
  117. package/dist/types/plugins/table/utils/dom.d.ts +2 -0
  118. package/dist/types/plugins/table/utils/index.d.ts +3 -2
  119. package/dist/types/plugins/table/utils/merged-cells.d.ts +3 -0
  120. package/dist/types-ts4.5/plugins/table/commands/hover.d.ts +2 -1
  121. package/dist/types-ts4.5/plugins/table/commands/index.d.ts +1 -1
  122. package/dist/types-ts4.5/plugins/table/event-handlers.d.ts +1 -0
  123. package/dist/types-ts4.5/plugins/table/nodeviews/types.d.ts +4 -3
  124. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/plugin.d.ts +2 -1
  125. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +1 -1
  126. package/dist/types-ts4.5/plugins/table/pm-plugins/default-table-selection.d.ts +12 -0
  127. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +5 -1
  128. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +6 -1
  129. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
  130. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/utils/monitor.d.ts +3 -0
  131. package/dist/types-ts4.5/plugins/table/pm-plugins/main.d.ts +1 -1
  132. package/dist/types-ts4.5/plugins/table/types.d.ts +35 -2
  133. package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +11 -0
  134. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +4 -1
  135. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.d.ts +17 -0
  136. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +16 -0
  137. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +2 -17
  138. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +3 -2
  139. package/dist/types-ts4.5/plugins/table/ui/consts.d.ts +2 -0
  140. package/dist/types-ts4.5/plugins/table/ui/ui-styles.d.ts +1 -0
  141. package/dist/types-ts4.5/plugins/table/utils/decoration.d.ts +4 -2
  142. package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +2 -0
  143. package/dist/types-ts4.5/plugins/table/utils/index.d.ts +3 -2
  144. package/dist/types-ts4.5/plugins/table/utils/merged-cells.d.ts +3 -0
  145. package/package.json +6 -2
  146. package/src/__tests__/unit/event-handlers.ts +74 -1
  147. package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +35 -15
  148. package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +146 -42
  149. package/src/__tests__/unit/ui/NumberColumn.tsx +148 -0
  150. package/src/__tests__/unit/ui/RowControls.tsx +4 -4
  151. package/src/__tests__/unit/ui/RowDragControls.tsx +118 -0
  152. package/src/__tests__/unit/ui/TableFloatingControls.tsx +9 -5
  153. package/src/plugins/table/commands/hover.ts +16 -7
  154. package/src/plugins/table/commands/index.ts +1 -0
  155. package/src/plugins/table/commands/misc.ts +0 -5
  156. package/src/plugins/table/event-handlers.ts +49 -2
  157. package/src/plugins/table/index.tsx +1 -1
  158. package/src/plugins/table/nodeviews/TableComponent.tsx +3 -2
  159. package/src/plugins/table/nodeviews/table.tsx +2 -0
  160. package/src/plugins/table/nodeviews/types.ts +4 -3
  161. package/src/plugins/table/pm-plugins/decorations/plugin.ts +13 -4
  162. package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +10 -5
  163. package/src/plugins/table/pm-plugins/default-table-selection.ts +10 -0
  164. package/src/plugins/table/pm-plugins/drag-and-drop/actions.ts +6 -1
  165. package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +58 -8
  166. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +77 -4
  167. package/src/plugins/table/pm-plugins/drag-and-drop/reducer.ts +2 -0
  168. package/src/plugins/table/pm-plugins/drag-and-drop/utils/index.ts +1 -0
  169. package/src/plugins/table/pm-plugins/drag-and-drop/utils/monitor.ts +72 -0
  170. package/src/plugins/table/pm-plugins/main.ts +9 -4
  171. package/src/plugins/table/reducer.ts +2 -1
  172. package/src/plugins/table/types.ts +37 -3
  173. package/src/plugins/table/ui/DragHandle/index.tsx +57 -0
  174. package/src/plugins/table/ui/TableFloatingControls/NumberColumn/index.tsx +68 -30
  175. package/src/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.tsx +129 -0
  176. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +75 -0
  177. package/src/plugins/table/ui/TableFloatingControls/RowControls/index.tsx +2 -135
  178. package/src/plugins/table/ui/TableFloatingControls/index.tsx +43 -24
  179. package/src/plugins/table/ui/common-styles.ts +54 -11
  180. package/src/plugins/table/ui/consts.ts +2 -0
  181. package/src/plugins/table/ui/ui-styles.ts +173 -14
  182. package/src/plugins/table/utils/decoration.ts +176 -27
  183. package/src/plugins/table/utils/dom.ts +8 -0
  184. package/src/plugins/table/utils/index.ts +5 -0
  185. package/src/plugins/table/utils/merged-cells.ts +67 -0
  186. package/tsconfig.app.json +3 -0
@@ -0,0 +1,118 @@
1
+ import React from 'react';
2
+
3
+ import { render } from '@testing-library/react';
4
+ import { IntlProvider } from 'react-intl-next';
5
+
6
+ import type { DocBuilder } from '@atlaskit/editor-common/types';
7
+ // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
8
+ import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
9
+ import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
10
+ import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
11
+ import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
12
+ import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
13
+ import { widthPlugin } from '@atlaskit/editor-plugin-width';
14
+ import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
15
+ // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
16
+ import {
17
+ createProsemirrorEditorFactory,
18
+ Preset,
19
+ } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
20
+ // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
21
+ import {
22
+ doc,
23
+ p,
24
+ table,
25
+ td,
26
+ tdEmpty,
27
+ tr,
28
+ } from '@atlaskit/editor-test-helpers/doc-builder';
29
+
30
+ import tablePlugin from '../../../plugins/table-plugin';
31
+ import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
32
+ import { TableCssClassName as ClassName } from '../../../plugins/table/types';
33
+ import { DragControls } from '../../../plugins/table/ui/TableFloatingControls/RowControls';
34
+
35
+ describe('NumberColumn', () => {
36
+ const createEditor = createProsemirrorEditorFactory();
37
+
38
+ const editor = (doc: DocBuilder, tableOptions = {}) =>
39
+ createEditor({
40
+ doc,
41
+ preset: new Preset<LightEditorPlugin>()
42
+ .add([featureFlagsPlugin, {}])
43
+ .add([analyticsPlugin, {}])
44
+ .add(contentInsertionPlugin)
45
+ .add(widthPlugin)
46
+ .add(guidelinePlugin)
47
+ .add(selectionPlugin)
48
+ .add([tablePlugin, { tableOptions }]),
49
+ pluginKey: pluginKey,
50
+ });
51
+
52
+ it('should only render one child container if hovered cell provided', () => {
53
+ const { editorView } = editor(
54
+ doc(
55
+ p('text'),
56
+ table()(
57
+ tr(tdEmpty, tdEmpty, tdEmpty),
58
+ tr(tdEmpty, tdEmpty, tdEmpty),
59
+ tr(td({})(p('\n\n\n\n\n')), tdEmpty, tdEmpty),
60
+ ),
61
+ ),
62
+ { dragAndDropEnabled: true },
63
+ );
64
+ const ref = editorView.dom.querySelector('table');
65
+
66
+ const { container } = render(
67
+ <IntlProvider locale="en">
68
+ <DragControls
69
+ tableRef={ref!}
70
+ tableActive
71
+ editorView={editorView}
72
+ hoveredCell={{ rowIndex: 1, colIndex: 1 }}
73
+ />
74
+ </IntlProvider>,
75
+ );
76
+
77
+ const dragHandleContainer = container.querySelector(
78
+ `.${ClassName.ROW_CONTROLS_WITH_DRAG}`,
79
+ );
80
+
81
+ expect(dragHandleContainer?.children.length).toBe(1);
82
+ });
83
+
84
+ it('should not render any drag handle containers if hoveredCell is undefined', () => {
85
+ const { editorView } = editor(
86
+ doc(
87
+ p('text'),
88
+ table()(
89
+ tr(tdEmpty, tdEmpty, tdEmpty),
90
+ tr(tdEmpty, tdEmpty, tdEmpty),
91
+ tr(td({})(p('\n\n\n\n\n')), tdEmpty, tdEmpty),
92
+ ),
93
+ ),
94
+ { dragAndDropEnabled: true },
95
+ );
96
+ const ref = editorView.dom.querySelector('table');
97
+
98
+ const { container } = render(
99
+ <IntlProvider locale="en">
100
+ <DragControls
101
+ tableRef={ref!}
102
+ tableActive
103
+ editorView={editorView}
104
+ hoveredCell={{
105
+ colIndex: undefined,
106
+ rowIndex: undefined,
107
+ }}
108
+ />
109
+ </IntlProvider>,
110
+ );
111
+
112
+ const dragHandleContainer = container.querySelector(
113
+ `.${ClassName.ROW_CONTROLS_WITH_DRAG}`,
114
+ );
115
+
116
+ expect(dragHandleContainer?.children.length).toBe(0);
117
+ });
118
+ });
@@ -37,7 +37,7 @@ import TableFloatingControls from '../../../plugins/table/ui/TableFloatingContro
37
37
 
38
38
  describe('TableFloatingControls', () => {
39
39
  const createEditor = createProsemirrorEditorFactory();
40
- const fakeGetEditorFeatureFlags = () => ({});
40
+
41
41
  const preset = new Preset<LightEditorPlugin>()
42
42
  .add([featureFlagsPlugin, {}])
43
43
  .add([analyticsPlugin, {}])
@@ -45,7 +45,10 @@ describe('TableFloatingControls', () => {
45
45
  .add(widthPlugin)
46
46
  .add(guidelinePlugin)
47
47
  .add(selectionPlugin)
48
- .add(tablePlugin);
48
+ .add([
49
+ tablePlugin,
50
+ { tableOptions: { advanced: true }, dragAndDropEnabled: false },
51
+ ]);
49
52
 
50
53
  const editor = (doc: DocBuilder) =>
51
54
  createEditor<TablePluginState, PluginKey, typeof preset>({
@@ -62,7 +65,7 @@ describe('TableFloatingControls', () => {
62
65
  const { container } = render(
63
66
  <TableFloatingControls
64
67
  editorView={editorView}
65
- getEditorFeatureFlags={fakeGetEditorFeatureFlags}
68
+ isDragAndDropEnabled={false}
66
69
  />,
67
70
  );
68
71
  expect(container.innerHTML).toEqual('');
@@ -72,7 +75,7 @@ describe('TableFloatingControls', () => {
72
75
  describe('when tableRef is defined', () => {
73
76
  it('should render CornerControls and RowControls', () => {
74
77
  const { editorView } = editor(
75
- doc(p('text'), table()(tr(tdEmpty, tdEmpty, tdEmpty))),
78
+ doc(p('text'), table()(tr(tdCursor, tdEmpty, tdEmpty))),
76
79
  );
77
80
  const ref = editorView.dom.querySelector('table') || undefined;
78
81
 
@@ -82,7 +85,8 @@ describe('TableFloatingControls', () => {
82
85
  tableRef={ref}
83
86
  tableActive={true}
84
87
  editorView={editorView}
85
- getEditorFeatureFlags={fakeGetEditorFeatureFlags}
88
+ isDragAndDropEnabled={false}
89
+ selection={editorView.state.selection}
86
90
  />
87
91
  </IntlProvider>,
88
92
  );
@@ -7,7 +7,8 @@ import {
7
7
  } from '@atlaskit/editor-tables/utils';
8
8
 
9
9
  import { createCommand } from '../pm-plugins/plugin-factory';
10
- import { Cell, CellColumnPositioning, TableDecorations } from '../types';
10
+ import type { Cell, CellColumnPositioning } from '../types';
11
+ import { TableDecorations } from '../types';
11
12
  import {
12
13
  createCellHoverDecoration,
13
14
  createColumnLineResize,
@@ -15,13 +16,9 @@ import {
15
16
  getMergedCellsPositions,
16
17
  updatePluginStateDecorations,
17
18
  } from '../utils';
18
- // #endregion
19
19
 
20
- // #region Utils
21
20
  const makeArray = (n: number) => Array.from(Array(n).keys());
22
- // #endregion
23
21
 
24
- // #region Commands
25
22
  export const hoverMergedCells = () =>
26
23
  createCommand(
27
24
  (state) => {
@@ -43,7 +40,7 @@ export const hoverMergedCells = () =>
43
40
  const decorations = createCellHoverDecoration(mergedCells);
44
41
 
45
42
  return {
46
- type: 'HOVER_CELLS',
43
+ type: 'HOVER_MERGED_CELLS',
47
44
  data: {
48
45
  decorationSet: updatePluginStateDecorations(
49
46
  state,
@@ -193,4 +190,16 @@ export const hideResizeHandleLine = () =>
193
190
  ),
194
191
  },
195
192
  }));
196
- // #endregion
193
+
194
+ export const hoverCell = (rowIndex?: number, colIndex?: number) =>
195
+ createCommand(
196
+ () => {
197
+ return {
198
+ type: 'HOVER_CELL',
199
+ data: {
200
+ hoveredCell: { rowIndex, colIndex },
201
+ },
202
+ };
203
+ },
204
+ (tr) => tr.setMeta('addToHistory', false),
205
+ );
@@ -2,6 +2,7 @@ export {
2
2
  hoverColumns,
3
3
  hoverRows,
4
4
  hoverTable,
5
+ hoverCell,
5
6
  hoverMergedCells,
6
7
  clearHoverSelection,
7
8
  showResizeHandleLine,
@@ -52,11 +52,7 @@ import {
52
52
  isIsolating,
53
53
  } from '../utils/nodes';
54
54
  import { updatePluginStateDecorations } from '../utils/update-plugin-state-decorations';
55
- // #endregion
56
55
 
57
- // #endregion
58
-
59
- // #region Commands
60
56
  export const setEditorFocus = (editorHasFocus: boolean) =>
61
57
  createCommand({
62
58
  type: 'SET_EDITOR_FOCUS',
@@ -588,4 +584,3 @@ export const addBoldInEmptyHeaderCells =
588
584
 
589
585
  return false;
590
586
  };
591
- // #endregion
@@ -33,6 +33,7 @@ import {
33
33
  clearHoverSelection,
34
34
  hideInsertColumnOrRowButton,
35
35
  hideResizeHandleLine,
36
+ hoverCell,
36
37
  hoverColumns,
37
38
  selectColumn,
38
39
  setEditorFocus,
@@ -275,14 +276,21 @@ export const handleMouseLeave = (view: EditorView, event: Event): boolean => {
275
276
  }
276
277
 
277
278
  const { state, dispatch } = view;
278
- const { insertColumnButtonIndex, insertRowButtonIndex } =
279
- getPluginState(state);
279
+ const {
280
+ insertColumnButtonIndex,
281
+ insertRowButtonIndex,
282
+ isDragAndDropEnabled,
283
+ } = getPluginState(state);
280
284
 
281
285
  const target = event.target;
282
286
  if (isTableControlsButton(target)) {
283
287
  return true;
284
288
  }
285
289
 
290
+ if (isDragAndDropEnabled) {
291
+ hoverCell(undefined, undefined)(state, dispatch);
292
+ }
293
+
286
294
  if (
287
295
  (typeof insertColumnButtonIndex !== 'undefined' ||
288
296
  typeof insertRowButtonIndex !== 'undefined') &&
@@ -498,3 +506,42 @@ export const whenTableInFocus =
498
506
 
499
507
  return eventHandler(view, mouseEvent, elementContentRects);
500
508
  };
509
+
510
+ const trackCellLocation = (view: EditorView, mouseEvent: Event) => {
511
+ const target = mouseEvent.target;
512
+ const maybeTableCell = isElementInTableCell(
513
+ target as HTMLElement,
514
+ ) as HTMLTableCellElement | null;
515
+
516
+ if (!maybeTableCell) {
517
+ return;
518
+ }
519
+
520
+ const colIndex = maybeTableCell.cellIndex;
521
+ const rowElement = closestElement(
522
+ target as HTMLElement,
523
+ 'tr',
524
+ ) as HTMLTableRowElement;
525
+ const rowIndex = rowElement && rowElement.rowIndex;
526
+ const { hoveredCell } = getPluginState(view.state);
527
+
528
+ if (hoveredCell.colIndex !== colIndex || hoveredCell.rowIndex !== rowIndex) {
529
+ hoverCell(rowIndex, colIndex)(view.state, view.dispatch);
530
+ }
531
+ };
532
+
533
+ export const withCellTracking =
534
+ (
535
+ eventHandler: (
536
+ view: EditorView,
537
+ mouseEvent: Event,
538
+ elementContentRects?: ElementContentRects,
539
+ ) => boolean,
540
+ elementContentRects?: ElementContentRects,
541
+ ) =>
542
+ (view: EditorView, mouseEvent: Event): boolean => {
543
+ if (getPluginState(view.state).isDragAndDropEnabled) {
544
+ trackCellLocation(view, mouseEvent);
545
+ }
546
+ return eventHandler(view, mouseEvent, elementContentRects);
547
+ };
@@ -196,8 +196,8 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
196
196
  getEditorFeatureFlags || defaultGetEditorFeatureFlags,
197
197
  getIntl,
198
198
  breakoutEnabled,
199
- fullWidthEnabled,
200
199
  tableResizingEnabled,
200
+ fullWidthEnabled,
201
201
  wasFullWidthEnabled,
202
202
  dragAndDropEnabled,
203
203
  editorAnalyticsAPI,
@@ -403,7 +403,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
403
403
  const { showBeforeShadow, showAfterShadow } = this.state;
404
404
  const node = getNode();
405
405
  // doesn't work well with WithPluginState
406
- const { isInDanger, hoveredRows } = getPluginState(view.state);
406
+ const { isInDanger, hoveredRows, hoveredCell } = getPluginState(view.state);
407
407
 
408
408
  const tableRef = this.table || undefined;
409
409
  const headerRow = tableRef
@@ -418,10 +418,12 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
418
418
  tableRef={tableRef}
419
419
  tableActive={tableActive}
420
420
  hoveredRows={hoveredRows}
421
+ hoveredCell={hoveredCell}
421
422
  isInDanger={isInDanger}
422
423
  isResizing={isResizing}
423
424
  isNumberColumnEnabled={node.attrs.isNumberColumnEnabled}
424
425
  isHeaderRowEnabled={isHeaderRowEnabled}
426
+ isDragAndDropEnabled={options?.isDragAndDropEnabled}
425
427
  ordering={ordering}
426
428
  isHeaderColumnEnabled={isHeaderColumnEnabled}
427
429
  hasHeaderRow={hasHeaderRow}
@@ -429,7 +431,6 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
429
431
  selection={view.state.selection}
430
432
  headerRowHeight={headerRow ? headerRow.offsetHeight : undefined}
431
433
  stickyHeader={this.state.stickyHeader}
432
- getEditorFeatureFlags={this.props.getEditorFeatureFlags}
433
434
  />
434
435
  </div>
435
436
  );
@@ -352,6 +352,7 @@ export const createTableView = (
352
352
  isFullWidthModeEnabled,
353
353
  wasFullWidthModeEnabled,
354
354
  isTableResizingEnabled,
355
+ isDragAndDropEnabled,
355
356
  } = getPluginState(view.state);
356
357
  const { allowColumnResizing } = getPluginConfig(pluginConfig);
357
358
  const hasIntlContext = true;
@@ -368,6 +369,7 @@ export const createTableView = (
368
369
  isFullWidthModeEnabled,
369
370
  wasFullWidthModeEnabled,
370
371
  isTableResizingEnabled,
372
+ isDragAndDropEnabled,
371
373
  },
372
374
  getEditorContainerWidth,
373
375
  getEditorFeatureFlags,
@@ -1,11 +1,11 @@
1
- import { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
1
+ import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
2
2
  import type { PortalProviderAPI } from '@atlaskit/editor-common/portal-provider';
3
3
  import type {
4
4
  GetEditorContainerWidth,
5
5
  GetEditorFeatureFlags,
6
6
  } from '@atlaskit/editor-common/types';
7
- import { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
8
- import { EditorView } from '@atlaskit/editor-prosemirror/view';
7
+ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
8
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
9
9
 
10
10
  import type { PluginInjectionAPI } from '../types';
11
11
 
@@ -14,6 +14,7 @@ export type TableOptions = {
14
14
  isFullWidthModeEnabled?: boolean;
15
15
  wasFullWidthModeEnabled?: boolean;
16
16
  isTableResizingEnabled?: boolean;
17
+ isDragAndDropEnabled?: boolean;
17
18
  };
18
19
 
19
20
  export interface Props {
@@ -1,11 +1,11 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import {
2
+ import type {
3
3
  EditorState,
4
- PluginKey,
5
4
  // @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
6
5
  ReadonlyTransaction,
7
6
  Transaction,
8
7
  } from '@atlaskit/editor-prosemirror/state';
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
11
 
@@ -30,6 +30,7 @@ export const handleDocOrSelectionChanged = (
30
30
  ): DecorationSet => {
31
31
  const isResizing = tableWidthPluginKey.getState(newState)?.resizing;
32
32
  const wasResizing = tableWidthPluginKey.getState(oldState)?.resizing;
33
+
33
34
  const changedResizing = isResizing !== wasResizing;
34
35
 
35
36
  // Remove column controls when resizing
@@ -38,7 +39,8 @@ export const handleDocOrSelectionChanged = (
38
39
  } else if (
39
40
  tr.docChanged ||
40
41
  tr.selection instanceof CellSelection ||
41
- changedResizing
42
+ changedResizing ||
43
+ tr.getMeta(tablePluginKey)?.type === 'HOVER_CELL'
42
44
  ) {
43
45
  return buildColumnControlsDecorations({
44
46
  decorationSet,
@@ -69,6 +71,12 @@ export const createPlugin = () => {
69
71
  apply: (tr, decorationSet, oldState, newState) => {
70
72
  let pluginState = decorationSet;
71
73
  const meta = tr.getMeta(tablePluginKey);
74
+ const previousHover = tablePluginKey.getState(oldState)?.hoveredCell;
75
+ const newHover = tablePluginKey.getState(newState)?.hoveredCell;
76
+ const changedCellHover =
77
+ previousHover?.colIndex !== newHover?.colIndex ||
78
+ previousHover?.rowIndex !== newHover?.rowIndex;
79
+
72
80
  if (meta && meta.data && meta.data.decorationSet) {
73
81
  pluginState = meta.data.decorationSet;
74
82
  }
@@ -76,7 +84,8 @@ export const createPlugin = () => {
76
84
  if (
77
85
  tr.docChanged ||
78
86
  tr.selectionSet ||
79
- tr.getMeta(tableWidthPluginKey)
87
+ tr.getMeta(tableWidthPluginKey) ||
88
+ changedCellHover
80
89
  ) {
81
90
  pluginState = pluginState.map(tr.mapping, tr.doc);
82
91
  return handleDocOrSelectionChanged(
@@ -1,9 +1,9 @@
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
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
8
8
  import { findTable } from '@atlaskit/editor-tables/utils';
9
9
 
@@ -15,9 +15,10 @@ import {
15
15
  findControlsHoverDecoration,
16
16
  updateDecorations,
17
17
  } from '../../../utils/decoration';
18
+ import { pluginKey as tablePluginKey } from '../../plugin-key';
18
19
 
19
20
  import { composeDecorations } from './compose-decorations';
20
- import { DecorationTransformer } from './types';
21
+ import type { DecorationTransformer } from './types';
21
22
 
22
23
  const isColumnSelected = (tr: Transaction | ReadonlyTransaction): boolean =>
23
24
  tr.selection instanceof CellSelection && tr.selection.isColSelection();
@@ -49,13 +50,17 @@ const maybeUpdateColumnControlsDecoration: DecorationTransformer = ({
49
50
  tr,
50
51
  }): DecorationSet => {
51
52
  const table = findTable(tr.selection);
52
- if (!table) {
53
+ const meta = tr.getMeta(tablePluginKey);
54
+
55
+ // avoid re-drawing state if dnd decorations don't need to be updated
56
+ if (!table && meta?.type !== 'HOVER_CELL') {
53
57
  return decorationSet;
54
58
  }
59
+
55
60
  return updateDecorations(
56
61
  tr.doc,
57
62
  decorationSet,
58
- createColumnControlsDecoration(tr.selection),
63
+ createColumnControlsDecoration(tr.selection, meta?.data?.hoveredCell),
59
64
  TableDecorations.COLUMN_CONTROLS_DECORATIONS,
60
65
  );
61
66
  };
@@ -2,3 +2,13 @@ export const defaultTableSelection = {
2
2
  hoveredColumns: [],
3
3
  hoveredRows: [],
4
4
  };
5
+
6
+ /**
7
+ * Creating a separate object for hoveredCell so it doesn't get defaulted when `handleDocOrSelectionChanged` runs.
8
+ *
9
+ * It is safe to persist this value as it gets removed when the mouse cursor leaves the table, so no need to remove it
10
+ * when doc changes.
11
+ */
12
+ export const defaultHoveredCell = {
13
+ hoveredCell: { rowIndex: undefined, colIndex: undefined },
14
+ };
@@ -1,3 +1,5 @@
1
+ import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
2
+
1
3
  import type { DropTargetType } from './consts';
2
4
 
3
5
  export interface DragAndDropAction<T, D> {
@@ -15,12 +17,15 @@ export type DragAndDropSetDropTargetAction = DragAndDropAction<
15
17
  {
16
18
  type: DropTargetType;
17
19
  index: number;
20
+ decorationSet: DecorationSet;
18
21
  }
19
22
  >;
20
23
 
21
24
  export type DragAndDropClearDropTargetAction = DragAndDropAction<
22
25
  typeof DragAndDropActionType.CLEAR_DROP_TARGET,
23
- undefined
26
+ {
27
+ decorationSet: DecorationSet;
28
+ }
24
29
  >;
25
30
 
26
31
  // NOTE: This should be a Union of all possible actions
@@ -1,22 +1,69 @@
1
- import type { Transaction } from '@atlaskit/editor-prosemirror/state';
1
+ import type {
2
+ EditorState,
3
+ Transaction,
4
+ } from '@atlaskit/editor-prosemirror/state';
5
+ import type { Decoration } from '@atlaskit/editor-prosemirror/view';
6
+ import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
+
8
+ import { TableDecorations } from '../../types';
9
+ import {
10
+ createColumnInsertLine,
11
+ createRowInsertLine,
12
+ updateDecorations,
13
+ } from '../../utils';
2
14
 
3
15
  import { DragAndDropActionType } from './actions';
4
16
  import type { DropTargetType } from './consts';
5
- import { createCommand } from './plugin-factory';
17
+ import { createCommand, getPluginState } from './plugin-factory';
18
+ import { pluginKey } from './plugin-key';
6
19
 
7
20
  // TODO: This command is a placeholder example. Please replace this if required.
21
+ export const getDecorations = (state: EditorState): DecorationSet => {
22
+ return pluginKey.getState(state)?.decorationSet || DecorationSet.empty;
23
+ };
24
+
25
+ export const updatePluginStateDecorations = (
26
+ state: EditorState,
27
+ decorations: Decoration[],
28
+ key: TableDecorations,
29
+ ): DecorationSet =>
30
+ updateDecorations(state.doc, getDecorations(state), decorations, key);
31
+
8
32
  export const setDropTarget = (
9
33
  type: DropTargetType,
10
34
  index: number,
11
35
  tr?: Transaction,
12
36
  ) =>
13
37
  createCommand(
14
- {
15
- type: DragAndDropActionType.SET_DROP_TARGET,
16
- data: {
17
- type,
18
- index,
19
- },
38
+ (state) => {
39
+ const { dropTargetType, dropTargetIndex } = getPluginState(state);
40
+ if (dropTargetType === type && dropTargetIndex === index) {
41
+ return false;
42
+ }
43
+
44
+ let decorationSet = DecorationSet.empty;
45
+ if (type === 'column') {
46
+ decorationSet = updatePluginStateDecorations(
47
+ state,
48
+ createColumnInsertLine(index, state.selection),
49
+ TableDecorations.COLUMN_INSERT_LINE,
50
+ );
51
+ } else if (type === 'row') {
52
+ decorationSet = updatePluginStateDecorations(
53
+ state,
54
+ createRowInsertLine(index, state.selection),
55
+ TableDecorations.ROW_INSERT_LINE,
56
+ );
57
+ }
58
+
59
+ return {
60
+ type: DragAndDropActionType.SET_DROP_TARGET,
61
+ data: {
62
+ decorationSet,
63
+ type,
64
+ index,
65
+ },
66
+ };
20
67
  },
21
68
  (originalTr: Transaction) =>
22
69
  (tr || originalTr).setMeta('addToHistory', false),
@@ -26,6 +73,9 @@ export const clearDropTarget = (tr?: Transaction) =>
26
73
  createCommand(
27
74
  {
28
75
  type: DragAndDropActionType.CLEAR_DROP_TARGET,
76
+ data: {
77
+ decorationSet: DecorationSet.empty,
78
+ },
29
79
  },
30
80
  (originalTr: Transaction) =>
31
81
  (tr || originalTr).setMeta('addToHistory', false),