@gridsheet/preact-core 3.0.2 → 3.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.
package/dist/index.js CHANGED
@@ -2901,6 +2901,7 @@ const safePreventDefault = (e) => {
2901
2901
  }
2902
2902
  };
2903
2903
  const Cell = memo(({ y, x }) => {
2904
+ var _a;
2904
2905
  const rowId = y2r(y);
2905
2906
  const colId = x2c(x);
2906
2907
  const address = `${colId}${rowId}`;
@@ -2926,8 +2927,8 @@ const Cell = memo(({ y, x }) => {
2926
2927
  const editing = editingAddress === address;
2927
2928
  const pointed = choosing.y === y && choosing.x === x;
2928
2929
  const _setEditorRect = useCallback(() => {
2929
- var _a;
2930
- const rect = (_a = cellRef.current) == null ? void 0 : _a.getBoundingClientRect();
2930
+ var _a2;
2931
+ const rect = (_a2 = cellRef.current) == null ? void 0 : _a2.getBoundingClientRect();
2931
2932
  if (rect == null) {
2932
2933
  return null;
2933
2934
  }
@@ -3104,8 +3105,8 @@ const Cell = memo(({ y, x }) => {
3104
3105
  [dispatch, x, y]
3105
3106
  );
3106
3107
  const handleErrorTriangleEnter = useCallback(() => {
3107
- var _a;
3108
- const rect = (_a = cellRef.current) == null ? void 0 : _a.getBoundingClientRect();
3108
+ var _a2;
3109
+ const rect = (_a2 = cellRef.current) == null ? void 0 : _a2.getBoundingClientRect();
3109
3110
  if (!rect) {
3110
3111
  return;
3111
3112
  }
@@ -3184,7 +3185,7 @@ const Cell = memo(({ y, x }) => {
3184
3185
  className: "gs-cell-inner",
3185
3186
  style: {
3186
3187
  ...cell == null ? void 0 : cell.style,
3187
- justifyContent: (cell == null ? void 0 : cell.justifyContent) || "left",
3188
+ textAlign: ((_a = cell == null ? void 0 : cell.style) == null ? void 0 : _a.textAlign) || (cell == null ? void 0 : cell.justifyContent) || "left",
3188
3189
  alignItems: (cell == null ? void 0 : cell.alignItems) || "start"
3189
3190
  },
3190
3191
  children: [
@@ -3196,7 +3197,18 @@ const Cell = memo(({ y, x }) => {
3196
3197
  onMouseLeave: handleErrorTriangleLeave
3197
3198
  }
3198
3199
  ),
3199
- /* @__PURE__ */ jsx("div", { className: "gs-cell-rendered", children: rendered })
3200
+ /* @__PURE__ */ jsx(
3201
+ "div",
3202
+ {
3203
+ className: "gs-cell-rendered",
3204
+ style: (cell == null ? void 0 : cell.alignItems) ? {
3205
+ display: "flex",
3206
+ flexDirection: "column",
3207
+ justifyContent: cell.alignItems === "center" ? "center" : cell.alignItems === "end" ? "flex-end" : void 0
3208
+ } : void 0,
3209
+ children: rendered
3210
+ }
3211
+ )
3200
3212
  ]
3201
3213
  }
3202
3214
  ),
@@ -3607,7 +3619,6 @@ const HeaderCellTop = memo(({ x }) => {
3607
3619
  dispatch(setColumnMenu({ x, position: { y: rect.bottom, x: rect.left } }));
3608
3620
  }
3609
3621
  },
3610
- title: "Sort & Filter",
3611
3622
  children: "⋮"
3612
3623
  }
3613
3624
  ),
@@ -3837,7 +3848,6 @@ const HeaderCellLeft = memo(({ y }) => {
3837
3848
  dispatch(setRowMenu({ y, position: { y: rect.bottom, x: rect.right } }));
3838
3849
  }
3839
3850
  },
3840
- title: "Row menu",
3841
3851
  children: "⋮"
3842
3852
  }
3843
3853
  ),
@@ -4101,10 +4111,13 @@ const CellStateOverlay = ({ refs = {} }) => {
4101
4111
  return;
4102
4112
  }
4103
4113
  container.addEventListener("scroll", handleScroll);
4114
+ const ro = new ResizeObserver(() => drawCanvas());
4115
+ ro.observe(container);
4104
4116
  return () => {
4105
4117
  container.removeEventListener("scroll", handleScroll);
4118
+ ro.disconnect();
4106
4119
  };
4107
- }, [tabularRef, handleScroll]);
4120
+ }, [tabularRef, handleScroll, drawCanvas]);
4108
4121
  return /* @__PURE__ */ jsx(
4109
4122
  "div",
4110
4123
  {
@@ -4264,8 +4277,9 @@ const Tabular = () => {
4264
4277
  {
4265
4278
  className: "gs-tabular-inner",
4266
4279
  style: {
4267
- width: sheet.totalWidth + 1,
4268
- height: sheet.totalHeight + 1
4280
+ width: sheet.totalWidth,
4281
+ height: sheet.totalHeight,
4282
+ overflow: "clip"
4269
4283
  },
4270
4284
  children: [
4271
4285
  /* @__PURE__ */ jsx(CellStateOverlay, { refs: mergedRefs }),
@@ -4291,7 +4305,6 @@ const Tabular = () => {
4291
4305
  "button",
4292
4306
  {
4293
4307
  className: "gs-menu-btn gs-corner-menu-btn",
4294
- title: "Menu",
4295
4308
  onClick: (e) => e.stopPropagation(),
4296
4309
  onMouseDown: (e) => {
4297
4310
  e.preventDefault();
@@ -5042,12 +5055,25 @@ function GridSheet({
5042
5055
  const [sheetHeight, setSheetHeight] = useState((options == null ? void 0 : options.sheetHeight) || estimateSheetHeight(initialCells));
5043
5056
  const [sheetWidth, setSheetWidth] = useState((options == null ? void 0 : options.sheetWidth) || estimateSheetWidth(initialCells));
5044
5057
  useEffect(() => {
5045
- const intervalId = window.setInterval(() => {
5046
- var _a2, _b2;
5047
- setSheetHeight(((_a2 = mainRef.current) == null ? void 0 : _a2.clientHeight) || 0);
5048
- setSheetWidth(((_b2 = mainRef.current) == null ? void 0 : _b2.clientWidth) || 0);
5049
- }, 1e3);
5050
- return () => window.clearInterval(intervalId);
5058
+ const el = mainRef.current;
5059
+ if (!el) {
5060
+ return;
5061
+ }
5062
+ let first = true;
5063
+ const ro = new ResizeObserver(() => {
5064
+ if (first) {
5065
+ first = false;
5066
+ return;
5067
+ }
5068
+ if (!options.sheetHeight) {
5069
+ setSheetHeight(el.clientHeight);
5070
+ }
5071
+ if (!options.sheetWidth) {
5072
+ setSheetWidth(el.clientWidth);
5073
+ }
5074
+ });
5075
+ ro.observe(el);
5076
+ return () => ro.disconnect();
5051
5077
  }, []);
5052
5078
  useEffect(() => {
5053
5079
  if (options.sheetHeight) {
@@ -5083,7 +5109,6 @@ function GridSheet({
5083
5109
  //width: '100%',
5084
5110
  maxWidth: (((_c = store.sheetReactive.current) == null ? void 0 : _c.totalWidth) || 0) + 2,
5085
5111
  maxHeight: (((_d = store.sheetReactive.current) == null ? void 0 : _d.fullHeight) || 0) + 2,
5086
- overflow: "auto",
5087
5112
  resize: sheetResize,
5088
5113
  ...style
5089
5114
  },