@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
@@ -179,9 +179,8 @@ export const handleMouseOver = (
179
179
  }
180
180
  const { state, dispatch } = view;
181
181
  const target = mouseEvent.target;
182
- const { insertColumnButtonIndex, insertRowButtonIndex } = getPluginState(
183
- state,
184
- );
182
+ const { insertColumnButtonIndex, insertRowButtonIndex } =
183
+ getPluginState(state);
185
184
 
186
185
  if (isInsertRowButton(target)) {
187
186
  const [startIndex, endIndex] = getColumnOrRowIndex(target);
@@ -276,9 +275,8 @@ export const handleMouseLeave = (view: EditorView, event: Event): boolean => {
276
275
  }
277
276
 
278
277
  const { state, dispatch } = view;
279
- const { insertColumnButtonIndex, insertRowButtonIndex } = getPluginState(
280
- state,
281
- );
278
+ const { insertColumnButtonIndex, insertRowButtonIndex } =
279
+ getPluginState(state);
282
280
 
283
281
  const target = event.target;
284
282
  if (isTableControlsButton(target)) {
@@ -296,99 +294,99 @@ export const handleMouseLeave = (view: EditorView, event: Event): boolean => {
296
294
  return false;
297
295
  };
298
296
 
299
- export const handleMouseMove = (
300
- getEditorFeatureFlags: GetEditorFeatureFlags,
301
- ) => (
302
- view: EditorView,
303
- event: Event,
304
- tableCellOptimization?: boolean,
305
- elementContentRects?: ElementContentRects,
306
- ) => {
307
- if (!(event.target instanceof HTMLElement)) {
308
- return false;
309
- }
310
- const element = event.target;
311
-
312
- if (isColumnControlsDecorations(element)) {
313
- const { state, dispatch } = view;
314
- const { insertColumnButtonIndex } = getPluginState(state);
315
- const [startIndex, endIndex] = getColumnOrRowIndex(element);
316
-
317
- const positionColumn =
318
- getMousePositionHorizontalRelativeByElement(
319
- event as MouseEvent,
320
- tableCellOptimization,
321
- elementContentRects,
322
- ) === 'right'
323
- ? endIndex
324
- : startIndex;
297
+ export const handleMouseMove =
298
+ (getEditorFeatureFlags: GetEditorFeatureFlags) =>
299
+ (
300
+ view: EditorView,
301
+ event: Event,
302
+ tableCellOptimization?: boolean,
303
+ elementContentRects?: ElementContentRects,
304
+ ) => {
305
+ if (!(event.target instanceof HTMLElement)) {
306
+ return false;
307
+ }
308
+ const element = event.target;
325
309
 
326
- if (positionColumn !== insertColumnButtonIndex) {
327
- return showInsertColumnButton(positionColumn)(state, dispatch);
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
+ tableCellOptimization,
319
+ elementContentRects,
320
+ ) === 'right'
321
+ ? endIndex
322
+ : startIndex;
323
+
324
+ if (positionColumn !== insertColumnButtonIndex) {
325
+ return showInsertColumnButton(positionColumn)(state, dispatch);
326
+ }
328
327
  }
329
- }
330
328
 
331
- if (isRowControlsButton(element)) {
332
- const { state, dispatch } = view;
333
- const { insertRowButtonIndex } = getPluginState(state);
334
- const [startIndex, endIndex] = getColumnOrRowIndex(element);
329
+ if (isRowControlsButton(element)) {
330
+ const { state, dispatch } = view;
331
+ const { insertRowButtonIndex } = getPluginState(state);
332
+ const [startIndex, endIndex] = getColumnOrRowIndex(element);
335
333
 
336
- const positionRow =
337
- getMousePositionVerticalRelativeByElement(event as MouseEvent) ===
338
- 'bottom'
339
- ? endIndex
340
- : startIndex;
334
+ const positionRow =
335
+ getMousePositionVerticalRelativeByElement(event as MouseEvent) ===
336
+ 'bottom'
337
+ ? endIndex
338
+ : startIndex;
341
339
 
342
- if (positionRow !== insertRowButtonIndex) {
343
- return showInsertRowButton(positionRow)(state, dispatch);
340
+ if (positionRow !== insertRowButtonIndex) {
341
+ return showInsertRowButton(positionRow)(state, dispatch);
342
+ }
344
343
  }
345
- }
346
344
 
347
- const { mouseMoveOptimization } = getEditorFeatureFlags();
348
- // we only want to allow mouseMoveOptimisation when tableCellOptimization is enabled
349
- // because it relies on tableCell node view that is added via tableCellOptimization
350
- const useMouseMoveOptimisation =
351
- tableCellOptimization && mouseMoveOptimization;
352
-
353
- if (!isResizeHandleDecoration(element) && isCell(element)) {
354
- const positionColumn = getMousePositionHorizontalRelativeByElement(
355
- event as MouseEvent,
356
- useMouseMoveOptimisation,
357
- elementContentRects,
358
- RESIZE_HANDLE_AREA_DECORATION_GAP,
359
- );
345
+ const { mouseMoveOptimization } = getEditorFeatureFlags();
346
+ // we only want to allow mouseMoveOptimisation when tableCellOptimization is enabled
347
+ // because it relies on tableCell node view that is added via tableCellOptimization
348
+ const useMouseMoveOptimisation =
349
+ tableCellOptimization && mouseMoveOptimization;
360
350
 
361
- if (positionColumn !== null) {
362
- const { state, dispatch } = view;
363
- const { resizeHandleColumnIndex } = getPluginState(state);
364
- const tableCell = closestElement(
365
- element,
366
- 'td, th',
367
- ) as HTMLTableCellElement;
368
- const cellStartPosition = view.posAtDOM(tableCell, 0);
369
- const rect = findCellRectClosestToPos(
370
- state.doc.resolve(cellStartPosition),
351
+ if (!isResizeHandleDecoration(element) && isCell(element)) {
352
+ const positionColumn = getMousePositionHorizontalRelativeByElement(
353
+ event as MouseEvent,
354
+ useMouseMoveOptimisation,
355
+ elementContentRects,
356
+ RESIZE_HANDLE_AREA_DECORATION_GAP,
371
357
  );
372
358
 
373
- if (rect) {
374
- const columnEndIndexTarget =
375
- positionColumn === 'left' ? rect.left : rect.right;
376
-
377
- if (
378
- columnEndIndexTarget !== resizeHandleColumnIndex ||
379
- !hasResizeHandler({ target: element, columnEndIndexTarget })
380
- ) {
381
- return addResizeHandleDecorations(columnEndIndexTarget)(
382
- state,
383
- dispatch,
384
- );
359
+ if (positionColumn !== null) {
360
+ const { state, dispatch } = view;
361
+ const { resizeHandleColumnIndex } = 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
+ if (
376
+ columnEndIndexTarget !== resizeHandleColumnIndex ||
377
+ !hasResizeHandler({ target: element, columnEndIndexTarget })
378
+ ) {
379
+ return addResizeHandleDecorations(columnEndIndexTarget)(
380
+ state,
381
+ dispatch,
382
+ );
383
+ }
385
384
  }
386
385
  }
387
386
  }
388
- }
389
387
 
390
- return false;
391
- };
388
+ return false;
389
+ };
392
390
 
393
391
  export function handleTripleClick(view: EditorView, pos: number) {
394
392
  const { state, dispatch } = view;
@@ -482,31 +480,33 @@ export const handleCut = (
482
480
  return tr;
483
481
  };
484
482
 
485
- export const whenTableInFocus = (
486
- eventHandler: (
487
- view: EditorView,
488
- mouseEvent: Event,
489
- tableCellOptimization?: boolean,
483
+ export const whenTableInFocus =
484
+ (
485
+ eventHandler: (
486
+ view: EditorView,
487
+ mouseEvent: Event,
488
+ tableCellOptimization?: boolean,
489
+ elementContentRects?: ElementContentRects,
490
+ ) => boolean,
490
491
  elementContentRects?: ElementContentRects,
491
- ) => boolean,
492
- elementContentRects?: ElementContentRects,
493
- ) => (view: EditorView, mouseEvent: Event): boolean => {
494
- const tableResizePluginState = getResizePluginState(view.state);
495
- const tablePluginState = getPluginState(view.state);
496
- const isDragging =
497
- tableResizePluginState && !!tableResizePluginState.dragging;
498
- const hasTableNode = tablePluginState && tablePluginState.tableNode;
499
- const tableCellOptimization =
500
- tablePluginState?.pluginConfig?.tableCellOptimization;
501
-
502
- if (!hasTableNode || isDragging) {
503
- return false;
504
- }
492
+ ) =>
493
+ (view: EditorView, mouseEvent: Event): boolean => {
494
+ const tableResizePluginState = getResizePluginState(view.state);
495
+ const tablePluginState = getPluginState(view.state);
496
+ const isDragging =
497
+ tableResizePluginState && !!tableResizePluginState.dragging;
498
+ const hasTableNode = tablePluginState && tablePluginState.tableNode;
499
+ const tableCellOptimization =
500
+ tablePluginState?.pluginConfig?.tableCellOptimization;
501
+
502
+ if (!hasTableNode || isDragging) {
503
+ return false;
504
+ }
505
505
 
506
- return eventHandler(
507
- view,
508
- mouseEvent,
509
- tableCellOptimization,
510
- elementContentRects,
511
- );
512
- };
506
+ return eventHandler(
507
+ view,
508
+ mouseEvent,
509
+ tableCellOptimization,
510
+ elementContentRects,
511
+ );
512
+ };
@@ -47,112 +47,113 @@ type BuilderTablePluginState = (props: {
47
47
  table?: ContentNodeWithPos;
48
48
  }) => (pluginState: TablePluginState) => TablePluginState;
49
49
 
50
- const updateTargetCellPosition: BuilderTablePluginState = ({ tr, table }) => (
51
- pluginState: TablePluginState,
52
- ) => {
53
- const tableNode = table && table.node;
54
- if (!tableNode) {
50
+ const updateTargetCellPosition: BuilderTablePluginState =
51
+ ({ tr, table }) =>
52
+ (pluginState: TablePluginState) => {
53
+ const tableNode = table && table.node;
54
+ if (!tableNode) {
55
+ return {
56
+ ...pluginState,
57
+ targetCellPosition: undefined,
58
+ };
59
+ }
60
+
61
+ const { tableCell, tableHeader } = tr.doc.type.schema.nodes;
62
+ const cell = findParentNodeOfType([tableCell, tableHeader])(tr.selection);
63
+ const targetCellPosition = cell ? cell.pos : undefined;
64
+
65
+ if (pluginState.targetCellPosition === targetCellPosition) {
66
+ return pluginState;
67
+ }
68
+
55
69
  return {
56
70
  ...pluginState,
57
- targetCellPosition: undefined,
71
+ targetCellPosition,
58
72
  };
59
- }
60
-
61
- const { tableCell, tableHeader } = tr.doc.type.schema.nodes;
62
- const cell = findParentNodeOfType([tableCell, tableHeader])(tr.selection);
63
- const targetCellPosition = cell ? cell.pos : undefined;
64
-
65
- if (pluginState.targetCellPosition === targetCellPosition) {
66
- return pluginState;
67
- }
68
-
69
- return {
70
- ...pluginState,
71
- targetCellPosition,
72
73
  };
73
- };
74
74
 
75
- const updateTableNodePluginState: BuilderTablePluginState = ({ tr, table }) => (
76
- pluginState,
77
- ) => {
78
- const tableNode = table && table.node;
75
+ const updateTableNodePluginState: BuilderTablePluginState =
76
+ ({ tr, table }) =>
77
+ (pluginState) => {
78
+ const tableNode = table && table.node;
79
79
 
80
- if (!tableNode || isTextInput(tr)) {
81
- return pluginState;
82
- }
80
+ if (!tableNode || isTextInput(tr)) {
81
+ return pluginState;
82
+ }
83
83
 
84
- return {
85
- ...pluginState,
86
- ...defaultTableSelection,
87
- tableNode,
88
- ordering: nextTableSorting(tr, table),
89
- resizeHandleColumnIndex: nextResizeHandleColumnIndex(
90
- tr,
91
- pluginState.resizeHandleColumnIndex,
92
- ),
93
- isNumberColumnEnabled: checkIfNumberColumnEnabled(tr.selection),
94
- isHeaderColumnEnabled: checkIfHeaderColumnEnabled(tr.selection),
95
- isHeaderRowEnabled: checkIfHeaderRowEnabled(tr.selection),
96
- };
97
- };
98
-
99
- const updateCollapseHandler: BuilderTablePluginState = ({ tr, table }) => (
100
- pluginState,
101
- ) => {
102
- const tableNode = table && table.node;
103
- const schema = tr.doc.type.schema;
104
- const allowCollapse = pluginState.pluginConfig.allowCollapse;
105
- const isExpandInSchema = schema.nodes.expand !== undefined;
106
- const isCollapseEnabled = allowCollapse && isExpandInSchema;
107
-
108
- /**
109
- * If we don't have focus, or collapse isn't allowed, or a table node doesn't
110
- * exist, we don't need to waste extra checks below
111
- */
112
- if (!pluginState.editorHasFocus || !isCollapseEnabled || !tableNode) {
113
- return pluginState;
114
- }
115
-
116
- const expandNodeType = schema.nodes.expand as NodeType;
117
- const isTableCollapsed =
118
- expandNodeType && !!findParentNodeOfType(expandNodeType)(tr.selection);
119
-
120
- const trCanBeCollapsed = isTableCollapsible(tr).tableIsCollapsible;
121
-
122
- // We're focused on a table + we're not inside an expand
123
- const canCollapseTable: boolean =
124
- !!pluginState.tableNode &&
125
- // is it already collapsed?
126
- !isTableCollapsed &&
127
- !!trCanBeCollapsed;
128
-
129
- if (
130
- pluginState.isTableCollapsed !== isTableCollapsed ||
131
- pluginState.canCollapseTable !== canCollapseTable
132
- ) {
133
84
  return {
134
85
  ...pluginState,
135
- isTableCollapsed,
136
- canCollapseTable,
86
+ ...defaultTableSelection,
87
+ tableNode,
88
+ ordering: nextTableSorting(tr, table),
89
+ resizeHandleColumnIndex: nextResizeHandleColumnIndex(
90
+ tr,
91
+ pluginState.resizeHandleColumnIndex,
92
+ ),
93
+ isNumberColumnEnabled: checkIfNumberColumnEnabled(tr.selection),
94
+ isHeaderColumnEnabled: checkIfHeaderColumnEnabled(tr.selection),
95
+ isHeaderRowEnabled: checkIfHeaderRowEnabled(tr.selection),
137
96
  };
138
- }
97
+ };
139
98
 
140
- return pluginState;
141
- };
99
+ const updateCollapseHandler: BuilderTablePluginState =
100
+ ({ tr, table }) =>
101
+ (pluginState) => {
102
+ const tableNode = table && table.node;
103
+ const schema = tr.doc.type.schema;
104
+ const allowCollapse = pluginState.pluginConfig.allowCollapse;
105
+ const isExpandInSchema = schema.nodes.expand !== undefined;
106
+ const isCollapseEnabled = allowCollapse && isExpandInSchema;
107
+
108
+ /**
109
+ * If we don't have focus, or collapse isn't allowed, or a table node doesn't
110
+ * exist, we don't need to waste extra checks below
111
+ */
112
+ if (!pluginState.editorHasFocus || !isCollapseEnabled || !tableNode) {
113
+ return pluginState;
114
+ }
115
+
116
+ const expandNodeType = schema.nodes.expand as NodeType;
117
+ const isTableCollapsed =
118
+ expandNodeType && !!findParentNodeOfType(expandNodeType)(tr.selection);
119
+
120
+ const trCanBeCollapsed = isTableCollapsible(tr).tableIsCollapsible;
121
+
122
+ // We're focused on a table + we're not inside an expand
123
+ const canCollapseTable: boolean =
124
+ !!pluginState.tableNode &&
125
+ // is it already collapsed?
126
+ !isTableCollapsed &&
127
+ !!trCanBeCollapsed;
128
+
129
+ if (
130
+ pluginState.isTableCollapsed !== isTableCollapsed ||
131
+ pluginState.canCollapseTable !== canCollapseTable
132
+ ) {
133
+ return {
134
+ ...pluginState,
135
+ isTableCollapsed,
136
+ canCollapseTable,
137
+ };
138
+ }
142
139
 
143
- const buildPluginState = (
144
- builders: Array<BuilderTablePluginState>,
145
- ): BuilderTablePluginState => (props) => (pluginState) => {
146
- if (!props.table) {
147
- return pluginState.targetCellPosition
148
- ? { ...pluginState, targetCellPosition: undefined }
149
- : pluginState;
150
- }
151
- return builders.reduce(
152
- (_pluginState, transform) => transform(props)(_pluginState),
153
- pluginState,
154
- );
155
- };
140
+ return pluginState;
141
+ };
142
+
143
+ const buildPluginState =
144
+ (builders: Array<BuilderTablePluginState>): BuilderTablePluginState =>
145
+ (props) =>
146
+ (pluginState) => {
147
+ if (!props.table) {
148
+ return pluginState.targetCellPosition
149
+ ? { ...pluginState, targetCellPosition: undefined }
150
+ : pluginState;
151
+ }
152
+ return builders.reduce(
153
+ (_pluginState, transform) => transform(props)(_pluginState),
154
+ pluginState,
155
+ );
156
+ };
156
157
 
157
158
  export const handleDocOrSelectionChanged = (
158
159
  tr: Transaction | ReadonlyTransaction,
@@ -170,9 +170,10 @@ export class OverflowShadowsObserver {
170
170
  }px`;
171
171
  // Use getElementsByClassName here for a live node list to capture
172
172
  // sticky shadows
173
- const liveRightShadows = this.wrapper?.parentElement?.getElementsByClassName(
174
- `${ClassName.TABLE_RIGHT_SHADOW}`,
175
- );
173
+ const liveRightShadows =
174
+ this.wrapper?.parentElement?.getElementsByClassName(
175
+ `${ClassName.TABLE_RIGHT_SHADOW}`,
176
+ );
176
177
  const liveLeftShadows = this.wrapper?.parentElement?.getElementsByClassName(
177
178
  `${ClassName.TABLE_LEFT_SHADOW}`,
178
179
  );
@@ -198,9 +198,8 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
198
198
  componentDidUpdate(prevProps: ComponentProps) {
199
199
  const { getNode, isMediaFullscreen, allowColumnResizing } = this.props;
200
200
 
201
- const {
202
- tableOverflowShadowsOptimization,
203
- } = this.props.getEditorFeatureFlags();
201
+ const { tableOverflowShadowsOptimization } =
202
+ this.props.getEditorFeatureFlags();
204
203
 
205
204
  if (!tableOverflowShadowsOptimization) {
206
205
  this.updateShadows();
@@ -281,9 +280,8 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
281
280
  };
282
281
 
283
282
  onStickyState = (state: StickyPluginState) => {
284
- const {
285
- tableOverflowShadowsOptimization,
286
- } = this.props.getEditorFeatureFlags();
283
+ const { tableOverflowShadowsOptimization } =
284
+ this.props.getEditorFeatureFlags();
287
285
 
288
286
  const pos = this.props.getPos();
289
287
  if (!isValidPosition(pos, this.props.view.state)) {
@@ -507,9 +505,8 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
507
505
  }
508
506
  }
509
507
 
510
- const {
511
- tableOverflowShadowsOptimization,
512
- } = this.props.getEditorFeatureFlags();
508
+ const { tableOverflowShadowsOptimization } =
509
+ this.props.getEditorFeatureFlags();
513
510
 
514
511
  if (!tableOverflowShadowsOptimization) {
515
512
  this.updateShadows();
@@ -22,51 +22,51 @@ export const updateShadowListForStickyStyles = (
22
22
  * Update overflow shadows for a given wrapper & table.
23
23
  * if `overflowShadowOptimization` is enabled, this will exit early.
24
24
  */
25
- export const updateOverflowShadows = (
26
- getEditorFeatureFlags: GetEditorFeatureFlags,
27
- ) => (
28
- editorState: EditorState,
29
- wrapper?: HTMLElement | null,
30
- table?: HTMLElement | null,
31
- rightShadows?: NodeListOf<HTMLElement> | null,
32
- leftShadows?: NodeListOf<HTMLElement> | null,
33
- ) => {
34
- if (getEditorFeatureFlags()?.tableOverflowShadowsOptimization === true) {
35
- return false;
36
- }
37
- // Right shadow
38
- if (table && wrapper) {
39
- const stickyRow = wrapper.querySelector('tr.sticky');
40
- const stickyCell = stickyRow && stickyRow.firstElementChild;
25
+ export const updateOverflowShadows =
26
+ (getEditorFeatureFlags: GetEditorFeatureFlags) =>
27
+ (
28
+ editorState: EditorState,
29
+ wrapper?: HTMLElement | null,
30
+ table?: HTMLElement | null,
31
+ rightShadows?: NodeListOf<HTMLElement> | null,
32
+ leftShadows?: NodeListOf<HTMLElement> | null,
33
+ ) => {
34
+ if (getEditorFeatureFlags()?.tableOverflowShadowsOptimization === true) {
35
+ return false;
36
+ }
37
+ // Right shadow
38
+ if (table && wrapper) {
39
+ const stickyRow = wrapper.querySelector('tr.sticky');
40
+ const stickyCell = stickyRow && stickyRow.firstElementChild;
41
41
 
42
- if (rightShadows) {
43
- const diff = table.offsetWidth - wrapper.offsetWidth;
42
+ if (rightShadows) {
43
+ const diff = table.offsetWidth - wrapper.offsetWidth;
44
44
 
45
- for (let i = 0; i < rightShadows.length; i++) {
46
- const rightShadow = rightShadows[i];
47
- rightShadow.style.display =
48
- diff > 0 && diff > wrapper.scrollLeft ? 'block' : 'none';
45
+ for (let i = 0; i < rightShadows.length; i++) {
46
+ const rightShadow = rightShadows[i];
47
+ rightShadow.style.display =
48
+ diff > 0 && diff > wrapper.scrollLeft ? 'block' : 'none';
49
49
 
50
- if (
51
- rightShadow.classList.contains(ClassName.TABLE_STICKY_SHADOW) &&
52
- stickyCell
53
- ) {
54
- rightShadow.style.height = `${stickyCell.clientHeight + 1}px`;
50
+ if (
51
+ rightShadow.classList.contains(ClassName.TABLE_STICKY_SHADOW) &&
52
+ stickyCell
53
+ ) {
54
+ rightShadow.style.height = `${stickyCell.clientHeight + 1}px`;
55
+ }
55
56
  }
56
57
  }
57
- }
58
- if (leftShadows) {
59
- for (let i = 0; i < leftShadows.length; i++) {
60
- const leftShadow = leftShadows[i];
61
- leftShadow.style.display = wrapper.scrollLeft > 0 ? 'block' : 'none';
58
+ if (leftShadows) {
59
+ for (let i = 0; i < leftShadows.length; i++) {
60
+ const leftShadow = leftShadows[i];
61
+ leftShadow.style.display = wrapper.scrollLeft > 0 ? 'block' : 'none';
62
62
 
63
- if (
64
- leftShadow.classList.contains(ClassName.TABLE_STICKY_SHADOW) &&
65
- stickyCell
66
- ) {
67
- leftShadow.style.height = `${stickyCell.clientHeight + 1}px`;
63
+ if (
64
+ leftShadow.classList.contains(ClassName.TABLE_STICKY_SHADOW) &&
65
+ stickyCell
66
+ ) {
67
+ leftShadow.style.height = `${stickyCell.clientHeight + 1}px`;
68
+ }
68
69
  }
69
70
  }
70
71
  }
71
- }
72
- };
72
+ };
@@ -65,16 +65,14 @@ const removeColumnControlsSelectedDecoration: DecorationTransformer = ({
65
65
  const hasColumnSelectedDecorations = (decorationSet: DecorationSet): boolean =>
66
66
  !!findColumnControlSelectedDecoration(decorationSet).length;
67
67
 
68
- export const maybeUpdateColumnControlsSelectedDecoration: DecorationTransformer = ({
69
- decorationSet,
70
- tr,
71
- }): DecorationSet => {
72
- if (!hasColumnSelectedDecorations(decorationSet)) {
73
- return decorationSet;
74
- }
68
+ export const maybeUpdateColumnControlsSelectedDecoration: DecorationTransformer =
69
+ ({ decorationSet, tr }): DecorationSet => {
70
+ if (!hasColumnSelectedDecorations(decorationSet)) {
71
+ return decorationSet;
72
+ }
75
73
 
76
- return removeColumnControlsSelectedDecoration({ decorationSet, tr });
77
- };
74
+ return removeColumnControlsSelectedDecoration({ decorationSet, tr });
75
+ };
78
76
 
79
77
  export const buildColumnControlsDecorations: DecorationTransformer = ({
80
78
  decorationSet,