@atlaskit/editor-plugin-table 7.16.11 → 7.16.12

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 (242) hide show
  1. package/.eslintrc.js +3 -3
  2. package/CHANGELOG.md +8 -0
  3. package/dist/cjs/commands/misc.js +3 -3
  4. package/dist/cjs/nodeviews/TableCell.js +10 -10
  5. package/dist/cjs/nodeviews/TableContainer.js +41 -6
  6. package/dist/cjs/nodeviews/TableResizer.js +7 -7
  7. package/dist/cjs/nodeviews/TableRow.js +23 -23
  8. package/dist/cjs/pm-plugins/table-resizing/plugin.js +3 -3
  9. package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +4 -4
  10. package/dist/cjs/pm-plugins/table-resizing/utils/scale-table.js +3 -3
  11. package/dist/cjs/ui/FloatingContextualMenu/styles.js +1 -1
  12. package/dist/cjs/ui/FloatingDragMenu/styles.js +1 -1
  13. package/dist/cjs/ui/common-styles.js +13 -13
  14. package/dist/cjs/ui/ui-styles.js +25 -25
  15. package/dist/cjs/utils/merged-cells.js +3 -3
  16. package/dist/es2019/commands/misc.js +3 -3
  17. package/dist/es2019/nodeviews/TableContainer.js +43 -5
  18. package/dist/es2019/nodeviews/TableResizer.js +7 -7
  19. package/dist/es2019/nodeviews/TableRow.js +21 -21
  20. package/dist/es2019/pm-plugins/table-resizing/plugin.js +3 -3
  21. package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +4 -4
  22. package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +3 -3
  23. package/dist/es2019/ui/FloatingContextualMenu/styles.js +47 -47
  24. package/dist/es2019/ui/FloatingDragMenu/styles.js +30 -30
  25. package/dist/es2019/ui/common-styles.js +802 -816
  26. package/dist/es2019/ui/ui-styles.js +665 -678
  27. package/dist/es2019/utils/merged-cells.js +3 -3
  28. package/dist/esm/commands/misc.js +3 -3
  29. package/dist/esm/nodeviews/TableCell.js +10 -10
  30. package/dist/esm/nodeviews/TableContainer.js +42 -7
  31. package/dist/esm/nodeviews/TableResizer.js +7 -7
  32. package/dist/esm/nodeviews/TableRow.js +23 -23
  33. package/dist/esm/pm-plugins/table-resizing/plugin.js +3 -3
  34. package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +4 -4
  35. package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +3 -3
  36. package/dist/esm/ui/FloatingContextualMenu/styles.js +1 -1
  37. package/dist/esm/ui/FloatingDragMenu/styles.js +1 -1
  38. package/dist/esm/ui/common-styles.js +13 -13
  39. package/dist/esm/ui/ui-styles.js +25 -25
  40. package/dist/esm/utils/merged-cells.js +3 -3
  41. package/dist/types/pm-plugins/decorations/utils/index.d.ts +1 -1
  42. package/dist/types/pm-plugins/drag-and-drop/utils/autoscrollers.d.ts +1 -1
  43. package/dist/types/pm-plugins/drag-and-drop/utils/getDragBehaviour.d.ts +1 -1
  44. package/dist/types/pm-plugins/table-resizing/utils/index.d.ts +1 -1
  45. package/dist/types/ui/ColumnResizeWidget/index.d.ts +1 -1
  46. package/dist/types/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.d.ts +1 -1
  47. package/dist/types/ui/FloatingToolbarLabel/FloatingToolbarLabel.d.ts +1 -1
  48. package/dist/types/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +1 -1
  49. package/dist/types/ui/TableFloatingControls/CornerControls/index.d.ts +1 -1
  50. package/dist/types/ui/icons/DragHandleDisabledIcon.d.ts +1 -1
  51. package/dist/types-ts4.5/pm-plugins/decorations/utils/index.d.ts +1 -1
  52. package/dist/types-ts4.5/pm-plugins/drag-and-drop/utils/autoscrollers.d.ts +1 -1
  53. package/dist/types-ts4.5/pm-plugins/drag-and-drop/utils/getDragBehaviour.d.ts +1 -1
  54. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/index.d.ts +1 -1
  55. package/dist/types-ts4.5/ui/ColumnResizeWidget/index.d.ts +1 -1
  56. package/dist/types-ts4.5/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.d.ts +1 -1
  57. package/dist/types-ts4.5/ui/FloatingToolbarLabel/FloatingToolbarLabel.d.ts +1 -1
  58. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +1 -1
  59. package/dist/types-ts4.5/ui/TableFloatingControls/CornerControls/index.d.ts +1 -1
  60. package/dist/types-ts4.5/ui/icons/DragHandleDisabledIcon.d.ts +1 -1
  61. package/docs/0-intro.tsx +9 -7
  62. package/package.json +2 -2
  63. package/report.api.md +67 -66
  64. package/src/commands/clear.ts +36 -44
  65. package/src/commands/collapse.ts +8 -8
  66. package/src/commands/column-resize.ts +412 -452
  67. package/src/commands/delete.ts +14 -14
  68. package/src/commands/display-mode.ts +10 -11
  69. package/src/commands/go-to-next-cell.ts +48 -54
  70. package/src/commands/hover.ts +210 -227
  71. package/src/commands/index.ts +35 -35
  72. package/src/commands/insert.ts +208 -235
  73. package/src/commands/misc.ts +655 -748
  74. package/src/commands/referentiality.ts +9 -9
  75. package/src/commands/selection.ts +433 -563
  76. package/src/commands/sort.ts +68 -86
  77. package/src/commands/split-cell.ts +14 -14
  78. package/src/commands/toggle.ts +69 -67
  79. package/src/commands-with-analytics.ts +570 -639
  80. package/src/create-plugin-config.ts +13 -13
  81. package/src/event-handlers.ts +513 -612
  82. package/src/handlers.ts +120 -133
  83. package/src/nodeviews/ExternalDropTargets.tsx +68 -73
  84. package/src/nodeviews/OverflowShadowsObserver.ts +148 -157
  85. package/src/nodeviews/TableCell.ts +47 -54
  86. package/src/nodeviews/TableComponent.tsx +1018 -1112
  87. package/src/nodeviews/TableComponentWithSharedState.tsx +91 -94
  88. package/src/nodeviews/TableContainer.tsx +363 -339
  89. package/src/nodeviews/TableNodeViewBase.ts +19 -24
  90. package/src/nodeviews/TableResizer.tsx +565 -657
  91. package/src/nodeviews/TableRow.ts +580 -629
  92. package/src/nodeviews/TableStickyScrollbar.ts +173 -190
  93. package/src/nodeviews/__mocks__/OverflowShadowsObserver.ts +8 -8
  94. package/src/nodeviews/__mocks__/OverridableMock.ts +14 -15
  95. package/src/nodeviews/table.tsx +345 -375
  96. package/src/nodeviews/types.ts +21 -24
  97. package/src/nodeviews/update-overflow-shadows.ts +8 -14
  98. package/src/plugin.tsx +578 -603
  99. package/src/pm-plugins/analytics/actions.ts +10 -12
  100. package/src/pm-plugins/analytics/commands.ts +31 -37
  101. package/src/pm-plugins/analytics/plugin-factory.ts +4 -2
  102. package/src/pm-plugins/analytics/plugin-key.ts +1 -3
  103. package/src/pm-plugins/analytics/plugin.ts +60 -70
  104. package/src/pm-plugins/analytics/reducer.ts +19 -19
  105. package/src/pm-plugins/analytics/types.ts +10 -10
  106. package/src/pm-plugins/analytics/utils/moved-event.ts +38 -38
  107. package/src/pm-plugins/decorations/plugin.ts +58 -77
  108. package/src/pm-plugins/decorations/utils/column-controls.ts +59 -71
  109. package/src/pm-plugins/decorations/utils/column-resizing.ts +50 -57
  110. package/src/pm-plugins/decorations/utils/compose-decorations.ts +6 -6
  111. package/src/pm-plugins/decorations/utils/index.ts +3 -6
  112. package/src/pm-plugins/decorations/utils/types.ts +7 -12
  113. package/src/pm-plugins/default-table-selection.ts +3 -3
  114. package/src/pm-plugins/drag-and-drop/actions.ts +25 -25
  115. package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +158 -190
  116. package/src/pm-plugins/drag-and-drop/commands.ts +154 -170
  117. package/src/pm-plugins/drag-and-drop/consts.ts +4 -5
  118. package/src/pm-plugins/drag-and-drop/plugin-factory.ts +23 -20
  119. package/src/pm-plugins/drag-and-drop/plugin-key.ts +1 -3
  120. package/src/pm-plugins/drag-and-drop/plugin.ts +329 -383
  121. package/src/pm-plugins/drag-and-drop/reducer.ts +30 -30
  122. package/src/pm-plugins/drag-and-drop/types.ts +8 -8
  123. package/src/pm-plugins/drag-and-drop/utils/autoscrollers.ts +38 -41
  124. package/src/pm-plugins/drag-and-drop/utils/getDragBehaviour.ts +3 -6
  125. package/src/pm-plugins/drag-and-drop/utils/monitor.ts +57 -70
  126. package/src/pm-plugins/keymap.ts +208 -220
  127. package/src/pm-plugins/main.ts +348 -400
  128. package/src/pm-plugins/plugin-factory.ts +32 -34
  129. package/src/pm-plugins/safari-delete-composition-text-issue-workaround.ts +83 -97
  130. package/src/pm-plugins/sticky-headers/commands.ts +2 -6
  131. package/src/pm-plugins/sticky-headers/plugin-key.ts +1 -3
  132. package/src/pm-plugins/sticky-headers/plugin-state.ts +41 -44
  133. package/src/pm-plugins/sticky-headers/plugin.ts +4 -4
  134. package/src/pm-plugins/sticky-headers/types.ts +8 -8
  135. package/src/pm-plugins/sticky-headers/util.ts +10 -10
  136. package/src/pm-plugins/table-analytics.ts +70 -72
  137. package/src/pm-plugins/table-local-id.ts +180 -184
  138. package/src/pm-plugins/table-resizing/commands.ts +72 -85
  139. package/src/pm-plugins/table-resizing/event-handlers.ts +298 -317
  140. package/src/pm-plugins/table-resizing/plugin-factory.ts +10 -10
  141. package/src/pm-plugins/table-resizing/plugin-key.ts +1 -3
  142. package/src/pm-plugins/table-resizing/plugin.ts +61 -68
  143. package/src/pm-plugins/table-resizing/reducer.ts +30 -33
  144. package/src/pm-plugins/table-resizing/utils/colgroup.ts +84 -84
  145. package/src/pm-plugins/table-resizing/utils/column-state.ts +78 -81
  146. package/src/pm-plugins/table-resizing/utils/content-width.ts +94 -114
  147. package/src/pm-plugins/table-resizing/utils/dom.ts +93 -110
  148. package/src/pm-plugins/table-resizing/utils/index.ts +29 -34
  149. package/src/pm-plugins/table-resizing/utils/misc.ts +94 -119
  150. package/src/pm-plugins/table-resizing/utils/resize-column.ts +93 -106
  151. package/src/pm-plugins/table-resizing/utils/resize-logic.ts +240 -257
  152. package/src/pm-plugins/table-resizing/utils/resize-state.ts +343 -372
  153. package/src/pm-plugins/table-resizing/utils/scale-table.ts +202 -207
  154. package/src/pm-plugins/table-resizing/utils/types.ts +17 -17
  155. package/src/pm-plugins/table-resizing/utils/unit-to-number.ts +1 -2
  156. package/src/pm-plugins/table-selection-keymap.ts +25 -51
  157. package/src/pm-plugins/table-width.ts +191 -204
  158. package/src/pm-plugins/view-mode-sort/index.ts +223 -227
  159. package/src/pm-plugins/view-mode-sort/plugin-key.ts +3 -2
  160. package/src/pm-plugins/view-mode-sort/types.ts +12 -12
  161. package/src/pm-plugins/view-mode-sort/utils.ts +108 -117
  162. package/src/reducer.ts +139 -155
  163. package/src/toolbar.tsx +815 -905
  164. package/src/transforms/column-width.ts +186 -213
  165. package/src/transforms/delete-columns.ts +208 -222
  166. package/src/transforms/delete-rows.ts +117 -121
  167. package/src/transforms/fix-tables.ts +190 -215
  168. package/src/transforms/merge.ts +263 -269
  169. package/src/transforms/replace-table.ts +27 -43
  170. package/src/transforms/split.ts +65 -75
  171. package/src/types.ts +421 -427
  172. package/src/ui/ColumnResizeWidget/index.tsx +40 -47
  173. package/src/ui/DragHandle/HandleIconComponent.tsx +9 -13
  174. package/src/ui/DragHandle/index.tsx +221 -250
  175. package/src/ui/DragPreview/index.tsx +35 -35
  176. package/src/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.tsx +33 -41
  177. package/src/ui/FloatingContextualButton/FixedButton.tsx +154 -157
  178. package/src/ui/FloatingContextualButton/index.tsx +109 -115
  179. package/src/ui/FloatingContextualButton/styles.ts +43 -46
  180. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +634 -694
  181. package/src/ui/FloatingContextualMenu/index.tsx +83 -101
  182. package/src/ui/FloatingContextualMenu/styles.ts +57 -65
  183. package/src/ui/FloatingDeleteButton/DeleteButton.tsx +37 -37
  184. package/src/ui/FloatingDeleteButton/getPopUpOptions.ts +47 -57
  185. package/src/ui/FloatingDeleteButton/index.tsx +319 -350
  186. package/src/ui/FloatingDragMenu/DragMenu.tsx +555 -596
  187. package/src/ui/FloatingDragMenu/DropdownMenu.tsx +152 -162
  188. package/src/ui/FloatingDragMenu/index.tsx +88 -102
  189. package/src/ui/FloatingDragMenu/styles.ts +51 -54
  190. package/src/ui/FloatingInsertButton/InsertButton.tsx +204 -217
  191. package/src/ui/FloatingInsertButton/getPopupOptions.ts +100 -115
  192. package/src/ui/FloatingInsertButton/index.tsx +248 -292
  193. package/src/ui/FloatingToolbarLabel/FloatingToolbarLabel.tsx +24 -29
  194. package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +308 -329
  195. package/src/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +85 -94
  196. package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +46 -46
  197. package/src/ui/TableFloatingColumnControls/index.tsx +116 -136
  198. package/src/ui/TableFloatingControls/CornerControls/ClassicCornerControls.tsx +79 -91
  199. package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +95 -102
  200. package/src/ui/TableFloatingControls/CornerControls/index.tsx +1 -4
  201. package/src/ui/TableFloatingControls/CornerControls/types.ts +8 -8
  202. package/src/ui/TableFloatingControls/FloatingControlsWithSelection.tsx +50 -50
  203. package/src/ui/TableFloatingControls/NumberColumn/index.tsx +111 -124
  204. package/src/ui/TableFloatingControls/RowControls/ClassicControls.tsx +86 -105
  205. package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +305 -341
  206. package/src/ui/TableFloatingControls/RowDropTarget/index.tsx +72 -75
  207. package/src/ui/TableFloatingControls/index.tsx +191 -193
  208. package/src/ui/TableFullWidthLabel/index.tsx +20 -20
  209. package/src/ui/common-styles.ts +880 -912
  210. package/src/ui/consts.ts +29 -74
  211. package/src/ui/icons/AddColLeftIcon.tsx +33 -39
  212. package/src/ui/icons/AddColRightIcon.tsx +33 -39
  213. package/src/ui/icons/AddRowAboveIcon.tsx +16 -22
  214. package/src/ui/icons/AddRowBelowIcon.tsx +33 -39
  215. package/src/ui/icons/DisplayModeIcon.tsx +31 -31
  216. package/src/ui/icons/DragHandleDisabledIcon.tsx +19 -21
  217. package/src/ui/icons/DragHandleIcon.tsx +12 -12
  218. package/src/ui/icons/DragInMotionIcon.tsx +45 -52
  219. package/src/ui/icons/MergeCellsIcon.tsx +22 -28
  220. package/src/ui/icons/MinimisedHandle.tsx +9 -9
  221. package/src/ui/icons/SplitCellIcon.tsx +30 -36
  222. package/src/ui/ui-styles.ts +769 -798
  223. package/src/utils/alignment.ts +1 -1
  224. package/src/utils/analytics.ts +192 -208
  225. package/src/utils/collapse.ts +55 -64
  226. package/src/utils/column-controls.ts +237 -254
  227. package/src/utils/create.ts +30 -30
  228. package/src/utils/decoration.ts +482 -502
  229. package/src/utils/dom.ts +127 -134
  230. package/src/utils/drag-menu.ts +322 -373
  231. package/src/utils/get-allow-add-column-custom-step.ts +4 -5
  232. package/src/utils/guidelines.ts +10 -21
  233. package/src/utils/index.ts +68 -68
  234. package/src/utils/merged-cells.ts +245 -254
  235. package/src/utils/nodes.ts +91 -106
  236. package/src/utils/paste.ts +119 -135
  237. package/src/utils/row-controls.ts +199 -213
  238. package/src/utils/selection.ts +77 -87
  239. package/src/utils/snapping.ts +84 -97
  240. package/src/utils/table.ts +44 -44
  241. package/src/utils/transforms.ts +5 -5
  242. package/src/utils/update-plugin-state-decorations.ts +5 -9
@@ -9,233 +9,216 @@ import { nonNullable } from '@atlaskit/editor-common/utils';
9
9
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
10
10
  // @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
11
11
  import type {
12
- ReadonlyTransaction,
13
- Selection,
14
- Transaction,
12
+ ReadonlyTransaction,
13
+ Selection,
14
+ Transaction,
15
15
  } from '@atlaskit/editor-prosemirror/state';
16
16
  import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
17
17
  import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
18
18
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
19
19
  import { TableMap } from '@atlaskit/editor-tables/table-map';
20
- import {
21
- findTable,
22
- getCellsInRow,
23
- getSelectionRect,
24
- } from '@atlaskit/editor-tables/utils';
20
+ import { findTable, getCellsInRow, getSelectionRect } from '@atlaskit/editor-tables/utils';
25
21
 
26
22
  import type { Cell, CellColumnPositioning } from '../types';
27
23
  import { TableCssClassName as ClassName, TableDecorations } from '../types';
28
24
  import { ColumnResizeWidget } from '../ui/ColumnResizeWidget';
29
25
 
30
- const filterDecorationByKey = (
31
- key: TableDecorations,
32
- decorationSet: DecorationSet,
33
- ): Decoration[] =>
34
- decorationSet.find(
35
- undefined,
36
- undefined,
37
- (spec) => spec.key.indexOf(key) > -1,
38
- );
39
-
40
- export const findColumnControlSelectedDecoration = (
41
- decorationSet: DecorationSet,
42
- ): Decoration[] =>
43
- filterDecorationByKey(TableDecorations.COLUMN_SELECTED, decorationSet);
44
-
45
- export const findControlsHoverDecoration = (
46
- decorationSet: DecorationSet,
47
- ): Decoration[] =>
48
- filterDecorationByKey(TableDecorations.ALL_CONTROLS_HOVER, decorationSet);
26
+ const filterDecorationByKey = (key: TableDecorations, decorationSet: DecorationSet): Decoration[] =>
27
+ decorationSet.find(undefined, undefined, (spec) => spec.key.indexOf(key) > -1);
28
+
29
+ export const findColumnControlSelectedDecoration = (decorationSet: DecorationSet): Decoration[] =>
30
+ filterDecorationByKey(TableDecorations.COLUMN_SELECTED, decorationSet);
31
+
32
+ export const findControlsHoverDecoration = (decorationSet: DecorationSet): Decoration[] =>
33
+ filterDecorationByKey(TableDecorations.ALL_CONTROLS_HOVER, decorationSet);
49
34
 
50
35
  export const createCellHoverDecoration = (cells: Cell[]): Decoration[] =>
51
- cells.map((cell) =>
52
- Decoration.node(
53
- cell.pos,
54
- cell.pos + cell.node.nodeSize,
55
- {
56
- class: ClassName.HOVERED_CELL_WARNING,
57
- },
58
- {
59
- key: TableDecorations.CELL_CONTROLS_HOVER,
60
- },
61
- ),
62
- );
36
+ cells.map((cell) =>
37
+ Decoration.node(
38
+ cell.pos,
39
+ cell.pos + cell.node.nodeSize,
40
+ {
41
+ class: ClassName.HOVERED_CELL_WARNING,
42
+ },
43
+ {
44
+ key: TableDecorations.CELL_CONTROLS_HOVER,
45
+ },
46
+ ),
47
+ );
63
48
 
64
49
  export const createControlsHoverDecoration = (
65
- cells: Cell[],
66
- type: 'row' | 'column' | 'table',
67
- tr: Transaction | ReadonlyTransaction,
68
- isDragAndDropEnable: boolean | undefined,
69
- hoveredIndexes: number[],
70
- danger?: boolean,
71
- selected?: boolean,
50
+ cells: Cell[],
51
+ type: 'row' | 'column' | 'table',
52
+ tr: Transaction | ReadonlyTransaction,
53
+ isDragAndDropEnable: boolean | undefined,
54
+ hoveredIndexes: number[],
55
+ danger?: boolean,
56
+ selected?: boolean,
72
57
  ): Decoration[] => {
73
- const table = findTable(tr.selection);
74
- if (!table) {
75
- return [];
76
- }
77
-
78
- const map = TableMap.get(table.node);
79
- const [min, max] = cells.reduce<[number | null, number | null]>(
80
- ([min, max], cell) => {
81
- if (min === null || cell.pos < min) {
82
- min = cell.pos;
83
- }
84
- if (max === null || cell.pos > max) {
85
- max = cell.pos;
86
- }
87
-
88
- return [min, max];
89
- },
90
- [null, null],
91
- );
92
-
93
- if (min === null || max === null) {
94
- return [];
95
- }
96
-
97
- let updatedCells: number[] = cells.map((x) => x.pos);
98
-
99
- // ED-15246 fixed trello card table overflow issue
100
- // If columns / rows have been merged the hovered selection is different to the actual selection
101
- // So If the table cells are in danger we want to create a "rectangle" selection
102
- // to match the "clicked" selection
103
-
104
- if (danger && type !== 'table') {
105
- const { selection } = tr;
106
- const table = findTable(selection);
107
- const rect = getSelectionRect(selection);
108
-
109
- if (table && rect) {
110
- updatedCells = map.cellsInRect(rect).map((x) => x + table.start);
111
- }
112
- }
113
-
114
- return updatedCells.map((pos) => {
115
- const cell = tr.doc.nodeAt(pos);
116
-
117
- const classes = [ClassName.HOVERED_CELL];
118
- if (danger) {
119
- classes.push(ClassName.HOVERED_CELL_IN_DANGER);
120
- }
121
- if (selected) {
122
- classes.push(ClassName.SELECTED_CELL);
123
- }
124
-
125
- if (isDragAndDropEnable) {
126
- if (type === 'column' || type === 'row') {
127
- classes.pop();
128
- classes.push(ClassName.HOVERED_NO_HIGHLIGHT);
129
- }
130
- } else {
131
- classes.push(
132
- type === 'column'
133
- ? ClassName.HOVERED_COLUMN
134
- : type === 'row'
135
- ? ClassName.HOVERED_ROW
136
- : ClassName.HOVERED_TABLE,
137
- );
138
- }
139
-
140
- let key: TableDecorations;
141
- switch (type) {
142
- case 'row':
143
- key = TableDecorations.ROW_CONTROLS_HOVER;
144
- break;
145
-
146
- case 'column':
147
- key = TableDecorations.COLUMN_CONTROLS_HOVER;
148
- break;
149
-
150
- default:
151
- key = TableDecorations.TABLE_CONTROLS_HOVER;
152
- break;
153
- }
154
-
155
- return Decoration.node(
156
- pos,
157
- pos + cell!.nodeSize,
158
- {
159
- class: classes.join(' '),
160
- },
161
- { key },
162
- );
163
- });
58
+ const table = findTable(tr.selection);
59
+ if (!table) {
60
+ return [];
61
+ }
62
+
63
+ const map = TableMap.get(table.node);
64
+ const [min, max] = cells.reduce<[number | null, number | null]>(
65
+ ([min, max], cell) => {
66
+ if (min === null || cell.pos < min) {
67
+ min = cell.pos;
68
+ }
69
+ if (max === null || cell.pos > max) {
70
+ max = cell.pos;
71
+ }
72
+
73
+ return [min, max];
74
+ },
75
+ [null, null],
76
+ );
77
+
78
+ if (min === null || max === null) {
79
+ return [];
80
+ }
81
+
82
+ let updatedCells: number[] = cells.map((x) => x.pos);
83
+
84
+ // ED-15246 fixed trello card table overflow issue
85
+ // If columns / rows have been merged the hovered selection is different to the actual selection
86
+ // So If the table cells are in danger we want to create a "rectangle" selection
87
+ // to match the "clicked" selection
88
+
89
+ if (danger && type !== 'table') {
90
+ const { selection } = tr;
91
+ const table = findTable(selection);
92
+ const rect = getSelectionRect(selection);
93
+
94
+ if (table && rect) {
95
+ updatedCells = map.cellsInRect(rect).map((x) => x + table.start);
96
+ }
97
+ }
98
+
99
+ return updatedCells.map((pos) => {
100
+ const cell = tr.doc.nodeAt(pos);
101
+
102
+ const classes = [ClassName.HOVERED_CELL];
103
+ if (danger) {
104
+ classes.push(ClassName.HOVERED_CELL_IN_DANGER);
105
+ }
106
+ if (selected) {
107
+ classes.push(ClassName.SELECTED_CELL);
108
+ }
109
+
110
+ if (isDragAndDropEnable) {
111
+ if (type === 'column' || type === 'row') {
112
+ classes.pop();
113
+ classes.push(ClassName.HOVERED_NO_HIGHLIGHT);
114
+ }
115
+ } else {
116
+ classes.push(
117
+ type === 'column'
118
+ ? ClassName.HOVERED_COLUMN
119
+ : type === 'row'
120
+ ? ClassName.HOVERED_ROW
121
+ : ClassName.HOVERED_TABLE,
122
+ );
123
+ }
124
+
125
+ let key: TableDecorations;
126
+ switch (type) {
127
+ case 'row':
128
+ key = TableDecorations.ROW_CONTROLS_HOVER;
129
+ break;
130
+
131
+ case 'column':
132
+ key = TableDecorations.COLUMN_CONTROLS_HOVER;
133
+ break;
134
+
135
+ default:
136
+ key = TableDecorations.TABLE_CONTROLS_HOVER;
137
+ break;
138
+ }
139
+
140
+ return Decoration.node(
141
+ pos,
142
+ pos + cell!.nodeSize,
143
+ {
144
+ class: classes.join(' '),
145
+ },
146
+ { key },
147
+ );
148
+ });
164
149
  };
165
150
 
166
151
  export const createColumnSelectedDecoration = (
167
- tr: Transaction | ReadonlyTransaction,
152
+ tr: Transaction | ReadonlyTransaction,
168
153
  ): Decoration[] => {
169
- const { selection, doc } = tr;
170
- const table = findTable(selection);
171
- const rect = getSelectionRect(selection);
172
-
173
- if (!table || !rect) {
174
- return [];
175
- }
176
-
177
- const map = TableMap.get(table.node);
178
- const cellPositions = map.cellsInRect(rect);
179
-
180
- return cellPositions.map((pos, index) => {
181
- const cell = doc.nodeAt(pos + table.start);
182
-
183
- return Decoration.node(
184
- pos + table.start,
185
- pos + table.start + cell!.nodeSize,
186
- {
187
- class: ClassName.COLUMN_SELECTED,
188
- },
189
- {
190
- key: `${TableDecorations.COLUMN_SELECTED}_${index}`,
191
- },
192
- );
193
- });
154
+ const { selection, doc } = tr;
155
+ const table = findTable(selection);
156
+ const rect = getSelectionRect(selection);
157
+
158
+ if (!table || !rect) {
159
+ return [];
160
+ }
161
+
162
+ const map = TableMap.get(table.node);
163
+ const cellPositions = map.cellsInRect(rect);
164
+
165
+ return cellPositions.map((pos, index) => {
166
+ const cell = doc.nodeAt(pos + table.start);
167
+
168
+ return Decoration.node(
169
+ pos + table.start,
170
+ pos + table.start + cell!.nodeSize,
171
+ {
172
+ class: ClassName.COLUMN_SELECTED,
173
+ },
174
+ {
175
+ key: `${TableDecorations.COLUMN_SELECTED}_${index}`,
176
+ },
177
+ );
178
+ });
194
179
  };
195
180
 
196
- export const createColumnControlsDecoration = (
197
- selection: Selection,
198
- ): Decoration[] => {
199
- const cells: ContentNodeWithPos[] = getCellsInRow(0)(selection) || [];
200
-
201
- let index = 0;
202
- return cells.map((cell) => {
203
- const colspan = (cell.node.attrs as CellAttributes).colspan || 1;
204
- // It's important these values are scoped locally as the widget callback could be executed anytime in the future
205
- // and we want to avoid value leak
206
- const startIndex = index;
207
- const endIndex = startIndex + colspan;
208
-
209
- // The next cell start index will commence from the current cell end index.
210
- index = endIndex;
211
-
212
- return Decoration.widget(
213
- cell.pos + 1,
214
- () => {
215
- const element = document.createElement('div');
216
- element.classList.add(ClassName.COLUMN_CONTROLS_DECORATIONS);
217
- element.dataset.startIndex = `${startIndex}`;
218
- element.dataset.endIndex = `${endIndex}`;
219
- return element;
220
- },
221
- {
222
- key: `${TableDecorations.COLUMN_CONTROLS_DECORATIONS}_${endIndex}`,
223
- // this decoration should be the first one, even before gap cursor.
224
- side: -100,
225
- },
226
- );
227
- });
181
+ export const createColumnControlsDecoration = (selection: Selection): Decoration[] => {
182
+ const cells: ContentNodeWithPos[] = getCellsInRow(0)(selection) || [];
183
+
184
+ let index = 0;
185
+ return cells.map((cell) => {
186
+ const colspan = (cell.node.attrs as CellAttributes).colspan || 1;
187
+ // It's important these values are scoped locally as the widget callback could be executed anytime in the future
188
+ // and we want to avoid value leak
189
+ const startIndex = index;
190
+ const endIndex = startIndex + colspan;
191
+
192
+ // The next cell start index will commence from the current cell end index.
193
+ index = endIndex;
194
+
195
+ return Decoration.widget(
196
+ cell.pos + 1,
197
+ () => {
198
+ const element = document.createElement('div');
199
+ element.classList.add(ClassName.COLUMN_CONTROLS_DECORATIONS);
200
+ element.dataset.startIndex = `${startIndex}`;
201
+ element.dataset.endIndex = `${endIndex}`;
202
+ return element;
203
+ },
204
+ {
205
+ key: `${TableDecorations.COLUMN_CONTROLS_DECORATIONS}_${endIndex}`,
206
+ // this decoration should be the first one, even before gap cursor.
207
+ side: -100,
208
+ },
209
+ );
210
+ });
228
211
  };
229
212
 
230
213
  export const updateDecorations = (
231
- node: PmNode,
232
- decorationSet: DecorationSet,
233
- decorations: Decoration[],
234
- key: TableDecorations,
214
+ node: PmNode,
215
+ decorationSet: DecorationSet,
216
+ decorations: Decoration[],
217
+ key: TableDecorations,
235
218
  ): DecorationSet => {
236
- const filteredDecorations = filterDecorationByKey(key, decorationSet);
237
- const decorationSetFiltered = decorationSet.remove(filteredDecorations);
238
- return decorationSetFiltered.add(node, decorations);
219
+ const filteredDecorations = filterDecorationByKey(key, decorationSet);
220
+ const decorationSetFiltered = decorationSet.remove(filteredDecorations);
221
+ return decorationSetFiltered.add(node, decorations);
239
222
  };
240
223
 
241
224
  const makeArray = (n: number) => Array.from(Array(n).keys());
@@ -320,144 +303,141 @@ const makeArray = (n: number) => Array.from(Array(n).keys());
320
303
  * hence the second media will receive this class `ClassName.LAST_ITEM_IN_CELL`
321
304
  */
322
305
  export const createResizeHandleDecoration = (
323
- tr: Transaction | ReadonlyTransaction,
324
- rowIndexTarget: number,
325
- columnEndIndexTarget: Omit<CellColumnPositioning, 'left'>,
326
- includeTooltip: boolean = false,
327
- getIntl: () => IntlShape,
306
+ tr: Transaction | ReadonlyTransaction,
307
+ rowIndexTarget: number,
308
+ columnEndIndexTarget: Omit<CellColumnPositioning, 'left'>,
309
+ includeTooltip: boolean = false,
310
+ getIntl: () => IntlShape,
328
311
  ): [Decoration[], Decoration[]] => {
329
- const emptyResult: [Decoration[], Decoration[]] = [[], []];
330
- const table = findTable(tr.selection);
331
- if (!table || !table.node) {
332
- return emptyResult;
333
- }
334
-
335
- const map = TableMap.get(table.node);
336
- if (!map.width) {
337
- return emptyResult;
338
- }
339
-
340
- const createResizerHandleDecoration = (
341
- cellColumnPositioning: CellColumnPositioning,
342
- columnIndex: number,
343
- rowIndex: number,
344
- cellPos: number,
345
- cellNode: PmNode,
346
- ): Decoration => {
347
- const position = cellPos + cellNode.nodeSize - 1;
348
- return Decoration.widget(
349
- position,
350
- () => {
351
- const element = document.createElement('div');
352
- ReactDOM.render(
353
- createElement(
354
- RawIntlProvider,
355
- { value: getIntl() },
356
- createElement(ColumnResizeWidget, {
357
- startIndex: cellColumnPositioning.left,
358
- endIndex: cellColumnPositioning.right,
359
- includeTooltip,
360
- }),
361
- ),
362
- element,
363
- );
364
- return element;
365
- },
366
- {
367
- key: `${
368
- TableDecorations.COLUMN_RESIZING_HANDLE_WIDGET
369
- }_${rowIndex}_${columnIndex}_${includeTooltip ? 'with' : 'no'}-tooltip`,
370
- destroy: (node) => {
371
- ReactDOM.unmountComponentAtNode(node as HTMLDivElement);
372
- },
373
- },
374
- );
375
- };
376
-
377
- const createLastCellElementDecoration = (
378
- cellColumnPositioning: CellColumnPositioning,
379
- cellPos: number,
380
- cellNode: PmNode,
381
- ): Decoration | null => {
382
- let lastItemPositions: { from: number; to: number } | undefined;
383
- cellNode.forEach((childNode, offset, index) => {
384
- if (index === cellNode.childCount - 1) {
385
- const from = offset + cellPos + 1;
386
- lastItemPositions = {
387
- from,
388
- to: from + childNode.nodeSize,
389
- };
390
- }
391
- });
392
-
393
- if (!lastItemPositions) {
394
- return null;
395
- }
396
-
397
- return Decoration.node(
398
- lastItemPositions.from,
399
- lastItemPositions.to,
400
- {
401
- class: ClassName.LAST_ITEM_IN_CELL,
402
- },
403
- {
404
- key: `${TableDecorations.LAST_CELL_ELEMENT}_${cellColumnPositioning.left}_${cellColumnPositioning.right}`,
405
- },
406
- );
407
- };
408
-
409
- const resizeHandleCellDecorations: Decoration[] = [];
410
- const lastCellElementsDecorations: Array<Decoration | null> = [];
411
-
412
- for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
413
- const seen: { [key: number]: boolean } = {};
414
-
415
- if (rowIndex !== rowIndexTarget) {
416
- continue;
417
- }
418
-
419
- for (let columnIndex = 0; columnIndex < map.width; columnIndex++) {
420
- const cellPosition = map.map[map.width * rowIndex + columnIndex];
421
- if (seen[cellPosition]) {
422
- continue;
423
- }
424
-
425
- seen[cellPosition] = true;
426
- const cellPos = table.start + cellPosition;
427
- const cell = tr.doc.nodeAt(cellPos);
428
- if (!cell) {
429
- continue;
430
- }
431
- const colspan = (cell.attrs as CellAttributes).colspan || 1;
432
- const startIndex = columnIndex;
433
- const endIndex = colspan + startIndex;
434
-
435
- if (endIndex !== columnEndIndexTarget.right) {
436
- continue;
437
- }
438
-
439
- const resizerHandleDec = createResizerHandleDecoration(
440
- { left: startIndex, right: endIndex },
441
- columnIndex,
442
- rowIndex,
443
- cellPos,
444
- cell,
445
- );
446
- const lastCellDec = createLastCellElementDecoration(
447
- { left: startIndex, right: endIndex },
448
- cellPos,
449
- cell,
450
- );
451
-
452
- resizeHandleCellDecorations.push(resizerHandleDec);
453
- lastCellElementsDecorations.push(lastCellDec);
454
- }
455
- }
456
-
457
- return [
458
- resizeHandleCellDecorations,
459
- lastCellElementsDecorations.filter(nonNullable),
460
- ];
312
+ const emptyResult: [Decoration[], Decoration[]] = [[], []];
313
+ const table = findTable(tr.selection);
314
+ if (!table || !table.node) {
315
+ return emptyResult;
316
+ }
317
+
318
+ const map = TableMap.get(table.node);
319
+ if (!map.width) {
320
+ return emptyResult;
321
+ }
322
+
323
+ const createResizerHandleDecoration = (
324
+ cellColumnPositioning: CellColumnPositioning,
325
+ columnIndex: number,
326
+ rowIndex: number,
327
+ cellPos: number,
328
+ cellNode: PmNode,
329
+ ): Decoration => {
330
+ const position = cellPos + cellNode.nodeSize - 1;
331
+ return Decoration.widget(
332
+ position,
333
+ () => {
334
+ const element = document.createElement('div');
335
+ ReactDOM.render(
336
+ createElement(
337
+ RawIntlProvider,
338
+ { value: getIntl() },
339
+ createElement(ColumnResizeWidget, {
340
+ startIndex: cellColumnPositioning.left,
341
+ endIndex: cellColumnPositioning.right,
342
+ includeTooltip,
343
+ }),
344
+ ),
345
+ element,
346
+ );
347
+ return element;
348
+ },
349
+ {
350
+ key: `${
351
+ TableDecorations.COLUMN_RESIZING_HANDLE_WIDGET
352
+ }_${rowIndex}_${columnIndex}_${includeTooltip ? 'with' : 'no'}-tooltip`,
353
+ destroy: (node) => {
354
+ ReactDOM.unmountComponentAtNode(node as HTMLDivElement);
355
+ },
356
+ },
357
+ );
358
+ };
359
+
360
+ const createLastCellElementDecoration = (
361
+ cellColumnPositioning: CellColumnPositioning,
362
+ cellPos: number,
363
+ cellNode: PmNode,
364
+ ): Decoration | null => {
365
+ let lastItemPositions: { from: number; to: number } | undefined;
366
+ cellNode.forEach((childNode, offset, index) => {
367
+ if (index === cellNode.childCount - 1) {
368
+ const from = offset + cellPos + 1;
369
+ lastItemPositions = {
370
+ from,
371
+ to: from + childNode.nodeSize,
372
+ };
373
+ }
374
+ });
375
+
376
+ if (!lastItemPositions) {
377
+ return null;
378
+ }
379
+
380
+ return Decoration.node(
381
+ lastItemPositions.from,
382
+ lastItemPositions.to,
383
+ {
384
+ class: ClassName.LAST_ITEM_IN_CELL,
385
+ },
386
+ {
387
+ key: `${TableDecorations.LAST_CELL_ELEMENT}_${cellColumnPositioning.left}_${cellColumnPositioning.right}`,
388
+ },
389
+ );
390
+ };
391
+
392
+ const resizeHandleCellDecorations: Decoration[] = [];
393
+ const lastCellElementsDecorations: Array<Decoration | null> = [];
394
+
395
+ for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
396
+ const seen: { [key: number]: boolean } = {};
397
+
398
+ if (rowIndex !== rowIndexTarget) {
399
+ continue;
400
+ }
401
+
402
+ for (let columnIndex = 0; columnIndex < map.width; columnIndex++) {
403
+ const cellPosition = map.map[map.width * rowIndex + columnIndex];
404
+ if (seen[cellPosition]) {
405
+ continue;
406
+ }
407
+
408
+ seen[cellPosition] = true;
409
+ const cellPos = table.start + cellPosition;
410
+ const cell = tr.doc.nodeAt(cellPos);
411
+ if (!cell) {
412
+ continue;
413
+ }
414
+ const colspan = (cell.attrs as CellAttributes).colspan || 1;
415
+ const startIndex = columnIndex;
416
+ const endIndex = colspan + startIndex;
417
+
418
+ if (endIndex !== columnEndIndexTarget.right) {
419
+ continue;
420
+ }
421
+
422
+ const resizerHandleDec = createResizerHandleDecoration(
423
+ { left: startIndex, right: endIndex },
424
+ columnIndex,
425
+ rowIndex,
426
+ cellPos,
427
+ cell,
428
+ );
429
+ const lastCellDec = createLastCellElementDecoration(
430
+ { left: startIndex, right: endIndex },
431
+ cellPos,
432
+ cell,
433
+ );
434
+
435
+ resizeHandleCellDecorations.push(resizerHandleDec);
436
+ lastCellElementsDecorations.push(lastCellDec);
437
+ }
438
+ }
439
+
440
+ return [resizeHandleCellDecorations, lastCellElementsDecorations.filter(nonNullable)];
461
441
  };
462
442
 
463
443
  /*
@@ -503,176 +483,176 @@ export const createResizeHandleDecoration = (
503
483
  * only on the cells: `C1` and `D1`.
504
484
  */
505
485
  export const createColumnLineResize = (
506
- selection: Selection,
507
- cellColumnPositioning: Omit<CellColumnPositioning, 'left'>,
486
+ selection: Selection,
487
+ cellColumnPositioning: Omit<CellColumnPositioning, 'left'>,
508
488
  ): Decoration[] => {
509
- const table = findTable(selection);
510
- if (!table || cellColumnPositioning.right === null) {
511
- return [];
512
- }
513
-
514
- let columnIndex = cellColumnPositioning.right;
515
- const map = TableMap.get(table.node);
516
-
517
- const isLastColumn = columnIndex === map.width;
518
- if (isLastColumn) {
519
- columnIndex -= 1;
520
- }
521
- const decorationClassName = isLastColumn
522
- ? ClassName.WITH_RESIZE_LINE_LAST_COLUMN
523
- : ClassName.WITH_RESIZE_LINE;
524
-
525
- const cellPositions = makeArray(map.height)
526
- .map((rowIndex) => map.map[map.width * rowIndex + columnIndex])
527
- .filter((cellPosition, rowIndex) => {
528
- if (isLastColumn) {
529
- return true; // If is the last column no filter applied
530
- }
531
- const nextPosition = map.map[map.width * rowIndex + columnIndex - 1];
532
- return cellPosition !== nextPosition; // Removed it if next position is merged
533
- });
534
-
535
- const cells = cellPositions.map((pos) => ({
536
- pos: pos + table.start,
537
- node: table.node.nodeAt(pos),
538
- }));
539
-
540
- return cells
541
- .map((cell, index) => {
542
- if (!cell || !cell.node) {
543
- return;
544
- }
545
-
546
- return Decoration.node(
547
- cell.pos,
548
- cell.pos + cell.node.nodeSize,
549
- {
550
- class: decorationClassName,
551
- },
552
- {
553
- key: `${TableDecorations.COLUMN_RESIZING_HANDLE_LINE}_${cellColumnPositioning.right}_${index}`,
554
- },
555
- );
556
- })
557
- .filter(nonNullable);
489
+ const table = findTable(selection);
490
+ if (!table || cellColumnPositioning.right === null) {
491
+ return [];
492
+ }
493
+
494
+ let columnIndex = cellColumnPositioning.right;
495
+ const map = TableMap.get(table.node);
496
+
497
+ const isLastColumn = columnIndex === map.width;
498
+ if (isLastColumn) {
499
+ columnIndex -= 1;
500
+ }
501
+ const decorationClassName = isLastColumn
502
+ ? ClassName.WITH_RESIZE_LINE_LAST_COLUMN
503
+ : ClassName.WITH_RESIZE_LINE;
504
+
505
+ const cellPositions = makeArray(map.height)
506
+ .map((rowIndex) => map.map[map.width * rowIndex + columnIndex])
507
+ .filter((cellPosition, rowIndex) => {
508
+ if (isLastColumn) {
509
+ return true; // If is the last column no filter applied
510
+ }
511
+ const nextPosition = map.map[map.width * rowIndex + columnIndex - 1];
512
+ return cellPosition !== nextPosition; // Removed it if next position is merged
513
+ });
514
+
515
+ const cells = cellPositions.map((pos) => ({
516
+ pos: pos + table.start,
517
+ node: table.node.nodeAt(pos),
518
+ }));
519
+
520
+ return cells
521
+ .map((cell, index) => {
522
+ if (!cell || !cell.node) {
523
+ return;
524
+ }
525
+
526
+ return Decoration.node(
527
+ cell.pos,
528
+ cell.pos + cell.node.nodeSize,
529
+ {
530
+ class: decorationClassName,
531
+ },
532
+ {
533
+ key: `${TableDecorations.COLUMN_RESIZING_HANDLE_LINE}_${cellColumnPositioning.right}_${index}`,
534
+ },
535
+ );
536
+ })
537
+ .filter(nonNullable);
558
538
  };
559
539
 
560
540
  export const createColumnInsertLine = (
561
- columnIndex: number,
562
- selection: Selection,
563
- hasMergedCells: boolean,
541
+ columnIndex: number,
542
+ selection: Selection,
543
+ hasMergedCells: boolean,
564
544
  ): Decoration[] => {
565
- const table = findTable(selection);
566
- if (!table) {
567
- return [];
568
- }
569
-
570
- const map = TableMap.get(table.node);
571
-
572
- const isFirstColumn = columnIndex === 0;
573
- const isLastColumn = columnIndex === map.width;
574
- if (isLastColumn) {
575
- columnIndex -= 1;
576
- }
577
-
578
- let decorationClassName: string;
579
- if (hasMergedCells) {
580
- decorationClassName = isFirstColumn
581
- ? ClassName.WITH_FIRST_COLUMN_INSERT_LINE_INACTIVE
582
- : isLastColumn
583
- ? ClassName.WITH_LAST_COLUMN_INSERT_LINE_INACTIVE
584
- : ClassName.WITH_COLUMN_INSERT_LINE_INACTIVE;
585
- } else {
586
- decorationClassName = isFirstColumn
587
- ? ClassName.WITH_FIRST_COLUMN_INSERT_LINE
588
- : isLastColumn
589
- ? ClassName.WITH_LAST_COLUMN_INSERT_LINE
590
- : ClassName.WITH_COLUMN_INSERT_LINE;
591
- }
592
-
593
- const cellPositions = makeArray(map.height)
594
- .map((rowIndex) => map.map[map.width * rowIndex + columnIndex])
595
- .filter((cellPosition, rowIndex) => {
596
- if (isLastColumn) {
597
- return true; // If is the last column no filter applied
598
- }
599
- const nextPosition = map.map[map.width * rowIndex + columnIndex - 1];
600
- return cellPosition !== nextPosition; // Removed it if next position is merged
601
- });
602
-
603
- const cells = cellPositions.map((pos) => ({
604
- pos: pos + table.start,
605
- node: table.node.nodeAt(pos),
606
- }));
607
-
608
- return cells
609
- .map((cell, index) => {
610
- if (!cell || !cell.node) {
611
- return;
612
- }
613
-
614
- return Decoration.node(
615
- cell.pos,
616
- cell.pos + cell.node.nodeSize,
617
- {
618
- class: decorationClassName,
619
- },
620
- {
621
- key: `${TableDecorations.COLUMN_INSERT_LINE}_${index}`,
622
- },
623
- );
624
- })
625
- .filter(nonNullable);
545
+ const table = findTable(selection);
546
+ if (!table) {
547
+ return [];
548
+ }
549
+
550
+ const map = TableMap.get(table.node);
551
+
552
+ const isFirstColumn = columnIndex === 0;
553
+ const isLastColumn = columnIndex === map.width;
554
+ if (isLastColumn) {
555
+ columnIndex -= 1;
556
+ }
557
+
558
+ let decorationClassName: string;
559
+ if (hasMergedCells) {
560
+ decorationClassName = isFirstColumn
561
+ ? ClassName.WITH_FIRST_COLUMN_INSERT_LINE_INACTIVE
562
+ : isLastColumn
563
+ ? ClassName.WITH_LAST_COLUMN_INSERT_LINE_INACTIVE
564
+ : ClassName.WITH_COLUMN_INSERT_LINE_INACTIVE;
565
+ } else {
566
+ decorationClassName = isFirstColumn
567
+ ? ClassName.WITH_FIRST_COLUMN_INSERT_LINE
568
+ : isLastColumn
569
+ ? ClassName.WITH_LAST_COLUMN_INSERT_LINE
570
+ : ClassName.WITH_COLUMN_INSERT_LINE;
571
+ }
572
+
573
+ const cellPositions = makeArray(map.height)
574
+ .map((rowIndex) => map.map[map.width * rowIndex + columnIndex])
575
+ .filter((cellPosition, rowIndex) => {
576
+ if (isLastColumn) {
577
+ return true; // If is the last column no filter applied
578
+ }
579
+ const nextPosition = map.map[map.width * rowIndex + columnIndex - 1];
580
+ return cellPosition !== nextPosition; // Removed it if next position is merged
581
+ });
582
+
583
+ const cells = cellPositions.map((pos) => ({
584
+ pos: pos + table.start,
585
+ node: table.node.nodeAt(pos),
586
+ }));
587
+
588
+ return cells
589
+ .map((cell, index) => {
590
+ if (!cell || !cell.node) {
591
+ return;
592
+ }
593
+
594
+ return Decoration.node(
595
+ cell.pos,
596
+ cell.pos + cell.node.nodeSize,
597
+ {
598
+ class: decorationClassName,
599
+ },
600
+ {
601
+ key: `${TableDecorations.COLUMN_INSERT_LINE}_${index}`,
602
+ },
603
+ );
604
+ })
605
+ .filter(nonNullable);
626
606
  };
627
607
 
628
608
  export const createRowInsertLine = (
629
- rowIndex: number,
630
- selection: Selection,
631
- hasMergedCells: boolean,
609
+ rowIndex: number,
610
+ selection: Selection,
611
+ hasMergedCells: boolean,
632
612
  ): Decoration[] => {
633
- const table = findTable(selection);
634
- if (!table) {
635
- return [];
636
- }
637
-
638
- const map = TableMap.get(table.node);
639
- const isLastRow = rowIndex === map.height;
640
- if (isLastRow) {
641
- rowIndex -= 1;
642
- }
643
-
644
- const cells = getCellsInRow(rowIndex)(selection);
645
- if (!cells) {
646
- return [];
647
- }
648
-
649
- let decorationClassName: string;
650
- if (hasMergedCells) {
651
- decorationClassName = isLastRow
652
- ? ClassName.WITH_LAST_ROW_INSERT_LINE_INACTIVE
653
- : ClassName.WITH_ROW_INSERT_LINE_INACTIVE;
654
- } else {
655
- decorationClassName = isLastRow
656
- ? ClassName.WITH_LAST_ROW_INSERT_LINE
657
- : ClassName.WITH_ROW_INSERT_LINE;
658
- }
659
-
660
- return cells
661
- .map((cell, index) => {
662
- if (!cell || !cell.node) {
663
- return;
664
- }
665
-
666
- return Decoration.node(
667
- cell.pos,
668
- cell.pos + cell.node.nodeSize,
669
- {
670
- class: decorationClassName,
671
- },
672
- {
673
- key: `${TableDecorations.ROW_INSERT_LINE}_${index}`,
674
- },
675
- );
676
- })
677
- .filter(nonNullable);
613
+ const table = findTable(selection);
614
+ if (!table) {
615
+ return [];
616
+ }
617
+
618
+ const map = TableMap.get(table.node);
619
+ const isLastRow = rowIndex === map.height;
620
+ if (isLastRow) {
621
+ rowIndex -= 1;
622
+ }
623
+
624
+ const cells = getCellsInRow(rowIndex)(selection);
625
+ if (!cells) {
626
+ return [];
627
+ }
628
+
629
+ let decorationClassName: string;
630
+ if (hasMergedCells) {
631
+ decorationClassName = isLastRow
632
+ ? ClassName.WITH_LAST_ROW_INSERT_LINE_INACTIVE
633
+ : ClassName.WITH_ROW_INSERT_LINE_INACTIVE;
634
+ } else {
635
+ decorationClassName = isLastRow
636
+ ? ClassName.WITH_LAST_ROW_INSERT_LINE
637
+ : ClassName.WITH_ROW_INSERT_LINE;
638
+ }
639
+
640
+ return cells
641
+ .map((cell, index) => {
642
+ if (!cell || !cell.node) {
643
+ return;
644
+ }
645
+
646
+ return Decoration.node(
647
+ cell.pos,
648
+ cell.pos + cell.node.nodeSize,
649
+ {
650
+ class: decorationClassName,
651
+ },
652
+ {
653
+ key: `${TableDecorations.ROW_INSERT_LINE}_${index}`,
654
+ },
655
+ );
656
+ })
657
+ .filter(nonNullable);
678
658
  };