canvas-datagrid 0.4.4 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/dist/canvas-datagrid.debug.js +3433 -1522
- package/dist/canvas-datagrid.debug.map +1 -1
- package/dist/canvas-datagrid.js +1 -1
- package/dist/canvas-datagrid.module.js +1 -1
- package/dist/canvas-datagrid.module.js.map +1 -1
- package/dist/types.d.ts +295 -70
- package/lib/component.js +1 -2
- package/lib/contextMenu.js +10 -102
- package/lib/defaults.js +7 -0
- package/lib/docs.js +37 -3
- package/lib/dom.js +2 -1
- package/lib/draw.js +169 -69
- package/lib/events/index.js +587 -277
- package/lib/intf.js +33 -219
- package/lib/main.js +3 -0
- package/lib/publicMethods.js +17 -386
- package/lib/selections/index.js +985 -0
- package/lib/selections/type.d.ts +38 -0
- package/lib/selections/util.js +1319 -0
- package/package.json +4 -4
package/lib/intf.js
CHANGED
|
@@ -89,9 +89,7 @@ export default function (self, ctor) {
|
|
|
89
89
|
columns: {},
|
|
90
90
|
trees: {},
|
|
91
91
|
};
|
|
92
|
-
self.
|
|
93
|
-
self.selectedRows = [];
|
|
94
|
-
self.selectedColumns = [];
|
|
92
|
+
self.fillOverlay = {};
|
|
95
93
|
self.filterable = {
|
|
96
94
|
rows: [],
|
|
97
95
|
columns: [],
|
|
@@ -215,185 +213,7 @@ export default function (self, ctor) {
|
|
|
215
213
|
'wheel',
|
|
216
214
|
];
|
|
217
215
|
self.mouse = { x: 0, y: 0 };
|
|
218
|
-
self.getSelectedData = function (expandToRow) {
|
|
219
|
-
const selectedData = [];
|
|
220
|
-
const schema = self.getSchema();
|
|
221
|
-
const viewDataLength = self.viewData.length;
|
|
222
216
|
|
|
223
|
-
if (viewDataLength === 0) {
|
|
224
|
-
return [];
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// self.selections is a sparse array, so `viewRowIndex` here
|
|
228
|
-
// will equal the row index as where it's rendered,
|
|
229
|
-
// not as where it is in the original data array.
|
|
230
|
-
self.selections.forEach(function (row, viewRowIndex) {
|
|
231
|
-
if (!row) {
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (viewRowIndex === viewDataLength) {
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
if (row.length === 0) {
|
|
240
|
-
selectedData[viewRowIndex] = null;
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
selectedData[viewRowIndex] = {};
|
|
245
|
-
|
|
246
|
-
row.forEach(function (col) {
|
|
247
|
-
if (col === -1 || !schema[col]) {
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
const orderedIndex = self.orders.columns[col];
|
|
252
|
-
|
|
253
|
-
if (!expandToRow && schema[orderedIndex].hidden) {
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
if (self.viewData[viewRowIndex]) {
|
|
258
|
-
selectedData[viewRowIndex][schema[orderedIndex].name] =
|
|
259
|
-
self.viewData[viewRowIndex][schema[orderedIndex].name];
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
return selectedData;
|
|
265
|
-
};
|
|
266
|
-
self.getSelectedCells = function (expandToRow) {
|
|
267
|
-
const selectedCells = [];
|
|
268
|
-
const schema = self.getSchema();
|
|
269
|
-
const viewDataLength = self.viewData.length;
|
|
270
|
-
|
|
271
|
-
if (viewDataLength === 0) {
|
|
272
|
-
return [];
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
for (const [viewRowIndex, row] of self.selections.entries()) {
|
|
276
|
-
if (!row || row.length === 0) continue;
|
|
277
|
-
|
|
278
|
-
for (const [, viewColumnIndex] of row.entries()) {
|
|
279
|
-
if (viewColumnIndex === -1 || !schema[viewColumnIndex]) {
|
|
280
|
-
continue;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
const boundColumnIndex = self.getBoundColumnIndexFromViewColumnIndex(
|
|
284
|
-
viewColumnIndex,
|
|
285
|
-
);
|
|
286
|
-
|
|
287
|
-
if (!expandToRow && schema[boundColumnIndex].hidden) {
|
|
288
|
-
continue;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
if (self.viewData[viewRowIndex]) {
|
|
292
|
-
const header = schema[boundColumnIndex];
|
|
293
|
-
const value = self.viewData[viewRowIndex][header.name];
|
|
294
|
-
const boundRowIndex = self.getBoundRowIndexFromViewRowIndex(
|
|
295
|
-
viewRowIndex,
|
|
296
|
-
);
|
|
297
|
-
|
|
298
|
-
const cell = {
|
|
299
|
-
value,
|
|
300
|
-
header,
|
|
301
|
-
boundRowIndex,
|
|
302
|
-
boundColumnIndex,
|
|
303
|
-
viewRowIndex,
|
|
304
|
-
viewColumnIndex,
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
selectedCells.push(cell);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
return selectedCells;
|
|
313
|
-
};
|
|
314
|
-
self.copySelectedCellsToClipboard = function (clipboardData) {
|
|
315
|
-
const selectedData = [];
|
|
316
|
-
const schema = self.getSchema();
|
|
317
|
-
let firstRowAsString;
|
|
318
|
-
let isNeat = true; // Selected like [[0, 1], [0, 1]] of [[0, 3]] is neat; Selected like [[0, 1], [1, 2]] is untidy
|
|
319
|
-
|
|
320
|
-
for (const [rowIndex, row] of self.selections.entries()) {
|
|
321
|
-
// If no cells are selected for a particular rowIndex the selections array will contain an empty element for that rowIndex.
|
|
322
|
-
if (!row) continue;
|
|
323
|
-
|
|
324
|
-
// Convert to string for easy comparison to the first row.
|
|
325
|
-
const rowAsString = row.join(',').toString();
|
|
326
|
-
const rowDict = {};
|
|
327
|
-
|
|
328
|
-
if (!firstRowAsString) firstRowAsString = row.join(',').toString();
|
|
329
|
-
if (isNeat && rowAsString !== firstRowAsString) isNeat = false;
|
|
330
|
-
|
|
331
|
-
const boundRowIndex = self.getBoundRowIndexFromViewRowIndex(rowIndex);
|
|
332
|
-
|
|
333
|
-
for (let columnIndex of row) {
|
|
334
|
-
// If the whole row is selected the columnIndex for the rowHeader is -1.
|
|
335
|
-
if (columnIndex < 0) continue;
|
|
336
|
-
|
|
337
|
-
const boundColumnIndex = self.getBoundColumnIndexFromViewColumnIndex(
|
|
338
|
-
columnIndex,
|
|
339
|
-
);
|
|
340
|
-
const columnName = schema[boundColumnIndex].name;
|
|
341
|
-
|
|
342
|
-
const value = self.originalData[boundRowIndex][columnName];
|
|
343
|
-
|
|
344
|
-
rowDict[columnName] = value;
|
|
345
|
-
}
|
|
346
|
-
selectedData.push(rowDict);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
if (selectedData.length > 0) {
|
|
350
|
-
const textString = createTextString(selectedData, isNeat);
|
|
351
|
-
const htmlString = createHTMLString(selectedData, isNeat);
|
|
352
|
-
|
|
353
|
-
const copiedData = {
|
|
354
|
-
'text/plain': textString,
|
|
355
|
-
'text/html': htmlString,
|
|
356
|
-
'text/csv': textString,
|
|
357
|
-
'application/json': JSON.stringify(selectedData),
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
for (const [mimeType, data] of Object.entries(copiedData)) {
|
|
361
|
-
clipboardData.setData(mimeType, data);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
};
|
|
365
|
-
self.clearSelectedCells = function () {
|
|
366
|
-
const schema = self.getSchema();
|
|
367
|
-
const affectedCells = [];
|
|
368
|
-
|
|
369
|
-
for (const [rowIndex, row] of self.selections.entries()) {
|
|
370
|
-
// If no cells are selected for a particular rowIndex the selections array will contain an empty element for that rowIndex.
|
|
371
|
-
if (!row) continue;
|
|
372
|
-
|
|
373
|
-
const boundRowIndex = self.getBoundRowIndexFromViewRowIndex(rowIndex);
|
|
374
|
-
|
|
375
|
-
for (let columnIndex of row) {
|
|
376
|
-
// If the whole row is selected the columnIndex for the rowHeader is -1.
|
|
377
|
-
if (columnIndex < 0) continue;
|
|
378
|
-
|
|
379
|
-
const boundColumnIndex = self.getBoundColumnIndexFromViewColumnIndex(
|
|
380
|
-
columnIndex,
|
|
381
|
-
);
|
|
382
|
-
const columnName = schema[boundColumnIndex].name;
|
|
383
|
-
|
|
384
|
-
self.viewData[boundRowIndex][columnName] = '';
|
|
385
|
-
|
|
386
|
-
affectedCells.push([
|
|
387
|
-
rowIndex,
|
|
388
|
-
columnIndex,
|
|
389
|
-
boundRowIndex,
|
|
390
|
-
boundColumnIndex,
|
|
391
|
-
]);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
return affectedCells;
|
|
396
|
-
};
|
|
397
217
|
self.getBoundRowIndexFromViewRowIndex = function (viewRowIndex) {
|
|
398
218
|
if (self.boundRowIndexMap && self.boundRowIndexMap.has(viewRowIndex)) {
|
|
399
219
|
return self.boundRowIndexMap.get(viewRowIndex);
|
|
@@ -581,27 +401,6 @@ export default function (self, ctor) {
|
|
|
581
401
|
self.createRowOrders = function () {
|
|
582
402
|
self.orders.rows = fillArray(0, self.originalData.length - 1);
|
|
583
403
|
};
|
|
584
|
-
self.fitSelectedColumns = function (width) {
|
|
585
|
-
const selectedColumns = self.selections[0];
|
|
586
|
-
const schema = self.getSchema();
|
|
587
|
-
|
|
588
|
-
for (const selectedColumn of selectedColumns) {
|
|
589
|
-
// Make sure the column is not the row header and that the whole column has in fact been selected.
|
|
590
|
-
if (selectedColumn >= 0 && self.isColumnSelected(selectedColumn)) {
|
|
591
|
-
if (isNaN(width)) {
|
|
592
|
-
const column = schema[self.orders.columns[selectedColumn]];
|
|
593
|
-
self.fitColumnToValues(column.name);
|
|
594
|
-
} else {
|
|
595
|
-
self.sizes.columns[selectedColumn] = width;
|
|
596
|
-
self.dispatchEvent('resizecolumn', {
|
|
597
|
-
x: width,
|
|
598
|
-
y: self.resizingStartingHeight,
|
|
599
|
-
draggingItem: self.currentCell,
|
|
600
|
-
});
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
};
|
|
605
404
|
self.getVisibleSchema = function () {
|
|
606
405
|
return self.getSchema().filter(function (col) {
|
|
607
406
|
return !col.hidden;
|
|
@@ -912,7 +711,11 @@ export default function (self, ctor) {
|
|
|
912
711
|
self.eventParent.removeEventListener('click', self.click, false);
|
|
913
712
|
self.eventParent.removeEventListener('mousemove', self.mousemove);
|
|
914
713
|
self.eventParent.removeEventListener('wheel', self.scrollWheel, false);
|
|
915
|
-
self.canvas.removeEventListener(
|
|
714
|
+
self.canvas.removeEventListener(
|
|
715
|
+
'contextmenu',
|
|
716
|
+
self.contextmenuEvent,
|
|
717
|
+
false,
|
|
718
|
+
);
|
|
916
719
|
self.canvas.removeEventListener('copy', self.copy);
|
|
917
720
|
self.controlInput.removeEventListener('copy', self.copy);
|
|
918
721
|
self.controlInput.removeEventListener('cut', self.cut);
|
|
@@ -1087,13 +890,7 @@ export default function (self, ctor) {
|
|
|
1087
890
|
colTrees.push(self.cellTree.origin.columns[k][l]);
|
|
1088
891
|
} else collapsedColCount++;
|
|
1089
892
|
}
|
|
1090
|
-
tempRow.push(
|
|
1091
|
-
...Array(collapsedColCount)
|
|
1092
|
-
.fill()
|
|
1093
|
-
.map(function () {
|
|
1094
|
-
return '';
|
|
1095
|
-
}),
|
|
1096
|
-
);
|
|
893
|
+
tempRow.push(...Array(collapsedColCount).fill(''));
|
|
1097
894
|
if (colTrees.length) {
|
|
1098
895
|
colTrees.push(
|
|
1099
896
|
...Array(collapsedColCount)
|
|
@@ -1113,13 +910,7 @@ export default function (self, ctor) {
|
|
|
1113
910
|
tempRow.push(self.viewData[k][l]);
|
|
1114
911
|
}
|
|
1115
912
|
otherData[k] = tempRow;
|
|
1116
|
-
collapsed.push(
|
|
1117
|
-
Array(self.viewData[0].length)
|
|
1118
|
-
.fill()
|
|
1119
|
-
.map(function () {
|
|
1120
|
-
return '';
|
|
1121
|
-
}),
|
|
1122
|
-
);
|
|
913
|
+
collapsed.push(Array(self.viewData[0].length).fill(''));
|
|
1123
914
|
collapsedCount++;
|
|
1124
915
|
}
|
|
1125
916
|
}
|
|
@@ -1291,7 +1082,7 @@ export default function (self, ctor) {
|
|
|
1291
1082
|
return fontStyle.replace(/\d+\.?\d*px/, '');
|
|
1292
1083
|
};
|
|
1293
1084
|
self.getFontHeight = function (fontStyle) {
|
|
1294
|
-
return parseFloat(fontStyle
|
|
1085
|
+
return parseFloat(fontStyle);
|
|
1295
1086
|
};
|
|
1296
1087
|
self.parseStyleValue = function (key) {
|
|
1297
1088
|
if (/Font/.test(key)) {
|
|
@@ -1483,7 +1274,6 @@ export default function (self, ctor) {
|
|
|
1483
1274
|
self.intf.clipElement = self.clipElement;
|
|
1484
1275
|
self.intf.getSchemaFromData = self.getSchemaFromData;
|
|
1485
1276
|
self.intf.setFilter = self.setFilter;
|
|
1486
|
-
self.intf.selectRow = self.selectRow;
|
|
1487
1277
|
self.intf.parentGrid = self.parentGrid;
|
|
1488
1278
|
self.intf.toggleTree = self.toggleTree;
|
|
1489
1279
|
self.intf.expandTree = self.expandTree;
|
|
@@ -1893,7 +1683,23 @@ export default function (self, ctor) {
|
|
|
1893
1683
|
return self.visibleRows;
|
|
1894
1684
|
},
|
|
1895
1685
|
});
|
|
1686
|
+
let warnedForObsoleteSelections;
|
|
1896
1687
|
Object.defineProperty(self.intf, 'selections', {
|
|
1688
|
+
get: function () {
|
|
1689
|
+
if (!warnedForObsoleteSelections) {
|
|
1690
|
+
console.warn(
|
|
1691
|
+
`DeprecationWarning: The property 'selections' is deprecated due to performance issue. ` +
|
|
1692
|
+
`And it will be removed in the future.` +
|
|
1693
|
+
`Please use new property 'selectionList' instead. ` +
|
|
1694
|
+
`Visit this link to get more information: ` +
|
|
1695
|
+
`https://github.com/TonyGermaneri/canvas-datagrid/pull/498`,
|
|
1696
|
+
);
|
|
1697
|
+
warnedForObsoleteSelections = true;
|
|
1698
|
+
}
|
|
1699
|
+
return self.getObsoleteSelectionMatrix();
|
|
1700
|
+
},
|
|
1701
|
+
});
|
|
1702
|
+
Object.defineProperty(self.intf, 'selectionList', {
|
|
1897
1703
|
get: function () {
|
|
1898
1704
|
return self.selections;
|
|
1899
1705
|
},
|
|
@@ -2057,6 +1863,14 @@ export default function (self, ctor) {
|
|
|
2057
1863
|
self.cellGridAttributes = value;
|
|
2058
1864
|
},
|
|
2059
1865
|
});
|
|
1866
|
+
Object.defineProperty(self.intf, 'fillCellCallback', {
|
|
1867
|
+
get: function () {
|
|
1868
|
+
return self.fillCellCallback;
|
|
1869
|
+
},
|
|
1870
|
+
set: function setFillCellCallback(value) {
|
|
1871
|
+
self.fillCellCallback = value;
|
|
1872
|
+
},
|
|
1873
|
+
});
|
|
2060
1874
|
Object.defineProperty(self.intf, 'ctx', {
|
|
2061
1875
|
get: function () {
|
|
2062
1876
|
return self.ctx;
|
package/lib/main.js
CHANGED
|
@@ -8,6 +8,7 @@ import draw from './draw';
|
|
|
8
8
|
import events from './events';
|
|
9
9
|
import touch from './touch';
|
|
10
10
|
import intf from './intf';
|
|
11
|
+
import selections from './selections/index';
|
|
11
12
|
import contextMenu from './contextMenu';
|
|
12
13
|
import button from './button';
|
|
13
14
|
import dom from './dom';
|
|
@@ -21,6 +22,7 @@ var modules = [
|
|
|
21
22
|
events,
|
|
22
23
|
touch,
|
|
23
24
|
intf,
|
|
25
|
+
selections,
|
|
24
26
|
contextMenu,
|
|
25
27
|
button,
|
|
26
28
|
dom,
|
|
@@ -103,6 +105,7 @@ export default function canvasDatagrid(args) {
|
|
|
103
105
|
'filters',
|
|
104
106
|
'treeGridAttributes',
|
|
105
107
|
'cellGridAttributes',
|
|
108
|
+
'fillCellCallback',
|
|
106
109
|
'data',
|
|
107
110
|
'schema',
|
|
108
111
|
];
|