canvas-datagrid 0.3.18 → 0.3.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,14 @@ All notable changes to this project will be documented in this file.
7
7
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
8
8
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
9
9
 
10
+ ## 0.3.19 - 2021-11-24
11
+
12
+ ### Fixed
13
+
14
+ - Fix copy when column name or cell value is number (faimaklg, #402)
15
+ - Fix moving multiple columns or rows (xianzhi3, #390)
16
+ - Fix position of scroll bar with frozen pane xianzhi3, (#393)
17
+
10
18
  ## 0.3.18 - 2021-11-18
11
19
 
12
20
  No changes; had to bump version number because race condition caused 0.3.16 to be published instead of 0.3.17.
@@ -2386,8 +2386,14 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
2386
2386
  m = self.style.scrollBarBoxMargin * 2;
2387
2387
  self.ctx.strokeStyle = self.style.scrollBarBorderColor;
2388
2388
  self.ctx.lineWidth = self.style.scrollBarBorderWidth;
2389
- en.horizontalBox.x = rowHeaderCellWidth + self.style.scrollBarBoxMargin + (en.horizontalBar.width - self.scrollBox.scrollBoxWidth) * (self.scrollBox.scrollLeft / self.scrollBox.scrollWidth);
2390
- en.verticalBox.y = columnHeaderCellHeight + self.style.scrollBarBoxMargin + (en.verticalBar.height - self.scrollBox.scrollBoxHeight) * (self.scrollBox.scrollTop / self.scrollBox.scrollHeight);
2389
+
2390
+ if (self.frozenColumn > 0) {
2391
+ en.horizontalBox.x = rowHeaderCellWidth + self.style.scrollBarBoxMargin + self.scrollCache.x[self.frozenColumn - 1] + (en.horizontalBar.width - self.scrollCache.x[self.frozenColumn - 1] - self.scrollBox.scrollBoxWidth) * (self.scrollBox.scrollLeft / self.scrollBox.scrollWidth);
2392
+ } else {
2393
+ en.horizontalBox.x = rowHeaderCellWidth + self.style.scrollBarBoxMargin + (en.horizontalBar.width - self.scrollBox.scrollBoxWidth) * (self.scrollBox.scrollLeft / self.scrollBox.scrollWidth);
2394
+ }
2395
+
2396
+ en.verticalBox.y = columnHeaderCellHeight + self.style.scrollBarBoxMargin + self.scrollCache.y[self.frozenRow] + (en.verticalBar.height - self.scrollBox.scrollBoxHeight - self.scrollCache.y[self.frozenRow]) * (self.scrollBox.scrollTop / self.scrollBox.scrollHeight);
2391
2397
 
2392
2398
  if (self.scrollBox.horizontalBarVisible) {
2393
2399
  self.ctx.fillStyle = self.style.scrollBarBackgroundColor;
@@ -3178,6 +3184,11 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
3178
3184
  self.ctx.strokeStyle = self.style.reorderMarkerBorderColor;
3179
3185
 
3180
3186
  if (self.dragMode === 'row-reorder') {
3187
+ for (var k = 0; k < self.selections.length; k++) {
3188
+ if (!self.selections[k] || k == self.reorderObject.rowIndex) continue;
3189
+ b.height += self.getRowHeight(k);
3190
+ }
3191
+
3181
3192
  b.width = w;
3182
3193
  b.x = 0;
3183
3194
  m.width = w;
@@ -3192,6 +3203,12 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
3192
3203
  addBorderLine(m, self.reorderTarget.sortRowIndex > self.reorderObject.sortRowIndex ? 'b' : 't');
3193
3204
  }
3194
3205
  } else if (self.dragMode === 'column-reorder' && self.reorderObject) {
3206
+ var selectedColumns = self.selections[0];
3207
+
3208
+ for (var k = 1; k < selectedColumns.length; k++) {
3209
+ b.width += self.getColumnWidth(self.orders.columns[selectedColumns[k]]);
3210
+ }
3211
+
3195
3212
  b.height = h;
3196
3213
  b.y = 0;
3197
3214
  m.height = h;
@@ -3809,14 +3826,20 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
3809
3826
  setScrollBoxSize();
3810
3827
  self.scrollBox.scrollWidth = dataWidth - self.scrollBox.width;
3811
3828
  self.scrollBox.scrollHeight = dataHeight - self.scrollBox.height;
3812
- self.scrollBox.widthBoxRatio = self.scrollBox.width / dataWidth;
3829
+
3830
+ if (self.frozenColumn > 0) {
3831
+ self.scrollBox.widthBoxRatio = (self.scrollBox.width - self.scrollCache.x[self.frozenColumn - 1]) / dataWidth;
3832
+ } else {
3833
+ self.scrollBox.widthBoxRatio = self.scrollBox.width / dataWidth;
3834
+ }
3835
+
3813
3836
  self.scrollBox.scrollBoxWidth = self.scrollBox.width * self.scrollBox.widthBoxRatio - self.style.scrollBarWidth - b - d; // TODO: This heightBoxRatio number is terribly wrong.
3814
3837
  // They should be a result of the size of the grid/canvas?
3815
3838
  // it being off causes the scroll bar to "slide" under
3816
3839
  // the dragged mouse.
3817
3840
  // https://github.com/TonyGermaneri/canvas-datagrid/issues/97
3818
3841
 
3819
- self.scrollBox.heightBoxRatio = (self.scrollBox.height - columnHeaderCellHeight) / dataHeight;
3842
+ self.scrollBox.heightBoxRatio = (self.scrollBox.height - columnHeaderCellHeight - self.scrollCache.y[self.frozenRow]) / dataHeight;
3820
3843
  self.scrollBox.scrollBoxHeight = self.scrollBox.height * self.scrollBox.heightBoxRatio - self.style.scrollBarWidth - b - d;
3821
3844
  self.scrollBox.scrollBoxWidth = Math.max(self.scrollBox.scrollBoxWidth, self.style.scrollBarBoxMinSize);
3822
3845
  self.scrollBox.scrollBoxHeight = Math.max(self.scrollBox.scrollBoxHeight, self.style.scrollBarBoxMinSize); // horizontal
@@ -3831,11 +3854,12 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
3831
3854
  nb.height = self.style.scrollBarBoxWidth; // vertical
3832
3855
 
3833
3856
  v.x += self.width - self.style.scrollBarWidth - self.style.scrollBarBorderWidth - d;
3834
- v.y += columnHeaderCellHeight;
3857
+ v.y += columnHeaderCellHeight + self.scrollCache.y[self.frozenRow];
3835
3858
  v.width = self.style.scrollBarWidth + self.style.scrollBarBorderWidth + d;
3836
3859
  v.height = self.height - columnHeaderCellHeight - self.style.scrollBarWidth - d - m; // vertical box
3837
3860
 
3838
3861
  vb.x = v.x + self.style.scrollBarBoxMargin;
3862
+ vb.y += self.scrollCache.y[self.frozenRow];
3839
3863
  vb.width = self.style.scrollBarBoxWidth;
3840
3864
  vb.height = self.scrollBox.scrollBoxHeight; // corner
3841
3865
 
@@ -4064,6 +4088,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
4064
4088
  }
4065
4089
  } else if (dragBounds.top !== -1) {
4066
4090
  self.selectArea(sBounds, true);
4091
+ if (sBounds.left == -1 && sBounds.top !== sBounds.bottom) self.isMultiRowsSelected = true;
4067
4092
  }
4068
4093
  }
4069
4094
 
@@ -4161,12 +4186,6 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
4161
4186
  checkSelectionChange();
4162
4187
  return;
4163
4188
  }
4164
-
4165
- if (self.attributes.columnHeaderClickBehavior === 'select') {
4166
- self.selectColumn(i.header.index, ctrl, e.shiftKey);
4167
- self.draw();
4168
- return;
4169
- }
4170
4189
  }
4171
4190
 
4172
4191
  self.selections[i.rowIndex] = self.selections[i.rowIndex] || [];
@@ -4346,6 +4365,12 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
4346
4365
  return;
4347
4366
  }
4348
4367
 
4368
+ if ((e.ctrlKey || e.metaKey || e.shiftKey) && self.reorderObject) {
4369
+ if (self.dragMode === 'column-reorder' && !self.isMultiColumnsSelected(self.draggingItem.header.index)) {
4370
+ self.selectColumn(self.draggingItem.header.index, false, false);
4371
+ }
4372
+ }
4373
+
4349
4374
  if (self.dispatchEvent('reordering', {
4350
4375
  NativeEvent: e,
4351
4376
  source: self.dragStartObject,
@@ -4357,6 +4382,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
4357
4382
 
4358
4383
  if (Math.abs(x) > self.attributes.reorderDeadZone || Math.abs(y) > self.attributes.reorderDeadZone) {
4359
4384
  self.reorderObject = self.draggingItem;
4385
+ if (self.isMultiRowsSelected) self.reorderObject = self.getVisibleCellByIndex(-1, self.activeCell.rowIndex);
4360
4386
  self.reorderTarget = self.currentCell;
4361
4387
  self.reorderObject.dragOffset = {
4362
4388
  x: x,
@@ -4369,7 +4395,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
4369
4395
  self.stopDragReorder = function (e) {
4370
4396
  var oIndex,
4371
4397
  tIndex,
4372
- odata,
4398
+ odata = [],
4373
4399
  cr = {
4374
4400
  'row-reorder': self.orders.rows,
4375
4401
  'column-reorder': self.orders.columns
@@ -4392,14 +4418,45 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
4392
4418
  tIndex = cr[self.dragMode].indexOf(self.reorderTarget[i]);
4393
4419
 
4394
4420
  if (self.dragMode === 'column-reorder') {
4395
- cr[self.dragMode].splice(oIndex, 1);
4396
- cr[self.dragMode].splice(tIndex, 0, self.reorderObject[i]);
4421
+ var sortColumnIndices = [];
4422
+ var seletedColumnIndices = [];
4423
+
4424
+ if (self.selections[0]) {
4425
+ self.selections[0].forEach(function (value) {
4426
+ sortColumnIndices.push(self.orders.columns[value]);
4427
+ });
4428
+ }
4429
+
4430
+ var deleteCount = sortColumnIndices.length;
4431
+ cr[self.dragMode].splice(oIndex, deleteCount);
4432
+ if (tIndex > oIndex) tIndex = tIndex - (deleteCount - 1);
4433
+
4434
+ for (var i = 0; i < sortColumnIndices.length; i++) {
4435
+ seletedColumnIndices.push(tIndex + i);
4436
+ cr[self.dragMode].splice(tIndex + i, 0, sortColumnIndices[i]);
4437
+ }
4438
+
4397
4439
  self.orders.columns = cr[self.dragMode];
4440
+ self.viewData.forEach(function (row, rowIndex) {
4441
+ self.selections[rowIndex] = seletedColumnIndices;
4442
+ });
4398
4443
  } else {
4399
- // self.orders.rows = cr[self.dragMode];
4400
- odata = self.viewData[oIndex];
4401
- self.viewData[oIndex] = self.viewData[tIndex];
4402
- self.viewData[tIndex] = odata;
4444
+ var selectedRows = [];
4445
+ self.selections.forEach(function (row, rowIndex) {
4446
+ if (row) {
4447
+ selectedRows.push(row);
4448
+ odata.push(self.viewData[rowIndex]);
4449
+ }
4450
+ });
4451
+ self.viewData.splice(oIndex, odata.length);
4452
+ self.selections = [];
4453
+ if (tIndex > oIndex) tIndex = tIndex - (odata.length - 1);
4454
+ self.activeCell.rowIndex = tIndex;
4455
+
4456
+ for (var i = 0; i < odata.length; i++) {
4457
+ self.viewData.splice(tIndex + i, 0, odata[i]);
4458
+ self.selections[tIndex + i] = selectedRows[i];
4459
+ }
4403
4460
  }
4404
4461
 
4405
4462
  self.resize();
@@ -4465,18 +4522,36 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
4465
4522
  return;
4466
4523
  }
4467
4524
 
4468
- var pos = self.getLayerPos(e);
4525
+ var pos = self.getLayerPos(e),
4526
+ bm = self.style.gridBorderCollapse === 'collapse' ? 1 : 2,
4527
+ columnHeaderCellBorder = self.style.columnHeaderCellBorderWidth * bm,
4528
+ columnHeaderCellHeight = self.getColumnHeaderCellHeight(),
4529
+ rowHeaderCellWidth = self.getRowHeaderCellWidth();
4469
4530
  self.ignoreNextClick = true;
4470
4531
  self.freezeMarkerPosition = pos;
4471
4532
 
4472
4533
  if (self.currentCell && self.currentCell.rowIndex !== undefined && self.dragMode === 'frozen-row-marker') {
4473
4534
  self.scrollBox.scrollTop = 0;
4474
4535
  self.frozenRow = self.currentCell.rowIndex + 1;
4536
+ self.scrollBox.bar.v.y = columnHeaderCellHeight + columnHeaderCellBorder + self.scrollCache.y[self.frozenRow];
4537
+ self.scrollBox.box.v.y = columnHeaderCellHeight + columnHeaderCellBorder + self.scrollCache.y[self.frozenRow];
4538
+ var dataHeight = self.scrollCache.y[self.scrollCache.y.length - 1];
4539
+ self.scrollBox.heightBoxRatio = (self.scrollBox.height - columnHeaderCellHeight - self.scrollCache.y[self.frozenRow]) / dataHeight;
4540
+ self.scrollBox.scrollBoxHeight = self.scrollBox.height * self.scrollBox.heightBoxRatio - self.style.scrollBarWidth;
4541
+ self.scrollBox.scrollBoxHeight = Math.max(self.scrollBox.scrollBoxHeight, self.style.scrollBarBoxMinSize);
4542
+ self.scrollBox.box.v.height = self.scrollBox.scrollBoxHeight;
4475
4543
  }
4476
4544
 
4477
4545
  if (self.currentCell && self.currentCell.columnIndex !== undefined && self.dragMode === 'frozen-column-marker') {
4478
4546
  self.scrollBox.scrollLeft = 0;
4479
4547
  self.frozenColumn = self.currentCell.columnIndex + 1;
4548
+ self.scrollBox.bar.h.x = rowHeaderCellWidth + self.scrollCache.x[self.frozenColumn - 1];
4549
+ self.scrollBox.box.h.x = rowHeaderCellWidth + self.scrollCache.x[self.frozenColumn - 1];
4550
+ var dataWidth = self.scrollCache.x[self.scrollCache.x.length - 1];
4551
+ self.scrollBox.widthBoxRatio = (self.scrollBox.width - self.scrollCache.x[self.frozenColumn - 1]) / dataWidth;
4552
+ self.scrollBox.scrollBoxWidth = self.scrollBox.width * self.scrollBox.widthBoxRatio - self.style.scrollBarWidth;
4553
+ self.scrollBox.scrollBoxWidth = Math.max(self.scrollBox.scrollBoxWidth, self.style.scrollBarBoxMinSize);
4554
+ self.scrollBox.box.h.width = self.scrollBox.scrollBoxWidth;
4480
4555
  }
4481
4556
 
4482
4557
  if (Math.abs(pos.x) > self.attributes.reorderDeadZone || Math.abs(pos.y) > self.attributes.reorderDeadZone) {
@@ -4535,7 +4610,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
4535
4610
  self.dragAddToSelection = !self.dragStartObject.selected;
4536
4611
 
4537
4612
  if (!ctrl && !e.shiftKey && !/(vertical|horizontal)-scroll-(bar|box)/.test(self.dragStartObject.context) && self.currentCell && !self.currentCell.isColumnHeader && !move && !freeze && !resize) {
4538
- self.selections = [];
4613
+ if (!(self.dragMode == 'row-reorder' && self.isMultiRowsSelected)) self.selections = [];
4539
4614
  }
4540
4615
 
4541
4616
  if (self.dragStartObject.isGrid) {
@@ -4626,9 +4701,10 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
4626
4701
  if (['row-reorder', 'column-reorder'].indexOf(self.dragMode) !== -1) {
4627
4702
  self.draggingItem = self.dragStartObject;
4628
4703
 
4629
- if (self.dragMode === 'column-reorder' && self.attributes.columnHeaderClickBehavior === 'select') {
4704
+ if (self.dragMode === 'column-reorder' && !self.isMultiColumnsSelected(self.currentCell.header.index)) {
4630
4705
  self.selectColumn(self.currentCell.header.index, ctrl, e.shiftKey);
4631
- self.draw();
4706
+ } else if (self.dragMode === 'row-reorder' && !self.isMultiRowsSelected) {
4707
+ self.selectRow(self.dragStartObject.rowIndex, ctrl, null);
4632
4708
  }
4633
4709
 
4634
4710
  document.body.addEventListener('mousemove', self.dragReorder, false);
@@ -4639,16 +4715,9 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
4639
4715
 
4640
4716
  self.mouseup = function (e) {
4641
4717
  clearTimeout(self.scrollTimer);
4642
- var ctrl = e.ctrlKey || e.metaKey;
4643
4718
  self.cellBoundaryCrossed = true;
4644
4719
  self.rowBoundaryCrossed = true;
4645
4720
  self.columnBoundaryCrossed = true;
4646
-
4647
- if (self.draggingItem) {
4648
- self.selectColumn(self.currentCell.header.index, ctrl, e.shiftKey);
4649
- self.draw();
4650
- }
4651
-
4652
4721
  self.selecting = undefined;
4653
4722
  self.draggingItem = undefined;
4654
4723
  self.dragStartObject = undefined;
@@ -5221,6 +5290,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
5221
5290
  isNeat = true; // Selected like [[0, 1], [0, 1]] of [[0, 3]] is neat; Selected like [[0, 1], [1, 2]] is untidy
5222
5291
 
5223
5292
  function htmlSafe(v) {
5293
+ if (typeof v === 'number') return v;
5224
5294
  return v.replace(/</g, '&lt;').replace(/>/g, '&gt;');
5225
5295
  }
5226
5296
 
@@ -5236,8 +5306,8 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
5236
5306
  if (!firstRowKeys) firstRowKeys = Object.keys(row);
5237
5307
  if (isNeat && rowKeys.length !== firstRowKeys.length) isNeat = false;
5238
5308
  sSorted.forEach(function (column, columnIndex) {
5239
- if (rowKeys.indexOf(column.name) < 0) {
5240
- if (firstRowKeys.indexOf(column.name) < 0) {
5309
+ if (rowKeys.indexOf(String(column.name)) < 0) {
5310
+ if (firstRowKeys.indexOf(String(column.name)) < 0) {
5241
5311
  return;
5242
5312
  } else if (isNeat) {
5243
5313
  isNeat = false;
@@ -7738,6 +7808,35 @@ __webpack_require__.r(__webpack_exports__);
7738
7808
 
7739
7809
  self.draw();
7740
7810
  };
7811
+ /**
7812
+ * Returns true if indices of columns next to the selected columnIndex is selected on every row.
7813
+ * @memberof canvasDatagrid
7814
+ * @name isMultiColumnsSelected
7815
+ * @method
7816
+ * @param {number} columnIndex The column index to check.
7817
+ */
7818
+
7819
+
7820
+ self.isMultiColumnsSelected = function (columnIndex) {
7821
+ var multiColIsSelected = true;
7822
+ self.viewData.forEach(function (row, rowIndex) {
7823
+ var columnIndices = self.selections[rowIndex];
7824
+
7825
+ if (!columnIndices || columnIndices.length <= 1 || columnIndices.indexOf(columnIndex) === -1) {
7826
+ multiColIsSelected = false;
7827
+ } else if (columnIndices.length > 1) {
7828
+ if (columnIndices[0] != columnIndex) multiColIsSelected = false;else {
7829
+ for (var i = 0; i < columnIndices.length - 1; i++) {
7830
+ if (columnIndices[i] + 1 != columnIndices[i + 1]) {
7831
+ multiColIsSelected = false;
7832
+ break;
7833
+ }
7834
+ }
7835
+ }
7836
+ }
7837
+ });
7838
+ return multiColIsSelected;
7839
+ };
7741
7840
  /**
7742
7841
  * Returns true if the selected columnIndex is selected on every row.
7743
7842
  * @memberof canvasDatagrid
@@ -7750,7 +7849,7 @@ __webpack_require__.r(__webpack_exports__);
7750
7849
  self.isColumnSelected = function (columnIndex) {
7751
7850
  var colIsSelected = true;
7752
7851
  self.viewData.forEach(function (row, rowIndex) {
7753
- if (!self.selections[rowIndex] || self.selections[rowIndex].indexOf(self.orders.columns[columnIndex]) === -1) {
7852
+ if (!self.selections[rowIndex] || self.selections[rowIndex].indexOf(columnIndex) === -1) {
7754
7853
  colIsSelected = false;
7755
7854
  }
7756
7855
  });
@@ -7878,6 +7977,7 @@ __webpack_require__.r(__webpack_exports__);
7878
7977
  st,
7879
7978
  en,
7880
7979
  s = self.getVisibleSchema();
7980
+ self.isMultiRowsSelected = false;
7881
7981
 
7882
7982
  function de() {
7883
7983
  if (supressEvent) {