@chao194/office 1.0.4 → 1.0.5

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.
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("vue"),t=require("eventemitter3"),i=require("axios");function o(e){const t=e.toLowerCase();if(["doc","docx","odt","rtf","txt","html","epub"].includes(t))return"word";if(["xls","xlsx","ods","csv"].includes(t))return"cell";return["ppt","pptx","odp"].includes(t)?"slide":"pdf"===t?"pdf":"other"}class n{constructor(e=""){this.baseUrl=e}async post(e,t,o){const n=this.baseUrl?`${this.baseUrl}${e}`:e;return i.post(n,t,o)}async get(e,t){const o=this.baseUrl?`${this.baseUrl}${e}`:e;return i.get(o,t)}}async function r(e,t){var i;try{const o=new n(e);return!0===(null===(i=(await o.post("/onlyoffice/token/verifyTokenSign",t)).data)||void 0===i?void 0:i.data)}catch(e){return console.error("验签请求失败:",e),!1}}async function s(e,t){try{await i.post(e,t)}catch(e){console.error("保存操作信息失败:",e)}}var l=Object.freeze({__proto__:null,HttpClient:n,saveSuccessInfo:s,verifyTokenSign:r});const c={comment:!1,download:!1,edit:!1,print:!0,review:!1,editCommentAuthorOnly:!1,fillForms:!1,modifyContentControl:!1};class a{constructor(){this.editor=null,this.callback=null,this.height="100%",this.width="100%",this.editorId=`editor-${Date.now().toString(32)}`,this.emitter=new t,this.documentConfig={fileType:"docx",key:"",url:"",title:"",permissions:{...c}},this.editorConfig={lang:"zh",user:{id:"",name:""}}}configure(e){if(e.height&&(this.height=e.height),e.width&&(this.width=e.width),e.fileType){if("other"===o(e.fileType))throw new Error(`不支持的文件类型: ${e.fileType}`);"other"!==o(e.fileType)&&(this.documentConfig.fileType=e.fileType)}e.key&&(this.documentConfig.key=e.key),e.url&&(this.documentConfig.url=e.url),e.title&&(this.documentConfig.title=e.title),e.permissions&&(this.documentConfig.permissions={...this.documentConfig.permissions,...e.permissions},"pdf"===this.documentConfig.fileType&&(this.documentConfig.permissions.edit=!1,this.documentConfig.permissions.review=!1,this.editorConfig.mode="view")),e.callbackUrl&&(this.editorConfig.callbackUrl=e.callbackUrl),e.userId&&(this.editorConfig.user={...this.editorConfig.user,id:e.userId}),e.userName&&(this.editorConfig.user={...this.editorConfig.user,name:e.userName}),e.userGroup&&(this.editorConfig.user={...this.editorConfig.user,group:e.userGroup})}async initOffice(e){const{dom:t,officeApiUrl:i,callback:o,auth:n,verifyFunction:s}=e;if(o&&(this.callback=o),n){let e=!1;if(s)e=await s(n);else{if(!n.verifyUrl)throw new Error("使用验签配置时,必须提供 verifyFunction 或 verifyUrl");e=await r(n.verifyUrl,{appId:n.appId,sign:n.sign,timestamp:n.timestamp})}if(!e)throw new Error("验签失败,请检查验签配置")}return this.createEditor(t,i)}init(e,t,i){return i&&(this.callback=i),this.createEditor(e,t)}createEditor(e,t){if(console.log("[OnlyOffice] createEditor called",{dom:e,officeApiUrl:t}),!e)throw new Error("必须提供挂载的 DOM 元素");if(!t)throw new Error("必须提供 OnlyOffice API 脚本地址");e.style.position="relative",console.log("[OnlyOffice] DOM dimensions:",{width:e.offsetWidth,height:e.offsetHeight});const i=document.createElement("div");i.id=this.editorId,i.style.height="100%",i.style.width="100%",e.appendChild(i);const o=`script-${this.editorId}`;if(document.querySelector(`#${o}`))console.log("[OnlyOffice] Script already loaded"),this.instantiateEditor();else{console.log("[OnlyOffice] Loading script:",t);const e=document.createElement("script");e.id=o,e.src=t,e.onload=()=>{console.log("[OnlyOffice] Script loaded successfully"),console.log("[OnlyOffice] window.DocsAPI:",window.DocsAPI),this.instantiateEditor()},e.onerror=e=>{console.error("[OnlyOffice] Script load failed:",e)},document.head.appendChild(e)}return this}instantiateEditor(){if(console.log("[OnlyOffice] instantiateEditor called"),this.editor&&(this.editor.destroyEditor(),this.editor=null),!window.DocsAPI||!window.DocsAPI.DocEditor)return void console.error("[OnlyOffice] window.DocsAPI.DocEditor is not available");const e={width:this.width,height:this.height,documentType:this.getDocumentType(),document:this.documentConfig,editorConfig:this.editorConfig,events:this.createEventHandlers()};console.log("[OnlyOffice] Creating editor with config:",e),console.log("[OnlyOffice] Editor container ID:",this.editorId),console.log("[OnlyOffice] Container element:",document.getElementById(this.editorId));try{this.editor=new window.DocsAPI.DocEditor(this.editorId,e),console.log("[OnlyOffice] Editor created successfully:",this.editor)}catch(e){console.error("[OnlyOffice] Error creating editor:",e)}}getDocumentType(){const e=o(this.documentConfig.fileType);return"other"===e?"word":e}createEventHandlers(){return{onDocumentStateChange:e=>{this.emitter.emit("documentStateChange",e)},onDocumentReady:()=>{var e,t;console.log("Document is loaded"),this.editorConfig.callbackUrl&&s(this.editorConfig.callbackUrl,{status:8,key:this.documentConfig.key,userdata:JSON.stringify({appUserId:null===(e=this.editorConfig.user)||void 0===e?void 0:e.id})}),null===(t=this.callback)||void 0===t||t.call(this,"onDocumentReady"),this.emitter.emit("onDocumentReady")},onInfo:e=>{var t;console.log("ONLYOFFICE Document Editor is opened in mode",e.data.mode),null===(t=this.callback)||void 0===t||t.call(this,"onInfo",e.data),this.emitter.emit("onInfo",e)},onError:e=>{console.error("ONLYOFFICE Error:",e.data.errorCode,e.data.errorDescription),this.emitter.emit("onError",e)},onRequestHistory:e=>{var t;null===(t=this.callback)||void 0===t||t.call(this,"onRequestHistory",e,this.editor),this.emitter.emit("onRequestHistory",{event:e,editor:this.editor})},onRequestHistoryData:e=>{var t;null===(t=this.callback)||void 0===t||t.call(this,"onRequestHistoryData",e,this.editor),this.emitter.emit("onRequestHistoryData",{event:e,editor:this.editor})},onRequestHistoryClose:e=>{var t;null===(t=this.callback)||void 0===t||t.call(this,"onRequestHistoryClose",e,this.editor),this.emitter.emit("onRequestHistoryClose",{event:e,editor:this.editor})},onRequestRestore:e=>{var t;null===(t=this.callback)||void 0===t||t.call(this,"onRequestRestore",e,this.editor),this.emitter.emit("onRequestRestore",{event:e,editor:this.editor})},onRequestSendNotify:e=>{console.log("onRequestSendNotify",e),this.emitter.emit("onRequestSendNotify",e)},onRequestUsers:e=>{console.log("onRequestUsers",e),this.emitter.emit("onRequestUsers",e)}}}on(e,t){this.emitter.on(e,t)}off(e,t){this.emitter.off(e,t)}getConfig(){return{...this.documentConfig,...this.editorConfig}}getEditor(){return this.editor}destroy(){this.editor&&(this.editor.destroyEditor(),this.editor=null),this.emitter.removeAllListeners(),this.callback=null}}const d=e.defineComponent({name:"OnlyOfficeEditor",props:{officeApiUrl:{type:String,required:!0},document:{type:Object,required:!0},auth:{type:Object,default:void 0},verifyFunction:{type:Function,default:void 0},skipVerification:{type:Boolean,default:!1},height:{type:String,default:"100%"},width:{type:String,default:"100%"}},emits:["ready","error","documentStateChange","requestHistory","requestHistoryData","requestHistoryClose","requestRestore"],setup(t,{emit:i}){const o=e.ref(null),n=e.ref(null),r=e.ref(!1),s=e.ref(null),l=async()=>{if(console.log("[OnlyOffice Component] initEditor called"),console.log("[OnlyOffice Component] containerRef.value:",o.value),o.value)try{console.log("[OnlyOffice Component] Creating OfficeEditor instance");const e=new a;e.configure({...t.document,height:t.height,width:t.width});const l=(e,t,o)=>{switch(e){case"onDocumentReady":r.value=!0,i("ready",o);break;case"onInfo":break;case"onRequestHistory":i("requestHistory",{event:t,editor:o});break;case"onRequestHistoryData":i("requestHistoryData",{event:t,editor:o});break;case"onRequestHistoryClose":i("requestHistoryClose",{event:t,editor:o});break;case"onRequestRestore":i("requestRestore",{event:t,editor:o})}};if(t.skipVerification||!t.auth&&!t.verifyFunction)n.value=e.init(o.value,t.officeApiUrl,l);else{const i={dom:o.value,officeApiUrl:t.officeApiUrl,callback:l,auth:t.auth,verifyFunction:t.verifyFunction};n.value=await e.initOffice(i)}e.on("onError",e=>{var t;s.value=(null===(t=e.data)||void 0===t?void 0:t.errorDescription)||"编辑器错误",i("error",e)}),e.on("documentStateChange",e=>{i("documentStateChange",e)})}catch(e){s.value=e.message||"初始化失败",i("error",e)}else console.warn("[OnlyOffice Component] containerRef is null, cannot init editor")},c=()=>{n.value&&(n.value.destroy(),n.value=null,r.value=!1)};return e.watch(()=>t.document,e=>{n.value&&e&&(c(),l())},{deep:!0}),e.onMounted(()=>{console.log("[OnlyOffice Component] onMounted called"),console.log("[OnlyOffice Component] Props:",{officeApiUrl:t.officeApiUrl,document:t.document,skipVerification:t.skipVerification}),l()}),e.onBeforeUnmount(()=>{c()}),{containerRef:o,editorInstance:n,isReady:r,error:s}},template:'\n <div class="onlyoffice-editor-container" :style="{ width: width, height: height, position: \'relative\', minHeight: \'400px\' }">\n <div ref="containerRef" :style="{ width: \'100%\', height: \'100%\' }"></div>\n <div v-if="error" class="onlyoffice-error" style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: red; z-index: 10;">\n {{ error }}\n </div>\n </div>\n '});exports.OnlyOfficeEditor=d,exports.createOfficeEditor=function(){return new a},exports.downloadSave=async function(e,t,i){const{saveSuccessInfo:o}=await Promise.resolve().then(function(){return l});await o(e,{status:9,key:t,userdata:JSON.stringify({appUserId:i})})},exports.init=function(e,t,i){return(new a).init(e,t,i)},exports.initOffice=async function(e){return(new a).initOffice(e)},exports.shareSave=async function(e,t,i){const{saveSuccessInfo:o}=await Promise.resolve().then(function(){return l});await o(e,{status:10,key:t,userdata:JSON.stringify({appUserId:i})})},exports.useOnlyOffice=function(t){const{officeApiUrl:i,document:o,auth:n,verifyFunction:r,height:s="100%",width:l="100%",autoInit:c=!0}=t,d=e.ref(null),u=e.ref(null),f=e.ref(!1),h=e.ref(null);let y=null;const m=async()=>{if(d.value)try{p(),y=new a,y.configure({...o,height:s,width:l});const e=(e,t,i)=>{if("onDocumentReady"===e)f.value=!0},t={dom:d.value,officeApiUrl:i,callback:e,auth:n,verifyFunction:r};u.value=await y.initOffice(t),y.on("onError",e=>{var t;h.value=(null===(t=e.data)||void 0===t?void 0:t.errorDescription)||"编辑器错误"})}catch(e){h.value=e.message||"初始化失败"}else h.value="容器元素未找到"},p=()=>{y&&(y.destroy(),y=null,u.value=null,f.value=!1)},g=async()=>{p(),await m()};return e.watch(()=>o,async e=>{y&&e&&await g()},{deep:!0}),e.onMounted(()=>{c&&m()}),e.onBeforeUnmount(()=>{p()}),{containerRef:d,editorInstance:u,isReady:f,error:h,init:m,destroy:p,reinit:g,on:(e,t)=>{y&&y.on(e,t)},off:(e,t)=>{y&&y.off(e,t)}}};
1
+ "use strict";var e=require("vue"),t=require("eventemitter3"),i=require("axios");function o(e){const t=e.toLowerCase();if(["doc","docx","odt","rtf","txt","html","epub"].includes(t))return"word";if(["xls","xlsx","ods","csv"].includes(t))return"cell";return["ppt","pptx","odp"].includes(t)?"slide":"pdf"===t?"pdf":"other"}class n{constructor(e=""){this.baseUrl=e}async post(e,t,o){const n=this.baseUrl?`${this.baseUrl}${e}`:e;return i.post(n,t,o)}async get(e,t){const o=this.baseUrl?`${this.baseUrl}${e}`:e;return i.get(o,t)}}async function r(e,t){var i;try{const o=new n(e);return!0===(null===(i=(await o.post("/onlyoffice/token/verifyTokenSign",t)).data)||void 0===i?void 0:i.data)}catch(e){return console.error("验签请求失败:",e),!1}}async function s(e,t){try{await i.post(e,t)}catch(e){console.error("保存操作信息失败:",e)}}var l=Object.freeze({__proto__:null,HttpClient:n,saveSuccessInfo:s,verifyTokenSign:r});const c={comment:!1,download:!1,edit:!1,print:!0,review:!1,editCommentAuthorOnly:!1,fillForms:!1,modifyContentControl:!1};class a{constructor(){this.editor=null,this.callback=null,this.height="100%",this.width="100%",this.editorId=`editor-${Date.now().toString(32)}`,this.emitter=new t,this.documentConfig={fileType:"docx",key:"",url:"",title:"",permissions:{...c}},this.editorConfig={lang:"zh",user:{id:"",name:""}}}configure(e){if(e.height&&(this.height=e.height),e.width&&(this.width=e.width),e.fileType){if("other"===o(e.fileType))throw new Error(`不支持的文件类型: ${e.fileType}`);"other"!==o(e.fileType)&&(this.documentConfig.fileType=e.fileType)}e.key&&(this.documentConfig.key=e.key),e.url&&(this.documentConfig.url=e.url),e.title&&(this.documentConfig.title=e.title),e.permissions&&(this.documentConfig.permissions={...this.documentConfig.permissions,...e.permissions},"pdf"===this.documentConfig.fileType&&(this.documentConfig.permissions.edit=!1,this.documentConfig.permissions.review=!1,this.editorConfig.mode="view")),e.callbackUrl&&(this.editorConfig.callbackUrl=e.callbackUrl),e.userId&&(this.editorConfig.user={...this.editorConfig.user,id:e.userId}),e.userName&&(this.editorConfig.user={...this.editorConfig.user,name:e.userName}),e.userGroup&&(this.editorConfig.user={...this.editorConfig.user,group:e.userGroup})}async initOffice(e){const{dom:t,officeApiUrl:i,callback:o,auth:n,verifyFunction:s}=e;if(o&&(this.callback=o),n){let e=!1;if(s)e=await s(n);else{if(!n.verifyUrl)throw new Error("使用验签配置时,必须提供 verifyFunction 或 verifyUrl");e=await r(n.verifyUrl,{appId:n.appId,sign:n.sign,timestamp:n.timestamp})}if(!e)throw new Error("验签失败,请检查验签配置")}return this.createEditor(t,i)}init(e,t,i){return i&&(this.callback=i),this.createEditor(e,t)}createEditor(e,t){if(console.log("[OnlyOffice] createEditor called",{dom:e,officeApiUrl:t}),!e)throw new Error("必须提供挂载的 DOM 元素");if(!t)throw new Error("必须提供 OnlyOffice API 脚本地址");e.style.position="relative",console.log("[OnlyOffice] DOM dimensions:",{width:e.offsetWidth,height:e.offsetHeight});const i=document.createElement("div");i.id=this.editorId,i.style.height="100%",i.style.width="100%",e.appendChild(i);const o=`script-${this.editorId}`;if(document.querySelector(`#${o}`))console.log("[OnlyOffice] Script already loaded"),this.instantiateEditor();else{console.log("[OnlyOffice] Loading script:",t);const e=document.createElement("script");e.id=o,e.src=t,e.onload=()=>{console.log("[OnlyOffice] Script loaded successfully"),console.log("[OnlyOffice] window.DocsAPI:",window.DocsAPI),this.instantiateEditor()},e.onerror=e=>{console.error("[OnlyOffice] Script load failed:",e)},document.head.appendChild(e)}return this}instantiateEditor(){if(console.log("[OnlyOffice] instantiateEditor called"),this.editor&&(this.editor.destroyEditor(),this.editor=null),!window.DocsAPI||!window.DocsAPI.DocEditor)return void console.error("[OnlyOffice] window.DocsAPI.DocEditor is not available");const e={width:this.width,height:this.height,documentType:this.getDocumentType(),document:this.documentConfig,editorConfig:this.editorConfig,events:this.createEventHandlers()};console.log("[OnlyOffice] Creating editor with config:",e),console.log("[OnlyOffice] Editor container ID:",this.editorId),console.log("[OnlyOffice] Container element:",document.getElementById(this.editorId));try{this.editor=new window.DocsAPI.DocEditor(this.editorId,e),console.log("[OnlyOffice] Editor created successfully:",this.editor)}catch(e){console.error("[OnlyOffice] Error creating editor:",e)}}getDocumentType(){const e=o(this.documentConfig.fileType);return"other"===e?"word":e}createEventHandlers(){return{onDocumentStateChange:e=>{this.emitter.emit("documentStateChange",e)},onDocumentReady:()=>{var e,t;console.log("Document is loaded"),this.editorConfig.callbackUrl&&s(this.editorConfig.callbackUrl,{status:8,key:this.documentConfig.key,userdata:JSON.stringify({appUserId:null===(e=this.editorConfig.user)||void 0===e?void 0:e.id})}),null===(t=this.callback)||void 0===t||t.call(this,"onDocumentReady"),this.emitter.emit("onDocumentReady")},onInfo:e=>{var t;console.log("ONLYOFFICE Document Editor is opened in mode",e.data.mode),null===(t=this.callback)||void 0===t||t.call(this,"onInfo",e.data),this.emitter.emit("onInfo",e)},onError:e=>{console.error("ONLYOFFICE Error:",e.data.errorCode,e.data.errorDescription),this.emitter.emit("onError",e)},onRequestHistory:e=>{var t;null===(t=this.callback)||void 0===t||t.call(this,"onRequestHistory",e,this.editor),this.emitter.emit("onRequestHistory",{event:e,editor:this.editor})},onRequestHistoryData:e=>{var t;null===(t=this.callback)||void 0===t||t.call(this,"onRequestHistoryData",e,this.editor),this.emitter.emit("onRequestHistoryData",{event:e,editor:this.editor})},onRequestHistoryClose:e=>{var t;null===(t=this.callback)||void 0===t||t.call(this,"onRequestHistoryClose",e,this.editor),this.emitter.emit("onRequestHistoryClose",{event:e,editor:this.editor})},onRequestRestore:e=>{var t;null===(t=this.callback)||void 0===t||t.call(this,"onRequestRestore",e,this.editor),this.emitter.emit("onRequestRestore",{event:e,editor:this.editor})},onRequestSendNotify:e=>{console.log("onRequestSendNotify",e),this.emitter.emit("onRequestSendNotify",e)},onRequestUsers:e=>{console.log("onRequestUsers",e),this.emitter.emit("onRequestUsers",e)}}}on(e,t){this.emitter.on(e,t)}off(e,t){this.emitter.off(e,t)}getConfig(){return{...this.documentConfig,...this.editorConfig}}getEditor(){return this.editor}destroy(){this.editor&&(this.editor.destroyEditor(),this.editor=null),this.emitter.removeAllListeners(),this.callback=null}}const d=e.defineComponent({name:"OnlyOfficeEditor",props:{officeApiUrl:{type:String,required:!0},document:{type:Object,required:!0},auth:{type:Object,default:void 0},verifyFunction:{type:Function,default:void 0},skipVerification:{type:Boolean,default:!1},height:{type:String,default:"100%"},width:{type:String,default:"100%"}},emits:["ready","error","documentStateChange","requestHistory","requestHistoryData","requestHistoryClose","requestRestore"],setup(t,{emit:i}){const o=e.ref(null),n=e.ref(null),r=e.ref(!1),s=e.ref(null),l=async()=>{if(console.log("[OnlyOffice Component] initEditor called"),console.log("[OnlyOffice Component] containerRef.value:",o.value),!o.value){console.warn("[OnlyOffice Component] containerRef is null, cannot init editor");const e=document.querySelector(".onlyoffice-editor-container > div:first-child");if(console.log("[OnlyOffice Component] Trying to find container by selector:",e),!e)return;o.value=e}try{console.log("[OnlyOffice Component] Container dimensions:",{width:o.value.offsetWidth,height:o.value.offsetHeight,clientWidth:o.value.clientWidth,clientHeight:o.value.clientHeight});const e=new a;e.configure({...t.document,height:t.height,width:t.width});const l=(e,t,o)=>{switch(e){case"onDocumentReady":r.value=!0,i("ready",o);break;case"onInfo":break;case"onRequestHistory":i("requestHistory",{event:t,editor:o});break;case"onRequestHistoryData":i("requestHistoryData",{event:t,editor:o});break;case"onRequestHistoryClose":i("requestHistoryClose",{event:t,editor:o});break;case"onRequestRestore":i("requestRestore",{event:t,editor:o})}};if(t.skipVerification||!t.auth&&!t.verifyFunction)n.value=e.init(o.value,t.officeApiUrl,l);else{const i={dom:o.value,officeApiUrl:t.officeApiUrl,callback:l,auth:t.auth,verifyFunction:t.verifyFunction};n.value=await e.initOffice(i)}e.on("onError",e=>{var t;s.value=(null===(t=e.data)||void 0===t?void 0:t.errorDescription)||"编辑器错误",i("error",e)}),e.on("documentStateChange",e=>{i("documentStateChange",e)})}catch(e){s.value=e.message||"初始化失败",i("error",e)}},c=()=>{n.value&&(n.value.destroy(),n.value=null,r.value=!1)};return e.watch(()=>t.document,e=>{n.value&&e&&(c(),l())},{deep:!0}),e.onMounted(async()=>{console.log("[OnlyOffice Component] onMounted called"),console.log("[OnlyOffice Component] Props:",{officeApiUrl:t.officeApiUrl,document:t.document,skipVerification:t.skipVerification}),await e.nextTick(),console.log("[OnlyOffice Component] After nextTick, containerRef.value:",o.value),o.value?l():(console.log("[OnlyOffice Component] containerRef still null, retrying with setTimeout"),setTimeout(()=>{console.log("[OnlyOffice Component] After setTimeout, containerRef.value:",o.value),l()},100))}),e.onBeforeUnmount(()=>{c()}),{containerRef:o,editorInstance:n,isReady:r,error:s}},template:'\n <div class="onlyoffice-editor-container" :style="{ width: width, height: height, position: \'relative\', minHeight: \'400px\' }">\n <div ref="containerRef" :style="{ width: \'100%\', height: \'100%\' }"></div>\n <div v-if="error" class="onlyoffice-error" style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: red; z-index: 10;">\n {{ error }}\n </div>\n </div>\n '});exports.OnlyOfficeEditor=d,exports.createOfficeEditor=function(){return new a},exports.downloadSave=async function(e,t,i){const{saveSuccessInfo:o}=await Promise.resolve().then(function(){return l});await o(e,{status:9,key:t,userdata:JSON.stringify({appUserId:i})})},exports.init=function(e,t,i){return(new a).init(e,t,i)},exports.initOffice=async function(e){return(new a).initOffice(e)},exports.shareSave=async function(e,t,i){const{saveSuccessInfo:o}=await Promise.resolve().then(function(){return l});await o(e,{status:10,key:t,userdata:JSON.stringify({appUserId:i})})},exports.useOnlyOffice=function(t){const{officeApiUrl:i,document:o,auth:n,verifyFunction:r,height:s="100%",width:l="100%",autoInit:c=!0}=t,d=e.ref(null),f=e.ref(null),u=e.ref(!1),h=e.ref(null);let y=null;const m=async()=>{if(d.value)try{p(),y=new a,y.configure({...o,height:s,width:l});const e=(e,t,i)=>{if("onDocumentReady"===e)u.value=!0},t={dom:d.value,officeApiUrl:i,callback:e,auth:n,verifyFunction:r};f.value=await y.initOffice(t),y.on("onError",e=>{var t;h.value=(null===(t=e.data)||void 0===t?void 0:t.errorDescription)||"编辑器错误"})}catch(e){h.value=e.message||"初始化失败"}else h.value="容器元素未找到"},p=()=>{y&&(y.destroy(),y=null,f.value=null,u.value=!1)},g=async()=>{p(),await m()};return e.watch(()=>o,async e=>{y&&e&&await g()},{deep:!0}),e.onMounted(()=>{c&&m()}),e.onBeforeUnmount(()=>{p()}),{containerRef:d,editorInstance:f,isReady:u,error:h,init:m,destroy:p,reinit:g,on:(e,t)=>{y&&y.on(e,t)},off:(e,t)=>{y&&y.off(e,t)}}};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../../src/core/utils/fileType.ts","../../../src/core/utils/http.ts","../../../src/core/editor.ts","../../../src/vue3/component.ts","../../../src/core/index.ts","../../../src/vue3/useOnlyOffice.ts"],"sourcesContent":["import type { DocumentType, FileType } from '../../types';\n\n/**\n * 根据文件扩展名获取 OnlyOffice 文档类型\n * @param fileType 文件扩展名\n * @returns 文档类型\n */\nexport function getDocumentType(fileType: FileType | string): DocumentType | 'other' {\n const type = fileType.toLowerCase();\n\n // 文档类型\n const wordTypes = ['doc', 'docx', 'odt', 'rtf', 'txt', 'html', 'epub'];\n if (wordTypes.includes(type)) {\n return 'word';\n }\n\n // 表格类型\n const cellTypes = ['xls', 'xlsx', 'ods', 'csv'];\n if (cellTypes.includes(type)) {\n return 'cell';\n }\n\n // 演示类型\n const slideTypes = ['ppt', 'pptx', 'odp'];\n if (slideTypes.includes(type)) {\n return 'slide';\n }\n\n // PDF 类型\n if (type === 'pdf') {\n return 'pdf';\n }\n\n return 'other';\n}\n\n/**\n * 检查文件类型是否受支持\n * @param fileType 文件扩展名\n * @returns 是否支持\n */\nexport function isSupportedFileType(fileType: string): boolean {\n return getDocumentType(fileType) !== 'other';\n}","import axios, { type AxiosRequestConfig, type AxiosResponse } from 'axios';\n\n/**\n * HTTP 请求工具\n */\nexport class HttpClient {\n private baseUrl: string;\n\n constructor(baseUrl: string = '') {\n this.baseUrl = baseUrl;\n }\n\n /**\n * 发送 POST 请求\n * @param url 请求地址\n * @param data 请求数据\n * @param config 额外配置\n * @returns Promise\n */\n async post<T = any>(\n url: string,\n data?: any,\n config?: AxiosRequestConfig\n ): Promise<AxiosResponse<T>> {\n const fullUrl = this.baseUrl ? `${this.baseUrl}${url}` : url;\n return axios.post<T>(fullUrl, data, config);\n }\n\n /**\n * 发送 GET 请求\n * @param url 请求地址\n * @param config 额外配置\n * @returns Promise\n */\n async get<T = any>(\n url: string,\n config?: AxiosRequestConfig\n ): Promise<AxiosResponse<T>> {\n const fullUrl = this.baseUrl ? `${this.baseUrl}${url}` : url;\n return axios.get<T>(fullUrl, config);\n }\n}\n\n/**\n * 验签接口请求\n * @param baseUrl 基础 URL\n * @param data 验签数据\n * @returns 验签结果\n */\nexport async function verifyTokenSign(\n baseUrl: string,\n data: {\n appId: string;\n sign: string;\n timestamp: number;\n }\n): Promise<boolean> {\n try {\n const client = new HttpClient(baseUrl);\n const response = await client.post<{ data: boolean }>(\n '/onlyoffice/token/verifyTokenSign',\n data\n );\n return response.data?.data === true;\n } catch (error) {\n console.error('验签请求失败:', error);\n return false;\n }\n}\n\n/**\n * 保存操作信息\n * @param callbackUrl 回调地址\n * @param data 操作数据\n */\nexport async function saveSuccessInfo(\n callbackUrl: string,\n data: {\n status: number;\n key: string;\n userdata: string;\n }\n): Promise<void> {\n try {\n await axios.post(callbackUrl, data);\n } catch (error) {\n console.error('保存操作信息失败:', error);\n }\n}","import EventEmitter from 'eventemitter3';\nimport type {\n DocumentConfig,\n EditorConfig,\n DocumentPermissions,\n OfficeEventType,\n OfficeCallback,\n OfficeEditorInstance,\n OfficeDocumentConfig,\n OfficeInitConfig,\n AuthConfig,\n VerifyTokenSignFunction,\n} from '../types';\nimport { getDocumentType, isSupportedFileType } from './utils/fileType';\nimport { verifyTokenSign, saveSuccessInfo } from './utils/http';\n\n/**\n * 默认文档权限\n */\nconst DEFAULT_PERMISSIONS: DocumentPermissions = {\n comment: false,\n download: false,\n edit: false,\n print: true,\n review: false,\n editCommentAuthorOnly: false,\n fillForms: false,\n modifyContentControl: false,\n};\n\n/**\n * OnlyOffice 编辑器管理类\n */\nexport class OfficeEditor implements OfficeEditorInstance {\n private editor: any = null;\n private editorId: string;\n private emitter: EventEmitter;\n private documentConfig: DocumentConfig;\n private editorConfig: EditorConfig;\n private callback: OfficeCallback | null = null;\n private height: string = '100%';\n private width: string = '100%';\n\n constructor() {\n this.editorId = `editor-${Date.now().toString(32)}`;\n this.emitter = new EventEmitter();\n this.documentConfig = {\n fileType: 'docx',\n key: '',\n url: '',\n title: '',\n permissions: { ...DEFAULT_PERMISSIONS },\n };\n this.editorConfig = {\n lang: 'zh',\n user: { id: '', name: '' },\n };\n }\n\n /**\n * 配置文档参数\n */\n configure(config: OfficeDocumentConfig): void {\n if (config.height) this.height = config.height;\n if (config.width) this.width = config.width;\n\n if (config.fileType) {\n if (!isSupportedFileType(config.fileType)) {\n throw new Error(`不支持的文件类型: ${config.fileType}`);\n }\n const docType = getDocumentType(config.fileType);\n if (docType !== 'other') {\n this.documentConfig.fileType = config.fileType;\n }\n }\n\n if (config.key) this.documentConfig.key = config.key;\n if (config.url) this.documentConfig.url = config.url;\n if (config.title) this.documentConfig.title = config.title;\n\n if (config.permissions) {\n this.documentConfig.permissions = {\n ...this.documentConfig.permissions,\n ...config.permissions,\n };\n\n // PDF 文件特殊处理\n if (this.documentConfig.fileType === 'pdf') {\n this.documentConfig.permissions.edit = false;\n this.documentConfig.permissions.review = false;\n this.editorConfig.mode = 'view';\n }\n }\n\n if (config.callbackUrl) this.editorConfig.callbackUrl = config.callbackUrl;\n if (config.userId) {\n this.editorConfig.user = {\n ...this.editorConfig.user,\n id: config.userId,\n };\n }\n if (config.userName) {\n this.editorConfig.user = {\n ...this.editorConfig.user,\n name: config.userName,\n };\n }\n if (config.userGroup) {\n this.editorConfig.user = {\n ...this.editorConfig.user,\n group: config.userGroup,\n };\n }\n }\n\n /**\n * 初始化编辑器(带验签)\n */\n async initOffice(config: OfficeInitConfig): Promise<OfficeEditorInstance> {\n const { dom, officeApiUrl, callback, auth, verifyFunction } = config;\n\n if (callback) this.callback = callback;\n\n // 验签逻辑\n if (auth) {\n let verified = false;\n\n if (verifyFunction) {\n // 使用自定义验签函数\n verified = await verifyFunction(auth);\n } else if (auth.verifyUrl) {\n // 使用自定义验签地址\n verified = await verifyTokenSign(auth.verifyUrl, {\n appId: auth.appId,\n sign: auth.sign,\n timestamp: auth.timestamp,\n });\n } else {\n throw new Error('使用验签配置时,必须提供 verifyFunction 或 verifyUrl');\n }\n\n if (!verified) {\n throw new Error('验签失败,请检查验签配置');\n }\n }\n\n return this.createEditor(dom, officeApiUrl);\n }\n\n /**\n * 简化初始化(无验签)\n */\n init(\n dom: HTMLElement,\n officeApiUrl: string,\n callback?: OfficeCallback\n ): OfficeEditorInstance {\n if (callback) this.callback = callback;\n return this.createEditor(dom, officeApiUrl);\n }\n\n /**\n * 创建编辑器实例\n */\n private createEditor(dom: HTMLElement, officeApiUrl: string): OfficeEditorInstance {\n console.log('[OnlyOffice] createEditor called', { dom, officeApiUrl });\n\n if (!dom) {\n throw new Error('必须提供挂载的 DOM 元素');\n }\n\n if (!officeApiUrl) {\n throw new Error('必须提供 OnlyOffice API 脚本地址');\n }\n\n // 设置容器样式\n dom.style.position = 'relative';\n console.log('[OnlyOffice] DOM dimensions:', { width: dom.offsetWidth, height: dom.offsetHeight });\n\n // 创建编辑器容器\n const mainDiv = document.createElement('div');\n mainDiv.id = this.editorId;\n mainDiv.style.height = '100%';\n mainDiv.style.width = '100%';\n dom.appendChild(mainDiv);\n\n // 动态加载 OnlyOffice API 脚本\n const scriptId = `script-${this.editorId}`;\n const existingScript = document.querySelector(`#${scriptId}`);\n\n if (!existingScript) {\n console.log('[OnlyOffice] Loading script:', officeApiUrl);\n const script = document.createElement('script');\n script.id = scriptId;\n script.src = officeApiUrl;\n script.onload = () => {\n console.log('[OnlyOffice] Script loaded successfully');\n console.log('[OnlyOffice] window.DocsAPI:', window.DocsAPI);\n this.instantiateEditor();\n };\n script.onerror = (err) => {\n console.error('[OnlyOffice] Script load failed:', err);\n };\n document.head.appendChild(script);\n } else {\n console.log('[OnlyOffice] Script already loaded');\n this.instantiateEditor();\n }\n\n return this;\n }\n\n /**\n * 实例化编辑器\n */\n private instantiateEditor(): void {\n console.log('[OnlyOffice] instantiateEditor called');\n\n // 销毁现有实例\n if (this.editor) {\n this.editor.destroyEditor();\n this.editor = null;\n }\n\n // 检查 DocsAPI 是否可用\n if (!window.DocsAPI || !window.DocsAPI.DocEditor) {\n console.error('[OnlyOffice] window.DocsAPI.DocEditor is not available');\n return;\n }\n\n // 构建配置对象\n const config = {\n width: this.width,\n height: this.height,\n documentType: this.getDocumentType(),\n document: this.documentConfig,\n editorConfig: this.editorConfig,\n events: this.createEventHandlers(),\n };\n\n console.log('[OnlyOffice] Creating editor with config:', config);\n console.log('[OnlyOffice] Editor container ID:', this.editorId);\n console.log('[OnlyOffice] Container element:', document.getElementById(this.editorId));\n\n // 创建编辑器实例\n try {\n this.editor = new window.DocsAPI.DocEditor(this.editorId, config);\n console.log('[OnlyOffice] Editor created successfully:', this.editor);\n } catch (err) {\n console.error('[OnlyOffice] Error creating editor:', err);\n }\n }\n\n /**\n * 获取文档类型\n */\n private getDocumentType(): string {\n const type = getDocumentType(this.documentConfig.fileType);\n return type === 'other' ? 'word' : type;\n }\n\n /**\n * 创建事件处理器\n */\n private createEventHandlers(): Record<string, (event: any) => void> {\n return {\n onDocumentStateChange: (event: any) => {\n this.emitter.emit('documentStateChange', event);\n },\n onDocumentReady: () => {\n console.log('Document is loaded');\n // 通知后端文档加载成功\n if (this.editorConfig.callbackUrl) {\n saveSuccessInfo(this.editorConfig.callbackUrl, {\n status: 8,\n key: this.documentConfig.key,\n userdata: JSON.stringify({\n appUserId: this.editorConfig.user?.id,\n }),\n });\n }\n this.callback?.('onDocumentReady');\n this.emitter.emit('onDocumentReady');\n },\n onInfo: (event: any) => {\n console.log('ONLYOFFICE Document Editor is opened in mode', event.data.mode);\n this.callback?.('onInfo', event.data);\n this.emitter.emit('onInfo', event);\n },\n onError: (event: any) => {\n console.error('ONLYOFFICE Error:', event.data.errorCode, event.data.errorDescription);\n this.emitter.emit('onError', event);\n },\n onRequestHistory: (event: any) => {\n this.callback?.('onRequestHistory', event, this.editor);\n this.emitter.emit('onRequestHistory', { event, editor: this.editor });\n },\n onRequestHistoryData: (event: any) => {\n this.callback?.('onRequestHistoryData', event, this.editor);\n this.emitter.emit('onRequestHistoryData', { event, editor: this.editor });\n },\n onRequestHistoryClose: (event: any) => {\n this.callback?.('onRequestHistoryClose', event, this.editor);\n this.emitter.emit('onRequestHistoryClose', { event, editor: this.editor });\n },\n onRequestRestore: (event: any) => {\n this.callback?.('onRequestRestore', event, this.editor);\n this.emitter.emit('onRequestRestore', { event, editor: this.editor });\n },\n onRequestSendNotify: (event: any) => {\n console.log('onRequestSendNotify', event);\n this.emitter.emit('onRequestSendNotify', event);\n },\n onRequestUsers: (event: any) => {\n console.log('onRequestUsers', event);\n this.emitter.emit('onRequestUsers', event);\n },\n };\n }\n\n /**\n * 监听事件\n */\n on(event: OfficeEventType, callback: (...args: any[]) => void): void {\n this.emitter.on(event, callback);\n }\n\n /**\n * 移除事件监听\n */\n off(event: OfficeEventType, callback: (...args: any[]) => void): void {\n this.emitter.off(event, callback);\n }\n\n /**\n * 获取当前配置\n */\n getConfig(): DocumentConfig & EditorConfig {\n return {\n ...this.documentConfig,\n ...this.editorConfig,\n };\n }\n\n /**\n * 获取内部编辑器实例\n */\n getEditor(): any {\n return this.editor;\n }\n\n /**\n * 销毁编辑器\n */\n destroy(): void {\n if (this.editor) {\n this.editor.destroyEditor();\n this.editor = null;\n }\n this.emitter.removeAllListeners();\n this.callback = null;\n }\n}","import {\n defineComponent,\n ref,\n onMounted,\n onBeforeUnmount,\n watch,\n type PropType,\n type Ref,\n} from 'vue';\nimport { OfficeEditor } from '../core/editor';\nimport type {\n OfficeDocumentConfig,\n OfficeInitConfig,\n OfficeCallback,\n OfficeEventType,\n AuthConfig,\n VerifyTokenSignFunction,\n OfficeEditorInstance,\n} from '../types';\n\n/**\n * OnlyOffice 编辑器 Vue 3 组件\n */\nexport const OnlyOfficeEditor = defineComponent({\n name: 'OnlyOfficeEditor',\n\n props: {\n /** OnlyOffice API 脚本地址 */\n officeApiUrl: {\n type: String,\n required: true,\n },\n /** 文档配置 */\n document: {\n type: Object as PropType<OfficeDocumentConfig>,\n required: true,\n },\n /** 验签配置 */\n auth: {\n type: Object as PropType<AuthConfig>,\n default: undefined,\n },\n /** 自定义验签函数 */\n verifyFunction: {\n type: Function as PropType<VerifyTokenSignFunction>,\n default: undefined,\n },\n /** 是否跳过验签(当 auth 已通过外部验签时使用) */\n skipVerification: {\n type: Boolean,\n default: false,\n },\n /** 编辑器高度 */\n height: {\n type: String,\n default: '100%',\n },\n /** 编辑器宽度 */\n width: {\n type: String,\n default: '100%',\n },\n },\n\n emits: [\n 'ready',\n 'error',\n 'documentStateChange',\n 'requestHistory',\n 'requestHistoryData',\n 'requestHistoryClose',\n 'requestRestore',\n ],\n\n setup(props: any, { emit }: any) {\n const containerRef: Ref<HTMLElement | null> = ref(null);\n const editorInstance: Ref<OfficeEditorInstance | null> = ref(null);\n const isReady: Ref<boolean> = ref(false);\n const error: Ref<string | null> = ref(null);\n\n /**\n * 初始化编辑器\n */\n const initEditor = async () => {\n console.log('[OnlyOffice Component] initEditor called');\n console.log('[OnlyOffice Component] containerRef.value:', containerRef.value);\n\n if (!containerRef.value) {\n console.warn('[OnlyOffice Component] containerRef is null, cannot init editor');\n return;\n }\n\n try {\n console.log('[OnlyOffice Component] Creating OfficeEditor instance');\n const editor = new OfficeEditor();\n\n // 配置文档参数\n editor.configure({\n ...props.document,\n height: props.height,\n width: props.width,\n });\n\n // 事件回调\n const callback: OfficeCallback = (type, event, editorInst) => {\n switch (type) {\n case 'onDocumentReady':\n isReady.value = true;\n emit('ready', editorInst);\n break;\n case 'onInfo':\n break;\n case 'onRequestHistory':\n emit('requestHistory', { event, editor: editorInst });\n break;\n case 'onRequestHistoryData':\n emit('requestHistoryData', { event, editor: editorInst });\n break;\n case 'onRequestHistoryClose':\n emit('requestHistoryClose', { event, editor: editorInst });\n break;\n case 'onRequestRestore':\n emit('requestRestore', { event, editor: editorInst });\n break;\n }\n };\n\n // 判断初始化方式\n if (props.skipVerification || (!props.auth && !props.verifyFunction)) {\n // 跳过验签或无验签配置:直接初始化\n editorInstance.value = editor.init(\n containerRef.value,\n props.officeApiUrl,\n callback\n );\n } else {\n // 带验签初始化\n const initConfig: OfficeInitConfig = {\n dom: containerRef.value,\n officeApiUrl: props.officeApiUrl,\n callback,\n auth: props.auth,\n verifyFunction: props.verifyFunction,\n };\n editorInstance.value = await editor.initOffice(initConfig);\n }\n\n // 监听错误事件\n editor.on('onError' as OfficeEventType, (event: any) => {\n error.value = event.data?.errorDescription || '编辑器错误';\n emit('error', event);\n });\n\n // 监听文档状态变化\n editor.on('documentStateChange' as OfficeEventType, (event: any) => {\n emit('documentStateChange', event);\n });\n } catch (err: any) {\n error.value = err.message || '初始化失败';\n emit('error', err);\n }\n };\n\n /**\n * 销毁编辑器\n */\n const destroyEditor = () => {\n if (editorInstance.value) {\n editorInstance.value.destroy();\n editorInstance.value = null;\n isReady.value = false;\n }\n };\n\n // 监听文档配置变化\n watch(\n () => props.document,\n (newDoc: any) => {\n if (editorInstance.value && newDoc) {\n // 重新初始化编辑器\n destroyEditor();\n initEditor();\n }\n },\n { deep: true }\n );\n\n // 组件挂载时初始化\n onMounted(() => {\n console.log('[OnlyOffice Component] onMounted called');\n console.log('[OnlyOffice Component] Props:', {\n officeApiUrl: props.officeApiUrl,\n document: props.document,\n skipVerification: props.skipVerification\n });\n initEditor();\n });\n\n // 组件销毁前清理\n onBeforeUnmount(() => {\n destroyEditor();\n });\n\n return {\n containerRef,\n editorInstance,\n isReady,\n error,\n };\n },\n\n template: `\n <div class=\"onlyoffice-editor-container\" :style=\"{ width: width, height: height, position: 'relative', minHeight: '400px' }\">\n <div ref=\"containerRef\" :style=\"{ width: '100%', height: '100%' }\"></div>\n <div v-if=\"error\" class=\"onlyoffice-error\" style=\"position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: red; z-index: 10;\">\n {{ error }}\n </div>\n </div>\n `,\n});\n\nexport default OnlyOfficeEditor;","export { OfficeEditor } from './editor';\nexport { getDocumentType, isSupportedFileType } from './utils/fileType';\nexport { HttpClient, verifyTokenSign, saveSuccessInfo } from './utils/http';\n\n// 导出类型\nexport type {\n DocumentType,\n FileType,\n DocumentPermissions,\n UserInfo,\n DocumentConfig,\n EditorConfig,\n AuthConfig,\n VerifyTokenSignFunction,\n OfficeInitConfig,\n OfficeDocumentConfig,\n OfficeEventType,\n OfficeCallbackType,\n OfficeCallback,\n OfficeEditorInstance,\n OfficeSDK,\n} from '../types';\n\nimport { OfficeEditor } from './editor';\nimport type {\n OfficeDocumentConfig,\n OfficeInitConfig,\n OfficeCallback,\n OfficeEventType,\n OfficeEditorInstance,\n} from '../types';\n\n/**\n * 创建 Office 编辑器实例\n * @returns OfficeEditor 实例\n */\nexport function createOfficeEditor(): OfficeEditor {\n return new OfficeEditor();\n}\n\n/**\n * 快速初始化 Office 编辑器\n * @param config 初始化配置\n * @returns Promise<OfficeEditorInstance>\n */\nexport async function initOffice(config: OfficeInitConfig): Promise<OfficeEditorInstance> {\n const editor = new OfficeEditor();\n return editor.initOffice(config);\n}\n\n/**\n * 简化初始化(无验签)\n * @param dom 挂载的 DOM 元素\n * @param officeApiUrl OnlyOffice API 地址\n * @param callback 事件回调\n * @returns OfficeEditorInstance\n */\nexport function init(\n dom: HTMLElement,\n officeApiUrl: string,\n callback?: OfficeCallback\n): OfficeEditorInstance {\n const editor = new OfficeEditor();\n return editor.init(dom, officeApiUrl, callback);\n}\n\n/**\n * 配置文档参数(全局配置,需要先创建编辑器实例)\n * @deprecated 建议使用 OfficeEditor.configure() 方法\n */\nexport function config(_config: OfficeDocumentConfig): void {\n console.warn('此方法已废弃,请使用 OfficeEditor.configure() 方法');\n}\n\n/**\n * 销毁编辑器(全局方法,需要先创建编辑器实例)\n * @deprecated 建议使用 OfficeEditor.destroy() 方法\n */\nexport function destroy(): void {\n console.warn('此方法已废弃,请使用 OfficeEditor.destroy() 方法');\n}\n\n/**\n * 监听事件(全局方法,需要先创建编辑器实例)\n * @deprecated 建议使用 OfficeEditor.on() 方法\n */\nexport function on(_event: OfficeEventType, _callback: (...args: any[]) => void): void {\n console.warn('此方法已废弃,请使用 OfficeEditor.on() 方法');\n}\n\n/**\n * 记录分享动作\n * @param callbackUrl 回调地址\n * @param fileKey 文件标识\n * @param appUserId 用户 ID\n */\nexport async function shareSave(\n callbackUrl: string,\n fileKey: string,\n appUserId: string\n): Promise<void> {\n const { saveSuccessInfo } = await import('./utils/http');\n await saveSuccessInfo(callbackUrl, {\n status: 10,\n key: fileKey,\n userdata: JSON.stringify({ appUserId }),\n });\n}\n\n/**\n * 记录下载动作\n * @param callbackUrl 回调地址\n * @param fileKey 文件标识\n * @param appUserId 用户 ID\n */\nexport async function downloadSave(\n callbackUrl: string,\n fileKey: string,\n appUserId: string\n): Promise<void> {\n const { saveSuccessInfo } = await import('./utils/http');\n await saveSuccessInfo(callbackUrl, {\n status: 9,\n key: fileKey,\n userdata: JSON.stringify({ appUserId }),\n });\n}","import { ref, onMounted, onBeforeUnmount, watch, type Ref } from 'vue';\nimport { OfficeEditor } from '../core/editor';\nimport type {\n OfficeDocumentConfig,\n OfficeInitConfig,\n OfficeCallback,\n OfficeEventType,\n AuthConfig,\n VerifyTokenSignFunction,\n OfficeEditorInstance,\n} from '../types';\n\n/**\n * useOnlyOffice 配置选项\n */\nexport interface UseOnlyOfficeOptions {\n /** OnlyOffice API 脚本地址 */\n officeApiUrl: string;\n /** 文档配置 */\n document: OfficeDocumentConfig;\n /** 验签配置 */\n auth?: AuthConfig;\n /** 自定义验签函数 */\n verifyFunction?: VerifyTokenSignFunction;\n /** 编辑器高度 */\n height?: string;\n /** 编辑器宽度 */\n width?: string;\n /** 是否自动初始化 */\n autoInit?: boolean;\n}\n\n/**\n * useOnlyOffice 返回值\n */\nexport interface UseOnlyOfficeReturn {\n /** 容器元素引用 */\n containerRef: Ref<HTMLElement | null>;\n /** 编辑器实例 */\n editorInstance: Ref<OfficeEditorInstance | null>;\n /** 是否已就绪 */\n isReady: Ref<boolean>;\n /** 错误信息 */\n error: Ref<string | null>;\n /** 初始化编辑器 */\n init: () => Promise<void>;\n /** 销毁编辑器 */\n destroy: () => void;\n /** 重新初始化 */\n reinit: () => Promise<void>;\n /** 监听事件 */\n on: (event: OfficeEventType, callback: (...args: any[]) => void) => void;\n /** 移除事件监听 */\n off: (event: OfficeEventType, callback: (...args: any[]) => void) => void;\n}\n\n/**\n * OnlyOffice Vue 3 组合式函数\n * @param options 配置选项\n * @returns 编辑器状态和方法\n */\nexport function useOnlyOffice(options: UseOnlyOfficeOptions): UseOnlyOfficeReturn {\n const {\n officeApiUrl,\n document: documentConfig,\n auth,\n verifyFunction,\n height = '100%',\n width = '100%',\n autoInit = true,\n } = options;\n\n const containerRef: Ref<HTMLElement | null> = ref(null);\n const editorInstance: Ref<OfficeEditorInstance | null> = ref(null);\n const isReady: Ref<boolean> = ref(false);\n const error: Ref<string | null> = ref(null);\n\n let editor: OfficeEditor | null = null;\n\n /**\n * 初始化编辑器\n */\n const init = async () => {\n if (!containerRef.value) {\n error.value = '容器元素未找到';\n return;\n }\n\n try {\n // 销毁现有实例\n destroy();\n\n editor = new OfficeEditor();\n\n // 配置文档参数\n editor.configure({\n ...documentConfig,\n height,\n width,\n });\n\n // 事件回调\n const callback: OfficeCallback = (type, _event, _editorInst) => {\n switch (type) {\n case 'onDocumentReady':\n isReady.value = true;\n break;\n case 'onInfo':\n break;\n }\n };\n\n // 初始化配置\n const initConfig: OfficeInitConfig = {\n dom: containerRef.value,\n officeApiUrl,\n callback,\n auth,\n verifyFunction,\n };\n\n // 初始化编辑器\n editorInstance.value = await editor.initOffice(initConfig);\n\n // 监听错误事件\n editor.on('onError' as OfficeEventType, (event: any) => {\n error.value = event.data?.errorDescription || '编辑器错误';\n });\n } catch (err: any) {\n error.value = err.message || '初始化失败';\n }\n };\n\n /**\n * 销毁编辑器\n */\n const destroy = () => {\n if (editor) {\n editor.destroy();\n editor = null;\n editorInstance.value = null;\n isReady.value = false;\n }\n };\n\n /**\n * 重新初始化\n */\n const reinit = async () => {\n destroy();\n await init();\n };\n\n /**\n * 监听事件\n */\n const on = (event: OfficeEventType, callback: (...args: any[]) => void) => {\n if (editor) {\n editor.on(event, callback);\n }\n };\n\n /**\n * 移除事件监听\n */\n const off = (event: OfficeEventType, callback: (...args: any[]) => void) => {\n if (editor) {\n editor.off(event, callback);\n }\n };\n\n // 监听文档配置变化\n watch(\n () => documentConfig,\n async (newDoc: any) => {\n if (editor && newDoc) {\n await reinit();\n }\n },\n { deep: true }\n );\n\n // 组件挂载时初始化\n onMounted(() => {\n if (autoInit) {\n init();\n }\n });\n\n // 组件销毁前清理\n onBeforeUnmount(() => {\n destroy();\n });\n\n return {\n containerRef,\n editorInstance,\n isReady,\n error,\n init,\n destroy,\n reinit,\n on,\n off,\n };\n}\n\nexport default useOnlyOffice;"],"names":["getDocumentType","fileType","type","toLowerCase","includes","HttpClient","constructor","baseUrl","this","post","url","data","config","fullUrl","axios","get","async","verifyTokenSign","client","_a","error","console","saveSuccessInfo","callbackUrl","DEFAULT_PERMISSIONS","comment","download","edit","print","review","editCommentAuthorOnly","fillForms","modifyContentControl","OfficeEditor","editor","callback","height","width","editorId","Date","now","toString","emitter","EventEmitter","documentConfig","key","title","permissions","editorConfig","lang","user","id","name","configure","Error","mode","userId","userName","userGroup","group","initOffice","dom","officeApiUrl","auth","verifyFunction","verified","verifyUrl","appId","sign","timestamp","createEditor","init","log","style","position","offsetWidth","offsetHeight","mainDiv","document","createElement","appendChild","scriptId","querySelector","instantiateEditor","script","src","onload","window","DocsAPI","onerror","err","head","destroyEditor","DocEditor","documentType","events","createEventHandlers","getElementById","onDocumentStateChange","event","emit","onDocumentReady","status","userdata","JSON","stringify","appUserId","_b","call","onInfo","onError","errorCode","errorDescription","onRequestHistory","onRequestHistoryData","onRequestHistoryClose","onRequestRestore","onRequestSendNotify","onRequestUsers","on","off","getConfig","getEditor","destroy","removeAllListeners","OnlyOfficeEditor","defineComponent","props","String","required","Object","default","undefined","Function","skipVerification","Boolean","emits","setup","containerRef","ref","editorInstance","isReady","initEditor","value","editorInst","initConfig","message","warn","watch","newDoc","deep","onMounted","onBeforeUnmount","template","fileKey","Promise","resolve","then","http","options","autoInit","_event","_editorInst","reinit"],"mappings":"gFAOM,SAAUA,EAAgBC,GAC9B,MAAMC,EAAOD,EAASE,cAItB,GADkB,CAAC,MAAO,OAAQ,MAAO,MAAO,MAAO,OAAQ,QACjDC,SAASF,GACrB,MAAO,OAKT,GADkB,CAAC,MAAO,OAAQ,MAAO,OAC3BE,SAASF,GACrB,MAAO,OAKT,MADmB,CAAC,MAAO,OAAQ,OACpBE,SAASF,GACf,QAII,QAATA,EACK,MAGF,OACT,OC7BaG,EAGX,WAAAC,CAAYC,EAAkB,IAC5BC,KAAKD,QAAUA,CACjB,CASA,UAAME,CACJC,EACAC,EACAC,GAEA,MAAMC,EAAUL,KAAKD,QAAU,GAAGC,KAAKD,UAAUG,IAAQA,EACzD,OAAOI,EAAML,KAAQI,EAASF,EAAMC,EACtC,CAQA,SAAMG,CACJL,EACAE,GAEA,MAAMC,EAAUL,KAAKD,QAAU,GAAGC,KAAKD,UAAUG,IAAQA,EACzD,OAAOI,EAAMC,IAAOF,EAASD,EAC/B,EASKI,eAAeC,EACpBV,EACAI,SAMA,IACE,MAAMO,EAAS,IAAIb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oDZpB,EAAU,KACVzF,IACFA,EAAOyF,UACPzF,EAAS,KACT0G,EAAeG,MAAQ,KACvBF,EAAQE,OAAQ,IAOdoB,EAASnJ,UACb2G,UACMpD,KA4CR,OAtBA6E,QACE,IAAMxG,EACN5B,MAAOqI,IACDnH,GAAUmH,SACNc,KAGV,CAAEb,MAAM,IAIVC,EAAAA,UAAU,KACJS,GACFzF,MAKJiF,EAAAA,gBAAgB,KACd7B,MAGK,CACLe,eACAE,iBACAC,UACAzH,QACAmD,OACAoD,UACAwC,SACA5C,GA9CS,CAACpB,EAAwBhE,KAC9BD,GACFA,EAAOqF,GAAGpB,EAAOhE,IA6CnBqF,IAtCU,CAACrB,EAAwBhE,KAC/BD,GACFA,EAAOsF,IAAIrB,EAAOhE,IAsCxB"}
1
+ {"version":3,"file":"index.cjs","sources":["../../../src/core/utils/fileType.ts","../../../src/core/utils/http.ts","../../../src/core/editor.ts","../../../src/vue3/component.ts","../../../src/core/index.ts","../../../src/vue3/useOnlyOffice.ts"],"sourcesContent":["import type { DocumentType, FileType } from '../../types';\n\n/**\n * 根据文件扩展名获取 OnlyOffice 文档类型\n * @param fileType 文件扩展名\n * @returns 文档类型\n */\nexport function getDocumentType(fileType: FileType | string): DocumentType | 'other' {\n const type = fileType.toLowerCase();\n\n // 文档类型\n const wordTypes = ['doc', 'docx', 'odt', 'rtf', 'txt', 'html', 'epub'];\n if (wordTypes.includes(type)) {\n return 'word';\n }\n\n // 表格类型\n const cellTypes = ['xls', 'xlsx', 'ods', 'csv'];\n if (cellTypes.includes(type)) {\n return 'cell';\n }\n\n // 演示类型\n const slideTypes = ['ppt', 'pptx', 'odp'];\n if (slideTypes.includes(type)) {\n return 'slide';\n }\n\n // PDF 类型\n if (type === 'pdf') {\n return 'pdf';\n }\n\n return 'other';\n}\n\n/**\n * 检查文件类型是否受支持\n * @param fileType 文件扩展名\n * @returns 是否支持\n */\nexport function isSupportedFileType(fileType: string): boolean {\n return getDocumentType(fileType) !== 'other';\n}","import axios, { type AxiosRequestConfig, type AxiosResponse } from 'axios';\n\n/**\n * HTTP 请求工具\n */\nexport class HttpClient {\n private baseUrl: string;\n\n constructor(baseUrl: string = '') {\n this.baseUrl = baseUrl;\n }\n\n /**\n * 发送 POST 请求\n * @param url 请求地址\n * @param data 请求数据\n * @param config 额外配置\n * @returns Promise\n */\n async post<T = any>(\n url: string,\n data?: any,\n config?: AxiosRequestConfig\n ): Promise<AxiosResponse<T>> {\n const fullUrl = this.baseUrl ? `${this.baseUrl}${url}` : url;\n return axios.post<T>(fullUrl, data, config);\n }\n\n /**\n * 发送 GET 请求\n * @param url 请求地址\n * @param config 额外配置\n * @returns Promise\n */\n async get<T = any>(\n url: string,\n config?: AxiosRequestConfig\n ): Promise<AxiosResponse<T>> {\n const fullUrl = this.baseUrl ? `${this.baseUrl}${url}` : url;\n return axios.get<T>(fullUrl, config);\n }\n}\n\n/**\n * 验签接口请求\n * @param baseUrl 基础 URL\n * @param data 验签数据\n * @returns 验签结果\n */\nexport async function verifyTokenSign(\n baseUrl: string,\n data: {\n appId: string;\n sign: string;\n timestamp: number;\n }\n): Promise<boolean> {\n try {\n const client = new HttpClient(baseUrl);\n const response = await client.post<{ data: boolean }>(\n '/onlyoffice/token/verifyTokenSign',\n data\n );\n return response.data?.data === true;\n } catch (error) {\n console.error('验签请求失败:', error);\n return false;\n }\n}\n\n/**\n * 保存操作信息\n * @param callbackUrl 回调地址\n * @param data 操作数据\n */\nexport async function saveSuccessInfo(\n callbackUrl: string,\n data: {\n status: number;\n key: string;\n userdata: string;\n }\n): Promise<void> {\n try {\n await axios.post(callbackUrl, data);\n } catch (error) {\n console.error('保存操作信息失败:', error);\n }\n}","import EventEmitter from 'eventemitter3';\nimport type {\n DocumentConfig,\n EditorConfig,\n DocumentPermissions,\n OfficeEventType,\n OfficeCallback,\n OfficeEditorInstance,\n OfficeDocumentConfig,\n OfficeInitConfig,\n AuthConfig,\n VerifyTokenSignFunction,\n} from '../types';\nimport { getDocumentType, isSupportedFileType } from './utils/fileType';\nimport { verifyTokenSign, saveSuccessInfo } from './utils/http';\n\n/**\n * 默认文档权限\n */\nconst DEFAULT_PERMISSIONS: DocumentPermissions = {\n comment: false,\n download: false,\n edit: false,\n print: true,\n review: false,\n editCommentAuthorOnly: false,\n fillForms: false,\n modifyContentControl: false,\n};\n\n/**\n * OnlyOffice 编辑器管理类\n */\nexport class OfficeEditor implements OfficeEditorInstance {\n private editor: any = null;\n private editorId: string;\n private emitter: EventEmitter;\n private documentConfig: DocumentConfig;\n private editorConfig: EditorConfig;\n private callback: OfficeCallback | null = null;\n private height: string = '100%';\n private width: string = '100%';\n\n constructor() {\n this.editorId = `editor-${Date.now().toString(32)}`;\n this.emitter = new EventEmitter();\n this.documentConfig = {\n fileType: 'docx',\n key: '',\n url: '',\n title: '',\n permissions: { ...DEFAULT_PERMISSIONS },\n };\n this.editorConfig = {\n lang: 'zh',\n user: { id: '', name: '' },\n };\n }\n\n /**\n * 配置文档参数\n */\n configure(config: OfficeDocumentConfig): void {\n if (config.height) this.height = config.height;\n if (config.width) this.width = config.width;\n\n if (config.fileType) {\n if (!isSupportedFileType(config.fileType)) {\n throw new Error(`不支持的文件类型: ${config.fileType}`);\n }\n const docType = getDocumentType(config.fileType);\n if (docType !== 'other') {\n this.documentConfig.fileType = config.fileType;\n }\n }\n\n if (config.key) this.documentConfig.key = config.key;\n if (config.url) this.documentConfig.url = config.url;\n if (config.title) this.documentConfig.title = config.title;\n\n if (config.permissions) {\n this.documentConfig.permissions = {\n ...this.documentConfig.permissions,\n ...config.permissions,\n };\n\n // PDF 文件特殊处理\n if (this.documentConfig.fileType === 'pdf') {\n this.documentConfig.permissions.edit = false;\n this.documentConfig.permissions.review = false;\n this.editorConfig.mode = 'view';\n }\n }\n\n if (config.callbackUrl) this.editorConfig.callbackUrl = config.callbackUrl;\n if (config.userId) {\n this.editorConfig.user = {\n ...this.editorConfig.user,\n id: config.userId,\n };\n }\n if (config.userName) {\n this.editorConfig.user = {\n ...this.editorConfig.user,\n name: config.userName,\n };\n }\n if (config.userGroup) {\n this.editorConfig.user = {\n ...this.editorConfig.user,\n group: config.userGroup,\n };\n }\n }\n\n /**\n * 初始化编辑器(带验签)\n */\n async initOffice(config: OfficeInitConfig): Promise<OfficeEditorInstance> {\n const { dom, officeApiUrl, callback, auth, verifyFunction } = config;\n\n if (callback) this.callback = callback;\n\n // 验签逻辑\n if (auth) {\n let verified = false;\n\n if (verifyFunction) {\n // 使用自定义验签函数\n verified = await verifyFunction(auth);\n } else if (auth.verifyUrl) {\n // 使用自定义验签地址\n verified = await verifyTokenSign(auth.verifyUrl, {\n appId: auth.appId,\n sign: auth.sign,\n timestamp: auth.timestamp,\n });\n } else {\n throw new Error('使用验签配置时,必须提供 verifyFunction 或 verifyUrl');\n }\n\n if (!verified) {\n throw new Error('验签失败,请检查验签配置');\n }\n }\n\n return this.createEditor(dom, officeApiUrl);\n }\n\n /**\n * 简化初始化(无验签)\n */\n init(\n dom: HTMLElement,\n officeApiUrl: string,\n callback?: OfficeCallback\n ): OfficeEditorInstance {\n if (callback) this.callback = callback;\n return this.createEditor(dom, officeApiUrl);\n }\n\n /**\n * 创建编辑器实例\n */\n private createEditor(dom: HTMLElement, officeApiUrl: string): OfficeEditorInstance {\n console.log('[OnlyOffice] createEditor called', { dom, officeApiUrl });\n\n if (!dom) {\n throw new Error('必须提供挂载的 DOM 元素');\n }\n\n if (!officeApiUrl) {\n throw new Error('必须提供 OnlyOffice API 脚本地址');\n }\n\n // 设置容器样式\n dom.style.position = 'relative';\n console.log('[OnlyOffice] DOM dimensions:', { width: dom.offsetWidth, height: dom.offsetHeight });\n\n // 创建编辑器容器\n const mainDiv = document.createElement('div');\n mainDiv.id = this.editorId;\n mainDiv.style.height = '100%';\n mainDiv.style.width = '100%';\n dom.appendChild(mainDiv);\n\n // 动态加载 OnlyOffice API 脚本\n const scriptId = `script-${this.editorId}`;\n const existingScript = document.querySelector(`#${scriptId}`);\n\n if (!existingScript) {\n console.log('[OnlyOffice] Loading script:', officeApiUrl);\n const script = document.createElement('script');\n script.id = scriptId;\n script.src = officeApiUrl;\n script.onload = () => {\n console.log('[OnlyOffice] Script loaded successfully');\n console.log('[OnlyOffice] window.DocsAPI:', window.DocsAPI);\n this.instantiateEditor();\n };\n script.onerror = (err) => {\n console.error('[OnlyOffice] Script load failed:', err);\n };\n document.head.appendChild(script);\n } else {\n console.log('[OnlyOffice] Script already loaded');\n this.instantiateEditor();\n }\n\n return this;\n }\n\n /**\n * 实例化编辑器\n */\n private instantiateEditor(): void {\n console.log('[OnlyOffice] instantiateEditor called');\n\n // 销毁现有实例\n if (this.editor) {\n this.editor.destroyEditor();\n this.editor = null;\n }\n\n // 检查 DocsAPI 是否可用\n if (!window.DocsAPI || !window.DocsAPI.DocEditor) {\n console.error('[OnlyOffice] window.DocsAPI.DocEditor is not available');\n return;\n }\n\n // 构建配置对象\n const config = {\n width: this.width,\n height: this.height,\n documentType: this.getDocumentType(),\n document: this.documentConfig,\n editorConfig: this.editorConfig,\n events: this.createEventHandlers(),\n };\n\n console.log('[OnlyOffice] Creating editor with config:', config);\n console.log('[OnlyOffice] Editor container ID:', this.editorId);\n console.log('[OnlyOffice] Container element:', document.getElementById(this.editorId));\n\n // 创建编辑器实例\n try {\n this.editor = new window.DocsAPI.DocEditor(this.editorId, config);\n console.log('[OnlyOffice] Editor created successfully:', this.editor);\n } catch (err) {\n console.error('[OnlyOffice] Error creating editor:', err);\n }\n }\n\n /**\n * 获取文档类型\n */\n private getDocumentType(): string {\n const type = getDocumentType(this.documentConfig.fileType);\n return type === 'other' ? 'word' : type;\n }\n\n /**\n * 创建事件处理器\n */\n private createEventHandlers(): Record<string, (event: any) => void> {\n return {\n onDocumentStateChange: (event: any) => {\n this.emitter.emit('documentStateChange', event);\n },\n onDocumentReady: () => {\n console.log('Document is loaded');\n // 通知后端文档加载成功\n if (this.editorConfig.callbackUrl) {\n saveSuccessInfo(this.editorConfig.callbackUrl, {\n status: 8,\n key: this.documentConfig.key,\n userdata: JSON.stringify({\n appUserId: this.editorConfig.user?.id,\n }),\n });\n }\n this.callback?.('onDocumentReady');\n this.emitter.emit('onDocumentReady');\n },\n onInfo: (event: any) => {\n console.log('ONLYOFFICE Document Editor is opened in mode', event.data.mode);\n this.callback?.('onInfo', event.data);\n this.emitter.emit('onInfo', event);\n },\n onError: (event: any) => {\n console.error('ONLYOFFICE Error:', event.data.errorCode, event.data.errorDescription);\n this.emitter.emit('onError', event);\n },\n onRequestHistory: (event: any) => {\n this.callback?.('onRequestHistory', event, this.editor);\n this.emitter.emit('onRequestHistory', { event, editor: this.editor });\n },\n onRequestHistoryData: (event: any) => {\n this.callback?.('onRequestHistoryData', event, this.editor);\n this.emitter.emit('onRequestHistoryData', { event, editor: this.editor });\n },\n onRequestHistoryClose: (event: any) => {\n this.callback?.('onRequestHistoryClose', event, this.editor);\n this.emitter.emit('onRequestHistoryClose', { event, editor: this.editor });\n },\n onRequestRestore: (event: any) => {\n this.callback?.('onRequestRestore', event, this.editor);\n this.emitter.emit('onRequestRestore', { event, editor: this.editor });\n },\n onRequestSendNotify: (event: any) => {\n console.log('onRequestSendNotify', event);\n this.emitter.emit('onRequestSendNotify', event);\n },\n onRequestUsers: (event: any) => {\n console.log('onRequestUsers', event);\n this.emitter.emit('onRequestUsers', event);\n },\n };\n }\n\n /**\n * 监听事件\n */\n on(event: OfficeEventType, callback: (...args: any[]) => void): void {\n this.emitter.on(event, callback);\n }\n\n /**\n * 移除事件监听\n */\n off(event: OfficeEventType, callback: (...args: any[]) => void): void {\n this.emitter.off(event, callback);\n }\n\n /**\n * 获取当前配置\n */\n getConfig(): DocumentConfig & EditorConfig {\n return {\n ...this.documentConfig,\n ...this.editorConfig,\n };\n }\n\n /**\n * 获取内部编辑器实例\n */\n getEditor(): any {\n return this.editor;\n }\n\n /**\n * 销毁编辑器\n */\n destroy(): void {\n if (this.editor) {\n this.editor.destroyEditor();\n this.editor = null;\n }\n this.emitter.removeAllListeners();\n this.callback = null;\n }\n}","import {\n defineComponent,\n ref,\n onMounted,\n onBeforeUnmount,\n watch,\n nextTick,\n type PropType,\n type Ref,\n} from 'vue';\nimport { OfficeEditor } from '../core/editor';\nimport type {\n OfficeDocumentConfig,\n OfficeInitConfig,\n OfficeCallback,\n OfficeEventType,\n AuthConfig,\n VerifyTokenSignFunction,\n OfficeEditorInstance,\n} from '../types';\n\n/**\n * OnlyOffice 编辑器 Vue 3 组件\n */\nexport const OnlyOfficeEditor = defineComponent({\n name: 'OnlyOfficeEditor',\n\n props: {\n /** OnlyOffice API 脚本地址 */\n officeApiUrl: {\n type: String,\n required: true,\n },\n /** 文档配置 */\n document: {\n type: Object as PropType<OfficeDocumentConfig>,\n required: true,\n },\n /** 验签配置 */\n auth: {\n type: Object as PropType<AuthConfig>,\n default: undefined,\n },\n /** 自定义验签函数 */\n verifyFunction: {\n type: Function as PropType<VerifyTokenSignFunction>,\n default: undefined,\n },\n /** 是否跳过验签(当 auth 已通过外部验签时使用) */\n skipVerification: {\n type: Boolean,\n default: false,\n },\n /** 编辑器高度 */\n height: {\n type: String,\n default: '100%',\n },\n /** 编辑器宽度 */\n width: {\n type: String,\n default: '100%',\n },\n },\n\n emits: [\n 'ready',\n 'error',\n 'documentStateChange',\n 'requestHistory',\n 'requestHistoryData',\n 'requestHistoryClose',\n 'requestRestore',\n ],\n\n setup(props: any, { emit }: any) {\n const containerRef: Ref<HTMLElement | null> = ref(null);\n const editorInstance: Ref<OfficeEditorInstance | null> = ref(null);\n const isReady: Ref<boolean> = ref(false);\n const error: Ref<string | null> = ref(null);\n\n /**\n * 初始化编辑器\n */\n const initEditor = async () => {\n console.log('[OnlyOffice Component] initEditor called');\n console.log('[OnlyOffice Component] containerRef.value:', containerRef.value);\n\n if (!containerRef.value) {\n console.warn('[OnlyOffice Component] containerRef is null, cannot init editor');\n // 尝试通过 ID 获取容器\n const container = document.querySelector('.onlyoffice-editor-container > div:first-child');\n console.log('[OnlyOffice Component] Trying to find container by selector:', container);\n if (container) {\n containerRef.value = container as HTMLElement;\n } else {\n return;\n }\n }\n\n try {\n console.log('[OnlyOffice Component] Container dimensions:', {\n width: containerRef.value.offsetWidth,\n height: containerRef.value.offsetHeight,\n clientWidth: containerRef.value.clientWidth,\n clientHeight: containerRef.value.clientHeight\n });\n const editor = new OfficeEditor();\n\n // 配置文档参数\n editor.configure({\n ...props.document,\n height: props.height,\n width: props.width,\n });\n\n // 事件回调\n const callback: OfficeCallback = (type, event, editorInst) => {\n switch (type) {\n case 'onDocumentReady':\n isReady.value = true;\n emit('ready', editorInst);\n break;\n case 'onInfo':\n break;\n case 'onRequestHistory':\n emit('requestHistory', { event, editor: editorInst });\n break;\n case 'onRequestHistoryData':\n emit('requestHistoryData', { event, editor: editorInst });\n break;\n case 'onRequestHistoryClose':\n emit('requestHistoryClose', { event, editor: editorInst });\n break;\n case 'onRequestRestore':\n emit('requestRestore', { event, editor: editorInst });\n break;\n }\n };\n\n // 判断初始化方式\n if (props.skipVerification || (!props.auth && !props.verifyFunction)) {\n // 跳过验签或无验签配置:直接初始化\n editorInstance.value = editor.init(\n containerRef.value,\n props.officeApiUrl,\n callback\n );\n } else {\n // 带验签初始化\n const initConfig: OfficeInitConfig = {\n dom: containerRef.value,\n officeApiUrl: props.officeApiUrl,\n callback,\n auth: props.auth,\n verifyFunction: props.verifyFunction,\n };\n editorInstance.value = await editor.initOffice(initConfig);\n }\n\n // 监听错误事件\n editor.on('onError' as OfficeEventType, (event: any) => {\n error.value = event.data?.errorDescription || '编辑器错误';\n emit('error', event);\n });\n\n // 监听文档状态变化\n editor.on('documentStateChange' as OfficeEventType, (event: any) => {\n emit('documentStateChange', event);\n });\n } catch (err: any) {\n error.value = err.message || '初始化失败';\n emit('error', err);\n }\n };\n\n /**\n * 销毁编辑器\n */\n const destroyEditor = () => {\n if (editorInstance.value) {\n editorInstance.value.destroy();\n editorInstance.value = null;\n isReady.value = false;\n }\n };\n\n // 监听文档配置变化\n watch(\n () => props.document,\n (newDoc: any) => {\n if (editorInstance.value && newDoc) {\n // 重新初始化编辑器\n destroyEditor();\n initEditor();\n }\n },\n { deep: true }\n );\n\n // 组件挂载时初始化\n onMounted(async () => {\n console.log('[OnlyOffice Component] onMounted called');\n console.log('[OnlyOffice Component] Props:', {\n officeApiUrl: props.officeApiUrl,\n document: props.document,\n skipVerification: props.skipVerification\n });\n\n // 使用 nextTick 确保 DOM 已经渲染完成\n await nextTick();\n console.log('[OnlyOffice Component] After nextTick, containerRef.value:', containerRef.value);\n\n // 如果仍然为 null,使用 setTimeout 重试\n if (!containerRef.value) {\n console.log('[OnlyOffice Component] containerRef still null, retrying with setTimeout');\n setTimeout(() => {\n console.log('[OnlyOffice Component] After setTimeout, containerRef.value:', containerRef.value);\n initEditor();\n }, 100);\n } else {\n initEditor();\n }\n });\n\n // 组件销毁前清理\n onBeforeUnmount(() => {\n destroyEditor();\n });\n\n return {\n containerRef,\n editorInstance,\n isReady,\n error,\n };\n },\n\n template: `\n <div class=\"onlyoffice-editor-container\" :style=\"{ width: width, height: height, position: 'relative', minHeight: '400px' }\">\n <div ref=\"containerRef\" :style=\"{ width: '100%', height: '100%' }\"></div>\n <div v-if=\"error\" class=\"onlyoffice-error\" style=\"position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: red; z-index: 10;\">\n {{ error }}\n </div>\n </div>\n `,\n});\n\nexport default OnlyOfficeEditor;","export { OfficeEditor } from './editor';\nexport { getDocumentType, isSupportedFileType } from './utils/fileType';\nexport { HttpClient, verifyTokenSign, saveSuccessInfo } from './utils/http';\n\n// 导出类型\nexport type {\n DocumentType,\n FileType,\n DocumentPermissions,\n UserInfo,\n DocumentConfig,\n EditorConfig,\n AuthConfig,\n VerifyTokenSignFunction,\n OfficeInitConfig,\n OfficeDocumentConfig,\n OfficeEventType,\n OfficeCallbackType,\n OfficeCallback,\n OfficeEditorInstance,\n OfficeSDK,\n} from '../types';\n\nimport { OfficeEditor } from './editor';\nimport type {\n OfficeDocumentConfig,\n OfficeInitConfig,\n OfficeCallback,\n OfficeEventType,\n OfficeEditorInstance,\n} from '../types';\n\n/**\n * 创建 Office 编辑器实例\n * @returns OfficeEditor 实例\n */\nexport function createOfficeEditor(): OfficeEditor {\n return new OfficeEditor();\n}\n\n/**\n * 快速初始化 Office 编辑器\n * @param config 初始化配置\n * @returns Promise<OfficeEditorInstance>\n */\nexport async function initOffice(config: OfficeInitConfig): Promise<OfficeEditorInstance> {\n const editor = new OfficeEditor();\n return editor.initOffice(config);\n}\n\n/**\n * 简化初始化(无验签)\n * @param dom 挂载的 DOM 元素\n * @param officeApiUrl OnlyOffice API 地址\n * @param callback 事件回调\n * @returns OfficeEditorInstance\n */\nexport function init(\n dom: HTMLElement,\n officeApiUrl: string,\n callback?: OfficeCallback\n): OfficeEditorInstance {\n const editor = new OfficeEditor();\n return editor.init(dom, officeApiUrl, callback);\n}\n\n/**\n * 配置文档参数(全局配置,需要先创建编辑器实例)\n * @deprecated 建议使用 OfficeEditor.configure() 方法\n */\nexport function config(_config: OfficeDocumentConfig): void {\n console.warn('此方法已废弃,请使用 OfficeEditor.configure() 方法');\n}\n\n/**\n * 销毁编辑器(全局方法,需要先创建编辑器实例)\n * @deprecated 建议使用 OfficeEditor.destroy() 方法\n */\nexport function destroy(): void {\n console.warn('此方法已废弃,请使用 OfficeEditor.destroy() 方法');\n}\n\n/**\n * 监听事件(全局方法,需要先创建编辑器实例)\n * @deprecated 建议使用 OfficeEditor.on() 方法\n */\nexport function on(_event: OfficeEventType, _callback: (...args: any[]) => void): void {\n console.warn('此方法已废弃,请使用 OfficeEditor.on() 方法');\n}\n\n/**\n * 记录分享动作\n * @param callbackUrl 回调地址\n * @param fileKey 文件标识\n * @param appUserId 用户 ID\n */\nexport async function shareSave(\n callbackUrl: string,\n fileKey: string,\n appUserId: string\n): Promise<void> {\n const { saveSuccessInfo } = await import('./utils/http');\n await saveSuccessInfo(callbackUrl, {\n status: 10,\n key: fileKey,\n userdata: JSON.stringify({ appUserId }),\n });\n}\n\n/**\n * 记录下载动作\n * @param callbackUrl 回调地址\n * @param fileKey 文件标识\n * @param appUserId 用户 ID\n */\nexport async function downloadSave(\n callbackUrl: string,\n fileKey: string,\n appUserId: string\n): Promise<void> {\n const { saveSuccessInfo } = await import('./utils/http');\n await saveSuccessInfo(callbackUrl, {\n status: 9,\n key: fileKey,\n userdata: JSON.stringify({ appUserId }),\n });\n}","import { ref, onMounted, onBeforeUnmount, watch, type Ref } from 'vue';\nimport { OfficeEditor } from '../core/editor';\nimport type {\n OfficeDocumentConfig,\n OfficeInitConfig,\n OfficeCallback,\n OfficeEventType,\n AuthConfig,\n VerifyTokenSignFunction,\n OfficeEditorInstance,\n} from '../types';\n\n/**\n * useOnlyOffice 配置选项\n */\nexport interface UseOnlyOfficeOptions {\n /** OnlyOffice API 脚本地址 */\n officeApiUrl: string;\n /** 文档配置 */\n document: OfficeDocumentConfig;\n /** 验签配置 */\n auth?: AuthConfig;\n /** 自定义验签函数 */\n verifyFunction?: VerifyTokenSignFunction;\n /** 编辑器高度 */\n height?: string;\n /** 编辑器宽度 */\n width?: string;\n /** 是否自动初始化 */\n autoInit?: boolean;\n}\n\n/**\n * useOnlyOffice 返回值\n */\nexport interface UseOnlyOfficeReturn {\n /** 容器元素引用 */\n containerRef: Ref<HTMLElement | null>;\n /** 编辑器实例 */\n editorInstance: Ref<OfficeEditorInstance | null>;\n /** 是否已就绪 */\n isReady: Ref<boolean>;\n /** 错误信息 */\n error: Ref<string | null>;\n /** 初始化编辑器 */\n init: () => Promise<void>;\n /** 销毁编辑器 */\n destroy: () => void;\n /** 重新初始化 */\n reinit: () => Promise<void>;\n /** 监听事件 */\n on: (event: OfficeEventType, callback: (...args: any[]) => void) => void;\n /** 移除事件监听 */\n off: (event: OfficeEventType, callback: (...args: any[]) => void) => void;\n}\n\n/**\n * OnlyOffice Vue 3 组合式函数\n * @param options 配置选项\n * @returns 编辑器状态和方法\n */\nexport function useOnlyOffice(options: UseOnlyOfficeOptions): UseOnlyOfficeReturn {\n const {\n officeApiUrl,\n document: documentConfig,\n auth,\n verifyFunction,\n height = '100%',\n width = '100%',\n autoInit = true,\n } = options;\n\n const containerRef: Ref<HTMLElement | null> = ref(null);\n const editorInstance: Ref<OfficeEditorInstance | null> = ref(null);\n const isReady: Ref<boolean> = ref(false);\n const error: Ref<string | null> = ref(null);\n\n let editor: OfficeEditor | null = null;\n\n /**\n * 初始化编辑器\n */\n const init = async () => {\n if (!containerRef.value) {\n error.value = '容器元素未找到';\n return;\n }\n\n try {\n // 销毁现有实例\n destroy();\n\n editor = new OfficeEditor();\n\n // 配置文档参数\n editor.configure({\n ...documentConfig,\n height,\n width,\n });\n\n // 事件回调\n const callback: OfficeCallback = (type, _event, _editorInst) => {\n switch (type) {\n case 'onDocumentReady':\n isReady.value = true;\n break;\n case 'onInfo':\n break;\n }\n };\n\n // 初始化配置\n const initConfig: OfficeInitConfig = {\n dom: containerRef.value,\n officeApiUrl,\n callback,\n auth,\n verifyFunction,\n };\n\n // 初始化编辑器\n editorInstance.value = await editor.initOffice(initConfig);\n\n // 监听错误事件\n editor.on('onError' as OfficeEventType, (event: any) => {\n error.value = event.data?.errorDescription || '编辑器错误';\n });\n } catch (err: any) {\n error.value = err.message || '初始化失败';\n }\n };\n\n /**\n * 销毁编辑器\n */\n const destroy = () => {\n if (editor) {\n editor.destroy();\n editor = null;\n editorInstance.value = null;\n isReady.value = false;\n }\n };\n\n /**\n * 重新初始化\n */\n const reinit = async () => {\n destroy();\n await init();\n };\n\n /**\n * 监听事件\n */\n const on = (event: OfficeEventType, callback: (...args: any[]) => void) => {\n if (editor) {\n editor.on(event, callback);\n }\n };\n\n /**\n * 移除事件监听\n */\n const off = (event: OfficeEventType, callback: (...args: any[]) => void) => {\n if (editor) {\n editor.off(event, callback);\n }\n };\n\n // 监听文档配置变化\n watch(\n () => documentConfig,\n async (newDoc: any) => {\n if (editor && newDoc) {\n await reinit();\n }\n },\n { deep: true }\n );\n\n // 组件挂载时初始化\n onMounted(() => {\n if (autoInit) {\n init();\n }\n });\n\n // 组件销毁前清理\n onBeforeUnmount(() => {\n destroy();\n });\n\n return {\n containerRef,\n editorInstance,\n isReady,\n error,\n init,\n destroy,\n reinit,\n on,\n off,\n };\n}\n\nexport default useOnlyOffice;"],"names":["getDocumentType","fileType","type","toLowerCase","includes","HttpClient","constructor","baseUrl","this","post","url","data","config","fullUrl","axios","get","async","verifyTokenSign","client","_a","error","console","saveSuccessInfo","callbackUrl","DEFAULT_PERMISSIONS","comment","download","edit","print","review","editCommentAuthorOnly","fillForms","modifyContentControl","OfficeEditor","editor","callback","height","width","editorId","Date","now","toString","emitter","EventEmitter","documentConfig","key","title","permissions","editorConfig","lang","user","id","name","configure","Error","mode","userId","userName","userGroup","group","initOffice","dom","officeApiUrl","auth","verifyFunction","verified","verifyUrl","appId","sign","timestamp","createEditor","init","log","style","position","offsetWidth","offsetHeight","mainDiv","document","createElement","appendChild","scriptId","querySelector","instantiateEditor","script","src","onload","window","DocsAPI","onerror","err","head","destroyEditor","DocEditor","documentType","events","createEventHandlers","getElementById","onDocumentStateChange","event","emit","onDocumentReady","status","userdata","JSON","stringify","appUserId","_b","call","onInfo","onError","errorCode","errorDescription","onRequestHistory","onRequestHistoryData","onRequestHistoryClose","onRequestRestore","onRequestSendNotify","onRequestUsers","on","off","getConfig","getEditor","destroy","removeAllListeners","OnlyOfficeEditor","defineComponent","props","String","required","Object","default","undefined","Function","skipVerification","Boolean","emits","setup","containerRef","ref","editorInstance","isReady","initEditor","value","warn","container","clientWidth","clientHeight","editorInst","initConfig","message","watch","newDoc","deep","onMounted","nextTick","setTimeout","onBeforeUnmount","template","fileKey","Promise","resolve","then","http","options","autoInit","_event","_editorInst","reinit"],"mappings":"gFAOM,SAAUA,EAAgBC,GAC9B,MAAMC,EAAOD,EAASE,cAItB,GADkB,CAAC,MAAO,OAAQ,MAAO,MAAO,MAAO,OAAQ,QACjDC,SAASF,GACrB,MAAO,OAKT,GADkB,CAAC,MAAO,OAAQ,MAAO,OAC3BE,SAASF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AAwBhE,KAC9BD,GACFA,EAAOqF,GAAGpB,EAAOhE,IA6CnBqF,IAtCU,CAACrB,EAAwBhE,KAC/BD,GACFA,EAAOsF,IAAIrB,EAAOhE,IAsCxB"}
@@ -1,2 +1,2 @@
1
- import{defineComponent as e,ref as t,watch as i,onMounted as o,onBeforeUnmount as n}from"vue";import r from"eventemitter3";import s from"axios";function l(e){const t=e.toLowerCase();if(["doc","docx","odt","rtf","txt","html","epub"].includes(t))return"word";if(["xls","xlsx","ods","csv"].includes(t))return"cell";return["ppt","pptx","odp"].includes(t)?"slide":"pdf"===t?"pdf":"other"}class c{constructor(e=""){this.baseUrl=e}async post(e,t,i){const o=this.baseUrl?`${this.baseUrl}${e}`:e;return s.post(o,t,i)}async get(e,t){const i=this.baseUrl?`${this.baseUrl}${e}`:e;return s.get(i,t)}}async function a(e,t){var i;try{const o=new c(e);return!0===(null===(i=(await o.post("/onlyoffice/token/verifyTokenSign",t)).data)||void 0===i?void 0:i.data)}catch(e){return console.error("验签请求失败:",e),!1}}async function d(e,t){try{await s.post(e,t)}catch(e){console.error("保存操作信息失败:",e)}}var u=Object.freeze({__proto__:null,HttpClient:c,saveSuccessInfo:d,verifyTokenSign:a});const f={comment:!1,download:!1,edit:!1,print:!0,review:!1,editCommentAuthorOnly:!1,fillForms:!1,modifyContentControl:!1};class h{constructor(){this.editor=null,this.callback=null,this.height="100%",this.width="100%",this.editorId=`editor-${Date.now().toString(32)}`,this.emitter=new r,this.documentConfig={fileType:"docx",key:"",url:"",title:"",permissions:{...f}},this.editorConfig={lang:"zh",user:{id:"",name:""}}}configure(e){if(e.height&&(this.height=e.height),e.width&&(this.width=e.width),e.fileType){if("other"===l(e.fileType))throw new Error(`不支持的文件类型: ${e.fileType}`);"other"!==l(e.fileType)&&(this.documentConfig.fileType=e.fileType)}e.key&&(this.documentConfig.key=e.key),e.url&&(this.documentConfig.url=e.url),e.title&&(this.documentConfig.title=e.title),e.permissions&&(this.documentConfig.permissions={...this.documentConfig.permissions,...e.permissions},"pdf"===this.documentConfig.fileType&&(this.documentConfig.permissions.edit=!1,this.documentConfig.permissions.review=!1,this.editorConfig.mode="view")),e.callbackUrl&&(this.editorConfig.callbackUrl=e.callbackUrl),e.userId&&(this.editorConfig.user={...this.editorConfig.user,id:e.userId}),e.userName&&(this.editorConfig.user={...this.editorConfig.user,name:e.userName}),e.userGroup&&(this.editorConfig.user={...this.editorConfig.user,group:e.userGroup})}async initOffice(e){const{dom:t,officeApiUrl:i,callback:o,auth:n,verifyFunction:r}=e;if(o&&(this.callback=o),n){let e=!1;if(r)e=await r(n);else{if(!n.verifyUrl)throw new Error("使用验签配置时,必须提供 verifyFunction 或 verifyUrl");e=await a(n.verifyUrl,{appId:n.appId,sign:n.sign,timestamp:n.timestamp})}if(!e)throw new Error("验签失败,请检查验签配置")}return this.createEditor(t,i)}init(e,t,i){return i&&(this.callback=i),this.createEditor(e,t)}createEditor(e,t){if(console.log("[OnlyOffice] createEditor called",{dom:e,officeApiUrl:t}),!e)throw new Error("必须提供挂载的 DOM 元素");if(!t)throw new Error("必须提供 OnlyOffice API 脚本地址");e.style.position="relative",console.log("[OnlyOffice] DOM dimensions:",{width:e.offsetWidth,height:e.offsetHeight});const i=document.createElement("div");i.id=this.editorId,i.style.height="100%",i.style.width="100%",e.appendChild(i);const o=`script-${this.editorId}`;if(document.querySelector(`#${o}`))console.log("[OnlyOffice] Script already loaded"),this.instantiateEditor();else{console.log("[OnlyOffice] Loading script:",t);const e=document.createElement("script");e.id=o,e.src=t,e.onload=()=>{console.log("[OnlyOffice] Script loaded successfully"),console.log("[OnlyOffice] window.DocsAPI:",window.DocsAPI),this.instantiateEditor()},e.onerror=e=>{console.error("[OnlyOffice] Script load failed:",e)},document.head.appendChild(e)}return this}instantiateEditor(){if(console.log("[OnlyOffice] instantiateEditor called"),this.editor&&(this.editor.destroyEditor(),this.editor=null),!window.DocsAPI||!window.DocsAPI.DocEditor)return void console.error("[OnlyOffice] window.DocsAPI.DocEditor is not available");const e={width:this.width,height:this.height,documentType:this.getDocumentType(),document:this.documentConfig,editorConfig:this.editorConfig,events:this.createEventHandlers()};console.log("[OnlyOffice] Creating editor with config:",e),console.log("[OnlyOffice] Editor container ID:",this.editorId),console.log("[OnlyOffice] Container element:",document.getElementById(this.editorId));try{this.editor=new window.DocsAPI.DocEditor(this.editorId,e),console.log("[OnlyOffice] Editor created successfully:",this.editor)}catch(e){console.error("[OnlyOffice] Error creating editor:",e)}}getDocumentType(){const e=l(this.documentConfig.fileType);return"other"===e?"word":e}createEventHandlers(){return{onDocumentStateChange:e=>{this.emitter.emit("documentStateChange",e)},onDocumentReady:()=>{var e,t;console.log("Document is loaded"),this.editorConfig.callbackUrl&&d(this.editorConfig.callbackUrl,{status:8,key:this.documentConfig.key,userdata:JSON.stringify({appUserId:null===(e=this.editorConfig.user)||void 0===e?void 0:e.id})}),null===(t=this.callback)||void 0===t||t.call(this,"onDocumentReady"),this.emitter.emit("onDocumentReady")},onInfo:e=>{var t;console.log("ONLYOFFICE Document Editor is opened in mode",e.data.mode),null===(t=this.callback)||void 0===t||t.call(this,"onInfo",e.data),this.emitter.emit("onInfo",e)},onError:e=>{console.error("ONLYOFFICE Error:",e.data.errorCode,e.data.errorDescription),this.emitter.emit("onError",e)},onRequestHistory:e=>{var t;null===(t=this.callback)||void 0===t||t.call(this,"onRequestHistory",e,this.editor),this.emitter.emit("onRequestHistory",{event:e,editor:this.editor})},onRequestHistoryData:e=>{var t;null===(t=this.callback)||void 0===t||t.call(this,"onRequestHistoryData",e,this.editor),this.emitter.emit("onRequestHistoryData",{event:e,editor:this.editor})},onRequestHistoryClose:e=>{var t;null===(t=this.callback)||void 0===t||t.call(this,"onRequestHistoryClose",e,this.editor),this.emitter.emit("onRequestHistoryClose",{event:e,editor:this.editor})},onRequestRestore:e=>{var t;null===(t=this.callback)||void 0===t||t.call(this,"onRequestRestore",e,this.editor),this.emitter.emit("onRequestRestore",{event:e,editor:this.editor})},onRequestSendNotify:e=>{console.log("onRequestSendNotify",e),this.emitter.emit("onRequestSendNotify",e)},onRequestUsers:e=>{console.log("onRequestUsers",e),this.emitter.emit("onRequestUsers",e)}}}on(e,t){this.emitter.on(e,t)}off(e,t){this.emitter.off(e,t)}getConfig(){return{...this.documentConfig,...this.editorConfig}}getEditor(){return this.editor}destroy(){this.editor&&(this.editor.destroyEditor(),this.editor=null),this.emitter.removeAllListeners(),this.callback=null}}const y=e({name:"OnlyOfficeEditor",props:{officeApiUrl:{type:String,required:!0},document:{type:Object,required:!0},auth:{type:Object,default:void 0},verifyFunction:{type:Function,default:void 0},skipVerification:{type:Boolean,default:!1},height:{type:String,default:"100%"},width:{type:String,default:"100%"}},emits:["ready","error","documentStateChange","requestHistory","requestHistoryData","requestHistoryClose","requestRestore"],setup(e,{emit:r}){const s=t(null),l=t(null),c=t(!1),a=t(null),d=async()=>{if(console.log("[OnlyOffice Component] initEditor called"),console.log("[OnlyOffice Component] containerRef.value:",s.value),s.value)try{console.log("[OnlyOffice Component] Creating OfficeEditor instance");const t=new h;t.configure({...e.document,height:e.height,width:e.width});const i=(e,t,i)=>{switch(e){case"onDocumentReady":c.value=!0,r("ready",i);break;case"onInfo":break;case"onRequestHistory":r("requestHistory",{event:t,editor:i});break;case"onRequestHistoryData":r("requestHistoryData",{event:t,editor:i});break;case"onRequestHistoryClose":r("requestHistoryClose",{event:t,editor:i});break;case"onRequestRestore":r("requestRestore",{event:t,editor:i})}};if(e.skipVerification||!e.auth&&!e.verifyFunction)l.value=t.init(s.value,e.officeApiUrl,i);else{const o={dom:s.value,officeApiUrl:e.officeApiUrl,callback:i,auth:e.auth,verifyFunction:e.verifyFunction};l.value=await t.initOffice(o)}t.on("onError",e=>{var t;a.value=(null===(t=e.data)||void 0===t?void 0:t.errorDescription)||"编辑器错误",r("error",e)}),t.on("documentStateChange",e=>{r("documentStateChange",e)})}catch(e){a.value=e.message||"初始化失败",r("error",e)}else console.warn("[OnlyOffice Component] containerRef is null, cannot init editor")},u=()=>{l.value&&(l.value.destroy(),l.value=null,c.value=!1)};return i(()=>e.document,e=>{l.value&&e&&(u(),d())},{deep:!0}),o(()=>{console.log("[OnlyOffice Component] onMounted called"),console.log("[OnlyOffice Component] Props:",{officeApiUrl:e.officeApiUrl,document:e.document,skipVerification:e.skipVerification}),d()}),n(()=>{u()}),{containerRef:s,editorInstance:l,isReady:c,error:a}},template:'\n <div class="onlyoffice-editor-container" :style="{ width: width, height: height, position: \'relative\', minHeight: \'400px\' }">\n <div ref="containerRef" :style="{ width: \'100%\', height: \'100%\' }"></div>\n <div v-if="error" class="onlyoffice-error" style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: red; z-index: 10;">\n {{ error }}\n </div>\n </div>\n '});function m(e){const{officeApiUrl:r,document:s,auth:l,verifyFunction:c,height:a="100%",width:d="100%",autoInit:u=!0}=e,f=t(null),y=t(null),m=t(!1),p=t(null);let g=null;const v=async()=>{if(f.value)try{w(),g=new h,g.configure({...s,height:a,width:d});const e=(e,t,i)=>{if("onDocumentReady"===e)m.value=!0},t={dom:f.value,officeApiUrl:r,callback:e,auth:l,verifyFunction:c};y.value=await g.initOffice(t),g.on("onError",e=>{var t;p.value=(null===(t=e.data)||void 0===t?void 0:t.errorDescription)||"编辑器错误"})}catch(e){p.value=e.message||"初始化失败"}else p.value="容器元素未找到"},w=()=>{g&&(g.destroy(),g=null,y.value=null,m.value=!1)},O=async()=>{w(),await v()};return i(()=>s,async e=>{g&&e&&await O()},{deep:!0}),o(()=>{u&&v()}),n(()=>{w()}),{containerRef:f,editorInstance:y,isReady:m,error:p,init:v,destroy:w,reinit:O,on:(e,t)=>{g&&g.on(e,t)},off:(e,t)=>{g&&g.off(e,t)}}}function p(){return new h}async function g(e){return(new h).initOffice(e)}function v(e,t,i){return(new h).init(e,t,i)}async function w(e,t,i){const{saveSuccessInfo:o}=await Promise.resolve().then(function(){return u});await o(e,{status:10,key:t,userdata:JSON.stringify({appUserId:i})})}async function O(e,t,i){const{saveSuccessInfo:o}=await Promise.resolve().then(function(){return u});await o(e,{status:9,key:t,userdata:JSON.stringify({appUserId:i})})}export{y as OnlyOfficeEditor,p as createOfficeEditor,O as downloadSave,v as init,g as initOffice,w as shareSave,m as useOnlyOffice};
1
+ import{defineComponent as e,ref as t,watch as i,onMounted as o,nextTick as n,onBeforeUnmount as r}from"vue";import s from"eventemitter3";import l from"axios";function c(e){const t=e.toLowerCase();if(["doc","docx","odt","rtf","txt","html","epub"].includes(t))return"word";if(["xls","xlsx","ods","csv"].includes(t))return"cell";return["ppt","pptx","odp"].includes(t)?"slide":"pdf"===t?"pdf":"other"}class a{constructor(e=""){this.baseUrl=e}async post(e,t,i){const o=this.baseUrl?`${this.baseUrl}${e}`:e;return l.post(o,t,i)}async get(e,t){const i=this.baseUrl?`${this.baseUrl}${e}`:e;return l.get(i,t)}}async function d(e,t){var i;try{const o=new a(e);return!0===(null===(i=(await o.post("/onlyoffice/token/verifyTokenSign",t)).data)||void 0===i?void 0:i.data)}catch(e){return console.error("验签请求失败:",e),!1}}async function u(e,t){try{await l.post(e,t)}catch(e){console.error("保存操作信息失败:",e)}}var f=Object.freeze({__proto__:null,HttpClient:a,saveSuccessInfo:u,verifyTokenSign:d});const h={comment:!1,download:!1,edit:!1,print:!0,review:!1,editCommentAuthorOnly:!1,fillForms:!1,modifyContentControl:!1};class y{constructor(){this.editor=null,this.callback=null,this.height="100%",this.width="100%",this.editorId=`editor-${Date.now().toString(32)}`,this.emitter=new s,this.documentConfig={fileType:"docx",key:"",url:"",title:"",permissions:{...h}},this.editorConfig={lang:"zh",user:{id:"",name:""}}}configure(e){if(e.height&&(this.height=e.height),e.width&&(this.width=e.width),e.fileType){if("other"===c(e.fileType))throw new Error(`不支持的文件类型: ${e.fileType}`);"other"!==c(e.fileType)&&(this.documentConfig.fileType=e.fileType)}e.key&&(this.documentConfig.key=e.key),e.url&&(this.documentConfig.url=e.url),e.title&&(this.documentConfig.title=e.title),e.permissions&&(this.documentConfig.permissions={...this.documentConfig.permissions,...e.permissions},"pdf"===this.documentConfig.fileType&&(this.documentConfig.permissions.edit=!1,this.documentConfig.permissions.review=!1,this.editorConfig.mode="view")),e.callbackUrl&&(this.editorConfig.callbackUrl=e.callbackUrl),e.userId&&(this.editorConfig.user={...this.editorConfig.user,id:e.userId}),e.userName&&(this.editorConfig.user={...this.editorConfig.user,name:e.userName}),e.userGroup&&(this.editorConfig.user={...this.editorConfig.user,group:e.userGroup})}async initOffice(e){const{dom:t,officeApiUrl:i,callback:o,auth:n,verifyFunction:r}=e;if(o&&(this.callback=o),n){let e=!1;if(r)e=await r(n);else{if(!n.verifyUrl)throw new Error("使用验签配置时,必须提供 verifyFunction 或 verifyUrl");e=await d(n.verifyUrl,{appId:n.appId,sign:n.sign,timestamp:n.timestamp})}if(!e)throw new Error("验签失败,请检查验签配置")}return this.createEditor(t,i)}init(e,t,i){return i&&(this.callback=i),this.createEditor(e,t)}createEditor(e,t){if(console.log("[OnlyOffice] createEditor called",{dom:e,officeApiUrl:t}),!e)throw new Error("必须提供挂载的 DOM 元素");if(!t)throw new Error("必须提供 OnlyOffice API 脚本地址");e.style.position="relative",console.log("[OnlyOffice] DOM dimensions:",{width:e.offsetWidth,height:e.offsetHeight});const i=document.createElement("div");i.id=this.editorId,i.style.height="100%",i.style.width="100%",e.appendChild(i);const o=`script-${this.editorId}`;if(document.querySelector(`#${o}`))console.log("[OnlyOffice] Script already loaded"),this.instantiateEditor();else{console.log("[OnlyOffice] Loading script:",t);const e=document.createElement("script");e.id=o,e.src=t,e.onload=()=>{console.log("[OnlyOffice] Script loaded successfully"),console.log("[OnlyOffice] window.DocsAPI:",window.DocsAPI),this.instantiateEditor()},e.onerror=e=>{console.error("[OnlyOffice] Script load failed:",e)},document.head.appendChild(e)}return this}instantiateEditor(){if(console.log("[OnlyOffice] instantiateEditor called"),this.editor&&(this.editor.destroyEditor(),this.editor=null),!window.DocsAPI||!window.DocsAPI.DocEditor)return void console.error("[OnlyOffice] window.DocsAPI.DocEditor is not available");const e={width:this.width,height:this.height,documentType:this.getDocumentType(),document:this.documentConfig,editorConfig:this.editorConfig,events:this.createEventHandlers()};console.log("[OnlyOffice] Creating editor with config:",e),console.log("[OnlyOffice] Editor container ID:",this.editorId),console.log("[OnlyOffice] Container element:",document.getElementById(this.editorId));try{this.editor=new window.DocsAPI.DocEditor(this.editorId,e),console.log("[OnlyOffice] Editor created successfully:",this.editor)}catch(e){console.error("[OnlyOffice] Error creating editor:",e)}}getDocumentType(){const e=c(this.documentConfig.fileType);return"other"===e?"word":e}createEventHandlers(){return{onDocumentStateChange:e=>{this.emitter.emit("documentStateChange",e)},onDocumentReady:()=>{var e,t;console.log("Document is loaded"),this.editorConfig.callbackUrl&&u(this.editorConfig.callbackUrl,{status:8,key:this.documentConfig.key,userdata:JSON.stringify({appUserId:null===(e=this.editorConfig.user)||void 0===e?void 0:e.id})}),null===(t=this.callback)||void 0===t||t.call(this,"onDocumentReady"),this.emitter.emit("onDocumentReady")},onInfo:e=>{var t;console.log("ONLYOFFICE Document Editor is opened in mode",e.data.mode),null===(t=this.callback)||void 0===t||t.call(this,"onInfo",e.data),this.emitter.emit("onInfo",e)},onError:e=>{console.error("ONLYOFFICE Error:",e.data.errorCode,e.data.errorDescription),this.emitter.emit("onError",e)},onRequestHistory:e=>{var t;null===(t=this.callback)||void 0===t||t.call(this,"onRequestHistory",e,this.editor),this.emitter.emit("onRequestHistory",{event:e,editor:this.editor})},onRequestHistoryData:e=>{var t;null===(t=this.callback)||void 0===t||t.call(this,"onRequestHistoryData",e,this.editor),this.emitter.emit("onRequestHistoryData",{event:e,editor:this.editor})},onRequestHistoryClose:e=>{var t;null===(t=this.callback)||void 0===t||t.call(this,"onRequestHistoryClose",e,this.editor),this.emitter.emit("onRequestHistoryClose",{event:e,editor:this.editor})},onRequestRestore:e=>{var t;null===(t=this.callback)||void 0===t||t.call(this,"onRequestRestore",e,this.editor),this.emitter.emit("onRequestRestore",{event:e,editor:this.editor})},onRequestSendNotify:e=>{console.log("onRequestSendNotify",e),this.emitter.emit("onRequestSendNotify",e)},onRequestUsers:e=>{console.log("onRequestUsers",e),this.emitter.emit("onRequestUsers",e)}}}on(e,t){this.emitter.on(e,t)}off(e,t){this.emitter.off(e,t)}getConfig(){return{...this.documentConfig,...this.editorConfig}}getEditor(){return this.editor}destroy(){this.editor&&(this.editor.destroyEditor(),this.editor=null),this.emitter.removeAllListeners(),this.callback=null}}const m=e({name:"OnlyOfficeEditor",props:{officeApiUrl:{type:String,required:!0},document:{type:Object,required:!0},auth:{type:Object,default:void 0},verifyFunction:{type:Function,default:void 0},skipVerification:{type:Boolean,default:!1},height:{type:String,default:"100%"},width:{type:String,default:"100%"}},emits:["ready","error","documentStateChange","requestHistory","requestHistoryData","requestHistoryClose","requestRestore"],setup(e,{emit:s}){const l=t(null),c=t(null),a=t(!1),d=t(null),u=async()=>{if(console.log("[OnlyOffice Component] initEditor called"),console.log("[OnlyOffice Component] containerRef.value:",l.value),!l.value){console.warn("[OnlyOffice Component] containerRef is null, cannot init editor");const e=document.querySelector(".onlyoffice-editor-container > div:first-child");if(console.log("[OnlyOffice Component] Trying to find container by selector:",e),!e)return;l.value=e}try{console.log("[OnlyOffice Component] Container dimensions:",{width:l.value.offsetWidth,height:l.value.offsetHeight,clientWidth:l.value.clientWidth,clientHeight:l.value.clientHeight});const t=new y;t.configure({...e.document,height:e.height,width:e.width});const i=(e,t,i)=>{switch(e){case"onDocumentReady":a.value=!0,s("ready",i);break;case"onInfo":break;case"onRequestHistory":s("requestHistory",{event:t,editor:i});break;case"onRequestHistoryData":s("requestHistoryData",{event:t,editor:i});break;case"onRequestHistoryClose":s("requestHistoryClose",{event:t,editor:i});break;case"onRequestRestore":s("requestRestore",{event:t,editor:i})}};if(e.skipVerification||!e.auth&&!e.verifyFunction)c.value=t.init(l.value,e.officeApiUrl,i);else{const o={dom:l.value,officeApiUrl:e.officeApiUrl,callback:i,auth:e.auth,verifyFunction:e.verifyFunction};c.value=await t.initOffice(o)}t.on("onError",e=>{var t;d.value=(null===(t=e.data)||void 0===t?void 0:t.errorDescription)||"编辑器错误",s("error",e)}),t.on("documentStateChange",e=>{s("documentStateChange",e)})}catch(e){d.value=e.message||"初始化失败",s("error",e)}},f=()=>{c.value&&(c.value.destroy(),c.value=null,a.value=!1)};return i(()=>e.document,e=>{c.value&&e&&(f(),u())},{deep:!0}),o(async()=>{console.log("[OnlyOffice Component] onMounted called"),console.log("[OnlyOffice Component] Props:",{officeApiUrl:e.officeApiUrl,document:e.document,skipVerification:e.skipVerification}),await n(),console.log("[OnlyOffice Component] After nextTick, containerRef.value:",l.value),l.value?u():(console.log("[OnlyOffice Component] containerRef still null, retrying with setTimeout"),setTimeout(()=>{console.log("[OnlyOffice Component] After setTimeout, containerRef.value:",l.value),u()},100))}),r(()=>{f()}),{containerRef:l,editorInstance:c,isReady:a,error:d}},template:'\n <div class="onlyoffice-editor-container" :style="{ width: width, height: height, position: \'relative\', minHeight: \'400px\' }">\n <div ref="containerRef" :style="{ width: \'100%\', height: \'100%\' }"></div>\n <div v-if="error" class="onlyoffice-error" style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: red; z-index: 10;">\n {{ error }}\n </div>\n </div>\n '});function g(e){const{officeApiUrl:n,document:s,auth:l,verifyFunction:c,height:a="100%",width:d="100%",autoInit:u=!0}=e,f=t(null),h=t(null),m=t(!1),g=t(null);let p=null;const v=async()=>{if(f.value)try{w(),p=new y,p.configure({...s,height:a,width:d});const e=(e,t,i)=>{if("onDocumentReady"===e)m.value=!0},t={dom:f.value,officeApiUrl:n,callback:e,auth:l,verifyFunction:c};h.value=await p.initOffice(t),p.on("onError",e=>{var t;g.value=(null===(t=e.data)||void 0===t?void 0:t.errorDescription)||"编辑器错误"})}catch(e){g.value=e.message||"初始化失败"}else g.value="容器元素未找到"},w=()=>{p&&(p.destroy(),p=null,h.value=null,m.value=!1)},O=async()=>{w(),await v()};return i(()=>s,async e=>{p&&e&&await O()},{deep:!0}),o(()=>{u&&v()}),r(()=>{w()}),{containerRef:f,editorInstance:h,isReady:m,error:g,init:v,destroy:w,reinit:O,on:(e,t)=>{p&&p.on(e,t)},off:(e,t)=>{p&&p.off(e,t)}}}function p(){return new y}async function v(e){return(new y).initOffice(e)}function w(e,t,i){return(new y).init(e,t,i)}async function O(e,t,i){const{saveSuccessInfo:o}=await Promise.resolve().then(function(){return f});await o(e,{status:10,key:t,userdata:JSON.stringify({appUserId:i})})}async function C(e,t,i){const{saveSuccessInfo:o}=await Promise.resolve().then(function(){return f});await o(e,{status:9,key:t,userdata:JSON.stringify({appUserId:i})})}export{m as OnlyOfficeEditor,p as createOfficeEditor,C as downloadSave,w as init,v as initOffice,O as shareSave,g as useOnlyOffice};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../src/core/utils/fileType.ts","../../../src/core/utils/http.ts","../../../src/core/editor.ts","../../../src/vue3/component.ts","../../../src/vue3/useOnlyOffice.ts","../../../src/core/index.ts"],"sourcesContent":["import type { DocumentType, FileType } from '../../types';\n\n/**\n * 根据文件扩展名获取 OnlyOffice 文档类型\n * @param fileType 文件扩展名\n * @returns 文档类型\n */\nexport function getDocumentType(fileType: FileType | string): DocumentType | 'other' {\n const type = fileType.toLowerCase();\n\n // 文档类型\n const wordTypes = ['doc', 'docx', 'odt', 'rtf', 'txt', 'html', 'epub'];\n if (wordTypes.includes(type)) {\n return 'word';\n }\n\n // 表格类型\n const cellTypes = ['xls', 'xlsx', 'ods', 'csv'];\n if (cellTypes.includes(type)) {\n return 'cell';\n }\n\n // 演示类型\n const slideTypes = ['ppt', 'pptx', 'odp'];\n if (slideTypes.includes(type)) {\n return 'slide';\n }\n\n // PDF 类型\n if (type === 'pdf') {\n return 'pdf';\n }\n\n return 'other';\n}\n\n/**\n * 检查文件类型是否受支持\n * @param fileType 文件扩展名\n * @returns 是否支持\n */\nexport function isSupportedFileType(fileType: string): boolean {\n return getDocumentType(fileType) !== 'other';\n}","import axios, { type AxiosRequestConfig, type AxiosResponse } from 'axios';\n\n/**\n * HTTP 请求工具\n */\nexport class HttpClient {\n private baseUrl: string;\n\n constructor(baseUrl: string = '') {\n this.baseUrl = baseUrl;\n }\n\n /**\n * 发送 POST 请求\n * @param url 请求地址\n * @param data 请求数据\n * @param config 额外配置\n * @returns Promise\n */\n async post<T = any>(\n url: string,\n data?: any,\n config?: AxiosRequestConfig\n ): Promise<AxiosResponse<T>> {\n const fullUrl = this.baseUrl ? `${this.baseUrl}${url}` : url;\n return axios.post<T>(fullUrl, data, config);\n }\n\n /**\n * 发送 GET 请求\n * @param url 请求地址\n * @param config 额外配置\n * @returns Promise\n */\n async get<T = any>(\n url: string,\n config?: AxiosRequestConfig\n ): Promise<AxiosResponse<T>> {\n const fullUrl = this.baseUrl ? `${this.baseUrl}${url}` : url;\n return axios.get<T>(fullUrl, config);\n }\n}\n\n/**\n * 验签接口请求\n * @param baseUrl 基础 URL\n * @param data 验签数据\n * @returns 验签结果\n */\nexport async function verifyTokenSign(\n baseUrl: string,\n data: {\n appId: string;\n sign: string;\n timestamp: number;\n }\n): Promise<boolean> {\n try {\n const client = new HttpClient(baseUrl);\n const response = await client.post<{ data: boolean }>(\n '/onlyoffice/token/verifyTokenSign',\n data\n );\n return response.data?.data === true;\n } catch (error) {\n console.error('验签请求失败:', error);\n return false;\n }\n}\n\n/**\n * 保存操作信息\n * @param callbackUrl 回调地址\n * @param data 操作数据\n */\nexport async function saveSuccessInfo(\n callbackUrl: string,\n data: {\n status: number;\n key: string;\n userdata: string;\n }\n): Promise<void> {\n try {\n await axios.post(callbackUrl, data);\n } catch (error) {\n console.error('保存操作信息失败:', error);\n }\n}","import EventEmitter from 'eventemitter3';\nimport type {\n DocumentConfig,\n EditorConfig,\n DocumentPermissions,\n OfficeEventType,\n OfficeCallback,\n OfficeEditorInstance,\n OfficeDocumentConfig,\n OfficeInitConfig,\n AuthConfig,\n VerifyTokenSignFunction,\n} from '../types';\nimport { getDocumentType, isSupportedFileType } from './utils/fileType';\nimport { verifyTokenSign, saveSuccessInfo } from './utils/http';\n\n/**\n * 默认文档权限\n */\nconst DEFAULT_PERMISSIONS: DocumentPermissions = {\n comment: false,\n download: false,\n edit: false,\n print: true,\n review: false,\n editCommentAuthorOnly: false,\n fillForms: false,\n modifyContentControl: false,\n};\n\n/**\n * OnlyOffice 编辑器管理类\n */\nexport class OfficeEditor implements OfficeEditorInstance {\n private editor: any = null;\n private editorId: string;\n private emitter: EventEmitter;\n private documentConfig: DocumentConfig;\n private editorConfig: EditorConfig;\n private callback: OfficeCallback | null = null;\n private height: string = '100%';\n private width: string = '100%';\n\n constructor() {\n this.editorId = `editor-${Date.now().toString(32)}`;\n this.emitter = new EventEmitter();\n this.documentConfig = {\n fileType: 'docx',\n key: '',\n url: '',\n title: '',\n permissions: { ...DEFAULT_PERMISSIONS },\n };\n this.editorConfig = {\n lang: 'zh',\n user: { id: '', name: '' },\n };\n }\n\n /**\n * 配置文档参数\n */\n configure(config: OfficeDocumentConfig): void {\n if (config.height) this.height = config.height;\n if (config.width) this.width = config.width;\n\n if (config.fileType) {\n if (!isSupportedFileType(config.fileType)) {\n throw new Error(`不支持的文件类型: ${config.fileType}`);\n }\n const docType = getDocumentType(config.fileType);\n if (docType !== 'other') {\n this.documentConfig.fileType = config.fileType;\n }\n }\n\n if (config.key) this.documentConfig.key = config.key;\n if (config.url) this.documentConfig.url = config.url;\n if (config.title) this.documentConfig.title = config.title;\n\n if (config.permissions) {\n this.documentConfig.permissions = {\n ...this.documentConfig.permissions,\n ...config.permissions,\n };\n\n // PDF 文件特殊处理\n if (this.documentConfig.fileType === 'pdf') {\n this.documentConfig.permissions.edit = false;\n this.documentConfig.permissions.review = false;\n this.editorConfig.mode = 'view';\n }\n }\n\n if (config.callbackUrl) this.editorConfig.callbackUrl = config.callbackUrl;\n if (config.userId) {\n this.editorConfig.user = {\n ...this.editorConfig.user,\n id: config.userId,\n };\n }\n if (config.userName) {\n this.editorConfig.user = {\n ...this.editorConfig.user,\n name: config.userName,\n };\n }\n if (config.userGroup) {\n this.editorConfig.user = {\n ...this.editorConfig.user,\n group: config.userGroup,\n };\n }\n }\n\n /**\n * 初始化编辑器(带验签)\n */\n async initOffice(config: OfficeInitConfig): Promise<OfficeEditorInstance> {\n const { dom, officeApiUrl, callback, auth, verifyFunction } = config;\n\n if (callback) this.callback = callback;\n\n // 验签逻辑\n if (auth) {\n let verified = false;\n\n if (verifyFunction) {\n // 使用自定义验签函数\n verified = await verifyFunction(auth);\n } else if (auth.verifyUrl) {\n // 使用自定义验签地址\n verified = await verifyTokenSign(auth.verifyUrl, {\n appId: auth.appId,\n sign: auth.sign,\n timestamp: auth.timestamp,\n });\n } else {\n throw new Error('使用验签配置时,必须提供 verifyFunction 或 verifyUrl');\n }\n\n if (!verified) {\n throw new Error('验签失败,请检查验签配置');\n }\n }\n\n return this.createEditor(dom, officeApiUrl);\n }\n\n /**\n * 简化初始化(无验签)\n */\n init(\n dom: HTMLElement,\n officeApiUrl: string,\n callback?: OfficeCallback\n ): OfficeEditorInstance {\n if (callback) this.callback = callback;\n return this.createEditor(dom, officeApiUrl);\n }\n\n /**\n * 创建编辑器实例\n */\n private createEditor(dom: HTMLElement, officeApiUrl: string): OfficeEditorInstance {\n console.log('[OnlyOffice] createEditor called', { dom, officeApiUrl });\n\n if (!dom) {\n throw new Error('必须提供挂载的 DOM 元素');\n }\n\n if (!officeApiUrl) {\n throw new Error('必须提供 OnlyOffice API 脚本地址');\n }\n\n // 设置容器样式\n dom.style.position = 'relative';\n console.log('[OnlyOffice] DOM dimensions:', { width: dom.offsetWidth, height: dom.offsetHeight });\n\n // 创建编辑器容器\n const mainDiv = document.createElement('div');\n mainDiv.id = this.editorId;\n mainDiv.style.height = '100%';\n mainDiv.style.width = '100%';\n dom.appendChild(mainDiv);\n\n // 动态加载 OnlyOffice API 脚本\n const scriptId = `script-${this.editorId}`;\n const existingScript = document.querySelector(`#${scriptId}`);\n\n if (!existingScript) {\n console.log('[OnlyOffice] Loading script:', officeApiUrl);\n const script = document.createElement('script');\n script.id = scriptId;\n script.src = officeApiUrl;\n script.onload = () => {\n console.log('[OnlyOffice] Script loaded successfully');\n console.log('[OnlyOffice] window.DocsAPI:', window.DocsAPI);\n this.instantiateEditor();\n };\n script.onerror = (err) => {\n console.error('[OnlyOffice] Script load failed:', err);\n };\n document.head.appendChild(script);\n } else {\n console.log('[OnlyOffice] Script already loaded');\n this.instantiateEditor();\n }\n\n return this;\n }\n\n /**\n * 实例化编辑器\n */\n private instantiateEditor(): void {\n console.log('[OnlyOffice] instantiateEditor called');\n\n // 销毁现有实例\n if (this.editor) {\n this.editor.destroyEditor();\n this.editor = null;\n }\n\n // 检查 DocsAPI 是否可用\n if (!window.DocsAPI || !window.DocsAPI.DocEditor) {\n console.error('[OnlyOffice] window.DocsAPI.DocEditor is not available');\n return;\n }\n\n // 构建配置对象\n const config = {\n width: this.width,\n height: this.height,\n documentType: this.getDocumentType(),\n document: this.documentConfig,\n editorConfig: this.editorConfig,\n events: this.createEventHandlers(),\n };\n\n console.log('[OnlyOffice] Creating editor with config:', config);\n console.log('[OnlyOffice] Editor container ID:', this.editorId);\n console.log('[OnlyOffice] Container element:', document.getElementById(this.editorId));\n\n // 创建编辑器实例\n try {\n this.editor = new window.DocsAPI.DocEditor(this.editorId, config);\n console.log('[OnlyOffice] Editor created successfully:', this.editor);\n } catch (err) {\n console.error('[OnlyOffice] Error creating editor:', err);\n }\n }\n\n /**\n * 获取文档类型\n */\n private getDocumentType(): string {\n const type = getDocumentType(this.documentConfig.fileType);\n return type === 'other' ? 'word' : type;\n }\n\n /**\n * 创建事件处理器\n */\n private createEventHandlers(): Record<string, (event: any) => void> {\n return {\n onDocumentStateChange: (event: any) => {\n this.emitter.emit('documentStateChange', event);\n },\n onDocumentReady: () => {\n console.log('Document is loaded');\n // 通知后端文档加载成功\n if (this.editorConfig.callbackUrl) {\n saveSuccessInfo(this.editorConfig.callbackUrl, {\n status: 8,\n key: this.documentConfig.key,\n userdata: JSON.stringify({\n appUserId: this.editorConfig.user?.id,\n }),\n });\n }\n this.callback?.('onDocumentReady');\n this.emitter.emit('onDocumentReady');\n },\n onInfo: (event: any) => {\n console.log('ONLYOFFICE Document Editor is opened in mode', event.data.mode);\n this.callback?.('onInfo', event.data);\n this.emitter.emit('onInfo', event);\n },\n onError: (event: any) => {\n console.error('ONLYOFFICE Error:', event.data.errorCode, event.data.errorDescription);\n this.emitter.emit('onError', event);\n },\n onRequestHistory: (event: any) => {\n this.callback?.('onRequestHistory', event, this.editor);\n this.emitter.emit('onRequestHistory', { event, editor: this.editor });\n },\n onRequestHistoryData: (event: any) => {\n this.callback?.('onRequestHistoryData', event, this.editor);\n this.emitter.emit('onRequestHistoryData', { event, editor: this.editor });\n },\n onRequestHistoryClose: (event: any) => {\n this.callback?.('onRequestHistoryClose', event, this.editor);\n this.emitter.emit('onRequestHistoryClose', { event, editor: this.editor });\n },\n onRequestRestore: (event: any) => {\n this.callback?.('onRequestRestore', event, this.editor);\n this.emitter.emit('onRequestRestore', { event, editor: this.editor });\n },\n onRequestSendNotify: (event: any) => {\n console.log('onRequestSendNotify', event);\n this.emitter.emit('onRequestSendNotify', event);\n },\n onRequestUsers: (event: any) => {\n console.log('onRequestUsers', event);\n this.emitter.emit('onRequestUsers', event);\n },\n };\n }\n\n /**\n * 监听事件\n */\n on(event: OfficeEventType, callback: (...args: any[]) => void): void {\n this.emitter.on(event, callback);\n }\n\n /**\n * 移除事件监听\n */\n off(event: OfficeEventType, callback: (...args: any[]) => void): void {\n this.emitter.off(event, callback);\n }\n\n /**\n * 获取当前配置\n */\n getConfig(): DocumentConfig & EditorConfig {\n return {\n ...this.documentConfig,\n ...this.editorConfig,\n };\n }\n\n /**\n * 获取内部编辑器实例\n */\n getEditor(): any {\n return this.editor;\n }\n\n /**\n * 销毁编辑器\n */\n destroy(): void {\n if (this.editor) {\n this.editor.destroyEditor();\n this.editor = null;\n }\n this.emitter.removeAllListeners();\n this.callback = null;\n }\n}","import {\n defineComponent,\n ref,\n onMounted,\n onBeforeUnmount,\n watch,\n type PropType,\n type Ref,\n} from 'vue';\nimport { OfficeEditor } from '../core/editor';\nimport type {\n OfficeDocumentConfig,\n OfficeInitConfig,\n OfficeCallback,\n OfficeEventType,\n AuthConfig,\n VerifyTokenSignFunction,\n OfficeEditorInstance,\n} from '../types';\n\n/**\n * OnlyOffice 编辑器 Vue 3 组件\n */\nexport const OnlyOfficeEditor = defineComponent({\n name: 'OnlyOfficeEditor',\n\n props: {\n /** OnlyOffice API 脚本地址 */\n officeApiUrl: {\n type: String,\n required: true,\n },\n /** 文档配置 */\n document: {\n type: Object as PropType<OfficeDocumentConfig>,\n required: true,\n },\n /** 验签配置 */\n auth: {\n type: Object as PropType<AuthConfig>,\n default: undefined,\n },\n /** 自定义验签函数 */\n verifyFunction: {\n type: Function as PropType<VerifyTokenSignFunction>,\n default: undefined,\n },\n /** 是否跳过验签(当 auth 已通过外部验签时使用) */\n skipVerification: {\n type: Boolean,\n default: false,\n },\n /** 编辑器高度 */\n height: {\n type: String,\n default: '100%',\n },\n /** 编辑器宽度 */\n width: {\n type: String,\n default: '100%',\n },\n },\n\n emits: [\n 'ready',\n 'error',\n 'documentStateChange',\n 'requestHistory',\n 'requestHistoryData',\n 'requestHistoryClose',\n 'requestRestore',\n ],\n\n setup(props: any, { emit }: any) {\n const containerRef: Ref<HTMLElement | null> = ref(null);\n const editorInstance: Ref<OfficeEditorInstance | null> = ref(null);\n const isReady: Ref<boolean> = ref(false);\n const error: Ref<string | null> = ref(null);\n\n /**\n * 初始化编辑器\n */\n const initEditor = async () => {\n console.log('[OnlyOffice Component] initEditor called');\n console.log('[OnlyOffice Component] containerRef.value:', containerRef.value);\n\n if (!containerRef.value) {\n console.warn('[OnlyOffice Component] containerRef is null, cannot init editor');\n return;\n }\n\n try {\n console.log('[OnlyOffice Component] Creating OfficeEditor instance');\n const editor = new OfficeEditor();\n\n // 配置文档参数\n editor.configure({\n ...props.document,\n height: props.height,\n width: props.width,\n });\n\n // 事件回调\n const callback: OfficeCallback = (type, event, editorInst) => {\n switch (type) {\n case 'onDocumentReady':\n isReady.value = true;\n emit('ready', editorInst);\n break;\n case 'onInfo':\n break;\n case 'onRequestHistory':\n emit('requestHistory', { event, editor: editorInst });\n break;\n case 'onRequestHistoryData':\n emit('requestHistoryData', { event, editor: editorInst });\n break;\n case 'onRequestHistoryClose':\n emit('requestHistoryClose', { event, editor: editorInst });\n break;\n case 'onRequestRestore':\n emit('requestRestore', { event, editor: editorInst });\n break;\n }\n };\n\n // 判断初始化方式\n if (props.skipVerification || (!props.auth && !props.verifyFunction)) {\n // 跳过验签或无验签配置:直接初始化\n editorInstance.value = editor.init(\n containerRef.value,\n props.officeApiUrl,\n callback\n );\n } else {\n // 带验签初始化\n const initConfig: OfficeInitConfig = {\n dom: containerRef.value,\n officeApiUrl: props.officeApiUrl,\n callback,\n auth: props.auth,\n verifyFunction: props.verifyFunction,\n };\n editorInstance.value = await editor.initOffice(initConfig);\n }\n\n // 监听错误事件\n editor.on('onError' as OfficeEventType, (event: any) => {\n error.value = event.data?.errorDescription || '编辑器错误';\n emit('error', event);\n });\n\n // 监听文档状态变化\n editor.on('documentStateChange' as OfficeEventType, (event: any) => {\n emit('documentStateChange', event);\n });\n } catch (err: any) {\n error.value = err.message || '初始化失败';\n emit('error', err);\n }\n };\n\n /**\n * 销毁编辑器\n */\n const destroyEditor = () => {\n if (editorInstance.value) {\n editorInstance.value.destroy();\n editorInstance.value = null;\n isReady.value = false;\n }\n };\n\n // 监听文档配置变化\n watch(\n () => props.document,\n (newDoc: any) => {\n if (editorInstance.value && newDoc) {\n // 重新初始化编辑器\n destroyEditor();\n initEditor();\n }\n },\n { deep: true }\n );\n\n // 组件挂载时初始化\n onMounted(() => {\n console.log('[OnlyOffice Component] onMounted called');\n console.log('[OnlyOffice Component] Props:', {\n officeApiUrl: props.officeApiUrl,\n document: props.document,\n skipVerification: props.skipVerification\n });\n initEditor();\n });\n\n // 组件销毁前清理\n onBeforeUnmount(() => {\n destroyEditor();\n });\n\n return {\n containerRef,\n editorInstance,\n isReady,\n error,\n };\n },\n\n template: `\n <div class=\"onlyoffice-editor-container\" :style=\"{ width: width, height: height, position: 'relative', minHeight: '400px' }\">\n <div ref=\"containerRef\" :style=\"{ width: '100%', height: '100%' }\"></div>\n <div v-if=\"error\" class=\"onlyoffice-error\" style=\"position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: red; z-index: 10;\">\n {{ error }}\n </div>\n </div>\n `,\n});\n\nexport default OnlyOfficeEditor;","import { ref, onMounted, onBeforeUnmount, watch, type Ref } from 'vue';\nimport { OfficeEditor } from '../core/editor';\nimport type {\n OfficeDocumentConfig,\n OfficeInitConfig,\n OfficeCallback,\n OfficeEventType,\n AuthConfig,\n VerifyTokenSignFunction,\n OfficeEditorInstance,\n} from '../types';\n\n/**\n * useOnlyOffice 配置选项\n */\nexport interface UseOnlyOfficeOptions {\n /** OnlyOffice API 脚本地址 */\n officeApiUrl: string;\n /** 文档配置 */\n document: OfficeDocumentConfig;\n /** 验签配置 */\n auth?: AuthConfig;\n /** 自定义验签函数 */\n verifyFunction?: VerifyTokenSignFunction;\n /** 编辑器高度 */\n height?: string;\n /** 编辑器宽度 */\n width?: string;\n /** 是否自动初始化 */\n autoInit?: boolean;\n}\n\n/**\n * useOnlyOffice 返回值\n */\nexport interface UseOnlyOfficeReturn {\n /** 容器元素引用 */\n containerRef: Ref<HTMLElement | null>;\n /** 编辑器实例 */\n editorInstance: Ref<OfficeEditorInstance | null>;\n /** 是否已就绪 */\n isReady: Ref<boolean>;\n /** 错误信息 */\n error: Ref<string | null>;\n /** 初始化编辑器 */\n init: () => Promise<void>;\n /** 销毁编辑器 */\n destroy: () => void;\n /** 重新初始化 */\n reinit: () => Promise<void>;\n /** 监听事件 */\n on: (event: OfficeEventType, callback: (...args: any[]) => void) => void;\n /** 移除事件监听 */\n off: (event: OfficeEventType, callback: (...args: any[]) => void) => void;\n}\n\n/**\n * OnlyOffice Vue 3 组合式函数\n * @param options 配置选项\n * @returns 编辑器状态和方法\n */\nexport function useOnlyOffice(options: UseOnlyOfficeOptions): UseOnlyOfficeReturn {\n const {\n officeApiUrl,\n document: documentConfig,\n auth,\n verifyFunction,\n height = '100%',\n width = '100%',\n autoInit = true,\n } = options;\n\n const containerRef: Ref<HTMLElement | null> = ref(null);\n const editorInstance: Ref<OfficeEditorInstance | null> = ref(null);\n const isReady: Ref<boolean> = ref(false);\n const error: Ref<string | null> = ref(null);\n\n let editor: OfficeEditor | null = null;\n\n /**\n * 初始化编辑器\n */\n const init = async () => {\n if (!containerRef.value) {\n error.value = '容器元素未找到';\n return;\n }\n\n try {\n // 销毁现有实例\n destroy();\n\n editor = new OfficeEditor();\n\n // 配置文档参数\n editor.configure({\n ...documentConfig,\n height,\n width,\n });\n\n // 事件回调\n const callback: OfficeCallback = (type, _event, _editorInst) => {\n switch (type) {\n case 'onDocumentReady':\n isReady.value = true;\n break;\n case 'onInfo':\n break;\n }\n };\n\n // 初始化配置\n const initConfig: OfficeInitConfig = {\n dom: containerRef.value,\n officeApiUrl,\n callback,\n auth,\n verifyFunction,\n };\n\n // 初始化编辑器\n editorInstance.value = await editor.initOffice(initConfig);\n\n // 监听错误事件\n editor.on('onError' as OfficeEventType, (event: any) => {\n error.value = event.data?.errorDescription || '编辑器错误';\n });\n } catch (err: any) {\n error.value = err.message || '初始化失败';\n }\n };\n\n /**\n * 销毁编辑器\n */\n const destroy = () => {\n if (editor) {\n editor.destroy();\n editor = null;\n editorInstance.value = null;\n isReady.value = false;\n }\n };\n\n /**\n * 重新初始化\n */\n const reinit = async () => {\n destroy();\n await init();\n };\n\n /**\n * 监听事件\n */\n const on = (event: OfficeEventType, callback: (...args: any[]) => void) => {\n if (editor) {\n editor.on(event, callback);\n }\n };\n\n /**\n * 移除事件监听\n */\n const off = (event: OfficeEventType, callback: (...args: any[]) => void) => {\n if (editor) {\n editor.off(event, callback);\n }\n };\n\n // 监听文档配置变化\n watch(\n () => documentConfig,\n async (newDoc: any) => {\n if (editor && newDoc) {\n await reinit();\n }\n },\n { deep: true }\n );\n\n // 组件挂载时初始化\n onMounted(() => {\n if (autoInit) {\n init();\n }\n });\n\n // 组件销毁前清理\n onBeforeUnmount(() => {\n destroy();\n });\n\n return {\n containerRef,\n editorInstance,\n isReady,\n error,\n init,\n destroy,\n reinit,\n on,\n off,\n };\n}\n\nexport default useOnlyOffice;","export { OfficeEditor } from './editor';\nexport { getDocumentType, isSupportedFileType } from './utils/fileType';\nexport { HttpClient, verifyTokenSign, saveSuccessInfo } from './utils/http';\n\n// 导出类型\nexport type {\n DocumentType,\n FileType,\n DocumentPermissions,\n UserInfo,\n DocumentConfig,\n EditorConfig,\n AuthConfig,\n VerifyTokenSignFunction,\n OfficeInitConfig,\n OfficeDocumentConfig,\n OfficeEventType,\n OfficeCallbackType,\n OfficeCallback,\n OfficeEditorInstance,\n OfficeSDK,\n} from '../types';\n\nimport { OfficeEditor } from './editor';\nimport type {\n OfficeDocumentConfig,\n OfficeInitConfig,\n OfficeCallback,\n OfficeEventType,\n OfficeEditorInstance,\n} from '../types';\n\n/**\n * 创建 Office 编辑器实例\n * @returns OfficeEditor 实例\n */\nexport function createOfficeEditor(): OfficeEditor {\n return new OfficeEditor();\n}\n\n/**\n * 快速初始化 Office 编辑器\n * @param config 初始化配置\n * @returns Promise<OfficeEditorInstance>\n */\nexport async function initOffice(config: OfficeInitConfig): Promise<OfficeEditorInstance> {\n const editor = new OfficeEditor();\n return editor.initOffice(config);\n}\n\n/**\n * 简化初始化(无验签)\n * @param dom 挂载的 DOM 元素\n * @param officeApiUrl OnlyOffice API 地址\n * @param callback 事件回调\n * @returns OfficeEditorInstance\n */\nexport function init(\n dom: HTMLElement,\n officeApiUrl: string,\n callback?: OfficeCallback\n): OfficeEditorInstance {\n const editor = new OfficeEditor();\n return editor.init(dom, officeApiUrl, callback);\n}\n\n/**\n * 配置文档参数(全局配置,需要先创建编辑器实例)\n * @deprecated 建议使用 OfficeEditor.configure() 方法\n */\nexport function config(_config: OfficeDocumentConfig): void {\n console.warn('此方法已废弃,请使用 OfficeEditor.configure() 方法');\n}\n\n/**\n * 销毁编辑器(全局方法,需要先创建编辑器实例)\n * @deprecated 建议使用 OfficeEditor.destroy() 方法\n */\nexport function destroy(): void {\n console.warn('此方法已废弃,请使用 OfficeEditor.destroy() 方法');\n}\n\n/**\n * 监听事件(全局方法,需要先创建编辑器实例)\n * @deprecated 建议使用 OfficeEditor.on() 方法\n */\nexport function on(_event: OfficeEventType, _callback: (...args: any[]) => void): void {\n console.warn('此方法已废弃,请使用 OfficeEditor.on() 方法');\n}\n\n/**\n * 记录分享动作\n * @param callbackUrl 回调地址\n * @param fileKey 文件标识\n * @param appUserId 用户 ID\n */\nexport async function shareSave(\n callbackUrl: string,\n fileKey: string,\n appUserId: string\n): Promise<void> {\n const { saveSuccessInfo } = await import('./utils/http');\n await saveSuccessInfo(callbackUrl, {\n status: 10,\n key: fileKey,\n userdata: JSON.stringify({ appUserId }),\n });\n}\n\n/**\n * 记录下载动作\n * @param callbackUrl 回调地址\n * @param fileKey 文件标识\n * @param appUserId 用户 ID\n */\nexport async function downloadSave(\n callbackUrl: string,\n fileKey: string,\n appUserId: string\n): Promise<void> {\n const { saveSuccessInfo } = await import('./utils/http');\n await saveSuccessInfo(callbackUrl, {\n status: 9,\n key: fileKey,\n userdata: JSON.stringify({ appUserId }),\n });\n}"],"names":["getDocumentType","fileType","type","toLowerCase","includes","HttpClient","constructor","baseUrl","this","post","url","data","config","fullUrl","axios","get","async","verifyTokenSign","client","_a","error","console","saveSuccessInfo","callbackUrl","DEFAULT_PERMISSIONS","comment","download","edit","print","review","editCommentAuthorOnly","fillForms","modifyContentControl","OfficeEditor","editor","callback","height","width","editorId","Date","now","toString","emitter","EventEmitter","documentConfig","key","title","permissions","editorConfig","lang","user","id","name","configure","Error","mode","userId","userName","userGroup","group","initOffice","dom","officeApiUrl","auth","verifyFunction","verified","verifyUrl","appId","sign","timestamp","createEditor","init","log","style","position","offsetWidth","offsetHeight","mainDiv","document","createElement","appendChild","scriptId","querySelector","instantiateEditor","script","src","onload","window","DocsAPI","onerror","err","head","destroyEditor","DocEditor","documentType","events","createEventHandlers","getElementById","onDocumentStateChange","event","emit","onDocumentReady","status","userdata","JSON","stringify","appUserId","_b","call","onInfo","onError","errorCode","errorDescription","onRequestHistory","onRequestHistoryData","onRequestHistoryClose","onRequestRestore","onRequestSendNotify","onRequestUsers","on","off","getConfig","getEditor","destroy","removeAllListeners","OnlyOfficeEditor","defineComponent","props","String","required","Object","default","undefined","Function","skipVerification","Boolean","emits","setup","containerRef","ref","editorInstance","isReady","initEditor","value","editorInst","initConfig","message","warn","watch","newDoc","deep","onMounted","onBeforeUnmount","template","useOnlyOffice","options","autoInit","_event","_editorInst","reinit","createOfficeEditor","shareSave","fileKey","Promise","resolve","then","http","downloadSave"],"mappings":"gJAOM,SAAUA,EAAgBC,GAC9B,MAAMC,EAAOD,EAASE,cAItB,GADkB,CAAC,MAAO,OAAQ,MAAO,MAAO,MAAO,OAAQ,QACjDC,SAASF,GACrB,MAAO,OAKT,GADkB,CAAC,MAAO,OAAQ,MAAO,OAC3BE,SAASF,GACrB,MAAO,OAKT,MADmB,CAAC,MAAO,OAAQ,OACpBE,SAASF,GACf,QAII,QAATA,EACK,MAGF,OACT,OC7BaG,EAGX,WAAAC,CAAYC,EAAkB,IAC5BC,KAAKD,QAAUA,CACjB,CASA,UAAME,CACJC,EACAC,EACAC,GAEA,MAAMC,EAAUL,KAAKD,QAAU,GAAGC,KAAKD,UAAUG,IAAQA,EACzD,OAAOI,EAAML,KAAQI,EAASF,EAAMC,EACtC,CAQA,SAAMG,CACJL,EACAE,GAEA,MAAMC,EAAUL,KAAKD,QAAU,GAAGC,KAAKD,UAAUG,IAAQA,EACzD,OAAOI,EAAMC,IAAOF,EAASD,EAC/B,EASKI,eAAeC,EACpBV,EACAI,SAMA,IACE,MAAMO,EAAS,IAAIb,EAAWE,GAK9B,OAA+B,KAAX,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ACA2I,EACAxD,GAEA,MAAMpF,gBAAEA,SAA0B6I,QAAAC,UAAAC,KAAA,WAAA,OAAAC,CAAA,SAC5BhJ,EAAgBC,EAAa,CACjC+E,OAAQ,GACRzD,IAAKqH,EACL3D,SAAUC,KAAKC,UAAU,CAAEC,eAE/B,CAQO1F,eAAeuJ,EACpBhJ,EACA2I,EACAxD,GAEA,MAAMpF,gBAAEA,SAA0B6I,QAAAC,UAAAC,KAAA,WAAA,OAAAC,CAAA,SAC5BhJ,EAAgBC,EAAa,CACjC+E,OAAQ,EACRzD,IAAKqH,EACL3D,SAAUC,KAAKC,UAAU,CAAEC,eAE/B"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../src/core/utils/fileType.ts","../../../src/core/utils/http.ts","../../../src/core/editor.ts","../../../src/vue3/component.ts","../../../src/vue3/useOnlyOffice.ts","../../../src/core/index.ts"],"sourcesContent":["import type { DocumentType, FileType } from '../../types';\n\n/**\n * 根据文件扩展名获取 OnlyOffice 文档类型\n * @param fileType 文件扩展名\n * @returns 文档类型\n */\nexport function getDocumentType(fileType: FileType | string): DocumentType | 'other' {\n const type = fileType.toLowerCase();\n\n // 文档类型\n const wordTypes = ['doc', 'docx', 'odt', 'rtf', 'txt', 'html', 'epub'];\n if (wordTypes.includes(type)) {\n return 'word';\n }\n\n // 表格类型\n const cellTypes = ['xls', 'xlsx', 'ods', 'csv'];\n if (cellTypes.includes(type)) {\n return 'cell';\n }\n\n // 演示类型\n const slideTypes = ['ppt', 'pptx', 'odp'];\n if (slideTypes.includes(type)) {\n return 'slide';\n }\n\n // PDF 类型\n if (type === 'pdf') {\n return 'pdf';\n }\n\n return 'other';\n}\n\n/**\n * 检查文件类型是否受支持\n * @param fileType 文件扩展名\n * @returns 是否支持\n */\nexport function isSupportedFileType(fileType: string): boolean {\n return getDocumentType(fileType) !== 'other';\n}","import axios, { type AxiosRequestConfig, type AxiosResponse } from 'axios';\n\n/**\n * HTTP 请求工具\n */\nexport class HttpClient {\n private baseUrl: string;\n\n constructor(baseUrl: string = '') {\n this.baseUrl = baseUrl;\n }\n\n /**\n * 发送 POST 请求\n * @param url 请求地址\n * @param data 请求数据\n * @param config 额外配置\n * @returns Promise\n */\n async post<T = any>(\n url: string,\n data?: any,\n config?: AxiosRequestConfig\n ): Promise<AxiosResponse<T>> {\n const fullUrl = this.baseUrl ? `${this.baseUrl}${url}` : url;\n return axios.post<T>(fullUrl, data, config);\n }\n\n /**\n * 发送 GET 请求\n * @param url 请求地址\n * @param config 额外配置\n * @returns Promise\n */\n async get<T = any>(\n url: string,\n config?: AxiosRequestConfig\n ): Promise<AxiosResponse<T>> {\n const fullUrl = this.baseUrl ? `${this.baseUrl}${url}` : url;\n return axios.get<T>(fullUrl, config);\n }\n}\n\n/**\n * 验签接口请求\n * @param baseUrl 基础 URL\n * @param data 验签数据\n * @returns 验签结果\n */\nexport async function verifyTokenSign(\n baseUrl: string,\n data: {\n appId: string;\n sign: string;\n timestamp: number;\n }\n): Promise<boolean> {\n try {\n const client = new HttpClient(baseUrl);\n const response = await client.post<{ data: boolean }>(\n '/onlyoffice/token/verifyTokenSign',\n data\n );\n return response.data?.data === true;\n } catch (error) {\n console.error('验签请求失败:', error);\n return false;\n }\n}\n\n/**\n * 保存操作信息\n * @param callbackUrl 回调地址\n * @param data 操作数据\n */\nexport async function saveSuccessInfo(\n callbackUrl: string,\n data: {\n status: number;\n key: string;\n userdata: string;\n }\n): Promise<void> {\n try {\n await axios.post(callbackUrl, data);\n } catch (error) {\n console.error('保存操作信息失败:', error);\n }\n}","import EventEmitter from 'eventemitter3';\nimport type {\n DocumentConfig,\n EditorConfig,\n DocumentPermissions,\n OfficeEventType,\n OfficeCallback,\n OfficeEditorInstance,\n OfficeDocumentConfig,\n OfficeInitConfig,\n AuthConfig,\n VerifyTokenSignFunction,\n} from '../types';\nimport { getDocumentType, isSupportedFileType } from './utils/fileType';\nimport { verifyTokenSign, saveSuccessInfo } from './utils/http';\n\n/**\n * 默认文档权限\n */\nconst DEFAULT_PERMISSIONS: DocumentPermissions = {\n comment: false,\n download: false,\n edit: false,\n print: true,\n review: false,\n editCommentAuthorOnly: false,\n fillForms: false,\n modifyContentControl: false,\n};\n\n/**\n * OnlyOffice 编辑器管理类\n */\nexport class OfficeEditor implements OfficeEditorInstance {\n private editor: any = null;\n private editorId: string;\n private emitter: EventEmitter;\n private documentConfig: DocumentConfig;\n private editorConfig: EditorConfig;\n private callback: OfficeCallback | null = null;\n private height: string = '100%';\n private width: string = '100%';\n\n constructor() {\n this.editorId = `editor-${Date.now().toString(32)}`;\n this.emitter = new EventEmitter();\n this.documentConfig = {\n fileType: 'docx',\n key: '',\n url: '',\n title: '',\n permissions: { ...DEFAULT_PERMISSIONS },\n };\n this.editorConfig = {\n lang: 'zh',\n user: { id: '', name: '' },\n };\n }\n\n /**\n * 配置文档参数\n */\n configure(config: OfficeDocumentConfig): void {\n if (config.height) this.height = config.height;\n if (config.width) this.width = config.width;\n\n if (config.fileType) {\n if (!isSupportedFileType(config.fileType)) {\n throw new Error(`不支持的文件类型: ${config.fileType}`);\n }\n const docType = getDocumentType(config.fileType);\n if (docType !== 'other') {\n this.documentConfig.fileType = config.fileType;\n }\n }\n\n if (config.key) this.documentConfig.key = config.key;\n if (config.url) this.documentConfig.url = config.url;\n if (config.title) this.documentConfig.title = config.title;\n\n if (config.permissions) {\n this.documentConfig.permissions = {\n ...this.documentConfig.permissions,\n ...config.permissions,\n };\n\n // PDF 文件特殊处理\n if (this.documentConfig.fileType === 'pdf') {\n this.documentConfig.permissions.edit = false;\n this.documentConfig.permissions.review = false;\n this.editorConfig.mode = 'view';\n }\n }\n\n if (config.callbackUrl) this.editorConfig.callbackUrl = config.callbackUrl;\n if (config.userId) {\n this.editorConfig.user = {\n ...this.editorConfig.user,\n id: config.userId,\n };\n }\n if (config.userName) {\n this.editorConfig.user = {\n ...this.editorConfig.user,\n name: config.userName,\n };\n }\n if (config.userGroup) {\n this.editorConfig.user = {\n ...this.editorConfig.user,\n group: config.userGroup,\n };\n }\n }\n\n /**\n * 初始化编辑器(带验签)\n */\n async initOffice(config: OfficeInitConfig): Promise<OfficeEditorInstance> {\n const { dom, officeApiUrl, callback, auth, verifyFunction } = config;\n\n if (callback) this.callback = callback;\n\n // 验签逻辑\n if (auth) {\n let verified = false;\n\n if (verifyFunction) {\n // 使用自定义验签函数\n verified = await verifyFunction(auth);\n } else if (auth.verifyUrl) {\n // 使用自定义验签地址\n verified = await verifyTokenSign(auth.verifyUrl, {\n appId: auth.appId,\n sign: auth.sign,\n timestamp: auth.timestamp,\n });\n } else {\n throw new Error('使用验签配置时,必须提供 verifyFunction 或 verifyUrl');\n }\n\n if (!verified) {\n throw new Error('验签失败,请检查验签配置');\n }\n }\n\n return this.createEditor(dom, officeApiUrl);\n }\n\n /**\n * 简化初始化(无验签)\n */\n init(\n dom: HTMLElement,\n officeApiUrl: string,\n callback?: OfficeCallback\n ): OfficeEditorInstance {\n if (callback) this.callback = callback;\n return this.createEditor(dom, officeApiUrl);\n }\n\n /**\n * 创建编辑器实例\n */\n private createEditor(dom: HTMLElement, officeApiUrl: string): OfficeEditorInstance {\n console.log('[OnlyOffice] createEditor called', { dom, officeApiUrl });\n\n if (!dom) {\n throw new Error('必须提供挂载的 DOM 元素');\n }\n\n if (!officeApiUrl) {\n throw new Error('必须提供 OnlyOffice API 脚本地址');\n }\n\n // 设置容器样式\n dom.style.position = 'relative';\n console.log('[OnlyOffice] DOM dimensions:', { width: dom.offsetWidth, height: dom.offsetHeight });\n\n // 创建编辑器容器\n const mainDiv = document.createElement('div');\n mainDiv.id = this.editorId;\n mainDiv.style.height = '100%';\n mainDiv.style.width = '100%';\n dom.appendChild(mainDiv);\n\n // 动态加载 OnlyOffice API 脚本\n const scriptId = `script-${this.editorId}`;\n const existingScript = document.querySelector(`#${scriptId}`);\n\n if (!existingScript) {\n console.log('[OnlyOffice] Loading script:', officeApiUrl);\n const script = document.createElement('script');\n script.id = scriptId;\n script.src = officeApiUrl;\n script.onload = () => {\n console.log('[OnlyOffice] Script loaded successfully');\n console.log('[OnlyOffice] window.DocsAPI:', window.DocsAPI);\n this.instantiateEditor();\n };\n script.onerror = (err) => {\n console.error('[OnlyOffice] Script load failed:', err);\n };\n document.head.appendChild(script);\n } else {\n console.log('[OnlyOffice] Script already loaded');\n this.instantiateEditor();\n }\n\n return this;\n }\n\n /**\n * 实例化编辑器\n */\n private instantiateEditor(): void {\n console.log('[OnlyOffice] instantiateEditor called');\n\n // 销毁现有实例\n if (this.editor) {\n this.editor.destroyEditor();\n this.editor = null;\n }\n\n // 检查 DocsAPI 是否可用\n if (!window.DocsAPI || !window.DocsAPI.DocEditor) {\n console.error('[OnlyOffice] window.DocsAPI.DocEditor is not available');\n return;\n }\n\n // 构建配置对象\n const config = {\n width: this.width,\n height: this.height,\n documentType: this.getDocumentType(),\n document: this.documentConfig,\n editorConfig: this.editorConfig,\n events: this.createEventHandlers(),\n };\n\n console.log('[OnlyOffice] Creating editor with config:', config);\n console.log('[OnlyOffice] Editor container ID:', this.editorId);\n console.log('[OnlyOffice] Container element:', document.getElementById(this.editorId));\n\n // 创建编辑器实例\n try {\n this.editor = new window.DocsAPI.DocEditor(this.editorId, config);\n console.log('[OnlyOffice] Editor created successfully:', this.editor);\n } catch (err) {\n console.error('[OnlyOffice] Error creating editor:', err);\n }\n }\n\n /**\n * 获取文档类型\n */\n private getDocumentType(): string {\n const type = getDocumentType(this.documentConfig.fileType);\n return type === 'other' ? 'word' : type;\n }\n\n /**\n * 创建事件处理器\n */\n private createEventHandlers(): Record<string, (event: any) => void> {\n return {\n onDocumentStateChange: (event: any) => {\n this.emitter.emit('documentStateChange', event);\n },\n onDocumentReady: () => {\n console.log('Document is loaded');\n // 通知后端文档加载成功\n if (this.editorConfig.callbackUrl) {\n saveSuccessInfo(this.editorConfig.callbackUrl, {\n status: 8,\n key: this.documentConfig.key,\n userdata: JSON.stringify({\n appUserId: this.editorConfig.user?.id,\n }),\n });\n }\n this.callback?.('onDocumentReady');\n this.emitter.emit('onDocumentReady');\n },\n onInfo: (event: any) => {\n console.log('ONLYOFFICE Document Editor is opened in mode', event.data.mode);\n this.callback?.('onInfo', event.data);\n this.emitter.emit('onInfo', event);\n },\n onError: (event: any) => {\n console.error('ONLYOFFICE Error:', event.data.errorCode, event.data.errorDescription);\n this.emitter.emit('onError', event);\n },\n onRequestHistory: (event: any) => {\n this.callback?.('onRequestHistory', event, this.editor);\n this.emitter.emit('onRequestHistory', { event, editor: this.editor });\n },\n onRequestHistoryData: (event: any) => {\n this.callback?.('onRequestHistoryData', event, this.editor);\n this.emitter.emit('onRequestHistoryData', { event, editor: this.editor });\n },\n onRequestHistoryClose: (event: any) => {\n this.callback?.('onRequestHistoryClose', event, this.editor);\n this.emitter.emit('onRequestHistoryClose', { event, editor: this.editor });\n },\n onRequestRestore: (event: any) => {\n this.callback?.('onRequestRestore', event, this.editor);\n this.emitter.emit('onRequestRestore', { event, editor: this.editor });\n },\n onRequestSendNotify: (event: any) => {\n console.log('onRequestSendNotify', event);\n this.emitter.emit('onRequestSendNotify', event);\n },\n onRequestUsers: (event: any) => {\n console.log('onRequestUsers', event);\n this.emitter.emit('onRequestUsers', event);\n },\n };\n }\n\n /**\n * 监听事件\n */\n on(event: OfficeEventType, callback: (...args: any[]) => void): void {\n this.emitter.on(event, callback);\n }\n\n /**\n * 移除事件监听\n */\n off(event: OfficeEventType, callback: (...args: any[]) => void): void {\n this.emitter.off(event, callback);\n }\n\n /**\n * 获取当前配置\n */\n getConfig(): DocumentConfig & EditorConfig {\n return {\n ...this.documentConfig,\n ...this.editorConfig,\n };\n }\n\n /**\n * 获取内部编辑器实例\n */\n getEditor(): any {\n return this.editor;\n }\n\n /**\n * 销毁编辑器\n */\n destroy(): void {\n if (this.editor) {\n this.editor.destroyEditor();\n this.editor = null;\n }\n this.emitter.removeAllListeners();\n this.callback = null;\n }\n}","import {\n defineComponent,\n ref,\n onMounted,\n onBeforeUnmount,\n watch,\n nextTick,\n type PropType,\n type Ref,\n} from 'vue';\nimport { OfficeEditor } from '../core/editor';\nimport type {\n OfficeDocumentConfig,\n OfficeInitConfig,\n OfficeCallback,\n OfficeEventType,\n AuthConfig,\n VerifyTokenSignFunction,\n OfficeEditorInstance,\n} from '../types';\n\n/**\n * OnlyOffice 编辑器 Vue 3 组件\n */\nexport const OnlyOfficeEditor = defineComponent({\n name: 'OnlyOfficeEditor',\n\n props: {\n /** OnlyOffice API 脚本地址 */\n officeApiUrl: {\n type: String,\n required: true,\n },\n /** 文档配置 */\n document: {\n type: Object as PropType<OfficeDocumentConfig>,\n required: true,\n },\n /** 验签配置 */\n auth: {\n type: Object as PropType<AuthConfig>,\n default: undefined,\n },\n /** 自定义验签函数 */\n verifyFunction: {\n type: Function as PropType<VerifyTokenSignFunction>,\n default: undefined,\n },\n /** 是否跳过验签(当 auth 已通过外部验签时使用) */\n skipVerification: {\n type: Boolean,\n default: false,\n },\n /** 编辑器高度 */\n height: {\n type: String,\n default: '100%',\n },\n /** 编辑器宽度 */\n width: {\n type: String,\n default: '100%',\n },\n },\n\n emits: [\n 'ready',\n 'error',\n 'documentStateChange',\n 'requestHistory',\n 'requestHistoryData',\n 'requestHistoryClose',\n 'requestRestore',\n ],\n\n setup(props: any, { emit }: any) {\n const containerRef: Ref<HTMLElement | null> = ref(null);\n const editorInstance: Ref<OfficeEditorInstance | null> = ref(null);\n const isReady: Ref<boolean> = ref(false);\n const error: Ref<string | null> = ref(null);\n\n /**\n * 初始化编辑器\n */\n const initEditor = async () => {\n console.log('[OnlyOffice Component] initEditor called');\n console.log('[OnlyOffice Component] containerRef.value:', containerRef.value);\n\n if (!containerRef.value) {\n console.warn('[OnlyOffice Component] containerRef is null, cannot init editor');\n // 尝试通过 ID 获取容器\n const container = document.querySelector('.onlyoffice-editor-container > div:first-child');\n console.log('[OnlyOffice Component] Trying to find container by selector:', container);\n if (container) {\n containerRef.value = container as HTMLElement;\n } else {\n return;\n }\n }\n\n try {\n console.log('[OnlyOffice Component] Container dimensions:', {\n width: containerRef.value.offsetWidth,\n height: containerRef.value.offsetHeight,\n clientWidth: containerRef.value.clientWidth,\n clientHeight: containerRef.value.clientHeight\n });\n const editor = new OfficeEditor();\n\n // 配置文档参数\n editor.configure({\n ...props.document,\n height: props.height,\n width: props.width,\n });\n\n // 事件回调\n const callback: OfficeCallback = (type, event, editorInst) => {\n switch (type) {\n case 'onDocumentReady':\n isReady.value = true;\n emit('ready', editorInst);\n break;\n case 'onInfo':\n break;\n case 'onRequestHistory':\n emit('requestHistory', { event, editor: editorInst });\n break;\n case 'onRequestHistoryData':\n emit('requestHistoryData', { event, editor: editorInst });\n break;\n case 'onRequestHistoryClose':\n emit('requestHistoryClose', { event, editor: editorInst });\n break;\n case 'onRequestRestore':\n emit('requestRestore', { event, editor: editorInst });\n break;\n }\n };\n\n // 判断初始化方式\n if (props.skipVerification || (!props.auth && !props.verifyFunction)) {\n // 跳过验签或无验签配置:直接初始化\n editorInstance.value = editor.init(\n containerRef.value,\n props.officeApiUrl,\n callback\n );\n } else {\n // 带验签初始化\n const initConfig: OfficeInitConfig = {\n dom: containerRef.value,\n officeApiUrl: props.officeApiUrl,\n callback,\n auth: props.auth,\n verifyFunction: props.verifyFunction,\n };\n editorInstance.value = await editor.initOffice(initConfig);\n }\n\n // 监听错误事件\n editor.on('onError' as OfficeEventType, (event: any) => {\n error.value = event.data?.errorDescription || '编辑器错误';\n emit('error', event);\n });\n\n // 监听文档状态变化\n editor.on('documentStateChange' as OfficeEventType, (event: any) => {\n emit('documentStateChange', event);\n });\n } catch (err: any) {\n error.value = err.message || '初始化失败';\n emit('error', err);\n }\n };\n\n /**\n * 销毁编辑器\n */\n const destroyEditor = () => {\n if (editorInstance.value) {\n editorInstance.value.destroy();\n editorInstance.value = null;\n isReady.value = false;\n }\n };\n\n // 监听文档配置变化\n watch(\n () => props.document,\n (newDoc: any) => {\n if (editorInstance.value && newDoc) {\n // 重新初始化编辑器\n destroyEditor();\n initEditor();\n }\n },\n { deep: true }\n );\n\n // 组件挂载时初始化\n onMounted(async () => {\n console.log('[OnlyOffice Component] onMounted called');\n console.log('[OnlyOffice Component] Props:', {\n officeApiUrl: props.officeApiUrl,\n document: props.document,\n skipVerification: props.skipVerification\n });\n\n // 使用 nextTick 确保 DOM 已经渲染完成\n await nextTick();\n console.log('[OnlyOffice Component] After nextTick, containerRef.value:', containerRef.value);\n\n // 如果仍然为 null,使用 setTimeout 重试\n if (!containerRef.value) {\n console.log('[OnlyOffice Component] containerRef still null, retrying with setTimeout');\n setTimeout(() => {\n console.log('[OnlyOffice Component] After setTimeout, containerRef.value:', containerRef.value);\n initEditor();\n }, 100);\n } else {\n initEditor();\n }\n });\n\n // 组件销毁前清理\n onBeforeUnmount(() => {\n destroyEditor();\n });\n\n return {\n containerRef,\n editorInstance,\n isReady,\n error,\n };\n },\n\n template: `\n <div class=\"onlyoffice-editor-container\" :style=\"{ width: width, height: height, position: 'relative', minHeight: '400px' }\">\n <div ref=\"containerRef\" :style=\"{ width: '100%', height: '100%' }\"></div>\n <div v-if=\"error\" class=\"onlyoffice-error\" style=\"position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: red; z-index: 10;\">\n {{ error }}\n </div>\n </div>\n `,\n});\n\nexport default OnlyOfficeEditor;","import { ref, onMounted, onBeforeUnmount, watch, type Ref } from 'vue';\nimport { OfficeEditor } from '../core/editor';\nimport type {\n OfficeDocumentConfig,\n OfficeInitConfig,\n OfficeCallback,\n OfficeEventType,\n AuthConfig,\n VerifyTokenSignFunction,\n OfficeEditorInstance,\n} from '../types';\n\n/**\n * useOnlyOffice 配置选项\n */\nexport interface UseOnlyOfficeOptions {\n /** OnlyOffice API 脚本地址 */\n officeApiUrl: string;\n /** 文档配置 */\n document: OfficeDocumentConfig;\n /** 验签配置 */\n auth?: AuthConfig;\n /** 自定义验签函数 */\n verifyFunction?: VerifyTokenSignFunction;\n /** 编辑器高度 */\n height?: string;\n /** 编辑器宽度 */\n width?: string;\n /** 是否自动初始化 */\n autoInit?: boolean;\n}\n\n/**\n * useOnlyOffice 返回值\n */\nexport interface UseOnlyOfficeReturn {\n /** 容器元素引用 */\n containerRef: Ref<HTMLElement | null>;\n /** 编辑器实例 */\n editorInstance: Ref<OfficeEditorInstance | null>;\n /** 是否已就绪 */\n isReady: Ref<boolean>;\n /** 错误信息 */\n error: Ref<string | null>;\n /** 初始化编辑器 */\n init: () => Promise<void>;\n /** 销毁编辑器 */\n destroy: () => void;\n /** 重新初始化 */\n reinit: () => Promise<void>;\n /** 监听事件 */\n on: (event: OfficeEventType, callback: (...args: any[]) => void) => void;\n /** 移除事件监听 */\n off: (event: OfficeEventType, callback: (...args: any[]) => void) => void;\n}\n\n/**\n * OnlyOffice Vue 3 组合式函数\n * @param options 配置选项\n * @returns 编辑器状态和方法\n */\nexport function useOnlyOffice(options: UseOnlyOfficeOptions): UseOnlyOfficeReturn {\n const {\n officeApiUrl,\n document: documentConfig,\n auth,\n verifyFunction,\n height = '100%',\n width = '100%',\n autoInit = true,\n } = options;\n\n const containerRef: Ref<HTMLElement | null> = ref(null);\n const editorInstance: Ref<OfficeEditorInstance | null> = ref(null);\n const isReady: Ref<boolean> = ref(false);\n const error: Ref<string | null> = ref(null);\n\n let editor: OfficeEditor | null = null;\n\n /**\n * 初始化编辑器\n */\n const init = async () => {\n if (!containerRef.value) {\n error.value = '容器元素未找到';\n return;\n }\n\n try {\n // 销毁现有实例\n destroy();\n\n editor = new OfficeEditor();\n\n // 配置文档参数\n editor.configure({\n ...documentConfig,\n height,\n width,\n });\n\n // 事件回调\n const callback: OfficeCallback = (type, _event, _editorInst) => {\n switch (type) {\n case 'onDocumentReady':\n isReady.value = true;\n break;\n case 'onInfo':\n break;\n }\n };\n\n // 初始化配置\n const initConfig: OfficeInitConfig = {\n dom: containerRef.value,\n officeApiUrl,\n callback,\n auth,\n verifyFunction,\n };\n\n // 初始化编辑器\n editorInstance.value = await editor.initOffice(initConfig);\n\n // 监听错误事件\n editor.on('onError' as OfficeEventType, (event: any) => {\n error.value = event.data?.errorDescription || '编辑器错误';\n });\n } catch (err: any) {\n error.value = err.message || '初始化失败';\n }\n };\n\n /**\n * 销毁编辑器\n */\n const destroy = () => {\n if (editor) {\n editor.destroy();\n editor = null;\n editorInstance.value = null;\n isReady.value = false;\n }\n };\n\n /**\n * 重新初始化\n */\n const reinit = async () => {\n destroy();\n await init();\n };\n\n /**\n * 监听事件\n */\n const on = (event: OfficeEventType, callback: (...args: any[]) => void) => {\n if (editor) {\n editor.on(event, callback);\n }\n };\n\n /**\n * 移除事件监听\n */\n const off = (event: OfficeEventType, callback: (...args: any[]) => void) => {\n if (editor) {\n editor.off(event, callback);\n }\n };\n\n // 监听文档配置变化\n watch(\n () => documentConfig,\n async (newDoc: any) => {\n if (editor && newDoc) {\n await reinit();\n }\n },\n { deep: true }\n );\n\n // 组件挂载时初始化\n onMounted(() => {\n if (autoInit) {\n init();\n }\n });\n\n // 组件销毁前清理\n onBeforeUnmount(() => {\n destroy();\n });\n\n return {\n containerRef,\n editorInstance,\n isReady,\n error,\n init,\n destroy,\n reinit,\n on,\n off,\n };\n}\n\nexport default useOnlyOffice;","export { OfficeEditor } from './editor';\nexport { getDocumentType, isSupportedFileType } from './utils/fileType';\nexport { HttpClient, verifyTokenSign, saveSuccessInfo } from './utils/http';\n\n// 导出类型\nexport type {\n DocumentType,\n FileType,\n DocumentPermissions,\n UserInfo,\n DocumentConfig,\n EditorConfig,\n AuthConfig,\n VerifyTokenSignFunction,\n OfficeInitConfig,\n OfficeDocumentConfig,\n OfficeEventType,\n OfficeCallbackType,\n OfficeCallback,\n OfficeEditorInstance,\n OfficeSDK,\n} from '../types';\n\nimport { OfficeEditor } from './editor';\nimport type {\n OfficeDocumentConfig,\n OfficeInitConfig,\n OfficeCallback,\n OfficeEventType,\n OfficeEditorInstance,\n} from '../types';\n\n/**\n * 创建 Office 编辑器实例\n * @returns OfficeEditor 实例\n */\nexport function createOfficeEditor(): OfficeEditor {\n return new OfficeEditor();\n}\n\n/**\n * 快速初始化 Office 编辑器\n * @param config 初始化配置\n * @returns Promise<OfficeEditorInstance>\n */\nexport async function initOffice(config: OfficeInitConfig): Promise<OfficeEditorInstance> {\n const editor = new OfficeEditor();\n return editor.initOffice(config);\n}\n\n/**\n * 简化初始化(无验签)\n * @param dom 挂载的 DOM 元素\n * @param officeApiUrl OnlyOffice API 地址\n * @param callback 事件回调\n * @returns OfficeEditorInstance\n */\nexport function init(\n dom: HTMLElement,\n officeApiUrl: string,\n callback?: OfficeCallback\n): OfficeEditorInstance {\n const editor = new OfficeEditor();\n return editor.init(dom, officeApiUrl, callback);\n}\n\n/**\n * 配置文档参数(全局配置,需要先创建编辑器实例)\n * @deprecated 建议使用 OfficeEditor.configure() 方法\n */\nexport function config(_config: OfficeDocumentConfig): void {\n console.warn('此方法已废弃,请使用 OfficeEditor.configure() 方法');\n}\n\n/**\n * 销毁编辑器(全局方法,需要先创建编辑器实例)\n * @deprecated 建议使用 OfficeEditor.destroy() 方法\n */\nexport function destroy(): void {\n console.warn('此方法已废弃,请使用 OfficeEditor.destroy() 方法');\n}\n\n/**\n * 监听事件(全局方法,需要先创建编辑器实例)\n * @deprecated 建议使用 OfficeEditor.on() 方法\n */\nexport function on(_event: OfficeEventType, _callback: (...args: any[]) => void): void {\n console.warn('此方法已废弃,请使用 OfficeEditor.on() 方法');\n}\n\n/**\n * 记录分享动作\n * @param callbackUrl 回调地址\n * @param fileKey 文件标识\n * @param appUserId 用户 ID\n */\nexport async function shareSave(\n callbackUrl: string,\n fileKey: string,\n appUserId: string\n): Promise<void> {\n const { saveSuccessInfo } = await import('./utils/http');\n await saveSuccessInfo(callbackUrl, {\n status: 10,\n key: fileKey,\n userdata: JSON.stringify({ appUserId }),\n });\n}\n\n/**\n * 记录下载动作\n * @param callbackUrl 回调地址\n * @param fileKey 文件标识\n * @param appUserId 用户 ID\n */\nexport async function downloadSave(\n callbackUrl: string,\n fileKey: string,\n appUserId: string\n): Promise<void> {\n const { saveSuccessInfo } = await import('./utils/http');\n await saveSuccessInfo(callbackUrl, {\n status: 9,\n key: fileKey,\n userdata: JSON.stringify({ appUserId }),\n });\n}"],"names":["getDocumentType","fileType","type","toLowerCase","includes","HttpClient","constructor","baseUrl","this","post","url","data","config","fullUrl","axios","get","async","verifyTokenSign","client","_a","error","console","saveSuccessInfo","callbackUrl","DEFAULT_PERMISSIONS","comment","download","edit","print","review","editCommentAuthorOnly","fillForms","modifyContentControl","OfficeEditor","editor","callback","height","width","editorId","Date","now","toString","emitter","EventEmitter","documentConfig","key","title","permissions","editorConfig","lang","user","id","name","configure","Error","mode","userId","userName","userGroup","group","initOffice","dom","officeApiUrl","auth","verifyFunction","verified","verifyUrl","appId","sign","timestamp","createEditor","init","log","style","position","offsetWidth","offsetHeight","mainDiv","document","createElement","appendChild","scriptId","querySelector","instantiateEditor","script","src","onload","window","DocsAPI","onerror","err","head","destroyEditor","DocEditor","documentType","events","createEventHandlers","getElementById","onDocumentStateChange","event","emit","onDocumentReady","status","userdata","JSON","stringify","appUserId","_b","call","onInfo","onError","errorCode","errorDescription","onRequestHistory","onRequestHistoryData","onRequestHistoryClose","onRequestRestore","onRequestSendNotify","onRequestUsers","on","off","getConfig","getEditor","destroy","removeAllListeners","OnlyOfficeEditor","defineComponent","props","String","required","Object","default","undefined","Function","skipVerification","Boolean","emits","setup","containerRef","ref","editorInstance","isReady","initEditor","value","warn","container","clientWidth","clientHeight","editorInst","initConfig","message","watch","newDoc","deep","onMounted","nextTick","setTimeout","onBeforeUnmount","template","useOnlyOffice","options","autoInit","_event","_editorInst","reinit","createOfficeEditor","shareSave","fileKey","Promise","resolve","then","http","downloadSave"],"mappings":"8JAOM,SAAUA,EAAgBC,GAC9B,MAAMC,EAAOD,EAASE,cAItB,GADkB,CAAC,MAAO,OAAQ,MAAO,MAAO,MAAO,OAAQ,QACjDC,SAASF,GACrB,MAAO,OAKT,GADkB,CAAC,MAAO,OAAQ,MAAO,OAC3BE,SAASF,GACrB,MAAO,OAKT,MADmB,CAAC,MAAO,OAAQ,OACpBE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AAKC,UAAU,CAAEC,eAE/B"}
@@ -1 +1 @@
1
- {"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../src/vue3/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,QAAQ,EACb,KAAK,GAAG,EACT,MAAM,KAAK,CAAC;AAEb,OAAO,KAAK,EACV,oBAAoB,EAIpB,UAAU,EACV,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,eAAO,MAAM,gBAAgB;IAIzB,0BAA0B;;;;;IAK1B,WAAW;;cAEO,QAAQ,CAAC,oBAAoB,CAAC;;;IAGhD,WAAW;;cAEO,QAAQ,CAAC,UAAU,CAAC;;;IAGtC,cAAc;;cAEM,QAAQ,CAAC,uBAAuB,CAAC;;;IAGrD,gCAAgC;;;;;IAKhC,YAAY;;;;;IAKZ,YAAY;;;;;;;;;;;IA9BZ,0BAA0B;;;;;IAK1B,WAAW;;cAEO,QAAQ,CAAC,oBAAoB,CAAC;;;IAGhD,WAAW;;cAEO,QAAQ,CAAC,UAAU,CAAC;;;IAGtC,cAAc;;cAEM,QAAQ,CAAC,uBAAuB,CAAC;;;IAGrD,gCAAgC;;;;;IAKhC,YAAY;;;;;IAKZ,YAAY;;;;;;;;;;;;;;;;;;;4EAkKd,CAAC;AAEH,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../src/vue3/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,QAAQ,EACb,KAAK,GAAG,EACT,MAAM,KAAK,CAAC;AAEb,OAAO,KAAK,EACV,oBAAoB,EAIpB,UAAU,EACV,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,eAAO,MAAM,gBAAgB;IAIzB,0BAA0B;;;;;IAK1B,WAAW;;cAEO,QAAQ,CAAC,oBAAoB,CAAC;;;IAGhD,WAAW;;cAEO,QAAQ,CAAC,UAAU,CAAC;;;IAGtC,cAAc;;cAEM,QAAQ,CAAC,uBAAuB,CAAC;;;IAGrD,gCAAgC;;;;;IAKhC,YAAY;;;;;IAKZ,YAAY;;;;;;;;;;;IA9BZ,0BAA0B;;;;;IAK1B,WAAW;;cAEO,QAAQ,CAAC,oBAAoB,CAAC;;;IAGhD,WAAW;;cAEO,QAAQ,CAAC,UAAU,CAAC;;;IAGtC,cAAc;;cAEM,QAAQ,CAAC,uBAAuB,CAAC;;;IAGrD,gCAAgC;;;;;IAKhC,YAAY;;;;;IAKZ,YAAY;;;;;;;;;;;;;;;;;;;4EA4Ld,CAAC;AAEH,eAAe,gBAAgB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chao194/office",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "即插即用的 OnlyOffice 前端集成方案,支持 Vue、React 和原生 JavaScript",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.cjs",