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/dist/types.d.ts CHANGED
@@ -66,6 +66,8 @@
66
66
  * @param [args.autoScrollMargin = 5] - Number of pixels of mouse movement to trigger auto scroll.
67
67
  * @param [args.allowFreezingRows = false] - When true, the UI provides a drag-able cutter to freeze rows.
68
68
  * @param [args.allowFreezingColumns = false] - When true, the UI provides a drag-able cutter to freeze columns.
69
+ * @param [args.allowShrinkingSelection = false] - When true, this allows users to shrink the selection by dragging and dropping the handle inwards, similar to Excel. (Not supported yet.)
70
+ * @param [args.clearCellsWhenShrinkingSelection = false] - When true, this allows the clearing of the previously selected cells after the handle is moved inwards. (Not supported yet.)
69
71
  * @param [args.filterFrozenRows = true] - When false, rows on and above {@link canvasDatagrid#property:frozenRow}` will be ignored by filters when {@link canvasDatagrid#param:allowFreezingRows} is true.
70
72
  * @param [args.sortFrozenRows = true] - When false, rows on and above {@link canvasDatagrid#property:frozenRow}` will be ignored by sorters when {@link canvasDatagrid#param:allowSorting} is true.
71
73
  * @param [args.allowColumnReordering = true] - When true columns can be reordered.
@@ -117,6 +119,7 @@
117
119
  * @param [args.rowGroupIndicatorPosition = 'bottom'] - Ths position of the row group indicator(icon), available values: 'top' and 'bottom'.
118
120
  * @param [args.showOrderByOption = true] - Show an option on the context menu sort rows.
119
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.
120
123
  * @param [args.schema = []] - Sets the schema. See {@link canvasDatagrid.schema}.
121
124
  * @param [args.data = []] - Sets the data. See {@link canvasDatagrid.data}.
122
125
  * @param [args.touchReleaseAnimationDurationMs = 2000] - How long the ease animation runs after touch release.
@@ -128,7 +131,7 @@
128
131
  * @param [args.copyText = Copy] - The text that appears on the context menu when copy is available.
129
132
  * @param [args.columnHeaderClickBehavior = sort] - Can be any of sort, select, none. When sort is selected, left clicking a column header will result in sorting ascending, then sorting descending if already sorted by this column. If select is selected then clicking a column header will result in the column becoming selected. Holding control/command or shift will select multiple columns in this mode.
130
133
  * @param [args.scrollPointerLock = false] - When true, clicking on the scroll box to scroll will cause the mouse cursor to disappear to prevent it from exiting the area observable to the grid.
131
- * @param [args.selectionHandleBehavior = 'none'] - When set to a value other than none a handle will appear in the lower right corner of the desktop version of the grid. It does nothing but will be used in a future version of the grid.
134
+ * @param [args.selectionHandleBehavior = 'none'] - When set to a value other than none, a handle will appear in the lower right corner of the desktop version of the grid.
132
135
  * @param [args.columnSelectorVisibleText = '  &nbsp '] - When a column is hidden, this is the value to the left of the title in the column selector content menu.
133
136
  * @param [args.columnSelectorHiddenText = '\u2713'] - When a column is visible, this is the value to the left of the title in the column selector content menu.
134
137
  * @param [args.columnSelectorText = 'Add/remove columns'] - The text of the column selector context menu.
@@ -143,6 +146,7 @@
143
146
  * @param [args.touchZoomMin = 0.5] - The minimum zoom scale.
144
147
  * @param [args.touchZoomMax = 1.75] - The maximum zoom scale.
145
148
  * @param [args.maxPixelRatio = 1.5] - The maximum pixel ratio for high DPI displays. High DPI displays can cause sluggish performance, this caps resolution the grid is rendered at. Standard resolution (e.g.: 1920x1080) have a pixel ratio of 1:1 while higher resolution displays can be higher (e.g.: Retina display 2:1). Higher numbers are sharper (higher resolution) up to the max of your display (usually 2), lower numbers are lower resolution, down to 1. It might be fun to set a value lower than 1, I've never done it.
149
+ * @param [args.fillCellCallback] - The callback function that is called when a cell is filled.
146
150
  * @param [args.style = {}] - Sets selected values in style.
147
151
  * @param [args.filters = {}] - Sets selected values in filters. See {@link canvasDatagrid.filters}.
148
152
  * @param [args.sorters = {}] - Sets selected values in sorters. See {@link canvasDatagrid.sorters}.
@@ -169,6 +173,8 @@ declare class canvasDatagrid {
169
173
  autoScrollMargin?: number;
170
174
  allowFreezingRows?: boolean;
171
175
  allowFreezingColumns?: boolean;
176
+ allowShrinkingSelection?: boolean;
177
+ clearCellsWhenShrinkingSelection?: boolean;
172
178
  filterFrozenRows?: boolean;
173
179
  sortFrozenRows?: boolean;
174
180
  allowColumnReordering?: boolean;
@@ -220,6 +226,7 @@ declare class canvasDatagrid {
220
226
  rowGroupIndicatorPosition?: string;
221
227
  showOrderByOption?: boolean;
222
228
  showPaste?: boolean;
229
+ resizeAfterDragged?: boolean;
223
230
  schema?: any[];
224
231
  data?: any[];
225
232
  touchReleaseAnimationDurationMs?: number;
@@ -246,6 +253,7 @@ declare class canvasDatagrid {
246
253
  touchZoomMin?: number;
247
254
  touchZoomMax?: number;
248
255
  maxPixelRatio?: number;
256
+ fillCellCallback?: any;
249
257
  style?: canvasDatagrid.style;
250
258
  filters?: canvasDatagrid.filter;
251
259
  sorters?: canvasDatagrid.sorter;
@@ -453,48 +461,6 @@ declare class canvasDatagrid {
453
461
  * @param y - The row index of the cell to set active.
454
462
  */
455
463
  static setActiveCell(x: number, y: number): void;
456
- /**
457
- * Removes the selection.
458
- * @param dontDraw - Suppress the draw method after the selection change.
459
- */
460
- static selectNone(dontDraw: boolean): void;
461
- /**
462
- * Selects every visible cell.
463
- * @param dontDraw - Suppress the draw method after the selection change.
464
- */
465
- static selectAll(dontDraw: boolean): void;
466
- /**
467
- * Returns true if the selected columnIndex is selected on every row.
468
- * @param columnIndex - The column index to check.
469
- */
470
- static isColumnSelected(columnIndex: number): void;
471
- /**
472
- * Returns true if the selected rowIndex is selected on every column.
473
- * @param rowIndex - The row index to check.
474
- */
475
- static isRowSelected(rowIndex: number): void;
476
- /**
477
- * Runs the defined method on each selected cell.
478
- * @param fn - The function to execute. The signature of the function is: (data, rowIndex, columnName).
479
- * @param expandToRow - When true the data in the array is expanded to the entire row.
480
- */
481
- static forEachSelectedCell(fn: number, expandToRow: number): void;
482
- /**
483
- * Selects a column.
484
- * @param columnIndex - The column index to select.
485
- * @param toggleSelectMode - When true, behaves as if you were holding control/command when you clicked the column.
486
- * @param shift - When true, behaves as if you were holding shift when you clicked the column.
487
- * @param supressSelectionchangedEvent - When true, prevents the selectionchanged event from firing.
488
- */
489
- static selectColumn(columnIndex: number, toggleSelectMode: boolean, shift: boolean, supressSelectionchangedEvent: boolean): void;
490
- /**
491
- * Selects a row.
492
- * @param rowIndex - The row index to select.
493
- * @param ctrl - When true, behaves as if you were holding control/command when you clicked the row.
494
- * @param shift - When true, behaves as if you were holding shift when you clicked the row.
495
- * @param supressSelectionchangedEvent - When true, prevents the selectionchanged event from firing.
496
- */
497
- static selectRow(rowIndex: number, ctrl: boolean, shift: boolean, supressSelectionchangedEvent: boolean): void;
498
464
  /**
499
465
  * Collapse a tree grid by row index.
500
466
  * @param index - The index of the row to collapse.
@@ -518,18 +484,26 @@ declare class canvasDatagrid {
518
484
  static getHeaderByName(name: string): header;
519
485
  /**
520
486
  * Hide column/columns
487
+ * @param beginColumnOrderIndex - The begin column order index
488
+ * @param [endColumnOrderIndex] - The end column order index
521
489
  */
522
490
  static hideColumns(beginColumnOrderIndex: number, endColumnOrderIndex?: number): void;
523
491
  /**
524
492
  * Unihde column/columns
493
+ * @param beginColumnOrderIndex - The begin column order index
494
+ * @param [endColumnOrderIndex] - The end column order index
525
495
  */
526
496
  static unhideColumns(beginColumnOrderIndex: number, endColumnOrderIndex?: number): void;
527
497
  /**
528
498
  * Hide rows
499
+ * @param beginRowIndex - The begin row index
500
+ * @param endRowIndex - The end row index
529
501
  */
530
502
  static hideRows(beginRowIndex: number, endRowIndex: number): void;
531
503
  /**
532
504
  * Unhide rows
505
+ * @param beginRowIndex - The begin row index
506
+ * @param endRowIndex - The end row index
533
507
  */
534
508
  static unhideRows(beginRowIndex: number, endRowIndex: number): void;
535
509
  /**
@@ -589,17 +563,6 @@ declare class canvasDatagrid {
589
563
  * @param rowIndexTo - The row index which is the end of the group
590
564
  */
591
565
  static toggleGroupRows(rowIndexFrom: number, rowIndexTo: number): void;
592
- /**
593
- * Moves the current selection relative to the its current position. Note: this method does not move the selected data, just the selection itself.
594
- * @param offsetX - The number of columns to offset the selection.
595
- * @param offsetY - The number of rows to offset the selection.
596
- */
597
- static moveSelection(offsetX: number, offsetY: number): void;
598
- /**
599
- * Deletes currently selected data.
600
- * @param dontDraw - Suppress the draw method after the selection change.
601
- */
602
- static deleteSelectedData(dontDraw: boolean): void;
603
566
  /**
604
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.
605
568
  * @param sel - 2D array representing selected rows and columns. `canvasDatagrid.selections` is in this format and can be used here.
@@ -661,11 +624,6 @@ declare class canvasDatagrid {
661
624
  * @returns cell at the selected location.
662
625
  */
663
626
  static getCellAt(x: number, y: number): cell;
664
- /**
665
- * Gets the bounds of current selection.
666
- * @returns selection.
667
- */
668
- static getSelectionBounds(): rect;
669
627
  /**
670
628
  * Returns an auto generated schema based on data structure.
671
629
  * @returns schema A schema based on the first item in the data array.
@@ -677,11 +635,6 @@ declare class canvasDatagrid {
677
635
  * track of changes made to the data since last this method was called.
678
636
  */
679
637
  static clearChangeLog(): void;
680
- /**
681
- * Selects an area of the grid.
682
- * @param bounds - A rect object representing the selected values.
683
- */
684
- static selectArea(bounds: rect): void;
685
638
  /**
686
639
  * Returns the maximum text width for a given column by column name.
687
640
  * @param name - The name of the column to calculate the value's width of.
@@ -702,6 +655,74 @@ declare class canvasDatagrid {
702
655
  * @param columnIndex - The column index to lookup.
703
656
  */
704
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;
705
726
  /**
706
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.
707
728
  */
@@ -1191,8 +1212,8 @@ declare namespace canvasDatagrid {
1191
1212
  * @property [activeCellSelectedBackgroundColor = rgba(236, 243, 255, 1)] - Style of activeCellSelectedBackgroundColor.
1192
1213
  * @property [activeCellSelectedColor = rgba(0, 0, 0, 1)] - Style of activeCellSelectedColor.
1193
1214
  * @property [activeCellVerticalAlignment = center] - Style of activeCellVerticalAlignment.
1194
- * @property [activeHeaderCellBackgroundColor = rgba(225, 225, 225, 1)] - Style of activeHeaderCellBackgroundColor.
1195
- * @property [activeHeaderCellColor = rgba(0, 0, 0, 1)] - Style of activeHeaderCellColor.
1215
+ * @property [activeColumnHeaderCellBackgroundColor = rgba(225, 225, 225, 1)] - Style of activeColumnHeaderCellBackgroundColor.
1216
+ * @property [activeColumnHeaderCellColor = rgba(0, 0, 0, 1)] - Style of activeColumnHeaderCellColor.
1196
1217
  * @property [activeRowHeaderCellBackgroundColor = rgba(225, 225, 225, 1)] - Style of activeRowHeaderCellBackgroundColor.
1197
1218
  * @property [activeRowHeaderCellColor = rgba(0, 0, 0, 1)] - Style of activeRowHeaderCellColor.
1198
1219
  * @property [autocompleteBottomMargin = 60] - Style of autocompleteBottomMargin.
@@ -1278,6 +1299,8 @@ declare namespace canvasDatagrid {
1278
1299
  * @property [editCellColor = black] - Style of editCellColor.
1279
1300
  * @property [editCellBackgroundColor = white] - Style of editCellBackgroundColor.
1280
1301
  * @property [editCellZIndex = 10000] - Style of editCellZIndex.
1302
+ * @property [fillOverlayBorderColor = rgba(127, 127, 127, 1)] - Style of fillOverlayBorderColor.
1303
+ * @property [fillOverlayBorderWidth = 2] - Style of fillOverlayBorderWidth.
1281
1304
  * @property [gridBackgroundColor = rgba(240, 240, 240, 1)] - Style of gridBackgroundColor.
1282
1305
  * @property [gridBorderColor = rgba(202, 202, 202, 1)] - Style of gridBorderColor.
1283
1306
  * @property [gridBorderWidth = 1] - Style of gridBorderWidth.
@@ -1317,6 +1340,8 @@ declare namespace canvasDatagrid {
1317
1340
  * @property [reorderMarkerBorderWidth = 1.25] - Style of reorderMarkerBorderWidth.
1318
1341
  * @property [reorderMarkerIndexBorderColor = rgba(66, 133, 244, 1)] - Style of reorderMarkerIndexBorderColor.
1319
1342
  * @property [reorderMarkerIndexBorderWidth = 2.75] - Style of reorderMarkerIndexBorderWidth.
1343
+ * @property [resizeMarkerColor = rgba(0, 0, 0, 0.2)] - Style of resizeMarkerColor.
1344
+ * @property [resizeMarkerSize = 2] - Style of resizeMarkerSize.
1320
1345
  * @property [rowGroupColumnWidth = 25] - Style of rowGroupColumnWidth.
1321
1346
  * @property [rowHeaderCellBackgroundColor = rgba(240, 240, 240, 1)] - Style of rowHeaderCellBackgroundColor.
1322
1347
  * @property [rowHeaderCellBorderColor = rgba(152, 152, 152, 1)] - Style of rowHeaderCellBorderColor.
@@ -1449,13 +1474,13 @@ declare namespace canvasDatagrid {
1449
1474
  */
1450
1475
  activeCellVerticalAlignment?: string;
1451
1476
  /**
1452
- * Style of activeHeaderCellBackgroundColor.
1477
+ * Style of activeColumnHeaderCellBackgroundColor.
1453
1478
  */
1454
- activeHeaderCellBackgroundColor?: string;
1479
+ activeColumnHeaderCellBackgroundColor?: string;
1455
1480
  /**
1456
- * Style of activeHeaderCellColor.
1481
+ * Style of activeColumnHeaderCellColor.
1457
1482
  */
1458
- activeHeaderCellColor?: string;
1483
+ activeColumnHeaderCellColor?: string;
1459
1484
  /**
1460
1485
  * Style of activeRowHeaderCellBackgroundColor.
1461
1486
  */
@@ -1796,6 +1821,14 @@ declare namespace canvasDatagrid {
1796
1821
  * Style of editCellZIndex.
1797
1822
  */
1798
1823
  editCellZIndex?: number;
1824
+ /**
1825
+ * Style of fillOverlayBorderColor.
1826
+ */
1827
+ fillOverlayBorderColor?: string;
1828
+ /**
1829
+ * Style of fillOverlayBorderWidth.
1830
+ */
1831
+ fillOverlayBorderWidth?: number;
1799
1832
  /**
1800
1833
  * Style of gridBackgroundColor.
1801
1834
  */
@@ -1952,6 +1985,14 @@ declare namespace canvasDatagrid {
1952
1985
  * Style of reorderMarkerIndexBorderWidth.
1953
1986
  */
1954
1987
  reorderMarkerIndexBorderWidth?: number;
1988
+ /**
1989
+ * Style of resizeMarkerColor.
1990
+ */
1991
+ resizeMarkerColor?: string;
1992
+ /**
1993
+ * Style of resizeMarkerSize.
1994
+ */
1995
+ resizeMarkerSize?: number;
1955
1996
  /**
1956
1997
  * Style of rowGroupColumnWidth.
1957
1998
  */
@@ -2215,3 +2256,187 @@ declare namespace canvasDatagrid {
2215
2256
  */
2216
2257
  declare function mergeHiddenRowRanges(hiddenRowRanges: any[], newRange: number[]): boolean;
2217
2258
 
2259
+ /**
2260
+ * Swap values between two properties in an object
2261
+ * @param obj - The object
2262
+ * @param prop0 - First property name
2263
+ * @param prop1 - Another property name
2264
+ */
2265
+ declare function swapProps(obj: any, prop0: string, prop1: string): void;
2266
+
2267
+ /**
2268
+ * This function transforms a selection object to normalized.
2269
+ * Here is the definition of **normalized selection object**:
2270
+ * - It contains these required properties: type, startRow, startColumn, endRow, endColumn
2271
+ * - Property `endRow` and property `endColumn` must exist even if their value are the same with `startRow` or `startColumn`.
2272
+ * - The value of `endRow` must be equals or greater than the value of `startRow`
2273
+ * - The value of `endColumn` must be equals or greater than the value of `startColumn`
2274
+ */
2275
+ declare function normalizeSelection(sel: SelectionDescriptor): SelectionDescriptor;
2276
+
2277
+ /**
2278
+ * Parse a string expression to a selection object. Here are some example expressions:
2279
+ * - cells:20,30-40,50
2280
+ * - row:5
2281
+ * - cols:5-9
2282
+ */
2283
+ declare function getSelectionFromString(str: string): SelectionDescriptor;
2284
+
2285
+ /**
2286
+ * Check are two cells block the same
2287
+ */
2288
+ declare function isSameCellsBlock(block0: SelectionDescriptor, block1: SelectionDescriptor): boolean;
2289
+
2290
+ /**
2291
+ * This function is used in the function `mergeSelections`
2292
+ */
2293
+ declare function mergeCellsIntoRowsOrColumns(cells: SelectionDescriptor, rowsOrColumns: SelectionDescriptor): SelectionDescriptor;
2294
+
2295
+ /**
2296
+ * Merge two selection objects (Splicing, Containing)
2297
+ * @returns A concatenated selection object based on `block0`.
2298
+ * Or `undefined` if they can't be concatenated
2299
+ */
2300
+ declare function mergeSelections(sel0: SelectionDescriptor, sel1: SelectionDescriptor): SelectionDescriptor;
2301
+
2302
+ /**
2303
+ * Remove some rows from a rows selection
2304
+ * @param selection - It must be a selection with type as `Rows`
2305
+ * @param remove - It must be a selection with type as `Rows`
2306
+ * @returns Returning a `undefined` represents parameter `remove` doesn't intersect with parameter `selection`
2307
+ */
2308
+ declare function removePartOfRowsSelection(selection: SelectionDescriptor, remove: SelectionDescriptor): SelectionDescriptor[];
2309
+
2310
+ /**
2311
+ * Remove some columns from a columns selection
2312
+ * @param selection - It must be a selection with type as `Columns`
2313
+ * @param remove - It must be a selection with type as `Columns`
2314
+ * @returns Returning a `undefined` represents parameter `remove` doesn't intersect with parameter `selection`
2315
+ */
2316
+ declare function removePartOfColumnsSelection(selection: any, remove: any): object[];
2317
+
2318
+ /**
2319
+ * Remove a cells block from a cells selection
2320
+ * @param selection - It must be a selection with type as `Cells` or `UnselectedCells`
2321
+ * @param remove - It must be a selection
2322
+ * @returns Returning a `undefined` represents parameter `remove` doesn't intersect with parameter `selection`
2323
+ */
2324
+ declare function removePartOfCellsSelection(selection: SelectionDescriptor, remove: SelectionDescriptor): SelectionDescriptor[];
2325
+
2326
+ /**
2327
+ * Get intersection of two selection object
2328
+ * @returns a selection object or undefined
2329
+ */
2330
+ declare function getIntersection(sel0: SelectionDescriptor, sel1: SelectionDescriptor): SelectionDescriptor;
2331
+
2332
+ /**
2333
+ * Add a selection object into `selections` array. And there are two behaviours if this function:
2334
+ * - It appends a new selection object into the `selections` array
2335
+ * - It rewrites the selection item in the `selections` array (merge or change its type)
2336
+ * @param add - Supported types: Cells, Rows, Columns
2337
+ * @param [context] - Eg: {rows:1000, columns:1000}
2338
+ * @returns is the selections array changed
2339
+ */
2340
+ declare function addIntoSelections(selections: SelectionDescriptor[], add: SelectionDescriptor, context?: ContextForSelectionAction): boolean;
2341
+
2342
+ /**
2343
+ * Remove a selection area from `selections` array
2344
+ * @param remove - Supported types: Cells, Rows, Columns
2345
+ * @param [context] - Eg: {rows:1000, columns:1000}
2346
+ * @returns is the selections array changed
2347
+ */
2348
+ declare function removeFromSelections(selections: SelectionDescriptor[], remove: SelectionDescriptor, context?: ContextForSelectionAction): boolean;
2349
+
2350
+ /**
2351
+ * Clean up a selections array.
2352
+ * This function removes unnecessary selection object, and it tries to merge different selections.
2353
+ */
2354
+ declare function cleanupSelections(selections: SelectionDescriptor[]): void;
2355
+
2356
+ /**
2357
+ * Check if all cells in a given row selected
2358
+ */
2359
+ declare function isRowSelected(selections: SelectionDescriptor[], rowIndex: number): void;
2360
+
2361
+ /**
2362
+ * Check if all cells in a given column selected
2363
+ */
2364
+ declare function isColumnSelected(selections: SelectionDescriptor[], columnIndex: number): void;
2365
+
2366
+ /**
2367
+ * Check if a given cell selected
2368
+ */
2369
+ declare function isCellSelected(selections: SelectionDescriptor[], rowIndex: number, columnIndex: number): void;
2370
+
2371
+ /**
2372
+ * Check if all given cells selected
2373
+ * @param range - the range of cells block
2374
+ */
2375
+ declare function areAllCellsSelected(selections: SelectionDescriptor[], range: RangeDescriptor): boolean;
2376
+
2377
+ /**
2378
+ * Get selection state from cells
2379
+ * @returns Returning `true` means all given cells are selected,
2380
+ * Returning `false` means all given cells are not selected.
2381
+ * Returning a two-dimensional array means some cells are selected and some cells are not selected.
2382
+ * A reference for returned value: `state[rowIndex - range.startRow][colIndex - range.startColumn]`
2383
+ */
2384
+ declare function getSelectionStateFromCells(selections: SelectionDescriptor[], range: RangeDescriptor): boolean | boolean[][];
2385
+
2386
+ /**
2387
+ * Get verbose selection state from cells.
2388
+ * (`verbose` in here means that you can locate particular selection for selected cells)
2389
+ * @returns Each item in this two-dimensional array is 0 or a positive int,
2390
+ * it represents the index of matched selection plus 1 if it is a positive int.
2391
+ * And if the value of item is 0, it means this cell is not selected.
2392
+ * A reference for returned value: `state[rowIndex - range.startRow][colIndex - range.startColumn]`
2393
+ */
2394
+ declare function getVerboseSelectionStateFromCells(selections: SelectionDescriptor[], range: RangeDescriptor): number[][];
2395
+
2396
+ /**
2397
+ * Check if any contiguous columns are selected.
2398
+ * (This function is useful for the preconditions for actions on columns, Eg: grouping, hiding)
2399
+ * @param allowImpurity - This function ignores other selected rows/cells if its value is `true`
2400
+ * @returns a tuple [beginViewColumnIndex, endViewColumnIndex] or `undefined`
2401
+ */
2402
+ declare function getSelectedContiguousColumns(selections: SelectionDescriptor[], allowImpurity: boolean): number[];
2403
+
2404
+ /**
2405
+ * Check if any contiguous rows are selected.
2406
+ * (This function is useful for the preconditions for actions on rows, Eg: grouping, hiding)
2407
+ * @param allowImpurity - This function ignores other selected columns/cells if its value is `true`
2408
+ * @returns a tuple [beginRowOrderIndex, endRowOrderIndex] or `undefined`
2409
+ */
2410
+ declare function getSelectedContiguousRows(selections: SelectionDescriptor[], allowImpurity: boolean): number[];
2411
+
2412
+ /**
2413
+ * Check if current selections are complex.
2414
+ * How we defined "complex" in here:
2415
+ * - There are any unselected cells in selected rows/columns
2416
+ * - More than one selection type in current selections
2417
+ */
2418
+ declare function areSelectionsComplex(selections: SelectionDescriptor[]): boolean;
2419
+
2420
+ /**
2421
+ * Check if current selections are neat.
2422
+ * This method is used for make new API are compatible with obsolete API
2423
+ * For example:
2424
+ * - Selected like <0,0-10,10> or rows<5-10> is neat
2425
+ * - Selected like <0,0-10,10>&<11,1-11,10> is untidy
2426
+ * @param selections - selections after clean up
2427
+ */
2428
+ declare function areSelectionsNeat(selections: SelectionDescriptor[]): boolean;
2429
+
2430
+ declare function moveSelections(selections: SelectionDescriptor[], offsetX: number, offsetY: number): void;
2431
+
2432
+ declare function cloneSelections(selections: SelectionDescriptor[]): SelectionDescriptor[];
2433
+
2434
+ declare function getSelectionBounds(selections: SelectionDescriptor[]): RectangleObject;
2435
+
2436
+ /**
2437
+ * @param cell - Signature: `{rowIndex:number;columnIndex:number}`
2438
+ * @param keyEvent - Signature: `{key:string;shiftKey:boolean}`
2439
+ * @param context - Signature: `{columns:number;rows:number}`
2440
+ */
2441
+ declare function shrinkOrExpandSelections(selections: SelectionDescriptor[], cell: any, keyEvent: any, context: any): boolean;
2442
+
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 = defs.defaults.styles;
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 === '') {
@@ -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
- self.paste(self.clipBoardData, e.cell.columnIndex, e.cell.rowIndex);
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(e, schema);
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);