@atlaskit/editor-plugin-table 2.9.0 → 2.10.0

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 (104) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/plugins/table/event-handlers.js +52 -56
  3. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +19 -69
  4. package/dist/cjs/plugins/table/nodeviews/TableContainer.js +9 -0
  5. package/dist/cjs/plugins/table/nodeviews/TableResizer.js +19 -4
  6. package/dist/cjs/plugins/table/nodeviews/table.js +23 -30
  7. package/dist/cjs/plugins/table/nodeviews/tableCell.js +3 -6
  8. package/dist/cjs/plugins/table/nodeviews/update-overflow-shadows.js +2 -40
  9. package/dist/cjs/plugins/table/pm-plugins/main.js +3 -3
  10. package/dist/cjs/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +2 -73
  11. package/dist/cjs/plugins/table/pm-plugins/sticky-headers/plugin.js +1 -1
  12. package/dist/cjs/plugins/table/pm-plugins/table-resizing/event-handlers.js +1 -1
  13. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/dom.js +1 -5
  14. package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +3 -7
  15. package/dist/cjs/plugins/table/ui/common-styles.js +2 -2
  16. package/dist/cjs/plugins/table/utils/dom.js +5 -12
  17. package/dist/es2019/plugins/table/event-handlers.js +3 -6
  18. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +18 -69
  19. package/dist/es2019/plugins/table/nodeviews/TableContainer.js +9 -0
  20. package/dist/es2019/plugins/table/nodeviews/TableResizer.js +19 -4
  21. package/dist/es2019/plugins/table/nodeviews/table.js +24 -32
  22. package/dist/es2019/plugins/table/nodeviews/tableCell.js +3 -7
  23. package/dist/es2019/plugins/table/nodeviews/update-overflow-shadows.js +0 -35
  24. package/dist/es2019/plugins/table/pm-plugins/main.js +3 -4
  25. package/dist/es2019/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +2 -77
  26. package/dist/es2019/plugins/table/pm-plugins/sticky-headers/plugin.js +1 -1
  27. package/dist/es2019/plugins/table/pm-plugins/table-resizing/event-handlers.js +1 -1
  28. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/dom.js +1 -5
  29. package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +3 -9
  30. package/dist/es2019/plugins/table/ui/common-styles.js +3 -3
  31. package/dist/es2019/plugins/table/utils/dom.js +5 -12
  32. package/dist/esm/plugins/table/event-handlers.js +52 -56
  33. package/dist/esm/plugins/table/nodeviews/TableComponent.js +19 -69
  34. package/dist/esm/plugins/table/nodeviews/TableContainer.js +9 -0
  35. package/dist/esm/plugins/table/nodeviews/TableResizer.js +19 -4
  36. package/dist/esm/plugins/table/nodeviews/table.js +23 -30
  37. package/dist/esm/plugins/table/nodeviews/tableCell.js +3 -6
  38. package/dist/esm/plugins/table/nodeviews/update-overflow-shadows.js +0 -37
  39. package/dist/esm/plugins/table/pm-plugins/main.js +3 -3
  40. package/dist/esm/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +2 -73
  41. package/dist/esm/plugins/table/pm-plugins/sticky-headers/plugin.js +1 -1
  42. package/dist/esm/plugins/table/pm-plugins/table-resizing/event-handlers.js +1 -1
  43. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/dom.js +1 -5
  44. package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +3 -7
  45. package/dist/esm/plugins/table/ui/common-styles.js +2 -2
  46. package/dist/esm/plugins/table/utils/dom.js +5 -12
  47. package/dist/types/plugins/table/event-handlers.d.ts +1 -2
  48. package/dist/types/plugins/table/nodeviews/TableComponent.d.ts +0 -2
  49. package/dist/types/plugins/table/nodeviews/TableContainer.d.ts +6 -5
  50. package/dist/types/plugins/table/nodeviews/TableResizer.d.ts +2 -1
  51. package/dist/types/plugins/table/nodeviews/table.d.ts +0 -1
  52. package/dist/types/plugins/table/nodeviews/tableCell.d.ts +2 -3
  53. package/dist/types/plugins/table/nodeviews/types.d.ts +0 -1
  54. package/dist/types/plugins/table/nodeviews/update-overflow-shadows.d.ts +0 -6
  55. package/dist/types/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +1 -6
  56. package/dist/types/plugins/table/pm-plugins/table-resizing/utils/dom.d.ts +1 -2
  57. package/dist/types/plugins/table/types.d.ts +2 -2
  58. package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +0 -1
  59. package/dist/types/plugins/table/utils/dom.d.ts +1 -1
  60. package/dist/types-ts4.5/plugins/table/event-handlers.d.ts +1 -2
  61. package/dist/types-ts4.5/plugins/table/nodeviews/TableComponent.d.ts +0 -2
  62. package/dist/types-ts4.5/plugins/table/nodeviews/TableContainer.d.ts +6 -5
  63. package/dist/types-ts4.5/plugins/table/nodeviews/TableResizer.d.ts +2 -1
  64. package/dist/types-ts4.5/plugins/table/nodeviews/table.d.ts +0 -1
  65. package/dist/types-ts4.5/plugins/table/nodeviews/tableCell.d.ts +2 -3
  66. package/dist/types-ts4.5/plugins/table/nodeviews/types.d.ts +0 -1
  67. package/dist/types-ts4.5/plugins/table/nodeviews/update-overflow-shadows.d.ts +0 -6
  68. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +1 -6
  69. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/dom.d.ts +1 -2
  70. package/dist/types-ts4.5/plugins/table/types.d.ts +2 -2
  71. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +0 -1
  72. package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +1 -1
  73. package/package.json +2 -2
  74. package/report.api.md +2 -0
  75. package/src/__tests__/integration/horizontal-scroll-shadows.ts +6 -9
  76. package/src/__tests__/integration/resize.ts +6 -16
  77. package/src/__tests__/unit/event-handlers.ts +1 -4
  78. package/src/__tests__/unit/nodeviews/TableComponent.tsx +48 -92
  79. package/src/__tests__/unit/nodeviews/cell.ts +1 -3
  80. package/src/__tests__/unit/nodeviews/table.ts +71 -83
  81. package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +5 -9
  82. package/src/__tests__/unit/ui/RowControls.tsx +1 -0
  83. package/src/__tests__/unit/utils/dom.ts +6 -112
  84. package/src/plugins/table/event-handlers.ts +72 -79
  85. package/src/plugins/table/nodeviews/TableComponent.tsx +37 -114
  86. package/src/plugins/table/nodeviews/TableContainer.tsx +17 -11
  87. package/src/plugins/table/nodeviews/TableResizer.tsx +34 -4
  88. package/src/plugins/table/nodeviews/table.tsx +22 -30
  89. package/src/plugins/table/nodeviews/tableCell.tsx +3 -11
  90. package/src/plugins/table/nodeviews/types.ts +0 -1
  91. package/src/plugins/table/nodeviews/update-overflow-shadows.ts +0 -54
  92. package/src/plugins/table/pm-plugins/main.ts +4 -22
  93. package/src/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.ts +1 -83
  94. package/src/plugins/table/pm-plugins/sticky-headers/plugin.ts +1 -7
  95. package/src/plugins/table/pm-plugins/table-resizing/event-handlers.ts +1 -1
  96. package/src/plugins/table/pm-plugins/table-resizing/utils/dom.ts +30 -48
  97. package/src/plugins/table/types.ts +3 -2
  98. package/src/plugins/table/ui/TableFloatingControls/index.tsx +3 -15
  99. package/src/plugins/table/ui/common-styles.ts +1 -1
  100. package/src/plugins/table/utils/dom.ts +3 -11
  101. package/tmp/api-report-tmp.d.ts +2 -0
  102. package/dist/cjs/version.json +0 -5
  103. package/dist/es2019/version.json +0 -5
  104. package/dist/esm/version.json +0 -5
@@ -5,7 +5,6 @@ import {
5
5
 
6
6
  describe('table plugin: utils/dom.js', () => {
7
7
  let element: HTMLElement;
8
- let mouseMoveOptimization = false;
9
8
  let elementContentRects: any;
10
9
  const elementRect: DOMRect = {
11
10
  width: 100,
@@ -30,7 +29,6 @@ describe('table plugin: utils/dom.js', () => {
30
29
 
31
30
  beforeEach(() => {
32
31
  element = document.createElement('div');
33
- mouseMoveOptimization = false;
34
32
  element.getBoundingClientRect = () => elementRect;
35
33
  });
36
34
 
@@ -40,37 +38,18 @@ describe('table plugin: utils/dom.js', () => {
40
38
 
41
39
  describe('and when the mouse is outside of the gap', () => {
42
40
  describe('for 1px on the left', () => {
43
- it('should return null when mouseMoveOptimization is disabled', () => {
44
- const event = {
45
- target: element,
46
- clientX: GAP + elementRect.left + 1,
47
- };
48
-
49
- expect(
50
- getMousePositionHorizontalRelativeByElement(
51
- // @ts-ignore
52
- event,
53
- mouseMoveOptimization,
54
- elementContentRects,
55
- GAP,
56
- ),
57
- ).toBeNull();
58
- });
59
-
60
- it('should return null when mouseMoveOptimization is enabled', () => {
41
+ it('should return null', () => {
61
42
  const event = {
62
43
  target: element,
63
44
  offsetX: GAP + 1,
64
45
  };
65
46
 
66
- mouseMoveOptimization = true;
67
47
  elementContentRects = { 'table-cell-id': { width: 100 } };
68
48
 
69
49
  expect(
70
50
  getMousePositionHorizontalRelativeByElement(
71
51
  // @ts-ignore
72
52
  event,
73
- mouseMoveOptimization,
74
53
  elementContentRects,
75
54
  GAP,
76
55
  ),
@@ -79,37 +58,18 @@ describe('table plugin: utils/dom.js', () => {
79
58
  });
80
59
 
81
60
  describe('for 1px on the right', () => {
82
- it('should return null when mouseMoveOptimization is disabled', () => {
83
- const event = {
84
- target: element,
85
- clientX: elementRect.width + elementRect.left - GAP - 1,
86
- };
87
-
88
- expect(
89
- getMousePositionHorizontalRelativeByElement(
90
- // @ts-ignore
91
- event,
92
- mouseMoveOptimization,
93
- elementContentRects,
94
- GAP,
95
- ),
96
- ).toBeNull();
97
- });
98
-
99
- it('should return null when mouseMoveOptimization is enabled', () => {
61
+ it('should return null', () => {
100
62
  const event = {
101
63
  target: element,
102
64
  offsetX: elementRect.width - GAP - 1,
103
65
  };
104
66
 
105
- mouseMoveOptimization = true;
106
67
  elementContentRects = { 'table-cell-id': { width: 100 } };
107
68
 
108
69
  expect(
109
70
  getMousePositionHorizontalRelativeByElement(
110
71
  // @ts-ignore
111
72
  event,
112
- mouseMoveOptimization,
113
73
  elementContentRects,
114
74
  GAP,
115
75
  ),
@@ -119,74 +79,36 @@ describe('table plugin: utils/dom.js', () => {
119
79
  });
120
80
 
121
81
  describe('and when the mouse is inside of the gap', () => {
122
- it('should return left when mouseMoveOptimization is disabled', () => {
123
- const event = {
124
- target: element,
125
- clientX: GAP + elementRect.left,
126
- };
127
-
128
- expect(
129
- getMousePositionHorizontalRelativeByElement(
130
- // @ts-ignore
131
- event,
132
- mouseMoveOptimization,
133
- elementContentRects,
134
- GAP,
135
- ),
136
- ).toBe('left');
137
- });
138
-
139
- it('should return left when mouseMoveOptimization is enabled', () => {
82
+ it('should return left', () => {
140
83
  const event = {
141
84
  target: element,
142
85
  offsetX: GAP,
143
86
  };
144
87
 
145
- mouseMoveOptimization = true;
146
88
  elementContentRects = { 'table-cell-id': { width: 100 } };
147
89
 
148
90
  expect(
149
91
  getMousePositionHorizontalRelativeByElement(
150
92
  // @ts-ignore
151
93
  event,
152
- mouseMoveOptimization,
153
94
  elementContentRects,
154
95
  GAP,
155
96
  ),
156
97
  ).toBe('left');
157
98
  });
158
99
 
159
- it('should return right when mouseMoveOptimization is disabled', () => {
160
- const event = {
161
- target: element,
162
- clientX: elementRect.width + elementRect.left - GAP,
163
- };
164
-
165
- expect(
166
- getMousePositionHorizontalRelativeByElement(
167
- // @ts-ignore
168
- event,
169
- mouseMoveOptimization,
170
- elementContentRects,
171
- GAP,
172
- ),
173
- ).toBe('right');
174
- });
175
-
176
- it('should return right when mouseMoveOptimization is enabled', () => {
100
+ it('should return right', () => {
177
101
  const event = {
178
102
  target: element,
179
103
  offsetX: elementRect.width - GAP,
180
104
  };
181
105
 
182
- mouseMoveOptimization = true;
183
106
  elementContentRects = { 'table-cell-id': { width: 100 } };
184
107
 
185
108
  expect(
186
109
  getMousePositionHorizontalRelativeByElement(
187
110
  // @ts-ignore
188
111
  event,
189
- mouseMoveOptimization,
190
112
  elementContentRects,
191
113
  GAP,
192
114
  ),
@@ -195,63 +117,35 @@ describe('table plugin: utils/dom.js', () => {
195
117
  });
196
118
  });
197
119
 
198
- it('should return left when the mouse is positioned before half of the element and mouseMoveOptimization is disabled', () => {
199
- const event = {
200
- target: element,
201
- clientX: 50,
202
- };
203
-
204
- expect(
205
- // @ts-ignore
206
- getMousePositionHorizontalRelativeByElement(event),
207
- ).toBe('left');
208
- });
209
-
210
- it('should return left when the mouse is positioned before half of the element and mouseMoveOptimization is enabled', () => {
120
+ it('should return left when the mouse is positioned before half of the element', () => {
211
121
  const event = {
212
122
  target: element,
213
123
  offsetX: 50,
214
124
  };
215
125
 
216
- mouseMoveOptimization = true;
217
126
  elementContentRects = { 'table-cell-id': { width: 100 } };
218
127
 
219
128
  expect(
220
129
  getMousePositionHorizontalRelativeByElement(
221
130
  // @ts-ignore
222
131
  event,
223
- mouseMoveOptimization,
224
132
  elementContentRects,
225
133
  ),
226
134
  ).toBe('left');
227
135
  });
228
136
 
229
- it('should return right when the mouse is positioned after half of the element and mouseMoveOptimization is disabled', () => {
230
- const event = {
231
- target: element,
232
- clientX: 101,
233
- };
234
-
235
- expect(
236
- // @ts-ignore
237
- getMousePositionHorizontalRelativeByElement(event),
238
- ).toBe('right');
239
- });
240
-
241
- it('should return right when the mouse is positioned after half of the element and mouseMoveOptimization is enabled', () => {
137
+ it('should return right when the mouse is positioned after half of the element', () => {
242
138
  const event = {
243
139
  target: element,
244
140
  offsetX: 101,
245
141
  };
246
142
 
247
- mouseMoveOptimization = true;
248
143
  elementContentRects = { 'table-cell-id': { width: 100 } };
249
144
 
250
145
  expect(
251
146
  getMousePositionHorizontalRelativeByElement(
252
147
  // @ts-ignore
253
148
  event,
254
- mouseMoveOptimization,
255
149
  elementContentRects,
256
150
  ),
257
151
  ).toBe('right');
@@ -4,7 +4,6 @@ import {
4
4
  EVENT_TYPE,
5
5
  TABLE_ACTION,
6
6
  } from '@atlaskit/editor-common/analytics';
7
- import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
8
7
  import {
9
8
  browser,
10
9
  closestElement,
@@ -298,98 +297,92 @@ export const handleMouseLeave = (view: EditorView, event: Event): boolean => {
298
297
  return false;
299
298
  };
300
299
 
301
- export const handleMouseMove =
302
- (getEditorFeatureFlags: GetEditorFeatureFlags) =>
303
- (
304
- view: EditorView,
305
- event: Event,
306
- elementContentRects?: ElementContentRects,
307
- ) => {
308
- if (!(event.target instanceof HTMLElement)) {
309
- return false;
310
- }
311
- const element = event.target;
300
+ export const handleMouseMove = (
301
+ view: EditorView,
302
+ event: Event,
303
+ elementContentRects?: ElementContentRects,
304
+ ) => {
305
+ if (!(event.target instanceof HTMLElement)) {
306
+ return false;
307
+ }
308
+ const element = event.target;
312
309
 
313
- if (isColumnControlsDecorations(element)) {
314
- const { state, dispatch } = view;
315
- const { insertColumnButtonIndex } = getPluginState(state);
316
- const [startIndex, endIndex] = getColumnOrRowIndex(element);
317
-
318
- const positionColumn =
319
- getMousePositionHorizontalRelativeByElement(
320
- event as MouseEvent,
321
- false,
322
- elementContentRects,
323
- ) === 'right'
324
- ? endIndex
325
- : startIndex;
326
-
327
- if (positionColumn !== insertColumnButtonIndex) {
328
- return showInsertColumnButton(positionColumn)(state, dispatch);
329
- }
310
+ if (isColumnControlsDecorations(element)) {
311
+ const { state, dispatch } = view;
312
+ const { insertColumnButtonIndex } = getPluginState(state);
313
+ const [startIndex, endIndex] = getColumnOrRowIndex(element);
314
+
315
+ const positionColumn =
316
+ getMousePositionHorizontalRelativeByElement(
317
+ event as MouseEvent,
318
+ elementContentRects,
319
+ ) === 'right'
320
+ ? endIndex
321
+ : startIndex;
322
+
323
+ if (positionColumn !== insertColumnButtonIndex) {
324
+ return showInsertColumnButton(positionColumn)(state, dispatch);
330
325
  }
326
+ }
331
327
 
332
- if (isRowControlsButton(element)) {
333
- const { state, dispatch } = view;
334
- const { insertRowButtonIndex } = getPluginState(state);
335
- const [startIndex, endIndex] = getColumnOrRowIndex(element);
328
+ if (isRowControlsButton(element)) {
329
+ const { state, dispatch } = view;
330
+ const { insertRowButtonIndex } = getPluginState(state);
331
+ const [startIndex, endIndex] = getColumnOrRowIndex(element);
336
332
 
337
- const positionRow =
338
- getMousePositionVerticalRelativeByElement(event as MouseEvent) ===
339
- 'bottom'
340
- ? endIndex
341
- : startIndex;
333
+ const positionRow =
334
+ getMousePositionVerticalRelativeByElement(event as MouseEvent) ===
335
+ 'bottom'
336
+ ? endIndex
337
+ : startIndex;
342
338
 
343
- if (positionRow !== insertRowButtonIndex) {
344
- return showInsertRowButton(positionRow)(state, dispatch);
345
- }
339
+ if (positionRow !== insertRowButtonIndex) {
340
+ return showInsertRowButton(positionRow)(state, dispatch);
346
341
  }
342
+ }
347
343
 
348
- const { mouseMoveOptimization } = getEditorFeatureFlags();
344
+ if (!isResizeHandleDecoration(element) && isCell(element)) {
345
+ const positionColumn = getMousePositionHorizontalRelativeByElement(
346
+ event as MouseEvent,
347
+ elementContentRects,
348
+ RESIZE_HANDLE_AREA_DECORATION_GAP,
349
+ );
349
350
 
350
- if (!isResizeHandleDecoration(element) && isCell(element)) {
351
- const positionColumn = getMousePositionHorizontalRelativeByElement(
352
- event as MouseEvent,
353
- mouseMoveOptimization,
354
- elementContentRects,
355
- RESIZE_HANDLE_AREA_DECORATION_GAP,
351
+ if (positionColumn !== null) {
352
+ const { state, dispatch } = view;
353
+ const { resizeHandleColumnIndex, resizeHandleRowIndex } =
354
+ getPluginState(state);
355
+ const tableCell = closestElement(
356
+ element,
357
+ 'td, th',
358
+ ) as HTMLTableCellElement;
359
+ const cellStartPosition = view.posAtDOM(tableCell, 0);
360
+ const rect = findCellRectClosestToPos(
361
+ state.doc.resolve(cellStartPosition),
356
362
  );
357
363
 
358
- if (positionColumn !== null) {
359
- const { state, dispatch } = view;
360
- const { resizeHandleColumnIndex, resizeHandleRowIndex } =
361
- getPluginState(state);
362
- const tableCell = closestElement(
363
- element,
364
- 'td, th',
365
- ) as HTMLTableCellElement;
366
- const cellStartPosition = view.posAtDOM(tableCell, 0);
367
- const rect = findCellRectClosestToPos(
368
- state.doc.resolve(cellStartPosition),
369
- );
370
-
371
- if (rect) {
372
- const columnEndIndexTarget =
373
- positionColumn === 'left' ? rect.left : rect.right;
374
-
375
- const rowIndexTarget = rect.top;
376
-
377
- if (
378
- columnEndIndexTarget !== resizeHandleColumnIndex ||
379
- rowIndexTarget !== resizeHandleRowIndex ||
380
- !hasResizeHandler({ target: element, columnEndIndexTarget })
381
- ) {
382
- return addResizeHandleDecorations(
383
- rowIndexTarget,
384
- columnEndIndexTarget,
385
- )(state, dispatch);
386
- }
364
+ if (rect) {
365
+ const columnEndIndexTarget =
366
+ positionColumn === 'left' ? rect.left : rect.right;
367
+
368
+ const rowIndexTarget = rect.top;
369
+
370
+ if (
371
+ columnEndIndexTarget !== resizeHandleColumnIndex ||
372
+ rowIndexTarget !== resizeHandleRowIndex ||
373
+ !hasResizeHandler({ target: element, columnEndIndexTarget })
374
+ ) {
375
+ return addResizeHandleDecorations(
376
+ rowIndexTarget,
377
+ columnEndIndexTarget,
378
+ )(state, dispatch);
387
379
  }
388
380
  }
389
381
  }
382
+ }
390
383
 
391
- return false;
392
- };
384
+ return false;
385
+ };
393
386
 
394
387
  export function handleTripleClick(view: EditorView, pos: number) {
395
388
  const { state, dispatch } = view;