@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
|
@@ -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,64 +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)) {
|
|
85
71
|
var _maybeTableCell$paren;
|
|
86
|
-
|
|
87
72
|
var end = view ? atEndOfCell(view, axis, dir) : null;
|
|
88
|
-
|
|
89
73
|
if (end === null) {
|
|
90
74
|
return false;
|
|
91
75
|
}
|
|
92
|
-
|
|
93
76
|
var _state$selection = state.selection,
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
var maybeTableCell = _$head.blockRange($anchor); // Make sure the selection is coming from the same cell
|
|
98
|
-
|
|
77
|
+
_$head = _state$selection.$head,
|
|
78
|
+
$anchor = _state$selection.$anchor;
|
|
79
|
+
var maybeTableCell = _$head.blockRange($anchor);
|
|
99
80
|
|
|
81
|
+
// Make sure the selection is coming from the same cell
|
|
100
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) || '');
|
|
101
|
-
|
|
102
83
|
if (!sameCell) {
|
|
103
84
|
return false;
|
|
104
85
|
}
|
|
105
|
-
|
|
106
86
|
sel = new CellSelection(state.doc.resolve(end));
|
|
107
87
|
}
|
|
108
|
-
|
|
109
88
|
var $head = nextCell(sel.$headCell, axis, dir);
|
|
110
|
-
|
|
111
89
|
if (!$head) {
|
|
112
90
|
return false;
|
|
113
91
|
}
|
|
114
|
-
|
|
115
92
|
if (dispatch) {
|
|
116
93
|
return maybeSetSelection(state, dispatch, new CellSelection(sel.$anchorCell, $head));
|
|
117
94
|
}
|
|
118
|
-
|
|
119
95
|
return true;
|
|
120
96
|
};
|
|
121
97
|
}
|
|
122
|
-
|
|
123
98
|
function deleteCellSelection(state, dispatch) {
|
|
124
99
|
var sel = state.selection;
|
|
125
|
-
|
|
126
100
|
if (!(sel instanceof CellSelection)) {
|
|
127
101
|
return false;
|
|
128
102
|
}
|
|
129
|
-
|
|
130
103
|
if (dispatch) {
|
|
131
104
|
var tr = state.tr;
|
|
132
105
|
var baseContent = tableNodeTypes(state.schema).cell.createAndFill().content;
|
|
@@ -135,37 +108,30 @@ function deleteCellSelection(state, dispatch) {
|
|
|
135
108
|
tr.replace(tr.mapping.map(pos + 1), tr.mapping.map(pos + cell.nodeSize - 1), new Slice(baseContent, 0, 0));
|
|
136
109
|
}
|
|
137
110
|
});
|
|
138
|
-
|
|
139
111
|
if (tr.docChanged) {
|
|
140
112
|
dispatch(tr);
|
|
141
113
|
}
|
|
142
114
|
}
|
|
143
|
-
|
|
144
115
|
return true;
|
|
145
116
|
}
|
|
146
|
-
|
|
147
117
|
export function handleTripleClick(view, pos) {
|
|
148
118
|
var doc = view.state.doc;
|
|
149
119
|
var $cell = cellAround(doc.resolve(pos));
|
|
150
|
-
|
|
151
120
|
if (!$cell) {
|
|
152
121
|
return false;
|
|
153
122
|
}
|
|
154
|
-
|
|
155
123
|
view.dispatch(view.state.tr.setSelection(new CellSelection($cell)));
|
|
156
124
|
return true;
|
|
157
125
|
}
|
|
158
126
|
export function handleMouseDown(view, event) {
|
|
159
|
-
var startEvent = event;
|
|
160
|
-
|
|
127
|
+
var startEvent = event;
|
|
128
|
+
// Prevent right clicks from making a cell selection https://product-fabric.atlassian.net/browse/ED-12527
|
|
161
129
|
if (startEvent.ctrlKey || startEvent.metaKey || startEvent.button === 2 // right mouse click
|
|
162
130
|
) {
|
|
163
131
|
return false;
|
|
164
132
|
}
|
|
165
|
-
|
|
166
133
|
var startDOMCell = domInCell(view, startEvent.target);
|
|
167
134
|
var $anchor = cellAround(view.state.selection.$anchor);
|
|
168
|
-
|
|
169
135
|
if (startEvent.shiftKey && view.state.selection instanceof CellSelection) {
|
|
170
136
|
// Adding to an existing cell selection
|
|
171
137
|
setCellSelection(view.state.selection.$anchorCell, startEvent);
|
|
@@ -178,14 +144,13 @@ export function handleMouseDown(view, event) {
|
|
|
178
144
|
} else if (!startDOMCell) {
|
|
179
145
|
// Not in a cell, let the default behavior happen.
|
|
180
146
|
return false;
|
|
181
|
-
}
|
|
182
|
-
// the position under the mouse.
|
|
183
|
-
|
|
147
|
+
}
|
|
184
148
|
|
|
149
|
+
// Create and dispatch a cell selection between the given anchor and
|
|
150
|
+
// the position under the mouse.
|
|
185
151
|
function setCellSelection($selectionAnchor, event) {
|
|
186
152
|
var $head = cellUnderMouse(view, event);
|
|
187
153
|
var starting = tableEditingKey.getState(view.state) == null;
|
|
188
|
-
|
|
189
154
|
if (!$head || !inSameTable($selectionAnchor, $head)) {
|
|
190
155
|
if (starting) {
|
|
191
156
|
$head = $selectionAnchor;
|
|
@@ -193,107 +158,88 @@ export function handleMouseDown(view, event) {
|
|
|
193
158
|
return false;
|
|
194
159
|
}
|
|
195
160
|
}
|
|
196
|
-
|
|
197
161
|
var selection = new CellSelection($selectionAnchor, $head);
|
|
198
|
-
|
|
199
162
|
if (starting || !view.state.selection.eq(selection)) {
|
|
200
163
|
var tr = view.state.tr.setSelection(selection);
|
|
201
|
-
|
|
202
164
|
if (starting) {
|
|
203
165
|
tr.setMeta(tableEditingKey, $selectionAnchor.pos);
|
|
204
166
|
}
|
|
205
|
-
|
|
206
167
|
view.dispatch(tr);
|
|
207
168
|
}
|
|
208
|
-
}
|
|
209
|
-
|
|
169
|
+
}
|
|
210
170
|
|
|
171
|
+
// Stop listening to mouse motion events.
|
|
211
172
|
function stop() {
|
|
212
173
|
view.root.removeEventListener('mouseup', stop);
|
|
213
174
|
view.root.removeEventListener('dragstart', stop);
|
|
214
175
|
view.root.removeEventListener('mousemove', move);
|
|
215
|
-
|
|
216
176
|
if (tableEditingKey.getState(view.state) != null) {
|
|
217
177
|
view.dispatch(view.state.tr.setMeta(tableEditingKey, -1));
|
|
218
178
|
}
|
|
219
179
|
}
|
|
220
|
-
|
|
221
180
|
function move(event) {
|
|
222
181
|
var anchor = tableEditingKey.getState(view.state);
|
|
223
182
|
var $moveAnchor;
|
|
224
|
-
|
|
225
183
|
if (anchor != null) {
|
|
226
184
|
// Continuing an existing cross-cell selection
|
|
227
185
|
$moveAnchor = view.state.doc.resolve(anchor);
|
|
228
186
|
} else if (domInCell(view, event.target) !== startDOMCell) {
|
|
229
187
|
// Moving out of the initial cell -- start a new cell selection
|
|
230
188
|
$moveAnchor = cellUnderMouse(view, startEvent);
|
|
231
|
-
|
|
232
189
|
if (!$moveAnchor) {
|
|
233
190
|
stop();
|
|
234
191
|
return;
|
|
235
192
|
}
|
|
236
193
|
}
|
|
237
|
-
|
|
238
194
|
if ($moveAnchor) {
|
|
239
195
|
setCellSelection($moveAnchor, event);
|
|
240
196
|
}
|
|
241
197
|
}
|
|
242
|
-
|
|
243
198
|
view.root.addEventListener('mouseup', stop);
|
|
244
199
|
view.root.addEventListener('dragstart', stop);
|
|
245
200
|
view.root.addEventListener('mousemove', move);
|
|
246
201
|
return false;
|
|
247
|
-
}
|
|
248
|
-
// motion would move out of the cell)
|
|
202
|
+
}
|
|
249
203
|
|
|
204
|
+
// Check whether the cursor is at the end of a cell (so that further
|
|
205
|
+
// motion would move out of the cell)
|
|
250
206
|
function atEndOfCell(view, axis, dir) {
|
|
251
207
|
if (!(view.state.selection instanceof TextSelection)) {
|
|
252
208
|
return null;
|
|
253
209
|
}
|
|
254
|
-
|
|
255
210
|
var $head = view.state.selection.$head;
|
|
256
|
-
|
|
257
211
|
for (var d = $head.depth - 1; d >= 0; d--) {
|
|
258
212
|
var parent = $head.node(d);
|
|
259
213
|
var index = dir < 0 ? $head.index(d) : $head.indexAfter(d);
|
|
260
|
-
|
|
261
214
|
if (index !== (dir < 0 ? 0 : parent.childCount)) {
|
|
262
215
|
return null;
|
|
263
216
|
}
|
|
264
|
-
|
|
265
217
|
if (parent.type.spec.tableRole === 'cell' || parent.type.spec.tableRole === 'header_cell') {
|
|
266
218
|
var cellPos = $head.before(d);
|
|
267
|
-
var dirStr =
|
|
219
|
+
var dirStr =
|
|
220
|
+
// eslint-disable-next-line no-nested-ternary
|
|
268
221
|
axis === 'vert' ? dir > 0 ? 'down' : 'up' : dir > 0 ? 'right' : 'left';
|
|
269
222
|
return view.endOfTextblock(dirStr) ? cellPos : null;
|
|
270
223
|
}
|
|
271
224
|
}
|
|
272
|
-
|
|
273
225
|
return null;
|
|
274
226
|
}
|
|
275
|
-
|
|
276
227
|
function domInCell(view, inputDom) {
|
|
277
228
|
var dom = inputDom;
|
|
278
|
-
|
|
279
229
|
for (; dom && dom !== view.dom; dom = dom.parentNode) {
|
|
280
230
|
if (dom.nodeName === 'TD' || dom.nodeName === 'TH') {
|
|
281
231
|
return dom;
|
|
282
232
|
}
|
|
283
233
|
}
|
|
284
|
-
|
|
285
234
|
return null;
|
|
286
235
|
}
|
|
287
|
-
|
|
288
236
|
function cellUnderMouse(view, event) {
|
|
289
237
|
var mousePos = view.posAtCoords({
|
|
290
238
|
left: event.clientX,
|
|
291
239
|
top: event.clientY
|
|
292
240
|
});
|
|
293
|
-
|
|
294
241
|
if (!mousePos) {
|
|
295
242
|
return null;
|
|
296
243
|
}
|
|
297
|
-
|
|
298
244
|
return cellAround(view.state.doc.resolve(mousePos.pos));
|
|
299
245
|
}
|