@atlaskit/editor-tables 2.8.1 → 2.8.3
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.
- package/CHANGELOG.md +17 -0
- package/afm-cc/tsconfig.json +6 -3
- package/afm-jira/tsconfig.json +23 -19
- package/afm-post-office/tsconfig.json +23 -19
- package/dist/cjs/cell-bookmark.js +3 -2
- package/dist/cjs/cell-selection.js +17 -8
- package/dist/cjs/pm-plugins/input.js +23 -4
- package/dist/cjs/table-map.js +21 -9
- package/dist/cjs/utils/add-column-at.js +2 -2
- package/dist/cjs/utils/add-column.js +4 -2
- package/dist/cjs/utils/add-row-at.js +2 -2
- package/dist/cjs/utils/add-row.js +4 -2
- package/dist/cjs/utils/clone-column.js +7 -0
- package/dist/cjs/utils/clone-row.js +2 -0
- package/dist/cjs/utils/copy-paste.js +29 -1
- package/dist/cjs/utils/find.js +5 -1
- package/dist/cjs/utils/fix-tables.js +8 -1
- package/dist/cjs/utils/get-cells-in-column.js +2 -0
- package/dist/cjs/utils/get-cells-in-row.js +2 -0
- package/dist/cjs/utils/move-column.js +9 -1
- package/dist/cjs/utils/move-row.js +2 -0
- package/dist/cjs/utils/normalize-selection.js +2 -0
- package/dist/cjs/utils/reorder-utils.js +20 -4
- package/dist/cjs/utils/split-cell-with-type.js +3 -3
- package/dist/cjs/utils/uuid.js +8 -4
- package/dist/es2019/cell-bookmark.js +3 -0
- package/dist/es2019/cell-selection.js +14 -1
- package/dist/es2019/index.js +3 -0
- package/dist/es2019/pm-plugins/input.js +23 -4
- package/dist/es2019/pm-plugins.js +3 -0
- package/dist/es2019/table-map.js +53 -41
- package/dist/es2019/utils/add-column-at.js +2 -2
- package/dist/es2019/utils/add-column.js +4 -2
- package/dist/es2019/utils/add-row-at.js +6 -6
- package/dist/es2019/utils/add-row.js +4 -2
- package/dist/es2019/utils/clone-column.js +11 -1
- package/dist/es2019/utils/clone-row.js +7 -2
- package/dist/es2019/utils/copy-paste.js +29 -1
- package/dist/es2019/utils/find.js +4 -1
- package/dist/es2019/utils/fix-tables.js +8 -1
- package/dist/es2019/utils/get-cells-in-column.js +2 -0
- package/dist/es2019/utils/get-cells-in-row.js +2 -0
- package/dist/es2019/utils/get-selection-range-in-column.js +2 -2
- package/dist/es2019/utils/get-selection-range-in-row.js +2 -2
- package/dist/es2019/utils/move-column.js +13 -2
- package/dist/es2019/utils/move-row.js +7 -2
- package/dist/es2019/utils/normalize-selection.js +2 -0
- package/dist/es2019/utils/remove-row.js +3 -3
- package/dist/es2019/utils/remove-table.js +1 -1
- package/dist/es2019/utils/reorder-utils.js +21 -5
- package/dist/es2019/utils/replace-table.js +1 -1
- package/dist/es2019/utils/split-cell-with-type.js +6 -6
- package/dist/es2019/utils/toggle-header.js +6 -6
- package/dist/es2019/utils/uuid.js +4 -1
- package/dist/es2019/utils.js +3 -0
- package/dist/esm/cell-bookmark.js +4 -2
- package/dist/esm/cell-selection.js +18 -7
- package/dist/esm/index.js +3 -0
- package/dist/esm/pm-plugins/input.js +23 -4
- package/dist/esm/pm-plugins.js +3 -0
- package/dist/esm/table-map.js +21 -9
- package/dist/esm/utils/add-column-at.js +2 -2
- package/dist/esm/utils/add-column.js +4 -2
- package/dist/esm/utils/add-row-at.js +2 -2
- package/dist/esm/utils/add-row.js +4 -2
- package/dist/esm/utils/clone-column.js +7 -0
- package/dist/esm/utils/clone-row.js +2 -0
- package/dist/esm/utils/copy-paste.js +29 -1
- package/dist/esm/utils/find.js +5 -1
- package/dist/esm/utils/fix-tables.js +8 -1
- package/dist/esm/utils/get-cells-in-column.js +2 -0
- package/dist/esm/utils/get-cells-in-row.js +2 -0
- package/dist/esm/utils/move-column.js +9 -1
- package/dist/esm/utils/move-row.js +2 -0
- package/dist/esm/utils/normalize-selection.js +2 -0
- package/dist/esm/utils/reorder-utils.js +20 -4
- package/dist/esm/utils/split-cell-with-type.js +3 -3
- package/dist/esm/utils/uuid.js +8 -4
- package/dist/esm/utils.js +3 -0
- package/dist/types/utils/add-column-at.d.ts +1 -1
- package/dist/types/utils/add-column.d.ts +1 -1
- package/dist/types/utils/add-row-at.d.ts +1 -1
- package/dist/types/utils/add-row.d.ts +1 -1
- package/dist/types-ts4.5/utils/add-column-at.d.ts +1 -1
- package/dist/types-ts4.5/utils/add-column.d.ts +1 -1
- package/dist/types-ts4.5/utils/add-row-at.d.ts +1 -1
- package/dist/types-ts4.5/utils/add-row.d.ts +1 -1
- package/package.json +8 -2
- package/tsconfig.json +0 -1
|
@@ -16,7 +16,7 @@ export function addColumn(tr, {
|
|
|
16
16
|
map,
|
|
17
17
|
tableStart,
|
|
18
18
|
table
|
|
19
|
-
}, col
|
|
19
|
+
}, col) {
|
|
20
20
|
let refColumn = col > 0 ? -1 : 0;
|
|
21
21
|
if (columnIsHeader(map, table, col + refColumn)) {
|
|
22
22
|
refColumn = col === 0 || col === map.width ? null : 0;
|
|
@@ -48,13 +48,15 @@ export function addColumn(tr, {
|
|
|
48
48
|
throw new Error(`addColumn: invalid node at mapped pos ${mappedPos}`);
|
|
49
49
|
}
|
|
50
50
|
type = cell.type;
|
|
51
|
-
if (cell.attrs.background
|
|
51
|
+
if (cell.attrs.background) {
|
|
52
52
|
attrs = {
|
|
53
53
|
background: cell.attrs.background
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
const pos = map.positionAt(row, col, table);
|
|
58
|
+
// Ignored via go/ees005
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
58
60
|
tr.insert(tr.mapping.map(tableStart + pos), type.createAndFill(attrs));
|
|
59
61
|
}
|
|
60
62
|
}
|
|
@@ -7,7 +7,7 @@ import { getCellsInRow } from './get-cells-in-row';
|
|
|
7
7
|
import { setCellAttrs } from './set-cell-attrs';
|
|
8
8
|
import { tableNodeTypes } from './table-node-types';
|
|
9
9
|
const filterCellsInRow = (rowIndex, predicate) => tr => {
|
|
10
|
-
|
|
10
|
+
const foundCells = [];
|
|
11
11
|
const cells = getCellsInRow(rowIndex)(tr.selection);
|
|
12
12
|
if (cells) {
|
|
13
13
|
for (let j = cells.length - 1; j >= 0; j--) {
|
|
@@ -33,7 +33,7 @@ export const cloneRowAt = rowIndex => tr => {
|
|
|
33
33
|
}
|
|
34
34
|
const cloneRow = tableNode.child(rowIndex);
|
|
35
35
|
// Re-create the same nodes with same attrs, dropping the node content.
|
|
36
|
-
|
|
36
|
+
const cells = [];
|
|
37
37
|
let rowWidth = 0;
|
|
38
38
|
cloneRow.forEach(cell => {
|
|
39
39
|
// If we're copying a row with rowspan somewhere, we dont want to copy that cell
|
|
@@ -49,9 +49,9 @@ export const cloneRowAt = rowIndex => tr => {
|
|
|
49
49
|
|
|
50
50
|
// If a higher row spans past our clone row, bump the higher row to cover this new row too.
|
|
51
51
|
if (rowWidth < map.width) {
|
|
52
|
-
|
|
52
|
+
const rowSpanCells = [];
|
|
53
53
|
for (let i = rowIndex; i >= 0; i--) {
|
|
54
|
-
|
|
54
|
+
const foundCells = filterCellsInRow(i, (cell, tr) => {
|
|
55
55
|
const rowspan = cell.node.attrs.rowspan;
|
|
56
56
|
const spanRange = i + rowspan;
|
|
57
57
|
return rowspan > 1 && spanRange > rowIndex;
|
|
@@ -73,7 +73,7 @@ export const cloneRowAt = rowIndex => tr => {
|
|
|
73
73
|
};
|
|
74
74
|
|
|
75
75
|
// Returns a new transaction that adds a new row at index `rowIndex`. Optionally clone the previous row.
|
|
76
|
-
export const addRowAt = (rowIndex, clonePreviousRow
|
|
76
|
+
export const addRowAt = (rowIndex, clonePreviousRow) => tr => {
|
|
77
77
|
const table = findTable(tr.selection);
|
|
78
78
|
if (table) {
|
|
79
79
|
const map = TableMap.get(table.node);
|
|
@@ -86,7 +86,7 @@ export const addRowAt = (rowIndex, clonePreviousRow, isCellBackgroundDuplicated)
|
|
|
86
86
|
map,
|
|
87
87
|
tableStart: table.start,
|
|
88
88
|
table: table.node
|
|
89
|
-
}, rowIndex
|
|
89
|
+
}, rowIndex));
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
return tr;
|
|
@@ -13,7 +13,7 @@ export function addRow(tr, {
|
|
|
13
13
|
map,
|
|
14
14
|
tableStart,
|
|
15
15
|
table
|
|
16
|
-
}, row
|
|
16
|
+
}, row) {
|
|
17
17
|
let rowPos = tableStart;
|
|
18
18
|
for (let i = 0; i < row; i++) {
|
|
19
19
|
rowPos += table.child(i).nodeSize;
|
|
@@ -51,12 +51,14 @@ export function addRow(tr, {
|
|
|
51
51
|
throw new Error(`addRow: invalid node at mapped pos ${mappedPos}`);
|
|
52
52
|
}
|
|
53
53
|
type = cell.type;
|
|
54
|
-
if (cell.attrs.background
|
|
54
|
+
if (cell.attrs.background) {
|
|
55
55
|
attrs = {
|
|
56
56
|
background: cell.attrs.background
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
+
// Ignored via go/ees005
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
60
62
|
cells.push(type.createAndFill(attrs));
|
|
61
63
|
}
|
|
62
64
|
}
|
|
@@ -15,7 +15,10 @@ export const cloneColumn = (state, originColumnIndex, targetColumnIndex, targetD
|
|
|
15
15
|
tryToFit: false,
|
|
16
16
|
direction: 0,
|
|
17
17
|
selectAfterClone: false
|
|
18
|
-
}
|
|
18
|
+
}
|
|
19
|
+
// Ignored via go/ees005
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
21
|
+
) => tr => {
|
|
19
22
|
var _originalColumnRanges, _targetColumnRanges$i;
|
|
20
23
|
const table = findTable(tr.selection);
|
|
21
24
|
if (!table) {
|
|
@@ -80,6 +83,8 @@ export const cloneColumn = (state, originColumnIndex, targetColumnIndex, targetD
|
|
|
80
83
|
// The actual target index needs to be translated per row, this is because row/col spans can affect the amount of
|
|
81
84
|
// cells each row contains.
|
|
82
85
|
const rowTargetPosition = translateTargetPosition(y, actualTargetIndex, tableMap);
|
|
86
|
+
// Ignored via go/ees005
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
83
88
|
const node = table.node.nodeAt(rowTargetPosition);
|
|
84
89
|
const pos = table.start + rowTargetPosition;
|
|
85
90
|
const insertPos = direction === 'end' ? newTr.mapping.map(pos + node.nodeSize, 1) : newTr.mapping.map(pos, -1);
|
|
@@ -96,12 +101,17 @@ export const cloneColumn = (state, originColumnIndex, targetColumnIndex, targetD
|
|
|
96
101
|
}
|
|
97
102
|
return newTr;
|
|
98
103
|
};
|
|
104
|
+
|
|
105
|
+
// Ignored via go/ees005
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
99
107
|
function normalizeCellNode(cellNode, rowHeaderEnabled, columnHeaderEnabled, types) {
|
|
100
108
|
const newTargetType = rowHeaderEnabled || columnHeaderEnabled ? types.header_cell : types.cell;
|
|
101
109
|
return cellNode.type !== newTargetType ? newTargetType.create(cellNode.attrs, cellNode.content, cellNode.marks) : cellNode;
|
|
102
110
|
}
|
|
103
111
|
function createContentNodeFactory(table) {
|
|
104
112
|
return nodePos => {
|
|
113
|
+
// Ignored via go/ees005
|
|
114
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
105
115
|
const node = table.node.nodeAt(nodePos);
|
|
106
116
|
const pos = nodePos + table.start;
|
|
107
117
|
return {
|
|
@@ -15,7 +15,10 @@ export const cloneRow = (state, originRowIndex, targetRowIndex, targetDirection,
|
|
|
15
15
|
tryToFit: false,
|
|
16
16
|
direction: 0,
|
|
17
17
|
selectAfterClone: false
|
|
18
|
-
}
|
|
18
|
+
}
|
|
19
|
+
// Ignored via go/ees005
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
21
|
+
) => tr => {
|
|
19
22
|
const table = findTable(tr.selection);
|
|
20
23
|
if (!table) {
|
|
21
24
|
return tr;
|
|
@@ -94,8 +97,10 @@ export const cloneRow = (state, originRowIndex, targetRowIndex, targetDirection,
|
|
|
94
97
|
* This ensures the row node cell type correctly reflect what they should be.
|
|
95
98
|
* @returns A copy of the rowNode
|
|
96
99
|
*/
|
|
100
|
+
// Ignored via go/ees005
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
97
102
|
function normalizeRowNode(rowNode, rowHeaderEnabled, columnHeaderEnabled, types) {
|
|
98
|
-
|
|
103
|
+
const content = [];
|
|
99
104
|
rowNode.forEach((node, offset, index) => {
|
|
100
105
|
const newTargetType = rowHeaderEnabled || columnHeaderEnabled && index === 0 ? types.header_cell : types.cell;
|
|
101
106
|
content.push(node.type !== newTargetType ? newTargetType.create(node.attrs, node.content, node.marks) : node);
|
|
@@ -115,6 +115,8 @@ function ensureRectangular(schema, rowsFragment) {
|
|
|
115
115
|
rows.push(Fragment.empty);
|
|
116
116
|
}
|
|
117
117
|
if (widths[r] < width) {
|
|
118
|
+
// Ignored via go/ees005
|
|
119
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
118
120
|
const empty = tableNodeTypes(schema).cell.createAndFill();
|
|
119
121
|
const cells = [];
|
|
120
122
|
for (let i = widths[r]; i < width; i++) {
|
|
@@ -201,6 +203,8 @@ export function clipCells({
|
|
|
201
203
|
|
|
202
204
|
// Make sure a table has at least the given width and height. Return
|
|
203
205
|
// true if something was changed.
|
|
206
|
+
// Ignored via go/ees005
|
|
207
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
204
208
|
function growTable(tr, map, table, start, width, height, mapFrom) {
|
|
205
209
|
const {
|
|
206
210
|
schema
|
|
@@ -215,8 +219,12 @@ function growTable(tr, map, table, start, width, height, mapFrom) {
|
|
|
215
219
|
const cells = [];
|
|
216
220
|
let add;
|
|
217
221
|
if (rowNode.lastChild == null || rowNode.lastChild.type === types.cell) {
|
|
222
|
+
// Ignored via go/ees005
|
|
223
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
218
224
|
add = empty || (empty = types.cell.createAndFill());
|
|
219
225
|
} else {
|
|
226
|
+
// Ignored via go/ees005
|
|
227
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
220
228
|
add = emptyHead || (emptyHead = types.header_cell.createAndFill());
|
|
221
229
|
}
|
|
222
230
|
for (let i = map.width; i < width; i++) {
|
|
@@ -239,7 +247,13 @@ function growTable(tr, map, table, start, width, height, mapFrom) {
|
|
|
239
247
|
}
|
|
240
248
|
header = node.type === types.header_cell;
|
|
241
249
|
}
|
|
242
|
-
cells.push(header ?
|
|
250
|
+
cells.push(header ?
|
|
251
|
+
// Ignored via go/ees005
|
|
252
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
253
|
+
emptyHead || (emptyHead = types.header_cell.createAndFill()) :
|
|
254
|
+
// Ignored via go/ees005
|
|
255
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
256
|
+
empty || (empty = types.cell.createAndFill()));
|
|
243
257
|
}
|
|
244
258
|
const emptyRow = types.row.create(null, Fragment.from(cells));
|
|
245
259
|
const rows = [];
|
|
@@ -254,6 +268,8 @@ function growTable(tr, map, table, start, width, height, mapFrom) {
|
|
|
254
268
|
// Make sure the given line (left, top) to (right, top) doesn't cross
|
|
255
269
|
// any rowspan cells by splitting cells that cross it. Return true if
|
|
256
270
|
// something changed.
|
|
271
|
+
// Ignored via go/ees005
|
|
272
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
257
273
|
function isolateHorizontal(tr, map, table, start, left, right, top, mapFrom) {
|
|
258
274
|
if (top === 0 || top === map.height) {
|
|
259
275
|
return false;
|
|
@@ -293,6 +309,8 @@ function isolateHorizontal(tr, map, table, start, left, right, top, mapFrom) {
|
|
|
293
309
|
// Make sure the given line (left, top) to (left, bottom) doesn't
|
|
294
310
|
// cross any colspan cells by splitting cells that cross it. Return
|
|
295
311
|
// true if something changed.
|
|
312
|
+
// Ignored via go/ees005
|
|
313
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
296
314
|
function isolateVertical(tr, map, table, start, top, bottom, left, mapFrom) {
|
|
297
315
|
if (left === 0 || left === map.width) {
|
|
298
316
|
return false;
|
|
@@ -320,10 +338,16 @@ function isolateVertical(tr, map, table, start, top, bottom, left, mapFrom) {
|
|
|
320
338
|
}
|
|
321
339
|
return found;
|
|
322
340
|
}
|
|
341
|
+
|
|
342
|
+
// Ignored via go/ees005
|
|
343
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
323
344
|
function applyHeaderCells(tr, tableMap, state, tableStart, table, headerRowEnabled, headerColumnEnabled) {
|
|
324
345
|
const {
|
|
325
346
|
schema
|
|
326
347
|
} = state;
|
|
348
|
+
|
|
349
|
+
// Ignored via go/ees005
|
|
350
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
327
351
|
const setMarkup = (tr, row, col, headerEnabled) => {
|
|
328
352
|
const cellPos = tableStart + tableMap.positionAt(row, col, table);
|
|
329
353
|
const cell = tr.doc.nodeAt(cellPos);
|
|
@@ -350,6 +374,8 @@ function applyHeaderCells(tr, tableMap, state, tableStart, table, headerRowEnabl
|
|
|
350
374
|
|
|
351
375
|
// Insert the given set of cells (as returned by `pastedCells`) into a
|
|
352
376
|
// table, at the position pointed at by rect.
|
|
377
|
+
// Ignored via go/ees005
|
|
378
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
353
379
|
export function insertCells(state, dispatch, tableStart, rect, cells) {
|
|
354
380
|
let table = state.doc;
|
|
355
381
|
const newRect = selectedRect(state);
|
|
@@ -376,6 +402,8 @@ export function insertCells(state, dispatch, tableStart, rect, cells) {
|
|
|
376
402
|
} = state;
|
|
377
403
|
let mapFrom = 0;
|
|
378
404
|
function recomp() {
|
|
405
|
+
// Ignored via go/ees005
|
|
406
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
379
407
|
table = tableStart ? tr.doc.nodeAt(tableStart - 1) : tr.doc;
|
|
380
408
|
map = TableMap.get(table);
|
|
381
409
|
mapFrom = tr.mapping.maps.length;
|
|
@@ -12,7 +12,10 @@ export const findTableClosestToPos = $pos => {
|
|
|
12
12
|
|
|
13
13
|
// Iterates over parent nodes, returning a table cell or a table header node closest to a given `$pos`.
|
|
14
14
|
export const findCellClosestToPos = $pos => {
|
|
15
|
-
const predicate = node =>
|
|
15
|
+
const predicate = node =>
|
|
16
|
+
// Ignored via go/ees005
|
|
17
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
18
|
+
node.type.spec.tableRole && /cell/i.test(node.type.spec.tableRole);
|
|
16
19
|
return findParentNodeClosestToPos($pos, predicate);
|
|
17
20
|
};
|
|
18
21
|
|
|
@@ -5,17 +5,20 @@ import { tableNodeTypes } from './table-node-types';
|
|
|
5
5
|
// Helper for iterating through the nodes in a document that changed
|
|
6
6
|
// compared to the given previous document. Useful for avoiding
|
|
7
7
|
// duplicate work on each transaction.
|
|
8
|
+
// Ignored via go/ees005
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
8
10
|
function changedDescendants(old, cur, offsetStart, f) {
|
|
9
11
|
let offset = offsetStart;
|
|
10
12
|
const oldSize = old.childCount;
|
|
11
13
|
const curSize = cur.childCount;
|
|
14
|
+
// eslint-disable-next-line no-labels
|
|
12
15
|
outer: for (let i = 0, j = 0; i < curSize; i++) {
|
|
13
16
|
const child = cur.child(i);
|
|
14
17
|
for (let scan = j, e = Math.min(oldSize, i + 3); scan < e; scan++) {
|
|
15
18
|
if (old.child(scan) === child) {
|
|
16
19
|
j = scan + 1;
|
|
17
20
|
offset += child.nodeSize;
|
|
18
|
-
// eslint-disable-next-line no-continue
|
|
21
|
+
// eslint-disable-next-line no-continue, no-labels
|
|
19
22
|
continue outer;
|
|
20
23
|
}
|
|
21
24
|
}
|
|
@@ -53,6 +56,8 @@ export function fixTables(state, oldState, reportFixedTable) {
|
|
|
53
56
|
// : (EditorState, Node, number, ?Transaction) → ?Transaction
|
|
54
57
|
// Fix the given table, if necessary. Will append to the transaction
|
|
55
58
|
// it was given, if non-null, or create a new one if necessary.
|
|
59
|
+
// Ignored via go/ees005
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
56
61
|
export function fixTable(state, table, tablePos, transaction, reportFixedTable) {
|
|
57
62
|
let tr = transaction;
|
|
58
63
|
const map = TableMap.get(table);
|
|
@@ -137,6 +142,8 @@ export function fixTable(state, table, tablePos, transaction, reportFixedTable)
|
|
|
137
142
|
}
|
|
138
143
|
const nodes = [];
|
|
139
144
|
for (let j = 0; j < add; j++) {
|
|
145
|
+
// Ignored via go/ees005
|
|
146
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
140
147
|
nodes.push(tableNodeTypes(state.schema)[tableNodeType].createAndFill());
|
|
141
148
|
}
|
|
142
149
|
const side = (i === 0 || first === i - 1) && last === i ? pos + 1 : end - 1;
|
|
@@ -17,6 +17,8 @@ export const getCellsInColumn = columnIndexes => selection => {
|
|
|
17
17
|
bottom: map.height
|
|
18
18
|
});
|
|
19
19
|
return acc.concat(cells.map(nodePos => {
|
|
20
|
+
// Ignored via go/ees005
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
20
22
|
const node = table.node.nodeAt(nodePos);
|
|
21
23
|
const pos = nodePos + table.start;
|
|
22
24
|
return {
|
|
@@ -17,6 +17,8 @@ export const getCellsInRow = rowIndex => selection => {
|
|
|
17
17
|
bottom: index + 1
|
|
18
18
|
});
|
|
19
19
|
return acc.concat(cells.map(nodePos => {
|
|
20
|
+
// Ignored via go/ees005
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
20
22
|
const node = table.node.nodeAt(nodePos);
|
|
21
23
|
const pos = nodePos + table.start;
|
|
22
24
|
return {
|
|
@@ -11,7 +11,7 @@ export const getSelectionRangeInColumn = (startColIndex, endColIndex = startColI
|
|
|
11
11
|
const cells = getCellsInColumn(i)(tr.selection);
|
|
12
12
|
if (cells) {
|
|
13
13
|
cells.forEach(cell => {
|
|
14
|
-
|
|
14
|
+
const maybeEndIndex = cell.node.attrs.colspan + i - 1;
|
|
15
15
|
if (maybeEndIndex >= startIndex) {
|
|
16
16
|
startIndex = i;
|
|
17
17
|
}
|
|
@@ -26,7 +26,7 @@ export const getSelectionRangeInColumn = (startColIndex, endColIndex = startColI
|
|
|
26
26
|
const cells = getCellsInColumn(i)(tr.selection);
|
|
27
27
|
if (cells) {
|
|
28
28
|
cells.forEach(cell => {
|
|
29
|
-
|
|
29
|
+
const maybeEndIndex = cell.node.attrs.colspan + i - 1;
|
|
30
30
|
if (cell.node.attrs.colspan > 1 && maybeEndIndex > endIndex) {
|
|
31
31
|
endIndex = maybeEndIndex;
|
|
32
32
|
}
|
|
@@ -11,7 +11,7 @@ export const getSelectionRangeInRow = (startRowIndex, endRowIndex = startRowInde
|
|
|
11
11
|
const cells = getCellsInRow(i)(tr.selection);
|
|
12
12
|
if (cells) {
|
|
13
13
|
cells.forEach(cell => {
|
|
14
|
-
|
|
14
|
+
const maybeEndIndex = cell.node.attrs.rowspan + i - 1;
|
|
15
15
|
if (maybeEndIndex >= startIndex) {
|
|
16
16
|
startIndex = i;
|
|
17
17
|
}
|
|
@@ -26,7 +26,7 @@ export const getSelectionRangeInRow = (startRowIndex, endRowIndex = startRowInde
|
|
|
26
26
|
const cells = getCellsInRow(i)(tr.selection);
|
|
27
27
|
if (cells) {
|
|
28
28
|
cells.forEach(cell => {
|
|
29
|
-
|
|
29
|
+
const maybeEndIndex = cell.node.attrs.rowspan + i - 1;
|
|
30
30
|
if (cell.node.attrs.rowspan > 1 && maybeEndIndex > endIndex) {
|
|
31
31
|
endIndex = maybeEndIndex;
|
|
32
32
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
1
2
|
import { CellSelection } from '../cell-selection';
|
|
2
3
|
import { TableMap } from '../table-map';
|
|
3
4
|
import { determineTableHeaderStateFromTableNode } from './analyse-table';
|
|
@@ -139,7 +140,10 @@ export const moveColumn = (state, originColumnIndex, targetColumnIndex, options
|
|
|
139
140
|
tryToFit: false,
|
|
140
141
|
direction: 0,
|
|
141
142
|
selectAfterMove: false
|
|
142
|
-
}
|
|
143
|
+
}
|
|
144
|
+
// Ignored via go/ees005
|
|
145
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
146
|
+
) => tr => {
|
|
143
147
|
var _originalColumnRanges, _targetColumnRanges$i;
|
|
144
148
|
const table = findTable(tr.selection);
|
|
145
149
|
if (!table) {
|
|
@@ -207,9 +211,11 @@ export const moveColumn = (state, originColumnIndex, targetColumnIndex, options
|
|
|
207
211
|
// The actual target index needs to be translated per row, this is because row/col spans can affect the amount of
|
|
208
212
|
// cells each row contains.
|
|
209
213
|
const rowTargetPosition = translateTargetPosition(y, actualTargetIndex, tableMap);
|
|
214
|
+
// Ignored via go/ees005
|
|
215
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
210
216
|
const node = table.node.nodeAt(rowTargetPosition);
|
|
211
217
|
const pos = table.start + rowTargetPosition;
|
|
212
|
-
const insertPos = direction === 'end' ? newTr.mapping.map(pos + node.nodeSize, 1) : newTr.mapping.map(pos, -1);
|
|
218
|
+
const insertPos = direction === 'end' || tableMap.isCellMergedTopLeft(y, actualTargetIndex) && fg('platform_editor_table_fix_move_column') ? newTr.mapping.map(pos + node.nodeSize, 1) : newTr.mapping.map(pos, -1);
|
|
213
219
|
newTr.insert(insertPos, row.map(({
|
|
214
220
|
node
|
|
215
221
|
}, x) => normalizeCellNode(node, rowHeaderEnabled && y === 0, columnHeaderEnabled && actualTargetIndex === 0 && x === 0, types)));
|
|
@@ -229,12 +235,17 @@ export const moveColumn = (state, originColumnIndex, targetColumnIndex, options
|
|
|
229
235
|
}
|
|
230
236
|
return newTr;
|
|
231
237
|
};
|
|
238
|
+
|
|
239
|
+
// Ignored via go/ees005
|
|
240
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
232
241
|
function normalizeCellNode(cellNode, rowHeaderEnabled, columnHeaderEnabled, types) {
|
|
233
242
|
const newTargetType = rowHeaderEnabled || columnHeaderEnabled ? types.header_cell : types.cell;
|
|
234
243
|
return cellNode.type !== newTargetType ? newTargetType.create(cellNode.attrs, cellNode.content, cellNode.marks) : cellNode;
|
|
235
244
|
}
|
|
236
245
|
function createContentNodeFactory(table) {
|
|
237
246
|
return nodePos => {
|
|
247
|
+
// Ignored via go/ees005
|
|
248
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
238
249
|
const node = table.node.nodeAt(nodePos);
|
|
239
250
|
const pos = nodePos + table.start;
|
|
240
251
|
return {
|
|
@@ -155,7 +155,10 @@ export const moveRow = (state, originRowIndex, targetRowIndex, options = {
|
|
|
155
155
|
tryToFit: false,
|
|
156
156
|
direction: 0,
|
|
157
157
|
selectAfterMove: false
|
|
158
|
-
}
|
|
158
|
+
}
|
|
159
|
+
// Ignored via go/ees005
|
|
160
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
161
|
+
) => tr => {
|
|
159
162
|
const table = findTable(tr.selection);
|
|
160
163
|
if (!table) {
|
|
161
164
|
return tr;
|
|
@@ -248,8 +251,10 @@ export const moveRow = (state, originRowIndex, targetRowIndex, options = {
|
|
|
248
251
|
* This ensures the row node cell type correctly reflect what they should be.
|
|
249
252
|
* @returns A copy of the rowNode
|
|
250
253
|
*/
|
|
254
|
+
// Ignored via go/ees005
|
|
255
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
251
256
|
function normalizeRowNode(rowNode, rowHeaderEnabled, columnHeaderEnabled, types) {
|
|
252
|
-
|
|
257
|
+
const content = [];
|
|
253
258
|
rowNode.forEach((node, offset, index) => {
|
|
254
259
|
const newTargetType = rowHeaderEnabled || columnHeaderEnabled && index === 0 ? types.header_cell : types.cell;
|
|
255
260
|
content.push(node.type !== newTargetType ? newTargetType.create(node.attrs, node.content, node.marks) : node);
|
|
@@ -56,6 +56,8 @@ function isCellBoundarySelection({
|
|
|
56
56
|
break;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
+
// Ignored via go/ees005
|
|
60
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
59
61
|
return afterFrom === beforeTo && /row|table/.test($from.node(depth).type.spec.tableRole);
|
|
60
62
|
}
|
|
61
63
|
function isTextSelectionAcrossCells({
|
|
@@ -14,11 +14,11 @@ function removeRow(tr, {
|
|
|
14
14
|
for (let i = 0; i < rowIndex; i++) {
|
|
15
15
|
rowPos += table.child(i).nodeSize;
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const nextRow = rowPos + table.child(rowIndex).nodeSize;
|
|
18
|
+
const mapFrom = tr.mapping.maps.length;
|
|
19
19
|
tr.delete(rowPos + tableStart, nextRow + tableStart);
|
|
20
20
|
for (let col = 0, index = rowIndex * map.width; col < map.width; col++, index++) {
|
|
21
|
-
|
|
21
|
+
const pos = map.map[index];
|
|
22
22
|
if (rowIndex > 0 && pos === map.map[index - map.width]) {
|
|
23
23
|
// If this cell starts in the row above, simply reduce its rowspan
|
|
24
24
|
const cell = table.nodeAt(pos);
|
|
@@ -6,7 +6,7 @@ export const removeTable = tr => {
|
|
|
6
6
|
$from
|
|
7
7
|
} = tr.selection;
|
|
8
8
|
for (let depth = $from.depth; depth > 0; depth--) {
|
|
9
|
-
|
|
9
|
+
const node = $from.node(depth);
|
|
10
10
|
if (node.type.spec.tableRole === 'table') {
|
|
11
11
|
return cloneTr(tr.delete($from.before(depth), $from.after(depth)));
|
|
12
12
|
}
|
|
@@ -28,7 +28,11 @@ import { TableMap } from '../table-map';
|
|
|
28
28
|
// ['a3', 'b3', 'c3', 'd3'],
|
|
29
29
|
// ]
|
|
30
30
|
// ```
|
|
31
|
+
// Ignored via go/ees005
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
33
|
export const transpose = array => {
|
|
34
|
+
// Ignored via go/ees005
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
36
|
return array[0].map((_, i) => {
|
|
33
37
|
return array.map(column => column[i]);
|
|
34
38
|
});
|
|
@@ -84,8 +88,11 @@ export const convertArrayOfRowsToTableNode = (tableNode, arrayOfNodes) => {
|
|
|
84
88
|
const newTable = tableNode.type.createChecked(tableNode.attrs, rowsPM, tableNode.marks);
|
|
85
89
|
return newTable;
|
|
86
90
|
};
|
|
87
|
-
const moveRowInArrayOfRows = (arrayOfNodes, indexesOrigin, indexesTarget, directionOverride
|
|
88
|
-
|
|
91
|
+
const moveRowInArrayOfRows = (arrayOfNodes, indexesOrigin, indexesTarget, directionOverride
|
|
92
|
+
// Ignored via go/ees005
|
|
93
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
94
|
+
) => {
|
|
95
|
+
const direction = indexesOrigin[0] > indexesTarget[0] ? -1 : 1;
|
|
89
96
|
const rowsExtracted = arrayOfNodes.splice(indexesOrigin[0], indexesOrigin.length);
|
|
90
97
|
const positionOffset = rowsExtracted.length % 2 === 0 ? 1 : 0;
|
|
91
98
|
let target;
|
|
@@ -149,18 +156,27 @@ export const convertTableNodeToArrayOfRows = tableNode => {
|
|
|
149
156
|
}
|
|
150
157
|
return rows;
|
|
151
158
|
};
|
|
152
|
-
export const moveTableRow = (table, indexesOrigin, indexesTarget, direction
|
|
159
|
+
export const moveTableRow = (table, indexesOrigin, indexesTarget, direction
|
|
160
|
+
// Ignored via go/ees005
|
|
161
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
162
|
+
) => {
|
|
153
163
|
let rows = convertTableNodeToArrayOfRows(table.node);
|
|
154
164
|
rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction);
|
|
155
165
|
return convertArrayOfRowsToTableNode(table.node, rows);
|
|
156
166
|
};
|
|
157
|
-
export const moveTableColumn = (table, indexesOrigin, indexesTarget, direction
|
|
167
|
+
export const moveTableColumn = (table, indexesOrigin, indexesTarget, direction
|
|
168
|
+
// Ignored via go/ees005
|
|
169
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
170
|
+
) => {
|
|
158
171
|
let rows = transpose(convertTableNodeToArrayOfRows(table.node));
|
|
159
172
|
rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction);
|
|
160
173
|
rows = transpose(rows);
|
|
161
174
|
return convertArrayOfRowsToTableNode(table.node, rows);
|
|
162
175
|
};
|
|
163
|
-
export const isValidReorder = (originIndex, targetIndex, targets, type
|
|
176
|
+
export const isValidReorder = (originIndex, targetIndex, targets, type
|
|
177
|
+
// Ignored via go/ees005
|
|
178
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
179
|
+
) => {
|
|
164
180
|
const direction = originIndex > targetIndex ? -1 : 1;
|
|
165
181
|
const errorMessage = `Target position is invalid, you can't move the ${type} ${originIndex} to ${targetIndex}, the target can't be split. You could use tryToFit option.`;
|
|
166
182
|
if (direction === 1) {
|
|
@@ -7,7 +7,7 @@ export const replaceSelectedTable = (state, content) => {
|
|
|
7
7
|
const table = findTable(state.selection);
|
|
8
8
|
if (table) {
|
|
9
9
|
const slice = typeof content === 'string' ? new Slice(Fragment.from(state.schema.text(content)), 0, 0) : content;
|
|
10
|
-
|
|
10
|
+
const tr = state.tr.replace(table.pos, table.pos + table.node.nodeSize, slice);
|
|
11
11
|
tr.setSelection(TextSelection.create(tr.doc, table.pos + slice.size + 1));
|
|
12
12
|
return tr;
|
|
13
13
|
}
|
|
@@ -16,7 +16,7 @@ export function cellWrapping($pos) {
|
|
|
16
16
|
// into smaller cells with the cell type (th, td) returned by getType function.
|
|
17
17
|
export function splitCellWithType(getCellType) {
|
|
18
18
|
return (state, dispatch) => {
|
|
19
|
-
|
|
19
|
+
const sel = state.selection;
|
|
20
20
|
let cellNode, cellPos;
|
|
21
21
|
if (!(sel instanceof CellSelection)) {
|
|
22
22
|
cellNode = cellWrapping(sel.$from);
|
|
@@ -36,9 +36,9 @@ export function splitCellWithType(getCellType) {
|
|
|
36
36
|
return false;
|
|
37
37
|
}
|
|
38
38
|
if (cellNode && dispatch) {
|
|
39
|
-
let cellAttrs = cellNode.attrs
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
let cellAttrs = cellNode.attrs;
|
|
40
|
+
const attrs = [];
|
|
41
|
+
const colwidth = cellAttrs.colwidth;
|
|
42
42
|
if (cellAttrs.rowspan && cellAttrs.rowspan > 1) {
|
|
43
43
|
cellAttrs = {
|
|
44
44
|
...cellAttrs,
|
|
@@ -51,8 +51,8 @@ export function splitCellWithType(getCellType) {
|
|
|
51
51
|
colspan: 1
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
const rect = selectedRect(state);
|
|
55
|
+
const tr = state.tr;
|
|
56
56
|
for (let i = 0; i < rect.right - rect.left; i++) {
|
|
57
57
|
attrs.push(colwidth ? {
|
|
58
58
|
...cellAttrs,
|
|
@@ -26,13 +26,13 @@ export function toggleHeader(type) {
|
|
|
26
26
|
return false;
|
|
27
27
|
}
|
|
28
28
|
if (dispatch) {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const types = tableNodeTypes(state.schema);
|
|
30
|
+
const rect = selectedRect(state),
|
|
31
31
|
tr = state.tr;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
const isHeaderRowEnabled = isHeaderEnabledByType('row', rect, types);
|
|
33
|
+
const isHeaderColumnEnabled = isHeaderEnabledByType('column', rect, types);
|
|
34
|
+
const isHeaderEnabled = type === 'column' ? isHeaderRowEnabled : type === 'row' ? isHeaderColumnEnabled : false;
|
|
35
|
+
const selectionStartsAt = isHeaderEnabled ? 1 : 0;
|
|
36
36
|
const cellsRect = type === 'column' ? new Rect(0, selectionStartsAt, 1, rect.map.height) : type === 'row' ? new Rect(selectionStartsAt, 0, rect.map.width, 1) : rect;
|
|
37
37
|
let newType;
|
|
38
38
|
if (type === 'column') {
|
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/* eslint-disable no-bitwise */
|
|
7
|
-
export const generateUuid = () =>
|
|
7
|
+
export const generateUuid = () =>
|
|
8
|
+
// Ignored via go/ees005
|
|
9
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
10
|
+
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
|
8
11
|
const r = Math.random() * 16 | 0;
|
|
9
12
|
return (c === 'x' ? r : r & 0x3 | 0x8).toString(16);
|
|
10
13
|
});
|
package/dist/es2019/utils.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
2
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
/* eslint-disable @atlaskit/editor/no-re-export */
|
|
4
|
+
// Entry file in package.json
|
|
5
|
+
|
|
3
6
|
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
4
7
|
import { inSameTable } from './utils/tables';
|
|
5
8
|
export var CellBookmark = /*#__PURE__*/function () {
|
|
@@ -8,7 +11,7 @@ export var CellBookmark = /*#__PURE__*/function () {
|
|
|
8
11
|
this.anchor = anchor;
|
|
9
12
|
this.head = head;
|
|
10
13
|
}
|
|
11
|
-
_createClass(CellBookmark, [{
|
|
14
|
+
return _createClass(CellBookmark, [{
|
|
12
15
|
key: "map",
|
|
13
16
|
value: function map(mapping) {
|
|
14
17
|
return new CellBookmark(mapping.map(this.anchor), mapping.map(this.head));
|
|
@@ -29,5 +32,4 @@ export var CellBookmark = /*#__PURE__*/function () {
|
|
|
29
32
|
return Selection.near($headCell, 1);
|
|
30
33
|
}
|
|
31
34
|
}]);
|
|
32
|
-
return CellBookmark;
|
|
33
35
|
}();
|