@gridsheet/preact-core 3.0.5 → 3.0.7

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
@@ -4,8 +4,8 @@ import { BaseFunction, BaseFunctionAsync, DEFAULT_HISTORY_LIMIT, FormulaError as
4
4
  import { jsxs, jsx, Fragment } from "preact/compat/jsx-runtime";
5
5
  import React, { createContext, useRef, useContext, useLayoutEffect, useState, useMemo, useCallback, createPortal, memo, useEffect, createRef, useReducer } from "preact/compat";
6
6
  import { Children, Component, Fragment as Fragment2, PureComponent, StrictMode, Suspense, SuspenseList, cloneElement, render as render2, createContext as createContext2, createElement, createFactory, createPortal as createPortal2, createRef as createRef2, findDOMNode, forwardRef, hydrate, isValidElement, lazy, memo as memo2, unmountComponentAtNode, unstable_batchedUpdates, useCallback as useCallback2, useContext as useContext2, useDebugValue, useEffect as useEffect2, useImperativeHandle, useLayoutEffect as useLayoutEffect2, useMemo as useMemo2, useReducer as useReducer2, useRef as useRef2, useState as useState2, version } from "preact/compat";
7
- import { u as useBrowser, s as setEditingAddress, w as write, a as setInputting, b as updateSheet, r as redo, c as undo, d as cut, e as setSearchQuery, f as setEntering, g as copy, h as select, i as arrow, j as escape, k as clear, l as walk, p as paste, m as setEditorHovering, n as setStore, o as setResizingPositionY, q as setResizingPositionX, t as filterRows, v as sortRows, x as removeCols, y as removeRows, z as insertColsRight, A as insertColsLeft, B as insertRowsBelow, C as insertRowsAbove, D as setContextMenuPosition, E as setColumnMenu, F as setRowMenu, G as isXSheetFocused, H as setEditorRect, I as choose, J as drag, K as setDragging, L as submitAutofill, M as setAutofillDraggingTo, N as selectCols, O as useDebounceCallback, P as selectRows, Q as search, R as setSearchCaseSensitive, S as setSearchRegex, T as setSearchRange, U as useBook, V as reducer } from "./hooks-DPIr6WaL.mjs";
8
- import { W } from "./hooks-DPIr6WaL.mjs";
7
+ import { u as useBrowser, s as setEditingAddress, w as write, a as setInputting, b as updateSheet, r as redo, c as undo, d as cut, e as setSearchQuery, f as setEntering, g as copy, h as select, i as arrow, j as escape, k as clear, l as walk, p as paste, m as setEditorHovering, n as setStore, o as setResizingPositionY, q as setResizingPositionX, t as filterRows, v as sortRows, x as removeCols, y as removeRows, z as insertColsRight, A as insertColsLeft, B as insertRowsBelow, C as insertRowsAbove, D as setContextMenuPosition, E as setColumnMenu, F as setRowMenu, G as isXSheetFocused, H as setEditorRect, I as choose, J as drag, K as setDragging, L as submitAutofill, M as setAutofillDraggingTo, N as selectCols, O as useDebounceCallback, P as selectRows, Q as search, R as setSearchCaseSensitive, S as setSearchRegex, T as setSearchRange, U as useBook, V as reducer, W as isMutationAction } from "./hooks-ykrgAwg5.mjs";
8
+ import { X } from "./hooks-ykrgAwg5.mjs";
9
9
  const Context = createContext(
10
10
  {}
11
11
  );
@@ -720,6 +720,7 @@ const Editor = ({ mode }) => {
720
720
  const [shiftKey, setShiftKey] = useState(false);
721
721
  const [selectionStart, setSelectionStart] = useState(0);
722
722
  const [isFocused, setIsFocused] = useState(false);
723
+ const composingRef = useRef(false);
723
724
  const {
724
725
  choosing,
725
726
  inputting,
@@ -889,6 +890,9 @@ const Editor = ({ mode }) => {
889
890
  if (!sheet) {
890
891
  return;
891
892
  }
893
+ if (e.nativeEvent.isComposing || composingRef.current) {
894
+ return;
895
+ }
892
896
  if (isKeyDown) {
893
897
  return;
894
898
  }
@@ -1367,6 +1371,17 @@ const Editor = ({ mode }) => {
1367
1371
  onPaste: handlePaste,
1368
1372
  onKeyDown: handleKeyDown,
1369
1373
  onKeyUp: handleKeyUpInternal,
1374
+ onCompositionStart: () => {
1375
+ composingRef.current = true;
1376
+ if (!editing) {
1377
+ dispatch(setEditingAddress(address));
1378
+ dispatch(setInputting(""));
1379
+ }
1380
+ },
1381
+ onCompositionEnd: (e) => {
1382
+ composingRef.current = false;
1383
+ dispatch(setInputting(e.currentTarget.value));
1384
+ },
1370
1385
  onMouseEnter: () => {
1371
1386
  dispatch(setEditorHovering(true));
1372
1387
  },
@@ -4082,6 +4097,10 @@ const CellStateOverlay = ({ refs = {} }) => {
4082
4097
  }
4083
4098
  }, [
4084
4099
  sheet,
4100
+ // The Sheet instance is mutated in place, so its identity stays stable across structural
4101
+ // changes (insert/remove rows & cols, resize, sort, filter). Depend on its monotonic version
4102
+ // so the overlay redraws when the grid layout shifts; otherwise the old box stays misaligned.
4103
+ sheet == null ? void 0 : sheet.currentVersion,
4085
4104
  tabularRef,
4086
4105
  choosing,
4087
4106
  selectingZone,
@@ -4246,7 +4265,14 @@ const Tabular = () => {
4246
4265
  return;
4247
4266
  }
4248
4267
  setVirtualized(virtualize(sheet, tabularRef.current));
4249
- }, [tabularRef.current, sheetReactive, (_a = mainRef.current) == null ? void 0 : _a.clientHeight, (_b = mainRef.current) == null ? void 0 : _b.clientWidth]);
4268
+ }, [
4269
+ tabularRef.current,
4270
+ sheetReactive,
4271
+ (_a = mainRef.current) == null ? void 0 : _a.clientHeight,
4272
+ (_b = mainRef.current) == null ? void 0 : _b.clientWidth,
4273
+ sheetHeight,
4274
+ sheetWidth
4275
+ ]);
4250
4276
  useEffect(() => {
4251
4277
  const el = tabularRef.current;
4252
4278
  if (!el) {
@@ -4266,8 +4292,8 @@ const Tabular = () => {
4266
4292
  {
4267
4293
  className: "gs-tabular",
4268
4294
  style: {
4269
- width: sheetWidth === -1 ? void 0 : sheetWidth,
4270
- height: sheetHeight === -1 ? void 0 : sheetHeight
4295
+ width: sheetWidth === -1 ? void 0 : Math.min(sheetWidth, sheet.totalWidth),
4296
+ height: sheetHeight === -1 ? void 0 : Math.min(sheetHeight, sheet.totalHeight)
4271
4297
  },
4272
4298
  ref: tabularRef,
4273
4299
  onMouseMove: handleMouseMove,
@@ -4443,6 +4469,7 @@ const FormulaBar = ({ ready }) => {
4443
4469
  optionsAll,
4444
4470
  functions: sheet == null ? void 0 : sheet.registry.functions
4445
4471
  });
4472
+ const composingRef = useRef(false);
4446
4473
  const largeInput = largeEditorRef.current;
4447
4474
  const handleInput = useCallback((e) => {
4448
4475
  dispatch(setInputting(e.currentTarget.value));
@@ -4485,6 +4512,9 @@ const FormulaBar = ({ ready }) => {
4485
4512
  );
4486
4513
  const handleKeyDown = useCallback(
4487
4514
  (e) => {
4515
+ if (e.nativeEvent.isComposing || composingRef.current) {
4516
+ return;
4517
+ }
4488
4518
  if (e.ctrlKey || !sheet) {
4489
4519
  return true;
4490
4520
  }
@@ -4716,6 +4746,13 @@ const FormulaBar = ({ ready }) => {
4716
4746
  },
4717
4747
  onKeyDown: handleKeyDown,
4718
4748
  onKeyUp: updateScroll,
4749
+ onCompositionStart: () => {
4750
+ composingRef.current = true;
4751
+ },
4752
+ onCompositionEnd: (e) => {
4753
+ composingRef.current = false;
4754
+ dispatch(setInputting(e.currentTarget.value));
4755
+ },
4719
4756
  onScroll: updateScroll,
4720
4757
  onMouseEnter: (e) => {
4721
4758
  dispatch(setEditorHovering(true));
@@ -4960,7 +4997,7 @@ function GridSheet({
4960
4997
  style,
4961
4998
  book: initialBook
4962
4999
  }) {
4963
- var _a, _b, _c, _d;
5000
+ var _a, _b, _c;
4964
5001
  const { sheetResize, showFormulaBar = true, mode = "light" } = options;
4965
5002
  const rootRef = useRef(null);
4966
5003
  const flashRef = useRef(null);
@@ -5052,8 +5089,14 @@ function GridSheet({
5052
5089
  useEffect(() => {
5053
5090
  embedStyle();
5054
5091
  }, []);
5055
- const [sheetHeight, setSheetHeight] = useState((options == null ? void 0 : options.sheetHeight) || estimateSheetHeight(initialCells));
5056
- const [sheetWidth, setSheetWidth] = useState((options == null ? void 0 : options.sheetWidth) || estimateSheetWidth(initialCells));
5092
+ const fillWidth = typeof options.sheetWidth === "string";
5093
+ const fillHeight = typeof options.sheetHeight === "string";
5094
+ const [sheetHeight, setSheetHeight] = useState(
5095
+ typeof (options == null ? void 0 : options.sheetHeight) === "number" ? options.sheetHeight : estimateSheetHeight(initialCells)
5096
+ );
5097
+ const [sheetWidth, setSheetWidth] = useState(
5098
+ typeof (options == null ? void 0 : options.sheetWidth) === "number" ? options.sheetWidth : estimateSheetWidth(initialCells)
5099
+ );
5057
5100
  useEffect(() => {
5058
5101
  const el = mainRef.current;
5059
5102
  if (!el) {
@@ -5063,25 +5106,47 @@ function GridSheet({
5063
5106
  const ro = new ResizeObserver(() => {
5064
5107
  if (first) {
5065
5108
  first = false;
5066
- return;
5109
+ if (!fillWidth && !fillHeight) {
5110
+ return;
5111
+ }
5067
5112
  }
5068
- setSheetHeight(options.sheetHeight ? Math.min(options.sheetHeight, el.clientHeight) : el.clientHeight);
5069
- setSheetWidth(options.sheetWidth ? Math.min(options.sheetWidth, el.clientWidth) : el.clientWidth);
5113
+ const root = rootRef.current;
5114
+ setSheetHeight(root ? Math.min(el.clientHeight, root.clientHeight) : el.clientHeight);
5115
+ setSheetWidth(root ? Math.min(el.clientWidth, root.clientWidth) : el.clientWidth);
5070
5116
  });
5071
5117
  ro.observe(el);
5072
5118
  return () => ro.disconnect();
5073
- }, []);
5119
+ }, [fillWidth, fillHeight]);
5074
5120
  useEffect(() => {
5075
- if (options.sheetHeight) {
5121
+ if (typeof options.sheetHeight === "number") {
5076
5122
  setSheetHeight(options.sheetHeight);
5077
5123
  }
5078
5124
  }, [options.sheetHeight]);
5079
5125
  useEffect(() => {
5080
- if (options.sheetWidth) {
5126
+ if (typeof options.sheetWidth === "number") {
5081
5127
  setSheetWidth(options.sheetWidth);
5082
5128
  }
5083
5129
  }, [options.sheetWidth]);
5084
- return /* @__PURE__ */ jsx(Context.Provider, { value: { store, dispatch }, children: /* @__PURE__ */ jsxs(
5130
+ const [loading, setLoading] = useState(false);
5131
+ useEffect(() => {
5132
+ if (loading) {
5133
+ setLoading(false);
5134
+ }
5135
+ });
5136
+ const wrappedDispatch = useCallback(
5137
+ (action) => {
5138
+ if (!isMutationAction(action.type)) {
5139
+ dispatch(action);
5140
+ return;
5141
+ }
5142
+ setLoading(true);
5143
+ requestAnimationFrame(() => {
5144
+ dispatch(action);
5145
+ });
5146
+ },
5147
+ [dispatch]
5148
+ );
5149
+ return /* @__PURE__ */ jsx(Context.Provider, { value: { store, dispatch: wrappedDispatch }, children: /* @__PURE__ */ jsxs(
5085
5150
  "div",
5086
5151
  {
5087
5152
  className: `gs-root1 ${registry.ready ? "gs-initialized" : ""}`,
@@ -5090,6 +5155,13 @@ function GridSheet({
5090
5155
  "data-mode": mode,
5091
5156
  "data-rows": ((_a = store.sheetReactive.current) == null ? void 0 : _a.numRows) ?? 0,
5092
5157
  "data-cols": ((_b = store.sheetReactive.current) == null ? void 0 : _b.numCols) ?? 0,
5158
+ style: fillWidth || fillHeight ? {
5159
+ // inline-flex (when width isn't filled) keeps the prior shrink-to-content width.
5160
+ display: fillWidth ? "flex" : "inline-flex",
5161
+ flexDirection: "column",
5162
+ ...fillWidth ? { width: options.sheetWidth } : null,
5163
+ ...fillHeight ? { height: options.sheetHeight } : null
5164
+ } : void 0,
5093
5165
  children: [
5094
5166
  /* @__PURE__ */ jsx("div", { className: "gs-flash-overlay", ref: flashRef }),
5095
5167
  /* @__PURE__ */ jsx(ScrollHandle, { style: { position: "fixed", top: 0, left: 0 } }),
@@ -5102,9 +5174,13 @@ function GridSheet({
5102
5174
  className: `gs-main ${className || ""}`,
5103
5175
  ref: mainRef,
5104
5176
  style: {
5105
- //width: '100%',
5106
- maxWidth: (((_c = store.sheetReactive.current) == null ? void 0 : _c.totalWidth) || 0) + 2,
5107
- maxHeight: (((_d = store.sheetReactive.current) == null ? void 0 : _d.fullHeight) || 0) + 2,
5177
+ ...fillWidth ? { width: "100%" } : null,
5178
+ maxWidth: "100%",
5179
+ // In fill-height mode the parent's height is the limit (flex:1 fills the remaining
5180
+ // space below the formula bar); otherwise cap at the viewport bottom as before.
5181
+ ...fillHeight ? { flex: 1, minHeight: 0, maxHeight: "100%" } : {
5182
+ maxHeight: mainRef.current ? window.innerHeight - mainRef.current.getBoundingClientRect().top : (((_c = store.sheetReactive.current) == null ? void 0 : _c.fullHeight) || 0) + 2
5183
+ },
5108
5184
  resize: sheetResize,
5109
5185
  ...style
5110
5186
  },
@@ -5116,7 +5192,8 @@ function GridSheet({
5116
5192
  /* @__PURE__ */ jsx(ColumnMenu, {}),
5117
5193
  /* @__PURE__ */ jsx(RowMenu, {}),
5118
5194
  /* @__PURE__ */ jsx(Resizer, {}),
5119
- /* @__PURE__ */ jsx(Emitter, {})
5195
+ /* @__PURE__ */ jsx(Emitter, {}),
5196
+ loading && /* @__PURE__ */ jsx("div", { className: "gs-loading-overlay", children: /* @__PURE__ */ jsx("div", { className: "gs-loading-spinner" }) })
5120
5197
  ]
5121
5198
  }
5122
5199
  )
@@ -5295,7 +5372,7 @@ export {
5295
5372
  useSheetRef,
5296
5373
  useState2 as useState,
5297
5374
  useStoreRef,
5298
- W as userActions,
5375
+ X as userActions,
5299
5376
  version,
5300
5377
  x2c2 as x2c,
5301
5378
  y2r2 as y2r,