@atlaskit/adf-schema 29.1.2 → 30.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/cjs/schema/default-schema.js +0 -1
- package/dist/cjs/schema/nodes/tableNodes.js +9 -8
- package/dist/cjs/steps.js +0 -21
- package/dist/es2019/schema/default-schema.js +1 -2
- package/dist/es2019/schema/nodes/tableNodes.js +10 -9
- package/dist/es2019/steps.js +0 -3
- package/dist/esm/schema/default-schema.js +1 -2
- package/dist/esm/schema/nodes/tableNodes.js +9 -8
- package/dist/esm/steps.js +0 -3
- package/dist/json-schema/v1/full.json +3 -0
- package/dist/types/schema/nodes/tableNodes.d.ts +8 -5
- package/dist/types/steps.d.ts +0 -4
- package/json-schema/v1/full.json +3 -0
- package/package.json +1 -2
- package/dist/cjs/steps/table/add-column.js +0 -381
- package/dist/cjs/steps/table/constants.js +0 -12
- package/dist/cjs/steps/table/sort-column.js +0 -68
- package/dist/cjs/steps/table/types.js +0 -5
- package/dist/cjs/steps/table/utils/cell-step.js +0 -202
- package/dist/cjs/steps/table/utils/cells-at-column.js +0 -73
- package/dist/cjs/steps/table/utils/find-column.js +0 -90
- package/dist/cjs/steps/table/utils/get-table-rect-from-doc.js +0 -36
- package/dist/cjs/steps/table/utils/side-effects/rows.js +0 -315
- package/dist/cjs/steps/table/utils/side-effects/side-effects.js +0 -83
- package/dist/cjs/steps/table/utils/side-effects/table.js +0 -110
- package/dist/cjs/steps/table/utils/side-effects/types.js +0 -5
- package/dist/cjs/steps/table/utils/table-map.js +0 -30
- package/dist/es2019/steps/table/add-column.js +0 -306
- package/dist/es2019/steps/table/constants.js +0 -5
- package/dist/es2019/steps/table/sort-column.js +0 -34
- package/dist/es2019/steps/table/types.js +0 -1
- package/dist/es2019/steps/table/utils/cell-step.js +0 -187
- package/dist/es2019/steps/table/utils/cells-at-column.js +0 -52
- package/dist/es2019/steps/table/utils/find-column.js +0 -83
- package/dist/es2019/steps/table/utils/get-table-rect-from-doc.js +0 -31
- package/dist/es2019/steps/table/utils/side-effects/rows.js +0 -257
- package/dist/es2019/steps/table/utils/side-effects/side-effects.js +0 -60
- package/dist/es2019/steps/table/utils/side-effects/table.js +0 -82
- package/dist/es2019/steps/table/utils/side-effects/types.js +0 -1
- package/dist/es2019/steps/table/utils/table-map.js +0 -19
- package/dist/esm/steps/table/add-column.js +0 -373
- package/dist/esm/steps/table/constants.js +0 -5
- package/dist/esm/steps/table/sort-column.js +0 -60
- package/dist/esm/steps/table/types.js +0 -1
- package/dist/esm/steps/table/utils/cell-step.js +0 -192
- package/dist/esm/steps/table/utils/cells-at-column.js +0 -66
- package/dist/esm/steps/table/utils/find-column.js +0 -84
- package/dist/esm/steps/table/utils/get-table-rect-from-doc.js +0 -31
- package/dist/esm/steps/table/utils/side-effects/rows.js +0 -307
- package/dist/esm/steps/table/utils/side-effects/side-effects.js +0 -75
- package/dist/esm/steps/table/utils/side-effects/table.js +0 -102
- package/dist/esm/steps/table/utils/side-effects/types.js +0 -1
- package/dist/esm/steps/table/utils/table-map.js +0 -19
- package/dist/types/steps/table/add-column.d.ts +0 -88
- package/dist/types/steps/table/constants.d.ts +0 -4
- package/dist/types/steps/table/sort-column.d.ts +0 -18
- package/dist/types/steps/table/types.d.ts +0 -39
- package/dist/types/steps/table/utils/cell-step.d.ts +0 -47
- package/dist/types/steps/table/utils/cells-at-column.d.ts +0 -20
- package/dist/types/steps/table/utils/find-column.d.ts +0 -8
- package/dist/types/steps/table/utils/get-table-rect-from-doc.d.ts +0 -8
- package/dist/types/steps/table/utils/side-effects/rows.d.ts +0 -25
- package/dist/types/steps/table/utils/side-effects/side-effects.d.ts +0 -15
- package/dist/types/steps/table/utils/side-effects/table.d.ts +0 -16
- package/dist/types/steps/table/utils/side-effects/types.d.ts +0 -33
- package/dist/types/steps/table/utils/table-map.d.ts +0 -6
@@ -1,52 +0,0 @@
|
|
1
|
-
import { columnIsHeader, tableNodeTypes } from '@atlaskit/editor-tables/utils';
|
2
|
-
import { getCellIndex, hasMergedColumns, isRootRow } from './table-map';
|
3
|
-
/**
|
4
|
-
* Helper to have a consistent way to iterate for all the cells in a column.
|
5
|
-
* You can skip rows by passing the rows to skipped in the next arguments.
|
6
|
-
* For example: `iter.next(1)` to skip the next row
|
7
|
-
* @param rect
|
8
|
-
* @param col
|
9
|
-
*/
|
10
|
-
export function* cellsAtColumn(rect, col) {
|
11
|
-
const {
|
12
|
-
map,
|
13
|
-
tableStart,
|
14
|
-
table
|
15
|
-
} = rect;
|
16
|
-
let refColumn = col > 0 ? -1 : 0;
|
17
|
-
if (columnIsHeader(map, table, col + refColumn)) {
|
18
|
-
refColumn = col === 0 || col === map.width ? null : 0;
|
19
|
-
}
|
20
|
-
for (let row = 0; row < map.height; row++) {
|
21
|
-
let index = getCellIndex(rect.map, row, col);
|
22
|
-
let pos = map.map[index];
|
23
|
-
|
24
|
-
// We only consider to has merged cell to the first cell in a rowspan.
|
25
|
-
const hasMergedCells = hasMergedColumns(rect.map, row, col) && isRootRow(rect.map, row, col);
|
26
|
-
|
27
|
-
// If this position falls inside a col-spanning cell
|
28
|
-
let type = refColumn == null ? tableNodeTypes(table.type.schema).cell : table.nodeAt(map.map[index + refColumn]).type;
|
29
|
-
if (!hasMergedCells) {
|
30
|
-
pos = map.positionAt(row, col, table);
|
31
|
-
}
|
32
|
-
let cell = table.nodeAt(pos);
|
33
|
-
const cellInfo = {
|
34
|
-
from: tableStart + pos,
|
35
|
-
to: tableStart + pos,
|
36
|
-
row,
|
37
|
-
col: hasMergedCells ? map.colCount(pos) : col,
|
38
|
-
type,
|
39
|
-
hasMergedCells
|
40
|
-
};
|
41
|
-
if (cell) {
|
42
|
-
cellInfo.attrs = cell.attrs;
|
43
|
-
cellInfo.to = tableStart + pos + cell.nodeSize;
|
44
|
-
}
|
45
|
-
|
46
|
-
// We let the consumer to pass the rows that we want to skip
|
47
|
-
const skippedRows = yield cellInfo;
|
48
|
-
if (skippedRows && skippedRows > 0) {
|
49
|
-
row += skippedRows;
|
50
|
-
}
|
51
|
-
}
|
52
|
-
}
|
@@ -1,83 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Try to find the right column based on the cell steps in column info..
|
3
|
-
* @param columnInfo - Map of cell positions sorted from lower to greather
|
4
|
-
* @param rect - map rect
|
5
|
-
*/
|
6
|
-
export function findColumn(columnInfo, rect) {
|
7
|
-
/**
|
8
|
-
* Algorithm explained
|
9
|
-
* Given a table like this:
|
10
|
-
* | 5 | 10 |
|
11
|
-
* | 15 | 20 |
|
12
|
-
* | 25 | 30 | 35 |
|
13
|
-
* Represented by a table map like this:
|
14
|
-
* rect.map = [5, 10, 10,
|
15
|
-
* 15, 15, 20,
|
16
|
-
* 25, 30, 35]
|
17
|
-
* And a have this inputs:
|
18
|
-
* columnInfo[].from = [10, 15, 30]
|
19
|
-
*
|
20
|
-
* Algorithm:
|
21
|
-
* * Initial state
|
22
|
-
* start = 0;
|
23
|
-
* end = 2 (rect.width - 1 === 3 - 1)
|
24
|
-
* * Iterate until find first cell position
|
25
|
-
* start = 1
|
26
|
-
* end = 2 (min(start column + colspan - 1, start column + end column))
|
27
|
-
* * Iterate until find second cell position
|
28
|
-
* start = 1
|
29
|
-
* end = 1
|
30
|
-
* * Start === end return 1
|
31
|
-
*/
|
32
|
-
|
33
|
-
// Initial range (start and end column) to search for each row
|
34
|
-
let [start, end] = [0, rect.map.width - 1];
|
35
|
-
const iter = columnInfo.values();
|
36
|
-
let next = iter.next();
|
37
|
-
|
38
|
-
// Iterate for each row
|
39
|
-
for (let row = 0; row < rect.map.height; row++) {
|
40
|
-
if (next.done) {
|
41
|
-
break;
|
42
|
-
}
|
43
|
-
// Iterate for the column. Starting with the current start range
|
44
|
-
for (let col = start; col <= end; col++) {
|
45
|
-
const i = row * rect.map.width + col;
|
46
|
-
const cell = rect.map.map[i];
|
47
|
-
const cellInfo = next.value.from - rect.tableStart;
|
48
|
-
|
49
|
-
// When cell is found update range with the new values
|
50
|
-
if (cell === cellInfo) {
|
51
|
-
start = col; // Start column will be the current column
|
52
|
-
// Try to find the end column. End column will be different that start when has merged cells.
|
53
|
-
const endIndex = end - start + i;
|
54
|
-
for (let j = i; j <= endIndex; j++) {
|
55
|
-
if (rect.map.map[j] !== cell) {
|
56
|
-
break;
|
57
|
-
}
|
58
|
-
|
59
|
-
// merged columns
|
60
|
-
end = start + j - i; // Update the end column with the new position
|
61
|
-
}
|
62
|
-
|
63
|
-
if (start === end) {
|
64
|
-
// We found the right column only when start and end columns are the same.
|
65
|
-
return start;
|
66
|
-
}
|
67
|
-
next = iter.next();
|
68
|
-
break;
|
69
|
-
}
|
70
|
-
|
71
|
-
// Sometimes I want to find a column at the end of the table (It doesn't exist, but we can add a new cell there).
|
72
|
-
// This is represented by the end position of the last cell in the column.
|
73
|
-
// In this case return, table width
|
74
|
-
if (col === rect.map.width - 1) {
|
75
|
-
const cellNode = rect.table.nodeAt(cell);
|
76
|
-
if (cell + cellNode.nodeSize === cellInfo) {
|
77
|
-
return rect.map.width;
|
78
|
-
}
|
79
|
-
}
|
80
|
-
}
|
81
|
-
}
|
82
|
-
return null;
|
83
|
-
}
|
@@ -1,31 +0,0 @@
|
|
1
|
-
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
2
|
-
|
3
|
-
/**
|
4
|
-
* Util to get the table rect from the docs
|
5
|
-
* @param doc
|
6
|
-
* @param tablePos
|
7
|
-
*/
|
8
|
-
export function getTableRectFromDoc(doc, tablePos) {
|
9
|
-
const table = doc.nodeAt(tablePos);
|
10
|
-
|
11
|
-
// Check for table existence
|
12
|
-
if (!table || table.type.name !== 'table') {
|
13
|
-
throw new Error(`No table at position "${tablePos}".`);
|
14
|
-
}
|
15
|
-
|
16
|
-
// Create transform base on the doc
|
17
|
-
const map = TableMap.get(table);
|
18
|
-
const $table = doc.resolve(tablePos);
|
19
|
-
// Nested tables start position might differ from the original position
|
20
|
-
const start = $table.start($table.depth + 1);
|
21
|
-
return {
|
22
|
-
map,
|
23
|
-
table: table,
|
24
|
-
tableStart: start,
|
25
|
-
// Default to zero
|
26
|
-
bottom: 0,
|
27
|
-
left: 0,
|
28
|
-
right: 0,
|
29
|
-
top: 0
|
30
|
-
};
|
31
|
-
}
|
@@ -1,257 +0,0 @@
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
2
|
-
import { hasMergedColumns } from '../table-map';
|
3
|
-
function mergedRanges(first, second) {
|
4
|
-
const newRanges = [];
|
5
|
-
const firstLength = first.length;
|
6
|
-
const secondLength = second.length;
|
7
|
-
let i = 0;
|
8
|
-
let j = 0;
|
9
|
-
while (i < firstLength && j < secondLength) {
|
10
|
-
if (first[i] < second[j]) {
|
11
|
-
newRanges.push(first[i], first[i + 1], first[i + 2]);
|
12
|
-
i += 3;
|
13
|
-
} else {
|
14
|
-
newRanges.push(second[j], second[j + 1], second[j + 2]);
|
15
|
-
j += 3;
|
16
|
-
}
|
17
|
-
}
|
18
|
-
if (i < firstLength) {
|
19
|
-
newRanges.push(...first.slice(i));
|
20
|
-
}
|
21
|
-
if (j < secondLength) {
|
22
|
-
newRanges.push(...second.slice(i));
|
23
|
-
}
|
24
|
-
return newRanges;
|
25
|
-
}
|
26
|
-
function increaseRowSpan(tr, rect, row) {
|
27
|
-
const {
|
28
|
-
map,
|
29
|
-
tableStart
|
30
|
-
} = rect;
|
31
|
-
for (let col = 0; col < map.width; col++) {
|
32
|
-
let index = row * map.width + col;
|
33
|
-
let pos = map.map[index];
|
34
|
-
const mappedPos = tr.mapping.map(pos + tableStart);
|
35
|
-
let attrs = tr.doc.nodeAt(mappedPos).attrs;
|
36
|
-
tr.setNodeMarkup(mappedPos, undefined, {
|
37
|
-
...attrs,
|
38
|
-
rowspan: attrs.rowspan + 1
|
39
|
-
});
|
40
|
-
col += attrs.colspan - 1;
|
41
|
-
}
|
42
|
-
}
|
43
|
-
function decreaseRowspan(tr, rect, row, colToRemove) {
|
44
|
-
let skipRows = 0;
|
45
|
-
const {
|
46
|
-
map,
|
47
|
-
table,
|
48
|
-
tableStart
|
49
|
-
} = rect;
|
50
|
-
for (let col = 0; col < map.width; col++) {
|
51
|
-
let index = row * map.width + col;
|
52
|
-
let pos = map.map[index];
|
53
|
-
if (row > 0 && pos === map.map[index - map.width]) {
|
54
|
-
// If this cell starts in the row above, simply reduce its rowspan
|
55
|
-
const mappedPos = tr.mapping.map(pos + tableStart);
|
56
|
-
let attrs = tr.doc.nodeAt(mappedPos).attrs;
|
57
|
-
tr.setNodeMarkup(mappedPos, undefined, {
|
58
|
-
...attrs,
|
59
|
-
rowspan: attrs.rowspan - 1
|
60
|
-
});
|
61
|
-
col += attrs.colspan - 1;
|
62
|
-
} else if (col === colToRemove) {
|
63
|
-
skipRows = table.nodeAt(pos).attrs.rowspan - 1;
|
64
|
-
}
|
65
|
-
}
|
66
|
-
return skipRows;
|
67
|
-
}
|
68
|
-
function isLastCellInRow(rect, row, col) {
|
69
|
-
const rowNode = rect.table.child(row);
|
70
|
-
if (!rowNode) {
|
71
|
-
return false;
|
72
|
-
}
|
73
|
-
return rowNode.childCount === 1 && !hasMergedColumns(rect.map, row, col);
|
74
|
-
}
|
75
|
-
function removeRowWithLastCell(tr, rect, row, _col) {
|
76
|
-
// Get row pos
|
77
|
-
let from = rect.tableStart;
|
78
|
-
for (let i = 0; i < row; i++) {
|
79
|
-
from += rect.table.child(i).nodeSize;
|
80
|
-
}
|
81
|
-
const rowNode = rect.table.child(row);
|
82
|
-
let to = from + rowNode.nodeSize;
|
83
|
-
|
84
|
-
// Create sideEffect and delete the row
|
85
|
-
// We store original row position before modifications
|
86
|
-
tr.delete(tr.mapping.map(from), tr.mapping.map(to));
|
87
|
-
|
88
|
-
// Change rowspan of all cells except current col and get the rows to skip
|
89
|
-
const skipRows = decreaseRowspan(tr, rect, row, _col);
|
90
|
-
return {
|
91
|
-
skipRows,
|
92
|
-
row: {
|
93
|
-
from,
|
94
|
-
to,
|
95
|
-
rowNode: rowNode.copy(rowNode.content)
|
96
|
-
}
|
97
|
-
};
|
98
|
-
}
|
99
|
-
function addRow(tr, rect, prevRow, rowSideEffect) {
|
100
|
-
const cellNode = rowSideEffect.rowNode.child(0);
|
101
|
-
tr.insert(tr.mapping.map(rowSideEffect.from), rowSideEffect.rowNode);
|
102
|
-
increaseRowSpan(tr, rect, prevRow);
|
103
|
-
return cellNode.attrs.rowspan - 1;
|
104
|
-
}
|
105
|
-
export class RowsSideEffectHandler {
|
106
|
-
constructor(rowsSideEffect) {
|
107
|
-
_defineProperty(this, "deleteHandler", () => {
|
108
|
-
const newRows = [];
|
109
|
-
return {
|
110
|
-
handle: (tr, rect, row, col, cell) => {
|
111
|
-
if (!isLastCellInRow(rect, row, col)) {
|
112
|
-
return {
|
113
|
-
handled: false
|
114
|
-
};
|
115
|
-
}
|
116
|
-
const {
|
117
|
-
row: rowSideEffect,
|
118
|
-
skipRows
|
119
|
-
} = removeRowWithLastCell(tr, rect, row, col);
|
120
|
-
newRows.push(rowSideEffect);
|
121
|
-
return {
|
122
|
-
handled: true,
|
123
|
-
skipRows: skipRows
|
124
|
-
};
|
125
|
-
},
|
126
|
-
end: () => {
|
127
|
-
if (newRows.length > 0) {
|
128
|
-
this.rows = newRows;
|
129
|
-
} else {
|
130
|
-
this.rows = undefined;
|
131
|
-
}
|
132
|
-
}
|
133
|
-
};
|
134
|
-
});
|
135
|
-
_defineProperty(this, "addHandler", () => {
|
136
|
-
let lastCellFrom = 0;
|
137
|
-
let i = 0;
|
138
|
-
return {
|
139
|
-
handle: (tr, rect, row, col, cell) => {
|
140
|
-
// // If not sideEffects stored return;
|
141
|
-
if (!this.rows || i >= this.rows.length) {
|
142
|
-
return {
|
143
|
-
handled: false
|
144
|
-
};
|
145
|
-
}
|
146
|
-
|
147
|
-
// Next row to add;
|
148
|
-
let skipRows;
|
149
|
-
let nextRow;
|
150
|
-
while ((nextRow = this.rows[i]) && nextRow.from > lastCellFrom && nextRow.from < cell.from) {
|
151
|
-
// I am in between of the previous and next row in the table;
|
152
|
-
skipRows = addRow(tr, rect, row - 1, nextRow);
|
153
|
-
i++;
|
154
|
-
}
|
155
|
-
lastCellFrom = cell.from;
|
156
|
-
if (!skipRows || skipRows === 0) {
|
157
|
-
return {
|
158
|
-
handled: false
|
159
|
-
};
|
160
|
-
}
|
161
|
-
return {
|
162
|
-
handled: true,
|
163
|
-
skipRows: skipRows - 1
|
164
|
-
};
|
165
|
-
},
|
166
|
-
end: (tr, rect, col) => {
|
167
|
-
if (!this.rows || i >= this.rows.length) {
|
168
|
-
return;
|
169
|
-
}
|
170
|
-
|
171
|
-
// Add rows at the end of the table
|
172
|
-
let nextRow;
|
173
|
-
while (nextRow = this.rows[i]) {
|
174
|
-
addRow(tr, rect, rect.map.height - 1, nextRow);
|
175
|
-
i++;
|
176
|
-
}
|
177
|
-
}
|
178
|
-
};
|
179
|
-
});
|
180
|
-
this.rows = rowsSideEffect;
|
181
|
-
}
|
182
|
-
start(isDelete) {
|
183
|
-
if (isDelete) {
|
184
|
-
return this.deleteHandler();
|
185
|
-
}
|
186
|
-
return this.addHandler();
|
187
|
-
}
|
188
|
-
addRowRanges(ranges, isDelete) {
|
189
|
-
if (!this.rows) {
|
190
|
-
return ranges;
|
191
|
-
}
|
192
|
-
const rowRanges = [];
|
193
|
-
for (const row of this.rows) {
|
194
|
-
const {
|
195
|
-
from,
|
196
|
-
to
|
197
|
-
} = row;
|
198
|
-
if (isDelete) {
|
199
|
-
rowRanges.push(from, to - from, 0);
|
200
|
-
} else {
|
201
|
-
rowRanges.push(from, 0, to - from);
|
202
|
-
}
|
203
|
-
}
|
204
|
-
|
205
|
-
// Merged ranges
|
206
|
-
return mergedRanges(ranges, rowRanges);
|
207
|
-
}
|
208
|
-
map(mapping) {
|
209
|
-
return [];
|
210
|
-
}
|
211
|
-
invert(originalDoc, isDelete, map) {
|
212
|
-
if (!this.rows) {
|
213
|
-
return;
|
214
|
-
}
|
215
|
-
const invertedRows = [];
|
216
|
-
for (const row of this.rows) {
|
217
|
-
if (isDelete) {
|
218
|
-
// Moving from delete to add keep the inverted rows + offset
|
219
|
-
let offset = map.map(row.from) - row.from;
|
220
|
-
invertedRows.push({
|
221
|
-
...row,
|
222
|
-
from: row.from + offset,
|
223
|
-
to: row.from + offset
|
224
|
-
});
|
225
|
-
} else {
|
226
|
-
// Moving from add to delete keep
|
227
|
-
// TODO: I think we need to add the respective cell into the cellSteps...... not sure....
|
228
|
-
}
|
229
|
-
}
|
230
|
-
return invertedRows;
|
231
|
-
}
|
232
|
-
toJSON() {
|
233
|
-
if (!this.rows) {
|
234
|
-
return;
|
235
|
-
}
|
236
|
-
const rowsInJson = [];
|
237
|
-
for (const row of this.rows) {
|
238
|
-
rowsInJson.push({
|
239
|
-
from: row.from,
|
240
|
-
to: row.to,
|
241
|
-
rowNode: row.rowNode.toJSON()
|
242
|
-
});
|
243
|
-
}
|
244
|
-
return rowsInJson;
|
245
|
-
}
|
246
|
-
static fromJSON(schema, json) {
|
247
|
-
const rowSideEffects = [];
|
248
|
-
for (const row of json) {
|
249
|
-
rowSideEffects.push({
|
250
|
-
from: row.from,
|
251
|
-
to: row.to,
|
252
|
-
rowNode: schema.nodeFromJSON(row.rowNode)
|
253
|
-
});
|
254
|
-
}
|
255
|
-
return rowSideEffects;
|
256
|
-
}
|
257
|
-
}
|
@@ -1,60 +0,0 @@
|
|
1
|
-
import { TableSideEffectHandler } from './table';
|
2
|
-
import { RowsSideEffectHandler } from './rows';
|
3
|
-
export class SideEffectsHandler {
|
4
|
-
constructor(sideEffects) {
|
5
|
-
this.table = new TableSideEffectHandler(sideEffects && sideEffects.table);
|
6
|
-
this.rows = new RowsSideEffectHandler(sideEffects && sideEffects.rows);
|
7
|
-
}
|
8
|
-
getTableMap(isDelete) {
|
9
|
-
return this.table.getTableMap(isDelete);
|
10
|
-
}
|
11
|
-
map(mapping) {
|
12
|
-
const sideEffects = {};
|
13
|
-
const tableSideEffect = this.table.map(mapping);
|
14
|
-
const rowsSideEffect = this.rows.map(mapping);
|
15
|
-
if (tableSideEffect) {
|
16
|
-
sideEffects.table = tableSideEffect;
|
17
|
-
}
|
18
|
-
if (rowsSideEffect) {
|
19
|
-
sideEffects.rows = rowsSideEffect;
|
20
|
-
}
|
21
|
-
return sideEffects;
|
22
|
-
}
|
23
|
-
invert(originalDoc, isDelete, map) {
|
24
|
-
const sideEffects = {};
|
25
|
-
const tableSideEffect = this.table.invert(originalDoc);
|
26
|
-
if (tableSideEffect) {
|
27
|
-
sideEffects.table = tableSideEffect;
|
28
|
-
}
|
29
|
-
const rowsSideEffect = this.rows.invert(originalDoc, isDelete, map);
|
30
|
-
if (rowsSideEffect) {
|
31
|
-
sideEffects.rows = rowsSideEffect;
|
32
|
-
}
|
33
|
-
return sideEffects;
|
34
|
-
}
|
35
|
-
toJSON() {
|
36
|
-
const tableSideEffectJson = this.table.toJSON();
|
37
|
-
const rowsSideEffectJson = this.rows.toJSON();
|
38
|
-
if (!tableSideEffectJson && !rowsSideEffectJson) {
|
39
|
-
return;
|
40
|
-
}
|
41
|
-
const sideEffectsJSON = {};
|
42
|
-
if (tableSideEffectJson) {
|
43
|
-
sideEffectsJSON.table = tableSideEffectJson;
|
44
|
-
}
|
45
|
-
if (rowsSideEffectJson) {
|
46
|
-
sideEffectsJSON.rows = rowsSideEffectJson;
|
47
|
-
}
|
48
|
-
return sideEffectsJSON;
|
49
|
-
}
|
50
|
-
static fromJSON(schema, json) {
|
51
|
-
const sideEffects = {};
|
52
|
-
if (json.table) {
|
53
|
-
sideEffects.table = TableSideEffectHandler.fromJSON(schema, json.table);
|
54
|
-
}
|
55
|
-
if (json.rows) {
|
56
|
-
sideEffects.rows = RowsSideEffectHandler.fromJSON(schema, json.rows);
|
57
|
-
}
|
58
|
-
return sideEffects;
|
59
|
-
}
|
60
|
-
}
|
@@ -1,82 +0,0 @@
|
|
1
|
-
import { StepMap } from '@atlaskit/editor-prosemirror/transform';
|
2
|
-
export class TableSideEffectHandler {
|
3
|
-
constructor(tableSideEffect) {
|
4
|
-
if (tableSideEffect) {
|
5
|
-
this.table = tableSideEffect;
|
6
|
-
}
|
7
|
-
}
|
8
|
-
addTableSideEffect(from, to, node) {
|
9
|
-
this.table = {
|
10
|
-
from,
|
11
|
-
to,
|
12
|
-
node
|
13
|
-
};
|
14
|
-
}
|
15
|
-
handleAddTable(tr, isDelete) {
|
16
|
-
if (isDelete || !this.table) {
|
17
|
-
return false;
|
18
|
-
}
|
19
|
-
tr.insert(this.table.from, this.table.node);
|
20
|
-
return true;
|
21
|
-
}
|
22
|
-
handleRemoveTable(tr, tablePos, tableRect, column, isDelete) {
|
23
|
-
if (isDelete && tableRect.map.width === 1 && column === 0) {
|
24
|
-
// Add side effect
|
25
|
-
this.addTableSideEffect(tablePos, tablePos + tableRect.table.nodeSize, tableRect.table.copy(tableRect.table.content));
|
26
|
-
tr.delete(tablePos, tablePos + tableRect.table.nodeSize);
|
27
|
-
return true;
|
28
|
-
}
|
29
|
-
return false;
|
30
|
-
}
|
31
|
-
getTableMap(isDelete) {
|
32
|
-
if (!this.table) {
|
33
|
-
return;
|
34
|
-
}
|
35
|
-
const {
|
36
|
-
from,
|
37
|
-
to
|
38
|
-
} = this.table;
|
39
|
-
if (isDelete) {
|
40
|
-
return new StepMap([from, to - from, 0]);
|
41
|
-
}
|
42
|
-
return new StepMap([from, 0, to - from]);
|
43
|
-
}
|
44
|
-
map(mapping) {
|
45
|
-
if (!this.table) {
|
46
|
-
return;
|
47
|
-
}
|
48
|
-
return {
|
49
|
-
from: mapping.map(this.table.from),
|
50
|
-
to: mapping.map(this.table.to),
|
51
|
-
node: this.table.node
|
52
|
-
};
|
53
|
-
}
|
54
|
-
invert(doc) {
|
55
|
-
if (!this.table) {
|
56
|
-
return;
|
57
|
-
}
|
58
|
-
const tableNode = doc.nodeAt(this.table.from);
|
59
|
-
return {
|
60
|
-
from: this.table.from,
|
61
|
-
to: this.table.from + tableNode.nodeSize,
|
62
|
-
node: tableNode.copy(tableNode.content)
|
63
|
-
};
|
64
|
-
}
|
65
|
-
toJSON() {
|
66
|
-
if (!this.table) {
|
67
|
-
return;
|
68
|
-
}
|
69
|
-
return {
|
70
|
-
from: this.table.from,
|
71
|
-
to: this.table.to,
|
72
|
-
node: this.table.node.toJSON()
|
73
|
-
};
|
74
|
-
}
|
75
|
-
static fromJSON(schema, json) {
|
76
|
-
return {
|
77
|
-
from: json.from,
|
78
|
-
to: json.to,
|
79
|
-
node: schema.nodeFromJSON(json.node)
|
80
|
-
};
|
81
|
-
}
|
82
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,19 +0,0 @@
|
|
1
|
-
export const getCellIndex = (map, row, col) => {
|
2
|
-
return row * map.width + col;
|
3
|
-
};
|
4
|
-
export function hasMergedColumns(map, row, col) {
|
5
|
-
const index = getCellIndex(map, row, col);
|
6
|
-
return col > 0 && map.map[index - 1] === map.map[index] || col < map.width - 1 && map.map[index + 1] === map.map[index];
|
7
|
-
}
|
8
|
-
export function hasMergedRows(map, row, col) {
|
9
|
-
const index = getCellIndex(map, row, col);
|
10
|
-
return row > 0 && map.map[index - map.width] !== map.map[index] || row < map.height - 1 && map.map[index + map.width] === map.map[index];
|
11
|
-
}
|
12
|
-
export function isRootRow(map, row, col) {
|
13
|
-
const index = getCellIndex(map, row, col);
|
14
|
-
return row > 0 ? map.map[index - map.width] !== map.map[index] : true;
|
15
|
-
}
|
16
|
-
export function isRootCol(map, row, col) {
|
17
|
-
const index = getCellIndex(map, row, col);
|
18
|
-
return row > 0 ? map.map[index - 1] !== map.map[index] : true;
|
19
|
-
}
|