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