wasm-onlyoffice-sdk 0.1.4 → 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 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** — the `v9.3.0.24-1/` directory from the WASM build. Can be served from the same origin or a CDN.
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** — the `x2t-1/` directory containing `x2t.js` and `x2t.wasm`. Must be served from the **same origin** as your app (required for the Web Worker).
13
+ **x2t WASM converter** — `x2t.js` and `x2t.wasm`. Can be served from the same origin or a CDN.
14
14
 
15
- ### Same-origin setup
15
+ ### Setup
16
16
 
17
- Place assets in your project's `public/` folder:
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/ ← OnlyOffice web-apps assets
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
- ### CDN setup
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
- `assetsPath` also accepts a full URL. The SDK will automatically handle cross-origin restrictions by keeping the editor frame same-origin while loading web-apps assets from the CDN:
34
+ `x2tPath` accepts either a local path or a full CDN URL:
35
35
 
36
36
  ```tsx
37
37
  <OnlyOfficeEditor
38
- assetsPath="https://cdn.example.com/v9.3.0.24-1"
39
- x2tPath="/x2t-1"
38
+ assetsPath="/v9.3.0.24-1"
39
+ x2tPath="https://cdn.example.com/x2t"
40
40
  ...
41
41
  />
42
42
  ```
43
43
 
44
- > **Note:** `x2tPath` must remain same-origin regardless of where `assetsPath` points.
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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zE,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,EACP,qBAAqB,EACrB,MAAM,EACN,OAAO,EACP,KAAK,EACL,SAAS,GACV,EAAE,qBAAqB,2CA2IvB"}
@@ -1,61 +1,61 @@
1
- import { jsx as w } from "react/jsx-runtime";
2
- import { useRef as X, useEffect as j, useLayoutEffect as F } from "react";
3
- import { EditorServer as M, getDocumentType as N, MockSocket as l, createXHRProxy as $, io as B } from "../index.mjs";
4
- function J({
5
- assetsPath: S,
6
- x2tPath: q = "/x2t-1",
7
- file: y,
8
- fileUrl: v,
9
- newDocument: D,
10
- language: x = "en",
11
- theme: A = "theme-light",
12
- user: b = { id: "uid", name: "User" },
13
- onReady: p,
14
- onDocumentStateChange: u,
15
- onSave: z,
16
- onError: t,
17
- style: P,
18
- className: R
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 d = X(!1), r = S.replace(/\/$/, ""), f = /^https?:\/\//.test(r);
21
- j(() => {
22
- const c = (a) => {
23
- d.current && (a.preventDefault(), a.returnValue = "");
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
- }, []), F(() => {
27
- const c = r + "/web-apps/apps/api/documents/api.js", a = f ? r + "/web-apps/apps/api/documents/" : location.origin, n = new M({ x2tPath: q, user: b });
28
- y ? n.open(y) : v ? n.openUrl(v) : D ? n.openNew(D) : n.openNew("docx");
29
- const s = n.getDocument(), I = N(s.fileType);
30
- let i = null;
31
- const g = ({ socket: e }) => n.handleConnect({ socket: e }), k = ({ socket: e }) => n.handleDisconnect({ socket: e });
32
- l.on("connect", g), l.on("disconnect", k);
33
- const O = () => {
34
- const e = document.querySelector('iframe[name="frameEditor"]'), o = e == null ? void 0 : e.contentWindow, h = e == null ? void 0 : e.contentDocument;
35
- if (!h || !o) {
36
- t == null || t(new Error("Iframe not loaded"));
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 E = $(o.XMLHttpRequest), U = o.Worker;
40
- E.use((m) => n.handleRequest(m)), Object.assign(o, {
41
- io: B,
42
- XMLHttpRequest: E,
43
- Worker: function(m, W) {
44
- return new U(new URL(m, a).href, W);
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 L = h.createElement("script");
48
- L.src = c, h.body.appendChild(L), p == null || p();
49
- }, T = () => {
50
- i = new window.DocsAPI.DocEditor("placeholder", {
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: s.fileType,
54
- key: s.key,
55
- title: s.title,
56
- url: s.url,
53
+ fileType: i.fileType,
54
+ key: i.key,
55
+ title: i.title,
56
+ url: i.url,
57
57
  permissions: {
58
- edit: s.fileType !== "pdf",
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: I,
66
+ documentType: U,
67
67
  editorConfig: {
68
- lang: x,
68
+ lang: R,
69
69
  coEditing: { mode: "fast", change: !1 },
70
- user: { ...b },
70
+ user: { ...y },
71
71
  customization: {
72
- uiTheme: A,
72
+ uiTheme: q,
73
73
  features: { spellcheck: { change: !1 } }
74
74
  }
75
75
  },
76
76
  events: {
77
- onAppReady: () => O(),
77
+ onAppReady: () => H(),
78
78
  onDocumentStateChange: (e) => {
79
- e.data && (d.current = !0), u == null || u(e.data);
79
+ e.data && (r.current = !0), a == null || a(e.data);
80
80
  },
81
- onError: (e) => t == null ? void 0 : t(new Error(String(e))),
81
+ onError: (e) => n == null ? void 0 : n(new Error(String(e))),
82
82
  onSaveDocument: () => {
83
- d.current = !1;
83
+ r.current = !1;
84
84
  },
85
85
  writeFile: () => {
86
- d.current = !1;
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
- T();
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 = () => T(), e.onerror = () => t == null ? void 0 : t(new Error("Failed to load DocsAPI script"));
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
- l.off("connect", g), l.off("disconnect", k), (e = i == null ? void 0 : i.destroyEditor) == null || e.call(i), n.destroy();
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 C = f ? void 0 : r + "/web-apps/apps/api/documents/preload.html", H = f ? `<!DOCTYPE html><html><head><base href="${r}/web-apps/apps/api/documents/"></head><body></body></html>` : void 0;
107
- return /* @__PURE__ */ w("div", { style: { width: "100%", height: "100%", ...P }, className: R, children: /* @__PURE__ */ w("div", { id: "placeholder", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ w(
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: C,
112
- srcDoc: H
111
+ src: S
113
112
  }
114
113
  ) }) });
115
114
  }
116
115
  export {
117
- J as OnlyOfficeEditor
116
+ _ as OnlyOfficeEditor
118
117
  };
@@ -1 +1 @@
1
- {"version":3,"file":"OnlyOfficeEditor.vue.d.ts","sourceRoot":"","sources":["../../src/vue/OnlyOfficeEditor.vue"],"names":[],"mappings":"AAoLA,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;;AAwMrB,wBAQG"}
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"}