@atlaskit/editor-plugin-table 0.2.2 → 0.2.4

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 (83) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/cjs/plugins/table/commands/hover.js +2 -1
  3. package/dist/cjs/plugins/table/event-handlers.js +9 -13
  4. package/dist/cjs/plugins/table/index.js +3 -1
  5. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +15 -5
  6. package/dist/cjs/plugins/table/pm-plugins/default-table-selection.js +1 -2
  7. package/dist/cjs/plugins/table/pm-plugins/main.js +2 -2
  8. package/dist/cjs/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +42 -8
  9. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +1 -1
  10. package/dist/cjs/plugins/table/toolbar.js +42 -10
  11. package/dist/cjs/plugins/table/ui/FloatingContextualButton/index.js +7 -1
  12. package/dist/cjs/plugins/table/ui/FloatingContextualButton/styles.js +34 -6
  13. package/dist/cjs/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +4 -1
  14. package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
  15. package/dist/cjs/plugins/table/ui/consts.js +4 -4
  16. package/dist/cjs/plugins/table/ui/ui-styles.js +5 -5
  17. package/dist/cjs/version.json +1 -1
  18. package/dist/es2019/plugins/table/commands/hover.js +2 -1
  19. package/dist/es2019/plugins/table/event-handlers.js +10 -13
  20. package/dist/es2019/plugins/table/index.js +1 -1
  21. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +12 -1
  22. package/dist/es2019/plugins/table/pm-plugins/default-table-selection.js +1 -2
  23. package/dist/es2019/plugins/table/pm-plugins/main.js +2 -2
  24. package/dist/es2019/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +31 -4
  25. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +1 -1
  26. package/dist/es2019/plugins/table/toolbar.js +43 -12
  27. package/dist/es2019/plugins/table/ui/FloatingContextualButton/index.js +6 -2
  28. package/dist/es2019/plugins/table/ui/FloatingContextualButton/styles.js +47 -8
  29. package/dist/es2019/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +4 -1
  30. package/dist/es2019/plugins/table/ui/common-styles.js +9 -9
  31. package/dist/es2019/plugins/table/ui/consts.js +5 -5
  32. package/dist/es2019/plugins/table/ui/ui-styles.js +5 -5
  33. package/dist/es2019/version.json +1 -1
  34. package/dist/esm/plugins/table/commands/hover.js +2 -1
  35. package/dist/esm/plugins/table/event-handlers.js +10 -14
  36. package/dist/esm/plugins/table/index.js +3 -1
  37. package/dist/esm/plugins/table/nodeviews/TableComponent.js +17 -6
  38. package/dist/esm/plugins/table/pm-plugins/default-table-selection.js +1 -2
  39. package/dist/esm/plugins/table/pm-plugins/main.js +2 -2
  40. package/dist/esm/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +43 -8
  41. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +1 -1
  42. package/dist/esm/plugins/table/toolbar.js +43 -12
  43. package/dist/esm/plugins/table/ui/FloatingContextualButton/index.js +8 -2
  44. package/dist/esm/plugins/table/ui/FloatingContextualButton/styles.js +28 -5
  45. package/dist/esm/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +4 -1
  46. package/dist/esm/plugins/table/ui/common-styles.js +1 -1
  47. package/dist/esm/plugins/table/ui/consts.js +5 -5
  48. package/dist/esm/plugins/table/ui/ui-styles.js +5 -5
  49. package/dist/esm/version.json +1 -1
  50. package/dist/types/plugins/table/event-handlers.d.ts +2 -2
  51. package/dist/types/plugins/table/pm-plugins/default-table-selection.d.ts +0 -1
  52. package/dist/types/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +8 -0
  53. package/dist/types/plugins/table/toolbar.d.ts +3 -2
  54. package/dist/types/plugins/table/ui/FloatingContextualButton/styles.d.ts +3 -1
  55. package/dist/types/plugins/table/ui/FloatingContextualMenu/styles.d.ts +2 -2
  56. package/dist/types/plugins/table/ui/common-styles.d.ts +3 -3
  57. package/dist/types/plugins/table/ui/consts.d.ts +2 -2
  58. package/dist/types/plugins/table/ui/ui-styles.d.ts +14 -14
  59. package/package.json +4 -4
  60. package/src/__tests__/integration/__snapshots__/floating-toolbar.ts.snap +321 -0
  61. package/src/__tests__/integration/delete-last-column-in-full-width.ts +6 -5
  62. package/src/__tests__/integration/floating-toolbar.ts +169 -0
  63. package/src/__tests__/unit/get-toolbar-config.ts +1 -0
  64. package/src/__tests__/unit/nodeviews/TableComponent.tsx +146 -4
  65. package/src/__tests__/unit/pm-plugins/table-resizing/event-handlers.ts +82 -31
  66. package/src/__tests__/unit/toolbar.ts +165 -4
  67. package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-row-menu-item-should-remove-the-table-row-on-click-1-snap.png +2 -2
  68. package/src/plugins/table/commands/hover.ts +1 -0
  69. package/src/plugins/table/event-handlers.ts +6 -17
  70. package/src/plugins/table/index.tsx +1 -0
  71. package/src/plugins/table/nodeviews/TableComponent.tsx +10 -2
  72. package/src/plugins/table/nodeviews/tableCell.tsx +1 -1
  73. package/src/plugins/table/pm-plugins/default-table-selection.ts +0 -1
  74. package/src/plugins/table/pm-plugins/main.ts +26 -28
  75. package/src/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.ts +44 -9
  76. package/src/plugins/table/pm-plugins/table-resizing/utils/resize-logic.ts +1 -1
  77. package/src/plugins/table/toolbar.tsx +60 -13
  78. package/src/plugins/table/ui/FloatingContextualButton/index.tsx +12 -2
  79. package/src/plugins/table/ui/FloatingContextualButton/styles.ts +51 -7
  80. package/src/plugins/table/ui/FloatingContextualMenu/ContextualMenu.tsx +3 -0
  81. package/src/plugins/table/ui/common-styles.ts +24 -9
  82. package/src/plugins/table/ui/consts.ts +7 -5
  83. package/src/plugins/table/ui/ui-styles.ts +20 -5
@@ -0,0 +1,321 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`should show hover indicators on delete columns menu option 1`] = `
4
+ Object {
5
+ "content": Array [
6
+ Object {
7
+ "attrs": Object {
8
+ "__autoSize": false,
9
+ "isNumberColumnEnabled": false,
10
+ "layout": "default",
11
+ "localId": "abc-123",
12
+ },
13
+ "content": Array [
14
+ Object {
15
+ "content": Array [
16
+ Object {
17
+ "attrs": Object {
18
+ "background": null,
19
+ "colspan": 1,
20
+ "colwidth": null,
21
+ "rowspan": 1,
22
+ },
23
+ "content": Array [
24
+ Object {
25
+ "type": "paragraph",
26
+ },
27
+ ],
28
+ "type": "tableHeader",
29
+ },
30
+ Object {
31
+ "attrs": Object {
32
+ "background": null,
33
+ "colspan": 1,
34
+ "colwidth": null,
35
+ "rowspan": 1,
36
+ },
37
+ "content": Array [
38
+ Object {
39
+ "type": "paragraph",
40
+ },
41
+ ],
42
+ "type": "tableHeader",
43
+ },
44
+ Object {
45
+ "attrs": Object {
46
+ "background": null,
47
+ "colspan": 1,
48
+ "colwidth": null,
49
+ "rowspan": 1,
50
+ },
51
+ "content": Array [
52
+ Object {
53
+ "type": "paragraph",
54
+ },
55
+ ],
56
+ "type": "tableHeader",
57
+ },
58
+ ],
59
+ "type": "tableRow",
60
+ },
61
+ Object {
62
+ "content": Array [
63
+ Object {
64
+ "attrs": Object {
65
+ "background": null,
66
+ "colspan": 1,
67
+ "colwidth": null,
68
+ "rowspan": 1,
69
+ },
70
+ "content": Array [
71
+ Object {
72
+ "type": "paragraph",
73
+ },
74
+ ],
75
+ "type": "tableCell",
76
+ },
77
+ Object {
78
+ "attrs": Object {
79
+ "background": null,
80
+ "colspan": 1,
81
+ "colwidth": null,
82
+ "rowspan": 1,
83
+ },
84
+ "content": Array [
85
+ Object {
86
+ "type": "paragraph",
87
+ },
88
+ ],
89
+ "type": "tableCell",
90
+ },
91
+ Object {
92
+ "attrs": Object {
93
+ "background": null,
94
+ "colspan": 1,
95
+ "colwidth": null,
96
+ "rowspan": 1,
97
+ },
98
+ "content": Array [
99
+ Object {
100
+ "type": "paragraph",
101
+ },
102
+ ],
103
+ "type": "tableCell",
104
+ },
105
+ ],
106
+ "type": "tableRow",
107
+ },
108
+ Object {
109
+ "content": Array [
110
+ Object {
111
+ "attrs": Object {
112
+ "background": null,
113
+ "colspan": 1,
114
+ "colwidth": null,
115
+ "rowspan": 1,
116
+ },
117
+ "content": Array [
118
+ Object {
119
+ "type": "paragraph",
120
+ },
121
+ ],
122
+ "type": "tableCell",
123
+ },
124
+ Object {
125
+ "attrs": Object {
126
+ "background": null,
127
+ "colspan": 1,
128
+ "colwidth": null,
129
+ "rowspan": 1,
130
+ },
131
+ "content": Array [
132
+ Object {
133
+ "type": "paragraph",
134
+ },
135
+ ],
136
+ "type": "tableCell",
137
+ },
138
+ Object {
139
+ "attrs": Object {
140
+ "background": null,
141
+ "colspan": 1,
142
+ "colwidth": null,
143
+ "rowspan": 1,
144
+ },
145
+ "content": Array [
146
+ Object {
147
+ "type": "paragraph",
148
+ },
149
+ ],
150
+ "type": "tableCell",
151
+ },
152
+ ],
153
+ "type": "tableRow",
154
+ },
155
+ ],
156
+ "type": "table",
157
+ },
158
+ ],
159
+ "type": "doc",
160
+ }
161
+ `;
162
+
163
+ exports[`should show hover indicators on delete rows menu option 1`] = `
164
+ Object {
165
+ "content": Array [
166
+ Object {
167
+ "attrs": Object {
168
+ "__autoSize": false,
169
+ "isNumberColumnEnabled": false,
170
+ "layout": "default",
171
+ "localId": "abc-123",
172
+ },
173
+ "content": Array [
174
+ Object {
175
+ "content": Array [
176
+ Object {
177
+ "attrs": Object {
178
+ "background": null,
179
+ "colspan": 1,
180
+ "colwidth": null,
181
+ "rowspan": 1,
182
+ },
183
+ "content": Array [
184
+ Object {
185
+ "type": "paragraph",
186
+ },
187
+ ],
188
+ "type": "tableHeader",
189
+ },
190
+ Object {
191
+ "attrs": Object {
192
+ "background": null,
193
+ "colspan": 1,
194
+ "colwidth": null,
195
+ "rowspan": 1,
196
+ },
197
+ "content": Array [
198
+ Object {
199
+ "type": "paragraph",
200
+ },
201
+ ],
202
+ "type": "tableHeader",
203
+ },
204
+ Object {
205
+ "attrs": Object {
206
+ "background": null,
207
+ "colspan": 1,
208
+ "colwidth": null,
209
+ "rowspan": 1,
210
+ },
211
+ "content": Array [
212
+ Object {
213
+ "type": "paragraph",
214
+ },
215
+ ],
216
+ "type": "tableHeader",
217
+ },
218
+ ],
219
+ "type": "tableRow",
220
+ },
221
+ Object {
222
+ "content": Array [
223
+ Object {
224
+ "attrs": Object {
225
+ "background": null,
226
+ "colspan": 1,
227
+ "colwidth": null,
228
+ "rowspan": 1,
229
+ },
230
+ "content": Array [
231
+ Object {
232
+ "type": "paragraph",
233
+ },
234
+ ],
235
+ "type": "tableCell",
236
+ },
237
+ Object {
238
+ "attrs": Object {
239
+ "background": null,
240
+ "colspan": 1,
241
+ "colwidth": null,
242
+ "rowspan": 1,
243
+ },
244
+ "content": Array [
245
+ Object {
246
+ "type": "paragraph",
247
+ },
248
+ ],
249
+ "type": "tableCell",
250
+ },
251
+ Object {
252
+ "attrs": Object {
253
+ "background": null,
254
+ "colspan": 1,
255
+ "colwidth": null,
256
+ "rowspan": 1,
257
+ },
258
+ "content": Array [
259
+ Object {
260
+ "type": "paragraph",
261
+ },
262
+ ],
263
+ "type": "tableCell",
264
+ },
265
+ ],
266
+ "type": "tableRow",
267
+ },
268
+ Object {
269
+ "content": Array [
270
+ Object {
271
+ "attrs": Object {
272
+ "background": null,
273
+ "colspan": 1,
274
+ "colwidth": null,
275
+ "rowspan": 1,
276
+ },
277
+ "content": Array [
278
+ Object {
279
+ "type": "paragraph",
280
+ },
281
+ ],
282
+ "type": "tableCell",
283
+ },
284
+ Object {
285
+ "attrs": Object {
286
+ "background": null,
287
+ "colspan": 1,
288
+ "colwidth": null,
289
+ "rowspan": 1,
290
+ },
291
+ "content": Array [
292
+ Object {
293
+ "type": "paragraph",
294
+ },
295
+ ],
296
+ "type": "tableCell",
297
+ },
298
+ Object {
299
+ "attrs": Object {
300
+ "background": null,
301
+ "colspan": 1,
302
+ "colwidth": null,
303
+ "rowspan": 1,
304
+ },
305
+ "content": Array [
306
+ Object {
307
+ "type": "paragraph",
308
+ },
309
+ ],
310
+ "type": "tableCell",
311
+ },
312
+ ],
313
+ "type": "tableRow",
314
+ },
315
+ ],
316
+ "type": "table",
317
+ },
318
+ ],
319
+ "type": "doc",
320
+ }
321
+ `;
@@ -56,11 +56,12 @@ BrowserTestCase(
56
56
  await page.waitForVisible(deleteButtonSelector);
57
57
  await page.click(deleteButtonSelector);
58
58
 
59
- // await page.checkConsoleErrors({
60
- // ignoreErrors: [
61
- // /is potentially unsafe when doing server-side rendering\. Try changing it to/,
62
- // ],
63
- // });
59
+ // TODO: Figure out why this is causing a warning and causing the following check to fail in chrome.
60
+ // await page.checkConsoleErrors({
61
+ // ignoreErrors: [
62
+ // /is potentially unsafe when doing server-side rendering\. Try changing it to/,
63
+ // ],
64
+ // });
64
65
 
65
66
  const doc = await page.$eval(editable, getDocFromElement);
66
67
  expect(doc).toMatchCustomDocSnapshot(testName);
@@ -0,0 +1,169 @@
1
+ import {
2
+ animationFrame,
3
+ editable,
4
+ fullpage,
5
+ getDocFromElement,
6
+ } from '@atlaskit/editor-test-helpers/integration/helpers';
7
+ import {
8
+ clickFirstCell,
9
+ multiCellTableSelectionBottomRightToMiddleTopCell,
10
+ tableSelectors,
11
+ } from '@atlaskit/editor-test-helpers/page-objects/table';
12
+ import {
13
+ goToEditorTestingWDExample,
14
+ mountEditor,
15
+ } from '@atlaskit/editor-test-helpers/testing-example-page';
16
+ import { BrowserTestCase } from '@atlaskit/webdriver-runner/runner';
17
+ import { TableCssClassName } from '../../plugins/table/types';
18
+ import basicTable from './__fixtures__/basic-table';
19
+
20
+ BrowserTestCase(
21
+ 'should floating toolbar context menu sit above other context menu layers',
22
+ { skip: [] },
23
+ async (client: any) => {
24
+ const page = await goToEditorTestingWDExample(
25
+ client,
26
+ 'editor-plugin-table',
27
+ );
28
+ await mountEditor(page, {
29
+ appearance: fullpage.appearance,
30
+ allowTables: {
31
+ advanced: true,
32
+ allowColumnSorting: true,
33
+ allowDistributeColumns: true,
34
+ allowCellOptionsInFloatingToolbar: true,
35
+ },
36
+ defaultValue: basicTable,
37
+ });
38
+ const tableFloatingToolbarContextMenuSelector = `div[aria-label="Table floating controls"][data-editor-popup=true]`;
39
+ // Select the all cells under column 2 and 3
40
+ await multiCellTableSelectionBottomRightToMiddleTopCell(page);
41
+ // Table floating toolbar should appear, then click on "Cell Options", which brings up another context menu
42
+ const cellOptionsMenuItem = await (
43
+ await page.$(tableFloatingToolbarContextMenuSelector)
44
+ ).$(`button=${tableSelectors.cellOptionsFloatingToolbarText}`);
45
+ await cellOptionsMenuItem.waitForClickable();
46
+ await cellOptionsMenuItem.click();
47
+ // Get the z-index style value of the delete icon popup
48
+ const popupZIndex = await page.evaluate(() => {
49
+ const popupSelector = 'div[aria-label="Popup"][data-editor-popup=true]';
50
+ const deleteIconSelector = 'button.pm-table-controls__delete-button';
51
+ return +(
52
+ (
53
+ document
54
+ ?.querySelector(`${popupSelector} ${deleteIconSelector}`)
55
+ ?.closest(popupSelector) as HTMLElement | null
56
+ )?.style.zIndex || 0
57
+ );
58
+ });
59
+ // Get the z-index style value of the table floating toolbar context menu
60
+ const floatingTablePopupZIndex = await page.evaluate(() => {
61
+ const floatingTablePopupSelector =
62
+ 'div[aria-label="Table floating controls"][data-editor-popup=true]';
63
+ return +(
64
+ (
65
+ document?.querySelector(
66
+ floatingTablePopupSelector,
67
+ ) as HTMLElement | null
68
+ )?.style.zIndex || 0
69
+ );
70
+ });
71
+ // Floating toolbar context menu should sit above the popup
72
+ expect(floatingTablePopupZIndex).toBeGreaterThan(popupZIndex);
73
+ },
74
+ );
75
+
76
+ BrowserTestCase(
77
+ 'should show hover indicators on delete columns menu option',
78
+ { skip: ['safari'] }, // The test does not pass on CI but works on physical browser
79
+ async (client: any, testName: string) => {
80
+ const page = await goToEditorTestingWDExample(
81
+ client,
82
+ 'editor-plugin-table',
83
+ );
84
+ await mountEditor(page, {
85
+ appearance: fullpage.appearance,
86
+ allowTables: {
87
+ advanced: true,
88
+ allowColumnSorting: true,
89
+ allowDistributeColumns: true,
90
+ allowCellOptionsInFloatingToolbar: true,
91
+ },
92
+ defaultValue: basicTable,
93
+ });
94
+ const tableFloatingToolbarContextMenuSelector = `div[aria-label="Table floating controls"][data-editor-popup=true]`;
95
+
96
+ // First click on the cell
97
+ await clickFirstCell(page);
98
+
99
+ // Table floating toolbar should appear, then click on "Cell Options", which brings up another context menu
100
+ const cellOptionsMenuItem = await (
101
+ await page.$(tableFloatingToolbarContextMenuSelector)
102
+ ).$(`button=${tableSelectors.cellOptionsFloatingToolbarText}`);
103
+ await cellOptionsMenuItem.waitForClickable();
104
+ await cellOptionsMenuItem.click();
105
+
106
+ // Hover on the "Delete column" menu option on the context menu
107
+ const deleteColumnMenuItem = await (
108
+ await page.$(tableFloatingToolbarContextMenuSelector)
109
+ ).$(`button=${tableSelectors.removeColumnText}`);
110
+ await deleteColumnMenuItem.moveTo();
111
+ await animationFrame(page);
112
+
113
+ // Check the first column cells should have the hover indicators appear
114
+ const hoverCells = await page.$$(
115
+ `tbody tr th.${TableCssClassName.HOVERED_CELL}.${TableCssClassName.HOVERED_COLUMN}, tbody tr td.${TableCssClassName.HOVERED_CELL}.${TableCssClassName.HOVERED_COLUMN}`,
116
+ );
117
+ expect(hoverCells.length).toBe(3);
118
+
119
+ const doc = await page.$eval(editable, getDocFromElement);
120
+ expect(doc).toMatchCustomDocSnapshot(testName);
121
+ },
122
+ );
123
+
124
+ BrowserTestCase(
125
+ 'should show hover indicators on delete rows menu option',
126
+ { skip: ['safari'] }, // The test does not pass on CI but works on physical browser
127
+ async (client: any, testName: string) => {
128
+ const page = await goToEditorTestingWDExample(
129
+ client,
130
+ 'editor-plugin-table',
131
+ );
132
+ await mountEditor(page, {
133
+ appearance: fullpage.appearance,
134
+ allowTables: {
135
+ allowColumnSorting: true,
136
+ allowDistributeColumns: true,
137
+ allowCellOptionsInFloatingToolbar: true,
138
+ },
139
+ defaultValue: basicTable,
140
+ });
141
+ const tableFloatingToolbarContextMenuSelector = `div[aria-label="Table floating controls"][data-editor-popup=true]`;
142
+
143
+ // First click on the cell
144
+ await clickFirstCell(page);
145
+
146
+ // Table floating toolbar should appear, then click on "Cell Options", which brings up another context menu
147
+ const cellOptionsMenuItem = await (
148
+ await page.$(tableFloatingToolbarContextMenuSelector)
149
+ ).$(`button=${tableSelectors.cellOptionsFloatingToolbarText}`);
150
+ await cellOptionsMenuItem.waitForClickable();
151
+ await cellOptionsMenuItem.click();
152
+
153
+ // Hover on the "Delete row" menu option on the context menu
154
+ const deleteRowMenuItem = await (
155
+ await page.$(tableFloatingToolbarContextMenuSelector)
156
+ ).$(`button=${tableSelectors.removeRowText}`);
157
+ await deleteRowMenuItem.moveTo();
158
+ await animationFrame(page);
159
+
160
+ // Check the first row cells should have the hover indicators appear (second row from the top)
161
+ const hoverCells = await page.$$(
162
+ `tbody tr:nth-child(2) td.${TableCssClassName.HOVERED_CELL}.${TableCssClassName.HOVERED_ROW}`,
163
+ );
164
+ expect(hoverCells.length).toBe(3);
165
+
166
+ const doc = await page.$eval(editable, getDocFromElement);
167
+ expect(doc).toMatchCustomDocSnapshot(testName);
168
+ },
169
+ );
@@ -46,6 +46,7 @@ describe('getToolbarConfig', () => {
46
46
  getEditorContainerWidth,
47
47
  editorAnalyticsAPIFake,
48
48
  getEditorFeatureFlags,
49
+ () => editorView,
49
50
  )({})(state, { formatMessage } as any, {} as any)!;
50
51
  //
51
52
  expect(config).not.toBeUndefined();