canvas-datagrid 0.4.5 → 0.4.7
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 +3052 -1520
- 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 +301 -75
- package/lib/component.js +1 -2
- package/lib/contextMenu.js +10 -102
- package/lib/defaults.js +3 -0
- package/lib/docs.js +13 -5
- package/lib/dom.js +2 -1
- package/lib/draw.js +75 -58
- package/lib/events/index.js +155 -231
- package/lib/intf.js +24 -219
- package/lib/main.js +2 -0
- package/lib/publicMethods.js +9 -378
- package/lib/selections/index.js +986 -0
- package/lib/selections/type.d.ts +38 -0
- package/lib/selections/util.js +1319 -0
- package/package.json +5 -5
package/dist/types.d.ts
CHANGED
|
@@ -119,6 +119,7 @@
|
|
|
119
119
|
* @param [args.rowGroupIndicatorPosition = 'bottom'] - Ths position of the row group indicator(icon), available values: 'top' and 'bottom'.
|
|
120
120
|
* @param [args.showOrderByOption = true] - Show an option on the context menu sort rows.
|
|
121
121
|
* @param [args.showPaste = false] - Show the paste option in the context menu when applicable.
|
|
122
|
+
* @param [args.resizeAfterDragged] - Resize after the handle is dropped, similar to Excel.
|
|
122
123
|
* @param [args.schema = []] - Sets the schema. See {@link canvasDatagrid.schema}.
|
|
123
124
|
* @param [args.data = []] - Sets the data. See {@link canvasDatagrid.data}.
|
|
124
125
|
* @param [args.touchReleaseAnimationDurationMs = 2000] - How long the ease animation runs after touch release.
|
|
@@ -225,6 +226,7 @@ declare class canvasDatagrid {
|
|
|
225
226
|
rowGroupIndicatorPosition?: string;
|
|
226
227
|
showOrderByOption?: boolean;
|
|
227
228
|
showPaste?: boolean;
|
|
229
|
+
resizeAfterDragged?: boolean;
|
|
228
230
|
schema?: any[];
|
|
229
231
|
data?: any[];
|
|
230
232
|
touchReleaseAnimationDurationMs?: number;
|
|
@@ -459,48 +461,6 @@ declare class canvasDatagrid {
|
|
|
459
461
|
* @param y - The row index of the cell to set active.
|
|
460
462
|
*/
|
|
461
463
|
static setActiveCell(x: number, y: number): void;
|
|
462
|
-
/**
|
|
463
|
-
* Removes the selection.
|
|
464
|
-
* @param dontDraw - Suppress the draw method after the selection change.
|
|
465
|
-
*/
|
|
466
|
-
static selectNone(dontDraw: boolean): void;
|
|
467
|
-
/**
|
|
468
|
-
* Selects every visible cell.
|
|
469
|
-
* @param dontDraw - Suppress the draw method after the selection change.
|
|
470
|
-
*/
|
|
471
|
-
static selectAll(dontDraw: boolean): void;
|
|
472
|
-
/**
|
|
473
|
-
* Returns true if the selected columnIndex is selected on every row.
|
|
474
|
-
* @param columnIndex - The column index to check.
|
|
475
|
-
*/
|
|
476
|
-
static isColumnSelected(columnIndex: number): void;
|
|
477
|
-
/**
|
|
478
|
-
* Returns true if the selected rowIndex is selected on every column.
|
|
479
|
-
* @param rowIndex - The row index to check.
|
|
480
|
-
*/
|
|
481
|
-
static isRowSelected(rowIndex: number): void;
|
|
482
|
-
/**
|
|
483
|
-
* Runs the defined method on each selected cell.
|
|
484
|
-
* @param fn - The function to execute. The signature of the function is: (data, rowIndex, columnName).
|
|
485
|
-
* @param expandToRow - When true the data in the array is expanded to the entire row.
|
|
486
|
-
*/
|
|
487
|
-
static forEachSelectedCell(fn: number, expandToRow: number): void;
|
|
488
|
-
/**
|
|
489
|
-
* Selects a column.
|
|
490
|
-
* @param columnIndex - The column index to select.
|
|
491
|
-
* @param toggleSelectMode - When true, behaves as if you were holding control/command when you clicked the column.
|
|
492
|
-
* @param shift - When true, behaves as if you were holding shift when you clicked the column.
|
|
493
|
-
* @param supressSelectionchangedEvent - When true, prevents the selectionchanged event from firing.
|
|
494
|
-
*/
|
|
495
|
-
static selectColumn(columnIndex: number, toggleSelectMode: boolean, shift: boolean, supressSelectionchangedEvent: boolean): void;
|
|
496
|
-
/**
|
|
497
|
-
* Selects a row.
|
|
498
|
-
* @param rowIndex - The row index to select.
|
|
499
|
-
* @param ctrl - When true, behaves as if you were holding control/command when you clicked the row.
|
|
500
|
-
* @param shift - When true, behaves as if you were holding shift when you clicked the row.
|
|
501
|
-
* @param supressSelectionchangedEvent - When true, prevents the selectionchanged event from firing.
|
|
502
|
-
*/
|
|
503
|
-
static selectRow(rowIndex: number, ctrl: boolean, shift: boolean, supressSelectionchangedEvent: boolean): void;
|
|
504
464
|
/**
|
|
505
465
|
* Collapse a tree grid by row index.
|
|
506
466
|
* @param index - The index of the row to collapse.
|
|
@@ -603,17 +563,6 @@ declare class canvasDatagrid {
|
|
|
603
563
|
* @param rowIndexTo - The row index which is the end of the group
|
|
604
564
|
*/
|
|
605
565
|
static toggleGroupRows(rowIndexFrom: number, rowIndexTo: number): void;
|
|
606
|
-
/**
|
|
607
|
-
* Moves the current selection relative to the its current position. Note: this method does not move the selected data, just the selection itself.
|
|
608
|
-
* @param offsetX - The number of columns to offset the selection.
|
|
609
|
-
* @param offsetY - The number of rows to offset the selection.
|
|
610
|
-
*/
|
|
611
|
-
static moveSelection(offsetX: number, offsetY: number): void;
|
|
612
|
-
/**
|
|
613
|
-
* Deletes currently selected data.
|
|
614
|
-
* @param dontDraw - Suppress the draw method after the selection change.
|
|
615
|
-
*/
|
|
616
|
-
static deleteSelectedData(dontDraw: boolean): void;
|
|
617
566
|
/**
|
|
618
567
|
* Moves data in the provided selection to another position in the grid. Moving data off the edge of the schema (columns/x) will truncate data.
|
|
619
568
|
* @param sel - 2D array representing selected rows and columns. `canvasDatagrid.selections` is in this format and can be used here.
|
|
@@ -675,11 +624,6 @@ declare class canvasDatagrid {
|
|
|
675
624
|
* @returns cell at the selected location.
|
|
676
625
|
*/
|
|
677
626
|
static getCellAt(x: number, y: number): cell;
|
|
678
|
-
/**
|
|
679
|
-
* Gets the bounds of current selection.
|
|
680
|
-
* @returns selection.
|
|
681
|
-
*/
|
|
682
|
-
static getSelectionBounds(): rect;
|
|
683
627
|
/**
|
|
684
628
|
* Returns an auto generated schema based on data structure.
|
|
685
629
|
* @returns schema A schema based on the first item in the data array.
|
|
@@ -691,11 +635,6 @@ declare class canvasDatagrid {
|
|
|
691
635
|
* track of changes made to the data since last this method was called.
|
|
692
636
|
*/
|
|
693
637
|
static clearChangeLog(): void;
|
|
694
|
-
/**
|
|
695
|
-
* Selects an area of the grid.
|
|
696
|
-
* @param bounds - A rect object representing the selected values.
|
|
697
|
-
*/
|
|
698
|
-
static selectArea(bounds: rect): void;
|
|
699
638
|
/**
|
|
700
639
|
* Returns the maximum text width for a given column by column name.
|
|
701
640
|
* @param name - The name of the column to calculate the value's width of.
|
|
@@ -716,6 +655,74 @@ declare class canvasDatagrid {
|
|
|
716
655
|
* @param columnIndex - The column index to lookup.
|
|
717
656
|
*/
|
|
718
657
|
static getColumnWidth(columnIndex: number): void;
|
|
658
|
+
/**
|
|
659
|
+
* Returns true if the selected columnIndex is selected on every row.
|
|
660
|
+
* @param columnIndex - The column index to check.
|
|
661
|
+
*/
|
|
662
|
+
static isColumnSelected(columnIndex: number): void;
|
|
663
|
+
/**
|
|
664
|
+
* Returns true if the selected rowIndex is selected on every column.
|
|
665
|
+
* @param rowIndex - The row index to check.
|
|
666
|
+
*/
|
|
667
|
+
static isRowSelected(rowIndex: number): void;
|
|
668
|
+
/**
|
|
669
|
+
* Removes the selection.
|
|
670
|
+
* @param dontDraw - Suppress the draw method after the selection change.
|
|
671
|
+
*/
|
|
672
|
+
static selectNone(dontDraw: boolean): void;
|
|
673
|
+
/**
|
|
674
|
+
* Selects every visible cell.
|
|
675
|
+
* @param dontDraw - Suppress the draw method after the selection change.
|
|
676
|
+
*/
|
|
677
|
+
static selectAll(dontDraw: boolean): void;
|
|
678
|
+
/**
|
|
679
|
+
* Moves the current selection relative to the its current position. Note: this method does not move the selected data, just the selection itself.
|
|
680
|
+
* @param offsetX - The number of columns to offset the selection.
|
|
681
|
+
* @param offsetY - The number of rows to offset the selection.
|
|
682
|
+
*/
|
|
683
|
+
static moveSelection(offsetX: number, offsetY: number): void;
|
|
684
|
+
/**
|
|
685
|
+
* Gets the bounds of current selection.
|
|
686
|
+
* @param [sanitized] - sanitize the bound object if the value of thie paramater is `true`
|
|
687
|
+
* @returns two situations:
|
|
688
|
+
* 1. The result is always a bound object if `sanitized` is not `true`.
|
|
689
|
+
* And the result is `{top: Infinity, left: Infinity, bottom: -Infinity, right: -Infinity}` if there haven't selections.
|
|
690
|
+
* This is used for keeping compatibility with existing APIs.
|
|
691
|
+
* 2. When the parameter `sanitized` is true. The result will be null if there haven't selections.
|
|
692
|
+
*/
|
|
693
|
+
static getSelectionBounds(sanitized?: boolean): rect;
|
|
694
|
+
/**
|
|
695
|
+
* Deletes currently selected data.
|
|
696
|
+
* @param dontDraw - Suppress the draw method after the selection change.
|
|
697
|
+
*/
|
|
698
|
+
static deleteSelectedData(dontDraw: boolean): void;
|
|
699
|
+
/**
|
|
700
|
+
* Runs the defined method on each selected cell.
|
|
701
|
+
* @param fn - The function to execute. The signature of the function is: (data, rowIndex, columnName).
|
|
702
|
+
* @param expandToRow - When true the data in the array is expanded to the entire row.
|
|
703
|
+
*/
|
|
704
|
+
static forEachSelectedCell(fn: number, expandToRow: number): void;
|
|
705
|
+
/**
|
|
706
|
+
* Selects a column.
|
|
707
|
+
* @param columnIndex - The column index to select.
|
|
708
|
+
* @param toggleSelectMode - When true, behaves as if you were holding control/command when you clicked the column.
|
|
709
|
+
* @param shift - When true, behaves as if you were holding shift when you clicked the column.
|
|
710
|
+
* @param suppressEvent - When true, prevents the selectionchanged event from firing.
|
|
711
|
+
*/
|
|
712
|
+
static selectColumn(columnIndex: number, toggleSelectMode: boolean, shift: boolean, suppressEvent: boolean): void;
|
|
713
|
+
/**
|
|
714
|
+
* Selects a row.
|
|
715
|
+
* @param rowIndex - The row index to select.
|
|
716
|
+
* @param ctrl - When true, behaves as if you were holding control/command when you clicked the row.
|
|
717
|
+
* @param shift - When true, behaves as if you were holding shift when you clicked the row.
|
|
718
|
+
* @param supressSelectionchangedEvent - When true, prevents the selectionchanged event from firing.
|
|
719
|
+
*/
|
|
720
|
+
static selectRow(rowIndex: number, ctrl: boolean, shift: boolean, supressSelectionchangedEvent: boolean): void;
|
|
721
|
+
/**
|
|
722
|
+
* Selects an area of the grid.
|
|
723
|
+
* @param [bounds] - A rect object representing the selected values.
|
|
724
|
+
*/
|
|
725
|
+
static selectArea(bounds?: rect, ctrl?: boolean): void;
|
|
719
726
|
/**
|
|
720
727
|
* Selected rows. Same as the `data` property but filtered for the rows the user has cells selected in. If any cell in the row is selected, all data for that row will appear in this array.
|
|
721
728
|
*/
|
|
@@ -1205,8 +1212,8 @@ declare namespace canvasDatagrid {
|
|
|
1205
1212
|
* @property [activeCellSelectedBackgroundColor = rgba(236, 243, 255, 1)] - Style of activeCellSelectedBackgroundColor.
|
|
1206
1213
|
* @property [activeCellSelectedColor = rgba(0, 0, 0, 1)] - Style of activeCellSelectedColor.
|
|
1207
1214
|
* @property [activeCellVerticalAlignment = center] - Style of activeCellVerticalAlignment.
|
|
1208
|
-
* @property [
|
|
1209
|
-
* @property [
|
|
1215
|
+
* @property [activeColumnHeaderCellBackgroundColor = rgba(225, 225, 225, 1)] - Style of activeColumnHeaderCellBackgroundColor.
|
|
1216
|
+
* @property [activeColumnHeaderCellColor = rgba(0, 0, 0, 1)] - Style of activeColumnHeaderCellColor.
|
|
1210
1217
|
* @property [activeRowHeaderCellBackgroundColor = rgba(225, 225, 225, 1)] - Style of activeRowHeaderCellBackgroundColor.
|
|
1211
1218
|
* @property [activeRowHeaderCellColor = rgba(0, 0, 0, 1)] - Style of activeRowHeaderCellColor.
|
|
1212
1219
|
* @property [autocompleteBottomMargin = 60] - Style of autocompleteBottomMargin.
|
|
@@ -1299,9 +1306,12 @@ declare namespace canvasDatagrid {
|
|
|
1299
1306
|
* @property [gridBorderWidth = 1] - Style of gridBorderWidth.
|
|
1300
1307
|
* @property [groupIndicatorColor = rgba(155, 155, 155, 1)'] - Foreground color of the group indicator(icon).
|
|
1301
1308
|
* @property [groupIndicatorBackgroundColor = rgba(255, 255, 255, 1)'] - Background color of the group indicator(icon).
|
|
1302
|
-
* @property [
|
|
1303
|
-
* @property [
|
|
1304
|
-
* @property [
|
|
1309
|
+
* @property [columnHeaderCellBackgroundColor = rgba(240, 240, 240, 1)] - Style of columnHeaderCellBackgroundColor.
|
|
1310
|
+
* @property [columnHeaderCellBorderColor = rgba(172, 172, 172, 1)] - Style of columnHeaderCellBackgroundColor.
|
|
1311
|
+
* @property [columnHeaderCellBorderWidth = 1] - Style of columnHeaderCellBackgroundColor.
|
|
1312
|
+
* @property [columnHeaderCellCapBackgroundColor = rgba(240, 240, 240, 1)] - Style of columnHeaderCellCapBackgroundColor.
|
|
1313
|
+
* @property [columnHeaderCellCapBorderColor = rgba(172, 172, 172, 1)] - Style of columnHeaderCellCapBackgroundColor.
|
|
1314
|
+
* @property [columnHeaderCellCapBorderWidth = 1] - Style of columnHeaderCellCapBackgroundColor.
|
|
1305
1315
|
* @property [columnHeaderCellBorderColor = rgba(152, 152, 152, 1)] - Style of columnHeaderCellBorderColor.
|
|
1306
1316
|
* @property [columnHeaderCellBorderWidth = 0.25] - Style of columnHeaderCellBorderWidth.
|
|
1307
1317
|
* @property [columnHeaderCellColor = rgba(50, 50, 50, 1)] - Style of columnHeaderCellColor.
|
|
@@ -1325,6 +1335,7 @@ declare namespace canvasDatagrid {
|
|
|
1325
1335
|
* @property [columnHeaderOrderByArrowWidth = 13] - Style of columnHeaderOrderByArrowWidth.
|
|
1326
1336
|
* @property [rowHeaderCellWidth = 57] - Style of rowHeaderCellWidth.
|
|
1327
1337
|
* @property [minColumnWidth = 45] - Style of minColumnWidth.
|
|
1338
|
+
* @property [height = auto] - Style of height.
|
|
1328
1339
|
* @property [minHeight = 24] - Style of minHeight.
|
|
1329
1340
|
* @property [minRowHeight = 24] - Style of minRowHeight.
|
|
1330
1341
|
* @property [name = default] - Style of name.
|
|
@@ -1333,6 +1344,8 @@ declare namespace canvasDatagrid {
|
|
|
1333
1344
|
* @property [reorderMarkerBorderWidth = 1.25] - Style of reorderMarkerBorderWidth.
|
|
1334
1345
|
* @property [reorderMarkerIndexBorderColor = rgba(66, 133, 244, 1)] - Style of reorderMarkerIndexBorderColor.
|
|
1335
1346
|
* @property [reorderMarkerIndexBorderWidth = 2.75] - Style of reorderMarkerIndexBorderWidth.
|
|
1347
|
+
* @property [resizeMarkerColor = rgba(0, 0, 0, 0.2)] - Style of resizeMarkerColor.
|
|
1348
|
+
* @property [resizeMarkerSize = 2] - Style of resizeMarkerSize.
|
|
1336
1349
|
* @property [rowGroupColumnWidth = 25] - Style of rowGroupColumnWidth.
|
|
1337
1350
|
* @property [rowHeaderCellBackgroundColor = rgba(240, 240, 240, 1)] - Style of rowHeaderCellBackgroundColor.
|
|
1338
1351
|
* @property [rowHeaderCellBorderColor = rgba(152, 152, 152, 1)] - Style of rowHeaderCellBorderColor.
|
|
@@ -1392,6 +1405,7 @@ declare namespace canvasDatagrid {
|
|
|
1392
1405
|
* @property [frozenMarkerWidth = 1] - Style of frozenMarkerWidth.
|
|
1393
1406
|
* @property [overflowY = auto] - When set to hidden, vertical scroll bar will be hidden. When set to auto vertical scroll bar will appear when data overflows the height. When set to scroll the vertical scrollbar will always be visible.
|
|
1394
1407
|
* @property [overflowX = auto] - When set to hidden, horizontal scroll bar will be hidden. When set to auto horizontal scroll bar will appear when data overflows the width. When set to scroll the horizontal scrollbar will always be visible.
|
|
1408
|
+
* @property [width = auto] - Style of width.
|
|
1395
1409
|
*
|
|
1396
1410
|
* ['', 'normal'],
|
|
1397
1411
|
*/
|
|
@@ -1465,13 +1479,13 @@ declare namespace canvasDatagrid {
|
|
|
1465
1479
|
*/
|
|
1466
1480
|
activeCellVerticalAlignment?: string;
|
|
1467
1481
|
/**
|
|
1468
|
-
* Style of
|
|
1482
|
+
* Style of activeColumnHeaderCellBackgroundColor.
|
|
1469
1483
|
*/
|
|
1470
|
-
|
|
1484
|
+
activeColumnHeaderCellBackgroundColor?: string;
|
|
1471
1485
|
/**
|
|
1472
|
-
* Style of
|
|
1486
|
+
* Style of activeColumnHeaderCellColor.
|
|
1473
1487
|
*/
|
|
1474
|
-
|
|
1488
|
+
activeColumnHeaderCellColor?: string;
|
|
1475
1489
|
/**
|
|
1476
1490
|
* Style of activeRowHeaderCellBackgroundColor.
|
|
1477
1491
|
*/
|
|
@@ -1843,13 +1857,25 @@ declare namespace canvasDatagrid {
|
|
|
1843
1857
|
/**
|
|
1844
1858
|
* Style of columnHeaderCellBackgroundColor.
|
|
1845
1859
|
*/
|
|
1860
|
+
columnHeaderCellBackgroundColor?: string;
|
|
1861
|
+
/**
|
|
1862
|
+
* Style of columnHeaderCellBorderColor.
|
|
1863
|
+
*/
|
|
1864
|
+
columnHeaderCellBorderColor?: string;
|
|
1865
|
+
/**
|
|
1866
|
+
* Style of columnHeaderCellBorderWidth.
|
|
1867
|
+
*/
|
|
1868
|
+
columnHeaderCellBorderWidth?: number;
|
|
1869
|
+
/**
|
|
1870
|
+
* Style of columnHeaderCellCapBackgroundColor.
|
|
1871
|
+
*/
|
|
1846
1872
|
columnHeaderCellCapBackgroundColor?: string;
|
|
1847
1873
|
/**
|
|
1848
|
-
* Style of
|
|
1874
|
+
* Style of columnHeaderCellCapBackgroundColor.
|
|
1849
1875
|
*/
|
|
1850
1876
|
columnHeaderCellCapBorderColor?: string;
|
|
1851
1877
|
/**
|
|
1852
|
-
* Style of
|
|
1878
|
+
* Style of columnHeaderCellCapBackgroundColor.
|
|
1853
1879
|
*/
|
|
1854
1880
|
columnHeaderCellCapBorderWidth?: number;
|
|
1855
1881
|
/**
|
|
@@ -1944,6 +1970,10 @@ declare namespace canvasDatagrid {
|
|
|
1944
1970
|
* Style of minColumnWidth.
|
|
1945
1971
|
*/
|
|
1946
1972
|
minColumnWidth?: number;
|
|
1973
|
+
/**
|
|
1974
|
+
* Style of height.
|
|
1975
|
+
*/
|
|
1976
|
+
height?: number | string;
|
|
1947
1977
|
/**
|
|
1948
1978
|
* Style of minHeight.
|
|
1949
1979
|
*/
|
|
@@ -1976,6 +2006,14 @@ declare namespace canvasDatagrid {
|
|
|
1976
2006
|
* Style of reorderMarkerIndexBorderWidth.
|
|
1977
2007
|
*/
|
|
1978
2008
|
reorderMarkerIndexBorderWidth?: number;
|
|
2009
|
+
/**
|
|
2010
|
+
* Style of resizeMarkerColor.
|
|
2011
|
+
*/
|
|
2012
|
+
resizeMarkerColor?: string;
|
|
2013
|
+
/**
|
|
2014
|
+
* Style of resizeMarkerSize.
|
|
2015
|
+
*/
|
|
2016
|
+
resizeMarkerSize?: number;
|
|
1979
2017
|
/**
|
|
1980
2018
|
* Style of rowGroupColumnWidth.
|
|
1981
2019
|
*/
|
|
@@ -2210,10 +2248,14 @@ declare namespace canvasDatagrid {
|
|
|
2210
2248
|
overflowY?: string;
|
|
2211
2249
|
/**
|
|
2212
2250
|
* When set to hidden, horizontal scroll bar will be hidden. When set to auto horizontal scroll bar will appear when data overflows the width. When set to scroll the horizontal scrollbar will always be visible.
|
|
2251
|
+
*/
|
|
2252
|
+
overflowX?: string;
|
|
2253
|
+
/**
|
|
2254
|
+
* Style of width.
|
|
2213
2255
|
|
|
2214
2256
|
['', 'normal'],
|
|
2215
2257
|
*/
|
|
2216
|
-
|
|
2258
|
+
width?: number | string;
|
|
2217
2259
|
}
|
|
2218
2260
|
/**
|
|
2219
2261
|
* An item in the context menu.
|
|
@@ -2239,3 +2281,187 @@ declare namespace canvasDatagrid {
|
|
|
2239
2281
|
*/
|
|
2240
2282
|
declare function mergeHiddenRowRanges(hiddenRowRanges: any[], newRange: number[]): boolean;
|
|
2241
2283
|
|
|
2284
|
+
/**
|
|
2285
|
+
* Swap values between two properties in an object
|
|
2286
|
+
* @param obj - The object
|
|
2287
|
+
* @param prop0 - First property name
|
|
2288
|
+
* @param prop1 - Another property name
|
|
2289
|
+
*/
|
|
2290
|
+
declare function swapProps(obj: any, prop0: string, prop1: string): void;
|
|
2291
|
+
|
|
2292
|
+
/**
|
|
2293
|
+
* This function transforms a selection object to normalized.
|
|
2294
|
+
* Here is the definition of **normalized selection object**:
|
|
2295
|
+
* - It contains these required properties: type, startRow, startColumn, endRow, endColumn
|
|
2296
|
+
* - Property `endRow` and property `endColumn` must exist even if their value are the same with `startRow` or `startColumn`.
|
|
2297
|
+
* - The value of `endRow` must be equals or greater than the value of `startRow`
|
|
2298
|
+
* - The value of `endColumn` must be equals or greater than the value of `startColumn`
|
|
2299
|
+
*/
|
|
2300
|
+
declare function normalizeSelection(sel: SelectionDescriptor): SelectionDescriptor;
|
|
2301
|
+
|
|
2302
|
+
/**
|
|
2303
|
+
* Parse a string expression to a selection object. Here are some example expressions:
|
|
2304
|
+
* - cells:20,30-40,50
|
|
2305
|
+
* - row:5
|
|
2306
|
+
* - cols:5-9
|
|
2307
|
+
*/
|
|
2308
|
+
declare function getSelectionFromString(str: string): SelectionDescriptor;
|
|
2309
|
+
|
|
2310
|
+
/**
|
|
2311
|
+
* Check are two cells block the same
|
|
2312
|
+
*/
|
|
2313
|
+
declare function isSameCellsBlock(block0: SelectionDescriptor, block1: SelectionDescriptor): boolean;
|
|
2314
|
+
|
|
2315
|
+
/**
|
|
2316
|
+
* This function is used in the function `mergeSelections`
|
|
2317
|
+
*/
|
|
2318
|
+
declare function mergeCellsIntoRowsOrColumns(cells: SelectionDescriptor, rowsOrColumns: SelectionDescriptor): SelectionDescriptor;
|
|
2319
|
+
|
|
2320
|
+
/**
|
|
2321
|
+
* Merge two selection objects (Splicing, Containing)
|
|
2322
|
+
* @returns A concatenated selection object based on `block0`.
|
|
2323
|
+
* Or `undefined` if they can't be concatenated
|
|
2324
|
+
*/
|
|
2325
|
+
declare function mergeSelections(sel0: SelectionDescriptor, sel1: SelectionDescriptor): SelectionDescriptor;
|
|
2326
|
+
|
|
2327
|
+
/**
|
|
2328
|
+
* Remove some rows from a rows selection
|
|
2329
|
+
* @param selection - It must be a selection with type as `Rows`
|
|
2330
|
+
* @param remove - It must be a selection with type as `Rows`
|
|
2331
|
+
* @returns Returning a `undefined` represents parameter `remove` doesn't intersect with parameter `selection`
|
|
2332
|
+
*/
|
|
2333
|
+
declare function removePartOfRowsSelection(selection: SelectionDescriptor, remove: SelectionDescriptor): SelectionDescriptor[];
|
|
2334
|
+
|
|
2335
|
+
/**
|
|
2336
|
+
* Remove some columns from a columns selection
|
|
2337
|
+
* @param selection - It must be a selection with type as `Columns`
|
|
2338
|
+
* @param remove - It must be a selection with type as `Columns`
|
|
2339
|
+
* @returns Returning a `undefined` represents parameter `remove` doesn't intersect with parameter `selection`
|
|
2340
|
+
*/
|
|
2341
|
+
declare function removePartOfColumnsSelection(selection: any, remove: any): object[];
|
|
2342
|
+
|
|
2343
|
+
/**
|
|
2344
|
+
* Remove a cells block from a cells selection
|
|
2345
|
+
* @param selection - It must be a selection with type as `Cells` or `UnselectedCells`
|
|
2346
|
+
* @param remove - It must be a selection
|
|
2347
|
+
* @returns Returning a `undefined` represents parameter `remove` doesn't intersect with parameter `selection`
|
|
2348
|
+
*/
|
|
2349
|
+
declare function removePartOfCellsSelection(selection: SelectionDescriptor, remove: SelectionDescriptor): SelectionDescriptor[];
|
|
2350
|
+
|
|
2351
|
+
/**
|
|
2352
|
+
* Get intersection of two selection object
|
|
2353
|
+
* @returns a selection object or undefined
|
|
2354
|
+
*/
|
|
2355
|
+
declare function getIntersection(sel0: SelectionDescriptor, sel1: SelectionDescriptor): SelectionDescriptor;
|
|
2356
|
+
|
|
2357
|
+
/**
|
|
2358
|
+
* Add a selection object into `selections` array. And there are two behaviours if this function:
|
|
2359
|
+
* - It appends a new selection object into the `selections` array
|
|
2360
|
+
* - It rewrites the selection item in the `selections` array (merge or change its type)
|
|
2361
|
+
* @param add - Supported types: Cells, Rows, Columns
|
|
2362
|
+
* @param [context] - Eg: {rows:1000, columns:1000}
|
|
2363
|
+
* @returns is the selections array changed
|
|
2364
|
+
*/
|
|
2365
|
+
declare function addIntoSelections(selections: SelectionDescriptor[], add: SelectionDescriptor, context?: ContextForSelectionAction): boolean;
|
|
2366
|
+
|
|
2367
|
+
/**
|
|
2368
|
+
* Remove a selection area from `selections` array
|
|
2369
|
+
* @param remove - Supported types: Cells, Rows, Columns
|
|
2370
|
+
* @param [context] - Eg: {rows:1000, columns:1000}
|
|
2371
|
+
* @returns is the selections array changed
|
|
2372
|
+
*/
|
|
2373
|
+
declare function removeFromSelections(selections: SelectionDescriptor[], remove: SelectionDescriptor, context?: ContextForSelectionAction): boolean;
|
|
2374
|
+
|
|
2375
|
+
/**
|
|
2376
|
+
* Clean up a selections array.
|
|
2377
|
+
* This function removes unnecessary selection object, and it tries to merge different selections.
|
|
2378
|
+
*/
|
|
2379
|
+
declare function cleanupSelections(selections: SelectionDescriptor[]): void;
|
|
2380
|
+
|
|
2381
|
+
/**
|
|
2382
|
+
* Check if all cells in a given row selected
|
|
2383
|
+
*/
|
|
2384
|
+
declare function isRowSelected(selections: SelectionDescriptor[], rowIndex: number): void;
|
|
2385
|
+
|
|
2386
|
+
/**
|
|
2387
|
+
* Check if all cells in a given column selected
|
|
2388
|
+
*/
|
|
2389
|
+
declare function isColumnSelected(selections: SelectionDescriptor[], columnIndex: number): void;
|
|
2390
|
+
|
|
2391
|
+
/**
|
|
2392
|
+
* Check if a given cell selected
|
|
2393
|
+
*/
|
|
2394
|
+
declare function isCellSelected(selections: SelectionDescriptor[], rowIndex: number, columnIndex: number): void;
|
|
2395
|
+
|
|
2396
|
+
/**
|
|
2397
|
+
* Check if all given cells selected
|
|
2398
|
+
* @param range - the range of cells block
|
|
2399
|
+
*/
|
|
2400
|
+
declare function areAllCellsSelected(selections: SelectionDescriptor[], range: RangeDescriptor): boolean;
|
|
2401
|
+
|
|
2402
|
+
/**
|
|
2403
|
+
* Get selection state from cells
|
|
2404
|
+
* @returns Returning `true` means all given cells are selected,
|
|
2405
|
+
* Returning `false` means all given cells are not selected.
|
|
2406
|
+
* Returning a two-dimensional array means some cells are selected and some cells are not selected.
|
|
2407
|
+
* A reference for returned value: `state[rowIndex - range.startRow][colIndex - range.startColumn]`
|
|
2408
|
+
*/
|
|
2409
|
+
declare function getSelectionStateFromCells(selections: SelectionDescriptor[], range: RangeDescriptor): boolean | boolean[][];
|
|
2410
|
+
|
|
2411
|
+
/**
|
|
2412
|
+
* Get verbose selection state from cells.
|
|
2413
|
+
* (`verbose` in here means that you can locate particular selection for selected cells)
|
|
2414
|
+
* @returns Each item in this two-dimensional array is 0 or a positive int,
|
|
2415
|
+
* it represents the index of matched selection plus 1 if it is a positive int.
|
|
2416
|
+
* And if the value of item is 0, it means this cell is not selected.
|
|
2417
|
+
* A reference for returned value: `state[rowIndex - range.startRow][colIndex - range.startColumn]`
|
|
2418
|
+
*/
|
|
2419
|
+
declare function getVerboseSelectionStateFromCells(selections: SelectionDescriptor[], range: RangeDescriptor): number[][];
|
|
2420
|
+
|
|
2421
|
+
/**
|
|
2422
|
+
* Check if any contiguous columns are selected.
|
|
2423
|
+
* (This function is useful for the preconditions for actions on columns, Eg: grouping, hiding)
|
|
2424
|
+
* @param allowImpurity - This function ignores other selected rows/cells if its value is `true`
|
|
2425
|
+
* @returns a tuple [beginViewColumnIndex, endViewColumnIndex] or `undefined`
|
|
2426
|
+
*/
|
|
2427
|
+
declare function getSelectedContiguousColumns(selections: SelectionDescriptor[], allowImpurity: boolean): number[];
|
|
2428
|
+
|
|
2429
|
+
/**
|
|
2430
|
+
* Check if any contiguous rows are selected.
|
|
2431
|
+
* (This function is useful for the preconditions for actions on rows, Eg: grouping, hiding)
|
|
2432
|
+
* @param allowImpurity - This function ignores other selected columns/cells if its value is `true`
|
|
2433
|
+
* @returns a tuple [beginRowOrderIndex, endRowOrderIndex] or `undefined`
|
|
2434
|
+
*/
|
|
2435
|
+
declare function getSelectedContiguousRows(selections: SelectionDescriptor[], allowImpurity: boolean): number[];
|
|
2436
|
+
|
|
2437
|
+
/**
|
|
2438
|
+
* Check if current selections are complex.
|
|
2439
|
+
* How we defined "complex" in here:
|
|
2440
|
+
* - There are any unselected cells in selected rows/columns
|
|
2441
|
+
* - More than one selection type in current selections
|
|
2442
|
+
*/
|
|
2443
|
+
declare function areSelectionsComplex(selections: SelectionDescriptor[]): boolean;
|
|
2444
|
+
|
|
2445
|
+
/**
|
|
2446
|
+
* Check if current selections are neat.
|
|
2447
|
+
* This method is used for make new API are compatible with obsolete API
|
|
2448
|
+
* For example:
|
|
2449
|
+
* - Selected like <0,0-10,10> or rows<5-10> is neat
|
|
2450
|
+
* - Selected like <0,0-10,10>&<11,1-11,10> is untidy
|
|
2451
|
+
* @param selections - selections after clean up
|
|
2452
|
+
*/
|
|
2453
|
+
declare function areSelectionsNeat(selections: SelectionDescriptor[]): boolean;
|
|
2454
|
+
|
|
2455
|
+
declare function moveSelections(selections: SelectionDescriptor[], offsetX: number, offsetY: number): void;
|
|
2456
|
+
|
|
2457
|
+
declare function cloneSelections(selections: SelectionDescriptor[]): SelectionDescriptor[];
|
|
2458
|
+
|
|
2459
|
+
declare function getSelectionBounds(selections: SelectionDescriptor[]): RectangleObject;
|
|
2460
|
+
|
|
2461
|
+
/**
|
|
2462
|
+
* @param cell - Signature: `{rowIndex:number;columnIndex:number}`
|
|
2463
|
+
* @param keyEvent - Signature: `{key:string;shiftKey:boolean}`
|
|
2464
|
+
* @param context - Signature: `{columns:number;rows:number}`
|
|
2465
|
+
*/
|
|
2466
|
+
declare function shrinkOrExpandSelections(selections: SelectionDescriptor[], cell: any, keyEvent: any, context: any): boolean;
|
|
2467
|
+
|
package/lib/component.js
CHANGED
|
@@ -60,8 +60,7 @@ export default function () {
|
|
|
60
60
|
defs = {};
|
|
61
61
|
intf.computedStyle = cStyle;
|
|
62
62
|
defaults(defs);
|
|
63
|
-
defs
|
|
64
|
-
defs.forEach(function (def) {
|
|
63
|
+
defs.defaults.styles.forEach(function (def) {
|
|
65
64
|
var val;
|
|
66
65
|
val = cStyle.getPropertyValue(component.hyphenateProperty(def[0], true));
|
|
67
66
|
if (val === '') {
|
package/lib/contextMenu.js
CHANGED
|
@@ -344,7 +344,7 @@ export default function (self) {
|
|
|
344
344
|
return selectedIndex;
|
|
345
345
|
},
|
|
346
346
|
set: function (value) {
|
|
347
|
-
if (typeof value !== 'number' || isNaN(value || !isFinite(value))
|
|
347
|
+
if (typeof value !== 'number' || isNaN(value) || !isFinite(value)) {
|
|
348
348
|
throw new Error('Context menu selected index must be a sane number.');
|
|
349
349
|
}
|
|
350
350
|
selectedIndex = value;
|
|
@@ -539,97 +539,6 @@ export default function (self) {
|
|
|
539
539
|
}
|
|
540
540
|
}
|
|
541
541
|
|
|
542
|
-
/**
|
|
543
|
-
* Return a tuple if the user selected contiguous columns, otherwise `null`.
|
|
544
|
-
* Info: Because the user may reorder the columns,
|
|
545
|
-
* the schemaIndex of the first item may be greater than the schemaIndex of the second item,
|
|
546
|
-
* but the columnIndex of the firs item must less than the columnIndex of the second item.
|
|
547
|
-
* @param {any[]} schema from `self.getSchema()`
|
|
548
|
-
* @returns {any[]} column schemas tuple (each schema has an additional field `schemaIndex`)
|
|
549
|
-
*/
|
|
550
|
-
function getSelectedContiguousColumns(ev, schema) {
|
|
551
|
-
const memoKey = '__contiguousColumns';
|
|
552
|
-
if (Array.isArray(ev[memoKey]) || ev[memoKey] === null) return ev[memoKey];
|
|
553
|
-
ev[memoKey] = null;
|
|
554
|
-
|
|
555
|
-
if (!Array.isArray(self.selections) || self.selections.length === 0) return;
|
|
556
|
-
const selection = self.selections[0];
|
|
557
|
-
if (!selection || selection.length === 0) return;
|
|
558
|
-
for (let rowIndex = 0; rowIndex < self.viewData.length; rowIndex++) {
|
|
559
|
-
const row = self.viewData[rowIndex];
|
|
560
|
-
if (!row) continue;
|
|
561
|
-
const compare = self.selections[rowIndex];
|
|
562
|
-
if (!compare) return;
|
|
563
|
-
if (compare.length !== selection.length) return;
|
|
564
|
-
for (let i = 0; i < selection.length; i++)
|
|
565
|
-
if (selection[i] !== compare[i]) return;
|
|
566
|
-
}
|
|
567
|
-
selection.sort((a, b) => a - b);
|
|
568
|
-
|
|
569
|
-
/** @type {number[][]} */
|
|
570
|
-
const ranges = [];
|
|
571
|
-
let begin = selection[0];
|
|
572
|
-
let end = selection[0];
|
|
573
|
-
for (let i = 1; i < selection.length; i++) {
|
|
574
|
-
const orderIndex = selection[i];
|
|
575
|
-
if (orderIndex === end + 1) {
|
|
576
|
-
end = orderIndex;
|
|
577
|
-
continue;
|
|
578
|
-
}
|
|
579
|
-
ranges.push([begin, end]);
|
|
580
|
-
begin = orderIndex;
|
|
581
|
-
end = orderIndex;
|
|
582
|
-
}
|
|
583
|
-
ranges.push([begin, end]);
|
|
584
|
-
|
|
585
|
-
const currentOrderIndex = ev.cell.columnIndex;
|
|
586
|
-
const matchedRange = ranges.find(
|
|
587
|
-
(range) =>
|
|
588
|
-
currentOrderIndex >= range[0] &&
|
|
589
|
-
currentOrderIndex <= range[1] &&
|
|
590
|
-
range[0] !== range[1],
|
|
591
|
-
);
|
|
592
|
-
if (!matchedRange) return;
|
|
593
|
-
|
|
594
|
-
/** @type {number[]} orders[index] => columnIndex */
|
|
595
|
-
const orders = self.orders.columns;
|
|
596
|
-
if (!Array.isArray(orders)) return;
|
|
597
|
-
|
|
598
|
-
const matchedSchema = matchedRange.map((orderIndex) => {
|
|
599
|
-
const schemaIndex = orders[orderIndex];
|
|
600
|
-
const thisSchema = schema[schemaIndex];
|
|
601
|
-
return Object.assign({}, thisSchema, { orderIndex });
|
|
602
|
-
});
|
|
603
|
-
if (matchedSchema.findIndex((it) => !it) >= 0) return;
|
|
604
|
-
return (ev[memoKey] = matchedSchema);
|
|
605
|
-
}
|
|
606
|
-
/**
|
|
607
|
-
* @param {boolean} [allowOnlyOneRow]
|
|
608
|
-
* @returns {number[]} a rowIndex tuple. It can contains one row index or two row indexes.
|
|
609
|
-
*/
|
|
610
|
-
function getSelectedContiguousRows(allowOnlyOneRow) {
|
|
611
|
-
let range = [];
|
|
612
|
-
let prev = -2;
|
|
613
|
-
let ok = true;
|
|
614
|
-
self.selections.forEach(function (row, index) {
|
|
615
|
-
if (!ok) return;
|
|
616
|
-
if (prev < -1) {
|
|
617
|
-
prev = index;
|
|
618
|
-
range[0] = index;
|
|
619
|
-
return;
|
|
620
|
-
}
|
|
621
|
-
if (index !== prev + 1 || !row || row.length === 0) {
|
|
622
|
-
ok = false;
|
|
623
|
-
return;
|
|
624
|
-
}
|
|
625
|
-
prev = index;
|
|
626
|
-
range[1] = index;
|
|
627
|
-
});
|
|
628
|
-
if (ok) {
|
|
629
|
-
if (range.length === 1) return allowOnlyOneRow ? range : null;
|
|
630
|
-
return range;
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
542
|
function addDefaultContextMenuItem(e) {
|
|
634
543
|
const schema = self.getSchema();
|
|
635
544
|
/**
|
|
@@ -656,12 +565,7 @@ export default function (self) {
|
|
|
656
565
|
if (self.attributes.showFilter && isNormalCell) {
|
|
657
566
|
createFilterContextMenuItems(e);
|
|
658
567
|
}
|
|
659
|
-
if (
|
|
660
|
-
self.attributes.showCopy &&
|
|
661
|
-
self.selections.reduce(function (p, r) {
|
|
662
|
-
return p + r.length;
|
|
663
|
-
}, 0) > 0
|
|
664
|
-
) {
|
|
568
|
+
if (self.attributes.showCopy && self.canSelectionsBeCopied()) {
|
|
665
569
|
e.items.push({
|
|
666
570
|
title: self.attributes.copyText,
|
|
667
571
|
click: function () {
|
|
@@ -675,7 +579,11 @@ export default function (self) {
|
|
|
675
579
|
e.items.push({
|
|
676
580
|
title: self.attributes.pasteText,
|
|
677
581
|
click: function () {
|
|
678
|
-
|
|
582
|
+
// Original function call:
|
|
583
|
+
// self.paste(self.clipBoardData, e.cell.columnIndex, e.cell.rowIndex);
|
|
584
|
+
// We can remove the last two parameters follow
|
|
585
|
+
// because this function only need one parameter by following the function declaration
|
|
586
|
+
self.paste(self.clipBoardData);
|
|
679
587
|
self.draw();
|
|
680
588
|
},
|
|
681
589
|
});
|
|
@@ -720,7 +628,7 @@ export default function (self) {
|
|
|
720
628
|
const columnOrderIndex = e.cell.columnIndex;
|
|
721
629
|
const columnIndex = self.orders.columns[columnOrderIndex];
|
|
722
630
|
|
|
723
|
-
const contiguousColumns = getSelectedContiguousColumns(
|
|
631
|
+
const contiguousColumns = self.getSelectedContiguousColumns(schema);
|
|
724
632
|
let title = '';
|
|
725
633
|
if (contiguousColumns) {
|
|
726
634
|
title = contiguousColumns
|
|
@@ -809,7 +717,7 @@ export default function (self) {
|
|
|
809
717
|
//#region hide rows
|
|
810
718
|
const canHideRows = !isSorting && e.cell.isRowHeader && e.cell.header;
|
|
811
719
|
if (canHideRows) {
|
|
812
|
-
const range = getSelectedContiguousRows(true);
|
|
720
|
+
const range = self.getSelectedContiguousRows(true);
|
|
813
721
|
if (range) {
|
|
814
722
|
const boundRowIndexes = range.map((viewRowIndex) =>
|
|
815
723
|
self.getBoundRowIndexFromViewRowIndex(viewRowIndex),
|
|
@@ -1009,7 +917,7 @@ export default function (self) {
|
|
|
1009
917
|
}
|
|
1010
918
|
}
|
|
1011
919
|
if (canGroupByRows) {
|
|
1012
|
-
const range = getSelectedContiguousRows(false) || [];
|
|
920
|
+
const range = self.getSelectedContiguousRows(false) || [];
|
|
1013
921
|
const rangeTitle = range
|
|
1014
922
|
.map((rowIndex) => {
|
|
1015
923
|
const index = self.getBoundRowIndexFromViewRowIndex(rowIndex);
|