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