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