wasm-onlyoffice-sdk 0.1.6 → 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.
@@ -16,9 +16,11 @@ export declare class EditorServer {
16
16
  private urlsMap;
17
17
  private downloadId;
18
18
  private downloadParts;
19
- constructor({ x2tPath, user }?: {
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;gBAE7B,EAAE,OAAkB,EAAE,IAAI,EAAE,GAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,IAAI,CAAA;KAAO;IAQ1E,IAAI,CACR,IAAI,EAAE,IAAI,EACV,EAAE,QAA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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 o = "from.bin";
454
- s.format == "pdf" && (o = "from.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: o,
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 = URL.createObjectURL(M), t = document.createElement("a");
465
- return t.href = i, t.download = s.title || "test.docx", t.click(), URL.revokeObjectURL(i), { status: "ok" };
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, o) {
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, o), M = B ? B + D : D;
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 o = 0, w = G.length, M = new Array(w); o < w; o++)
547
- M[o] = G[o].fn;
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, o, w, M) {
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 t = this._events[i], I = arguments.length, c, n;
556
- if (t.fn) {
557
- switch (t.once && this.removeListener(D, t.fn, void 0, !0), I) {
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 t.fn.call(t.context), !0;
565
+ return o.fn.call(o.context), !0;
560
566
  case 2:
561
- return t.fn.call(t.context, e), !0;
567
+ return o.fn.call(o.context, e), !0;
562
568
  case 3:
563
- return t.fn.call(t.context, e, G), !0;
569
+ return o.fn.call(o.context, e, G), !0;
564
570
  case 4:
565
- return t.fn.call(t.context, e, G, o), !0;
571
+ return o.fn.call(o.context, e, G, t), !0;
566
572
  case 5:
567
- return t.fn.call(t.context, e, G, o, w), !0;
573
+ return o.fn.call(o.context, e, G, t, w), !0;
568
574
  case 6:
569
- return t.fn.call(t.context, e, G, o, w, M), !0;
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
- t.fn.apply(t.context, c);
579
+ o.fn.apply(o.context, c);
574
580
  } else {
575
- var m = t.length, h;
581
+ var m = o.length, Y;
576
582
  for (n = 0; n < m; n++)
577
- switch (t[n].once && this.removeListener(D, t[n].fn, void 0, !0), I) {
583
+ switch (o[n].once && this.removeListener(D, o[n].fn, void 0, !0), I) {
578
584
  case 1:
579
- t[n].fn.call(t[n].context);
585
+ o[n].fn.call(o[n].context);
580
586
  break;
581
587
  case 2:
582
- t[n].fn.call(t[n].context, e);
588
+ o[n].fn.call(o[n].context, e);
583
589
  break;
584
590
  case 3:
585
- t[n].fn.call(t[n].context, e, G);
591
+ o[n].fn.call(o[n].context, e, G);
586
592
  break;
587
593
  case 4:
588
- t[n].fn.call(t[n].context, e, G, o);
594
+ o[n].fn.call(o[n].context, e, G, t);
589
595
  break;
590
596
  default:
591
- if (!c) for (h = 1, c = new Array(I - 1); h < I; h++)
592
- c[h - 1] = arguments[h];
593
- t[n].fn.apply(t[n].context, c);
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, o) {
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 && (!o || M.once) && (!G || M.context === G) && P(this, w);
614
+ M.fn === e && (!t || M.once) && (!G || M.context === G) && P(this, w);
609
615
  else {
610
- for (var i = 0, t = [], I = M.length; i < I; i++)
611
- (M[i].fn !== e || o && !M[i].once || G && M[i].context !== G) && t.push(M[i]);
612
- t.length ? this._events[w] = t.length === 1 ? t[0] : t : P(this, w);
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), Y = class Y {
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
- Y._staticEmitter.on(A, B);
666
+ h._staticEmitter.on(A, B);
661
667
  }
662
668
  static off(A, B) {
663
- Y._staticEmitter.off(A, B);
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"), Y._staticEmitter.emit("connect", { socket: this });
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"), Y._staticEmitter.emit("disconnect", { socket: this }), this;
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
- Y._staticEmitter = new T();
739
- let p = Y;
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(o) {
759
- this._middlewares.push(o);
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(o, w, M = !0, i, t) {
768
- H(this, B, o), H(this, Q, w.toString()), H(this, E, new Headers()), H(this, A, !1), super.open(
769
- o,
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
- t ?? void 0
779
+ o ?? void 0
774
780
  );
775
781
  }
776
- setRequestHeader(o, w) {
777
- a(this, E).append(o, w), a(this, A) || super.setRequestHeader(o, w);
782
+ setRequestHeader(t, w) {
783
+ a(this, E).append(t, w), a(this, A) || super.setRequestHeader(t, w);
778
784
  }
779
- send(o) {
780
- H(this, s, o), l(this, P, N).call(this).then((w) => {
781
- w || super.send(o);
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(o);
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 o;
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"), o = new Request(a(this, Q), w);
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(o.clone());
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(o) {
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 o.json();
824
+ w = await t.json();
819
825
  else if (this.responseType === "arraybuffer")
820
- w = await o.arrayBuffer();
826
+ w = await t.arrayBuffer();
821
827
  else if (this.responseType === "blob")
822
- w = await o.blob();
828
+ w = await t.blob();
823
829
  else if (this.responseType === "document") {
824
- const M = await o.text();
830
+ const M = await t.text();
825
831
  w = new DOMParser().parseFromString(M, "text/xml");
826
832
  } else
827
- w = await o.text();
833
+ w = await t.text();
828
834
  Object.defineProperty(this, "status", {
829
- value: o.status,
835
+ value: t.status,
830
836
  writable: !1,
831
837
  configurable: !0
832
838
  }), Object.defineProperty(this, "statusText", {
833
- value: o.statusText,
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: o.url,
851
+ value: t.url,
846
852
  writable: !1,
847
853
  configurable: !0
848
854
  }), this.dispatchEvent(
@@ -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,C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AAE,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,2CAqJvB"}
@@ -1,52 +1,56 @@
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
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
+ newDocument: g,
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 r = W(!1), g = T.replace(/\/$/, "");
21
- X(() => {
22
- const c = (t) => {
23
- r.current && (t.preventDefault(), t.returnValue = "");
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
- }, []), 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);
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);
30
33
  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"));
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 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);
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 b = p.createElement("script");
48
- b.src = new URL(c, location.origin).href, p.body.appendChild(b), l == null || l();
49
- }, k = () => {
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 = () => {
50
54
  s = new window.DocsAPI.DocEditor("placeholder", {
51
55
  isLocalFile: !0,
52
56
  document: {
@@ -63,27 +67,31 @@ function _({
63
67
  print: !1
64
68
  }
65
69
  },
66
- documentType: U,
70
+ documentType: M,
67
71
  editorConfig: {
68
- lang: R,
72
+ lang: P,
69
73
  coEditing: { mode: "fast", change: !1 },
70
- user: { ...y },
74
+ user: { ...E },
71
75
  customization: {
72
- uiTheme: q,
76
+ uiTheme: W,
73
77
  features: { spellcheck: { change: !1 } }
74
78
  }
75
79
  },
76
80
  events: {
77
- onAppReady: () => H(),
81
+ onAppReady: () => O(),
78
82
  onDocumentStateChange: (e) => {
79
- e.data && (r.current = !0), a == null || a(e.data);
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) => n == null ? void 0 : n(new Error(String(e))),
82
90
  onSaveDocument: () => {
83
- r.current = !1;
91
+ l.current = !1;
84
92
  },
85
93
  writeFile: () => {
86
- r.current = !1;
94
+ l.current = !1;
87
95
  }
88
96
  },
89
97
  width: "100%",
@@ -91,27 +99,30 @@ function _({
91
99
  });
92
100
  };
93
101
  return (() => {
94
- var o;
95
- if ((o = window.DocsAPI) != null && o.DocEditor) {
96
- k();
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 = () => k(), e.onerror = () => n == null ? void 0 : n(new Error("Failed to load DocsAPI script"));
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
- d.off("connect", v), d.off("disconnect", D), (e = s == null ? void 0 : s.destroyEditor) == null || e.call(s), t.destroy();
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 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(
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: S
122
+ src: F
112
123
  }
113
124
  ) }) });
114
125
  }
115
126
  export {
116
- _ as OnlyOfficeEditor
127
+ Z as OnlyOfficeEditor
117
128
  };
@@ -2,7 +2,7 @@ var L = (g) => {
2
2
  throw TypeError(g);
3
3
  };
4
4
  var k = (g, B, A) => B.has(g) || L("Cannot " + A);
5
- var U = (g, B, A) => (k(g, B, "read from private field"), A ? A.call(g) : B.get(g)), H = (g, B, A) => B.has(g) ? L("Cannot add the same private member more than once") : B instanceof WeakSet ? B.add(g) : B.set(g, A), h = (g, B, A, Q) => (k(g, B, "write to private field"), Q ? Q.call(g, A) : B.set(g, A), A), f = (g, B, A) => (k(g, B, "access private method"), A);
5
+ var H = (g, B, A) => (k(g, B, "read from private field"), A ? A.call(g) : B.get(g)), h = (g, B, A) => B.has(g) ? L("Cannot add the same private member more than once") : B instanceof WeakSet ? B.add(g) : B.set(g, A), l = (g, B, A, Q) => (k(g, B, "write to private field"), Q ? Q.call(g, A) : B.set(g, A), A), f = (g, B, A) => (k(g, B, "access private method"), A);
6
6
  import { defineComponent as j, ref as q, computed as X, onMounted as _, onUnmounted as $, openBlock as AA, createElementBlock as BA, mergeProps as QA, createElementVNode as N } from "vue";
7
7
  class gA {
8
8
  constructor(B = "/x2t-1") {
@@ -210,11 +210,11 @@ function T(g, B) {
210
210
  return URL.createObjectURL(A);
211
211
  }
212
212
  class oA {
213
- constructor({ x2tPath: B = "/x2t-1", user: A } = {}) {
213
+ constructor({ x2tPath: B = "/x2t-1", user: A, onSave: Q } = {}) {
214
214
  this.id = "", this.socket = null, this.sessionId = "session-id", this.user = {
215
215
  id: "uid",
216
216
  name: "Me"
217
- }, 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 gA(B), A && (this.user = A), this.send = this.send.bind(this), this.handleConnect = this.handleConnect.bind(this), this.handleMessage = this.handleMessage.bind(this);
217
+ }, 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 gA(B), A && (this.user = A), Q && (this.onSave = Q), this.send = this.send.bind(this), this.handleConnect = this.handleConnect.bind(this), this.handleMessage = this.handleMessage.bind(this);
218
218
  }
219
219
  async open(B, { fileType: A, fileName: Q } = {}) {
220
220
  const E = Q || B.name;
@@ -451,19 +451,25 @@ class oA {
451
451
  !r && C.endsWith(".pdf") && (r = 513);
452
452
  const s = async () => {
453
453
  const P = tA(this.downloadParts);
454
- let o = "from.bin";
455
- w.format == "pdf" && (o = "from.pdf");
454
+ let t = "from.bin";
455
+ w.format == "pdf" && (t = "from.pdf");
456
456
  let { output: D } = await this.converter.convert({
457
457
  data: P.buffer,
458
- fileFrom: o,
458
+ fileFrom: t,
459
459
  fileTo: C,
460
460
  formatTo: r,
461
461
  media: Object.fromEntries(this.fsMap)
462
462
  });
463
463
  if (!D && w.format == "pdf" && (D = P), !D)
464
464
  return console.error("Conversion failed"), { status: "error" };
465
- const n = new Blob([new Uint8Array(D)]), i = URL.createObjectURL(n), t = document.createElement("a");
466
- return t.href = i, t.download = w.title || "test.docx", t.click(), URL.revokeObjectURL(i), { status: "ok" };
465
+ const M = new Blob([new Uint8Array(D)]), c = w.title || "document.docx";
466
+ if (this.onSave)
467
+ this.onSave(M, c);
468
+ else {
469
+ const o = URL.createObjectURL(M), i = document.createElement("a");
470
+ i.href = o, i.download = c, i.click(), URL.revokeObjectURL(o);
471
+ }
472
+ return { status: "ok" };
467
473
  };
468
474
  let e = {
469
475
  status: "ok"
@@ -522,11 +528,11 @@ function PA() {
522
528
  function E(r, s, e) {
523
529
  this.fn = r, this.context = s, this.once = e || !1;
524
530
  }
525
- function w(r, s, e, P, o) {
531
+ function w(r, s, e, P, t) {
526
532
  if (typeof e != "function")
527
533
  throw new TypeError("The listener must be a function");
528
- var D = new E(e, P || r, o), n = A ? A + s : s;
529
- return r._events[n] ? r._events[n].fn ? r._events[n] = [r._events[n], D] : r._events[n].push(D) : (r._events[n] = D, r._eventsCount++), r;
534
+ var D = new E(e, P || r, t), M = A ? A + s : s;
535
+ return r._events[M] ? r._events[M].fn ? r._events[M] = [r._events[M], D] : r._events[M].push(D) : (r._events[M] = D, r._eventsCount++), r;
530
536
  }
531
537
  function G(r, s) {
532
538
  --r._eventsCount === 0 ? r._events = new Q() : delete r._events[s];
@@ -544,54 +550,54 @@ function PA() {
544
550
  var e = A ? A + s : s, P = this._events[e];
545
551
  if (!P) return [];
546
552
  if (P.fn) return [P.fn];
547
- for (var o = 0, D = P.length, n = new Array(D); o < D; o++)
548
- n[o] = P[o].fn;
549
- return n;
553
+ for (var t = 0, D = P.length, M = new Array(D); t < D; t++)
554
+ M[t] = P[t].fn;
555
+ return M;
550
556
  }, C.prototype.listenerCount = function(s) {
551
557
  var e = A ? A + s : s, P = this._events[e];
552
558
  return P ? P.fn ? 1 : P.length : 0;
553
- }, C.prototype.emit = function(s, e, P, o, D, n) {
554
- var i = A ? A + s : s;
555
- if (!this._events[i]) return !1;
556
- var t = this._events[i], c = arguments.length, a, M;
557
- if (t.fn) {
558
- switch (t.once && this.removeListener(s, t.fn, void 0, !0), c) {
559
+ }, C.prototype.emit = function(s, e, P, t, D, M) {
560
+ var c = A ? A + s : s;
561
+ if (!this._events[c]) return !1;
562
+ var o = this._events[c], i = arguments.length, a, n;
563
+ if (o.fn) {
564
+ switch (o.once && this.removeListener(s, o.fn, void 0, !0), i) {
559
565
  case 1:
560
- return t.fn.call(t.context), !0;
566
+ return o.fn.call(o.context), !0;
561
567
  case 2:
562
- return t.fn.call(t.context, e), !0;
568
+ return o.fn.call(o.context, e), !0;
563
569
  case 3:
564
- return t.fn.call(t.context, e, P), !0;
570
+ return o.fn.call(o.context, e, P), !0;
565
571
  case 4:
566
- return t.fn.call(t.context, e, P, o), !0;
572
+ return o.fn.call(o.context, e, P, t), !0;
567
573
  case 5:
568
- return t.fn.call(t.context, e, P, o, D), !0;
574
+ return o.fn.call(o.context, e, P, t, D), !0;
569
575
  case 6:
570
- return t.fn.call(t.context, e, P, o, D, n), !0;
576
+ return o.fn.call(o.context, e, P, t, D, M), !0;
571
577
  }
572
- for (M = 1, a = new Array(c - 1); M < c; M++)
573
- a[M - 1] = arguments[M];
574
- t.fn.apply(t.context, a);
578
+ for (n = 1, a = new Array(i - 1); n < i; n++)
579
+ a[n - 1] = arguments[n];
580
+ o.fn.apply(o.context, a);
575
581
  } else {
576
- var Y = t.length, I;
577
- for (M = 0; M < Y; M++)
578
- switch (t[M].once && this.removeListener(s, t[M].fn, void 0, !0), c) {
582
+ var U = o.length, I;
583
+ for (n = 0; n < U; n++)
584
+ switch (o[n].once && this.removeListener(s, o[n].fn, void 0, !0), i) {
579
585
  case 1:
580
- t[M].fn.call(t[M].context);
586
+ o[n].fn.call(o[n].context);
581
587
  break;
582
588
  case 2:
583
- t[M].fn.call(t[M].context, e);
589
+ o[n].fn.call(o[n].context, e);
584
590
  break;
585
591
  case 3:
586
- t[M].fn.call(t[M].context, e, P);
592
+ o[n].fn.call(o[n].context, e, P);
587
593
  break;
588
594
  case 4:
589
- t[M].fn.call(t[M].context, e, P, o);
595
+ o[n].fn.call(o[n].context, e, P, t);
590
596
  break;
591
597
  default:
592
- if (!a) for (I = 1, a = new Array(c - 1); I < c; I++)
598
+ if (!a) for (I = 1, a = new Array(i - 1); I < i; I++)
593
599
  a[I - 1] = arguments[I];
594
- t[M].fn.apply(t[M].context, a);
600
+ o[n].fn.apply(o[n].context, a);
595
601
  }
596
602
  }
597
603
  return !0;
@@ -599,18 +605,18 @@ function PA() {
599
605
  return w(this, s, e, P, !1);
600
606
  }, C.prototype.once = function(s, e, P) {
601
607
  return w(this, s, e, P, !0);
602
- }, C.prototype.removeListener = function(s, e, P, o) {
608
+ }, C.prototype.removeListener = function(s, e, P, t) {
603
609
  var D = A ? A + s : s;
604
610
  if (!this._events[D]) return this;
605
611
  if (!e)
606
612
  return G(this, D), this;
607
- var n = this._events[D];
608
- if (n.fn)
609
- n.fn === e && (!o || n.once) && (!P || n.context === P) && G(this, D);
613
+ var M = this._events[D];
614
+ if (M.fn)
615
+ M.fn === e && (!t || M.once) && (!P || M.context === P) && G(this, D);
610
616
  else {
611
- for (var i = 0, t = [], c = n.length; i < c; i++)
612
- (n[i].fn !== e || o && !n[i].once || P && n[i].context !== P) && t.push(n[i]);
613
- t.length ? this._events[D] = t.length === 1 ? t[0] : t : G(this, D);
617
+ for (var c = 0, o = [], i = M.length; c < i; c++)
618
+ (M[c].fn !== e || t && !M[c].once || P && M[c].context !== P) && o.push(M[c]);
619
+ o.length ? this._events[D] = o.length === 1 ? o[0] : o : G(this, D);
614
620
  }
615
621
  return this;
616
622
  }, C.prototype.removeAllListeners = function(s) {
@@ -620,7 +626,7 @@ function PA() {
620
626
  })(v)), v.exports;
621
627
  }
622
628
  var CA = PA();
623
- const y = /* @__PURE__ */ GA(CA), l = class l {
629
+ const y = /* @__PURE__ */ GA(CA), d = class d {
624
630
  constructor(B = {}) {
625
631
  this.active = !0, this.connected = !1, this.disconnected = !0, this.recovered = !1, this.id = "", this.io = {
626
632
  setOpenToken: () => {
@@ -658,10 +664,10 @@ const y = /* @__PURE__ */ GA(CA), l = class l {
658
664
  }, this._debug = B.debug ?? !1, this.connect();
659
665
  }
660
666
  static on(B, A) {
661
- l._staticEmitter.on(B, A);
667
+ d._staticEmitter.on(B, A);
662
668
  }
663
669
  static off(B, A) {
664
- l._staticEmitter.off(B, A);
670
+ d._staticEmitter.off(B, A);
665
671
  }
666
672
  _log(...B) {
667
673
  this._debug && console.log("[MockSocket]", ...B);
@@ -676,11 +682,11 @@ const y = /* @__PURE__ */ GA(CA), l = class l {
676
682
  */
677
683
  connect() {
678
684
  return this.connected = !0, this.disconnected = !1, this.id = Math.random().toString(36).substring(2, 15), setTimeout(() => {
679
- this._trigger("connect"), l._staticEmitter.emit("connect", { socket: this });
685
+ this._trigger("connect"), d._staticEmitter.emit("connect", { socket: this });
680
686
  }, 0), this;
681
687
  }
682
688
  disconnect() {
683
- return this.connected = !1, this.disconnected = !0, this._trigger("disconnect"), l._staticEmitter.emit("disconnect", { socket: this }), this;
689
+ return this.connected = !1, this.disconnected = !0, this._trigger("disconnect"), d._staticEmitter.emit("disconnect", { socket: this }), this;
684
690
  }
685
691
  close() {
686
692
  return this.disconnect();
@@ -736,28 +742,28 @@ const y = /* @__PURE__ */ GA(CA), l = class l {
736
742
  return setTimeout(() => Q(), 0), this;
737
743
  }
738
744
  };
739
- l._staticEmitter = new y();
740
- let d = l;
745
+ d._staticEmitter = new y();
746
+ let Y = d;
741
747
  function rA(g, B) {
742
- return new d(B);
748
+ return new Y(B);
743
749
  }
744
750
  function nA(g = globalThis.XMLHttpRequest) {
745
751
  var B, A, Q, E, w, G, x, J, s;
746
752
  return s = class extends g {
747
753
  constructor() {
748
754
  super(...arguments);
749
- H(this, G);
750
- H(this, B, !1);
751
- H(this, A, "GET");
752
- H(this, Q, "");
753
- H(this, E, new Headers());
754
- H(this, w, null);
755
+ h(this, G);
756
+ h(this, B, !1);
757
+ h(this, A, "GET");
758
+ h(this, Q, "");
759
+ h(this, E, new Headers());
760
+ h(this, w, null);
755
761
  }
756
762
  /**
757
763
  * Register global middleware
758
764
  */
759
- static use(o) {
760
- this._middlewares.push(o);
765
+ static use(t) {
766
+ this._middlewares.push(t);
761
767
  }
762
768
  /**
763
769
  * Clear all middleware
@@ -765,45 +771,45 @@ function nA(g = globalThis.XMLHttpRequest) {
765
771
  static clearMiddlewares() {
766
772
  this._middlewares = [];
767
773
  }
768
- open(o, D, n = !0, i, t) {
769
- h(this, A, o), h(this, Q, D.toString()), h(this, E, new Headers()), h(this, B, !1), super.open(
770
- o,
774
+ open(t, D, M = !0, c, o) {
775
+ l(this, A, t), l(this, Q, D.toString()), l(this, E, new Headers()), l(this, B, !1), super.open(
776
+ t,
771
777
  D,
772
- n,
773
- i ?? void 0,
774
- t ?? void 0
778
+ M,
779
+ c ?? void 0,
780
+ o ?? void 0
775
781
  );
776
782
  }
777
- setRequestHeader(o, D) {
778
- U(this, E).append(o, D), U(this, B) || super.setRequestHeader(o, D);
783
+ setRequestHeader(t, D) {
784
+ H(this, E).append(t, D), H(this, B) || super.setRequestHeader(t, D);
779
785
  }
780
- send(o) {
781
- h(this, w, o), f(this, G, x).call(this).then((D) => {
782
- D || super.send(o);
786
+ send(t) {
787
+ l(this, w, t), f(this, G, x).call(this).then((D) => {
788
+ D || super.send(t);
783
789
  }).catch((D) => {
784
- console.error("ProxyXMLHttpRequest middleware error:", D), super.send(o);
790
+ console.error("ProxyXMLHttpRequest middleware error:", D), super.send(t);
785
791
  });
786
792
  }
787
793
  }, B = new WeakMap(), A = new WeakMap(), Q = new WeakMap(), E = new WeakMap(), w = new WeakMap(), G = new WeakSet(), x = async function() {
788
- let o;
794
+ let t;
789
795
  try {
790
796
  const D = {
791
- method: U(this, A),
792
- headers: U(this, E),
793
- body: U(this, w),
797
+ method: H(this, A),
798
+ headers: H(this, E),
799
+ body: H(this, w),
794
800
  mode: "cors"
795
801
  };
796
- this.withCredentials && (D.credentials = "include"), o = new Request(U(this, Q), D);
802
+ this.withCredentials && (D.credentials = "include"), t = new Request(H(this, Q), D);
797
803
  } catch {
798
804
  return !1;
799
805
  }
800
806
  for (const D of s._middlewares) {
801
- const n = await D(o.clone());
802
- if (n)
803
- return h(this, B, !0), await f(this, G, J).call(this, n), !0;
807
+ const M = await D(t.clone());
808
+ if (M)
809
+ return l(this, B, !0), await f(this, G, J).call(this, M), !0;
804
810
  }
805
811
  return !1;
806
- }, J = async function(o) {
812
+ }, J = async function(t) {
807
813
  this.dispatchEvent(new ProgressEvent("loadstart")), Object.defineProperty(this, "readyState", {
808
814
  value: 2,
809
815
  writable: !1,
@@ -816,22 +822,22 @@ function nA(g = globalThis.XMLHttpRequest) {
816
822
  try {
817
823
  let D;
818
824
  if (this.responseType === "json")
819
- D = await o.json();
825
+ D = await t.json();
820
826
  else if (this.responseType === "arraybuffer")
821
- D = await o.arrayBuffer();
827
+ D = await t.arrayBuffer();
822
828
  else if (this.responseType === "blob")
823
- D = await o.blob();
829
+ D = await t.blob();
824
830
  else if (this.responseType === "document") {
825
- const n = await o.text();
826
- D = new DOMParser().parseFromString(n, "text/xml");
831
+ const M = await t.text();
832
+ D = new DOMParser().parseFromString(M, "text/xml");
827
833
  } else
828
- D = await o.text();
834
+ D = await t.text();
829
835
  Object.defineProperty(this, "status", {
830
- value: o.status,
836
+ value: t.status,
831
837
  writable: !1,
832
838
  configurable: !0
833
839
  }), Object.defineProperty(this, "statusText", {
834
- value: o.statusText,
840
+ value: t.statusText,
835
841
  writable: !1,
836
842
  configurable: !0
837
843
  }), Object.defineProperty(this, "response", {
@@ -843,7 +849,7 @@ function nA(g = globalThis.XMLHttpRequest) {
843
849
  writable: !1,
844
850
  configurable: !0
845
851
  }), Object.defineProperty(this, "responseURL", {
846
- value: o.url,
852
+ value: t.url,
847
853
  writable: !1,
848
854
  configurable: !0
849
855
  }), this.dispatchEvent(
@@ -889,18 +895,18 @@ const MA = {
889
895
  const C = ({ socket: e }) => w == null ? void 0 : w.handleConnect({ socket: e }), r = ({ socket: e }) => w == null ? void 0 : w.handleDisconnect({ socket: e }), s = X(() => A.assetsPath.replace(/\/$/, "") + "/web-apps/apps/api/documents/preload.html");
890
896
  return _(() => {
891
897
  var a;
892
- const P = A.assetsPath.replace(/\/$/, "") + "/web-apps/apps/api/documents/api.js", o = A.user ?? { id: "uid", name: "User" };
893
- w = new oA({ x2tPath: A.x2tPath, user: o }), A.file ? w.open(A.file) : A.fileUrl ? w.openUrl(A.fileUrl) : A.newDocument ? w.openNew(A.newDocument) : w.openNew("docx");
894
- const D = w.getDocument(), n = u(D.fileType);
895
- d.on("connect", C), d.on("disconnect", r);
896
- const i = () => {
897
- const M = document.querySelector('iframe[name="frameEditor"]'), Y = M == null ? void 0 : M.contentWindow, I = M == null ? void 0 : M.contentDocument;
898
- if (!I || !Y) {
898
+ const P = A.assetsPath.replace(/\/$/, "") + "/web-apps/apps/api/documents/api.js", t = A.user ?? { id: "uid", name: "User" };
899
+ w = new oA({ x2tPath: A.x2tPath, user: t, onSave: (n, U) => Q("save", n, U) }), A.file ? w.open(A.file) : A.fileUrl ? w.openUrl(A.fileUrl) : A.newDocument ? w.openNew(A.newDocument) : w.openNew("docx");
900
+ const D = w.getDocument(), M = u(D.fileType);
901
+ Y.on("connect", C), Y.on("disconnect", r);
902
+ const c = () => {
903
+ const n = document.querySelector('iframe[name="frameEditor"]'), U = n == null ? void 0 : n.contentWindow, I = n == null ? void 0 : n.contentDocument;
904
+ if (!I || !U) {
899
905
  Q("error", new Error("Iframe not loaded"));
900
906
  return;
901
907
  }
902
- const R = nA(Y.XMLHttpRequest), S = Y.Worker;
903
- R.use((b) => w.handleRequest(b)), Object.assign(Y, {
908
+ const R = nA(U.XMLHttpRequest), S = U.Worker;
909
+ R.use((b) => w.handleRequest(b)), Object.assign(U, {
904
910
  io: rA,
905
911
  XMLHttpRequest: R,
906
912
  Worker: new Proxy(S, {
@@ -911,7 +917,7 @@ const MA = {
911
917
  });
912
918
  const Z = I.createElement("script");
913
919
  Z.src = new URL(P, location.origin).href, I.body.appendChild(Z), Q("ready");
914
- }, t = () => {
920
+ }, o = () => {
915
921
  G = new window.DocsAPI.DocEditor("placeholder", {
916
922
  isLocalFile: !0,
917
923
  document: {
@@ -921,19 +927,19 @@ const MA = {
921
927
  url: D.url,
922
928
  permissions: { edit: D.fileType !== "pdf", chat: !1, rename: !0, protect: !0, review: !1, print: !1 }
923
929
  },
924
- documentType: n,
930
+ documentType: M,
925
931
  editorConfig: {
926
932
  lang: A.language,
927
933
  coEditing: { mode: "fast", change: !1 },
928
- user: { ...o },
934
+ user: { ...t },
929
935
  customization: { uiTheme: A.theme, features: { spellcheck: { change: !1 } } }
930
936
  },
931
937
  events: {
932
- onAppReady: () => i(),
933
- onDocumentStateChange: (M) => {
934
- M.data && (E.value = !0), Q("documentStateChange", M.data);
938
+ onAppReady: () => c(),
939
+ onDocumentStateChange: (n) => {
940
+ n.data && (E.value = !0), Q("documentStateChange", n.data);
935
941
  },
936
- onError: (M) => Q("error", new Error(String(M))),
942
+ onError: (n) => Q("error", new Error(String(n))),
937
943
  onSaveDocument: () => {
938
944
  E.value = !1;
939
945
  },
@@ -946,14 +952,14 @@ const MA = {
946
952
  });
947
953
  };
948
954
  if ((a = window.DocsAPI) != null && a.DocEditor) {
949
- t();
955
+ o();
950
956
  return;
951
957
  }
952
- let c = document.querySelector(`script[src="${P}"]`);
953
- c || (c = document.createElement("script"), c.src = P, document.head.appendChild(c)), c.onload = () => t(), c.onerror = () => Q("error", new Error("Failed to load DocsAPI script"));
958
+ let i = document.querySelector(`script[src="${P}"]`);
959
+ i || (i = document.createElement("script"), i.src = P, document.head.appendChild(i)), i.onload = () => o(), i.onerror = () => Q("error", new Error("Failed to load DocsAPI script"));
954
960
  }), $(() => {
955
961
  var e;
956
- d.off("connect", C), d.off("disconnect", r), (e = G == null ? void 0 : G.destroyEditor) == null || e.call(G), w == null || w.destroy();
962
+ Y.off("connect", C), Y.off("disconnect", r), (e = G == null ? void 0 : G.destroyEditor) == null || e.call(G), w == null || w.destroy();
957
963
  }), (e, P) => (AA(), BA("div", QA(e.$attrs, { style: { width: "100%", height: "100%" } }), [
958
964
  N("div", MA, [
959
965
  N("iframe", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wasm-onlyoffice-sdk",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Offline OnlyOffice document editor SDK for React and Vue, powered by WebAssembly",
5
5
  "license": "AGPL-3.0-or-later",
6
6
  "homepage": "https://github.com/oonxt/wasm-onlyoffice-sdk#readme",