@gridsheet/preact-core 2.0.4 → 2.0.5
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/README.md +6 -1
- package/dist/index.js +42 -42
- package/dist/index.js.map +1 -1
- package/dist/lib/table.d.ts +5 -6
- package/dist/types.d.ts +0 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Spreadsheet component for Preact
|
|
|
8
8
|
npm install @gridsheet/preact-core
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
### Peer Dependencies
|
|
12
12
|
|
|
13
13
|
This package requires the following peer dependencies:
|
|
14
14
|
|
|
@@ -67,6 +67,11 @@ This package exports all the core GridSheet functionality along with Preact comp
|
|
|
67
67
|
- Core GridSheet components and utilities
|
|
68
68
|
- Preact-specific exports (`h`, `render`)
|
|
69
69
|
|
|
70
|
+
## Docs
|
|
71
|
+
|
|
72
|
+
- [GridSheet document](https://gridsheet.walkframe.com/)
|
|
73
|
+
- [Examples](https://gridsheet.walkframe.com/examples/case1)
|
|
74
|
+
|
|
70
75
|
## Development
|
|
71
76
|
|
|
72
77
|
```bash
|
package/dist/index.js
CHANGED
|
@@ -3193,7 +3193,6 @@ class InsertRowsAboveAction extends CoreAction {
|
|
|
3193
3193
|
});
|
|
3194
3194
|
return {
|
|
3195
3195
|
...store,
|
|
3196
|
-
...table.getTotalSize(),
|
|
3197
3196
|
tableReactive: { current: table }
|
|
3198
3197
|
};
|
|
3199
3198
|
}
|
|
@@ -3231,7 +3230,6 @@ class InsertRowsBelowAction extends CoreAction {
|
|
|
3231
3230
|
});
|
|
3232
3231
|
return {
|
|
3233
3232
|
...store,
|
|
3234
|
-
...table.getTotalSize(),
|
|
3235
3233
|
selectingZone: nextSelectingZone,
|
|
3236
3234
|
choosing: nextChoosing,
|
|
3237
3235
|
tableReactive: { current: table }
|
|
@@ -3265,7 +3263,6 @@ class InsertColsLeftAction extends CoreAction {
|
|
|
3265
3263
|
});
|
|
3266
3264
|
return {
|
|
3267
3265
|
...store,
|
|
3268
|
-
...table.getTotalSize(),
|
|
3269
3266
|
tableReactive: { current: table }
|
|
3270
3267
|
};
|
|
3271
3268
|
}
|
|
@@ -3305,7 +3302,6 @@ class InsertColsRightAction extends CoreAction {
|
|
|
3305
3302
|
});
|
|
3306
3303
|
return {
|
|
3307
3304
|
...store,
|
|
3308
|
-
...table.getTotalSize(),
|
|
3309
3305
|
selectingZone: nextSelectingZone,
|
|
3310
3306
|
choosing: nextChoosing,
|
|
3311
3307
|
tableReactive: { current: table }
|
|
@@ -3339,7 +3335,6 @@ class RemoveRowsAction extends CoreAction {
|
|
|
3339
3335
|
});
|
|
3340
3336
|
return {
|
|
3341
3337
|
...store,
|
|
3342
|
-
...table.getTotalSize(),
|
|
3343
3338
|
tableReactive: { current: table }
|
|
3344
3339
|
};
|
|
3345
3340
|
}
|
|
@@ -3371,7 +3366,6 @@ class RemoveColsAction extends CoreAction {
|
|
|
3371
3366
|
});
|
|
3372
3367
|
return {
|
|
3373
3368
|
...store,
|
|
3374
|
-
...table.getTotalSize(),
|
|
3375
3369
|
tableReactive: { current: table }
|
|
3376
3370
|
};
|
|
3377
3371
|
}
|
|
@@ -4653,8 +4647,7 @@ const Resizer = () => {
|
|
|
4653
4647
|
});
|
|
4654
4648
|
dispatch(
|
|
4655
4649
|
setStore({
|
|
4656
|
-
tableReactive: { current: table }
|
|
4657
|
-
...table.getTotalSize()
|
|
4650
|
+
tableReactive: { current: table }
|
|
4658
4651
|
})
|
|
4659
4652
|
);
|
|
4660
4653
|
dispatch(setResizingPositionY([-1, -1, -1]));
|
|
@@ -7718,6 +7711,8 @@ class Table {
|
|
|
7718
7711
|
this.prevSheetName = "";
|
|
7719
7712
|
this.status = 0;
|
|
7720
7713
|
this.idsToBeIdentified = [];
|
|
7714
|
+
this.totalWidth = 0;
|
|
7715
|
+
this.totalHeight = 0;
|
|
7721
7716
|
this.version = 0;
|
|
7722
7717
|
this.area = { top: 0, left: 0, bottom: 0, right: 0 };
|
|
7723
7718
|
this.addressCaches = /* @__PURE__ */ new Map();
|
|
@@ -7904,7 +7899,7 @@ class Table {
|
|
|
7904
7899
|
}
|
|
7905
7900
|
return { width, height };
|
|
7906
7901
|
}
|
|
7907
|
-
|
|
7902
|
+
setTotalSize() {
|
|
7908
7903
|
const { bottom, right } = this.area;
|
|
7909
7904
|
const { width, height } = this.getRectSize({
|
|
7910
7905
|
top: 1,
|
|
@@ -7912,24 +7907,25 @@ class Table {
|
|
|
7912
7907
|
bottom: bottom + 1,
|
|
7913
7908
|
right: right + 1
|
|
7914
7909
|
});
|
|
7915
|
-
|
|
7916
|
-
|
|
7917
|
-
totalHeight: height + this.headerHeight
|
|
7918
|
-
};
|
|
7910
|
+
this.totalWidth = width + this.headerWidth;
|
|
7911
|
+
this.totalHeight = height + this.headerHeight;
|
|
7919
7912
|
}
|
|
7920
|
-
refresh(
|
|
7913
|
+
refresh(relocate = false, resize = false) {
|
|
7921
7914
|
this.incrementVersion();
|
|
7922
7915
|
this.lastChangedAt = this.changedAt;
|
|
7923
7916
|
this.changedAt = /* @__PURE__ */ new Date();
|
|
7924
7917
|
this.clearSolvedCaches();
|
|
7925
|
-
if (
|
|
7918
|
+
if (relocate) {
|
|
7926
7919
|
this.addressCaches.clear();
|
|
7927
7920
|
}
|
|
7921
|
+
if (resize) {
|
|
7922
|
+
this.setTotalSize();
|
|
7923
|
+
}
|
|
7928
7924
|
return this;
|
|
7929
7925
|
}
|
|
7930
|
-
clone(
|
|
7926
|
+
clone(relocate = false) {
|
|
7931
7927
|
const copied = Object.assign(Object.create(Object.getPrototypeOf(this)), this);
|
|
7932
|
-
return copied.refresh(
|
|
7928
|
+
return copied.refresh(relocate);
|
|
7933
7929
|
}
|
|
7934
7930
|
getPointById(id, slideY = 0, slideX = 0) {
|
|
7935
7931
|
const absCol = id.startsWith("$");
|
|
@@ -8447,7 +8443,7 @@ class Table {
|
|
|
8447
8443
|
this.wire.onEdit({ table: srcTable.__raw__.trim(src) });
|
|
8448
8444
|
this.wire.onEdit({ table: this.__raw__.trim(dst) });
|
|
8449
8445
|
}
|
|
8450
|
-
return this.refresh(
|
|
8446
|
+
return this.refresh(true);
|
|
8451
8447
|
}
|
|
8452
8448
|
copy({
|
|
8453
8449
|
srcTable = this,
|
|
@@ -8533,15 +8529,16 @@ class Table {
|
|
|
8533
8529
|
const diffBefore = {};
|
|
8534
8530
|
const diffAfter = {};
|
|
8535
8531
|
const changedAt = /* @__PURE__ */ new Date();
|
|
8532
|
+
let resized = false;
|
|
8536
8533
|
Object.keys(diff).forEach((address) => {
|
|
8537
8534
|
var _a, _b, _c, _d;
|
|
8538
8535
|
const point = a2p(address);
|
|
8539
8536
|
const id = this.getId(point);
|
|
8540
8537
|
const original = this.wire.data[id];
|
|
8541
|
-
let patch = { ...diff[address] };
|
|
8542
8538
|
if (operator === "USER" && hasOperation(original.prevention, Update)) {
|
|
8543
8539
|
return;
|
|
8544
8540
|
}
|
|
8541
|
+
let patch = { ...diff[address] };
|
|
8545
8542
|
if (formulaIdentify) {
|
|
8546
8543
|
patch.value = identifyFormula(patch.value, {
|
|
8547
8544
|
table: this,
|
|
@@ -8571,6 +8568,9 @@ class Table {
|
|
|
8571
8568
|
if (updateChangedAt) {
|
|
8572
8569
|
this.setChangedAt(patch, changedAt);
|
|
8573
8570
|
}
|
|
8571
|
+
if (patch.width != null || patch.height != null) {
|
|
8572
|
+
resized = true;
|
|
8573
|
+
}
|
|
8574
8574
|
diffBefore[id] = { ...original };
|
|
8575
8575
|
const policy = this.policies[original.policy] ?? defaultPolicy;
|
|
8576
8576
|
const p = policy.restrict({
|
|
@@ -8593,7 +8593,8 @@ class Table {
|
|
|
8593
8593
|
}
|
|
8594
8594
|
return {
|
|
8595
8595
|
diffBefore,
|
|
8596
|
-
diffAfter
|
|
8596
|
+
diffAfter,
|
|
8597
|
+
resized
|
|
8597
8598
|
};
|
|
8598
8599
|
}
|
|
8599
8600
|
update({
|
|
@@ -8606,7 +8607,7 @@ class Table {
|
|
|
8606
8607
|
undoReflection,
|
|
8607
8608
|
redoReflection
|
|
8608
8609
|
}) {
|
|
8609
|
-
const { diffBefore, diffAfter } = this._update({
|
|
8610
|
+
const { diffBefore, diffAfter, resized } = this._update({
|
|
8610
8611
|
diff,
|
|
8611
8612
|
partial,
|
|
8612
8613
|
operator,
|
|
@@ -8626,7 +8627,7 @@ class Table {
|
|
|
8626
8627
|
partial
|
|
8627
8628
|
});
|
|
8628
8629
|
}
|
|
8629
|
-
return this.refresh(
|
|
8630
|
+
return this.refresh(false, resized);
|
|
8630
8631
|
}
|
|
8631
8632
|
writeRawCellMatrix({
|
|
8632
8633
|
point,
|
|
@@ -8756,7 +8757,7 @@ class Table {
|
|
|
8756
8757
|
cloned.addressCaches = /* @__PURE__ */ new Map();
|
|
8757
8758
|
this.wire.onInsertRows({ table: cloned, y, numRows });
|
|
8758
8759
|
}
|
|
8759
|
-
return this.refresh(
|
|
8760
|
+
return this.refresh(true, true);
|
|
8760
8761
|
}
|
|
8761
8762
|
removeRows({
|
|
8762
8763
|
y,
|
|
@@ -8818,7 +8819,7 @@ class Table {
|
|
|
8818
8819
|
cloned.addressCaches = /* @__PURE__ */ new Map();
|
|
8819
8820
|
this.wire.onRemoveRows({ table: cloned, ys: ys.reverse() });
|
|
8820
8821
|
}
|
|
8821
|
-
return this.refresh(
|
|
8822
|
+
return this.refresh(true, true);
|
|
8822
8823
|
}
|
|
8823
8824
|
insertCols({
|
|
8824
8825
|
x,
|
|
@@ -8884,7 +8885,7 @@ class Table {
|
|
|
8884
8885
|
cloned.addressCaches = /* @__PURE__ */ new Map();
|
|
8885
8886
|
this.wire.onInsertCols({ table: cloned, x, numCols });
|
|
8886
8887
|
}
|
|
8887
|
-
return this.refresh(
|
|
8888
|
+
return this.refresh(true, true);
|
|
8888
8889
|
}
|
|
8889
8890
|
removeCols({
|
|
8890
8891
|
x,
|
|
@@ -8949,7 +8950,7 @@ class Table {
|
|
|
8949
8950
|
cloned.addressCaches = /* @__PURE__ */ new Map();
|
|
8950
8951
|
this.wire.onRemoveCols({ table: cloned, xs: xs.reverse() });
|
|
8951
8952
|
}
|
|
8952
|
-
return this.refresh(
|
|
8953
|
+
return this.refresh(true, true);
|
|
8953
8954
|
}
|
|
8954
8955
|
getHistories() {
|
|
8955
8956
|
return [...this.wire.histories];
|
|
@@ -9109,7 +9110,7 @@ class Table {
|
|
|
9109
9110
|
break;
|
|
9110
9111
|
}
|
|
9111
9112
|
}
|
|
9112
|
-
this.refresh(
|
|
9113
|
+
this.refresh(shouldTracking(history.operation), true);
|
|
9113
9114
|
return {
|
|
9114
9115
|
history,
|
|
9115
9116
|
callback: ({ tableReactive: tableRef }) => {
|
|
@@ -9181,7 +9182,7 @@ class Table {
|
|
|
9181
9182
|
}
|
|
9182
9183
|
}
|
|
9183
9184
|
}
|
|
9184
|
-
this.refresh(
|
|
9185
|
+
this.refresh(shouldTracking(history.operation), true);
|
|
9185
9186
|
return {
|
|
9186
9187
|
history,
|
|
9187
9188
|
callback: ({ tableReactive: tableRef }) => {
|
|
@@ -10090,9 +10091,7 @@ const Tabular = () => {
|
|
|
10090
10091
|
sheetHeight,
|
|
10091
10092
|
inputting,
|
|
10092
10093
|
leftHeaderSelecting,
|
|
10093
|
-
topHeaderSelecting
|
|
10094
|
-
totalWidth,
|
|
10095
|
-
totalHeight
|
|
10094
|
+
topHeaderSelecting
|
|
10096
10095
|
} = store;
|
|
10097
10096
|
const table = tableReactive.current;
|
|
10098
10097
|
const [virtualized, setVirtualized] = useState(null);
|
|
@@ -10201,8 +10200,8 @@ const Tabular = () => {
|
|
|
10201
10200
|
{
|
|
10202
10201
|
className: "gs-tabular-inner",
|
|
10203
10202
|
style: {
|
|
10204
|
-
width: totalWidth + 1,
|
|
10205
|
-
height: totalHeight + 1
|
|
10203
|
+
width: table.totalWidth + 1,
|
|
10204
|
+
height: table.totalHeight + 1
|
|
10206
10205
|
},
|
|
10207
10206
|
children: /* @__PURE__ */ jsxs("table", { className: `gs-table`, children: [
|
|
10208
10207
|
/* @__PURE__ */ jsx("thead", { className: "gs-thead", style: { height: table.headerHeight }, children: /* @__PURE__ */ jsxs("tr", { className: "gs-row", children: [
|
|
@@ -10736,6 +10735,7 @@ function GridSheet({
|
|
|
10736
10735
|
style,
|
|
10737
10736
|
hub: initialHub
|
|
10738
10737
|
}) {
|
|
10738
|
+
var _a, _b;
|
|
10739
10739
|
const { sheetResize, showFormulaBar = true, mode = "light" } = options;
|
|
10740
10740
|
const rootRef = useRef(null);
|
|
10741
10741
|
const mainRef = useRef(null);
|
|
@@ -10755,7 +10755,7 @@ function GridSheet({
|
|
|
10755
10755
|
const sheetId = sheetIdRef.current;
|
|
10756
10756
|
const tableReactive = useRef(null);
|
|
10757
10757
|
const [initialState] = useState(() => {
|
|
10758
|
-
var
|
|
10758
|
+
var _a2;
|
|
10759
10759
|
if (!sheetName) {
|
|
10760
10760
|
sheetName = `Sheet${sheetId}`;
|
|
10761
10761
|
console.debug("GridSheet: sheetName is not provided, using default name:", sheetName);
|
|
@@ -10772,7 +10772,8 @@ function GridSheet({
|
|
|
10772
10772
|
table.sheetId = sheetId;
|
|
10773
10773
|
wire.sheetIdsByName[sheetName] = sheetId;
|
|
10774
10774
|
table.initialize(initialCells);
|
|
10775
|
-
(
|
|
10775
|
+
(_a2 = wire.onInit) == null ? void 0 : _a2.call(wire, { table });
|
|
10776
|
+
table.setTotalSize();
|
|
10776
10777
|
tableReactive.current = table;
|
|
10777
10778
|
const store2 = {
|
|
10778
10779
|
sheetId,
|
|
@@ -10808,8 +10809,7 @@ function GridSheet({
|
|
|
10808
10809
|
maxNumRows: -1,
|
|
10809
10810
|
minNumCols: 1,
|
|
10810
10811
|
maxNumCols: -1,
|
|
10811
|
-
mode: "light"
|
|
10812
|
-
...table.getTotalSize()
|
|
10812
|
+
mode: "light"
|
|
10813
10813
|
};
|
|
10814
10814
|
return store2;
|
|
10815
10815
|
});
|
|
@@ -10825,9 +10825,9 @@ function GridSheet({
|
|
|
10825
10825
|
const [sheetWidth, setSheetWidth] = useState((options == null ? void 0 : options.sheetWidth) || estimateSheetWidth(initialCells));
|
|
10826
10826
|
useEffect(() => {
|
|
10827
10827
|
const intervalId = window.setInterval(() => {
|
|
10828
|
-
var
|
|
10829
|
-
setSheetHeight(((
|
|
10830
|
-
setSheetWidth(((
|
|
10828
|
+
var _a2, _b2;
|
|
10829
|
+
setSheetHeight(((_a2 = mainRef.current) == null ? void 0 : _a2.clientHeight) || 0);
|
|
10830
|
+
setSheetWidth(((_b2 = mainRef.current) == null ? void 0 : _b2.clientWidth) || 0);
|
|
10831
10831
|
}, 1e3);
|
|
10832
10832
|
return () => window.clearInterval(intervalId);
|
|
10833
10833
|
}, []);
|
|
@@ -10860,8 +10860,8 @@ function GridSheet({
|
|
|
10860
10860
|
ref: mainRef,
|
|
10861
10861
|
style: {
|
|
10862
10862
|
//width: '100%',
|
|
10863
|
-
maxWidth: (store.totalWidth || 0) + 2,
|
|
10864
|
-
maxHeight: (store.totalHeight || 0) + 2,
|
|
10863
|
+
maxWidth: (((_a = store.tableReactive.current) == null ? void 0 : _a.totalWidth) || 0) + 2,
|
|
10864
|
+
maxHeight: (((_b = store.tableReactive.current) == null ? void 0 : _b.totalHeight) || 0) + 2,
|
|
10865
10865
|
overflow: "auto",
|
|
10866
10866
|
resize: sheetResize,
|
|
10867
10867
|
...style
|