handsontable 0.0.0-next-8dc7078-20240322 → 0.0.0-next-28fc088-20240325
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of handsontable might be problematic. Click here for more details.
- package/3rdparty/walkontable/src/cell/range.d.ts +2 -1
- package/3rdparty/walkontable/src/cell/range.js +22 -5
- package/3rdparty/walkontable/src/cell/range.mjs +22 -5
- package/base.js +2 -2
- package/base.mjs +2 -2
- package/core/viewportScroll/index.js +4 -1
- package/core/viewportScroll/index.mjs +4 -1
- package/core/viewportScroll/scrollStrategies/focusScroll.js +15 -0
- package/core/viewportScroll/scrollStrategies/focusScroll.mjs +11 -0
- package/core.d.ts +4 -3
- package/core.js +76 -21
- package/core.mjs +76 -21
- package/dist/handsontable.css +2 -2
- package/dist/handsontable.full.css +2 -2
- package/dist/handsontable.full.js +2649 -1389
- package/dist/handsontable.full.min.css +2 -2
- package/dist/handsontable.full.min.js +71 -71
- package/dist/handsontable.js +2653 -1393
- package/dist/handsontable.min.css +2 -2
- package/dist/handsontable.min.js +19 -19
- package/editorManager.js +12 -8
- package/editorManager.mjs +12 -8
- package/focusManager.js +7 -1
- package/focusManager.mjs +7 -1
- package/helpers/mixed.js +1 -1
- package/helpers/mixed.mjs +1 -1
- package/package.json +1 -1
- package/pluginHooks.d.ts +4 -0
- package/pluginHooks.js +98 -37
- package/pluginHooks.mjs +98 -37
- package/plugins/collapsibleColumns/collapsibleColumns.js +9 -3
- package/plugins/collapsibleColumns/collapsibleColumns.mjs +9 -3
- package/plugins/columnSorting/columnSorting.js +8 -2
- package/plugins/columnSorting/columnSorting.mjs +8 -2
- package/plugins/contextMenu/menu/defaultShortcutsList.js +26 -10
- package/plugins/contextMenu/menu/defaultShortcutsList.mjs +26 -10
- package/plugins/mergeCells/calculations/selection.js +1 -70
- package/plugins/mergeCells/calculations/selection.mjs +1 -70
- package/plugins/mergeCells/cellsCollection.js +116 -0
- package/plugins/mergeCells/cellsCollection.mjs +116 -0
- package/plugins/mergeCells/contextMenuItem/toggleMerge.js +11 -1
- package/plugins/mergeCells/contextMenuItem/toggleMerge.mjs +11 -1
- package/plugins/mergeCells/focusOrder.js +305 -0
- package/plugins/mergeCells/focusOrder.mjs +300 -0
- package/plugins/mergeCells/mergeCells.js +336 -192
- package/plugins/mergeCells/mergeCells.mjs +336 -192
- package/plugins/multiColumnSorting/multiColumnSorting.js +8 -2
- package/plugins/multiColumnSorting/multiColumnSorting.mjs +8 -2
- package/plugins/nestedHeaders/nestedHeaders.js +1 -0
- package/plugins/nestedHeaders/nestedHeaders.mjs +1 -0
- package/plugins/nestedRows/nestedRows.js +9 -3
- package/plugins/nestedRows/nestedRows.mjs +9 -3
- package/renderers/checkboxRenderer/checkboxRenderer.js +8 -5
- package/renderers/checkboxRenderer/checkboxRenderer.mjs +8 -5
- package/selection/highlight/visualSelection.js +2 -0
- package/selection/highlight/visualSelection.mjs +2 -0
- package/selection/selection.js +209 -40
- package/selection/selection.mjs +208 -39
- package/selection/transformation.js +83 -32
- package/selection/transformation.mjs +83 -32
- package/shortcutContexts/commands/editor/closeAndSave.js +2 -2
- package/shortcutContexts/commands/editor/closeAndSave.mjs +2 -2
- package/shortcutContexts/commands/editor/open.js +18 -3
- package/shortcutContexts/commands/editor/open.mjs +18 -3
- package/shortcutContexts/commands/extendCellsSelection/down.js +1 -1
- package/shortcutContexts/commands/extendCellsSelection/down.mjs +1 -1
- package/shortcutContexts/commands/extendCellsSelection/left.js +1 -1
- package/shortcutContexts/commands/extendCellsSelection/left.mjs +1 -1
- package/shortcutContexts/commands/extendCellsSelection/right.js +1 -1
- package/shortcutContexts/commands/extendCellsSelection/right.mjs +1 -1
- package/shortcutContexts/commands/extendCellsSelection/toColumns.js +1 -1
- package/shortcutContexts/commands/extendCellsSelection/toColumns.mjs +1 -1
- package/shortcutContexts/commands/extendCellsSelection/toMostBottom.js +3 -1
- package/shortcutContexts/commands/extendCellsSelection/toMostBottom.mjs +3 -1
- package/shortcutContexts/commands/extendCellsSelection/toMostInlineEnd.js +9 -3
- package/shortcutContexts/commands/extendCellsSelection/toMostInlineEnd.mjs +9 -3
- package/shortcutContexts/commands/extendCellsSelection/toMostInlineStart.js +10 -3
- package/shortcutContexts/commands/extendCellsSelection/toMostInlineStart.mjs +10 -3
- package/shortcutContexts/commands/extendCellsSelection/toMostLeft.js +3 -1
- package/shortcutContexts/commands/extendCellsSelection/toMostLeft.mjs +3 -1
- package/shortcutContexts/commands/extendCellsSelection/toMostRight.js +3 -1
- package/shortcutContexts/commands/extendCellsSelection/toMostRight.mjs +3 -1
- package/shortcutContexts/commands/extendCellsSelection/toMostTop.js +3 -1
- package/shortcutContexts/commands/extendCellsSelection/toMostTop.mjs +3 -1
- package/shortcutContexts/commands/extendCellsSelection/toRows.js +1 -1
- package/shortcutContexts/commands/extendCellsSelection/toRows.mjs +1 -1
- package/shortcutContexts/commands/extendCellsSelection/up.js +1 -1
- package/shortcutContexts/commands/extendCellsSelection/up.mjs +1 -1
- package/shortcutContexts/commands/moveCellSelection/inlineEnd.js +6 -1
- package/shortcutContexts/commands/moveCellSelection/inlineEnd.mjs +6 -1
- package/shortcutContexts/commands/moveCellSelection/inlineStart.js +6 -1
- package/shortcutContexts/commands/moveCellSelection/inlineStart.mjs +6 -1
- package/shortcutContexts/grid.js +2 -2
- package/shortcutContexts/grid.mjs +2 -2
- package/shortcuts/context.js +2 -1
- package/shortcuts/context.mjs +2 -1
- package/utils/dataStructures/linkedList.js +6 -1
- package/utils/dataStructures/linkedList.mjs +6 -1
@@ -0,0 +1,305 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
exports.__esModule = true;
|
4
|
+
require("core-js/modules/es.error.cause.js");
|
5
|
+
require("core-js/modules/es.array.push.js");
|
6
|
+
var _linkedList = _interopRequireDefault(require("../../utils/dataStructures/linkedList"));
|
7
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
8
|
+
function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
|
9
|
+
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
10
|
+
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
11
|
+
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
12
|
+
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
13
|
+
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
14
|
+
/**
|
15
|
+
* Class responsible for providing the correct focus order (vertical and horizontal) within a selection that
|
16
|
+
* contains merged cells.
|
17
|
+
*
|
18
|
+
* @private
|
19
|
+
*/
|
20
|
+
var _cellsHorizontalOrder = /*#__PURE__*/new WeakMap();
|
21
|
+
var _cellsVerticalOrder = /*#__PURE__*/new WeakMap();
|
22
|
+
var _currentHorizontalLinkedNode = /*#__PURE__*/new WeakMap();
|
23
|
+
var _currentVerticalLinkedNode = /*#__PURE__*/new WeakMap();
|
24
|
+
var _mergedCellsGetter = /*#__PURE__*/new WeakMap();
|
25
|
+
var _rowIndexMapper = /*#__PURE__*/new WeakMap();
|
26
|
+
var _columnIndexMapper = /*#__PURE__*/new WeakMap();
|
27
|
+
var _FocusOrder_brand = /*#__PURE__*/new WeakSet();
|
28
|
+
class FocusOrder {
|
29
|
+
constructor(_ref) {
|
30
|
+
let {
|
31
|
+
mergedCellsGetter,
|
32
|
+
rowIndexMapper,
|
33
|
+
columnIndexMapper
|
34
|
+
} = _ref;
|
35
|
+
/**
|
36
|
+
* Pushes a new node to the provided list order.
|
37
|
+
*
|
38
|
+
* @param {CellRange} selectedRange The selected range to build the focus order for.
|
39
|
+
* @param {LinkedList} listOrder The list order to push the node to.
|
40
|
+
* @param {WeakSet} mergeCellsVisitor The set of visited cells.
|
41
|
+
* @param {number} row The visual row index.
|
42
|
+
* @param {number} column The visual column index.
|
43
|
+
* @returns {NodeStructure | null}
|
44
|
+
*/
|
45
|
+
_classPrivateMethodInitSpec(this, _FocusOrder_brand);
|
46
|
+
/**
|
47
|
+
* The linked list of the all cells within the current selection in horizontal order. The list is
|
48
|
+
* recreated every time the selection is changed.
|
49
|
+
*
|
50
|
+
* @type {LinkedList}
|
51
|
+
*/
|
52
|
+
_classPrivateFieldInitSpec(this, _cellsHorizontalOrder, new _linkedList.default());
|
53
|
+
/**
|
54
|
+
* The linked list of the all cells within the current selection in horizontal order. The list is
|
55
|
+
* recreated every time the selection is changed.
|
56
|
+
*
|
57
|
+
* @type {LinkedList}
|
58
|
+
*/
|
59
|
+
_classPrivateFieldInitSpec(this, _cellsVerticalOrder, new _linkedList.default());
|
60
|
+
/**
|
61
|
+
* The currently highlighted cell within the horizontal linked list.
|
62
|
+
*
|
63
|
+
* @type {NodeStructure | null}
|
64
|
+
*/
|
65
|
+
_classPrivateFieldInitSpec(this, _currentHorizontalLinkedNode, null);
|
66
|
+
/**
|
67
|
+
* The currently highlighted cell within the vertical linked list.
|
68
|
+
*
|
69
|
+
* @type {NodeStructure | null}
|
70
|
+
*/
|
71
|
+
_classPrivateFieldInitSpec(this, _currentVerticalLinkedNode, null);
|
72
|
+
/**
|
73
|
+
* The merged cells getter function.
|
74
|
+
*
|
75
|
+
* @type {function(): {row: number, col: number, rowspan: number, colspan: number} | null}}
|
76
|
+
*/
|
77
|
+
_classPrivateFieldInitSpec(this, _mergedCellsGetter, null);
|
78
|
+
/**
|
79
|
+
* The row index mapper.
|
80
|
+
*
|
81
|
+
* @type {IndexMapper}
|
82
|
+
*/
|
83
|
+
_classPrivateFieldInitSpec(this, _rowIndexMapper, null);
|
84
|
+
/**
|
85
|
+
* The column index mapper.
|
86
|
+
*
|
87
|
+
* @type {IndexMapper}
|
88
|
+
*/
|
89
|
+
_classPrivateFieldInitSpec(this, _columnIndexMapper, null);
|
90
|
+
_classPrivateFieldSet(_mergedCellsGetter, this, mergedCellsGetter);
|
91
|
+
_classPrivateFieldSet(_rowIndexMapper, this, rowIndexMapper);
|
92
|
+
_classPrivateFieldSet(_columnIndexMapper, this, columnIndexMapper);
|
93
|
+
}
|
94
|
+
|
95
|
+
/**
|
96
|
+
* Gets the currently selected node data from the vertical focus order list.
|
97
|
+
*
|
98
|
+
* @returns {NodeStructure}
|
99
|
+
*/
|
100
|
+
getCurrentVerticalNode() {
|
101
|
+
return _classPrivateFieldGet(_currentVerticalLinkedNode, this).data;
|
102
|
+
}
|
103
|
+
|
104
|
+
/**
|
105
|
+
* Gets the first node data from the vertical focus order list.
|
106
|
+
*
|
107
|
+
* @returns {NodeStructure}
|
108
|
+
*/
|
109
|
+
getFirstVerticalNode() {
|
110
|
+
return _classPrivateFieldGet(_cellsVerticalOrder, this).first.data;
|
111
|
+
}
|
112
|
+
|
113
|
+
/**
|
114
|
+
* Gets the next selected node data from the vertical focus order list.
|
115
|
+
*
|
116
|
+
* @returns {NodeStructure}
|
117
|
+
*/
|
118
|
+
getNextVerticalNode() {
|
119
|
+
return _classPrivateFieldGet(_currentVerticalLinkedNode, this).next.data;
|
120
|
+
}
|
121
|
+
|
122
|
+
/**
|
123
|
+
* Gets the previous selected node data from the vertical focus order list.
|
124
|
+
*
|
125
|
+
* @returns {NodeStructure}
|
126
|
+
*/
|
127
|
+
getPrevVerticalNode() {
|
128
|
+
return _classPrivateFieldGet(_currentVerticalLinkedNode, this).prev.data;
|
129
|
+
}
|
130
|
+
|
131
|
+
/**
|
132
|
+
* Gets the currently selected node data from the horizontal focus order list.
|
133
|
+
*
|
134
|
+
* @returns {NodeStructure}
|
135
|
+
*/
|
136
|
+
getCurrentHorizontalNode() {
|
137
|
+
return _classPrivateFieldGet(_currentHorizontalLinkedNode, this).data;
|
138
|
+
}
|
139
|
+
|
140
|
+
/**
|
141
|
+
* Gets the first node data from the horizontal focus order list.
|
142
|
+
*
|
143
|
+
* @returns {NodeStructure}
|
144
|
+
*/
|
145
|
+
getFirstHorizontalNode() {
|
146
|
+
return _classPrivateFieldGet(_cellsHorizontalOrder, this).first.data;
|
147
|
+
}
|
148
|
+
|
149
|
+
/**
|
150
|
+
* Gets the next selected node data from the horizontal focus order list.
|
151
|
+
*
|
152
|
+
* @returns {NodeStructure}
|
153
|
+
*/
|
154
|
+
getNextHorizontalNode() {
|
155
|
+
return _classPrivateFieldGet(_currentHorizontalLinkedNode, this).next.data;
|
156
|
+
}
|
157
|
+
|
158
|
+
/**
|
159
|
+
* Gets the previous selected node data from the horizontal focus order list.
|
160
|
+
*
|
161
|
+
* @returns {NodeStructure}
|
162
|
+
*/
|
163
|
+
getPrevHorizontalNode() {
|
164
|
+
return _classPrivateFieldGet(_currentHorizontalLinkedNode, this).prev.data;
|
165
|
+
}
|
166
|
+
|
167
|
+
/**
|
168
|
+
* Sets the previous node from the vertical focus order list as active.
|
169
|
+
*/
|
170
|
+
setPrevNodeAsActive() {
|
171
|
+
_classPrivateFieldSet(_currentVerticalLinkedNode, this, _classPrivateFieldGet(_currentVerticalLinkedNode, this).prev);
|
172
|
+
_classPrivateFieldSet(_currentHorizontalLinkedNode, this, _classPrivateFieldGet(_currentHorizontalLinkedNode, this).prev);
|
173
|
+
}
|
174
|
+
|
175
|
+
/**
|
176
|
+
* Sets the previous node from the horizontal focus order list as active.
|
177
|
+
*/
|
178
|
+
setNextNodeAsActive() {
|
179
|
+
_classPrivateFieldSet(_currentVerticalLinkedNode, this, _classPrivateFieldGet(_currentVerticalLinkedNode, this).next);
|
180
|
+
_classPrivateFieldSet(_currentHorizontalLinkedNode, this, _classPrivateFieldGet(_currentHorizontalLinkedNode, this).next);
|
181
|
+
}
|
182
|
+
|
183
|
+
/**
|
184
|
+
* Rebuilds the focus order list based on the provided selection.
|
185
|
+
*
|
186
|
+
* @param {CellRange} selectedRange The selected range to build the focus order for.
|
187
|
+
*/
|
188
|
+
buildFocusOrder(selectedRange) {
|
189
|
+
const topStart = selectedRange.getTopStartCorner();
|
190
|
+
const bottomEnd = selectedRange.getBottomEndCorner();
|
191
|
+
const visitedHorizontalCells = new WeakSet();
|
192
|
+
_classPrivateFieldSet(_cellsHorizontalOrder, this, new _linkedList.default());
|
193
|
+
for (let r = topStart.row; r <= bottomEnd.row; r++) {
|
194
|
+
if (_classPrivateFieldGet(_rowIndexMapper, this).isHidden(r)) {
|
195
|
+
// eslint-disable-next-line no-continue
|
196
|
+
continue;
|
197
|
+
}
|
198
|
+
for (let c = topStart.col; c <= bottomEnd.col; c++) {
|
199
|
+
if (_classPrivateFieldGet(_columnIndexMapper, this).isHidden(c)) {
|
200
|
+
// eslint-disable-next-line no-continue
|
201
|
+
continue;
|
202
|
+
}
|
203
|
+
const node = _assertClassBrand(_FocusOrder_brand, this, _pushOrderNode).call(this, selectedRange, _classPrivateFieldGet(_cellsHorizontalOrder, this), visitedHorizontalCells, r, c);
|
204
|
+
if (node) {
|
205
|
+
_classPrivateFieldSet(_currentHorizontalLinkedNode, this, node);
|
206
|
+
}
|
207
|
+
}
|
208
|
+
}
|
209
|
+
|
210
|
+
// create circular linked list
|
211
|
+
if (_classPrivateFieldGet(_cellsHorizontalOrder, this).first) {
|
212
|
+
_classPrivateFieldGet(_cellsHorizontalOrder, this).first.prev = _classPrivateFieldGet(_cellsHorizontalOrder, this).last;
|
213
|
+
_classPrivateFieldGet(_cellsHorizontalOrder, this).last.next = _classPrivateFieldGet(_cellsHorizontalOrder, this).first;
|
214
|
+
}
|
215
|
+
const visitedVerticalCells = new WeakSet();
|
216
|
+
_classPrivateFieldSet(_cellsVerticalOrder, this, new _linkedList.default());
|
217
|
+
for (let c = topStart.col; c <= bottomEnd.col; c++) {
|
218
|
+
if (_classPrivateFieldGet(_columnIndexMapper, this).isHidden(c)) {
|
219
|
+
// eslint-disable-next-line no-continue
|
220
|
+
continue;
|
221
|
+
}
|
222
|
+
for (let r = topStart.row; r <= bottomEnd.row; r++) {
|
223
|
+
if (_classPrivateFieldGet(_rowIndexMapper, this).isHidden(r)) {
|
224
|
+
// eslint-disable-next-line no-continue
|
225
|
+
continue;
|
226
|
+
}
|
227
|
+
const node = _assertClassBrand(_FocusOrder_brand, this, _pushOrderNode).call(this, selectedRange, _classPrivateFieldGet(_cellsVerticalOrder, this), visitedVerticalCells, r, c);
|
228
|
+
if (node) {
|
229
|
+
_classPrivateFieldSet(_currentVerticalLinkedNode, this, node);
|
230
|
+
}
|
231
|
+
}
|
232
|
+
}
|
233
|
+
|
234
|
+
// create circular linked list
|
235
|
+
if (_classPrivateFieldGet(_cellsVerticalOrder, this).first) {
|
236
|
+
_classPrivateFieldGet(_cellsVerticalOrder, this).first.prev = _classPrivateFieldGet(_cellsVerticalOrder, this).last;
|
237
|
+
_classPrivateFieldGet(_cellsVerticalOrder, this).last.next = _classPrivateFieldGet(_cellsVerticalOrder, this).first;
|
238
|
+
}
|
239
|
+
}
|
240
|
+
/**
|
241
|
+
* Sets the active node based on the provided row and column.
|
242
|
+
*
|
243
|
+
* @param {number} row The visual row index.
|
244
|
+
* @param {number} column The visual column index.
|
245
|
+
* @returns {FocusOrder}
|
246
|
+
*/
|
247
|
+
setActiveNode(row, column) {
|
248
|
+
_classPrivateFieldGet(_cellsHorizontalOrder, this).inorder(node => {
|
249
|
+
const {
|
250
|
+
rowStart,
|
251
|
+
rowEnd,
|
252
|
+
colStart,
|
253
|
+
colEnd
|
254
|
+
} = node.data;
|
255
|
+
if (row >= rowStart && row <= rowEnd && column >= colStart && column <= colEnd) {
|
256
|
+
_classPrivateFieldSet(_currentHorizontalLinkedNode, this, node);
|
257
|
+
return false;
|
258
|
+
}
|
259
|
+
});
|
260
|
+
_classPrivateFieldGet(_cellsVerticalOrder, this).inorder(node => {
|
261
|
+
const {
|
262
|
+
rowStart,
|
263
|
+
rowEnd,
|
264
|
+
colStart,
|
265
|
+
colEnd
|
266
|
+
} = node.data;
|
267
|
+
if (row >= rowStart && row <= rowEnd && column >= colStart && column <= colEnd) {
|
268
|
+
_classPrivateFieldSet(_currentVerticalLinkedNode, this, node);
|
269
|
+
return false;
|
270
|
+
}
|
271
|
+
});
|
272
|
+
return this;
|
273
|
+
}
|
274
|
+
}
|
275
|
+
exports.FocusOrder = FocusOrder;
|
276
|
+
function _pushOrderNode(selectedRange, listOrder, mergeCellsVisitor, row, column) {
|
277
|
+
const topStart = selectedRange.getTopStartCorner();
|
278
|
+
const bottomEnd = selectedRange.getBottomEndCorner();
|
279
|
+
const highlight = selectedRange.highlight.clone().normalize();
|
280
|
+
const mergeParent = _classPrivateFieldGet(_mergedCellsGetter, this).call(this, row, column);
|
281
|
+
if (mergeParent && mergeCellsVisitor.has(mergeParent)) {
|
282
|
+
return null;
|
283
|
+
}
|
284
|
+
const node = {
|
285
|
+
colStart: column,
|
286
|
+
colEnd: column,
|
287
|
+
rowStart: row,
|
288
|
+
rowEnd: row
|
289
|
+
};
|
290
|
+
if (mergeParent) {
|
291
|
+
mergeCellsVisitor.add(mergeParent);
|
292
|
+
if (mergeParent.row < topStart.row || mergeParent.row + mergeParent.rowspan - 1 > bottomEnd.row || mergeParent.col < topStart.col || mergeParent.col + mergeParent.colspan - 1 > bottomEnd.col) {
|
293
|
+
return null;
|
294
|
+
}
|
295
|
+
node.colStart = mergeParent.col;
|
296
|
+
node.colEnd = mergeParent.col + mergeParent.colspan - 1;
|
297
|
+
node.rowStart = mergeParent.row;
|
298
|
+
node.rowEnd = mergeParent.row + mergeParent.rowspan - 1;
|
299
|
+
}
|
300
|
+
const linkedNode = listOrder.push(node);
|
301
|
+
if (row === highlight.row && column === highlight.col || mergeParent && highlight.row >= mergeParent.row && highlight.row <= mergeParent.row + mergeParent.rowspan - 1 && highlight.col >= mergeParent.col && highlight.col <= mergeParent.col + mergeParent.colspan - 1) {
|
302
|
+
return linkedNode;
|
303
|
+
}
|
304
|
+
return null;
|
305
|
+
}
|
@@ -0,0 +1,300 @@
|
|
1
|
+
import "core-js/modules/es.error.cause.js";
|
2
|
+
import "core-js/modules/es.array.push.js";
|
3
|
+
function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
|
4
|
+
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
5
|
+
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
6
|
+
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
7
|
+
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
8
|
+
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
9
|
+
import LinkedList from "../../utils/dataStructures/linkedList.mjs";
|
10
|
+
/**
|
11
|
+
* Class responsible for providing the correct focus order (vertical and horizontal) within a selection that
|
12
|
+
* contains merged cells.
|
13
|
+
*
|
14
|
+
* @private
|
15
|
+
*/
|
16
|
+
var _cellsHorizontalOrder = /*#__PURE__*/new WeakMap();
|
17
|
+
var _cellsVerticalOrder = /*#__PURE__*/new WeakMap();
|
18
|
+
var _currentHorizontalLinkedNode = /*#__PURE__*/new WeakMap();
|
19
|
+
var _currentVerticalLinkedNode = /*#__PURE__*/new WeakMap();
|
20
|
+
var _mergedCellsGetter = /*#__PURE__*/new WeakMap();
|
21
|
+
var _rowIndexMapper = /*#__PURE__*/new WeakMap();
|
22
|
+
var _columnIndexMapper = /*#__PURE__*/new WeakMap();
|
23
|
+
var _FocusOrder_brand = /*#__PURE__*/new WeakSet();
|
24
|
+
export class FocusOrder {
|
25
|
+
constructor(_ref) {
|
26
|
+
let {
|
27
|
+
mergedCellsGetter,
|
28
|
+
rowIndexMapper,
|
29
|
+
columnIndexMapper
|
30
|
+
} = _ref;
|
31
|
+
/**
|
32
|
+
* Pushes a new node to the provided list order.
|
33
|
+
*
|
34
|
+
* @param {CellRange} selectedRange The selected range to build the focus order for.
|
35
|
+
* @param {LinkedList} listOrder The list order to push the node to.
|
36
|
+
* @param {WeakSet} mergeCellsVisitor The set of visited cells.
|
37
|
+
* @param {number} row The visual row index.
|
38
|
+
* @param {number} column The visual column index.
|
39
|
+
* @returns {NodeStructure | null}
|
40
|
+
*/
|
41
|
+
_classPrivateMethodInitSpec(this, _FocusOrder_brand);
|
42
|
+
/**
|
43
|
+
* The linked list of the all cells within the current selection in horizontal order. The list is
|
44
|
+
* recreated every time the selection is changed.
|
45
|
+
*
|
46
|
+
* @type {LinkedList}
|
47
|
+
*/
|
48
|
+
_classPrivateFieldInitSpec(this, _cellsHorizontalOrder, new LinkedList());
|
49
|
+
/**
|
50
|
+
* The linked list of the all cells within the current selection in horizontal order. The list is
|
51
|
+
* recreated every time the selection is changed.
|
52
|
+
*
|
53
|
+
* @type {LinkedList}
|
54
|
+
*/
|
55
|
+
_classPrivateFieldInitSpec(this, _cellsVerticalOrder, new LinkedList());
|
56
|
+
/**
|
57
|
+
* The currently highlighted cell within the horizontal linked list.
|
58
|
+
*
|
59
|
+
* @type {NodeStructure | null}
|
60
|
+
*/
|
61
|
+
_classPrivateFieldInitSpec(this, _currentHorizontalLinkedNode, null);
|
62
|
+
/**
|
63
|
+
* The currently highlighted cell within the vertical linked list.
|
64
|
+
*
|
65
|
+
* @type {NodeStructure | null}
|
66
|
+
*/
|
67
|
+
_classPrivateFieldInitSpec(this, _currentVerticalLinkedNode, null);
|
68
|
+
/**
|
69
|
+
* The merged cells getter function.
|
70
|
+
*
|
71
|
+
* @type {function(): {row: number, col: number, rowspan: number, colspan: number} | null}}
|
72
|
+
*/
|
73
|
+
_classPrivateFieldInitSpec(this, _mergedCellsGetter, null);
|
74
|
+
/**
|
75
|
+
* The row index mapper.
|
76
|
+
*
|
77
|
+
* @type {IndexMapper}
|
78
|
+
*/
|
79
|
+
_classPrivateFieldInitSpec(this, _rowIndexMapper, null);
|
80
|
+
/**
|
81
|
+
* The column index mapper.
|
82
|
+
*
|
83
|
+
* @type {IndexMapper}
|
84
|
+
*/
|
85
|
+
_classPrivateFieldInitSpec(this, _columnIndexMapper, null);
|
86
|
+
_classPrivateFieldSet(_mergedCellsGetter, this, mergedCellsGetter);
|
87
|
+
_classPrivateFieldSet(_rowIndexMapper, this, rowIndexMapper);
|
88
|
+
_classPrivateFieldSet(_columnIndexMapper, this, columnIndexMapper);
|
89
|
+
}
|
90
|
+
|
91
|
+
/**
|
92
|
+
* Gets the currently selected node data from the vertical focus order list.
|
93
|
+
*
|
94
|
+
* @returns {NodeStructure}
|
95
|
+
*/
|
96
|
+
getCurrentVerticalNode() {
|
97
|
+
return _classPrivateFieldGet(_currentVerticalLinkedNode, this).data;
|
98
|
+
}
|
99
|
+
|
100
|
+
/**
|
101
|
+
* Gets the first node data from the vertical focus order list.
|
102
|
+
*
|
103
|
+
* @returns {NodeStructure}
|
104
|
+
*/
|
105
|
+
getFirstVerticalNode() {
|
106
|
+
return _classPrivateFieldGet(_cellsVerticalOrder, this).first.data;
|
107
|
+
}
|
108
|
+
|
109
|
+
/**
|
110
|
+
* Gets the next selected node data from the vertical focus order list.
|
111
|
+
*
|
112
|
+
* @returns {NodeStructure}
|
113
|
+
*/
|
114
|
+
getNextVerticalNode() {
|
115
|
+
return _classPrivateFieldGet(_currentVerticalLinkedNode, this).next.data;
|
116
|
+
}
|
117
|
+
|
118
|
+
/**
|
119
|
+
* Gets the previous selected node data from the vertical focus order list.
|
120
|
+
*
|
121
|
+
* @returns {NodeStructure}
|
122
|
+
*/
|
123
|
+
getPrevVerticalNode() {
|
124
|
+
return _classPrivateFieldGet(_currentVerticalLinkedNode, this).prev.data;
|
125
|
+
}
|
126
|
+
|
127
|
+
/**
|
128
|
+
* Gets the currently selected node data from the horizontal focus order list.
|
129
|
+
*
|
130
|
+
* @returns {NodeStructure}
|
131
|
+
*/
|
132
|
+
getCurrentHorizontalNode() {
|
133
|
+
return _classPrivateFieldGet(_currentHorizontalLinkedNode, this).data;
|
134
|
+
}
|
135
|
+
|
136
|
+
/**
|
137
|
+
* Gets the first node data from the horizontal focus order list.
|
138
|
+
*
|
139
|
+
* @returns {NodeStructure}
|
140
|
+
*/
|
141
|
+
getFirstHorizontalNode() {
|
142
|
+
return _classPrivateFieldGet(_cellsHorizontalOrder, this).first.data;
|
143
|
+
}
|
144
|
+
|
145
|
+
/**
|
146
|
+
* Gets the next selected node data from the horizontal focus order list.
|
147
|
+
*
|
148
|
+
* @returns {NodeStructure}
|
149
|
+
*/
|
150
|
+
getNextHorizontalNode() {
|
151
|
+
return _classPrivateFieldGet(_currentHorizontalLinkedNode, this).next.data;
|
152
|
+
}
|
153
|
+
|
154
|
+
/**
|
155
|
+
* Gets the previous selected node data from the horizontal focus order list.
|
156
|
+
*
|
157
|
+
* @returns {NodeStructure}
|
158
|
+
*/
|
159
|
+
getPrevHorizontalNode() {
|
160
|
+
return _classPrivateFieldGet(_currentHorizontalLinkedNode, this).prev.data;
|
161
|
+
}
|
162
|
+
|
163
|
+
/**
|
164
|
+
* Sets the previous node from the vertical focus order list as active.
|
165
|
+
*/
|
166
|
+
setPrevNodeAsActive() {
|
167
|
+
_classPrivateFieldSet(_currentVerticalLinkedNode, this, _classPrivateFieldGet(_currentVerticalLinkedNode, this).prev);
|
168
|
+
_classPrivateFieldSet(_currentHorizontalLinkedNode, this, _classPrivateFieldGet(_currentHorizontalLinkedNode, this).prev);
|
169
|
+
}
|
170
|
+
|
171
|
+
/**
|
172
|
+
* Sets the previous node from the horizontal focus order list as active.
|
173
|
+
*/
|
174
|
+
setNextNodeAsActive() {
|
175
|
+
_classPrivateFieldSet(_currentVerticalLinkedNode, this, _classPrivateFieldGet(_currentVerticalLinkedNode, this).next);
|
176
|
+
_classPrivateFieldSet(_currentHorizontalLinkedNode, this, _classPrivateFieldGet(_currentHorizontalLinkedNode, this).next);
|
177
|
+
}
|
178
|
+
|
179
|
+
/**
|
180
|
+
* Rebuilds the focus order list based on the provided selection.
|
181
|
+
*
|
182
|
+
* @param {CellRange} selectedRange The selected range to build the focus order for.
|
183
|
+
*/
|
184
|
+
buildFocusOrder(selectedRange) {
|
185
|
+
const topStart = selectedRange.getTopStartCorner();
|
186
|
+
const bottomEnd = selectedRange.getBottomEndCorner();
|
187
|
+
const visitedHorizontalCells = new WeakSet();
|
188
|
+
_classPrivateFieldSet(_cellsHorizontalOrder, this, new LinkedList());
|
189
|
+
for (let r = topStart.row; r <= bottomEnd.row; r++) {
|
190
|
+
if (_classPrivateFieldGet(_rowIndexMapper, this).isHidden(r)) {
|
191
|
+
// eslint-disable-next-line no-continue
|
192
|
+
continue;
|
193
|
+
}
|
194
|
+
for (let c = topStart.col; c <= bottomEnd.col; c++) {
|
195
|
+
if (_classPrivateFieldGet(_columnIndexMapper, this).isHidden(c)) {
|
196
|
+
// eslint-disable-next-line no-continue
|
197
|
+
continue;
|
198
|
+
}
|
199
|
+
const node = _assertClassBrand(_FocusOrder_brand, this, _pushOrderNode).call(this, selectedRange, _classPrivateFieldGet(_cellsHorizontalOrder, this), visitedHorizontalCells, r, c);
|
200
|
+
if (node) {
|
201
|
+
_classPrivateFieldSet(_currentHorizontalLinkedNode, this, node);
|
202
|
+
}
|
203
|
+
}
|
204
|
+
}
|
205
|
+
|
206
|
+
// create circular linked list
|
207
|
+
if (_classPrivateFieldGet(_cellsHorizontalOrder, this).first) {
|
208
|
+
_classPrivateFieldGet(_cellsHorizontalOrder, this).first.prev = _classPrivateFieldGet(_cellsHorizontalOrder, this).last;
|
209
|
+
_classPrivateFieldGet(_cellsHorizontalOrder, this).last.next = _classPrivateFieldGet(_cellsHorizontalOrder, this).first;
|
210
|
+
}
|
211
|
+
const visitedVerticalCells = new WeakSet();
|
212
|
+
_classPrivateFieldSet(_cellsVerticalOrder, this, new LinkedList());
|
213
|
+
for (let c = topStart.col; c <= bottomEnd.col; c++) {
|
214
|
+
if (_classPrivateFieldGet(_columnIndexMapper, this).isHidden(c)) {
|
215
|
+
// eslint-disable-next-line no-continue
|
216
|
+
continue;
|
217
|
+
}
|
218
|
+
for (let r = topStart.row; r <= bottomEnd.row; r++) {
|
219
|
+
if (_classPrivateFieldGet(_rowIndexMapper, this).isHidden(r)) {
|
220
|
+
// eslint-disable-next-line no-continue
|
221
|
+
continue;
|
222
|
+
}
|
223
|
+
const node = _assertClassBrand(_FocusOrder_brand, this, _pushOrderNode).call(this, selectedRange, _classPrivateFieldGet(_cellsVerticalOrder, this), visitedVerticalCells, r, c);
|
224
|
+
if (node) {
|
225
|
+
_classPrivateFieldSet(_currentVerticalLinkedNode, this, node);
|
226
|
+
}
|
227
|
+
}
|
228
|
+
}
|
229
|
+
|
230
|
+
// create circular linked list
|
231
|
+
if (_classPrivateFieldGet(_cellsVerticalOrder, this).first) {
|
232
|
+
_classPrivateFieldGet(_cellsVerticalOrder, this).first.prev = _classPrivateFieldGet(_cellsVerticalOrder, this).last;
|
233
|
+
_classPrivateFieldGet(_cellsVerticalOrder, this).last.next = _classPrivateFieldGet(_cellsVerticalOrder, this).first;
|
234
|
+
}
|
235
|
+
}
|
236
|
+
/**
|
237
|
+
* Sets the active node based on the provided row and column.
|
238
|
+
*
|
239
|
+
* @param {number} row The visual row index.
|
240
|
+
* @param {number} column The visual column index.
|
241
|
+
* @returns {FocusOrder}
|
242
|
+
*/
|
243
|
+
setActiveNode(row, column) {
|
244
|
+
_classPrivateFieldGet(_cellsHorizontalOrder, this).inorder(node => {
|
245
|
+
const {
|
246
|
+
rowStart,
|
247
|
+
rowEnd,
|
248
|
+
colStart,
|
249
|
+
colEnd
|
250
|
+
} = node.data;
|
251
|
+
if (row >= rowStart && row <= rowEnd && column >= colStart && column <= colEnd) {
|
252
|
+
_classPrivateFieldSet(_currentHorizontalLinkedNode, this, node);
|
253
|
+
return false;
|
254
|
+
}
|
255
|
+
});
|
256
|
+
_classPrivateFieldGet(_cellsVerticalOrder, this).inorder(node => {
|
257
|
+
const {
|
258
|
+
rowStart,
|
259
|
+
rowEnd,
|
260
|
+
colStart,
|
261
|
+
colEnd
|
262
|
+
} = node.data;
|
263
|
+
if (row >= rowStart && row <= rowEnd && column >= colStart && column <= colEnd) {
|
264
|
+
_classPrivateFieldSet(_currentVerticalLinkedNode, this, node);
|
265
|
+
return false;
|
266
|
+
}
|
267
|
+
});
|
268
|
+
return this;
|
269
|
+
}
|
270
|
+
}
|
271
|
+
function _pushOrderNode(selectedRange, listOrder, mergeCellsVisitor, row, column) {
|
272
|
+
const topStart = selectedRange.getTopStartCorner();
|
273
|
+
const bottomEnd = selectedRange.getBottomEndCorner();
|
274
|
+
const highlight = selectedRange.highlight.clone().normalize();
|
275
|
+
const mergeParent = _classPrivateFieldGet(_mergedCellsGetter, this).call(this, row, column);
|
276
|
+
if (mergeParent && mergeCellsVisitor.has(mergeParent)) {
|
277
|
+
return null;
|
278
|
+
}
|
279
|
+
const node = {
|
280
|
+
colStart: column,
|
281
|
+
colEnd: column,
|
282
|
+
rowStart: row,
|
283
|
+
rowEnd: row
|
284
|
+
};
|
285
|
+
if (mergeParent) {
|
286
|
+
mergeCellsVisitor.add(mergeParent);
|
287
|
+
if (mergeParent.row < topStart.row || mergeParent.row + mergeParent.rowspan - 1 > bottomEnd.row || mergeParent.col < topStart.col || mergeParent.col + mergeParent.colspan - 1 > bottomEnd.col) {
|
288
|
+
return null;
|
289
|
+
}
|
290
|
+
node.colStart = mergeParent.col;
|
291
|
+
node.colEnd = mergeParent.col + mergeParent.colspan - 1;
|
292
|
+
node.rowStart = mergeParent.row;
|
293
|
+
node.rowEnd = mergeParent.row + mergeParent.rowspan - 1;
|
294
|
+
}
|
295
|
+
const linkedNode = listOrder.push(node);
|
296
|
+
if (row === highlight.row && column === highlight.col || mergeParent && highlight.row >= mergeParent.row && highlight.row <= mergeParent.row + mergeParent.rowspan - 1 && highlight.col >= mergeParent.col && highlight.col <= mergeParent.col + mergeParent.colspan - 1) {
|
297
|
+
return linkedNode;
|
298
|
+
}
|
299
|
+
return null;
|
300
|
+
}
|