| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- var h = Object.defineProperty;
- var v = (n, e, t) => e in n ? h(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
- var u = (n, e, t) => v(n, typeof e != "symbol" ? e + "" : e, t);
- import { Inject as _, Injector as I, UniverInstanceType as d, UndoCommand as g, RedoCommand as p, DOC_RANGE_TYPE as S, IUniverInstanceService as l, ICommandService as f, IResourceManagerService as D, FUniver as m } from "@univerjs/core";
- import { InsertCommand as U, DocSelectionRenderService as C } from "@univerjs/docs-ui";
- import { IRenderManagerService as M } from "@univerjs/engine-render";
- var y = Object.defineProperty, O = Object.getOwnPropertyDescriptor, R = (n, e, t, r) => {
- for (var s = r > 1 ? void 0 : r ? O(e, t) : e, i = n.length - 1, a; i >= 0; i--)
- (a = n[i]) && (s = (r ? a(e, t, s) : a(s)) || s);
- return r && s && y(e, t, s), s;
- }, c = (n, e) => (t, r) => e(t, r, n);
- let o = class {
- constructor(n, e, t, r, s, i) {
- u(this, "id");
- this._documentDataModel = n, this._injector = e, this._univerInstanceService = t, this._commandService = r, this._resourceManagerService = s, this._renderManagerService = i, this.id = this._documentDataModel.getUnitId();
- }
- getId() {
- return this._documentDataModel.getUnitId();
- }
- getName() {
- return this.getSnapshot().title || "";
- }
- getSnapshot() {
- const n = this._resourceManagerService.getResourcesByType(this.id, d.UNIVER_DOC), e = this._documentDataModel.getSnapshot();
- return e.resources = n, e;
- }
- undo() {
- return this._univerInstanceService.focusUnit(this.id), this._commandService.executeCommand(g.id);
- }
- redo() {
- return this._univerInstanceService.focusUnit(this.id), this._commandService.executeCommand(p.id);
- }
- /**
- * Adds the specified text to the end of this text region.
- * @param text - The text to be added to the end of this text region.
- */
- appendText(n) {
- const e = this.id, { body: t } = this.getSnapshot();
- if (!t)
- throw new Error("The document body is empty");
- const r = t.dataStream.length - 2, s = {
- startOffset: r,
- endOffset: r,
- collapsed: !0,
- segmentId: ""
- }, { segmentId: i } = s;
- return this._commandService.executeCommand(U.id, {
- unitId: e,
- body: {
- dataStream: n
- },
- range: s,
- segmentId: i
- });
- }
- /**
- * Sets the selection to a specified text range in the document.
- * @param startOffset - The starting offset of the selection in the document.
- * @param endOffset - The ending offset of the selection in the document.
- * @example
- * ```typescript
- * document.setSelection(10, 20);
- * ```
- */
- setSelection(n, e) {
- var r;
- const t = (r = this._renderManagerService.getRenderById(this.getId())) == null ? void 0 : r.with(C);
- t == null || t.removeAllRanges(), t == null || t.addDocRanges(
- [
- {
- startOffset: n,
- endOffset: e,
- rangeType: S.TEXT
- }
- ],
- !0
- );
- }
- };
- o = R([
- c(1, _(I)),
- c(2, l),
- c(3, f),
- c(4, D),
- c(5, M)
- ], o);
- class T extends m {
- createUniverDoc(e) {
- const t = this._univerInstanceService.createUnit(d.UNIVER_DOC, e);
- return this._injector.createInstance(o, t);
- }
- getActiveDocument() {
- const e = this._univerInstanceService.getCurrentUnitForType(d.UNIVER_DOC);
- return e ? this._injector.createInstance(o, e) : null;
- }
- getUniverDoc(e) {
- const t = this._univerInstanceService.getUniverDocInstance(e);
- return t ? this._injector.createInstance(o, t) : null;
- }
- }
- m.extend(T);
- export {
- o as FDocument
- };
|