canvas-datagrid 0.3.20 → 0.3.21

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
@@ -505,6 +505,11 @@ declare class canvasDatagrid {
505
505
  * @param offsetY - The number of rows to offset the selection.
506
506
  */
507
507
  static moveSelection(offsetX: number, offsetY: number): void;
508
+ /**
509
+ * Deletes currently selected data.
510
+ * @param dontDraw - Suppress the draw method after the selection change.
511
+ */
512
+ static deleteSelectedData(dontDraw: boolean): void;
508
513
  /**
509
514
  * 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.
510
515
  * @param sel - 2D array representing selected rows and columns. `canvasDatagrid.selections` is in this format and can be used here.
package/lib/button.js CHANGED
@@ -150,6 +150,7 @@ export default function (self) {
150
150
  if (item.click) {
151
151
  menuItemContainer.addEventListener('click', function (ev) {
152
152
  item.click.apply(self, [ev]);
153
+ self.disposeButton();
153
154
  });
154
155
  }
155
156
  }
package/lib/docs.js CHANGED
@@ -460,6 +460,14 @@
460
460
  * @param {object} e.boundRowIndexMap Mapping of view data row to bound data row index.
461
461
  * @param {object} e.boundColumnIndexMap Mapping of view column order to bound column order.
462
462
  */
463
+ /**
464
+ * Fires when the selected is deleted by pressing backspace or delete key.
465
+ * @event
466
+ * @name canvasDatagrid#afterdelete
467
+ * @param {object} e Event object.
468
+ * @param {object} e.ctx Canvas context.
469
+ * @param {array} e.cells Cells affected by the delete action. Each item in the array is a tuple of [rowIndex, columnIndex, boundRowIndex, boundColumnIndex].
470
+ */
463
471
  /**
464
472
  * Fires when the user clicks on the "drill in" arrow. When the arrow is clicked a new
465
473
  * grid is created and nested inside of the row. The grid, the row data and row index are passed
@@ -552,7 +560,7 @@
552
560
  * @name canvasDatagrid#afterpaste
553
561
  * @param {object} e Event object
554
562
  * @param {object} e.ctx Canvas context.
555
- * @param {array} e.cells Cells affected by the paste action. Each item in the array is a tuple of [rowIndex, columnIndex].
563
+ * @param {array} e.cells Cells affected by the paste action. Each item in the array is a tuple of [rowIndex, columnIndex, boundRowIndex, boundColumnIndex].
556
564
  */
557
565
  /**
558
566
  * Fired just before a cell is drawn onto the canvas. `e.preventDefault();` prevents the cell from being drawn.
@@ -472,10 +472,18 @@ export default function (self) {
472
472
  };
473
473
  if (
474
474
  cell.isFilterable &&
475
- x > cell.x + cell.width - self.style.filterButtonWidth &&
476
- x < cell.x + cell.width &&
477
- y > cell.y + cell.height - self.style.filterButtonHeight &&
478
- y < cell.y + cell.height
475
+ x >
476
+ cell.x +
477
+ cell.width +
478
+ self.canvasOffsetLeft -
479
+ self.style.filterButtonWidth &&
480
+ x < cell.x + cell.width + self.canvasOffsetLeft &&
481
+ y >
482
+ cell.y +
483
+ cell.height +
484
+ self.canvasOffsetTop -
485
+ self.style.filterButtonHeight &&
486
+ y < cell.y + cell.height + self.canvasOffsetTop
479
487
  ) {
480
488
  self.hovers.onFilterButton = true;
481
489
  self.draw();
@@ -1420,6 +1428,8 @@ export default function (self) {
1420
1428
  self.selectNone();
1421
1429
  } else if (ctrl && e.key === 'a') {
1422
1430
  self.selectAll();
1431
+ } else if (['Backspace', 'Delete'].includes(e.key)) {
1432
+ self.deleteSelectedData();
1423
1433
  } else if (e.key === 'ArrowDown') {
1424
1434
  y += 1;
1425
1435
  } else if (e.key === 'ArrowUp') {
@@ -1861,6 +1871,8 @@ export default function (self) {
1861
1871
  if (self.dispatchEvent('cut', { NativeEvent: e, cells: affectedCells })) {
1862
1872
  return;
1863
1873
  }
1874
+
1875
+ requestAnimationFrame(() => self.draw());
1864
1876
  };
1865
1877
  self.copy = function (e) {
1866
1878
  if (self.dispatchEvent('copy', { NativeEvent: e })) {
package/lib/intf.js CHANGED
@@ -242,6 +242,38 @@ export default function (self, ctor) {
242
242
 
243
243
  return selectedCells;
244
244
  };
245
+ self.clearSelectedCells = function () {
246
+ const schema = self.getSchema();
247
+ const affectedCells = [];
248
+
249
+ for (const [rowIndex, row] of self.selections.entries()) {
250
+ // If no cells are selected for a particular rowIndex the selections array will contain an empty element for that rowIndex.
251
+ if (!row) continue;
252
+
253
+ const boundRowIndex = self.getBoundRowIndexFromViewRowIndex(rowIndex);
254
+
255
+ for (let columnIndex of row) {
256
+ // If the whole row is selected the columnIndex for the rowHeader is -1.
257
+ if (columnIndex < 0) continue;
258
+
259
+ const boundColumnIndex = self.getBoundColumnIndexFromViewColumnIndex(
260
+ columnIndex,
261
+ );
262
+ const columnName = schema[boundColumnIndex].name;
263
+
264
+ self.viewData[boundRowIndex][columnName] = null;
265
+
266
+ affectedCells.push([
267
+ rowIndex,
268
+ columnIndex,
269
+ boundRowIndex,
270
+ boundColumnIndex,
271
+ ]);
272
+ }
273
+ }
274
+
275
+ return affectedCells;
276
+ };
245
277
  self.getBoundRowIndexFromViewRowIndex = function (viewRowIndex) {
246
278
  if (self.boundRowIndexMap && self.boundRowIndexMap.has(viewRowIndex)) {
247
279
  return self.boundRowIndexMap.get(viewRowIndex);
@@ -557,6 +589,7 @@ export default function (self, ctor) {
557
589
  self.controlInput.removeEventListener('keypress', self.keypress, false);
558
590
  self.controlInput.removeEventListener('keyup', self.keyup, false);
559
591
  self.controlInput.removeEventListener('keydown', self.keydown, false);
592
+ document.body.removeEventListener('mousemove', self.mousemove);
560
593
  window.removeEventListener('resize', self.resize);
561
594
  if (self.observer && self.observer.disconnect) {
562
595
  self.observer.disconnect();
@@ -734,6 +767,7 @@ export default function (self, ctor) {
734
767
  self.pointerLockPosition = { x: 0, y: 0 };
735
768
  Object.keys(self.style).forEach(self.parseStyleValue);
736
769
  self.intf.moveSelection = self.moveSelection;
770
+ self.intf.deleteSelectedData = self.deleteSelectedData;
737
771
  self.intf.moveTo = self.moveTo;
738
772
  self.intf.addEventListener = self.addEventListener;
739
773
  self.intf.removeEventListener = self.removeEventListener;
@@ -734,9 +734,23 @@ export default function (self) {
734
734
  if (!self.canvas) {
735
735
  return;
736
736
  }
737
- self.sizes.columns[
738
- name === 'cornerCell' ? -1 : self.getHeaderByName(name).index
739
- ] = Math.max(self.findColumnMaxTextLength(name), self.style.minColumnWidth);
737
+
738
+ const columnIndex =
739
+ name === 'cornerCell' ? -1 : self.getHeaderByName(name).index;
740
+
741
+ const newSize = Math.max(
742
+ self.findColumnMaxTextLength(name),
743
+ self.style.minColumnWidth,
744
+ );
745
+
746
+ self.sizes.columns[columnIndex] = newSize;
747
+
748
+ self.dispatchEvent('resizecolumn', {
749
+ x: newSize,
750
+ y: self.resizingStartingHeight,
751
+ draggingItem: self.currentCell,
752
+ });
753
+
740
754
  if (!internal) {
741
755
  self.resize();
742
756
  self.draw(true);
@@ -856,6 +870,26 @@ export default function (self) {
856
870
  });
857
871
  self.selections = sel;
858
872
  };
873
+ /**
874
+ * Deletes currently selected data.
875
+ * @memberof canvasDatagrid
876
+ * @name deleteSelectedData
877
+ * @method
878
+ * @param {boolean} dontDraw Suppress the draw method after the selection change.
879
+ */
880
+ self.deleteSelectedData = function (dontDraw) {
881
+ const affectedCells = self.clearSelectedCells();
882
+
883
+ self.dispatchEvent('afterdelete', {
884
+ cells: affectedCells,
885
+ });
886
+
887
+ if (dontDraw) {
888
+ return;
889
+ }
890
+
891
+ requestAnimationFrame(() => self.draw());
892
+ };
859
893
  /**
860
894
  * 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.
861
895
  * @memberof canvasDatagrid
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvas-datagrid",
3
- "version": "0.3.20",
3
+ "version": "0.3.21",
4
4
  "description": "Canvas based data grid web component. Capable of displaying millions of contiguous hierarchical rows and columns without paging or loading, on a single canvas element.",
5
5
  "main": "./dist/canvas-datagrid.js",
6
6
  "module": "./dist/canvas-datagrid.module.js",