@gridsheet/preact-core 3.0.3 → 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
  ),
@@ -4099,10 +4111,13 @@ const CellStateOverlay = ({ refs = {} }) => {
4099
4111
  return;
4100
4112
  }
4101
4113
  container.addEventListener("scroll", handleScroll);
4114
+ const ro = new ResizeObserver(() => drawCanvas());
4115
+ ro.observe(container);
4102
4116
  return () => {
4103
4117
  container.removeEventListener("scroll", handleScroll);
4118
+ ro.disconnect();
4104
4119
  };
4105
- }, [tabularRef, handleScroll]);
4120
+ }, [tabularRef, handleScroll, drawCanvas]);
4106
4121
  return /* @__PURE__ */ jsx(
4107
4122
  "div",
4108
4123
  {
@@ -4262,8 +4277,9 @@ const Tabular = () => {
4262
4277
  {
4263
4278
  className: "gs-tabular-inner",
4264
4279
  style: {
4265
- width: sheet.totalWidth + 1,
4266
- height: sheet.totalHeight + 1
4280
+ width: sheet.totalWidth,
4281
+ height: sheet.totalHeight,
4282
+ overflow: "clip"
4267
4283
  },
4268
4284
  children: [
4269
4285
  /* @__PURE__ */ jsx(CellStateOverlay, { refs: mergedRefs }),
@@ -5039,12 +5055,25 @@ function GridSheet({
5039
5055
  const [sheetHeight, setSheetHeight] = useState((options == null ? void 0 : options.sheetHeight) || estimateSheetHeight(initialCells));
5040
5056
  const [sheetWidth, setSheetWidth] = useState((options == null ? void 0 : options.sheetWidth) || estimateSheetWidth(initialCells));
5041
5057
  useEffect(() => {
5042
- const intervalId = window.setInterval(() => {
5043
- var _a2, _b2;
5044
- setSheetHeight(((_a2 = mainRef.current) == null ? void 0 : _a2.clientHeight) || 0);
5045
- setSheetWidth(((_b2 = mainRef.current) == null ? void 0 : _b2.clientWidth) || 0);
5046
- }, 1e3);
5047
- 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();
5048
5077
  }, []);
5049
5078
  useEffect(() => {
5050
5079
  if (options.sheetHeight) {
@@ -5080,7 +5109,6 @@ function GridSheet({
5080
5109
  //width: '100%',
5081
5110
  maxWidth: (((_c = store.sheetReactive.current) == null ? void 0 : _c.totalWidth) || 0) + 2,
5082
5111
  maxHeight: (((_d = store.sheetReactive.current) == null ? void 0 : _d.fullHeight) || 0) + 2,
5083
- overflow: "auto",
5084
5112
  resize: sheetResize,
5085
5113
  ...style
5086
5114
  },