@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
|
@@ -7,12 +7,10 @@ import { findTable } from './find';
|
|
|
7
7
|
import { getCellsInRow } from './get-cells-in-row';
|
|
8
8
|
import { setCellAttrs } from './set-cell-attrs';
|
|
9
9
|
import { tableNodeTypes } from './table-node-types';
|
|
10
|
-
|
|
11
10
|
var filterCellsInRow = function filterCellsInRow(rowIndex, predicate) {
|
|
12
11
|
return function (tr) {
|
|
13
12
|
var foundCells = [];
|
|
14
13
|
var cells = getCellsInRow(rowIndex)(tr.selection);
|
|
15
|
-
|
|
16
14
|
if (cells) {
|
|
17
15
|
for (var j = cells.length - 1; j >= 0; j--) {
|
|
18
16
|
if (predicate(cells[j], tr)) {
|
|
@@ -20,30 +18,25 @@ var filterCellsInRow = function filterCellsInRow(rowIndex, predicate) {
|
|
|
20
18
|
}
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
|
-
|
|
24
21
|
return foundCells;
|
|
25
22
|
};
|
|
26
|
-
};
|
|
27
|
-
|
|
23
|
+
};
|
|
28
24
|
|
|
25
|
+
// Returns a new transaction that adds a new row after `cloneRowIndex`, cloning the row attributes at `cloneRowIndex`.
|
|
29
26
|
export var cloneRowAt = function cloneRowAt(rowIndex) {
|
|
30
27
|
return function (tr) {
|
|
31
28
|
var table = findTable(tr.selection);
|
|
32
|
-
|
|
33
29
|
if (table) {
|
|
34
30
|
var map = TableMap.get(table.node);
|
|
35
|
-
|
|
36
31
|
if (rowIndex >= 0 && rowIndex <= map.height) {
|
|
37
32
|
var tableNode = table.node;
|
|
38
33
|
var tableNodes = tableNodeTypes(tableNode.type.schema);
|
|
39
34
|
var rowPos = table.start;
|
|
40
|
-
|
|
41
35
|
for (var i = 0; i < rowIndex + 1; i++) {
|
|
42
36
|
rowPos += tableNode.child(i).nodeSize;
|
|
43
37
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
var cloneRow = tableNode.child(rowIndex);
|
|
39
|
+
// Re-create the same nodes with same attrs, dropping the node content.
|
|
47
40
|
var cells = [];
|
|
48
41
|
var rowWidth = 0;
|
|
49
42
|
cloneRow.forEach(function (cell) {
|
|
@@ -52,16 +45,15 @@ export var cloneRowAt = function cloneRowAt(rowIndex) {
|
|
|
52
45
|
if (cell.attrs.rowspan === 1) {
|
|
53
46
|
rowWidth += cell.attrs.colspan;
|
|
54
47
|
var node = tableNodes[cell.type.spec.tableRole].createAndFill(cell.attrs, [], cell.marks);
|
|
55
|
-
|
|
56
48
|
if (node) {
|
|
57
49
|
cells.push(node);
|
|
58
50
|
}
|
|
59
51
|
}
|
|
60
|
-
});
|
|
52
|
+
});
|
|
61
53
|
|
|
54
|
+
// If a higher row spans past our clone row, bump the higher row to cover this new row too.
|
|
62
55
|
if (rowWidth < map.width) {
|
|
63
56
|
var rowSpanCells = [];
|
|
64
|
-
|
|
65
57
|
var _loop = function _loop(_i) {
|
|
66
58
|
var foundCells = filterCellsInRow(_i, function (cell, tr) {
|
|
67
59
|
var rowspan = cell.node.attrs.rowspan;
|
|
@@ -70,11 +62,9 @@ export var cloneRowAt = function cloneRowAt(rowIndex) {
|
|
|
70
62
|
})(tr);
|
|
71
63
|
rowSpanCells.push.apply(rowSpanCells, _toConsumableArray(foundCells));
|
|
72
64
|
};
|
|
73
|
-
|
|
74
65
|
for (var _i = rowIndex; _i >= 0; _i--) {
|
|
75
66
|
_loop(_i);
|
|
76
67
|
}
|
|
77
|
-
|
|
78
68
|
if (rowSpanCells.length) {
|
|
79
69
|
rowSpanCells.forEach(function (cell) {
|
|
80
70
|
tr = setCellAttrs(cell, {
|
|
@@ -83,27 +73,23 @@ export var cloneRowAt = function cloneRowAt(rowIndex) {
|
|
|
83
73
|
});
|
|
84
74
|
}
|
|
85
75
|
}
|
|
86
|
-
|
|
87
76
|
return safeInsert(tableNodes.row.create(cloneRow.attrs, cells), rowPos)(tr);
|
|
88
77
|
}
|
|
89
78
|
}
|
|
90
|
-
|
|
91
79
|
return tr;
|
|
92
80
|
};
|
|
93
|
-
};
|
|
81
|
+
};
|
|
94
82
|
|
|
83
|
+
// Returns a new transaction that adds a new row at index `rowIndex`. Optionally clone the previous row.
|
|
95
84
|
export var addRowAt = function addRowAt(rowIndex, clonePreviousRow) {
|
|
96
85
|
return function (tr) {
|
|
97
86
|
var table = findTable(tr.selection);
|
|
98
|
-
|
|
99
87
|
if (table) {
|
|
100
88
|
var map = TableMap.get(table.node);
|
|
101
89
|
var cloneRowIndex = rowIndex - 1;
|
|
102
|
-
|
|
103
90
|
if (clonePreviousRow && cloneRowIndex >= 0) {
|
|
104
91
|
return cloneTr(cloneRowAt(cloneRowIndex)(tr));
|
|
105
92
|
}
|
|
106
|
-
|
|
107
93
|
if (rowIndex >= 0 && rowIndex <= map.height) {
|
|
108
94
|
return cloneTr(addRow(tr, {
|
|
109
95
|
map: map,
|
|
@@ -112,7 +98,6 @@ export var addRowAt = function addRowAt(rowIndex, clonePreviousRow) {
|
|
|
112
98
|
}, rowIndex));
|
|
113
99
|
}
|
|
114
100
|
}
|
|
115
|
-
|
|
116
101
|
return tr;
|
|
117
102
|
};
|
|
118
103
|
};
|
|
@@ -1,52 +1,38 @@
|
|
|
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 { tableNodeTypes } from './table-node-types';
|
|
8
|
-
|
|
9
5
|
function rowIsHeader(map, table, row) {
|
|
10
6
|
var headerCell = tableNodeTypes(table.type.schema).header_cell;
|
|
11
|
-
|
|
12
7
|
for (var col = 0; col < map.width; col++) {
|
|
13
8
|
var cell = table.nodeAt(map.map[col + row * map.width]);
|
|
14
|
-
|
|
15
9
|
if (cell && cell.type !== headerCell) {
|
|
16
10
|
return false;
|
|
17
11
|
}
|
|
18
12
|
}
|
|
19
|
-
|
|
20
13
|
return true;
|
|
21
14
|
}
|
|
22
|
-
|
|
23
15
|
export function addRow(tr, _ref, row) {
|
|
24
16
|
var map = _ref.map,
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
tableStart = _ref.tableStart,
|
|
18
|
+
table = _ref.table;
|
|
27
19
|
var rowPos = tableStart;
|
|
28
|
-
|
|
29
20
|
for (var i = 0; i < row; i++) {
|
|
30
21
|
rowPos += table.child(i).nodeSize;
|
|
31
22
|
}
|
|
32
|
-
|
|
33
23
|
var cells = [];
|
|
34
24
|
var refRow = row > 0 ? -1 : 0;
|
|
35
|
-
|
|
36
25
|
if (rowIsHeader(map, table, row + refRow)) {
|
|
37
26
|
refRow = row === 0 || row === map.height ? null : 0;
|
|
38
27
|
}
|
|
39
|
-
|
|
40
28
|
for (var col = 0, index = map.width * row; col < map.width; col++, index++) {
|
|
41
29
|
// Covered by a rowspan cell
|
|
42
30
|
if (row > 0 && row < map.height && map.map[index] === map.map[index - map.width]) {
|
|
43
31
|
var pos = map.map[index];
|
|
44
32
|
var node = table.nodeAt(pos);
|
|
45
|
-
|
|
46
33
|
if (!node) {
|
|
47
34
|
throw new Error("addRow: node not found at pos ".concat(pos));
|
|
48
35
|
}
|
|
49
|
-
|
|
50
36
|
var attrs = node.attrs;
|
|
51
37
|
tr.setNodeMarkup(tableStart + pos, undefined, _objectSpread(_objectSpread({}, attrs), {}, {
|
|
52
38
|
rowspan: attrs.rowspan + 1
|
|
@@ -54,24 +40,19 @@ export function addRow(tr, _ref, row) {
|
|
|
54
40
|
col += attrs.colspan - 1;
|
|
55
41
|
} else {
|
|
56
42
|
var type = void 0;
|
|
57
|
-
|
|
58
43
|
if (refRow == null) {
|
|
59
44
|
type = tableNodeTypes(table.type.schema).cell;
|
|
60
45
|
} else {
|
|
61
46
|
var mappedPos = map.map[index + refRow * map.width];
|
|
62
47
|
var cell = table.nodeAt(mappedPos);
|
|
63
|
-
|
|
64
48
|
if (!cell) {
|
|
65
49
|
throw new Error("addRow: invalid node at mapped pos ".concat(mappedPos));
|
|
66
50
|
}
|
|
67
|
-
|
|
68
51
|
type = cell.type;
|
|
69
52
|
}
|
|
70
|
-
|
|
71
53
|
cells.push(type.createAndFill());
|
|
72
54
|
}
|
|
73
55
|
}
|
|
74
|
-
|
|
75
56
|
var rowType = tableNodeTypes(table.type.schema).row;
|
|
76
57
|
var rowCells = rowType.create(null, cells);
|
|
77
58
|
tr.insert(rowPos, rowCells);
|
|
@@ -6,13 +6,11 @@ export function getSelectedTableInfo(selection) {
|
|
|
6
6
|
var totalRowCount = 0;
|
|
7
7
|
var totalColumnCount = 0;
|
|
8
8
|
var table = findTable(selection);
|
|
9
|
-
|
|
10
9
|
if (table) {
|
|
11
10
|
map = TableMap.get(table.node);
|
|
12
11
|
totalRowCount = map.height;
|
|
13
12
|
totalColumnCount = map.width;
|
|
14
13
|
}
|
|
15
|
-
|
|
16
14
|
return {
|
|
17
15
|
table: table,
|
|
18
16
|
map: map,
|
|
@@ -24,23 +22,19 @@ export function getSelectedCellInfo(selection) {
|
|
|
24
22
|
var horizontalCells = 1;
|
|
25
23
|
var verticalCells = 1;
|
|
26
24
|
var totalCells = 1;
|
|
27
|
-
|
|
28
25
|
var _getSelectedTableInfo = getSelectedTableInfo(selection),
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
table = _getSelectedTableInfo.table,
|
|
27
|
+
map = _getSelectedTableInfo.map,
|
|
28
|
+
totalRowCount = _getSelectedTableInfo.totalRowCount,
|
|
29
|
+
totalColumnCount = _getSelectedTableInfo.totalColumnCount;
|
|
34
30
|
if (table && map) {
|
|
35
31
|
var rect = getSelectionRect(selection);
|
|
36
|
-
|
|
37
32
|
if (rect) {
|
|
38
33
|
totalCells = map.cellsInRect(rect).length;
|
|
39
34
|
horizontalCells = rect.right - rect.left;
|
|
40
35
|
verticalCells = rect.bottom - rect.top;
|
|
41
36
|
}
|
|
42
37
|
}
|
|
43
|
-
|
|
44
38
|
return {
|
|
45
39
|
totalRowCount: totalRowCount,
|
|
46
40
|
totalColumnCount: totalColumnCount,
|
package/dist/esm/utils/cells.js
CHANGED
|
@@ -5,20 +5,16 @@ export function pointsAtCell($pos) {
|
|
|
5
5
|
export function cellNear($pos) {
|
|
6
6
|
for (var after = $pos.nodeAfter, pos = $pos.pos; after; after = after.firstChild, pos++) {
|
|
7
7
|
var role = after.type.spec.tableRole;
|
|
8
|
-
|
|
9
8
|
if (role === 'cell' || role === 'header_cell') {
|
|
10
9
|
return $pos.doc.resolve(pos);
|
|
11
10
|
}
|
|
12
11
|
}
|
|
13
|
-
|
|
14
12
|
for (var before = $pos.nodeBefore, _pos = $pos.pos; before; before = before.lastChild, _pos--) {
|
|
15
13
|
var _role = before.type.spec.tableRole;
|
|
16
|
-
|
|
17
14
|
if (_role === 'cell' || _role === 'header_cell') {
|
|
18
15
|
return $pos.doc.resolve(_pos - before.nodeSize);
|
|
19
16
|
}
|
|
20
17
|
}
|
|
21
|
-
|
|
22
18
|
return null;
|
|
23
19
|
}
|
|
24
20
|
export function cellAround($pos) {
|
|
@@ -27,7 +23,6 @@ export function cellAround($pos) {
|
|
|
27
23
|
return $pos.node(0).resolve($pos.before(d + 1));
|
|
28
24
|
}
|
|
29
25
|
}
|
|
30
|
-
|
|
31
26
|
return null;
|
|
32
27
|
}
|
|
33
28
|
export function nextCell($pos, axis, dir) {
|
|
@@ -1,58 +1,46 @@
|
|
|
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
|
export function removeColSpan(attrs, pos) {
|
|
8
5
|
var n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
9
|
-
|
|
10
6
|
if (!attrs.colspan) {
|
|
11
7
|
throw new Error('removeColSpan(): attrs.colspan not defined');
|
|
12
8
|
}
|
|
13
|
-
|
|
14
9
|
var result = _objectSpread(_objectSpread({}, attrs), {}, {
|
|
15
10
|
colspan: attrs.colspan - n
|
|
16
11
|
});
|
|
17
|
-
|
|
18
12
|
if (result.colwidth) {
|
|
19
13
|
result.colwidth = result.colwidth.slice();
|
|
20
14
|
result.colwidth.splice(pos, n);
|
|
21
|
-
|
|
22
15
|
if (!result.colwidth.some(function (w) {
|
|
23
16
|
return w > 0;
|
|
24
17
|
})) {
|
|
25
18
|
result.colwidth = undefined;
|
|
26
19
|
}
|
|
27
20
|
}
|
|
28
|
-
|
|
29
21
|
return result;
|
|
30
22
|
}
|
|
31
23
|
export function assertColspan(attrs) {
|
|
32
24
|
if (typeof attrs.colspan === 'undefined') {
|
|
33
25
|
throw new Error('addColSpan: attrs.colspan is not defined');
|
|
34
26
|
}
|
|
35
|
-
|
|
36
27
|
if (typeof attrs.colspan !== 'number' || Number.isNaN(attrs.colspan) || attrs.colspan < 1) {
|
|
37
28
|
throw new Error("addColSpan: attrs.colspan must be number >= 1, received: ".concat(attrs.colspan));
|
|
38
29
|
}
|
|
39
|
-
}
|
|
30
|
+
}
|
|
40
31
|
|
|
32
|
+
// TODO: replace "addColSpan" from table plugin with this function
|
|
41
33
|
export function addColSpan(attrs, pos) {
|
|
42
34
|
var n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
43
35
|
assertColspan(attrs);
|
|
44
|
-
|
|
45
36
|
var result = _objectSpread(_objectSpread({}, attrs), {}, {
|
|
46
37
|
colspan: attrs.colspan + n
|
|
47
38
|
});
|
|
48
|
-
|
|
49
39
|
if (result.colwidth) {
|
|
50
40
|
result.colwidth = result.colwidth.slice();
|
|
51
|
-
|
|
52
41
|
for (var i = 0; i < n; i++) {
|
|
53
42
|
result.colwidth.splice(pos, 0, 0);
|
|
54
43
|
}
|
|
55
44
|
}
|
|
56
|
-
|
|
57
45
|
return result;
|
|
58
46
|
}
|