wasm-onlyoffice-sdk 0.1.5 → 0.1.7
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/core/editor-server.d.ts +3 -1
- package/dist/core/editor-server.d.ts.map +1 -1
- package/dist/index.mjs +73 -67
- package/dist/react/index.mjs +76 -66
- package/dist/vue/OnlyOfficeEditor.vue.d.ts.map +1 -1
- package/dist/vue/index.mjs +264 -265
- 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
|
|
|
@@ -16,9 +16,11 @@ export declare class EditorServer {
|
|
|
16
16
|
private urlsMap;
|
|
17
17
|
private downloadId;
|
|
18
18
|
private downloadParts;
|
|
19
|
-
|
|
19
|
+
private onSave;
|
|
20
|
+
constructor({ x2tPath, user, onSave }?: {
|
|
20
21
|
x2tPath?: string;
|
|
21
22
|
user?: User;
|
|
23
|
+
onSave?: (blob: Blob, filename: string) => void;
|
|
22
24
|
});
|
|
23
25
|
open(file: File, { fileType, fileName }?: {
|
|
24
26
|
fileType?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor-server.d.ts","sourceRoot":"","sources":["../../src/core/editor-server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,IAAI,EAA6B,MAAM,SAAS,CAAA;AA0BzD,qBAAa,YAAY;IACvB,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,EAAE,CAAM;IAChB,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,SAAS,CAAwB;IACzC,OAAO,CAAC,IAAI,CAGV;IACF,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,gBAAgB,CAAK;IAC7B,OAAO,CAAC,WAAW,CAA8B;IAEjD,OAAO,CAAC,IAAI,CAAqB;IACjC,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,KAAK,CAAsC;IACnD,OAAO,CAAC,OAAO,CAAkC;IAEjD,OAAO,CAAC,UAAU,CAAc;IAChC,OAAO,CAAC,aAAa,CAAoB;
|
|
1
|
+
{"version":3,"file":"editor-server.d.ts","sourceRoot":"","sources":["../../src/core/editor-server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,IAAI,EAA6B,MAAM,SAAS,CAAA;AA0BzD,qBAAa,YAAY;IACvB,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,EAAE,CAAM;IAChB,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,SAAS,CAAwB;IACzC,OAAO,CAAC,IAAI,CAGV;IACF,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,gBAAgB,CAAK;IAC7B,OAAO,CAAC,WAAW,CAA8B;IAEjD,OAAO,CAAC,IAAI,CAAqB;IACjC,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,KAAK,CAAsC;IACnD,OAAO,CAAC,OAAO,CAAkC;IAEjD,OAAO,CAAC,UAAU,CAAc;IAChC,OAAO,CAAC,aAAa,CAAoB;IAEzC,OAAO,CAAC,MAAM,CAAuD;gBAEzD,EAAE,OAAkB,EAAE,IAAI,EAAE,MAAM,EAAE,GAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,IAAI,CAAC;QAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;KAAO;IASnI,IAAI,CACR,IAAI,EAAE,IAAI,EACV,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAO;;;;IAiBvE,OAAO,CAAC,QAAQ,CAAC,EAAE,MAAM;;;;IAqCnB,OAAO,CACX,GAAG,EAAE,MAAM,EACX,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAO;;;;IAgBvE,WAAW;;;;;;IAaX,OAAO;YAIO,YAAY;IAqC1B,OAAO,CAAC,QAAQ;IAQhB,aAAa,CAAC,EAAE,MAAM,EAAE,EAAE;QAAE,MAAM,EAAE,UAAU,CAAA;KAAE;IA+ChD,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAAE;QAAE,MAAM,EAAE,UAAU,CAAA;KAAE;IAKnD,IAAI,CAAC,GAAG,EAAE,GAAG;IAQP,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE;IAyG1C,aAAa,CAAC,GAAG,EAAE,OAAO;IAiHhC,OAAO;CAIR"}
|
package/dist/index.mjs
CHANGED
|
@@ -209,11 +209,11 @@ function u(g, A) {
|
|
|
209
209
|
return URL.createObjectURL(B);
|
|
210
210
|
}
|
|
211
211
|
class $ {
|
|
212
|
-
constructor({ x2tPath: A = "/x2t-1", user: B } = {}) {
|
|
212
|
+
constructor({ x2tPath: A = "/x2t-1", user: B, onSave: Q } = {}) {
|
|
213
213
|
this.id = "", this.socket = null, this.sessionId = "session-id", this.user = {
|
|
214
214
|
id: "uid",
|
|
215
215
|
name: "Me"
|
|
216
|
-
}, this.participants = [], this.syncChangesIndex = 0, this.loadPromise = null, this.file = null, this.fileType = "docx", this.title = "", this.fsMap = /* @__PURE__ */ new Map(), this.urlsMap = /* @__PURE__ */ new Map(), this.downloadId = "", this.downloadParts = [], this.converter = new K(A), B && (this.user = B), this.send = this.send.bind(this), this.handleConnect = this.handleConnect.bind(this), this.handleMessage = this.handleMessage.bind(this);
|
|
216
|
+
}, this.participants = [], this.syncChangesIndex = 0, this.loadPromise = null, this.file = null, this.fileType = "docx", this.title = "", this.fsMap = /* @__PURE__ */ new Map(), this.urlsMap = /* @__PURE__ */ new Map(), this.downloadId = "", this.downloadParts = [], this.converter = new K(A), B && (this.user = B), Q && (this.onSave = Q), this.send = this.send.bind(this), this.handleConnect = this.handleConnect.bind(this), this.handleMessage = this.handleMessage.bind(this);
|
|
217
217
|
}
|
|
218
218
|
async open(A, { fileType: B, fileName: Q } = {}) {
|
|
219
219
|
const E = Q || A.name;
|
|
@@ -450,19 +450,25 @@ class $ {
|
|
|
450
450
|
!r && C.endsWith(".pdf") && (r = 513);
|
|
451
451
|
const D = async () => {
|
|
452
452
|
const G = W(this.downloadParts);
|
|
453
|
-
let
|
|
454
|
-
s.format == "pdf" && (
|
|
453
|
+
let t = "from.bin";
|
|
454
|
+
s.format == "pdf" && (t = "from.pdf");
|
|
455
455
|
let { output: w } = await this.converter.convert({
|
|
456
456
|
data: G.buffer,
|
|
457
|
-
fileFrom:
|
|
457
|
+
fileFrom: t,
|
|
458
458
|
fileTo: C,
|
|
459
459
|
formatTo: r,
|
|
460
460
|
media: Object.fromEntries(this.fsMap)
|
|
461
461
|
});
|
|
462
462
|
if (!w && s.format == "pdf" && (w = G), !w)
|
|
463
463
|
return console.error("Conversion failed"), { status: "error" };
|
|
464
|
-
const M = new Blob([new Uint8Array(w)]), i =
|
|
465
|
-
|
|
464
|
+
const M = new Blob([new Uint8Array(w)]), i = s.title || "document.docx";
|
|
465
|
+
if (this.onSave)
|
|
466
|
+
this.onSave(M, i);
|
|
467
|
+
else {
|
|
468
|
+
const o = URL.createObjectURL(M), I = document.createElement("a");
|
|
469
|
+
I.href = o, I.download = i, I.click(), URL.revokeObjectURL(o);
|
|
470
|
+
}
|
|
471
|
+
return { status: "ok" };
|
|
466
472
|
};
|
|
467
473
|
let e = {
|
|
468
474
|
status: "ok"
|
|
@@ -521,10 +527,10 @@ function q() {
|
|
|
521
527
|
function E(r, D, e) {
|
|
522
528
|
this.fn = r, this.context = D, this.once = e || !1;
|
|
523
529
|
}
|
|
524
|
-
function s(r, D, e, G,
|
|
530
|
+
function s(r, D, e, G, t) {
|
|
525
531
|
if (typeof e != "function")
|
|
526
532
|
throw new TypeError("The listener must be a function");
|
|
527
|
-
var w = new E(e, G || r,
|
|
533
|
+
var w = new E(e, G || r, t), M = B ? B + D : D;
|
|
528
534
|
return r._events[M] ? r._events[M].fn ? r._events[M] = [r._events[M], w] : r._events[M].push(w) : (r._events[M] = w, r._eventsCount++), r;
|
|
529
535
|
}
|
|
530
536
|
function P(r, D) {
|
|
@@ -543,54 +549,54 @@ function q() {
|
|
|
543
549
|
var e = B ? B + D : D, G = this._events[e];
|
|
544
550
|
if (!G) return [];
|
|
545
551
|
if (G.fn) return [G.fn];
|
|
546
|
-
for (var
|
|
547
|
-
M[
|
|
552
|
+
for (var t = 0, w = G.length, M = new Array(w); t < w; t++)
|
|
553
|
+
M[t] = G[t].fn;
|
|
548
554
|
return M;
|
|
549
555
|
}, C.prototype.listenerCount = function(D) {
|
|
550
556
|
var e = B ? B + D : D, G = this._events[e];
|
|
551
557
|
return G ? G.fn ? 1 : G.length : 0;
|
|
552
|
-
}, C.prototype.emit = function(D, e, G,
|
|
558
|
+
}, C.prototype.emit = function(D, e, G, t, w, M) {
|
|
553
559
|
var i = B ? B + D : D;
|
|
554
560
|
if (!this._events[i]) return !1;
|
|
555
|
-
var
|
|
556
|
-
if (
|
|
557
|
-
switch (
|
|
561
|
+
var o = this._events[i], I = arguments.length, c, n;
|
|
562
|
+
if (o.fn) {
|
|
563
|
+
switch (o.once && this.removeListener(D, o.fn, void 0, !0), I) {
|
|
558
564
|
case 1:
|
|
559
|
-
return
|
|
565
|
+
return o.fn.call(o.context), !0;
|
|
560
566
|
case 2:
|
|
561
|
-
return
|
|
567
|
+
return o.fn.call(o.context, e), !0;
|
|
562
568
|
case 3:
|
|
563
|
-
return
|
|
569
|
+
return o.fn.call(o.context, e, G), !0;
|
|
564
570
|
case 4:
|
|
565
|
-
return
|
|
571
|
+
return o.fn.call(o.context, e, G, t), !0;
|
|
566
572
|
case 5:
|
|
567
|
-
return
|
|
573
|
+
return o.fn.call(o.context, e, G, t, w), !0;
|
|
568
574
|
case 6:
|
|
569
|
-
return
|
|
575
|
+
return o.fn.call(o.context, e, G, t, w, M), !0;
|
|
570
576
|
}
|
|
571
577
|
for (n = 1, c = new Array(I - 1); n < I; n++)
|
|
572
578
|
c[n - 1] = arguments[n];
|
|
573
|
-
|
|
579
|
+
o.fn.apply(o.context, c);
|
|
574
580
|
} else {
|
|
575
|
-
var m =
|
|
581
|
+
var m = o.length, Y;
|
|
576
582
|
for (n = 0; n < m; n++)
|
|
577
|
-
switch (
|
|
583
|
+
switch (o[n].once && this.removeListener(D, o[n].fn, void 0, !0), I) {
|
|
578
584
|
case 1:
|
|
579
|
-
|
|
585
|
+
o[n].fn.call(o[n].context);
|
|
580
586
|
break;
|
|
581
587
|
case 2:
|
|
582
|
-
|
|
588
|
+
o[n].fn.call(o[n].context, e);
|
|
583
589
|
break;
|
|
584
590
|
case 3:
|
|
585
|
-
|
|
591
|
+
o[n].fn.call(o[n].context, e, G);
|
|
586
592
|
break;
|
|
587
593
|
case 4:
|
|
588
|
-
|
|
594
|
+
o[n].fn.call(o[n].context, e, G, t);
|
|
589
595
|
break;
|
|
590
596
|
default:
|
|
591
|
-
if (!c) for (
|
|
592
|
-
c[
|
|
593
|
-
|
|
597
|
+
if (!c) for (Y = 1, c = new Array(I - 1); Y < I; Y++)
|
|
598
|
+
c[Y - 1] = arguments[Y];
|
|
599
|
+
o[n].fn.apply(o[n].context, c);
|
|
594
600
|
}
|
|
595
601
|
}
|
|
596
602
|
return !0;
|
|
@@ -598,18 +604,18 @@ function q() {
|
|
|
598
604
|
return s(this, D, e, G, !1);
|
|
599
605
|
}, C.prototype.once = function(D, e, G) {
|
|
600
606
|
return s(this, D, e, G, !0);
|
|
601
|
-
}, C.prototype.removeListener = function(D, e, G,
|
|
607
|
+
}, C.prototype.removeListener = function(D, e, G, t) {
|
|
602
608
|
var w = B ? B + D : D;
|
|
603
609
|
if (!this._events[w]) return this;
|
|
604
610
|
if (!e)
|
|
605
611
|
return P(this, w), this;
|
|
606
612
|
var M = this._events[w];
|
|
607
613
|
if (M.fn)
|
|
608
|
-
M.fn === e && (!
|
|
614
|
+
M.fn === e && (!t || M.once) && (!G || M.context === G) && P(this, w);
|
|
609
615
|
else {
|
|
610
|
-
for (var i = 0,
|
|
611
|
-
(M[i].fn !== e ||
|
|
612
|
-
|
|
616
|
+
for (var i = 0, o = [], I = M.length; i < I; i++)
|
|
617
|
+
(M[i].fn !== e || t && !M[i].once || G && M[i].context !== G) && o.push(M[i]);
|
|
618
|
+
o.length ? this._events[w] = o.length === 1 ? o[0] : o : P(this, w);
|
|
613
619
|
}
|
|
614
620
|
return this;
|
|
615
621
|
}, C.prototype.removeAllListeners = function(D) {
|
|
@@ -619,7 +625,7 @@ function q() {
|
|
|
619
625
|
})(f)), f.exports;
|
|
620
626
|
}
|
|
621
627
|
var X = q();
|
|
622
|
-
const T = /* @__PURE__ */ j(X),
|
|
628
|
+
const T = /* @__PURE__ */ j(X), h = class h {
|
|
623
629
|
constructor(A = {}) {
|
|
624
630
|
this.active = !0, this.connected = !1, this.disconnected = !0, this.recovered = !1, this.id = "", this.io = {
|
|
625
631
|
setOpenToken: () => {
|
|
@@ -657,10 +663,10 @@ const T = /* @__PURE__ */ j(X), Y = class Y {
|
|
|
657
663
|
}, this._debug = A.debug ?? !1, this.connect();
|
|
658
664
|
}
|
|
659
665
|
static on(A, B) {
|
|
660
|
-
|
|
666
|
+
h._staticEmitter.on(A, B);
|
|
661
667
|
}
|
|
662
668
|
static off(A, B) {
|
|
663
|
-
|
|
669
|
+
h._staticEmitter.off(A, B);
|
|
664
670
|
}
|
|
665
671
|
_log(...A) {
|
|
666
672
|
this._debug && console.log("[MockSocket]", ...A);
|
|
@@ -675,11 +681,11 @@ const T = /* @__PURE__ */ j(X), Y = class Y {
|
|
|
675
681
|
*/
|
|
676
682
|
connect() {
|
|
677
683
|
return this.connected = !0, this.disconnected = !1, this.id = Math.random().toString(36).substring(2, 15), setTimeout(() => {
|
|
678
|
-
this._trigger("connect"),
|
|
684
|
+
this._trigger("connect"), h._staticEmitter.emit("connect", { socket: this });
|
|
679
685
|
}, 0), this;
|
|
680
686
|
}
|
|
681
687
|
disconnect() {
|
|
682
|
-
return this.connected = !1, this.disconnected = !0, this._trigger("disconnect"),
|
|
688
|
+
return this.connected = !1, this.disconnected = !0, this._trigger("disconnect"), h._staticEmitter.emit("disconnect", { socket: this }), this;
|
|
683
689
|
}
|
|
684
690
|
close() {
|
|
685
691
|
return this.disconnect();
|
|
@@ -735,8 +741,8 @@ const T = /* @__PURE__ */ j(X), Y = class Y {
|
|
|
735
741
|
return setTimeout(() => Q(), 0), this;
|
|
736
742
|
}
|
|
737
743
|
};
|
|
738
|
-
|
|
739
|
-
let p =
|
|
744
|
+
h._staticEmitter = new T();
|
|
745
|
+
let p = h;
|
|
740
746
|
function AA(g, A) {
|
|
741
747
|
return new p(A);
|
|
742
748
|
}
|
|
@@ -755,8 +761,8 @@ function BA(g = globalThis.XMLHttpRequest) {
|
|
|
755
761
|
/**
|
|
756
762
|
* Register global middleware
|
|
757
763
|
*/
|
|
758
|
-
static use(
|
|
759
|
-
this._middlewares.push(
|
|
764
|
+
static use(t) {
|
|
765
|
+
this._middlewares.push(t);
|
|
760
766
|
}
|
|
761
767
|
/**
|
|
762
768
|
* Clear all middleware
|
|
@@ -764,27 +770,27 @@ function BA(g = globalThis.XMLHttpRequest) {
|
|
|
764
770
|
static clearMiddlewares() {
|
|
765
771
|
this._middlewares = [];
|
|
766
772
|
}
|
|
767
|
-
open(
|
|
768
|
-
H(this, B,
|
|
769
|
-
|
|
773
|
+
open(t, w, M = !0, i, o) {
|
|
774
|
+
H(this, B, t), H(this, Q, w.toString()), H(this, E, new Headers()), H(this, A, !1), super.open(
|
|
775
|
+
t,
|
|
770
776
|
w,
|
|
771
777
|
M,
|
|
772
778
|
i ?? void 0,
|
|
773
|
-
|
|
779
|
+
o ?? void 0
|
|
774
780
|
);
|
|
775
781
|
}
|
|
776
|
-
setRequestHeader(
|
|
777
|
-
a(this, E).append(
|
|
782
|
+
setRequestHeader(t, w) {
|
|
783
|
+
a(this, E).append(t, w), a(this, A) || super.setRequestHeader(t, w);
|
|
778
784
|
}
|
|
779
|
-
send(
|
|
780
|
-
H(this, s,
|
|
781
|
-
w || super.send(
|
|
785
|
+
send(t) {
|
|
786
|
+
H(this, s, t), l(this, P, N).call(this).then((w) => {
|
|
787
|
+
w || super.send(t);
|
|
782
788
|
}).catch((w) => {
|
|
783
|
-
console.error("ProxyXMLHttpRequest middleware error:", w), super.send(
|
|
789
|
+
console.error("ProxyXMLHttpRequest middleware error:", w), super.send(t);
|
|
784
790
|
});
|
|
785
791
|
}
|
|
786
792
|
}, A = new WeakMap(), B = new WeakMap(), Q = new WeakMap(), E = new WeakMap(), s = new WeakMap(), P = new WeakSet(), N = async function() {
|
|
787
|
-
let
|
|
793
|
+
let t;
|
|
788
794
|
try {
|
|
789
795
|
const w = {
|
|
790
796
|
method: a(this, B),
|
|
@@ -792,17 +798,17 @@ function BA(g = globalThis.XMLHttpRequest) {
|
|
|
792
798
|
body: a(this, s),
|
|
793
799
|
mode: "cors"
|
|
794
800
|
};
|
|
795
|
-
this.withCredentials && (w.credentials = "include"),
|
|
801
|
+
this.withCredentials && (w.credentials = "include"), t = new Request(a(this, Q), w);
|
|
796
802
|
} catch {
|
|
797
803
|
return !1;
|
|
798
804
|
}
|
|
799
805
|
for (const w of D._middlewares) {
|
|
800
|
-
const M = await w(
|
|
806
|
+
const M = await w(t.clone());
|
|
801
807
|
if (M)
|
|
802
808
|
return H(this, A, !0), await l(this, P, O).call(this, M), !0;
|
|
803
809
|
}
|
|
804
810
|
return !1;
|
|
805
|
-
}, O = async function(
|
|
811
|
+
}, O = async function(t) {
|
|
806
812
|
this.dispatchEvent(new ProgressEvent("loadstart")), Object.defineProperty(this, "readyState", {
|
|
807
813
|
value: 2,
|
|
808
814
|
writable: !1,
|
|
@@ -815,22 +821,22 @@ function BA(g = globalThis.XMLHttpRequest) {
|
|
|
815
821
|
try {
|
|
816
822
|
let w;
|
|
817
823
|
if (this.responseType === "json")
|
|
818
|
-
w = await
|
|
824
|
+
w = await t.json();
|
|
819
825
|
else if (this.responseType === "arraybuffer")
|
|
820
|
-
w = await
|
|
826
|
+
w = await t.arrayBuffer();
|
|
821
827
|
else if (this.responseType === "blob")
|
|
822
|
-
w = await
|
|
828
|
+
w = await t.blob();
|
|
823
829
|
else if (this.responseType === "document") {
|
|
824
|
-
const M = await
|
|
830
|
+
const M = await t.text();
|
|
825
831
|
w = new DOMParser().parseFromString(M, "text/xml");
|
|
826
832
|
} else
|
|
827
|
-
w = await
|
|
833
|
+
w = await t.text();
|
|
828
834
|
Object.defineProperty(this, "status", {
|
|
829
|
-
value:
|
|
835
|
+
value: t.status,
|
|
830
836
|
writable: !1,
|
|
831
837
|
configurable: !0
|
|
832
838
|
}), Object.defineProperty(this, "statusText", {
|
|
833
|
-
value:
|
|
839
|
+
value: t.statusText,
|
|
834
840
|
writable: !1,
|
|
835
841
|
configurable: !0
|
|
836
842
|
}), Object.defineProperty(this, "response", {
|
|
@@ -842,7 +848,7 @@ function BA(g = globalThis.XMLHttpRequest) {
|
|
|
842
848
|
writable: !1,
|
|
843
849
|
configurable: !0
|
|
844
850
|
}), Object.defineProperty(this, "responseURL", {
|
|
845
|
-
value:
|
|
851
|
+
value: t.url,
|
|
846
852
|
writable: !1,
|
|
847
853
|
configurable: !0
|
|
848
854
|
}), this.dispatchEvent(
|
package/dist/react/index.mjs
CHANGED
|
@@ -1,61 +1,65 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useRef as
|
|
3
|
-
import { EditorServer as
|
|
4
|
-
function
|
|
5
|
-
assetsPath:
|
|
6
|
-
x2tPath:
|
|
7
|
-
file:
|
|
8
|
-
fileUrl:
|
|
1
|
+
import { jsx as m } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as d, useEffect as z, useLayoutEffect as B } from "react";
|
|
3
|
+
import { EditorServer as V, getDocumentType as _, MockSocket as f, createXHRProxy as G, io as J } from "../index.mjs";
|
|
4
|
+
function Z({
|
|
5
|
+
assetsPath: H,
|
|
6
|
+
x2tPath: I = "/x2t-1",
|
|
7
|
+
file: w,
|
|
8
|
+
fileUrl: y,
|
|
9
9
|
newDocument: g,
|
|
10
|
-
language:
|
|
11
|
-
theme:
|
|
12
|
-
user:
|
|
13
|
-
onReady:
|
|
14
|
-
onDocumentStateChange:
|
|
15
|
-
onSave:
|
|
16
|
-
onError:
|
|
17
|
-
style:
|
|
18
|
-
className:
|
|
10
|
+
language: P = "en",
|
|
11
|
+
theme: W = "theme-light",
|
|
12
|
+
user: E = { id: "uid", name: "User" },
|
|
13
|
+
onReady: D,
|
|
14
|
+
onDocumentStateChange: v,
|
|
15
|
+
onSave: k,
|
|
16
|
+
onError: L,
|
|
17
|
+
style: X,
|
|
18
|
+
className: j
|
|
19
19
|
}) {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const c = (
|
|
23
|
-
|
|
20
|
+
const l = d(!1), b = H.replace(/\/$/, ""), a = d(D), u = d(v), p = d(k), r = d(L);
|
|
21
|
+
a.current = D, u.current = v, p.current = k, r.current = L, z(() => {
|
|
22
|
+
const c = (n) => {
|
|
23
|
+
l.current && (n.preventDefault(), n.returnValue = "");
|
|
24
24
|
};
|
|
25
25
|
return window.addEventListener("beforeunload", c), () => window.removeEventListener("beforeunload", c);
|
|
26
|
-
}, []),
|
|
27
|
-
const c =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
}, []), B(() => {
|
|
27
|
+
const c = b + "/web-apps/apps/api/documents/api.js", n = new V({ x2tPath: I, user: E, onSave: (e, t) => {
|
|
28
|
+
var o;
|
|
29
|
+
return (o = p.current) == null ? void 0 : o.call(p, e, t);
|
|
30
|
+
} });
|
|
31
|
+
w ? n.open(w) : y ? n.openUrl(y) : g ? n.openNew(g) : n.openNew("docx");
|
|
32
|
+
const i = n.getDocument(), M = _(i.fileType);
|
|
33
|
+
let s = null;
|
|
34
|
+
const T = ({ socket: e }) => n.handleConnect({ socket: e }), q = ({ socket: e }) => n.handleDisconnect({ socket: e });
|
|
35
|
+
f.on("connect", T), f.on("disconnect", q);
|
|
36
|
+
const O = () => {
|
|
37
|
+
var U, C;
|
|
38
|
+
const e = document.querySelector('iframe[name="frameEditor"]'), t = e == null ? void 0 : e.contentWindow, o = e == null ? void 0 : e.contentDocument;
|
|
39
|
+
if (!o || !t) {
|
|
40
|
+
(U = r.current) == null || U.call(r, new Error("Iframe not loaded"));
|
|
37
41
|
return;
|
|
38
42
|
}
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
io:
|
|
42
|
-
XMLHttpRequest:
|
|
43
|
-
Worker: function(
|
|
44
|
-
return new
|
|
43
|
+
const A = G(t.XMLHttpRequest), N = t.Worker;
|
|
44
|
+
A.use((h) => n.handleRequest(h)), Object.assign(t, {
|
|
45
|
+
io: J,
|
|
46
|
+
XMLHttpRequest: A,
|
|
47
|
+
Worker: function(h, $) {
|
|
48
|
+
return new N(new URL(h, location.origin).href, $);
|
|
45
49
|
}
|
|
46
50
|
});
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
+
const S = o.createElement("script");
|
|
52
|
+
S.src = new URL(c, location.origin).href, o.body.appendChild(S), (C = a.current) == null || C.call(a);
|
|
53
|
+
}, x = () => {
|
|
54
|
+
s = new window.DocsAPI.DocEditor("placeholder", {
|
|
51
55
|
isLocalFile: !0,
|
|
52
56
|
document: {
|
|
53
|
-
fileType:
|
|
54
|
-
key:
|
|
55
|
-
title:
|
|
56
|
-
url:
|
|
57
|
+
fileType: i.fileType,
|
|
58
|
+
key: i.key,
|
|
59
|
+
title: i.title,
|
|
60
|
+
url: i.url,
|
|
57
61
|
permissions: {
|
|
58
|
-
edit:
|
|
62
|
+
edit: i.fileType !== "pdf",
|
|
59
63
|
chat: !1,
|
|
60
64
|
rename: !0,
|
|
61
65
|
protect: !0,
|
|
@@ -63,27 +67,31 @@ function J({
|
|
|
63
67
|
print: !1
|
|
64
68
|
}
|
|
65
69
|
},
|
|
66
|
-
documentType:
|
|
70
|
+
documentType: M,
|
|
67
71
|
editorConfig: {
|
|
68
|
-
lang:
|
|
72
|
+
lang: P,
|
|
69
73
|
coEditing: { mode: "fast", change: !1 },
|
|
70
|
-
user: { ...
|
|
74
|
+
user: { ...E },
|
|
71
75
|
customization: {
|
|
72
|
-
uiTheme:
|
|
76
|
+
uiTheme: W,
|
|
73
77
|
features: { spellcheck: { change: !1 } }
|
|
74
78
|
}
|
|
75
79
|
},
|
|
76
80
|
events: {
|
|
77
|
-
onAppReady: () =>
|
|
81
|
+
onAppReady: () => O(),
|
|
78
82
|
onDocumentStateChange: (e) => {
|
|
79
|
-
|
|
83
|
+
var t;
|
|
84
|
+
e.data && (l.current = !0), (t = u.current) == null || t.call(u, e.data);
|
|
85
|
+
},
|
|
86
|
+
onError: (e) => {
|
|
87
|
+
var t;
|
|
88
|
+
return (t = r.current) == null ? void 0 : t.call(r, new Error(String(e)));
|
|
80
89
|
},
|
|
81
|
-
onError: (e) => t == null ? void 0 : t(new Error(String(e))),
|
|
82
90
|
onSaveDocument: () => {
|
|
83
|
-
|
|
91
|
+
l.current = !1;
|
|
84
92
|
},
|
|
85
93
|
writeFile: () => {
|
|
86
|
-
|
|
94
|
+
l.current = !1;
|
|
87
95
|
}
|
|
88
96
|
},
|
|
89
97
|
width: "100%",
|
|
@@ -91,28 +99,30 @@ function J({
|
|
|
91
99
|
});
|
|
92
100
|
};
|
|
93
101
|
return (() => {
|
|
94
|
-
var
|
|
95
|
-
if ((
|
|
96
|
-
|
|
102
|
+
var t;
|
|
103
|
+
if ((t = window.DocsAPI) != null && t.DocEditor) {
|
|
104
|
+
x();
|
|
97
105
|
return;
|
|
98
106
|
}
|
|
99
107
|
let e = document.querySelector(`script[src="${c}"]`);
|
|
100
|
-
e || (e = document.createElement("script"), e.src = c, document.head.appendChild(e)), e.onload = () =>
|
|
108
|
+
e || (e = document.createElement("script"), e.src = c, document.head.appendChild(e)), e.onload = () => x(), e.onerror = () => {
|
|
109
|
+
var o;
|
|
110
|
+
return (o = r.current) == null ? void 0 : o.call(r, new Error("Failed to load DocsAPI script"));
|
|
111
|
+
};
|
|
101
112
|
})(), () => {
|
|
102
113
|
var e;
|
|
103
|
-
|
|
114
|
+
f.off("connect", T), f.off("disconnect", q), (e = s == null ? void 0 : s.destroyEditor) == null || e.call(s), n.destroy();
|
|
104
115
|
};
|
|
105
116
|
}, []);
|
|
106
|
-
const
|
|
107
|
-
return /* @__PURE__ */
|
|
117
|
+
const F = b + "/web-apps/apps/api/documents/preload.html";
|
|
118
|
+
return /* @__PURE__ */ m("div", { style: { width: "100%", height: "100%", ...X }, className: j, children: /* @__PURE__ */ m("div", { id: "placeholder", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ m(
|
|
108
119
|
"iframe",
|
|
109
120
|
{
|
|
110
121
|
style: { width: 0, height: 0, display: "none" },
|
|
111
|
-
src:
|
|
112
|
-
srcDoc: C
|
|
122
|
+
src: F
|
|
113
123
|
}
|
|
114
124
|
) }) });
|
|
115
125
|
}
|
|
116
126
|
export {
|
|
117
|
-
|
|
127
|
+
Z as OnlyOfficeEditor
|
|
118
128
|
};
|
|
@@ -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"}
|