facade.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import { Inject as L, generateRandomId as f, CustomRangeType as C, DataStreamTreeTokenType as k, FEventName as b, FUniver as u, ICommandService as x, CanceledError as d } from "@univerjs/core";
  2. import { SheetsHyperLinkParserService as a, AddHyperLinkCommand as g, UpdateHyperLinkCommand as S, CancelHyperLinkCommand as v } from "@univerjs/sheets-hyper-link";
  3. import { FWorkbook as w, FWorksheet as _, FRange as y } from "@univerjs/sheets/facade";
  4. var I = Object.defineProperty, H = Object.getOwnPropertyDescriptor, U = (o, e, i, r) => {
  5. for (var n = r > 1 ? void 0 : r ? H(e, i) : e, t = o.length - 1, s; t >= 0; t--)
  6. (s = o[t]) && (n = (r ? s(e, i, n) : s(n)) || n);
  7. return r && n && I(e, i, n), n;
  8. }, R = (o, e) => (i, r) => e(i, r, o);
  9. let m = class {
  10. constructor(o, e) {
  11. this._workbook = o, this._parserService = e;
  12. }
  13. getRangeUrl(o) {
  14. return this._parserService.buildHyperLink(this._workbook.getId(), o.getSheetId(), o.getRange()), this;
  15. }
  16. };
  17. m = U([
  18. R(1, L(a))
  19. ], m);
  20. class E extends w {
  21. createSheetHyperlink(e, i) {
  22. return this._injector.get(a).buildHyperLink(this.getId(), e, i);
  23. }
  24. /**
  25. * Parse the hyperlink string to get the hyperlink info.
  26. * @param {string} hyperlink the hyperlink string
  27. * @returns {ISheetHyperLinkInfo} the hyperlink info
  28. */
  29. parseSheetHyperlink(e) {
  30. return this._injector.get(a).parseHyperLink(e);
  31. }
  32. }
  33. w.extend(E);
  34. class T extends _ {
  35. getUrl() {
  36. return this._injector.get(a).buildHyperLink(this._workbook.getUnitId(), this._worksheet.getSheetId());
  37. }
  38. }
  39. _.extend(T);
  40. class B extends y {
  41. // #region hyperlink
  42. setHyperLink(e, i) {
  43. const r = {
  44. unitId: this.getUnitId(),
  45. subUnitId: this._worksheet.getSheetId(),
  46. link: {
  47. row: this._range.startRow,
  48. column: this._range.startColumn,
  49. payload: e,
  50. display: i,
  51. id: f()
  52. }
  53. };
  54. return this._commandService.executeCommand(g.id, r);
  55. }
  56. getHyperLinks() {
  57. var i, r, n;
  58. const e = this._worksheet.getCellRaw(this._range.startRow, this._range.startColumn);
  59. return e != null && e.p ? (n = (r = (i = e.p.body) == null ? void 0 : i.customRanges) == null ? void 0 : r.filter((t) => t.rangeType === C.HYPERLINK).map((t) => {
  60. var s, h, c, p, l;
  61. return {
  62. id: `${t.rangeId}`,
  63. startIndex: t.startIndex,
  64. endIndex: t.endIndex,
  65. url: (h = (s = t.properties) == null ? void 0 : s.url) != null ? h : "",
  66. label: (l = (p = (c = e.p) == null ? void 0 : c.body) == null ? void 0 : p.dataStream.slice(t.startIndex, t.endIndex + 1).replaceAll(k.CUSTOM_RANGE_START, "").replaceAll(k.CUSTOM_RANGE_END, "")) != null ? l : ""
  67. };
  68. })) != null ? n : [] : [];
  69. }
  70. updateHyperLink(e, i, r) {
  71. const n = {
  72. unitId: this.getUnitId(),
  73. subUnitId: this._worksheet.getSheetId(),
  74. row: this._range.startRow,
  75. column: this._range.startColumn,
  76. id: e,
  77. payload: {
  78. payload: i,
  79. display: r
  80. }
  81. };
  82. return this._commandService.executeCommand(S.id, n);
  83. }
  84. cancelHyperLink(e) {
  85. const i = {
  86. unitId: this.getUnitId(),
  87. subUnitId: this._worksheet.getSheetId(),
  88. row: this._range.startRow,
  89. column: this._range.startColumn,
  90. id: e
  91. };
  92. return this._commandService.syncExecuteCommand(v.id, i);
  93. }
  94. getUrl() {
  95. return this._injector.get(a).buildHyperLink(this.getUnitId(), this.getSheetId(), this.getRange());
  96. }
  97. // #endregion
  98. }
  99. y.extend(B);
  100. class A {
  101. get BeforeSheetLinkAdd() {
  102. return "BeforeSheetLinkAdd";
  103. }
  104. get BeforeSheetLinkCancel() {
  105. return "BeforeSheetLinkCancel";
  106. }
  107. get BeforeSheetLinkUpdate() {
  108. return "BeforeSheetLinkUpdate";
  109. }
  110. }
  111. b.extend(A);
  112. class F extends u {
  113. _initialize(e) {
  114. const i = e.get(x);
  115. this.disposeWithMe(
  116. i.beforeCommandExecuted((r) => {
  117. if (r.id === g.id) {
  118. if (!this._eventListend(this.Event.BeforeSheetLinkAdd)) return;
  119. const n = this.getCommandSheetTarget(r);
  120. if (!n) return;
  121. const t = r.params, s = {
  122. workbook: n.workbook,
  123. worksheet: n.worksheet,
  124. row: t.link.row,
  125. col: t.link.column,
  126. link: t.link
  127. };
  128. if (this.fireEvent(this.Event.BeforeSheetLinkAdd, s), s.cancel)
  129. throw new d();
  130. }
  131. if (r.id === S.id) {
  132. const n = this.getCommandSheetTarget(r);
  133. if (!n) return;
  134. const t = r.params, s = {
  135. workbook: n.workbook,
  136. worksheet: n.worksheet,
  137. row: t.row,
  138. column: t.column,
  139. id: t.id,
  140. payload: t.payload
  141. };
  142. if (this.fireEvent(this.Event.BeforeSheetLinkUpdate, s), s.cancel)
  143. throw new d();
  144. }
  145. if (r.id === v.id) {
  146. const n = this.getCommandSheetTarget(r);
  147. if (!n) return;
  148. const t = r.params, s = {
  149. workbook: n.workbook,
  150. worksheet: n.worksheet,
  151. row: t.row,
  152. column: t.column,
  153. id: t.id
  154. };
  155. if (this.fireEvent(this.Event.BeforeSheetLinkCancel, s), s.cancel)
  156. throw new d();
  157. }
  158. })
  159. );
  160. }
  161. }
  162. u.extend(F);
  163. export {
  164. E as FWorkbookHyperLinkMixin
  165. };