@atlaskit/editor-tables 2.2.3 → 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 +14 -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 +24 -75
- 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 +94 -120
- 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 +4 -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 +27 -63
- 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 +85 -99
- 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 +4 -13
- 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 +24 -63
- 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 +88 -109
- 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 +4 -13
- package/dist/esm/version.json +1 -1
- package/dist/types/utils/toggle-header.d.ts +3 -0
- package/package.json +7 -5
- package/report.api.md +11 -0
|
@@ -4,20 +4,17 @@ import _createClass from "@babel/runtime/helpers/createClass";
|
|
|
4
4
|
import _inherits from "@babel/runtime/helpers/inherits";
|
|
5
5
|
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
6
6
|
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
7
|
-
|
|
8
7
|
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; }
|
|
9
|
-
|
|
10
8
|
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; }
|
|
11
|
-
|
|
12
9
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
13
|
-
|
|
14
10
|
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; } }
|
|
15
|
-
|
|
16
11
|
// Was copied from https://github.com/ProseMirror/prosemirror-tables/blob/master/src/cellselection.js
|
|
12
|
+
|
|
17
13
|
// This file defines a ProseMirror selection subclass that models
|
|
18
14
|
// table cell selections. The table plugin needs to be active to wire
|
|
19
15
|
// in the user interaction part of table selections (so that you
|
|
20
16
|
// actually get such selections when you select across cells).
|
|
17
|
+
|
|
21
18
|
import { Fragment, Slice } from 'prosemirror-model';
|
|
22
19
|
import { Selection, TextSelection } from 'prosemirror-state';
|
|
23
20
|
import { CellBookmark } from './cell-bookmark';
|
|
@@ -25,68 +22,60 @@ import { TableMap } from './table-map';
|
|
|
25
22
|
import { pointsAtCell } from './utils/cells';
|
|
26
23
|
import { removeColSpan } from './utils/colspan';
|
|
27
24
|
import { getCellSelectionRanges } from './utils/get-cell-selection-ranges';
|
|
28
|
-
import { inSameTable } from './utils/tables';
|
|
25
|
+
import { inSameTable } from './utils/tables';
|
|
26
|
+
|
|
27
|
+
// ::- A [`Selection`](http://prosemirror.net/docs/ref/#state.Selection)
|
|
29
28
|
// subclass that represents a cell selection spanning part of a table.
|
|
30
29
|
// With the plugin enabled, these will be created when the user
|
|
31
30
|
// selects across cells, and will be drawn by giving selected cells a
|
|
32
31
|
// `selectedCell` CSS class.
|
|
33
|
-
|
|
34
32
|
export var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
35
33
|
_inherits(CellSelection, _Selection);
|
|
36
|
-
|
|
37
34
|
var _super = _createSuper(CellSelection);
|
|
38
|
-
|
|
39
35
|
// :: (ResolvedPos, ?ResolvedPos)
|
|
40
36
|
// A table selection is identified by its anchor and head cells. The
|
|
41
37
|
// positions given to this constructor should point _before_ two
|
|
42
38
|
// cells in the same table. They may be the same, to select a single
|
|
43
39
|
// cell.
|
|
40
|
+
|
|
44
41
|
function CellSelection($anchorCell) {
|
|
45
42
|
var _this;
|
|
46
|
-
|
|
47
43
|
var $headCell = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : $anchorCell;
|
|
48
|
-
|
|
49
44
|
_classCallCheck(this, CellSelection);
|
|
50
|
-
|
|
51
45
|
var ranges = getCellSelectionRanges($anchorCell, $headCell);
|
|
52
|
-
_this = _super.call(this, ranges[0].$from, ranges[0].$to, ranges);
|
|
46
|
+
_this = _super.call(this, ranges[0].$from, ranges[0].$to, ranges);
|
|
47
|
+
// :: ResolvedPos
|
|
53
48
|
// A resolved position pointing _in front of_ the anchor cell (the one
|
|
54
49
|
// that doesn't move when extending the selection).
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
_this.$anchorCell = $anchorCell;
|
|
51
|
+
// :: ResolvedPos
|
|
57
52
|
// A resolved position pointing in front of the head cell (the one
|
|
58
53
|
// moves when extending the selection).
|
|
59
|
-
|
|
60
54
|
_this.$headCell = $headCell;
|
|
61
55
|
_this.visible = false;
|
|
62
56
|
return _this;
|
|
63
57
|
}
|
|
64
|
-
|
|
65
58
|
_createClass(CellSelection, [{
|
|
66
59
|
key: "map",
|
|
67
60
|
value: function map(doc, mapping) {
|
|
68
61
|
var $anchorCell = doc.resolve(mapping.map(this.$anchorCell.pos));
|
|
69
62
|
var $headCell = doc.resolve(mapping.map(this.$headCell.pos));
|
|
70
|
-
|
|
71
63
|
if (pointsAtCell($anchorCell) && pointsAtCell($headCell) && inSameTable($anchorCell, $headCell)) {
|
|
72
64
|
var tableChanged = this.$anchorCell.node(-1) !== $anchorCell.node(-1);
|
|
73
|
-
|
|
74
65
|
if (tableChanged && this.isRowSelection()) {
|
|
75
66
|
return CellSelection.rowSelection($anchorCell, $headCell);
|
|
76
67
|
}
|
|
77
|
-
|
|
78
68
|
if (tableChanged && this.isColSelection()) {
|
|
79
69
|
return CellSelection.colSelection($anchorCell, $headCell);
|
|
80
70
|
}
|
|
81
|
-
|
|
82
71
|
return new CellSelection($anchorCell, $headCell);
|
|
83
72
|
}
|
|
84
|
-
|
|
85
73
|
return TextSelection.between($anchorCell, $headCell);
|
|
86
|
-
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// :: () → Slice
|
|
87
77
|
// Returns a rectangular slice of table rows containing the selected
|
|
88
78
|
// cells.
|
|
89
|
-
|
|
90
79
|
}, {
|
|
91
80
|
key: "content",
|
|
92
81
|
value: function content() {
|
|
@@ -96,75 +85,58 @@ export var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
96
85
|
var rect = map.rectBetween(this.$anchorCell.pos - start, this.$headCell.pos - start);
|
|
97
86
|
var seen = {};
|
|
98
87
|
var rows = [];
|
|
99
|
-
|
|
100
88
|
for (var row = rect.top; row < rect.bottom; row++) {
|
|
101
89
|
var rowContent = [];
|
|
102
|
-
|
|
103
90
|
for (var index = row * map.width + rect.left, col = rect.left; col < rect.right; col++, index++) {
|
|
104
91
|
var _pos = map.map[index];
|
|
105
|
-
|
|
106
92
|
if (!seen[_pos]) {
|
|
107
93
|
seen[_pos] = true;
|
|
108
94
|
var cellRect = map.findCell(_pos);
|
|
109
95
|
var cell = table.nodeAt(_pos);
|
|
110
|
-
|
|
111
96
|
if (cell === null || cell === undefined) {
|
|
112
97
|
throw new Error("No cell at position ".concat(_pos));
|
|
113
98
|
}
|
|
114
|
-
|
|
115
99
|
var extraLeft = rect.left - cellRect.left;
|
|
116
100
|
var extraRight = cellRect.right - rect.right;
|
|
117
|
-
|
|
118
101
|
if (extraLeft > 0 || extraRight > 0) {
|
|
119
102
|
var _cell = cell,
|
|
120
|
-
|
|
121
|
-
|
|
103
|
+
attrs = _cell.attrs;
|
|
122
104
|
if (!attrs) {
|
|
123
105
|
throw new Error("No cell at position ".concat(_pos));
|
|
124
106
|
}
|
|
125
|
-
|
|
126
107
|
if (extraLeft > 0) {
|
|
127
108
|
attrs = removeColSpan(attrs, 0, extraLeft);
|
|
128
109
|
}
|
|
129
|
-
|
|
130
110
|
if (extraRight > 0) {
|
|
131
111
|
attrs = removeColSpan(attrs, attrs.colspan - extraRight, extraRight);
|
|
132
112
|
}
|
|
133
|
-
|
|
134
113
|
if (cellRect.left < rect.left) {
|
|
135
114
|
cell = cell.type.createAndFill(attrs);
|
|
136
115
|
} else {
|
|
137
116
|
cell = cell.type.create(attrs, cell.content);
|
|
138
117
|
}
|
|
139
118
|
}
|
|
140
|
-
|
|
141
119
|
if (cell === null || cell === undefined) {
|
|
142
120
|
throw new Error("No cell at position after create/createAndFill");
|
|
143
121
|
}
|
|
144
|
-
|
|
145
122
|
if (cellRect.top < rect.top || cellRect.bottom > rect.bottom) {
|
|
146
123
|
var _attrs = _objectSpread(_objectSpread({}, cell.attrs), {}, {
|
|
147
124
|
rowspan: Math.min(cellRect.bottom, rect.bottom) - Math.max(cellRect.top, rect.top)
|
|
148
125
|
});
|
|
149
|
-
|
|
150
126
|
if (cellRect.top < rect.top) {
|
|
151
127
|
cell = cell.type.createAndFill(_attrs);
|
|
152
128
|
} else {
|
|
153
129
|
cell = cell.type.create(_attrs, cell.content);
|
|
154
130
|
}
|
|
155
131
|
}
|
|
156
|
-
|
|
157
132
|
if (cell === null || cell === undefined) {
|
|
158
133
|
throw new Error("No cell at position before rowContent.push");
|
|
159
134
|
}
|
|
160
|
-
|
|
161
135
|
rowContent.push(cell);
|
|
162
136
|
}
|
|
163
137
|
}
|
|
164
|
-
|
|
165
138
|
rows.push(table.child(row).copy(Fragment.from(rowContent)));
|
|
166
139
|
}
|
|
167
|
-
|
|
168
140
|
var fragment = this.isColSelection() && this.isRowSelection() ? table : rows;
|
|
169
141
|
return new Slice(Fragment.from(fragment), 1, 1);
|
|
170
142
|
}
|
|
@@ -174,17 +146,14 @@ export var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
174
146
|
var content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Slice.empty;
|
|
175
147
|
var mapFrom = tr.steps.length;
|
|
176
148
|
var ranges = this.ranges;
|
|
177
|
-
|
|
178
149
|
for (var i = 0; i < ranges.length; i++) {
|
|
179
150
|
var _ranges$i = ranges[i],
|
|
180
|
-
|
|
181
|
-
|
|
151
|
+
$from = _ranges$i.$from,
|
|
152
|
+
$to = _ranges$i.$to;
|
|
182
153
|
var mapping = tr.mapping.slice(mapFrom);
|
|
183
154
|
tr.replace(mapping.map($from.pos), mapping.map($to.pos), i ? Slice.empty : content);
|
|
184
155
|
}
|
|
185
|
-
|
|
186
156
|
var sel = Selection.findFrom(tr.doc.resolve(tr.mapping.slice(mapFrom).map(this.to)), -1);
|
|
187
|
-
|
|
188
157
|
if (sel) {
|
|
189
158
|
tr.setSelection(sel);
|
|
190
159
|
}
|
|
@@ -201,75 +170,71 @@ export var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
201
170
|
var map = TableMap.get(table);
|
|
202
171
|
var start = this.$anchorCell.start(-1);
|
|
203
172
|
var cells = map.cellsInRect(map.rectBetween(this.$anchorCell.pos - start, this.$headCell.pos - start));
|
|
204
|
-
|
|
205
173
|
for (var i = 0; i < cells.length; i++) {
|
|
206
174
|
var cell = table.nodeAt(cells[i]);
|
|
207
|
-
|
|
208
175
|
if (cell === null || cell === undefined) {
|
|
209
176
|
throw new Error("undefined cell at pos ".concat(cells[i]));
|
|
210
177
|
}
|
|
211
|
-
|
|
212
178
|
f(cell, start + cells[i]);
|
|
213
179
|
}
|
|
214
|
-
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// :: () → bool
|
|
215
183
|
// True if this selection goes all the way from the top to the
|
|
216
184
|
// bottom of the table.
|
|
217
|
-
|
|
218
185
|
}, {
|
|
219
186
|
key: "isColSelection",
|
|
220
187
|
value: function isColSelection() {
|
|
221
188
|
if (!this.$anchorCell || !this.$headCell) {
|
|
222
189
|
throw new Error('invalid $anchorCell or $headCell');
|
|
223
190
|
}
|
|
224
|
-
|
|
225
191
|
var anchorTop = this.$anchorCell.index(-1);
|
|
226
192
|
var headTop = this.$headCell.index(-1);
|
|
227
|
-
|
|
228
193
|
if (Math.min(anchorTop, headTop) > 0) {
|
|
229
194
|
return false;
|
|
230
195
|
}
|
|
231
|
-
|
|
232
196
|
var anchorBot = anchorTop + this.$anchorCell.nodeAfter.attrs.rowspan;
|
|
233
197
|
var headBot = headTop + this.$headCell.nodeAfter.attrs.rowspan;
|
|
234
198
|
return Math.max(anchorBot, headBot) === this.$headCell.node(-1).childCount;
|
|
235
|
-
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// :: (ResolvedPos, ?ResolvedPos) → CellSelection
|
|
236
202
|
// Returns the smallest column selection that covers the given anchor
|
|
237
203
|
// and head cell.
|
|
238
|
-
|
|
239
204
|
}, {
|
|
240
205
|
key: "isRowSelection",
|
|
241
|
-
value:
|
|
206
|
+
value:
|
|
207
|
+
// :: () → bool
|
|
242
208
|
// True if this selection goes all the way from the left to the
|
|
243
209
|
// right of the table.
|
|
244
210
|
function isRowSelection() {
|
|
245
211
|
if (!this.$anchorCell || !this.$headCell) {
|
|
246
212
|
return false;
|
|
247
213
|
}
|
|
248
|
-
|
|
249
214
|
var start = this.$anchorCell.start(-1);
|
|
250
215
|
var map = TableMap.get(this.$anchorCell.node(-1));
|
|
251
216
|
var rowAtAnchorCell = map.rowCount(this.$anchorCell.pos - start);
|
|
252
217
|
var rowAtHeadCell = map.rowCount(this.$headCell.pos - start);
|
|
253
|
-
var isSelectionSameRow = rowAtAnchorCell === rowAtHeadCell;
|
|
218
|
+
var isSelectionSameRow = rowAtAnchorCell === rowAtHeadCell;
|
|
219
|
+
|
|
220
|
+
// if anchor and head in the same line, counting how many cells
|
|
254
221
|
// should be in the row except merged cell
|
|
222
|
+
var maxColumnInSelectedRow = map.getMaxColInRow(this.$anchorCell);
|
|
255
223
|
|
|
256
|
-
|
|
224
|
+
// if selected cells less than table max column amount, and
|
|
257
225
|
// the anchor/head not in a merged cell
|
|
258
226
|
// it should be select maxColumnInSelectedRow to be TRUE
|
|
259
|
-
|
|
260
227
|
if (isSelectionSameRow && this.ranges.length <= map.width && !map.isPosMerged(this.$anchorCell.pos - start) && !map.isPosMerged(this.$headCell.pos - start)) {
|
|
261
228
|
return this.ranges.length === maxColumnInSelectedRow;
|
|
262
|
-
}
|
|
263
|
-
// last column to select the whole row.
|
|
264
|
-
|
|
229
|
+
}
|
|
265
230
|
|
|
231
|
+
// If anchor and head in different row, it should be always in first and
|
|
232
|
+
// last column to select the whole row.
|
|
266
233
|
var anchorLeft = map.colCount(this.$anchorCell.pos - start);
|
|
267
234
|
var headLeft = map.colCount(this.$headCell.pos - start);
|
|
268
|
-
|
|
269
235
|
if (Math.min(anchorLeft, headLeft) > 0) {
|
|
270
236
|
return false;
|
|
271
237
|
}
|
|
272
|
-
|
|
273
238
|
var anchorRight = anchorLeft + this.$anchorCell.nodeAfter.attrs.colspan;
|
|
274
239
|
var headRight = headLeft + this.$headCell.nodeAfter.attrs.colspan;
|
|
275
240
|
return Math.max(anchorRight, headRight) === map.width;
|
|
@@ -278,10 +243,11 @@ export var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
278
243
|
key: "eq",
|
|
279
244
|
value: function eq(other) {
|
|
280
245
|
return other instanceof CellSelection && other.$anchorCell.pos === this.$anchorCell.pos && other.$headCell.pos === this.$headCell.pos;
|
|
281
|
-
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// :: (ResolvedPos, ?ResolvedPos) → CellSelection
|
|
282
249
|
// Returns the smallest row selection that covers the given anchor
|
|
283
250
|
// and head cell.
|
|
284
|
-
|
|
285
251
|
}, {
|
|
286
252
|
key: "toJSON",
|
|
287
253
|
value: function toJSON() {
|
|
@@ -307,12 +273,10 @@ export var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
307
273
|
var anchorRect = map.findCell($calculatedAnchorCell.pos - start);
|
|
308
274
|
var headRect = map.findCell($calculatedHeadCell.pos - start);
|
|
309
275
|
var doc = $calculatedAnchorCell.node(0);
|
|
310
|
-
|
|
311
276
|
if (anchorRect.top <= headRect.top) {
|
|
312
277
|
if (anchorRect.top > 0) {
|
|
313
278
|
$calculatedAnchorCell = doc.resolve(start + map.map[anchorRect.left]);
|
|
314
279
|
}
|
|
315
|
-
|
|
316
280
|
if (headRect.bottom < map.height) {
|
|
317
281
|
$calculatedHeadCell = doc.resolve(start + map.map[map.width * (map.height - 1) + headRect.right - 1]);
|
|
318
282
|
}
|
|
@@ -320,12 +284,10 @@ export var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
320
284
|
if (headRect.top > 0) {
|
|
321
285
|
$calculatedHeadCell = doc.resolve(start + map.map[headRect.left]);
|
|
322
286
|
}
|
|
323
|
-
|
|
324
287
|
if (anchorRect.bottom < map.height) {
|
|
325
288
|
$calculatedAnchorCell = doc.resolve(start + map.map[map.width * (map.height - 1) + anchorRect.right - 1]);
|
|
326
289
|
}
|
|
327
290
|
}
|
|
328
|
-
|
|
329
291
|
return new CellSelection($calculatedAnchorCell, $calculatedHeadCell);
|
|
330
292
|
}
|
|
331
293
|
}, {
|
|
@@ -339,12 +301,10 @@ export var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
339
301
|
var anchorRect = map.findCell($calculatedAnchorCell.pos - start);
|
|
340
302
|
var headRect = map.findCell($calculatedHeadCell.pos - start);
|
|
341
303
|
var doc = $calculatedAnchorCell.node(0);
|
|
342
|
-
|
|
343
304
|
if (anchorRect.left <= headRect.left) {
|
|
344
305
|
if (anchorRect.left > 0) {
|
|
345
306
|
$calculatedAnchorCell = doc.resolve(start + map.map[anchorRect.top * map.width]);
|
|
346
307
|
}
|
|
347
|
-
|
|
348
308
|
if (headRect.right < map.width) {
|
|
349
309
|
$calculatedHeadCell = doc.resolve(start + map.map[map.width * (headRect.top + 1) - 1]);
|
|
350
310
|
}
|
|
@@ -352,20 +312,19 @@ export var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
352
312
|
if (headRect.left > 0) {
|
|
353
313
|
$calculatedHeadCell = doc.resolve(start + map.map[headRect.top * map.width]);
|
|
354
314
|
}
|
|
355
|
-
|
|
356
315
|
if (anchorRect.right < map.width) {
|
|
357
316
|
$calculatedAnchorCell = doc.resolve(start + map.map[map.width * (anchorRect.top + 1) - 1]);
|
|
358
317
|
}
|
|
359
318
|
}
|
|
360
|
-
|
|
361
319
|
return new CellSelection($calculatedAnchorCell, $calculatedHeadCell);
|
|
362
320
|
}
|
|
363
321
|
}, {
|
|
364
322
|
key: "fromJSON",
|
|
365
323
|
value: function fromJSON(doc, json) {
|
|
366
324
|
return new CellSelection(doc.resolve(json.anchor), doc.resolve(json.head));
|
|
367
|
-
}
|
|
325
|
+
}
|
|
368
326
|
|
|
327
|
+
// :: (Node, number, ?number) → CellSelection
|
|
369
328
|
}, {
|
|
370
329
|
key: "create",
|
|
371
330
|
value: function create(doc, anchorCell) {
|
|
@@ -373,7 +332,6 @@ export var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
373
332
|
return new CellSelection(doc.resolve(anchorCell), doc.resolve(headCell));
|
|
374
333
|
}
|
|
375
334
|
}]);
|
|
376
|
-
|
|
377
335
|
return CellSelection;
|
|
378
336
|
}(Selection);
|
|
379
337
|
Selection.jsonID('cell', CellSelection);
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// This file defines a number of helpers for wiring up user input to
|
|
2
2
|
// table-related functionality.
|
|
3
|
+
|
|
3
4
|
import { keydownHandler } from 'prosemirror-keymap';
|
|
4
5
|
import { Slice } from 'prosemirror-model';
|
|
5
6
|
import { Selection, TextSelection } from 'prosemirror-state';
|
|
@@ -22,46 +23,35 @@ export var handleKeyDown = keydownHandler({
|
|
|
22
23
|
Delete: deleteCellSelection,
|
|
23
24
|
'Mod-Delete': deleteCellSelection
|
|
24
25
|
});
|
|
25
|
-
|
|
26
26
|
function maybeSetSelection(state, dispatch, selection) {
|
|
27
27
|
if (selection.eq(state.selection)) {
|
|
28
28
|
return false;
|
|
29
29
|
}
|
|
30
|
-
|
|
31
30
|
if (dispatch) {
|
|
32
31
|
dispatch(state.tr.setSelection(selection).scrollIntoView());
|
|
33
32
|
}
|
|
34
|
-
|
|
35
33
|
return true;
|
|
36
34
|
}
|
|
37
|
-
|
|
38
35
|
function arrow(axis, dir) {
|
|
39
36
|
return function (state, dispatch, view) {
|
|
40
37
|
if (dispatch) {
|
|
41
38
|
var sel = state.selection;
|
|
42
|
-
|
|
43
39
|
if (sel instanceof CellSelection) {
|
|
44
40
|
return maybeSetSelection(state, dispatch, Selection.near(sel.$headCell, dir));
|
|
45
41
|
}
|
|
46
|
-
|
|
47
42
|
if (axis !== 'horiz' && !sel.empty) {
|
|
48
43
|
return false;
|
|
49
44
|
}
|
|
50
|
-
|
|
51
45
|
var end = view ? atEndOfCell(view, axis, dir) : null;
|
|
52
|
-
|
|
53
46
|
if (end === null) {
|
|
54
47
|
return false;
|
|
55
48
|
}
|
|
56
|
-
|
|
57
49
|
if (axis === 'horiz') {
|
|
58
50
|
return maybeSetSelection(state, dispatch, Selection.near(state.doc.resolve(sel.head + dir), dir));
|
|
59
51
|
}
|
|
60
|
-
|
|
61
52
|
var $cell = state.doc.resolve(end);
|
|
62
53
|
var $next = nextCell($cell, axis, dir);
|
|
63
54
|
var newSel;
|
|
64
|
-
|
|
65
55
|
if ($next) {
|
|
66
56
|
newSel = Selection.near($next, 1);
|
|
67
57
|
} else if (dir < 0) {
|
|
@@ -69,49 +59,47 @@ function arrow(axis, dir) {
|
|
|
69
59
|
} else {
|
|
70
60
|
newSel = Selection.near(state.doc.resolve($cell.after(-1)), 1);
|
|
71
61
|
}
|
|
72
|
-
|
|
73
62
|
return maybeSetSelection(state, dispatch, newSel);
|
|
74
63
|
}
|
|
75
|
-
|
|
76
64
|
return true;
|
|
77
65
|
};
|
|
78
66
|
}
|
|
79
|
-
|
|
80
67
|
function shiftArrow(axis, dir) {
|
|
81
68
|
return function (state, dispatch, view) {
|
|
82
69
|
var sel = state.selection;
|
|
83
|
-
|
|
84
70
|
if (!(sel instanceof CellSelection)) {
|
|
71
|
+
var _maybeTableCell$paren;
|
|
85
72
|
var end = view ? atEndOfCell(view, axis, dir) : null;
|
|
86
|
-
|
|
87
73
|
if (end === null) {
|
|
88
74
|
return false;
|
|
89
75
|
}
|
|
90
|
-
|
|
76
|
+
var _state$selection = state.selection,
|
|
77
|
+
_$head = _state$selection.$head,
|
|
78
|
+
$anchor = _state$selection.$anchor;
|
|
79
|
+
var maybeTableCell = _$head.blockRange($anchor);
|
|
80
|
+
|
|
81
|
+
// Make sure the selection is coming from the same cell
|
|
82
|
+
var sameCell = ['tableCell', 'tableHeader'].includes((maybeTableCell === null || maybeTableCell === void 0 ? void 0 : (_maybeTableCell$paren = maybeTableCell.parent) === null || _maybeTableCell$paren === void 0 ? void 0 : _maybeTableCell$paren.type.name) || '');
|
|
83
|
+
if (!sameCell) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
91
86
|
sel = new CellSelection(state.doc.resolve(end));
|
|
92
87
|
}
|
|
93
|
-
|
|
94
88
|
var $head = nextCell(sel.$headCell, axis, dir);
|
|
95
|
-
|
|
96
89
|
if (!$head) {
|
|
97
90
|
return false;
|
|
98
91
|
}
|
|
99
|
-
|
|
100
92
|
if (dispatch) {
|
|
101
93
|
return maybeSetSelection(state, dispatch, new CellSelection(sel.$anchorCell, $head));
|
|
102
94
|
}
|
|
103
|
-
|
|
104
95
|
return true;
|
|
105
96
|
};
|
|
106
97
|
}
|
|
107
|
-
|
|
108
98
|
function deleteCellSelection(state, dispatch) {
|
|
109
99
|
var sel = state.selection;
|
|
110
|
-
|
|
111
100
|
if (!(sel instanceof CellSelection)) {
|
|
112
101
|
return false;
|
|
113
102
|
}
|
|
114
|
-
|
|
115
103
|
if (dispatch) {
|
|
116
104
|
var tr = state.tr;
|
|
117
105
|
var baseContent = tableNodeTypes(state.schema).cell.createAndFill().content;
|
|
@@ -120,37 +108,30 @@ function deleteCellSelection(state, dispatch) {
|
|
|
120
108
|
tr.replace(tr.mapping.map(pos + 1), tr.mapping.map(pos + cell.nodeSize - 1), new Slice(baseContent, 0, 0));
|
|
121
109
|
}
|
|
122
110
|
});
|
|
123
|
-
|
|
124
111
|
if (tr.docChanged) {
|
|
125
112
|
dispatch(tr);
|
|
126
113
|
}
|
|
127
114
|
}
|
|
128
|
-
|
|
129
115
|
return true;
|
|
130
116
|
}
|
|
131
|
-
|
|
132
117
|
export function handleTripleClick(view, pos) {
|
|
133
118
|
var doc = view.state.doc;
|
|
134
119
|
var $cell = cellAround(doc.resolve(pos));
|
|
135
|
-
|
|
136
120
|
if (!$cell) {
|
|
137
121
|
return false;
|
|
138
122
|
}
|
|
139
|
-
|
|
140
123
|
view.dispatch(view.state.tr.setSelection(new CellSelection($cell)));
|
|
141
124
|
return true;
|
|
142
125
|
}
|
|
143
126
|
export function handleMouseDown(view, event) {
|
|
144
|
-
var startEvent = event;
|
|
145
|
-
|
|
127
|
+
var startEvent = event;
|
|
128
|
+
// Prevent right clicks from making a cell selection https://product-fabric.atlassian.net/browse/ED-12527
|
|
146
129
|
if (startEvent.ctrlKey || startEvent.metaKey || startEvent.button === 2 // right mouse click
|
|
147
130
|
) {
|
|
148
131
|
return false;
|
|
149
132
|
}
|
|
150
|
-
|
|
151
133
|
var startDOMCell = domInCell(view, startEvent.target);
|
|
152
134
|
var $anchor = cellAround(view.state.selection.$anchor);
|
|
153
|
-
|
|
154
135
|
if (startEvent.shiftKey && view.state.selection instanceof CellSelection) {
|
|
155
136
|
// Adding to an existing cell selection
|
|
156
137
|
setCellSelection(view.state.selection.$anchorCell, startEvent);
|
|
@@ -163,14 +144,13 @@ export function handleMouseDown(view, event) {
|
|
|
163
144
|
} else if (!startDOMCell) {
|
|
164
145
|
// Not in a cell, let the default behavior happen.
|
|
165
146
|
return false;
|
|
166
|
-
}
|
|
167
|
-
// the position under the mouse.
|
|
168
|
-
|
|
147
|
+
}
|
|
169
148
|
|
|
149
|
+
// Create and dispatch a cell selection between the given anchor and
|
|
150
|
+
// the position under the mouse.
|
|
170
151
|
function setCellSelection($selectionAnchor, event) {
|
|
171
152
|
var $head = cellUnderMouse(view, event);
|
|
172
153
|
var starting = tableEditingKey.getState(view.state) == null;
|
|
173
|
-
|
|
174
154
|
if (!$head || !inSameTable($selectionAnchor, $head)) {
|
|
175
155
|
if (starting) {
|
|
176
156
|
$head = $selectionAnchor;
|
|
@@ -178,107 +158,88 @@ export function handleMouseDown(view, event) {
|
|
|
178
158
|
return false;
|
|
179
159
|
}
|
|
180
160
|
}
|
|
181
|
-
|
|
182
161
|
var selection = new CellSelection($selectionAnchor, $head);
|
|
183
|
-
|
|
184
162
|
if (starting || !view.state.selection.eq(selection)) {
|
|
185
163
|
var tr = view.state.tr.setSelection(selection);
|
|
186
|
-
|
|
187
164
|
if (starting) {
|
|
188
165
|
tr.setMeta(tableEditingKey, $selectionAnchor.pos);
|
|
189
166
|
}
|
|
190
|
-
|
|
191
167
|
view.dispatch(tr);
|
|
192
168
|
}
|
|
193
|
-
}
|
|
194
|
-
|
|
169
|
+
}
|
|
195
170
|
|
|
171
|
+
// Stop listening to mouse motion events.
|
|
196
172
|
function stop() {
|
|
197
173
|
view.root.removeEventListener('mouseup', stop);
|
|
198
174
|
view.root.removeEventListener('dragstart', stop);
|
|
199
175
|
view.root.removeEventListener('mousemove', move);
|
|
200
|
-
|
|
201
176
|
if (tableEditingKey.getState(view.state) != null) {
|
|
202
177
|
view.dispatch(view.state.tr.setMeta(tableEditingKey, -1));
|
|
203
178
|
}
|
|
204
179
|
}
|
|
205
|
-
|
|
206
180
|
function move(event) {
|
|
207
181
|
var anchor = tableEditingKey.getState(view.state);
|
|
208
182
|
var $moveAnchor;
|
|
209
|
-
|
|
210
183
|
if (anchor != null) {
|
|
211
184
|
// Continuing an existing cross-cell selection
|
|
212
185
|
$moveAnchor = view.state.doc.resolve(anchor);
|
|
213
186
|
} else if (domInCell(view, event.target) !== startDOMCell) {
|
|
214
187
|
// Moving out of the initial cell -- start a new cell selection
|
|
215
188
|
$moveAnchor = cellUnderMouse(view, startEvent);
|
|
216
|
-
|
|
217
189
|
if (!$moveAnchor) {
|
|
218
190
|
stop();
|
|
219
191
|
return;
|
|
220
192
|
}
|
|
221
193
|
}
|
|
222
|
-
|
|
223
194
|
if ($moveAnchor) {
|
|
224
195
|
setCellSelection($moveAnchor, event);
|
|
225
196
|
}
|
|
226
197
|
}
|
|
227
|
-
|
|
228
198
|
view.root.addEventListener('mouseup', stop);
|
|
229
199
|
view.root.addEventListener('dragstart', stop);
|
|
230
200
|
view.root.addEventListener('mousemove', move);
|
|
231
201
|
return false;
|
|
232
|
-
}
|
|
233
|
-
// motion would move out of the cell)
|
|
202
|
+
}
|
|
234
203
|
|
|
204
|
+
// Check whether the cursor is at the end of a cell (so that further
|
|
205
|
+
// motion would move out of the cell)
|
|
235
206
|
function atEndOfCell(view, axis, dir) {
|
|
236
207
|
if (!(view.state.selection instanceof TextSelection)) {
|
|
237
208
|
return null;
|
|
238
209
|
}
|
|
239
|
-
|
|
240
210
|
var $head = view.state.selection.$head;
|
|
241
|
-
|
|
242
211
|
for (var d = $head.depth - 1; d >= 0; d--) {
|
|
243
212
|
var parent = $head.node(d);
|
|
244
213
|
var index = dir < 0 ? $head.index(d) : $head.indexAfter(d);
|
|
245
|
-
|
|
246
214
|
if (index !== (dir < 0 ? 0 : parent.childCount)) {
|
|
247
215
|
return null;
|
|
248
216
|
}
|
|
249
|
-
|
|
250
217
|
if (parent.type.spec.tableRole === 'cell' || parent.type.spec.tableRole === 'header_cell') {
|
|
251
218
|
var cellPos = $head.before(d);
|
|
252
|
-
var dirStr =
|
|
219
|
+
var dirStr =
|
|
220
|
+
// eslint-disable-next-line no-nested-ternary
|
|
253
221
|
axis === 'vert' ? dir > 0 ? 'down' : 'up' : dir > 0 ? 'right' : 'left';
|
|
254
222
|
return view.endOfTextblock(dirStr) ? cellPos : null;
|
|
255
223
|
}
|
|
256
224
|
}
|
|
257
|
-
|
|
258
225
|
return null;
|
|
259
226
|
}
|
|
260
|
-
|
|
261
227
|
function domInCell(view, inputDom) {
|
|
262
228
|
var dom = inputDom;
|
|
263
|
-
|
|
264
229
|
for (; dom && dom !== view.dom; dom = dom.parentNode) {
|
|
265
230
|
if (dom.nodeName === 'TD' || dom.nodeName === 'TH') {
|
|
266
231
|
return dom;
|
|
267
232
|
}
|
|
268
233
|
}
|
|
269
|
-
|
|
270
234
|
return null;
|
|
271
235
|
}
|
|
272
|
-
|
|
273
236
|
function cellUnderMouse(view, event) {
|
|
274
237
|
var mousePos = view.posAtCoords({
|
|
275
238
|
left: event.clientX,
|
|
276
239
|
top: event.clientY
|
|
277
240
|
});
|
|
278
|
-
|
|
279
241
|
if (!mousePos) {
|
|
280
242
|
return null;
|
|
281
243
|
}
|
|
282
|
-
|
|
283
244
|
return cellAround(view.state.doc.resolve(mousePos.pos));
|
|
284
245
|
}
|