wasm-onlyoffice-sdk 0.1.5 → 0.1.6
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 +39 -13
- package/dist/react/OnlyOfficeEditor.d.ts.map +1 -1
- package/dist/react/index.mjs +64 -65
- package/dist/vue/OnlyOfficeEditor.vue.d.ts.map +1 -1
- package/dist/vue/index.mjs +243 -250
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,40 +8,66 @@ Offline OnlyOffice document editor SDK for React and Vue, powered by WebAssembly
|
|
|
8
8
|
|
|
9
9
|
This SDK requires two sets of static assets:
|
|
10
10
|
|
|
11
|
-
**OnlyOffice web-apps** —
|
|
11
|
+
**OnlyOffice web-apps scaffold** — a small set of HTML files (~2 MB) that must be served from the **same origin** as your app. These HTML files contain `<base href>` tags pointing to a CDN, so the browser loads the actual heavy content (SDK JS, fonts, CSS) from the CDN at runtime. You do not need to self-host the full OnlyOffice SDK.
|
|
12
12
|
|
|
13
|
-
**x2t WASM converter** —
|
|
13
|
+
**x2t WASM converter** — `x2t.js` and `x2t.wasm`. Can be served from the same origin or a CDN.
|
|
14
14
|
|
|
15
|
-
###
|
|
15
|
+
### Setup
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
Download the web-apps scaffold from the [demo repo](https://github.com/oonxt/wasm-onlyoffice-demo) (`public/` directory) and place it in your project:
|
|
18
18
|
|
|
19
19
|
```
|
|
20
20
|
your-project/
|
|
21
21
|
public/
|
|
22
|
-
v9.3.0.24-1/ ←
|
|
23
|
-
x2t-1/ ← x2t WASM converter (x2t.js + x2t.wasm)
|
|
22
|
+
v9.3.0.24-1/ ← web-apps scaffold (HTML files + api.js, ~2 MB)
|
|
23
|
+
x2t-1/ ← x2t WASM converter (x2t.js + x2t.wasm), optional if using CDN
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
Pass a relative path to `assetsPath`:
|
|
27
|
-
|
|
28
26
|
```tsx
|
|
29
27
|
<OnlyOfficeEditor assetsPath="/v9.3.0.24-1" x2tPath="/x2t-1" ... />
|
|
30
28
|
```
|
|
31
29
|
|
|
32
|
-
|
|
30
|
+
The scaffold's HTML files have `<base href>` tags pre-configured to load assets from a public CDN. You can swap those URLs to your own CDN if needed.
|
|
31
|
+
|
|
32
|
+
### Using a CDN for x2t
|
|
33
33
|
|
|
34
|
-
`
|
|
34
|
+
`x2tPath` accepts either a local path or a full CDN URL:
|
|
35
35
|
|
|
36
36
|
```tsx
|
|
37
37
|
<OnlyOfficeEditor
|
|
38
|
-
assetsPath="
|
|
39
|
-
x2tPath="/x2t
|
|
38
|
+
assetsPath="/v9.3.0.24-1"
|
|
39
|
+
x2tPath="https://cdn.example.com/x2t"
|
|
40
40
|
...
|
|
41
41
|
/>
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
The x2t worker script is bundled inside the SDK (always same-origin). `x2tPath` only controls where the worker fetches `x2t.js` and `x2t.wasm`.
|
|
45
|
+
|
|
46
|
+
Both files are brotli-compressed and must be served with the following headers:
|
|
47
|
+
|
|
48
|
+
| File | `Content-Type` | `Content-Encoding` |
|
|
49
|
+
|------|---------------|-------------------|
|
|
50
|
+
| `x2t.js` | `application/javascript` | `br` |
|
|
51
|
+
| `x2t.wasm` | `application/wasm` | `br` |
|
|
52
|
+
|
|
53
|
+
When using a CDN, also add `Access-Control-Allow-Origin: *` on both files.
|
|
54
|
+
|
|
55
|
+
### Vite setup
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
export default defineConfig({
|
|
59
|
+
optimizeDeps: {
|
|
60
|
+
exclude: ['wasm-onlyoffice-sdk'],
|
|
61
|
+
},
|
|
62
|
+
server: {
|
|
63
|
+
fs: {
|
|
64
|
+
allow: ['../..'], // only needed when referencing the SDK via a local file: path
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
})
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`optimizeDeps.exclude` is required because the SDK resolves its bundled worker via `new URL(...)`, which Vite's pre-bundler would break.
|
|
45
71
|
|
|
46
72
|
## Installation
|
|
47
73
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OnlyOfficeEditor.d.ts","sourceRoot":"","sources":["../../src/react/OnlyOfficeEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsC,aAAa,EAAE,MAAM,OAAO,CAAA;AAKzE,OAAO,KAAK,EAAa,WAAW,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AAEjE,MAAM,WAAW,qBAAqB;IACpC,qEAAqE;IACrE,UAAU,EAAE,MAAM,CAAA;IAClB,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB,mCAAmC;IACnC,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,oDAAoD;IACpD,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAA;IAE9C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,WAAW,CAAA;IACnB,IAAI,CAAC,EAAE,IAAI,CAAA;IAEX,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,qBAAqB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IAClD,uDAAuD;IACvD,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;IAC/C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;IAEhC,KAAK,CAAC,EAAE,aAAa,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,gBAAgB,CAAC,EAC/B,UAAU,EACV,OAAkB,EAClB,IAAI,EACJ,OAAO,EACP,WAAW,EACX,QAAe,EACf,KAAqB,EACrB,IAAkC,EAClC,OAAO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ACrB,MAAM,EACN,OAAO,EACP,KAAK,EACL,SAAS,GACV,EAAE,qBAAqB,2CA2IvB"}
|
package/dist/react/index.mjs
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useRef as
|
|
3
|
-
import { EditorServer as
|
|
4
|
-
function
|
|
5
|
-
assetsPath:
|
|
6
|
-
x2tPath:
|
|
7
|
-
file:
|
|
8
|
-
fileUrl:
|
|
9
|
-
newDocument:
|
|
10
|
-
language:
|
|
11
|
-
theme:
|
|
12
|
-
user:
|
|
13
|
-
onReady:
|
|
14
|
-
onDocumentStateChange:
|
|
15
|
-
onSave:
|
|
16
|
-
onError:
|
|
17
|
-
style:
|
|
18
|
-
className:
|
|
1
|
+
import { jsx as u } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as W, useEffect as X, useLayoutEffect as j } from "react";
|
|
3
|
+
import { EditorServer as F, getDocumentType as M, MockSocket as d, createXHRProxy as O, io as C } from "../index.mjs";
|
|
4
|
+
function _({
|
|
5
|
+
assetsPath: T,
|
|
6
|
+
x2tPath: E = "/x2t-1",
|
|
7
|
+
file: h,
|
|
8
|
+
fileUrl: m,
|
|
9
|
+
newDocument: w,
|
|
10
|
+
language: R = "en",
|
|
11
|
+
theme: q = "theme-light",
|
|
12
|
+
user: y = { id: "uid", name: "User" },
|
|
13
|
+
onReady: l,
|
|
14
|
+
onDocumentStateChange: a,
|
|
15
|
+
onSave: N,
|
|
16
|
+
onError: n,
|
|
17
|
+
style: x,
|
|
18
|
+
className: A
|
|
19
19
|
}) {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const c = (
|
|
23
|
-
|
|
20
|
+
const r = W(!1), g = T.replace(/\/$/, "");
|
|
21
|
+
X(() => {
|
|
22
|
+
const c = (t) => {
|
|
23
|
+
r.current && (t.preventDefault(), t.returnValue = "");
|
|
24
24
|
};
|
|
25
25
|
return window.addEventListener("beforeunload", c), () => window.removeEventListener("beforeunload", c);
|
|
26
|
-
}, []),
|
|
27
|
-
const c =
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
let
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
const e = document.querySelector('iframe[name="frameEditor"]'), o = e == null ? void 0 : e.contentWindow,
|
|
35
|
-
if (!
|
|
36
|
-
|
|
26
|
+
}, []), j(() => {
|
|
27
|
+
const c = g + "/web-apps/apps/api/documents/api.js", t = new F({ x2tPath: E, user: y });
|
|
28
|
+
h ? t.open(h) : m ? t.openUrl(m) : w ? t.openNew(w) : t.openNew("docx");
|
|
29
|
+
const i = t.getDocument(), U = M(i.fileType);
|
|
30
|
+
let s = null;
|
|
31
|
+
const v = ({ socket: e }) => t.handleConnect({ socket: e }), D = ({ socket: e }) => t.handleDisconnect({ socket: e });
|
|
32
|
+
d.on("connect", v), d.on("disconnect", D);
|
|
33
|
+
const H = () => {
|
|
34
|
+
const e = document.querySelector('iframe[name="frameEditor"]'), o = e == null ? void 0 : e.contentWindow, p = e == null ? void 0 : e.contentDocument;
|
|
35
|
+
if (!p || !o) {
|
|
36
|
+
n == null || n(new Error("Iframe not loaded"));
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
io:
|
|
42
|
-
XMLHttpRequest:
|
|
43
|
-
Worker: function(
|
|
44
|
-
return new
|
|
39
|
+
const L = O(o.XMLHttpRequest), I = o.Worker;
|
|
40
|
+
L.use((f) => t.handleRequest(f)), Object.assign(o, {
|
|
41
|
+
io: C,
|
|
42
|
+
XMLHttpRequest: L,
|
|
43
|
+
Worker: function(f, P) {
|
|
44
|
+
return new I(new URL(f, location.origin).href, P);
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
|
|
47
|
+
const b = p.createElement("script");
|
|
48
|
+
b.src = new URL(c, location.origin).href, p.body.appendChild(b), l == null || l();
|
|
49
|
+
}, k = () => {
|
|
50
|
+
s = new window.DocsAPI.DocEditor("placeholder", {
|
|
51
51
|
isLocalFile: !0,
|
|
52
52
|
document: {
|
|
53
|
-
fileType:
|
|
54
|
-
key:
|
|
55
|
-
title:
|
|
56
|
-
url:
|
|
53
|
+
fileType: i.fileType,
|
|
54
|
+
key: i.key,
|
|
55
|
+
title: i.title,
|
|
56
|
+
url: i.url,
|
|
57
57
|
permissions: {
|
|
58
|
-
edit:
|
|
58
|
+
edit: i.fileType !== "pdf",
|
|
59
59
|
chat: !1,
|
|
60
60
|
rename: !0,
|
|
61
61
|
protect: !0,
|
|
@@ -63,27 +63,27 @@ function J({
|
|
|
63
63
|
print: !1
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
-
documentType:
|
|
66
|
+
documentType: U,
|
|
67
67
|
editorConfig: {
|
|
68
|
-
lang:
|
|
68
|
+
lang: R,
|
|
69
69
|
coEditing: { mode: "fast", change: !1 },
|
|
70
|
-
user: { ...
|
|
70
|
+
user: { ...y },
|
|
71
71
|
customization: {
|
|
72
|
-
uiTheme:
|
|
72
|
+
uiTheme: q,
|
|
73
73
|
features: { spellcheck: { change: !1 } }
|
|
74
74
|
}
|
|
75
75
|
},
|
|
76
76
|
events: {
|
|
77
|
-
onAppReady: () =>
|
|
77
|
+
onAppReady: () => H(),
|
|
78
78
|
onDocumentStateChange: (e) => {
|
|
79
|
-
e.data && (
|
|
79
|
+
e.data && (r.current = !0), a == null || a(e.data);
|
|
80
80
|
},
|
|
81
|
-
onError: (e) =>
|
|
81
|
+
onError: (e) => n == null ? void 0 : n(new Error(String(e))),
|
|
82
82
|
onSaveDocument: () => {
|
|
83
|
-
|
|
83
|
+
r.current = !1;
|
|
84
84
|
},
|
|
85
85
|
writeFile: () => {
|
|
86
|
-
|
|
86
|
+
r.current = !1;
|
|
87
87
|
}
|
|
88
88
|
},
|
|
89
89
|
width: "100%",
|
|
@@ -93,26 +93,25 @@ function J({
|
|
|
93
93
|
return (() => {
|
|
94
94
|
var o;
|
|
95
95
|
if ((o = window.DocsAPI) != null && o.DocEditor) {
|
|
96
|
-
|
|
96
|
+
k();
|
|
97
97
|
return;
|
|
98
98
|
}
|
|
99
99
|
let e = document.querySelector(`script[src="${c}"]`);
|
|
100
|
-
e || (e = document.createElement("script"), e.src = c, document.head.appendChild(e)), e.onload = () =>
|
|
100
|
+
e || (e = document.createElement("script"), e.src = c, document.head.appendChild(e)), e.onload = () => k(), e.onerror = () => n == null ? void 0 : n(new Error("Failed to load DocsAPI script"));
|
|
101
101
|
})(), () => {
|
|
102
102
|
var e;
|
|
103
|
-
|
|
103
|
+
d.off("connect", v), d.off("disconnect", D), (e = s == null ? void 0 : s.destroyEditor) == null || e.call(s), t.destroy();
|
|
104
104
|
};
|
|
105
105
|
}, []);
|
|
106
|
-
const
|
|
107
|
-
return /* @__PURE__ */
|
|
106
|
+
const S = g + "/web-apps/apps/api/documents/preload.html";
|
|
107
|
+
return /* @__PURE__ */ u("div", { style: { width: "100%", height: "100%", ...x }, className: A, children: /* @__PURE__ */ u("div", { id: "placeholder", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ u(
|
|
108
108
|
"iframe",
|
|
109
109
|
{
|
|
110
110
|
style: { width: 0, height: 0, display: "none" },
|
|
111
|
-
src:
|
|
112
|
-
srcDoc: C
|
|
111
|
+
src: S
|
|
113
112
|
}
|
|
114
113
|
) }) });
|
|
115
114
|
}
|
|
116
115
|
export {
|
|
117
|
-
|
|
116
|
+
_ as OnlyOfficeEditor
|
|
118
117
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OnlyOfficeEditor.vue.d.ts","sourceRoot":"","sources":["../../src/vue/OnlyOfficeEditor.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"OnlyOfficeEditor.vue.d.ts","sourceRoot":"","sources":["../../src/vue/OnlyOfficeEditor.vue"],"names":[],"mappings":"AAsKA,OAAO,KAAK,EAAa,WAAW,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AAEjE,UAAU,KAAK;IACb,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAA;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,WAAW,CAAA;IACnB,IAAI,CAAC,EAAE,IAAI,CAAA;CACZ;;;;;;;;;;;;aAPW,MAAM;UAMT,IAAI;cAFA,MAAM;WACT,WAAW;;AAyLrB,wBAQG"}
|