@particle-academy/fancy-sheets 0.7.6 → 0.8.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/README.md +21 -0
- package/dist/index.cjs +35 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +90 -1
- package/dist/index.d.ts +90 -1
- package/dist/index.js +31 -29
- package/dist/index.js.map +1 -1
- package/docs/recipes/csv-roundtrip.md +53 -0
- package/docs/recipes/custom-functions.md +56 -0
- package/docs/recipes/external-state-sync.md +71 -0
- package/docs/recipes/headless-recalc.md +67 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,6 +49,26 @@ The component fills its container — wrap it in a sized element (height is requ
|
|
|
49
49
|
| Full component API (props, sub-components, `useSpreadsheet` hook, data model, keyboard shortcuts) | [docs/Spreadsheet.md](./docs/Spreadsheet.md) |
|
|
50
50
|
| 80+ built-in formula functions + custom function registration | [docs/formulas.md](./docs/formulas.md) |
|
|
51
51
|
| CSV import / export utilities | [docs/csv.md](./docs/csv.md) |
|
|
52
|
+
| **Headless recalculation** (Node / SSR / exports / tests) | [docs/recipes/headless-recalc.md](./docs/recipes/headless-recalc.md) |
|
|
53
|
+
| **External state sync + autosave** (controlled `data`, agent bridge, undo/redo) | [docs/recipes/external-state-sync.md](./docs/recipes/external-state-sync.md) |
|
|
54
|
+
| **Custom formula functions** (`registerFunction` walkthrough) | [docs/recipes/custom-functions.md](./docs/recipes/custom-functions.md) |
|
|
55
|
+
| **CSV round-trip** | [docs/recipes/csv-roundtrip.md](./docs/recipes/csv-roundtrip.md) |
|
|
56
|
+
|
|
57
|
+
### Headless formula engine (0.8+)
|
|
58
|
+
|
|
59
|
+
The engine is pure functions — no React, no DOM — so backends, schedulers,
|
|
60
|
+
exporters, and test rigs can use it directly:
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import {
|
|
64
|
+
recalculateWorkbook, recalculateSheet, // recompute computedValues
|
|
65
|
+
lexFormula, parseFormula, evaluateAST, // low-level lex → parse → eval
|
|
66
|
+
} from "@particle-academy/fancy-sheets";
|
|
67
|
+
|
|
68
|
+
const computed = recalculateWorkbook(workbook); // new workbook, formulas evaluated
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
See [docs/recipes/headless-recalc.md](./docs/recipes/headless-recalc.md).
|
|
52
72
|
|
|
53
73
|
## Commands
|
|
54
74
|
|
|
@@ -65,6 +85,7 @@ pnpm --filter @particle-academy/fancy-sheets clean # Remove dist/
|
|
|
65
85
|
- **`useSpreadsheet` hook** — full workbook state and actions accessible from any child
|
|
66
86
|
- **80+ built-in formulas** — Math, Text, Logic, Conditional aggregates, Lookup, Date/Time, Info
|
|
67
87
|
- **Multi-sheet workbooks** — cross-sheet references via `Sheet2!A1` syntax
|
|
88
|
+
- **Headless engine (0.8+)** — `recalculateWorkbook` / `lexFormula` / `parseFormula` / `evaluateAST` exported as pure, React-free functions for SSR, exports, and Node tests
|
|
68
89
|
- **Features** — editing, navigation, selection (single, range, multi-range), formatting (bold/italic/align), clipboard (copy/cut/paste with TSV), column resize, freeze rows/cols, undo/redo (50 steps), drag-to-select
|
|
69
90
|
- **Zero third-party dependencies** — custom lexer, parser, evaluator, and dependency graph
|
|
70
91
|
|
package/dist/index.cjs
CHANGED
|
@@ -1255,7 +1255,7 @@ function getRecalculationOrder(graph) {
|
|
|
1255
1255
|
return order;
|
|
1256
1256
|
}
|
|
1257
1257
|
|
|
1258
|
-
// src/
|
|
1258
|
+
// src/engine/recalc.ts
|
|
1259
1259
|
function recalculateWorkbook(workbook) {
|
|
1260
1260
|
const recalculated = [];
|
|
1261
1261
|
for (const sheet of workbook.sheets) {
|
|
@@ -1267,33 +1267,6 @@ function recalculateWorkbook(workbook) {
|
|
|
1267
1267
|
}
|
|
1268
1268
|
return { ...workbook, sheets: finalSheets };
|
|
1269
1269
|
}
|
|
1270
|
-
function createInitialState(data) {
|
|
1271
|
-
const workbook = data ?? createEmptyWorkbook();
|
|
1272
|
-
return {
|
|
1273
|
-
workbook: recalculateWorkbook(workbook),
|
|
1274
|
-
selection: { activeCell: "A1", ranges: [{ start: "A1", end: "A1" }] },
|
|
1275
|
-
editingCell: null,
|
|
1276
|
-
editValue: "",
|
|
1277
|
-
undoStack: [],
|
|
1278
|
-
redoStack: []
|
|
1279
|
-
};
|
|
1280
|
-
}
|
|
1281
|
-
function getActiveSheet(state) {
|
|
1282
|
-
return state.workbook.sheets.find((s) => s.id === state.workbook.activeSheetId);
|
|
1283
|
-
}
|
|
1284
|
-
function updateActiveSheet(state, updater) {
|
|
1285
|
-
return {
|
|
1286
|
-
...state.workbook,
|
|
1287
|
-
sheets: state.workbook.sheets.map(
|
|
1288
|
-
(s) => s.id === state.workbook.activeSheetId ? updater(s) : s
|
|
1289
|
-
)
|
|
1290
|
-
};
|
|
1291
|
-
}
|
|
1292
|
-
function pushUndo(state) {
|
|
1293
|
-
const stack = [...state.undoStack, state.workbook];
|
|
1294
|
-
if (stack.length > 50) stack.shift();
|
|
1295
|
-
return { undoStack: stack, redoStack: [] };
|
|
1296
|
-
}
|
|
1297
1270
|
function recalculateSheet(sheet, allSheets) {
|
|
1298
1271
|
const graph = buildDependencyGraph(sheet.cells);
|
|
1299
1272
|
if (graph.size === 0) return sheet;
|
|
@@ -1350,6 +1323,35 @@ function recalculateSheet(sheet, allSheets) {
|
|
|
1350
1323
|
}
|
|
1351
1324
|
return { ...sheet, cells };
|
|
1352
1325
|
}
|
|
1326
|
+
|
|
1327
|
+
// src/hooks/use-spreadsheet-store.ts
|
|
1328
|
+
function createInitialState(data) {
|
|
1329
|
+
const workbook = data ?? createEmptyWorkbook();
|
|
1330
|
+
return {
|
|
1331
|
+
workbook: recalculateWorkbook(workbook),
|
|
1332
|
+
selection: { activeCell: "A1", ranges: [{ start: "A1", end: "A1" }] },
|
|
1333
|
+
editingCell: null,
|
|
1334
|
+
editValue: "",
|
|
1335
|
+
undoStack: [],
|
|
1336
|
+
redoStack: []
|
|
1337
|
+
};
|
|
1338
|
+
}
|
|
1339
|
+
function getActiveSheet(state) {
|
|
1340
|
+
return state.workbook.sheets.find((s) => s.id === state.workbook.activeSheetId);
|
|
1341
|
+
}
|
|
1342
|
+
function updateActiveSheet(state, updater) {
|
|
1343
|
+
return {
|
|
1344
|
+
...state.workbook,
|
|
1345
|
+
sheets: state.workbook.sheets.map(
|
|
1346
|
+
(s) => s.id === state.workbook.activeSheetId ? updater(s) : s
|
|
1347
|
+
)
|
|
1348
|
+
};
|
|
1349
|
+
}
|
|
1350
|
+
function pushUndo(state) {
|
|
1351
|
+
const stack = [...state.undoStack, state.workbook];
|
|
1352
|
+
if (stack.length > 50) stack.shift();
|
|
1353
|
+
return { undoStack: stack, redoStack: [] };
|
|
1354
|
+
}
|
|
1353
1355
|
function getCellDisplayValue(cell) {
|
|
1354
1356
|
if (!cell) return "";
|
|
1355
1357
|
if (cell.computedValue !== void 0) return String(cell.computedValue);
|
|
@@ -2872,9 +2874,14 @@ exports.columnToLetter = columnToLetter;
|
|
|
2872
2874
|
exports.createEmptySheet = createEmptySheet;
|
|
2873
2875
|
exports.createEmptyWorkbook = createEmptyWorkbook;
|
|
2874
2876
|
exports.csvToWorkbook = csvToWorkbook;
|
|
2877
|
+
exports.evaluateAST = evaluateAST;
|
|
2875
2878
|
exports.letterToColumn = letterToColumn;
|
|
2879
|
+
exports.lexFormula = lexFormula;
|
|
2876
2880
|
exports.parseAddress = parseAddress;
|
|
2877
2881
|
exports.parseCSV = parseCSV;
|
|
2882
|
+
exports.parseFormula = parseFormula;
|
|
2883
|
+
exports.recalculateSheet = recalculateSheet;
|
|
2884
|
+
exports.recalculateWorkbook = recalculateWorkbook;
|
|
2878
2885
|
exports.registerFunction = registerFunction;
|
|
2879
2886
|
exports.stringifyCSV = stringifyCSV;
|
|
2880
2887
|
exports.toAddress = toAddress;
|