@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,6 +1,5 @@
1
1
  import { MediaAttributes } from '@atlaskit/adf-schema';
2
2
  import { TextSelection } from 'prosemirror-state';
3
- import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
4
3
  import {
5
4
  createProsemirrorEditorFactory,
6
5
  LightEditorPlugin,
@@ -19,7 +18,6 @@ import {
19
18
  mediaGroup,
20
19
  p,
21
20
  } from '@atlaskit/editor-test-helpers/doc-builder';
22
- import { TablePluginState } from '../../plugins/table/types';
23
21
  import {
24
22
  handleMouseOver,
25
23
  handleMouseMove,
@@ -36,6 +34,7 @@ import {
36
34
  import { pluginKey } from '../../plugins/table/pm-plugins/plugin-key';
37
35
  import { TableCssClassName as ClassName } from '../../plugins/table/types';
38
36
  import tablePlugin from '../../plugins/table-plugin';
37
+ import mediaPlugin from '@atlaskit/editor-core/src/plugins/media';
39
38
 
40
39
  describe('table plugin: decorations', () => {
41
40
  const createEditor = createProsemirrorEditorFactory();
@@ -148,21 +147,19 @@ describe('table plugin: decorations', () => {
148
147
  });
149
148
 
150
149
  describe('table event handlers', () => {
151
- const createEditor = createEditorFactory<TablePluginState>();
150
+ const createEditor = createProsemirrorEditorFactory();
152
151
  const fakeGetEditorFeatureFlags = () => ({});
153
152
  const editor = (doc: DocBuilder) =>
154
153
  createEditor({
155
154
  doc,
156
- editorProps: {
157
- allowTables: false,
158
- media: {
155
+ attachTo: document.body,
156
+ preset: new Preset<LightEditorPlugin>().add(tablePlugin).add([
157
+ mediaPlugin,
158
+ {
159
159
  allowMediaSingle: true,
160
160
  allowMediaGroup: true,
161
161
  },
162
- dangerouslyAppendPlugins: {
163
- __plugins: [tablePlugin()],
164
- },
165
- },
162
+ ]),
166
163
  pluginKey,
167
164
  });
168
165
 
@@ -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,
@@ -8,21 +12,17 @@ import {
8
12
  th,
9
13
  DocBuilder,
10
14
  } from '@atlaskit/editor-test-helpers/doc-builder';
11
- import { TablePluginState, PluginConfig } from '../../plugins/table/types';
15
+ import { PluginConfig } from '../../plugins/table/types';
12
16
 
13
17
  import { pluginKey as tablePluginKey } from '../../plugins/table/pm-plugins/plugin-key';
14
18
  import tablePlugin from '../../plugins/table-plugin';
19
+
15
20
  const TABLE_LOCAL_ID = 'test-table-local-id';
16
21
 
17
22
  describe('fix tables', () => {
18
- const createEditor = createEditorFactory<TablePluginState>();
23
+ const createEditor = createProsemirrorEditorFactory();
19
24
  // @ts-ignore
20
25
  global['fetch'] = jest.fn();
21
- const createAnalyticsEvent = jest.fn();
22
-
23
- afterEach(() => {
24
- createAnalyticsEvent.mockReset();
25
- });
26
26
 
27
27
  const editor = (doc: DocBuilder) => {
28
28
  const tableOptions = {
@@ -35,18 +35,12 @@ describe('fix tables', () => {
35
35
 
36
36
  return createEditor({
37
37
  doc,
38
- editorProps: {
39
- dangerouslyAppendPlugins: {
40
- __plugins: [
41
- tablePlugin({
42
- tableOptions,
43
- }),
44
- ],
45
- },
46
- allowAnalyticsGASV3: true,
47
- },
38
+ attachTo: document.body,
39
+ preset: new Preset<LightEditorPlugin>().add([
40
+ tablePlugin,
41
+ { tableOptions },
42
+ ]),
48
43
  pluginKey: tablePluginKey,
49
- createAnalyticsEvent,
50
44
  });
51
45
  };
52
46
 
@@ -92,7 +86,7 @@ describe('fix tables', () => {
92
86
  const TABLE_LOCAL_ID = 'test-table-2';
93
87
  const SPAN_VALUE = -2;
94
88
  it('should fire v3 analytics', () => {
95
- editor(
89
+ const { dispatchAnalyticsEvent } = editor(
96
90
  doc(
97
91
  table({ localId: TABLE_LOCAL_ID })(
98
92
  tr(
@@ -105,7 +99,7 @@ describe('fix tables', () => {
105
99
  ),
106
100
  );
107
101
 
108
- expect(createAnalyticsEvent).toHaveBeenCalledWith(
102
+ expect(dispatchAnalyticsEvent).toHaveBeenCalledWith(
109
103
  expect.objectContaining({
110
104
  action: 'invalidDocumentEncountered',
111
105
  actionSubject: 'editor',
@@ -125,7 +119,7 @@ describe('fix tables', () => {
125
119
  const TABLE_LOCAL_ID = 'test-table-3';
126
120
  const SPAN_VALUE = -2;
127
121
  it('should fire v3 analytics', () => {
128
- editor(
122
+ const { dispatchAnalyticsEvent } = editor(
129
123
  doc(
130
124
  table({ localId: TABLE_LOCAL_ID })(
131
125
  tr(
@@ -138,7 +132,7 @@ describe('fix tables', () => {
138
132
  ),
139
133
  );
140
134
 
141
- expect(createAnalyticsEvent).toHaveBeenCalledWith(
135
+ expect(dispatchAnalyticsEvent).toHaveBeenCalledWith(
142
136
  expect.objectContaining({
143
137
  action: 'invalidDocumentEncountered',
144
138
  actionSubject: 'editor',
@@ -65,11 +65,6 @@ describe('getToolbarConfig', () => {
65
65
  return button;
66
66
  };
67
67
 
68
- /**
69
- * Use `createEditorFactory` here to enable referentiality as
70
- * `createProsemirrorEditorFactory` has some issues with correctly mimicking
71
- * old state for the unique localId plugin
72
- */
73
68
  const createEditorFn = createProsemirrorEditorFactory();
74
69
  const createEditor = (doc: DocBuilder) => {
75
70
  const output = createEditorFn({
@@ -26,11 +26,7 @@ import {
26
26
  hoverRows,
27
27
  hoverTable,
28
28
  } from '../../plugins/table/commands';
29
- import {
30
- TableDecorations,
31
- TableCssClassName as ClassName,
32
- TablePluginState,
33
- } from '../../plugins/table/types';
29
+ import { TableDecorations, TablePluginState } from '../../plugins/table/types';
34
30
  import { pluginKey } from '../../plugins/table/pm-plugins/plugin-key';
35
31
  import { getDecorations } from '../../plugins/table/pm-plugins/decorations/plugin';
36
32
  import tablePlugin from '../../plugins/table-plugin';
@@ -130,51 +126,6 @@ describe('table hover selection plugin', () => {
130
126
  // selection spans 2 cells in the selected column (because we have 2 rows in the table)
131
127
  expect(decos).toHaveLength(2);
132
128
  });
133
-
134
- it('should apply the hovered column class', () => {
135
- hoverColumns([column])(editorView.state, editorView.dispatch);
136
-
137
- const decos = getTableDecorations(
138
- editorView,
139
- getCellsInColumn(column)(editorView.state.selection)!,
140
- TableDecorations.ALL_CONTROLS_HOVER,
141
- );
142
-
143
- decos.forEach((deco) => {
144
- expect(deco).toEqual(
145
- expect.objectContaining({
146
- type: expect.objectContaining({
147
- attrs: expect.objectContaining({
148
- class: expect.stringContaining(ClassName.HOVERED_COLUMN),
149
- }),
150
- }),
151
- }),
152
- );
153
- });
154
- });
155
-
156
- it('can apply the danger class to the decoration', () => {
157
- hoverColumns([column], true)(editorView.state, editorView.dispatch);
158
-
159
- const decos = getTableDecorations(
160
- editorView,
161
- getCellsInColumn(column)(editorView.state.selection)!,
162
- TableDecorations.ALL_CONTROLS_HOVER,
163
- );
164
-
165
- expect(decos).toHaveLength(2);
166
- const expected = [
167
- ClassName.HOVERED_CELL_IN_DANGER,
168
- ClassName.HOVERED_COLUMN,
169
- ];
170
-
171
- decos.forEach((deco) => {
172
- // @ts-ignore
173
- expect(deco.type.attrs.class.split(' ')).toEqual(
174
- expect.arrayContaining(expected),
175
- );
176
- });
177
- });
178
129
  },
179
130
  );
180
131
  });
@@ -224,22 +175,6 @@ describe('table hover selection plugin', () => {
224
175
  ),
225
176
  ).toHaveLength(2);
226
177
  });
227
-
228
- it('can apply the danger class to the decoration', () => {
229
- hoverRows([row], true)(editorView.state, editorView.dispatch);
230
- const cells = getCellsInRow(row)(editorView.state.selection)!;
231
- const decos = getTableDecorations(
232
- editorView,
233
- cells,
234
- TableDecorations.ALL_CONTROLS_HOVER,
235
- );
236
-
237
- expect(decos).toHaveLength(2);
238
- decos.forEach((deco) => {
239
- // @ts-ignore
240
- expect(deco.type.attrs.class.split(' ')).toContain('danger');
241
- });
242
- });
243
178
  });
244
179
  });
245
180
  });
@@ -72,7 +72,7 @@ describe.skip('TableView', () => {
72
72
  // create the NodeView
73
73
  const node = table()(tr(tdCursor, tdEmpty, tdEmpty))(defaultSchema);
74
74
  const { editorView, portalProviderAPI } = editor(doc(p()));
75
- const eventDispatcher = ({ on: () => {} } as unknown) as EventDispatcher;
75
+ const eventDispatcher = { on: () => {} } as unknown as EventDispatcher;
76
76
  const tableView = new TableView({
77
77
  node,
78
78
  allowColumnResizing: false,
@@ -450,8 +450,8 @@ describe('table plugin', () => {
450
450
  );
451
451
 
452
452
  editorView.dispatch(selectColumn(column)(editorView.state.tr));
453
- const selection = (editorView.state
454
- .selection as any) as CellSelection;
453
+ const selection = editorView.state
454
+ .selection as any as CellSelection;
455
455
  const tableNode = selection.$anchorCell.node(-1);
456
456
  const map = TableMap.get(tableNode);
457
457
  const start = selection.$anchorCell.start(-1);
@@ -476,8 +476,8 @@ describe('table plugin', () => {
476
476
  );
477
477
 
478
478
  editorView.dispatch(selectRow(row)(editorView.state.tr));
479
- const selection = (editorView.state
480
- .selection as any) as CellSelection;
479
+ const selection = editorView.state
480
+ .selection as any as CellSelection;
481
481
  const anchor = selection.$anchorCell.index(-1);
482
482
  const head = selection.$headCell.index(-1);
483
483
  expect(anchor).toEqual(row);
@@ -496,7 +496,7 @@ describe('table plugin', () => {
496
496
  );
497
497
 
498
498
  editorView.dispatch(selectTable(editorView.state.tr));
499
- const selection = (editorView.state.selection as any) as CellSelection;
499
+ const selection = editorView.state.selection as any as CellSelection;
500
500
  expect(selection.isRowSelection()).toEqual(true);
501
501
  expect(selection.isColSelection()).toEqual(true);
502
502
  });
@@ -1,7 +1,6 @@
1
1
  import React from 'react';
2
- import { mount, ReactWrapper, shallow } from 'enzyme';
3
2
  import { replaceRaf } from 'raf-stub';
4
-
3
+ import { render } from '@testing-library/react';
5
4
  import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
6
5
  import tablePlugin from '../../../plugins/table-plugin';
7
6
  import {
@@ -13,7 +12,6 @@ import {
13
12
  tdEmpty,
14
13
  tdCursor,
15
14
  DocBuilder,
16
- thEmpty,
17
15
  } from '@atlaskit/editor-test-helpers/doc-builder';
18
16
  import { findTable, selectTable } from '@atlaskit/editor-tables/utils';
19
17
  import {
@@ -21,15 +19,10 @@ import {
21
19
  TablePluginState,
22
20
  } from '../../../plugins/table/types';
23
21
  import TableComponent from '../../../plugins/table/nodeviews/TableComponent';
24
- import { OverflowShadowsObserver } from '../../../plugins/table/nodeviews/OverflowShadowsObserver';
22
+
25
23
  import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
26
24
  import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
27
25
  import { toggleNumberColumn } from '../../../plugins/table/commands';
28
- import {
29
- pluginKey as stickyHeadersPluginKey,
30
- StickyPluginState,
31
- } from '../../../plugins/table/pm-plugins/sticky-headers';
32
- import { tablesHaveDifferentColumnWidths } from '../../../plugins/table/utils/nodes';
33
26
 
34
27
  jest.mock('../../../plugins/table/utils/nodes', () =>
35
28
  Object.assign({}, jest.requireActual('../../../plugins/table/utils/nodes'), {
@@ -37,17 +30,12 @@ jest.mock('../../../plugins/table/utils/nodes', () =>
37
30
  }),
38
31
  );
39
32
 
40
- // with this jest will load mocked class from the relative __mocks__ folder
41
- jest.mock('../../../plugins/table/nodeviews/OverflowShadowsObserver');
42
-
43
33
  replaceRaf();
44
34
  const requestAnimationFrame = window.requestAnimationFrame as any;
45
35
 
46
36
  describe('table -> nodeviews -> TableComponent.tsx', () => {
47
37
  const createEditor = createEditorFactory<TablePluginState>();
48
- //
49
38
  const getEditorFeatureFlags = jest.fn();
50
- //
51
39
  const editor = (
52
40
  doc: DocBuilder,
53
41
  featureFlags?: { [featureFlag: string]: string | boolean },
@@ -65,7 +53,6 @@ describe('table -> nodeviews -> TableComponent.tsx', () => {
65
53
  pluginKey,
66
54
  });
67
55
  };
68
- //
69
56
  afterEach(() => {
70
57
  jest.clearAllMocks();
71
58
  });
@@ -165,224 +152,30 @@ describe('table -> nodeviews -> TableComponent.tsx', () => {
165
152
 
166
153
  const tableF = findTable(view.state.selection);
167
154
  const getNode = () => tableF!.node;
168
- const wrapper = shallow(
169
- <TableComponent
170
- view={view}
171
- eventDispatcher={({ on: () => {} } as any) as EventDispatcher}
172
- // @ts-ignore
173
- containerWidth={{}}
174
- // @ts-ignore
175
- getNode={getNode}
176
- getEditorFeatureFlags={getEditorFeatureFlags}
177
- {...props}
178
- />,
179
- );
180
-
181
- expect(wrapper.hasClass(ClassName.WITH_CONTROLS)).toBe(expected);
182
- });
183
- });
184
-
185
- describe('overflowShadowOptimization', () => {
186
- let overflowShadowsConstructorSpy = jest.fn();
187
- let updateStickyShadowsSpy = jest.fn();
188
- let observeCellsSpy = jest.fn();
189
- let disposeSpy = jest.fn();
190
- beforeAll(() => {
191
- (OverflowShadowsObserver as any).setMock('observeCells', observeCellsSpy);
192
- (OverflowShadowsObserver as any).setMock('dispose', disposeSpy);
193
- (OverflowShadowsObserver as any).setMock(
194
- 'updateStickyShadows',
195
- updateStickyShadowsSpy,
196
- );
197
- (OverflowShadowsObserver as any).setMock(
198
- 'constructor',
199
- overflowShadowsConstructorSpy,
200
- );
201
- });
202
-
203
- afterAll(() => {
204
- (OverflowShadowsObserver as any).resetMocks();
205
- });
206
-
207
- let triggerDispatcherEvent: { [key: string]: any } = {};
208
- const tablePos = 0;
209
-
210
- function setupTable(tableOverflowShadowsOptimization: boolean = false) {
211
- const editorData = editor(
212
- doc(
213
- table()(
214
- tr(thEmpty, thEmpty, thEmpty),
215
- tr(td()(p('{<>}text')), tdEmpty, tdEmpty),
216
- ),
217
- ),
218
- {
219
- tableOverflowShadowsOptimization,
220
- },
221
- );
222
-
223
- const view = editorData.editorView;
224
- const tableF = findTable(view.state.selection);
225
-
226
- const getNode = () => view.state.doc.firstChild!;
227
- const wrapper = mount(
155
+ const { container } = render(
228
156
  <TableComponent
229
157
  view={view}
230
158
  eventDispatcher={
231
- ({
232
- on: (key: string, action: Function) => {
233
- triggerDispatcherEvent[key] = action;
234
- },
235
- off: jest.fn(),
236
- } as any) as EventDispatcher
159
+ { on: jest.fn(), off: jest.fn() } as unknown as EventDispatcher
237
160
  }
238
161
  // @ts-ignore
239
162
  containerWidth={{}}
240
- pluginState={{
241
- pluginConfig: {
242
- allowControls: false,
243
- },
244
- }}
245
- getPos={() => tablePos}
246
163
  getNode={getNode}
247
- node={tableF!.node}
248
- contentDOM={(wrapper: HTMLElement | null) => {
164
+ contentDOM={(contentElement: HTMLElement | null) => {
249
165
  const node = view.dom.getElementsByTagName('table')[0];
250
166
 
251
- if (!wrapper?.firstChild) {
252
- wrapper?.appendChild(node);
167
+ if (!contentElement?.firstChild) {
168
+ contentElement?.appendChild(node);
253
169
  }
254
170
  }}
255
171
  getEditorFeatureFlags={getEditorFeatureFlags}
172
+ {...props}
256
173
  />,
257
174
  );
258
-
259
- return { wrapper, view };
260
- }
261
-
262
- describe('with optimization on', () => {
263
- let wrapper: ReactWrapper;
264
- beforeEach(() => {
265
- wrapper = setupTable(true).wrapper;
266
- });
267
-
268
- it('inits overflow shadows observer', () => {
269
- const tableWrapperNode = wrapper
270
- .find(`.${ClassName.TABLE_NODE_WRAPPER}`)
271
- .getDOMNode();
272
- const tableNode = tableWrapperNode.querySelector('table');
273
- wrapper.setProps({});
274
- expect(overflowShadowsConstructorSpy).toHaveBeenCalledWith(
275
- expect.any(Function),
276
- tableNode,
277
- tableWrapperNode,
278
- );
279
- });
280
-
281
- it('observes table cells on component update', () => {
282
- expect(observeCellsSpy).not.toHaveBeenCalled();
283
- wrapper.setProps({});
284
- expect(observeCellsSpy).toHaveBeenCalledTimes(1);
285
- });
286
-
287
- it('updates sticky shadows on sticky state changed', () => {
288
- const newStickyState: StickyPluginState = [
289
- {
290
- pos: tablePos + 1,
291
- top: 0,
292
- padding: 10,
293
- sticky: true,
294
- },
295
- ];
296
- triggerDispatcherEvent[(stickyHeadersPluginKey as any).key](
297
- newStickyState,
298
- );
299
- expect(updateStickyShadowsSpy).toHaveBeenCalled();
300
- });
301
-
302
- it('disposes shadows observer on unmount', () => {
303
- wrapper.setProps({});
304
- wrapper.unmount();
305
- expect(disposeSpy).toHaveBeenCalled();
306
- });
307
- });
308
-
309
- describe('with optimization off', () => {
310
- let wrapper: ReactWrapper;
311
- beforeEach(() => {
312
- wrapper = setupTable(false).wrapper;
313
- });
314
-
315
- it('does not init overflow shadows observer', () => {
316
- wrapper.setProps({});
317
- expect(overflowShadowsConstructorSpy).not.toHaveBeenCalled();
318
- });
319
- });
320
- });
321
-
322
- describe('when media fullscreen is changed', () => {
323
- function setupTable(isMediaFullscreen: boolean) {
324
- const editorData = editor(
325
- doc(
326
- table()(
327
- tr(thEmpty, thEmpty, thEmpty),
328
- tr(td()(p('{<>}text')), tdEmpty, tdEmpty),
329
- ),
330
- ),
331
- );
332
-
333
- const view = editorData.editorView;
334
- const tableF = findTable(view.state.selection);
335
- let triggerDispatcherEvent: { [key: string]: any } = {};
336
- const getNode = () => view.state.doc.firstChild!;
337
- const tablePos = 0;
338
-
339
- const wrapper = mount(
340
- <TableComponent
341
- view={view}
342
- eventDispatcher={
343
- ({
344
- on: (key: string, action: Function) => {
345
- triggerDispatcherEvent[key] = action;
346
- },
347
- off: jest.fn(),
348
- } as any) as EventDispatcher
349
- }
350
- // @ts-ignore
351
- containerWidth={{}}
352
- pluginState={{
353
- pluginConfig: {
354
- allowControls: false,
355
- },
356
- }}
357
- getPos={() => tablePos}
358
- getNode={getNode}
359
- node={tableF!.node}
360
- contentDOM={(wrapper: HTMLElement | null) => {
361
- const node = view.dom.getElementsByTagName('table')[0];
362
- if (!wrapper?.firstChild) {
363
- wrapper?.appendChild(node);
364
- }
365
- }}
366
- isMediaFullscreen={isMediaFullscreen}
367
- allowColumnResizing={true}
368
- getEditorFeatureFlags={getEditorFeatureFlags}
369
- />,
175
+ const controlsContainer = container.querySelector(
176
+ `.${ClassName.WITH_CONTROLS}`,
370
177
  );
371
- return { wrapper, view };
372
- }
373
-
374
- it('when media is not fullscreen', () => {
375
- const wrapper = setupTable(false).wrapper;
376
- wrapper.setProps({});
377
-
378
- expect(tablesHaveDifferentColumnWidths).toHaveBeenCalled();
379
- });
380
-
381
- it('when media is fullscreen', () => {
382
- const wrapper = setupTable(true).wrapper;
383
- wrapper.setProps({});
384
-
385
- expect(tablesHaveDifferentColumnWidths).not.toHaveBeenCalled();
178
+ expect(!!controlsContainer).toBe(expected);
386
179
  });
387
180
  });
388
181
  });
@@ -2,7 +2,11 @@ import {
2
2
  setCellAttrs,
3
3
  findCellClosestToPos,
4
4
  } from '@atlaskit/editor-tables/utils';
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,
@@ -19,13 +23,14 @@ import {
19
23
  rgbToHex,
20
24
  uuid,
21
25
  } from '@atlaskit/adf-schema';
22
- import { TablePluginState, PluginConfig } from '../../../plugins/table/types';
26
+ import { PluginConfig } from '../../../plugins/table/types';
23
27
  import { mergeCells } from '../../../plugins/table/transforms';
24
28
  import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
25
29
  import TableCellViews from '../../../plugins/table/nodeviews/tableCell';
26
30
  import sendKeyToPm from '@atlaskit/editor-test-helpers/send-key-to-pm';
27
31
  import * as domHelpers from '../../../plugins/table/pm-plugins/sticky-headers/nodeviews/dom';
28
32
  import tablePlugin from '../../../plugins/table-plugin';
33
+ import undoRedoPlugin from '@atlaskit/editor-core/src/plugins/undo-redo';
29
34
 
30
35
  jest.mock('@atlaskit/editor-common/utils', () => ({
31
36
  ...jest.requireActual<Object>('@atlaskit/editor-common/utils'),
@@ -36,18 +41,15 @@ jest.mock('@atlaskit/editor-common/utils', () => ({
36
41
 
37
42
  describe('table -> nodeviews -> tableCell.tsx', () => {
38
43
  const TABLE_LOCAL_ID = 'test-table-local-id';
39
- const createEditor = createEditorFactory<TablePluginState>();
44
+ const createEditor = createProsemirrorEditorFactory();
40
45
 
41
46
  const editor = (doc: DocBuilder, props?: PluginConfig) =>
42
47
  createEditor({
43
48
  doc,
44
- editorProps: {
45
- dangerouslyAppendPlugins: {
46
- __plugins: [
47
- tablePlugin({ tableOptions: { advanced: true, ...props } }),
48
- ],
49
- },
50
- },
49
+ attachTo: document.body,
50
+ preset: new Preset<LightEditorPlugin>()
51
+ .add([tablePlugin, { tableOptions: { advanced: true, ...props } }])
52
+ .add(undoRedoPlugin),
51
53
  pluginKey,
52
54
  });
53
55