@refinitiv-ui/efx-grid 6.0.128 → 6.0.129
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/core/dist/core.js +220 -11
- package/lib/core/dist/core.min.js +1 -1
- package/lib/core/es6/data/DataCache.js +29 -0
- package/lib/core/es6/data/DataTable.d.ts +4 -0
- package/lib/core/es6/data/DataTable.js +117 -1
- package/lib/core/es6/data/DataView.d.ts +6 -0
- package/lib/core/es6/data/DataView.js +43 -0
- package/lib/core/es6/data/SegmentCollection.d.ts +2 -0
- package/lib/core/es6/data/SegmentCollection.js +21 -0
- package/lib/core/es6/grid/Core.js +1 -1
- package/lib/core/es6/grid/plugins/SortableTitlePlugin.js +9 -9
- package/lib/grid/index.js +1 -1
- package/lib/row-segmenting/es6/RowSegmenting.d.ts +6 -0
- package/lib/row-segmenting/es6/RowSegmenting.js +62 -11
- package/lib/rt-grid/dist/rt-grid.js +261 -23
- package/lib/rt-grid/dist/rt-grid.min.js +1 -1
- package/lib/rt-grid/es6/DataConnector.js +1 -1
- package/lib/rt-grid/es6/Grid.js +40 -11
- package/lib/tr-grid-cell-selection/es6/CellSelection.d.ts +3 -2
- package/lib/tr-grid-cell-selection/es6/CellSelection.js +1100 -1124
- package/lib/tr-grid-row-filtering/es6/RowFiltering.js +2 -2
- package/lib/types/es6/CellSelection.d.ts +3 -2
- package/lib/types/es6/Core/data/DataTable.d.ts +4 -0
- package/lib/types/es6/Core/data/DataView.d.ts +6 -0
- package/lib/types/es6/Core/data/SegmentCollection.d.ts +2 -0
- package/lib/types/es6/RowSegmenting.d.ts +6 -0
- package/lib/versions.json +3 -3
- package/package.json +1 -1
@@ -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 {
|
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
|
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=[
|
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
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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([
|
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
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
/**
|
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
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
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.
|
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.
|
228
|
+
CellSelectionPlugin.prototype._dragging = false;
|
228
229
|
/** @override
|
229
230
|
* @return {string}
|
230
231
|
*/
|
231
232
|
CellSelectionPlugin.prototype.getName = function () {
|
232
|
-
|
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
|
-
|
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
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
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
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
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
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
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
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
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
|
-
* @
|
415
|
-
* @param {number} rowIndex
|
410
|
+
* @return {!Object}
|
416
411
|
*/
|
417
|
-
CellSelectionPlugin.prototype.
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
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
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
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
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
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
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
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
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
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
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
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
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
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
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
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
|
-
|
701
|
-
|
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
|
-
|
709
|
-
|
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
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
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
|
-
/**
|
774
|
-
* @private
|
748
|
+
/** @private
|
775
749
|
* @param {Object} e
|
776
750
|
*/
|
777
|
-
CellSelectionPlugin.prototype._onBlur = function (e) {
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
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
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
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
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
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
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
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
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
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
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
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
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
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
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
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
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
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
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
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
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
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
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
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
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
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
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
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
|
-
|
1245
|
-
|
1246
|
-
|
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
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
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
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
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
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
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
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
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
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
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
|
-
|
1390
|
-
|
1391
|
-
|
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
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
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
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
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
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1455
|
-
|
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
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
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
|
-
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
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
|
-
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1527
|
-
|
1528
|
-
|
1529
|
-
|
1530
|
-
|
1531
|
-
|
1532
|
-
|
1533
|
-
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
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
|
-
|
1552
|
-
|
1553
|
-
|
1554
|
-
|
1555
|
-
|
1556
|
-
|
1557
|
-
|
1558
|
-
|
1559
|
-
|
1560
|
-
|
1561
|
-
|
1562
|
-
|
1563
|
-
|
1564
|
-
|
1565
|
-
|
1566
|
-
|
1567
|
-
|
1568
|
-
|
1569
|
-
|
1570
|
-
|
1571
|
-
|
1572
|
-
|
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
|
-
|
1586
|
-
|
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
|
-
|
1595
|
-
|
1596
|
-
|
1597
|
-
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1601
|
-
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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 };
|