canvas-datagrid 0.4.4 → 0.4.5

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.
@@ -128,7 +130,7 @@
128
130
  * @param [args.copyText = Copy] - The text that appears on the context menu when copy is available.
129
131
  * @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
132
  * @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.
133
+ * @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
134
  * @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
135
  * @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
136
  * @param [args.columnSelectorText = 'Add/remove columns'] - The text of the column selector context menu.
@@ -143,6 +145,7 @@
143
145
  * @param [args.touchZoomMin = 0.5] - The minimum zoom scale.
144
146
  * @param [args.touchZoomMax = 1.75] - The maximum zoom scale.
145
147
  * @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.
148
+ * @param [args.fillCellCallback] - The callback function that is called when a cell is filled.
146
149
  * @param [args.style = {}] - Sets selected values in style.
147
150
  * @param [args.filters = {}] - Sets selected values in filters. See {@link canvasDatagrid.filters}.
148
151
  * @param [args.sorters = {}] - Sets selected values in sorters. See {@link canvasDatagrid.sorters}.
@@ -169,6 +172,8 @@ declare class canvasDatagrid {
169
172
  autoScrollMargin?: number;
170
173
  allowFreezingRows?: boolean;
171
174
  allowFreezingColumns?: boolean;
175
+ allowShrinkingSelection?: boolean;
176
+ clearCellsWhenShrinkingSelection?: boolean;
172
177
  filterFrozenRows?: boolean;
173
178
  sortFrozenRows?: boolean;
174
179
  allowColumnReordering?: boolean;
@@ -246,6 +251,7 @@ declare class canvasDatagrid {
246
251
  touchZoomMin?: number;
247
252
  touchZoomMax?: number;
248
253
  maxPixelRatio?: number;
254
+ fillCellCallback?: any;
249
255
  style?: canvasDatagrid.style;
250
256
  filters?: canvasDatagrid.filter;
251
257
  sorters?: canvasDatagrid.sorter;
@@ -518,18 +524,26 @@ declare class canvasDatagrid {
518
524
  static getHeaderByName(name: string): header;
519
525
  /**
520
526
  * Hide column/columns
527
+ * @param beginColumnOrderIndex - The begin column order index
528
+ * @param [endColumnOrderIndex] - The end column order index
521
529
  */
522
530
  static hideColumns(beginColumnOrderIndex: number, endColumnOrderIndex?: number): void;
523
531
  /**
524
532
  * Unihde column/columns
533
+ * @param beginColumnOrderIndex - The begin column order index
534
+ * @param [endColumnOrderIndex] - The end column order index
525
535
  */
526
536
  static unhideColumns(beginColumnOrderIndex: number, endColumnOrderIndex?: number): void;
527
537
  /**
528
538
  * Hide rows
539
+ * @param beginRowIndex - The begin row index
540
+ * @param endRowIndex - The end row index
529
541
  */
530
542
  static hideRows(beginRowIndex: number, endRowIndex: number): void;
531
543
  /**
532
544
  * Unhide rows
545
+ * @param beginRowIndex - The begin row index
546
+ * @param endRowIndex - The end row index
533
547
  */
534
548
  static unhideRows(beginRowIndex: number, endRowIndex: number): void;
535
549
  /**
@@ -1278,6 +1292,8 @@ declare namespace canvasDatagrid {
1278
1292
  * @property [editCellColor = black] - Style of editCellColor.
1279
1293
  * @property [editCellBackgroundColor = white] - Style of editCellBackgroundColor.
1280
1294
  * @property [editCellZIndex = 10000] - Style of editCellZIndex.
1295
+ * @property [fillOverlayBorderColor = rgba(127, 127, 127, 1)] - Style of fillOverlayBorderColor.
1296
+ * @property [fillOverlayBorderWidth = 2] - Style of fillOverlayBorderWidth.
1281
1297
  * @property [gridBackgroundColor = rgba(240, 240, 240, 1)] - Style of gridBackgroundColor.
1282
1298
  * @property [gridBorderColor = rgba(202, 202, 202, 1)] - Style of gridBorderColor.
1283
1299
  * @property [gridBorderWidth = 1] - Style of gridBorderWidth.
@@ -1796,6 +1812,14 @@ declare namespace canvasDatagrid {
1796
1812
  * Style of editCellZIndex.
1797
1813
  */
1798
1814
  editCellZIndex?: number;
1815
+ /**
1816
+ * Style of fillOverlayBorderColor.
1817
+ */
1818
+ fillOverlayBorderColor?: string;
1819
+ /**
1820
+ * Style of fillOverlayBorderWidth.
1821
+ */
1822
+ fillOverlayBorderWidth?: number;
1799
1823
  /**
1800
1824
  * Style of gridBackgroundColor.
1801
1825
  */
package/lib/defaults.js CHANGED
@@ -25,9 +25,11 @@ export default function (self) {
25
25
  ['autoResizeRows', false],
26
26
  ['autoScrollOnMousemove', false],
27
27
  ['autoScrollMargin', 5],
28
+ ['allowShrinkingSelection', false],
28
29
  ['blanksText', '(Blanks)'],
29
30
  ['borderDragBehavior', 'none'],
30
31
  ['borderResizeZone', 10],
32
+ ['clearCellsWhenShrinkingSelection', false],
31
33
  ['clearSettingsOptionText', 'Clear saved settings'],
32
34
  ['columnHeaderClickBehavior', 'sort'],
33
35
  ['columnSelectorHiddenText', '   '],
@@ -371,6 +373,8 @@ export default function (self) {
371
373
  ['selectionHandleColor', 'rgba(66, 133, 244, 1)'],
372
374
  ['selectionHandleSize', 8],
373
375
  ['selectionHandleType', 'square'],
376
+ ['fillOverlayBorderColor', 'rgba(127, 127, 127, 1)'],
377
+ ['fillOverlayBorderWidth', 2],
374
378
  ['selectionOverlayBorderColor', 'rgba(66, 133, 244, 1)'],
375
379
  ['selectionOverlayBorderWidth', 1],
376
380
  ['treeArrowBorderColor', 'rgba(195, 199, 202, 1)'],
package/lib/docs.js CHANGED
@@ -29,6 +29,8 @@
29
29
  * @param {number} [args.autoScrollMargin=5] - Number of pixels of mouse movement to trigger auto scroll.
30
30
  * @param {boolean} [args.allowFreezingRows=false] - When true, the UI provides a drag-able cutter to freeze rows.
31
31
  * @param {boolean} [args.allowFreezingColumns=false] - When true, the UI provides a drag-able cutter to freeze columns.
32
+ * @param {boolean} [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.)
33
+ * @param {boolean} [args.clearCellsWhenShrinkingSelection=false] - When true, this allows the clearing of the previously selected cells after the handle is moved inwards. (Not supported yet.)
32
34
  * @param {boolean} [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.
33
35
  * @param {boolean} [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.
34
36
  * @param {boolean} [args.allowColumnReordering=true] - When true columns can be reordered.
@@ -91,7 +93,7 @@
91
93
  * @param {string} [args.copyText=Copy] - The text that appears on the context menu when copy is available.
92
94
  * @param {string} [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.
93
95
  * @param {boolean} [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.
94
- * @param {string} [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.
96
+ * @param {string} [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.
95
97
  * @param {string} [args.columnSelectorVisibleText='  &nbsp '] - When a column is hidden, this is the value to the left of the title in the column selector content menu.
96
98
  * @param {string} [args.columnSelectorHiddenText='\u2713'] - When a column is visible, this is the value to the left of the title in the column selector content menu.
97
99
  * @param {string} [args.columnSelectorText='Add/remove columns'] - The text of the column selector context menu.
@@ -106,6 +108,7 @@
106
108
  * @param {number} [args.touchZoomMin=0.5] - The minimum zoom scale.
107
109
  * @param {number} [args.touchZoomMax=1.75] - The maximum zoom scale.
108
110
  * @param {number} [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.
111
+ * @param {object} [args.fillCellCallback] - The callback function that is called when a cell is filled.
109
112
  * @param {canvasDatagrid.style} [args.style={}] - Sets selected values in style.
110
113
  * @param {canvasDatagrid.filter} [args.filters={}] - Sets selected values in filters. See {@link canvasDatagrid.filters}.
111
114
  * @param {canvasDatagrid.sorter} [args.sorters={}] - Sets selected values in sorters. See {@link canvasDatagrid.sorters}.
@@ -256,6 +259,32 @@
256
259
  * @property {object} text.width - The width of the text, including truncation and ellipsis.
257
260
  * @property {object} text.value - The value of the text, including truncation and ellipsis.
258
261
  */
262
+ /**
263
+ * The additional function to invoke when a cell is filled. The return value of this
264
+ * function sets the new data of the cell.
265
+ * @function
266
+ * @name canvasDataGrid.fillCellCallback
267
+ * @param {object} args - Arguments that are passed to the function.
268
+ * @param {array} args.rows - Data that is being filled into all the cells, including this one.
269
+ * @param {string} args.direction - Direction of the fill operation, which can be 'horizontal' for x axis, 'vertical' for y axis, or 'both' when it goes both ways, e.g., when pasting unevenly.
270
+ * @param {object} args.newRowData - New row data that is going to replace 'existingRowData'. The result of this function will be kept in this object.
271
+ * @param {object} args.existingRowData - Existing data of the row. This will be replaced with 'newRowData'.
272
+ * @param {number} args.rowIndex - Index of the row on the grid.
273
+ * @param {number} args.rowOffset - Position/offset of 'cells' in 'rows'. Starts with '0'.
274
+ * @param {array} args.cells - New data for all the cells, including this one, for the current row. This is the same as accessing 'rows' using 'rowOffset'.
275
+ * @param {boolean} args.reversed - Whether the fill operation is applied in the reverse order, meaning if horizontal, we are going from right to left, and if vertical, we are going from bottom to top.
276
+ * @param {boolean} args.isFillingRow - Whether the current row is being filled. If the 'direction' is 'vertical', this will always be true, or sometimes true if the 'direction' is 'both'.
277
+ * @param {number} args.fillingRowPosition - Increase in position since the first filling of the rows. This will be '-1' if 'isFillingRow' is false. Starts with '0'.
278
+ * @param {number} args.fillingRowLength - Total length that 'fillingRowPosition' will go. This will be '-1' if 'isFillingRow' is false.
279
+ * @param {object} args.column - Column that this cell is on.
280
+ * @param {number} args.columnIndex - The index of the column on the grid.
281
+ * @param {string} args.newCellData - Data from 'cells' to be set for this cell. You can modify this and return the result to set the new data for this cell.
282
+ * @param {string} args.existingCellData - Existing data on this cell that is about to be replaced with the data you will return.
283
+ * @param {number} args.columnOffset - Position/offset of the 'newCellData' in 'cells'. Starts with '0'.
284
+ * @param {boolean} args.isFillingColumn - Whether the current column is being filled. If the 'direction' is 'horizontal', this will always be true, or sometimes true if the 'direction' is 'both'.
285
+ * @param {number} args.fillingColumnPosition - Increase in position since the first filling of the columns. This will be '-1' if 'isFillingColumn' is false. Starts with '0'.
286
+ * @param {number} args.fillingColumnLength - Total length that 'fillingColumnPosition' will go. This will be '-1' if 'isFillingColumn' is false.
287
+ */
259
288
  /**
260
289
  * Styles for the canvas data grid. Standard CSS styles still apply but are not listed here.
261
290
  * @class
@@ -364,6 +393,8 @@
364
393
  * @property {string} [editCellColor=black] - Style of editCellColor.
365
394
  * @property {string} [editCellBackgroundColor=white] - Style of editCellBackgroundColor.
366
395
  * @property {number} [editCellZIndex=10000] - Style of editCellZIndex.
396
+ * @property {string} [fillOverlayBorderColor=rgba(127, 127, 127, 1)] - Style of fillOverlayBorderColor.
397
+ * @property {number} [fillOverlayBorderWidth=2] - Style of fillOverlayBorderWidth.
367
398
  * @property {string} [gridBackgroundColor=rgba(240, 240, 240, 1)] - Style of gridBackgroundColor.
368
399
  * @property {string} [gridBorderColor=rgba(202, 202, 202, 1)] - Style of gridBorderColor.
369
400
  * @property {number} [gridBorderWidth=1] - Style of gridBorderWidth.
package/lib/draw.js CHANGED
@@ -943,13 +943,17 @@ export default function (self) {
943
943
  selectionHandles.push([cell, 'tr']);
944
944
  cell.selectionHandle = 'tr';
945
945
  }
946
- if (
947
- cell.selectionBorderTop &&
948
- cell.selectionBorderLeft &&
949
- self.mobile
950
- ) {
951
- selectionHandles.push([cell, 'tl']);
952
- cell.selectionHandle = 'tl';
946
+ if (cell.selectionBorderTop && cell.selectionBorderLeft) {
947
+ if (self.mobile) {
948
+ selectionHandles.push([cell, 'tl']);
949
+ cell.selectionHandle = 'tl';
950
+ }
951
+ if (self.fillOverlay.handle) {
952
+ self.fillOverlay.snapTo = {
953
+ x: cell.x,
954
+ y: cell.y,
955
+ };
956
+ }
953
957
  }
954
958
  if (
955
959
  cell.selectionBorderBottom &&
@@ -966,6 +970,22 @@ export default function (self) {
966
970
  ) {
967
971
  selectionHandles.push([cell, 'br']);
968
972
  cell.selectionHandle = 'br';
973
+
974
+ if (self.fillOverlay.handle) {
975
+ self.fillOverlay.handle.x = cell.x + cell.width;
976
+ self.fillOverlay.handle.y = cell.y + cell.height;
977
+ }
978
+ }
979
+
980
+ if (self.fillOverlay.handle) {
981
+ // Some corners may not be displaying, so we get at least
982
+ // one correct axis in order to display a fill overlay.
983
+ if (self.fillOverlay.snapTo.x === -1 && cell.selectionBorderLeft) {
984
+ self.fillOverlay.snapTo.x = cell.x;
985
+ }
986
+ if (self.fillOverlay.snapTo.y === -1 && cell.selectionBorderTop) {
987
+ self.fillOverlay.snapTo.y = cell.y;
988
+ }
969
989
  }
970
990
  }
971
991
  }
@@ -2496,10 +2516,12 @@ export default function (self) {
2496
2516
  strokeRect(0, 0, self.width, self.height);
2497
2517
  }
2498
2518
  function drawSelectionBorders() {
2499
- self.ctx.lineWidth = self.style.selectionOverlayBorderWidth;
2500
- self.ctx.strokeStyle = self.style.selectionOverlayBorderColor;
2501
2519
  function dsb(c) {
2502
- addBorderLine(c[0], c[1]);
2520
+ if (!self.fillOverlay.handle) {
2521
+ self.ctx.lineWidth = self.style.selectionOverlayBorderWidth;
2522
+ self.ctx.strokeStyle = self.style.selectionOverlayBorderColor;
2523
+ addBorderLine(c[0], c[1]);
2524
+ }
2503
2525
  }
2504
2526
  selectionBorders
2505
2527
  .filter(function (c) {
@@ -2542,9 +2564,14 @@ export default function (self) {
2542
2564
  })
2543
2565
  .forEach(dsb);
2544
2566
  self.ctx.restore();
2567
+
2568
+ drawFillOverlay();
2545
2569
  }
2546
2570
  function drawSelectionHandles() {
2547
- if (self.mobile || self.attributes.allowMovingSelection) {
2571
+ if (
2572
+ (self.mobile || self.attributes.allowMovingSelection) &&
2573
+ self.attributes.editable
2574
+ ) {
2548
2575
  self.ctx.lineWidth = self.style.selectionHandleBorderWidth;
2549
2576
  self.ctx.strokeStyle = self.style.selectionHandleBorderColor;
2550
2577
  self.ctx.fillStyle = self.style.selectionHandleColor;
@@ -2565,6 +2592,62 @@ export default function (self) {
2565
2592
  });
2566
2593
  }
2567
2594
  }
2595
+ function drawFillOverlay() {
2596
+ if (!self.fillOverlay.handle || !self.fillOverlay.snapTo) {
2597
+ return;
2598
+ }
2599
+
2600
+ self.ctx.save();
2601
+
2602
+ const overlay = self.fillOverlay;
2603
+ const handle = overlay.handle;
2604
+ const toX = overlay.snapTo.x;
2605
+ const toY = overlay.snapTo.y;
2606
+
2607
+ // The cell that the cursor is moving over. This may be unavailable
2608
+ // when the cursor is outside the grid or is pointing to something else.
2609
+ //
2610
+ // When unavailable, we use the actual position of the cursor to draw
2611
+ // the overlay.
2612
+ const snap = overlay.snap;
2613
+
2614
+ // Calculate the X, Y coordinates of the cursor with snap positions and
2615
+ // the direction of the movement in mind.
2616
+ //
2617
+ // When the movement is horizontal, we get the Y coordinate from the handle,
2618
+ // and vice-versa.
2619
+ const cursorX =
2620
+ overlay.direction === 'x'
2621
+ ? snap
2622
+ ? snap.x + (overlay.x < toX ? 0 : snap.width)
2623
+ : overlay.x
2624
+ : handle.x;
2625
+ const cursorY =
2626
+ overlay.direction === undefined || overlay.direction === 'y'
2627
+ ? snap
2628
+ ? snap.y + (overlay.y < toY ? 0 : snap.height)
2629
+ : overlay.y
2630
+ : handle.y;
2631
+
2632
+ // The final coordinates of the rect. We use 'minX' and 'minY' to avoid
2633
+ // drawing on the frozen area.
2634
+ const x = Math.max(Math.min(toX, cursorX), overlay.minX);
2635
+ const y = Math.max(Math.min(toY, cursorY), overlay.minY);
2636
+
2637
+ // Width and height of the rect are the difference between the
2638
+ // coordinates of both the rect and the cursor. The user may be pointing
2639
+ // behind and/or upwards of the rect, so we need to take that into
2640
+ // account.
2641
+ const width = Math.max(toX, cursorX) - x;
2642
+ const height = Math.max(toY, cursorY) - y;
2643
+
2644
+ self.ctx.strokeStyle = self.style.fillOverlayBorderColor;
2645
+ self.ctx.lineWidth = self.style.fillOverlayBorderWidth;
2646
+ self.ctx.setLineDash([3, 3]);
2647
+ strokeRect(x, y, width, height);
2648
+ self.ctx.setLineDash([]);
2649
+ self.ctx.restore();
2650
+ }
2568
2651
  function drawActiveCell() {
2569
2652
  if (!aCell) {
2570
2653
  return;