@gridsheet/preact-core 3.1.0 → 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.
- package/dist/components/StoreObserver.d.ts +2 -0
- package/dist/index.js +80 -8
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +27 -1
- package/package.json +3 -3
|
@@ -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
|
-
|
|
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();
|
|
@@ -4298,8 +4325,10 @@ const Tabular = () => {
|
|
|
4298
4325
|
{
|
|
4299
4326
|
className: "gs-tabular",
|
|
4300
4327
|
style: {
|
|
4301
|
-
|
|
4302
|
-
|
|
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)
|
|
4303
4332
|
},
|
|
4304
4333
|
ref: tabularRef,
|
|
4305
4334
|
onMouseMove: handleMouseMove,
|
|
@@ -4666,7 +4695,7 @@ const FormulaBar = ({ ready }) => {
|
|
|
4666
4695
|
if (!sheet) {
|
|
4667
4696
|
return /* @__PURE__ */ jsxs("label", { className: "gs-formula-bar gs-hidden", style, children: [
|
|
4668
4697
|
/* @__PURE__ */ jsx("div", { className: "gs-selecting-address" }),
|
|
4669
|
-
/* @__PURE__ */ jsx("div", { className: "gs-fx", children: "
|
|
4698
|
+
/* @__PURE__ */ jsx("div", { className: "gs-fx", children: "fx" }),
|
|
4670
4699
|
/* @__PURE__ */ jsx("div", { className: "gs-formula-bar-editor-inner", children: /* @__PURE__ */ jsx("textarea", {}) })
|
|
4671
4700
|
] });
|
|
4672
4701
|
}
|
|
@@ -4719,7 +4748,7 @@ const FormulaBar = ({ ready }) => {
|
|
|
4719
4748
|
children: [
|
|
4720
4749
|
/* @__PURE__ */ jsx(ScrollHandle, { style: { position: "absolute", left: 0, top: 0, zIndex: 2 }, vertical: -1 }),
|
|
4721
4750
|
/* @__PURE__ */ jsx("div", { className: "gs-selecting-address", children: originAddress != null ? originAddress : address }),
|
|
4722
|
-
/* @__PURE__ */ jsx("div", { className: "gs-fx", children: "
|
|
4751
|
+
/* @__PURE__ */ jsx("div", { className: "gs-fx", children: "fx" }),
|
|
4723
4752
|
/* @__PURE__ */ jsxs("div", { className: "gs-formula-bar-editor-inner", children: [
|
|
4724
4753
|
/* @__PURE__ */ jsx(
|
|
4725
4754
|
"div",
|
|
@@ -5004,7 +5033,26 @@ function GridSheet({
|
|
|
5004
5033
|
book: initialBook
|
|
5005
5034
|
}) {
|
|
5006
5035
|
var _a, _b, _c;
|
|
5007
|
-
const {
|
|
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
|
+
};
|
|
5008
5056
|
const rootRef = useRef(null);
|
|
5009
5057
|
const flashRef = useRef(null);
|
|
5010
5058
|
const mainRef = useRef(null);
|
|
@@ -5069,6 +5117,8 @@ function GridSheet({
|
|
|
5069
5117
|
dragging: false,
|
|
5070
5118
|
sheetHeight: 0,
|
|
5071
5119
|
sheetWidth: 0,
|
|
5120
|
+
fixedWidth: false,
|
|
5121
|
+
fixedHeight: false,
|
|
5072
5122
|
entering: false,
|
|
5073
5123
|
matchingCells: [],
|
|
5074
5124
|
matchingCellIndex: 0,
|
|
@@ -5098,6 +5148,13 @@ function GridSheet({
|
|
|
5098
5148
|
}, []);
|
|
5099
5149
|
const fillWidth = typeof options.sheetWidth === "string";
|
|
5100
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);
|
|
5101
5158
|
const [sheetHeight, setSheetHeight] = useState(
|
|
5102
5159
|
typeof (options == null ? void 0 : options.sheetHeight) === "number" ? options.sheetHeight : estimateSheetHeight(initialCells)
|
|
5103
5160
|
);
|
|
@@ -5111,6 +5168,12 @@ function GridSheet({
|
|
|
5111
5168
|
}
|
|
5112
5169
|
let first = true;
|
|
5113
5170
|
const ro = new ResizeObserver(() => {
|
|
5171
|
+
if (el.style.width) {
|
|
5172
|
+
setResizedWidth(true);
|
|
5173
|
+
}
|
|
5174
|
+
if (el.style.height) {
|
|
5175
|
+
setResizedHeight(true);
|
|
5176
|
+
}
|
|
5114
5177
|
if (first) {
|
|
5115
5178
|
first = false;
|
|
5116
5179
|
if (!fillWidth && !fillHeight) {
|
|
@@ -5160,15 +5223,19 @@ function GridSheet({
|
|
|
5160
5223
|
ref: rootRef,
|
|
5161
5224
|
"data-sheet-name": sheetName,
|
|
5162
5225
|
"data-mode": mode,
|
|
5226
|
+
"data-density": density,
|
|
5227
|
+
"data-gridlines": gridLines,
|
|
5228
|
+
"data-matrix-align": matrixAlignment,
|
|
5163
5229
|
"data-rows": ((_a = store.sheetReactive.current) == null ? void 0 : _a.numRows) ?? 0,
|
|
5164
5230
|
"data-cols": ((_b = store.sheetReactive.current) == null ? void 0 : _b.numCols) ?? 0,
|
|
5165
5231
|
style: fillWidth || fillHeight ? {
|
|
5232
|
+
...borderVars,
|
|
5166
5233
|
// inline-flex (when width isn't filled) keeps the prior shrink-to-content width.
|
|
5167
5234
|
display: fillWidth ? "flex" : "inline-flex",
|
|
5168
5235
|
flexDirection: "column",
|
|
5169
5236
|
...fillWidth ? { width: options.sheetWidth } : null,
|
|
5170
5237
|
...fillHeight ? { height: options.sheetHeight } : null
|
|
5171
|
-
} :
|
|
5238
|
+
} : borderVars,
|
|
5172
5239
|
children: [
|
|
5173
5240
|
/* @__PURE__ */ jsx("div", { className: "gs-flash-overlay", ref: flashRef }),
|
|
5174
5241
|
/* @__PURE__ */ jsx(ScrollHandle, { style: { position: "fixed", top: 0, left: 0 } }),
|
|
@@ -5194,7 +5261,12 @@ function GridSheet({
|
|
|
5194
5261
|
children: [
|
|
5195
5262
|
/* @__PURE__ */ jsx(Editor, { mode }),
|
|
5196
5263
|
/* @__PURE__ */ jsx(Tabular, {}),
|
|
5197
|
-
/* @__PURE__ */ jsx(
|
|
5264
|
+
/* @__PURE__ */ jsx(
|
|
5265
|
+
StoreObserver,
|
|
5266
|
+
{
|
|
5267
|
+
...{ ...options, sheetHeight, sheetWidth, fixedWidth, fixedHeight, sheetName, sheetRef, storeRef }
|
|
5268
|
+
}
|
|
5269
|
+
),
|
|
5198
5270
|
/* @__PURE__ */ jsx(ContextMenu, {}),
|
|
5199
5271
|
/* @__PURE__ */ jsx(ColumnMenu, {}),
|
|
5200
5272
|
/* @__PURE__ */ jsx(RowMenu, {}),
|