facade.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. var h = Object.defineProperty;
  2. var v = (n, e, t) => e in n ? h(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
  3. var u = (n, e, t) => v(n, typeof e != "symbol" ? e + "" : e, t);
  4. 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";
  5. import { InsertCommand as U, DocSelectionRenderService as C } from "@univerjs/docs-ui";
  6. import { IRenderManagerService as M } from "@univerjs/engine-render";
  7. var y = Object.defineProperty, O = Object.getOwnPropertyDescriptor, R = (n, e, t, r) => {
  8. for (var s = r > 1 ? void 0 : r ? O(e, t) : e, i = n.length - 1, a; i >= 0; i--)
  9. (a = n[i]) && (s = (r ? a(e, t, s) : a(s)) || s);
  10. return r && s && y(e, t, s), s;
  11. }, c = (n, e) => (t, r) => e(t, r, n);
  12. let o = class {
  13. constructor(n, e, t, r, s, i) {
  14. u(this, "id");
  15. this._documentDataModel = n, this._injector = e, this._univerInstanceService = t, this._commandService = r, this._resourceManagerService = s, this._renderManagerService = i, this.id = this._documentDataModel.getUnitId();
  16. }
  17. getId() {
  18. return this._documentDataModel.getUnitId();
  19. }
  20. getName() {
  21. return this.getSnapshot().title || "";
  22. }
  23. getSnapshot() {
  24. const n = this._resourceManagerService.getResourcesByType(this.id, d.UNIVER_DOC), e = this._documentDataModel.getSnapshot();
  25. return e.resources = n, e;
  26. }
  27. undo() {
  28. return this._univerInstanceService.focusUnit(this.id), this._commandService.executeCommand(g.id);
  29. }
  30. redo() {
  31. return this._univerInstanceService.focusUnit(this.id), this._commandService.executeCommand(p.id);
  32. }
  33. /**
  34. * Adds the specified text to the end of this text region.
  35. * @param text - The text to be added to the end of this text region.
  36. */
  37. appendText(n) {
  38. const e = this.id, { body: t } = this.getSnapshot();
  39. if (!t)
  40. throw new Error("The document body is empty");
  41. const r = t.dataStream.length - 2, s = {
  42. startOffset: r,
  43. endOffset: r,
  44. collapsed: !0,
  45. segmentId: ""
  46. }, { segmentId: i } = s;
  47. return this._commandService.executeCommand(U.id, {
  48. unitId: e,
  49. body: {
  50. dataStream: n
  51. },
  52. range: s,
  53. segmentId: i
  54. });
  55. }
  56. /**
  57. * Sets the selection to a specified text range in the document.
  58. * @param startOffset - The starting offset of the selection in the document.
  59. * @param endOffset - The ending offset of the selection in the document.
  60. * @example
  61. * ```typescript
  62. * document.setSelection(10, 20);
  63. * ```
  64. */
  65. setSelection(n, e) {
  66. var r;
  67. const t = (r = this._renderManagerService.getRenderById(this.getId())) == null ? void 0 : r.with(C);
  68. t == null || t.removeAllRanges(), t == null || t.addDocRanges(
  69. [
  70. {
  71. startOffset: n,
  72. endOffset: e,
  73. rangeType: S.TEXT
  74. }
  75. ],
  76. !0
  77. );
  78. }
  79. };
  80. o = R([
  81. c(1, _(I)),
  82. c(2, l),
  83. c(3, f),
  84. c(4, D),
  85. c(5, M)
  86. ], o);
  87. class T extends m {
  88. createUniverDoc(e) {
  89. const t = this._univerInstanceService.createUnit(d.UNIVER_DOC, e);
  90. return this._injector.createInstance(o, t);
  91. }
  92. getActiveDocument() {
  93. const e = this._univerInstanceService.getCurrentUnitForType(d.UNIVER_DOC);
  94. return e ? this._injector.createInstance(o, e) : null;
  95. }
  96. getUniverDoc(e) {
  97. const t = this._univerInstanceService.getUniverDocInstance(e);
  98. return t ? this._injector.createInstance(o, t) : null;
  99. }
  100. }
  101. m.extend(T);
  102. export {
  103. o as FDocument
  104. };