wasm-onlyoffice-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,26 @@
1
+ import { CSSProperties } from 'react';
2
+ import { OfficeTheme, User } from '../core/types';
3
+ export interface OnlyOfficeEditorProps {
4
+ /** URL prefix for OnlyOffice web-apps assets, e.g. "/v9.3.0.24-1" */
5
+ assetsPath: string;
6
+ /** URL prefix for x2t WASM files, e.g. "/x2t-1". Defaults to "/x2t-1" */
7
+ x2tPath?: string;
8
+ /** Open an existing File object */
9
+ file?: File;
10
+ /** Open a document from a remote URL */
11
+ fileUrl?: string;
12
+ /** Create a new blank document of the given type */
13
+ newDocument?: 'docx' | 'xlsx' | 'pptx' | 'pdf';
14
+ language?: string;
15
+ theme?: OfficeTheme;
16
+ user?: User;
17
+ onReady?: () => void;
18
+ onDocumentStateChange?: (isDirty: boolean) => void;
19
+ /** Called when the user triggers Save As / Download */
20
+ onSave?: (blob: Blob, filename: string) => void;
21
+ onError?: (error: Error) => void;
22
+ style?: CSSProperties;
23
+ className?: string;
24
+ }
25
+ export declare function OnlyOfficeEditor({ assetsPath, x2tPath, file, fileUrl, newDocument, language, theme, user, onReady, onDocumentStateChange, onSave, onError, style, className, }: OnlyOfficeEditorProps): import("react/jsx-runtime").JSX.Element;
26
+ //# sourceMappingURL=OnlyOfficeEditor.d.ts.map
@@ -0,0 +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,EACP,qBAAqB,EACrB,MAAM,EACN,OAAO,EACP,KAAK,EACL,SAAS,GACV,EAAE,qBAAqB,2CAwIvB"}
@@ -0,0 +1,3 @@
1
+ export { OnlyOfficeEditor } from './OnlyOfficeEditor';
2
+ export type { OnlyOfficeEditorProps } from './OnlyOfficeEditor';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA"}
@@ -0,0 +1,115 @@
1
+ import { jsx as f } from "react/jsx-runtime";
2
+ import { useRef as W, useEffect as X, useLayoutEffect as j } from "react";
3
+ import { EditorServer as M, getDocumentType as O, MockSocket as d, createXHRProxy as P, io as C } from "../index.mjs";
4
+ function _({
5
+ assetsPath: h,
6
+ x2tPath: L = "/x2t-1",
7
+ file: m,
8
+ fileUrl: w,
9
+ newDocument: y,
10
+ language: q = "en",
11
+ theme: x = "theme-light",
12
+ user: g = { id: "uid", name: "User" },
13
+ onReady: l,
14
+ onDocumentStateChange: a,
15
+ onSave: F,
16
+ onError: n,
17
+ style: A,
18
+ className: R
19
+ }) {
20
+ const r = W(!1);
21
+ return X(() => {
22
+ const c = (t) => {
23
+ r.current && (t.preventDefault(), t.returnValue = "");
24
+ };
25
+ return window.addEventListener("beforeunload", c), () => window.removeEventListener("beforeunload", c);
26
+ }, []), j(() => {
27
+ const c = h + "/web-apps/apps/api/documents/api.js", t = new M({ x2tPath: L, user: g });
28
+ m ? t.open(m) : w ? t.openUrl(w) : y ? t.openNew(y) : t.openNew("docx");
29
+ const i = t.getDocument(), H = O(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 I = () => {
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
+ return;
38
+ }
39
+ const T = P(o.XMLHttpRequest), S = o.Worker;
40
+ T.use((u) => t.handleRequest(u)), Object.assign(o, {
41
+ io: C,
42
+ XMLHttpRequest: T,
43
+ Worker: function(u, U) {
44
+ const E = new URL(u, location.origin);
45
+ return new S(E.href.replace(E.origin, location.origin), U);
46
+ }
47
+ });
48
+ const b = p.createElement("script");
49
+ b.src = c, p.body.appendChild(b), l == null || l();
50
+ }, k = () => {
51
+ s = new window.DocsAPI.DocEditor("placeholder", {
52
+ document: {
53
+ fileType: i.fileType,
54
+ key: i.key,
55
+ title: i.title,
56
+ url: i.url,
57
+ permissions: {
58
+ edit: i.fileType !== "pdf",
59
+ chat: !1,
60
+ rename: !0,
61
+ protect: !0,
62
+ review: !1,
63
+ print: !1
64
+ }
65
+ },
66
+ documentType: H,
67
+ editorConfig: {
68
+ lang: q,
69
+ coEditing: { mode: "fast", change: !1 },
70
+ user: { ...g },
71
+ customization: {
72
+ uiTheme: x,
73
+ features: { spellcheck: { change: !1 } }
74
+ }
75
+ },
76
+ events: {
77
+ onAppReady: () => I(),
78
+ onDocumentStateChange: (e) => {
79
+ e.data && (r.current = !0), a == null || a(e.data);
80
+ },
81
+ onError: (e) => n == null ? void 0 : n(new Error(String(e))),
82
+ onSaveDocument: () => {
83
+ r.current = !1;
84
+ },
85
+ writeFile: () => {
86
+ r.current = !1;
87
+ }
88
+ },
89
+ width: "100%",
90
+ height: "100%"
91
+ });
92
+ };
93
+ return (() => {
94
+ var o;
95
+ if ((o = window.DocsAPI) != null && o.DocEditor) {
96
+ k();
97
+ return;
98
+ }
99
+ 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"));
101
+ })(), () => {
102
+ var e;
103
+ d.off("connect", v), d.off("disconnect", D), (e = s == null ? void 0 : s.destroyEditor) == null || e.call(s), t.destroy();
104
+ };
105
+ }, []), /* @__PURE__ */ f("div", { style: { width: "100%", height: "100%", ...A }, className: R, children: /* @__PURE__ */ f("div", { id: "placeholder", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ f(
106
+ "iframe",
107
+ {
108
+ style: { width: 0, height: 0, display: "none" },
109
+ src: h + "/web-apps/apps/api/documents/preload.html"
110
+ }
111
+ ) }) });
112
+ }
113
+ export {
114
+ _ as OnlyOfficeEditor
115
+ };
@@ -0,0 +1,29 @@
1
+ import { OfficeTheme, User } from '../core/types';
2
+ interface Props {
3
+ assetsPath: string;
4
+ x2tPath?: string;
5
+ file?: File;
6
+ fileUrl?: string;
7
+ newDocument?: 'docx' | 'xlsx' | 'pptx' | 'pdf';
8
+ language?: string;
9
+ theme?: OfficeTheme;
10
+ user?: User;
11
+ }
12
+ declare const _default: import('vue').DefineComponent<Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
13
+ ready: () => any;
14
+ error: (error: Error) => any;
15
+ save: (blob: Blob, filename: string) => any;
16
+ documentStateChange: (isDirty: boolean) => any;
17
+ }, string, import('vue').PublicProps, Readonly<Props> & Readonly<{
18
+ onReady?: (() => any) | undefined;
19
+ onError?: ((error: Error) => any) | undefined;
20
+ onSave?: ((blob: Blob, filename: string) => any) | undefined;
21
+ onDocumentStateChange?: ((isDirty: boolean) => any) | undefined;
22
+ }>, {
23
+ x2tPath: string;
24
+ user: User;
25
+ language: string;
26
+ theme: OfficeTheme;
27
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
28
+ export default _default;
29
+ //# sourceMappingURL=OnlyOfficeEditor.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OnlyOfficeEditor.vue.d.ts","sourceRoot":"","sources":["../../src/vue/OnlyOfficeEditor.vue"],"names":[],"mappings":"AAiKA,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;;AAmLrB,wBAQG"}
@@ -0,0 +1,2 @@
1
+ export { default as OnlyOfficeEditor } from './OnlyOfficeEditor.vue';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vue/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,wBAAwB,CAAA"}