@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "5.3.0",
3
+ "version": "5.3.2",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -40,8 +40,9 @@
40
40
  "@atlaskit/platform-feature-flags": "^0.2.1",
41
41
  "@atlaskit/pragmatic-drag-and-drop": "^0.23.0",
42
42
  "@atlaskit/pragmatic-drag-and-drop-hitbox": "^0.11.8",
43
+ "@atlaskit/pragmatic-drag-and-drop-react-accessibility": "^0.4.0",
43
44
  "@atlaskit/theme": "^12.6.0",
44
- "@atlaskit/tokens": "^1.26.0",
45
+ "@atlaskit/tokens": "^1.27.0",
45
46
  "@atlaskit/tooltip": "^17.8.0",
46
47
  "@babel/runtime": "^7.0.0",
47
48
  "@emotion/react": "^11.7.1",
@@ -106,6 +107,9 @@
106
107
  "platform.editor.custom-table-width": {
107
108
  "type": "boolean"
108
109
  },
110
+ "platform.editor.table.drag-and-drop": {
111
+ "type": "boolean"
112
+ },
109
113
  "platform.editor.table-sticky-scrollbar": {
110
114
  "type": "boolean"
111
115
  },
@@ -25,6 +25,7 @@ import {
25
25
  tdEmpty,
26
26
  tr,
27
27
  } from '@atlaskit/editor-test-helpers/doc-builder';
28
+ import { ffTest } from '@atlassian/feature-flags-test-utils';
28
29
 
29
30
  import tablePlugin from '../../plugins/table-plugin';
30
31
  import {
@@ -36,7 +37,9 @@ import {
36
37
  handleMouseMove,
37
38
  handleMouseOut,
38
39
  handleMouseOver,
40
+ withCellTracking,
39
41
  } from '../../plugins/table/event-handlers';
42
+ import { getPluginState } from '../../plugins/table/pm-plugins/plugin-factory';
40
43
  import { pluginKey } from '../../plugins/table/pm-plugins/plugin-key';
41
44
  import { TableCssClassName as ClassName } from '../../plugins/table/types';
42
45
 
@@ -60,7 +63,7 @@ describe('table plugin: decorations', () => {
60
63
  beforeEach(() => {
61
64
  jest.resetAllMocks();
62
65
  });
63
- it('should return true & prevent default behaviour for table wrappers: pm-table-contianer', () => {
66
+ it('should return true & prevent default behaviour for table wrappers: pm-table-container', () => {
64
67
  const { editorView } = editor(
65
68
  doc(table()(tr(td({})(p())), tr(td({})(p())), tr(td({})(p())))),
66
69
  );
@@ -232,3 +235,73 @@ describe('table event handlers', () => {
232
235
  });
233
236
  });
234
237
  });
238
+
239
+ describe('withCellTracking', () => {
240
+ const createEditor = createProsemirrorEditorFactory();
241
+ const editor = (doc: DocBuilder, isDragAndDropEnabled = false) =>
242
+ createEditor({
243
+ doc,
244
+ attachTo: document.body,
245
+ preset: new Preset<LightEditorPlugin>()
246
+ .add([featureFlagsPlugin, {}])
247
+ .add([analyticsPlugin, {}])
248
+ .add(contentInsertionPlugin)
249
+ .add(decorationsPlugin)
250
+ .add(widthPlugin)
251
+ .add(guidelinePlugin)
252
+ .add(gridPlugin)
253
+ .add(selectionPlugin)
254
+ .add([
255
+ tablePlugin,
256
+ {
257
+ dragAndDropEnabled: isDragAndDropEnabled,
258
+ tableOptions: { advanced: true },
259
+ },
260
+ ]),
261
+ pluginKey,
262
+ });
263
+
264
+ describe('should fire event handler passed in', () => {
265
+ ffTest(
266
+ 'platform.editor.table.drag-and-drop',
267
+ () => {
268
+ const { editorView } = editor(
269
+ doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
270
+ true,
271
+ );
272
+ const eventHandlerSpy = jest.fn();
273
+ withCellTracking(eventHandlerSpy)(editorView, {} as any);
274
+
275
+ expect(eventHandlerSpy).toHaveBeenCalled();
276
+ },
277
+ () => {
278
+ const { editorView } = editor(
279
+ doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
280
+ );
281
+ const eventHandlerSpy = jest.fn();
282
+ withCellTracking(eventHandlerSpy)(editorView, {} as any);
283
+
284
+ expect(eventHandlerSpy).toHaveBeenCalled();
285
+ },
286
+ );
287
+ });
288
+
289
+ describe('should correctly set table cell coordinates based on mouse location', () => {
290
+ ffTest('platform.editor.table.drag-and-drop', () => {
291
+ const { editorView, refs } = editor(
292
+ doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
293
+ true,
294
+ );
295
+ const firstCell = editorView.domAtPos(refs['<>']);
296
+
297
+ const event = {
298
+ target: firstCell.node,
299
+ };
300
+
301
+ withCellTracking(jest.fn())(editorView, event as any);
302
+
303
+ const pluginState = getPluginState(editorView.state);
304
+ expect(pluginState.hoveredCell).toEqual({ colIndex: 0, rowIndex: 0 });
305
+ });
306
+ });
307
+ });
@@ -9,27 +9,47 @@ 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
13
 
13
14
  import { buildColumnControlsDecorations } from '../../../../plugins/table/pm-plugins/decorations/utils';
14
15
  import { TableDecorations } from '../../../../plugins/table/types';
15
16
 
16
17
  describe('tables: column controls decorations', () => {
17
- describe('#buildColumnControlsDecorations', () => {
18
- const decorationKey = TableDecorations.COLUMN_CONTROLS_DECORATIONS;
19
- it(`should return a decorationSet with 2 ${decorationKey} type`, () => {
20
- const state = createEditorState(doc(table()(tr(tdCursor, tdEmpty))));
21
- const nextDecorationSet = buildColumnControlsDecorations({
22
- decorationSet: DecorationSet.empty,
23
- tr: state.tr,
24
- });
18
+ describe(`should return a decorationSet with 2 ${TableDecorations.COLUMN_CONTROLS_DECORATIONS} type`, () => {
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
+ });
25
28
 
26
- const decorations = nextDecorationSet.find(
27
- undefined,
28
- undefined,
29
- (spec: any) => spec.key.indexOf(decorationKey) > -1,
30
- );
29
+ const decorations = nextDecorationSet.find(
30
+ undefined,
31
+ undefined,
32
+ (spec: any) => spec.key.indexOf(decorationKey) > -1,
33
+ );
31
34
 
32
- expect(decorations).toHaveLength(2);
33
- });
35
+ expect(decorations).toHaveLength(2);
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
+ },
53
+ );
34
54
  });
35
55
  });
@@ -23,6 +23,7 @@ import {
23
23
  tdEmpty,
24
24
  tr,
25
25
  } from '@atlaskit/editor-test-helpers/doc-builder';
26
+ import { ffTest } from '@atlassian/feature-flags-test-utils';
26
27
 
27
28
  import tablePlugin from '../../../../plugins/table';
28
29
  import { selectColumn } from '../../../../plugins/table/commands';
@@ -53,28 +54,92 @@ describe('decorations plugin', () => {
53
54
 
54
55
  // ED-8457
55
56
  describe('when there is a selection pointer set', () => {
56
- it('should remove the column selected decorations', () => {
57
- const { editorView } = editor(
58
- doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
59
- );
57
+ describe('should remove the column selected decorations', () => {
58
+ ffTest(
59
+ 'platform.editor.table.drag-and-drop',
60
+ () => {
61
+ const { editorView } = editor(
62
+ doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
63
+ );
64
+
65
+ selectColumn(1)(editorView.state, editorView.dispatch);
66
+
67
+ const { tr: transaction } = editorView.state;
68
+
69
+ transaction.setMeta('pointer', true);
70
+ transaction.setSelection(Selection.atStart(transaction.doc));
71
+ editorView.dispatch(transaction);
72
+
73
+ const decorationSet = getDecorations(editorView.state);
74
+
75
+ const columnSelectedDecorations = decorationSet.find(
76
+ undefined,
77
+ undefined,
78
+ (spec) => spec.key.indexOf(TableDecorations.COLUMN_SELECTED) > -1,
79
+ );
80
+
81
+ expect(columnSelectedDecorations).toHaveLength(0);
82
+ },
83
+ () => {
84
+ const { editorView } = editor(
85
+ doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
86
+ );
60
87
 
61
- selectColumn(1)(editorView.state, editorView.dispatch);
88
+ selectColumn(1)(editorView.state, editorView.dispatch);
62
89
 
63
- const { tr: transaction } = editorView.state;
90
+ const { tr: transaction } = editorView.state;
64
91
 
65
- transaction.setMeta('pointer', true);
66
- transaction.setSelection(Selection.atStart(transaction.doc));
67
- editorView.dispatch(transaction);
92
+ transaction.setMeta('pointer', true);
93
+ transaction.setSelection(Selection.atStart(transaction.doc));
94
+ editorView.dispatch(transaction);
68
95
 
69
- const decorationSet = getDecorations(editorView.state);
96
+ const decorationSet = getDecorations(editorView.state);
70
97
 
71
- const columnSelectedDecorations = decorationSet.find(
72
- undefined,
73
- undefined,
74
- (spec) => spec.key.indexOf(TableDecorations.COLUMN_SELECTED) > -1,
98
+ const columnSelectedDecorations = decorationSet.find(
99
+ undefined,
100
+ undefined,
101
+ (spec) => spec.key.indexOf(TableDecorations.COLUMN_SELECTED) > -1,
102
+ );
103
+
104
+ expect(columnSelectedDecorations).toHaveLength(0);
105
+ },
75
106
  );
107
+ });
108
+ });
109
+
110
+ describe('when the hovered cell state changes', () => {
111
+ describe('should add column control decorations', () => {
112
+ ffTest('platform.editor.table.drag-and-drop', () => {
113
+ const pluginState = DecorationSet.empty;
114
+ const { editorView } = editor(
115
+ doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
116
+ );
76
117
 
77
- expect(columnSelectedDecorations).toHaveLength(0);
118
+ const transaction = editorView.state.tr.setMeta(pluginKey, {
119
+ type: 'HOVER_CELL',
120
+ data: {
121
+ colIndex: 0,
122
+ rowIndex: 0,
123
+ },
124
+ });
125
+
126
+ const oldState = handleDocOrSelectionChanged(
127
+ transaction,
128
+ pluginState,
129
+ editorView.state,
130
+ editorView.state,
131
+ );
132
+
133
+ editorView.dispatch(transaction);
134
+ const newState = handleDocOrSelectionChanged(
135
+ transaction,
136
+ oldState,
137
+ editorView.state,
138
+ editorView.state,
139
+ );
140
+
141
+ expect(oldState).not.toEqual(newState);
142
+ });
78
143
  });
79
144
  });
80
145
 
@@ -104,37 +169,76 @@ describe('decorations plugin', () => {
104
169
  });
105
170
 
106
171
  describe('when the table changed', () => {
107
- it('should re-create the column controls decorations', () => {
108
- const { editorView } = editor(
109
- doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
110
- );
111
- const { state } = editorView;
172
+ describe('should re-create the column controls decorations', () => {
173
+ ffTest(
174
+ 'platform.editor.table.drag-and-drop',
175
+ () => {
176
+ const { editorView } = editor(
177
+ doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
178
+ );
179
+ const { state } = editorView;
112
180
 
113
- const nextPluginState = handleDocOrSelectionChanged(
114
- editorView.state.tr,
115
- DecorationSet.empty,
116
- editorView.state,
117
- state,
118
- );
181
+ const nextPluginState = handleDocOrSelectionChanged(
182
+ editorView.state.tr,
183
+ DecorationSet.empty,
184
+ editorView.state,
185
+ state,
186
+ );
119
187
 
120
- const { tr: transaction } = state;
121
- editorView.dispatch(addColumnAt(2)(transaction));
188
+ const { tr: transaction } = state;
189
+ editorView.dispatch(addColumnAt(2)(transaction));
122
190
 
123
- const newState = handleDocOrSelectionChanged(
124
- transaction,
125
- nextPluginState,
126
- editorView.state,
127
- state,
128
- );
129
- const expectedDecorationSet = newState;
130
- const decorations = expectedDecorationSet.find(
131
- undefined,
132
- undefined,
133
- (spec) =>
134
- spec.key.indexOf(TableDecorations.COLUMN_CONTROLS_DECORATIONS) > -1,
135
- );
191
+ const newState = handleDocOrSelectionChanged(
192
+ transaction,
193
+ nextPluginState,
194
+ editorView.state,
195
+ state,
196
+ );
197
+ const expectedDecorationSet = newState;
198
+ const decorations = expectedDecorationSet.find(
199
+ undefined,
200
+ undefined,
201
+ (spec) =>
202
+ spec.key.indexOf(TableDecorations.COLUMN_CONTROLS_DECORATIONS) >
203
+ -1,
204
+ );
205
+
206
+ expect(decorations).toHaveLength(3);
207
+ },
208
+ () => {
209
+ const { editorView } = editor(
210
+ doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
211
+ );
212
+ const { state } = editorView;
213
+
214
+ const nextPluginState = handleDocOrSelectionChanged(
215
+ editorView.state.tr,
216
+ DecorationSet.empty,
217
+ editorView.state,
218
+ state,
219
+ );
136
220
 
137
- expect(decorations).toHaveLength(3);
221
+ const { tr: transaction } = state;
222
+ editorView.dispatch(addColumnAt(2)(transaction));
223
+
224
+ const newState = handleDocOrSelectionChanged(
225
+ transaction,
226
+ nextPluginState,
227
+ editorView.state,
228
+ state,
229
+ );
230
+ const expectedDecorationSet = newState;
231
+ const decorations = expectedDecorationSet.find(
232
+ undefined,
233
+ undefined,
234
+ (spec) =>
235
+ spec.key.indexOf(TableDecorations.COLUMN_CONTROLS_DECORATIONS) >
236
+ -1,
237
+ );
238
+
239
+ expect(decorations).toHaveLength(3);
240
+ },
241
+ );
138
242
  });
139
243
  });
140
244
 
@@ -0,0 +1,148 @@
1
+ import React from 'react';
2
+
3
+ import { fireEvent, 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
+ tdEmpty,
26
+ tr,
27
+ } from '@atlaskit/editor-test-helpers/doc-builder';
28
+
29
+ import tablePlugin from '../../../plugins/table-plugin';
30
+ import { getPluginState } from '../../../plugins/table/pm-plugins/plugin-factory';
31
+ import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
32
+ // import type { TablePluginState } from '../../../plugins/table/types';
33
+ import { TableCssClassName as ClassName } from '../../../plugins/table/types';
34
+ import NumberColumn from '../../../plugins/table/ui/TableFloatingControls/NumberColumn';
35
+
36
+ describe('NumberColumn', () => {
37
+ const createEditor = createProsemirrorEditorFactory();
38
+
39
+ const editor = (doc: DocBuilder, tableOptions = {}) =>
40
+ createEditor({
41
+ doc,
42
+ preset: new Preset<LightEditorPlugin>()
43
+ .add([featureFlagsPlugin, {}])
44
+ .add([analyticsPlugin, {}])
45
+ .add(contentInsertionPlugin)
46
+ .add(widthPlugin)
47
+ .add(guidelinePlugin)
48
+ .add(selectionPlugin)
49
+ .add([tablePlugin, { tableOptions }]),
50
+ pluginKey: pluginKey,
51
+ });
52
+
53
+ it('should update plugin state for hovered cell - when drag and drop is enabled', () => {
54
+ const { editorView } = editor(
55
+ doc(p('text'), table()(tr(tdEmpty, tdEmpty, tdEmpty))),
56
+ { dragAndDropEnabled: true },
57
+ );
58
+ const ref = editorView.dom.querySelector('table');
59
+
60
+ const { container } = render(
61
+ <IntlProvider locale="en">
62
+ <NumberColumn
63
+ tableRef={ref!}
64
+ tableActive
65
+ editorView={editorView}
66
+ hoverRows={jest.fn()}
67
+ selectRow={jest.fn()}
68
+ isDragAndDropEnabled
69
+ />
70
+ </IntlProvider>,
71
+ );
72
+
73
+ const firstNumberedCell = container.querySelector(
74
+ `.${ClassName.NUMBERED_COLUMN} > div`,
75
+ );
76
+
77
+ fireEvent.mouseOver(firstNumberedCell!);
78
+
79
+ const pluginState = getPluginState(editorView.state);
80
+ // colIndex is not defined yet, keep undefined
81
+ expect(pluginState.hoveredCell).toEqual({
82
+ colIndex: undefined,
83
+ rowIndex: 0,
84
+ });
85
+ });
86
+
87
+ it('should render button disabled numbered column cells - when drag and drop is enabled', () => {
88
+ const { editorView } = editor(
89
+ doc(p('text'), table()(tr(tdEmpty, tdEmpty, tdEmpty))),
90
+ { dragAndDropEnabled: true },
91
+ );
92
+ const ref = editorView.dom.querySelector('table');
93
+
94
+ const { container } = render(
95
+ <IntlProvider locale="en">
96
+ <NumberColumn
97
+ tableRef={ref!}
98
+ tableActive
99
+ editorView={editorView}
100
+ hoverRows={jest.fn()}
101
+ selectRow={jest.fn()}
102
+ isDragAndDropEnabled
103
+ />
104
+ </IntlProvider>,
105
+ );
106
+
107
+ const firstNumberedCells = container.querySelectorAll(
108
+ `.${ClassName.NUMBERED_COLUMN} > div`,
109
+ );
110
+
111
+ firstNumberedCells.forEach((cell) => {
112
+ expect(
113
+ cell.classList.contains(ClassName.NUMBERED_COLUMN_BUTTON_DISABLED),
114
+ ).toBeTruthy();
115
+ });
116
+ });
117
+
118
+ it('should render buttons for numbered column cells - when drag and drop is disabled', () => {
119
+ const { editorView } = editor(
120
+ doc(p('text'), table()(tr(tdEmpty, tdEmpty, tdEmpty))),
121
+ { dragAndDropEnabled: false },
122
+ );
123
+ const ref = editorView.dom.querySelector('table');
124
+
125
+ const { container } = render(
126
+ <IntlProvider locale="en">
127
+ <NumberColumn
128
+ tableRef={ref!}
129
+ tableActive
130
+ editorView={editorView}
131
+ hoverRows={jest.fn()}
132
+ selectRow={jest.fn()}
133
+ isDragAndDropEnabled={false}
134
+ />
135
+ </IntlProvider>,
136
+ );
137
+
138
+ const firstNumberedCells = container.querySelectorAll(
139
+ `.${ClassName.NUMBERED_COLUMN} > div`,
140
+ );
141
+
142
+ firstNumberedCells.forEach((cell) => {
143
+ expect(
144
+ cell.classList.contains(ClassName.NUMBERED_COLUMN_BUTTON_DISABLED),
145
+ ).toBeFalsy();
146
+ });
147
+ });
148
+ });
@@ -41,7 +41,6 @@ import { RowControls } from '../../../plugins/table/ui/TableFloatingControls/Row
41
41
 
42
42
  describe('RowControls', () => {
43
43
  const createEditor = createProsemirrorEditorFactory();
44
- const fakeGetEditorFeatureFlags = jest.fn(() => ({}));
45
44
  let originalResizeObserver: any;
46
45
 
47
46
  beforeAll(() => {
@@ -94,7 +93,8 @@ describe('RowControls', () => {
94
93
  tableRef={ref}
95
94
  tableActive
96
95
  editorView={editorView}
97
- getEditorFeatureFlags={fakeGetEditorFeatureFlags}
96
+ isDragAndDropEnabled={false}
97
+ selection={editorView.state.selection}
98
98
  />
99
99
  </IntlProvider>,
100
100
  );
@@ -116,7 +116,6 @@ describe('RowControls', () => {
116
116
  tableRef={ref}
117
117
  tableActive={false}
118
118
  editorView={editorView}
119
- getEditorFeatureFlags={fakeGetEditorFeatureFlags}
120
119
  />
121
120
  </IntlProvider>,
122
121
  );
@@ -145,7 +144,8 @@ describe('RowControls', () => {
145
144
  tableRef={ref}
146
145
  tableActive
147
146
  editorView={editorView}
148
- getEditorFeatureFlags={fakeGetEditorFeatureFlags}
147
+ isDragAndDropEnabled={false}
148
+ selection={editorView.state.selection}
149
149
  />
150
150
  </IntlProvider>,
151
151
  );