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