@refinitiv-ui/efx-grid 6.0.128 → 6.0.129

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.
@@ -2,7 +2,7 @@ import { Ext } from "../../tr-grid-util/es6/Ext.js";
2
2
  import { GridPlugin } from "../../tr-grid-util/es6/GridPlugin.js";
3
3
  import { MouseDownTrait } from "../../tr-grid-util/es6/MouseDownTrait.js";
4
4
  import { EventDispatcher } from "../../tr-grid-util/es6/EventDispatcher.js";
5
- import { isIE, cloneObject, prepareTSVContent } from "../../tr-grid-util/es6/Util.js";
5
+ import { cloneObject, prepareTSVContent } from "../../tr-grid-util/es6/Util.js";
6
6
  import { ElfUtil } from "../../tr-grid-util/es6/ElfUtil.js";
7
7
  import { injectCss, prettifyCss } from "../../tr-grid-util/es6/Util.js";
8
8
 
@@ -10,12 +10,13 @@ import { injectCss, prettifyCss } from "../../tr-grid-util/es6/Util.js";
10
10
  * @description The options can be specified by `cellSelection` property of the main grid's options
11
11
  * @property {string=} mode="cell" Available options are cell, row, and column
12
12
  * @property {boolean=} multipleSelection=true If disabled, only single cell can be selected at time
13
- * @property {boolean=} autoDeselecting=true If disabled, the selection will remain after grid losing focus
14
- * @property {boolean=} tabToSelect=false If enabled, the selection can be moved when user press tab key during the time grid is in focus.
13
+ * @property {boolean=} autoDeselecting=true If disabled, the cell selection will be kept after the focus on the grid element is lost
14
+ * @property {boolean=} tabToSelect=false If enabled, the selection can be moved when user press tab key during the time grid is in focus
15
15
  * @property {Function=} selectionChanged=null Event handler
16
16
  * @property {Function=} copy=null Event handler
17
17
  * @property {Function=} beforeMouseDown=null Event handler
18
- * @property {Array=} selectableSections=['content'] Use to set which section can be selected, if not specific then only content section can select
18
+ * @property {Array=} selectableSections=["content"] Use to set which section can be selected, if not specific then only content section can select
19
+ * @property {boolean=} copyDisabled=false If enabled, there will be no dafault content copying by the extension
19
20
  */
20
21
 
21
22
  /** @event CellSelectionPlugin#selectionChanged
@@ -24,63 +25,77 @@ import { injectCss, prettifyCss } from "../../tr-grid-util/es6/Util.js";
24
25
 
25
26
  /** @event CellSelectionPlugin#copy
26
27
  * @description Happens when Copy is triggered (e.g. Ctrl + C, or selecting copy from context menu).
28
+ * @property {Object} grid Core grid instance
29
+ * @property {boolean=} cancel This property can be set to true to cancel the operation
30
+ * @property {string=} data The data to be copied to system clipboard
31
+ * @property {string=} format="text/plain" The format of the data
32
+ * @example
33
+ * copy: function(e) {
34
+ * e.cancel = true; // To cancel the operation
35
+ * }
27
36
  */
28
37
 
29
38
  /** @event CellSelectionPlugin#beforeMouseDown
30
39
  * @description Happens when mouse is down.
31
40
  * @type {Object}
32
- * @property {boolean=} cancel Set to true to cancel operation.
41
+ * @property {boolean=} cancel This property can be set to true to cancel the operation
33
42
  */
34
43
 
35
44
  /** @constructor
36
45
  * @param {Object=} options
37
46
  * @extends {GridPlugin}
38
47
  */
39
- var CellSelectionPlugin = function CellSelectionPlugin(options) {
40
- this._textRange = document.createRange();
41
- this._isIE = isIE();
42
- this._unselectables = {
43
- title: true,
44
- header: true,
45
- content: false
46
- };
47
- this._hosts = [];
48
- this._map = [];
49
- this._curRect = {};
50
- this._curRect.left = 0;
51
- this._curRect.right = 0;
52
- this._curRect.top = 0;
53
- this._curRect.bottom = 0;
54
- this._onMouseMove = this._onMouseMove.bind(this);
55
- this._onMouseUp = this._onMouseUp.bind(this);
56
- this._onMouseDown = this._onMouseDown.bind(this);
57
- this._onBlur = this._onBlur.bind(this);
58
- this._onCopy = this._onCopy.bind(this);
59
- this._onTab = this._onTab.bind(this);
60
- this._onPostSectionDataBinding = this._onPostSectionDataBinding.bind(this);
61
- this._onColumnMoved = this._onColumnMoved.bind(this);
62
- if (options) {
63
- this.config({
64
- "cellSelection": options
65
- });
66
- }
48
+ let CellSelectionPlugin = function (options) {
49
+ this._textRange = document.createRange();
50
+ this._unselectables = {
51
+ title: true,
52
+ header: true,
53
+ content: false
54
+ };
55
+
56
+ this._hosts = [];
57
+ this._map = [];
58
+ this._curRect = {};
59
+ this._curRect.left = 0;
60
+ this._curRect.right = 0;
61
+ this._curRect.top = 0;
62
+ this._curRect.bottom = 0;
63
+
64
+ this._onMouseMove = this._onMouseMove.bind(this);
65
+ this._onMouseUp = this._onMouseUp.bind(this);
66
+ this._onMouseDown = this._onMouseDown.bind(this);
67
+ this._onBlur = this._onBlur.bind(this);
68
+ this._onCopy = this._onCopy.bind(this);
69
+ this._onTab = this._onTab.bind(this);
70
+ this._onPostSectionDataBinding = this._onPostSectionDataBinding.bind(this);
71
+ this._onColumnMoved = this._onColumnMoved.bind(this);
72
+
73
+ if(options) {
74
+ this.config({ "cellSelection": options });
75
+ }
67
76
  };
77
+
68
78
  Ext.inherits(CellSelectionPlugin, GridPlugin);
69
79
 
70
80
  /** @type {string}
71
81
  * @private
72
82
  */
73
- CellSelectionPlugin._styles = prettifyCss([":host .tr-grid .cell.selection", ["background-image: none;", "background-color: var(--grid-selection-bgcolor);"]]);
83
+ CellSelectionPlugin._styles = prettifyCss([
84
+ ":host .tr-grid .cell.selection", [
85
+ "background-image: none;",
86
+ "background-color: var(--grid-selection-bgcolor);"
87
+ ]
88
+ ]);
74
89
 
75
90
  /** @private
76
91
  * @param {Object} grid core grid instance
77
92
  */
78
- CellSelectionPlugin._applyStyles = function (grid) {
79
- if (!grid || grid._cellSelectionStyles || !ElfUtil.isHaloTheme()) {
80
- return;
81
- }
82
- grid._cellSelectionStyles = true; // Prevent loading the same style twice
83
- injectCss(CellSelectionPlugin._styles, grid.getElement());
93
+ CellSelectionPlugin._applyStyles = function(grid) {
94
+ if(!grid || grid._cellSelectionStyles || !ElfUtil.isHaloTheme()) {
95
+ return;
96
+ }
97
+ grid._cellSelectionStyles = true; // Prevent loading the same style twice
98
+ injectCss(CellSelectionPlugin._styles, grid.getElement());
84
99
  };
85
100
 
86
101
  /** @type {Range}
@@ -133,25 +148,20 @@ CellSelectionPlugin.prototype._unselectables;
133
148
  */
134
149
  CellSelectionPlugin.prototype._lastSelection = null;
135
150
 
136
- /** WORKAROUND FOR IE11 <br>
137
- * to prevent onblur event perform action if this blur event come from onmouseup handler <br>
138
- * _lastMouseUpTimeStamp will change in onmouseup handler
139
- * @type {Object}
140
- * @private
141
- */
142
- CellSelectionPlugin.prototype._lastMouseUpTimeStamp;
143
-
144
- /** Control auto Deseleting when on blur.
151
+ /** If disabled, the cell selection will be kept after the focus on the grid element is lost
145
152
  * @type {boolean}
146
153
  * @private
147
154
  */
148
155
  CellSelectionPlugin.prototype._autoDeselecting = true;
149
-
150
156
  /** Turn on/off cell selection.
151
157
  * @type {boolean}
152
158
  * @private
153
159
  */
154
160
  CellSelectionPlugin.prototype._disabled = false;
161
+ /** @type {boolean}
162
+ * @private
163
+ */
164
+ CellSelectionPlugin.prototype._copyDisabled = false;
155
165
 
156
166
  /** Trait Mouse Down
157
167
  * @type {MouseDownTrait}
@@ -163,32 +173,23 @@ CellSelectionPlugin.prototype._mouseTrait = null;
163
173
  * @private
164
174
  */
165
175
  CellSelectionPlugin.prototype._allowMultipleSelection = true;
166
- /** @type {boolean}
167
- * @private
168
- */
169
- CellSelectionPlugin.prototype._dirty = false;
170
176
  /** Allow user tab to select next/previous cell
171
177
  * @type {boolean}
172
178
  * @private
173
179
  */
174
180
  CellSelectionPlugin.prototype._tabToSelect = false;
175
- /** Flag to tell that browser is IE or Edge or not
176
- * @type {boolean}
177
- * @private
178
- */
179
- CellSelectionPlugin.prototype._isIE;
180
181
  /** Mapping of unclickable element tag
181
182
  * @type {Object}
182
183
  * @private
183
184
  */
184
185
  CellSelectionPlugin.prototype._unclickableMapping = {
185
- 'A': 1,
186
- 'INPUT': 1,
187
- 'BUTTON': 1,
188
- 'SELECT': 1,
189
- 'CHECKBOX': 1,
190
- 'EF-DATETIME-PICKER': 1,
191
- 'EF-MULTI-SELECT': 1
186
+ "A": 1,
187
+ "INPUT": 1,
188
+ "BUTTON": 1,
189
+ "SELECT": 1,
190
+ "CHECKBOX": 1,
191
+ "EF-DATETIME-PICKER": 1,
192
+ "EF-MULTI-SELECT": 1
192
193
  };
193
194
 
194
195
  /** Indicates direction vectors of mouse
@@ -207,7 +208,7 @@ CellSelectionPlugin.prototype._mouseOutOfGrid = false;
207
208
  * @type {number}
208
209
  * @private
209
210
  */
210
- CellSelectionPlugin.prototype._timeoutID = null;
211
+ CellSelectionPlugin.prototype._scrollingTimer = null;
211
212
 
212
213
  /** Default scroll speed
213
214
  * @type {number}
@@ -224,12 +225,12 @@ CellSelectionPlugin.prototype._prevRect = {};
224
225
  * @type {boolean}
225
226
  * @private
226
227
  */
227
- CellSelectionPlugin.prototype._draggable = false;
228
+ CellSelectionPlugin.prototype._dragging = false;
228
229
  /** @override
229
230
  * @return {string}
230
231
  */
231
232
  CellSelectionPlugin.prototype.getName = function () {
232
- return "CellSelectionPlugin";
233
+ return "CellSelectionPlugin";
233
234
  };
234
235
 
235
236
  /** Plugin that has multi-table support means that it can have multiple hosts/tables and share its states across those hosts/tables.
@@ -237,120 +238,129 @@ CellSelectionPlugin.prototype.getName = function () {
237
238
  * @public
238
239
  * @return {boolean}
239
240
  */
240
- CellSelectionPlugin.prototype.hasMultiTableSupport = function () {
241
- return true;
241
+ CellSelectionPlugin.prototype.hasMultiTableSupport = function() {
242
+ return true;
242
243
  };
243
244
 
244
245
  /** Called by Grid plugin's initialization
245
246
  * @override
246
247
  */
247
248
  CellSelectionPlugin.prototype.initialize = function (host, options) {
248
- if (this._hosts.indexOf(host) >= 0) {
249
- return;
250
- }
251
- this._hosts.push(host);
252
-
253
- // Set dragable event
254
- this._mouseTrait = new MouseDownTrait(host.getElement());
255
- this._mouseTrait.addEventListener('mouseDown', this._onMouseDown);
256
- this._mouseTrait.addEventListener('mouseUp', this._onMouseUp);
257
- this._mouseTrait.addEventListener('mouseMove', this._onMouseMove);
258
-
259
- // Set Behavior events.
260
- // the onblur event does not bubble
261
- host.getParent().addEventListener('blur', this._onBlur, true);
262
- host.listen("focusout", this._onBlur);
263
- host.listen("copy", this._onCopy);
264
-
265
- // Listen keydown from other hosts
266
- if (this._tabToSelect) {
267
- host.listen("keydown", this._onTab);
268
- }
269
- host.listen('postSectionDataBinding', this._onPostSectionDataBinding);
270
- host.listen('columnMoved', this._onColumnMoved);
271
- host.enableClass("no-text-select", true);
272
- if (this._hosts.length === 1) {
273
- this.config(options);
274
- }
275
- CellSelectionPlugin._applyStyles(host);
249
+ if(this._hosts.indexOf(host) >= 0) { return; }
250
+ this._hosts.push(host);
251
+
252
+ // Set dragable event
253
+ this._mouseTrait = new MouseDownTrait(host.getElement());
254
+ this._mouseTrait.addEventListener("mouseDown", this._onMouseDown);
255
+ this._mouseTrait.addEventListener("mouseUp", this._onMouseUp);
256
+ this._mouseTrait.addEventListener("mouseMove", this._onMouseMove);
257
+
258
+ host.listen("focusout", this._onBlur);
259
+ host.listen("copy", this._onCopy);
260
+
261
+ // Listen keydown from other hosts
262
+ if(this._tabToSelect) {
263
+ host.listen("keydown", this._onTab);
264
+ }
265
+
266
+ host.listen("postSectionDataBinding", this._onPostSectionDataBinding);
267
+ host.listen("columnMoved", this._onColumnMoved);
268
+
269
+ host.enableClass("no-text-select", true);
270
+
271
+ if(this._hosts.length === 1) {
272
+ this.config(options);
273
+ }
274
+
275
+ CellSelectionPlugin._applyStyles(host);
276
276
  };
277
277
 
278
278
  /** Prevent memory leak, when we leave witout unlisten.
279
279
  * @override
280
280
  */
281
281
  CellSelectionPlugin.prototype.unload = function (host) {
282
- var at = this._hosts.indexOf(host);
283
- if (at < 0) {
284
- return;
285
- }
286
- this._mouseTrait.removeEventListener('mouseDown', this._onMouseDown);
287
- this._mouseTrait.removeEventListener('mouseMove', this._onMouseMove);
288
- this._mouseTrait.removeEventListener('mouseUp', this._onMouseUp);
289
- host.unlisten("copy", this._onCopy);
290
- host.getParent().removeEventListener('blur', this._onBlur);
291
- host.unlisten("keydown", this._onTab);
292
- host.unlisten('postSectionDataBinding', this._onPostSectionDataBinding);
293
- host.unlisten('columnMoved', this._onColumnMoved);
294
-
295
- // Reset cell-selection behavior.
296
- this.deselectAll();
297
- host.enableClass("no-text-select", false);
298
-
299
- // remove host from host list
300
- this._hosts.splice(at, 1);
301
- if (!this._hosts.length) {
302
- this._compositeGrid = null;
303
- this._realTimeGrid = null;
304
- }
282
+ let at = this._hosts.indexOf(host);
283
+ if(at < 0) {
284
+ return;
285
+ }
286
+
287
+ this._mouseTrait.removeEventListener("mouseDown", this._onMouseDown);
288
+ this._mouseTrait.removeEventListener("mouseMove", this._onMouseMove);
289
+ this._mouseTrait.removeEventListener("mouseUp", this._onMouseUp);
290
+
291
+ host.unlisten("copy", this._onCopy);
292
+ host.unlisten("focusout", this._onBlur);
293
+ host.unlisten("keydown", this._onTab);
294
+
295
+ host.unlisten("postSectionDataBinding", this._onPostSectionDataBinding);
296
+ host.unlisten("columnMoved", this._onColumnMoved);
297
+
298
+ // Reset cell-selection behavior.
299
+ this.deselectAll();
300
+ host.enableClass("no-text-select", false);
301
+
302
+ // remove host from host list
303
+ this._hosts.splice(at, 1);
304
+
305
+ this._dispose();
305
306
  };
306
307
 
307
308
  /** Involk when config object is set.
308
309
  * @public
309
310
  * @param {Object=} options
310
311
  */
311
- CellSelectionPlugin.prototype.config = function (options) {
312
- if (!options) {
313
- return;
314
- }
315
- var pluginOption = options["cellSelection"];
316
- if (!pluginOption) {
317
- return;
318
- }
319
-
320
- // Mode
321
- var val = pluginOption["mode"];
322
- this._mode = val ? val : this._mode;
323
-
324
- // Is multiple selection
325
- val = pluginOption["multipleSelection"];
326
- this._allowMultipleSelection = val != null ? val : this._allowMultipleSelection;
327
- if (!this._allowMultipleSelection) {
328
- this._mouseTrait.removeEventListener("mouseMove", this._onMouseMove);
329
- }
330
-
331
- // Auto deselecting on blue
332
- val = pluginOption["autoDeselecting"];
333
- this._autoDeselecting = val != null ? val : this._autoDeselecting;
334
-
335
- // selectable sections
336
- val = pluginOption["selectableSections"];
337
- if (val) {
338
- this.setSelectableSections(val);
339
- }
340
-
341
- // Listen keydown from the first host
342
- val = pluginOption["tabToSelect"];
343
- if (val) {
344
- this._tabToSelect = true;
345
- if (this._hosts[0]) {
346
- this._hosts[0].listen("keydown", this._onTab);
347
- }
348
- }
349
-
350
- // event callback
351
- this.addListener(pluginOption, "selectionChanged");
352
- this.addListener(pluginOption, "copy");
353
- this.addListener(pluginOption, "beforeMouseDown");
312
+ CellSelectionPlugin.prototype.config = function(options) {
313
+ if(!options) {
314
+ return;
315
+ }
316
+
317
+ let pluginOption = options["cellSelection"];
318
+
319
+ if(!pluginOption) {
320
+ return;
321
+ }
322
+
323
+ let val = pluginOption["mode"];
324
+ if(val) {
325
+ this._mode = val; // TODO: Check for valid mode
326
+ }
327
+
328
+ val = pluginOption["multipleSelection"];
329
+ if(val != null) {
330
+ this._allowMultipleSelection = val ? true : false;
331
+ }
332
+
333
+ if(!this._allowMultipleSelection) {
334
+ this._mouseTrait.removeEventListener("mouseMove", this._onMouseMove);
335
+ }
336
+
337
+ val = pluginOption["autoDeselecting"];
338
+ if(val != null) {
339
+ this._autoDeselecting = val ? true : false;
340
+ }
341
+ val = pluginOption["copyDisabled"];
342
+ if(val != null) {
343
+ this._copyDisabled = val ? true : false;
344
+ }
345
+
346
+ val = pluginOption["selectableSections"];
347
+ if(val) {
348
+ this.setSelectableSections(val);
349
+ }
350
+
351
+ // Listen keydown from the first host
352
+ val = pluginOption["tabToSelect"];
353
+ if(val) {
354
+ this._tabToSelect = true;
355
+ if(this._hosts[0]) {
356
+ this._hosts[0].listen("keydown", this._onTab);
357
+ }
358
+ }
359
+
360
+ // event callback
361
+ this.addListener(pluginOption, "selectionChanged");
362
+ this.addListener(pluginOption, "copy");
363
+ this.addListener(pluginOption, "beforeMouseDown");
354
364
  };
355
365
 
356
366
  /** @public
@@ -358,110 +368,82 @@ CellSelectionPlugin.prototype.config = function (options) {
358
368
  * @return {!Object}
359
369
  */
360
370
  CellSelectionPlugin.prototype.getConfigObject = function (gridOptions) {
361
- var obj = gridOptions || {};
362
- var extOptions = obj.cellSelection;
363
- if (!extOptions) {
364
- extOptions = obj.cellSelection = {};
365
- }
366
- extOptions.mode = this._mode;
367
- if (!this._allowMultipleSelection) {
368
- extOptions.multipleSelection = false;
369
- }
370
- if (!this._autoDeselecting) {
371
- extOptions.autoDeselecting = false;
372
- }
373
- if (this._tabToSelect) {
374
- extOptions.tabToSelect = true;
375
- }
376
- var unSelectables = this._unselectables;
377
- var sections = [];
378
- for (var sectionName in unSelectables) {
379
- if (!unSelectables[sectionName]) {
380
- sections.push(sectionName);
381
- }
382
- }
383
- if (sections.length > 0 && sections.length < 3) {
384
- extOptions.selectableSections = sections;
385
- }
386
- return obj;
387
- };
388
- /** @public
389
- * @description Emitate the mousedown event. This is for testing purpose.
390
- * @ignore
391
- * @param {number} colIndex
392
- * @param {number} rowIndex
393
- */
394
- CellSelectionPlugin.prototype.mockMouseClick = function (colIndex, rowIndex) {
395
- var host = this._hosts[0];
396
- host.focus(); // Used for blur event triggering
397
- var evt = this._mockMouseEvent(colIndex, rowIndex);
398
- this._onMouseDown(evt);
399
- this._onMouseUp(evt);
400
- };
401
- /** @public
402
- * @description Emitate the mousedown event. This is for testing purpose.
403
- * @ignore
404
- * @param {number} colIndex
405
- * @param {number} rowIndex
406
- */
407
- CellSelectionPlugin.prototype.mockMouseDown = function (colIndex, rowIndex) {
408
- var evt = this._mockMouseEvent(colIndex, rowIndex);
409
- this._onMouseDown(evt);
371
+ let obj = gridOptions || {};
372
+
373
+ let extOptions = obj.cellSelection;
374
+ if(!extOptions) {
375
+ extOptions = obj.cellSelection = {};
376
+ }
377
+
378
+ extOptions.mode = this._mode;
379
+
380
+ if(!this._allowMultipleSelection) {
381
+ extOptions.multipleSelection = false;
382
+ }
383
+
384
+ if(!this._autoDeselecting) {
385
+ extOptions.autoDeselecting = false;
386
+ }
387
+ if(this._copyDisabled) {
388
+ extOptions.copyDisabled = true;
389
+ }
390
+
391
+ if(this._tabToSelect) {
392
+ extOptions.tabToSelect = true;
393
+ }
394
+
395
+ let unSelectables = this._unselectables;
396
+ let sections = [];
397
+ for(let sectionName in unSelectables) {
398
+ if(!unSelectables[sectionName]) {
399
+ sections.push(sectionName);
400
+ }
401
+ }
402
+ if(sections.length > 0 && sections.length < 3) {
403
+ extOptions.selectableSections = sections;
404
+ }
405
+
406
+ return obj;
410
407
  };
411
408
  /** @public
412
- * @description Emitate the mousedown event. This is for testing purpose.
413
409
  * @ignore
414
- * @param {number} colIndex
415
- * @param {number} rowIndex
410
+ * @return {!Object}
416
411
  */
417
- CellSelectionPlugin.prototype.mockMouseUp = function (colIndex, rowIndex) {
418
- var evt = this._mockMouseEvent(colIndex, rowIndex);
419
- this._onMouseUp(evt);
420
- };
421
- /** @public
422
- * @description Emitate the mousemove event. This is for testing purpose.
423
- * @ignore
424
- * @param {number} colIndex
425
- * @param {number} rowIndex
426
- * @param {number} x
427
- * @param {number} y
428
- * @param {Element} target Specify element out side of Grid to test scrolling
429
- */
430
- CellSelectionPlugin.prototype.mockMouseMove = function (colIndex, rowIndex, x, y, target) {
431
- var evt = {
432
- clientX: x,
433
- clientY: y
434
- };
435
- evt = this._mockMouseEvent(colIndex, rowIndex, evt);
436
- if (target) {
437
- evt.target = target;
438
- evt.path = [target];
439
- } else {
440
- evt.path = [evt.target];
441
- }
442
- this._onMouseMove(evt);
412
+ CellSelectionPlugin.prototype._getEventHandlers = function() {
413
+ return {
414
+ "mousedown": this._onMouseDown,
415
+ "mousemove": this._onMouseMove,
416
+ "mouseup": this._onMouseUp,
417
+ "copy": this._onCopy,
418
+ "blur": this._onBlur,
419
+ "keydown": this._onTab
420
+ };
443
421
  };
444
422
  /** Fire when mouse down.
445
423
  * @private
446
424
  * @param {MouseEvent} e
447
425
  */
448
426
  CellSelectionPlugin.prototype._onMouseDown = function (e) {
449
- this._draggable = false;
450
- if (this._disabled || !this._isClickable(e.target)) {
451
- return;
452
- }
453
- var activeGrid = this.getRelativeGrid(e);
454
- var newAnchor = activeGrid.getRelativePosition(e);
455
- if (this._unselectables[newAnchor.sectionType]) {
456
- return;
457
- }
458
- this._dispatch('beforeMouseDown', newAnchor);
459
- if (newAnchor.cancel) {
460
- return;
461
- }
462
- this._dirty = true;
463
- this.selectSingleCell(newAnchor);
464
- this._draggable = true;
427
+ this._dragging = false;
428
+ if(this._disabled || !this._isClickable(e.target)) {
429
+ return;
430
+ }
431
+
432
+ let activeGrid = this.getRelativeGrid(e);
433
+ let newAnchor = activeGrid.getRelativePosition(e);
434
+
435
+ if(this._unselectables[newAnchor.sectionType]) {
436
+ return;
437
+ }
438
+
439
+ this._dispatch("beforeMouseDown", newAnchor);
440
+
441
+ if(newAnchor.cancel) {
442
+ return;
443
+ }
444
+
445
+ this._dragging = true;
446
+ this.selectSingleCell(newAnchor);
465
447
  };
466
448
 
467
449
  /** Fire when mouse is draging.
@@ -469,81 +451,89 @@ CellSelectionPlugin.prototype._onMouseDown = function (e) {
469
451
  * @param {Event} e
470
452
  */
471
453
  CellSelectionPlugin.prototype._onMouseMove = function (e) {
472
- if (this._disabled || !this._anchor || !this._draggable) {
473
- return;
474
- }
475
- var activeGrid = this._getActiveGrid();
476
- var newMouse = activeGrid.getRelativePosition(e);
477
-
478
- // Avoid cross section selection but scrolling is still working
479
- if (this._anchor["sectionType"] === "title" && newMouse["sectionType"] !== "title") {
480
- return;
481
- } else if (this._anchor["sectionType"] === "content" && newMouse["sectionType"] === "title") {
482
- return;
483
- }
484
- if (!newMouse['hit']) {
485
- var gridHeight = activeGrid.getHeight();
486
- var gridWidth = activeGrid.getWidth();
487
- if (activeGrid.getScrollWidth() === 0 && activeGrid.getScrollHeight() === 0) {
488
- // prevent Auto Scrolling, if Grid does not have scroll
489
- return;
490
- }
491
- if (gridHeight >= newMouse.y && !(newMouse.y < 0) && gridWidth >= newMouse.x && !(newMouse.x < 0)) {
492
- // return Auto Scrolling, if mouse out of Grid
493
- return;
494
- }
495
- var x = 0;
496
- var y = 0;
497
- if (newMouse.x > gridWidth) {
498
- x = newMouse.x - gridWidth;
499
- } else if (newMouse.x < 0) {
500
- x = newMouse.x;
501
- }
502
- if (newMouse.y > gridHeight) {
503
- y = newMouse.y - gridHeight;
504
- } else if (newMouse.y < 0) {
505
- y = newMouse.y;
506
- }
507
- var dirVectors = {
508
- "x": x,
509
- "y": y
510
- };
511
-
512
- // set up scrollSpeed
513
- this._setScrollSpeed(dirVectors);
514
- var isSameProps = this._checkIsSameProps(dirVectors);
515
- if (this._mouseOutOfGrid && isSameProps) {
516
- return;
517
- }
518
- this._dirVectors = dirVectors;
519
- this._setScrollInterval(dirVectors);
520
- return;
521
- }
522
- if (this._timeoutID) {
523
- clearTimeout(this._timeoutID);
524
- this._mouseOutOfGrid = false;
525
- }
526
- if (this._isTheSamePosition(this._curMouse, newMouse)) {
527
- // No selection has been changed
528
- return;
529
- }
530
- this._curMouse = newMouse;
531
- this._dirty = true;
532
- var tgtRect = this._newSelectionRect();
533
- this._updateSelection(tgtRect);
454
+ if(this._disabled || !this._anchor || !this._dragging) {
455
+ return;
456
+ }
457
+ let activeGrid = this._getActiveGrid();
458
+ let newMouse = activeGrid.getRelativePosition(e);
459
+
460
+ // Avoid cross section selection but scrolling is still working
461
+ if(this._anchor["sectionType"] === "title" && newMouse["sectionType"] !== "title") {
462
+ return;
463
+ } else if (this._anchor["sectionType"] === "content" && newMouse["sectionType"] === "title") {
464
+ return;
465
+ }
466
+
467
+ if(!newMouse["hit"]) {
468
+ let gridHeight = activeGrid.getHeight();
469
+ let gridWidth = activeGrid.getWidth();
470
+
471
+ if(activeGrid.getScrollWidth() === 0 && activeGrid.getScrollHeight() === 0) {
472
+ // prevent Auto Scrolling, if Grid does not have scroll
473
+ return;
474
+ }
475
+
476
+ if((gridHeight >= newMouse.y && !(newMouse.y < 0)) && (gridWidth >= newMouse.x && !(newMouse.x < 0))) {
477
+ // return Auto Scrolling, if mouse out of Grid
478
+ return;
479
+ }
480
+
481
+ let x = 0;
482
+ let y = 0;
483
+ if(newMouse.x > gridWidth) {
484
+ x = newMouse.x - gridWidth;
485
+ } else if(newMouse.x < 0) {
486
+ x = newMouse.x;
487
+ }
488
+ if(newMouse.y > gridHeight) {
489
+ y = newMouse.y - gridHeight;
490
+ } else if(newMouse.y < 0) {
491
+ y = newMouse.y;
492
+ }
493
+
494
+ let dirVectors = {
495
+ "x": x,
496
+ "y": y
497
+ };
498
+
499
+ // set up scrollSpeed
500
+ this._setScrollSpeed(dirVectors);
501
+
502
+ let isSameProps = this._checkIsSameProps(dirVectors);
503
+
504
+ if(this._mouseOutOfGrid && isSameProps) {
505
+ return;
506
+ }
507
+
508
+ this._dirVectors = dirVectors;
509
+ this._setScrollInterval(dirVectors);
510
+ return;
511
+ }
512
+
513
+ this._clearScrollingTimer();
514
+
515
+ if(this._isTheSamePosition(this._curMouse, newMouse)) {
516
+ // No selection has been changed
517
+ return;
518
+ }
519
+
520
+ this._curMouse = newMouse;
521
+ let tgtRect = this._newSelectionRect();
522
+
523
+ this._updateSelection(tgtRect);
534
524
  };
535
525
 
536
526
  /** Get active grid
537
527
  * @private
538
528
  * @return {Object} core grid
539
529
  */
540
- CellSelectionPlugin.prototype._getActiveGrid = function () {
541
- var anchor = this._anchor;
542
- if (anchor && anchor["grid"]) {
543
- return anchor["grid"];
544
- } else {
545
- return this._hosts[0];
546
- }
530
+ CellSelectionPlugin.prototype._getActiveGrid = function() {
531
+ let anchor = this._anchor;
532
+ if(anchor && anchor["grid"]) {
533
+ return anchor["grid"];
534
+ } else {
535
+ return this._hosts[0];
536
+ }
547
537
  };
548
538
 
549
539
  /** Set scroll speed
@@ -551,11 +541,12 @@ CellSelectionPlugin.prototype._getActiveGrid = function () {
551
541
  * @param {Object} dirVectors Indicates direction vectors of mouse
552
542
  */
553
543
  CellSelectionPlugin.prototype._setScrollSpeed = function (dirVectors) {
554
- var basedSped = 300;
555
- var scrollSpeed = Math.floor(basedSped - Math.abs((dirVectors.x + dirVectors.y) / 2));
556
- if (scrollSpeed % 10 === 0) {
557
- this._scrollSpeed = scrollSpeed > 0 || scrollSpeed <= 500 ? scrollSpeed : 50;
558
- }
544
+ let basedSped = 300;
545
+ let scrollSpeed = Math.floor(basedSped - Math.abs((dirVectors.x + dirVectors.y) / 2));
546
+
547
+ if(scrollSpeed % 10 === 0) {
548
+ this._scrollSpeed = scrollSpeed > 0 || scrollSpeed <= 500 ? scrollSpeed : 50;
549
+ }
559
550
  };
560
551
 
561
552
  /** Detect direction vector
@@ -563,17 +554,17 @@ CellSelectionPlugin.prototype._setScrollSpeed = function (dirVectors) {
563
554
  * @param {number} vector
564
555
  * @return {string|null}
565
556
  */
566
- CellSelectionPlugin.prototype._detectDir = function (vector) {
567
- var part = null;
568
- if (vector < 0) {
569
- part = 'minus'; // minus vector
570
- } else if (vector === 0) {
571
- part = 'zero'; // zero vector
572
- } else if (vector > 0) {
573
- part = 'positive'; // positive vector
574
- }
575
-
576
- return part;
557
+ CellSelectionPlugin.prototype._detectDir = function(vector) {
558
+ let part = null;
559
+ if(vector < 0) {
560
+ part = "minus"; // minus vector
561
+ } else if(vector === 0) {
562
+ part = "zero"; // zero vector
563
+ } else if(vector > 0) {
564
+ part = "positive"; // positive vector
565
+ }
566
+
567
+ return part;
577
568
  };
578
569
 
579
570
  /** Check Is Same Props
@@ -581,132 +572,156 @@ CellSelectionPlugin.prototype._detectDir = function (vector) {
581
572
  * @param {Object} newDirVectors - indicates direction vectors of mouse
582
573
  * @return {boolean}
583
574
  */
584
- CellSelectionPlugin.prototype._checkIsSameProps = function (newDirVectors) {
585
- if (!this._dirVectors || !newDirVectors) {
586
- return false;
587
- }
588
- var isX = this._detectDir(this._dirVectors.x) === this._detectDir(newDirVectors.x);
589
- var isY = this._detectDir(this._dirVectors.y) === this._detectDir(newDirVectors.y);
590
- return isX && isY;
575
+ CellSelectionPlugin.prototype._checkIsSameProps = function(newDirVectors) {
576
+
577
+ if(!this._dirVectors || !newDirVectors) {
578
+ return false;
579
+ }
580
+
581
+ let isX = this._detectDir(this._dirVectors.x) === this._detectDir(newDirVectors.x);
582
+ let isY = this._detectDir(this._dirVectors.y) === this._detectDir(newDirVectors.y);
583
+
584
+ return (
585
+ isX && isY
586
+ );
591
587
  };
592
588
 
589
+ /** @private
590
+ */
591
+ CellSelectionPlugin.prototype._clearScrollingTimer = function () {
592
+ if(this._scrollingTimer) {
593
+ clearInterval(this._scrollingTimer);
594
+ this._scrollingTimer = 0;
595
+ this._mouseOutOfGrid = false;
596
+ }
597
+ };
593
598
  /** @private
594
599
  * @param {Object} dirVectors
595
600
  */
596
601
  CellSelectionPlugin.prototype._setScrollInterval = function (dirVectors) {
597
- if (this._timeoutID) {
598
- clearTimeout(this._timeoutID);
599
- }
600
- if (!this._mouseOutOfGrid) {
601
- this._mouseOutOfGrid = true;
602
- }
603
- var tgtRect = this._newSelectionRect();
604
- var initialScrollSpeed = this._scrollSpeed || 500;
605
- this._timeoutID = setInterval(function () {
606
- if (initialScrollSpeed !== this._scrollSpeed) {
607
- this._setScrollInterval(dirVectors);
608
- return;
609
- }
610
- var currentScrollTop = this._hosts[0].getScrollTop();
611
- var currentScrollLeft = this._hosts[0].getScrollLeft();
612
- var isYPositive = dirVectors.y > 0;
613
- var isXPositive = dirVectors.x > 0;
614
- var cellWidth = this._map[0].section.getCellWidth();
615
- var cellHeight = this._map[0].section.getCellHeight();
616
- var scrollToTop = isYPositive ? currentScrollTop + cellWidth : currentScrollTop - cellWidth;
617
- var scrollToLeft = isXPositive ? currentScrollLeft + cellHeight : currentScrollLeft - cellHeight;
618
- if (dirVectors.y !== 0) {
619
- // updates scroll position
620
- this._hosts[0].setScrollTop(scrollToTop);
621
- var vScrollbar = this._hosts[0].getVScrollbar();
622
- var rowVirtualizer = this._hosts[0].getRowVirtualizer();
623
- var isEndOfVerticalScroll = this._isEndOfVerticalScroll();
624
- var vTrackHeight = vScrollbar.getHeight();
625
- var scrollViewOffset = rowVirtualizer.getViewOffset();
626
-
627
- // scrolling down
628
- if (isYPositive) {
629
- var nextBottomRowEndPos = rowVirtualizer.getContentStart(tgtRect.bottom + 1) - scrollViewOffset; //end position of next bottom row
630
-
631
- if (nextBottomRowEndPos <= vTrackHeight) {
632
- // while next row is in scroll view, extend to next bottom row
633
- while (nextBottomRowEndPos <= vTrackHeight) {
634
- tgtRect.bottom += 1;
635
- nextBottomRowEndPos = rowVirtualizer.getContentStart(tgtRect.bottom + 1) - scrollViewOffset;
636
- }
637
- } else if (isEndOfVerticalScroll) {
638
- tgtRect.bottom = this._hosts[0].getRowCount();
639
- }
640
- }
641
- // scrolling up
642
- else {
643
- var nextTopRowStartPos = rowVirtualizer.getContentStart(tgtRect.top - 1) - scrollViewOffset; //start position of next top row
644
-
645
- if (nextTopRowStartPos >= 0) {
646
- // while next row is in scroll view, extend to next top row
647
- while (nextTopRowStartPos >= 0) {
648
- tgtRect.top -= 1;
649
- nextTopRowStartPos = rowVirtualizer.getContentStart(tgtRect.top - 1) - scrollViewOffset;
650
- }
651
- } else if (isEndOfVerticalScroll) {
652
- tgtRect.top = 1;
653
- }
654
- }
655
- }
656
- if (dirVectors.x !== 0) {
657
- // updates scroll position
658
- this._hosts[0].setScrollLeft(Math.floor(scrollToLeft));
659
- var isEndOfHorizontalScroll = this._isEndOfHorizontalScroll();
660
- var hScrollbar = this._hosts[0].getHScrollbar();
661
- var hTrackWidth = hScrollbar.getTrackSize();
662
-
663
- // scrolling right
664
- if (isXPositive) {
665
- var leftPinnedWidth = 0;
666
- var leftPinnedCount = this._hosts[0].getPinnedLeftColumnCount();
667
-
668
- // getting width of left pinned columns
669
- if (leftPinnedCount) {
670
- leftPinnedWidth = this._hosts[0].getContentWidth() - hScrollbar.getContentWidth();
671
- }
672
- var nextRightColEndPos = this._hosts[0].getColumnRight(tgtRect.right) - leftPinnedWidth; //end position of next right column
673
- // if next column is in scroll view, extend to next right column
674
- if (nextRightColEndPos <= hTrackWidth) {
675
- tgtRect.right += 1;
676
- } else if (isEndOfHorizontalScroll) {
677
- tgtRect.right = this._hosts[0].getColumnCount();
678
- }
679
- }
680
- // scrolling left
681
- else {
682
- var nextLeftColStartPos = this._hosts[0].getColumnLeft(tgtRect.left - 1); //start position of next left column
683
- // if next column is in scroll view, extend to next left column
684
- if (nextLeftColStartPos >= 0) {
685
- tgtRect.left -= 1;
686
- } else if (isEndOfHorizontalScroll) {
687
- tgtRect.left = 0;
688
- }
689
- }
690
- }
691
- this._updateSelection(tgtRect);
692
- this._prevRect = cloneObject(tgtRect);
693
- }.bind(this), initialScrollSpeed);
602
+ this._clearScrollingTimer();
603
+ this._mouseOutOfGrid = true;
604
+
605
+ let tgtRect = this._newSelectionRect();
606
+ let initialScrollSpeed = this._scrollSpeed || 500;
607
+
608
+ this._scrollingTimer = setInterval(function () {
609
+ if(initialScrollSpeed !== this._scrollSpeed) {
610
+ this._setScrollInterval(dirVectors);
611
+ return;
612
+ }
613
+ let currentScrollTop = this._hosts[0].getScrollTop();
614
+ let currentScrollLeft = this._hosts[0].getScrollLeft();
615
+
616
+ let isYPositive = dirVectors.y > 0;
617
+ let isXPositive = dirVectors.x > 0;
618
+
619
+ let cellWidth = this._map[0].section.getCellWidth();
620
+ let cellHeight = this._map[0].section.getCellHeight();
621
+
622
+ let scrollToTop = isYPositive ? currentScrollTop + cellWidth : currentScrollTop - cellWidth;
623
+ let scrollToLeft = isXPositive ? currentScrollLeft + cellHeight : currentScrollLeft - cellHeight;
624
+
625
+ if(dirVectors.y !== 0) {
626
+ // updates scroll position
627
+ this._hosts[0].setScrollTop(scrollToTop);
628
+
629
+ let vScrollbar = this._hosts[0].getVScrollbar();
630
+ let rowVirtualizer = this._hosts[0].getRowVirtualizer();
631
+ let isEndOfVerticalScroll = this._isEndOfVerticalScroll();
632
+ let vTrackHeight = vScrollbar.getHeight();
633
+ let scrollViewOffset = rowVirtualizer.getViewOffset();
634
+
635
+ // scrolling down
636
+ if(isYPositive) {
637
+ let nextBottomRowEndPos = rowVirtualizer.getContentStart(tgtRect.bottom + 1) - scrollViewOffset; //end position of next bottom row
638
+
639
+ if(nextBottomRowEndPos <= vTrackHeight){
640
+ // while next row is in scroll view, extend to next bottom row
641
+ while(nextBottomRowEndPos <= vTrackHeight){
642
+ tgtRect.bottom += 1;
643
+ nextBottomRowEndPos = rowVirtualizer.getContentStart(tgtRect.bottom + 1) - scrollViewOffset;
644
+ }
645
+ } else if(isEndOfVerticalScroll){
646
+ tgtRect.bottom = this._hosts[0].getRowCount();
647
+ }
648
+ }
649
+ // scrolling up
650
+ else {
651
+ let nextTopRowStartPos = rowVirtualizer.getContentStart(tgtRect.top - 1) - scrollViewOffset; //start position of next top row
652
+
653
+ if(nextTopRowStartPos >= 0){
654
+ // while next row is in scroll view, extend to next top row
655
+ while(nextTopRowStartPos >= 0){
656
+ tgtRect.top -= 1;
657
+ nextTopRowStartPos = rowVirtualizer.getContentStart(tgtRect.top - 1) - scrollViewOffset;
658
+ }
659
+ } else if(isEndOfVerticalScroll){
660
+ tgtRect.top = 1;
661
+ }
662
+ }
663
+ }
664
+
665
+ if(dirVectors.x !== 0) {
666
+ // updates scroll position
667
+ this._hosts[0].setScrollLeft(Math.floor(scrollToLeft));
668
+
669
+ let isEndOfHorizontalScroll = this._isEndOfHorizontalScroll();
670
+ let hScrollbar = this._hosts[0].getHScrollbar();
671
+ let hTrackWidth = hScrollbar.getTrackSize();
672
+
673
+ // scrolling right
674
+ if(isXPositive){
675
+ let leftPinnedWidth = 0;
676
+ let leftPinnedCount = this._hosts[0].getPinnedLeftColumnCount();
677
+
678
+ // getting width of left pinned columns
679
+ if(leftPinnedCount){
680
+ leftPinnedWidth = this._hosts[0].getContentWidth() - hScrollbar.getContentWidth();
681
+ }
682
+
683
+ let nextRightColEndPos = this._hosts[0].getColumnRight(tgtRect.right) - leftPinnedWidth; //end position of next right column
684
+ // if next column is in scroll view, extend to next right column
685
+ if(nextRightColEndPos <= hTrackWidth){
686
+ tgtRect.right += 1;
687
+ } else if(isEndOfHorizontalScroll){
688
+ tgtRect.right = this._hosts[0].getColumnCount();
689
+ }
690
+ }
691
+ // scrolling left
692
+ else {
693
+ let nextLeftColStartPos = this._hosts[0].getColumnLeft(tgtRect.left - 1); //start position of next left column
694
+ // if next column is in scroll view, extend to next left column
695
+ if(nextLeftColStartPos >= 0){
696
+ tgtRect.left -= 1;
697
+ } else if(isEndOfHorizontalScroll){
698
+ tgtRect.left = 0;
699
+ }
700
+ }
701
+ }
702
+
703
+ this._updateSelection(tgtRect);
704
+ this._prevRect = cloneObject(tgtRect);
705
+ }.bind(this), initialScrollSpeed);
694
706
  };
695
707
 
696
708
  /** @private
697
709
  * @return {boolean}
698
710
  */
699
711
  CellSelectionPlugin.prototype._isEndOfVerticalScroll = function () {
700
- var getScrollTop = this._hosts[0].getScrollTop();
701
- return getScrollTop === 0 || getScrollTop + this._hosts[0].getHeight() > this._hosts[0].getScrollHeight();
712
+ let scrollTop = this._hosts[0].getScrollTop();
713
+ if(!scrollTop) {
714
+ return true;
715
+ }
716
+ return (scrollTop + this._hosts[0].getHeight()) > this._hosts[0].getScrollHeight();
702
717
  };
703
718
 
704
719
  /** @private
705
720
  * @return {boolean}
706
721
  */
707
722
  CellSelectionPlugin.prototype._isEndOfHorizontalScroll = function () {
708
- var hScrollbar = this._hosts[0].getHScrollbar();
709
- return hScrollbar.isEndOfHorizontalScroll() || this._hosts[0].getScrollLeft() == 0;
723
+ let hScrollbar = this._hosts[0].getHScrollbar();
724
+ return hScrollbar.isEndOfHorizontalScroll() || this._hosts[0].getScrollLeft() == 0;
710
725
  };
711
726
 
712
727
  /** Fire when draging was end.
@@ -714,81 +729,33 @@ CellSelectionPlugin.prototype._isEndOfHorizontalScroll = function () {
714
729
  * @param {Object} e
715
730
  */
716
731
  CellSelectionPlugin.prototype._onMouseUp = function (e) {
717
- if (this._timeoutID) {
718
- clearTimeout(this._timeoutID);
719
- this._mouseOutOfGrid = false;
720
- }
721
- if (this._disabled || !this._dirty) {
722
- return;
723
- }
724
- this._draggable = false;
725
-
726
- // WORKAROUND: FOR IE11
727
- if (this._isIE) {
728
- // timestamp to use in onblur event
729
- this._lastMouseUpTimeStamp = e.timeStamp;
730
- }
731
- this._updateSelectionText();
732
- this._dispatch("selectionChanged", {});
733
- this._dirty = false;
734
- };
735
-
736
- /** to update selection text
737
- * @private
738
- */
739
- CellSelectionPlugin.prototype._updateSelectionText = function () {
740
- // Native copy event will not be triggered, if there's no text selection.
741
- // So we will select text in hiddenInput
742
- // we can only use selection.addRange because it not hijack focus of other element
743
- // EXCEPT IE11 there is no way to select text without changing focus element
744
- var hiddenInput = this._getGridHiddenInput();
745
- if (hiddenInput) {
746
- var selection = window.getSelection();
747
- var selectionText;
748
- if (this._isIE) {
749
- selectionText = this._textRange.htmlText;
750
- } else {
751
- selectionText = selection.toString();
752
- }
753
-
754
- // we cannot set start with hidden input
755
- // it will cause error in IE11
756
- // So we use hiddenInput parent instead
757
- if (!selectionText) {
758
- this._textRange.setStart(hiddenInput.parentNode, 0);
759
- this._textRange.setEnd(hiddenInput, 0);
760
- selection.removeAllRanges();
761
-
762
- // THIS WILL CAUSE IE11 FIRE BLUR EVENT AND CHANG FOCUS
763
- selection.addRange(this._textRange);
764
- // Cause in IE11, active element will change when perform text select
765
- // so we will make current grid focus again
766
- if (this._isIE) {
767
- this._getActiveGrid().focus();
768
- }
769
- }
770
- }
732
+ this._clearScrollingTimer();
733
+
734
+ if(this._disabled || !this._dragging) {
735
+ return;
736
+ }
737
+
738
+ if(!CellSelectionPlugin._hasTextSelection()) {
739
+ let activeGrid = this._getActiveGrid();
740
+ if(activeGrid) {
741
+ activeGrid.focus(); // Trigger blur and focusout events
742
+ }
743
+ }
744
+ this._dragging = false;
745
+ this._dispatch("selectionChanged", {});
771
746
  };
772
747
 
773
- /** Fire when out of focus.
774
- * @private
748
+ /** @private
775
749
  * @param {Object} e
776
750
  */
777
- CellSelectionPlugin.prototype._onBlur = function (e) {
778
- if (this._dirty) {
779
- // Prevent onBlur while dragging
780
- return;
781
- } else if (!this._autoDeselecting) {
782
- return;
783
- } else if (this._lastMouseUpTimeStamp && e.timeStamp - this._lastMouseUpTimeStamp < 100) {
784
- // should use more than 100 millisec
785
- // WORKAROUND: FOR IE11
786
- // if onblur fire immediately after mouseup event
787
- // we will ignore this blur event
788
- return;
789
- } else if (this.deselectAll()) {
790
- this._dispatch("selectionChanged", {});
791
- }
751
+ CellSelectionPlugin.prototype._onBlur = function (e) { // WARNING: This happens immediately after the first mousedown on the grid
752
+ if(this._dragging || !this._autoDeselecting) { // Ignore any blur and focusout during the dragging operation
753
+ return;
754
+ }
755
+
756
+ if(this.deselectAll()) {
757
+ this._dispatch("selectionChanged", {});
758
+ }
792
759
  };
793
760
 
794
761
  /** to remove selection UI when column moved, then postSectionData will rerender selection UI again
@@ -796,44 +763,41 @@ CellSelectionPlugin.prototype._onBlur = function (e) {
796
763
  * @param {Object} e
797
764
  */
798
765
  CellSelectionPlugin.prototype._onColumnMoved = function (e) {
799
- var rect = this._curRect;
800
- var from = e.fromColIndex;
801
- var to = e.toColIndex;
802
- // ignore column that moved outside selection range
803
- if (from < rect.left && to < rect.left) {
804
- return;
805
- } else if (from >= rect.right && to >= rect.right) {
806
- return;
807
- }
808
- var clearColIndex;
809
- // move from outside left to right
810
- // the selection column will shift to left
811
- if (from < rect.left) {
812
- clearColIndex = rect.left - 1;
813
- }
814
- // move from outside right to left
815
- // the selection column will shift to right
816
- else if (from >= rect.right) {
817
- clearColIndex = rect.right;
818
- }
819
- // move from inside to outside
820
- // the selection column will move to specific column
821
- else if (to < rect.left || to >= rect.right) {
822
- clearColIndex = to;
823
- }
824
- // move from inside to inside
825
- else {
826
- return; // just do nothing
827
- }
828
-
829
- for (var rowIndex = rect.top; rowIndex < rect.bottom; rowIndex++) {
830
- var rowObj = this._map[rowIndex];
831
- rowObj.section.selectCell(clearColIndex, rowObj.rowIndex, false);
832
- }
833
- // NOTED: No need to reselect after clear selection UI.
834
- // postSectionDataBinding will do this job
835
-
836
- this._updateSelectionText();
766
+ let rect = this._curRect;
767
+ let from = e.fromColIndex;
768
+ let to = e.toColIndex;
769
+ // ignore column that moved outside selection range
770
+ if(from < rect.left && to < rect.left) {
771
+ return;
772
+ } else if(from >= rect.right && to >= rect.right) {
773
+ return;
774
+ }
775
+
776
+ let clearColIndex;
777
+ // move from outside left to right
778
+ // the selection column will shift to left
779
+ if(from < rect.left) {
780
+ clearColIndex = rect.left - 1;
781
+ }
782
+ // move from outside right to left
783
+ // the selection column will shift to right
784
+ else if(from >= rect.right) {
785
+ clearColIndex = rect.right;
786
+ }
787
+ // move from inside to outside
788
+ // the selection column will move to specific column
789
+ else if(to < rect.left || to >= rect.right) {
790
+ clearColIndex = to;
791
+ }
792
+ // move from inside to inside
793
+ else {
794
+ return; // just do nothing
795
+ }
796
+
797
+ for(let rowIndex = rect.top; rowIndex < rect.bottom; rowIndex++) {
798
+ let rowObj = this._map[rowIndex];
799
+ rowObj.section.selectCell(clearColIndex, rowObj.rowIndex, false);
800
+ }
837
801
  };
838
802
 
839
803
  /** Check if the element clickable.
@@ -843,17 +807,28 @@ CellSelectionPlugin.prototype._onColumnMoved = function (e) {
843
807
  * @return {boolean}
844
808
  */
845
809
  CellSelectionPlugin.prototype._isClickable = function (elem, activeGrid) {
846
- if (!this._hosts[0] || !elem
847
- // case tagName = EF-<whatever> but except EF-ICON and EF-HEADER
848
- || 'EF-ICON' !== elem.tagName && 'EF-HEADER' !== elem.tagName && 0 === elem.tagName.indexOf('EF-')) {
849
- return false;
850
- }
851
- // case elem.tagName is in inclickable list
852
- if (this._unclickableMapping[elem.tagName] && !elem.classList.contains("valigner")) {
853
- // button.valigner is clickable
854
- return false;
855
- }
856
- return true;
810
+ if(!this._hosts[0] || !elem
811
+ // case tagName = EF-<whatever> but except EF-ICON and EF-HEADER
812
+ || ("EF-ICON" !== elem.tagName
813
+ && "EF-HEADER" !== elem.tagName
814
+ && 0 === elem.tagName.indexOf("EF-"))
815
+ ) {
816
+ return false;
817
+ }
818
+ // case elem.tagName is in inclickable list
819
+ if(this._unclickableMapping[elem.tagName] && !elem.classList.contains("valigner")) { // button.valigner is clickable
820
+ return false;
821
+ }
822
+
823
+ return true;
824
+ };
825
+
826
+ /** Check if there is any text selection in the document. This method adds more testability.
827
+ * @private
828
+ * @returns {boolean}
829
+ */
830
+ CellSelectionPlugin._hasTextSelection = function() {
831
+ return window.getSelection().toString() ? true : false;
857
832
  };
858
833
 
859
834
  /** Copy text in selected cell to clipboard. If no selection, clipboard will NOT be replaced by empty string
@@ -861,131 +836,129 @@ CellSelectionPlugin.prototype._isClickable = function (elem, activeGrid) {
861
836
  * @param {MouseEvent} e
862
837
  */
863
838
  CellSelectionPlugin.prototype._onCopy = function (e) {
864
- var obj = {
865
- "grid": this._hosts[0],
866
- "sender": this,
867
- "data": "",
868
- "format": "",
869
- "clipboards": []
870
- };
871
- this._dispatch("copy", obj);
872
- var selectionText;
873
- if (this._isIE) {
874
- selectionText = this._textRange.htmlText;
875
- } else {
876
- selectionText = window.getSelection().toString();
877
- }
878
- if (selectionText) {
879
- return;
880
- }
881
- var clipboardData, format;
882
- if (e.clipboardData) {
883
- clipboardData = e.clipboardData;
884
- format = "text/plain";
885
- } else {
886
- clipboardData = window.clipboardData;
887
- format = "Text";
888
- }
889
- // Set clipboards data to copy api.
890
- if (obj.data) {
891
- clipboardData.setData(obj.format || format, obj.data);
892
- } else {
893
- var txt = this.getSelectedText();
894
- if (txt) {
895
- // Use Native browser event object intead of Google's BrowserEvent
896
- clipboardData.setData(format, txt);
897
- }
898
- }
899
- var len = obj.clipboards ? obj.clipboards.length : 0;
900
- for (var i = 0; i < len; ++i) {
901
- var clipboard = obj.clipboards[i];
902
- if (clipboard.format) {
903
- clipboardData.setData(clipboard.format, clipboard.data || "");
904
- }
905
- }
906
- EventDispatcher.preventDefault(e);
839
+ if(this._copyDisabled) {
840
+ return;
841
+ }
842
+
843
+ if(CellSelectionPlugin._hasTextSelection()) {
844
+ return; // If there is already native text selection, custom copying is not allowed
845
+ }
846
+
847
+ let obj = {
848
+ grid: this._hosts[0],
849
+ sender: this,
850
+ data: "",
851
+ format: "",
852
+ clipboards: []
853
+ };
854
+
855
+ this._dispatch("copy", obj);
856
+
857
+ if(obj.cancel) {
858
+ return;
859
+ }
860
+
861
+ let clipboardData = (e.clipboardData || window.clipboardData);
862
+ let format = "text/plain";
863
+ let dirty = false;
864
+ // Single format support
865
+ if(obj.data) {
866
+ clipboardData.setData(obj.format || format, obj.data);
867
+ dirty = true;
868
+ } else {
869
+ let txt = this.getSelectedText();
870
+ if(txt) {
871
+ clipboardData.setData(format, txt);
872
+ dirty = true;
873
+ }
874
+ }
875
+
876
+ // Multiple formats support
877
+ let len = obj.clipboards ? obj.clipboards.length : 0;
878
+ for(let i = 0; i < len; ++i) {
879
+ let clipboard = obj.clipboards[i];
880
+ if(clipboard.format){
881
+ clipboardData.setData(clipboard.format, clipboard.data || "");
882
+ dirty = true;
883
+ }
884
+ }
885
+
886
+ if(dirty) {
887
+ EventDispatcher.preventDefault(e);
888
+ }
907
889
  };
908
890
 
909
891
  /** @private
910
892
  * @param {KeyboardEvent} e
911
893
  */
912
894
  CellSelectionPlugin.prototype._onTab = function (e) {
913
- if (e.keyCode === 9) {
914
- // Tab key
915
- if (e.altKey || e.ctrlKey) {
916
- return;
917
- }
918
- var ret = e.shiftKey ? this.selectPrevCell() : this.selectNextCell();
919
- if (ret) {
920
- EventDispatcher.preventDefault(e);
921
- }
922
- }
895
+ if(e.keyCode === 9) { // Tab key
896
+ if(e.altKey || e.ctrlKey || e.metaKey) {
897
+ return;
898
+ }
899
+ let ret = (e.shiftKey) ? this.selectPrevCell() : this.selectNextCell();
900
+ if(ret) {
901
+ EventDispatcher.preventDefault(e);
902
+ }
903
+ }
923
904
  };
924
905
 
925
906
  /** @private
926
907
  * @param {Object} e for cell style binding
927
908
  */
928
909
  CellSelectionPlugin.prototype._onPostSectionDataBinding = function (e) {
929
- var activeGrid = this._getActiveGrid();
930
- if (this.getSelectionCount() > 0 && activeGrid === e.sender) {
931
- // let colCount = this._hosts[0].getColumnCount();
932
- var rowOffset = e.section.getRowOffset();
933
- var selectionRowStart = this._curRect.top - rowOffset;
934
- var selectionRowEnd = this._curRect.bottom - rowOffset;
935
- var selectionColStart = this._curRect.left;
936
- var selectionColEnd = this._curRect.right;
937
- var rowIndex, colIndex;
938
- for (rowIndex = e.fromRowIndex; rowIndex < e.toRowIndex; rowIndex++) {
939
- if (rowIndex >= selectionRowStart && rowIndex < selectionRowEnd) {
940
- // if row inside selection range
941
- for (colIndex = selectionColStart; colIndex < selectionColEnd; colIndex++) {
942
- e.section.selectCell(colIndex, rowIndex, true);
943
- }
944
- } else {
945
- for (colIndex = selectionColStart; colIndex < selectionColEnd; colIndex++) {
946
- e.section.selectCell(colIndex, rowIndex, false);
947
- }
948
- }
949
- }
950
- }
951
- };
952
-
953
- /** Get content string in the cell.
954
- * @private
955
- * @param {string} elem
956
- * @return {boolean}
957
- */
958
- CellSelectionPlugin.prototype._isString = function (elem) {
959
- return Object.prototype.toString.call(elem) === "[object String]";
910
+ let activeGrid = this._getActiveGrid();
911
+ if(this.getSelectionCount() > 0 && activeGrid === e.sender) {
912
+ // let colCount = this._hosts[0].getColumnCount();
913
+ let rowOffset = e.section.getRowOffset();
914
+ let selectionRowStart = this._curRect.top - rowOffset;
915
+ let selectionRowEnd = this._curRect.bottom - rowOffset;
916
+ let selectionColStart = this._curRect.left;
917
+ let selectionColEnd = this._curRect.right;
918
+ let rowIndex, colIndex;
919
+ for(rowIndex = e.fromRowIndex; rowIndex < e.toRowIndex; rowIndex++) {
920
+ if(rowIndex >= selectionRowStart && rowIndex < selectionRowEnd) {
921
+ // if row inside selection range
922
+ for(colIndex = selectionColStart; colIndex < selectionColEnd; colIndex++) {
923
+ e.section.selectCell(colIndex, rowIndex, true);
924
+ }
925
+ } else {
926
+ for(colIndex = selectionColStart; colIndex < selectionColEnd; colIndex++) {
927
+ e.section.selectCell(colIndex, rowIndex, false);
928
+ }
929
+ }
930
+ }
931
+ }
960
932
  };
961
933
 
962
934
  /** @private */
963
935
  CellSelectionPlugin.prototype._cacheSectionMap = function () {
964
- var sectionCount = this._hosts[0].getSectionCount();
965
- var totalRow = 0;
966
- var rowOffset = 0;
967
- this._hasCellSpan = false;
968
- var activeGrid = this._getActiveGrid();
969
- for (var i = 0; i < sectionCount; ++i) {
970
- var sectionSettings = activeGrid.getSectionSettings(i);
971
- var section = sectionSettings.getSection();
972
- var hasCellSpan = section.hasCellSpan();
973
- var rowCount = section.getRowCount();
974
- for (var j = 0; j < rowCount; ++j) {
975
- var obj = {};
976
- obj.section = section;
977
- obj.hasCellSpan = hasCellSpan;
978
- obj.sectionIndex = i;
979
- obj.rowIndex = j;
980
- obj.rowOffset = rowOffset;
981
- obj.type = sectionSettings.getType();
982
- this._map[totalRow] = obj;
983
- totalRow++;
984
- }
985
- rowOffset += rowCount;
986
- this._hasCellSpan |= hasCellSpan;
987
- }
988
- this._map.length = totalRow;
936
+ let sectionCount = this._hosts[0].getSectionCount();
937
+ let totalRow = 0;
938
+ let rowOffset = 0;
939
+
940
+ this._hasCellSpan = false;
941
+ let activeGrid = this._getActiveGrid();
942
+ for(let i = 0; i < sectionCount; ++i) {
943
+ let sectionSettings = activeGrid.getSectionSettings(i);
944
+ let section = sectionSettings.getSection();
945
+ let hasCellSpan = section.hasCellSpan();
946
+ let rowCount = section.getRowCount();
947
+ for(let j = 0; j < rowCount; ++j) {
948
+ let obj = {};
949
+ obj.section = section;
950
+ obj.hasCellSpan = hasCellSpan;
951
+ obj.sectionIndex = i;
952
+ obj.rowIndex = j;
953
+ obj.rowOffset = rowOffset;
954
+ obj.type = sectionSettings.getType();
955
+ this._map[totalRow] = obj;
956
+ totalRow++;
957
+ }
958
+ rowOffset += rowCount;
959
+ this._hasCellSpan |= hasCellSpan;
960
+ }
961
+ this._map.length = totalRow;
989
962
  };
990
963
 
991
964
  /** @private
@@ -993,13 +966,13 @@ CellSelectionPlugin.prototype._cacheSectionMap = function () {
993
966
  * @return {number}
994
967
  */
995
968
  CellSelectionPlugin.prototype._getCumulativeIndex = function (obj) {
996
- var section = obj["section"];
997
- if (!section) {
998
- section = this._hosts[0].getSection("content");
999
- } else if (typeof section === "string" || typeof section === "number") {
1000
- section = this._hosts[0].getSection(section);
1001
- }
1002
- return section.getRowOffset() + obj["rowIndex"];
969
+ let section = obj["section"];
970
+ if(!section) {
971
+ section = this._hosts[0].getSection("content");
972
+ } else if(typeof section === "string" || typeof section === "number") {
973
+ section = this._hosts[0].getSection(section);
974
+ }
975
+ return section.getRowOffset() + obj["rowIndex"];
1003
976
  };
1004
977
 
1005
978
  /** Add new selection rectangle area.
@@ -1007,40 +980,43 @@ CellSelectionPlugin.prototype._getCumulativeIndex = function (obj) {
1007
980
  * @return {!Object} Rectangle
1008
981
  */
1009
982
  CellSelectionPlugin.prototype._newSelectionRect = function () {
1010
- if (!this._anchor || !this._curMouse) {
1011
- return this._curRect;
1012
- }
1013
- var rect = {};
1014
- if (this._mode !== "row") {
1015
- if (this._anchor["colIndex"] <= this._curMouse["colIndex"]) {
1016
- rect.left = this._anchor["colIndex"];
1017
- rect.right = this._curMouse["colIndex"] + 1;
1018
- } else {
1019
- rect.left = this._curMouse["colIndex"];
1020
- rect.right = this._anchor["colIndex"] + 1;
1021
- }
1022
- } else {
1023
- rect.left = 0;
1024
- rect.right = this._hosts[0].getColumnCount();
1025
- }
1026
-
1027
- // Required
1028
- var cIndex = this._getCumulativeIndex(this._curMouse);
1029
- var aIndex = this._getCumulativeIndex(this._anchor);
1030
- if (this._mode !== "column") {
1031
- if (aIndex <= cIndex) {
1032
- rect.top = aIndex;
1033
- rect.bottom = cIndex + 1;
1034
- } else {
1035
- rect.top = cIndex;
1036
- rect.bottom = aIndex + 1;
1037
- }
1038
- } else {
1039
- rect.top = 0;
1040
- rect.bottom = this._hosts[0].getRowCount();
1041
- }
1042
- this._scanCellSpans(rect);
1043
- return rect;
983
+ if(!this._anchor || !this._curMouse) {
984
+ return this._curRect;
985
+ }
986
+
987
+ let rect = {};
988
+ if(this._mode !== "row") {
989
+ if(this._anchor["colIndex"] <= this._curMouse["colIndex"]) {
990
+ rect.left = this._anchor["colIndex"];
991
+ rect.right = this._curMouse["colIndex"] + 1;
992
+ } else {
993
+ rect.left = this._curMouse["colIndex"];
994
+ rect.right = this._anchor["colIndex"] + 1;
995
+ }
996
+ } else {
997
+ rect.left = 0;
998
+ rect.right = this._hosts[0].getColumnCount();
999
+ }
1000
+
1001
+ // Required
1002
+ let cIndex = this._getCumulativeIndex(this._curMouse);
1003
+ let aIndex = this._getCumulativeIndex(this._anchor);
1004
+
1005
+ if(this._mode !== "column") {
1006
+ if(aIndex <= cIndex) {
1007
+ rect.top = aIndex;
1008
+ rect.bottom = cIndex + 1;
1009
+ } else {
1010
+ rect.top = cIndex;
1011
+ rect.bottom = aIndex + 1;
1012
+ }
1013
+ } else {
1014
+ rect.top = 0;
1015
+ rect.bottom = this._hosts[0].getRowCount();
1016
+ }
1017
+
1018
+ this._scanCellSpans(rect);
1019
+ return rect;
1044
1020
  };
1045
1021
 
1046
1022
  /** we will expand rect by cell span (cell merged)
@@ -1048,33 +1024,31 @@ CellSelectionPlugin.prototype._newSelectionRect = function () {
1048
1024
  * @param {Object} rect
1049
1025
  */
1050
1026
  CellSelectionPlugin.prototype._scanCellSpans = function (rect) {
1051
- if (!this._hasCellSpan) {
1052
- return;
1053
- }
1054
- var c = 0,
1055
- r = 0;
1056
- var tgtChanged = false;
1057
- do {
1058
- tgtChanged = false;
1059
- for (c = rect.left; c < rect.right; ++c) {
1060
- // Left to right
1061
- tgtChanged |= this._expandRect(c, rect.top, rect);
1062
- }
1063
- c = rect.right - 1;
1064
- for (r = rect.top + 1; r < rect.bottom; ++r) {
1065
- // Top to bottom
1066
- tgtChanged |= this._expandRect(c, r, rect);
1067
- }
1068
- r = rect.bottom - 1;
1069
- for (c = rect.right - 1; --c >= rect.left;) {
1070
- // Bottom right to bottom left
1071
- tgtChanged |= this._expandRect(c, r, rect);
1072
- }
1073
- for (r = rect.bottom - 1; --r >= rect.top;) {
1074
- // Bottom left to top
1075
- tgtChanged |= this._expandRect(rect.left, r, rect);
1076
- }
1077
- } while (tgtChanged);
1027
+ if(!this._hasCellSpan) { return; }
1028
+ let c = 0, r = 0;
1029
+ let tgtChanged = false;
1030
+
1031
+ do {
1032
+ tgtChanged = false;
1033
+ for(c = rect.left; c < rect.right; ++c) {
1034
+ // Left to right
1035
+ tgtChanged |= this._expandRect(c, rect.top, rect);
1036
+ }
1037
+ c = rect.right - 1;
1038
+ for(r = rect.top + 1; r < rect.bottom; ++r) {
1039
+ // Top to bottom
1040
+ tgtChanged |= this._expandRect(c, r, rect);
1041
+ }
1042
+ r = rect.bottom - 1;
1043
+ for(c = rect.right - 1; --c >= rect.left; ) {
1044
+ // Bottom right to bottom left
1045
+ tgtChanged |= this._expandRect(c, r, rect);
1046
+ }
1047
+ for(r = rect.bottom - 1; --r >= rect.top; ) {
1048
+ // Bottom left to top
1049
+ tgtChanged |= this._expandRect(rect.left, r, rect);
1050
+ }
1051
+ } while (tgtChanged);
1078
1052
  };
1079
1053
 
1080
1054
  /** @private
@@ -1084,56 +1058,55 @@ CellSelectionPlugin.prototype._scanCellSpans = function (rect) {
1084
1058
  * @return {boolean}
1085
1059
  */
1086
1060
  CellSelectionPlugin.prototype._expandRect = function (colIndex, rowIndex, rect) {
1087
- var obj = this._map[rowIndex];
1088
- if (!obj.hasCellSpan) {
1089
- return false;
1090
- }
1091
- if (this._unselectables[obj.type] === true) {
1092
- return false;
1093
- }
1094
- var changed = false;
1095
- var newIndex = 0;
1096
- var colSpan = obj.section.getCellColSpan(colIndex, obj.rowIndex);
1097
- if (colSpan > 1) {
1098
- newIndex = colIndex + colSpan;
1099
- if (newIndex > rect.right) {
1100
- rect.right = newIndex; // Exclusive
1101
- changed = true;
1102
- }
1103
- } else if (colSpan < 0) {
1104
- newIndex = colIndex + colSpan;
1105
- if (newIndex < rect.left) {
1106
- rect.left = newIndex;
1107
- changed = true;
1108
- }
1109
- colSpan = obj.section.getCellColSpan(newIndex, obj.rowIndex);
1110
- newIndex = newIndex + colSpan;
1111
- if (newIndex > rect.right) {
1112
- rect.right = newIndex; // Exclusive
1113
- changed = true;
1114
- }
1115
- }
1116
- var rowSpan = obj.section.getCellRowSpan(colIndex, obj.rowIndex);
1117
- if (rowSpan > 1) {
1118
- newIndex = obj.section.getRowOffset() + obj.rowIndex + rowSpan;
1119
- if (newIndex > rect.bottom) {
1120
- rect.bottom = newIndex; // Exclusive
1121
- changed = true;
1122
- }
1123
- } else if (rowSpan < 0) {
1124
- newIndex = obj.section.getRowOffset() + obj.rowIndex + rowSpan;
1125
- if (newIndex < rect.top) {
1126
- rect.top = newIndex;
1127
- changed = true;
1128
- }
1129
- rowSpan = obj.section.getCellRowSpan(colIndex, newIndex);
1130
- newIndex = newIndex + rowSpan;
1131
- if (newIndex > rect.bottom) {
1132
- rect.bottom = newIndex; // Exclusive
1133
- changed = true;
1134
- }
1135
- }
1136
- return changed;
1061
+ let obj = this._map[rowIndex];
1062
+ if(!obj.hasCellSpan) { return false; }
1063
+ if(this._unselectables[obj.type] === true) { return false; }
1064
+
1065
+ let changed = false;
1066
+ let newIndex = 0;
1067
+ let colSpan = obj.section.getCellColSpan(colIndex, obj.rowIndex);
1068
+ if(colSpan > 1) {
1069
+ newIndex = colIndex + colSpan;
1070
+ if(newIndex > rect.right) {
1071
+ rect.right = newIndex; // Exclusive
1072
+ changed = true;
1073
+ }
1074
+ } else if(colSpan < 0) {
1075
+ newIndex = colIndex + colSpan;
1076
+ if(newIndex < rect.left) {
1077
+ rect.left = newIndex;
1078
+ changed = true;
1079
+ }
1080
+ colSpan = obj.section.getCellColSpan(newIndex, obj.rowIndex);
1081
+ newIndex = newIndex + colSpan;
1082
+ if(newIndex > rect.right) {
1083
+ rect.right = newIndex; // Exclusive
1084
+ changed = true;
1085
+ }
1086
+ }
1087
+
1088
+ let rowSpan = obj.section.getCellRowSpan(colIndex, obj.rowIndex);
1089
+ if(rowSpan > 1) {
1090
+ newIndex = obj.section.getRowOffset() + obj.rowIndex + rowSpan;
1091
+ if(newIndex > rect.bottom) {
1092
+ rect.bottom = newIndex; // Exclusive
1093
+ changed = true;
1094
+ }
1095
+ } else if(rowSpan < 0) {
1096
+ newIndex = obj.section.getRowOffset() + obj.rowIndex + rowSpan;
1097
+ if(newIndex < rect.top) {
1098
+ rect.top = newIndex;
1099
+ changed = true;
1100
+ }
1101
+ rowSpan = obj.section.getCellRowSpan(colIndex, newIndex);
1102
+ newIndex = newIndex + rowSpan;
1103
+ if(newIndex > rect.bottom) {
1104
+ rect.bottom = newIndex; // Exclusive
1105
+ changed = true;
1106
+ }
1107
+ }
1108
+
1109
+ return changed;
1137
1110
  };
1138
1111
 
1139
1112
  /** Update all row & column that mouse draged over.
@@ -1141,46 +1114,49 @@ CellSelectionPlugin.prototype._expandRect = function (colIndex, rowIndex, rect)
1141
1114
  * @param {Object} tgtRect
1142
1115
  */
1143
1116
  CellSelectionPlugin.prototype._updateSelection = function (tgtRect) {
1144
- // Expand/Shrink Left
1145
- this._updateColumnSelection(tgtRect.left, this._curRect.left);
1146
- this._curRect.left = tgtRect.left;
1147
-
1148
- // Expand/Shrink Right
1149
- this._updateColumnSelection(this._curRect.right, tgtRect.right);
1150
- this._curRect.right = tgtRect.right;
1151
-
1152
- // Expand/Shrink Top
1153
- this._updateRowSelection(tgtRect.top, this._curRect.top);
1154
- this._curRect.top = tgtRect.top;
1155
-
1156
- // Expand/Shrink Bottom
1157
- this._updateRowSelection(this._curRect.bottom, tgtRect.bottom);
1158
- this._curRect.bottom = tgtRect.bottom;
1159
- var activeGrid = this._getActiveGrid();
1160
- if (activeGrid) {
1161
- var x = this._curRect.left;
1162
- var y = this._curRect.top;
1163
- var mapInfo = this._map[y];
1164
- var w = 0;
1165
- var h = 0;
1166
- if (mapInfo) {
1167
- w = this._curRect.right - x;
1168
- h = this._curRect.bottom - y;
1169
- y -= mapInfo.rowOffset;
1170
- var contentType = mapInfo.type;
1171
- if (contentType === "content") {
1172
- var contentSect = activeGrid.getSection("content");
1173
- if (contentSect) {
1174
- contentSect.setCellBounds(x, y, w, h);
1175
- }
1176
- } else {
1177
- var titleSect = activeGrid.getSection("title");
1178
- if (titleSect) {
1179
- titleSect.setCellBounds(x, y, w, h);
1180
- }
1181
- }
1182
- }
1183
- }
1117
+ // Expand/Shrink Left
1118
+ this._updateColumnSelection(tgtRect.left, this._curRect.left);
1119
+ this._curRect.left = tgtRect.left;
1120
+
1121
+ // Expand/Shrink Right
1122
+ this._updateColumnSelection(this._curRect.right, tgtRect.right);
1123
+ this._curRect.right = tgtRect.right;
1124
+
1125
+ // Expand/Shrink Top
1126
+ this._updateRowSelection(tgtRect.top, this._curRect.top);
1127
+ this._curRect.top = tgtRect.top;
1128
+
1129
+ // Expand/Shrink Bottom
1130
+ this._updateRowSelection(this._curRect.bottom, tgtRect.bottom);
1131
+ this._curRect.bottom = tgtRect.bottom;
1132
+
1133
+ let activeGrid = this._getActiveGrid();
1134
+ if(activeGrid) {
1135
+ let x = this._curRect.left;
1136
+ let y = this._curRect.top;
1137
+
1138
+ let mapInfo = this._map[y];
1139
+
1140
+ let w = 0;
1141
+ let h = 0;
1142
+ if(mapInfo) {
1143
+ w = this._curRect.right - x;
1144
+ h = this._curRect.bottom - y;
1145
+ y -= mapInfo.rowOffset;
1146
+ let contentType = mapInfo.type;
1147
+ if(contentType === "content") {
1148
+ let contentSect = activeGrid.getSection("content");
1149
+ if(contentSect) {
1150
+ contentSect.setCellBounds(x, y, w, h);
1151
+ }
1152
+ } else {
1153
+ let titleSect = activeGrid.getSection("title");
1154
+ if(titleSect) {
1155
+ titleSect.setCellBounds(x, y, w, h);
1156
+ }
1157
+ }
1158
+ }
1159
+ }
1184
1160
  };
1185
1161
 
1186
1162
  /** Update all column that mouse draged over.
@@ -1189,24 +1165,23 @@ CellSelectionPlugin.prototype._updateSelection = function (tgtRect) {
1189
1165
  * @param {number} to Exclusive destination index
1190
1166
  */
1191
1167
  CellSelectionPlugin.prototype._updateColumnSelection = function (from, to) {
1192
- if (from === to) {
1193
- return;
1194
- }
1195
- var c, r;
1196
- if (from < to) {
1197
- for (r = this._curRect.top; r < this._curRect.bottom; ++r) {
1198
- for (c = from; c < to; ++c) {
1199
- this._selectAsPosition(r, c, true);
1200
- }
1201
- }
1202
- } else {
1203
- // from > to
1204
- for (r = this._curRect.top; r < this._curRect.bottom; ++r) {
1205
- for (c = from; --c >= to;) {
1206
- this._selectAsPosition(r, c, false);
1207
- }
1208
- }
1209
- }
1168
+ if(from === to) { return; }
1169
+
1170
+ let c, r;
1171
+
1172
+ if(from < to) {
1173
+ for(r = this._curRect.top; r < this._curRect.bottom; ++r) {
1174
+ for(c = from; c < to; ++c) {
1175
+ this._selectAsPosition(r, c, true);
1176
+ }
1177
+ }
1178
+ } else { // from > to
1179
+ for(r = this._curRect.top; r < this._curRect.bottom; ++r) {
1180
+ for(c = from; --c >= to;) {
1181
+ this._selectAsPosition(r, c, false);
1182
+ }
1183
+ }
1184
+ }
1210
1185
  };
1211
1186
 
1212
1187
  /** Update all row that mouse draged over.
@@ -1215,24 +1190,23 @@ CellSelectionPlugin.prototype._updateColumnSelection = function (from, to) {
1215
1190
  * @param {number} to Exclusive destination index
1216
1191
  */
1217
1192
  CellSelectionPlugin.prototype._updateRowSelection = function (from, to) {
1218
- if (from === to) {
1219
- return;
1220
- }
1221
- var c, r;
1222
- if (from < to) {
1223
- for (r = from; r < to; ++r) {
1224
- for (c = this._curRect.left; c < this._curRect.right; ++c) {
1225
- this._selectAsPosition(r, c, true);
1226
- }
1227
- }
1228
- } else {
1229
- // from > to
1230
- for (r = from; --r >= to;) {
1231
- for (c = this._curRect.left; c < this._curRect.right; ++c) {
1232
- this._selectAsPosition(r, c, false);
1233
- }
1234
- }
1235
- }
1193
+ if(from === to) { return; }
1194
+
1195
+ let c, r;
1196
+
1197
+ if(from < to) {
1198
+ for(r = from; r < to; ++r) {
1199
+ for(c = this._curRect.left; c < this._curRect.right; ++c) {
1200
+ this._selectAsPosition(r, c, true);
1201
+ }
1202
+ }
1203
+ } else { // from > to
1204
+ for(r = from; --r >= to; ) {
1205
+ for(c = this._curRect.left; c < this._curRect.right; ++c) {
1206
+ this._selectAsPosition(r, c, false);
1207
+ }
1208
+ }
1209
+ }
1236
1210
  };
1237
1211
 
1238
1212
  /** @private
@@ -1241,10 +1215,10 @@ CellSelectionPlugin.prototype._updateRowSelection = function (from, to) {
1241
1215
  * @param {boolean} isSelect
1242
1216
  */
1243
1217
  CellSelectionPlugin.prototype._selectAsPosition = function (rowIndex, colIndex, isSelect) {
1244
- var mapInfo = this._map[rowIndex];
1245
- if (mapInfo && !this._unselectables[mapInfo.type]) {
1246
- mapInfo.section.selectCell(colIndex, mapInfo.rowIndex, isSelect);
1247
- }
1218
+ let mapInfo = this._map[rowIndex];
1219
+ if(mapInfo && !this._unselectables[mapInfo.type]) {
1220
+ mapInfo.section.selectCell(colIndex, mapInfo.rowIndex, isSelect);
1221
+ }
1248
1222
  };
1249
1223
 
1250
1224
  /** Check mouse is draging over cell that already selected.
@@ -1254,13 +1228,14 @@ CellSelectionPlugin.prototype._selectAsPosition = function (rowIndex, colIndex,
1254
1228
  * @return {boolean}
1255
1229
  */
1256
1230
  CellSelectionPlugin.prototype._isTheSamePosition = function (cellA, cellB) {
1257
- if (cellA === null && cellB === null) {
1258
- return true;
1259
- }
1260
- if (cellA !== null && cellB !== null) {
1261
- return cellA["rowIndex"] === cellB["rowIndex"] && cellA["colIndex"] === cellB["colIndex"] && cellA["sectionIndex"] === cellB["sectionIndex"];
1262
- }
1263
- return false;
1231
+ if(cellA === null && cellB === null) { return true; }
1232
+
1233
+ if(cellA !== null && cellB !== null) {
1234
+ return (cellA["rowIndex"] === cellB["rowIndex"] &&
1235
+ cellA["colIndex"] === cellB["colIndex"] &&
1236
+ cellA["sectionIndex"] === cellB["sectionIndex"]);
1237
+ }
1238
+ return false;
1264
1239
  };
1265
1240
 
1266
1241
  /** Grid has hidden input it's a dummy element <br>
@@ -1269,10 +1244,11 @@ CellSelectionPlugin.prototype._isTheSamePosition = function (cellA, cellB) {
1269
1244
  * @return {Element}
1270
1245
  */
1271
1246
  CellSelectionPlugin.prototype._getGridHiddenInput = function () {
1272
- if (this._hosts[0]) {
1273
- return this._hosts[0].getHiddenInput();
1274
- }
1275
- return null;
1247
+ if(this._hosts[0]) {
1248
+ return this._hosts[0].getHiddenInput();
1249
+ }
1250
+
1251
+ return null;
1276
1252
  };
1277
1253
 
1278
1254
  /** Get text from selected cells. If no selection, return empty string. <br>
@@ -1283,69 +1259,72 @@ CellSelectionPlugin.prototype._getGridHiddenInput = function () {
1283
1259
  * @return {string}
1284
1260
  */
1285
1261
  CellSelectionPlugin.prototype.getSelectedText = function () {
1286
- var activeGrid = this._getActiveGrid();
1287
- if (!activeGrid || !this.getGridApi() || this.getSelectionCount() <= 0) return "";
1288
- var ret_txt = "";
1289
- var dv = activeGrid.getDataSource();
1290
- for (var r = this._curRect.top; r < this._curRect.bottom; ++r) {
1291
- var rowMapping = this._map[r];
1292
- if (r !== this._curRect.top) {
1293
- ret_txt += "\n";
1294
- }
1295
- var rowData = null;
1296
- if (this._unselectables[rowMapping.type] === true) {
1297
- continue;
1298
- } else if (rowMapping.type === 'content') {
1299
- rowData = this._getRow(dv, rowMapping.rowIndex);
1300
- }
1301
- for (var c = this._curRect.left; c < this._curRect.right; ++c) {
1302
- if (c !== this._curRect.left) {
1303
- ret_txt += "\t";
1304
- }
1305
- if (rowMapping.type === 'content') {
1306
- // for content section we will get text from dataSource to support row virtualization
1307
- if (rowData) {
1308
- var cField = this._getField(c);
1309
- ret_txt += prepareTSVContent(rowData[cField]);
1310
- }
1311
- } else {
1312
- // other section not has row virtualization
1313
- // so we can get text from cell directly
1314
- var txt = rowMapping.section.getCell(c, rowMapping.rowIndex).getTextContent();
1315
- ret_txt += prepareTSVContent(txt);
1316
- }
1317
- }
1318
- }
1319
- return ret_txt;
1262
+ let activeGrid = this._getActiveGrid();
1263
+ if(!activeGrid || !this.getGridApi() || this.getSelectionCount() <= 0) return "";
1264
+
1265
+ let ret_txt = "";
1266
+ let dv = activeGrid.getDataSource();
1267
+ for(let r = this._curRect.top; r < this._curRect.bottom; ++r) {
1268
+ let rowMapping = this._map[r];
1269
+
1270
+ if(r !== this._curRect.top) {
1271
+ ret_txt += "\n";
1272
+ }
1273
+
1274
+ let rowData = null;
1275
+ if(this._unselectables[rowMapping.type] === true) { continue; }
1276
+ else if(rowMapping.type === "content") {
1277
+ rowData = this._getRow(dv, rowMapping.rowIndex);
1278
+ }
1279
+ for(let c = this._curRect.left; c < this._curRect.right; ++c) {
1280
+ if(c !== this._curRect.left) {
1281
+ ret_txt += "\t";
1282
+ }
1283
+
1284
+ if(rowMapping.type === "content") {
1285
+ // for content section we will get text from dataSource to support row virtualization
1286
+ if(rowData) {
1287
+ let cField = this._getField(c);
1288
+ ret_txt += prepareTSVContent(rowData[cField]);
1289
+ }
1290
+ } else {
1291
+ // other section not has row virtualization
1292
+ // so we can get text from cell directly
1293
+ let txt = rowMapping.section.getCell(c, rowMapping.rowIndex).getTextContent();
1294
+ ret_txt += prepareTSVContent(txt);
1295
+ }
1296
+ }
1297
+ }
1298
+ return ret_txt;
1320
1299
  };
1321
1300
 
1322
1301
  /** Select all cell.
1323
1302
  * @public
1324
1303
  */
1325
1304
  CellSelectionPlugin.prototype.selectAll = function () {
1326
- var activeGrid = this._getActiveGrid();
1327
- var selectAllRectangle = {
1328
- left: 0,
1329
- right: activeGrid.getColumnCount(),
1330
- top: 0,
1331
- bottom: activeGrid.getRowCount()
1332
- };
1333
-
1334
- // Un-select all selected
1335
- this.deselectAll();
1336
-
1337
- // Need to keep the active-grid
1338
- this._anchor = {
1339
- grid: activeGrid
1340
- };
1341
-
1342
- // Need to be done first for getting cumulative row index
1343
- this._cacheSectionMap();
1344
-
1345
- // Make new rectangle selection & fire event
1346
- this._scanCellSpans(selectAllRectangle);
1347
- this._updateSelection(selectAllRectangle);
1348
- this._dispatch("selectionChanged", {});
1305
+ let activeGrid = this._getActiveGrid();
1306
+ let selectAllRectangle = {
1307
+ left: 0,
1308
+ right: activeGrid.getColumnCount(),
1309
+ top: 0,
1310
+ bottom: activeGrid.getRowCount()
1311
+ };
1312
+
1313
+ // Un-select all selected
1314
+ this.deselectAll();
1315
+
1316
+ // Need to keep the active-grid
1317
+ this._anchor = {
1318
+ grid: activeGrid
1319
+ };
1320
+
1321
+ // Need to be done first for getting cumulative row index
1322
+ this._cacheSectionMap();
1323
+
1324
+ // Make new rectangle selection & fire event
1325
+ this._scanCellSpans(selectAllRectangle);
1326
+ this._updateSelection(selectAllRectangle);
1327
+ this._dispatch("selectionChanged", {});
1349
1328
  };
1350
1329
 
1351
1330
  /** Deselect all selected cell.
@@ -1353,32 +1332,31 @@ CellSelectionPlugin.prototype.selectAll = function () {
1353
1332
  * @return {boolean} true if there is any change
1354
1333
  */
1355
1334
  CellSelectionPlugin.prototype.deselectAll = function () {
1356
- if (this.getSelectionCount() <= 0) {
1357
- return false;
1358
- }
1359
-
1360
- // clear selection from ui
1361
- var activeGrid = this._getActiveGrid();
1362
- if (activeGrid) {
1363
- var selectedCells = activeGrid.getElement().querySelectorAll("div.cell.selection"); // TODO: Move this logic to core grid
1364
- var c = selectedCells.length;
1365
- for (var i = 0; i < c; i++) {
1366
- selectedCells[i].classList.remove('selection');
1367
- }
1368
- var contentSect = activeGrid.getSection("content");
1369
- if (contentSect) {
1370
- contentSect.setCellBounds(0, 0, 0, 0);
1371
- }
1372
- var titleSect = activeGrid.getSection("title");
1373
- if (titleSect) {
1374
- titleSect.setCellBounds(0, 0, 0, 0);
1375
- }
1376
- }
1377
- this._lastSelection = this.getSelectionBounds();
1378
- this._anchor = null;
1379
- this._curRect.right = this._curRect.left;
1380
- this._curRect.bottom = this._curRect.top;
1381
- return true;
1335
+ if(this.getSelectionCount() <= 0) { return false; }
1336
+
1337
+ // clear selection from ui
1338
+ let activeGrid = this._getActiveGrid();
1339
+ if(activeGrid) {
1340
+ let selectedCells = activeGrid.getElement().querySelectorAll("div.cell.selection"); // TODO: Move this logic to core grid
1341
+ let c = selectedCells.length;
1342
+ for(let i = 0; i < c; i++) {
1343
+ selectedCells[i].classList.remove("selection");
1344
+ }
1345
+ let contentSect = activeGrid.getSection("content");
1346
+ if(contentSect) {
1347
+ contentSect.setCellBounds(0, 0, 0, 0);
1348
+ }
1349
+ let titleSect = activeGrid.getSection("title");
1350
+ if(titleSect) {
1351
+ titleSect.setCellBounds(0, 0, 0, 0);
1352
+ }
1353
+ }
1354
+
1355
+ this._lastSelection = this.getSelectionBounds();
1356
+ this._anchor = null;
1357
+ this._curRect.right = this._curRect.left;
1358
+ this._curRect.bottom = this._curRect.top;
1359
+ return true;
1382
1360
  };
1383
1361
 
1384
1362
  /** Return total number of selected cells
@@ -1386,9 +1364,9 @@ CellSelectionPlugin.prototype.deselectAll = function () {
1386
1364
  * @return {number}
1387
1365
  */
1388
1366
  CellSelectionPlugin.prototype.getSelectionCount = function () {
1389
- var width = this._curRect.right - this._curRect.left;
1390
- var height = this._curRect.bottom - this._curRect.top;
1391
- return width * height;
1367
+ let width = this._curRect.right - this._curRect.left;
1368
+ let height = this._curRect.bottom - this._curRect.top;
1369
+ return width * height;
1392
1370
  };
1393
1371
 
1394
1372
  /** Add left, top, right, bottom properties to the given object
@@ -1397,25 +1375,24 @@ CellSelectionPlugin.prototype.getSelectionCount = function () {
1397
1375
  * @return {Object}
1398
1376
  */
1399
1377
  CellSelectionPlugin.prototype.getSelectionBounds = function (opt_ret) {
1400
- if (this.getSelectionCount() <= 0) {
1401
- return null;
1402
- }
1403
- var obj = opt_ret != null ? opt_ret : {};
1404
- obj["left"] = this._curRect.left;
1405
- obj["right"] = this._curRect.right - 1; // Inclusive
1406
- obj["top"] = this._curRect.top;
1407
- obj["bottom"] = this._curRect.bottom - 1; // Inclusive
1408
-
1409
- if (this._map.length > 0 && obj["bottom"] < this._map.length) {
1410
- var mapper = this._map[obj["top"]];
1411
- obj["startSection"] = mapper.sectionIndex;
1412
- obj["startSectionRow"] = mapper.rowIndex;
1413
- mapper = this._map[obj["bottom"]];
1414
- obj["endSection"] = mapper.sectionIndex; // Inclusive
1415
- obj["endSectionRow"] = mapper.rowIndex; // Inclusive
1416
- }
1417
-
1418
- return obj;
1378
+ if(this.getSelectionCount() <= 0) { return null; }
1379
+
1380
+ let obj = (opt_ret != null) ? opt_ret : {};
1381
+ obj["left"] = this._curRect.left;
1382
+ obj["right"] = this._curRect.right - 1; // Inclusive
1383
+ obj["top"] = this._curRect.top;
1384
+ obj["bottom"] = this._curRect.bottom - 1; // Inclusive
1385
+
1386
+ if(this._map.length > 0 && obj["bottom"] < this._map.length) {
1387
+ let mapper = this._map[obj["top"]];
1388
+ obj["startSection"] = mapper.sectionIndex;
1389
+ obj["startSectionRow"] = mapper.rowIndex;
1390
+
1391
+ mapper = this._map[obj["bottom"]];
1392
+ obj["endSection"] = mapper.sectionIndex; // Inclusive
1393
+ obj["endSectionRow"] = mapper.rowIndex; // Inclusive
1394
+ }
1395
+ return obj;
1419
1396
  };
1420
1397
 
1421
1398
  /** Add left, top, right, bottom properties to the given object
@@ -1424,14 +1401,13 @@ CellSelectionPlugin.prototype.getSelectionBounds = function (opt_ret) {
1424
1401
  * @return {Object}
1425
1402
  */
1426
1403
  CellSelectionPlugin.prototype.getLastSelectionBounds = function (opt_ret) {
1427
- if (this._lastSelection === null) {
1428
- return null;
1429
- }
1430
- var obj = opt_ret != null ? opt_ret : {};
1431
- for (var key in this._lastSelection) {
1432
- obj[key] = this._lastSelection[key];
1433
- }
1434
- return obj;
1404
+ if(this._lastSelection === null) { return null; }
1405
+
1406
+ let obj = (opt_ret != null) ? opt_ret : {};
1407
+ for(let key in this._lastSelection) {
1408
+ obj[key] = this._lastSelection[key];
1409
+ }
1410
+ return obj;
1435
1411
  };
1436
1412
 
1437
1413
  /** Use to set which section can be selected,[ header, title, content ]
@@ -1439,21 +1415,22 @@ CellSelectionPlugin.prototype.getLastSelectionBounds = function (opt_ret) {
1439
1415
  * @param {(string|Array.<string>|null)=} types Use null to allow all sections to be select
1440
1416
  */
1441
1417
  CellSelectionPlugin.prototype.setSelectableSections = function (types) {
1442
- this._unselectables["content"] = true;
1443
- this._unselectables["header"] = true;
1444
- this._unselectables["title"] = true;
1445
-
1446
- // Set null or empty to allow all sections
1447
- if (!types) {
1448
- this._unselectables["content"] = false;
1449
- this._unselectables["header"] = false;
1450
- this._unselectables["title"] = false;
1451
- return;
1452
- }
1453
- var list = typeof types === "string" ? [types] : types;
1454
- for (var i = list.length; --i >= 0;) {
1455
- this._unselectables[list[i]] = false;
1456
- }
1418
+ this._unselectables["content"] = true;
1419
+ this._unselectables["header"] = true;
1420
+ this._unselectables["title"] = true;
1421
+
1422
+ // Set null or empty to allow all sections
1423
+ if(!types) {
1424
+ this._unselectables["content"] = false;
1425
+ this._unselectables["header"] = false;
1426
+ this._unselectables["title"] = false;
1427
+ return;
1428
+ }
1429
+
1430
+ let list = (typeof types === "string") ? [types] : types;
1431
+ for(let i = list.length; --i >= 0; ) {
1432
+ this._unselectables[list[i]] = false;
1433
+ }
1457
1434
  };
1458
1435
 
1459
1436
  /** Use to select single cell and deselect previous selected cells.
@@ -1463,21 +1440,23 @@ CellSelectionPlugin.prototype.setSelectableSections = function (types) {
1463
1440
  * extension.selectSingleCell({colIndex: 1, rowIndex: 0});
1464
1441
  */
1465
1442
  CellSelectionPlugin.prototype.selectSingleCell = function (anchor) {
1466
- this.deselectAll();
1467
- if (!anchor) {
1468
- return;
1469
- }
1470
- this._anchor = anchor;
1471
- this._curMouse = anchor;
1472
-
1473
- // Need to be done first for getting cumulative row index
1474
- this._cacheSectionMap();
1475
- this._curRect.left = this._anchor["colIndex"];
1476
- this._curRect.top = this._getCumulativeIndex(this._anchor);
1477
- this._curRect.right = this._curRect.left;
1478
- this._curRect.bottom = this._curRect.top;
1479
- var tgtRect = this._newSelectionRect();
1480
- this._updateSelection(tgtRect);
1443
+ this.deselectAll();
1444
+
1445
+ if(!anchor) { return; }
1446
+
1447
+ this._anchor = anchor;
1448
+ this._curMouse = anchor;
1449
+
1450
+ // Need to be done first for getting cumulative row index
1451
+ this._cacheSectionMap();
1452
+
1453
+ this._curRect.left = this._anchor["colIndex"];
1454
+ this._curRect.top = this._getCumulativeIndex(this._anchor);
1455
+ this._curRect.right = this._curRect.left;
1456
+ this._curRect.bottom = this._curRect.top;
1457
+
1458
+ let tgtRect = this._newSelectionRect();
1459
+ this._updateSelection(tgtRect);
1481
1460
  };
1482
1461
 
1483
1462
  /** Use to select multiple cells, can be selected by rectangle area.
@@ -1489,24 +1468,26 @@ CellSelectionPlugin.prototype.selectSingleCell = function (anchor) {
1489
1468
  * });
1490
1469
  */
1491
1470
  CellSelectionPlugin.prototype.selectCells = function (rect) {
1492
- this.deselectAll();
1493
- if (!rect) {
1494
- return;
1495
- }
1496
- this._anchor = rect;
1497
- this._curMouse = {
1498
- "rowIndex": rect["rowIndex"] + (rect["height"] - 1),
1499
- "colIndex": rect["colIndex"] + (rect["width"] - 1)
1500
- };
1501
-
1502
- // Need to be done first for getting cumulative row index
1503
- this._cacheSectionMap();
1504
- this._curRect.left = this._anchor["colIndex"];
1505
- this._curRect.top = this._getCumulativeIndex(this._anchor);
1506
- this._curRect.right = this._curRect.left;
1507
- this._curRect.bottom = this._curRect.top;
1508
- var tgtRect = this._newSelectionRect();
1509
- this._updateSelection(tgtRect);
1471
+ this.deselectAll();
1472
+
1473
+ if(!rect) { return; }
1474
+
1475
+ this._anchor = rect;
1476
+ this._curMouse = {
1477
+ "rowIndex": rect["rowIndex"] + (rect["height"] - 1),
1478
+ "colIndex": rect["colIndex"] + (rect["width"] - 1)
1479
+ };
1480
+
1481
+ // Need to be done first for getting cumulative row index
1482
+ this._cacheSectionMap();
1483
+
1484
+ this._curRect.left = this._anchor["colIndex"];
1485
+ this._curRect.top = this._getCumulativeIndex(this._anchor);
1486
+ this._curRect.right = this._curRect.left;
1487
+ this._curRect.bottom = this._curRect.top;
1488
+
1489
+ let tgtRect = this._newSelectionRect();
1490
+ this._updateSelection(tgtRect);
1510
1491
  };
1511
1492
 
1512
1493
  /** Select next cell from the current selection anchor.
@@ -1514,76 +1495,64 @@ CellSelectionPlugin.prototype.selectCells = function (rect) {
1514
1495
  * @return {boolean} Return true if the next cell is selected, otherwise false
1515
1496
  */
1516
1497
  CellSelectionPlugin.prototype.selectNextCell = function () {
1517
- var newAnchor;
1518
- if (this._anchor) {
1519
- // TODO: Handle looping
1520
- var activeGrid = this._getActiveGrid();
1521
- if (this._mode == "row") {
1522
- newAnchor = activeGrid.getCellInfo({
1523
- "colIndex": 0,
1524
- "rowIndex": this._anchor["rowIndex"] + 1
1525
- });
1526
- } else if (this._mode == "column") {
1527
- newAnchor = activeGrid.getCellInfo({
1528
- "colIndex": this._anchor["colIndex"] + 1,
1529
- "rowIndex": 0
1530
- });
1531
- } else {
1532
- newAnchor = activeGrid.getNextCell(this._anchor);
1533
- if (newAnchor && !newAnchor.cell) {
1534
- newAnchor = null; // Last cell in the last row has been reached
1535
- }
1536
- }
1537
-
1538
- // Need to store active-grid
1539
- if (newAnchor) {
1540
- newAnchor.grid = activeGrid;
1541
- }
1542
- this.selectSingleCell(newAnchor);
1543
- }
1544
- return newAnchor ? true : false;
1498
+ let newAnchor;
1499
+ if(this._anchor) { // TODO: Handle looping
1500
+ let activeGrid = this._getActiveGrid();
1501
+ if(this._mode == "row") {
1502
+ newAnchor = activeGrid.getCellInfo({"colIndex": 0, "rowIndex": this._anchor["rowIndex"] + 1});
1503
+ } else if(this._mode == "column") {
1504
+ newAnchor = activeGrid.getCellInfo({"colIndex": this._anchor["colIndex"] + 1, "rowIndex": 0});
1505
+ } else {
1506
+ newAnchor = activeGrid.getNextCell(this._anchor);
1507
+ if(newAnchor && !newAnchor.cell) {
1508
+ newAnchor = null; // Last cell in the last row has been reached
1509
+ }
1510
+ }
1511
+
1512
+ // Need to store active-grid
1513
+ if(newAnchor) {
1514
+ newAnchor.grid = activeGrid;
1515
+ }
1516
+
1517
+ this.selectSingleCell(newAnchor);
1518
+ }
1519
+ return newAnchor ? true : false;
1545
1520
  };
1546
1521
  /** Select previous cell from the current selection anchor.
1547
1522
  * @public
1548
1523
  * @return {boolean} Return true if the next cell is selected, otherwise false
1549
1524
  */
1550
1525
  CellSelectionPlugin.prototype.selectPrevCell = function () {
1551
- var newAnchor;
1552
- if (this._anchor) {
1553
- // TODO: Handle looping
1554
- var activeGrid = this._getActiveGrid();
1555
- if (this._mode == "row") {
1556
- newAnchor = activeGrid.getCellInfo({
1557
- "colIndex": 0,
1558
- "rowIndex": this._anchor["rowIndex"] - 1
1559
- });
1560
- } else if (this._mode == "column") {
1561
- newAnchor = activeGrid.getCellInfo({
1562
- "colIndex": this._anchor["colIndex"] - 1,
1563
- "rowIndex": 0
1564
- });
1565
- } else {
1566
- newAnchor = activeGrid.getPrevCell(this._anchor);
1567
- if (newAnchor && !newAnchor.cell) {
1568
- newAnchor = null; // The first cell in the first row has been reached
1569
- }
1570
- }
1571
-
1572
- // Need to store active-grid
1573
- if (newAnchor) {
1574
- newAnchor.grid = activeGrid;
1575
- }
1576
- this.selectSingleCell(newAnchor);
1577
- }
1578
- return newAnchor ? true : false;
1526
+ let newAnchor;
1527
+ if(this._anchor) { // TODO: Handle looping
1528
+ let activeGrid = this._getActiveGrid();
1529
+ if(this._mode == "row") {
1530
+ newAnchor = activeGrid.getCellInfo({"colIndex": 0, "rowIndex": this._anchor["rowIndex"] - 1});
1531
+ } else if(this._mode == "column") {
1532
+ newAnchor = activeGrid.getCellInfo({"colIndex": this._anchor["colIndex"] - 1, "rowIndex": 0});
1533
+ } else {
1534
+ newAnchor = activeGrid.getPrevCell(this._anchor);
1535
+ if(newAnchor && !newAnchor.cell) {
1536
+ newAnchor = null; // The first cell in the first row has been reached
1537
+ }
1538
+ }
1539
+
1540
+ // Need to store active-grid
1541
+ if(newAnchor) {
1542
+ newAnchor.grid = activeGrid;
1543
+ }
1544
+
1545
+ this.selectSingleCell(newAnchor);
1546
+ }
1547
+ return newAnchor ? true : false;
1579
1548
  };
1580
1549
  /** Get information about current selection anchor
1581
1550
  * @public
1582
1551
  * @return {Object} MouseInfo
1583
1552
  */
1584
1553
  CellSelectionPlugin.prototype.getAnchorInfo = function () {
1585
- var activeGrid = this._getActiveGrid();
1586
- return activeGrid.getCellInfo(this._anchor);
1554
+ let activeGrid = this._getActiveGrid();
1555
+ return activeGrid.getCellInfo(this._anchor);
1587
1556
  };
1588
1557
 
1589
1558
  /** Use to get selected cells.
@@ -1591,17 +1560,21 @@ CellSelectionPlugin.prototype.getAnchorInfo = function () {
1591
1560
  * @return {Array.<Array>} 2D array of cells
1592
1561
  */
1593
1562
  CellSelectionPlugin.prototype.getSelectedCells = function () {
1594
- var selectedCells = [];
1595
- for (var r = this._curRect.top; r < this._curRect.bottom; ++r) {
1596
- var obj = this._map[r];
1597
- var cells = [];
1598
- for (var c = this._curRect.left; c < this._curRect.right; ++c) {
1599
- var cell = obj.section.getCell(c, obj.rowIndex);
1600
- cells.push(cell);
1601
- }
1602
- selectedCells.push(cells);
1603
- }
1604
- return selectedCells;
1563
+ let selectedCells = [];
1564
+
1565
+ for(let r = this._curRect.top; r < this._curRect.bottom; ++r) {
1566
+ let obj = this._map[r];
1567
+ let cells = [];
1568
+
1569
+ for(let c = this._curRect.left; c < this._curRect.right; ++c) {
1570
+ let cell = obj.section.getCell(c, obj.rowIndex);
1571
+ cells.push(cell);
1572
+ }
1573
+
1574
+ selectedCells.push(cells);
1575
+ }
1576
+
1577
+ return selectedCells;
1605
1578
  };
1606
1579
 
1607
1580
  /** Disable selection
@@ -1609,7 +1582,7 @@ CellSelectionPlugin.prototype.getSelectedCells = function () {
1609
1582
  * @param {boolean=} opt_disable
1610
1583
  */
1611
1584
  CellSelectionPlugin.prototype.disableSelection = function (opt_disable) {
1612
- this._disabled = opt_disable !== false;
1585
+ this._disabled = (opt_disable !== false);
1613
1586
  };
1614
1587
 
1615
1588
  /** Use to set Auto Deselecting when blur.
@@ -1617,7 +1590,7 @@ CellSelectionPlugin.prototype.disableSelection = function (opt_disable) {
1617
1590
  * @param {boolean} bool
1618
1591
  */
1619
1592
  CellSelectionPlugin.prototype.setAutoDeselectingOnBlur = function (bool) {
1620
- this._autoDeselecting = bool;
1593
+ this._autoDeselecting = bool;
1621
1594
  };
1622
1595
 
1623
1596
  /** Use to get state Auto Deselecting.
@@ -1625,7 +1598,10 @@ CellSelectionPlugin.prototype.setAutoDeselectingOnBlur = function (bool) {
1625
1598
  * @return {boolean}
1626
1599
  */
1627
1600
  CellSelectionPlugin.prototype.getAutoDeselectingOnBlur = function () {
1628
- return this._autoDeselecting;
1601
+ return this._autoDeselecting;
1629
1602
  };
1603
+
1604
+
1605
+
1630
1606
  export default CellSelectionPlugin;
1631
- export { CellSelectionPlugin, CellSelectionPlugin as CellSelection, CellSelectionPlugin as CellSelectionExtension };
1607
+ export { CellSelectionPlugin, CellSelectionPlugin as CellSelection, CellSelectionPlugin as CellSelectionExtension };