@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.
Files changed (158) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/cell-bookmark.js +0 -10
  3. package/dist/cjs/cell-selection.js +37 -102
  4. package/dist/cjs/index.js +0 -4
  5. package/dist/cjs/pm-plugins/input.js +17 -83
  6. package/dist/cjs/pm-plugins/plugin-key.js +0 -2
  7. package/dist/cjs/pm-plugins/table-editing.js +17 -18
  8. package/dist/cjs/pm-plugins.js +0 -2
  9. package/dist/cjs/table-map.js +67 -138
  10. package/dist/cjs/utils/add-column-at.js +0 -9
  11. package/dist/cjs/utils/add-column.js +8 -24
  12. package/dist/cjs/utils/add-row-at.js +8 -37
  13. package/dist/cjs/utils/add-row.js +2 -23
  14. package/dist/cjs/utils/analytics-helpers.js +4 -15
  15. package/dist/cjs/utils/cells.js +0 -12
  16. package/dist/cjs/utils/clone-tr.js +0 -2
  17. package/dist/cjs/utils/colspan.js +2 -18
  18. package/dist/cjs/utils/copy-paste.js +51 -139
  19. package/dist/cjs/utils/create-table.js +14 -28
  20. package/dist/cjs/utils/draw-cell-selection.js +0 -4
  21. package/dist/cjs/utils/empty-cells.js +0 -6
  22. package/dist/cjs/utils/find.js +6 -18
  23. package/dist/cjs/utils/fix-tables.js +13 -56
  24. package/dist/cjs/utils/for-each-cell.js +3 -17
  25. package/dist/cjs/utils/get-cell-selection-ranges.js +2 -9
  26. package/dist/cjs/utils/get-cells-in-column.js +0 -7
  27. package/dist/cjs/utils/get-cells-in-row.js +0 -7
  28. package/dist/cjs/utils/get-cells-in-table.js +0 -8
  29. package/dist/cjs/utils/get-selection-range-in-column.js +6 -27
  30. package/dist/cjs/utils/get-selection-range-in-row.js +6 -27
  31. package/dist/cjs/utils/get-selection-rect.js +0 -7
  32. package/dist/cjs/utils/go-to-next-cell.js +3 -22
  33. package/dist/cjs/utils/handle-paste.js +5 -34
  34. package/dist/cjs/utils/is-selected.js +6 -23
  35. package/dist/cjs/utils/is-selection-type.js +0 -2
  36. package/dist/cjs/utils/move-column.js +0 -12
  37. package/dist/cjs/utils/move-row.js +0 -11
  38. package/dist/cjs/utils/normalize-selection.js +3 -27
  39. package/dist/cjs/utils/remove-column.js +10 -46
  40. package/dist/cjs/utils/remove-row.js +8 -49
  41. package/dist/cjs/utils/remove-table.js +0 -6
  42. package/dist/cjs/utils/reorder-utils.js +13 -37
  43. package/dist/cjs/utils/replace-table.js +0 -8
  44. package/dist/cjs/utils/select-nodes.js +11 -31
  45. package/dist/cjs/utils/selection-cell.js +0 -5
  46. package/dist/cjs/utils/selection-rect.js +0 -10
  47. package/dist/cjs/utils/set-cell-attrs.js +0 -4
  48. package/dist/cjs/utils/split-cell-with-type.js +2 -35
  49. package/dist/cjs/utils/split-cell.js +0 -4
  50. package/dist/cjs/utils/table-node-types.js +4 -8
  51. package/dist/cjs/utils/tables.js +0 -4
  52. package/dist/cjs/utils/test-utils.js +9 -26
  53. package/dist/cjs/utils/toggle-header.js +3 -16
  54. package/dist/cjs/utils/uuid.js +0 -3
  55. package/dist/cjs/utils.js +0 -42
  56. package/dist/cjs/version.json +1 -1
  57. package/dist/es2019/cell-bookmark.js +0 -5
  58. package/dist/es2019/cell-selection.js +37 -81
  59. package/dist/es2019/index.js +1 -0
  60. package/dist/es2019/pm-plugins/input.js +15 -67
  61. package/dist/es2019/pm-plugins/table-editing.js +3 -12
  62. package/dist/es2019/table-map.js +57 -127
  63. package/dist/es2019/utils/add-column-at.js +2 -4
  64. package/dist/es2019/utils/add-column.js +6 -16
  65. package/dist/es2019/utils/add-row-at.js +8 -22
  66. package/dist/es2019/utils/add-row.js +2 -17
  67. package/dist/es2019/utils/analytics-helpers.js +0 -5
  68. package/dist/es2019/utils/cells.js +4 -9
  69. package/dist/es2019/utils/colspan.js +6 -11
  70. package/dist/es2019/utils/copy-paste.js +41 -115
  71. package/dist/es2019/utils/create-table.js +3 -12
  72. package/dist/es2019/utils/draw-cell-selection.js +0 -1
  73. package/dist/es2019/utils/empty-cells.js +2 -3
  74. package/dist/es2019/utils/find.js +8 -8
  75. package/dist/es2019/utils/fix-tables.js +17 -47
  76. package/dist/es2019/utils/for-each-cell.js +6 -11
  77. package/dist/es2019/utils/get-cell-selection-ranges.js +2 -4
  78. package/dist/es2019/utils/get-cells-in-column.js +2 -3
  79. package/dist/es2019/utils/get-cells-in-row.js +2 -3
  80. package/dist/es2019/utils/get-cells-in-table.js +2 -4
  81. package/dist/es2019/utils/get-selection-range-in-column.js +8 -22
  82. package/dist/es2019/utils/get-selection-range-in-row.js +8 -22
  83. package/dist/es2019/utils/get-selection-rect.js +2 -2
  84. package/dist/es2019/utils/go-to-next-cell.js +3 -19
  85. package/dist/es2019/utils/handle-paste.js +3 -14
  86. package/dist/es2019/utils/is-selected.js +8 -10
  87. package/dist/es2019/utils/is-selection-type.js +0 -1
  88. package/dist/es2019/utils/move-column.js +3 -8
  89. package/dist/es2019/utils/move-row.js +3 -7
  90. package/dist/es2019/utils/normalize-selection.js +0 -16
  91. package/dist/es2019/utils/remove-column.js +10 -27
  92. package/dist/es2019/utils/remove-row.js +12 -32
  93. package/dist/es2019/utils/remove-table.js +2 -4
  94. package/dist/es2019/utils/reorder-utils.js +11 -26
  95. package/dist/es2019/utils/replace-table.js +0 -2
  96. package/dist/es2019/utils/select-nodes.js +9 -20
  97. package/dist/es2019/utils/selection-cell.js +0 -2
  98. package/dist/es2019/utils/selection-rect.js +0 -4
  99. package/dist/es2019/utils/set-cell-attrs.js +2 -2
  100. package/dist/es2019/utils/split-cell-with-type.js +8 -28
  101. package/dist/es2019/utils/split-cell.js +3 -2
  102. package/dist/es2019/utils/table-node-types.js +4 -7
  103. package/dist/es2019/utils/tables.js +0 -2
  104. package/dist/es2019/utils/test-utils.js +12 -16
  105. package/dist/es2019/utils/toggle-header.js +3 -10
  106. package/dist/es2019/utils/uuid.js +0 -2
  107. package/dist/es2019/version.json +1 -1
  108. package/dist/esm/cell-bookmark.js +0 -5
  109. package/dist/esm/cell-selection.js +37 -79
  110. package/dist/esm/index.js +1 -0
  111. package/dist/esm/pm-plugins/input.js +17 -71
  112. package/dist/esm/pm-plugins/table-editing.js +8 -13
  113. package/dist/esm/table-map.js +68 -133
  114. package/dist/esm/utils/add-column-at.js +2 -4
  115. package/dist/esm/utils/add-column.js +8 -20
  116. package/dist/esm/utils/add-row-at.js +8 -23
  117. package/dist/esm/utils/add-row.js +2 -21
  118. package/dist/esm/utils/analytics-helpers.js +4 -10
  119. package/dist/esm/utils/cells.js +0 -5
  120. package/dist/esm/utils/colspan.js +2 -14
  121. package/dist/esm/utils/copy-paste.js +44 -125
  122. package/dist/esm/utils/create-table.js +14 -25
  123. package/dist/esm/utils/draw-cell-selection.js +0 -1
  124. package/dist/esm/utils/empty-cells.js +2 -3
  125. package/dist/esm/utils/find.js +8 -8
  126. package/dist/esm/utils/fix-tables.js +13 -49
  127. package/dist/esm/utils/for-each-cell.js +6 -11
  128. package/dist/esm/utils/get-cell-selection-ranges.js +2 -4
  129. package/dist/esm/utils/get-cells-in-column.js +2 -3
  130. package/dist/esm/utils/get-cells-in-row.js +2 -3
  131. package/dist/esm/utils/get-cells-in-table.js +2 -4
  132. package/dist/esm/utils/get-selection-range-in-column.js +8 -24
  133. package/dist/esm/utils/get-selection-range-in-row.js +8 -24
  134. package/dist/esm/utils/get-selection-rect.js +2 -2
  135. package/dist/esm/utils/go-to-next-cell.js +3 -19
  136. package/dist/esm/utils/handle-paste.js +5 -23
  137. package/dist/esm/utils/is-selected.js +8 -10
  138. package/dist/esm/utils/is-selection-type.js +0 -1
  139. package/dist/esm/utils/move-column.js +3 -8
  140. package/dist/esm/utils/move-row.js +3 -7
  141. package/dist/esm/utils/normalize-selection.js +3 -22
  142. package/dist/esm/utils/remove-column.js +10 -31
  143. package/dist/esm/utils/remove-row.js +8 -35
  144. package/dist/esm/utils/remove-table.js +2 -4
  145. package/dist/esm/utils/reorder-utils.js +11 -26
  146. package/dist/esm/utils/replace-table.js +0 -2
  147. package/dist/esm/utils/select-nodes.js +11 -22
  148. package/dist/esm/utils/selection-cell.js +0 -2
  149. package/dist/esm/utils/selection-rect.js +0 -4
  150. package/dist/esm/utils/set-cell-attrs.js +2 -2
  151. package/dist/esm/utils/split-cell-with-type.js +2 -28
  152. package/dist/esm/utils/split-cell.js +3 -2
  153. package/dist/esm/utils/table-node-types.js +4 -7
  154. package/dist/esm/utils/tables.js +0 -2
  155. package/dist/esm/utils/test-utils.js +12 -16
  156. package/dist/esm/utils/toggle-header.js +3 -10
  157. package/dist/esm/version.json +1 -1
  158. package/package.json +6 -4
@@ -1,35 +1,23 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.cloneRowAt = exports.addRowAt = void 0;
9
-
10
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
-
12
9
  var _prosemirrorUtils = require("prosemirror-utils");
13
-
14
10
  var _tableMap = require("../table-map");
15
-
16
11
  var _addRow = require("./add-row");
17
-
18
12
  var _cloneTr = require("./clone-tr");
19
-
20
13
  var _find = require("./find");
21
-
22
14
  var _getCellsInRow = require("./get-cells-in-row");
23
-
24
15
  var _setCellAttrs = require("./set-cell-attrs");
25
-
26
16
  var _tableNodeTypes = require("./table-node-types");
27
-
28
17
  var filterCellsInRow = function filterCellsInRow(rowIndex, predicate) {
29
18
  return function (tr) {
30
19
  var foundCells = [];
31
20
  var cells = (0, _getCellsInRow.getCellsInRow)(rowIndex)(tr.selection);
32
-
33
21
  if (cells) {
34
22
  for (var j = cells.length - 1; j >= 0; j--) {
35
23
  if (predicate(cells[j], tr)) {
@@ -37,30 +25,25 @@ var filterCellsInRow = function filterCellsInRow(rowIndex, predicate) {
37
25
  }
38
26
  }
39
27
  }
40
-
41
28
  return foundCells;
42
29
  };
43
- }; // Returns a new transaction that adds a new row after `cloneRowIndex`, cloning the row attributes at `cloneRowIndex`.
44
-
30
+ };
45
31
 
32
+ // Returns a new transaction that adds a new row after `cloneRowIndex`, cloning the row attributes at `cloneRowIndex`.
46
33
  var cloneRowAt = function cloneRowAt(rowIndex) {
47
34
  return function (tr) {
48
35
  var table = (0, _find.findTable)(tr.selection);
49
-
50
36
  if (table) {
51
37
  var map = _tableMap.TableMap.get(table.node);
52
-
53
38
  if (rowIndex >= 0 && rowIndex <= map.height) {
54
39
  var tableNode = table.node;
55
40
  var tableNodes = (0, _tableNodeTypes.tableNodeTypes)(tableNode.type.schema);
56
41
  var rowPos = table.start;
57
-
58
42
  for (var i = 0; i < rowIndex + 1; i++) {
59
43
  rowPos += tableNode.child(i).nodeSize;
60
44
  }
61
-
62
- var cloneRow = tableNode.child(rowIndex); // Re-create the same nodes with same attrs, dropping the node content.
63
-
45
+ var cloneRow = tableNode.child(rowIndex);
46
+ // Re-create the same nodes with same attrs, dropping the node content.
64
47
  var cells = [];
65
48
  var rowWidth = 0;
66
49
  cloneRow.forEach(function (cell) {
@@ -69,16 +52,15 @@ var cloneRowAt = function cloneRowAt(rowIndex) {
69
52
  if (cell.attrs.rowspan === 1) {
70
53
  rowWidth += cell.attrs.colspan;
71
54
  var node = tableNodes[cell.type.spec.tableRole].createAndFill(cell.attrs, [], cell.marks);
72
-
73
55
  if (node) {
74
56
  cells.push(node);
75
57
  }
76
58
  }
77
- }); // If a higher row spans past our clone row, bump the higher row to cover this new row too.
59
+ });
78
60
 
61
+ // If a higher row spans past our clone row, bump the higher row to cover this new row too.
79
62
  if (rowWidth < map.width) {
80
63
  var rowSpanCells = [];
81
-
82
64
  var _loop = function _loop(_i) {
83
65
  var foundCells = filterCellsInRow(_i, function (cell, tr) {
84
66
  var rowspan = cell.node.attrs.rowspan;
@@ -87,11 +69,9 @@ var cloneRowAt = function cloneRowAt(rowIndex) {
87
69
  })(tr);
88
70
  rowSpanCells.push.apply(rowSpanCells, (0, _toConsumableArray2.default)(foundCells));
89
71
  };
90
-
91
72
  for (var _i = rowIndex; _i >= 0; _i--) {
92
73
  _loop(_i);
93
74
  }
94
-
95
75
  if (rowSpanCells.length) {
96
76
  rowSpanCells.forEach(function (cell) {
97
77
  tr = (0, _setCellAttrs.setCellAttrs)(cell, {
@@ -100,31 +80,24 @@ var cloneRowAt = function cloneRowAt(rowIndex) {
100
80
  });
101
81
  }
102
82
  }
103
-
104
83
  return (0, _prosemirrorUtils.safeInsert)(tableNodes.row.create(cloneRow.attrs, cells), rowPos)(tr);
105
84
  }
106
85
  }
107
-
108
86
  return tr;
109
87
  };
110
- }; // Returns a new transaction that adds a new row at index `rowIndex`. Optionally clone the previous row.
111
-
88
+ };
112
89
 
90
+ // Returns a new transaction that adds a new row at index `rowIndex`. Optionally clone the previous row.
113
91
  exports.cloneRowAt = cloneRowAt;
114
-
115
92
  var addRowAt = function addRowAt(rowIndex, clonePreviousRow) {
116
93
  return function (tr) {
117
94
  var table = (0, _find.findTable)(tr.selection);
118
-
119
95
  if (table) {
120
96
  var map = _tableMap.TableMap.get(table.node);
121
-
122
97
  var cloneRowIndex = rowIndex - 1;
123
-
124
98
  if (clonePreviousRow && cloneRowIndex >= 0) {
125
99
  return (0, _cloneTr.cloneTr)(cloneRowAt(cloneRowIndex)(tr));
126
100
  }
127
-
128
101
  if (rowIndex >= 0 && rowIndex <= map.height) {
129
102
  return (0, _cloneTr.cloneTr)((0, _addRow.addRow)(tr, {
130
103
  map: map,
@@ -133,9 +106,7 @@ var addRowAt = function addRowAt(rowIndex, clonePreviousRow) {
133
106
  }, rowIndex));
134
107
  }
135
108
  }
136
-
137
109
  return tr;
138
110
  };
139
111
  };
140
-
141
112
  exports.addRowAt = addRowAt;
@@ -1,61 +1,45 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.addRow = addRow;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
9
  var _tableNodeTypes = require("./table-node-types");
13
-
14
10
  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; }
15
-
16
11
  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) { (0, _defineProperty2.default)(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; }
17
-
18
12
  function rowIsHeader(map, table, row) {
19
13
  var headerCell = (0, _tableNodeTypes.tableNodeTypes)(table.type.schema).header_cell;
20
-
21
14
  for (var col = 0; col < map.width; col++) {
22
15
  var cell = table.nodeAt(map.map[col + row * map.width]);
23
-
24
16
  if (cell && cell.type !== headerCell) {
25
17
  return false;
26
18
  }
27
19
  }
28
-
29
20
  return true;
30
21
  }
31
-
32
22
  function addRow(tr, _ref, row) {
33
23
  var map = _ref.map,
34
- tableStart = _ref.tableStart,
35
- table = _ref.table;
24
+ tableStart = _ref.tableStart,
25
+ table = _ref.table;
36
26
  var rowPos = tableStart;
37
-
38
27
  for (var i = 0; i < row; i++) {
39
28
  rowPos += table.child(i).nodeSize;
40
29
  }
41
-
42
30
  var cells = [];
43
31
  var refRow = row > 0 ? -1 : 0;
44
-
45
32
  if (rowIsHeader(map, table, row + refRow)) {
46
33
  refRow = row === 0 || row === map.height ? null : 0;
47
34
  }
48
-
49
35
  for (var col = 0, index = map.width * row; col < map.width; col++, index++) {
50
36
  // Covered by a rowspan cell
51
37
  if (row > 0 && row < map.height && map.map[index] === map.map[index - map.width]) {
52
38
  var pos = map.map[index];
53
39
  var node = table.nodeAt(pos);
54
-
55
40
  if (!node) {
56
41
  throw new Error("addRow: node not found at pos ".concat(pos));
57
42
  }
58
-
59
43
  var attrs = node.attrs;
60
44
  tr.setNodeMarkup(tableStart + pos, undefined, _objectSpread(_objectSpread({}, attrs), {}, {
61
45
  rowspan: attrs.rowspan + 1
@@ -63,24 +47,19 @@ function addRow(tr, _ref, row) {
63
47
  col += attrs.colspan - 1;
64
48
  } else {
65
49
  var type = void 0;
66
-
67
50
  if (refRow == null) {
68
51
  type = (0, _tableNodeTypes.tableNodeTypes)(table.type.schema).cell;
69
52
  } else {
70
53
  var mappedPos = map.map[index + refRow * map.width];
71
54
  var cell = table.nodeAt(mappedPos);
72
-
73
55
  if (!cell) {
74
56
  throw new Error("addRow: invalid node at mapped pos ".concat(mappedPos));
75
57
  }
76
-
77
58
  type = cell.type;
78
59
  }
79
-
80
60
  cells.push(type.createAndFill());
81
61
  }
82
62
  }
83
-
84
63
  var rowType = (0, _tableNodeTypes.tableNodeTypes)(table.type.schema).row;
85
64
  var rowCells = rowType.create(null, cells);
86
65
  tr.insert(rowPos, rowCells);
@@ -5,25 +5,19 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getSelectedCellInfo = getSelectedCellInfo;
7
7
  exports.getSelectedTableInfo = getSelectedTableInfo;
8
-
9
8
  var _tableMap = require("../table-map");
10
-
11
9
  var _find = require("./find");
12
-
13
10
  var _getSelectionRect = require("./get-selection-rect");
14
-
15
11
  function getSelectedTableInfo(selection) {
16
12
  var map;
17
13
  var totalRowCount = 0;
18
14
  var totalColumnCount = 0;
19
15
  var table = (0, _find.findTable)(selection);
20
-
21
16
  if (table) {
22
17
  map = _tableMap.TableMap.get(table.node);
23
18
  totalRowCount = map.height;
24
19
  totalColumnCount = map.width;
25
20
  }
26
-
27
21
  return {
28
22
  table: table,
29
23
  map: map,
@@ -31,28 +25,23 @@ function getSelectedTableInfo(selection) {
31
25
  totalColumnCount: totalColumnCount
32
26
  };
33
27
  }
34
-
35
28
  function getSelectedCellInfo(selection) {
36
29
  var horizontalCells = 1;
37
30
  var verticalCells = 1;
38
31
  var totalCells = 1;
39
-
40
32
  var _getSelectedTableInfo = getSelectedTableInfo(selection),
41
- table = _getSelectedTableInfo.table,
42
- map = _getSelectedTableInfo.map,
43
- totalRowCount = _getSelectedTableInfo.totalRowCount,
44
- totalColumnCount = _getSelectedTableInfo.totalColumnCount;
45
-
33
+ table = _getSelectedTableInfo.table,
34
+ map = _getSelectedTableInfo.map,
35
+ totalRowCount = _getSelectedTableInfo.totalRowCount,
36
+ totalColumnCount = _getSelectedTableInfo.totalColumnCount;
46
37
  if (table && map) {
47
38
  var rect = (0, _getSelectionRect.getSelectionRect)(selection);
48
-
49
39
  if (rect) {
50
40
  totalCells = map.cellsInRect(rect).length;
51
41
  horizontalCells = rect.right - rect.left;
52
42
  verticalCells = rect.bottom - rect.top;
53
43
  }
54
44
  }
55
-
56
45
  return {
57
46
  totalRowCount: totalRowCount,
58
47
  totalColumnCount: totalColumnCount,
@@ -7,48 +7,36 @@ exports.cellAround = cellAround;
7
7
  exports.cellNear = cellNear;
8
8
  exports.nextCell = nextCell;
9
9
  exports.pointsAtCell = pointsAtCell;
10
-
11
10
  var _tableMap = require("../table-map");
12
-
13
11
  function pointsAtCell($pos) {
14
12
  return $pos.parent.type.spec.tableRole === 'row' && $pos.nodeAfter;
15
13
  }
16
-
17
14
  function cellNear($pos) {
18
15
  for (var after = $pos.nodeAfter, pos = $pos.pos; after; after = after.firstChild, pos++) {
19
16
  var role = after.type.spec.tableRole;
20
-
21
17
  if (role === 'cell' || role === 'header_cell') {
22
18
  return $pos.doc.resolve(pos);
23
19
  }
24
20
  }
25
-
26
21
  for (var before = $pos.nodeBefore, _pos = $pos.pos; before; before = before.lastChild, _pos--) {
27
22
  var _role = before.type.spec.tableRole;
28
-
29
23
  if (_role === 'cell' || _role === 'header_cell') {
30
24
  return $pos.doc.resolve(_pos - before.nodeSize);
31
25
  }
32
26
  }
33
-
34
27
  return null;
35
28
  }
36
-
37
29
  function cellAround($pos) {
38
30
  for (var d = $pos.depth - 1; d > 0; d--) {
39
31
  if ($pos.node(d).type.spec.tableRole === 'row') {
40
32
  return $pos.node(0).resolve($pos.before(d + 1));
41
33
  }
42
34
  }
43
-
44
35
  return null;
45
36
  }
46
-
47
37
  function nextCell($pos, axis, dir) {
48
38
  var start = $pos.start(-1);
49
-
50
39
  var map = _tableMap.TableMap.get($pos.node(-1));
51
-
52
40
  var moved = map.nextCell($pos.pos - start, axis, dir);
53
41
  return moved == null ? null : $pos.node(0).resolve(start + moved);
54
42
  }
@@ -4,10 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.cloneTr = void 0;
7
-
8
7
  // Creates a new transaction object from a given transaction
9
8
  var cloneTr = function cloneTr(tr) {
10
9
  return Object.assign(Object.create(tr), tr).setTime(Date.now());
11
10
  };
12
-
13
11
  exports.cloneTr = cloneTr;
@@ -1,71 +1,55 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.addColSpan = addColSpan;
9
8
  exports.assertColspan = assertColspan;
10
9
  exports.removeColSpan = removeColSpan;
11
-
12
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
-
14
11
  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; }
15
-
16
12
  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) { (0, _defineProperty2.default)(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; }
17
-
18
13
  function removeColSpan(attrs, pos) {
19
14
  var n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
20
-
21
15
  if (!attrs.colspan) {
22
16
  throw new Error('removeColSpan(): attrs.colspan not defined');
23
17
  }
24
-
25
18
  var result = _objectSpread(_objectSpread({}, attrs), {}, {
26
19
  colspan: attrs.colspan - n
27
20
  });
28
-
29
21
  if (result.colwidth) {
30
22
  result.colwidth = result.colwidth.slice();
31
23
  result.colwidth.splice(pos, n);
32
-
33
24
  if (!result.colwidth.some(function (w) {
34
25
  return w > 0;
35
26
  })) {
36
27
  result.colwidth = undefined;
37
28
  }
38
29
  }
39
-
40
30
  return result;
41
31
  }
42
-
43
32
  function assertColspan(attrs) {
44
33
  if (typeof attrs.colspan === 'undefined') {
45
34
  throw new Error('addColSpan: attrs.colspan is not defined');
46
35
  }
47
-
48
36
  if (typeof attrs.colspan !== 'number' || Number.isNaN(attrs.colspan) || attrs.colspan < 1) {
49
37
  throw new Error("addColSpan: attrs.colspan must be number >= 1, received: ".concat(attrs.colspan));
50
38
  }
51
- } // TODO: replace "addColSpan" from table plugin with this function
52
-
39
+ }
53
40
 
41
+ // TODO: replace "addColSpan" from table plugin with this function
54
42
  function addColSpan(attrs, pos) {
55
43
  var n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
56
44
  assertColspan(attrs);
57
-
58
45
  var result = _objectSpread(_objectSpread({}, attrs), {}, {
59
46
  colspan: attrs.colspan + n
60
47
  });
61
-
62
48
  if (result.colwidth) {
63
49
  result.colwidth = result.colwidth.slice();
64
-
65
50
  for (var i = 0; i < n; i++) {
66
51
  result.colwidth.splice(pos, 0, 0);
67
52
  }
68
53
  }
69
-
70
54
  return result;
71
55
  }