@gridsheet/react-core 2.0.1 → 2.0.3

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/index.js CHANGED
@@ -255,15 +255,17 @@ const putMatrix = (dst, src, dstArea, filter = () => true) => {
255
255
  for (let y = top; y <= bottom; y++) {
256
256
  const lostRow = [];
257
257
  for (let x = left; x <= right; x++) {
258
+ const srcPoint = { y: y - top, x: x - left };
259
+ const dstPoint = { y, x };
258
260
  const value = src[y - top][x - left];
259
261
  if (y < dstNumRows - 1 && x < dstNumCols - 1) {
260
- if (filter(value, dst[y][x], { y, x })) {
262
+ if (filter({ srcValue: value, dstValue: dst[y][x], srcPoint, dstPoint })) {
261
263
  dst[y][x] = value;
262
264
  }
263
265
  continue;
264
266
  }
265
267
  if (lostRow.length === 0) {
266
- lostRows[p2a({ y, x })] = [lostRow];
268
+ lostRows[p2a(dstPoint)] = [lostRow];
267
269
  }
268
270
  lostRow.push(value);
269
271
  }
@@ -2613,13 +2615,13 @@ class PasteAction extends CoreAction {
2613
2615
  const { wire } = dstTable;
2614
2616
  const { copyingSheetId, copyingZone, cutting } = wire;
2615
2617
  const srcTable = dstTable.getTableBySheetId(copyingSheetId);
2616
- if (!srcTable) {
2617
- return store;
2618
- }
2619
2618
  let selectingArea = zoneToArea(selectingZone);
2620
2619
  const copyingArea = zoneToArea(copyingZone);
2621
2620
  const { matrix, onlyValue } = payload;
2622
2621
  if (cutting) {
2622
+ if (!srcTable) {
2623
+ return store;
2624
+ }
2623
2625
  const src = copyingArea;
2624
2626
  const { height: h, width: w } = areaShape(copyingArea);
2625
2627
  const dst = selectingArea.top !== -1 ? {
@@ -2692,6 +2694,9 @@ class PasteAction extends CoreAction {
2692
2694
  }
2693
2695
  });
2694
2696
  } else {
2697
+ if (srcTable == null) {
2698
+ return store;
2699
+ }
2695
2700
  let { height, width } = areaShape(copyingArea);
2696
2701
  if (selectingArea.top !== -1) {
2697
2702
  y = selectingArea.top;
@@ -3703,10 +3708,14 @@ function parseStyleString(element) {
3703
3708
  const styleString = element.getAttribute("style") ?? "";
3704
3709
  const styleObj = {};
3705
3710
  styleString.split(";").forEach((d) => {
3706
- const [rawKey, rawValue] = d.split(":");
3711
+ let [rawKey, rawValue] = d.split(":");
3707
3712
  if (!rawKey || !rawValue) {
3708
3713
  return;
3709
3714
  }
3715
+ rawKey = rawKey.trim();
3716
+ if (rawKey === "height" || rawKey === "width") {
3717
+ return;
3718
+ }
3710
3719
  const key = rawKey.trim().replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
3711
3720
  if (key === "float" || key === "display" || key.startsWith("padding")) {
3712
3721
  return;
@@ -8337,7 +8346,7 @@ class Table {
8337
8346
  const matrixTo = this.getIdMatrixFromArea(dst);
8338
8347
  const diffBefore = {};
8339
8348
  const preserver = new ReferencePreserver(this);
8340
- const lostRows = putMatrix(this.idMatrix, matrixFrom, dst, (srcId, dstId, point) => {
8349
+ const lostRows = putMatrix(this.idMatrix, matrixFrom, dst, ({ srcValue: srcId, dstValue: dstId }) => {
8341
8350
  var _a;
8342
8351
  if (srcId == null || dstId == null) {
8343
8352
  return false;
@@ -8377,8 +8386,11 @@ class Table {
8377
8386
  });
8378
8387
  const srcTableRaw = srcTable.__raw__;
8379
8388
  const srcContext = this.wire.contextsBySheetId[srcTableRaw.sheetId];
8380
- putMatrix(srcTableRaw.idMatrix, matrixNew, src, (newId, srcId) => {
8389
+ putMatrix(srcTableRaw.idMatrix, matrixNew, src, ({ srcValue: newId, dstValue: srcId, dstPoint: srcPoint }) => {
8381
8390
  var _a;
8391
+ if (among(dst, srcPoint) && srcTable === this) {
8392
+ return false;
8393
+ }
8382
8394
  preserver.map[srcId] = newId;
8383
8395
  const srcCell = srcTableRaw.wire.data[srcId];
8384
8396
  if (operator === "USER" && hasOperation(srcCell == null ? void 0 : srcCell.prevention, MoveFrom)) {
@@ -8408,7 +8420,9 @@ class Table {
8408
8420
  Object.assign(diffBefore, resolvedDiff);
8409
8421
  if (srcTable !== this && srcContext !== null) {
8410
8422
  const { dispatch } = srcContext;
8411
- dispatch(updateTable(srcTableRaw));
8423
+ requestAnimationFrame(() => {
8424
+ dispatch(updateTable(srcTableRaw));
8425
+ });
8412
8426
  }
8413
8427
  if (historicize) {
8414
8428
  this.pushHistory({