var Ae = Object.defineProperty; var We = (s, e, t) => e in s ? Ae(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t; var w = (s, e, t) => We(s, typeof e != "symbol" ? e + "" : e, t); import { Disposable as V, ObjectMatrix as q, UniverInstanceType as v, IUniverInstanceService as E, CommandType as L, CustomRangeType as b, Inject as M, ICommandService as P, sequenceExecuteAsync as Re, isValidRange as Se, toDisposable as Be, DisposableCollection as je, Rectangle as Fe, Range as Ke, Tools as oe, BuildTextUtils as Z, generateRandomId as de, TextX as ce, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as Ye, IResourceManagerService as Ge, IUndoRedoService as Ie, CellValueType as ve, sequenceExecute as ze, getBodySlice as Ne, LocaleService as Je, DependentOn as Xe, Injector as qe, Plugin as Ze, merge as Qe, registerDependencies as et, touchDependencies as tt, IConfigService as nt } from "@univerjs/core"; import { Subject as rt } from "rxjs"; import { getSheetCommandTarget as j, RefRangeService as Oe, SheetsSelectionsService as ke, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as st, handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests as it, SheetInterceptorService as le, RemoveSheetCommand as at, handleDefaultRangeChangeWithEffectRefCommands as ot, SetRangeValuesMutation as H, SetRangeValuesCommand as dt, ClearSelectionContentCommand as ct, ClearSelectionAllCommand as lt, ClearSelectionFormatCommand as ut, AFTER_CELL_EDIT as pt, SetRangeValuesUndoMutationFactory as Me, UniverSheetsPlugin as ht } from "@univerjs/sheets"; import { deserializeRangeWithSheet as Ce, serializeRange as B, serializeRangeWithSheet as gt, IDefinedNamesService as ft } from "@univerjs/engine-formula"; import { addCustomRangeBySelectionFactory as _t, deleteCustomRangeFactory as mt, replaceSelectionFactory as De } from "@univerjs/docs"; var yt = Object.defineProperty, Rt = Object.getOwnPropertyDescriptor, St = (s, e, t, n) => { for (var r = n > 1 ? void 0 : n ? Rt(e, t) : e, i = s.length - 1, a; i >= 0; i--) (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r); return n && r && yt(e, t, r), r; }, It = (s, e) => (t, n) => e(t, n, s); let I = class extends V { constructor(e) { super(); w(this, "_linkUpdate$", new rt()); w(this, "linkUpdate$", this._linkUpdate$.asObservable()); w(this, "_linkMap", /* @__PURE__ */ new Map()); w(this, "_linkPositionMap", /* @__PURE__ */ new Map()); this._univerInstanceService = e, this.disposeWithMe({ dispose: () => { this._linkUpdate$.complete(); } }); } _ensureMap(e, t) { let n = this._linkMap.get(e); n || (n = /* @__PURE__ */ new Map(), this._linkMap.set(e, n)); let r = n.get(t); r || (r = new q(), n.set(t, r)); let i = this._linkPositionMap.get(e); i || (i = /* @__PURE__ */ new Map(), this._linkPositionMap.set(e, i)); let a = i.get(t); return a || (a = /* @__PURE__ */ new Map(), i.set(t, a)), { matrix: r, positionMap: a }; } addHyperLink(e, t, n) { const { matrix: r, positionMap: i } = this._ensureMap(e, t); return r.setValue(n.row, n.column, n), i.set(n.id, { row: n.row, column: n.column, link: n }), this._linkUpdate$.next({ unitId: e, subUnitId: t, payload: n, type: "add" }), !0; } updateHyperLink(e, t, n, r, i = !1) { const { matrix: a, positionMap: o } = this._ensureMap(e, t), c = o.get(n); if (!c) return !0; const d = a.getValue(c.row, c.column); return d && (Object.assign(d, r), this._linkUpdate$.next({ unitId: e, subUnitId: t, payload: { display: d.display, payload: d.payload }, id: n, type: "update", silent: i })), !0; } updateHyperLinkRef(e, t, n, r, i = !1) { const { matrix: a, positionMap: o } = this._ensureMap(e, t), c = o.get(n); if (!c) return !0; let d = a.getValue(c.row, c.column); return !d || d.id !== n ? d = c.link : a.realDeleteValue(c.row, c.column), Object.assign(d, r), o.set(n, { ...r, link: d }), a.setValue(r.row, r.column, d), this._linkUpdate$.next({ unitId: e, subUnitId: t, payload: r, id: n, type: "updateRef", silent: i }), !0; } removeHyperLink(e, t, n) { const { matrix: r, positionMap: i } = this._ensureMap(e, t), a = i.get(n); if (!a) return !1; i.delete(n); const o = r.getValue(a.row, a.column); return o && o.id === n && r.realDeleteValue(a.row, a.column), this._linkUpdate$.next({ unitId: e, subUnitId: t, payload: a.link, type: "remove" }), !0; } getHyperLink(e, t, n) { const { matrix: r, positionMap: i } = this._ensureMap(e, t), a = i.get(n); if (a) return r.getValue(a.row, a.column); } getHyperLinkByLocation(e, t, n, r) { const { matrix: i } = this._ensureMap(e, t); return i.getValue(n, r); } getHyperLinkByLocationSync(e, t, n, r) { var l, u, h, g, p; const { matrix: i } = this._ensureMap(e, t), a = this._univerInstanceService.getUnit(e, v.UNIVER_SHEET), o = (l = a == null ? void 0 : a.getSheetBySheetId(t)) == null ? void 0 : l.getCellRaw(n, r), c = ((p = (g = o == null ? void 0 : o.v) != null ? g : (h = (u = o == null ? void 0 : o.p) == null ? void 0 : u.body) == null ? void 0 : h.dataStream.slice(0, -2)) != null ? p : "").toString(), d = i.getValue(n, r); if (d) return { ...d, display: c }; } getSubUnit(e, t) { const { matrix: n } = this._ensureMap(e, t), r = []; return n.forValue((i, a, o) => { o && r.push(o); }), r; } getUnit(e) { const t = this._linkMap.get(e); return t ? Array.from(t.keys()).map((n) => { const r = this.getSubUnit(e, n); return { unitId: e, subUnitId: n, links: r }; }) : []; } deleteUnit(e) { const t = this.getUnit(e); this._linkMap.delete(e), this._linkPositionMap.delete(e), this._linkUpdate$.next({ type: "unload", unitId: e, unitLinks: t }); } getAll() { return Array.from(this._linkMap.keys()).map((t) => this.getUnit(t)); } }; I = St([ It(0, E) ], I); var U = /* @__PURE__ */ ((s) => (s.SHEET = "gid", s.RANGE = "range", s.DEFINE_NAME = "rangeid", s.INVALID = "invalid", s.URL = "url", s))(U || {}); const vt = "sheets-hyper-link.config", Ue = {}, O = { type: L.MUTATION, id: "sheets.mutation.add-hyper-link", handler(s, e) { if (!e) return !1; const t = s.get(I), { unitId: n, subUnitId: r, link: i } = e; return t.addHyperLink(n, r, i); } }, k = { type: L.MUTATION, id: "sheets.mutation.remove-hyper-link", handler(s, e) { if (!e) return !1; const t = s.get(I), { unitId: n, subUnitId: r, id: i } = e; return t.removeHyperLink(n, r, i); } }, _e = { type: L.MUTATION, id: "sheets.mutation.update-hyper-link", handler(s, e) { if (!e) return !1; const t = s.get(I), { unitId: n, subUnitId: r, payload: i, id: a } = e; return t.updateHyperLink(n, r, a, i, !1); } }, me = { type: L.MUTATION, id: "sheets.mutation.update-hyper-link-ref", handler(s, e) { if (!e) return !1; const t = s.get(I), { unitId: n, subUnitId: r, id: i, row: a, column: o, silent: c } = e; return t.updateHyperLinkRef(n, r, i, { row: a, column: o }, c); } }, X = { type: L.MUTATION, id: "sheets.mutation.update-rich-hyper-link", handler(s, e) { var g, p, f; if (!e) return !1; const { unitId: t, subUnitId: n, row: r, col: i, id: a, url: o } = e, c = s.get(E), d = j(c, { unitId: t, subUnitId: n }); if (!d) return !1; const { worksheet: l } = d, u = l.getCellRaw(r, i), h = (f = (p = (g = u == null ? void 0 : u.p) == null ? void 0 : g.body) == null ? void 0 : p.customRanges) == null ? void 0 : f.find((_) => _.rangeType === b.HYPERLINK && _.rangeId === a); return h && (h.properties.url = o), !0; } }, He = "SHEET_HYPER_LINK_PLUGIN", Q = "err"; var Mt = Object.defineProperty, Ct = Object.getOwnPropertyDescriptor, wt = (s, e, t, n) => { for (var r = n > 1 ? void 0 : n ? Ct(e, t) : e, i = s.length - 1, a; i >= 0; i--) (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r); return n && r && Mt(e, t, r), r; }, z = (s, e) => (t, n) => e(t, n, s); let ee = class extends V { constructor(e, t, n, r) { super(); w(this, "_disposableMap", /* @__PURE__ */ new Map()); w(this, "_watchDisposableMap", /* @__PURE__ */ new Map()); w(this, "_rangeDisableMap", /* @__PURE__ */ new Map()); w(this, "_rangeWatcherMap", /* @__PURE__ */ new Map()); w(this, "_handlePositionChange", (e, t, n, r, i) => { const a = { startColumn: n.column, endColumn: n.column, startRow: n.row, endRow: n.row }; return r ? { redos: [{ id: me.id, params: { unitId: e, subUnitId: t, id: n.id, row: r.startRow, column: r.startColumn, silent: i } }], undos: [{ id: me.id, params: { unitId: e, subUnitId: t, id: n.id, row: a.startRow, column: a.startColumn, silent: i } }] } : { redos: [{ id: k.id, params: { unitId: e, subUnitId: t, id: n.id } }], undos: [{ id: O.id, params: { unitId: e, subUnitId: t, link: n } }] }; }); this._refRangeService = e, this._hyperLinkModel = t, this._selectionManagerService = n, this._commandService = r, this._initData(), this._initRefRange(); } _registerPosition(e, t, n) { const r = n.id, i = { startColumn: n.column, endColumn: n.column, startRow: n.row, endRow: n.row }, a = (o) => { const c = st(i, o, { selectionManagerService: this._selectionManagerService }), d = Array.isArray(c) ? c[0] : c; return d && d.startColumn === i.startColumn && d.startRow === i.startRow ? { undos: [], redos: [] } : this._handlePositionChange(e, t, n, d, !1); }; this._disposableMap.set(r, this._refRangeService.registerRefRange(i, a, e, t)); } _watchPosition(e, t, n) { const r = n.id, i = { startColumn: n.column, endColumn: n.column, startRow: n.row, endRow: n.row }; this._watchDisposableMap.set( r, this._refRangeService.watchRange(e, t, i, (a, o) => { const { redos: c } = this._handlePositionChange(e, t, n, o, !0); Re(c, this._commandService, { onlyLocal: !0 }); }, !0) ); } _unregisterPosition(e) { const t = this._disposableMap.get(e); t == null || t.dispose(), this._disposableMap.delete(e); } _unwatchPosition(e) { const t = this._watchDisposableMap.get(e); t == null || t.dispose(), this._watchDisposableMap.delete(e); } _registerRange(e, t, n, r = !1) { var i, a, o; if (n.startsWith("#")) { const c = new URLSearchParams(n.slice(1)), d = { gid: (i = c.get("gid")) != null ? i : "", range: (a = c.get("range")) != null ? a : "", rangeid: (o = c.get("rangeid")) != null ? o : "" }; if (d.range && d.gid) { const l = d.gid, u = Ce(d.range).range; if (Se(u) && d.range !== Q) { const h = (g) => { const p = it(u, g, { selectionManagerService: this._selectionManagerService }); return p && B(p) === B(u) ? { redos: [], undos: [] } : { redos: [{ id: _e.id, params: { unitId: e, subUnitId: l, id: t, payload: { payload: `#gid=${l}&range=${p ? B(p) : "err"}` } } }], undos: [{ id: _e.id, params: { unitId: e, subUnitId: l, id: t, payload: { payload: n } } }] }; }; this._rangeDisableMap.set(t, this._refRangeService.registerRefRange(u, h, e, l)), r || this._rangeWatcherMap.set(t, this._refRangeService.watchRange(e, l, u, (g, p) => { this._hyperLinkModel.updateHyperLink(e, l, t, { payload: `#gid=${l}&range=${p ? B(p) : "err"}` }, !0); }, !0)); } } } } _unregisterRange(e) { const t = this._rangeDisableMap.get(e); t == null || t.dispose(), this._rangeDisableMap.delete(e); } _unwatchRange(e) { const t = this._rangeWatcherMap.get(e); t == null || t.dispose(), this._rangeWatcherMap.delete(e); } _initData() { this._hyperLinkModel.getAll().forEach((t) => { t.forEach((n) => { const { unitId: r, subUnitId: i, links: a } = n; a.forEach((o) => { this._registerPosition(r, i, o), this._watchPosition(r, i, o), this._registerRange(r, o.id, o.payload); }); }); }); } _initRefRange() { this.disposeWithMe( this._hyperLinkModel.linkUpdate$.subscribe((e) => { switch (e.type) { case "add": { this._registerPosition(e.unitId, e.subUnitId, e.payload), this._watchPosition(e.unitId, e.subUnitId, e.payload), this._registerRange(e.unitId, e.payload.id, e.payload.payload); break; } case "remove": { this._unregisterPosition(e.payload.id), this._unwatchPosition(e.payload.id), this._unregisterRange(e.payload.id), this._unwatchRange(e.payload.id); break; } case "updateRef": { const { unitId: t, subUnitId: n, id: r, silent: i } = e, a = this._hyperLinkModel.getHyperLink(t, n, r); if (!a) return; this._unregisterPosition(r), this._registerPosition(t, n, a), i || (this._unwatchPosition(r), this._watchPosition(t, n, a)); break; } case "unload": { const { unitLinks: t } = e; t.forEach((n) => { const { links: r } = n; r.forEach((i) => { this._unregisterPosition(i.id), this._unwatchPosition(i.id), this._unregisterRange(i.id), this._unwatchRange(i.id); }); }); break; } case "update": { e.silent || this._unwatchRange(e.id), this._unregisterRange(e.id), this._registerRange(e.unitId, e.id, e.payload.payload, e.silent); break; } } }) ), this.disposeWithMe(Be(() => { this._disposableMap.forEach((e) => { e.dispose(); }), this._disposableMap.clear(); })); } }; ee = wt([ z(0, M(Oe)), z(1, M(I)), z(2, M(ke)), z(3, P) ], ee); var Et = Object.defineProperty, Lt = Object.getOwnPropertyDescriptor, Ut = (s, e, t, n) => { for (var r = n > 1 ? void 0 : n ? Lt(e, t) : e, i = s.length - 1, a; i >= 0; i--) (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r); return n && r && Et(e, t, r), r; }, he = (s, e) => (t, n) => e(t, n, s); let te = class extends V { constructor(s, e, t) { super(), this._sheetInterceptorService = s, this._univerInstanceService = e, this._hyperLinkModel = t, this._initSheetChange(); } _initSheetChange() { this.disposeWithMe( this._sheetInterceptorService.interceptCommand({ getMutations: (s) => { var e; if (s.id === at.id) { const t = s.params, n = t.unitId ? this._univerInstanceService.getUnit(t.unitId) : this._univerInstanceService.getCurrentUnitForType(v.UNIVER_SHEET); if (!n) return { redos: [], undos: [] }; const r = n.getUnitId(), i = t.subUnitId || ((e = n.getActiveSheet()) == null ? void 0 : e.getSheetId()); if (!i) return { redos: [], undos: [] }; const a = this._hyperLinkModel.getSubUnit(r, i), o = a.map((d) => ({ id: k.id, params: { unitId: r, subUnitId: i, id: d.id } })), c = a.map((d) => ({ id: O.id, params: { unitId: r, subUnitId: i, link: d } })); return { redos: o, undos: c }; } return { redos: [], undos: [] }; } }) ); } }; te = Ut([ he(0, M(le)), he(1, E), he(2, M(I)) ], te); var bt = Object.defineProperty, Pt = Object.getOwnPropertyDescriptor, Nt = (s, e, t, n) => { for (var r = n > 1 ? void 0 : n ? Pt(e, t) : e, i = s.length - 1, a; i >= 0; i--) (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r); return n && r && bt(e, t, r), r; }, ge = (s, e) => (t, n) => e(t, n, s); let ne = class extends V { constructor(e, t, n) { super(); w(this, "_refRangeMap", /* @__PURE__ */ new Map()); this._commandService = e, this._univerInstanceService = t, this._refRangeService = n, this._initWorkbookLoad(), this._initWorkbookUnload(), this._initSetRangesListener(); } _enusreMap(e, t) { let n = this._refRangeMap.get(e); n || (n = /* @__PURE__ */ new Map(), this._refRangeMap.set(e, n)); let r = n.get(t); return r || (r = new q(), n.set(t, r)), r; } _isLegalRangeUrl(e, t) { var r, i, a; const n = this._univerInstanceService.getUnit(e, v.UNIVER_SHEET); if (!n) return null; if (t && t.startsWith("#")) { const o = new URLSearchParams(t.slice(1)), c = { gid: (r = o.get("gid")) != null ? r : "", range: (i = o.get("range")) != null ? i : "", rangeid: (a = o.get("rangeid")) != null ? a : "" }; if (c.range && c.gid) { const d = c.gid, l = n.getSheetBySheetId(d); if (!l) return null; const u = Ce(c.range).range; if (Se(u, l) && c.range !== Q) return { range: u, worksheet: l }; } } return null; } _registerRange(e, t, n, r, i) { var o, c, d, l; const a = this._enusreMap(e, t); if ((c = (o = i.body) == null ? void 0 : o.customRanges) != null && c.some((u) => { var h; return u.rangeType === b.HYPERLINK && this._isLegalRangeUrl(e, (h = u.properties) == null ? void 0 : h.url); })) { const u = new je(); let h = !1; (l = (d = i.body) == null ? void 0 : d.customRanges) == null || l.forEach((g) => { var p; if (g.rangeType === b.HYPERLINK) { const f = (p = g.properties) == null ? void 0 : p.url, _ = this._isLegalRangeUrl(e, f); if (_) { const { range: m, worksheet: C } = _; h = !0, u.add( this._refRangeService.registerRefRange( m, (y) => { const R = ot(m, y); return R && Fe.equals(R, m) ? { preRedos: [], preUndos: [], redos: [], undos: [] } : { preRedos: [{ id: X.id, params: { unitId: e, subUnitId: t, row: n, col: r, id: g.rangeId, url: `#gid=${t}&range=${R ? B(R) : Q}` } }], undos: [{ id: X.id, params: { unitId: e, subUnitId: t, row: n, col: r, id: g.rangeId, url: f } }], redos: [] }; }, C.getUnitId(), C.getSheetId() ) ); } } }), h && a.setValue(n, r, u); } } _initWorkbookLoad() { const e = (t) => { const n = t.getUnitId(); t.getSheets().forEach((r) => { const i = r.getSheetId(), a = this._enusreMap(n, i); r.getCellMatrix().forValue((o, c, d) => { const l = a.getValue(o, c); l && l.dispose(), d && d.p && this._registerRange(n, i, o, c, d.p); }); }); }; this._univerInstanceService.getAllUnitsForType(v.UNIVER_SHEET).forEach((t) => { e(t); }), this.disposeWithMe( this._univerInstanceService.unitAdded$.subscribe((t) => { t.type === v.UNIVER_SHEET && e(t); }) ); } _initWorkbookUnload() { this._univerInstanceService.unitDisposed$.subscribe((e) => { if (e.type === v.UNIVER_SHEET) { const t = e, n = t.getUnitId(); t.getSheets().forEach((r) => { const i = r.getSheetId(); this._enusreMap(n, i).forValue((o, c, d) => { d && d.dispose(); }); }), this._refRangeMap.delete(n); } }); } _initSetRangesListener() { this.disposeWithMe( this._commandService.onCommandExecuted((e) => { if (e.id === H.id) { const t = e.params, { unitId: n, subUnitId: r, cellValue: i } = t, a = this._enusreMap(n, r); i && new q(i).forValue((o, c, d) => { const l = a.getValue(o, c); l && l.dispose(), d && d.p && this._registerRange(n, r, o, c, d.p); }); } }) ), this.disposeWithMe( this._commandService.onCommandExecuted((e) => { if (e.id === X.id) { const t = e.params, { unitId: n, subUnitId: r, row: i, col: a } = t, o = j(this._univerInstanceService, { unitId: n, subUnitId: r }), d = this._enusreMap(n, r).getValue(i, a); if (d && d.dispose(), o) { const { worksheet: l } = o, u = l.getCellRaw(i, a); u && u.p && this._registerRange(n, r, i, a, u.p); } } }) ); } }; ne = Nt([ ge(0, P), ge(1, E), ge(2, M(Oe)) ], ne); var Ot = Object.defineProperty, kt = Object.getOwnPropertyDescriptor, Dt = (s, e, t, n) => { for (var r = n > 1 ? void 0 : n ? kt(e, t) : e, i = s.length - 1, a; i >= 0; i--) (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r); return n && r && Ot(e, t, r), r; }, J = (s, e) => (t, n) => e(t, n, s); let re = class extends V { constructor(s, e, t, n) { super(), this._sheetInterceptorService = s, this._hyperLinkModel = e, this._selectionManagerService = t, this._univerInstanceService = n, this._initCommandInterceptor(), this._initAfterEditor(); } _initCommandInterceptor() { this._initSetRangeValuesCommandInterceptor(), this._initClearSelectionCommandInterceptor(); } _initSetRangeValuesCommandInterceptor() { this.disposeWithMe(this._sheetInterceptorService.interceptCommand({ getMutations: (s) => { if (s.id === dt.id) { const e = s.params, { unitId: t, subUnitId: n } = e, r = [], i = []; return e.cellValue && new q(e.cellValue).forValue((a, o) => { const c = this._hyperLinkModel.getHyperLinkByLocation(t, n, a, o); c && (r.push({ id: k.id, params: { unitId: t, subUnitId: n, id: c.id } }), i.push({ id: O.id, params: { unitId: t, subUnitId: n, link: c } })); }), { undos: i, redos: r }; } return { redos: [], undos: [] }; } })); } _initClearSelectionCommandInterceptor() { this.disposeWithMe(this._sheetInterceptorService.interceptCommand({ getMutations: (s) => { if (s.id === ct.id || s.id === lt.id || s.id === ut.id) { const e = [], t = [], n = this._selectionManagerService.getCurrentLastSelection(), r = j(this._univerInstanceService); if (n && r) { const { unitId: i, subUnitId: a } = r; Ke.foreach(n.range, (o, c) => { const d = this._hyperLinkModel.getHyperLinkByLocation(i, a, o, c); d && (e.push({ id: k.id, params: { unitId: i, subUnitId: a, id: d.id } }), t.push({ id: O.id, params: { unitId: i, subUnitId: a, link: d } })); }); } return { redos: e, undos: t }; } return { redos: [], undos: [] }; } })); } _initAfterEditor() { this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(pt, { handler: (s, e, t) => { if (!s || s.p) return t(s); if (typeof s.v == "string" && oe.isLegalUrl(s.v) && s.v[s.v.length - 1] !== " ") { const { unitId: n, subUnitId: r } = e, i = this._univerInstanceService.getUnit(n, v.UNIVER_SHEET), a = i == null ? void 0 : i.getSheetBySheetId(r); if (!a) return t(s); const o = a.getBlankCellDocumentModel(s); if (!o.documentModel) return t(s); const c = Z.selection.replace({ selection: { startOffset: 0, endOffset: s.v.length, collapsed: !1 }, body: { dataStream: `${s.v}`, customRanges: [{ startIndex: 0, endIndex: s.v.length - 1, rangeId: de(), rangeType: b.HYPERLINK, properties: { url: s.v } }] }, doc: o.documentModel }); if (!c) return t(s); const d = o.documentModel.getBody(); return ce.apply(d, c.serialize()), t({ ...s, p: { id: Ye, body: d, documentStyle: { pageSize: { width: 1 / 0, height: 1 / 0 } } } }); } return t(s); } })); } }; re = Dt([ J(0, M(le)), J(1, M(I)), J(2, M(ke)), J(3, E) ], re); var Ve = /* @__PURE__ */ ((s) => (s[s.UNIVER_UNKNOWN = 0] = "UNIVER_UNKNOWN", s[s.UNIVER_DOC = 1] = "UNIVER_DOC", s[s.UNIVER_SHEET = 2] = "UNIVER_SHEET", s[s.UNIVER_SLIDE = 3] = "UNIVER_SLIDE", s[s.UNIVER_PROJECT = 4] = "UNIVER_PROJECT", s[s.UNRECOGNIZED = -1] = "UNRECOGNIZED", s))(Ve || {}), Ht = Object.defineProperty, Vt = Object.getOwnPropertyDescriptor, $t = (s, e, t, n) => { for (var r = n > 1 ? void 0 : n ? Vt(e, t) : e, i = s.length - 1, a; i >= 0; i--) (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r); return n && r && Ht(e, t, r), r; }, be = (s, e) => (t, n) => e(t, n, s); let se = class extends V { constructor(s, e) { super(), this._resourceManagerService = s, this._hyperLinkModel = e, this._initSnapshot(); } _initSnapshot() { const s = (t) => { const n = this._hyperLinkModel.getUnit(t), r = {}; return n ? (n.forEach((i) => { r[i.subUnitId] = i.links.map(({ display: a, ...o }) => o); }), JSON.stringify(r)) : ""; }, e = (t) => { if (!t) return {}; try { return JSON.parse(t); } catch { return {}; } }; this.disposeWithMe( this._resourceManagerService.registerPluginResource({ pluginName: He, businesses: [Ve.UNIVER_SHEET], toJson: (t) => s(t), parseJson: (t) => e(t), onUnLoad: (t) => { this._hyperLinkModel.deleteUnit(t); }, onLoad: async (t, n) => { Object.keys(n).forEach((r) => { n[r].forEach((a) => { this._hyperLinkModel.addHyperLink(t, r, a); }); }); } }) ); } }; se = $t([ be(0, Ge), be(1, M(I)) ], se); const xt = { type: L.COMMAND, id: "sheets.command.add-hyper-link", // eslint-disable-next-line max-lines-per-function async handler(s, e) { if (!e) return !1; const t = s.get(P), n = s.get(Ie), r = s.get(E), i = s.get(I), a = s.get(le), o = j(r, e); if (!o) return !1; const { unitId: c, subUnitId: d, workbook: l, worksheet: u } = o, { link: h } = e, { payload: g, display: p, row: f, column: _, id: m } = h, C = u.getCell(f, _), y = u.getBlankCellDocumentModel(C), R = y.documentModel.getSnapshot(), S = oe.deepClone(R.body); if (!S) return !1; let N; if (p ? N = Z.selection.replace({ selection: { startOffset: 0, endOffset: S.dataStream.length - 2, collapsed: S.dataStream.length - 2 === 0 }, body: { dataStream: `${p}`, customRanges: [{ startIndex: 0, endIndex: p.length - 1, rangeType: b.HYPERLINK, rangeId: m, properties: { url: g // refId: id, } }] }, doc: y.documentModel }) : N = Z.customRange.add({ body: S, ranges: [{ startOffset: 0, endOffset: S.dataStream.length - 2, collapsed: !1 }], rangeId: m, rangeType: b.HYPERLINK, properties: { url: g, refId: m } }), !N) return !1; const F = ce.apply(S, N.serialize()), D = { p: { ...R, body: F }, t: ve.STRING }, x = await a.onWriteCell(l, u, f, _, D), T = { unitId: c, subUnitId: d, cellValue: { [h.row]: { [h.column]: x } } }, ue = { id: H.id, params: T }, Y = Me(s, T), pe = { id: H.id, params: Y }, K = [ue], A = [pe], W = i.getHyperLinkByLocation(c, d, f, _); return W && (K.push({ id: k.id, params: { unitId: c, subUnitId: d, id: W.id } }), A.push({ id: O.id, params: { unitId: c, subUnitId: d, link: W } })), await Re(K, t) ? (n.pushUndoRedo({ redoMutations: K, undoMutations: A, unitID: c }), !0) : !1; } }, Tt = { id: "sheets.command.add-rich-hyper-link", type: L.COMMAND, handler: async (s, e) => { if (!e) return !1; const { documentId: t, link: n } = e, r = s.get(P), i = de(), { payload: a } = n, o = _t(s, { unitId: t, rangeId: i, rangeType: b.HYPERLINK, properties: { url: a, refId: i } }); return o ? r.syncExecuteCommand(o.id, o.params) : !1; } }, At = { type: L.COMMAND, id: "sheets.command.cancel-hyper-link", // eslint-disable-next-line max-lines-per-function handler(s, e) { var D, x; if (!e) return !1; const t = s.get(P), n = s.get(Ie), r = s.get(E), i = s.get(I), a = j(r, e); if (!a) return !1; const { row: o, column: c, id: d } = e, { unitId: l, subUnitId: u, worksheet: h } = a, g = h.getCell(o, c); if (!g) return !1; const p = h.getCellDocumentModelWithFormula(g); if (!(p != null && p.documentModel)) return !1; const f = oe.deepClone(p.documentModel.getSnapshot()), _ = (x = (D = f.body) == null ? void 0 : D.customRanges) == null ? void 0 : x.find((T) => `${T.rangeId}` === d); if (!_) return !1; const m = Z.customRange.delete({ documentDataModel: p.documentModel, rangeId: _.rangeId }); if (!m) return !1; const C = ce.apply(f.body, m.serialize()), y = [], R = [], S = { unitId: l, subUnitId: u, cellValue: { [o]: { [c]: { p: { ...f, body: C }, t: ve.STRING } } } }; y.push({ id: H.id, params: S }); const N = Me(s, S); R.push({ id: H.id, params: N }); const F = i.getHyperLinkByLocation(l, u, o, c); return F && (y.push({ id: k.id, params: { unitId: l, subUnitId: u, id: d } }), R.push({ id: O.id, params: { unitId: l, subUnitId: u, link: { ...F } } })), ze(y, t).result ? (n.pushUndoRedo({ redoMutations: y, undoMutations: R, unitID: l }), !0) : !1; } }, Wt = { type: L.COMMAND, id: "sheets.command.cancel-rich-hyper-link", handler(s, e) { var l, u; if (!e) return !1; const { id: t, documentId: n } = e, r = s.get(P), a = s.get(E).getUnit(n, v.UNIVER_DOC), o = (u = (l = a == null ? void 0 : a.getBody()) == null ? void 0 : l.customRanges) == null ? void 0 : u.find((h) => h.rangeId === t); let c = null; o && o.endIndex === a.getBody().dataStream.length - 3 && (c = { dataStream: " " }); const d = mt(s, { unitId: n, rangeId: t, insert: c }); return d ? r.syncExecuteCommand(d.id, d.params) : !1; } }, Bt = { type: L.COMMAND, id: "sheets.command.update-hyper-link", // eslint-disable-next-line max-lines-per-function async handler(s, e) { var we, Ee, Le; if (!e) return !1; const t = s.get(P), n = s.get(Ie), r = s.get(E), i = s.get(I), a = s.get(le), o = j(r, { unitId: e.unitId, subUnitId: e.subUnitId }); if (!o) return !1; const { payload: c, row: d, column: l, id: u } = e, { workbook: h, worksheet: g, unitId: p, subUnitId: f } = o, { payload: _, display: m = "" } = c, C = g.getCell(d, l); if (!C) return !1; const y = g.getCellDocumentModelWithFormula(C); if (!(y != null && y.documentModel)) return !1; const R = y.documentModel.getSnapshot(), S = (Ee = (we = R.body) == null ? void 0 : we.customRanges) == null ? void 0 : Ee.find((Te) => `${Te.rangeId}` === u); if (!S) return !1; const N = de(), $ = (Le = Ne(y.documentModel.getBody(), S.startIndex, S.endIndex + 1).textRuns) == null ? void 0 : Le[0]; $ && ($.ed = m.length + 1); const D = De(s, { unitId: p, body: { dataStream: `${m}`, customRanges: [{ rangeId: N, rangeType: b.HYPERLINK, startIndex: 0, endIndex: m.length - 1, properties: { url: _ } }], textRuns: $ ? [$] : void 0 }, selection: { startOffset: S.startIndex, endOffset: S.endIndex + 1, collapsed: !1 }, doc: y.documentModel }); if (!D) return !1; const x = ce.apply(oe.deepClone(R.body), D.textX.serialize()), T = { p: { ...R, body: x }, t: ve.STRING }, ue = await a.onWriteCell(h, g, d, l, T), Y = { id: H.id, params: { unitId: p, subUnitId: f, cellValue: { [d]: { [l]: ue } } } }, pe = Me(s, Y.params), K = { id: H.id, params: pe }, A = [Y], W = [K], G = i.getHyperLinkByLocation(p, f, d, l); return G && (A.push({ id: k.id, params: { unitId: p, subUnitId: f, id: G.id } }), W.push({ id: O.id, params: { unitId: p, subUnitId: f, link: G } })), await Re(A, t) ? (n.pushUndoRedo({ redoMutations: A, undoMutations: W, unitID: p }), !0) : !1; } }, jt = { type: L.COMMAND, id: "sheets.command.update-rich-hyper-link", handler: (s, e) => { var p, f, _, m; if (!e) return !1; const { documentId: t, payload: n, id: r } = e, i = s.get(E), a = s.get(P), o = i.getUnit(t, v.UNIVER_DOC); if (!o) return !1; const c = (f = (p = o.getBody()) == null ? void 0 : p.customRanges) == null ? void 0 : f.find((C) => C.rangeId === r); if (!c) return !1; const d = (_ = e.payload.display) != null ? _ : "", l = de(), h = (m = Ne(o.getBody(), c.startIndex, c.endIndex + 1).textRuns) == null ? void 0 : m[0]; h && (h.ed = d.length + 1); const g = De(s, { unitId: t, body: { dataStream: `${d}`, customRanges: [{ rangeId: l, rangeType: b.HYPERLINK, startIndex: 0, endIndex: d.length - 1, properties: { url: n.payload } }], textRuns: h ? [h] : void 0 }, selection: { startOffset: c.startIndex, endOffset: c.endIndex + 1, collapsed: !1 }, doc: o }); return g ? a.syncExecuteCommand(g.id, g.params) : !1; } }; var Ft = Object.defineProperty, Kt = Object.getOwnPropertyDescriptor, Yt = (s, e, t, n) => { for (var r = n > 1 ? void 0 : n ? Kt(e, t) : e, i = s.length - 1, a; i >= 0; i--) (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r); return n && r && Ft(e, t, r), r; }, Gt = (s, e) => (t, n) => e(t, n, s); let ie = class extends V { constructor(s) { super(), this._commandService = s, this._registerCommands(); } _registerCommands() { [ xt, Bt, At, jt, Wt, Tt, O, _e, k, me, X ].forEach((s) => { this._commandService.registerCommand(s); }); } }; ie = Yt([ Gt(0, P) ], ie); var zt = Object.defineProperty, Jt = Object.getOwnPropertyDescriptor, Xt = (s, e, t, n) => { for (var r = n > 1 ? void 0 : n ? Jt(e, t) : e, i = s.length - 1, a; i >= 0; i--) (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r); return n && r && zt(e, t, r), r; }, fe = (s, e) => (t, n) => e(t, n, s); let ye = class { constructor(s, e, t) { this._univerInstanceService = s, this._localeService = e, this._definedNamesService = t; } buildHyperLink(s, e, t) { return `#${U.SHEET}=${e}${t ? `&${typeof t == "string" ? U.DEFINE_NAME : U.RANGE}=${typeof t == "string" ? t : B(t)}` : ""}`; } parseHyperLink(s) { var e, t, n, r; if (s.startsWith("#")) { const i = new URLSearchParams(s.slice(1)), a = { gid: (e = i.get("gid")) != null ? e : "", range: (t = i.get("range")) != null ? t : "", rangeid: (n = i.get("rangeid")) != null ? n : "", unitid: (r = i.get("unitid")) != null ? r : "" }, o = this._getURLName(a); return { type: o.type, name: o.name, url: s, searchObj: a }; } else return { type: U.URL, name: s, url: s, searchObj: null }; } _getURLName(s) { var d; const { gid: e, range: t, rangeid: n, unitid: r } = s, i = r ? this._univerInstanceService.getUnit(r, v.UNIVER_SHEET) : this._univerInstanceService.getCurrentUnitForType(v.UNIVER_SHEET), a = { type: U.INVALID, name: this._localeService.t("hyperLink.message.refError") }; if (!i) return a; const o = e ? i.getSheetBySheetId(e) : i.getActiveSheet(), c = (d = o == null ? void 0 : o.getName()) != null ? d : ""; if (t) { if (!o) return a; const l = Ce(t).range; return Se(l, o) && t !== Q ? { type: U.RANGE, name: gt(c, l) } : a; } if (n) { const l = this._definedNamesService.getValueById(i.getUnitId(), n); return l ? { type: U.DEFINE_NAME, name: l.formulaOrRefString } : a; } if (e) { const l = i.getSheetBySheetId(e); return l ? { type: U.SHEET, name: l.getName() } : a; } return a; } }; ye = Xt([ fe(0, E), fe(1, M(Je)), fe(2, ft) ], ye); var $e = Object.defineProperty, qt = Object.getOwnPropertyDescriptor, Zt = (s, e, t) => e in s ? $e(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, Qt = (s, e, t, n) => { for (var r = n > 1 ? void 0 : n ? qt(e, t) : e, i = s.length - 1, a; i >= 0; i--) (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r); return n && r && $e(e, t, r), r; }, Pe = (s, e) => (t, n) => e(t, n, s), xe = (s, e, t) => Zt(s, typeof e != "symbol" ? e + "" : e, t); let ae = class extends Ze { constructor(s = Ue, e, t) { super(), this._config = s, this._injector = e, this._configService = t; const { ...n } = Qe( {}, Ue, this._config ); this._configService.setConfig(vt, n); } onStarting() { et(this._injector, [ [I], [ye], [se], [ie], [ee], [re], [te], [ne] ]), tt(this._injector, [ [ee], [se], [ie], [re], [te], [ne] ]); } }; xe(ae, "pluginName", He); xe(ae, "type", v.UNIVER_SHEET); ae = Qt([ Xe(ht), Pe(1, M(qe)), Pe(2, nt) ], ae); export { xt as AddHyperLinkCommand, O as AddHyperLinkMutation, Tt as AddRichHyperLinkCommand, At as CancelHyperLinkCommand, Wt as CancelRichHyperLinkCommand, Q as ERROR_RANGE, I as HyperLinkModel, k as RemoveHyperLinkMutation, U as SheetHyperLinkType, ye as SheetsHyperLinkParserService, ae as UniverSheetsHyperLinkPlugin, Bt as UpdateHyperLinkCommand, _e as UpdateHyperLinkMutation, me as UpdateHyperLinkRefMutation, jt as UpdateRichHyperLinkCommand };