@atlaskit/adf-schema 29.2.0 → 30.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/cjs/steps.js +0 -21
- package/dist/es2019/steps.js +0 -3
- package/dist/esm/steps.js +0 -3
- package/dist/types/schema/nodes/tableNodes.d.ts +6 -2
- package/dist/types/steps.d.ts +0 -4
- package/package.json +1 -3
- 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,202 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
5
|
-
value: true
|
6
|
-
});
|
7
|
-
exports.applyCellStep = applyCellStep;
|
8
|
-
exports.createCellStep = createCellStep;
|
9
|
-
exports.getMapFromCellStep = getMapFromCellStep;
|
10
|
-
exports.invertCellStep = invertCellStep;
|
11
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
12
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
13
|
-
var _utils = require("@atlaskit/editor-tables/utils");
|
14
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
15
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
16
|
-
var EmptyCellNodeSize = 4;
|
17
|
-
function calculateRowsToSkip(attrs) {
|
18
|
-
if (attrs && attrs.rowspan) {
|
19
|
-
return attrs.rowspan - 1;
|
20
|
-
}
|
21
|
-
return 0;
|
22
|
-
}
|
23
|
-
|
24
|
-
/**
|
25
|
-
* Given a cell step, this function has to do the specific transformation to executed that step.
|
26
|
-
* It returns the applied cellStep and rows that needs to skip (because it was already handled).
|
27
|
-
* @param tr
|
28
|
-
* @param tableRect
|
29
|
-
* @param cell
|
30
|
-
* @param cellStep
|
31
|
-
* @param isDelete
|
32
|
-
* @param column
|
33
|
-
*/
|
34
|
-
function applyCellStep(tr, tableRect, cell, cellStep, isDelete, column) {
|
35
|
-
// Apply the merge actions,
|
36
|
-
if (cellStep.mergeWith !== undefined) {
|
37
|
-
var cellNode = tr.doc.nodeAt(tr.mapping.map(cellStep.mergeWith));
|
38
|
-
var columns = column - tableRect.map.colCount(cellStep.mergeWith - tableRect.tableStart);
|
39
|
-
var cellAttrs = isDelete ? (0, _utils.removeColSpan)(cellNode.attrs, columns) : (0, _utils.addColSpan)(cellNode.attrs, columns);
|
40
|
-
if (cellAttrs.colspan > 0) {
|
41
|
-
// When colspan is 0 should remove the cell
|
42
|
-
tr.setNodeMarkup(tr.mapping.map(cellStep.mergeWith), undefined, cellAttrs);
|
43
|
-
return {
|
44
|
-
tr: tr,
|
45
|
-
skipRows: calculateRowsToSkip(cellAttrs),
|
46
|
-
cellStep: cellStep
|
47
|
-
};
|
48
|
-
}
|
49
|
-
|
50
|
-
// When the new colspan is 0, I need to change the operation to a delete operation
|
51
|
-
// Update cellStep with the proper data
|
52
|
-
cellStep.from = cellStep.mergeWith;
|
53
|
-
cellStep.to = cellStep.from + cellNode.nodeSize;
|
54
|
-
cellStep.mergeWith = undefined;
|
55
|
-
}
|
56
|
-
var skipRows = 0;
|
57
|
-
// Modify temporary document
|
58
|
-
if (isDelete) {
|
59
|
-
var _cellNode = tr.doc.nodeAt(tr.mapping.map(cellStep.from));
|
60
|
-
skipRows = calculateRowsToSkip(_cellNode.attrs);
|
61
|
-
tr.delete(tr.mapping.map(cellStep.from), tr.mapping.map(cellStep.to));
|
62
|
-
} else {
|
63
|
-
if (cellStep.newCell) {
|
64
|
-
tr.insert(tr.mapping.map(cellStep.from), cellStep.newCell);
|
65
|
-
skipRows = calculateRowsToSkip(cellStep.newCell.attrs);
|
66
|
-
} else {
|
67
|
-
tr.insert(tr.mapping.map(cellStep.from), cell.type.createAndFill());
|
68
|
-
}
|
69
|
-
}
|
70
|
-
return {
|
71
|
-
tr: tr,
|
72
|
-
skipRows: skipRows,
|
73
|
-
cellStep: cellStep
|
74
|
-
};
|
75
|
-
}
|
76
|
-
|
77
|
-
/**
|
78
|
-
* Given a cell step, this functions return un StepMap representing this action.
|
79
|
-
* [position, oldSize, newSize]
|
80
|
-
* @param cellStep
|
81
|
-
* @param isDelete
|
82
|
-
*/
|
83
|
-
function getMapFromCellStep(cellStep, isDelete) {
|
84
|
-
if (cellStep.mergeWith !== undefined) {
|
85
|
-
return [cellStep.mergeWith, 1, 1];
|
86
|
-
}
|
87
|
-
if (isDelete) {
|
88
|
-
return [cellStep.from, cellStep.to - cellStep.from, 0];
|
89
|
-
} else {
|
90
|
-
if (cellStep.newCell) {
|
91
|
-
return [cellStep.from, 0, cellStep.newCell.nodeSize];
|
92
|
-
}
|
93
|
-
return [cellStep.from, 0, EmptyCellNodeSize];
|
94
|
-
}
|
95
|
-
}
|
96
|
-
|
97
|
-
/**
|
98
|
-
* Helper to calculate the offset of the inverted cells.
|
99
|
-
* When you delete consecutive rows in a single step, the position in the generated document
|
100
|
-
* are skipped by the all the changes except your own. (StepMap.map is not valid)
|
101
|
-
* @param map
|
102
|
-
* @param cellStep
|
103
|
-
* @param isDelete
|
104
|
-
*/
|
105
|
-
function getOffset(map, cellStep, isDelete) {
|
106
|
-
if (isDelete) {
|
107
|
-
return map.map(cellStep.from) - cellStep.from;
|
108
|
-
}
|
109
|
-
var _getMapFromCellStep = getMapFromCellStep(cellStep, isDelete),
|
110
|
-
_getMapFromCellStep2 = (0, _slicedToArray2.default)(_getMapFromCellStep, 3),
|
111
|
-
oldSize = _getMapFromCellStep2[1],
|
112
|
-
newSize = _getMapFromCellStep2[2];
|
113
|
-
return map.map(cellStep.from) - cellStep.from - (newSize - oldSize);
|
114
|
-
}
|
115
|
-
|
116
|
-
/**
|
117
|
-
* Given a cell step, this function invert that step.
|
118
|
-
* @param doc
|
119
|
-
* @param getTableRectAndColumn
|
120
|
-
* @param cellStep
|
121
|
-
* @param isDelete
|
122
|
-
* @param stepMap
|
123
|
-
*/
|
124
|
-
function invertCellStep(doc, getTableRectAndColumn, cellStep, isDelete, stepMap) {
|
125
|
-
/**
|
126
|
-
* We need a correct map when a cell is added
|
127
|
-
* We need the normal map position minus the size of the cell you added it. Why?
|
128
|
-
* Having a table 3x3 and we add a new column at 2 creates this ranges
|
129
|
-
* [
|
130
|
-
* 10, 0, 4,
|
131
|
-
* 20, 0, 4,
|
132
|
-
* 30, 0, 4,
|
133
|
-
* ]
|
134
|
-
* Where:
|
135
|
-
* * [10, 20, 30] are the original cell positions where we add the cells
|
136
|
-
* * [0, 0, 0] are the old size. We are adding new cells, so it's always zero
|
137
|
-
* * [4, 4, 4] are the new size. In this case, we are adding empty cell and has size 4, this will be different for prefill cells.
|
138
|
-
* In the document generated the cells that I want to delete (if I invert this step) are [10, 24, 38]
|
139
|
-
* this is calculated in the given way
|
140
|
-
* * Map the position using this step mapping function, this will return the cell in the next column
|
141
|
-
* * Remove the diff (4 - 0 in this case) of the current position.
|
142
|
-
* For a delete action this not happen, it will always return the right value
|
143
|
-
*/
|
144
|
-
var offset = getOffset(stepMap, cellStep, isDelete);
|
145
|
-
var newCellStepInfo = _objectSpread(_objectSpread({}, cellStep), {}, {
|
146
|
-
// Map the position to position of the generated document
|
147
|
-
from: cellStep.from + offset,
|
148
|
-
to: cellStep.to + offset
|
149
|
-
});
|
150
|
-
if (cellStep.mergeWith !== undefined) {
|
151
|
-
newCellStepInfo.mergeWith = cellStep.mergeWith + offset;
|
152
|
-
}
|
153
|
-
if (isDelete) {
|
154
|
-
// Add the removed cell as the new cell of the inverted step
|
155
|
-
var removedCell = doc.nodeAt(cellStep.from);
|
156
|
-
newCellStepInfo.newCell = removedCell.copy(removedCell.content);
|
157
|
-
|
158
|
-
// When we delete a column we can end in a position that doesnt represent the right column.
|
159
|
-
// This only happens on merged cell that ends in the deleted column.
|
160
|
-
// We need to remap this position to the "next" cell (AKA cellStep.to)
|
161
|
-
var _getTableRectAndColum = getTableRectAndColumn(),
|
162
|
-
column = _getTableRectAndColum.column,
|
163
|
-
rect = _getTableRectAndColum.rect;
|
164
|
-
if (column < rect.map.width) {
|
165
|
-
var isAtTheEnd = rect.map.colCount(cellStep.from - rect.tableStart) + removedCell.attrs.colspan - 1 === column;
|
166
|
-
if (cellStep.mergeWith !== undefined && isAtTheEnd) {
|
167
|
-
newCellStepInfo.mergeWith = newCellStepInfo.from;
|
168
|
-
newCellStepInfo.from = newCellStepInfo.to;
|
169
|
-
}
|
170
|
-
}
|
171
|
-
}
|
172
|
-
return newCellStepInfo;
|
173
|
-
}
|
174
|
-
|
175
|
-
/**
|
176
|
-
* Create a cell step based on the current cell and operation (add/delete)
|
177
|
-
* @param cell
|
178
|
-
* @param column
|
179
|
-
* @param isDelete
|
180
|
-
* @param previousCellStep
|
181
|
-
*/
|
182
|
-
function createCellStep(cell, column, isDelete, previousCellStep) {
|
183
|
-
var newCellStepInfo = {
|
184
|
-
from: cell.from,
|
185
|
-
to: cell.to
|
186
|
-
};
|
187
|
-
if (cell.hasMergedCells) {
|
188
|
-
// Check what column has to merge
|
189
|
-
if (column !== cell.col || isDelete) {
|
190
|
-
newCellStepInfo.mergeWith = cell.from;
|
191
|
-
}
|
192
|
-
}
|
193
|
-
if (previousCellStep) {
|
194
|
-
if (previousCellStep.mergeWith !== undefined) {
|
195
|
-
newCellStepInfo.mergeWith = previousCellStep.mergeWith;
|
196
|
-
}
|
197
|
-
if (previousCellStep.newCell) {
|
198
|
-
newCellStepInfo.newCell = previousCellStep.newCell;
|
199
|
-
}
|
200
|
-
}
|
201
|
-
return newCellStepInfo;
|
202
|
-
}
|
@@ -1,73 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
5
|
-
value: true
|
6
|
-
});
|
7
|
-
exports.cellsAtColumn = cellsAtColumn;
|
8
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
9
|
-
var _utils = require("@atlaskit/editor-tables/utils");
|
10
|
-
var _tableMap = require("./table-map");
|
11
|
-
var _marked = /*#__PURE__*/_regenerator.default.mark(cellsAtColumn);
|
12
|
-
/**
|
13
|
-
* Helper to have a consistent way to iterate for all the cells in a column.
|
14
|
-
* You can skip rows by passing the rows to skipped in the next arguments.
|
15
|
-
* For example: `iter.next(1)` to skip the next row
|
16
|
-
* @param rect
|
17
|
-
* @param col
|
18
|
-
*/
|
19
|
-
function cellsAtColumn(rect, col) {
|
20
|
-
var map, tableStart, table, refColumn, row, index, pos, hasMergedCells, type, cell, cellInfo, skippedRows;
|
21
|
-
return _regenerator.default.wrap(function cellsAtColumn$(_context) {
|
22
|
-
while (1) switch (_context.prev = _context.next) {
|
23
|
-
case 0:
|
24
|
-
map = rect.map, tableStart = rect.tableStart, table = rect.table;
|
25
|
-
refColumn = col > 0 ? -1 : 0;
|
26
|
-
if ((0, _utils.columnIsHeader)(map, table, col + refColumn)) {
|
27
|
-
refColumn = col === 0 || col === map.width ? null : 0;
|
28
|
-
}
|
29
|
-
row = 0;
|
30
|
-
case 4:
|
31
|
-
if (!(row < map.height)) {
|
32
|
-
_context.next = 20;
|
33
|
-
break;
|
34
|
-
}
|
35
|
-
index = (0, _tableMap.getCellIndex)(rect.map, row, col);
|
36
|
-
pos = map.map[index]; // We only consider to has merged cell to the first cell in a rowspan.
|
37
|
-
hasMergedCells = (0, _tableMap.hasMergedColumns)(rect.map, row, col) && (0, _tableMap.isRootRow)(rect.map, row, col); // If this position falls inside a col-spanning cell
|
38
|
-
type = refColumn == null ? (0, _utils.tableNodeTypes)(table.type.schema).cell : table.nodeAt(map.map[index + refColumn]).type;
|
39
|
-
if (!hasMergedCells) {
|
40
|
-
pos = map.positionAt(row, col, table);
|
41
|
-
}
|
42
|
-
cell = table.nodeAt(pos);
|
43
|
-
cellInfo = {
|
44
|
-
from: tableStart + pos,
|
45
|
-
to: tableStart + pos,
|
46
|
-
row: row,
|
47
|
-
col: hasMergedCells ? map.colCount(pos) : col,
|
48
|
-
type: type,
|
49
|
-
hasMergedCells: hasMergedCells
|
50
|
-
};
|
51
|
-
if (cell) {
|
52
|
-
cellInfo.attrs = cell.attrs;
|
53
|
-
cellInfo.to = tableStart + pos + cell.nodeSize;
|
54
|
-
}
|
55
|
-
|
56
|
-
// We let the consumer to pass the rows that we want to skip
|
57
|
-
_context.next = 15;
|
58
|
-
return cellInfo;
|
59
|
-
case 15:
|
60
|
-
skippedRows = _context.sent;
|
61
|
-
if (skippedRows && skippedRows > 0) {
|
62
|
-
row += skippedRows;
|
63
|
-
}
|
64
|
-
case 17:
|
65
|
-
row++;
|
66
|
-
_context.next = 4;
|
67
|
-
break;
|
68
|
-
case 20:
|
69
|
-
case "end":
|
70
|
-
return _context.stop();
|
71
|
-
}
|
72
|
-
}, _marked);
|
73
|
-
}
|
@@ -1,90 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.findColumn = findColumn;
|
7
|
-
/**
|
8
|
-
* Try to find the right column based on the cell steps in column info..
|
9
|
-
* @param columnInfo - Map of cell positions sorted from lower to greather
|
10
|
-
* @param rect - map rect
|
11
|
-
*/
|
12
|
-
function findColumn(columnInfo, rect) {
|
13
|
-
/**
|
14
|
-
* Algorithm explained
|
15
|
-
* Given a table like this:
|
16
|
-
* | 5 | 10 |
|
17
|
-
* | 15 | 20 |
|
18
|
-
* | 25 | 30 | 35 |
|
19
|
-
* Represented by a table map like this:
|
20
|
-
* rect.map = [5, 10, 10,
|
21
|
-
* 15, 15, 20,
|
22
|
-
* 25, 30, 35]
|
23
|
-
* And a have this inputs:
|
24
|
-
* columnInfo[].from = [10, 15, 30]
|
25
|
-
*
|
26
|
-
* Algorithm:
|
27
|
-
* * Initial state
|
28
|
-
* start = 0;
|
29
|
-
* end = 2 (rect.width - 1 === 3 - 1)
|
30
|
-
* * Iterate until find first cell position
|
31
|
-
* start = 1
|
32
|
-
* end = 2 (min(start column + colspan - 1, start column + end column))
|
33
|
-
* * Iterate until find second cell position
|
34
|
-
* start = 1
|
35
|
-
* end = 1
|
36
|
-
* * Start === end return 1
|
37
|
-
*/
|
38
|
-
|
39
|
-
// Initial range (start and end column) to search for each row
|
40
|
-
var start = 0,
|
41
|
-
end = rect.map.width - 1;
|
42
|
-
var iter = columnInfo.values();
|
43
|
-
var next = iter.next();
|
44
|
-
|
45
|
-
// Iterate for each row
|
46
|
-
for (var row = 0; row < rect.map.height; row++) {
|
47
|
-
if (next.done) {
|
48
|
-
break;
|
49
|
-
}
|
50
|
-
// Iterate for the column. Starting with the current start range
|
51
|
-
for (var col = start; col <= end; col++) {
|
52
|
-
var i = row * rect.map.width + col;
|
53
|
-
var cell = rect.map.map[i];
|
54
|
-
var cellInfo = next.value.from - rect.tableStart;
|
55
|
-
|
56
|
-
// When cell is found update range with the new values
|
57
|
-
if (cell === cellInfo) {
|
58
|
-
start = col; // Start column will be the current column
|
59
|
-
// Try to find the end column. End column will be different that start when has merged cells.
|
60
|
-
var endIndex = end - start + i;
|
61
|
-
for (var j = i; j <= endIndex; j++) {
|
62
|
-
if (rect.map.map[j] !== cell) {
|
63
|
-
break;
|
64
|
-
}
|
65
|
-
|
66
|
-
// merged columns
|
67
|
-
end = start + j - i; // Update the end column with the new position
|
68
|
-
}
|
69
|
-
|
70
|
-
if (start === end) {
|
71
|
-
// We found the right column only when start and end columns are the same.
|
72
|
-
return start;
|
73
|
-
}
|
74
|
-
next = iter.next();
|
75
|
-
break;
|
76
|
-
}
|
77
|
-
|
78
|
-
// 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).
|
79
|
-
// This is represented by the end position of the last cell in the column.
|
80
|
-
// In this case return, table width
|
81
|
-
if (col === rect.map.width - 1) {
|
82
|
-
var cellNode = rect.table.nodeAt(cell);
|
83
|
-
if (cell + cellNode.nodeSize === cellInfo) {
|
84
|
-
return rect.map.width;
|
85
|
-
}
|
86
|
-
}
|
87
|
-
}
|
88
|
-
}
|
89
|
-
return null;
|
90
|
-
}
|
@@ -1,36 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.getTableRectFromDoc = getTableRectFromDoc;
|
7
|
-
var _tableMap = require("@atlaskit/editor-tables/table-map");
|
8
|
-
/**
|
9
|
-
* Util to get the table rect from the docs
|
10
|
-
* @param doc
|
11
|
-
* @param tablePos
|
12
|
-
*/
|
13
|
-
function getTableRectFromDoc(doc, tablePos) {
|
14
|
-
var table = doc.nodeAt(tablePos);
|
15
|
-
|
16
|
-
// Check for table existence
|
17
|
-
if (!table || table.type.name !== 'table') {
|
18
|
-
throw new Error("No table at position \"".concat(tablePos, "\"."));
|
19
|
-
}
|
20
|
-
|
21
|
-
// Create transform base on the doc
|
22
|
-
var map = _tableMap.TableMap.get(table);
|
23
|
-
var $table = doc.resolve(tablePos);
|
24
|
-
// Nested tables start position might differ from the original position
|
25
|
-
var start = $table.start($table.depth + 1);
|
26
|
-
return {
|
27
|
-
map: map,
|
28
|
-
table: table,
|
29
|
-
tableStart: start,
|
30
|
-
// Default to zero
|
31
|
-
bottom: 0,
|
32
|
-
left: 0,
|
33
|
-
right: 0,
|
34
|
-
top: 0
|
35
|
-
};
|
36
|
-
}
|