@atlaskit/editor-plugin-table 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/commands/package.json +1 -0
  3. package/dist/cjs/plugins/table/create-plugin-config.js +0 -1
  4. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/dom.js +3 -5
  5. package/dist/cjs/plugins/table/ui/common-styles.js +8 -1
  6. package/dist/cjs/plugins/table/ui/ui-styles.js +1 -1
  7. package/dist/cjs/plugins/table/utils/column-controls.js +1 -1
  8. package/dist/cjs/version.json +2 -1
  9. package/dist/es2019/plugins/table/create-plugin-config.js +0 -1
  10. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/dom.js +3 -8
  11. package/dist/es2019/plugins/table/ui/common-styles.js +16 -8
  12. package/dist/es2019/plugins/table/ui/ui-styles.js +1 -6
  13. package/dist/es2019/plugins/table/utils/column-controls.js +1 -1
  14. package/dist/es2019/version.json +2 -1
  15. package/dist/esm/plugins/table/create-plugin-config.js +0 -1
  16. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/dom.js +3 -8
  17. package/dist/esm/plugins/table/ui/common-styles.js +8 -1
  18. package/dist/esm/plugins/table/ui/ui-styles.js +2 -2
  19. package/dist/esm/plugins/table/utils/column-controls.js +1 -1
  20. package/dist/esm/version.json +2 -1
  21. package/dist/types/plugins/table/types.d.ts +0 -1
  22. package/package.json +2 -1
  23. package/plugin-key/package.json +1 -0
  24. package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +8 -0
  25. package/src/__tests__/visual-regression/__fixtures__/sticky-header-with-horizontal-scroll.json +5228 -0
  26. package/src/__tests__/visual-regression/__image_snapshots__/sticky-header-ts-snapshot-test-table-sticky-header-should-align-with-table-cell-when-active-1-snap.png +3 -0
  27. package/src/__tests__/visual-regression/__image_snapshots__/sticky-header-ts-snapshot-test-table-sticky-header-should-align-with-table-cell-when-active-2-snap.png +3 -0
  28. package/src/__tests__/visual-regression/cell-options-menu.ts +110 -99
  29. package/src/__tests__/visual-regression/index.ts +56 -44
  30. package/src/__tests__/visual-regression/sticky-header.ts +55 -0
  31. package/src/plugins/table/create-plugin-config.ts +0 -1
  32. package/src/plugins/table/pm-plugins/table-resizing/utils/dom.ts +5 -11
  33. package/src/plugins/table/types.ts +0 -1
  34. package/src/plugins/table/ui/common-styles.ts +16 -8
  35. package/src/plugins/table/ui/ui-styles.ts +0 -6
  36. package/src/plugins/table/utils/column-controls.ts +1 -1
  37. package/types/package.json +1 -0
  38. package/ui/common-styles/package.json +1 -0
  39. package/ui/consts/package.json +1 -0
@@ -0,0 +1,3 @@
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4c5e3b7ade5e92b861452ef14e9774592b6252c91a89e955a33e56e3678cf54c
3
+ size 20560
@@ -0,0 +1,3 @@
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f1a5a555cab8c01960d1dd4009d44eb51abf0fbd27674404e0bc8ddc9152c345
3
+ size 19785
@@ -1,99 +1,110 @@
1
- export {};
2
-
3
- // import {
4
- // PuppeteerPage,
5
- // waitForNoTooltip,
6
- // } from '@atlaskit/visual-regression/helper';
7
- // import { insertTable } from '../../../../__tests__/__helpers/page-objects/_table';
8
-
9
- // import {
10
- // snapshot,
11
- // initFullPageEditorWithAdf,
12
- // } from '../../../../__tests__/visual-regression/_utils';
13
-
14
- it.skip('TODO: restore vr `packages/editor/editor-plugin-table/src/plugins/table/__tests__/visual-regression/cell-options-menu.ts`', () => {});
15
-
16
- // const firstCellSelector = 'table tbody th p';
17
- // const cellOptionsSelector = '[aria-label="Cell options"]';
18
- // const deleteColumnCellOptionSelector = '[aria-label="Delete column"]';
19
- // const deleteRowCellOptionSelector = '[aria-label="Delete row"]';
20
-
21
- // const emptyDocAdf = {
22
- // version: 1,
23
- // type: 'doc',
24
- // content: [],
25
- // };
26
-
27
- // describe('Table cell options menu', () => {
28
- // let page: PuppeteerPage;
29
-
30
- // beforeEach(async () => {
31
- // page = global.page;
32
- // await initFullPageEditorWithAdf(page, emptyDocAdf);
33
- // await insertTable(page);
34
- // page.waitForSelector(firstCellSelector);
35
-
36
- // // move the focus to the first table cell
37
- // await page.type(firstCellSelector, 'focus table cell');
38
- // });
39
-
40
- // describe('delete column menu item', () => {
41
- // it('visual hints should be added to the table column on hover', async () => {
42
- // // open the table cell options menu
43
- // await page.waitForSelector(cellOptionsSelector);
44
- // await page.click(cellOptionsSelector);
45
-
46
- // // hover over the table cell options Delete column entry
47
- // await page.waitForSelector(deleteColumnCellOptionSelector);
48
- // await page.hover(deleteColumnCellOptionSelector);
49
-
50
- // await waitForNoTooltip(page);
51
-
52
- // await snapshot(page);
53
- // });
54
-
55
- // it('should remove the table column on click', async () => {
56
- // // open the table cell options menu
57
- // await page.waitForSelector(cellOptionsSelector);
58
- // await page.click(cellOptionsSelector);
59
-
60
- // // click the table cell options Delete column entry
61
- // await page.waitForSelector(deleteColumnCellOptionSelector);
62
- // await page.click(deleteColumnCellOptionSelector);
63
-
64
- // await waitForNoTooltip(page);
65
-
66
- // await snapshot(page);
67
- // });
68
- // });
69
-
70
- // describe('delete row menu item', () => {
71
- // it('visual hints should be added to the table row on hover', async () => {
72
- // // open the table cell options menu
73
- // await page.waitForSelector(cellOptionsSelector);
74
- // await page.click(cellOptionsSelector);
75
-
76
- // // hover over the table cell options Delete row entry
77
- // await page.waitForSelector(deleteRowCellOptionSelector);
78
- // await page.hover(deleteRowCellOptionSelector);
79
-
80
- // await waitForNoTooltip(page);
81
-
82
- // await snapshot(page);
83
- // });
84
-
85
- // it('should remove the table row on click', async () => {
86
- // // open the table cell options menu
87
- // await page.waitForSelector(cellOptionsSelector);
88
- // await page.click(cellOptionsSelector);
89
-
90
- // // click the table cell options Delete row entry
91
- // await page.waitForSelector(deleteColumnCellOptionSelector);
92
- // await page.click(deleteRowCellOptionSelector);
93
-
94
- // await waitForNoTooltip(page);
95
-
96
- // await snapshot(page);
97
- // });
98
- // });
99
- // });
1
+ import {
2
+ PuppeteerPage,
3
+ waitForNoTooltip,
4
+ } from '@atlaskit/visual-regression/helper';
5
+ import { insertTable } from '@atlaskit/editor-test-helpers/page-objects/table';
6
+ import {
7
+ snapshot,
8
+ initFullPageEditorWithAdf,
9
+ } from '@atlaskit/editor-test-helpers/vr-utils/base-utils';
10
+
11
+ const firstCellSelector = 'table tbody th p';
12
+ const cellOptionsSelector = '[aria-label="Cell options"]';
13
+ const deleteColumnCellOptionSelector = '[aria-label="Delete column"]';
14
+ const deleteRowCellOptionSelector = '[aria-label="Delete row"]';
15
+
16
+ const emptyDocAdf = {
17
+ version: 1,
18
+ type: 'doc',
19
+ content: [],
20
+ };
21
+
22
+ describe('Table cell options menu', () => {
23
+ let page: PuppeteerPage;
24
+
25
+ beforeEach(async () => {
26
+ page = global.page;
27
+ await initFullPageEditorWithAdf(
28
+ page,
29
+ emptyDocAdf,
30
+ undefined,
31
+ undefined,
32
+ {},
33
+ undefined,
34
+ undefined,
35
+ true,
36
+ false,
37
+ undefined,
38
+ {
39
+ group: 'editor',
40
+ packageName: 'editor-plugin-table',
41
+ exampleName: 'testing',
42
+ },
43
+ );
44
+ await insertTable(page);
45
+ page.waitForSelector(firstCellSelector);
46
+
47
+ // move the focus to the first table cell
48
+ await page.type(firstCellSelector, 'focus table cell');
49
+ });
50
+
51
+ describe('delete column menu item', () => {
52
+ it('visual hints should be added to the table column on hover', async () => {
53
+ // open the table cell options menu
54
+ await page.waitForSelector(cellOptionsSelector);
55
+ await page.click(cellOptionsSelector);
56
+
57
+ // hover over the table cell options Delete column entry
58
+ await page.waitForSelector(deleteColumnCellOptionSelector);
59
+ await page.hover(deleteColumnCellOptionSelector);
60
+
61
+ await waitForNoTooltip(page);
62
+
63
+ await snapshot(page);
64
+ });
65
+
66
+ it('should remove the table column on click', async () => {
67
+ // open the table cell options menu
68
+ await page.waitForSelector(cellOptionsSelector);
69
+ await page.click(cellOptionsSelector);
70
+
71
+ // click the table cell options Delete column entry
72
+ await page.waitForSelector(deleteColumnCellOptionSelector);
73
+ await page.click(deleteColumnCellOptionSelector);
74
+
75
+ await waitForNoTooltip(page);
76
+
77
+ await snapshot(page);
78
+ });
79
+ });
80
+
81
+ describe('delete row menu item', () => {
82
+ it('visual hints should be added to the table row on hover', async () => {
83
+ // open the table cell options menu
84
+ await page.waitForSelector(cellOptionsSelector);
85
+ await page.click(cellOptionsSelector);
86
+
87
+ // hover over the table cell options Delete row entry
88
+ await page.waitForSelector(deleteRowCellOptionSelector);
89
+ await page.hover(deleteRowCellOptionSelector);
90
+
91
+ await waitForNoTooltip(page);
92
+
93
+ await snapshot(page);
94
+ });
95
+
96
+ it('should remove the table row on click', async () => {
97
+ // open the table cell options menu
98
+ await page.waitForSelector(cellOptionsSelector);
99
+ await page.click(cellOptionsSelector);
100
+
101
+ // click the table cell options Delete row entry
102
+ await page.waitForSelector(deleteColumnCellOptionSelector);
103
+ await page.click(deleteRowCellOptionSelector);
104
+
105
+ await waitForNoTooltip(page);
106
+
107
+ await snapshot(page);
108
+ });
109
+ });
110
+ });
@@ -1,44 +1,56 @@
1
- export {};
2
-
3
- // import { PuppeteerPage } from '@atlaskit/visual-regression/helper';
4
- // import { Device } from '@atlaskit/editor-test-helpers/vr-utils/device-viewport';
5
- // import {
6
- // snapshot,
7
- // initFullPageEditorWithAdf,
8
- // } from '../../../../__tests__/visual-regression/_utils';
9
- // import tableWith100ListItemsADF from './__fixtures__/table-with-100-numbered-list-items.json';
10
- // import {
11
- // scrollToBottom,
12
- // scrollToElement,
13
- // } from '../../../../__tests__/__helpers/page-objects/_editor';
14
-
15
- // async function initEditor(page: PuppeteerPage, adf: Object) {
16
- // await initFullPageEditorWithAdf(page, adf, Device.LaptopMDPI, undefined, {});
17
- // }
18
-
19
- it.skip('TODO: restore vr `packages/editor/editor-plugin-table/src/plugins/table/__tests__/visual-regression/index.ts`', () => {});
20
-
21
- // describe('Snapshot Test: Table', () => {
22
- // let page: PuppeteerPage;
23
-
24
- // beforeEach(() => {
25
- // page = global.page;
26
- // });
27
-
28
- // describe('numbered list', () => {
29
- // it('should not overflow table cell, when there are more than 100 ordered list items', async () => {
30
- // await initEditor(page, tableWith100ListItemsADF);
31
-
32
- // // initial elements
33
- // await snapshot(page);
34
-
35
- // // 100th elements
36
- // await scrollToElement(page, 'ol > li:nth-of-type(120)');
37
- // await snapshot(page);
38
-
39
- // // 1000th elements
40
- // await scrollToBottom(page);
41
- // await snapshot(page);
42
- // });
43
- // });
44
- // });
1
+ import { PuppeteerPage } from '@atlaskit/visual-regression/helper';
2
+ import { Device } from '@atlaskit/editor-test-helpers/vr-utils/device-viewport';
3
+ import {
4
+ snapshot,
5
+ initFullPageEditorWithAdf,
6
+ } from '@atlaskit/editor-test-helpers/vr-utils/base-utils';
7
+ import tableWith100ListItemsADF from './__fixtures__/table-with-100-numbered-list-items.json';
8
+ import {
9
+ scrollToBottom,
10
+ scrollToElement,
11
+ } from '@atlaskit/editor-test-helpers/page-objects/editor';
12
+
13
+ async function initEditor(page: PuppeteerPage, adf: Object) {
14
+ await initFullPageEditorWithAdf(
15
+ page,
16
+ adf,
17
+ Device.LaptopMDPI,
18
+ undefined,
19
+ {},
20
+ undefined,
21
+ undefined,
22
+ true,
23
+ false,
24
+ undefined,
25
+ {
26
+ group: 'editor',
27
+ packageName: 'editor-plugin-table',
28
+ exampleName: 'testing',
29
+ },
30
+ );
31
+ }
32
+
33
+ describe('Snapshot Test: Table', () => {
34
+ let page: PuppeteerPage;
35
+
36
+ beforeAll(async () => {
37
+ page = global.page;
38
+ });
39
+
40
+ describe('numbered list', () => {
41
+ it('should not overflow table cell, when there are more than 100 ordered list items', async () => {
42
+ await initEditor(page, tableWith100ListItemsADF);
43
+
44
+ // initial elements
45
+ await snapshot(page);
46
+
47
+ // 100th elements
48
+ await scrollToElement(page, 'ol > li:nth-of-type(120)');
49
+ await snapshot(page);
50
+
51
+ // 1000th elements
52
+ await scrollToBottom(page);
53
+ await snapshot(page);
54
+ });
55
+ });
56
+ });
@@ -0,0 +1,55 @@
1
+ import { PuppeteerPage } from '@atlaskit/visual-regression/helper';
2
+ import {
3
+ snapshot,
4
+ initEditorWithAdf,
5
+ Appearance,
6
+ } from '@atlaskit/editor-test-helpers/vr-utils/base-utils';
7
+ import stickyHeaderWithHorizontalScroll from './__fixtures__/sticky-header-with-horizontal-scroll.json';
8
+ import { scrollToElement } from '@atlaskit/editor-test-helpers/page-objects/editor';
9
+ import { clickFirstCell } from '@atlaskit/editor-test-helpers/page-objects/table';
10
+
11
+ const initEditor = async (page: PuppeteerPage, adf: any) => {
12
+ await initEditorWithAdf(
13
+ page,
14
+ {
15
+ appearance: Appearance.fullPage,
16
+ adf,
17
+ viewport: { width: 1280, height: 868 },
18
+ editorProps: {
19
+ allowTables: {
20
+ stickyHeaders: true,
21
+ allowColumnResizing: true,
22
+ },
23
+ },
24
+ },
25
+ {
26
+ group: 'editor',
27
+ packageName: 'editor-plugin-table',
28
+ exampleName: 'testing',
29
+ },
30
+ );
31
+ };
32
+
33
+ describe('Snapshot Test: Table', () => {
34
+ let page: PuppeteerPage;
35
+
36
+ beforeEach(async () => {
37
+ page = global.page;
38
+ });
39
+
40
+ describe('sticky header', () => {
41
+ it('should align with table cell when active', async () => {
42
+ await initEditor(page, stickyHeaderWithHorizontalScroll);
43
+
44
+ await clickFirstCell(page, true);
45
+
46
+ // scroll to bottom center to see scroll shadows
47
+ await scrollToElement(page, 'ol > li');
48
+ await snapshot(page);
49
+
50
+ // scroll to bottom right
51
+ await scrollToElement(page, 'ul > li');
52
+ await snapshot(page);
53
+ });
54
+ });
55
+ });
@@ -9,7 +9,6 @@ export const pluginConfig = (config: PluginConfig = {}) => {
9
9
  allowHeaderRow: true,
10
10
  allowMergeCells: true,
11
11
  allowNumberColumn: true,
12
- stickToolbarToBottom: true,
13
12
  permittedLayouts: 'all' as PermittedLayoutsDescriptor,
14
13
  allowControls: true,
15
14
  ...config,
@@ -4,10 +4,8 @@ import { EditorView } from 'prosemirror-view';
4
4
  import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
5
5
  import {
6
6
  tableCellBorderWidth,
7
- tableCellPadding,
8
7
  tableMarginTop,
9
8
  } from '@atlaskit/editor-common/styles';
10
- import { browser } from '@atlaskit/editor-common/utils';
11
9
 
12
10
  import {
13
11
  closestElement,
@@ -114,15 +112,11 @@ export const updateStickyMargins = (table: HTMLElement) => {
114
112
 
115
113
  const paddingTop =
116
114
  parsePx(window.getComputedStyle(row).paddingTop || '') || 0;
117
- const firstRowHeight = row.clientHeight - paddingTop - 2; /* border */
118
-
119
- // firefox handles margin and padding differently
120
- // when applied with tables
121
- table.style.marginTop = `${
122
- browser.gecko
123
- ? firstRowHeight + tableCellPadding - tableCellBorderWidth
124
- : tableMarginTop + firstRowHeight
125
- }px`;
115
+
116
+ const firstRowHeight =
117
+ row.getBoundingClientRect().height - paddingTop - tableCellBorderWidth;
118
+
119
+ table.style.marginTop = `${tableMarginTop + firstRowHeight}px`;
126
120
  };
127
121
 
128
122
  export const applyColWidthsToStickyRow = (
@@ -46,7 +46,6 @@ export interface PluginConfig {
46
46
  allowAddColumnWithCustomStep?: boolean;
47
47
  allowCollapse?: boolean;
48
48
  isHeaderRowRequired?: boolean;
49
- stickToolbarToBottom?: boolean;
50
49
  permittedLayouts?: PermittedLayoutsDescriptor;
51
50
  allowControls?: boolean;
52
51
  stickyHeaders?: boolean;
@@ -67,6 +67,13 @@ import { token } from '@atlaskit/tokens';
67
67
 
68
68
  const cornerControlHeight = tableToolbarSize + 1;
69
69
 
70
+ /*
71
+ compensating for half of the insert column button
72
+ that is aligned to the right edge initially on hover of the top right column control when table overflown,
73
+ its center should be aligned with the edge
74
+ */
75
+ const insertColumnButtonOffset = tableInsertColumnButtonSize / 2;
76
+
70
77
  const rangeSelectionStyles = `
71
78
  .${ClassName.NODEVIEW_WRAPPER}.${akEditorSelectedNodeClassName} table tbody tr {
72
79
  th,td {
@@ -280,7 +287,7 @@ export const tableStyles = (props: ThemeProps) => css`
280
287
  /* add a little bit so the scroll lines up with the table */
281
288
  .${ClassName.TABLE_STICKY} tr.sticky::after {
282
289
  content: ' ';
283
- width: 1px;
290
+ width: ${insertColumnButtonOffset + 1}px;
284
291
  }
285
292
 
286
293
  /* To fix jumpiness caused in Chrome Browsers for sticky headers */
@@ -580,6 +587,12 @@ export const tableStyles = (props: ThemeProps) => css`
580
587
  /* Table */
581
588
  .${ClassName.TABLE_NODE_WRAPPER} > table {
582
589
  table-layout: fixed;
590
+ white-space: normal;
591
+ border-top: none;
592
+
593
+ > tbody > tr {
594
+ white-space: pre-wrap;
595
+ }
583
596
 
584
597
  .${ClassName.COLUMN_CONTROLS_DECORATIONS} + * {
585
598
  margin-top: 0;
@@ -664,13 +677,8 @@ export const tableStyles = (props: ThemeProps) => css`
664
677
  left: -${tableToolbarSize}px;
665
678
  }
666
679
  .${ClassName.TABLE_NODE_WRAPPER} {
667
- /*
668
- compensating for half of the insert column button
669
- that is aligned to the right edge initially on hover of the top right column control when table overflown,
670
- its center should be aligned with the edge
671
- */
672
- padding-right: ${tableInsertColumnButtonSize / 2}px;
673
- margin-right: -${tableInsertColumnButtonSize / 2}px;
680
+ padding-right: ${insertColumnButtonOffset}px;
681
+ margin-right: -${insertColumnButtonOffset}px;
674
682
  padding-bottom: ${tableScrollbarOffset}px;
675
683
  margin-bottom: -${tableScrollbarOffset}px;
676
684
  /* fixes gap cursor height */
@@ -38,7 +38,6 @@ import {
38
38
  tableToolbarSize,
39
39
  tableInsertColumnButtonSize,
40
40
  tableDeleteButtonSize,
41
- tableControlsSpacing,
42
41
  } from './consts';
43
42
 
44
43
  import { TableCssClassName as ClassName } from '../types';
@@ -273,11 +272,6 @@ export const OverflowShadow = (props: ThemeProps) => css`
273
272
  border-left: 1px solid ${tableBorderColor(props)};
274
273
  }
275
274
  }
276
- .${ClassName.WITH_CONTROLS}.${ClassName.TABLE_STICKY} {
277
- .${ClassName.TABLE_RIGHT_SHADOW}, .${ClassName.TABLE_LEFT_SHADOW} {
278
- top: ${tableControlsSpacing}px;
279
- }
280
- }
281
275
  `;
282
276
  /* eslint-enable @atlaskit/design-system/ensure-design-token-usage */
283
277
 
@@ -195,7 +195,7 @@ export const colWidthsForRow = (
195
195
  if (copyTarget) {
196
196
  // either from the first row while it's still in the table
197
197
  const cellInfos = maphElem(copyTarget, (cell) => ({
198
- width: cell.offsetWidth,
198
+ width: cell.getBoundingClientRect().width,
199
199
  colspan: Number(cell.getAttribute('colspan') || 1),
200
200
  colwidth: cell.dataset.colwidth,
201
201
  }));
@@ -3,6 +3,7 @@
3
3
  "main": "../dist/cjs/plugins/table/types.js",
4
4
  "module": "../dist/esm/plugins/table/types.js",
5
5
  "module:es2019": "../dist/es2019/plugins/table/types.js",
6
+ "sideEffects": false,
6
7
  "types": "../dist/types/plugins/table/types.d.ts",
7
8
  "typesVersions": {
8
9
  ">=4.0 <4.5": {
@@ -3,6 +3,7 @@
3
3
  "main": "../../dist/cjs/plugins/table/ui/common-styles.js",
4
4
  "module": "../../dist/esm/plugins/table/ui/common-styles.js",
5
5
  "module:es2019": "../../dist/es2019/plugins/table/ui/common-styles.js",
6
+ "sideEffects": false,
6
7
  "types": "../../dist/types/plugins/table/ui/common-styles.d.ts",
7
8
  "typesVersions": {
8
9
  ">=4.0 <4.5": {
@@ -3,6 +3,7 @@
3
3
  "main": "../../dist/cjs/plugins/table/ui/consts.js",
4
4
  "module": "../../dist/esm/plugins/table/ui/consts.js",
5
5
  "module:es2019": "../../dist/es2019/plugins/table/ui/consts.js",
6
+ "sideEffects": false,
6
7
  "types": "../../dist/types/plugins/table/ui/consts.d.ts",
7
8
  "typesVersions": {
8
9
  ">=4.0 <4.5": {