@gridsheet/preact-core 3.0.7 → 3.2.0

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.
@@ -3,6 +3,8 @@ import { OptionsType, SheetHandle, StoreHandle } from '../types';
3
3
  type StoreObserverProps = Omit<OptionsType, 'sheetHeight' | 'sheetWidth'> & {
4
4
  sheetHeight?: number;
5
5
  sheetWidth?: number;
6
+ fixedWidth?: boolean;
7
+ fixedHeight?: boolean;
6
8
  sheetName?: string;
7
9
  sheetRef?: MutableRefObject<SheetHandle | null>;
8
10
  storeRef?: MutableRefObject<StoreHandle | null>;
package/dist/index.js CHANGED
@@ -1491,6 +1491,8 @@ const StoreObserver = ({
1491
1491
  sheetName,
1492
1492
  sheetHeight,
1493
1493
  sheetWidth,
1494
+ fixedWidth,
1495
+ fixedHeight,
1494
1496
  sheetRef,
1495
1497
  storeRef,
1496
1498
  editingOnEnter,
@@ -1546,6 +1548,9 @@ const StoreObserver = ({
1546
1548
  dispatch(setStore({ sheetWidth }));
1547
1549
  }
1548
1550
  }, [sheetWidth]);
1551
+ useEffect(() => {
1552
+ dispatch(setStore({ fixedWidth: !!fixedWidth, fixedHeight: !!fixedHeight }));
1553
+ }, [fixedWidth, fixedHeight]);
1549
1554
  useEffect(() => {
1550
1555
  if (typeof editingOnEnter !== "undefined") {
1551
1556
  dispatch(setStore({ editingOnEnter }));
@@ -3401,7 +3406,9 @@ function ScrollHandle({ style, horizontal = 0, vertical = 0, className = "" }) {
3401
3406
  useEffect(() => {
3402
3407
  return stopScroll;
3403
3408
  }, [stopScroll]);
3404
- if (!editorRef.current || !dragging && !autofillDraggingTo) {
3409
+ const t = tabularRef.current;
3410
+ const cannotScrollHere = !!t && (horizontal > 0 && t.scrollLeft + t.clientWidth >= t.scrollWidth - 1 || horizontal < 0 && t.scrollLeft <= 0 || vertical > 0 && t.scrollTop + t.clientHeight >= t.scrollHeight - 1 || vertical < 0 && t.scrollTop <= 0);
3411
+ if (!editorRef.current || !dragging && !autofillDraggingTo || cannotScrollHere) {
3405
3412
  return /* @__PURE__ */ jsx("div", { className: `gs-scroll-handle gs-hidden ${className}` });
3406
3413
  }
3407
3414
  return /* @__PURE__ */ jsx(
@@ -4176,6 +4183,8 @@ const Tabular = () => {
4176
4183
  mainRef,
4177
4184
  sheetWidth,
4178
4185
  sheetHeight,
4186
+ fixedWidth,
4187
+ fixedHeight,
4179
4188
  inputting,
4180
4189
  leftHeaderSelecting,
4181
4190
  topHeaderSelecting,
@@ -4183,6 +4192,24 @@ const Tabular = () => {
4183
4192
  } = store;
4184
4193
  const sheet = sheetReactive.current;
4185
4194
  const [virtualized, setVirtualized] = useState(null);
4195
+ useEffect(() => {
4196
+ const t = tabularRef.current;
4197
+ const m = mainRef.current;
4198
+ if (!t || !m) {
4199
+ return;
4200
+ }
4201
+ const raf = requestAnimationFrame(() => {
4202
+ const ox = String(t.scrollWidth > t.clientWidth + 1);
4203
+ const oy = String(t.scrollHeight > t.clientHeight + 1);
4204
+ if (m.getAttribute("data-overflow-x") !== ox) {
4205
+ m.setAttribute("data-overflow-x", ox);
4206
+ }
4207
+ if (m.getAttribute("data-overflow-y") !== oy) {
4208
+ m.setAttribute("data-overflow-y", oy);
4209
+ }
4210
+ });
4211
+ return () => cancelAnimationFrame(raf);
4212
+ });
4186
4213
  const handleMouseMove = useCallback((e) => {
4187
4214
  e.preventDefault();
4188
4215
  e.stopPropagation();
@@ -4280,6 +4307,12 @@ const Tabular = () => {
4280
4307
  }
4281
4308
  return preventSafariBounce(el);
4282
4309
  }, [sheetReactive]);
4310
+ useEffect(() => {
4311
+ if (!sheet || !sheet.eager || !sheet.registry.ready) {
4312
+ return;
4313
+ }
4314
+ sheet.resolveAll();
4315
+ }, [sheet, sheetReactive]);
4283
4316
  const mergedRefs = {
4284
4317
  ...palette,
4285
4318
  ...sheet ? sheet.registry.paletteBySheetName[sheet.name] : {}
@@ -4292,8 +4325,10 @@ const Tabular = () => {
4292
4325
  {
4293
4326
  className: "gs-tabular",
4294
4327
  style: {
4295
- width: sheetWidth === -1 ? void 0 : Math.min(sheetWidth, sheet.totalWidth),
4296
- height: sheetHeight === -1 ? void 0 : Math.min(sheetHeight, sheet.totalHeight)
4328
+ // When a size is explicitly configured, keep that box so a smaller grid can be
4329
+ // centered within it (see .gs-tabular in tabular.less); otherwise shrink to fit.
4330
+ width: sheetWidth === -1 ? void 0 : fixedWidth ? sheetWidth : Math.min(sheetWidth, sheet.totalWidth),
4331
+ height: sheetHeight === -1 ? void 0 : fixedHeight ? sheetHeight : Math.min(sheetHeight, sheet.totalHeight)
4297
4332
  },
4298
4333
  ref: tabularRef,
4299
4334
  onMouseMove: handleMouseMove,
@@ -4660,7 +4695,7 @@ const FormulaBar = ({ ready }) => {
4660
4695
  if (!sheet) {
4661
4696
  return /* @__PURE__ */ jsxs("label", { className: "gs-formula-bar gs-hidden", style, children: [
4662
4697
  /* @__PURE__ */ jsx("div", { className: "gs-selecting-address" }),
4663
- /* @__PURE__ */ jsx("div", { className: "gs-fx", children: "Fx" }),
4698
+ /* @__PURE__ */ jsx("div", { className: "gs-fx", children: "fx" }),
4664
4699
  /* @__PURE__ */ jsx("div", { className: "gs-formula-bar-editor-inner", children: /* @__PURE__ */ jsx("textarea", {}) })
4665
4700
  ] });
4666
4701
  }
@@ -4713,7 +4748,7 @@ const FormulaBar = ({ ready }) => {
4713
4748
  children: [
4714
4749
  /* @__PURE__ */ jsx(ScrollHandle, { style: { position: "absolute", left: 0, top: 0, zIndex: 2 }, vertical: -1 }),
4715
4750
  /* @__PURE__ */ jsx("div", { className: "gs-selecting-address", children: originAddress != null ? originAddress : address }),
4716
- /* @__PURE__ */ jsx("div", { className: "gs-fx", children: "Fx" }),
4751
+ /* @__PURE__ */ jsx("div", { className: "gs-fx", children: "fx" }),
4717
4752
  /* @__PURE__ */ jsxs("div", { className: "gs-formula-bar-editor-inner", children: [
4718
4753
  /* @__PURE__ */ jsx(
4719
4754
  "div",
@@ -4998,7 +5033,26 @@ function GridSheet({
4998
5033
  book: initialBook
4999
5034
  }) {
5000
5035
  var _a, _b, _c;
5001
- const { sheetResize, showFormulaBar = true, mode = "light" } = options;
5036
+ const {
5037
+ sheetResize,
5038
+ showFormulaBar = true,
5039
+ mode = "light",
5040
+ density = "compact",
5041
+ gridLines = "all",
5042
+ formulaBarBorders = { all: true },
5043
+ matrixBorders = { all: true }
5044
+ } = options;
5045
+ const bw = (b, side) => b[side] ?? b.all ?? false ? "1px" : "0";
5046
+ const borderVars = {
5047
+ "--gs-fb-bl": bw(formulaBarBorders, "left"),
5048
+ "--gs-fb-bt": bw(formulaBarBorders, "top"),
5049
+ "--gs-fb-br": bw(formulaBarBorders, "right"),
5050
+ "--gs-fb-bb": bw(formulaBarBorders, "bottom"),
5051
+ "--gs-mx-bl": bw(matrixBorders, "left"),
5052
+ "--gs-mx-bt": bw(matrixBorders, "top"),
5053
+ "--gs-mx-br": bw(matrixBorders, "right"),
5054
+ "--gs-mx-bb": bw(matrixBorders, "bottom")
5055
+ };
5002
5056
  const rootRef = useRef(null);
5003
5057
  const flashRef = useRef(null);
5004
5058
  const mainRef = useRef(null);
@@ -5029,11 +5083,12 @@ function GridSheet({
5029
5083
  sheetName = `Sheet${sheetId}`;
5030
5084
  console.debug("GridSheet: sheetName is not provided, using default name:", sheetName);
5031
5085
  }
5032
- const { limits, contextMenu, rowMenu, colMenu } = options;
5086
+ const { limits, contextMenu, rowMenu, colMenu, eager } = options;
5033
5087
  const sheet = new Sheet({
5034
5088
  limits,
5035
5089
  name: sheetName,
5036
- registry
5090
+ registry,
5091
+ eager
5037
5092
  });
5038
5093
  sheet.id = sheetId;
5039
5094
  registry.sheetIdsByName[sheetName] = sheetId;
@@ -5062,6 +5117,8 @@ function GridSheet({
5062
5117
  dragging: false,
5063
5118
  sheetHeight: 0,
5064
5119
  sheetWidth: 0,
5120
+ fixedWidth: false,
5121
+ fixedHeight: false,
5065
5122
  entering: false,
5066
5123
  matchingCells: [],
5067
5124
  matchingCellIndex: 0,
@@ -5091,6 +5148,13 @@ function GridSheet({
5091
5148
  }, []);
5092
5149
  const fillWidth = typeof options.sheetWidth === "string";
5093
5150
  const fillHeight = typeof options.sheetHeight === "string";
5151
+ const matrixAlignment = options.matrixAlignment ?? "none";
5152
+ const centersWidth = matrixAlignment === "horizontal" || matrixAlignment === "both";
5153
+ const centersHeight = matrixAlignment === "vertical" || matrixAlignment === "both";
5154
+ const [resizedWidth, setResizedWidth] = useState(false);
5155
+ const [resizedHeight, setResizedHeight] = useState(false);
5156
+ const fixedWidth = centersWidth && (options.sheetWidth != null || resizedWidth);
5157
+ const fixedHeight = centersHeight && (options.sheetHeight != null || resizedHeight);
5094
5158
  const [sheetHeight, setSheetHeight] = useState(
5095
5159
  typeof (options == null ? void 0 : options.sheetHeight) === "number" ? options.sheetHeight : estimateSheetHeight(initialCells)
5096
5160
  );
@@ -5104,6 +5168,12 @@ function GridSheet({
5104
5168
  }
5105
5169
  let first = true;
5106
5170
  const ro = new ResizeObserver(() => {
5171
+ if (el.style.width) {
5172
+ setResizedWidth(true);
5173
+ }
5174
+ if (el.style.height) {
5175
+ setResizedHeight(true);
5176
+ }
5107
5177
  if (first) {
5108
5178
  first = false;
5109
5179
  if (!fillWidth && !fillHeight) {
@@ -5153,15 +5223,19 @@ function GridSheet({
5153
5223
  ref: rootRef,
5154
5224
  "data-sheet-name": sheetName,
5155
5225
  "data-mode": mode,
5226
+ "data-density": density,
5227
+ "data-gridlines": gridLines,
5228
+ "data-matrix-align": matrixAlignment,
5156
5229
  "data-rows": ((_a = store.sheetReactive.current) == null ? void 0 : _a.numRows) ?? 0,
5157
5230
  "data-cols": ((_b = store.sheetReactive.current) == null ? void 0 : _b.numCols) ?? 0,
5158
5231
  style: fillWidth || fillHeight ? {
5232
+ ...borderVars,
5159
5233
  // inline-flex (when width isn't filled) keeps the prior shrink-to-content width.
5160
5234
  display: fillWidth ? "flex" : "inline-flex",
5161
5235
  flexDirection: "column",
5162
5236
  ...fillWidth ? { width: options.sheetWidth } : null,
5163
5237
  ...fillHeight ? { height: options.sheetHeight } : null
5164
- } : void 0,
5238
+ } : borderVars,
5165
5239
  children: [
5166
5240
  /* @__PURE__ */ jsx("div", { className: "gs-flash-overlay", ref: flashRef }),
5167
5241
  /* @__PURE__ */ jsx(ScrollHandle, { style: { position: "fixed", top: 0, left: 0 } }),
@@ -5187,7 +5261,12 @@ function GridSheet({
5187
5261
  children: [
5188
5262
  /* @__PURE__ */ jsx(Editor, { mode }),
5189
5263
  /* @__PURE__ */ jsx(Tabular, {}),
5190
- /* @__PURE__ */ jsx(StoreObserver, { ...{ ...options, sheetHeight, sheetWidth, sheetName, sheetRef, storeRef } }),
5264
+ /* @__PURE__ */ jsx(
5265
+ StoreObserver,
5266
+ {
5267
+ ...{ ...options, sheetHeight, sheetWidth, fixedWidth, fixedHeight, sheetName, sheetRef, storeRef }
5268
+ }
5269
+ ),
5191
5270
  /* @__PURE__ */ jsx(ContextMenu, {}),
5192
5271
  /* @__PURE__ */ jsx(ColumnMenu, {}),
5193
5272
  /* @__PURE__ */ jsx(RowMenu, {}),