@gridsheet/react-core 2.0.2 → 2.0.4

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,2 +1,6 @@
1
- export declare const FormulaBar: () => JSX.Element;
1
+ type FormulaBarProps = {
2
+ ready: boolean;
3
+ };
4
+ export declare const FormulaBar: ({ ready }: FormulaBarProps) => JSX.Element;
5
+ export {};
2
6
  //# sourceMappingURL=FormulaBar.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormulaBar.d.ts","sourceRoot":"","sources":["../../src/components/FormulaBar.tsx"],"names":[],"mappings":"AAUA,eAAO,MAAM,UAAU,mBAuMtB,CAAC"}
1
+ {"version":3,"file":"FormulaBar.d.ts","sourceRoot":"","sources":["../../src/components/FormulaBar.tsx"],"names":[],"mappings":"AAUA,KAAK,eAAe,GAAG;IACrB,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,WAAW,eAAe,gBAsMpD,CAAC"}
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
  }
@@ -8344,7 +8346,7 @@ class Table {
8344
8346
  const matrixTo = this.getIdMatrixFromArea(dst);
8345
8347
  const diffBefore = {};
8346
8348
  const preserver = new ReferencePreserver(this);
8347
- const lostRows = putMatrix(this.idMatrix, matrixFrom, dst, (srcId, dstId, point) => {
8349
+ const lostRows = putMatrix(this.idMatrix, matrixFrom, dst, ({ srcValue: srcId, dstValue: dstId }) => {
8348
8350
  var _a;
8349
8351
  if (srcId == null || dstId == null) {
8350
8352
  return false;
@@ -8384,8 +8386,11 @@ class Table {
8384
8386
  });
8385
8387
  const srcTableRaw = srcTable.__raw__;
8386
8388
  const srcContext = this.wire.contextsBySheetId[srcTableRaw.sheetId];
8387
- putMatrix(srcTableRaw.idMatrix, matrixNew, src, (newId, srcId) => {
8389
+ putMatrix(srcTableRaw.idMatrix, matrixNew, src, ({ srcValue: newId, dstValue: srcId, dstPoint: srcPoint }) => {
8388
8390
  var _a;
8391
+ if (among(dst, srcPoint) && srcTable === this) {
8392
+ return false;
8393
+ }
8389
8394
  preserver.map[srcId] = newId;
8390
8395
  const srcCell = srcTableRaw.wire.data[srcId];
8391
8396
  if (operator === "USER" && hasOperation(srcCell == null ? void 0 : srcCell.prevention, MoveFrom)) {
@@ -8415,7 +8420,9 @@ class Table {
8415
8420
  Object.assign(diffBefore, resolvedDiff);
8416
8421
  if (srcTable !== this && srcContext !== null) {
8417
8422
  const { dispatch } = srcContext;
8418
- dispatch(updateTable(srcTableRaw));
8423
+ requestAnimationFrame(() => {
8424
+ dispatch(updateTable(srcTableRaw));
8425
+ });
8419
8426
  }
8420
8427
  if (historicize) {
8421
8428
  this.pushHistory({
@@ -10408,7 +10415,7 @@ const embedStyle = () => {
10408
10415
  style.setAttribute("data-modified-at", `${LAST_MODIFIED}`);
10409
10416
  style.innerText = CSS;
10410
10417
  };
10411
- const FormulaBar = () => {
10418
+ const FormulaBar = ({ ready }) => {
10412
10419
  var _a;
10413
10420
  const { store, dispatch } = useContext(Context);
10414
10421
  const [before, setBefore] = useState("");
@@ -10457,7 +10464,6 @@ const FormulaBar = () => {
10457
10464
  }, []);
10458
10465
  const largeInput = largeEditorRef.current;
10459
10466
  const handleInput = useCallback((e) => {
10460
- console.log("e.currentTarget.value", e.currentTarget.value);
10461
10467
  dispatch(setInputting(e.currentTarget.value));
10462
10468
  }, []);
10463
10469
  const updateScroll = useCallback(() => {
@@ -10549,14 +10555,15 @@ const FormulaBar = () => {
10549
10555
  },
10550
10556
  [table, choosing, before, writeCell, updateScroll]
10551
10557
  );
10558
+ const style = ready ? {} : { visibility: "hidden" };
10552
10559
  if (!table) {
10553
- return /* @__PURE__ */ jsxs("label", { className: "gs-formula-bar gs-hidden", children: [
10560
+ return /* @__PURE__ */ jsxs("label", { className: "gs-formula-bar gs-hidden", style, children: [
10554
10561
  /* @__PURE__ */ jsx("div", { className: "gs-selecting-address" }),
10555
10562
  /* @__PURE__ */ jsx("div", { className: "gs-fx", children: "Fx" }),
10556
10563
  /* @__PURE__ */ jsx("div", { className: "gs-formula-bar-editor-inner", children: /* @__PURE__ */ jsx("textarea", {}) })
10557
10564
  ] });
10558
10565
  }
10559
- return /* @__PURE__ */ jsxs("label", { className: "gs-formula-bar", children: [
10566
+ return /* @__PURE__ */ jsxs("label", { className: "gs-formula-bar", "data-sheet-id": store.sheetId, style, children: [
10560
10567
  /* @__PURE__ */ jsx(ScrollHandle, { style: { position: "absolute", left: 0, top: 0, zIndex: 2 }, vertical: -1 }),
10561
10568
  /* @__PURE__ */ jsx("div", { className: "gs-selecting-address", children: address }),
10562
10569
  /* @__PURE__ */ jsx("div", { className: "gs-fx", children: "Fx" }),
@@ -10844,7 +10851,7 @@ function GridSheet({
10844
10851
  /* @__PURE__ */ jsx(ScrollHandle, { style: { position: "fixed", top: 0, left: 0 } }),
10845
10852
  /* @__PURE__ */ jsx(ScrollHandle, { style: { position: "absolute", zIndex: 4, right: 0, top: 0, width: 5 }, horizontal: 1 }),
10846
10853
  /* @__PURE__ */ jsx(ScrollHandle, { style: { position: "absolute", zIndex: 4, left: 0, bottom: 0, height: 5 }, vertical: 1 }),
10847
- typeof store.searchQuery === "undefined" ? showFormulaBar && /* @__PURE__ */ jsx(FormulaBar, {}) : /* @__PURE__ */ jsx(SearchBar, {}),
10854
+ typeof store.searchQuery === "undefined" ? showFormulaBar && /* @__PURE__ */ jsx(FormulaBar, { ready: wire.ready }) : /* @__PURE__ */ jsx(SearchBar, {}),
10848
10855
  /* @__PURE__ */ jsxs(
10849
10856
  "div",
10850
10857
  {