@atlaskit/editor-tables 2.2.4 → 2.2.6
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/cell-bookmark.js +0 -10
- package/dist/cjs/cell-selection.js +37 -102
- package/dist/cjs/index.js +0 -4
- package/dist/cjs/pm-plugins/input.js +17 -83
- package/dist/cjs/pm-plugins/plugin-key.js +0 -2
- package/dist/cjs/pm-plugins/table-editing.js +17 -18
- package/dist/cjs/pm-plugins.js +0 -2
- package/dist/cjs/table-map.js +67 -138
- package/dist/cjs/utils/add-column-at.js +0 -9
- package/dist/cjs/utils/add-column.js +8 -24
- package/dist/cjs/utils/add-row-at.js +8 -37
- package/dist/cjs/utils/add-row.js +2 -23
- package/dist/cjs/utils/analytics-helpers.js +4 -15
- package/dist/cjs/utils/cells.js +0 -12
- package/dist/cjs/utils/clone-tr.js +0 -2
- package/dist/cjs/utils/colspan.js +2 -18
- package/dist/cjs/utils/copy-paste.js +51 -139
- package/dist/cjs/utils/create-table.js +14 -28
- package/dist/cjs/utils/draw-cell-selection.js +0 -4
- package/dist/cjs/utils/empty-cells.js +0 -6
- package/dist/cjs/utils/find.js +6 -18
- package/dist/cjs/utils/fix-tables.js +13 -56
- package/dist/cjs/utils/for-each-cell.js +3 -17
- package/dist/cjs/utils/get-cell-selection-ranges.js +2 -9
- package/dist/cjs/utils/get-cells-in-column.js +0 -7
- package/dist/cjs/utils/get-cells-in-row.js +0 -7
- package/dist/cjs/utils/get-cells-in-table.js +0 -8
- package/dist/cjs/utils/get-selection-range-in-column.js +6 -27
- package/dist/cjs/utils/get-selection-range-in-row.js +6 -27
- package/dist/cjs/utils/get-selection-rect.js +0 -7
- package/dist/cjs/utils/go-to-next-cell.js +3 -22
- package/dist/cjs/utils/handle-paste.js +5 -34
- package/dist/cjs/utils/is-selected.js +6 -23
- package/dist/cjs/utils/is-selection-type.js +0 -2
- package/dist/cjs/utils/move-column.js +0 -12
- package/dist/cjs/utils/move-row.js +0 -11
- package/dist/cjs/utils/normalize-selection.js +3 -27
- package/dist/cjs/utils/remove-column.js +10 -46
- package/dist/cjs/utils/remove-row.js +8 -49
- package/dist/cjs/utils/remove-table.js +0 -6
- package/dist/cjs/utils/reorder-utils.js +13 -37
- package/dist/cjs/utils/replace-table.js +0 -8
- package/dist/cjs/utils/select-nodes.js +11 -31
- package/dist/cjs/utils/selection-cell.js +0 -5
- package/dist/cjs/utils/selection-rect.js +0 -10
- package/dist/cjs/utils/set-cell-attrs.js +0 -4
- package/dist/cjs/utils/split-cell-with-type.js +2 -35
- package/dist/cjs/utils/split-cell.js +0 -4
- package/dist/cjs/utils/table-node-types.js +4 -8
- package/dist/cjs/utils/tables.js +0 -4
- package/dist/cjs/utils/test-utils.js +9 -26
- package/dist/cjs/utils/toggle-header.js +3 -16
- package/dist/cjs/utils/uuid.js +0 -3
- package/dist/cjs/utils.js +0 -42
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/cell-bookmark.js +0 -5
- package/dist/es2019/cell-selection.js +37 -81
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/pm-plugins/input.js +15 -67
- package/dist/es2019/pm-plugins/table-editing.js +3 -12
- package/dist/es2019/table-map.js +57 -127
- package/dist/es2019/utils/add-column-at.js +2 -4
- package/dist/es2019/utils/add-column.js +6 -16
- package/dist/es2019/utils/add-row-at.js +8 -22
- package/dist/es2019/utils/add-row.js +2 -17
- package/dist/es2019/utils/analytics-helpers.js +0 -5
- package/dist/es2019/utils/cells.js +4 -9
- package/dist/es2019/utils/colspan.js +6 -11
- package/dist/es2019/utils/copy-paste.js +41 -115
- package/dist/es2019/utils/create-table.js +3 -12
- package/dist/es2019/utils/draw-cell-selection.js +0 -1
- package/dist/es2019/utils/empty-cells.js +2 -3
- package/dist/es2019/utils/find.js +8 -8
- package/dist/es2019/utils/fix-tables.js +17 -47
- package/dist/es2019/utils/for-each-cell.js +6 -11
- package/dist/es2019/utils/get-cell-selection-ranges.js +2 -4
- package/dist/es2019/utils/get-cells-in-column.js +2 -3
- package/dist/es2019/utils/get-cells-in-row.js +2 -3
- package/dist/es2019/utils/get-cells-in-table.js +2 -4
- package/dist/es2019/utils/get-selection-range-in-column.js +8 -22
- package/dist/es2019/utils/get-selection-range-in-row.js +8 -22
- package/dist/es2019/utils/get-selection-rect.js +2 -2
- package/dist/es2019/utils/go-to-next-cell.js +3 -19
- package/dist/es2019/utils/handle-paste.js +3 -14
- package/dist/es2019/utils/is-selected.js +8 -10
- package/dist/es2019/utils/is-selection-type.js +0 -1
- package/dist/es2019/utils/move-column.js +3 -8
- package/dist/es2019/utils/move-row.js +3 -7
- package/dist/es2019/utils/normalize-selection.js +0 -16
- package/dist/es2019/utils/remove-column.js +10 -27
- package/dist/es2019/utils/remove-row.js +12 -32
- package/dist/es2019/utils/remove-table.js +2 -4
- package/dist/es2019/utils/reorder-utils.js +11 -26
- package/dist/es2019/utils/replace-table.js +0 -2
- package/dist/es2019/utils/select-nodes.js +9 -20
- package/dist/es2019/utils/selection-cell.js +0 -2
- package/dist/es2019/utils/selection-rect.js +0 -4
- package/dist/es2019/utils/set-cell-attrs.js +2 -2
- package/dist/es2019/utils/split-cell-with-type.js +8 -28
- package/dist/es2019/utils/split-cell.js +3 -2
- package/dist/es2019/utils/table-node-types.js +4 -7
- package/dist/es2019/utils/tables.js +0 -2
- package/dist/es2019/utils/test-utils.js +12 -16
- package/dist/es2019/utils/toggle-header.js +3 -10
- package/dist/es2019/utils/uuid.js +0 -2
- package/dist/es2019/version.json +1 -1
- package/dist/esm/cell-bookmark.js +0 -5
- package/dist/esm/cell-selection.js +37 -79
- package/dist/esm/index.js +1 -0
- package/dist/esm/pm-plugins/input.js +17 -71
- package/dist/esm/pm-plugins/table-editing.js +8 -13
- package/dist/esm/table-map.js +68 -133
- package/dist/esm/utils/add-column-at.js +2 -4
- package/dist/esm/utils/add-column.js +8 -20
- package/dist/esm/utils/add-row-at.js +8 -23
- package/dist/esm/utils/add-row.js +2 -21
- package/dist/esm/utils/analytics-helpers.js +4 -10
- package/dist/esm/utils/cells.js +0 -5
- package/dist/esm/utils/colspan.js +2 -14
- package/dist/esm/utils/copy-paste.js +44 -125
- package/dist/esm/utils/create-table.js +14 -25
- package/dist/esm/utils/draw-cell-selection.js +0 -1
- package/dist/esm/utils/empty-cells.js +2 -3
- package/dist/esm/utils/find.js +8 -8
- package/dist/esm/utils/fix-tables.js +13 -49
- package/dist/esm/utils/for-each-cell.js +6 -11
- package/dist/esm/utils/get-cell-selection-ranges.js +2 -4
- package/dist/esm/utils/get-cells-in-column.js +2 -3
- package/dist/esm/utils/get-cells-in-row.js +2 -3
- package/dist/esm/utils/get-cells-in-table.js +2 -4
- package/dist/esm/utils/get-selection-range-in-column.js +8 -24
- package/dist/esm/utils/get-selection-range-in-row.js +8 -24
- package/dist/esm/utils/get-selection-rect.js +2 -2
- package/dist/esm/utils/go-to-next-cell.js +3 -19
- package/dist/esm/utils/handle-paste.js +5 -23
- package/dist/esm/utils/is-selected.js +8 -10
- package/dist/esm/utils/is-selection-type.js +0 -1
- package/dist/esm/utils/move-column.js +3 -8
- package/dist/esm/utils/move-row.js +3 -7
- package/dist/esm/utils/normalize-selection.js +3 -22
- package/dist/esm/utils/remove-column.js +10 -31
- package/dist/esm/utils/remove-row.js +8 -35
- package/dist/esm/utils/remove-table.js +2 -4
- package/dist/esm/utils/reorder-utils.js +11 -26
- package/dist/esm/utils/replace-table.js +0 -2
- package/dist/esm/utils/select-nodes.js +11 -22
- package/dist/esm/utils/selection-cell.js +0 -2
- package/dist/esm/utils/selection-rect.js +0 -4
- package/dist/esm/utils/set-cell-attrs.js +2 -2
- package/dist/esm/utils/split-cell-with-type.js +2 -28
- package/dist/esm/utils/split-cell.js +3 -2
- package/dist/esm/utils/table-node-types.js +4 -7
- package/dist/esm/utils/tables.js +0 -2
- package/dist/esm/utils/test-utils.js +12 -16
- package/dist/esm/utils/toggle-header.js +3 -10
- package/dist/esm/version.json +1 -1
- package/package.json +6 -4
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
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; } } }; }
|
|
2
|
-
|
|
3
2
|
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); }
|
|
4
|
-
|
|
5
|
-
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; }
|
|
6
|
-
|
|
3
|
+
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; }
|
|
7
4
|
import { Fragment } from 'prosemirror-model';
|
|
8
5
|
import { CellSelection } from '../cell-selection';
|
|
9
6
|
import { TableMap } from '../table-map';
|
|
@@ -15,10 +12,8 @@ export function handlePaste(view, event, slice) {
|
|
|
15
12
|
if (!isInTable(view.state)) {
|
|
16
13
|
return false;
|
|
17
14
|
}
|
|
18
|
-
|
|
19
15
|
var cells = pastedCells(slice);
|
|
20
16
|
var sel = view.state.selection;
|
|
21
|
-
|
|
22
17
|
if (sel instanceof CellSelection) {
|
|
23
18
|
if (!cells) {
|
|
24
19
|
cells = {
|
|
@@ -27,7 +22,6 @@ export function handlePaste(view, event, slice) {
|
|
|
27
22
|
rows: [Fragment.from(fitSlice(tableNodeTypes(view.state.schema).cell, slice))]
|
|
28
23
|
};
|
|
29
24
|
}
|
|
30
|
-
|
|
31
25
|
var table = sel.$anchorCell.node(-1);
|
|
32
26
|
var start = sel.$anchorCell.start(-1);
|
|
33
27
|
var tableMap = TableMap.get(table);
|
|
@@ -36,45 +30,35 @@ export function handlePaste(view, event, slice) {
|
|
|
36
30
|
insertCells(view.state, view.dispatch, start, rect, clearColumnWidthOfCells(cells, rect, tableMap));
|
|
37
31
|
return true;
|
|
38
32
|
}
|
|
39
|
-
|
|
40
33
|
if (cells) {
|
|
41
34
|
var $cell = selectionCell(sel);
|
|
42
|
-
|
|
43
35
|
if (!$cell) {
|
|
44
36
|
throw new Error("handlePaste: no cell found");
|
|
45
37
|
}
|
|
46
|
-
|
|
47
38
|
var _start = $cell.start(-1);
|
|
48
|
-
|
|
49
39
|
var _rect = TableMap.get($cell.node(-1)).findCell($cell.pos - _start);
|
|
50
|
-
|
|
51
40
|
var _tableMap = TableMap.get($cell.node(-1));
|
|
52
|
-
|
|
53
41
|
insertCells(view.state, view.dispatch, _start, _rect, clearColumnWidthOfCells(cells, _rect, _tableMap));
|
|
54
42
|
return true;
|
|
55
43
|
}
|
|
56
|
-
|
|
57
44
|
return false;
|
|
58
|
-
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Clear the pasted cells column widths so that it maintains
|
|
59
48
|
// the column widths of the destination table only if the pasted
|
|
60
49
|
// cells overlap with existing cells in the destination table.
|
|
61
50
|
// If the table grows on paste, keep the column widhts of the
|
|
62
51
|
// original table.
|
|
63
|
-
|
|
64
52
|
var clearColumnWidthOfCells = function clearColumnWidthOfCells(cells, rect, table) {
|
|
65
53
|
var overlappingCells = [];
|
|
66
|
-
|
|
67
54
|
var _iterator = _createForOfIteratorHelper(cells.rows),
|
|
68
|
-
|
|
69
|
-
|
|
55
|
+
_step;
|
|
70
56
|
try {
|
|
71
57
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
72
58
|
var row = _step.value;
|
|
73
59
|
var colNum = rect.left;
|
|
74
|
-
|
|
75
60
|
for (var index = 0; index < row.childCount; index++) {
|
|
76
61
|
var _cell = row.child(index);
|
|
77
|
-
|
|
78
62
|
if (colNum + _cell.attrs.colspan <= table.width) {
|
|
79
63
|
overlappingCells.push(_cell);
|
|
80
64
|
colNum += _cell.attrs.colspan;
|
|
@@ -88,11 +72,9 @@ var clearColumnWidthOfCells = function clearColumnWidthOfCells(cells, rect, tabl
|
|
|
88
72
|
} finally {
|
|
89
73
|
_iterator.f();
|
|
90
74
|
}
|
|
91
|
-
|
|
92
75
|
for (var _i = 0, _overlappingCells = overlappingCells; _i < _overlappingCells.length; _i++) {
|
|
93
76
|
var cell = _overlappingCells[_i];
|
|
94
77
|
cell.attrs.colwidth = null;
|
|
95
78
|
}
|
|
96
|
-
|
|
97
79
|
return cells;
|
|
98
80
|
};
|
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import { TableMap } from '../table-map';
|
|
2
|
-
import { isSelectionType } from './is-selection-type';
|
|
2
|
+
import { isSelectionType } from './is-selection-type';
|
|
3
3
|
|
|
4
|
+
// Checks if a given CellSelection rect is selected
|
|
4
5
|
export var isRectSelected = function isRectSelected(rect) {
|
|
5
6
|
return function (selection) {
|
|
6
7
|
if (!isSelectionType(selection, 'cell')) {
|
|
7
8
|
return false;
|
|
8
9
|
}
|
|
9
|
-
|
|
10
10
|
var map = TableMap.get(selection.$anchorCell.node(-1));
|
|
11
11
|
var start = selection.$anchorCell.start(-1);
|
|
12
12
|
var cells = map.cellsInRect(rect);
|
|
13
13
|
var selectedCells = map.cellsInRect(map.rectBetween(selection.$anchorCell.pos - start, selection.$headCell.pos - start));
|
|
14
|
-
|
|
15
14
|
for (var i = 0, count = cells.length; i < count; i++) {
|
|
16
15
|
if (selectedCells.indexOf(cells[i]) === -1) {
|
|
17
16
|
return false;
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
|
-
|
|
21
19
|
return true;
|
|
22
20
|
};
|
|
23
|
-
};
|
|
21
|
+
};
|
|
24
22
|
|
|
23
|
+
// Checks if entire column at index `columnIndex` is selected.
|
|
25
24
|
export var isColumnSelected = function isColumnSelected(columnIndex) {
|
|
26
25
|
return function (selection) {
|
|
27
26
|
if (isSelectionType(selection, 'cell')) {
|
|
@@ -33,11 +32,11 @@ export var isColumnSelected = function isColumnSelected(columnIndex) {
|
|
|
33
32
|
bottom: map.height
|
|
34
33
|
})(selection);
|
|
35
34
|
}
|
|
36
|
-
|
|
37
35
|
return false;
|
|
38
36
|
};
|
|
39
|
-
};
|
|
37
|
+
};
|
|
40
38
|
|
|
39
|
+
// Checks if entire row at index `rowIndex` is selected.
|
|
41
40
|
export var isRowSelected = function isRowSelected(rowIndex) {
|
|
42
41
|
return function (selection) {
|
|
43
42
|
if (isSelectionType(selection, 'cell')) {
|
|
@@ -49,11 +48,11 @@ export var isRowSelected = function isRowSelected(rowIndex) {
|
|
|
49
48
|
bottom: rowIndex + 1
|
|
50
49
|
})(selection);
|
|
51
50
|
}
|
|
52
|
-
|
|
53
51
|
return false;
|
|
54
52
|
};
|
|
55
|
-
};
|
|
53
|
+
};
|
|
56
54
|
|
|
55
|
+
// Checks if entire table is selected
|
|
57
56
|
export var isTableSelected = function isTableSelected(selection) {
|
|
58
57
|
if (isSelectionType(selection, 'cell')) {
|
|
59
58
|
var map = TableMap.get(selection.$anchorCell.node(-1));
|
|
@@ -64,6 +63,5 @@ export var isTableSelected = function isTableSelected(selection) {
|
|
|
64
63
|
bottom: map.height
|
|
65
64
|
})(selection);
|
|
66
65
|
}
|
|
67
|
-
|
|
68
66
|
return false;
|
|
69
67
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { cloneTr } from './clone-tr';
|
|
2
2
|
import { findTable } from './find';
|
|
3
3
|
import { getSelectionRangeInColumn } from './get-selection-range-in-column';
|
|
4
|
-
import { isValidReorder, moveTableColumn } from './reorder-utils';
|
|
4
|
+
import { isValidReorder, moveTableColumn } from './reorder-utils';
|
|
5
|
+
|
|
6
|
+
// :: (originColumnIndex: number, targetColumnIndex: targetColumnIndex, options?: MovementOptions) → (tr: Transaction) → Transaction
|
|
5
7
|
// Returns a new transaction that moves the origin column to the target index;
|
|
6
8
|
//
|
|
7
9
|
// by default "tryToFit" is false, that means if you try to move a column to a place
|
|
@@ -129,7 +131,6 @@ import { isValidReorder, moveTableColumn } from './reorder-utils'; // :: (origin
|
|
|
129
131
|
// moveColumn(x, y, options)(state.tr)
|
|
130
132
|
// );
|
|
131
133
|
// ```
|
|
132
|
-
|
|
133
134
|
export var moveColumn = function moveColumn(originColumnIndex, targetColumnIndex) {
|
|
134
135
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
135
136
|
tryToFit: false,
|
|
@@ -137,26 +138,20 @@ export var moveColumn = function moveColumn(originColumnIndex, targetColumnIndex
|
|
|
137
138
|
};
|
|
138
139
|
return function (tr) {
|
|
139
140
|
var _originalColumnRanges, _targetColumnRanges$i;
|
|
140
|
-
|
|
141
141
|
var table = findTable(tr.selection);
|
|
142
|
-
|
|
143
142
|
if (!table) {
|
|
144
143
|
return tr;
|
|
145
144
|
}
|
|
146
|
-
|
|
147
145
|
var originalColumnRanges = getSelectionRangeInColumn(originColumnIndex)(tr);
|
|
148
146
|
var targetColumnRanges = getSelectionRangeInColumn(targetColumnIndex)(tr);
|
|
149
147
|
var indexesOriginColumn = (_originalColumnRanges = originalColumnRanges === null || originalColumnRanges === void 0 ? void 0 : originalColumnRanges.indexes) !== null && _originalColumnRanges !== void 0 ? _originalColumnRanges : [];
|
|
150
148
|
var indexesTargetColumn = (_targetColumnRanges$i = targetColumnRanges === null || targetColumnRanges === void 0 ? void 0 : targetColumnRanges.indexes) !== null && _targetColumnRanges$i !== void 0 ? _targetColumnRanges$i : [];
|
|
151
|
-
|
|
152
149
|
if (indexesOriginColumn.includes(targetColumnIndex)) {
|
|
153
150
|
return tr;
|
|
154
151
|
}
|
|
155
|
-
|
|
156
152
|
if (!options.tryToFit && indexesTargetColumn.length > 1) {
|
|
157
153
|
isValidReorder(originColumnIndex, targetColumnIndex, indexesTargetColumn, 'column');
|
|
158
154
|
}
|
|
159
|
-
|
|
160
155
|
var newTable = moveTableColumn(table, indexesOriginColumn, indexesTargetColumn, options.direction);
|
|
161
156
|
return cloneTr(tr).replaceWith(table.pos, table.pos + table.node.nodeSize, newTable);
|
|
162
157
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { cloneTr } from './clone-tr';
|
|
2
2
|
import { findTable } from './find';
|
|
3
3
|
import { getSelectionRangeInRow } from './get-selection-range-in-row';
|
|
4
|
-
import { isValidReorder, moveTableRow } from './reorder-utils';
|
|
4
|
+
import { isValidReorder, moveTableRow } from './reorder-utils';
|
|
5
|
+
|
|
6
|
+
// :: (originRowIndex: number, targetRowIndex: targetColumnIndex, options?: MovementOptions) → (tr: Transaction) → Transaction
|
|
5
7
|
// Returns a new transaction that moves the origin row to the target index;
|
|
6
8
|
//
|
|
7
9
|
// by default "tryToFit" is false, that means if you try to move a row to a place
|
|
@@ -144,7 +146,6 @@ import { isValidReorder, moveTableRow } from './reorder-utils'; // :: (originRow
|
|
|
144
146
|
// moveRow(x, y, options)(state.tr)
|
|
145
147
|
// );
|
|
146
148
|
// ```
|
|
147
|
-
|
|
148
149
|
export var moveRow = function moveRow(originRowIndex, targetRowIndex) {
|
|
149
150
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
150
151
|
tryToFit: false,
|
|
@@ -152,24 +153,19 @@ export var moveRow = function moveRow(originRowIndex, targetRowIndex) {
|
|
|
152
153
|
};
|
|
153
154
|
return function (tr) {
|
|
154
155
|
var table = findTable(tr.selection);
|
|
155
|
-
|
|
156
156
|
if (!table) {
|
|
157
157
|
return tr;
|
|
158
158
|
}
|
|
159
|
-
|
|
160
159
|
var originalRowRanges = getSelectionRangeInRow(originRowIndex)(tr);
|
|
161
160
|
var targetRowRanges = getSelectionRangeInRow(targetRowIndex)(tr);
|
|
162
161
|
var indexesOriginRow = (originalRowRanges === null || originalRowRanges === void 0 ? void 0 : originalRowRanges.indexes) || [];
|
|
163
162
|
var indexesTargetRow = (targetRowRanges === null || targetRowRanges === void 0 ? void 0 : targetRowRanges.indexes) || [];
|
|
164
|
-
|
|
165
163
|
if (indexesOriginRow.includes(targetRowIndex)) {
|
|
166
164
|
return tr;
|
|
167
165
|
}
|
|
168
|
-
|
|
169
166
|
if (!options.tryToFit && indexesTargetRow.length > 1) {
|
|
170
167
|
isValidReorder(originRowIndex, targetRowIndex, indexesTargetRow, 'row');
|
|
171
168
|
}
|
|
172
|
-
|
|
173
169
|
var newTable = moveTableRow(table, indexesOriginRow, indexesTargetRow, options.direction);
|
|
174
170
|
return cloneTr(tr).replaceWith(table.pos, table.pos + table.node.nodeSize, newTable);
|
|
175
171
|
};
|
|
@@ -4,17 +4,13 @@ import { TableMap } from '../table-map';
|
|
|
4
4
|
export function normalizeSelection(state, transaction, allowTableNodeSelection) {
|
|
5
5
|
var tr = transaction;
|
|
6
6
|
var sel = (tr || state).selection;
|
|
7
|
-
|
|
8
7
|
var _ref = tr || state,
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
doc = _ref.doc;
|
|
11
9
|
var normalize;
|
|
12
10
|
var role;
|
|
13
|
-
|
|
14
11
|
if (sel instanceof NodeSelection) {
|
|
15
12
|
role = sel.node.type.spec.tableRole;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
if (sel instanceof NodeSelection && role) {
|
|
19
15
|
if (role === 'cell' || role === 'header_cell') {
|
|
20
16
|
normalize = CellSelection.create(doc, sel.from);
|
|
@@ -32,65 +28,50 @@ export function normalizeSelection(state, transaction, allowTableNodeSelection)
|
|
|
32
28
|
} else if (sel instanceof TextSelection && isTextSelectionAcrossCells(sel)) {
|
|
33
29
|
normalize = TextSelection.create(doc, sel.$from.start(), sel.$from.end());
|
|
34
30
|
}
|
|
35
|
-
|
|
36
31
|
if (normalize) {
|
|
37
32
|
(tr || (tr = state.tr)).setSelection(normalize);
|
|
38
33
|
}
|
|
39
|
-
|
|
40
34
|
return tr;
|
|
41
35
|
}
|
|
42
|
-
|
|
43
36
|
function isCellBoundarySelection(_ref2) {
|
|
44
37
|
var $from = _ref2.$from,
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
$to = _ref2.$to;
|
|
47
39
|
if ($from.pos === $to.pos || $from.pos < $from.pos - 6) {
|
|
48
40
|
return false;
|
|
49
41
|
} // Cheap elimination
|
|
50
|
-
|
|
51
|
-
|
|
52
42
|
var afterFrom = $from.pos;
|
|
53
43
|
var beforeTo = $to.pos;
|
|
54
44
|
var depth = $from.depth;
|
|
55
|
-
|
|
56
45
|
for (; depth >= 0; depth--, afterFrom++) {
|
|
57
46
|
if ($from.after(depth + 1) < $from.end(depth)) {
|
|
58
47
|
break;
|
|
59
48
|
}
|
|
60
49
|
}
|
|
61
|
-
|
|
62
50
|
for (var d = $to.depth; d >= 0; d--, beforeTo--) {
|
|
63
51
|
if ($to.before(d + 1) > $to.start(d)) {
|
|
64
52
|
break;
|
|
65
53
|
}
|
|
66
54
|
}
|
|
67
|
-
|
|
68
55
|
return afterFrom === beforeTo && /row|table/.test($from.node(depth).type.spec.tableRole);
|
|
69
56
|
}
|
|
70
|
-
|
|
71
57
|
function isTextSelectionAcrossCells(_ref3) {
|
|
72
58
|
var $from = _ref3.$from,
|
|
73
|
-
|
|
59
|
+
$to = _ref3.$to;
|
|
74
60
|
var fromCellBoundaryNode;
|
|
75
61
|
var toCellBoundaryNode;
|
|
76
|
-
|
|
77
62
|
for (var i = $from.depth; i > 0; i--) {
|
|
78
63
|
var node = $from.node(i);
|
|
79
|
-
|
|
80
64
|
if (node.type.spec.tableRole === 'cell' || node.type.spec.tableRole === 'header_cell') {
|
|
81
65
|
fromCellBoundaryNode = node;
|
|
82
66
|
break;
|
|
83
67
|
}
|
|
84
68
|
}
|
|
85
|
-
|
|
86
69
|
for (var _i = $to.depth; _i > 0; _i--) {
|
|
87
70
|
var _node = $to.node(_i);
|
|
88
|
-
|
|
89
71
|
if (_node.type.spec.tableRole === 'cell' || _node.type.spec.tableRole === 'header_cell') {
|
|
90
72
|
toCellBoundaryNode = _node;
|
|
91
73
|
break;
|
|
92
74
|
}
|
|
93
75
|
}
|
|
94
|
-
|
|
95
76
|
return fromCellBoundaryNode !== toCellBoundaryNode && $to.parentOffset === 0;
|
|
96
77
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
|
|
3
2
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
-
|
|
5
3
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
|
-
|
|
7
4
|
import { setTextSelection } from 'prosemirror-utils';
|
|
8
5
|
import { TableMap } from '../table-map';
|
|
9
6
|
import { cloneTr } from './clone-tr';
|
|
@@ -12,44 +9,37 @@ import { findCellRectClosestToPos, findTable } from './find';
|
|
|
12
9
|
import { isTableSelected } from './is-selected';
|
|
13
10
|
import { isSelectionType } from './is-selection-type';
|
|
14
11
|
import { removeTable } from './remove-table';
|
|
15
|
-
|
|
16
12
|
function removeColumn(tr, _ref, columnIndex) {
|
|
17
13
|
var map = _ref.map,
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
table = _ref.table,
|
|
15
|
+
tableStart = _ref.tableStart;
|
|
20
16
|
var mapStart = tr.mapping.maps.length;
|
|
21
|
-
|
|
22
17
|
for (var row = 0; row < map.height;) {
|
|
23
18
|
var index = row * map.width + columnIndex;
|
|
24
19
|
var pos = map.map[index];
|
|
25
20
|
var cell = table.nodeAt(pos);
|
|
26
|
-
|
|
27
21
|
if (!cell) {
|
|
28
22
|
continue;
|
|
29
|
-
}
|
|
30
|
-
|
|
23
|
+
}
|
|
31
24
|
|
|
25
|
+
// If this is part of a col-spanning cell
|
|
32
26
|
if (columnIndex > 0 && map.map[index - 1] === pos || columnIndex < map.width - 1 && map.map[index + 1] === pos) {
|
|
33
27
|
tr.setNodeMarkup(tr.mapping.slice(mapStart).map(tableStart + pos), undefined, removeColSpan(cell.attrs, columnIndex - map.colCount(pos)));
|
|
34
28
|
} else {
|
|
35
29
|
var start = tr.mapping.slice(mapStart).map(tableStart + pos);
|
|
36
30
|
tr.delete(start, start + cell.nodeSize);
|
|
37
31
|
}
|
|
38
|
-
|
|
39
32
|
row += cell.attrs.rowspan;
|
|
40
33
|
}
|
|
41
|
-
|
|
42
34
|
return tr;
|
|
43
|
-
}
|
|
44
|
-
|
|
35
|
+
}
|
|
45
36
|
|
|
37
|
+
// Returns a new transaction that removes a column at index `columnIndex`. If there is only one column left, it will remove the entire table.
|
|
46
38
|
export var removeColumnAt = function removeColumnAt(columnIndex) {
|
|
47
39
|
return function (tr) {
|
|
48
40
|
var table = findTable(tr.selection);
|
|
49
|
-
|
|
50
41
|
if (table) {
|
|
51
42
|
var map = TableMap.get(table.node);
|
|
52
|
-
|
|
53
43
|
if (columnIndex === 0 && map.width === 1) {
|
|
54
44
|
return removeTable(tr);
|
|
55
45
|
} else if (columnIndex >= 0 && columnIndex <= map.width) {
|
|
@@ -61,61 +51,50 @@ export var removeColumnAt = function removeColumnAt(columnIndex) {
|
|
|
61
51
|
return cloneTr(tr);
|
|
62
52
|
}
|
|
63
53
|
}
|
|
64
|
-
|
|
65
54
|
return tr;
|
|
66
55
|
};
|
|
67
|
-
};
|
|
56
|
+
};
|
|
68
57
|
|
|
58
|
+
// Returns a new transaction that removes selected columns.
|
|
69
59
|
export var removeSelectedColumns = function removeSelectedColumns(tr) {
|
|
70
60
|
var selection = tr.selection;
|
|
71
|
-
|
|
72
61
|
if (isTableSelected(selection)) {
|
|
73
62
|
return removeTable(tr);
|
|
74
63
|
}
|
|
75
|
-
|
|
76
64
|
if (isSelectionType(selection, 'cell')) {
|
|
77
65
|
var table = findTable(selection);
|
|
78
|
-
|
|
79
66
|
if (table) {
|
|
80
67
|
var map = TableMap.get(table.node);
|
|
81
68
|
var rect = map.rectBetween(selection.$anchorCell.pos - table.start, selection.$headCell.pos - table.start);
|
|
82
|
-
|
|
83
69
|
if (rect.left === 0 && rect.right === map.width) {
|
|
84
70
|
return tr;
|
|
85
71
|
}
|
|
86
|
-
|
|
87
72
|
var pmTableRect = _objectSpread(_objectSpread({}, rect), {}, {
|
|
88
73
|
map: map,
|
|
89
74
|
table: table.node,
|
|
90
75
|
tableStart: table.start
|
|
91
76
|
});
|
|
92
|
-
|
|
93
77
|
for (var i = pmTableRect.right - 1;; i--) {
|
|
94
78
|
removeColumn(tr, pmTableRect, i);
|
|
95
|
-
|
|
96
79
|
if (i === pmTableRect.left) {
|
|
97
80
|
break;
|
|
98
81
|
}
|
|
99
|
-
|
|
100
82
|
pmTableRect.table = pmTableRect.tableStart ? tr.doc.nodeAt(pmTableRect.tableStart - 1) : tr.doc;
|
|
101
83
|
pmTableRect.map = TableMap.get(pmTableRect.table);
|
|
102
84
|
}
|
|
103
|
-
|
|
104
85
|
return cloneTr(tr);
|
|
105
86
|
}
|
|
106
87
|
}
|
|
107
|
-
|
|
108
88
|
return tr;
|
|
109
|
-
};
|
|
89
|
+
};
|
|
110
90
|
|
|
91
|
+
// Returns a new transaction that removes a column closest to a given `$pos`.
|
|
111
92
|
export var removeColumnClosestToPos = function removeColumnClosestToPos($pos) {
|
|
112
93
|
return function (tr) {
|
|
113
94
|
var rect = findCellRectClosestToPos($pos);
|
|
114
|
-
|
|
115
95
|
if (rect) {
|
|
116
96
|
return removeColumnAt(rect.left)(setTextSelection($pos.pos)(tr));
|
|
117
97
|
}
|
|
118
|
-
|
|
119
98
|
return tr;
|
|
120
99
|
};
|
|
121
100
|
};
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
|
|
3
2
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
-
|
|
5
3
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
|
-
|
|
7
4
|
import { setTextSelection } from 'prosemirror-utils';
|
|
8
5
|
import { TableMap } from '../table-map';
|
|
9
6
|
import { cloneTr } from './clone-tr';
|
|
@@ -11,32 +8,25 @@ import { findCellRectClosestToPos, findTable } from './find';
|
|
|
11
8
|
import { isTableSelected } from './is-selected';
|
|
12
9
|
import { isSelectionType } from './is-selection-type';
|
|
13
10
|
import { removeTable } from './remove-table';
|
|
14
|
-
|
|
15
11
|
function removeRow(tr, _ref, rowIndex) {
|
|
16
12
|
var map = _ref.map,
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
table = _ref.table,
|
|
14
|
+
tableStart = _ref.tableStart;
|
|
19
15
|
var rowPos = 0;
|
|
20
|
-
|
|
21
16
|
for (var i = 0; i < rowIndex; i++) {
|
|
22
17
|
rowPos += table.child(i).nodeSize;
|
|
23
18
|
}
|
|
24
|
-
|
|
25
19
|
var nextRow = rowPos + table.child(rowIndex).nodeSize;
|
|
26
20
|
var mapFrom = tr.mapping.maps.length;
|
|
27
21
|
tr.delete(rowPos + tableStart, nextRow + tableStart);
|
|
28
|
-
|
|
29
22
|
for (var col = 0, index = rowIndex * map.width; col < map.width; col++, index++) {
|
|
30
23
|
var pos = map.map[index];
|
|
31
|
-
|
|
32
24
|
if (rowIndex > 0 && pos === map.map[index - map.width]) {
|
|
33
25
|
// If this cell starts in the row above, simply reduce its rowspan
|
|
34
26
|
var cell = table.nodeAt(pos);
|
|
35
|
-
|
|
36
27
|
if (!cell) {
|
|
37
28
|
continue;
|
|
38
29
|
}
|
|
39
|
-
|
|
40
30
|
var attrs = cell.attrs;
|
|
41
31
|
tr.setNodeMarkup(tr.mapping.slice(mapFrom).map(pos + tableStart), undefined, _objectSpread(_objectSpread({}, attrs), {}, {
|
|
42
32
|
rowspan: attrs.rowspan - 1
|
|
@@ -45,32 +35,26 @@ function removeRow(tr, _ref, rowIndex) {
|
|
|
45
35
|
} else if (rowIndex < map.width && pos === map.map[index + map.width]) {
|
|
46
36
|
// Else, if it continues in the row below, it has to be moved down
|
|
47
37
|
var _cell = table.nodeAt(pos);
|
|
48
|
-
|
|
49
38
|
if (!_cell) {
|
|
50
39
|
continue;
|
|
51
40
|
}
|
|
52
|
-
|
|
53
41
|
var copy = _cell.type.create(_objectSpread(_objectSpread({}, _cell.attrs), {}, {
|
|
54
42
|
rowspan: _cell.attrs.rowspan - 1
|
|
55
43
|
}), _cell.content);
|
|
56
|
-
|
|
57
44
|
var newPos = map.positionAt(rowIndex + 1, col, table);
|
|
58
45
|
tr.insert(tr.mapping.slice(mapFrom).map(tableStart + newPos), copy);
|
|
59
46
|
col += _cell.attrs.colspan - 1;
|
|
60
47
|
}
|
|
61
48
|
}
|
|
62
|
-
|
|
63
49
|
return tr;
|
|
64
|
-
}
|
|
65
|
-
|
|
50
|
+
}
|
|
66
51
|
|
|
52
|
+
// Returns a new transaction that removes a row at index `rowIndex`. If there is only one row left, it will remove the entire table.
|
|
67
53
|
export var removeRowAt = function removeRowAt(rowIndex) {
|
|
68
54
|
return function (tr) {
|
|
69
55
|
var table = findTable(tr.selection);
|
|
70
|
-
|
|
71
56
|
if (table) {
|
|
72
57
|
var map = TableMap.get(table.node);
|
|
73
|
-
|
|
74
58
|
if (rowIndex === 0 && map.height === 1) {
|
|
75
59
|
return removeTable(tr);
|
|
76
60
|
} else if (rowIndex >= 0 && rowIndex <= map.height) {
|
|
@@ -82,61 +66,50 @@ export var removeRowAt = function removeRowAt(rowIndex) {
|
|
|
82
66
|
return cloneTr(tr);
|
|
83
67
|
}
|
|
84
68
|
}
|
|
85
|
-
|
|
86
69
|
return tr;
|
|
87
70
|
};
|
|
88
|
-
};
|
|
71
|
+
};
|
|
89
72
|
|
|
73
|
+
// Returns a new transaction that removes selected rows.
|
|
90
74
|
export var removeSelectedRows = function removeSelectedRows(tr) {
|
|
91
75
|
var selection = tr.selection;
|
|
92
|
-
|
|
93
76
|
if (isTableSelected(selection)) {
|
|
94
77
|
return removeTable(tr);
|
|
95
78
|
}
|
|
96
|
-
|
|
97
79
|
if (isSelectionType(selection, 'cell')) {
|
|
98
80
|
var table = findTable(selection);
|
|
99
|
-
|
|
100
81
|
if (table) {
|
|
101
82
|
var map = TableMap.get(table.node);
|
|
102
83
|
var rect = map.rectBetween(selection.$anchorCell.pos - table.start, selection.$headCell.pos - table.start);
|
|
103
|
-
|
|
104
84
|
if (rect.top === 0 && rect.bottom === map.height) {
|
|
105
85
|
return tr;
|
|
106
86
|
}
|
|
107
|
-
|
|
108
87
|
var pmTableRect = _objectSpread(_objectSpread({}, rect), {}, {
|
|
109
88
|
map: map,
|
|
110
89
|
table: table.node,
|
|
111
90
|
tableStart: table.start
|
|
112
91
|
});
|
|
113
|
-
|
|
114
92
|
for (var i = pmTableRect.bottom - 1;; i--) {
|
|
115
93
|
removeRow(tr, pmTableRect, i);
|
|
116
|
-
|
|
117
94
|
if (i === pmTableRect.top) {
|
|
118
95
|
break;
|
|
119
96
|
}
|
|
120
|
-
|
|
121
97
|
pmTableRect.table = pmTableRect.tableStart ? tr.doc.nodeAt(pmTableRect.tableStart - 1) : tr.doc;
|
|
122
98
|
pmTableRect.map = TableMap.get(pmTableRect.table);
|
|
123
99
|
}
|
|
124
|
-
|
|
125
100
|
return cloneTr(tr);
|
|
126
101
|
}
|
|
127
102
|
}
|
|
128
|
-
|
|
129
103
|
return tr;
|
|
130
|
-
};
|
|
104
|
+
};
|
|
131
105
|
|
|
106
|
+
// Returns a new transaction that removes a row closest to a given `$pos`.
|
|
132
107
|
export var removeRowClosestToPos = function removeRowClosestToPos($pos) {
|
|
133
108
|
return function (tr) {
|
|
134
109
|
var rect = findCellRectClosestToPos($pos);
|
|
135
|
-
|
|
136
110
|
if (rect) {
|
|
137
111
|
return removeRowAt(rect.top)(setTextSelection($pos.pos)(tr));
|
|
138
112
|
}
|
|
139
|
-
|
|
140
113
|
return tr;
|
|
141
114
|
};
|
|
142
115
|
};
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { cloneTr } from './clone-tr';
|
|
1
|
+
import { cloneTr } from './clone-tr';
|
|
2
2
|
|
|
3
|
+
// Returns a new transaction that removes a table node if the cursor is inside of it.
|
|
3
4
|
export var removeTable = function removeTable(tr) {
|
|
4
5
|
var $from = tr.selection.$from;
|
|
5
|
-
|
|
6
6
|
for (var depth = $from.depth; depth > 0; depth--) {
|
|
7
7
|
var node = $from.node(depth);
|
|
8
|
-
|
|
9
8
|
if (node.type.spec.tableRole === 'table') {
|
|
10
9
|
return cloneTr(tr.delete($from.before(depth), $from.after(depth)));
|
|
11
10
|
}
|
|
12
11
|
}
|
|
13
|
-
|
|
14
12
|
return tr;
|
|
15
13
|
};
|