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