@gridsheet/react-core 2.0.5-0 → 2.0.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.
@@ -1 +1 @@
1
- {"version":3,"file":"Resizer.d.ts","sourceRoot":"","sources":["../../src/components/Resizer.tsx"],"names":[],"mappings":"AAWA,eAAO,MAAM,OAAO,mBAwGnB,CAAC"}
1
+ {"version":3,"file":"Resizer.d.ts","sourceRoot":"","sources":["../../src/components/Resizer.tsx"],"names":[],"mappings":"AAWA,eAAO,MAAM,OAAO,mBAuGnB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Tabular.d.ts","sourceRoot":"","sources":["../../src/components/Tabular.tsx"],"names":[],"mappings":"AAkBA,eAAO,MAAM,OAAO,0BAsMnB,CAAC"}
1
+ {"version":3,"file":"Tabular.d.ts","sourceRoot":"","sources":["../../src/components/Tabular.tsx"],"names":[],"mappings":"AAkBA,eAAO,MAAM,OAAO,0BAoMnB,CAAC"}
package/dist/index.js CHANGED
@@ -3192,7 +3192,6 @@ class InsertRowsAboveAction extends CoreAction {
3192
3192
  });
3193
3193
  return {
3194
3194
  ...store,
3195
- ...table.getTotalSize(),
3196
3195
  tableReactive: { current: table }
3197
3196
  };
3198
3197
  }
@@ -3230,7 +3229,6 @@ class InsertRowsBelowAction extends CoreAction {
3230
3229
  });
3231
3230
  return {
3232
3231
  ...store,
3233
- ...table.getTotalSize(),
3234
3232
  selectingZone: nextSelectingZone,
3235
3233
  choosing: nextChoosing,
3236
3234
  tableReactive: { current: table }
@@ -3264,7 +3262,6 @@ class InsertColsLeftAction extends CoreAction {
3264
3262
  });
3265
3263
  return {
3266
3264
  ...store,
3267
- ...table.getTotalSize(),
3268
3265
  tableReactive: { current: table }
3269
3266
  };
3270
3267
  }
@@ -3304,7 +3301,6 @@ class InsertColsRightAction extends CoreAction {
3304
3301
  });
3305
3302
  return {
3306
3303
  ...store,
3307
- ...table.getTotalSize(),
3308
3304
  selectingZone: nextSelectingZone,
3309
3305
  choosing: nextChoosing,
3310
3306
  tableReactive: { current: table }
@@ -3338,7 +3334,6 @@ class RemoveRowsAction extends CoreAction {
3338
3334
  });
3339
3335
  return {
3340
3336
  ...store,
3341
- ...table.getTotalSize(),
3342
3337
  tableReactive: { current: table }
3343
3338
  };
3344
3339
  }
@@ -3370,7 +3365,6 @@ class RemoveColsAction extends CoreAction {
3370
3365
  });
3371
3366
  return {
3372
3367
  ...store,
3373
- ...table.getTotalSize(),
3374
3368
  tableReactive: { current: table }
3375
3369
  };
3376
3370
  }
@@ -4652,8 +4646,7 @@ const Resizer = () => {
4652
4646
  });
4653
4647
  dispatch(
4654
4648
  setStore({
4655
- tableReactive: { current: table },
4656
- ...table.getTotalSize()
4649
+ tableReactive: { current: table }
4657
4650
  })
4658
4651
  );
4659
4652
  dispatch(setResizingPositionY([-1, -1, -1]));
@@ -7717,6 +7710,8 @@ class Table {
7717
7710
  this.prevSheetName = "";
7718
7711
  this.status = 0;
7719
7712
  this.idsToBeIdentified = [];
7713
+ this.totalWidth = 0;
7714
+ this.totalHeight = 0;
7720
7715
  this.version = 0;
7721
7716
  this.area = { top: 0, left: 0, bottom: 0, right: 0 };
7722
7717
  this.addressCaches = /* @__PURE__ */ new Map();
@@ -7903,7 +7898,7 @@ class Table {
7903
7898
  }
7904
7899
  return { width, height };
7905
7900
  }
7906
- getTotalSize() {
7901
+ setTotalSize() {
7907
7902
  const { bottom, right } = this.area;
7908
7903
  const { width, height } = this.getRectSize({
7909
7904
  top: 1,
@@ -7911,24 +7906,25 @@ class Table {
7911
7906
  bottom: bottom + 1,
7912
7907
  right: right + 1
7913
7908
  });
7914
- return {
7915
- totalWidth: width + this.headerWidth,
7916
- totalHeight: height + this.headerHeight
7917
- };
7909
+ this.totalWidth = width + this.headerWidth;
7910
+ this.totalHeight = height + this.headerHeight;
7918
7911
  }
7919
- refresh(keepAddressCache = true) {
7912
+ refresh(relocate = false, resize = false) {
7920
7913
  this.incrementVersion();
7921
7914
  this.lastChangedAt = this.changedAt;
7922
7915
  this.changedAt = /* @__PURE__ */ new Date();
7923
7916
  this.clearSolvedCaches();
7924
- if (!keepAddressCache) {
7917
+ if (relocate) {
7925
7918
  this.addressCaches.clear();
7926
7919
  }
7920
+ if (resize) {
7921
+ this.setTotalSize();
7922
+ }
7927
7923
  return this;
7928
7924
  }
7929
- clone(keepAddressCache = true) {
7925
+ clone(relocate = false) {
7930
7926
  const copied = Object.assign(Object.create(Object.getPrototypeOf(this)), this);
7931
- return copied.refresh(keepAddressCache);
7927
+ return copied.refresh(relocate);
7932
7928
  }
7933
7929
  getPointById(id, slideY = 0, slideX = 0) {
7934
7930
  const absCol = id.startsWith("$");
@@ -8446,7 +8442,7 @@ class Table {
8446
8442
  this.wire.onEdit({ table: srcTable.__raw__.trim(src) });
8447
8443
  this.wire.onEdit({ table: this.__raw__.trim(dst) });
8448
8444
  }
8449
- return this.refresh(false);
8445
+ return this.refresh(true);
8450
8446
  }
8451
8447
  copy({
8452
8448
  srcTable = this,
@@ -8532,15 +8528,16 @@ class Table {
8532
8528
  const diffBefore = {};
8533
8529
  const diffAfter = {};
8534
8530
  const changedAt = /* @__PURE__ */ new Date();
8531
+ let resized = false;
8535
8532
  Object.keys(diff).forEach((address) => {
8536
8533
  var _a, _b, _c, _d;
8537
8534
  const point = a2p(address);
8538
8535
  const id = this.getId(point);
8539
8536
  const original = this.wire.data[id];
8540
- let patch = { ...diff[address] };
8541
8537
  if (operator === "USER" && hasOperation(original.prevention, Update)) {
8542
8538
  return;
8543
8539
  }
8540
+ let patch = { ...diff[address] };
8544
8541
  if (formulaIdentify) {
8545
8542
  patch.value = identifyFormula(patch.value, {
8546
8543
  table: this,
@@ -8570,6 +8567,9 @@ class Table {
8570
8567
  if (updateChangedAt) {
8571
8568
  this.setChangedAt(patch, changedAt);
8572
8569
  }
8570
+ if (patch.width != null || patch.height != null) {
8571
+ resized = true;
8572
+ }
8573
8573
  diffBefore[id] = { ...original };
8574
8574
  const policy = this.policies[original.policy] ?? defaultPolicy;
8575
8575
  const p = policy.restrict({
@@ -8592,7 +8592,8 @@ class Table {
8592
8592
  }
8593
8593
  return {
8594
8594
  diffBefore,
8595
- diffAfter
8595
+ diffAfter,
8596
+ resized
8596
8597
  };
8597
8598
  }
8598
8599
  update({
@@ -8605,7 +8606,7 @@ class Table {
8605
8606
  undoReflection,
8606
8607
  redoReflection
8607
8608
  }) {
8608
- const { diffBefore, diffAfter } = this._update({
8609
+ const { diffBefore, diffAfter, resized } = this._update({
8609
8610
  diff,
8610
8611
  partial,
8611
8612
  operator,
@@ -8625,7 +8626,7 @@ class Table {
8625
8626
  partial
8626
8627
  });
8627
8628
  }
8628
- return this.refresh(true);
8629
+ return this.refresh(false, resized);
8629
8630
  }
8630
8631
  writeRawCellMatrix({
8631
8632
  point,
@@ -8755,7 +8756,7 @@ class Table {
8755
8756
  cloned.addressCaches = /* @__PURE__ */ new Map();
8756
8757
  this.wire.onInsertRows({ table: cloned, y, numRows });
8757
8758
  }
8758
- return this.refresh(false);
8759
+ return this.refresh(true, true);
8759
8760
  }
8760
8761
  removeRows({
8761
8762
  y,
@@ -8817,7 +8818,7 @@ class Table {
8817
8818
  cloned.addressCaches = /* @__PURE__ */ new Map();
8818
8819
  this.wire.onRemoveRows({ table: cloned, ys: ys.reverse() });
8819
8820
  }
8820
- return this.refresh(false);
8821
+ return this.refresh(true, true);
8821
8822
  }
8822
8823
  insertCols({
8823
8824
  x,
@@ -8883,7 +8884,7 @@ class Table {
8883
8884
  cloned.addressCaches = /* @__PURE__ */ new Map();
8884
8885
  this.wire.onInsertCols({ table: cloned, x, numCols });
8885
8886
  }
8886
- return this.refresh(false);
8887
+ return this.refresh(true, true);
8887
8888
  }
8888
8889
  removeCols({
8889
8890
  x,
@@ -8948,7 +8949,7 @@ class Table {
8948
8949
  cloned.addressCaches = /* @__PURE__ */ new Map();
8949
8950
  this.wire.onRemoveCols({ table: cloned, xs: xs.reverse() });
8950
8951
  }
8951
- return this.refresh(false);
8952
+ return this.refresh(true, true);
8952
8953
  }
8953
8954
  getHistories() {
8954
8955
  return [...this.wire.histories];
@@ -9108,7 +9109,7 @@ class Table {
9108
9109
  break;
9109
9110
  }
9110
9111
  }
9111
- this.refresh(!shouldTracking(history.operation));
9112
+ this.refresh(shouldTracking(history.operation), true);
9112
9113
  return {
9113
9114
  history,
9114
9115
  callback: ({ tableReactive: tableRef }) => {
@@ -9180,7 +9181,7 @@ class Table {
9180
9181
  }
9181
9182
  }
9182
9183
  }
9183
- this.refresh(!shouldTracking(history.operation));
9184
+ this.refresh(shouldTracking(history.operation), true);
9184
9185
  return {
9185
9186
  history,
9186
9187
  callback: ({ tableReactive: tableRef }) => {
@@ -10089,9 +10090,7 @@ const Tabular = () => {
10089
10090
  sheetHeight,
10090
10091
  inputting,
10091
10092
  leftHeaderSelecting,
10092
- topHeaderSelecting,
10093
- totalWidth,
10094
- totalHeight
10093
+ topHeaderSelecting
10095
10094
  } = store;
10096
10095
  const table = tableReactive.current;
10097
10096
  const [virtualized, setVirtualized] = useState(null);
@@ -10200,8 +10199,8 @@ const Tabular = () => {
10200
10199
  {
10201
10200
  className: "gs-tabular-inner",
10202
10201
  style: {
10203
- width: totalWidth + 1,
10204
- height: totalHeight + 1
10202
+ width: table.totalWidth + 1,
10203
+ height: table.totalHeight + 1
10205
10204
  },
10206
10205
  children: /* @__PURE__ */ jsxs("table", { className: `gs-table`, children: [
10207
10206
  /* @__PURE__ */ jsx("thead", { className: "gs-thead", style: { height: table.headerHeight }, children: /* @__PURE__ */ jsxs("tr", { className: "gs-row", children: [
@@ -10735,6 +10734,7 @@ function GridSheet({
10735
10734
  style,
10736
10735
  hub: initialHub
10737
10736
  }) {
10737
+ var _a, _b;
10738
10738
  const { sheetResize, showFormulaBar = true, mode = "light" } = options;
10739
10739
  const rootRef = useRef(null);
10740
10740
  const mainRef = useRef(null);
@@ -10754,7 +10754,7 @@ function GridSheet({
10754
10754
  const sheetId = sheetIdRef.current;
10755
10755
  const tableReactive = useRef(null);
10756
10756
  const [initialState] = useState(() => {
10757
- var _a;
10757
+ var _a2;
10758
10758
  if (!sheetName) {
10759
10759
  sheetName = `Sheet${sheetId}`;
10760
10760
  console.debug("GridSheet: sheetName is not provided, using default name:", sheetName);
@@ -10771,7 +10771,8 @@ function GridSheet({
10771
10771
  table.sheetId = sheetId;
10772
10772
  wire.sheetIdsByName[sheetName] = sheetId;
10773
10773
  table.initialize(initialCells);
10774
- (_a = wire.onInit) == null ? void 0 : _a.call(wire, { table });
10774
+ (_a2 = wire.onInit) == null ? void 0 : _a2.call(wire, { table });
10775
+ table.setTotalSize();
10775
10776
  tableReactive.current = table;
10776
10777
  const store2 = {
10777
10778
  sheetId,
@@ -10807,8 +10808,7 @@ function GridSheet({
10807
10808
  maxNumRows: -1,
10808
10809
  minNumCols: 1,
10809
10810
  maxNumCols: -1,
10810
- mode: "light",
10811
- ...table.getTotalSize()
10811
+ mode: "light"
10812
10812
  };
10813
10813
  return store2;
10814
10814
  });
@@ -10824,9 +10824,9 @@ function GridSheet({
10824
10824
  const [sheetWidth, setSheetWidth] = useState((options == null ? void 0 : options.sheetWidth) || estimateSheetWidth(initialCells));
10825
10825
  useEffect(() => {
10826
10826
  const intervalId = window.setInterval(() => {
10827
- var _a, _b;
10828
- setSheetHeight(((_a = mainRef.current) == null ? void 0 : _a.clientHeight) || 0);
10829
- setSheetWidth(((_b = mainRef.current) == null ? void 0 : _b.clientWidth) || 0);
10827
+ var _a2, _b2;
10828
+ setSheetHeight(((_a2 = mainRef.current) == null ? void 0 : _a2.clientHeight) || 0);
10829
+ setSheetWidth(((_b2 = mainRef.current) == null ? void 0 : _b2.clientWidth) || 0);
10830
10830
  }, 1e3);
10831
10831
  return () => window.clearInterval(intervalId);
10832
10832
  }, []);
@@ -10859,8 +10859,8 @@ function GridSheet({
10859
10859
  ref: mainRef,
10860
10860
  style: {
10861
10861
  //width: '100%',
10862
- maxWidth: (store.totalWidth || 0) + 2,
10863
- maxHeight: (store.totalHeight || 0) + 2,
10862
+ maxWidth: (((_a = store.tableReactive.current) == null ? void 0 : _a.totalWidth) || 0) + 2,
10863
+ maxHeight: (((_b = store.tableReactive.current) == null ? void 0 : _b.totalHeight) || 0) + 2,
10864
10864
  overflow: "auto",
10865
10865
  resize: sheetResize,
10866
10866
  ...style