@univerjs/docs-ui
Version:
Univer normal ui-plugin-docs
2 lines (1 loc) • 2.6 kB
JavaScript
"use strict";var v=Object.defineProperty;var h=(r,e,t)=>e in r?v(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var u=(r,e,t)=>h(r,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/core"),m=require("@univerjs/core/facade"),d=require("@univerjs/docs-ui"),g=require("@univerjs/engine-render");var _=Object.getOwnPropertyDescriptor,I=(r,e,t,n)=>{for(var c=n>1?void 0:n?_(e,t):e,i=r.length-1,o;i>=0;i--)(o=r[i])&&(c=o(c)||c);return c},a=(r,e)=>(t,n)=>e(t,n,r);exports.FDocument=class{constructor(e,t,n,c,i,o){u(this,"id");this._documentDataModel=e,this._injector=t,this._univerInstanceService=n,this._commandService=c,this._resourceManagerService=i,this._renderManagerService=o,this.id=this._documentDataModel.getUnitId()}getId(){return this._documentDataModel.getUnitId()}getName(){return this.getSnapshot().title||""}getSnapshot(){const e=this._resourceManagerService.getResourcesByType(this.id,s.UniverInstanceType.UNIVER_DOC),t=this._documentDataModel.getSnapshot();return t.resources=e,t}undo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.executeCommand(s.UndoCommand.id)}redo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.executeCommand(s.RedoCommand.id)}appendText(e){const t=this.id,{body:n}=this.getSnapshot();if(!n)throw new Error("The document body is empty");const c=n.dataStream.length-2,i={startOffset:c,endOffset:c,collapsed:!0,segmentId:""},{segmentId:o}=i;return this._commandService.executeCommand(d.InsertCommand.id,{unitId:t,body:{dataStream:e},range:i,segmentId:o})}setSelection(e,t){var c;const n=(c=this._renderManagerService.getRenderById(this.getId()))==null?void 0:c.with(d.DocSelectionRenderService);n==null||n.removeAllRanges(),n==null||n.addDocRanges([{startOffset:e,endOffset:t,rangeType:s.DOC_RANGE_TYPE.TEXT}],!0)}};exports.FDocument=I([a(1,s.Inject(s.Injector)),a(2,s.IUniverInstanceService),a(3,s.ICommandService),a(4,s.IResourceManagerService),a(5,g.IRenderManagerService)],exports.FDocument);class D extends m.FUniver{createUniverDoc(e){const t=this._univerInstanceService.createUnit(s.UniverInstanceType.UNIVER_DOC,e);return this._injector.createInstance(exports.FDocument,t)}getActiveDocument(){const e=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC);return e?this._injector.createInstance(exports.FDocument,e):null}getUniverDoc(e){const t=this._univerInstanceService.getUniverDocInstance(e);return t?this._injector.createInstance(exports.FDocument,t):null}}m.FUniver.extend(D);