@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.
Files changed (67) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/schema/default-schema.js +0 -1
  3. package/dist/cjs/schema/nodes/tableNodes.js +9 -8
  4. package/dist/cjs/steps.js +0 -21
  5. package/dist/es2019/schema/default-schema.js +1 -2
  6. package/dist/es2019/schema/nodes/tableNodes.js +10 -9
  7. package/dist/es2019/steps.js +0 -3
  8. package/dist/esm/schema/default-schema.js +1 -2
  9. package/dist/esm/schema/nodes/tableNodes.js +9 -8
  10. package/dist/esm/steps.js +0 -3
  11. package/dist/json-schema/v1/full.json +3 -0
  12. package/dist/types/schema/nodes/tableNodes.d.ts +8 -5
  13. package/dist/types/steps.d.ts +0 -4
  14. package/json-schema/v1/full.json +3 -0
  15. package/package.json +1 -2
  16. package/dist/cjs/steps/table/add-column.js +0 -381
  17. package/dist/cjs/steps/table/constants.js +0 -12
  18. package/dist/cjs/steps/table/sort-column.js +0 -68
  19. package/dist/cjs/steps/table/types.js +0 -5
  20. package/dist/cjs/steps/table/utils/cell-step.js +0 -202
  21. package/dist/cjs/steps/table/utils/cells-at-column.js +0 -73
  22. package/dist/cjs/steps/table/utils/find-column.js +0 -90
  23. package/dist/cjs/steps/table/utils/get-table-rect-from-doc.js +0 -36
  24. package/dist/cjs/steps/table/utils/side-effects/rows.js +0 -315
  25. package/dist/cjs/steps/table/utils/side-effects/side-effects.js +0 -83
  26. package/dist/cjs/steps/table/utils/side-effects/table.js +0 -110
  27. package/dist/cjs/steps/table/utils/side-effects/types.js +0 -5
  28. package/dist/cjs/steps/table/utils/table-map.js +0 -30
  29. package/dist/es2019/steps/table/add-column.js +0 -306
  30. package/dist/es2019/steps/table/constants.js +0 -5
  31. package/dist/es2019/steps/table/sort-column.js +0 -34
  32. package/dist/es2019/steps/table/types.js +0 -1
  33. package/dist/es2019/steps/table/utils/cell-step.js +0 -187
  34. package/dist/es2019/steps/table/utils/cells-at-column.js +0 -52
  35. package/dist/es2019/steps/table/utils/find-column.js +0 -83
  36. package/dist/es2019/steps/table/utils/get-table-rect-from-doc.js +0 -31
  37. package/dist/es2019/steps/table/utils/side-effects/rows.js +0 -257
  38. package/dist/es2019/steps/table/utils/side-effects/side-effects.js +0 -60
  39. package/dist/es2019/steps/table/utils/side-effects/table.js +0 -82
  40. package/dist/es2019/steps/table/utils/side-effects/types.js +0 -1
  41. package/dist/es2019/steps/table/utils/table-map.js +0 -19
  42. package/dist/esm/steps/table/add-column.js +0 -373
  43. package/dist/esm/steps/table/constants.js +0 -5
  44. package/dist/esm/steps/table/sort-column.js +0 -60
  45. package/dist/esm/steps/table/types.js +0 -1
  46. package/dist/esm/steps/table/utils/cell-step.js +0 -192
  47. package/dist/esm/steps/table/utils/cells-at-column.js +0 -66
  48. package/dist/esm/steps/table/utils/find-column.js +0 -84
  49. package/dist/esm/steps/table/utils/get-table-rect-from-doc.js +0 -31
  50. package/dist/esm/steps/table/utils/side-effects/rows.js +0 -307
  51. package/dist/esm/steps/table/utils/side-effects/side-effects.js +0 -75
  52. package/dist/esm/steps/table/utils/side-effects/table.js +0 -102
  53. package/dist/esm/steps/table/utils/side-effects/types.js +0 -1
  54. package/dist/esm/steps/table/utils/table-map.js +0 -19
  55. package/dist/types/steps/table/add-column.d.ts +0 -88
  56. package/dist/types/steps/table/constants.d.ts +0 -4
  57. package/dist/types/steps/table/sort-column.d.ts +0 -18
  58. package/dist/types/steps/table/types.d.ts +0 -39
  59. package/dist/types/steps/table/utils/cell-step.d.ts +0 -47
  60. package/dist/types/steps/table/utils/cells-at-column.d.ts +0 -20
  61. package/dist/types/steps/table/utils/find-column.d.ts +0 -8
  62. package/dist/types/steps/table/utils/get-table-rect-from-doc.d.ts +0 -8
  63. package/dist/types/steps/table/utils/side-effects/rows.d.ts +0 -25
  64. package/dist/types/steps/table/utils/side-effects/side-effects.d.ts +0 -15
  65. package/dist/types/steps/table/utils/side-effects/table.d.ts +0 -16
  66. package/dist/types/steps/table/utils/side-effects/types.d.ts +0 -33
  67. package/dist/types/steps/table/utils/table-map.d.ts +0 -6
@@ -1,66 +0,0 @@
1
- import _regeneratorRuntime from "@babel/runtime/regenerator";
2
- var _marked = /*#__PURE__*/_regeneratorRuntime.mark(cellsAtColumn);
3
- import { columnIsHeader, tableNodeTypes } from '@atlaskit/editor-tables/utils';
4
- import { getCellIndex, hasMergedColumns, isRootRow } from './table-map';
5
- /**
6
- * Helper to have a consistent way to iterate for all the cells in a column.
7
- * You can skip rows by passing the rows to skipped in the next arguments.
8
- * For example: `iter.next(1)` to skip the next row
9
- * @param rect
10
- * @param col
11
- */
12
- export function cellsAtColumn(rect, col) {
13
- var map, tableStart, table, refColumn, row, index, pos, hasMergedCells, type, cell, cellInfo, skippedRows;
14
- return _regeneratorRuntime.wrap(function cellsAtColumn$(_context) {
15
- while (1) switch (_context.prev = _context.next) {
16
- case 0:
17
- map = rect.map, tableStart = rect.tableStart, table = rect.table;
18
- refColumn = col > 0 ? -1 : 0;
19
- if (columnIsHeader(map, table, col + refColumn)) {
20
- refColumn = col === 0 || col === map.width ? null : 0;
21
- }
22
- row = 0;
23
- case 4:
24
- if (!(row < map.height)) {
25
- _context.next = 20;
26
- break;
27
- }
28
- index = getCellIndex(rect.map, row, col);
29
- pos = map.map[index]; // We only consider to has merged cell to the first cell in a rowspan.
30
- hasMergedCells = hasMergedColumns(rect.map, row, col) && isRootRow(rect.map, row, col); // If this position falls inside a col-spanning cell
31
- type = refColumn == null ? tableNodeTypes(table.type.schema).cell : table.nodeAt(map.map[index + refColumn]).type;
32
- if (!hasMergedCells) {
33
- pos = map.positionAt(row, col, table);
34
- }
35
- cell = table.nodeAt(pos);
36
- cellInfo = {
37
- from: tableStart + pos,
38
- to: tableStart + pos,
39
- row: row,
40
- col: hasMergedCells ? map.colCount(pos) : col,
41
- type: type,
42
- hasMergedCells: hasMergedCells
43
- };
44
- if (cell) {
45
- cellInfo.attrs = cell.attrs;
46
- cellInfo.to = tableStart + pos + cell.nodeSize;
47
- }
48
-
49
- // We let the consumer to pass the rows that we want to skip
50
- _context.next = 15;
51
- return cellInfo;
52
- case 15:
53
- skippedRows = _context.sent;
54
- if (skippedRows && skippedRows > 0) {
55
- row += skippedRows;
56
- }
57
- case 17:
58
- row++;
59
- _context.next = 4;
60
- break;
61
- case 20:
62
- case "end":
63
- return _context.stop();
64
- }
65
- }, _marked);
66
- }
@@ -1,84 +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
- var start = 0,
35
- end = rect.map.width - 1;
36
- var iter = columnInfo.values();
37
- var next = iter.next();
38
-
39
- // Iterate for each row
40
- for (var row = 0; row < rect.map.height; row++) {
41
- if (next.done) {
42
- break;
43
- }
44
- // Iterate for the column. Starting with the current start range
45
- for (var col = start; col <= end; col++) {
46
- var i = row * rect.map.width + col;
47
- var cell = rect.map.map[i];
48
- var cellInfo = next.value.from - rect.tableStart;
49
-
50
- // When cell is found update range with the new values
51
- if (cell === cellInfo) {
52
- start = col; // Start column will be the current column
53
- // Try to find the end column. End column will be different that start when has merged cells.
54
- var endIndex = end - start + i;
55
- for (var j = i; j <= endIndex; j++) {
56
- if (rect.map.map[j] !== cell) {
57
- break;
58
- }
59
-
60
- // merged columns
61
- end = start + j - i; // Update the end column with the new position
62
- }
63
-
64
- if (start === end) {
65
- // We found the right column only when start and end columns are the same.
66
- return start;
67
- }
68
- next = iter.next();
69
- break;
70
- }
71
-
72
- // 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).
73
- // This is represented by the end position of the last cell in the column.
74
- // In this case return, table width
75
- if (col === rect.map.width - 1) {
76
- var cellNode = rect.table.nodeAt(cell);
77
- if (cell + cellNode.nodeSize === cellInfo) {
78
- return rect.map.width;
79
- }
80
- }
81
- }
82
- }
83
- return null;
84
- }
@@ -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
- var 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 \"".concat(tablePos, "\"."));
14
- }
15
-
16
- // Create transform base on the doc
17
- var map = TableMap.get(table);
18
- var $table = doc.resolve(tablePos);
19
- // Nested tables start position might differ from the original position
20
- var start = $table.start($table.depth + 1);
21
- return {
22
- map: 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,307 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
5
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
6
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
7
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
8
- 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; }
9
- 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) { _defineProperty(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; }
10
- import { hasMergedColumns } from '../table-map';
11
- function mergedRanges(first, second) {
12
- var newRanges = [];
13
- var firstLength = first.length;
14
- var secondLength = second.length;
15
- var i = 0;
16
- var j = 0;
17
- while (i < firstLength && j < secondLength) {
18
- if (first[i] < second[j]) {
19
- newRanges.push(first[i], first[i + 1], first[i + 2]);
20
- i += 3;
21
- } else {
22
- newRanges.push(second[j], second[j + 1], second[j + 2]);
23
- j += 3;
24
- }
25
- }
26
- if (i < firstLength) {
27
- newRanges.push.apply(newRanges, _toConsumableArray(first.slice(i)));
28
- }
29
- if (j < secondLength) {
30
- newRanges.push.apply(newRanges, _toConsumableArray(second.slice(i)));
31
- }
32
- return newRanges;
33
- }
34
- function increaseRowSpan(tr, rect, row) {
35
- var map = rect.map,
36
- tableStart = rect.tableStart;
37
- for (var _col2 = 0; _col2 < map.width; _col2++) {
38
- var index = row * map.width + _col2;
39
- var pos = map.map[index];
40
- var mappedPos = tr.mapping.map(pos + tableStart);
41
- var attrs = tr.doc.nodeAt(mappedPos).attrs;
42
- tr.setNodeMarkup(mappedPos, undefined, _objectSpread(_objectSpread({}, attrs), {}, {
43
- rowspan: attrs.rowspan + 1
44
- }));
45
- _col2 += attrs.colspan - 1;
46
- }
47
- }
48
- function decreaseRowspan(tr, rect, row, colToRemove) {
49
- var skipRows = 0;
50
- var map = rect.map,
51
- table = rect.table,
52
- tableStart = rect.tableStart;
53
- for (var _col3 = 0; _col3 < map.width; _col3++) {
54
- var index = row * map.width + _col3;
55
- var pos = map.map[index];
56
- if (row > 0 && pos === map.map[index - map.width]) {
57
- // If this cell starts in the row above, simply reduce its rowspan
58
- var mappedPos = tr.mapping.map(pos + tableStart);
59
- var attrs = tr.doc.nodeAt(mappedPos).attrs;
60
- tr.setNodeMarkup(mappedPos, undefined, _objectSpread(_objectSpread({}, attrs), {}, {
61
- rowspan: attrs.rowspan - 1
62
- }));
63
- _col3 += attrs.colspan - 1;
64
- } else if (_col3 === colToRemove) {
65
- skipRows = table.nodeAt(pos).attrs.rowspan - 1;
66
- }
67
- }
68
- return skipRows;
69
- }
70
- function isLastCellInRow(rect, row, col) {
71
- var rowNode = rect.table.child(row);
72
- if (!rowNode) {
73
- return false;
74
- }
75
- return rowNode.childCount === 1 && !hasMergedColumns(rect.map, row, col);
76
- }
77
- function removeRowWithLastCell(tr, rect, row, _col) {
78
- // Get row pos
79
- var from = rect.tableStart;
80
- for (var i = 0; i < row; i++) {
81
- from += rect.table.child(i).nodeSize;
82
- }
83
- var rowNode = rect.table.child(row);
84
- var to = from + rowNode.nodeSize;
85
-
86
- // Create sideEffect and delete the row
87
- // We store original row position before modifications
88
- tr.delete(tr.mapping.map(from), tr.mapping.map(to));
89
-
90
- // Change rowspan of all cells except current col and get the rows to skip
91
- var skipRows = decreaseRowspan(tr, rect, row, _col);
92
- return {
93
- skipRows: skipRows,
94
- row: {
95
- from: from,
96
- to: to,
97
- rowNode: rowNode.copy(rowNode.content)
98
- }
99
- };
100
- }
101
- function addRow(tr, rect, prevRow, rowSideEffect) {
102
- var cellNode = rowSideEffect.rowNode.child(0);
103
- tr.insert(tr.mapping.map(rowSideEffect.from), rowSideEffect.rowNode);
104
- increaseRowSpan(tr, rect, prevRow);
105
- return cellNode.attrs.rowspan - 1;
106
- }
107
- export var RowsSideEffectHandler = /*#__PURE__*/function () {
108
- function RowsSideEffectHandler(rowsSideEffect) {
109
- var _this = this;
110
- _classCallCheck(this, RowsSideEffectHandler);
111
- _defineProperty(this, "deleteHandler", function () {
112
- var newRows = [];
113
- return {
114
- handle: function handle(tr, rect, row, col, cell) {
115
- if (!isLastCellInRow(rect, row, col)) {
116
- return {
117
- handled: false
118
- };
119
- }
120
- var _removeRowWithLastCel = removeRowWithLastCell(tr, rect, row, col),
121
- rowSideEffect = _removeRowWithLastCel.row,
122
- skipRows = _removeRowWithLastCel.skipRows;
123
- newRows.push(rowSideEffect);
124
- return {
125
- handled: true,
126
- skipRows: skipRows
127
- };
128
- },
129
- end: function end() {
130
- if (newRows.length > 0) {
131
- _this.rows = newRows;
132
- } else {
133
- _this.rows = undefined;
134
- }
135
- }
136
- };
137
- });
138
- _defineProperty(this, "addHandler", function () {
139
- var lastCellFrom = 0;
140
- var i = 0;
141
- return {
142
- handle: function handle(tr, rect, row, col, cell) {
143
- // // If not sideEffects stored return;
144
- if (!_this.rows || i >= _this.rows.length) {
145
- return {
146
- handled: false
147
- };
148
- }
149
-
150
- // Next row to add;
151
- var skipRows;
152
- var nextRow;
153
- while ((nextRow = _this.rows[i]) && nextRow.from > lastCellFrom && nextRow.from < cell.from) {
154
- // I am in between of the previous and next row in the table;
155
- skipRows = addRow(tr, rect, row - 1, nextRow);
156
- i++;
157
- }
158
- lastCellFrom = cell.from;
159
- if (!skipRows || skipRows === 0) {
160
- return {
161
- handled: false
162
- };
163
- }
164
- return {
165
- handled: true,
166
- skipRows: skipRows - 1
167
- };
168
- },
169
- end: function end(tr, rect, col) {
170
- if (!_this.rows || i >= _this.rows.length) {
171
- return;
172
- }
173
-
174
- // Add rows at the end of the table
175
- var nextRow;
176
- while (nextRow = _this.rows[i]) {
177
- addRow(tr, rect, rect.map.height - 1, nextRow);
178
- i++;
179
- }
180
- }
181
- };
182
- });
183
- this.rows = rowsSideEffect;
184
- }
185
- _createClass(RowsSideEffectHandler, [{
186
- key: "start",
187
- value: function start(isDelete) {
188
- if (isDelete) {
189
- return this.deleteHandler();
190
- }
191
- return this.addHandler();
192
- }
193
- }, {
194
- key: "addRowRanges",
195
- value: function addRowRanges(ranges, isDelete) {
196
- if (!this.rows) {
197
- return ranges;
198
- }
199
- var rowRanges = [];
200
- var _iterator = _createForOfIteratorHelper(this.rows),
201
- _step;
202
- try {
203
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
204
- var _row = _step.value;
205
- var from = _row.from,
206
- to = _row.to;
207
- if (isDelete) {
208
- rowRanges.push(from, to - from, 0);
209
- } else {
210
- rowRanges.push(from, 0, to - from);
211
- }
212
- }
213
-
214
- // Merged ranges
215
- } catch (err) {
216
- _iterator.e(err);
217
- } finally {
218
- _iterator.f();
219
- }
220
- return mergedRanges(ranges, rowRanges);
221
- }
222
- }, {
223
- key: "map",
224
- value: function map(mapping) {
225
- return [];
226
- }
227
- }, {
228
- key: "invert",
229
- value: function invert(originalDoc, isDelete, map) {
230
- if (!this.rows) {
231
- return;
232
- }
233
- var invertedRows = [];
234
- var _iterator2 = _createForOfIteratorHelper(this.rows),
235
- _step2;
236
- try {
237
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
238
- var _row2 = _step2.value;
239
- if (isDelete) {
240
- // Moving from delete to add keep the inverted rows + offset
241
- var offset = map.map(_row2.from) - _row2.from;
242
- invertedRows.push(_objectSpread(_objectSpread({}, _row2), {}, {
243
- from: _row2.from + offset,
244
- to: _row2.from + offset
245
- }));
246
- } else {
247
- // Moving from add to delete keep
248
- // TODO: I think we need to add the respective cell into the cellSteps...... not sure....
249
- }
250
- }
251
- } catch (err) {
252
- _iterator2.e(err);
253
- } finally {
254
- _iterator2.f();
255
- }
256
- return invertedRows;
257
- }
258
- }, {
259
- key: "toJSON",
260
- value: function toJSON() {
261
- if (!this.rows) {
262
- return;
263
- }
264
- var rowsInJson = [];
265
- var _iterator3 = _createForOfIteratorHelper(this.rows),
266
- _step3;
267
- try {
268
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
269
- var _row3 = _step3.value;
270
- rowsInJson.push({
271
- from: _row3.from,
272
- to: _row3.to,
273
- rowNode: _row3.rowNode.toJSON()
274
- });
275
- }
276
- } catch (err) {
277
- _iterator3.e(err);
278
- } finally {
279
- _iterator3.f();
280
- }
281
- return rowsInJson;
282
- }
283
- }], [{
284
- key: "fromJSON",
285
- value: function fromJSON(schema, json) {
286
- var rowSideEffects = [];
287
- var _iterator4 = _createForOfIteratorHelper(json),
288
- _step4;
289
- try {
290
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
291
- var _row4 = _step4.value;
292
- rowSideEffects.push({
293
- from: _row4.from,
294
- to: _row4.to,
295
- rowNode: schema.nodeFromJSON(_row4.rowNode)
296
- });
297
- }
298
- } catch (err) {
299
- _iterator4.e(err);
300
- } finally {
301
- _iterator4.f();
302
- }
303
- return rowSideEffects;
304
- }
305
- }]);
306
- return RowsSideEffectHandler;
307
- }();
@@ -1,75 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import { TableSideEffectHandler } from './table';
4
- import { RowsSideEffectHandler } from './rows';
5
- export var SideEffectsHandler = /*#__PURE__*/function () {
6
- function SideEffectsHandler(sideEffects) {
7
- _classCallCheck(this, SideEffectsHandler);
8
- this.table = new TableSideEffectHandler(sideEffects && sideEffects.table);
9
- this.rows = new RowsSideEffectHandler(sideEffects && sideEffects.rows);
10
- }
11
- _createClass(SideEffectsHandler, [{
12
- key: "getTableMap",
13
- value: function getTableMap(isDelete) {
14
- return this.table.getTableMap(isDelete);
15
- }
16
- }, {
17
- key: "map",
18
- value: function map(mapping) {
19
- var sideEffects = {};
20
- var tableSideEffect = this.table.map(mapping);
21
- var rowsSideEffect = this.rows.map(mapping);
22
- if (tableSideEffect) {
23
- sideEffects.table = tableSideEffect;
24
- }
25
- if (rowsSideEffect) {
26
- sideEffects.rows = rowsSideEffect;
27
- }
28
- return sideEffects;
29
- }
30
- }, {
31
- key: "invert",
32
- value: function invert(originalDoc, isDelete, map) {
33
- var sideEffects = {};
34
- var tableSideEffect = this.table.invert(originalDoc);
35
- if (tableSideEffect) {
36
- sideEffects.table = tableSideEffect;
37
- }
38
- var rowsSideEffect = this.rows.invert(originalDoc, isDelete, map);
39
- if (rowsSideEffect) {
40
- sideEffects.rows = rowsSideEffect;
41
- }
42
- return sideEffects;
43
- }
44
- }, {
45
- key: "toJSON",
46
- value: function toJSON() {
47
- var tableSideEffectJson = this.table.toJSON();
48
- var rowsSideEffectJson = this.rows.toJSON();
49
- if (!tableSideEffectJson && !rowsSideEffectJson) {
50
- return;
51
- }
52
- var sideEffectsJSON = {};
53
- if (tableSideEffectJson) {
54
- sideEffectsJSON.table = tableSideEffectJson;
55
- }
56
- if (rowsSideEffectJson) {
57
- sideEffectsJSON.rows = rowsSideEffectJson;
58
- }
59
- return sideEffectsJSON;
60
- }
61
- }], [{
62
- key: "fromJSON",
63
- value: function fromJSON(schema, json) {
64
- var sideEffects = {};
65
- if (json.table) {
66
- sideEffects.table = TableSideEffectHandler.fromJSON(schema, json.table);
67
- }
68
- if (json.rows) {
69
- sideEffects.rows = RowsSideEffectHandler.fromJSON(schema, json.rows);
70
- }
71
- return sideEffects;
72
- }
73
- }]);
74
- return SideEffectsHandler;
75
- }();
@@ -1,102 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import { StepMap } from '@atlaskit/editor-prosemirror/transform';
4
- export var TableSideEffectHandler = /*#__PURE__*/function () {
5
- function TableSideEffectHandler(tableSideEffect) {
6
- _classCallCheck(this, TableSideEffectHandler);
7
- if (tableSideEffect) {
8
- this.table = tableSideEffect;
9
- }
10
- }
11
- _createClass(TableSideEffectHandler, [{
12
- key: "addTableSideEffect",
13
- value: function addTableSideEffect(from, to, node) {
14
- this.table = {
15
- from: from,
16
- to: to,
17
- node: node
18
- };
19
- }
20
- }, {
21
- key: "handleAddTable",
22
- value: function handleAddTable(tr, isDelete) {
23
- if (isDelete || !this.table) {
24
- return false;
25
- }
26
- tr.insert(this.table.from, this.table.node);
27
- return true;
28
- }
29
- }, {
30
- key: "handleRemoveTable",
31
- value: function handleRemoveTable(tr, tablePos, tableRect, column, isDelete) {
32
- if (isDelete && tableRect.map.width === 1 && column === 0) {
33
- // Add side effect
34
- this.addTableSideEffect(tablePos, tablePos + tableRect.table.nodeSize, tableRect.table.copy(tableRect.table.content));
35
- tr.delete(tablePos, tablePos + tableRect.table.nodeSize);
36
- return true;
37
- }
38
- return false;
39
- }
40
- }, {
41
- key: "getTableMap",
42
- value: function getTableMap(isDelete) {
43
- if (!this.table) {
44
- return;
45
- }
46
- var _this$table = this.table,
47
- from = _this$table.from,
48
- to = _this$table.to;
49
- if (isDelete) {
50
- return new StepMap([from, to - from, 0]);
51
- }
52
- return new StepMap([from, 0, to - from]);
53
- }
54
- }, {
55
- key: "map",
56
- value: function map(mapping) {
57
- if (!this.table) {
58
- return;
59
- }
60
- return {
61
- from: mapping.map(this.table.from),
62
- to: mapping.map(this.table.to),
63
- node: this.table.node
64
- };
65
- }
66
- }, {
67
- key: "invert",
68
- value: function invert(doc) {
69
- if (!this.table) {
70
- return;
71
- }
72
- var tableNode = doc.nodeAt(this.table.from);
73
- return {
74
- from: this.table.from,
75
- to: this.table.from + tableNode.nodeSize,
76
- node: tableNode.copy(tableNode.content)
77
- };
78
- }
79
- }, {
80
- key: "toJSON",
81
- value: function toJSON() {
82
- if (!this.table) {
83
- return;
84
- }
85
- return {
86
- from: this.table.from,
87
- to: this.table.to,
88
- node: this.table.node.toJSON()
89
- };
90
- }
91
- }], [{
92
- key: "fromJSON",
93
- value: function fromJSON(schema, json) {
94
- return {
95
- from: json.from,
96
- to: json.to,
97
- node: schema.nodeFromJSON(json.node)
98
- };
99
- }
100
- }]);
101
- return TableSideEffectHandler;
102
- }();
@@ -1 +0,0 @@
1
- export {};
@@ -1,19 +0,0 @@
1
- export var getCellIndex = function getCellIndex(map, row, col) {
2
- return row * map.width + col;
3
- };
4
- export function hasMergedColumns(map, row, col) {
5
- var 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
- var 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
- var 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
- var index = getCellIndex(map, row, col);
18
- return row > 0 ? map.map[index - 1] !== map.map[index] : true;
19
- }