logisheets-runtime 1.10.0 → 1.12.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/index.d.ts CHANGED
@@ -49,6 +49,29 @@ export declare class Workbook {
49
49
  constructor(bookId: number, path?: string);
50
50
  /** Read a single cell's evaluated value. */
51
51
  getValue(sheetIdx: number, row: number, col: number): Value;
52
+ /**
53
+ * Serialize the workbook back to .xlsx bytes.
54
+ *
55
+ * `saveWorkbook` is deliberately absent from {@link Client}: it is a
56
+ * whole-file operation rather than one of the per-cell/per-sheet
57
+ * `WorkbookMethods`, so it goes straight through the engine entry here.
58
+ *
59
+ * @param appData opaque per-document JSON the host owns (craft state and
60
+ * friends). It round-trips through the file; pass what the
61
+ * engine's `getAppData` gave you, or nothing.
62
+ * @param resolveBlockRefs write block formulas as ordinary A1 references
63
+ * instead of `BLOCKREF(...)`. Off by default: the named form
64
+ * is readable and reopens here intact, but no other
65
+ * spreadsheet knows those functions, so a file Excel has to
66
+ * recalculate needs coordinates. One-way — see the note on
67
+ * the engine's `FormulaFormat`.
68
+ */
69
+ save(appData?: string, resolveBlockRefs?: boolean): Uint8Array;
70
+ /**
71
+ * Serialize and write the workbook to `path`. Defaults to the path it was
72
+ * loaded from, so a load -> edit -> `saveAs()` round-trip needs no argument.
73
+ */
74
+ saveAs(path?: string, appData?: string, resolveBlockRefs?: boolean): Promise<void>;
52
75
  /** Undo the most recent transaction. Returns whether anything was undone. */
53
76
  undo(): Promise<boolean>;
54
77
  /** Redo the most recently undone transaction. Returns whether anything was redone. */
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@
10
10
  // workbook logic lives in logisheets-core's WorkbookOps; the runtime only
11
11
  // adapts the synchronous Node `handle()` entry point into the async Client that
12
12
  // WorkbookOps consumes, then exposes that ops layer per workbook.
13
- import { readFile } from 'node:fs/promises';
13
+ import { readFile, writeFile } from 'node:fs/promises';
14
14
  import { basename, resolve } from 'node:path';
15
15
  import { createRequire } from 'node:module';
16
16
  import { WorkbookOps } from 'logisheets-core';
@@ -98,6 +98,44 @@ export class Workbook {
98
98
  getValue(sheetIdx, row, col) {
99
99
  return handle({ method: 'getValue', value: { sheetIdx, row, col } }, this.id);
100
100
  }
101
+ /**
102
+ * Serialize the workbook back to .xlsx bytes.
103
+ *
104
+ * `saveWorkbook` is deliberately absent from {@link Client}: it is a
105
+ * whole-file operation rather than one of the per-cell/per-sheet
106
+ * `WorkbookMethods`, so it goes straight through the engine entry here.
107
+ *
108
+ * @param appData opaque per-document JSON the host owns (craft state and
109
+ * friends). It round-trips through the file; pass what the
110
+ * engine's `getAppData` gave you, or nothing.
111
+ * @param resolveBlockRefs write block formulas as ordinary A1 references
112
+ * instead of `BLOCKREF(...)`. Off by default: the named form
113
+ * is readable and reopens here intact, but no other
114
+ * spreadsheet knows those functions, so a file Excel has to
115
+ * recalculate needs coordinates. One-way — see the note on
116
+ * the engine's `FormulaFormat`.
117
+ */
118
+ save(appData = '', resolveBlockRefs = false) {
119
+ const r = handle({ method: 'saveWorkbook', value: { appData, resolveBlockRefs } }, this.id);
120
+ if (r.code !== 0) {
121
+ throw new Error(`failed to save workbook (code ${r.code})`);
122
+ }
123
+ // The wasm boundary hands back either a typed array or a plain number
124
+ // array depending on the serializer path; normalize so callers can
125
+ // always treat this as bytes.
126
+ return r.data instanceof Uint8Array ? r.data : Uint8Array.from(r.data);
127
+ }
128
+ /**
129
+ * Serialize and write the workbook to `path`. Defaults to the path it was
130
+ * loaded from, so a load -> edit -> `saveAs()` round-trip needs no argument.
131
+ */
132
+ async saveAs(path, appData = '', resolveBlockRefs = false) {
133
+ const target = path ?? this.path;
134
+ if (target === undefined) {
135
+ throw new Error('saveAs: no path given and this workbook was not loaded from one');
136
+ }
137
+ await writeFile(resolve(target), this.save(appData, resolveBlockRefs));
138
+ }
101
139
  /** Undo the most recent transaction. Returns whether anything was undone. */
102
140
  async undo() {
103
141
  return (await this.client.undo()) === true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "logisheets-runtime",
3
- "version": "1.10.0",
3
+ "version": "1.12.0",
4
4
  "description": "Headless LogiSheets spreadsheet runtime for Node — logisheets-core wired to the Node WASM engine. The Node counterpart of the browser app.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -17,9 +17,30 @@
17
17
  ],
18
18
  "author": "Jeremy He",
19
19
  "license": "MIT",
20
+ "keywords": [
21
+ "spreadsheet",
22
+ "xlsx",
23
+ "excel",
24
+ "headless",
25
+ "nodejs",
26
+ "server",
27
+ "wasm",
28
+ "rust",
29
+ "formula",
30
+ "workbook"
31
+ ],
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/logisky/LogiSheets.git",
35
+ "directory": "packages/runtime"
36
+ },
37
+ "bugs": {
38
+ "url": "https://github.com/logisky/LogiSheets/issues"
39
+ },
40
+ "homepage": "https://github.com/logisky/LogiSheets",
20
41
  "dependencies": {
21
- "logisheets": "^1.10.0",
22
- "logisheets-core": "^1.10.0"
42
+ "logisheets": "^1.12.0",
43
+ "logisheets-core": "^1.12.0"
23
44
  },
24
45
  "devDependencies": {
25
46
  "@types/node": "^18",