-
Notifications
You must be signed in to change notification settings - Fork 3k
/
manualColumnMove.js
741 lines (621 loc) · 24.6 KB
/
manualColumnMove.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
import { BasePlugin } from '../base';
import Hooks from '../../pluginHooks';
import { arrayReduce } from '../../helpers/array';
import { addClass, removeClass, offset, hasClass, outerWidth } from '../../helpers/dom/element';
import { rangeEach } from '../../helpers/number';
import EventManager from '../../eventManager';
import BacklightUI from './ui/backlight';
import GuidelineUI from './ui/guideline';
import './manualColumnMove.css';
Hooks.getSingleton().register('beforeColumnMove');
Hooks.getSingleton().register('afterColumnMove');
export const PLUGIN_KEY = 'manualColumnMove';
export const PLUGIN_PRIORITY = 120;
const privatePool = new WeakMap();
const CSS_PLUGIN = 'ht__manualColumnMove';
const CSS_SHOW_UI = 'show-ui';
const CSS_ON_MOVING = 'on-moving--columns';
const CSS_AFTER_SELECTION = 'after-selection--columns';
/* eslint-disable jsdoc/require-description-complete-sentence */
/**
* @plugin ManualColumnMove
* @class ManualColumnMove
*
* @description
* This plugin allows to change columns order. To make columns order persistent the {@link Options#persistentState}
* plugin should be enabled.
*
* API:
* - `moveColumn` - move single column to the new position.
* - `moveColumns` - move many columns (as an array of indexes) to the new position.
* - `dragColumn` - drag single column to the new position.
* - `dragColumns` - drag many columns (as an array of indexes) to the new position.
*
* [Documentation](@/guides/columns/column-moving.md) explain differences between drag and move actions.
* Please keep in mind that if you want apply visual changes,
* you have to call manually the `render` method on the instance of Handsontable.
*
* The plugin creates additional components to make moving possibly using user interface:
* - backlight - highlight of selected columns.
* - guideline - line which shows where columns has been moved.
*
* @class ManualColumnMove
* @plugin ManualColumnMove
*/
export class ManualColumnMove extends BasePlugin {
static get PLUGIN_KEY() {
return PLUGIN_KEY;
}
static get PLUGIN_PRIORITY() {
return PLUGIN_PRIORITY;
}
constructor(hotInstance) {
super(hotInstance);
/**
* Set up WeakMap of plugin to sharing private parameters;.
*/
privatePool.set(this, {
columnsToMove: [],
countCols: 0,
fixedColumns: 0,
pressed: void 0,
target: {
eventPageX: void 0,
coords: void 0,
TD: void 0,
col: void 0
},
cachedDropIndex: void 0
});
/**
* Event Manager object.
*
* @private
* @type {object}
*/
this.eventManager = new EventManager(this);
/**
* Backlight UI object.
*
* @private
* @type {object}
*/
this.backlight = new BacklightUI(hotInstance);
/**
* Guideline UI object.
*
* @private
* @type {object}
*/
this.guideline = new GuidelineUI(hotInstance);
}
/**
* Checks if the plugin is enabled in the handsontable settings. This method is executed in {@link Hooks#beforeInit}
* hook and if it returns `true` then the {@link ManualColumnMove#enablePlugin} method is called.
*
* @returns {boolean}
*/
isEnabled() {
return !!this.hot.getSettings()[PLUGIN_KEY];
}
/**
* Enables the plugin functionality for this Handsontable instance.
*/
enablePlugin() {
if (this.enabled) {
return;
}
this.addHook('beforeOnCellMouseDown', (...args) => this.onBeforeOnCellMouseDown(...args));
this.addHook('beforeOnCellMouseOver', (...args) => this.onBeforeOnCellMouseOver(...args));
this.addHook('afterScrollVertically', () => this.onAfterScrollVertically());
this.addHook('afterLoadData', (...args) => this.onAfterLoadData(...args));
this.buildPluginUI();
this.registerEvents();
// TODO: move adding plugin classname to BasePlugin.
addClass(this.hot.rootElement, CSS_PLUGIN);
super.enablePlugin();
}
/**
* Updates the plugin's state.
*
* This method is executed when [`updateSettings()`](@/api/core.md#updatesettings) is invoked with any of the following configuration options:
* - [`manualColumnMove`](@/api/options.md#manualcolumnmove)
*/
updatePlugin() {
this.disablePlugin();
this.enablePlugin();
this.moveBySettingsOrLoad();
super.updatePlugin();
}
/**
* Disables the plugin functionality for this Handsontable instance.
*/
disablePlugin() {
removeClass(this.hot.rootElement, CSS_PLUGIN);
this.unregisterEvents();
this.backlight.destroy();
this.guideline.destroy();
super.disablePlugin();
}
/**
* Moves a single column.
*
* @param {number} column Visual column index to be moved.
* @param {number} finalIndex Visual column index, being a start index for the moved columns. Points to where the elements will be placed after the moving action.
* To check the visualization of the final index, please take a look at [documentation](@/guides/columns/column-moving.md#drag-and-move-actions-of-manualcolumnmove-plugin).
* @fires Hooks#beforeColumnMove
* @fires Hooks#afterColumnMove
* @returns {boolean}
*/
moveColumn(column, finalIndex) {
return this.moveColumns([column], finalIndex);
}
/**
* Moves a multiple columns.
*
* @param {Array} columns Array of visual column indexes to be moved.
* @param {number} finalIndex Visual column index, being a start index for the moved columns. Points to where the elements will be placed after the moving action.
* To check the visualization of the final index, please take a look at [documentation](@/guides/columns/column-moving.md#drag-and-move-actions-of-manualcolumnmove-plugin).
* @fires Hooks#beforeColumnMove
* @fires Hooks#afterColumnMove
* @returns {boolean}
*/
moveColumns(columns, finalIndex) {
const priv = privatePool.get(this);
const dropIndex = priv.cachedDropIndex;
const movePossible = this.isMovePossible(columns, finalIndex);
const beforeMoveHook = this.hot.runHooks('beforeColumnMove', columns, finalIndex, dropIndex, movePossible);
priv.cachedDropIndex = void 0;
if (beforeMoveHook === false) {
return;
}
if (movePossible) {
this.hot.columnIndexMapper.moveIndexes(columns, finalIndex);
}
const movePerformed = movePossible && this.isColumnOrderChanged(columns, finalIndex);
this.hot.runHooks('afterColumnMove', columns, finalIndex, dropIndex, movePossible, movePerformed);
return movePerformed;
}
/**
* Drag a single column to drop index position.
*
* @param {number} column Visual column index to be dragged.
* @param {number} dropIndex Visual column index, being a drop index for the moved columns. Points to where we are going to drop the moved elements.
* To check visualization of drop index please take a look at [documentation](@/guides/columns/column-moving.md#drag-and-move-actions-of-manualcolumnmove-plugin).
* @fires Hooks#beforeColumnMove
* @fires Hooks#afterColumnMove
* @returns {boolean}
*/
dragColumn(column, dropIndex) {
return this.dragColumns([column], dropIndex);
}
/**
* Drag multiple columns to drop index position.
*
* @param {Array} columns Array of visual column indexes to be dragged.
* @param {number} dropIndex Visual column index, being a drop index for the moved columns. Points to where we are going to drop the moved elements.
* To check visualization of drop index please take a look at [documentation](@/guides/columns/column-moving.md#drag-and-move-actions-of-manualcolumnmove-plugin).
* @fires Hooks#beforeColumnMove
* @fires Hooks#afterColumnMove
* @returns {boolean}
*/
dragColumns(columns, dropIndex) {
const finalIndex = this.countFinalIndex(columns, dropIndex);
const priv = privatePool.get(this);
priv.cachedDropIndex = dropIndex;
return this.moveColumns(columns, finalIndex);
}
/**
* Indicates if it's possible to move columns to the desired position. Some of the actions aren't
* possible, i.e. You can’t move more than one element to the last position.
*
* @param {Array} movedColumns Array of visual column indexes to be moved.
* @param {number} finalIndex Visual column index, being a start index for the moved columns. Points to where the elements will be placed after the moving action.
* To check the visualization of the final index, please take a look at [documentation](@/guides/columns/column-moving.md#drag-and-move-actions-of-manualcolumnmove-plugin).
* @returns {boolean}
*/
isMovePossible(movedColumns, finalIndex) {
const length = this.hot.columnIndexMapper.getNotTrimmedIndexesLength();
// An attempt to transfer more columns to start destination than is possible (only when moving from the top to the bottom).
const tooHighDestinationIndex = movedColumns.length + finalIndex > length;
const tooLowDestinationIndex = finalIndex < 0;
const tooLowMovedColumnIndex = movedColumns.some(movedColumn => movedColumn < 0);
const tooHighMovedColumnIndex = movedColumns.some(movedColumn => movedColumn >= length);
if (tooHighDestinationIndex || tooLowDestinationIndex || tooLowMovedColumnIndex || tooHighMovedColumnIndex) {
return false;
}
return true;
}
/**
* Indicates if order of columns was changed.
*
* @private
* @param {Array} movedColumns Array of visual column indexes to be moved.
* @param {number} finalIndex Visual column index, being a start index for the moved columns. Points to where the elements will be placed after the moving action.
* To check the visualization of the final index, please take a look at [documentation](@/guides/columns/column-moving.md#drag-and-move-actions-of-manualcolumnmove-plugin).
* @returns {boolean}
*/
isColumnOrderChanged(movedColumns, finalIndex) {
return movedColumns.some((column, nrOfMovedElement) => column - nrOfMovedElement !== finalIndex);
}
/**
* Count the final column index from the drop index.
*
* @private
* @param {Array} movedColumns Array of visual column indexes to be moved.
* @param {number} dropIndex Visual column index, being a drop index for the moved columns.
* @returns {number} Visual column index, being a start index for the moved columns.
*/
countFinalIndex(movedColumns, dropIndex) {
const numberOfColumnsLowerThanDropIndex = arrayReduce(movedColumns, (numberOfColumns, currentColumnIndex) => {
if (currentColumnIndex < dropIndex) {
numberOfColumns += 1;
}
return numberOfColumns;
}, 0);
return dropIndex - numberOfColumnsLowerThanDropIndex;
}
/**
* Gets the sum of the widths of columns in the provided range.
*
* @private
* @param {number} fromColumn Visual column index.
* @param {number} toColumn Visual column index.
* @returns {number}
*/
getColumnsWidth(fromColumn, toColumn) {
const columnMapper = this.hot.columnIndexMapper;
let columnsWidth = 0;
for (let visualColumnIndex = fromColumn; visualColumnIndex <= toColumn; visualColumnIndex += 1) {
// We can't use just `getColWidth` (even without indexes translation) as it doesn't return proper values
// when column is stretched.
const renderableIndex = columnMapper.getRenderableFromVisualIndex(visualColumnIndex);
if (visualColumnIndex < 0) {
columnsWidth += this.hot.view._wt.wtViewport.getRowHeaderWidth() || 0;
} else if (renderableIndex !== null) {
columnsWidth += this.hot.view._wt.wtTable.getStretchedColumnWidth(renderableIndex) || 0;
}
}
return columnsWidth;
}
/**
* Loads initial settings when persistent state is saved or when plugin was initialized as an array.
*
* @private
*/
moveBySettingsOrLoad() {
const pluginSettings = this.hot.getSettings()[PLUGIN_KEY];
if (Array.isArray(pluginSettings)) {
this.moveColumns(pluginSettings, 0);
} else if (pluginSettings !== void 0) {
const persistentState = this.persistentStateLoad();
if (persistentState.length) {
this.moveColumns(persistentState, 0);
}
}
}
/**
* Checks if the provided column is in the fixedColumnsTop section.
*
* @private
* @param {number} column Visual column index to check.
* @returns {boolean}
*/
isFixedColumnsStart(column) {
return column < this.hot.getSettings().fixedColumnsStart;
}
/**
* Saves the manual column positions to the persistent state (the {@link Options#persistentState} option has to be enabled).
*
* @private
* @fires Hooks#persistentStateSave
*/
persistentStateSave() {
this.hot.runHooks('persistentStateSave', 'manualColumnMove', this.hot.columnIndexMapper.getIndexesSequence()); // The `PersistentState` plugin should be refactored.
}
/**
* Loads the manual column positions from the persistent state (the {@link Options#persistentState} option has to be enabled).
*
* @private
* @fires Hooks#persistentStateLoad
* @returns {Array} Stored state.
*/
persistentStateLoad() {
const storedState = {};
this.hot.runHooks('persistentStateLoad', 'manualColumnMove', storedState);
return storedState.value ? storedState.value : [];
}
/**
* Prepares an array of indexes based on actual selection.
*
* @private
* @param {number} start The start index.
* @param {number} end The end index.
* @returns {Array}
*/
prepareColumnsToMoving(start, end) {
const selectedColumns = [];
rangeEach(start, end, (i) => {
selectedColumns.push(i);
});
return selectedColumns;
}
/**
* Update the UI visual position.
*
* @private
*/
refreshPositions() {
const priv = privatePool.get(this);
const firstVisible = this.hot.view.getFirstFullyVisibleColumn();
if (this.isFixedColumnsStart(priv.hoveredColumn) && firstVisible > 0) {
this.hot.scrollViewportTo(
void 0, this.hot.columnIndexMapper.getNearestNotHiddenIndex(firstVisible - 1, -1));
}
const wtTable = this.hot.view._wt.wtTable;
const scrollableElement = this.hot.view._wt.wtOverlays.scrollableElement;
const scrollStart = typeof scrollableElement.scrollX === 'number' ?
scrollableElement.scrollX : scrollableElement.scrollLeft;
let tdOffsetStart = this.hot.view.THEAD.offsetLeft + this.getColumnsWidth(0, priv.hoveredColumn - 1);
const hiderWidth = wtTable.hider.offsetWidth;
const tbodyOffsetLeft = wtTable.TBODY.offsetLeft;
const backlightElemMarginStart = this.backlight.getOffset().start;
const backlightElemWidth = this.backlight.getSize().width;
let rowHeaderWidth = 0;
let mouseOffsetStart = 0;
if (this.hot.isRtl()) {
const rootWindow = this.hot.rootWindow;
const containerWidth = outerWidth(this.hot.rootElement);
const gridMostRightPos = rootWindow.innerWidth - priv.rootElementOffset - containerWidth;
mouseOffsetStart = rootWindow.innerWidth - priv.target.eventPageX - gridMostRightPos -
(scrollableElement.scrollX === void 0 ? scrollStart : 0);
} else {
mouseOffsetStart = priv.target.eventPageX -
(priv.rootElementOffset - (scrollableElement.scrollX === void 0 ? scrollStart : 0));
}
if (priv.hasRowHeaders) {
rowHeaderWidth = this.hot.view._wt.wtOverlays.inlineStartOverlay.clone.wtTable.getColumnHeader(-1).offsetWidth;
}
if (this.isFixedColumnsStart(priv.hoveredColumn)) {
tdOffsetStart += scrollStart;
}
tdOffsetStart += rowHeaderWidth;
if (priv.hoveredColumn < 0) {
// if hover on rowHeader
if (priv.fixedColumnsStart > 0) {
priv.target.col = 0;
} else {
priv.target.col = firstVisible > 0 ? firstVisible - 1 : firstVisible;
}
} else if (((priv.target.TD.offsetWidth / 2) + tdOffsetStart) <= mouseOffsetStart) {
const newCoordsCol = priv.hoveredColumn >= priv.countCols ? priv.countCols - 1 : priv.hoveredColumn;
// if hover on right part of TD
priv.target.col = newCoordsCol + 1;
// unfortunately first column is bigger than rest
tdOffsetStart += priv.target.TD.offsetWidth;
} else {
// elsewhere on table
priv.target.col = priv.hoveredColumn;
}
let backlightStart = mouseOffsetStart;
let guidelineStart = tdOffsetStart;
if (mouseOffsetStart + backlightElemWidth + backlightElemMarginStart >= hiderWidth) {
// prevent display backlight on the right side of the table
backlightStart = hiderWidth - backlightElemWidth - backlightElemMarginStart;
} else if (mouseOffsetStart + backlightElemMarginStart < tbodyOffsetLeft + rowHeaderWidth) {
// prevent display backlight on the left side of the table
backlightStart = tbodyOffsetLeft + rowHeaderWidth + Math.abs(backlightElemMarginStart);
}
if (tdOffsetStart >= hiderWidth - 1) {
// prevent display guideline outside the table
guidelineStart = hiderWidth - 1;
} else if (guidelineStart === 0) {
// guideline has got `margin-left: -1px` as default
guidelineStart = 1;
} else if (scrollableElement.scrollX !== void 0 && priv.hoveredColumn < priv.fixedColumnsStart) {
guidelineStart -= ((priv.rootElementOffset <= scrollableElement.scrollX) ? priv.rootElementOffset : 0);
}
this.backlight.setPosition(null, backlightStart);
this.guideline.setPosition(null, guidelineStart);
}
/**
* Binds the events used by the plugin.
*
* @private
*/
registerEvents() {
const { documentElement } = this.hot.rootDocument;
this.eventManager.addEventListener(documentElement, 'mousemove', event => this.onMouseMove(event));
this.eventManager.addEventListener(documentElement, 'mouseup', () => this.onMouseUp());
}
/**
* Unbinds the events used by the plugin.
*
* @private
*/
unregisterEvents() {
this.eventManager.clear();
}
/**
* Change the behavior of selection / dragging.
*
* @private
* @param {MouseEvent} event `mousedown` event properties.
* @param {CellCoords} coords Visual cell coordinates where was fired event.
* @param {HTMLElement} TD Cell represented as HTMLElement.
* @param {object} controller An object with properties `row`, `column` and `cell`. Each property contains
* a boolean value that allows or disallows changing the selection for that particular area.
*/
onBeforeOnCellMouseDown(event, coords, TD, controller) {
const wtTable = this.hot.view._wt.wtTable;
const isHeaderSelection = this.hot.selection.isSelectedByColumnHeader();
const selection = this.hot.getSelectedRangeLast();
const priv = privatePool.get(this);
// This block action shouldn't be handled below.
const isSortingElement = hasClass(event.target, 'sortAction');
if (!selection || !isHeaderSelection || priv.pressed || event.button !== 0 || isSortingElement) {
priv.pressed = false;
priv.columnsToMove.length = 0;
removeClass(this.hot.rootElement, [CSS_ON_MOVING, CSS_SHOW_UI]);
return;
}
const guidelineIsNotReady = this.guideline.isBuilt() && !this.guideline.isAppended();
const backlightIsNotReady = this.backlight.isBuilt() && !this.backlight.isAppended();
if (guidelineIsNotReady && backlightIsNotReady) {
this.guideline.appendTo(wtTable.hider);
this.backlight.appendTo(wtTable.hider);
}
const { from, to } = selection;
const start = Math.min(from.col, to.col);
const end = Math.max(from.col, to.col);
if (coords.row < 0 && (coords.col >= start && coords.col <= end)) {
controller.column = true;
priv.pressed = true;
priv.target.eventPageX = event.pageX;
priv.target.eventOffsetX = event.offsetX;
priv.hoveredColumn = coords.col;
priv.target.TD = TD;
priv.target.col = coords.col;
priv.columnsToMove = this.prepareColumnsToMoving(start, end);
priv.hasRowHeaders = !!this.hot.getSettings().rowHeaders;
priv.countCols = this.hot.countCols();
priv.fixedColumnsStart = this.hot.getSettings().fixedColumnsStart;
priv.rootElementOffset = offset(this.hot.rootElement).left;
const countColumnsFrom = priv.hasRowHeaders ? -1 : 0;
const topPos = wtTable.holder.scrollTop + wtTable.getColumnHeaderHeight(0) + 1;
const fixedColumnsStart = coords.col < priv.fixedColumnsStart;
const horizontalScrollPosition = Math.abs(this.hot.view._wt.wtOverlays.inlineStartOverlay.getScrollPosition());
const offsetX = Math.abs(event.offsetX - (this.hot.isRtl() ? event.target.offsetWidth : 0));
const inlineOffset = this.getColumnsWidth(start, coords.col - 1) + offsetX;
const inlinePos = this.getColumnsWidth(countColumnsFrom, start - 1) +
(fixedColumnsStart ? horizontalScrollPosition : 0) + inlineOffset;
this.backlight.setPosition(topPos, inlinePos);
this.backlight.setSize(this.getColumnsWidth(start, end), wtTable.hider.offsetHeight - topPos);
this.backlight.setOffset(null, -inlineOffset);
addClass(this.hot.rootElement, CSS_ON_MOVING);
} else {
removeClass(this.hot.rootElement, CSS_AFTER_SELECTION);
priv.pressed = false;
priv.columnsToMove.length = 0;
}
}
/**
* 'mouseMove' event callback. Fired when pointer move on document.documentElement.
*
* @private
* @param {MouseEvent} event `mousemove` event properties.
*/
onMouseMove(event) {
const priv = privatePool.get(this);
if (!priv.pressed) {
return;
}
// callback for browser which doesn't supports CSS pointer-event: none
if (event.target === this.backlight.element) {
const width = this.backlight.getSize().width;
this.backlight.setSize(0);
setTimeout(function() {
this.backlight.setPosition(width);
});
}
priv.target.eventPageX = event.pageX;
this.refreshPositions();
}
/**
* 'beforeOnCellMouseOver' hook callback. Fired when pointer was over cell.
*
* @private
* @param {MouseEvent} event `mouseover` event properties.
* @param {CellCoords} coords Visual cell coordinates where was fired event.
* @param {HTMLElement} TD Cell represented as HTMLElement.
* @param {object} controller An object with properties `row`, `column` and `cell`. Each property contains
* a boolean value that allows or disallows changing the selection for that particular area.
*/
onBeforeOnCellMouseOver(event, coords, TD, controller) {
const selectedRange = this.hot.getSelectedRangeLast();
const priv = privatePool.get(this);
if (!selectedRange || !priv.pressed) {
return;
}
if (priv.columnsToMove.indexOf(coords.col) > -1) {
removeClass(this.hot.rootElement, CSS_SHOW_UI);
} else {
addClass(this.hot.rootElement, CSS_SHOW_UI);
}
controller.row = true;
controller.column = true;
controller.cell = true;
priv.hoveredColumn = coords.col;
priv.target.TD = TD;
}
/**
* `onMouseUp` hook callback.
*
* @private
*/
onMouseUp() {
const priv = privatePool.get(this);
const target = priv.target.col;
const columnsLen = priv.columnsToMove.length;
priv.hoveredColumn = void 0;
priv.pressed = false;
priv.backlightWidth = 0;
removeClass(this.hot.rootElement, [CSS_ON_MOVING, CSS_SHOW_UI, CSS_AFTER_SELECTION]);
if (this.hot.selection.isSelectedByColumnHeader()) {
addClass(this.hot.rootElement, CSS_AFTER_SELECTION);
}
if (columnsLen < 1 || target === void 0) {
return;
}
const firstMovedVisualColumn = priv.columnsToMove[0];
const firstMovedPhysicalColumn = this.hot.toPhysicalColumn(firstMovedVisualColumn);
const movePerformed = this.dragColumns(priv.columnsToMove, target);
priv.columnsToMove.length = 0;
if (movePerformed === true) {
this.persistentStateSave();
this.hot.render();
this.hot.view.adjustElementsSize(true);
const selectionStart = this.hot.toVisualColumn(firstMovedPhysicalColumn);
const selectionEnd = selectionStart + columnsLen - 1;
this.hot.selectColumns(selectionStart, selectionEnd);
}
}
/**
* `afterScrollHorizontally` hook callback. Fired the table was scrolled horizontally.
*
* @private
*/
onAfterScrollVertically() {
const wtTable = this.hot.view._wt.wtTable;
const headerHeight = wtTable.getColumnHeaderHeight(0) + 1;
const scrollTop = wtTable.holder.scrollTop;
const posTop = headerHeight + scrollTop;
this.backlight.setPosition(posTop);
this.backlight.setSize(null, wtTable.hider.offsetHeight - posTop);
}
/**
* Builds the plugin's UI.
*
* @private
*/
buildPluginUI() {
this.backlight.build();
this.guideline.build();
}
/**
* Callback for the `afterLoadData` hook.
*
* @private
*/
onAfterLoadData() {
this.moveBySettingsOrLoad();
}
/**
* Destroys the plugin instance.
*/
destroy() {
this.backlight.destroy();
this.guideline.destroy();
super.destroy();
}
}