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"; import { SheetsHyperLinkParserService as a, AddHyperLinkCommand as g, UpdateHyperLinkCommand as S, CancelHyperLinkCommand as v } from "@univerjs/sheets-hyper-link"; import { FWorkbook as w, FWorksheet as _, FRange as y } from "@univerjs/sheets/facade"; var I = Object.defineProperty, H = Object.getOwnPropertyDescriptor, U = (o, e, i, r) => { for (var n = r > 1 ? void 0 : r ? H(e, i) : e, t = o.length - 1, s; t >= 0; t--) (s = o[t]) && (n = (r ? s(e, i, n) : s(n)) || n); return r && n && I(e, i, n), n; }, R = (o, e) => (i, r) => e(i, r, o); let m = class { constructor(o, e) { this._workbook = o, this._parserService = e; } getRangeUrl(o) { return this._parserService.buildHyperLink(this._workbook.getId(), o.getSheetId(), o.getRange()), this; } }; m = U([ R(1, L(a)) ], m); class E extends w { createSheetHyperlink(e, i) { return this._injector.get(a).buildHyperLink(this.getId(), e, i); } /** * Parse the hyperlink string to get the hyperlink info. * @param {string} hyperlink the hyperlink string * @returns {ISheetHyperLinkInfo} the hyperlink info */ parseSheetHyperlink(e) { return this._injector.get(a).parseHyperLink(e); } } w.extend(E); class T extends _ { getUrl() { return this._injector.get(a).buildHyperLink(this._workbook.getUnitId(), this._worksheet.getSheetId()); } } _.extend(T); class B extends y { // #region hyperlink setHyperLink(e, i) { const r = { unitId: this.getUnitId(), subUnitId: this._worksheet.getSheetId(), link: { row: this._range.startRow, column: this._range.startColumn, payload: e, display: i, id: f() } }; return this._commandService.executeCommand(g.id, r); } getHyperLinks() { var i, r, n; const e = this._worksheet.getCellRaw(this._range.startRow, this._range.startColumn); 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) => { var s, h, c, p, l; return { id: `${t.rangeId}`, startIndex: t.startIndex, endIndex: t.endIndex, url: (h = (s = t.properties) == null ? void 0 : s.url) != null ? h : "", 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 : "" }; })) != null ? n : [] : []; } updateHyperLink(e, i, r) { const n = { unitId: this.getUnitId(), subUnitId: this._worksheet.getSheetId(), row: this._range.startRow, column: this._range.startColumn, id: e, payload: { payload: i, display: r } }; return this._commandService.executeCommand(S.id, n); } cancelHyperLink(e) { const i = { unitId: this.getUnitId(), subUnitId: this._worksheet.getSheetId(), row: this._range.startRow, column: this._range.startColumn, id: e }; return this._commandService.syncExecuteCommand(v.id, i); } getUrl() { return this._injector.get(a).buildHyperLink(this.getUnitId(), this.getSheetId(), this.getRange()); } // #endregion } y.extend(B); class A { get BeforeSheetLinkAdd() { return "BeforeSheetLinkAdd"; } get BeforeSheetLinkCancel() { return "BeforeSheetLinkCancel"; } get BeforeSheetLinkUpdate() { return "BeforeSheetLinkUpdate"; } } b.extend(A); class F extends u { _initialize(e) { const i = e.get(x); this.disposeWithMe( i.beforeCommandExecuted((r) => { if (r.id === g.id) { if (!this._eventListend(this.Event.BeforeSheetLinkAdd)) return; const n = this.getCommandSheetTarget(r); if (!n) return; const t = r.params, s = { workbook: n.workbook, worksheet: n.worksheet, row: t.link.row, col: t.link.column, link: t.link }; if (this.fireEvent(this.Event.BeforeSheetLinkAdd, s), s.cancel) throw new d(); } if (r.id === S.id) { const n = this.getCommandSheetTarget(r); if (!n) return; const t = r.params, s = { workbook: n.workbook, worksheet: n.worksheet, row: t.row, column: t.column, id: t.id, payload: t.payload }; if (this.fireEvent(this.Event.BeforeSheetLinkUpdate, s), s.cancel) throw new d(); } if (r.id === v.id) { const n = this.getCommandSheetTarget(r); if (!n) return; const t = r.params, s = { workbook: n.workbook, worksheet: n.worksheet, row: t.row, column: t.column, id: t.id }; if (this.fireEvent(this.Event.BeforeSheetLinkCancel, s), s.cancel) throw new d(); } }) ); } } u.extend(F); export { E as FWorkbookHyperLinkMixin };