@atlaskit/editor-plugin-table 0.1.0 → 0.1.1

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 (190) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
  3. package/dist/cjs/version.json +1 -1
  4. package/dist/es2019/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
  5. package/dist/es2019/version.json +1 -1
  6. package/dist/esm/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
  7. package/dist/esm/version.json +1 -1
  8. package/examples/99-testing.tsx +35 -30
  9. package/package.json +2 -11
  10. package/src/__tests__/integration/__fixtures__/auto-size-documents.ts +5 -10
  11. package/src/__tests__/integration/__fixtures__/layout-documents.ts +1 -2
  12. package/src/__tests__/integration/__fixtures__/resize-documents.ts +5 -10
  13. package/src/__tests__/integration/resize.ts +1 -2
  14. package/src/__tests__/unit/analytics.ts +33 -32
  15. package/src/__tests__/unit/collab.ts +12 -9
  16. package/src/__tests__/unit/commands/sort.ts +28 -28
  17. package/src/__tests__/unit/copy-paste.ts +6 -8
  18. package/src/__tests__/unit/event-handlers.ts +7 -10
  19. package/src/__tests__/unit/fix-tables.ts +17 -23
  20. package/src/__tests__/unit/get-toolbar-config.ts +0 -5
  21. package/src/__tests__/unit/hover-selection.ts +1 -66
  22. package/src/__tests__/unit/index-with-fake-timers.ts +1 -1
  23. package/src/__tests__/unit/index.ts +5 -5
  24. package/src/__tests__/unit/nodeviews/TableComponent.tsx +11 -218
  25. package/src/__tests__/unit/nodeviews/cell.ts +12 -10
  26. package/src/__tests__/unit/nodeviews/table.ts +25 -26
  27. package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +11 -8
  28. package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +11 -12
  29. package/src/__tests__/unit/toolbar.ts +18 -5
  30. package/src/__tests__/unit/ui/ContextualMenu.tsx +55 -0
  31. package/src/__tests__/unit/ui/CornerControls.tsx +7 -7
  32. package/src/__tests__/unit/ui/FloatingContextualButton.tsx +45 -49
  33. package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +49 -0
  34. package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +30 -2
  35. package/src/__tests__/unit/ui/FloatingInsertButton.tsx +143 -111
  36. package/src/__tests__/unit/ui/RowControls.tsx +112 -141
  37. package/src/__tests__/unit/ui/TableFloatingControls.tsx +18 -15
  38. package/src/__tests__/unit/undo-redo.ts +10 -9
  39. package/src/__tests__/unit/utils/nodes.ts +8 -4
  40. package/src/__tests__/unit/utils/row-controls.ts +8 -4
  41. package/src/plugins/table/commands/clear.ts +30 -29
  42. package/src/plugins/table/commands/go-to-next-cell.ts +41 -38
  43. package/src/plugins/table/commands/insert.ts +91 -91
  44. package/src/plugins/table/commands/misc.ts +123 -125
  45. package/src/plugins/table/commands/selection.ts +329 -319
  46. package/src/plugins/table/commands-with-analytics.ts +299 -294
  47. package/src/plugins/table/event-handlers.ts +111 -111
  48. package/src/plugins/table/handlers.ts +95 -94
  49. package/src/plugins/table/nodeviews/OverflowShadowsObserver.ts +4 -3
  50. package/src/plugins/table/nodeviews/TableComponent.tsx +6 -9
  51. package/src/plugins/table/nodeviews/update-overflow-shadows.ts +39 -39
  52. package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +7 -9
  53. package/src/plugins/table/pm-plugins/decorations/utils/column-resizing.ts +30 -30
  54. package/src/plugins/table/pm-plugins/decorations/utils/compose-decorations.ts +7 -7
  55. package/src/plugins/table/pm-plugins/plugin-factory.ts +33 -33
  56. package/src/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.ts +6 -9
  57. package/src/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.ts +3 -2
  58. package/src/plugins/table/pm-plugins/table-resizing/commands.ts +98 -90
  59. package/src/plugins/table/pm-plugins/table-resizing/utils/dom.ts +46 -47
  60. package/src/plugins/table/toolbar.tsx +116 -113
  61. package/src/plugins/table/transforms/column-width.ts +143 -146
  62. package/src/plugins/table/transforms/delete-columns.ts +144 -142
  63. package/src/plugins/table/transforms/delete-rows.ts +110 -111
  64. package/src/plugins/table/transforms/metadata.ts +9 -9
  65. package/src/plugins/table/ui/FloatingContextualMenu/ContextualMenu.tsx +7 -6
  66. package/src/plugins/table/ui/FloatingDeleteButton/index.tsx +3 -2
  67. package/src/plugins/table/ui/FloatingInsertButton/index.tsx +2 -5
  68. package/src/plugins/table/ui/LayoutButton/index.tsx +2 -6
  69. package/src/plugins/table/ui/common-styles.ts +1 -3
  70. package/src/plugins/table/utils/analytics.ts +24 -25
  71. package/src/plugins/table/utils/dom.ts +3 -3
  72. package/src/plugins/table/utils/row-controls.ts +92 -93
  73. package/dist/types-ts4.0/index.d.ts +0 -1
  74. package/dist/types-ts4.0/plugins/table/commands/clear.d.ts +0 -3
  75. package/dist/types-ts4.0/plugins/table/commands/collapse.d.ts +0 -2
  76. package/dist/types-ts4.0/plugins/table/commands/go-to-next-cell.d.ts +0 -4
  77. package/dist/types-ts4.0/plugins/table/commands/hover.d.ts +0 -8
  78. package/dist/types-ts4.0/plugins/table/commands/index.d.ts +0 -7
  79. package/dist/types-ts4.0/plugins/table/commands/insert.d.ts +0 -10
  80. package/dist/types-ts4.0/plugins/table/commands/misc.d.ts +0 -27
  81. package/dist/types-ts4.0/plugins/table/commands/selection.d.ts +0 -8
  82. package/dist/types-ts4.0/plugins/table/commands/sort.d.ts +0 -3
  83. package/dist/types-ts4.0/plugins/table/commands/split-cell.d.ts +0 -6
  84. package/dist/types-ts4.0/plugins/table/commands/toggle.d.ts +0 -12
  85. package/dist/types-ts4.0/plugins/table/commands-with-analytics.d.ts +0 -26
  86. package/dist/types-ts4.0/plugins/table/create-plugin-config.d.ts +0 -2
  87. package/dist/types-ts4.0/plugins/table/event-handlers.d.ts +0 -16
  88. package/dist/types-ts4.0/plugins/table/handlers.d.ts +0 -3
  89. package/dist/types-ts4.0/plugins/table/index.d.ts +0 -17
  90. package/dist/types-ts4.0/plugins/table/nodeviews/OverflowShadowsObserver.d.ts +0 -26
  91. package/dist/types-ts4.0/plugins/table/nodeviews/TableComponent.d.ts +0 -72
  92. package/dist/types-ts4.0/plugins/table/nodeviews/__mocks__/OverflowShadowsObserver.d.ts +0 -9
  93. package/dist/types-ts4.0/plugins/table/nodeviews/__mocks__/OverridableMock.d.ts +0 -9
  94. package/dist/types-ts4.0/plugins/table/nodeviews/table.d.ts +0 -31
  95. package/dist/types-ts4.0/plugins/table/nodeviews/tableCell.d.ts +0 -19
  96. package/dist/types-ts4.0/plugins/table/nodeviews/types.d.ts +0 -24
  97. package/dist/types-ts4.0/plugins/table/nodeviews/update-overflow-shadows.d.ts +0 -8
  98. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/plugin.d.ts +0 -7
  99. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +0 -3
  100. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/column-resizing.d.ts +0 -2
  101. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +0 -2
  102. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/index.d.ts +0 -3
  103. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/types.d.ts +0 -6
  104. package/dist/types-ts4.0/plugins/table/pm-plugins/default-table-selection.d.ts +0 -5
  105. package/dist/types-ts4.0/plugins/table/pm-plugins/keymap.d.ts +0 -5
  106. package/dist/types-ts4.0/plugins/table/pm-plugins/main.d.ts +0 -8
  107. package/dist/types-ts4.0/plugins/table/pm-plugins/plugin-factory.d.ts +0 -1
  108. package/dist/types-ts4.0/plugins/table/pm-plugins/plugin-key.d.ts +0 -3
  109. package/dist/types-ts4.0/plugins/table/pm-plugins/safari-delayed-dom-selection-syncing-workaround.d.ts +0 -4
  110. package/dist/types-ts4.0/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.d.ts +0 -15
  111. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/commands.d.ts +0 -3
  112. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/index.d.ts +0 -6
  113. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.d.ts +0 -6
  114. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +0 -65
  115. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin-key.d.ts +0 -3
  116. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin-state.d.ts +0 -3
  117. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin.d.ts +0 -4
  118. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/types.d.ts +0 -16
  119. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/util.d.ts +0 -2
  120. package/dist/types-ts4.0/plugins/table/pm-plugins/table-local-id.d.ts +0 -22
  121. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/commands.d.ts +0 -25
  122. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/event-handlers.d.ts +0 -4
  123. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/index.d.ts +0 -4
  124. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin-factory.d.ts +0 -4
  125. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin-key.d.ts +0 -3
  126. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin.d.ts +0 -6
  127. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/reducer.d.ts +0 -3
  128. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/colgroup.d.ts +0 -8
  129. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/column-state.d.ts +0 -14
  130. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/content-width.d.ts +0 -4
  131. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/dom.d.ts +0 -13
  132. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/index.d.ts +0 -12
  133. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +0 -22
  134. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-column.d.ts +0 -2
  135. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-logic.d.ts +0 -4
  136. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-state.d.ts +0 -29
  137. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +0 -17
  138. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/types.d.ts +0 -22
  139. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/unit-to-number.d.ts +0 -1
  140. package/dist/types-ts4.0/plugins/table/pm-plugins/table-selection-keymap.d.ts +0 -4
  141. package/dist/types-ts4.0/plugins/table/reducer.d.ts +0 -3
  142. package/dist/types-ts4.0/plugins/table/toolbar.d.ts +0 -36
  143. package/dist/types-ts4.0/plugins/table/transforms/column-width.d.ts +0 -18
  144. package/dist/types-ts4.0/plugins/table/transforms/delete-columns.d.ts +0 -3
  145. package/dist/types-ts4.0/plugins/table/transforms/delete-rows.d.ts +0 -3
  146. package/dist/types-ts4.0/plugins/table/transforms/fix-tables.d.ts +0 -10
  147. package/dist/types-ts4.0/plugins/table/transforms/index.d.ts +0 -7
  148. package/dist/types-ts4.0/plugins/table/transforms/merge.d.ts +0 -5
  149. package/dist/types-ts4.0/plugins/table/transforms/metadata.d.ts +0 -21
  150. package/dist/types-ts4.0/plugins/table/transforms/replace-table.d.ts +0 -5
  151. package/dist/types-ts4.0/plugins/table/transforms/split.d.ts +0 -9
  152. package/dist/types-ts4.0/plugins/table/types.d.ts +0 -328
  153. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualButton/index.d.ts +0 -29
  154. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualButton/styles.d.ts +0 -1
  155. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/ContextualMenu.d.ts +0 -87
  156. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/index.d.ts +0 -22
  157. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/styles.d.ts +0 -2
  158. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/DeleteButton.d.ts +0 -14
  159. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/getPopUpOptions.d.ts +0 -10
  160. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/index.d.ts +0 -54
  161. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/types.d.ts +0 -1
  162. package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +0 -12
  163. package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +0 -3
  164. package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/index.d.ts +0 -35
  165. package/dist/types-ts4.0/plugins/table/ui/LayoutButton/index.d.ts +0 -21
  166. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/CornerControls/index.d.ts +0 -16
  167. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +0 -21
  168. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +0 -17
  169. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/index.d.ts +0 -40
  170. package/dist/types-ts4.0/plugins/table/ui/common-styles.d.ts +0 -4
  171. package/dist/types-ts4.0/plugins/table/ui/consts.d.ts +0 -39
  172. package/dist/types-ts4.0/plugins/table/ui/messages.d.ts +0 -38
  173. package/dist/types-ts4.0/plugins/table/ui/ui-styles.d.ts +0 -15
  174. package/dist/types-ts4.0/plugins/table/utils/analytics.d.ts +0 -18
  175. package/dist/types-ts4.0/plugins/table/utils/collapse.d.ts +0 -29
  176. package/dist/types-ts4.0/plugins/table/utils/column-controls.d.ts +0 -10
  177. package/dist/types-ts4.0/plugins/table/utils/decoration.d.ts +0 -16
  178. package/dist/types-ts4.0/plugins/table/utils/dom.d.ts +0 -20
  179. package/dist/types-ts4.0/plugins/table/utils/get-allow-add-column-custom-step.d.ts +0 -2
  180. package/dist/types-ts4.0/plugins/table/utils/index.d.ts +0 -11
  181. package/dist/types-ts4.0/plugins/table/utils/nodes.d.ts +0 -12
  182. package/dist/types-ts4.0/plugins/table/utils/paste.d.ts +0 -14
  183. package/dist/types-ts4.0/plugins/table/utils/referentiality.d.ts +0 -2
  184. package/dist/types-ts4.0/plugins/table/utils/row-controls.d.ts +0 -16
  185. package/dist/types-ts4.0/plugins/table/utils/selection.d.ts +0 -6
  186. package/dist/types-ts4.0/plugins/table/utils/table.d.ts +0 -4
  187. package/dist/types-ts4.0/plugins/table/utils/update-plugin-state-decorations.d.ts +0 -4
  188. package/dist/types-ts4.0/plugins/table-plugin.d.ts +0 -2
  189. package/src/plugins/table/ui/FloatingContextualMenu/__tests__/ContextualMenu.tsx +0 -56
  190. package/src/plugins/table/ui/FloatingContextualMenu/__tests__/FloatingContextualMenu.tsx +0 -50
@@ -1,5 +1,10 @@
1
- import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
2
- import { mountWithIntl } from '@atlaskit/editor-test-helpers/enzyme';
1
+ import { render, screen, fireEvent } from '@testing-library/react';
2
+ import { IntlProvider } from 'react-intl-next';
3
+ import {
4
+ createProsemirrorEditorFactory,
5
+ LightEditorPlugin,
6
+ Preset,
7
+ } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
3
8
  import {
4
9
  doc,
5
10
  p,
@@ -14,39 +19,18 @@ import {
14
19
  import { selectRows } from '@atlaskit/editor-test-helpers/table';
15
20
  import { getSelectionRect, selectRow } from '@atlaskit/editor-tables/utils';
16
21
  import React from 'react';
17
- import type { EditorProps } from '@atlaskit/editor-core';
18
22
  import { setTextSelection } from '@atlaskit/editor-common/utils';
19
23
  import { hoverRows } from '../../../plugins/table/commands';
20
- import {
21
- TableCssClassName as ClassName,
22
- TablePluginState,
23
- } from '../../../plugins/table/types';
24
24
  import TableFloatingControls from '../../../plugins/table/ui/TableFloatingControls';
25
25
  import { RowControls } from '../../../plugins/table/ui/TableFloatingControls/RowControls';
26
26
  import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
27
- import { ReactWrapper } from 'enzyme';
28
27
  import tablePlugin from '../../../plugins/table-plugin';
29
28
 
30
- const ControlsButton = `.${ClassName.CONTROLS_BUTTON}`;
31
- const RowControlsButtonWrap = `.${ClassName.ROW_CONTROLS_BUTTON_WRAP}`;
32
-
33
29
  describe('RowControls', () => {
34
- const createEditor = createEditorFactory<TablePluginState>();
30
+ const createEditor = createProsemirrorEditorFactory();
35
31
  const fakeGetEditorFeatureFlags = jest.fn(() => ({}));
36
- let floatingControls: ReactWrapper;
37
32
  let originalResizeObserver: any;
38
33
 
39
- let triggerElementResize = (element: HTMLElement, height: number) => {
40
- const entries = [
41
- {
42
- target: element,
43
- contentRect: { height },
44
- },
45
- ];
46
- resizeCallback(entries);
47
- };
48
- let resizeCallback: (entries: any[]) => {};
49
-
50
34
  beforeAll(() => {
51
35
  originalResizeObserver = (window as any).ResizeObserver;
52
36
  (window as any).ResizeObserver = function resizeObserverMock(
@@ -54,7 +38,6 @@ describe('RowControls', () => {
54
38
  ) {
55
39
  this.disconnect = jest.fn();
56
40
  this.observe = jest.fn();
57
- resizeCallback = callback;
58
41
  };
59
42
  });
60
43
 
@@ -63,23 +46,13 @@ describe('RowControls', () => {
63
46
  });
64
47
 
65
48
  afterEach(() => {
66
- if (floatingControls && floatingControls.length) {
67
- floatingControls.unmount();
68
- }
69
49
  jest.clearAllMocks();
70
50
  });
71
51
 
72
- const editor = (doc: DocBuilder, props?: EditorProps) => {
73
- const { featureFlags } = props || {};
74
- fakeGetEditorFeatureFlags.mockReturnValue(featureFlags || {});
75
-
52
+ const editor = (doc: DocBuilder) => {
76
53
  return createEditor({
77
54
  doc,
78
- editorProps: {
79
- allowTables: false,
80
- dangerouslyAppendPlugins: { __plugins: [tablePlugin()] },
81
- ...props,
82
- },
55
+ preset: new Preset<LightEditorPlugin>().add(tablePlugin),
83
56
  pluginKey,
84
57
  });
85
58
  };
@@ -92,52 +65,42 @@ describe('RowControls', () => {
92
65
  rows.push(tr(tdEmpty));
93
66
  }
94
67
  const { editorView } = editor(doc(p('text'), table()(...rows)));
95
- floatingControls = mountWithIntl(
96
- <TableFloatingControls
97
- tableRef={document.querySelector('table')!}
98
- tableActive={true}
99
- editorView={editorView}
100
- getEditorFeatureFlags={fakeGetEditorFeatureFlags}
101
- />,
68
+ const ref = editorView.dom.querySelector('table') || undefined;
69
+
70
+ render(
71
+ <IntlProvider locale="en">
72
+ <TableFloatingControls
73
+ tableRef={ref}
74
+ tableActive
75
+ editorView={editorView}
76
+ getEditorFeatureFlags={fakeGetEditorFeatureFlags}
77
+ />
78
+ </IntlProvider>,
102
79
  );
103
- expect(floatingControls.find(RowControlsButtonWrap)).toHaveLength(row);
80
+
81
+ const rowControlButtons = screen.getAllByLabelText('Highlight row');
82
+
83
+ expect(rowControlButtons).toHaveLength(row);
104
84
  });
105
85
  });
106
86
  });
107
87
 
108
88
  it('does not render rowControls if table is not active', () => {
109
89
  const { editorView } = editor(doc(p('text'), table()(tr(tdCursor))));
110
- floatingControls = mountWithIntl(
111
- <TableFloatingControls
112
- tableRef={document.querySelector('table')!}
113
- tableActive={false}
114
- editorView={editorView}
115
- getEditorFeatureFlags={fakeGetEditorFeatureFlags}
116
- />,
117
- );
118
- expect(floatingControls.find(RowControlsButtonWrap)).toHaveLength(0);
119
- });
90
+ const ref = editorView.dom.querySelector('table') || undefined;
120
91
 
121
- describe('with tableRenderOptimization enabled', () => {
122
- it('updates rowControls if table height changes', () => {
123
- const { editorView } = editor(doc(table()(tr(tdCursor))), {
124
- featureFlags: { tableRenderOptimization: true },
125
- });
126
- floatingControls = mountWithIntl(
92
+ render(
93
+ <IntlProvider locale="en">
127
94
  <TableFloatingControls
128
- tableRef={document.querySelector('table')!}
129
- tableActive={true}
95
+ tableRef={ref}
96
+ tableActive={false}
130
97
  editorView={editorView}
131
98
  getEditorFeatureFlags={fakeGetEditorFeatureFlags}
132
- />,
133
- );
134
- const tableElement = editorView.domAtPos(1).node as HTMLElement;
135
- triggerElementResize(tableElement, 10);
136
- expect(floatingControls.state('tableHeight')).toBe(10);
137
- tableElement.style.height = '100px';
138
- triggerElementResize(tableElement, 100);
139
- expect(floatingControls.state('tableHeight')).toBe(100);
140
- });
99
+ />
100
+ </IntlProvider>,
101
+ );
102
+
103
+ expect(screen.queryByLabelText('Highlight row')).toBeFalsy();
141
104
  });
142
105
 
143
106
  [0, 1, 2].forEach((row) => {
@@ -153,13 +116,17 @@ describe('RowControls', () => {
153
116
  ),
154
117
  );
155
118
 
156
- floatingControls = mountWithIntl(
157
- <TableFloatingControls
158
- tableRef={document.querySelector('table')!}
159
- tableActive={true}
160
- editorView={editorView}
161
- getEditorFeatureFlags={fakeGetEditorFeatureFlags}
162
- />,
119
+ const ref = editorView.dom.querySelector('table') || undefined;
120
+
121
+ render(
122
+ <IntlProvider locale="en">
123
+ <TableFloatingControls
124
+ tableRef={ref}
125
+ tableActive
126
+ editorView={editorView}
127
+ getEditorFeatureFlags={fakeGetEditorFeatureFlags}
128
+ />
129
+ </IntlProvider>,
163
130
  );
164
131
 
165
132
  // move to header row
@@ -167,24 +134,16 @@ describe('RowControls', () => {
167
134
  setTextSelection(editorView, nextPos);
168
135
 
169
136
  // now hover the row
170
- floatingControls
171
- .find(RowControlsButtonWrap)
172
- .at(row)
173
- .find('button')
174
- .first()
175
- .simulate('mouseover');
137
+ const rowControls = screen.getAllByLabelText('Highlight row');
138
+
139
+ fireEvent.mouseOver(rowControls[row]);
176
140
 
177
141
  // assert the cursor is still in same position
178
142
  expect(editorView.state.selection.$from.pos).toBe(nextPos);
179
143
  expect(editorView.state.selection.$to.pos).toBe(nextPos);
180
144
 
181
145
  // release the hover
182
- floatingControls
183
- .find(RowControlsButtonWrap)
184
- .at(row)
185
- .find('button')
186
- .first()
187
- .simulate('mouseout');
146
+ fireEvent.mouseOut(rowControls[row]);
188
147
 
189
148
  // assert the cursor is still in same position
190
149
  expect(editorView.state.selection.$from.pos).toBe(nextPos);
@@ -204,31 +163,37 @@ describe('RowControls', () => {
204
163
  ),
205
164
  );
206
165
 
207
- floatingControls = mountWithIntl(
208
- <RowControls
209
- tableRef={document.querySelector('table')!}
210
- editorView={editorView}
211
- hoverRows={(rows, danger) => {
212
- hoverRows(rows, danger)(editorView.state, editorView.dispatch);
213
- }}
214
- hoveredRows={[0, 1]}
215
- isInDanger={true}
216
- selectRow={(row) => {
217
- editorView.dispatch(selectRow(row)(editorView.state.tr));
218
- }}
219
- />,
166
+ const ref = editorView.dom.querySelector('table') || undefined;
167
+
168
+ render(
169
+ <IntlProvider locale="en">
170
+ <RowControls
171
+ tableRef={ref!}
172
+ editorView={editorView}
173
+ hoverRows={(rows, danger) => {
174
+ hoverRows(rows, danger)(editorView.state, editorView.dispatch);
175
+ }}
176
+ hoveredRows={[0, 1]}
177
+ isInDanger={true}
178
+ selectRow={(row) => {
179
+ editorView.dispatch(selectRow(row)(editorView.state.tr));
180
+ }}
181
+ />
182
+ </IntlProvider>,
220
183
  );
221
184
 
222
- floatingControls
223
- .find(RowControlsButtonWrap)
185
+ const rowControls = screen.getAllByLabelText('Highlight row');
186
+ rowControls
224
187
  .slice(0, 2)
225
- .forEach((buttonWrap) => {
226
- expect(buttonWrap.hasClass('danger')).toBe(true);
227
- });
188
+ .forEach((control) =>
189
+ expect(
190
+ control?.parentElement?.classList?.contains('danger'),
191
+ ).toBeTruthy(),
192
+ );
228
193
  });
229
194
 
230
195
  describe('row shift selection', () => {
231
- it('should shift select rows after the currently selected row', () => {
196
+ it('should be able to shift + click to select rows after the currently selected row', () => {
232
197
  const { editorView } = editor(
233
198
  doc(
234
199
  table()(
@@ -241,29 +206,32 @@ describe('RowControls', () => {
241
206
  );
242
207
 
243
208
  selectRows([0])(editorView.state, editorView.dispatch);
244
- floatingControls = mountWithIntl(
245
- <RowControls
246
- tableRef={document.querySelector('table')!}
247
- editorView={editorView}
248
- hoverRows={(rows, danger) => {
249
- hoverRows(rows, danger)(editorView.state, editorView.dispatch);
250
- }}
251
- selectRow={(row, expand) => {
252
- editorView.dispatch(selectRow(row, expand)(editorView.state.tr));
253
- }}
254
- />,
209
+
210
+ const ref = editorView.dom.querySelector('table');
211
+
212
+ render(
213
+ <IntlProvider locale="en">
214
+ <RowControls
215
+ tableRef={ref!}
216
+ editorView={editorView}
217
+ hoverRows={(rows, danger) => {
218
+ hoverRows(rows, danger)(editorView.state, editorView.dispatch);
219
+ }}
220
+ selectRow={(row, expand) => {
221
+ editorView.dispatch(selectRow(row, expand)(editorView.state.tr));
222
+ }}
223
+ />
224
+ </IntlProvider>,
255
225
  );
256
226
 
257
- floatingControls
258
- .find(ControlsButton)
259
- .at(2)
260
- .simulate('click', { shiftKey: true });
227
+ const rowControls = screen.getAllByLabelText('Highlight row');
228
+ fireEvent.click(rowControls[2], { shiftKey: true });
261
229
 
262
230
  const rect = getSelectionRect(editorView.state.selection);
263
231
  expect(rect).toEqual({ left: 0, top: 0, right: 3, bottom: 3 });
264
232
  });
265
233
 
266
- it('should shift select row before the currently selected row', () => {
234
+ it('should be able to shift + click to select rows before the currently selected row', () => {
267
235
  const { editorView } = editor(
268
236
  doc(
269
237
  table()(
@@ -276,23 +244,26 @@ describe('RowControls', () => {
276
244
  );
277
245
 
278
246
  selectRows([2])(editorView.state, editorView.dispatch);
279
- floatingControls = mountWithIntl(
280
- <RowControls
281
- tableRef={document.querySelector('table')!}
282
- editorView={editorView}
283
- hoverRows={(rows, danger) => {
284
- hoverRows(rows, danger)(editorView.state, editorView.dispatch);
285
- }}
286
- selectRow={(row, expand) => {
287
- editorView.dispatch(selectRow(row, expand)(editorView.state.tr));
288
- }}
289
- />,
247
+
248
+ const ref = editorView.dom.querySelector('table') || undefined;
249
+
250
+ render(
251
+ <IntlProvider locale="en">
252
+ <RowControls
253
+ tableRef={ref!}
254
+ editorView={editorView}
255
+ hoverRows={(rows, danger) => {
256
+ hoverRows(rows, danger)(editorView.state, editorView.dispatch);
257
+ }}
258
+ selectRow={(row, expand) => {
259
+ editorView.dispatch(selectRow(row, expand)(editorView.state.tr));
260
+ }}
261
+ />
262
+ </IntlProvider>,
290
263
  );
291
264
 
292
- floatingControls
293
- .find(ControlsButton)
294
- .first()
295
- .simulate('click', { shiftKey: true });
265
+ const rowControls = screen.getAllByLabelText('Highlight row');
266
+ fireEvent.click(rowControls[0], { shiftKey: true });
296
267
 
297
268
  const rect = getSelectionRect(editorView.state.selection);
298
269
  expect(rect).toEqual({ left: 0, top: 0, right: 3, bottom: 3 });
@@ -1,4 +1,5 @@
1
- import { shallow, mount } from 'enzyme';
1
+ import { render, screen } from '@testing-library/react';
2
+ import { IntlProvider } from 'react-intl-next';
2
3
  import React from 'react';
3
4
 
4
5
  import {
@@ -19,8 +20,6 @@ import {
19
20
  import { TablePluginState } from '../../../plugins/table/types';
20
21
  import { hoverTable } from '../../../plugins/table/commands';
21
22
  import TableFloatingControls from '../../../plugins/table/ui/TableFloatingControls';
22
- import { CornerControls } from '../../../plugins/table/ui/TableFloatingControls/CornerControls';
23
- import { RowControls } from '../../../plugins/table/ui/TableFloatingControls/RowControls';
24
23
  import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
25
24
  import { getDecorations } from '../../../plugins/table/pm-plugins/decorations/plugin';
26
25
  import tablePlugin from '../../../plugins/table-plugin';
@@ -43,14 +42,13 @@ describe('TableFloatingControls', () => {
43
42
  const { editorView } = editor(
44
43
  doc(p('text'), table()(tr(tdEmpty, tdEmpty, tdEmpty))),
45
44
  );
46
- const floatingControls = mount(
45
+ const { container } = render(
47
46
  <TableFloatingControls
48
47
  editorView={editorView}
49
48
  getEditorFeatureFlags={fakeGetEditorFeatureFlags}
50
49
  />,
51
50
  );
52
- expect(floatingControls.html()).toEqual(null);
53
- floatingControls.unmount();
51
+ expect(container.innerHTML).toEqual('');
54
52
  });
55
53
  });
56
54
 
@@ -59,16 +57,21 @@ describe('TableFloatingControls', () => {
59
57
  const { editorView } = editor(
60
58
  doc(p('text'), table()(tr(tdEmpty, tdEmpty, tdEmpty))),
61
59
  );
62
- const floatingControls = shallow(
63
- <TableFloatingControls
64
- tableRef={document.createElement('table')}
65
- tableActive={true}
66
- editorView={editorView}
67
- getEditorFeatureFlags={fakeGetEditorFeatureFlags}
68
- />,
60
+ const ref = editorView.dom.querySelector('table') || undefined;
61
+
62
+ render(
63
+ <IntlProvider locale="en">
64
+ <TableFloatingControls
65
+ tableRef={ref}
66
+ tableActive={true}
67
+ editorView={editorView}
68
+ getEditorFeatureFlags={fakeGetEditorFeatureFlags}
69
+ />
70
+ </IntlProvider>,
69
71
  );
70
- expect(floatingControls.find(CornerControls).length).toEqual(1);
71
- expect(floatingControls.find(RowControls).length).toEqual(1);
72
+
73
+ expect(screen.getByLabelText('Highlight row')).toBeTruthy();
74
+ expect(screen.getByLabelText('Highlight table')).toBeTruthy();
72
75
  });
73
76
  });
74
77
 
@@ -1,4 +1,8 @@
1
- import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
1
+ import {
2
+ createProsemirrorEditorFactory,
3
+ LightEditorPlugin,
4
+ Preset,
5
+ } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
2
6
  import {
3
7
  doc,
4
8
  p,
@@ -12,7 +16,6 @@ import {
12
16
  tdEmpty,
13
17
  } from '@atlaskit/editor-test-helpers/doc-builder';
14
18
  import { EditorView } from 'prosemirror-view';
15
- import { TablePluginState } from '../../plugins/table/types';
16
19
  import { pluginKey as tablePluginKey } from '../../plugins/table/pm-plugins/plugin-key';
17
20
  import { redo, undo } from 'prosemirror-history';
18
21
  import { insertColumn } from '../../plugins/table/commands';
@@ -21,6 +24,7 @@ import { colsToRect } from '../../plugins/table/utils/table';
21
24
  import sendKeyToPm from '@atlaskit/editor-test-helpers/send-key-to-pm';
22
25
  import clone from 'lodash/clone';
23
26
  import tablePlugin from '../../plugins/table';
27
+ import widthPlugin from '@atlaskit/editor-core/src/plugins/width';
24
28
 
25
29
  const TABLE_LOCAL_ID = 'test-table-local-id';
26
30
 
@@ -46,7 +50,7 @@ const SHORTCUT_ADD_COLUMN_AFTER = (editorView: EditorView) =>
46
50
  sendKeyToPm(editorView, 'Ctrl-Alt-ArrowRight');
47
51
 
48
52
  describe('undo/redo with tables', () => {
49
- const createEditor = createEditorFactory<TablePluginState>();
53
+ const createEditor = createProsemirrorEditorFactory();
50
54
  const editor = (doc: DocBuilder) => {
51
55
  const tableOptions = {
52
56
  advanced: true,
@@ -54,12 +58,9 @@ describe('undo/redo with tables', () => {
54
58
  };
55
59
  return createEditor({
56
60
  doc,
57
- editorProps: {
58
- allowTables: false,
59
- dangerouslyAppendPlugins: {
60
- __plugins: [tablePlugin({ tableOptions })],
61
- },
62
- },
61
+ preset: new Preset<LightEditorPlugin>()
62
+ .add([tablePlugin, { tableOptions }])
63
+ .add(widthPlugin),
63
64
  pluginKey: tablePluginKey,
64
65
  });
65
66
  };
@@ -1,5 +1,9 @@
1
1
  import { findTable } from '@atlaskit/editor-tables/utils';
2
- import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
2
+ import {
3
+ createProsemirrorEditorFactory,
4
+ LightEditorPlugin,
5
+ Preset,
6
+ } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
3
7
  import {
4
8
  doc,
5
9
  p,
@@ -11,17 +15,17 @@ import {
11
15
  thEmpty,
12
16
  DocBuilder,
13
17
  } from '@atlaskit/editor-test-helpers/doc-builder';
14
- import { TablePluginState } from '../../../plugins/table/types';
15
18
  import { containsHeaderColumn } from '../../../plugins/table/utils/nodes';
16
19
  import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
20
+ import tablePlugin from '../../../plugins/table-plugin';
17
21
 
18
22
  describe('table merging logic', () => {
19
- const createEditor = createEditorFactory<TablePluginState>();
23
+ const createEditor = createProsemirrorEditorFactory();
20
24
 
21
25
  const editor = (doc: DocBuilder) =>
22
26
  createEditor({
23
27
  doc,
24
- editorProps: { allowTables: true },
28
+ preset: new Preset<LightEditorPlugin>().add(tablePlugin),
25
29
  pluginKey,
26
30
  });
27
31
 
@@ -2,7 +2,11 @@ import { TableMap } from '@atlaskit/editor-tables/table-map';
2
2
  import { findTable } from '@atlaskit/editor-tables/utils';
3
3
  import { uuid } from '@atlaskit/adf-schema';
4
4
 
5
- import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
5
+ import {
6
+ createProsemirrorEditorFactory,
7
+ LightEditorPlugin,
8
+ Preset,
9
+ } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
6
10
  import {
7
11
  doc,
8
12
  p,
@@ -12,9 +16,9 @@ import {
12
16
  td,
13
17
  DocBuilder,
14
18
  } from '@atlaskit/editor-test-helpers/doc-builder';
15
- import { TablePluginState } from '../../../plugins/table/types';
16
19
  import { copyPreviousRow } from '../../../plugins/table/utils/row-controls';
17
20
  import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
21
+ import tablePlugin from '../../../plugins/table-plugin';
18
22
 
19
23
  const TABLE_LOCAL_ID = 'test-table-local-id';
20
24
 
@@ -27,11 +31,11 @@ describe('table plugin: utils/row-controls.js', () => {
27
31
  uuid.setStatic(false);
28
32
  });
29
33
 
30
- const createEditor = createEditorFactory<TablePluginState>();
34
+ const createEditor = createProsemirrorEditorFactory();
31
35
  const editor = (doc: DocBuilder) =>
32
36
  createEditor({
33
37
  doc,
34
- editorProps: { allowTables: true },
38
+ preset: new Preset<LightEditorPlugin>().add(tablePlugin),
35
39
  pluginKey,
36
40
  });
37
41
 
@@ -11,39 +11,40 @@ import { Command } from '@atlaskit/editor-common/types';
11
11
  // #endregion
12
12
 
13
13
  // #region Commands
14
- export const clearMultipleCells = (targetCellPosition?: number): Command => (
15
- state,
16
- dispatch,
17
- ) => {
18
- let cursorPos: number | undefined;
19
- let { tr } = state;
14
+ export const clearMultipleCells =
15
+ (targetCellPosition?: number): Command =>
16
+ (state, dispatch) => {
17
+ let cursorPos: number | undefined;
18
+ let { tr } = state;
20
19
 
21
- if (isSelectionType(tr.selection, 'cell')) {
22
- const selection = (tr.selection as any) as CellSelection;
23
- selection.forEachCell((_node, pos) => {
24
- const $pos = tr.doc.resolve(tr.mapping.map(pos + 1));
25
- tr = emptyCell(findCellClosestToPos($pos)!, state.schema)(tr);
26
- });
27
- cursorPos = selection.$headCell.pos;
28
- } else if (targetCellPosition) {
29
- const cell = findCellClosestToPos(tr.doc.resolve(targetCellPosition + 1))!;
30
- tr = emptyCell(cell, state.schema)(tr);
31
- cursorPos = cell.pos;
32
- }
33
- if (tr.docChanged && cursorPos) {
34
- const $pos = tr.doc.resolve(tr.mapping.map(cursorPos));
35
- const textSelection = Selection.findFrom($pos, 1, true);
36
- if (textSelection) {
37
- tr.setSelection(textSelection);
20
+ if (isSelectionType(tr.selection, 'cell')) {
21
+ const selection = tr.selection as any as CellSelection;
22
+ selection.forEachCell((_node, pos) => {
23
+ const $pos = tr.doc.resolve(tr.mapping.map(pos + 1));
24
+ tr = emptyCell(findCellClosestToPos($pos)!, state.schema)(tr);
25
+ });
26
+ cursorPos = selection.$headCell.pos;
27
+ } else if (targetCellPosition) {
28
+ const cell = findCellClosestToPos(
29
+ tr.doc.resolve(targetCellPosition + 1),
30
+ )!;
31
+ tr = emptyCell(cell, state.schema)(tr);
32
+ cursorPos = cell.pos;
38
33
  }
34
+ if (tr.docChanged && cursorPos) {
35
+ const $pos = tr.doc.resolve(tr.mapping.map(cursorPos));
36
+ const textSelection = Selection.findFrom($pos, 1, true);
37
+ if (textSelection) {
38
+ tr.setSelection(textSelection);
39
+ }
39
40
 
40
- if (dispatch) {
41
- dispatch(tr);
41
+ if (dispatch) {
42
+ dispatch(tr);
43
+ }
44
+ return true;
42
45
  }
43
- return true;
44
- }
45
- return false;
46
- };
46
+ return false;
47
+ };
47
48
 
48
49
  export const clearSelection: Command = (state, dispatch) => {
49
50
  if (dispatch) {