@particle-academy/holy-sheet 2.3.1 → 2.4.1
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 +35 -0
- package/dist/index.cjs +853 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +317 -27
- package/dist/index.d.ts +317 -27
- package/dist/index.js +851 -26
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,6 +48,7 @@ await Agent.write(schema, "sales.xlsx");
|
|
|
48
48
|
- `fromCsv(csvOrPath, options?)` → schema
|
|
49
49
|
- `read(bytes)` → schema (universal) and `describe(path)` → schema (Node only): the round-trip reader, for an `.xlsx` **or an `.ods`**
|
|
50
50
|
- `toolDefinition()` → JSON Schema for LLM tool-use
|
|
51
|
+
- `diff(a, b)` → the ops that turn one schema into another, `reduce(schema, opOrOps)` → a new schema, `opSchema()` → JSON Schema for one op, `equivalent(a, b)` → whether two schemas write the same workbook (see [Versions as diffs](#versions-as-diffs))
|
|
51
52
|
- `version()` → string
|
|
52
53
|
|
|
53
54
|
See `docs/` for the full schema reference.
|
|
@@ -68,6 +69,40 @@ when there is one). What maps and what does not is listed in the PHP package's
|
|
|
68
69
|
[`docs/ReadPath.md`](https://github.com/Particle-Academy/holy-sheet/blob/main/docs/ReadPath.md#opendocument-spreadsheets-ods);
|
|
69
70
|
this port reads the same fixtures and is diffed against it.
|
|
70
71
|
|
|
72
|
+
### Versions as diffs
|
|
73
|
+
|
|
74
|
+
`Agent.diff(a, b)` returns the ops that turn one schema into another, and
|
|
75
|
+
`Agent.reduce(schema, ops)` applies them. Keep the current workbook as a real
|
|
76
|
+
file and each older version as the ops that restore it:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { Agent, type SheetOp } from "@particle-academy/holy-sheet";
|
|
80
|
+
|
|
81
|
+
const old = Agent.read(currentBytes);
|
|
82
|
+
const ops: SheetOp[] = Agent.diff(edited, old); // store these with the version
|
|
83
|
+
|
|
84
|
+
Agent.reduce(edited, ops); // equals old
|
|
85
|
+
Agent.opSchema(); // JSON Schema for one op
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
- **Exact:** `reduce(a, diff(a, b))` equals `b`, key order aside.
|
|
89
|
+
- **Small:** one changed cell is one `set_cell`, and an inserted row is one
|
|
90
|
+
`insert_rows` plus that row's cells. Rows and columns are aligned by content
|
|
91
|
+
before cells are compared.
|
|
92
|
+
- **Nothing for no change:** schemas that write the same workbook diff to `[]`,
|
|
93
|
+
so `diff(s, read(toBytes(s)))` is `[]`. `Agent.equivalent()` asks that
|
|
94
|
+
question directly.
|
|
95
|
+
- **The same ops as PHP:** this is a port of `particle-academy/holy-sheet`
|
|
96
|
+
2.3.0's `Agent::diff`, checked against it op for op, so a history written by
|
|
97
|
+
either runtime replays in the other.
|
|
98
|
+
|
|
99
|
+
`set_cell`, `set_range` and `set_workbook` are fancy-sheets' `SheetOp` shapes, so
|
|
100
|
+
stored ops can drive a live `useSheetSync` session. The other ops cover sheets,
|
|
101
|
+
rows, columns, merges, widths, frozen panes and meta. Granular ops address
|
|
102
|
+
sheets in the cell form `read()` returns; a sheet authored as columns/rows is
|
|
103
|
+
replaced whole when it changes. `reduce()` never modifies its input, and shares
|
|
104
|
+
the parts an op leaves alone with its result.
|
|
105
|
+
|
|
71
106
|
---
|
|
72
107
|
|
|
73
108
|
## ⭐ Star Fancy UI
|