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