@univerjs_docs-ui_facade.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import {
  2. Se,
  3. Vs
  4. } from "./chunk-MIOQ566M.js";
  5. import "./chunk-POAJ2YNP.js";
  6. import "./chunk-GBYP4PB2.js";
  7. import "./chunk-PZD7N4BC.js";
  8. import {
  9. Yx
  10. } from "./chunk-2MK3Q52E.js";
  11. import "./chunk-BSDDCPAW.js";
  12. import "./chunk-QG2HZMYH.js";
  13. import {
  14. Ag,
  15. Bi,
  16. Fe,
  17. Nn,
  18. Ot,
  19. Pt,
  20. Tn,
  21. _n,
  22. ot,
  23. pi
  24. } from "./chunk-23V3HWTR.js";
  25. import "./chunk-GNR2UJZM.js";
  26. import "./chunk-2LSFTFF7.js";
  27. // node_modules/.pnpm/@univerjs+docs-ui@0.5.5_@grpc+grpc-js@1.13.4_react-dom@18.3.1_react@18.3.1_rxjs@7.8.1_typescript@5.4.5/node_modules/@univerjs/docs-ui/lib/es/facade.js
  28. var h = Object.defineProperty;
  29. var v = (n, e, t) => e in n ? h(n, e, { enumerable: true, configurable: true, writable: true, value: t }) : n[e] = t;
  30. var u = (n, e, t) => v(n, typeof e != "symbol" ? e + "" : e, t);
  31. var y = Object.defineProperty;
  32. var O = Object.getOwnPropertyDescriptor;
  33. var R = (n, e, t, r) => {
  34. for (var s = r > 1 ? void 0 : r ? O(e, t) : e, i = n.length - 1, a; i >= 0; i--)
  35. (a = n[i]) && (s = (r ? a(e, t, s) : a(s)) || s);
  36. return r && s && y(e, t, s), s;
  37. };
  38. var c = (n, e) => (t, r) => e(t, r, n);
  39. var o = class {
  40. constructor(n, e, t, r, s, i) {
  41. u(this, "id");
  42. this._documentDataModel = n, this._injector = e, this._univerInstanceService = t, this._commandService = r, this._resourceManagerService = s, this._renderManagerService = i, this.id = this._documentDataModel.getUnitId();
  43. }
  44. getId() {
  45. return this._documentDataModel.getUnitId();
  46. }
  47. getName() {
  48. return this.getSnapshot().title || "";
  49. }
  50. getSnapshot() {
  51. const n = this._resourceManagerService.getResourcesByType(this.id, Fe.UNIVER_DOC), e = this._documentDataModel.getSnapshot();
  52. return e.resources = n, e;
  53. }
  54. undo() {
  55. return this._univerInstanceService.focusUnit(this.id), this._commandService.executeCommand(Nn.id);
  56. }
  57. redo() {
  58. return this._univerInstanceService.focusUnit(this.id), this._commandService.executeCommand(Tn.id);
  59. }
  60. /**
  61. * Adds the specified text to the end of this text region.
  62. * @param text - The text to be added to the end of this text region.
  63. */
  64. appendText(n) {
  65. const e = this.id, { body: t } = this.getSnapshot();
  66. if (!t)
  67. throw new Error("The document body is empty");
  68. const r = t.dataStream.length - 2, s = {
  69. startOffset: r,
  70. endOffset: r,
  71. collapsed: true,
  72. segmentId: ""
  73. }, { segmentId: i } = s;
  74. return this._commandService.executeCommand(Vs.id, {
  75. unitId: e,
  76. body: {
  77. dataStream: n
  78. },
  79. range: s,
  80. segmentId: i
  81. });
  82. }
  83. /**
  84. * Sets the selection to a specified text range in the document.
  85. * @param startOffset - The starting offset of the selection in the document.
  86. * @param endOffset - The ending offset of the selection in the document.
  87. * @example
  88. * ```typescript
  89. * document.setSelection(10, 20);
  90. * ```
  91. */
  92. setSelection(n, e) {
  93. var r;
  94. const t = (r = this._renderManagerService.getRenderById(this.getId())) == null ? void 0 : r.with(Se);
  95. t == null || t.removeAllRanges(), t == null || t.addDocRanges(
  96. [
  97. {
  98. startOffset: n,
  99. endOffset: e,
  100. rangeType: Ag.TEXT
  101. }
  102. ],
  103. true
  104. );
  105. }
  106. };
  107. o = R([
  108. c(1, ot(Ot)),
  109. c(2, _n),
  110. c(3, Pt),
  111. c(4, Bi),
  112. c(5, Yx)
  113. ], o);
  114. var T = class extends pi {
  115. createUniverDoc(e) {
  116. const t = this._univerInstanceService.createUnit(Fe.UNIVER_DOC, e);
  117. return this._injector.createInstance(o, t);
  118. }
  119. getActiveDocument() {
  120. const e = this._univerInstanceService.getCurrentUnitForType(Fe.UNIVER_DOC);
  121. return e ? this._injector.createInstance(o, e) : null;
  122. }
  123. getUniverDoc(e) {
  124. const t = this._univerInstanceService.getUniverDocInstance(e);
  125. return t ? this._injector.createInstance(o, t) : null;
  126. }
  127. };
  128. pi.extend(T);
  129. export {
  130. o as FDocument
  131. };
  132. //# sourceMappingURL=@univerjs_docs-ui_facade.js.map