index.js 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280
  1. var Ae = Object.defineProperty;
  2. var We = (s, e, t) => e in s ? Ae(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
  3. var w = (s, e, t) => We(s, typeof e != "symbol" ? e + "" : e, t);
  4. 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";
  5. import { Subject as rt } from "rxjs";
  6. 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";
  7. import { deserializeRangeWithSheet as Ce, serializeRange as B, serializeRangeWithSheet as gt, IDefinedNamesService as ft } from "@univerjs/engine-formula";
  8. import { addCustomRangeBySelectionFactory as _t, deleteCustomRangeFactory as mt, replaceSelectionFactory as De } from "@univerjs/docs";
  9. var yt = Object.defineProperty, Rt = Object.getOwnPropertyDescriptor, St = (s, e, t, n) => {
  10. for (var r = n > 1 ? void 0 : n ? Rt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
  11. (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
  12. return n && r && yt(e, t, r), r;
  13. }, It = (s, e) => (t, n) => e(t, n, s);
  14. let I = class extends V {
  15. constructor(e) {
  16. super();
  17. w(this, "_linkUpdate$", new rt());
  18. w(this, "linkUpdate$", this._linkUpdate$.asObservable());
  19. w(this, "_linkMap", /* @__PURE__ */ new Map());
  20. w(this, "_linkPositionMap", /* @__PURE__ */ new Map());
  21. this._univerInstanceService = e, this.disposeWithMe({
  22. dispose: () => {
  23. this._linkUpdate$.complete();
  24. }
  25. });
  26. }
  27. _ensureMap(e, t) {
  28. let n = this._linkMap.get(e);
  29. n || (n = /* @__PURE__ */ new Map(), this._linkMap.set(e, n));
  30. let r = n.get(t);
  31. r || (r = new q(), n.set(t, r));
  32. let i = this._linkPositionMap.get(e);
  33. i || (i = /* @__PURE__ */ new Map(), this._linkPositionMap.set(e, i));
  34. let a = i.get(t);
  35. return a || (a = /* @__PURE__ */ new Map(), i.set(t, a)), {
  36. matrix: r,
  37. positionMap: a
  38. };
  39. }
  40. addHyperLink(e, t, n) {
  41. const { matrix: r, positionMap: i } = this._ensureMap(e, t);
  42. return r.setValue(n.row, n.column, n), i.set(n.id, { row: n.row, column: n.column, link: n }), this._linkUpdate$.next({
  43. unitId: e,
  44. subUnitId: t,
  45. payload: n,
  46. type: "add"
  47. }), !0;
  48. }
  49. updateHyperLink(e, t, n, r, i = !1) {
  50. const { matrix: a, positionMap: o } = this._ensureMap(e, t), c = o.get(n);
  51. if (!c)
  52. return !0;
  53. const d = a.getValue(c.row, c.column);
  54. return d && (Object.assign(d, r), this._linkUpdate$.next({
  55. unitId: e,
  56. subUnitId: t,
  57. payload: {
  58. display: d.display,
  59. payload: d.payload
  60. },
  61. id: n,
  62. type: "update",
  63. silent: i
  64. })), !0;
  65. }
  66. updateHyperLinkRef(e, t, n, r, i = !1) {
  67. const { matrix: a, positionMap: o } = this._ensureMap(e, t), c = o.get(n);
  68. if (!c)
  69. return !0;
  70. let d = a.getValue(c.row, c.column);
  71. 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({
  72. unitId: e,
  73. subUnitId: t,
  74. payload: r,
  75. id: n,
  76. type: "updateRef",
  77. silent: i
  78. }), !0;
  79. }
  80. removeHyperLink(e, t, n) {
  81. const { matrix: r, positionMap: i } = this._ensureMap(e, t), a = i.get(n);
  82. if (!a)
  83. return !1;
  84. i.delete(n);
  85. const o = r.getValue(a.row, a.column);
  86. return o && o.id === n && r.realDeleteValue(a.row, a.column), this._linkUpdate$.next({
  87. unitId: e,
  88. subUnitId: t,
  89. payload: a.link,
  90. type: "remove"
  91. }), !0;
  92. }
  93. getHyperLink(e, t, n) {
  94. const { matrix: r, positionMap: i } = this._ensureMap(e, t), a = i.get(n);
  95. if (a)
  96. return r.getValue(a.row, a.column);
  97. }
  98. getHyperLinkByLocation(e, t, n, r) {
  99. const { matrix: i } = this._ensureMap(e, t);
  100. return i.getValue(n, r);
  101. }
  102. getHyperLinkByLocationSync(e, t, n, r) {
  103. var l, u, h, g, p;
  104. 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);
  105. if (d)
  106. return {
  107. ...d,
  108. display: c
  109. };
  110. }
  111. getSubUnit(e, t) {
  112. const { matrix: n } = this._ensureMap(e, t), r = [];
  113. return n.forValue((i, a, o) => {
  114. o && r.push(o);
  115. }), r;
  116. }
  117. getUnit(e) {
  118. const t = this._linkMap.get(e);
  119. return t ? Array.from(t.keys()).map((n) => {
  120. const r = this.getSubUnit(e, n);
  121. return {
  122. unitId: e,
  123. subUnitId: n,
  124. links: r
  125. };
  126. }) : [];
  127. }
  128. deleteUnit(e) {
  129. const t = this.getUnit(e);
  130. this._linkMap.delete(e), this._linkPositionMap.delete(e), this._linkUpdate$.next({
  131. type: "unload",
  132. unitId: e,
  133. unitLinks: t
  134. });
  135. }
  136. getAll() {
  137. return Array.from(this._linkMap.keys()).map((t) => this.getUnit(t));
  138. }
  139. };
  140. I = St([
  141. It(0, E)
  142. ], I);
  143. var U = /* @__PURE__ */ ((s) => (s.SHEET = "gid", s.RANGE = "range", s.DEFINE_NAME = "rangeid", s.INVALID = "invalid", s.URL = "url", s))(U || {});
  144. const vt = "sheets-hyper-link.config", Ue = {}, O = {
  145. type: L.MUTATION,
  146. id: "sheets.mutation.add-hyper-link",
  147. handler(s, e) {
  148. if (!e)
  149. return !1;
  150. const t = s.get(I), { unitId: n, subUnitId: r, link: i } = e;
  151. return t.addHyperLink(n, r, i);
  152. }
  153. }, k = {
  154. type: L.MUTATION,
  155. id: "sheets.mutation.remove-hyper-link",
  156. handler(s, e) {
  157. if (!e)
  158. return !1;
  159. const t = s.get(I), { unitId: n, subUnitId: r, id: i } = e;
  160. return t.removeHyperLink(n, r, i);
  161. }
  162. }, _e = {
  163. type: L.MUTATION,
  164. id: "sheets.mutation.update-hyper-link",
  165. handler(s, e) {
  166. if (!e)
  167. return !1;
  168. const t = s.get(I), { unitId: n, subUnitId: r, payload: i, id: a } = e;
  169. return t.updateHyperLink(n, r, a, i, !1);
  170. }
  171. }, me = {
  172. type: L.MUTATION,
  173. id: "sheets.mutation.update-hyper-link-ref",
  174. handler(s, e) {
  175. if (!e)
  176. return !1;
  177. const t = s.get(I), { unitId: n, subUnitId: r, id: i, row: a, column: o, silent: c } = e;
  178. return t.updateHyperLinkRef(n, r, i, { row: a, column: o }, c);
  179. }
  180. }, X = {
  181. type: L.MUTATION,
  182. id: "sheets.mutation.update-rich-hyper-link",
  183. handler(s, e) {
  184. var g, p, f;
  185. if (!e)
  186. return !1;
  187. 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 });
  188. if (!d)
  189. return !1;
  190. 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);
  191. return h && (h.properties.url = o), !0;
  192. }
  193. }, He = "SHEET_HYPER_LINK_PLUGIN", Q = "err";
  194. var Mt = Object.defineProperty, Ct = Object.getOwnPropertyDescriptor, wt = (s, e, t, n) => {
  195. for (var r = n > 1 ? void 0 : n ? Ct(e, t) : e, i = s.length - 1, a; i >= 0; i--)
  196. (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
  197. return n && r && Mt(e, t, r), r;
  198. }, z = (s, e) => (t, n) => e(t, n, s);
  199. let ee = class extends V {
  200. constructor(e, t, n, r) {
  201. super();
  202. w(this, "_disposableMap", /* @__PURE__ */ new Map());
  203. w(this, "_watchDisposableMap", /* @__PURE__ */ new Map());
  204. w(this, "_rangeDisableMap", /* @__PURE__ */ new Map());
  205. w(this, "_rangeWatcherMap", /* @__PURE__ */ new Map());
  206. w(this, "_handlePositionChange", (e, t, n, r, i) => {
  207. const a = {
  208. startColumn: n.column,
  209. endColumn: n.column,
  210. startRow: n.row,
  211. endRow: n.row
  212. };
  213. return r ? {
  214. redos: [{
  215. id: me.id,
  216. params: {
  217. unitId: e,
  218. subUnitId: t,
  219. id: n.id,
  220. row: r.startRow,
  221. column: r.startColumn,
  222. silent: i
  223. }
  224. }],
  225. undos: [{
  226. id: me.id,
  227. params: {
  228. unitId: e,
  229. subUnitId: t,
  230. id: n.id,
  231. row: a.startRow,
  232. column: a.startColumn,
  233. silent: i
  234. }
  235. }]
  236. } : {
  237. redos: [{
  238. id: k.id,
  239. params: {
  240. unitId: e,
  241. subUnitId: t,
  242. id: n.id
  243. }
  244. }],
  245. undos: [{
  246. id: O.id,
  247. params: {
  248. unitId: e,
  249. subUnitId: t,
  250. link: n
  251. }
  252. }]
  253. };
  254. });
  255. this._refRangeService = e, this._hyperLinkModel = t, this._selectionManagerService = n, this._commandService = r, this._initData(), this._initRefRange();
  256. }
  257. _registerPosition(e, t, n) {
  258. const r = n.id, i = {
  259. startColumn: n.column,
  260. endColumn: n.column,
  261. startRow: n.row,
  262. endRow: n.row
  263. }, a = (o) => {
  264. const c = st(i, o, { selectionManagerService: this._selectionManagerService }), d = Array.isArray(c) ? c[0] : c;
  265. return d && d.startColumn === i.startColumn && d.startRow === i.startRow ? {
  266. undos: [],
  267. redos: []
  268. } : this._handlePositionChange(e, t, n, d, !1);
  269. };
  270. this._disposableMap.set(r, this._refRangeService.registerRefRange(i, a, e, t));
  271. }
  272. _watchPosition(e, t, n) {
  273. const r = n.id, i = {
  274. startColumn: n.column,
  275. endColumn: n.column,
  276. startRow: n.row,
  277. endRow: n.row
  278. };
  279. this._watchDisposableMap.set(
  280. r,
  281. this._refRangeService.watchRange(e, t, i, (a, o) => {
  282. const { redos: c } = this._handlePositionChange(e, t, n, o, !0);
  283. Re(c, this._commandService, { onlyLocal: !0 });
  284. }, !0)
  285. );
  286. }
  287. _unregisterPosition(e) {
  288. const t = this._disposableMap.get(e);
  289. t == null || t.dispose(), this._disposableMap.delete(e);
  290. }
  291. _unwatchPosition(e) {
  292. const t = this._watchDisposableMap.get(e);
  293. t == null || t.dispose(), this._watchDisposableMap.delete(e);
  294. }
  295. _registerRange(e, t, n, r = !1) {
  296. var i, a, o;
  297. if (n.startsWith("#")) {
  298. const c = new URLSearchParams(n.slice(1)), d = {
  299. gid: (i = c.get("gid")) != null ? i : "",
  300. range: (a = c.get("range")) != null ? a : "",
  301. rangeid: (o = c.get("rangeid")) != null ? o : ""
  302. };
  303. if (d.range && d.gid) {
  304. const l = d.gid, u = Ce(d.range).range;
  305. if (Se(u) && d.range !== Q) {
  306. const h = (g) => {
  307. const p = it(u, g, { selectionManagerService: this._selectionManagerService });
  308. return p && B(p) === B(u) ? {
  309. redos: [],
  310. undos: []
  311. } : {
  312. redos: [{
  313. id: _e.id,
  314. params: {
  315. unitId: e,
  316. subUnitId: l,
  317. id: t,
  318. payload: {
  319. payload: `#gid=${l}&range=${p ? B(p) : "err"}`
  320. }
  321. }
  322. }],
  323. undos: [{
  324. id: _e.id,
  325. params: {
  326. unitId: e,
  327. subUnitId: l,
  328. id: t,
  329. payload: {
  330. payload: n
  331. }
  332. }
  333. }]
  334. };
  335. };
  336. this._rangeDisableMap.set(t, this._refRangeService.registerRefRange(u, h, e, l)), r || this._rangeWatcherMap.set(t, this._refRangeService.watchRange(e, l, u, (g, p) => {
  337. this._hyperLinkModel.updateHyperLink(e, l, t, {
  338. payload: `#gid=${l}&range=${p ? B(p) : "err"}`
  339. }, !0);
  340. }, !0));
  341. }
  342. }
  343. }
  344. }
  345. _unregisterRange(e) {
  346. const t = this._rangeDisableMap.get(e);
  347. t == null || t.dispose(), this._rangeDisableMap.delete(e);
  348. }
  349. _unwatchRange(e) {
  350. const t = this._rangeWatcherMap.get(e);
  351. t == null || t.dispose(), this._rangeWatcherMap.delete(e);
  352. }
  353. _initData() {
  354. this._hyperLinkModel.getAll().forEach((t) => {
  355. t.forEach((n) => {
  356. const { unitId: r, subUnitId: i, links: a } = n;
  357. a.forEach((o) => {
  358. this._registerPosition(r, i, o), this._watchPosition(r, i, o), this._registerRange(r, o.id, o.payload);
  359. });
  360. });
  361. });
  362. }
  363. _initRefRange() {
  364. this.disposeWithMe(
  365. this._hyperLinkModel.linkUpdate$.subscribe((e) => {
  366. switch (e.type) {
  367. case "add": {
  368. 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);
  369. break;
  370. }
  371. case "remove": {
  372. this._unregisterPosition(e.payload.id), this._unwatchPosition(e.payload.id), this._unregisterRange(e.payload.id), this._unwatchRange(e.payload.id);
  373. break;
  374. }
  375. case "updateRef": {
  376. const { unitId: t, subUnitId: n, id: r, silent: i } = e, a = this._hyperLinkModel.getHyperLink(t, n, r);
  377. if (!a)
  378. return;
  379. this._unregisterPosition(r), this._registerPosition(t, n, a), i || (this._unwatchPosition(r), this._watchPosition(t, n, a));
  380. break;
  381. }
  382. case "unload": {
  383. const { unitLinks: t } = e;
  384. t.forEach((n) => {
  385. const { links: r } = n;
  386. r.forEach((i) => {
  387. this._unregisterPosition(i.id), this._unwatchPosition(i.id), this._unregisterRange(i.id), this._unwatchRange(i.id);
  388. });
  389. });
  390. break;
  391. }
  392. case "update": {
  393. e.silent || this._unwatchRange(e.id), this._unregisterRange(e.id), this._registerRange(e.unitId, e.id, e.payload.payload, e.silent);
  394. break;
  395. }
  396. }
  397. })
  398. ), this.disposeWithMe(Be(() => {
  399. this._disposableMap.forEach((e) => {
  400. e.dispose();
  401. }), this._disposableMap.clear();
  402. }));
  403. }
  404. };
  405. ee = wt([
  406. z(0, M(Oe)),
  407. z(1, M(I)),
  408. z(2, M(ke)),
  409. z(3, P)
  410. ], ee);
  411. var Et = Object.defineProperty, Lt = Object.getOwnPropertyDescriptor, Ut = (s, e, t, n) => {
  412. for (var r = n > 1 ? void 0 : n ? Lt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
  413. (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
  414. return n && r && Et(e, t, r), r;
  415. }, he = (s, e) => (t, n) => e(t, n, s);
  416. let te = class extends V {
  417. constructor(s, e, t) {
  418. super(), this._sheetInterceptorService = s, this._univerInstanceService = e, this._hyperLinkModel = t, this._initSheetChange();
  419. }
  420. _initSheetChange() {
  421. this.disposeWithMe(
  422. this._sheetInterceptorService.interceptCommand({
  423. getMutations: (s) => {
  424. var e;
  425. if (s.id === at.id) {
  426. const t = s.params, n = t.unitId ? this._univerInstanceService.getUnit(t.unitId) : this._univerInstanceService.getCurrentUnitForType(v.UNIVER_SHEET);
  427. if (!n)
  428. return { redos: [], undos: [] };
  429. const r = n.getUnitId(), i = t.subUnitId || ((e = n.getActiveSheet()) == null ? void 0 : e.getSheetId());
  430. if (!i)
  431. return { redos: [], undos: [] };
  432. const a = this._hyperLinkModel.getSubUnit(r, i), o = a.map((d) => ({
  433. id: k.id,
  434. params: {
  435. unitId: r,
  436. subUnitId: i,
  437. id: d.id
  438. }
  439. })), c = a.map((d) => ({
  440. id: O.id,
  441. params: {
  442. unitId: r,
  443. subUnitId: i,
  444. link: d
  445. }
  446. }));
  447. return { redos: o, undos: c };
  448. }
  449. return { redos: [], undos: [] };
  450. }
  451. })
  452. );
  453. }
  454. };
  455. te = Ut([
  456. he(0, M(le)),
  457. he(1, E),
  458. he(2, M(I))
  459. ], te);
  460. var bt = Object.defineProperty, Pt = Object.getOwnPropertyDescriptor, Nt = (s, e, t, n) => {
  461. for (var r = n > 1 ? void 0 : n ? Pt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
  462. (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
  463. return n && r && bt(e, t, r), r;
  464. }, ge = (s, e) => (t, n) => e(t, n, s);
  465. let ne = class extends V {
  466. constructor(e, t, n) {
  467. super();
  468. w(this, "_refRangeMap", /* @__PURE__ */ new Map());
  469. this._commandService = e, this._univerInstanceService = t, this._refRangeService = n, this._initWorkbookLoad(), this._initWorkbookUnload(), this._initSetRangesListener();
  470. }
  471. _enusreMap(e, t) {
  472. let n = this._refRangeMap.get(e);
  473. n || (n = /* @__PURE__ */ new Map(), this._refRangeMap.set(e, n));
  474. let r = n.get(t);
  475. return r || (r = new q(), n.set(t, r)), r;
  476. }
  477. _isLegalRangeUrl(e, t) {
  478. var r, i, a;
  479. const n = this._univerInstanceService.getUnit(e, v.UNIVER_SHEET);
  480. if (!n)
  481. return null;
  482. if (t && t.startsWith("#")) {
  483. const o = new URLSearchParams(t.slice(1)), c = {
  484. gid: (r = o.get("gid")) != null ? r : "",
  485. range: (i = o.get("range")) != null ? i : "",
  486. rangeid: (a = o.get("rangeid")) != null ? a : ""
  487. };
  488. if (c.range && c.gid) {
  489. const d = c.gid, l = n.getSheetBySheetId(d);
  490. if (!l)
  491. return null;
  492. const u = Ce(c.range).range;
  493. if (Se(u, l) && c.range !== Q)
  494. return {
  495. range: u,
  496. worksheet: l
  497. };
  498. }
  499. }
  500. return null;
  501. }
  502. _registerRange(e, t, n, r, i) {
  503. var o, c, d, l;
  504. const a = this._enusreMap(e, t);
  505. if ((c = (o = i.body) == null ? void 0 : o.customRanges) != null && c.some((u) => {
  506. var h;
  507. return u.rangeType === b.HYPERLINK && this._isLegalRangeUrl(e, (h = u.properties) == null ? void 0 : h.url);
  508. })) {
  509. const u = new je();
  510. let h = !1;
  511. (l = (d = i.body) == null ? void 0 : d.customRanges) == null || l.forEach((g) => {
  512. var p;
  513. if (g.rangeType === b.HYPERLINK) {
  514. const f = (p = g.properties) == null ? void 0 : p.url, _ = this._isLegalRangeUrl(e, f);
  515. if (_) {
  516. const { range: m, worksheet: C } = _;
  517. h = !0, u.add(
  518. this._refRangeService.registerRefRange(
  519. m,
  520. (y) => {
  521. const R = ot(m, y);
  522. return R && Fe.equals(R, m) ? {
  523. preRedos: [],
  524. preUndos: [],
  525. redos: [],
  526. undos: []
  527. } : {
  528. preRedos: [{
  529. id: X.id,
  530. params: {
  531. unitId: e,
  532. subUnitId: t,
  533. row: n,
  534. col: r,
  535. id: g.rangeId,
  536. url: `#gid=${t}&range=${R ? B(R) : Q}`
  537. }
  538. }],
  539. undos: [{
  540. id: X.id,
  541. params: {
  542. unitId: e,
  543. subUnitId: t,
  544. row: n,
  545. col: r,
  546. id: g.rangeId,
  547. url: f
  548. }
  549. }],
  550. redos: []
  551. };
  552. },
  553. C.getUnitId(),
  554. C.getSheetId()
  555. )
  556. );
  557. }
  558. }
  559. }), h && a.setValue(n, r, u);
  560. }
  561. }
  562. _initWorkbookLoad() {
  563. const e = (t) => {
  564. const n = t.getUnitId();
  565. t.getSheets().forEach((r) => {
  566. const i = r.getSheetId(), a = this._enusreMap(n, i);
  567. r.getCellMatrix().forValue((o, c, d) => {
  568. const l = a.getValue(o, c);
  569. l && l.dispose(), d && d.p && this._registerRange(n, i, o, c, d.p);
  570. });
  571. });
  572. };
  573. this._univerInstanceService.getAllUnitsForType(v.UNIVER_SHEET).forEach((t) => {
  574. e(t);
  575. }), this.disposeWithMe(
  576. this._univerInstanceService.unitAdded$.subscribe((t) => {
  577. t.type === v.UNIVER_SHEET && e(t);
  578. })
  579. );
  580. }
  581. _initWorkbookUnload() {
  582. this._univerInstanceService.unitDisposed$.subscribe((e) => {
  583. if (e.type === v.UNIVER_SHEET) {
  584. const t = e, n = t.getUnitId();
  585. t.getSheets().forEach((r) => {
  586. const i = r.getSheetId();
  587. this._enusreMap(n, i).forValue((o, c, d) => {
  588. d && d.dispose();
  589. });
  590. }), this._refRangeMap.delete(n);
  591. }
  592. });
  593. }
  594. _initSetRangesListener() {
  595. this.disposeWithMe(
  596. this._commandService.onCommandExecuted((e) => {
  597. if (e.id === H.id) {
  598. const t = e.params, { unitId: n, subUnitId: r, cellValue: i } = t, a = this._enusreMap(n, r);
  599. i && new q(i).forValue((o, c, d) => {
  600. const l = a.getValue(o, c);
  601. l && l.dispose(), d && d.p && this._registerRange(n, r, o, c, d.p);
  602. });
  603. }
  604. })
  605. ), this.disposeWithMe(
  606. this._commandService.onCommandExecuted((e) => {
  607. if (e.id === X.id) {
  608. 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);
  609. if (d && d.dispose(), o) {
  610. const { worksheet: l } = o, u = l.getCellRaw(i, a);
  611. u && u.p && this._registerRange(n, r, i, a, u.p);
  612. }
  613. }
  614. })
  615. );
  616. }
  617. };
  618. ne = Nt([
  619. ge(0, P),
  620. ge(1, E),
  621. ge(2, M(Oe))
  622. ], ne);
  623. var Ot = Object.defineProperty, kt = Object.getOwnPropertyDescriptor, Dt = (s, e, t, n) => {
  624. for (var r = n > 1 ? void 0 : n ? kt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
  625. (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
  626. return n && r && Ot(e, t, r), r;
  627. }, J = (s, e) => (t, n) => e(t, n, s);
  628. let re = class extends V {
  629. constructor(s, e, t, n) {
  630. super(), this._sheetInterceptorService = s, this._hyperLinkModel = e, this._selectionManagerService = t, this._univerInstanceService = n, this._initCommandInterceptor(), this._initAfterEditor();
  631. }
  632. _initCommandInterceptor() {
  633. this._initSetRangeValuesCommandInterceptor(), this._initClearSelectionCommandInterceptor();
  634. }
  635. _initSetRangeValuesCommandInterceptor() {
  636. this.disposeWithMe(this._sheetInterceptorService.interceptCommand({
  637. getMutations: (s) => {
  638. if (s.id === dt.id) {
  639. const e = s.params, { unitId: t, subUnitId: n } = e, r = [], i = [];
  640. return e.cellValue && new q(e.cellValue).forValue((a, o) => {
  641. const c = this._hyperLinkModel.getHyperLinkByLocation(t, n, a, o);
  642. c && (r.push({
  643. id: k.id,
  644. params: {
  645. unitId: t,
  646. subUnitId: n,
  647. id: c.id
  648. }
  649. }), i.push({
  650. id: O.id,
  651. params: {
  652. unitId: t,
  653. subUnitId: n,
  654. link: c
  655. }
  656. }));
  657. }), {
  658. undos: i,
  659. redos: r
  660. };
  661. }
  662. return {
  663. redos: [],
  664. undos: []
  665. };
  666. }
  667. }));
  668. }
  669. _initClearSelectionCommandInterceptor() {
  670. this.disposeWithMe(this._sheetInterceptorService.interceptCommand({
  671. getMutations: (s) => {
  672. if (s.id === ct.id || s.id === lt.id || s.id === ut.id) {
  673. const e = [], t = [], n = this._selectionManagerService.getCurrentLastSelection(), r = j(this._univerInstanceService);
  674. if (n && r) {
  675. const { unitId: i, subUnitId: a } = r;
  676. Ke.foreach(n.range, (o, c) => {
  677. const d = this._hyperLinkModel.getHyperLinkByLocation(i, a, o, c);
  678. d && (e.push({
  679. id: k.id,
  680. params: {
  681. unitId: i,
  682. subUnitId: a,
  683. id: d.id
  684. }
  685. }), t.push({
  686. id: O.id,
  687. params: {
  688. unitId: i,
  689. subUnitId: a,
  690. link: d
  691. }
  692. }));
  693. });
  694. }
  695. return {
  696. redos: e,
  697. undos: t
  698. };
  699. }
  700. return {
  701. redos: [],
  702. undos: []
  703. };
  704. }
  705. }));
  706. }
  707. _initAfterEditor() {
  708. this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(pt, {
  709. handler: (s, e, t) => {
  710. if (!s || s.p)
  711. return t(s);
  712. if (typeof s.v == "string" && oe.isLegalUrl(s.v) && s.v[s.v.length - 1] !== " ") {
  713. const { unitId: n, subUnitId: r } = e, i = this._univerInstanceService.getUnit(n, v.UNIVER_SHEET), a = i == null ? void 0 : i.getSheetBySheetId(r);
  714. if (!a)
  715. return t(s);
  716. const o = a.getBlankCellDocumentModel(s);
  717. if (!o.documentModel)
  718. return t(s);
  719. const c = Z.selection.replace({
  720. selection: {
  721. startOffset: 0,
  722. endOffset: s.v.length,
  723. collapsed: !1
  724. },
  725. body: {
  726. dataStream: `${s.v}`,
  727. customRanges: [{
  728. startIndex: 0,
  729. endIndex: s.v.length - 1,
  730. rangeId: de(),
  731. rangeType: b.HYPERLINK,
  732. properties: {
  733. url: s.v
  734. }
  735. }]
  736. },
  737. doc: o.documentModel
  738. });
  739. if (!c)
  740. return t(s);
  741. const d = o.documentModel.getBody();
  742. return ce.apply(d, c.serialize()), t({
  743. ...s,
  744. p: {
  745. id: Ye,
  746. body: d,
  747. documentStyle: {
  748. pageSize: {
  749. width: 1 / 0,
  750. height: 1 / 0
  751. }
  752. }
  753. }
  754. });
  755. }
  756. return t(s);
  757. }
  758. }));
  759. }
  760. };
  761. re = Dt([
  762. J(0, M(le)),
  763. J(1, M(I)),
  764. J(2, M(ke)),
  765. J(3, E)
  766. ], re);
  767. 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) => {
  768. for (var r = n > 1 ? void 0 : n ? Vt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
  769. (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
  770. return n && r && Ht(e, t, r), r;
  771. }, be = (s, e) => (t, n) => e(t, n, s);
  772. let se = class extends V {
  773. constructor(s, e) {
  774. super(), this._resourceManagerService = s, this._hyperLinkModel = e, this._initSnapshot();
  775. }
  776. _initSnapshot() {
  777. const s = (t) => {
  778. const n = this._hyperLinkModel.getUnit(t), r = {};
  779. return n ? (n.forEach((i) => {
  780. r[i.subUnitId] = i.links.map(({ display: a, ...o }) => o);
  781. }), JSON.stringify(r)) : "";
  782. }, e = (t) => {
  783. if (!t)
  784. return {};
  785. try {
  786. return JSON.parse(t);
  787. } catch {
  788. return {};
  789. }
  790. };
  791. this.disposeWithMe(
  792. this._resourceManagerService.registerPluginResource({
  793. pluginName: He,
  794. businesses: [Ve.UNIVER_SHEET],
  795. toJson: (t) => s(t),
  796. parseJson: (t) => e(t),
  797. onUnLoad: (t) => {
  798. this._hyperLinkModel.deleteUnit(t);
  799. },
  800. onLoad: async (t, n) => {
  801. Object.keys(n).forEach((r) => {
  802. n[r].forEach((a) => {
  803. this._hyperLinkModel.addHyperLink(t, r, a);
  804. });
  805. });
  806. }
  807. })
  808. );
  809. }
  810. };
  811. se = $t([
  812. be(0, Ge),
  813. be(1, M(I))
  814. ], se);
  815. const xt = {
  816. type: L.COMMAND,
  817. id: "sheets.command.add-hyper-link",
  818. // eslint-disable-next-line max-lines-per-function
  819. async handler(s, e) {
  820. if (!e) return !1;
  821. 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);
  822. if (!o) return !1;
  823. 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);
  824. if (!S) return !1;
  825. let N;
  826. if (p ? N = Z.selection.replace({
  827. selection: {
  828. startOffset: 0,
  829. endOffset: S.dataStream.length - 2,
  830. collapsed: S.dataStream.length - 2 === 0
  831. },
  832. body: {
  833. dataStream: `${p}`,
  834. customRanges: [{
  835. startIndex: 0,
  836. endIndex: p.length - 1,
  837. rangeType: b.HYPERLINK,
  838. rangeId: m,
  839. properties: {
  840. url: g
  841. // refId: id,
  842. }
  843. }]
  844. },
  845. doc: y.documentModel
  846. }) : N = Z.customRange.add({
  847. body: S,
  848. ranges: [{ startOffset: 0, endOffset: S.dataStream.length - 2, collapsed: !1 }],
  849. rangeId: m,
  850. rangeType: b.HYPERLINK,
  851. properties: {
  852. url: g,
  853. refId: m
  854. }
  855. }), !N) return !1;
  856. const F = ce.apply(S, N.serialize()), D = {
  857. p: {
  858. ...R,
  859. body: F
  860. },
  861. t: ve.STRING
  862. }, x = await a.onWriteCell(l, u, f, _, D), T = {
  863. unitId: c,
  864. subUnitId: d,
  865. cellValue: {
  866. [h.row]: {
  867. [h.column]: x
  868. }
  869. }
  870. }, ue = {
  871. id: H.id,
  872. params: T
  873. }, Y = Me(s, T), pe = {
  874. id: H.id,
  875. params: Y
  876. }, K = [ue], A = [pe], W = i.getHyperLinkByLocation(c, d, f, _);
  877. return W && (K.push({
  878. id: k.id,
  879. params: {
  880. unitId: c,
  881. subUnitId: d,
  882. id: W.id
  883. }
  884. }), A.push({
  885. id: O.id,
  886. params: {
  887. unitId: c,
  888. subUnitId: d,
  889. link: W
  890. }
  891. })), await Re(K, t) ? (n.pushUndoRedo({
  892. redoMutations: K,
  893. undoMutations: A,
  894. unitID: c
  895. }), !0) : !1;
  896. }
  897. }, Tt = {
  898. id: "sheets.command.add-rich-hyper-link",
  899. type: L.COMMAND,
  900. handler: async (s, e) => {
  901. if (!e)
  902. return !1;
  903. const { documentId: t, link: n } = e, r = s.get(P), i = de(), { payload: a } = n, o = _t(s, {
  904. unitId: t,
  905. rangeId: i,
  906. rangeType: b.HYPERLINK,
  907. properties: {
  908. url: a,
  909. refId: i
  910. }
  911. });
  912. return o ? r.syncExecuteCommand(o.id, o.params) : !1;
  913. }
  914. }, At = {
  915. type: L.COMMAND,
  916. id: "sheets.command.cancel-hyper-link",
  917. // eslint-disable-next-line max-lines-per-function
  918. handler(s, e) {
  919. var D, x;
  920. if (!e) return !1;
  921. const t = s.get(P), n = s.get(Ie), r = s.get(E), i = s.get(I), a = j(r, e);
  922. if (!a) return !1;
  923. const { row: o, column: c, id: d } = e, { unitId: l, subUnitId: u, worksheet: h } = a, g = h.getCell(o, c);
  924. if (!g) return !1;
  925. const p = h.getCellDocumentModelWithFormula(g);
  926. if (!(p != null && p.documentModel)) return !1;
  927. 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);
  928. if (!_) return !1;
  929. const m = Z.customRange.delete({ documentDataModel: p.documentModel, rangeId: _.rangeId });
  930. if (!m) return !1;
  931. const C = ce.apply(f.body, m.serialize()), y = [], R = [], S = {
  932. unitId: l,
  933. subUnitId: u,
  934. cellValue: {
  935. [o]: {
  936. [c]: {
  937. p: {
  938. ...f,
  939. body: C
  940. },
  941. t: ve.STRING
  942. }
  943. }
  944. }
  945. };
  946. y.push({
  947. id: H.id,
  948. params: S
  949. });
  950. const N = Me(s, S);
  951. R.push({
  952. id: H.id,
  953. params: N
  954. });
  955. const F = i.getHyperLinkByLocation(l, u, o, c);
  956. return F && (y.push({
  957. id: k.id,
  958. params: {
  959. unitId: l,
  960. subUnitId: u,
  961. id: d
  962. }
  963. }), R.push({
  964. id: O.id,
  965. params: {
  966. unitId: l,
  967. subUnitId: u,
  968. link: {
  969. ...F
  970. }
  971. }
  972. })), ze(y, t).result ? (n.pushUndoRedo({
  973. redoMutations: y,
  974. undoMutations: R,
  975. unitID: l
  976. }), !0) : !1;
  977. }
  978. }, Wt = {
  979. type: L.COMMAND,
  980. id: "sheets.command.cancel-rich-hyper-link",
  981. handler(s, e) {
  982. var l, u;
  983. if (!e)
  984. return !1;
  985. 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);
  986. let c = null;
  987. o && o.endIndex === a.getBody().dataStream.length - 3 && (c = {
  988. dataStream: " "
  989. });
  990. const d = mt(s, { unitId: n, rangeId: t, insert: c });
  991. return d ? r.syncExecuteCommand(d.id, d.params) : !1;
  992. }
  993. }, Bt = {
  994. type: L.COMMAND,
  995. id: "sheets.command.update-hyper-link",
  996. // eslint-disable-next-line max-lines-per-function
  997. async handler(s, e) {
  998. var we, Ee, Le;
  999. if (!e) return !1;
  1000. const t = s.get(P), n = s.get(Ie), r = s.get(E), i = s.get(I), a = s.get(le), o = j(r, {
  1001. unitId: e.unitId,
  1002. subUnitId: e.subUnitId
  1003. });
  1004. if (!o) return !1;
  1005. 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);
  1006. if (!C) return !1;
  1007. const y = g.getCellDocumentModelWithFormula(C);
  1008. if (!(y != null && y.documentModel)) return !1;
  1009. const R = y.documentModel.getSnapshot(), S = (Ee = (we = R.body) == null ? void 0 : we.customRanges) == null ? void 0 : Ee.find((Te) => `${Te.rangeId}` === u);
  1010. if (!S) return !1;
  1011. const N = de(), $ = (Le = Ne(y.documentModel.getBody(), S.startIndex, S.endIndex + 1).textRuns) == null ? void 0 : Le[0];
  1012. $ && ($.ed = m.length + 1);
  1013. const D = De(s, {
  1014. unitId: p,
  1015. body: {
  1016. dataStream: `${m}`,
  1017. customRanges: [{
  1018. rangeId: N,
  1019. rangeType: b.HYPERLINK,
  1020. startIndex: 0,
  1021. endIndex: m.length - 1,
  1022. properties: {
  1023. url: _
  1024. }
  1025. }],
  1026. textRuns: $ ? [$] : void 0
  1027. },
  1028. selection: {
  1029. startOffset: S.startIndex,
  1030. endOffset: S.endIndex + 1,
  1031. collapsed: !1
  1032. },
  1033. doc: y.documentModel
  1034. });
  1035. if (!D)
  1036. return !1;
  1037. const x = ce.apply(oe.deepClone(R.body), D.textX.serialize()), T = {
  1038. p: {
  1039. ...R,
  1040. body: x
  1041. },
  1042. t: ve.STRING
  1043. }, ue = await a.onWriteCell(h, g, d, l, T), Y = {
  1044. id: H.id,
  1045. params: {
  1046. unitId: p,
  1047. subUnitId: f,
  1048. cellValue: {
  1049. [d]: {
  1050. [l]: ue
  1051. }
  1052. }
  1053. }
  1054. }, pe = Me(s, Y.params), K = {
  1055. id: H.id,
  1056. params: pe
  1057. }, A = [Y], W = [K], G = i.getHyperLinkByLocation(p, f, d, l);
  1058. return G && (A.push({
  1059. id: k.id,
  1060. params: {
  1061. unitId: p,
  1062. subUnitId: f,
  1063. id: G.id
  1064. }
  1065. }), W.push({
  1066. id: O.id,
  1067. params: {
  1068. unitId: p,
  1069. subUnitId: f,
  1070. link: G
  1071. }
  1072. })), await Re(A, t) ? (n.pushUndoRedo({
  1073. redoMutations: A,
  1074. undoMutations: W,
  1075. unitID: p
  1076. }), !0) : !1;
  1077. }
  1078. }, jt = {
  1079. type: L.COMMAND,
  1080. id: "sheets.command.update-rich-hyper-link",
  1081. handler: (s, e) => {
  1082. var p, f, _, m;
  1083. if (!e)
  1084. return !1;
  1085. const { documentId: t, payload: n, id: r } = e, i = s.get(E), a = s.get(P), o = i.getUnit(t, v.UNIVER_DOC);
  1086. if (!o)
  1087. return !1;
  1088. const c = (f = (p = o.getBody()) == null ? void 0 : p.customRanges) == null ? void 0 : f.find((C) => C.rangeId === r);
  1089. if (!c)
  1090. return !1;
  1091. const d = (_ = e.payload.display) != null ? _ : "", l = de(), h = (m = Ne(o.getBody(), c.startIndex, c.endIndex + 1).textRuns) == null ? void 0 : m[0];
  1092. h && (h.ed = d.length + 1);
  1093. const g = De(s, {
  1094. unitId: t,
  1095. body: {
  1096. dataStream: `${d}`,
  1097. customRanges: [{
  1098. rangeId: l,
  1099. rangeType: b.HYPERLINK,
  1100. startIndex: 0,
  1101. endIndex: d.length - 1,
  1102. properties: {
  1103. url: n.payload
  1104. }
  1105. }],
  1106. textRuns: h ? [h] : void 0
  1107. },
  1108. selection: {
  1109. startOffset: c.startIndex,
  1110. endOffset: c.endIndex + 1,
  1111. collapsed: !1
  1112. },
  1113. doc: o
  1114. });
  1115. return g ? a.syncExecuteCommand(g.id, g.params) : !1;
  1116. }
  1117. };
  1118. var Ft = Object.defineProperty, Kt = Object.getOwnPropertyDescriptor, Yt = (s, e, t, n) => {
  1119. for (var r = n > 1 ? void 0 : n ? Kt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
  1120. (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
  1121. return n && r && Ft(e, t, r), r;
  1122. }, Gt = (s, e) => (t, n) => e(t, n, s);
  1123. let ie = class extends V {
  1124. constructor(s) {
  1125. super(), this._commandService = s, this._registerCommands();
  1126. }
  1127. _registerCommands() {
  1128. [
  1129. xt,
  1130. Bt,
  1131. At,
  1132. jt,
  1133. Wt,
  1134. Tt,
  1135. O,
  1136. _e,
  1137. k,
  1138. me,
  1139. X
  1140. ].forEach((s) => {
  1141. this._commandService.registerCommand(s);
  1142. });
  1143. }
  1144. };
  1145. ie = Yt([
  1146. Gt(0, P)
  1147. ], ie);
  1148. var zt = Object.defineProperty, Jt = Object.getOwnPropertyDescriptor, Xt = (s, e, t, n) => {
  1149. for (var r = n > 1 ? void 0 : n ? Jt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
  1150. (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
  1151. return n && r && zt(e, t, r), r;
  1152. }, fe = (s, e) => (t, n) => e(t, n, s);
  1153. let ye = class {
  1154. constructor(s, e, t) {
  1155. this._univerInstanceService = s, this._localeService = e, this._definedNamesService = t;
  1156. }
  1157. buildHyperLink(s, e, t) {
  1158. return `#${U.SHEET}=${e}${t ? `&${typeof t == "string" ? U.DEFINE_NAME : U.RANGE}=${typeof t == "string" ? t : B(t)}` : ""}`;
  1159. }
  1160. parseHyperLink(s) {
  1161. var e, t, n, r;
  1162. if (s.startsWith("#")) {
  1163. const i = new URLSearchParams(s.slice(1)), a = {
  1164. gid: (e = i.get("gid")) != null ? e : "",
  1165. range: (t = i.get("range")) != null ? t : "",
  1166. rangeid: (n = i.get("rangeid")) != null ? n : "",
  1167. unitid: (r = i.get("unitid")) != null ? r : ""
  1168. }, o = this._getURLName(a);
  1169. return {
  1170. type: o.type,
  1171. name: o.name,
  1172. url: s,
  1173. searchObj: a
  1174. };
  1175. } else
  1176. return {
  1177. type: U.URL,
  1178. name: s,
  1179. url: s,
  1180. searchObj: null
  1181. };
  1182. }
  1183. _getURLName(s) {
  1184. var d;
  1185. 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 = {
  1186. type: U.INVALID,
  1187. name: this._localeService.t("hyperLink.message.refError")
  1188. };
  1189. if (!i)
  1190. return a;
  1191. const o = e ? i.getSheetBySheetId(e) : i.getActiveSheet(), c = (d = o == null ? void 0 : o.getName()) != null ? d : "";
  1192. if (t) {
  1193. if (!o) return a;
  1194. const l = Ce(t).range;
  1195. return Se(l, o) && t !== Q ? {
  1196. type: U.RANGE,
  1197. name: gt(c, l)
  1198. } : a;
  1199. }
  1200. if (n) {
  1201. const l = this._definedNamesService.getValueById(i.getUnitId(), n);
  1202. return l ? {
  1203. type: U.DEFINE_NAME,
  1204. name: l.formulaOrRefString
  1205. } : a;
  1206. }
  1207. if (e) {
  1208. const l = i.getSheetBySheetId(e);
  1209. return l ? {
  1210. type: U.SHEET,
  1211. name: l.getName()
  1212. } : a;
  1213. }
  1214. return a;
  1215. }
  1216. };
  1217. ye = Xt([
  1218. fe(0, E),
  1219. fe(1, M(Je)),
  1220. fe(2, ft)
  1221. ], ye);
  1222. 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) => {
  1223. for (var r = n > 1 ? void 0 : n ? qt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
  1224. (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
  1225. return n && r && $e(e, t, r), r;
  1226. }, Pe = (s, e) => (t, n) => e(t, n, s), xe = (s, e, t) => Zt(s, typeof e != "symbol" ? e + "" : e, t);
  1227. let ae = class extends Ze {
  1228. constructor(s = Ue, e, t) {
  1229. super(), this._config = s, this._injector = e, this._configService = t;
  1230. const { ...n } = Qe(
  1231. {},
  1232. Ue,
  1233. this._config
  1234. );
  1235. this._configService.setConfig(vt, n);
  1236. }
  1237. onStarting() {
  1238. et(this._injector, [
  1239. [I],
  1240. [ye],
  1241. [se],
  1242. [ie],
  1243. [ee],
  1244. [re],
  1245. [te],
  1246. [ne]
  1247. ]), tt(this._injector, [
  1248. [ee],
  1249. [se],
  1250. [ie],
  1251. [re],
  1252. [te],
  1253. [ne]
  1254. ]);
  1255. }
  1256. };
  1257. xe(ae, "pluginName", He);
  1258. xe(ae, "type", v.UNIVER_SHEET);
  1259. ae = Qt([
  1260. Xe(ht),
  1261. Pe(1, M(qe)),
  1262. Pe(2, nt)
  1263. ], ae);
  1264. export {
  1265. xt as AddHyperLinkCommand,
  1266. O as AddHyperLinkMutation,
  1267. Tt as AddRichHyperLinkCommand,
  1268. At as CancelHyperLinkCommand,
  1269. Wt as CancelRichHyperLinkCommand,
  1270. Q as ERROR_RANGE,
  1271. I as HyperLinkModel,
  1272. k as RemoveHyperLinkMutation,
  1273. U as SheetHyperLinkType,
  1274. ye as SheetsHyperLinkParserService,
  1275. ae as UniverSheetsHyperLinkPlugin,
  1276. Bt as UpdateHyperLinkCommand,
  1277. _e as UpdateHyperLinkMutation,
  1278. me as UpdateHyperLinkRefMutation,
  1279. jt as UpdateRichHyperLinkCommand
  1280. };