@atlaskit/editor-tables 2.2.4 → 2.2.5
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 +6 -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 +63 -134
- 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 +4 -33
- 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 +54 -124
- 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 +65 -130
- 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 +4 -22
- 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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atlaskit/editor-tables
|
|
2
2
|
|
|
3
|
+
## 2.2.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`2e01c9c74b5`](https://bitbucket.org/atlassian/atlassian-frontend/commits/2e01c9c74b5) - DUMMY remove before merging to master; dupe adf-schema via adf-utils
|
|
8
|
+
|
|
3
9
|
## 2.2.4
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -1,27 +1,20 @@
|
|
|
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.CellBookmark = void 0;
|
|
9
|
-
|
|
10
8
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
|
|
12
9
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
|
|
14
10
|
var _prosemirrorState = require("prosemirror-state");
|
|
15
|
-
|
|
16
11
|
var _tables = require("./utils/tables");
|
|
17
|
-
|
|
18
12
|
var CellBookmark = /*#__PURE__*/function () {
|
|
19
13
|
function CellBookmark(anchor, head) {
|
|
20
14
|
(0, _classCallCheck2.default)(this, CellBookmark);
|
|
21
15
|
this.anchor = anchor;
|
|
22
16
|
this.head = head;
|
|
23
17
|
}
|
|
24
|
-
|
|
25
18
|
(0, _createClass2.default)(CellBookmark, [{
|
|
26
19
|
key: "map",
|
|
27
20
|
value: function map(mapping) {
|
|
@@ -32,7 +25,6 @@ var CellBookmark = /*#__PURE__*/function () {
|
|
|
32
25
|
value: function resolve(doc) {
|
|
33
26
|
var $anchorCell = doc.resolve(this.anchor);
|
|
34
27
|
var $headCell = doc.resolve(this.head);
|
|
35
|
-
|
|
36
28
|
if ($anchorCell.parent.type.spec.tableRole === 'row' && $headCell.parent.type.spec.tableRole === 'row' && $anchorCell.index() < $anchorCell.parent.childCount && $headCell.index() < $headCell.parent.childCount && (0, _tables.inSameTable)($anchorCell, $headCell)) {
|
|
37
29
|
var data = {
|
|
38
30
|
type: 'cell',
|
|
@@ -41,11 +33,9 @@ var CellBookmark = /*#__PURE__*/function () {
|
|
|
41
33
|
};
|
|
42
34
|
return _prosemirrorState.Selection.fromJSON(doc, data);
|
|
43
35
|
}
|
|
44
|
-
|
|
45
36
|
return _prosemirrorState.Selection.near($headCell, 1);
|
|
46
37
|
}
|
|
47
38
|
}]);
|
|
48
39
|
return CellBookmark;
|
|
49
40
|
}();
|
|
50
|
-
|
|
51
41
|
exports.CellBookmark = CellBookmark;
|
|
@@ -1,48 +1,32 @@
|
|
|
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.CellSelection = void 0;
|
|
9
|
-
|
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
9
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
-
|
|
14
10
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
-
|
|
16
11
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
17
|
-
|
|
18
12
|
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
19
|
-
|
|
20
13
|
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
21
|
-
|
|
22
14
|
var _prosemirrorModel = require("prosemirror-model");
|
|
23
|
-
|
|
24
15
|
var _prosemirrorState = require("prosemirror-state");
|
|
25
|
-
|
|
26
16
|
var _cellBookmark = require("./cell-bookmark");
|
|
27
|
-
|
|
28
17
|
var _tableMap = require("./table-map");
|
|
29
|
-
|
|
30
18
|
var _cells = require("./utils/cells");
|
|
31
|
-
|
|
32
19
|
var _colspan = require("./utils/colspan");
|
|
33
|
-
|
|
34
20
|
var _getCellSelectionRanges = require("./utils/get-cell-selection-ranges");
|
|
35
|
-
|
|
36
21
|
var _tables = require("./utils/tables");
|
|
37
|
-
|
|
38
22
|
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; }
|
|
39
|
-
|
|
40
23
|
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; }
|
|
41
|
-
|
|
42
24
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
25
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } // Was copied from https://github.com/ProseMirror/prosemirror-tables/blob/master/src/cellselection.js
|
|
26
|
+
// This file defines a ProseMirror selection subclass that models
|
|
27
|
+
// table cell selections. The table plugin needs to be active to wire
|
|
28
|
+
// in the user interaction part of table selections (so that you
|
|
29
|
+
// actually get such selections when you select across cells).
|
|
46
30
|
// ::- A [`Selection`](http://prosemirror.net/docs/ref/#state.Selection)
|
|
47
31
|
// subclass that represents a cell selection spanning part of a table.
|
|
48
32
|
// With the plugin enabled, these will be created when the user
|
|
@@ -50,138 +34,112 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
50
34
|
// `selectedCell` CSS class.
|
|
51
35
|
var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
52
36
|
(0, _inherits2.default)(CellSelection, _Selection);
|
|
53
|
-
|
|
54
37
|
var _super = _createSuper(CellSelection);
|
|
55
|
-
|
|
56
38
|
// :: (ResolvedPos, ?ResolvedPos)
|
|
57
39
|
// A table selection is identified by its anchor and head cells. The
|
|
58
40
|
// positions given to this constructor should point _before_ two
|
|
59
41
|
// cells in the same table. They may be the same, to select a single
|
|
60
42
|
// cell.
|
|
43
|
+
|
|
61
44
|
function CellSelection($anchorCell) {
|
|
62
45
|
var _this;
|
|
63
|
-
|
|
64
46
|
var $headCell = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : $anchorCell;
|
|
65
47
|
(0, _classCallCheck2.default)(this, CellSelection);
|
|
66
48
|
var ranges = (0, _getCellSelectionRanges.getCellSelectionRanges)($anchorCell, $headCell);
|
|
67
|
-
_this = _super.call(this, ranges[0].$from, ranges[0].$to, ranges);
|
|
49
|
+
_this = _super.call(this, ranges[0].$from, ranges[0].$to, ranges);
|
|
50
|
+
// :: ResolvedPos
|
|
68
51
|
// A resolved position pointing _in front of_ the anchor cell (the one
|
|
69
52
|
// that doesn't move when extending the selection).
|
|
70
|
-
|
|
71
|
-
|
|
53
|
+
_this.$anchorCell = $anchorCell;
|
|
54
|
+
// :: ResolvedPos
|
|
72
55
|
// A resolved position pointing in front of the head cell (the one
|
|
73
56
|
// moves when extending the selection).
|
|
74
|
-
|
|
75
57
|
_this.$headCell = $headCell;
|
|
76
58
|
_this.visible = false;
|
|
77
59
|
return _this;
|
|
78
60
|
}
|
|
79
|
-
|
|
80
61
|
(0, _createClass2.default)(CellSelection, [{
|
|
81
62
|
key: "map",
|
|
82
63
|
value: function map(doc, mapping) {
|
|
83
64
|
var $anchorCell = doc.resolve(mapping.map(this.$anchorCell.pos));
|
|
84
65
|
var $headCell = doc.resolve(mapping.map(this.$headCell.pos));
|
|
85
|
-
|
|
86
66
|
if ((0, _cells.pointsAtCell)($anchorCell) && (0, _cells.pointsAtCell)($headCell) && (0, _tables.inSameTable)($anchorCell, $headCell)) {
|
|
87
67
|
var tableChanged = this.$anchorCell.node(-1) !== $anchorCell.node(-1);
|
|
88
|
-
|
|
89
68
|
if (tableChanged && this.isRowSelection()) {
|
|
90
69
|
return CellSelection.rowSelection($anchorCell, $headCell);
|
|
91
70
|
}
|
|
92
|
-
|
|
93
71
|
if (tableChanged && this.isColSelection()) {
|
|
94
72
|
return CellSelection.colSelection($anchorCell, $headCell);
|
|
95
73
|
}
|
|
96
|
-
|
|
97
74
|
return new CellSelection($anchorCell, $headCell);
|
|
98
75
|
}
|
|
99
|
-
|
|
100
76
|
return _prosemirrorState.TextSelection.between($anchorCell, $headCell);
|
|
101
|
-
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// :: () → Slice
|
|
102
80
|
// Returns a rectangular slice of table rows containing the selected
|
|
103
81
|
// cells.
|
|
104
|
-
|
|
105
82
|
}, {
|
|
106
83
|
key: "content",
|
|
107
84
|
value: function content() {
|
|
108
85
|
var table = this.$anchorCell.node(-1);
|
|
109
|
-
|
|
110
86
|
var map = _tableMap.TableMap.get(table);
|
|
111
|
-
|
|
112
87
|
var start = this.$anchorCell.start(-1);
|
|
113
88
|
var rect = map.rectBetween(this.$anchorCell.pos - start, this.$headCell.pos - start);
|
|
114
89
|
var seen = {};
|
|
115
90
|
var rows = [];
|
|
116
|
-
|
|
117
91
|
for (var row = rect.top; row < rect.bottom; row++) {
|
|
118
92
|
var rowContent = [];
|
|
119
|
-
|
|
120
93
|
for (var index = row * map.width + rect.left, col = rect.left; col < rect.right; col++, index++) {
|
|
121
94
|
var _pos = map.map[index];
|
|
122
|
-
|
|
123
95
|
if (!seen[_pos]) {
|
|
124
96
|
seen[_pos] = true;
|
|
125
97
|
var cellRect = map.findCell(_pos);
|
|
126
98
|
var cell = table.nodeAt(_pos);
|
|
127
|
-
|
|
128
99
|
if (cell === null || cell === undefined) {
|
|
129
100
|
throw new Error("No cell at position ".concat(_pos));
|
|
130
101
|
}
|
|
131
|
-
|
|
132
102
|
var extraLeft = rect.left - cellRect.left;
|
|
133
103
|
var extraRight = cellRect.right - rect.right;
|
|
134
|
-
|
|
135
104
|
if (extraLeft > 0 || extraRight > 0) {
|
|
136
105
|
var _cell = cell,
|
|
137
|
-
|
|
138
|
-
|
|
106
|
+
attrs = _cell.attrs;
|
|
139
107
|
if (!attrs) {
|
|
140
108
|
throw new Error("No cell at position ".concat(_pos));
|
|
141
109
|
}
|
|
142
|
-
|
|
143
110
|
if (extraLeft > 0) {
|
|
144
111
|
attrs = (0, _colspan.removeColSpan)(attrs, 0, extraLeft);
|
|
145
112
|
}
|
|
146
|
-
|
|
147
113
|
if (extraRight > 0) {
|
|
148
114
|
attrs = (0, _colspan.removeColSpan)(attrs, attrs.colspan - extraRight, extraRight);
|
|
149
115
|
}
|
|
150
|
-
|
|
151
116
|
if (cellRect.left < rect.left) {
|
|
152
117
|
cell = cell.type.createAndFill(attrs);
|
|
153
118
|
} else {
|
|
154
119
|
cell = cell.type.create(attrs, cell.content);
|
|
155
120
|
}
|
|
156
121
|
}
|
|
157
|
-
|
|
158
122
|
if (cell === null || cell === undefined) {
|
|
159
123
|
throw new Error("No cell at position after create/createAndFill");
|
|
160
124
|
}
|
|
161
|
-
|
|
162
125
|
if (cellRect.top < rect.top || cellRect.bottom > rect.bottom) {
|
|
163
126
|
var _attrs = _objectSpread(_objectSpread({}, cell.attrs), {}, {
|
|
164
127
|
rowspan: Math.min(cellRect.bottom, rect.bottom) - Math.max(cellRect.top, rect.top)
|
|
165
128
|
});
|
|
166
|
-
|
|
167
129
|
if (cellRect.top < rect.top) {
|
|
168
130
|
cell = cell.type.createAndFill(_attrs);
|
|
169
131
|
} else {
|
|
170
132
|
cell = cell.type.create(_attrs, cell.content);
|
|
171
133
|
}
|
|
172
134
|
}
|
|
173
|
-
|
|
174
135
|
if (cell === null || cell === undefined) {
|
|
175
136
|
throw new Error("No cell at position before rowContent.push");
|
|
176
137
|
}
|
|
177
|
-
|
|
178
138
|
rowContent.push(cell);
|
|
179
139
|
}
|
|
180
140
|
}
|
|
181
|
-
|
|
182
141
|
rows.push(table.child(row).copy(_prosemirrorModel.Fragment.from(rowContent)));
|
|
183
142
|
}
|
|
184
|
-
|
|
185
143
|
var fragment = this.isColSelection() && this.isRowSelection() ? table : rows;
|
|
186
144
|
return new _prosemirrorModel.Slice(_prosemirrorModel.Fragment.from(fragment), 1, 1);
|
|
187
145
|
}
|
|
@@ -191,17 +149,14 @@ var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
191
149
|
var content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _prosemirrorModel.Slice.empty;
|
|
192
150
|
var mapFrom = tr.steps.length;
|
|
193
151
|
var ranges = this.ranges;
|
|
194
|
-
|
|
195
152
|
for (var i = 0; i < ranges.length; i++) {
|
|
196
153
|
var _ranges$i = ranges[i],
|
|
197
|
-
|
|
198
|
-
|
|
154
|
+
$from = _ranges$i.$from,
|
|
155
|
+
$to = _ranges$i.$to;
|
|
199
156
|
var mapping = tr.mapping.slice(mapFrom);
|
|
200
157
|
tr.replace(mapping.map($from.pos), mapping.map($to.pos), i ? _prosemirrorModel.Slice.empty : content);
|
|
201
158
|
}
|
|
202
|
-
|
|
203
159
|
var sel = _prosemirrorState.Selection.findFrom(tr.doc.resolve(tr.mapping.slice(mapFrom).map(this.to)), -1);
|
|
204
|
-
|
|
205
160
|
if (sel) {
|
|
206
161
|
tr.setSelection(sel);
|
|
207
162
|
}
|
|
@@ -215,82 +170,74 @@ var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
215
170
|
key: "forEachCell",
|
|
216
171
|
value: function forEachCell(f) {
|
|
217
172
|
var table = this.$anchorCell.node(-1);
|
|
218
|
-
|
|
219
173
|
var map = _tableMap.TableMap.get(table);
|
|
220
|
-
|
|
221
174
|
var start = this.$anchorCell.start(-1);
|
|
222
175
|
var cells = map.cellsInRect(map.rectBetween(this.$anchorCell.pos - start, this.$headCell.pos - start));
|
|
223
|
-
|
|
224
176
|
for (var i = 0; i < cells.length; i++) {
|
|
225
177
|
var cell = table.nodeAt(cells[i]);
|
|
226
|
-
|
|
227
178
|
if (cell === null || cell === undefined) {
|
|
228
179
|
throw new Error("undefined cell at pos ".concat(cells[i]));
|
|
229
180
|
}
|
|
230
|
-
|
|
231
181
|
f(cell, start + cells[i]);
|
|
232
182
|
}
|
|
233
|
-
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// :: () → bool
|
|
234
186
|
// True if this selection goes all the way from the top to the
|
|
235
187
|
// bottom of the table.
|
|
236
|
-
|
|
237
188
|
}, {
|
|
238
189
|
key: "isColSelection",
|
|
239
190
|
value: function isColSelection() {
|
|
240
191
|
if (!this.$anchorCell || !this.$headCell) {
|
|
241
192
|
throw new Error('invalid $anchorCell or $headCell');
|
|
242
193
|
}
|
|
243
|
-
|
|
244
194
|
var anchorTop = this.$anchorCell.index(-1);
|
|
245
195
|
var headTop = this.$headCell.index(-1);
|
|
246
|
-
|
|
247
196
|
if (Math.min(anchorTop, headTop) > 0) {
|
|
248
197
|
return false;
|
|
249
198
|
}
|
|
250
|
-
|
|
251
199
|
var anchorBot = anchorTop + this.$anchorCell.nodeAfter.attrs.rowspan;
|
|
252
200
|
var headBot = headTop + this.$headCell.nodeAfter.attrs.rowspan;
|
|
253
201
|
return Math.max(anchorBot, headBot) === this.$headCell.node(-1).childCount;
|
|
254
|
-
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// :: (ResolvedPos, ?ResolvedPos) → CellSelection
|
|
255
205
|
// Returns the smallest column selection that covers the given anchor
|
|
256
206
|
// and head cell.
|
|
257
|
-
|
|
258
207
|
}, {
|
|
259
208
|
key: "isRowSelection",
|
|
260
|
-
value:
|
|
209
|
+
value:
|
|
210
|
+
// :: () → bool
|
|
261
211
|
// True if this selection goes all the way from the left to the
|
|
262
212
|
// right of the table.
|
|
263
213
|
function isRowSelection() {
|
|
264
214
|
if (!this.$anchorCell || !this.$headCell) {
|
|
265
215
|
return false;
|
|
266
216
|
}
|
|
267
|
-
|
|
268
217
|
var start = this.$anchorCell.start(-1);
|
|
269
|
-
|
|
270
218
|
var map = _tableMap.TableMap.get(this.$anchorCell.node(-1));
|
|
271
|
-
|
|
272
219
|
var rowAtAnchorCell = map.rowCount(this.$anchorCell.pos - start);
|
|
273
220
|
var rowAtHeadCell = map.rowCount(this.$headCell.pos - start);
|
|
274
|
-
var isSelectionSameRow = rowAtAnchorCell === rowAtHeadCell;
|
|
221
|
+
var isSelectionSameRow = rowAtAnchorCell === rowAtHeadCell;
|
|
222
|
+
|
|
223
|
+
// if anchor and head in the same line, counting how many cells
|
|
275
224
|
// should be in the row except merged cell
|
|
225
|
+
var maxColumnInSelectedRow = map.getMaxColInRow(this.$anchorCell);
|
|
276
226
|
|
|
277
|
-
|
|
227
|
+
// if selected cells less than table max column amount, and
|
|
278
228
|
// the anchor/head not in a merged cell
|
|
279
229
|
// it should be select maxColumnInSelectedRow to be TRUE
|
|
280
|
-
|
|
281
230
|
if (isSelectionSameRow && this.ranges.length <= map.width && !map.isPosMerged(this.$anchorCell.pos - start) && !map.isPosMerged(this.$headCell.pos - start)) {
|
|
282
231
|
return this.ranges.length === maxColumnInSelectedRow;
|
|
283
|
-
}
|
|
284
|
-
// last column to select the whole row.
|
|
285
|
-
|
|
232
|
+
}
|
|
286
233
|
|
|
234
|
+
// If anchor and head in different row, it should be always in first and
|
|
235
|
+
// last column to select the whole row.
|
|
287
236
|
var anchorLeft = map.colCount(this.$anchorCell.pos - start);
|
|
288
237
|
var headLeft = map.colCount(this.$headCell.pos - start);
|
|
289
|
-
|
|
290
238
|
if (Math.min(anchorLeft, headLeft) > 0) {
|
|
291
239
|
return false;
|
|
292
240
|
}
|
|
293
|
-
|
|
294
241
|
var anchorRight = anchorLeft + this.$anchorCell.nodeAfter.attrs.colspan;
|
|
295
242
|
var headRight = headLeft + this.$headCell.nodeAfter.attrs.colspan;
|
|
296
243
|
return Math.max(anchorRight, headRight) === map.width;
|
|
@@ -299,10 +246,11 @@ var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
299
246
|
key: "eq",
|
|
300
247
|
value: function eq(other) {
|
|
301
248
|
return other instanceof CellSelection && other.$anchorCell.pos === this.$anchorCell.pos && other.$headCell.pos === this.$headCell.pos;
|
|
302
|
-
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// :: (ResolvedPos, ?ResolvedPos) → CellSelection
|
|
303
252
|
// Returns the smallest row selection that covers the given anchor
|
|
304
253
|
// and head cell.
|
|
305
|
-
|
|
306
254
|
}, {
|
|
307
255
|
key: "toJSON",
|
|
308
256
|
value: function toJSON() {
|
|
@@ -323,19 +271,15 @@ var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
323
271
|
var $headCell = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : $anchorCell;
|
|
324
272
|
var $calculatedAnchorCell = $anchorCell;
|
|
325
273
|
var $calculatedHeadCell = $headCell;
|
|
326
|
-
|
|
327
274
|
var map = _tableMap.TableMap.get($calculatedAnchorCell.node(-1));
|
|
328
|
-
|
|
329
275
|
var start = $calculatedAnchorCell.start(-1);
|
|
330
276
|
var anchorRect = map.findCell($calculatedAnchorCell.pos - start);
|
|
331
277
|
var headRect = map.findCell($calculatedHeadCell.pos - start);
|
|
332
278
|
var doc = $calculatedAnchorCell.node(0);
|
|
333
|
-
|
|
334
279
|
if (anchorRect.top <= headRect.top) {
|
|
335
280
|
if (anchorRect.top > 0) {
|
|
336
281
|
$calculatedAnchorCell = doc.resolve(start + map.map[anchorRect.left]);
|
|
337
282
|
}
|
|
338
|
-
|
|
339
283
|
if (headRect.bottom < map.height) {
|
|
340
284
|
$calculatedHeadCell = doc.resolve(start + map.map[map.width * (map.height - 1) + headRect.right - 1]);
|
|
341
285
|
}
|
|
@@ -343,12 +287,10 @@ var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
343
287
|
if (headRect.top > 0) {
|
|
344
288
|
$calculatedHeadCell = doc.resolve(start + map.map[headRect.left]);
|
|
345
289
|
}
|
|
346
|
-
|
|
347
290
|
if (anchorRect.bottom < map.height) {
|
|
348
291
|
$calculatedAnchorCell = doc.resolve(start + map.map[map.width * (map.height - 1) + anchorRect.right - 1]);
|
|
349
292
|
}
|
|
350
293
|
}
|
|
351
|
-
|
|
352
294
|
return new CellSelection($calculatedAnchorCell, $calculatedHeadCell);
|
|
353
295
|
}
|
|
354
296
|
}, {
|
|
@@ -357,19 +299,15 @@ var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
357
299
|
var $headCell = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : $anchorCell;
|
|
358
300
|
var $calculatedAnchorCell = $anchorCell;
|
|
359
301
|
var $calculatedHeadCell = $headCell;
|
|
360
|
-
|
|
361
302
|
var map = _tableMap.TableMap.get($calculatedAnchorCell.node(-1));
|
|
362
|
-
|
|
363
303
|
var start = $calculatedAnchorCell.start(-1);
|
|
364
304
|
var anchorRect = map.findCell($calculatedAnchorCell.pos - start);
|
|
365
305
|
var headRect = map.findCell($calculatedHeadCell.pos - start);
|
|
366
306
|
var doc = $calculatedAnchorCell.node(0);
|
|
367
|
-
|
|
368
307
|
if (anchorRect.left <= headRect.left) {
|
|
369
308
|
if (anchorRect.left > 0) {
|
|
370
309
|
$calculatedAnchorCell = doc.resolve(start + map.map[anchorRect.top * map.width]);
|
|
371
310
|
}
|
|
372
|
-
|
|
373
311
|
if (headRect.right < map.width) {
|
|
374
312
|
$calculatedHeadCell = doc.resolve(start + map.map[map.width * (headRect.top + 1) - 1]);
|
|
375
313
|
}
|
|
@@ -377,20 +315,19 @@ var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
377
315
|
if (headRect.left > 0) {
|
|
378
316
|
$calculatedHeadCell = doc.resolve(start + map.map[headRect.top * map.width]);
|
|
379
317
|
}
|
|
380
|
-
|
|
381
318
|
if (anchorRect.right < map.width) {
|
|
382
319
|
$calculatedAnchorCell = doc.resolve(start + map.map[map.width * (anchorRect.top + 1) - 1]);
|
|
383
320
|
}
|
|
384
321
|
}
|
|
385
|
-
|
|
386
322
|
return new CellSelection($calculatedAnchorCell, $calculatedHeadCell);
|
|
387
323
|
}
|
|
388
324
|
}, {
|
|
389
325
|
key: "fromJSON",
|
|
390
326
|
value: function fromJSON(doc, json) {
|
|
391
327
|
return new CellSelection(doc.resolve(json.anchor), doc.resolve(json.head));
|
|
392
|
-
}
|
|
328
|
+
}
|
|
393
329
|
|
|
330
|
+
// :: (Node, number, ?number) → CellSelection
|
|
394
331
|
}, {
|
|
395
332
|
key: "create",
|
|
396
333
|
value: function create(doc, anchorCell) {
|
|
@@ -400,7 +337,5 @@ var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
400
337
|
}]);
|
|
401
338
|
return CellSelection;
|
|
402
339
|
}(_prosemirrorState.Selection);
|
|
403
|
-
|
|
404
340
|
exports.CellSelection = CellSelection;
|
|
405
|
-
|
|
406
341
|
_prosemirrorState.Selection.jsonID('cell', CellSelection);
|
package/dist/cjs/index.js
CHANGED
|
@@ -33,11 +33,7 @@ Object.defineProperty(exports, "uuid", {
|
|
|
33
33
|
return _uuid.uuid;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
|
-
|
|
37
36
|
var _tableMap = require("./table-map");
|
|
38
|
-
|
|
39
37
|
var _cellSelection = require("./cell-selection");
|
|
40
|
-
|
|
41
38
|
var _find = require("./utils/find");
|
|
42
|
-
|
|
43
39
|
var _uuid = require("./utils/uuid");
|