@p10node/office-engine 0.3.0 → 0.4.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.
- package/README.md +1 -0
- package/dist/{DocViewer-xjB59Aqn.js → DocViewer-BEaMBKhh.js} +1848 -1840
- package/dist/DocViewer-BEaMBKhh.js.map +1 -0
- package/dist/embed.js +15 -8
- package/dist/embed.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/office-engine.embed.js +33 -33
- package/dist/types/embed.d.ts +2 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/react/DocViewer.d.ts +6 -0
- package/dist/types/react/common/hooks.d.ts +4 -0
- package/package.json +1 -1
- package/dist/DocViewer-xjB59Aqn.js.map +0 -1
package/dist/embed.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
|
|
2
2
|
import "./default-worker-BDj6MNRA.js";
|
|
3
|
-
import { t as e } from "./DocViewer-
|
|
3
|
+
import { t as e } from "./DocViewer-BEaMBKhh.js";
|
|
4
4
|
import { createElement as t } from "react";
|
|
5
5
|
import { createRoot as n } from "react-dom/client";
|
|
6
6
|
// src/embed.ts
|
|
7
|
-
|
|
7
|
+
var r = [
|
|
8
|
+
"light",
|
|
9
|
+
"dark",
|
|
10
|
+
"auto"
|
|
11
|
+
];
|
|
12
|
+
function i(r, i) {
|
|
8
13
|
let a = n(r), o = i, s = r.getRootNode() instanceof ShadowRoot ? r.getRootNode() : void 0, c = () => a?.render(t(e, {
|
|
9
14
|
...o,
|
|
10
15
|
styleTarget: s
|
|
@@ -21,7 +26,7 @@ function r(r, i) {
|
|
|
21
26
|
}
|
|
22
27
|
};
|
|
23
28
|
}
|
|
24
|
-
var
|
|
29
|
+
var a = class extends HTMLElement {
|
|
25
30
|
static observedAttributes = [
|
|
26
31
|
"src",
|
|
27
32
|
"name",
|
|
@@ -33,6 +38,7 @@ var i = class extends HTMLElement {
|
|
|
33
38
|
"file-menu",
|
|
34
39
|
"open",
|
|
35
40
|
"capture-select-all",
|
|
41
|
+
"theme",
|
|
36
42
|
"collab",
|
|
37
43
|
"room",
|
|
38
44
|
"user",
|
|
@@ -49,7 +55,7 @@ var i = class extends HTMLElement {
|
|
|
49
55
|
connectedCallback() {
|
|
50
56
|
if (this.viewer) return;
|
|
51
57
|
let e = this.shadowRoot ?? this.attachShadow({ mode: "open" }), t = document.createElement("div");
|
|
52
|
-
t.style.cssText = "width:100%;height:100%", e.innerHTML = "<style>:host{display:block;height:480px;position:relative}</style>", e.appendChild(t), this.viewer =
|
|
58
|
+
t.style.cssText = "width:100%;height:100%", e.innerHTML = "<style>:host{display:block;height:480px;position:relative}</style>", e.appendChild(t), this.viewer = i(t, this.props());
|
|
53
59
|
}
|
|
54
60
|
disconnectedCallback() {
|
|
55
61
|
this.viewer?.destroy(), this.viewer = void 0, this.shadowRoot && (this.shadowRoot.innerHTML = "");
|
|
@@ -69,6 +75,7 @@ var i = class extends HTMLElement {
|
|
|
69
75
|
fileMenu: this.getAttribute("file-menu") !== "false",
|
|
70
76
|
allowOpen: this.getAttribute("open") !== "false",
|
|
71
77
|
captureSelectAll: this.getAttribute("capture-select-all") !== "false",
|
|
78
|
+
theme: r.find((e) => e === this.getAttribute("theme")),
|
|
72
79
|
collab: this.getAttribute("collab") && this.getAttribute("room") ? {
|
|
73
80
|
transport: this.getAttribute("collab"),
|
|
74
81
|
room: this.getAttribute("room"),
|
|
@@ -86,10 +93,10 @@ var i = class extends HTMLElement {
|
|
|
86
93
|
this.viewer?.update(this.props());
|
|
87
94
|
}
|
|
88
95
|
};
|
|
89
|
-
function
|
|
90
|
-
typeof customElements < "u" && !customElements.get(e) && customElements.define(e,
|
|
96
|
+
function o(e = "office-viewer") {
|
|
97
|
+
typeof customElements < "u" && !customElements.get(e) && customElements.define(e, a);
|
|
91
98
|
}
|
|
92
|
-
|
|
93
|
-
export { e as DocViewer,
|
|
99
|
+
o();
|
|
100
|
+
export { e as DocViewer, a as OfficeViewerElement, o as defineElement, i as mount };
|
|
94
101
|
|
|
95
102
|
//# sourceMappingURL=embed.js.map
|
package/dist/embed.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embed.js","names":["DocViewer","mount","root","createRoot","el","props","options","shadow","render","createElement","next","OfficeViewerElement","v","host","client","error","defineElement","tag"],"sources":["../src/embed.ts"],"sourcesContent":["import { createElement } from 'react'\nimport { createRoot, type Root } from 'react-dom/client'\nimport './core/default-worker'\nimport { DocViewer, type DocViewerProps } from './react/DocViewer'\n\nexport type MountOptions = Omit<DocViewerProps, 'styleTarget'>\n\nexport interface MountedViewer {\n update(next: Partial<MountOptions>): void\n destroy(): void\n}\n\n/** Framework-free embedding: renders the viewer into `el`. */\nexport function mount(el: HTMLElement, options: MountOptions): MountedViewer {\n let root: Root | null = createRoot(el)\n let props = options\n const shadow = el.getRootNode() instanceof ShadowRoot ? (el.getRootNode() as ShadowRoot) : undefined\n const render = () => root?.render(createElement(DocViewer, { ...props, styleTarget: shadow }))\n render()\n return {\n update(next) {\n props = { ...props, ...next }\n render()\n },\n destroy() {\n root?.unmount()\n root = null\n },\n }\n}\n\n/**\n * `<office-viewer src=\"/file.xlsx\" style=\"height:600px\"></office-viewer>`\n * Rendered inside a shadow root so host page CSS cannot leak in.\n * Attributes: src, name, editable, toolbar / thumbnails / save / download / file-menu / open / capture-select-all (\"false\" to turn off);\n * real-time collaboration: collab (hub WebSocket URL), room, user (display name), base (snapshot seq `src` was opened at).\n * Property: `file` (File/Blob/ArrayBuffer) for local data.\n */\nexport class OfficeViewerElement extends HTMLElement {\n static observedAttributes = ['src', 'name', 'toolbar', 'thumbnails', 'editable', 'save', 'download', 'file-menu', 'open', 'capture-select-all', 'collab', 'room', 'user', 'base']\n private viewer?: MountedViewer\n private _file?: Blob | ArrayBuffer\n\n get file() {\n return this._file\n }\n set file(v: Blob | ArrayBuffer | undefined) {\n this._file = v\n this.sync()\n }\n\n connectedCallback() {\n if (this.viewer) return\n const shadow = this.shadowRoot ?? this.attachShadow({ mode: 'open' })\n const host = document.createElement('div')\n host.style.cssText = 'width:100%;height:100%'\n shadow.innerHTML = '<style>:host{display:block;height:480px;position:relative}</style>'\n shadow.appendChild(host)\n this.viewer = mount(host, this.props())\n }\n\n disconnectedCallback() {\n this.viewer?.destroy()\n this.viewer = undefined\n if (this.shadowRoot) this.shadowRoot.innerHTML = ''\n }\n\n attributeChangedCallback() {\n this.sync()\n }\n\n private props(): MountOptions {\n return {\n src: this._file ?? this.getAttribute('src'),\n name: this.getAttribute('name') ?? undefined,\n toolbar: this.getAttribute('toolbar') !== 'false',\n thumbnails: this.getAttribute('thumbnails') !== 'false',\n editable: this.hasAttribute('editable') && this.getAttribute('editable') !== 'false',\n allowSave: this.getAttribute('save') !== 'false',\n allowDownload: this.getAttribute('download') !== 'false',\n fileMenu: this.getAttribute('file-menu') !== 'false',\n allowOpen: this.getAttribute('open') !== 'false',\n captureSelectAll: this.getAttribute('capture-select-all') !== 'false',\n collab:\n this.getAttribute('collab') && this.getAttribute('room')\n ? {\n transport: this.getAttribute('collab')!,\n room: this.getAttribute('room')!,\n base: Number(this.getAttribute('base')) || 0,\n user: { name: this.getAttribute('user') || 'Guest' },\n }\n : undefined,\n onLoad: (client) => this.dispatchEvent(new CustomEvent('load', { detail: { kind: client.kind, name: client.name } })),\n onError: (error) => this.dispatchEvent(new CustomEvent('error', { detail: error })),\n }\n }\n\n private sync() {\n this.viewer?.update(this.props())\n }\n}\n\nexport function defineElement(tag = 'office-viewer') {\n if (typeof customElements !== 'undefined' && !customElements.get(tag)) customElements.define(tag, OfficeViewerElement)\n}\n\ndefineElement()\n\nexport { DocViewer }\n"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"embed.js","names":["DocViewer","THEMES","mount","root","createRoot","el","props","options","shadow","render","createElement","next","OfficeViewerElement","v","host","t","client","error","defineElement","tag"],"sources":["../src/embed.ts"],"sourcesContent":["import { createElement } from 'react'\nimport { createRoot, type Root } from 'react-dom/client'\nimport './core/default-worker'\nimport { DocViewer, type DocViewerProps } from './react/DocViewer'\n\nexport type MountOptions = Omit<DocViewerProps, 'styleTarget'>\n\nconst THEMES = ['light', 'dark', 'auto'] as const\n\nexport interface MountedViewer {\n update(next: Partial<MountOptions>): void\n destroy(): void\n}\n\n/** Framework-free embedding: renders the viewer into `el`. */\nexport function mount(el: HTMLElement, options: MountOptions): MountedViewer {\n let root: Root | null = createRoot(el)\n let props = options\n const shadow = el.getRootNode() instanceof ShadowRoot ? (el.getRootNode() as ShadowRoot) : undefined\n const render = () => root?.render(createElement(DocViewer, { ...props, styleTarget: shadow }))\n render()\n return {\n update(next) {\n props = { ...props, ...next }\n render()\n },\n destroy() {\n root?.unmount()\n root = null\n },\n }\n}\n\n/**\n * `<office-viewer src=\"/file.xlsx\" style=\"height:600px\"></office-viewer>`\n * Rendered inside a shadow root so host page CSS cannot leak in.\n * Attributes: src, name, editable, toolbar / thumbnails / save / download / file-menu / open / capture-select-all (\"false\" to turn off),\n * theme (\"light\" | \"dark\" | \"auto\");\n * real-time collaboration: collab (hub WebSocket URL), room, user (display name), base (snapshot seq `src` was opened at).\n * Property: `file` (File/Blob/ArrayBuffer) for local data.\n */\nexport class OfficeViewerElement extends HTMLElement {\n static observedAttributes = ['src', 'name', 'toolbar', 'thumbnails', 'editable', 'save', 'download', 'file-menu', 'open', 'capture-select-all', 'theme', 'collab', 'room', 'user', 'base']\n private viewer?: MountedViewer\n private _file?: Blob | ArrayBuffer\n\n get file() {\n return this._file\n }\n set file(v: Blob | ArrayBuffer | undefined) {\n this._file = v\n this.sync()\n }\n\n connectedCallback() {\n if (this.viewer) return\n const shadow = this.shadowRoot ?? this.attachShadow({ mode: 'open' })\n const host = document.createElement('div')\n host.style.cssText = 'width:100%;height:100%'\n shadow.innerHTML = '<style>:host{display:block;height:480px;position:relative}</style>'\n shadow.appendChild(host)\n this.viewer = mount(host, this.props())\n }\n\n disconnectedCallback() {\n this.viewer?.destroy()\n this.viewer = undefined\n if (this.shadowRoot) this.shadowRoot.innerHTML = ''\n }\n\n attributeChangedCallback() {\n this.sync()\n }\n\n private props(): MountOptions {\n return {\n src: this._file ?? this.getAttribute('src'),\n name: this.getAttribute('name') ?? undefined,\n toolbar: this.getAttribute('toolbar') !== 'false',\n thumbnails: this.getAttribute('thumbnails') !== 'false',\n editable: this.hasAttribute('editable') && this.getAttribute('editable') !== 'false',\n allowSave: this.getAttribute('save') !== 'false',\n allowDownload: this.getAttribute('download') !== 'false',\n fileMenu: this.getAttribute('file-menu') !== 'false',\n allowOpen: this.getAttribute('open') !== 'false',\n captureSelectAll: this.getAttribute('capture-select-all') !== 'false',\n theme: THEMES.find((t) => t === this.getAttribute('theme')),\n collab:\n this.getAttribute('collab') && this.getAttribute('room')\n ? {\n transport: this.getAttribute('collab')!,\n room: this.getAttribute('room')!,\n base: Number(this.getAttribute('base')) || 0,\n user: { name: this.getAttribute('user') || 'Guest' },\n }\n : undefined,\n onLoad: (client) => this.dispatchEvent(new CustomEvent('load', { detail: { kind: client.kind, name: client.name } })),\n onError: (error) => this.dispatchEvent(new CustomEvent('error', { detail: error })),\n }\n }\n\n private sync() {\n this.viewer?.update(this.props())\n }\n}\n\nexport function defineElement(tag = 'office-viewer') {\n if (typeof customElements !== 'undefined' && !customElements.get(tag)) customElements.define(tag, OfficeViewerElement)\n}\n\ndefineElement()\n\nexport { DocViewer }\n"],"mappings":";;;;;;AAOA,IAAMC,IAAS;CAAC;CAAS;CAAQ;AAAM;AAQvC,SAAgBC,EAAM,GAAiB,GAAsC;CAC3E,IAAIC,IAAoBC,EAAWC,CAAE,GACjCC,IAAQC,GACNC,IAASH,EAAG,YAAY,aAAa,aAAcA,EAAG,YAAY,IAAmB,KAAA,GACrFI,UAAeN,GAAM,OAAOO,EAAcV,GAAW;EAAE,GAAGM;EAAO,aAAaE;CAAO,CAAC,CAAC;CAE7F,OADAC,EAAO,GACA;EACL,OAAO,GAAM;GAEX,AADA,IAAQ;IAAE,GAAGH;IAAO,GAAGK;GAAK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AAO,MAAM,MAAMc,MAAM,KAAK,aAAa,OAAO,CAAC;GAC1D,QACE,KAAK,aAAa,QAAQ,KAAK,KAAK,aAAa,MAAM,IACnD;IACE,WAAW,KAAK,aAAa,QAAQ;IACrC,MAAM,KAAK,aAAa,MAAM;IAC9B,MAAM,OAAO,KAAK,aAAa,MAAM,CAAC,KAAK;IAC3C,MAAM,EAAE,MAAM,KAAK,aAAa,MAAM,KAAK,QAAQ;GACrD,IACA,KAAA;GACN,SAAS,MAAW,KAAK,cAAc,IAAI,YAAY,QAAQ,EAAE,QAAQ;IAAE,MAAMC,EAAO;IAAM,MAAMA,EAAO;GAAK,EAAE,CAAC,CAAC;GACpH,UAAU,MAAU,KAAK,cAAc,IAAI,YAAY,SAAS,EAAE,QAAQC,EAAM,CAAC,CAAC;EACpF;CACF;CAEA,OAAe;EACb,KAAK,QAAQ,OAAO,KAAK,MAAM,CAAC;CAClC;AACF;AAEA,SAAgBC,EAAc,IAAM,iBAAiB;CACnD,AAAI,OAAO,iBAAmB,OAAe,CAAC,eAAe,IAAIC,CAAG,KAAG,eAAe,OAAOA,GAAKP,CAAmB;AACvH;AAEAM,EAAc"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
2
|
import { n as e, t } from "./default-worker-BDj6MNRA.js";
|
|
3
|
-
import { a as n, c as r, d as i, i as a, l as o, n as s, o as c, r as l, s as u, t as d, u as f } from "./DocViewer-
|
|
3
|
+
import { a as n, c as r, d as i, i as a, l as o, n as s, o as c, r as l, s as u, t as d, u as f } from "./DocViewer-BEaMBKhh.js";
|
|
4
4
|
import { a as p, o as m, s as h, t as g, u as _ } from "./collab-Dx00zqXR.js";
|
|
5
5
|
export { s as CollabBar, p as CollabHub, _ as CollabSession, d as DocViewer, t as DocumentClient, i as DocxView, m as MemoryTransport, l as PeerOverlay, u as PptxView, r as SlideView, h as WebSocketTransport, n as XlsxView, o as injectStyles, e as setDefaultWorker, g as startCollab, f as stylesText, a as useCollab, c as useDocument };
|