canvas-datagrid 0.4.5 → 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
@@ -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 [activeHeaderCellBackgroundColor = rgba(225, 225, 225, 1)] - Style of activeHeaderCellBackgroundColor.
1209
- * @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.
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.
@@ -1333,6 +1340,8 @@ declare namespace canvasDatagrid {
1333
1340
  * @property [reorderMarkerBorderWidth = 1.25] - Style of reorderMarkerBorderWidth.
1334
1341
  * @property [reorderMarkerIndexBorderColor = rgba(66, 133, 244, 1)] - Style of reorderMarkerIndexBorderColor.
1335
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.
1336
1345
  * @property [rowGroupColumnWidth = 25] - Style of rowGroupColumnWidth.
1337
1346
  * @property [rowHeaderCellBackgroundColor = rgba(240, 240, 240, 1)] - Style of rowHeaderCellBackgroundColor.
1338
1347
  * @property [rowHeaderCellBorderColor = rgba(152, 152, 152, 1)] - Style of rowHeaderCellBorderColor.
@@ -1465,13 +1474,13 @@ declare namespace canvasDatagrid {
1465
1474
  */
1466
1475
  activeCellVerticalAlignment?: string;
1467
1476
  /**
1468
- * Style of activeHeaderCellBackgroundColor.
1477
+ * Style of activeColumnHeaderCellBackgroundColor.
1469
1478
  */
1470
- activeHeaderCellBackgroundColor?: string;
1479
+ activeColumnHeaderCellBackgroundColor?: string;
1471
1480
  /**
1472
- * Style of activeHeaderCellColor.
1481
+ * Style of activeColumnHeaderCellColor.
1473
1482
  */
1474
- activeHeaderCellColor?: string;
1483
+ activeColumnHeaderCellColor?: string;
1475
1484
  /**
1476
1485
  * Style of activeRowHeaderCellBackgroundColor.
1477
1486
  */
@@ -1976,6 +1985,14 @@ declare namespace canvasDatagrid {
1976
1985
  * Style of reorderMarkerIndexBorderWidth.
1977
1986
  */
1978
1987
  reorderMarkerIndexBorderWidth?: number;
1988
+ /**
1989
+ * Style of resizeMarkerColor.
1990
+ */
1991
+ resizeMarkerColor?: string;
1992
+ /**
1993
+ * Style of resizeMarkerSize.
1994
+ */
1995
+ resizeMarkerSize?: number;
1979
1996
  /**
1980
1997
  * Style of rowGroupColumnWidth.
1981
1998
  */
@@ -2239,3 +2256,187 @@ declare namespace canvasDatagrid {
2239
2256
  */
2240
2257
  declare function mergeHiddenRowRanges(hiddenRowRanges: any[], newRange: number[]): boolean;
2241
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);
package/lib/defaults.js CHANGED
@@ -61,6 +61,7 @@ export default function (self) {
61
61
  ['persistantSelectionMode', false],
62
62
  ['removeFilterOptionText', 'Remove filter on %s'],
63
63
  ['reorderDeadZone', 3],
64
+ ['resizeAfterDragged', false],
64
65
  ['resizeScrollZone', 20],
65
66
  ['rowGrabZoneSize', 5],
66
67
  ['columnGrabZoneSize', 30],
@@ -336,6 +337,8 @@ export default function (self) {
336
337
  ['reorderMarkerBorderWidth', 1.25],
337
338
  ['reorderMarkerIndexBorderColor', 'rgba(66, 133, 244, 1)'],
338
339
  ['reorderMarkerIndexBorderWidth', 2.75],
340
+ ['resizeMarkerColor', 'rgba(0, 0, 0, 0.2)'],
341
+ ['resizeMarkerSize', 2],
339
342
  ['rowGroupColumnWidth', 25],
340
343
  ['rowHeaderCellBackgroundColor', 'rgba(240, 240, 240, 1)'],
341
344
  ['rowHeaderCellBorderColor', 'rgba(200, 200, 200, 1)'],
package/lib/docs.js CHANGED
@@ -82,6 +82,7 @@
82
82
  * @param {string} [args.rowGroupIndicatorPosition='bottom'] - Ths position of the row group indicator(icon), available values: 'top' and 'bottom'.
83
83
  * @param {boolean} [args.showOrderByOption=true] - Show an option on the context menu sort rows.
84
84
  * @param {boolean} [args.showPaste=false] - Show the paste option in the context menu when applicable.
85
+ * @param {boolean} [args.resizeAfterDragged] - Resize after the handle is dropped, similar to Excel.
85
86
  * @param {array} [args.schema=[]] - Sets the schema. See {@link canvasDatagrid.schema}.
86
87
  * @param {array} [args.data=[]] - Sets the data. See {@link canvasDatagrid.data}.
87
88
  * @param {number} [args.touchReleaseAnimationDurationMs=2000] - How long the ease animation runs after touch release.
@@ -306,8 +307,8 @@
306
307
  * @property {string} [activeCellSelectedBackgroundColor=rgba(236, 243, 255, 1)] - Style of activeCellSelectedBackgroundColor.
307
308
  * @property {string} [activeCellSelectedColor=rgba(0, 0, 0, 1)] - Style of activeCellSelectedColor.
308
309
  * @property {string} [activeCellVerticalAlignment=center] - Style of activeCellVerticalAlignment.
309
- * @property {string} [activeHeaderCellBackgroundColor=rgba(225, 225, 225, 1)] - Style of activeHeaderCellBackgroundColor.
310
- * @property {string} [activeHeaderCellColor=rgba(0, 0, 0, 1)] - Style of activeHeaderCellColor.
310
+ * @property {string} [activeColumnHeaderCellBackgroundColor=rgba(225, 225, 225, 1)] - Style of activeColumnHeaderCellBackgroundColor.
311
+ * @property {string} [activeColumnHeaderCellColor=rgba(0, 0, 0, 1)] - Style of activeColumnHeaderCellColor.
311
312
  * @property {string} [activeRowHeaderCellBackgroundColor=rgba(225, 225, 225, 1)] - Style of activeRowHeaderCellBackgroundColor.
312
313
  * @property {string} [activeRowHeaderCellColor=rgba(0, 0, 0, 1)] - Style of activeRowHeaderCellColor.
313
314
  * @property {number} [autocompleteBottomMargin=60] - Style of autocompleteBottomMargin.
@@ -434,6 +435,8 @@
434
435
  * @property {number} [reorderMarkerBorderWidth=1.25] - Style of reorderMarkerBorderWidth.
435
436
  * @property {string} [reorderMarkerIndexBorderColor=rgba(66, 133, 244, 1)] - Style of reorderMarkerIndexBorderColor.
436
437
  * @property {number} [reorderMarkerIndexBorderWidth=2.75] - Style of reorderMarkerIndexBorderWidth.
438
+ * @property {string} [resizeMarkerColor=rgba(0, 0, 0, 0.2)] - Style of resizeMarkerColor.
439
+ * @property {number} [resizeMarkerSize=2] - Style of resizeMarkerSize.
437
440
  * @property {number} [rowGroupColumnWidth=25] - Style of rowGroupColumnWidth.
438
441
  * @property {string} [rowHeaderCellBackgroundColor=rgba(240, 240, 240, 1)] - Style of rowHeaderCellBackgroundColor.
439
442
  * @property {string} [rowHeaderCellBorderColor=rgba(152, 152, 152, 1)] - Style of rowHeaderCellBorderColor.
package/lib/dom.js CHANGED
@@ -755,6 +755,7 @@ export default function (self) {
755
755
  Object.keys(css[className]).map(function (prop) {
756
756
  el.style[prop] = css[className][prop];
757
757
  });
758
+ el.className = className;
758
759
  }
759
760
  return;
760
761
  };
@@ -803,7 +804,7 @@ export default function (self) {
803
804
  self.eventParent.addEventListener('mousedown', self.mousedown, false);
804
805
  self.eventParent.addEventListener('dblclick', self.dblclick, false);
805
806
  self.eventParent.addEventListener('click', self.click, false);
806
- window.addEventListener('mouseup', self.mouseup, false);
807
+ self.eventParent.addEventListener('mouseup', self.mouseup, false);
807
808
  window.addEventListener('mousemove', self.mousemove);
808
809
  self[self.isChildGrid ? 'parentGrid' : 'eventParent'].addEventListener(
809
810
  'wheel',