logisheets-runtime 1.10.0 → 1.11.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 +17 -0
- package/dist/index.js +33 -1
- package/package.json +24 -3
package/dist/index.d.ts
CHANGED
|
@@ -49,6 +49,23 @@ 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
|
+
*/
|
|
63
|
+
save(appData?: string): Uint8Array;
|
|
64
|
+
/**
|
|
65
|
+
* Serialize and write the workbook to `path`. Defaults to the path it was
|
|
66
|
+
* loaded from, so a load -> edit -> `saveAs()` round-trip needs no argument.
|
|
67
|
+
*/
|
|
68
|
+
saveAs(path?: string, appData?: string): Promise<void>;
|
|
52
69
|
/** Undo the most recent transaction. Returns whether anything was undone. */
|
|
53
70
|
undo(): Promise<boolean>;
|
|
54
71
|
/** 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,38 @@ 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
|
+
*/
|
|
112
|
+
save(appData = '') {
|
|
113
|
+
const r = handle({ method: 'saveWorkbook', value: { appData } }, this.id);
|
|
114
|
+
if (r.code !== 0) {
|
|
115
|
+
throw new Error(`failed to save workbook (code ${r.code})`);
|
|
116
|
+
}
|
|
117
|
+
// The wasm boundary hands back either a typed array or a plain number
|
|
118
|
+
// array depending on the serializer path; normalize so callers can
|
|
119
|
+
// always treat this as bytes.
|
|
120
|
+
return r.data instanceof Uint8Array ? r.data : Uint8Array.from(r.data);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Serialize and write the workbook to `path`. Defaults to the path it was
|
|
124
|
+
* loaded from, so a load -> edit -> `saveAs()` round-trip needs no argument.
|
|
125
|
+
*/
|
|
126
|
+
async saveAs(path, appData = '') {
|
|
127
|
+
const target = path ?? this.path;
|
|
128
|
+
if (target === undefined) {
|
|
129
|
+
throw new Error('saveAs: no path given and this workbook was not loaded from one');
|
|
130
|
+
}
|
|
131
|
+
await writeFile(resolve(target), this.save(appData));
|
|
132
|
+
}
|
|
101
133
|
/** Undo the most recent transaction. Returns whether anything was undone. */
|
|
102
134
|
async undo() {
|
|
103
135
|
return (await this.client.undo()) === true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "logisheets-runtime",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.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.
|
|
22
|
-
"logisheets-core": "^1.
|
|
42
|
+
"logisheets": "^1.11.0",
|
|
43
|
+
"logisheets-core": "^1.11.0"
|
|
23
44
|
},
|
|
24
45
|
"devDependencies": {
|
|
25
46
|
"@types/node": "^18",
|