@atlaskit/editor-plugin-table 12.2.5 → 12.2.7

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 (207) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/ui/TableFloatingControls/NumberColumn/index.js +24 -2
  3. package/dist/es2019/ui/TableFloatingControls/NumberColumn/index.js +23 -1
  4. package/dist/esm/ui/TableFloatingControls/NumberColumn/index.js +24 -2
  5. package/package.json +4 -4
  6. package/afm-cc/tsconfig.json +0 -123
  7. package/afm-dev-agents/tsconfig.json +0 -123
  8. package/afm-jira/tsconfig.json +0 -123
  9. package/afm-passionfruit/tsconfig.json +0 -123
  10. package/afm-post-office/tsconfig.json +0 -123
  11. package/afm-rovo-extension/tsconfig.json +0 -123
  12. package/afm-townsquare/tsconfig.json +0 -123
  13. package/afm-volt/tsconfig.json +0 -114
  14. package/build/tsconfig.json +0 -23
  15. package/docs/0-intro.tsx +0 -57
  16. package/src/index.ts +0 -21
  17. package/src/nodeviews/ExternalDropTargets.tsx +0 -91
  18. package/src/nodeviews/OverflowShadowsObserver.ts +0 -156
  19. package/src/nodeviews/TableCell.ts +0 -134
  20. package/src/nodeviews/TableComponent.tsx +0 -1590
  21. package/src/nodeviews/TableComponentWithSharedState.tsx +0 -278
  22. package/src/nodeviews/TableContainer.tsx +0 -926
  23. package/src/nodeviews/TableNodeViewBase.ts +0 -29
  24. package/src/nodeviews/TableResizer.tsx +0 -884
  25. package/src/nodeviews/TableRow.ts +0 -830
  26. package/src/nodeviews/TableStickyScrollbar.ts +0 -211
  27. package/src/nodeviews/__mocks__/OverflowShadowsObserver.ts +0 -15
  28. package/src/nodeviews/__mocks__/OverridableMock.ts +0 -26
  29. package/src/nodeviews/table-container-styles.ts +0 -9
  30. package/src/nodeviews/table-node-views.ts +0 -76
  31. package/src/nodeviews/table.tsx +0 -530
  32. package/src/nodeviews/toDOM.ts +0 -244
  33. package/src/nodeviews/types.ts +0 -36
  34. package/src/nodeviews/update-overflow-shadows.ts +0 -11
  35. package/src/pm-plugins/analytics/actions.ts +0 -21
  36. package/src/pm-plugins/analytics/commands.ts +0 -47
  37. package/src/pm-plugins/analytics/plugin-factory.ts +0 -9
  38. package/src/pm-plugins/analytics/plugin-key.ts +0 -5
  39. package/src/pm-plugins/analytics/plugin.ts +0 -80
  40. package/src/pm-plugins/analytics/reducer.ts +0 -27
  41. package/src/pm-plugins/analytics/types.ts +0 -20
  42. package/src/pm-plugins/analytics/utils/moved-event.ts +0 -51
  43. package/src/pm-plugins/commands/clear.ts +0 -43
  44. package/src/pm-plugins/commands/collapse.ts +0 -17
  45. package/src/pm-plugins/commands/column-resize.ts +0 -478
  46. package/src/pm-plugins/commands/commands-with-analytics.ts +0 -715
  47. package/src/pm-plugins/commands/delete.ts +0 -42
  48. package/src/pm-plugins/commands/display-mode.ts +0 -18
  49. package/src/pm-plugins/commands/go-to-next-cell.ts +0 -198
  50. package/src/pm-plugins/commands/hover.ts +0 -242
  51. package/src/pm-plugins/commands/index.ts +0 -51
  52. package/src/pm-plugins/commands/insert.ts +0 -438
  53. package/src/pm-plugins/commands/misc.ts +0 -811
  54. package/src/pm-plugins/commands/referentiality.ts +0 -15
  55. package/src/pm-plugins/commands/selection.ts +0 -537
  56. package/src/pm-plugins/commands/sort.ts +0 -102
  57. package/src/pm-plugins/commands/split-cell.ts +0 -28
  58. package/src/pm-plugins/commands/toggle.ts +0 -109
  59. package/src/pm-plugins/create-plugin-config.ts +0 -17
  60. package/src/pm-plugins/decorations/plugin.ts +0 -107
  61. package/src/pm-plugins/decorations/utils/column-controls.ts +0 -91
  62. package/src/pm-plugins/decorations/utils/column-resizing.ts +0 -71
  63. package/src/pm-plugins/decorations/utils/compose-decorations.ts +0 -9
  64. package/src/pm-plugins/decorations/utils/types.ts +0 -16
  65. package/src/pm-plugins/default-table-selection.ts +0 -14
  66. package/src/pm-plugins/drag-and-drop/actions.ts +0 -48
  67. package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +0 -222
  68. package/src/pm-plugins/drag-and-drop/commands.ts +0 -194
  69. package/src/pm-plugins/drag-and-drop/consts.ts +0 -7
  70. package/src/pm-plugins/drag-and-drop/plugin-factory.ts +0 -33
  71. package/src/pm-plugins/drag-and-drop/plugin-key.ts +0 -5
  72. package/src/pm-plugins/drag-and-drop/plugin.ts +0 -398
  73. package/src/pm-plugins/drag-and-drop/reducer.ts +0 -38
  74. package/src/pm-plugins/drag-and-drop/types.ts +0 -18
  75. package/src/pm-plugins/drag-and-drop/utils/autoscrollers.ts +0 -49
  76. package/src/pm-plugins/drag-and-drop/utils/getDragBehaviour.ts +0 -9
  77. package/src/pm-plugins/drag-and-drop/utils/monitor.ts +0 -73
  78. package/src/pm-plugins/handlers.ts +0 -161
  79. package/src/pm-plugins/keymap.ts +0 -436
  80. package/src/pm-plugins/main.ts +0 -433
  81. package/src/pm-plugins/plugin-factory.ts +0 -42
  82. package/src/pm-plugins/plugin-key.ts +0 -8
  83. package/src/pm-plugins/reducer.ts +0 -145
  84. package/src/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -102
  85. package/src/pm-plugins/sticky-headers/commands.ts +0 -8
  86. package/src/pm-plugins/sticky-headers/plugin-key.ts +0 -5
  87. package/src/pm-plugins/sticky-headers/plugin-state.ts +0 -52
  88. package/src/pm-plugins/sticky-headers/plugin.ts +0 -12
  89. package/src/pm-plugins/sticky-headers/types.ts +0 -20
  90. package/src/pm-plugins/sticky-headers/util.ts +0 -18
  91. package/src/pm-plugins/table-analytics.ts +0 -100
  92. package/src/pm-plugins/table-local-id.ts +0 -213
  93. package/src/pm-plugins/table-resizing/commands.ts +0 -116
  94. package/src/pm-plugins/table-resizing/event-handlers.ts +0 -352
  95. package/src/pm-plugins/table-resizing/plugin-factory.ts +0 -29
  96. package/src/pm-plugins/table-resizing/plugin-key.ts +0 -5
  97. package/src/pm-plugins/table-resizing/plugin.ts +0 -94
  98. package/src/pm-plugins/table-resizing/reducer.ts +0 -37
  99. package/src/pm-plugins/table-resizing/utils/colgroup.ts +0 -306
  100. package/src/pm-plugins/table-resizing/utils/column-state.ts +0 -120
  101. package/src/pm-plugins/table-resizing/utils/consts.ts +0 -11
  102. package/src/pm-plugins/table-resizing/utils/content-width.ts +0 -118
  103. package/src/pm-plugins/table-resizing/utils/dom.ts +0 -132
  104. package/src/pm-plugins/table-resizing/utils/misc.ts +0 -282
  105. package/src/pm-plugins/table-resizing/utils/resize-column.ts +0 -34
  106. package/src/pm-plugins/table-resizing/utils/resize-logic.ts +0 -289
  107. package/src/pm-plugins/table-resizing/utils/resize-state.ts +0 -417
  108. package/src/pm-plugins/table-resizing/utils/scale-table.ts +0 -290
  109. package/src/pm-plugins/table-resizing/utils/types.ts +0 -25
  110. package/src/pm-plugins/table-resizing/utils/unit-to-number.ts +0 -1
  111. package/src/pm-plugins/table-selection-keymap.ts +0 -64
  112. package/src/pm-plugins/table-size-selector.ts +0 -39
  113. package/src/pm-plugins/table-width-in-comment-fix.ts +0 -113
  114. package/src/pm-plugins/table-width.ts +0 -153
  115. package/src/pm-plugins/transforms/column-width.ts +0 -249
  116. package/src/pm-plugins/transforms/delete-columns.ts +0 -281
  117. package/src/pm-plugins/transforms/delete-rows.ts +0 -154
  118. package/src/pm-plugins/transforms/fix-tables.ts +0 -249
  119. package/src/pm-plugins/transforms/merge.ts +0 -301
  120. package/src/pm-plugins/transforms/replace-table.ts +0 -38
  121. package/src/pm-plugins/transforms/split.ts +0 -90
  122. package/src/pm-plugins/utils/alignment.ts +0 -33
  123. package/src/pm-plugins/utils/analytics.ts +0 -238
  124. package/src/pm-plugins/utils/collapse.ts +0 -93
  125. package/src/pm-plugins/utils/column-controls.ts +0 -250
  126. package/src/pm-plugins/utils/create.ts +0 -64
  127. package/src/pm-plugins/utils/decoration.ts +0 -672
  128. package/src/pm-plugins/utils/dom.ts +0 -251
  129. package/src/pm-plugins/utils/drag-menu.tsx +0 -491
  130. package/src/pm-plugins/utils/get-allow-add-column-custom-step.ts +0 -10
  131. package/src/pm-plugins/utils/guidelines.ts +0 -30
  132. package/src/pm-plugins/utils/merged-cells.ts +0 -239
  133. package/src/pm-plugins/utils/nodes.ts +0 -162
  134. package/src/pm-plugins/utils/paste.ts +0 -386
  135. package/src/pm-plugins/utils/row-controls.ts +0 -211
  136. package/src/pm-plugins/utils/selection.ts +0 -17
  137. package/src/pm-plugins/utils/snapping.ts +0 -136
  138. package/src/pm-plugins/utils/table.ts +0 -60
  139. package/src/pm-plugins/utils/update-plugin-state-decorations.ts +0 -13
  140. package/src/pm-plugins/view-mode-sort/consts.ts +0 -3
  141. package/src/pm-plugins/view-mode-sort/index.ts +0 -291
  142. package/src/pm-plugins/view-mode-sort/plugin-key.ts +0 -7
  143. package/src/pm-plugins/view-mode-sort/types.ts +0 -23
  144. package/src/pm-plugins/view-mode-sort/utils.ts +0 -136
  145. package/src/tablePlugin.tsx +0 -971
  146. package/src/tablePluginType.ts +0 -102
  147. package/src/types/index.ts +0 -592
  148. package/src/ui/ColumnResizeWidget/index.tsx +0 -61
  149. package/src/ui/ContentComponent.tsx +0 -311
  150. package/src/ui/DragHandle/HandleIconComponent.tsx +0 -21
  151. package/src/ui/DragHandle/index.tsx +0 -391
  152. package/src/ui/DragPreview/index.tsx +0 -51
  153. package/src/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.tsx +0 -59
  154. package/src/ui/FloatingContextualButton/FixedButton.tsx +0 -203
  155. package/src/ui/FloatingContextualButton/index.tsx +0 -168
  156. package/src/ui/FloatingContextualButton/styles.ts +0 -69
  157. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +0 -931
  158. package/src/ui/FloatingContextualMenu/index.tsx +0 -141
  159. package/src/ui/FloatingContextualMenu/styles.ts +0 -77
  160. package/src/ui/FloatingDeleteButton/DeleteButton.tsx +0 -54
  161. package/src/ui/FloatingDeleteButton/getPopUpOptions.ts +0 -65
  162. package/src/ui/FloatingDeleteButton/index.tsx +0 -383
  163. package/src/ui/FloatingDeleteButton/types.ts +0 -3
  164. package/src/ui/FloatingDragMenu/DragMenu.tsx +0 -668
  165. package/src/ui/FloatingDragMenu/DropdownMenu.tsx +0 -221
  166. package/src/ui/FloatingDragMenu/index.tsx +0 -136
  167. package/src/ui/FloatingDragMenu/styles.ts +0 -83
  168. package/src/ui/FloatingInsertButton/InsertButton.tsx +0 -263
  169. package/src/ui/FloatingInsertButton/getPopupOptions.ts +0 -131
  170. package/src/ui/FloatingInsertButton/index.tsx +0 -314
  171. package/src/ui/FloatingToolbarLabel/FloatingToolbarLabel.tsx +0 -31
  172. package/src/ui/SizeSelector/index.tsx +0 -74
  173. package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +0 -397
  174. package/src/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +0 -105
  175. package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +0 -63
  176. package/src/ui/TableFloatingColumnControls/index.tsx +0 -151
  177. package/src/ui/TableFloatingControls/CornerControls/ClassicCornerControls.tsx +0 -106
  178. package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +0 -143
  179. package/src/ui/TableFloatingControls/CornerControls/types.ts +0 -12
  180. package/src/ui/TableFloatingControls/FloatingControlsWithSelection.tsx +0 -88
  181. package/src/ui/TableFloatingControls/NumberColumn/index.tsx +0 -150
  182. package/src/ui/TableFloatingControls/RowControls/ClassicControls.tsx +0 -131
  183. package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +0 -429
  184. package/src/ui/TableFloatingControls/RowDropTarget/index.tsx +0 -96
  185. package/src/ui/TableFloatingControls/index.tsx +0 -275
  186. package/src/ui/TableFullWidthLabel/index.tsx +0 -38
  187. package/src/ui/common-styles.ts +0 -1218
  188. package/src/ui/consts.ts +0 -109
  189. package/src/ui/event-handlers.ts +0 -662
  190. package/src/ui/global-styles.tsx +0 -55
  191. package/src/ui/hooks/useInternalTablePluginStateSelector.ts +0 -38
  192. package/src/ui/icons/AddColLeftIcon.tsx +0 -37
  193. package/src/ui/icons/AddColRightIcon.tsx +0 -37
  194. package/src/ui/icons/AddRowAboveIcon.tsx +0 -22
  195. package/src/ui/icons/AddRowBelowIcon.tsx +0 -39
  196. package/src/ui/icons/DragHandleDisabledIcon.tsx +0 -25
  197. package/src/ui/icons/DragHandleIcon.tsx +0 -16
  198. package/src/ui/icons/DragInMotionIcon.tsx +0 -54
  199. package/src/ui/icons/MergeCellsIcon.tsx +0 -26
  200. package/src/ui/icons/MinimisedHandle.tsx +0 -15
  201. package/src/ui/icons/SortingIconWrapper.tsx +0 -43
  202. package/src/ui/icons/SplitCellIcon.tsx +0 -34
  203. package/src/ui/toolbar.tsx +0 -1153
  204. package/src/ui/ui-styles.ts +0 -960
  205. package/tsconfig.app.json +0 -135
  206. package/tsconfig.dev.json +0 -54
  207. package/tsconfig.json +0 -18
@@ -1,281 +0,0 @@
1
- import type { CellAttributes } from '@atlaskit/adf-schema';
2
- import { AddColumnStep } from '@atlaskit/custom-steps';
3
- import { TABLE_OVERFLOW_CHANGE_TRIGGER } from '@atlaskit/editor-common/analytics';
4
- import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
5
- import type { Transaction } from '@atlaskit/editor-prosemirror/state';
6
- import { Selection } from '@atlaskit/editor-prosemirror/state';
7
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
8
- import type { Rect } from '@atlaskit/editor-tables/table-map';
9
- import { TableMap } from '@atlaskit/editor-tables/table-map';
10
- import { findTable } from '@atlaskit/editor-tables/utils';
11
-
12
- import type { PluginInjectionAPI } from '../../types';
13
- import { META_KEYS } from '../table-analytics';
14
-
15
- import { rescaleColumns } from './column-width';
16
- import { splitCellsInColumns } from './split';
17
-
18
- const deleteColumnsCustomStep =
19
- (rect: Rect) =>
20
- (tr: Transaction): Transaction => {
21
- const table = findTable(tr.selection);
22
- if (!table) {
23
- return tr;
24
- }
25
-
26
- // Need to split all the merge in the ranges (this is the current behaviour)
27
- // Maybe is better to split only the last column?
28
- // TODO: ED-26961 - After talking with Roto about this behaviour, he likes when we dont split the columns, I am keeping this for consistency of the current implementation.
29
- splitCellsInColumns(tr, table.pos, rect.left, rect.right);
30
-
31
- // Delete the columns
32
- const mapStart = tr.mapping.maps.length;
33
- const originalDoc = tr.doc;
34
- const deletedColumns: number[] = [];
35
- for (let i = rect.left; i < rect.right; i++) {
36
- const step = AddColumnStep.create(originalDoc, table.pos, i, true);
37
- deletedColumns.push(i);
38
- // Ignored via go/ees005
39
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
40
- tr.step(step.map(tr.mapping.slice(mapStart))!);
41
- }
42
-
43
- const tablePosResult = tr.mapping.mapResult(table.pos);
44
- if (tablePosResult.deleted) {
45
- const pos = Math.min(tablePosResult.pos, tr.doc.nodeSize - 1);
46
- tr.setSelection(Selection.near(tr.doc.resolve(pos)));
47
- } else {
48
- const newTable = tr.doc.nodeAt(tablePosResult.pos);
49
- if (newTable) {
50
- const cursorPos = getNextCursorPos(newTable, deletedColumns);
51
- tr.setSelection(Selection.near(tr.doc.resolve(table.pos + cursorPos)));
52
- }
53
- }
54
-
55
- return tr;
56
- };
57
-
58
- const deleteColumnsLegacy =
59
- (rect: Rect) =>
60
- (tr: Transaction): Transaction => {
61
- const table = findTable(tr.selection);
62
- if (!table) {
63
- return tr;
64
- }
65
-
66
- const columnsToDelete: number[] = [];
67
- for (let i = rect.left; i < rect.right; i++) {
68
- columnsToDelete.push(i);
69
- }
70
-
71
- if (!columnsToDelete.length) {
72
- return tr;
73
- }
74
-
75
- const map = TableMap.get(table.node);
76
- const rows: PMNode[] = [];
77
- const seen: { [key: string]: boolean } = {};
78
- const deletedCells: { [key: string]: boolean } = {};
79
-
80
- for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
81
- const rowCells: PMNode[] = [];
82
- const row = table.node.child(rowIndex);
83
-
84
- for (let colIndex = 0; colIndex < map.width; colIndex++) {
85
- const cellPos = map.map[rowIndex * map.width + colIndex];
86
- const cell = table.node.nodeAt(cellPos);
87
- if (!cell) {
88
- continue;
89
- }
90
- const cellsInColumn = map.cellsInRect({
91
- left: colIndex,
92
- top: 0,
93
- right: colIndex + 1,
94
- bottom: map.height,
95
- });
96
- if (columnsToDelete.indexOf(colIndex) === -1) {
97
- // decrement colspans for col-spanning cells that overlap deleted columns
98
- if (cellsInColumn.indexOf(cellPos) > -1 && !seen[cellPos]) {
99
- let overlappingCols = 0;
100
- columnsToDelete.forEach((colIndexToDelete) => {
101
- if (
102
- colIndex < colIndexToDelete &&
103
- cell.attrs.colspan + colIndex - 1 >= colIndexToDelete
104
- ) {
105
- overlappingCols += 1;
106
- }
107
- });
108
- if (overlappingCols > 0) {
109
- const attrs: CellAttributes = {
110
- ...cell.attrs,
111
- colspan: cell.attrs.colspan - overlappingCols,
112
- };
113
- if (cell.attrs.colwidth) {
114
- const minColIndex = Math.min(...columnsToDelete);
115
- const pos = minColIndex > 0 ? minColIndex - map.colCount(cellPos) : 0;
116
- const colwidth = cell.attrs.colwidth.slice() || [];
117
- colwidth.splice(pos, overlappingCols);
118
- attrs.colwidth = colwidth;
119
- }
120
- const newCell = cell.type.createChecked(attrs, cell.content, cell.marks);
121
- rowCells.push(newCell);
122
- seen[cellPos] = true;
123
- continue;
124
- }
125
- } else if (deletedCells[cellPos]) {
126
- // if we're removing a col-spanning cell, we need to add missing cells to columns to the right
127
- const attrs: CellAttributes = {
128
- ...cell.attrs,
129
- colspan: 1,
130
- rowspan: 1,
131
- };
132
- if (cell.attrs.colwidth) {
133
- const pos = colIndex > 0 ? colIndex - map.colCount(cellPos) : 0;
134
- attrs.colwidth = cell.attrs.colwidth.slice().splice(pos, 1);
135
- }
136
- const newCell = cell.type.createChecked(
137
- attrs,
138
- cell.type.schema.nodes.paragraph.createChecked(),
139
- cell.marks,
140
- );
141
- rowCells.push(newCell);
142
- continue;
143
- }
144
-
145
- // normal cells that we want to keep
146
- if (!seen[cellPos]) {
147
- seen[cellPos] = true;
148
- rowCells.push(cell);
149
- }
150
- } else if (cellsInColumn.indexOf(cellPos) > -1) {
151
- deletedCells[cellPos] = true;
152
- }
153
- }
154
-
155
- if (rowCells.length) {
156
- rows.push(row.type.createChecked(row.attrs, rowCells, row.marks));
157
- }
158
- }
159
-
160
- if (!rows.length) {
161
- return tr;
162
- }
163
-
164
- const newTable = table.node.type.createChecked(table.node.attrs, rows, table.node.marks);
165
-
166
- const fixedTable = fixRowSpans(newTable);
167
- if (fixedTable === null) {
168
- return tr;
169
- }
170
-
171
- const cursorPos = getNextCursorPos(newTable, columnsToDelete);
172
-
173
- return (
174
- tr
175
- .replaceWith(table.pos, table.pos + table.node.nodeSize, fixedTable)
176
- // move cursor to the left of the deleted columns if possible, otherwise - to the first column
177
- .setSelection(Selection.near(tr.doc.resolve(table.pos + cursorPos)))
178
- );
179
- };
180
-
181
- function getNextCursorPos(table: PMNode, deletedColumns: number[]): number {
182
- const minColumn = Math.min(...deletedColumns);
183
- const nextColumnWithCursor = minColumn > 0 ? minColumn - 1 : 0;
184
- const map = TableMap.get(table);
185
- return map.map[nextColumnWithCursor];
186
- }
187
-
188
- // returns an array of numbers, each number indicates the minimum rowSpan in each row
189
- function getMinRowSpans(table: PMNode): number[] {
190
- const minRowSpans: number[] = [];
191
- for (let rowIndex = 0; rowIndex < table.childCount; rowIndex++) {
192
- const rowSpans: number[] = [];
193
- const row = table.child(rowIndex);
194
- for (let colIndex = 0; colIndex < row.childCount; colIndex++) {
195
- const cell = row.child(colIndex);
196
- rowSpans.push(cell.attrs.rowspan);
197
- }
198
- minRowSpans[rowIndex] = Math.min(...rowSpans);
199
- }
200
-
201
- return minRowSpans;
202
- }
203
-
204
- function fixRowSpans(table: PMNode): PMNode | null {
205
- const map = TableMap.get(table);
206
- const minRowSpans = getMinRowSpans(table);
207
- if (!minRowSpans.some((rowspan) => rowspan > 1)) {
208
- return table;
209
- }
210
-
211
- const rows: PMNode[] = [];
212
- for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
213
- const row = table.child(rowIndex);
214
- if (minRowSpans[rowIndex] === 1) {
215
- rows.push(row);
216
- } else {
217
- const rowCells: PMNode[] = [];
218
- for (let colIndex = 0; colIndex < row.childCount; colIndex++) {
219
- const cell = row.child(colIndex);
220
- const rowspan = cell.attrs.rowspan - minRowSpans[rowIndex] + 1;
221
- if (rowspan < 1) {
222
- return null;
223
- }
224
- const newCell = cell.type.createChecked(
225
- {
226
- ...cell.attrs,
227
- rowspan,
228
- },
229
- cell.content,
230
- cell.marks,
231
- );
232
- rowCells.push(newCell);
233
- }
234
- rows.push(row.type.createChecked(row.attrs, rowCells, row.marks));
235
- }
236
- }
237
-
238
- if (!rows.length) {
239
- return null;
240
- }
241
-
242
- return table.type.createChecked(table.attrs, rows, table.marks);
243
- }
244
-
245
- export const deleteColumns =
246
- (
247
- rect: Rect,
248
- allowCustomStep: boolean,
249
- api: PluginInjectionAPI | undefined | null,
250
- view?: EditorView,
251
- isTableScalingEnabled = false,
252
- isTableFixedColumnWidthsOptionEnabled = false,
253
- shouldUseIncreasedScalingPercent = false,
254
- isCommentEditor = false,
255
- ) =>
256
- (tr: Transaction) => {
257
- let updatedTr = tr;
258
- updatedTr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
259
- name: TABLE_OVERFLOW_CHANGE_TRIGGER.DELETED_COLUMN,
260
- });
261
-
262
- if (allowCustomStep) {
263
- updatedTr = deleteColumnsCustomStep(rect)(updatedTr);
264
- } else {
265
- updatedTr = deleteColumnsLegacy(rect)(updatedTr);
266
- }
267
- const table = findTable(updatedTr.selection);
268
- if (table) {
269
- updatedTr = rescaleColumns(
270
- isTableScalingEnabled,
271
- isTableFixedColumnWidthsOptionEnabled,
272
- shouldUseIncreasedScalingPercent,
273
- api,
274
- isCommentEditor,
275
- )(
276
- table,
277
- view,
278
- )(updatedTr);
279
- }
280
- return updatedTr;
281
- };
@@ -1,154 +0,0 @@
1
- import type { CellAttributes } from '@atlaskit/adf-schema';
2
- import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
- import type { Transaction } from '@atlaskit/editor-prosemirror/state';
4
- import { Selection } from '@atlaskit/editor-prosemirror/state';
5
- import type { Rect } from '@atlaskit/editor-tables/table-map';
6
- import { TableMap } from '@atlaskit/editor-tables/table-map';
7
- import { findTable } from '@atlaskit/editor-tables/utils';
8
-
9
- import { pluginKey } from '../plugin-key';
10
-
11
- import { mergeEmptyColumns } from './merge';
12
-
13
- export const deleteRows =
14
- (rect: Rect, isHeaderRowRequired: boolean = false) =>
15
- (tr: Transaction): Transaction => {
16
- const table = findTable(tr.selection);
17
- if (!table) {
18
- return tr;
19
- }
20
-
21
- const rowsToDelete: number[] = [];
22
-
23
- const map = TableMap.get(table.node);
24
-
25
- for (let i = rect.top; i < rect.bottom; i++) {
26
- // skip header row if its required
27
- if (isHeaderRowRequired) {
28
- const cell = table.node.nodeAt(map.map[i * map.width]);
29
- if (cell && cell.type !== cell.type.schema.nodes.tableHeader) {
30
- rowsToDelete.push(i);
31
- }
32
- } else {
33
- rowsToDelete.push(i);
34
- }
35
- }
36
-
37
- if (!rowsToDelete.length) {
38
- return tr;
39
- }
40
-
41
- const rows: PMNode[] = [];
42
- const seen: { [key: string]: boolean } = {};
43
- const deletedCells: { [key: string]: boolean } = {};
44
-
45
- for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
46
- const rowCells: PMNode[] = [];
47
- const row = table.node.child(rowIndex);
48
-
49
- for (let colIndex = 0; colIndex < map.width; colIndex++) {
50
- const cellPos = map.map[rowIndex * map.width + colIndex];
51
- const cell = table.node.nodeAt(cellPos);
52
- if (!cell) {
53
- continue;
54
- }
55
- const cellsInRow = map.cellsInRect({
56
- left: 0,
57
- top: rowIndex,
58
- right: map.width,
59
- bottom: rowIndex + 1,
60
- });
61
- if (rowsToDelete.indexOf(rowIndex) === -1 && !seen[cellPos]) {
62
- // decrement rowspans for row-spanning cells that overlap deleted rows
63
- if (cellsInRow.indexOf(cellPos) > -1) {
64
- let overlappingRows = 0;
65
- rowsToDelete.forEach((rowIndexToDelete) => {
66
- if (
67
- rowIndex < rowIndexToDelete &&
68
- cell.attrs.rowspan + rowIndex - 1 >= rowIndexToDelete
69
- ) {
70
- overlappingRows += 1;
71
- }
72
- });
73
- if (overlappingRows > 0) {
74
- const newCell = cell.type.createChecked(
75
- {
76
- ...cell.attrs,
77
- rowspan: cell.attrs.rowspan - overlappingRows,
78
- },
79
- cell.content,
80
- cell.marks,
81
- );
82
- rowCells.push(newCell);
83
- seen[cellPos] = true;
84
- continue;
85
- }
86
- } else if (deletedCells[cellPos]) {
87
- // if we're removing a row-spanning cell, we need to add missing cells to rows below
88
- const attrs: CellAttributes = {
89
- ...cell.attrs,
90
- colspan: 1,
91
- rowspan: 1,
92
- };
93
- if (cell.attrs.colwidth) {
94
- const pos = colIndex > 0 ? colIndex - map.colCount(cellPos) : 0;
95
- attrs.colwidth = cell.attrs.colwidth.slice().splice(pos, 1);
96
- }
97
- const newCell = cell.type.createChecked(
98
- attrs,
99
- cell.type.schema.nodes.paragraph.createChecked(),
100
- cell.marks,
101
- );
102
- rowCells.push(newCell);
103
- continue;
104
- }
105
-
106
- // normal cells that we want to keep
107
- if (!seen[cellPos]) {
108
- seen[cellPos] = true;
109
- rowCells.push(cell);
110
- }
111
- } else if (cellsInRow.indexOf(cellPos) > -1) {
112
- deletedCells[cellPos] = true;
113
- }
114
- }
115
-
116
- if (rowCells.length) {
117
- rows.push(row.type.createChecked(row.attrs, rowCells, row.marks));
118
- }
119
- }
120
-
121
- if (!rows.length) {
122
- return tr;
123
- }
124
-
125
- const newTable = table.node.type.createChecked(table.node.attrs, rows, table.node.marks);
126
- const fixedTable = mergeEmptyColumns(newTable);
127
- if (fixedTable === null) {
128
- return tr;
129
- }
130
- const cursorPos = getNextCursorPos(newTable, rowsToDelete);
131
-
132
- // If we delete a row we should also clean up the hover selection
133
- tr.setMeta(pluginKey, {
134
- type: 'CLEAR_HOVER_SELECTION',
135
- data: {
136
- isInDanger: false,
137
- isWholeTableInDanger: false,
138
- },
139
- });
140
-
141
- return (
142
- tr
143
- .replaceWith(table.pos, table.pos + table.node.nodeSize, fixedTable)
144
- // move cursor before the deleted rows if possible, otherwise - to the first row
145
- .setSelection(Selection.near(tr.doc.resolve(table.pos + cursorPos)))
146
- );
147
- };
148
-
149
- function getNextCursorPos(table: PMNode, deletedRows: number[]): number {
150
- const minRow = Math.min(...deletedRows);
151
- const nextRowWithCursor = minRow > 0 ? minRow - 1 : 0;
152
- const map = TableMap.get(table);
153
- return map.map[nextRowWithCursor * map.width];
154
- }
@@ -1,249 +0,0 @@
1
- import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
2
- import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
- import type { Transaction } from '@atlaskit/editor-prosemirror/state';
4
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
- import {
6
- akEditorDefaultLayoutWidth,
7
- akEditorWideLayoutWidth,
8
- } from '@atlaskit/editor-shared-styles';
9
-
10
- import type { ReportInvalidNodeAttrs } from '../../types';
11
- import { calculateColumnWidth, getCellsRefsInColumn } from '../table-resizing/utils/column-state';
12
- import { contentWidth } from '../table-resizing/utils/content-width';
13
- import { getLayoutSize } from '../table-resizing/utils/misc';
14
-
15
- const validateTableCellNodeAttrs = (
16
- { colspan, rowspan, tableLocalId }: { colspan?: number; rowspan?: number; tableLocalId: string },
17
- reportInvalidTableCellSpanAttrs: ReportInvalidNodeAttrs,
18
- ): void => {
19
- if (colspan && colspan < 0) {
20
- reportInvalidTableCellSpanAttrs({
21
- nodeType: 'tableCell',
22
- attribute: 'colspan',
23
- reason: 'negative value',
24
- tableLocalId,
25
- spanValue: colspan,
26
- });
27
- }
28
-
29
- if (rowspan && rowspan < 0) {
30
- reportInvalidTableCellSpanAttrs({
31
- nodeType: 'tableCell',
32
- attribute: 'rowspan',
33
- reason: 'negative value',
34
- tableLocalId,
35
- spanValue: rowspan,
36
- });
37
- }
38
- return;
39
- };
40
-
41
- // We attempt to patch the document when we have extra, unneeded, column widths
42
- // Take this node for example:
43
- //
44
- // ['td', { colwidth: [100, 100, 100], colspan: 2 }]
45
- //
46
- // This row only spans two columns, yet it contains widths for 3.
47
- // We remove the third width here, assumed duplicate content.
48
- export const removeExtraneousColumnWidths = (
49
- node: PMNode,
50
- basePos: number,
51
- tr: Transaction,
52
- reportInvalidTableCellSpanAttrs?: ReportInvalidNodeAttrs,
53
- ): boolean => {
54
- let hasProblems = false;
55
-
56
- tr = replaceCells(tr, node, basePos, (cell) => {
57
- const { colwidth, colspan, rowspan } = cell.attrs;
58
-
59
- if (reportInvalidTableCellSpanAttrs) {
60
- validateTableCellNodeAttrs(
61
- { colspan, rowspan, tableLocalId: node.attrs.localId },
62
- reportInvalidTableCellSpanAttrs,
63
- );
64
- }
65
-
66
- if (colwidth && colwidth.length > colspan) {
67
- hasProblems = true;
68
- return cell.type.createChecked(
69
- {
70
- ...cell.attrs,
71
- colwidth: colwidth.slice(0, colspan),
72
- },
73
- cell.content,
74
- cell.marks,
75
- );
76
- }
77
-
78
- return cell;
79
- });
80
-
81
- if (hasProblems) {
82
- return true;
83
- }
84
-
85
- return false;
86
- };
87
-
88
- export const fixTables = (
89
- tr: Transaction,
90
- reportInvalidTableCellSpanAttrs?: ReportInvalidNodeAttrs,
91
- ): Transaction | undefined => {
92
- let hasProblems = false;
93
- tr.doc.descendants((node, pos) => {
94
- if (node.type.name === 'table') {
95
- // in the unlikely event of having to fix multiple tables at the same time
96
- hasProblems = removeExtraneousColumnWidths(
97
- node,
98
- tr.mapping.map(pos),
99
- tr,
100
- reportInvalidTableCellSpanAttrs,
101
- );
102
- }
103
- });
104
-
105
- if (hasProblems) {
106
- return tr;
107
- }
108
- };
109
-
110
- // When we get a table with an 'auto' attribute, we want to:
111
- // 1. render with table-layout: auto
112
- // 2. capture the column widths
113
- // 3. set the column widths as attributes, and remove the 'auto' attribute,
114
- // so the table renders the same, but is now fixed-width
115
- //
116
- // This can be used to migrate table appearances from other sources that are
117
- // usually rendered with 'auto'.
118
- //
119
- // We use this when migrating TinyMCE tables for Confluence, for example:
120
- // https://pug.jira-dev.com/wiki/spaces/AEC/pages/3362882215/How+do+we+map+TinyMCE+tables+to+Fabric+tables
121
- export const fixAutoSizedTable = (
122
- view: EditorView,
123
- tableNode: PMNode,
124
- tableRef: HTMLTableElement,
125
- tablePos: number,
126
- opts: { containerWidth: number },
127
- ): Transaction => {
128
- let { tr } = view.state;
129
- const domAtPos = view.domAtPos.bind(view);
130
- const tableStart = tablePos + 1;
131
- const colWidths = parseDOMColumnWidths(domAtPos, tableNode, tableStart, tableRef);
132
- const totalContentWidth = colWidths.reduce((acc, current) => acc + current, 0);
133
- const tableLayout = getLayoutBasedOnWidth(totalContentWidth);
134
- const maxLayoutSize = getLayoutSize(tableLayout, opts.containerWidth, {});
135
-
136
- // Content width will generally not meet the constraints of the layout
137
- // whether it be below or above, so we scale our columns widths
138
- // to meet these requirements
139
- let scale = 1;
140
- if (totalContentWidth !== maxLayoutSize) {
141
- scale = maxLayoutSize / totalContentWidth;
142
- }
143
-
144
- const scaledColumnWidths = colWidths.map((width) => Math.floor(width * scale));
145
-
146
- tr = replaceCells(tr, tableNode, tablePos, (cell, _rowIndex, colIndex) => {
147
- const newColWidths = scaledColumnWidths.slice(colIndex, colIndex + cell.attrs.colspan);
148
- return cell.type.createChecked(
149
- {
150
- ...cell.attrs,
151
- colwidth: newColWidths.length ? newColWidths : null,
152
- },
153
- cell.content,
154
- cell.marks,
155
- );
156
- });
157
-
158
- // clear autosizing on the table node
159
- return tr
160
- .setNodeMarkup(tablePos, undefined, {
161
- ...tableNode.attrs,
162
- layout: tableLayout,
163
- __autoSize: false,
164
- })
165
- .setMeta('addToHistory', false);
166
- };
167
-
168
- const getLayoutBasedOnWidth = (totalWidth: number) => {
169
- if (totalWidth > akEditorWideLayoutWidth) {
170
- return 'full-width';
171
- } else if (totalWidth > akEditorDefaultLayoutWidth && totalWidth < akEditorWideLayoutWidth) {
172
- return 'wide';
173
- } else {
174
- return 'default';
175
- }
176
- };
177
-
178
- function parseDOMColumnWidths(
179
- domAtPos: (pos: number) => { node: Node; offset: number },
180
- tableNode: PMNode,
181
- tableStart: number,
182
- tableRef: HTMLTableElement,
183
- ): Array<number> {
184
- const row = tableRef.querySelector('tr');
185
-
186
- if (!row) {
187
- return [];
188
- }
189
-
190
- const cols: Array<number> = [];
191
-
192
- for (let col = 0; col < row.childElementCount; col++) {
193
- const currentCol = row.children[col];
194
- const colspan = Number(currentCol.getAttribute('colspan') || 1);
195
- for (let span = 0; span < colspan; span++) {
196
- const colIdx = col + span;
197
- const cells = getCellsRefsInColumn(colIdx, tableNode, tableStart, domAtPos);
198
- const colWidth = calculateColumnWidth(cells, (_, col) => {
199
- // Ignored via go/ees005
200
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
201
- return contentWidth(col as HTMLElement, tableRef).width;
202
- });
203
-
204
- cols[colIdx] = Math.max(colWidth, tableCellMinWidth);
205
- }
206
- }
207
-
208
- return cols;
209
- }
210
-
211
- // TODO: ED-26961 - move to prosemirror-utils
212
- const replaceCells = (
213
- tr: Transaction,
214
- table: PMNode,
215
- tablePos: number,
216
- modifyCell: (cell: PMNode, rowIndex: number, colIndex: number) => PMNode,
217
- ): Transaction => {
218
- const rows: PMNode[] = [];
219
- let modifiedCells = 0;
220
- for (let rowIndex = 0; rowIndex < table.childCount; rowIndex++) {
221
- const row = table.child(rowIndex);
222
- const cells: PMNode[] = [];
223
-
224
- for (let colIndex = 0; colIndex < row.childCount; colIndex++) {
225
- const cell = row.child(colIndex);
226
-
227
- // TODO: ED-26961 - The rowIndex and colIndex are not accurate in a merged cell scenario
228
- // e.g. table with 5 columns might have only one cell in a row, colIndex will be 1, where it should be 4
229
- const node = modifyCell(cell, rowIndex, colIndex);
230
- if (node.sameMarkup(cell) === false) {
231
- modifiedCells++;
232
- }
233
- cells.push(node);
234
- }
235
-
236
- if (cells.length) {
237
- rows.push(row.type.createChecked(row.attrs, cells, row.marks));
238
- }
239
- }
240
-
241
- // Check if the table has changed before replacing.
242
- // If no cells are modified our counter will be zero.
243
- if (rows.length && modifiedCells !== 0) {
244
- const newTable = table.type.createChecked(table.attrs, rows, table.marks);
245
- return tr.replaceWith(tablePos, tablePos + table.nodeSize, newTable);
246
- }
247
-
248
- return tr;
249
- };