@univerjs/sheets-hyper-link 0.10.12 → 0.10.13-nightly.202510290902
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.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +88 -88
- package/lib/index.js +88 -88
- package/lib/umd/index.js +1 -1
- package/package.json +7 -7
- package/LICENSE +0 -176
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var $e = Object.defineProperty;
|
|
2
2
|
var Ae = (s, e, t) => e in s ? $e(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
3
|
var w = (s, e, t) => Ae(s, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
-
import { Disposable as T, ObjectMatrix as
|
|
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
5
|
import { addCustomRangeBySelectionFactory as nt, deleteCustomRangeFactory as rt, replaceSelectionFactory as Ne } from "@univerjs/docs";
|
|
6
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
7
|
import { Subject as gt } from "rxjs";
|
|
@@ -28,7 +28,7 @@ let R = class extends T {
|
|
|
28
28
|
let n = this._linkMap.get(e);
|
|
29
29
|
n || (n = /* @__PURE__ */ new Map(), this._linkMap.set(e, n));
|
|
30
30
|
let r = n.get(t);
|
|
31
|
-
r || (r = new
|
|
31
|
+
r || (r = new Z(), n.set(t, r));
|
|
32
32
|
let i = this._linkPositionMap.get(e);
|
|
33
33
|
i || (i = /* @__PURE__ */ new Map(), this._linkPositionMap.set(e, i));
|
|
34
34
|
let a = i.get(t);
|
|
@@ -166,10 +166,10 @@ const D = {
|
|
|
166
166
|
if (!e) return !1;
|
|
167
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
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 =
|
|
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
170
|
if (!S) return !1;
|
|
171
171
|
let P;
|
|
172
|
-
if (p ? P =
|
|
172
|
+
if (p ? P = ee.selection.replace({
|
|
173
173
|
selection: {
|
|
174
174
|
startOffset: 0,
|
|
175
175
|
endOffset: S.dataStream.length - 2,
|
|
@@ -189,7 +189,7 @@ const D = {
|
|
|
189
189
|
}]
|
|
190
190
|
},
|
|
191
191
|
doc: y.documentModel
|
|
192
|
-
}) : P =
|
|
192
|
+
}) : P = ee.customRange.add({
|
|
193
193
|
body: S,
|
|
194
194
|
ranges: [{ startOffset: 0, endOffset: S.dataStream.length - 2, collapsed: !1 }],
|
|
195
195
|
rangeId: _,
|
|
@@ -216,9 +216,9 @@ const D = {
|
|
|
216
216
|
}, pe = {
|
|
217
217
|
id: V.id,
|
|
218
218
|
params: W
|
|
219
|
-
},
|
|
219
|
+
}, z = Me(s, W), he = {
|
|
220
220
|
id: V.id,
|
|
221
|
-
params:
|
|
221
|
+
params: z
|
|
222
222
|
}, K = [pe], H = [he], x = i.getHyperLinkByLocation(c, d, f, m);
|
|
223
223
|
return x && (K.push({
|
|
224
224
|
id: N.id,
|
|
@@ -234,7 +234,7 @@ const D = {
|
|
|
234
234
|
subUnitId: d,
|
|
235
235
|
link: x
|
|
236
236
|
}
|
|
237
|
-
})), await
|
|
237
|
+
})), await G(K, t) ? await a.onValidateCell(l, u, f, m) === !1 ? (G(H, t), !1) : (n.pushUndoRedo({
|
|
238
238
|
redoMutations: K,
|
|
239
239
|
undoMutations: H,
|
|
240
240
|
unitID: c
|
|
@@ -270,9 +270,9 @@ const D = {
|
|
|
270
270
|
if (!g) return !1;
|
|
271
271
|
const p = h.getCellDocumentModelWithFormula(g, o, c);
|
|
272
272
|
if (!(p != null && p.documentModel)) return !1;
|
|
273
|
-
const f =
|
|
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
274
|
if (!m) return !1;
|
|
275
|
-
const _ =
|
|
275
|
+
const _ = ee.customRange.delete({ documentDataModel: p.documentModel, rangeId: m.rangeId });
|
|
276
276
|
if (!_) return !1;
|
|
277
277
|
const C = ce.apply(f.body, _.serialize()), y = [], v = [], S = {
|
|
278
278
|
unitId: l,
|
|
@@ -315,7 +315,7 @@ const D = {
|
|
|
315
315
|
...F
|
|
316
316
|
}
|
|
317
317
|
}
|
|
318
|
-
})),
|
|
318
|
+
})), G(y, t).result ? (n.pushUndoRedo({
|
|
319
319
|
redoMutations: y,
|
|
320
320
|
undoMutations: v,
|
|
321
321
|
unitID: l
|
|
@@ -380,13 +380,13 @@ const D = {
|
|
|
380
380
|
});
|
|
381
381
|
if (!O)
|
|
382
382
|
return !1;
|
|
383
|
-
const A = ce.apply(
|
|
383
|
+
const A = ce.apply(Y.deepClone(v.body), O.textX.serialize()), W = {
|
|
384
384
|
p: {
|
|
385
385
|
...v,
|
|
386
386
|
body: A
|
|
387
387
|
},
|
|
388
388
|
t: Re.STRING
|
|
389
|
-
}, pe = a.onWriteCell(h, g, d, l, W),
|
|
389
|
+
}, pe = a.onWriteCell(h, g, d, l, W), z = {
|
|
390
390
|
id: V.id,
|
|
391
391
|
params: {
|
|
392
392
|
unitId: p,
|
|
@@ -397,25 +397,25 @@ const D = {
|
|
|
397
397
|
}
|
|
398
398
|
}
|
|
399
399
|
}
|
|
400
|
-
}, he = Me(s,
|
|
400
|
+
}, he = Me(s, z.params), K = {
|
|
401
401
|
id: V.id,
|
|
402
402
|
params: he
|
|
403
|
-
}, H = [
|
|
404
|
-
return
|
|
403
|
+
}, H = [z], x = [K], J = i.getHyperLinkByLocation(p, f, d, l);
|
|
404
|
+
return J && (H.push({
|
|
405
405
|
id: N.id,
|
|
406
406
|
params: {
|
|
407
407
|
unitId: p,
|
|
408
408
|
subUnitId: f,
|
|
409
|
-
id:
|
|
409
|
+
id: J.id
|
|
410
410
|
}
|
|
411
411
|
}), x.push({
|
|
412
412
|
id: D.id,
|
|
413
413
|
params: {
|
|
414
414
|
unitId: p,
|
|
415
415
|
subUnitId: f,
|
|
416
|
-
link:
|
|
416
|
+
link: J
|
|
417
417
|
}
|
|
418
|
-
})),
|
|
418
|
+
})), G(H, t) ? await a.onValidateCell(h, g, d, l) === !1 ? (G(x, t), !1) : (n.pushUndoRedo({
|
|
419
419
|
redoMutations: H,
|
|
420
420
|
undoMutations: x,
|
|
421
421
|
unitID: p
|
|
@@ -478,7 +478,7 @@ const D = {
|
|
|
478
478
|
const t = s.get(R), { unitId: n, subUnitId: r, id: i, row: a, column: o, silent: c } = e;
|
|
479
479
|
return t.updateHyperLinkRef(n, r, i, { row: a, column: o }, c);
|
|
480
480
|
}
|
|
481
|
-
},
|
|
481
|
+
}, Q = {
|
|
482
482
|
type: L.MUTATION,
|
|
483
483
|
id: "sheets.mutation.update-rich-hyper-link",
|
|
484
484
|
handler(s, e) {
|
|
@@ -491,13 +491,13 @@ const D = {
|
|
|
491
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
492
|
return h && (h.properties.url = o), !0;
|
|
493
493
|
}
|
|
494
|
-
}, kt = "sheets-hyper-link.config", Ue = {}, xe = "SHEET_HYPER_LINK_PLUGIN",
|
|
494
|
+
}, kt = "sheets-hyper-link.config", Ue = {}, xe = "SHEET_HYPER_LINK_PLUGIN", te = "err";
|
|
495
495
|
var Lt = Object.getOwnPropertyDescriptor, Et = (s, e, t, n) => {
|
|
496
496
|
for (var r = n > 1 ? void 0 : n ? Lt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
|
|
497
497
|
(a = s[i]) && (r = a(r) || r);
|
|
498
498
|
return r;
|
|
499
|
-
},
|
|
500
|
-
let
|
|
499
|
+
}, X = (s, e) => (t, n) => e(t, n, s);
|
|
500
|
+
let ne = class extends T {
|
|
501
501
|
constructor(e, t, n, r) {
|
|
502
502
|
super();
|
|
503
503
|
w(this, "_disposableMap", /* @__PURE__ */ new Map());
|
|
@@ -600,7 +600,7 @@ let te = class extends T {
|
|
|
600
600
|
};
|
|
601
601
|
if (d.range && d.gid) {
|
|
602
602
|
const l = d.gid, u = Ce(d.range).range;
|
|
603
|
-
if (Ie(u) && d.range !==
|
|
603
|
+
if (Ie(u) && d.range !== te) {
|
|
604
604
|
const h = (g) => {
|
|
605
605
|
const p = it(u, g, { selectionManagerService: this._selectionManagerService });
|
|
606
606
|
return p && B(p) === B(u) ? {
|
|
@@ -700,18 +700,18 @@ let te = class extends T {
|
|
|
700
700
|
}));
|
|
701
701
|
}
|
|
702
702
|
};
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
],
|
|
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
709
|
var Ut = Object.getOwnPropertyDescriptor, bt = (s, e, t, n) => {
|
|
710
710
|
for (var r = n > 1 ? void 0 : n ? Ut(e, t) : e, i = s.length - 1, a; i >= 0; i--)
|
|
711
711
|
(a = s[i]) && (r = a(r) || r);
|
|
712
712
|
return r;
|
|
713
713
|
}, ge = (s, e) => (t, n) => e(t, n, s);
|
|
714
|
-
let
|
|
714
|
+
let re = class extends T {
|
|
715
715
|
constructor(s, e, t) {
|
|
716
716
|
super(), this._sheetInterceptorService = s, this._univerInstanceService = e, this._hyperLinkModel = t, this._initSheetChange();
|
|
717
717
|
}
|
|
@@ -750,17 +750,17 @@ let ne = class extends T {
|
|
|
750
750
|
);
|
|
751
751
|
}
|
|
752
752
|
};
|
|
753
|
-
|
|
753
|
+
re = bt([
|
|
754
754
|
ge(0, M(ue)),
|
|
755
755
|
ge(1, k),
|
|
756
756
|
ge(2, M(R))
|
|
757
|
-
],
|
|
757
|
+
], re);
|
|
758
758
|
var Pt = Object.getOwnPropertyDescriptor, Dt = (s, e, t, n) => {
|
|
759
759
|
for (var r = n > 1 ? void 0 : n ? Pt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
|
|
760
760
|
(a = s[i]) && (r = a(r) || r);
|
|
761
761
|
return r;
|
|
762
762
|
}, fe = (s, e) => (t, n) => e(t, n, s);
|
|
763
|
-
let
|
|
763
|
+
let se = class extends T {
|
|
764
764
|
constructor(e, t, n) {
|
|
765
765
|
super();
|
|
766
766
|
w(this, "_refRangeMap", /* @__PURE__ */ new Map());
|
|
@@ -770,7 +770,7 @@ let re = class extends T {
|
|
|
770
770
|
let n = this._refRangeMap.get(e);
|
|
771
771
|
n || (n = /* @__PURE__ */ new Map(), this._refRangeMap.set(e, n));
|
|
772
772
|
let r = n.get(t);
|
|
773
|
-
return r || (r = new
|
|
773
|
+
return r || (r = new Z(), n.set(t, r)), r;
|
|
774
774
|
}
|
|
775
775
|
_isLegalRangeUrl(e, t) {
|
|
776
776
|
var r, i, a;
|
|
@@ -788,7 +788,7 @@ let re = class extends T {
|
|
|
788
788
|
if (!l)
|
|
789
789
|
return null;
|
|
790
790
|
const u = Ce(c.range).range;
|
|
791
|
-
if (Ie(u, l) && c.range !==
|
|
791
|
+
if (Ie(u, l) && c.range !== te)
|
|
792
792
|
return {
|
|
793
793
|
range: u,
|
|
794
794
|
worksheet: l
|
|
@@ -824,18 +824,18 @@ let re = class extends T {
|
|
|
824
824
|
undos: []
|
|
825
825
|
} : {
|
|
826
826
|
preRedos: [{
|
|
827
|
-
id:
|
|
827
|
+
id: Q.id,
|
|
828
828
|
params: {
|
|
829
829
|
unitId: e,
|
|
830
830
|
subUnitId: t,
|
|
831
831
|
row: n,
|
|
832
832
|
col: r,
|
|
833
833
|
id: g.rangeId,
|
|
834
|
-
url: `#gid=${t}&range=${v ? B(v) :
|
|
834
|
+
url: `#gid=${t}&range=${v ? B(v) : te}`
|
|
835
835
|
}
|
|
836
836
|
}],
|
|
837
837
|
undos: [{
|
|
838
|
-
id:
|
|
838
|
+
id: Q.id,
|
|
839
839
|
params: {
|
|
840
840
|
unitId: e,
|
|
841
841
|
subUnitId: t,
|
|
@@ -896,7 +896,7 @@ let re = class extends T {
|
|
|
896
896
|
this._commandService.onCommandExecuted((e) => {
|
|
897
897
|
if (e.id === V.id) {
|
|
898
898
|
const t = e.params, { unitId: n, subUnitId: r, cellValue: i } = t, a = this._enusreMap(n, r);
|
|
899
|
-
i && new
|
|
899
|
+
i && new Z(i).forValue((o, c, d) => {
|
|
900
900
|
const l = a.getValue(o, c);
|
|
901
901
|
l && l.dispose(), d && d.p && this._registerRange(n, r, o, c, d.p);
|
|
902
902
|
});
|
|
@@ -904,7 +904,7 @@ let re = class extends T {
|
|
|
904
904
|
})
|
|
905
905
|
), this.disposeWithMe(
|
|
906
906
|
this._commandService.onCommandExecuted((e) => {
|
|
907
|
-
if (e.id ===
|
|
907
|
+
if (e.id === Q.id) {
|
|
908
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
909
|
if (d && d.dispose(), o) {
|
|
910
910
|
const { worksheet: l } = o, u = l.getCellRaw(i, a);
|
|
@@ -915,17 +915,17 @@ let re = class extends T {
|
|
|
915
915
|
);
|
|
916
916
|
}
|
|
917
917
|
};
|
|
918
|
-
|
|
918
|
+
se = Dt([
|
|
919
919
|
fe(0, b),
|
|
920
920
|
fe(1, k),
|
|
921
921
|
fe(2, M(Oe))
|
|
922
|
-
],
|
|
922
|
+
], se);
|
|
923
923
|
var Nt = Object.getOwnPropertyDescriptor, Ot = (s, e, t, n) => {
|
|
924
924
|
for (var r = n > 1 ? void 0 : n ? Nt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
|
|
925
925
|
(a = s[i]) && (r = a(r) || r);
|
|
926
926
|
return r;
|
|
927
|
-
},
|
|
928
|
-
let
|
|
927
|
+
}, q = (s, e) => (t, n) => e(t, n, s);
|
|
928
|
+
let ie = class extends T {
|
|
929
929
|
constructor(s, e, t, n) {
|
|
930
930
|
super(), this._sheetInterceptorService = s, this._hyperLinkModel = e, this._selectionManagerService = t, this._univerInstanceService = n, this._initCommandInterceptor(), this._initAfterEditor();
|
|
931
931
|
}
|
|
@@ -937,7 +937,7 @@ let se = class extends T {
|
|
|
937
937
|
getMutations: (s) => {
|
|
938
938
|
if (s.id === dt.id) {
|
|
939
939
|
const e = s.params, { unitId: t, subUnitId: n } = e, r = [], i = [];
|
|
940
|
-
return e.cellValue && new
|
|
940
|
+
return e.cellValue && new Z(e.cellValue).forValue((a, o) => {
|
|
941
941
|
const c = this._hyperLinkModel.getHyperLinkByLocation(t, n, a, o);
|
|
942
942
|
c && (r.push({
|
|
943
943
|
id: N.id,
|
|
@@ -1009,14 +1009,14 @@ let se = class extends T {
|
|
|
1009
1009
|
handler: (s, e, t) => {
|
|
1010
1010
|
if (!s || s.p)
|
|
1011
1011
|
return t(s);
|
|
1012
|
-
if (typeof s.v == "string" &&
|
|
1013
|
-
const { unitId: n, subUnitId: r, row: i, col: a } = e, o = this._univerInstanceService.getUnit(n, I.UNIVER_SHEET),
|
|
1014
|
-
if (!
|
|
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
1015
|
return t(s);
|
|
1016
|
-
const
|
|
1017
|
-
if (!
|
|
1016
|
+
const l = d.getBlankCellDocumentModel(s, i, a);
|
|
1017
|
+
if (!l.documentModel)
|
|
1018
1018
|
return t(s);
|
|
1019
|
-
const
|
|
1019
|
+
const u = ee.selection.replace({
|
|
1020
1020
|
selection: {
|
|
1021
1021
|
startOffset: 0,
|
|
1022
1022
|
endOffset: s.v.length,
|
|
@@ -1030,20 +1030,20 @@ let se = class extends T {
|
|
|
1030
1030
|
rangeId: le(),
|
|
1031
1031
|
rangeType: U.HYPERLINK,
|
|
1032
1032
|
properties: {
|
|
1033
|
-
url:
|
|
1033
|
+
url: o
|
|
1034
1034
|
}
|
|
1035
1035
|
}]
|
|
1036
1036
|
},
|
|
1037
|
-
doc:
|
|
1037
|
+
doc: l.documentModel
|
|
1038
1038
|
});
|
|
1039
|
-
if (!
|
|
1039
|
+
if (!u)
|
|
1040
1040
|
return t(s);
|
|
1041
|
-
const
|
|
1042
|
-
return ce.apply(
|
|
1041
|
+
const h = l.documentModel.getBody();
|
|
1042
|
+
return ce.apply(h, u.serialize()), t({
|
|
1043
1043
|
...s,
|
|
1044
1044
|
p: {
|
|
1045
1045
|
id: Ye,
|
|
1046
|
-
body:
|
|
1046
|
+
body: h,
|
|
1047
1047
|
documentStyle: {
|
|
1048
1048
|
pageSize: {
|
|
1049
1049
|
width: 1 / 0,
|
|
@@ -1058,18 +1058,18 @@ let se = class extends T {
|
|
|
1058
1058
|
}));
|
|
1059
1059
|
}
|
|
1060
1060
|
};
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
],
|
|
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
1067
|
var Ht = Object.getOwnPropertyDescriptor, xt = (s, e, t, n) => {
|
|
1068
1068
|
for (var r = n > 1 ? void 0 : n ? Ht(e, t) : e, i = s.length - 1, a; i >= 0; i--)
|
|
1069
1069
|
(a = s[i]) && (r = a(r) || r);
|
|
1070
1070
|
return r;
|
|
1071
1071
|
}, be = (s, e) => (t, n) => e(t, n, s);
|
|
1072
|
-
let
|
|
1072
|
+
let ae = class extends T {
|
|
1073
1073
|
constructor(s, e) {
|
|
1074
1074
|
super(), this._resourceManagerService = s, this._hyperLinkModel = e, this._initSnapshot();
|
|
1075
1075
|
}
|
|
@@ -1108,16 +1108,16 @@ let ie = class extends T {
|
|
|
1108
1108
|
);
|
|
1109
1109
|
}
|
|
1110
1110
|
};
|
|
1111
|
-
|
|
1111
|
+
ae = xt([
|
|
1112
1112
|
be(0, Ge),
|
|
1113
1113
|
be(1, M(R))
|
|
1114
|
-
],
|
|
1114
|
+
], ae);
|
|
1115
1115
|
var Vt = Object.getOwnPropertyDescriptor, Tt = (s, e, t, n) => {
|
|
1116
1116
|
for (var r = n > 1 ? void 0 : n ? Vt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
|
|
1117
1117
|
(a = s[i]) && (r = a(r) || r);
|
|
1118
1118
|
return r;
|
|
1119
1119
|
}, $t = (s, e) => (t, n) => e(t, n, s);
|
|
1120
|
-
let
|
|
1120
|
+
let oe = class extends T {
|
|
1121
1121
|
constructor(s) {
|
|
1122
1122
|
super(), this._commandService = s, this._registerCommands();
|
|
1123
1123
|
}
|
|
@@ -1133,15 +1133,15 @@ let ae = class extends T {
|
|
|
1133
1133
|
_e,
|
|
1134
1134
|
N,
|
|
1135
1135
|
ye,
|
|
1136
|
-
|
|
1136
|
+
Q
|
|
1137
1137
|
].forEach((s) => {
|
|
1138
1138
|
this._commandService.registerCommand(s);
|
|
1139
1139
|
});
|
|
1140
1140
|
}
|
|
1141
1141
|
};
|
|
1142
|
-
|
|
1142
|
+
oe = Tt([
|
|
1143
1143
|
$t(0, b)
|
|
1144
|
-
],
|
|
1144
|
+
], oe);
|
|
1145
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
1146
|
for (var r = n > 1 ? void 0 : n ? At(e, t) : e, i = s.length - 1, a; i >= 0; i--)
|
|
1147
1147
|
(a = s[i]) && (r = a(r) || r);
|
|
@@ -1189,7 +1189,7 @@ let ve = class {
|
|
|
1189
1189
|
if (t) {
|
|
1190
1190
|
if (!o) return a;
|
|
1191
1191
|
const l = Ce(t).range;
|
|
1192
|
-
return Ie(l, o) && t !==
|
|
1192
|
+
return Ie(l, o) && t !== te ? {
|
|
1193
1193
|
type: E.RANGE,
|
|
1194
1194
|
name: mt(c, l)
|
|
1195
1195
|
} : a;
|
|
@@ -1221,7 +1221,7 @@ var Bt = Object.defineProperty, jt = Object.getOwnPropertyDescriptor, Ft = (s, e
|
|
|
1221
1221
|
(a = s[i]) && (r = a(r) || r);
|
|
1222
1222
|
return r;
|
|
1223
1223
|
}, Pe = (s, e) => (t, n) => e(t, n, s), Ve = (s, e, t) => Ft(s, typeof e != "symbol" ? e + "" : e, t);
|
|
1224
|
-
let
|
|
1224
|
+
let de = class extends Qe {
|
|
1225
1225
|
constructor(s = Ue, e, t) {
|
|
1226
1226
|
super(), this._config = s, this._injector = e, this._configService = t;
|
|
1227
1227
|
const { ...n } = Ze(
|
|
@@ -1235,41 +1235,41 @@ let oe = class extends Qe {
|
|
|
1235
1235
|
et(this._injector, [
|
|
1236
1236
|
[R],
|
|
1237
1237
|
[ve],
|
|
1238
|
-
[ie],
|
|
1239
1238
|
[ae],
|
|
1240
|
-
[
|
|
1241
|
-
[se],
|
|
1239
|
+
[oe],
|
|
1242
1240
|
[ne],
|
|
1243
|
-
[re]
|
|
1244
|
-
]), tt(this._injector, [
|
|
1245
|
-
[te],
|
|
1246
1241
|
[ie],
|
|
1247
|
-
[
|
|
1248
|
-
[se]
|
|
1242
|
+
[re],
|
|
1243
|
+
[se]
|
|
1244
|
+
]), tt(this._injector, [
|
|
1249
1245
|
[ne],
|
|
1250
|
-
[
|
|
1246
|
+
[ae],
|
|
1247
|
+
[oe],
|
|
1248
|
+
[ie],
|
|
1249
|
+
[re],
|
|
1250
|
+
[se]
|
|
1251
1251
|
]);
|
|
1252
1252
|
}
|
|
1253
1253
|
};
|
|
1254
|
-
Ve(
|
|
1255
|
-
Ve(
|
|
1256
|
-
|
|
1254
|
+
Ve(de, "pluginName", xe);
|
|
1255
|
+
Ve(de, "type", I.UNIVER_SHEET);
|
|
1256
|
+
de = Kt([
|
|
1257
1257
|
Je(ht),
|
|
1258
1258
|
Pe(1, M(Xe)),
|
|
1259
1259
|
Pe(2, qe)
|
|
1260
|
-
],
|
|
1260
|
+
], de);
|
|
1261
1261
|
export {
|
|
1262
1262
|
St as AddHyperLinkCommand,
|
|
1263
1263
|
D as AddHyperLinkMutation,
|
|
1264
1264
|
Rt as AddRichHyperLinkCommand,
|
|
1265
1265
|
It as CancelHyperLinkCommand,
|
|
1266
1266
|
Mt as CancelRichHyperLinkCommand,
|
|
1267
|
-
|
|
1267
|
+
te as ERROR_RANGE,
|
|
1268
1268
|
R as HyperLinkModel,
|
|
1269
1269
|
N as RemoveHyperLinkMutation,
|
|
1270
1270
|
E as SheetHyperLinkType,
|
|
1271
1271
|
ve as SheetsHyperLinkParserService,
|
|
1272
|
-
|
|
1272
|
+
de as UniverSheetsHyperLinkPlugin,
|
|
1273
1273
|
Ct as UpdateHyperLinkCommand,
|
|
1274
1274
|
_e as UpdateHyperLinkMutation,
|
|
1275
1275
|
ye as UpdateHyperLinkRefMutation,
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(g,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/docs"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs","@univerjs/sheets","rxjs","@univerjs/engine-formula"],a):(g=typeof globalThis<"u"?globalThis:g||self,a(g.UniverSheetsHyperLink={},g.UniverCore,g.UniverDocs,g.UniverSheets,g.rxjs,g.UniverEngineFormula))})(this,(function(g,a,w,m,Se,C){"use strict";var Ke=Object.defineProperty;var Ye=(g,a,w)=>a in g?Ke(g,a,{enumerable:!0,configurable:!0,writable:!0,value:w}):g[a]=w;var L=(g,a,w)=>Ye(g,typeof a!="symbol"?a+"":a,w);var Ie=Object.getOwnPropertyDescriptor,Re=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ie(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},Me=(r,t)=>(e,n)=>t(e,n,r);g.HyperLinkModel=class extends a.Disposable{constructor(e){super();L(this,"_linkUpdate$",new Se.Subject);L(this,"linkUpdate$",this._linkUpdate$.asObservable());L(this,"_linkMap",new Map);L(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let i=this._linkMap.get(e);i||(i=new Map,this._linkMap.set(e,i));let s=i.get(n);s||(s=new a.ObjectMatrix,i.set(n,s));let o=this._linkPositionMap.get(e);o||(o=new Map,this._linkPositionMap.set(e,o));let d=o.get(n);return d||(d=new Map,o.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n);return s.setValue(i.row,i.column,i),o.set(i.id,{row:i.row,column:i.column,link:i}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:i,type:"add"}),!0}updateHyperLink(e,n,i,s,o=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;const u=d.getValue(l.row,l.column);return u&&(Object.assign(u,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:u.display,payload:u.payload},id:i,type:"update",silent:o})),!0}updateHyperLinkRef(e,n,i,s,o=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;let u=d.getValue(l.row,l.column);return!u||u.id!==i?u=l.link:d.realDeleteValue(l.row,l.column),Object.assign(u,s),c.set(i,{...s,link:u}),d.setValue(s.row,s.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:i,type:"updateRef",silent:o}),!0}removeHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(!d)return!1;o.delete(i);const c=s.getValue(d.row,d.column);return c&&c.id===i&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,i,s){const{matrix:o}=this._ensureMap(e,n);return o.getValue(i,s)}getHyperLinkByLocationSync(e,n,i,s){var p,f,y,h,_;const{matrix:o}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,a.UniverInstanceType.UNIVER_SHEET),c=(p=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:p.getCellRaw(i,s),l=((_=(h=c==null?void 0:c.v)!=null?h:(y=(f=c==null?void 0:c.p)==null?void 0:f.body)==null?void 0:y.dataStream.slice(0,-2))!=null?_:"").toString(),u=o.getValue(i,s);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:i}=this._ensureMap(e,n),s=[];return i.forValue((o,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(i=>{const s=this.getSubUnit(e,i);return{unitId:e,subUnitId:i,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}},g.HyperLinkModel=Re([Me(0,a.IUniverInstanceService)],g.HyperLinkModel);const E={type:a.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,link:s}=t;return e.addHyperLink(n,i,s)}},T={type:a.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,id:s}=t;return e.removeHyperLink(n,i,s)}},re={type:a.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(r,t){if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(g.HyperLinkModel),o=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:u,worksheet:p}=d,{link:f}=t,{payload:y,display:h,row:_,column:v,id:S}=f,k=p.getCell(_,v),I=p.getBlankCellDocumentModel(k,_,v),R=I.documentModel.getSnapshot(),M=a.Tools.deepClone(R.body);if(!M)return!1;let H;if(h?H=a.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:M.dataStream.length-2,collapsed:M.dataStream.length-2===0},body:{dataStream:`${h}`,customRanges:[{startIndex:0,endIndex:h.length-1,rangeType:a.CustomRangeType.HYPERLINK,rangeId:S,properties:{url:y}}]},doc:I.documentModel}):H=a.BuildTextUtils.customRange.add({body:M,ranges:[{startOffset:0,endOffset:M.dataStream.length-2,collapsed:!1}],rangeId:S,rangeType:a.CustomRangeType.HYPERLINK,properties:{url:y,refId:S}}),!H)return!1;const j=a.TextX.apply(M,H.serialize()),b={p:{...R,body:j},t:a.CellValueType.STRING},N=o.onWriteCell(u,p,_,v,b),V={unitId:c,subUnitId:l,cellValue:{[f.row]:{[f.column]:N}}},ie={id:m.SetRangeValuesMutation.id,params:V},Q=m.SetRangeValuesUndoMutationFactory(r,V),se={id:m.SetRangeValuesMutation.id,params:Q},A=[ie],P=[se],D=s.getHyperLinkByLocation(c,l,_,v);return D&&(A.push({id:T.id,params:{unitId:c,subUnitId:l,id:D.id}}),P.push({id:E.id,params:{unitId:c,subUnitId:l,link:D}})),await a.sequenceExecute(A,e)?await o.onValidateCell(u,p,_,v)===!1?(a.sequenceExecute(P,e),!1):(n.pushUndoRedo({redoMutations:A,undoMutations:P,unitID:c}),!0):!1}},ae={id:"sheets.command.add-rich-hyper-link",type:a.CommandType.COMMAND,handler:async(r,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,i=r.get(a.ICommandService),s=a.generateRandomId(),{payload:o}=n,d=w.addCustomRangeBySelectionFactory(r,{unitId:e,rangeId:s,rangeType:a.CustomRangeType.HYPERLINK,properties:{url:o,refId:s}});return d?i.syncExecuteCommand(d.id,d.params):!1}},oe={type:a.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(r,t){var b,N;if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(g.HyperLinkModel),o=m.getSheetCommandTarget(i,t);if(!o)return!1;const{row:d,column:c,id:l}=t,{unitId:u,subUnitId:p,worksheet:f}=o,y=f.getCell(d,c);if(!y)return!1;const h=f.getCellDocumentModelWithFormula(y,d,c);if(!(h!=null&&h.documentModel))return!1;const _=a.Tools.deepClone(h.documentModel.getSnapshot()),v=(N=(b=_.body)==null?void 0:b.customRanges)==null?void 0:N.find(V=>`${V.rangeId}`===l);if(!v)return!1;const S=a.BuildTextUtils.customRange.delete({documentDataModel:h.documentModel,rangeId:v.rangeId});if(!S)return!1;const k=a.TextX.apply(_.body,S.serialize()),I=[],R=[],M={unitId:u,subUnitId:p,cellValue:{[d]:{[c]:{p:{..._,body:k},t:a.CellValueType.STRING}}}};I.push({id:m.SetRangeValuesMutation.id,params:M});const H=m.SetRangeValuesUndoMutationFactory(r,M);R.push({id:m.SetRangeValuesMutation.id,params:H});const j=s.getHyperLinkByLocation(u,p,d,c);return j&&(I.push({id:T.id,params:{unitId:u,subUnitId:p,id:l}}),R.push({id:E.id,params:{unitId:u,subUnitId:p,link:{...j}}})),a.sequenceExecute(I,e).result?(n.pushUndoRedo({redoMutations:I,undoMutations:R,unitID:u}),!0):!1}},de={type:a.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(r,t){var u,p;if(!t)return!1;const{id:e,documentId:n}=t,i=r.get(a.ICommandService),o=r.get(a.IUniverInstanceService).getUnit(n,a.UniverInstanceType.UNIVER_DOC),d=(p=(u=o==null?void 0:o.getBody())==null?void 0:u.customRanges)==null?void 0:p.find(f=>f.rangeId===e);let c=null;d&&d.endIndex===o.getBody().dataStream.length-3&&(c={dataStream:" "});const l=w.deleteCustomRangeFactory(r,{unitId:n,rangeId:e,insert:c});return l?i.syncExecuteCommand(l.id,l.params):!1}},ce={type:a.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(r,t){var fe,ye,_e;if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(g.HyperLinkModel),o=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:u,id:p}=t,{workbook:f,worksheet:y,unitId:h,subUnitId:_}=d,{payload:v,display:S=""}=c,k=y.getCell(l,u);if(!k)return!1;const I=y.getCellDocumentModelWithFormula(k,l,u);if(!(I!=null&&I.documentModel))return!1;const R=I.documentModel.getSnapshot(),M=(ye=(fe=R.body)==null?void 0:fe.customRanges)==null?void 0:ye.find(ve=>`${ve.rangeId}`===p);if(!M)return!1;const H=a.generateRandomId(),O=(_e=a.getBodySlice(I.documentModel.getBody(),M.startIndex,M.endIndex+1).textRuns)==null?void 0:_e[0];O&&(O.ed=S.length+1);const b=w.replaceSelectionFactory(r,{unitId:h,body:{dataStream:`${S}`,customRanges:[{rangeId:H,rangeType:a.CustomRangeType.HYPERLINK,startIndex:0,endIndex:S.length-1,properties:{url:v}}],textRuns:O?[O]:void 0},selection:{startOffset:M.startIndex,endOffset:M.endIndex+1,collapsed:!1},doc:I.documentModel});if(!b)return!1;const N=a.TextX.apply(a.Tools.deepClone(R.body),b.textX.serialize()),V={p:{...R,body:N},t:a.CellValueType.STRING},ie=o.onWriteCell(f,y,l,u,V),Q={id:m.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:_,cellValue:{[l]:{[u]:ie}}}},se=m.SetRangeValuesUndoMutationFactory(r,Q.params),A={id:m.SetRangeValuesMutation.id,params:se},P=[Q],D=[A],Z=s.getHyperLinkByLocation(h,_,l,u);return Z&&(P.push({id:T.id,params:{unitId:h,subUnitId:_,id:Z.id}}),D.push({id:E.id,params:{unitId:h,subUnitId:_,link:Z}})),a.sequenceExecute(P,e)?await o.onValidateCell(f,y,l,u)===!1?(a.sequenceExecute(D,e),!1):(n.pushUndoRedo({redoMutations:P,undoMutations:D,unitID:h}),!0):!1}},le={type:a.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(r,t)=>{var h,_,v,S;if(!t)return!1;const{documentId:e,payload:n,id:i}=t,s=r.get(a.IUniverInstanceService),o=r.get(a.ICommandService),d=s.getUnit(e,a.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(_=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:_.find(k=>k.rangeId===i);if(!c)return!1;const l=(v=t.payload.display)!=null?v:"",u=a.generateRandomId(),f=(S=a.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:S[0];f&&(f.ed=l.length+1);const y=w.replaceSelectionFactory(r,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:u,rangeType:a.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:f?[f]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return y?o.syncExecuteCommand(y.id,y.params):!1}},x={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,payload:s,id:o}=t;return e.updateHyperLink(n,i,o,s,!1)}},W={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,id:s,row:o,column:d,silent:c}=t;return e.updateHyperLinkRef(n,i,s,{row:o,column:d},c)}},B={type:a.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(r,t){var y,h,_;if(!t)return!1;const{unitId:e,subUnitId:n,row:i,col:s,id:o,url:d}=t,c=r.get(a.IUniverInstanceService),l=m.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,p=u.getCellRaw(i,s),f=(_=(h=(y=p==null?void 0:p.p)==null?void 0:y.body)==null?void 0:h.customRanges)==null?void 0:_.find(v=>v.rangeType===a.CustomRangeType.HYPERLINK&&v.rangeId===o);return f&&(f.properties.url=d),!0}},Ce="sheets-hyper-link.config",ue={},pe="SHEET_HYPER_LINK_PLUGIN",$="err";var ke=Object.getOwnPropertyDescriptor,Le=(r,t,e,n)=>{for(var i=n>1?void 0:n?ke(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},z=(r,t)=>(e,n)=>t(e,n,r);let K=class extends a.Disposable{constructor(t,e,n,i){super();L(this,"_disposableMap",new Map);L(this,"_watchDisposableMap",new Map);L(this,"_rangeDisableMap",new Map);L(this,"_rangeWatcherMap",new Map);L(this,"_handlePositionChange",(t,e,n,i,s)=>{const o={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return i?{redos:[{id:W.id,params:{unitId:t,subUnitId:e,id:n.id,row:i.startRow,column:i.startColumn,silent:s}}],undos:[{id:W.id,params:{unitId:t,subUnitId:e,id:n.id,row:o.startRow,column:o.startColumn,silent:s}}]}:{redos:[{id:T.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:E.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=i,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},o=d=>{const c=m.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(i,this._refRangeService.registerRefRange(s,o,t,e))}_watchPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(t,e,s,(o,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);a.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,i=!1){var s,o,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(o=c.get("range"))!=null?o:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const u=l.gid,p=C.deserializeRangeWithSheet(l.range).range;if(a.isValidRange(p)&&l.range!==$){const f=y=>{const h=m.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(p,y,{selectionManagerService:this._selectionManagerService});return h&&C.serializeRange(h)===C.serializeRange(p)?{redos:[],undos:[]}:{redos:[{id:x.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`}}}],undos:[{id:x.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(p,f,t,u)),i||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,p,(y,h)=>{this._hyperLinkModel.updateHyperLink(t,u,e,{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:i,subUnitId:s,links:o}=n;o.forEach(d=>{this._registerPosition(i,s,d),this._watchPosition(i,s,d),this._registerRange(i,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:i,silent:s}=t,o=this._hyperLinkModel.getHyperLink(e,n,i);if(!o)return;this._unregisterPosition(i),this._registerPosition(e,n,o),s||(this._unwatchPosition(i),this._watchPosition(e,n,o));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:i}=n;i.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(a.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};K=Le([z(0,a.Inject(m.RefRangeService)),z(1,a.Inject(g.HyperLinkModel)),z(2,a.Inject(m.SheetsSelectionsService)),z(3,a.ICommandService)],K);var Ue=Object.getOwnPropertyDescriptor,we=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ue(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},ee=(r,t)=>(e,n)=>t(e,n,r);let Y=class extends a.Disposable{constructor(r,t,e){super(),this._sheetInterceptorService=r,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{var t;if(r.id===m.RemoveSheetCommand.id){const e=r.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const i=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const o=this._hyperLinkModel.getSubUnit(i,s),d=o.map(l=>({id:T.id,params:{unitId:i,subUnitId:s,id:l.id}})),c=o.map(l=>({id:E.id,params:{unitId:i,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};Y=we([ee(0,a.Inject(m.SheetInterceptorService)),ee(1,a.IUniverInstanceService),ee(2,a.Inject(g.HyperLinkModel))],Y);var Ee=Object.getOwnPropertyDescriptor,Te=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ee(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},te=(r,t)=>(e,n)=>t(e,n,r);let q=class extends a.Disposable{constructor(t,e,n){super();L(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let i=n.get(e);return i||(i=new a.ObjectMatrix,n.set(e,i)),i}_isLegalRangeUrl(t,e){var i,s,o;const n=this._univerInstanceService.getUnit(t,a.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(i=d.get("gid"))!=null?i:"",range:(s=d.get("range"))!=null?s:"",rangeid:(o=d.get("rangeid"))!=null?o:""};if(c.range&&c.gid){const l=c.gid,u=n.getSheetBySheetId(l);if(!u)return null;const p=C.deserializeRangeWithSheet(c.range).range;if(a.isValidRange(p,u)&&c.range!==$)return{range:p,worksheet:u}}}return null}_registerRange(t,e,n,i,s){var d,c,l,u;const o=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(p=>{var f;return p.rangeType===a.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(f=p.properties)==null?void 0:f.url)})){const p=new a.DisposableCollection;let f=!1;(u=(l=s.body)==null?void 0:l.customRanges)==null||u.forEach(y=>{var h;if(y.rangeType===a.CustomRangeType.HYPERLINK){const _=(h=y.properties)==null?void 0:h.url,v=this._isLegalRangeUrl(t,_);if(v){const{range:S,worksheet:k}=v;f=!0,p.add(this._refRangeService.registerRefRange(S,I=>{const R=m.handleDefaultRangeChangeWithEffectRefCommands(S,I);return R&&a.Rectangle.equals(R,S)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:y.rangeId,url:`#gid=${e}&range=${R?C.serializeRange(R):$}`}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:y.rangeId,url:_}}],redos:[]}},k.getUnitId(),k.getSheetId()))}}}),f&&o.setValue(n,i,p)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId(),o=this._enusreMap(n,s);i.getCellMatrix().forValue((d,c,l)=>{const u=o.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,s,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===a.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===a.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}}))}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===m.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:i,cellValue:s}=e,o=this._enusreMap(n,i);s&&new a.ObjectMatrix(s).forValue((d,c,l)=>{const u=o.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,i,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===B.id){const e=t.params,{unitId:n,subUnitId:i,row:s,col:o}=e,d=m.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),l=this._enusreMap(n,i).getValue(s,o);if(l&&l.dispose(),d){const{worksheet:u}=d,p=u.getCellRaw(s,o);p&&p.p&&this._registerRange(n,i,s,o,p.p)}}}))}};q=Te([te(0,a.ICommandService),te(1,a.IUniverInstanceService),te(2,a.Inject(m.RefRangeService))],q);var He=Object.getOwnPropertyDescriptor,be=(r,t,e,n)=>{for(var i=n>1?void 0:n?He(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},G=(r,t)=>(e,n)=>t(e,n,r);let F=class extends a.Disposable{constructor(r,t,e,n){super(),this._sheetInterceptorService=r,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.SetRangeValuesCommand.id){const t=r.params,{unitId:e,subUnitId:n}=t,i=[],s=[];return t.cellValue&&new a.ObjectMatrix(t.cellValue).forValue((o,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,o,d);c&&(i.push({id:T.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:E.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:i}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.ClearSelectionContentCommand.id||r.id===m.ClearSelectionAllCommand.id||r.id===m.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),i=m.getSheetCommandTarget(this._univerInstanceService);if(n&&i){const{unitId:s,subUnitId:o}=i;a.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,o,d,c);l&&(t.push({id:T.id,params:{unitId:s,subUnitId:o,id:l.id}}),e.push({id:E.id,params:{unitId:s,subUnitId:o,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(m.AFTER_CELL_EDIT,{handler:(r,t,e)=>{if(!r||r.p)return e(r);if(typeof r.v=="string"&&a.Tools.isLegalUrl(r.v)&&r.v[r.v.length-1]!==" "){const{unitId:n,subUnitId:i,row:s,col:o}=t,d=this._univerInstanceService.getUnit(n,a.UniverInstanceType.UNIVER_SHEET),c=d==null?void 0:d.getSheetBySheetId(i);if(!c)return e(r);const l=c.getBlankCellDocumentModel(r,s,o);if(!l.documentModel)return e(r);const u=a.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:r.v.length,collapsed:!1},body:{dataStream:`${r.v}`,customRanges:[{startIndex:0,endIndex:r.v.length-1,rangeId:a.generateRandomId(),rangeType:a.CustomRangeType.HYPERLINK,properties:{url:r.v}}]},doc:l.documentModel});if(!u)return e(r);const p=l.documentModel.getBody();return a.TextX.apply(p,u.serialize()),e({...r,p:{id:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:p,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(r)}}))}};F=be([G(0,a.Inject(m.SheetInterceptorService)),G(1,a.Inject(g.HyperLinkModel)),G(2,a.Inject(m.SheetsSelectionsService)),G(3,a.IUniverInstanceService)],F);var Pe=Object.getOwnPropertyDescriptor,De=(r,t,e,n)=>{for(var i=n>1?void 0:n?Pe(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},ge=(r,t)=>(e,n)=>t(e,n,r);let X=class extends a.Disposable{constructor(r,t){super(),this._resourceManagerService=r,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const r=e=>{const n=this._hyperLinkModel.getUnit(e),i={};return n?(n.forEach(s=>{i[s.subUnitId]=s.links.map(({display:o,...d})=>d)}),JSON.stringify(i)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:pe,businesses:[a.UniverInstanceType.UNIVER_SHEET],toJson:e=>r(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(i=>{n[i].forEach(o=>{this._hyperLinkModel.addHyperLink(e,i,o)})})}}))}};X=De([ge(0,a.IResourceManagerService),ge(1,a.Inject(g.HyperLinkModel))],X);var Oe=Object.getOwnPropertyDescriptor,Ne=(r,t,e,n)=>{for(var i=n>1?void 0:n?Oe(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},Ve=(r,t)=>(e,n)=>t(e,n,r);let J=class extends a.Disposable{constructor(r){super(),this._commandService=r,this._registerCommands()}_registerCommands(){[re,ce,oe,le,de,ae,E,x,T,W,B].forEach(r=>{this._commandService.registerCommand(r)})}};J=Ne([Ve(0,a.ICommandService)],J);var U=(r=>(r.SHEET="gid",r.RANGE="range",r.DEFINE_NAME="rangeid",r.INVALID="invalid",r.URL="url",r))(U||{}),$e=Object.getOwnPropertyDescriptor,je=(r,t,e,n)=>{for(var i=n>1?void 0:n?$e(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},ne=(r,t)=>(e,n)=>t(e,n,r);g.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${U.SHEET}=${e}${n?`&${typeof n=="string"?U.DEFINE_NAME:U.RANGE}=${typeof n=="string"?n:C.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,i,s;if(t.startsWith("#")){const o=new URLSearchParams(t.slice(1)),d={gid:(e=o.get("gid"))!=null?e:"",range:(n=o.get("range"))!=null?n:"",rangeid:(i=o.get("rangeid"))!=null?i:"",unitid:(s=o.get("unitid"))!=null?s:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:U.URL,name:t,url:t,searchObj:null}}_getURLName(t){var u;const{gid:e,range:n,rangeid:i,unitid:s}=t,o=s?this._univerInstanceService.getUnit(s,a.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d={type:U.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!o)return d;const c=e?o.getSheetBySheetId(e):o.getActiveSheet(),l=(u=c==null?void 0:c.getName())!=null?u:"";if(n){if(!c)return d;const p=C.deserializeRangeWithSheet(n).range;return a.isValidRange(p,c)&&n!==$?{type:U.RANGE,name:C.serializeRangeWithSheet(l,p)}:d}if(i){const p=this._definedNamesService.getValueById(o.getUnitId(),i);return p?{type:U.DEFINE_NAME,name:p.formulaOrRefString}:d}if(e){const p=o.getSheetBySheetId(e);return p?{type:U.SHEET,name:p.getName()}:d}return d}},g.SheetsHyperLinkParserService=je([ne(0,a.IUniverInstanceService),ne(1,a.Inject(a.LocaleService)),ne(2,C.IDefinedNamesService)],g.SheetsHyperLinkParserService);var Ae=Object.defineProperty,xe=Object.getOwnPropertyDescriptor,We=(r,t,e)=>t in r?Ae(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Be=(r,t,e,n)=>{for(var i=n>1?void 0:n?xe(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},he=(r,t)=>(e,n)=>t(e,n,r),me=(r,t,e)=>We(r,typeof t!="symbol"?t+"":t,e);g.UniverSheetsHyperLinkPlugin=class extends a.Plugin{constructor(t=ue,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...i}=a.merge({},ue,this._config);this._configService.setConfig(Ce,i)}onStarting(){a.registerDependencies(this._injector,[[g.HyperLinkModel],[g.SheetsHyperLinkParserService],[X],[J],[K],[F],[Y],[q]]),a.touchDependencies(this._injector,[[K],[X],[J],[F],[Y],[q]])}},me(g.UniverSheetsHyperLinkPlugin,"pluginName",pe),me(g.UniverSheetsHyperLinkPlugin,"type",a.UniverInstanceType.UNIVER_SHEET),g.UniverSheetsHyperLinkPlugin=Be([a.DependentOn(m.UniverSheetsPlugin),he(1,a.Inject(a.Injector)),he(2,a.IConfigService)],g.UniverSheetsHyperLinkPlugin),g.AddHyperLinkCommand=re,g.AddHyperLinkMutation=E,g.AddRichHyperLinkCommand=ae,g.CancelHyperLinkCommand=oe,g.CancelRichHyperLinkCommand=de,g.ERROR_RANGE=$,g.RemoveHyperLinkMutation=T,g.SheetHyperLinkType=U,g.UpdateHyperLinkCommand=ce,g.UpdateHyperLinkMutation=x,g.UpdateHyperLinkRefMutation=W,g.UpdateRichHyperLinkCommand=le,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(g,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/docs"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs","@univerjs/sheets","rxjs","@univerjs/engine-formula"],a):(g=typeof globalThis<"u"?globalThis:g||self,a(g.UniverSheetsHyperLink={},g.UniverCore,g.UniverDocs,g.UniverSheets,g.rxjs,g.UniverEngineFormula))})(this,(function(g,a,w,m,Se,C){"use strict";var Ke=Object.defineProperty;var Ye=(g,a,w)=>a in g?Ke(g,a,{enumerable:!0,configurable:!0,writable:!0,value:w}):g[a]=w;var L=(g,a,w)=>Ye(g,typeof a!="symbol"?a+"":a,w);var Ie=Object.getOwnPropertyDescriptor,Re=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ie(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},Me=(r,t)=>(e,n)=>t(e,n,r);g.HyperLinkModel=class extends a.Disposable{constructor(e){super();L(this,"_linkUpdate$",new Se.Subject);L(this,"linkUpdate$",this._linkUpdate$.asObservable());L(this,"_linkMap",new Map);L(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let i=this._linkMap.get(e);i||(i=new Map,this._linkMap.set(e,i));let s=i.get(n);s||(s=new a.ObjectMatrix,i.set(n,s));let o=this._linkPositionMap.get(e);o||(o=new Map,this._linkPositionMap.set(e,o));let d=o.get(n);return d||(d=new Map,o.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n);return s.setValue(i.row,i.column,i),o.set(i.id,{row:i.row,column:i.column,link:i}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:i,type:"add"}),!0}updateHyperLink(e,n,i,s,o=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;const u=d.getValue(l.row,l.column);return u&&(Object.assign(u,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:u.display,payload:u.payload},id:i,type:"update",silent:o})),!0}updateHyperLinkRef(e,n,i,s,o=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;let u=d.getValue(l.row,l.column);return!u||u.id!==i?u=l.link:d.realDeleteValue(l.row,l.column),Object.assign(u,s),c.set(i,{...s,link:u}),d.setValue(s.row,s.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:i,type:"updateRef",silent:o}),!0}removeHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(!d)return!1;o.delete(i);const c=s.getValue(d.row,d.column);return c&&c.id===i&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,i,s){const{matrix:o}=this._ensureMap(e,n);return o.getValue(i,s)}getHyperLinkByLocationSync(e,n,i,s){var p,f,y,h,_;const{matrix:o}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,a.UniverInstanceType.UNIVER_SHEET),c=(p=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:p.getCellRaw(i,s),l=((_=(h=c==null?void 0:c.v)!=null?h:(y=(f=c==null?void 0:c.p)==null?void 0:f.body)==null?void 0:y.dataStream.slice(0,-2))!=null?_:"").toString(),u=o.getValue(i,s);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:i}=this._ensureMap(e,n),s=[];return i.forValue((o,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(i=>{const s=this.getSubUnit(e,i);return{unitId:e,subUnitId:i,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}},g.HyperLinkModel=Re([Me(0,a.IUniverInstanceService)],g.HyperLinkModel);const E={type:a.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,link:s}=t;return e.addHyperLink(n,i,s)}},T={type:a.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,id:s}=t;return e.removeHyperLink(n,i,s)}},re={type:a.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(r,t){if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(g.HyperLinkModel),o=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:u,worksheet:p}=d,{link:f}=t,{payload:y,display:h,row:_,column:v,id:S}=f,k=p.getCell(_,v),I=p.getBlankCellDocumentModel(k,_,v),R=I.documentModel.getSnapshot(),M=a.Tools.deepClone(R.body);if(!M)return!1;let H;if(h?H=a.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:M.dataStream.length-2,collapsed:M.dataStream.length-2===0},body:{dataStream:`${h}`,customRanges:[{startIndex:0,endIndex:h.length-1,rangeType:a.CustomRangeType.HYPERLINK,rangeId:S,properties:{url:y}}]},doc:I.documentModel}):H=a.BuildTextUtils.customRange.add({body:M,ranges:[{startOffset:0,endOffset:M.dataStream.length-2,collapsed:!1}],rangeId:S,rangeType:a.CustomRangeType.HYPERLINK,properties:{url:y,refId:S}}),!H)return!1;const j=a.TextX.apply(M,H.serialize()),b={p:{...R,body:j},t:a.CellValueType.STRING},N=o.onWriteCell(u,p,_,v,b),V={unitId:c,subUnitId:l,cellValue:{[f.row]:{[f.column]:N}}},ie={id:m.SetRangeValuesMutation.id,params:V},Q=m.SetRangeValuesUndoMutationFactory(r,V),se={id:m.SetRangeValuesMutation.id,params:Q},A=[ie],P=[se],D=s.getHyperLinkByLocation(c,l,_,v);return D&&(A.push({id:T.id,params:{unitId:c,subUnitId:l,id:D.id}}),P.push({id:E.id,params:{unitId:c,subUnitId:l,link:D}})),await a.sequenceExecute(A,e)?await o.onValidateCell(u,p,_,v)===!1?(a.sequenceExecute(P,e),!1):(n.pushUndoRedo({redoMutations:A,undoMutations:P,unitID:c}),!0):!1}},ae={id:"sheets.command.add-rich-hyper-link",type:a.CommandType.COMMAND,handler:async(r,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,i=r.get(a.ICommandService),s=a.generateRandomId(),{payload:o}=n,d=w.addCustomRangeBySelectionFactory(r,{unitId:e,rangeId:s,rangeType:a.CustomRangeType.HYPERLINK,properties:{url:o,refId:s}});return d?i.syncExecuteCommand(d.id,d.params):!1}},oe={type:a.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(r,t){var b,N;if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(g.HyperLinkModel),o=m.getSheetCommandTarget(i,t);if(!o)return!1;const{row:d,column:c,id:l}=t,{unitId:u,subUnitId:p,worksheet:f}=o,y=f.getCell(d,c);if(!y)return!1;const h=f.getCellDocumentModelWithFormula(y,d,c);if(!(h!=null&&h.documentModel))return!1;const _=a.Tools.deepClone(h.documentModel.getSnapshot()),v=(N=(b=_.body)==null?void 0:b.customRanges)==null?void 0:N.find(V=>`${V.rangeId}`===l);if(!v)return!1;const S=a.BuildTextUtils.customRange.delete({documentDataModel:h.documentModel,rangeId:v.rangeId});if(!S)return!1;const k=a.TextX.apply(_.body,S.serialize()),I=[],R=[],M={unitId:u,subUnitId:p,cellValue:{[d]:{[c]:{p:{..._,body:k},t:a.CellValueType.STRING}}}};I.push({id:m.SetRangeValuesMutation.id,params:M});const H=m.SetRangeValuesUndoMutationFactory(r,M);R.push({id:m.SetRangeValuesMutation.id,params:H});const j=s.getHyperLinkByLocation(u,p,d,c);return j&&(I.push({id:T.id,params:{unitId:u,subUnitId:p,id:l}}),R.push({id:E.id,params:{unitId:u,subUnitId:p,link:{...j}}})),a.sequenceExecute(I,e).result?(n.pushUndoRedo({redoMutations:I,undoMutations:R,unitID:u}),!0):!1}},de={type:a.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(r,t){var u,p;if(!t)return!1;const{id:e,documentId:n}=t,i=r.get(a.ICommandService),o=r.get(a.IUniverInstanceService).getUnit(n,a.UniverInstanceType.UNIVER_DOC),d=(p=(u=o==null?void 0:o.getBody())==null?void 0:u.customRanges)==null?void 0:p.find(f=>f.rangeId===e);let c=null;d&&d.endIndex===o.getBody().dataStream.length-3&&(c={dataStream:" "});const l=w.deleteCustomRangeFactory(r,{unitId:n,rangeId:e,insert:c});return l?i.syncExecuteCommand(l.id,l.params):!1}},ce={type:a.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(r,t){var fe,ye,_e;if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(g.HyperLinkModel),o=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:u,id:p}=t,{workbook:f,worksheet:y,unitId:h,subUnitId:_}=d,{payload:v,display:S=""}=c,k=y.getCell(l,u);if(!k)return!1;const I=y.getCellDocumentModelWithFormula(k,l,u);if(!(I!=null&&I.documentModel))return!1;const R=I.documentModel.getSnapshot(),M=(ye=(fe=R.body)==null?void 0:fe.customRanges)==null?void 0:ye.find(ve=>`${ve.rangeId}`===p);if(!M)return!1;const H=a.generateRandomId(),O=(_e=a.getBodySlice(I.documentModel.getBody(),M.startIndex,M.endIndex+1).textRuns)==null?void 0:_e[0];O&&(O.ed=S.length+1);const b=w.replaceSelectionFactory(r,{unitId:h,body:{dataStream:`${S}`,customRanges:[{rangeId:H,rangeType:a.CustomRangeType.HYPERLINK,startIndex:0,endIndex:S.length-1,properties:{url:v}}],textRuns:O?[O]:void 0},selection:{startOffset:M.startIndex,endOffset:M.endIndex+1,collapsed:!1},doc:I.documentModel});if(!b)return!1;const N=a.TextX.apply(a.Tools.deepClone(R.body),b.textX.serialize()),V={p:{...R,body:N},t:a.CellValueType.STRING},ie=o.onWriteCell(f,y,l,u,V),Q={id:m.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:_,cellValue:{[l]:{[u]:ie}}}},se=m.SetRangeValuesUndoMutationFactory(r,Q.params),A={id:m.SetRangeValuesMutation.id,params:se},P=[Q],D=[A],Z=s.getHyperLinkByLocation(h,_,l,u);return Z&&(P.push({id:T.id,params:{unitId:h,subUnitId:_,id:Z.id}}),D.push({id:E.id,params:{unitId:h,subUnitId:_,link:Z}})),a.sequenceExecute(P,e)?await o.onValidateCell(f,y,l,u)===!1?(a.sequenceExecute(D,e),!1):(n.pushUndoRedo({redoMutations:P,undoMutations:D,unitID:h}),!0):!1}},le={type:a.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(r,t)=>{var h,_,v,S;if(!t)return!1;const{documentId:e,payload:n,id:i}=t,s=r.get(a.IUniverInstanceService),o=r.get(a.ICommandService),d=s.getUnit(e,a.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(_=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:_.find(k=>k.rangeId===i);if(!c)return!1;const l=(v=t.payload.display)!=null?v:"",u=a.generateRandomId(),f=(S=a.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:S[0];f&&(f.ed=l.length+1);const y=w.replaceSelectionFactory(r,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:u,rangeType:a.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:f?[f]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return y?o.syncExecuteCommand(y.id,y.params):!1}},x={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,payload:s,id:o}=t;return e.updateHyperLink(n,i,o,s,!1)}},W={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,id:s,row:o,column:d,silent:c}=t;return e.updateHyperLinkRef(n,i,s,{row:o,column:d},c)}},B={type:a.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(r,t){var y,h,_;if(!t)return!1;const{unitId:e,subUnitId:n,row:i,col:s,id:o,url:d}=t,c=r.get(a.IUniverInstanceService),l=m.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,p=u.getCellRaw(i,s),f=(_=(h=(y=p==null?void 0:p.p)==null?void 0:y.body)==null?void 0:h.customRanges)==null?void 0:_.find(v=>v.rangeType===a.CustomRangeType.HYPERLINK&&v.rangeId===o);return f&&(f.properties.url=d),!0}},Ce="sheets-hyper-link.config",ue={},pe="SHEET_HYPER_LINK_PLUGIN",$="err";var ke=Object.getOwnPropertyDescriptor,Le=(r,t,e,n)=>{for(var i=n>1?void 0:n?ke(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},z=(r,t)=>(e,n)=>t(e,n,r);let K=class extends a.Disposable{constructor(t,e,n,i){super();L(this,"_disposableMap",new Map);L(this,"_watchDisposableMap",new Map);L(this,"_rangeDisableMap",new Map);L(this,"_rangeWatcherMap",new Map);L(this,"_handlePositionChange",(t,e,n,i,s)=>{const o={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return i?{redos:[{id:W.id,params:{unitId:t,subUnitId:e,id:n.id,row:i.startRow,column:i.startColumn,silent:s}}],undos:[{id:W.id,params:{unitId:t,subUnitId:e,id:n.id,row:o.startRow,column:o.startColumn,silent:s}}]}:{redos:[{id:T.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:E.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=i,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},o=d=>{const c=m.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(i,this._refRangeService.registerRefRange(s,o,t,e))}_watchPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(t,e,s,(o,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);a.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,i=!1){var s,o,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(o=c.get("range"))!=null?o:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const u=l.gid,p=C.deserializeRangeWithSheet(l.range).range;if(a.isValidRange(p)&&l.range!==$){const f=y=>{const h=m.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(p,y,{selectionManagerService:this._selectionManagerService});return h&&C.serializeRange(h)===C.serializeRange(p)?{redos:[],undos:[]}:{redos:[{id:x.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`}}}],undos:[{id:x.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(p,f,t,u)),i||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,p,(y,h)=>{this._hyperLinkModel.updateHyperLink(t,u,e,{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:i,subUnitId:s,links:o}=n;o.forEach(d=>{this._registerPosition(i,s,d),this._watchPosition(i,s,d),this._registerRange(i,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:i,silent:s}=t,o=this._hyperLinkModel.getHyperLink(e,n,i);if(!o)return;this._unregisterPosition(i),this._registerPosition(e,n,o),s||(this._unwatchPosition(i),this._watchPosition(e,n,o));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:i}=n;i.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(a.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};K=Le([z(0,a.Inject(m.RefRangeService)),z(1,a.Inject(g.HyperLinkModel)),z(2,a.Inject(m.SheetsSelectionsService)),z(3,a.ICommandService)],K);var Ue=Object.getOwnPropertyDescriptor,we=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ue(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},ee=(r,t)=>(e,n)=>t(e,n,r);let Y=class extends a.Disposable{constructor(r,t,e){super(),this._sheetInterceptorService=r,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{var t;if(r.id===m.RemoveSheetCommand.id){const e=r.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const i=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const o=this._hyperLinkModel.getSubUnit(i,s),d=o.map(l=>({id:T.id,params:{unitId:i,subUnitId:s,id:l.id}})),c=o.map(l=>({id:E.id,params:{unitId:i,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};Y=we([ee(0,a.Inject(m.SheetInterceptorService)),ee(1,a.IUniverInstanceService),ee(2,a.Inject(g.HyperLinkModel))],Y);var Ee=Object.getOwnPropertyDescriptor,Te=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ee(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},te=(r,t)=>(e,n)=>t(e,n,r);let q=class extends a.Disposable{constructor(t,e,n){super();L(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let i=n.get(e);return i||(i=new a.ObjectMatrix,n.set(e,i)),i}_isLegalRangeUrl(t,e){var i,s,o;const n=this._univerInstanceService.getUnit(t,a.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(i=d.get("gid"))!=null?i:"",range:(s=d.get("range"))!=null?s:"",rangeid:(o=d.get("rangeid"))!=null?o:""};if(c.range&&c.gid){const l=c.gid,u=n.getSheetBySheetId(l);if(!u)return null;const p=C.deserializeRangeWithSheet(c.range).range;if(a.isValidRange(p,u)&&c.range!==$)return{range:p,worksheet:u}}}return null}_registerRange(t,e,n,i,s){var d,c,l,u;const o=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(p=>{var f;return p.rangeType===a.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(f=p.properties)==null?void 0:f.url)})){const p=new a.DisposableCollection;let f=!1;(u=(l=s.body)==null?void 0:l.customRanges)==null||u.forEach(y=>{var h;if(y.rangeType===a.CustomRangeType.HYPERLINK){const _=(h=y.properties)==null?void 0:h.url,v=this._isLegalRangeUrl(t,_);if(v){const{range:S,worksheet:k}=v;f=!0,p.add(this._refRangeService.registerRefRange(S,I=>{const R=m.handleDefaultRangeChangeWithEffectRefCommands(S,I);return R&&a.Rectangle.equals(R,S)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:y.rangeId,url:`#gid=${e}&range=${R?C.serializeRange(R):$}`}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:y.rangeId,url:_}}],redos:[]}},k.getUnitId(),k.getSheetId()))}}}),f&&o.setValue(n,i,p)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId(),o=this._enusreMap(n,s);i.getCellMatrix().forValue((d,c,l)=>{const u=o.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,s,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===a.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===a.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}}))}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===m.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:i,cellValue:s}=e,o=this._enusreMap(n,i);s&&new a.ObjectMatrix(s).forValue((d,c,l)=>{const u=o.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,i,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===B.id){const e=t.params,{unitId:n,subUnitId:i,row:s,col:o}=e,d=m.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),l=this._enusreMap(n,i).getValue(s,o);if(l&&l.dispose(),d){const{worksheet:u}=d,p=u.getCellRaw(s,o);p&&p.p&&this._registerRange(n,i,s,o,p.p)}}}))}};q=Te([te(0,a.ICommandService),te(1,a.IUniverInstanceService),te(2,a.Inject(m.RefRangeService))],q);var He=Object.getOwnPropertyDescriptor,be=(r,t,e,n)=>{for(var i=n>1?void 0:n?He(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},G=(r,t)=>(e,n)=>t(e,n,r);let F=class extends a.Disposable{constructor(r,t,e,n){super(),this._sheetInterceptorService=r,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.SetRangeValuesCommand.id){const t=r.params,{unitId:e,subUnitId:n}=t,i=[],s=[];return t.cellValue&&new a.ObjectMatrix(t.cellValue).forValue((o,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,o,d);c&&(i.push({id:T.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:E.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:i}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.ClearSelectionContentCommand.id||r.id===m.ClearSelectionAllCommand.id||r.id===m.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),i=m.getSheetCommandTarget(this._univerInstanceService);if(n&&i){const{unitId:s,subUnitId:o}=i;a.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,o,d,c);l&&(t.push({id:T.id,params:{unitId:s,subUnitId:o,id:l.id}}),e.push({id:E.id,params:{unitId:s,subUnitId:o,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(m.AFTER_CELL_EDIT,{handler:(r,t,e)=>{if(!r||r.p)return e(r);if(typeof r.v=="string"&&a.Tools.isLegalUrl(r.v)&&r.v[r.v.length-1]!==" "){const{unitId:n,subUnitId:i,row:s,col:o}=t,d=a.Tools.normalizeUrl(r.v),c=this._univerInstanceService.getUnit(n,a.UniverInstanceType.UNIVER_SHEET),l=c==null?void 0:c.getSheetBySheetId(i);if(!l)return e(r);const u=l.getBlankCellDocumentModel(r,s,o);if(!u.documentModel)return e(r);const p=a.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:r.v.length,collapsed:!1},body:{dataStream:`${r.v}`,customRanges:[{startIndex:0,endIndex:r.v.length-1,rangeId:a.generateRandomId(),rangeType:a.CustomRangeType.HYPERLINK,properties:{url:d}}]},doc:u.documentModel});if(!p)return e(r);const f=u.documentModel.getBody();return a.TextX.apply(f,p.serialize()),e({...r,p:{id:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:f,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(r)}}))}};F=be([G(0,a.Inject(m.SheetInterceptorService)),G(1,a.Inject(g.HyperLinkModel)),G(2,a.Inject(m.SheetsSelectionsService)),G(3,a.IUniverInstanceService)],F);var Pe=Object.getOwnPropertyDescriptor,De=(r,t,e,n)=>{for(var i=n>1?void 0:n?Pe(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},ge=(r,t)=>(e,n)=>t(e,n,r);let X=class extends a.Disposable{constructor(r,t){super(),this._resourceManagerService=r,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const r=e=>{const n=this._hyperLinkModel.getUnit(e),i={};return n?(n.forEach(s=>{i[s.subUnitId]=s.links.map(({display:o,...d})=>d)}),JSON.stringify(i)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:pe,businesses:[a.UniverInstanceType.UNIVER_SHEET],toJson:e=>r(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(i=>{n[i].forEach(o=>{this._hyperLinkModel.addHyperLink(e,i,o)})})}}))}};X=De([ge(0,a.IResourceManagerService),ge(1,a.Inject(g.HyperLinkModel))],X);var Oe=Object.getOwnPropertyDescriptor,Ne=(r,t,e,n)=>{for(var i=n>1?void 0:n?Oe(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},Ve=(r,t)=>(e,n)=>t(e,n,r);let J=class extends a.Disposable{constructor(r){super(),this._commandService=r,this._registerCommands()}_registerCommands(){[re,ce,oe,le,de,ae,E,x,T,W,B].forEach(r=>{this._commandService.registerCommand(r)})}};J=Ne([Ve(0,a.ICommandService)],J);var U=(r=>(r.SHEET="gid",r.RANGE="range",r.DEFINE_NAME="rangeid",r.INVALID="invalid",r.URL="url",r))(U||{}),$e=Object.getOwnPropertyDescriptor,je=(r,t,e,n)=>{for(var i=n>1?void 0:n?$e(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},ne=(r,t)=>(e,n)=>t(e,n,r);g.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${U.SHEET}=${e}${n?`&${typeof n=="string"?U.DEFINE_NAME:U.RANGE}=${typeof n=="string"?n:C.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,i,s;if(t.startsWith("#")){const o=new URLSearchParams(t.slice(1)),d={gid:(e=o.get("gid"))!=null?e:"",range:(n=o.get("range"))!=null?n:"",rangeid:(i=o.get("rangeid"))!=null?i:"",unitid:(s=o.get("unitid"))!=null?s:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:U.URL,name:t,url:t,searchObj:null}}_getURLName(t){var u;const{gid:e,range:n,rangeid:i,unitid:s}=t,o=s?this._univerInstanceService.getUnit(s,a.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d={type:U.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!o)return d;const c=e?o.getSheetBySheetId(e):o.getActiveSheet(),l=(u=c==null?void 0:c.getName())!=null?u:"";if(n){if(!c)return d;const p=C.deserializeRangeWithSheet(n).range;return a.isValidRange(p,c)&&n!==$?{type:U.RANGE,name:C.serializeRangeWithSheet(l,p)}:d}if(i){const p=this._definedNamesService.getValueById(o.getUnitId(),i);return p?{type:U.DEFINE_NAME,name:p.formulaOrRefString}:d}if(e){const p=o.getSheetBySheetId(e);return p?{type:U.SHEET,name:p.getName()}:d}return d}},g.SheetsHyperLinkParserService=je([ne(0,a.IUniverInstanceService),ne(1,a.Inject(a.LocaleService)),ne(2,C.IDefinedNamesService)],g.SheetsHyperLinkParserService);var Ae=Object.defineProperty,xe=Object.getOwnPropertyDescriptor,We=(r,t,e)=>t in r?Ae(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Be=(r,t,e,n)=>{for(var i=n>1?void 0:n?xe(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},he=(r,t)=>(e,n)=>t(e,n,r),me=(r,t,e)=>We(r,typeof t!="symbol"?t+"":t,e);g.UniverSheetsHyperLinkPlugin=class extends a.Plugin{constructor(t=ue,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...i}=a.merge({},ue,this._config);this._configService.setConfig(Ce,i)}onStarting(){a.registerDependencies(this._injector,[[g.HyperLinkModel],[g.SheetsHyperLinkParserService],[X],[J],[K],[F],[Y],[q]]),a.touchDependencies(this._injector,[[K],[X],[J],[F],[Y],[q]])}},me(g.UniverSheetsHyperLinkPlugin,"pluginName",pe),me(g.UniverSheetsHyperLinkPlugin,"type",a.UniverInstanceType.UNIVER_SHEET),g.UniverSheetsHyperLinkPlugin=Be([a.DependentOn(m.UniverSheetsPlugin),he(1,a.Inject(a.Injector)),he(2,a.IConfigService)],g.UniverSheetsHyperLinkPlugin),g.AddHyperLinkCommand=re,g.AddHyperLinkMutation=E,g.AddRichHyperLinkCommand=ae,g.CancelHyperLinkCommand=oe,g.CancelRichHyperLinkCommand=de,g.ERROR_RANGE=$,g.RemoveHyperLinkMutation=T,g.SheetHyperLinkType=U,g.UpdateHyperLinkCommand=ce,g.UpdateHyperLinkMutation=x,g.UpdateHyperLinkRefMutation=W,g.UpdateRichHyperLinkCommand=le,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-hyper-link",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.13-nightly.202510290902",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -56,17 +56,17 @@
|
|
|
56
56
|
"rxjs": ">=7.0.0"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@univerjs/core": "0.10.
|
|
60
|
-
"@univerjs/
|
|
61
|
-
"@univerjs/
|
|
62
|
-
"@univerjs/engine-formula": "0.10.
|
|
59
|
+
"@univerjs/core": "0.10.13-nightly.202510290902",
|
|
60
|
+
"@univerjs/docs": "0.10.13-nightly.202510290902",
|
|
61
|
+
"@univerjs/sheets": "0.10.13-nightly.202510290902",
|
|
62
|
+
"@univerjs/engine-formula": "0.10.13-nightly.202510290902"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"rxjs": "^7.8.2",
|
|
66
66
|
"typescript": "^5.9.3",
|
|
67
|
-
"vite": "^7.1.
|
|
67
|
+
"vite": "^7.1.12",
|
|
68
68
|
"vitest": "^3.2.4",
|
|
69
|
-
"@univerjs-infra/shared": "0.10.
|
|
69
|
+
"@univerjs-infra/shared": "0.10.13"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"test": "vitest run",
|