@univerjs/sheets-hyper-link 0.16.1 → 0.17.0-insiders.20260318-d69dc16

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